narraleaf-react 0.29.1 → 0.31.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.
@@ -22,9 +22,10 @@ export declare const DisplayableActionTypes: {
22
22
  readonly applyTransform: "displayable:applyTransform";
23
23
  readonly applyTransition: "displayable:applyTransition";
24
24
  readonly init: "displayable:init";
25
+ readonly bringToFront: "displayable:bringToFront";
25
26
  };
26
27
  export type DisplayableActionContentType<TransitionType extends Transition = Transition> = {
27
- [K in typeof DisplayableActionTypes[keyof typeof DisplayableActionTypes]]: K extends "displayable:applyTransform" ? [Transform] : K extends "displayable:applyTransition" ? [TransitionType, ((transition: TransitionType) => TransitionType)?] : K extends "displayable:init" ? [scene: Scene | null, layer: Layer | null, isElement?: boolean] : any;
28
+ [K in typeof DisplayableActionTypes[keyof typeof DisplayableActionTypes]]: K extends "displayable:applyTransform" ? [Transform] : K extends "displayable:applyTransition" ? [TransitionType, ((transition: TransitionType) => TransitionType)?] : K extends "displayable:init" ? [scene: Scene | null, layer: Layer | null, isElement?: boolean] : K extends "displayable:bringToFront" ? [] : any;
28
29
  };
29
30
  export declare const CharacterActionTypes: {
30
31
  readonly say: "character:say";
@@ -17,10 +17,26 @@ export declare class DisplayableAction<T extends Values<typeof DisplayableAction
17
17
  readonly applyTransform: "displayable:applyTransform";
18
18
  readonly applyTransition: "displayable:applyTransition";
19
19
  readonly init: "displayable:init";
20
+ readonly bringToFront: "displayable:bringToFront";
20
21
  };
21
22
  executeAction(gameState: GameState, injection: ActionExecutionInjection): ExecutedActionResult;
22
23
  applyTransform(state: GameState, element: Displayable<any, any>, transform: Transform, injection: ActionExecutionInjection, onFinished?: () => void): Awaitable<CalledActionResult, CalledActionResult>;
23
24
  applyTransition(state: GameState, element: Displayable<any, any>, transition: TransitionType, injection: ActionExecutionInjection, onFinished?: () => void): Awaitable<CalledActionResult, CalledActionResult>;
24
25
  initDisplayable(state: GameState, scene: Scene | null, element: Displayable<any, any>, layer: Layer | null, isElement: boolean | undefined, injection: ActionExecutionInjection): Awaitable<CalledActionResult>;
26
+ /**
27
+ * Move the element to the end of the array its layer draws from.
28
+ *
29
+ * A layer renders its elements in array order, so the last entry is the one drawn on top; there
30
+ * is no per-element depth number to set. Reordering the array rather than introducing one is
31
+ * what keeps this saveable for free — {@link GameState.toData} writes each layer out as a list
32
+ * of ids in exactly this order, and loading rebuilds the array from it.
33
+ *
34
+ * Nothing is tweened, so the returned awaitable is settled before it is handed back.
35
+ */
36
+ bringToFront(state: GameState, element: Displayable<any, any>, injection: ActionExecutionInjection): Awaitable<CalledActionResult>;
37
+ /**
38
+ * The array of the scene's layer that currently holds this element, or null if none does.
39
+ */
40
+ private static getLayerElements;
25
41
  stringify(_story: Story, _seen: Set<LogicAction.Actions>, _strict: boolean): string;
26
42
  }
@@ -9,8 +9,9 @@ import { Darkness } from "../elements/transition/transitions/image/darkness";
9
9
  import { Exposure } from "../elements/transition/transitions/image/exposure";
10
10
  import { ThroughColor } from "../elements/transition/transitions/image/throughColor";
11
11
  import { Reveal } from "../elements/transition/transitions/image/reveal";
12
+ import { RuleReveal } from "../elements/transition/transitions/image/ruleReveal";
12
13
  import { Mask } from "../elements/transition/transitions/image/mask";
