narraleaf-react 0.6.0 → 0.8.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.
Files changed (31) hide show
  1. package/dist/game/nlcore/common/core.d.ts +2 -1
  2. package/dist/game/nlcore/common/game.d.ts +2 -1
  3. package/dist/game/nlcore/common/interface.d.ts +1 -0
  4. package/dist/game/nlcore/common/player.d.ts +2 -1
  5. package/dist/game/nlcore/common/types.d.ts +5 -1
  6. package/dist/game/nlcore/elements/built-in/Gallery.d.ts +151 -0
  7. package/dist/game/nlcore/elements/built-in/built-in.d.ts +1 -0
  8. package/dist/game/nlcore/elements/displayable/displayable.d.ts +26 -6
  9. package/dist/game/nlcore/elements/service.d.ts +0 -4
  10. package/dist/game/nlcore/elements/transform/transform.d.ts +19 -10
  11. package/dist/game/nlcore/game/keyMap.d.ts +82 -0
  12. package/dist/game/nlcore/game/liveGame.d.ts +2 -0
  13. package/dist/game/nlcore/game/types.d.ts +22 -0
  14. package/dist/game/nlcore/game.d.ts +7 -0
  15. package/dist/game/nlcore/gameTypes.d.ts +7 -14
  16. package/dist/game/nlcore/types.d.ts +15 -5
  17. package/dist/game/player/elements/Player.d.ts +1 -1
  18. package/dist/game/player/elements/type.d.ts +7 -1
  19. package/dist/game/player/gameState.d.ts +1 -2
  20. package/dist/game/player/lib/ErrorBoundary.d.ts +1 -0
  21. package/dist/game/player/lib/PageRouter/AnimatePresence.d.ts +3 -2
  22. package/dist/game/player/lib/PageRouter/Layout.d.ts +48 -0
  23. package/dist/game/player/lib/PageRouter/Page.d.ts +43 -6
  24. package/dist/game/player/lib/PageRouter/router.d.ts +619 -9
  25. package/dist/game/player/lib/PageRouter/routerHooks.d.ts +6 -0
  26. package/dist/game/player/lib/keyMap.d.ts +3 -0
  27. package/dist/game/player/lib/useConstant.d.ts +1 -0
  28. package/dist/game/player/libElements.d.ts +6 -2
  29. package/dist/main.js +43 -75
  30. package/package.json +5 -4
  31. package/dist/game/player/lib/PageRouter/PageRouter.d.ts +0 -27
@@ -5,4 +5,5 @@ export * from "./player";
5
5
  export * from "./types";
6
6
  export * from "./position";
7
7
  export * from "./transition";
8
- export { i, c, b, };
8
+ export * from "./interface";
9
+ export { i, c, b };
@@ -4,5 +4,6 @@ import { Storable, Namespace } from "../elements/persistent/storable";
4
4
  import { LiveGame } from "../game/liveGame";
5
5
  import { Preference } from "../game/preference";
6
6
  import type { SavedGame } from "../gameTypes";
7
- export { LiveGame, GameState, Game, Storable, Namespace, Preference, };
7
+ import { KeyMap } from "../game/keyMap";
8
+ export { LiveGame, GameState, Game, Storable, Namespace, Preference, KeyMap, };
8
9
  export type { SavedGame, };
@@ -0,0 +1 @@
1
+ export { Gallery } from "../elements/built-in/Gallery";
@@ -2,6 +2,7 @@ import Player from "../../player/elements/Player";
2
2
  import GameProviders from "../../player/provider/providers";
3
3
  import { useGame } from "../../../game/player/provider/game-state";
4
4
  import { useRouter } from "../../player/lib/PageRouter/router";
5
+ import { usePathname, useParams, useQueryParams } from "../../player/lib/PageRouter/routerHooks";
5
6
  export * from "../../player/type";
6
7
  export * from "../../player/libElements";
7
- export { GameProviders, Player, useGame, useRouter, };
8
+ export { GameProviders, Player, useGame, useRouter, usePathname, useParams, useQueryParams, };
@@ -5,5 +5,9 @@ import { IGamePluginRegistry } from "../game/plugin/plugin";
5
5
  import { LiveGameEventToken } from "../types";
