narraleaf-react 0.29.0 → 0.30.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";
@@ -82,4 +82,20 @@ export declare class Camera extends Displayable<CameraDataRaw, Camera, Transform
82
82
  * ```
83
83
  */
84
84
  resetCamera(duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Camera, Chained<LogicAction.Actions, Camera>>;
85
+ /**
86
+ * Not available on a camera: a camera has no front or back to be moved to.
87
+ *
88
+ * `bringToFront` reorders the list of elements a layer draws, and the camera is in no such list
89
+ * — it is the thing those lists are drawn *inside*. Every layer of every scene moves with it as
90
+ * one unit, which is the whole point of it, and there is therefore no sprite it could be put in
91
+ * front of. This is not a matter of the camera not being on stage yet, which is what the
92
+ * inherited error would have said: waiting changes nothing, because the camera never enters a
93
+ * layer at all.
94
+ *
95
+ * Reach for a transform instead — `zoom`, or {@link Camera.pan} — if the goal was to
96
+ * bring something into view.
97
+ *
98
+ * @throws RuntimeGameError - always
99
+ */
100
+ bringToFront(): never;
85
101
  }
@@ -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
  }
@@ -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 {};