13
- export { Transition, ImageTransition, TextTransition, Dissolve, FadeIn, BlurDissolve, Push, Darkness, Exposure, ThroughColor, Reveal, Mask, };
14
+ export { Transition, ImageTransition, TextTransition, Dissolve, FadeIn, BlurDissolve, Push, Darkness, Exposure, ThroughColor, Reveal, RuleReveal, Mask, };
14
15
  export type { DissolveOptions } from "../elements/transition/transitions/image/dissolve";
15
16
  export type { FadeInOptions } from "../elements/transition/transitions/image/fadeIn";
16
17
  export type { BlurDissolveOptions } from "../elements/transition/transitions/image/blurDissolve";
@@ -19,5 +20,6 @@ export type { DarknessOptions } from "../elements/transition/transitions/image/d
19
20
  export type { ExposureOptions } from "../elements/transition/transitions/image/exposure";
20
21
  export type { ThroughColorOptions, ThroughColorUncover, } from "../elements/transition/transitions/image/throughColor";
21
22
  export type { RevealOptions } from "../elements/transition/transitions/image/reveal";
23
+ export type { RuleRevealOptions } from "../elements/transition/transitions/image/ruleReveal";
22
24
  export type { MaskPattern, WipePatternOptions, BarnDoorPatternOptions, IrisPatternOptions, ClockPatternOptions, FanPatternOptions, BlindsPatternOptions, DotsPatternOptions, } from "../elements/transition/transitions/image/mask";
23
25
  export type { BlindsOrientation } from "../elements/transition/transitions/image/transitionMaskUtils";
@@ -8,9 +8,10 @@ import { Chained, Proxied } from "../action/chain";
8
8
  *
9
9
  * A camera is transformed exactly like any other displayable, so its initial pose is described
10
10
  * with the same {@link TransformDefinitions.ImageTransformProps} fields (position, zoom, scale,
11
- * rotation, opacity, filter, ...).
11
+ * rotation, opacity, filter, ...), plus the lens channels
12
+ * ({@link TransformDefinitions.CameraLensProps}) only a camera has.
12
13
  */
13
- export type ICameraUserConfig = TransformDefinitions.ImageTransformProps;
14
+ export type ICameraUserConfig = TransformDefinitions.CameraTransformProps;
14
15
  export type CameraDataRaw = {
15
16
  transformState: Record<string, any>;
16
17
  };
@@ -35,7 +36,7 @@ export type CameraDataRaw = {
35
36
  * ]);