6
6
  import { GameHistory } from "../action/gameHistory";
7
7
  import { GameConfig, SavedGame, NotificationToken, SavedGameMetaData } from "../gameTypes";
8
+ import type { LayoutRouter } from "../../../game/player/lib/PageRouter/router";
9
+ import { KeyBindingType, WebKeyboardKey } from "../game/types";
10
+ import { KeyBindingValue } from "../game/keyMap";
8
11
  export * from "../elements/type";
9
- export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions, GameConfig, SavedGame, NotificationToken, SavedGameMetaData, };
12
+ export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions, GameConfig, SavedGame, NotificationToken, SavedGameMetaData, LayoutRouter, KeyBindingValue, WebKeyboardKey, };
13
+ export { KeyBindingType, };
@@ -0,0 +1,151 @@
1
+ import { Lambda } from "../condition";
2
+ import { ScriptCtx } from "../script";
3
+ import { Service } from "../service";
4
+ type GalleryActions<T extends Record<string, any>> = {
5
+ "add": [name: string, metadata: T | ((ctx: ScriptCtx) => T)];
6
+ "remove": [name: string];
7
+ "clear": [];
8
+ };
9
+ /**
10
+ * A utility to manage a gallery of items
11
+ * @template Metadata - The metadata of the items
12
+ * @class
13
+ * @example
14
+ * ```ts
15
+ * const gallery = new Gallery<{timestamp: number}>();
16
+ *
17
+ * scene.action([
18
+ * gallery.add("item", () => ({
19
+ * timestamp: Date.now(),
20
+ * }))
21
+ * ]);
22
+ *
23
+ * scene.action([
24
+ * gallery.remove("item")
25
+ * ]);
26
+ *
27
+ * scene.action([
28
+ * Condition.If(gallery.has("item"), [
29
+ * // ...
30
+ * ])
31
+ * ]);
32
+ * ```
33
+ *
34
+ * to use this class, you need to register it in the story:
35
+ * ```ts
36
+ * story.registerService("gallery", gallery);
37
+ * ```
38
+ *
39
+ * After registering, you can access the gallery using game context:
40
+ * ```ts
41
+ * const liveGame = useLiveGame();
42
+ *
43
+ * const gallery = liveGame.story?.getService<Gallery<{timestamp: number}>>("gallery");
44
+ *
45
+ * if (gallery) {
46
+ * console.log("All items in the gallery:", gallery.$getAll());
47
+ * }
48
+ * ```
49
+ */
50
+ export declare class Gallery<Metadata extends Record<string, any>> extends Service<GalleryActions<Metadata>> {
51
+ private unlocked;
52
+ constructor();
53
+ serialize(): Record<string, any> | null;
54
+ deserialize(data: Record<string, any>): void;
55
+ /**
56
+ * Add an item to the gallery
57
+ * @chainable
58
+ * @param name - The name of the item to add
59
+ * @example
60
+ * ```ts
61
+ * scene.action([
62
+ * gallery.add("item", {
63
+ * // ...
64
+ * })
65
+ * ]);
66
+ *
67
+ * // or
68
+ *
69
+ * scene.action([
70
+ * gallery.add("item", (ctx) => {
71
+ * return {
72
+ * timestamp: Date.now(),
73
+ * };
74
+ * })
75
+ * ]);
76
+ * ```
77
+ */
78
+ add(name: string, metadata: Metadata | ((ctx: ScriptCtx) => Metadata)): never;
79
+ /**
80
+ * Check if an item is in the gallery
81
+ * @param name - The name of the item to check
82
+ * @returns A lambda that returns true if the item is in the gallery, false otherwise
83
+ * @example
84
+ * ```ts
85
+ * Condition.If(gallery.has("item"), [
86
+ * // ...
87
+ * ])
88
+ * ```
89
+ */
90
+ has(name: string): Lambda<boolean>;
91
+ /**
92
+ * Remove an item from the gallery
93
+ * @chainable
94
+ * @param name - The name of the item to remove
95
+ * @example
96
+ * ```ts
97
+ * scene.action([
98
+ * gallery
99
+ * .remove("item")
100
+ * .remove("item2"),
101
+ * ]);
102
+ * ```
103
+ */
104
+ remove(name: string): never;
105
+ /**
106
+ * Clear the gallery
107
+ * @chainable
108
+ * @example
109
+ * ```ts
110
+ * scene.action([
111
+ * gallery.clear()
112
+ * ]);
113
+ * ```
114
+ */
115
+ clear(): never;
116
+ /**
117
+ * Remove an item from the gallery INSTANTLY
118
+ * @param name - The name of the item to remove
119
+ */
120
+ $remove(name: string): void;
121
+ /**
122
+ * Clear the gallery
123
+ *
124
+ * After calling this method, the gallery will be empty INSTANTLY
125
+ */
126
+ $clear(): void;
127
+ /**
128
+ * Get the metadata of an item
129
+ * @param name - The name of the item to get the metadata of
130
+ * @returns The metadata of the item
131
+ */
132
+ $get(name: string): Metadata;
133
+ /**
134
+ * Set the metadata of an item
135
+ * @param name - The name of the item to set the metadata of
136
+ * @param metadata - The metadata of the item to set
137
+ */
138
+ $set(name: string, metadata: Metadata): void;
139
+ /**
140
+ * Get all the items in the gallery
141
+ * @returns All the items in the gallery
142
+ */
143
+ $getAll(): Record<string, Metadata>;
144
+ /**
145
+ * Check if an item is in the gallery
146
+ * @param name - The name of the item to check
147
+ * @returns True if the item is in the gallery, false otherwise
148
+ */
149
+ $has(name: string): boolean;
150
+ }
151
+ export {};
@@ -0,0 +1 @@
1
+ export { Gallery } from "./Gallery";
@@ -15,13 +15,33 @@ export declare abstract class Displayable<StateData extends Record<string, any>,
15
15
  */