36
37
  * ```
37
38
  */
38
- export declare class Camera extends Displayable<CameraDataRaw, Camera, TransformDefinitions.ImageTransformProps> implements EventfulDisplayable {
39
+ export declare class Camera extends Displayable<CameraDataRaw, Camera, TransformDefinitions.CameraTransformProps> implements EventfulDisplayable {
39
40
  /**
40
41
  * Create a camera. A story already owns a default one ({@link Story.camera}); construct your
41
42
  * own only to override the initial pose via the story config.
@@ -66,8 +67,64 @@ export declare class Camera extends Displayable<CameraDataRaw, Camera, Transform
66
67
  */
67
68
  darken(darkness: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Camera, Chained<LogicAction.Actions, Camera>>;
68
69
  /**
69
- * Return the camera to its neutral pose: centred, zoom `1`, no rotation, fully opaque and no
70
- * filter (which also clears {@link Camera.darken}).
70
+ * Close or open the shutter: two blades that meet in the middle of the frame.
71
+ *
72
+ * `1` is fully shut and `0` fully open, and everything between is a partial cover — which makes
73
+ * a small standing value a letterbox rather than a blink, `0.12` being about a cinematic matte.
74
+ * A blink is this driven to `1` and back; the timing of one is the story's to choose, so the
75
+ * engine offers the channel rather than a named routine.
76
+ *
77
+ * @param shutter - Coverage between `0` (open) and `1` (shut). Out-of-range values are clamped.
78
+ * @chainable
79
+ * @example
80
+ * ```ts
81
+ * scene.action([
82
+ * story.camera.shutter(1, 180, "easeInOut"),
83
+ * story.camera.shutter(0, 220, "easeInOut"),
84
+ * ]);
85
+ * ```
86
+ */
87
+ shutter(shutter: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Camera, Chained<LogicAction.Actions, Camera>>;
88
+ /**
89
+ * Darken the corners of the frame.
90
+ *
91
+ * Unlike {@link Camera.darken}, which is a filter over the picture, this is a plate over the
92
+ * *view*: it does not move with the camera, so a vignette holds still while the stage
93
+ * underneath it zooms, pans and rotates. Adjust its falloff with {@link Camera.lens}.
94
+ *
95
+ * @param vignette - Strength between `0` (none) and `1`. Out-of-range values are clamped.
96
+ * @chainable
97
+ * @example
98
+ * ```ts
99
+ * scene.action([
100
+ * story.camera.vignette(0.72, 300, "easeInOut"),
101
+ * jS`Everything narrowed to the middle of the room.`,
102
+ * story.camera.vignette(0, 300, "easeInOut"),
103
+ * ]);
104
+ * ```
105
+ */
106
+ vignette(vignette: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Camera, Chained<LogicAction.Actions, Camera>>;
107
+ /**
108
+ * Set any of the lens channels at once — the two strengths and the colour and falloff geometry
109
+ * they are drawn with.
110
+ *
111
+ * The geometry fields take effect the next time the strength they belong to is above `0`, so
112
+ * they are usually set as a cut before the effect is faded in.
113
+ *
114
+ * @chainable
115
+ * @example
116
+ * ```ts
117
+ * scene.action([
118
+ * story.camera.lens({vignetteColor: "#1a0b2e", vignetteInner: "20%", vignetteOuter: "95%"}),
119
+ * story.camera.vignette(0.9, 400),
120
+ * ]);
121
+ * ```
122
+ */
123
+ lens(lens: TransformDefinitions.CameraLensProps, options?: TransformDefinitions.VisualEffectOptions): Proxied<Camera, Chained<LogicAction.Actions, Camera>>;
124
+ /**
125
+ * Return the camera to its neutral pose: centred, zoom `1`, no rotation, fully opaque, no
126
+ * filter (which also clears {@link Camera.darken}) and no lens effect — the shutter opens and
127
+ * the vignette lifts.
71
128
  *
72
129
  * Named `resetCamera` rather than `reset` because every element already owns an internal
73
130
  * `reset()` lifecycle hook — the one the engine calls when a new game starts — and an authoring
@@ -82,4 +139,20 @@ export declare class Camera extends Displayable<CameraDataRaw, Camera, Transform
82
139
  * ```
83
140
  */