16
16
  pos(position: TransformDefinitions.ImageTransformProps["position"], duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
17
17
  /**
18
- * Set Image Scale
19
- * @param scale - The scale of the image, between 0 and 1
20
- * @param duration - The duration of the scale animation
21
- * @param easing - The easing of the scale animation
22
- * @chainable
18
+ * Set the zoom of the current staging sequence.
19
+ * @param zoom - The zoom of the transform. use `1` to keep the original size
20
+ */
21
+ zoom(zoom: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
22
+ /**
23
+ * Set the scale of the current staging sequence on x axis.
24
+ * @param scaleX - The scale of the transform on x axis.
25
+ */
26
+ scaleX(scaleX: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
27
+ /**
28
+ * Set the scale of the current staging sequence on y axis.
29
+ * @param scaleY - The scale of the transform on y axis.
30
+ */
31
+ scaleY(scaleY: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
32
+ /**
33
+ * Set the scale of the current staging sequence.
34
+ * @param scaleX - The scale of the transform on x axis. use negative value to invert the scale
35
+ * @param scaleY - The scale of the transform on y axis. use negative value to invert the scale
36
+ */
37
+ scale(scaleX: number, scaleY: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
38
+ /**
39
+ * Set the scale of the current staging sequence on x and y axis.
40
+ * @param scaleX - The scale of the transform on x axis. use negative value to invert the scale
41
+ * @param scaleY - The scale of the transform on y axis. use negative value to invert the scale
42
+ * @alias {@link Displayable.scale}
23
43
  */
24
- scale(scale: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
44
+ scaleXY(scaleX: number, scaleY: number, duration?: number, easing?: TransformDefinitions.EasingDefinition): Proxied<Self, Chained<LogicAction.Actions>>;
25
45
  /**
26
46
  * Set Image Rotation
27
47
  * @param rotation - The rotation of the image, in degrees
@@ -51,9 +51,5 @@ export declare abstract class Service<Content extends ServiceContentType = Servi
51
51
  * @param data data exported from toData
52
52
  */
53
53
  abstract deserialize?(data: RawData): void;
54
- /**
55
- * Called when the service is initialized
56
- */
57
- abstract init?(): void;
58
54
  }
59
55
  export {};
@@ -1,13 +1,7 @@
1
- import React from "react";
2
1
  import type { CommonDisplayableConfig } from "../../types";
3
- import type { DOMKeyframesDefinition } from "motion";
4
2
  import { TransformDefinitions } from "./type";
5
3
  import { CSSProps } from "../../elements/transition/type";
6
- export type Transformers = "position" | "opacity" | "scale" | "rotation" | "display" | "src" | "backgroundColor" | "backgroundOpacity" | "transform" | "fontColor";
7
- export type TransformHandler<T> = (value: T) => DOMKeyframesDefinition;
8
4
  type OverwriteMap = {
9
- transform: React.CSSProperties["transform"];
10
- scale: React.CSSProperties["scale"];
11
5
  overwrite: CSSProps;
12
6
  };
13
7
  export type OverwriteDefinition = {
@@ -86,11 +80,26 @@ export declare class Transform<T extends TransformDefinitions.Types = CommonDisp
86
80
  */
87
81
  commit(options?: Partial<TransformDefinitions.SequenceOptions>): this;
88
82
  /**
89
- * Scale the current staging sequence.
90
- * @param {number} scale - The scale of the transform.
91
- * @returns {this} The current Transform instance for method chaining.
83
+ * Set the zoom of the current staging sequence.
84
+ * @param zoom - The zoom of the transform. use `1` to keep the original size
85
+ */
86
+ zoom(zoom: TransformDefinitions.Types["zoom"]): this;
87
+ /**
88
+ * Set the scale of the current staging sequence on x axis.
89
+ * @param scaleX - The scale of the transform on x axis.
90
+ */
91
+ scaleX(scaleX: TransformDefinitions.Types["scaleX"]): this;
92
+ /**
93
+ * Set the scale of the current staging sequence on y axis.
94
+ * @param scaleY - The scale of the transform on y axis.
95
+ */
96
+ scaleY(scaleY: TransformDefinitions.Types["scaleY"]): this;
97
+ /**
98
+ * Set the scale of the current staging sequence.
99
+ * @param scaleX - The scale of the transform on x axis. use negative value to invert the scale
100
+ * @param scaleY - The scale of the transform on y axis. use negative value to invert the scale
92
101
  */
93
- scale(scale: TransformDefinitions.Types["scale"]): this;
102
+ scale(scaleX: TransformDefinitions.Types["scaleX"], scaleY: TransformDefinitions.Types["scaleY"]): this;
94
103
  /**
95
104
  * Rotate the current staging sequence.
96
105
  * @param {number} rotation - The rotation of the transform.
@@ -0,0 +1,82 @@
1
+ import { EventDispatcher } from "../../../util/data";
2
+ import { KeyBindingType, WebKeyboardKey } from "./types";
3
+ export type KeyBindingValue = WebKeyboardKey[] | WebKeyboardKey | null;
4
+ export declare class KeyMap {
5
+ private keyMap;
6
+ readonly events: EventDispatcher<{
7
+ "event:keyMap.change": [KeyBindingType | string, KeyBindingValue];
8
+ }>;
9
+ constructor(keyMap?: Record<KeyBindingType | string, KeyBindingValue>);
10
+ /**
11
+ * Set a key binding (case-insensitive)
12
+ * @param type - The type of key binding
13
+ * @param value - The value of the key binding
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // Set the skip action to the space key
18
+ * game.keyMap.setKeyBinding(KeyBindingType.skipAction, " ");
19
+ *
20
+ * // Press either Control or F3 to skip the action
21
+ * game.keyMap.setKeyBinding(KeyBindingType.skipAction, ["Control", "F3"]);
22
+ *
23
+ * // Remove the key binding
24
+ * game.keyMap.setKeyBinding(KeyBindingType.skipAction, null);
25
+ * ```
26
+ */
27
+ setKeyBinding(type: KeyBindingType | string, value: KeyBindingValue): void;
28
+ /**
29
+ * Get a key binding
30
+ * @param type - The type of key binding
31
+ * @returns The value of the key binding
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const skipKeyBinding = game.keyMap.getKeyBinding(KeyBindingType.skipAction);
36
+ * // ["Control"]
37
+ * ```
38
+ */
39
+ getKeyBinding(type: KeyBindingType | string): KeyBindingValue;
40
+ /**
41
+ * Add a key binding (case-insensitive)
42
+ * @param type - The type of key binding
43
+ * @param value - The value of the key binding
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * game.keyMap.addKeyBinding(KeyBindingType.skipAction, "F3");
48
+ * // Now you can press F3 to skip the action
49
+ *
50
+ * // equivalent to
51
+ * const currentKeyBinding = game.keyMap.getKeyBinding(KeyBindingType.skipAction);
52
+ * game.keyMap.setKeyBinding(
53
+ * KeyBindingType.skipAction,
54
+ * [
55
+ * ...(Array.isArray(currentKeyBinding) ? currentKeyBinding :
56
+ * currentKeyBinding !== null ? [currentKeyBinding] : []),
57
+ * "F3"
58
+ * ]
59
+ * );
60
+ * ```
61
+ */
62
+ addKeyBinding(type: KeyBindingType | string, value: KeyBindingValue): void;
63
+ getKeyBindings(): Record<KeyBindingType | string, KeyBindingValue>;
64
+ onKeyBindingChange(type: KeyBindingType | string, listener: (value: KeyBindingValue) => void): import("../../../util/data").EventToken<import("../../../util/data").EventTypes>;
65
+ importKeyBindings(keyBindings: Record<KeyBindingType | string, KeyBindingValue>): void;
66
+ exportKeyBindings(): Record<KeyBindingType | string, KeyBindingValue>;
67
+ /**
68
+ * Check if a key matches a key binding (case-insensitive)
69
+ * @param type - The type of key binding
70
+ * @param key - The key to check
71
+ * @returns True if the key matches the key binding, false otherwise
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * // if the skip action is set to [" ", "F3"]
76
+ * game.keyMap.match(KeyBindingType.skipAction, " "); // true
77
+ * game.keyMap.match(KeyBindingType.skipAction, "F3"); // true
78
+ * game.keyMap.match(KeyBindingType.skipAction, "A"); // false
79
+ * ```
80
+ */
81
+ match(type: KeyBindingType | string, key: WebKeyboardKey): boolean;
82
+ }
@@ -1,4 +1,5 @@
1
1
  import { Storable } from "../elements/persistent/storable";
2
+ import { Story } from "../elements/story";
2
3
  import { Game } from "../game";
3
4
  import type { NotificationToken, SavedGame } from "../gameTypes";
4
5
  import { LiveGameEventHandler, LiveGameEventToken } from "../types";
@@ -19,6 +20,7 @@ export declare class LiveGame {
19
20
  };
20
21
  game: Game;
21
22
  events: EventDispatcher<LiveGameEvent>;
23
+ story: Story | null;
22
24
  getStorable(): Storable;
23
25
  get storable(): Storable;
24
26
  /**
@@ -0,0 +1,22 @@
1
+ /**
2
+ * See [Key_Values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
3
+ *
4
+ * Case-insensitive
5
+ */
6
+ export type WebKeyboardKey = string;
7
+ export declare enum KeyBindingType {
8
+ /**
9
+ * When the player presses one of these keys, the game will show the next sentence
10
+ *
11
+ * See [Key_Values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
12
+ * @default [" "]
13
+ */
14
+ skipAction = "skipAction",
15
+ /**
16
+ * When the player presses one of these keys, the game will skip the current action
17
+ *
18
+ * See [Key_Values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
19
+ * @default ["Control"]
20
+ */
21
+ nextAction = "nextAction"
22
+ }
@@ -4,6 +4,8 @@ import { LogicAction } from "./action/logicAction";
4
4
  import { LiveGame } from "./game/liveGame";
5
5
  import { Preference } from "./game/preference";
6
6
  import { Plugins, IGamePluginRegistry } from "./game/plugin/plugin";
7
+ import { LayoutRouter } from "../player/lib/PageRouter/router";
8
+ import { KeyMap } from "./game/keyMap";
7
9
  declare enum GameSettingsNamespace {
8
10
  game = "game"
9
11
  }
@@ -31,10 +33,15 @@ export declare class Game {
31
33
  * Game settings
32
34
  */
33
35
  preference: Preference<GamePreference>;
36
+ /**
37
+ * Game key bindings
38
+ */
39
+ keyMap: KeyMap;
34
40
  /**
35
41
  * Plugin registry
36
42
  */
37
43
  plugins: Plugins;
44
+ router: LayoutRouter;
38
45
  /**
39
46
  * Create a new game
40
47
  * @param config - Game configuration
@@ -87,13 +87,6 @@ export type GameConfig = {
87
87
  * @default 1080
88
88
  */
89
89
  height: number;
90
- /**
91
- * When the player presses one of these keys, the game will skip the current action
92
- *
93
- * See [Key_Values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
94
- * @default ["Control"]
95
- */
96
- skipKey: React.KeyboardEvent["key"][];
97
90
  /**
98
91
  * If true, the game will listen to the window events instead of the player element
99
92
  *
@@ -173,13 +166,6 @@ export type GameConfig = {
173
166
  * @default 1
174
167
  */
175
168
  screenshotQuality: number;
176
- /**
177
- * When the player presses one of these keys, the game will show the next sentence
178
- *
179
- * See [Key_Values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values)
180
- * @default [" "]
181
- */
182
- nextKey: React.KeyboardEvent["key"][];
183
169
  /**
184
170
  * If true, the game will scale the dialog to fit the screen
185
171
  *
@@ -231,6 +217,13 @@ export type GameConfig = {
231
217
  * @default true
232
218
  */
233
219
  allowSkipTextTransition: boolean;
220
+ /**
221
+ * If true, the animation will propagate to the children
222
+ *
223
+ * This behavior is controlled by [motion](https://motion.dev): `When true, exit animations will be propagated to nested AnimatePresence components.`
224
+ * @default true
225
+ */
226
+ animationPropagate: boolean;
234
227
  /**
235
228
  * Base width of the dialog in pixels
236
229
  *
@@ -28,11 +28,6 @@ export type Length = number | `${number}px`;
28
28
  export type RelativeLength = Length | "100%";
29
29
  export type CommonImagePosition = "left" | "center" | "right";
30
30
  export type CommonDisplayableConfig = {
31
- /**
32
- * Scale of the element, between 0 and 1
33
- * @default 1
34
- */
35
- scale?: number;
36
31
  /**
37
32
  * Rotation of the element, in degrees
38
33
  * @default 0
@@ -52,6 +47,21 @@ export type CommonDisplayableConfig = {
52
47
  * Alt text of the element
53
48
  */
54
49
  alt?: string;
50
+ /**
51
+ * Scale of the element on x axis, use negative value to invert the scale
52
+ * @default 1
53
+ */
54
+ scaleX?: number;
55
+ /**
56
+ * Scale of the element on y axis, use negative value to invert the scale
57
+ * @default 1
58
+ */
59
+ scaleY?: number;
60
+ /**
61
+ * Zoom of the element, use `1` to keep the original size
62
+ * @default 1
63
+ */
64
+ zoom?: number;
55
65
  };
56
66
  export declare const ImagePosition: {
57
67
  [K in CommonImagePosition]: K;
@@ -1,4 +1,4 @@
1
1
  import "client-only";
2
2
  import { PlayerProps } from "../elements/type";
3
3
  import React from "react";
4
- export default function Player({ story, width, height, className, onReady, onEnd, children, active, }: Readonly<PlayerProps>): React.JSX.Element;
4
+ export default function Player({ story, width, height, className, onReady, onEnd, onError, children, active, }: Readonly<PlayerProps>): React.JSX.Element;
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { ErrorInfo } from "react";
2
2
  import { IDialogProps, SayElementProps } from "../elements/say/type";
3
3
  import { IUserMenuProps, MenuElementProps } from "../elements/menu/type";
4
4
  import { Story } from "../../nlcore/elements/story";
@@ -41,6 +41,12 @@ export interface PlayerProps {
41
41
  * only called each lifecycle once
42
42
  */
43
43
  onEnd?: (ctx: PlayerEventContext) => void;
44
+ /**
45
+ * Once the game encounters an error
46
+ *
47
+ * only called each lifecycle once
48
+ */
49
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
44
50
  children?: React.ReactNode;
45
51
  /**
46
52
  * Whether to show the player
@@ -24,7 +24,6 @@ import { Timelines } from "./Tasks";
24
24
  import { Notification, NotificationManager } from "./lib/notification";
25
25
  import { ActionHistoryManager } from "../../game/nlcore/action/actionHistory";
26
26
  import { GameHistoryManager } from "../../game/nlcore/action/gameHistory";
27
- import { Router } from "./lib/PageRouter/router";
28
27
  type Legacy_PlayerStateElement = {
29
28
  texts: Clickable<TextElement>[];
30
29
  menus: Clickable<MenuElement, Chosen>[];
@@ -105,7 +104,7 @@ export declare class GameState {
105
104
  readonly idManager: IdManager;
106
105
  readonly actionHistory: ActionHistoryManager;
107
106
  readonly gameHistory: GameHistoryManager;
108
- pageRouter: Router | null;
107
+ pageRouter: null;
109
108
  constructor(game: Game, stage: StageUtils);
110
109
  get deps(): number;
111
110
  addVideo(video: Video): this;
@@ -1,6 +1,7 @@
1
1
  import React, { ErrorInfo, ReactNode } from "react";
2
2
  interface ErrorBoundaryProps {
3
3
  children: ReactNode;
4
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
4
5
  }
5
6
  interface ErrorBoundaryState {
6
7
  hasError: boolean;
@@ -1,4 +1,5 @@
1
1
  import { FirstParam } from "../../../../util/data";
2
- import { AnimatePresence } from "motion/react";
3
2
  import { JSX } from "react";
4
- export type AnimatePresenceComponent = (arg0: FirstParam<typeof AnimatePresence>) => JSX.Element;
3
+ import { AnimatePresence as OriginalAnimatePresence } from "motion/react";
4
+ export type AnimatePresenceComponent = (arg0: FirstParam<typeof OriginalAnimatePresence>) => JSX.Element;
5
+ export declare const AnimatePresence: AnimatePresenceComponent;
@@ -0,0 +1,48 @@
1
+ import React from "react";
2
+ import { LayoutRouter } from "./router";
3
+ type LayoutContextType = {
4
+ router: LayoutRouter;
5
+ path: string | null;
6
+ consumedBy?: string;
7
+ };
8
+ type LayoutContextProviderProps = {
9
+ children: React.ReactNode;
10
+ path: string | null;
11
+ consumedBy?: string;
12
+ };
13
+ export declare function LayoutRouterProvider({ children, path, consumedBy }: LayoutContextProviderProps): React.JSX.Element;
14
+ export declare function useLayout(): Omit<LayoutContextType, "path"> & {
15
+ path: string;
16
+ };
17
+ export type LayoutProps = {
18
+ children: React.ReactNode;
19
+ /**
20
+ * The relative path of the layout. It can be a path or a path pattern.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Can be navigated to by "/home"
25
+ * <Layout name="home">
26
+ * <div>Home</div>
27
+ * </Layout>
28
+ *
29
+ * <Layout name="user">
30
+ * // equivalent to "/user/:id"
31
+ * // Can be navigated to by "/user/123"
32
+ * <Layout name=":id">
33
+ * <div>User</div>
34
+ * </Layout>
35
+ * </Layout>
36
+ * ```
37
+ */
38
+ name: string;
39
+ /**
40
+ * When true, exit animations will be propagated to nested AnimatePresence components.
41
+ */
42
+ propagate?: boolean;
43
+ };
44
+ export declare function Layout({ children, name, propagate }: LayoutProps): React.JSX.Element;
45
+ export declare function RootLayout({ children }: {
46
+ children: React.ReactNode;
47
+ }): React.JSX.Element;
48
+ export {};