84
141
  resetCamera(duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Camera, Chained<LogicAction.Actions, Camera>>;
142
+ /**
143
+ * Not available on a camera: a camera has no front or back to be moved to.
144
+ *
145
+ * `bringToFront` reorders the list of elements a layer draws, and the camera is in no such list
146
+ * — it is the thing those lists are drawn *inside*. Every layer of every scene moves with it as
147
+ * one unit, which is the whole point of it, and there is therefore no sprite it could be put in
148
+ * front of. This is not a matter of the camera not being on stage yet, which is what the
149
+ * inherited error would have said: waiting changes nothing, because the camera never enters a
150
+ * layer at all.
151
+ *
152
+ * Reach for a transform instead — `zoom`, or {@link Camera.pan} — if the goal was to
153
+ * bring something into view.
154
+ *
155
+ * @throws RuntimeGameError - always
156
+ */
157
+ bringToFront(): never;
85
158
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -179,6 +179,29 @@ export declare abstract class Displayable<StateData extends Record<string, any>,
179
179
  * ```
180
180
  */
181
181
  transform(transform: Transform<TransformType>): Proxied<Self, Chained<LogicAction.Actions, Self>>;
182
+ /**
183
+ * Bring the Displayable to the front of the layer it is on.
184
+ *
185
+ * Within one layer the order elements are shown in is the order they were added in, so the one
186
+ * added last is drawn over the others. This moves the element to the end of that order, and
187
+ * nothing else about it changes — it stays on the same layer, keeps its transform, and the move
188
+ * is instant.
189
+ *
190
+ * Depth *between* layers is a separate thing, decided by each layer's z-index; this cannot lift
191
+ * an element above one that sits on a higher layer.
192
+ *
193
+ * The new order is part of the saved game, so a save taken afterwards restores it.
194
+ *
195
+ * @chainable
196
+ * @example
197
+ * ```ts
198
+ * scene.action([
199
+ * yukoSprite.bringToFront(),
200
+ * yuko.say`It was me, all along.`,
201
+ * ]);
202
+ * ```
203
+ */
204
+ bringToFront(): Proxied<Self, Chained<LogicAction.Actions, Self>>;
182
205
  private registerEffectSrc;
183
206
  private static toCSSUrl;
184
207
  private static extractCSSUrls;
@@ -44,4 +44,15 @@ export declare class Layer extends Displayable<LayerDataRaw, Layer, TransformDef
44
44
  * @chainable
45
45
  */
46
46
  setZIndex(zIndex: number): Proxied<Layer, Chained<LogicAction.Actions>>;
47
+ /**
48
+ * Not available on a layer: depth between layers is the z-index.
49
+ *
50
+ * `bringToFront` moves an element to the end of the list its layer draws, and a layer is not
51
+ * in any such list — it *is* one. Accepting the call would mean accepting a story that reads as
52
+ * if it raised the layer and plays as if the line were not there, which is the failure the
53
+ * throw exists to prevent. Use {@link Layer.setZIndex} instead.
54
+ *
55
+ * @throws RuntimeGameError - always
56
+ */
57
+ bringToFront(): never;
47
58
  }
@@ -1,3 +1,4 @@
1
+ import React from "react";
1
2
  import { TransformDefinitions } from "./type";
2
3
  import { CSSProps } from "../../elements/transition/type";
3
4
  type OverwriteMap = {
@@ -7,6 +8,30 @@ export type OverwriteDefinition = {
7
8
  [K in keyof OverwriteMap]?: OverwriteHandler<OverwriteMap[K]>;
8
9
  };
9
10
  type OverwriteHandler<T> = (value: Partial<TransformDefinitions.Types>) => T;
11
+ /**
12
+ * An element that is animated *alongside* the transform's own element, from the same transform
13
+ * state, in the same `motion` sequence.
14
+ *
15
+ * The transform pipeline drives exactly one element, and its style is built by
16
+ * {@link Transform.constructStyle} — a literal, so a prop it does not know about goes nowhere. A
17
+ * companion is the escape hatch for props whose picture belongs to a *different* element than the
18
+ * one being transformed: the camera's lens overlay, which must not inherit the camera's transform,
19
+ * is the case this exists for.
20
+ *
21
+ * `project` turns the accumulated state of a segment into that element's style for that segment.
22
+ */
23
+ export type TransformCompanion = {
24
+ el: Element;
25
+ project: (props: Partial<TransformDefinitions.Types>) => CSSProps;
26
+ };
27
+ /**
28
+ * The same thing before the elements are known — what a React host holds, resolved to
29
+ * {@link TransformCompanion} at the moment the animation is built.
30
+ */
31
+ export type TransformCompanionRef = {
32
+ ref: React.RefObject<HTMLElement | null>;
33
+ project: (props: Partial<TransformDefinitions.Types>) => CSSProps;
34
+ };
10
35
  export declare class Transform<T extends TransformDefinitions.Types = TransformDefinitions.Types> {
11
36
  /**
12
37
  * Apply transform immediately
@@ -127,6 +152,19 @@ export declare class Transform<T extends TransformDefinitions.Types = TransformD
127
152
  * Set visual effect fields in the current staging sequence.
128
153
  */
129
154
  effect(effect: TransformDefinitions.VisualEffectTransformProps): this;
155
+ /**
156
+ * Set camera lens fields in the current staging sequence.
157
+ *
158
+ * Only a {@link Camera} draws these; on any other displayable they are carried in the state and
159
+ * never painted.
160
+ * @example
161
+ * ```ts
162
+ * Transform.create<TransformDefinitions.CameraTransformProps>()
163
+ * .lens({shutter: 1}).commit({duration: 180, ease: "easeInOut"})
164
+ * .lens({shutter: 0}).commit({duration: 220, ease: "easeInOut"});
165
+ * ```
166
+ */
167
+ lens(lens: TransformDefinitions.CameraLensProps): this;
130
168
  /**
131
169
  * Set the CSS mask image of the current staging sequence.
132
170
  */
@@ -29,6 +29,50 @@ export declare namespace TransformDefinitions {
29
29
  backdropFilter?: React.CSSProperties["backdropFilter"];
30
30
  mixBlendMode?: React.CSSProperties["mixBlendMode"];
31
31
  };
32
+ /**
33
+ * The camera's lens channels.
34
+ *
35
+ * These describe things a *lens* does, not things the picture does, which is why they are not
36
+ * part of {@link VisualEffectTransformProps} and never reach an element's own style: they are
37
+ * drawn by an overlay pinned to the viewport, outside the camera's transform, so a vignette
38
+ * stays put while the camera it belongs to zooms, pans and rotates underneath it.
39
+ */
40
+ type CameraLensProps = {
41
+ /**
42
+ * How far the shutter is closed, between `0` (open) and `1` (shut).
43
+ *
44
+ * Two blades close symmetrically from the top and bottom of the frame, so at `1` each
45
+ * covers half of it. Small values are a letterbox rather than a blink: `0.12` is a
46
+ * cinematic matte.
47
+ * @default 0
48
+ */
49
+ shutter?: number;
50
+ /**
51
+ * Colour of the shutter blades.
52
+ * @default "#000"
53
+ */
54
+ shutterColor?: string;
55
+ /**
56
+ * Strength of the vignette, between `0` (none) and `1` (opaque at the edges).
57
+ * @default 0
58
+ */
59
+ vignette?: number;
60
+ /**
61
+ * Colour of the vignette.
62
+ * @default "#000"
63
+ */
64
+ vignetteColor?: string;
65
+ /**
66
+ * Radius at which the vignette starts, as a CSS length or percentage of the frame.
67
+ * @default "44%"
68
+ */
69
+ vignetteInner?: string;
70
+ /**
71
+ * Radius at which the vignette reaches full strength.
72
+ * @default "78%"
73
+ */
74
+ vignetteOuter?: string;
75
+ };
32
76
  type VisualEffectOptions = Partial<CommonTransformProps>;
33
77
  type MaskOptions = VisualEffectOptions & Pick<VisualEffectTransformProps, "maskSize" | "maskPosition" | "maskRepeat" | "maskMode">;
34
78
  type WipeDirection = "left" | "right" | "top" | "bottom";
@@ -49,7 +93,16 @@ export declare namespace TransformDefinitions {
49
93
  type TextTransformProps = CommonDisplayableConfig & {
50
94
  fontColor?: Color;
51
95
  } & VisualEffectTransformProps;
52
- type Types = CommonDisplayableConfig & ImageTransformProps & TextTransformProps;
96
+ /**
97
+ * What a camera can be transformed by: everything an image can, plus the lens channels.
98
+ */
99
+ type CameraTransformProps = ImageTransformProps & CameraLensProps;
100
+ /**
101
+ * The closed set of keys a {@link Transform} can stage a change for. Every prop any displayable
102
+ * understands has to appear here, camera-only ones included, or the chainable setters cannot
103
+ * name it.
104
+ */
105
+ type Types = CommonDisplayableConfig & ImageTransformProps & TextTransformProps & CameraLensProps;
53
106
  type SequenceProps<T> = Partial<T>;
54
107
  type SequenceOptions = Partial<CommonTransformProps>;
55
108
  type Sequence<T> = {
@@ -0,0 +1,102 @@
1
+ import { AnimationController, AnimationTaskMapArray, TransitionAnimationType, TransitionTask } from "../../../../elements/transition/type";
2
+ import { TransformDefinitions } from "../../../../elements/transform/type";
3
+ import { ImageTransition } from "../../../../elements/transition/transitions/image/imageTransition";
4
+ import { ImageSrc } from "../../../../types";
5
+ type AnimationType = [TransitionAnimationType.Number];
6
+ export type RuleRevealOptions = {
7
+ /** Duration in milliseconds. */
8
+ duration: number;
9
+ /**
10
+ * The rule image: a greyscale picture whose brightness at each point says *when* that point
11
+ * changes over. Dark changes first, bright last, so a rule painted as a spiral wipes as a
12
+ * spiral. Stretched to the frame, so paint it at the stage's aspect ratio.
13
+ */
14
+ rule: ImageSrc;
15
+ /**
16
+ * Width of the soft edge, as a fraction of the rule's brightness range. `0.12` puts roughly an
17
+ * eighth of the rule's tonal range in transition at any moment; smaller is a crisper edge.
18
+ * @default 0.12
19
+ */
20
+ feather?: number;
21
+ /** Change the bright areas over first instead of the dark ones. @default false */
22
+ inverted?: boolean;
23
+ easing?: TransformDefinitions.EasingDefinition;
24
+ };
25
+ /**
26
+ * The **rule-image** engine: the target is revealed over the previous frame in the order a
27
+ * greyscale picture dictates, rather than through a geometric pattern.
28
+ *
29
+ * This is the transition form commercial visual novels are authored against — a pack of rule
30
+ * images (spirals, shatters, brush strokes, drifting cloud fronts) and one engine that plays any of
31
+ * them. {@link Reveal} covers the geometric half of the same job with {@link Mask} patterns, which
32
+ * are CSS gradients and therefore limited to shapes that can be *described*; a rule image is
33
+ * per-pixel data and can be any shape at all, which is why it is its own engine rather than another
34
+ * `MaskPattern`.
35
+ *
36
+ * ```ts
37
+ * scene.jumpTo(next, new RuleReveal({duration: 1200, rule: "/rules/spiral.png"}))
38
+ * ```
39
+ *
40
+ * ### How it works, and the one thing worth knowing
41
+ *
42
+ * At progress `t` a point changes over once the sweep has passed its brightness:
43
+ *
44
+ * ```text
45
+ * alpha = clamp01((T - luminance) / feather), T sweeping 0 .. 1 + feather
46
+ * ```
47
+ *
48
+ * That is computed by an SVG filter — `feImage` reads the rule, `feColorMatrix` turns its
49
+ * brightness into coverage, and one `feComposite` does the comparison — so the whole sweep is one
50
+ * GPU pass over the frame and costs the same as no filter at all in practice.
51
+ *
52
+ * The filter runs in **sRGB**, deliberately: filters default to linearRGB, under which a rule's
53
+ * mid-grey would land at 0.21 rather than half way, and every rule in a pack would play with its
54
+ * timing bent. Nothing about that failure looks like an error, so it is pinned here rather than
55
+ * left to a default.
56
+ */
57
+ export declare class RuleReveal extends ImageTransition<AnimationType> {
58
+ private duration;
59
+ private rule;
60
+ private feather;
61
+ private inverted;
62
+ private easing?;
63
+ /**@package */
64
+ private filterId;
65
+ /**@package */
66
+ private host;
67
+ /**@package */
68
+ private cut;
69
+ constructor(options: RuleRevealOptions);
70
+ createTask(): TransitionTask<HTMLImageElement, AnimationType>;
71
+ /**
72
+ * Tear the scaffold down when the run ends, however it ends.
73
+ *
74
+ * Both drivers call this, and the controller they get back outlives the React element — a
75
+ * transition whose element unmounts mid-run still completes its value animation — so this is
76
+ * the one place that sees every ending. {@link styleAt} also drops it on the settled frame, so
77
+ * the normal path never waits for this.
78
+ * @package
79
+ */
80
+ requestAnimations(tasks: AnimationTaskMapArray<AnimationType>): AnimationController<AnimationType>;
81
+ copy(): RuleReveal;
82
+ /**
83
+ * The style for one frame — and the side of this class that has to stay honest about the DOM.
84
+ *
85
+ * The settled frame carries no filter at all rather than a filter wound to its end: a filter
86
+ * left on a scene root keeps that subtree rasterised as one layer, and the settled pose resets
87
+ * `filter` on the assumption that a finished transition owns nothing.
88
+ * @package
89
+ */
90
+ private styleAt;
91
+ /**
92
+ * Build the filter once, on first use, and hand back the id to point `filter` at.
93
+ *
94
+ * Not built in `createTask`: that method is documented as free of side effects, and it is
95
+ * called by callers that only want to read what a transition would write.
96
+ * @package
97
+ */
98
+ private ensureScaffold;
99
+ /**@package */
100
+ private dispose;
101
+ }
102
+ export {};