narraleaf-react 0.4.0-beta.3 → 0.4.1

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.
package/README.md CHANGED
@@ -1,10 +1,15 @@
1
- ![](docs/nlr-logo-banner.png)
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-transparent.png">
3
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
4
+ <img alt="Fallback image description" src="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
5
+ </picture>
2
6
 
3
- # NarraLeaf-React
7
+ <h1 align="center">NarraLeaf-React</h1>
4
8
 
5
- English | [简体中文](docs/README.zh-CN.md)
9
+ <h4 align="center">A React visual novel player framework</h3>
10
+
11
+ <p align="center">English | <a href="docs/README.zh-CN.md">简体中文</a></p>
6
12
 
7
- A React visual novel player framework
8
13
 
9
14
  ## What is NarraLeaf-React?
10
15
 
@@ -85,7 +90,7 @@ npm install narraleaf-react
85
90
 
86
91
  ### Documentation
87
92
 
88
- - [Introduction](https://react.narraleaf.com/documentation/introduction)
93
+ - [Introduction](https://react.narraleaf.com/documentation/introduction)****
89
94
  - [Quick Start](https://react.narraleaf.com/documentation/quick-start)
90
95
  - [Installation](https://react.narraleaf.com/documentation/installation)
91
96
  - [Basic](https://react.narraleaf.com/documentation/basic)
@@ -100,6 +105,9 @@ npm install narraleaf-react
100
105
  - [Conditional](https://react.narraleaf.com/documentation/basic/conditional)
101
106
  - [Voice](https://react.narraleaf.com/documentation/basic/voice)
102
107
  - [Manage Preferences](https://react.narraleaf.com/documentation/basic/manage-preferences)
108
+ - [Solutions](https://react.narraleaf.com/documentation/solutions)
109
+ - [Customizing the font](https://react.narraleaf.com/documentation/solutions/font)
110
+ - [Migration from Ren'Py](https://react.narraleaf.com/documentation/solutions/from-renpy)
103
111
  - [Core](https://react.narraleaf.com/documentation/core)
104
112
  - [Elements](https://react.narraleaf.com/documentation/core/elements)
105
113
  - [Scene](https://react.narraleaf.com/documentation/core/elements/scene)
@@ -116,13 +124,16 @@ npm install narraleaf-react
116
124
  - [Text](https://react.narraleaf.com/documentation/core/elements/text)
117
125
  - [Persistent](https://react.narraleaf.com/documentation/core/elements/persistent)
118
126
  - [Story](https://react.narraleaf.com/documentation/core/elements/story)
127
+ - [Displayable](https://react.narraleaf.com/documentation/core/elements/displayable)
128
+ - [Layer](https://react.narraleaf.com/documentation/core/elements/layer)
129
+ - [Service](https://react.narraleaf.com/documentation/core/elements/service)
130
+ - [Video](https://react.narraleaf.com/documentation/core/elements/video)
119
131
  - [Animation](https://react.narraleaf.com/documentation/core/animation)
120
132
  - [Game](https://react.narraleaf.com/documentation/core/game)
133
+ - [Plugin](https://react.narraleaf.com/documentation/core/plugin)
134
+ - [Utils](https://react.narraleaf.com/documentation/core/utils)
121
135
  - [Player](https://react.narraleaf.com/documentation/player)
122
- - [Customization](https://react.narraleaf.com/documentation/custom)
123
- - [Migration](https://react.narraleaf.com/documentation/migration)
124
- - [From Ren'Py](https://react.narraleaf.com/documentation/migration/from-renpy)
125
- - Info
136
+ - About
126
137
  - [License](https://react.narraleaf.com/documentation/info/license)
127
138
  - [Incompatible Changes](https://react.narraleaf.com/documentation/info/incompatible-changes)
128
139
 
@@ -6,7 +6,6 @@ import { Transform } from "../elements/transform/transform";
6
6
  import type { Scene } from "../elements/scene";
7
7
  import type { MenuData } from "../elements/menu";
8
8
  import { Awaitable, FlexibleTuple, SelectElementFromEach } from "../../../util/data";
9
- import { ITransition } from "../elements/transition/type";
10
9
  import type { Sound } from "../elements/sound";
11
10
  import type { Script } from "../elements/script";
12
11
  import { Sentence } from "../elements/character/sentence";
@@ -110,7 +109,7 @@ export declare const TextActionTypes: {
110
109
  readonly setFontSize: "text:setFontSize";
111
110
  };
112
111
  export type TextActionContentType = {
113
- [K in typeof TextActionTypes[keyof typeof TextActionTypes]]: K extends "text:setText" ? [string] : K extends "text:show" ? [Transform<TransformDefinitions.TextTransformProps>] : K extends "text:hide" ? [Transform<TransformDefinitions.TextTransformProps>] : K extends "text:applyTransform" ? [Transform<TransformDefinitions.TextTransformProps>] : K extends "text:init" ? [Scene?] : K extends "text:applyTransition" ? [ITransition] : K extends "text:setFontSize" ? [number] : any;
112
+ [K in typeof TextActionTypes[keyof typeof TextActionTypes]]: K extends "text:setText" ? [string] : K extends "text:show" ? [Transform<TransformDefinitions.TextTransformProps>] : K extends "text:hide" ? [Transform<TransformDefinitions.TextTransformProps>] : K extends "text:applyTransform" ? [Transform<TransformDefinitions.TextTransformProps>] : K extends "text:init" ? [Scene?] : K extends "text:setFontSize" ? [number] : any;
114
113
  };
115
114
  export declare const PersistentActionTypes: {
116
115
  readonly action: "persistent:action";
@@ -4,5 +4,6 @@ import { TransformDefinitions } from "../elements/transform/type";
4
4
  import { IGamePluginRegistry } from "../game/plugin/plugin";
5
5
  import { LiveGameEventToken } from "../types";
6
6
  import { GameHistory } from "../action/gameHistory";
7
+ import { GameConfig } from "../gameTypes";
7
8
  export * from "../elements/type";
8
- export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions };
9
+ export type { GameHistory, IGamePluginRegistry, LiveGameEventToken, Origins, ServiceHandlerCtx, TransformDefinitions, GameConfig, };
@@ -1,12 +1,21 @@
1
- import type { EventToken } from "../../../../util/data";
2
1
  import { TransformDefinitions } from "../../elements/transform/type";
3
- /**@deprecated */
4
- export interface ITransition<T extends ElementProp = Record<string, any>> {
5
- start(onComplete?: () => void): void;
6
- toElementProps(): T[];
7
- copy(): ITransition<T>;
8
- complete(): void;
9
- }
2
+ import type { EventToken } from "../../../../util/data";
3
+ import type { DOMKeyframesDefinition } from "motion/react";
4
+ import React from "react";
5
+ export type ElementProp<T extends Element = Element, U extends React.HTMLAttributes<T> = React.HTMLAttributes<T>> = T extends HTMLImageElement ? React.JSX.IntrinsicAttributes & React.ClassAttributes<T> & React.ImgHTMLAttributes<T> & U : T extends HTMLAnchorElement ? React.JSX.IntrinsicAttributes & React.ClassAttributes<T> & React.AnchorHTMLAttributes<T> & U : T extends HTMLButtonElement ? React.JSX.IntrinsicAttributes & React.ClassAttributes<T> & React.ButtonHTMLAttributes<T> & U : React.JSX.IntrinsicAttributes & React.ClassAttributes<T> & React.HTMLAttributes<T> & U;
6
+ export type ImgElementProp = ElementProp<HTMLImageElement, React.ImgHTMLAttributes<HTMLImageElement>>;
7
+ export type SpanElementProp = ElementProp<HTMLSpanElement, React.HTMLAttributes<HTMLSpanElement>>;
8
+ export type DivElementProp = ElementProp<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>;
9
+ export type CSSElementProp<T extends React.CSSProperties | DOMKeyframesDefinition> = ElementProp & {
10
+ style: T;
11
+ };
12
+ export type CSSProps = React.CSSProperties;
13
+ export type EmptyObject = {};
14
+ export type EventTypes<T extends any[]> = {
15
+ "start": [null];
16
+ "update": T;
17
+ "end": [null];
18
+ };
10
19
  export declare enum TransitionAnimationType {
11
20
  Number = 0,
12
21
  HexColor = 1
@@ -1,4 +1,8 @@
1
1
  import { BooleanValueKeyOf, EventDispatcher } from "../../../util/data";
2
+ type PreferenceEventToken = {
3
+ cancel: () => void;
4
+ };
5
+ type StringKeyof<T> = Extract<keyof T, string>;
2
6
  export declare class Preference<T extends Record<string, string | boolean | number | null | undefined>> {
3
7
  private readonly settings;
4
8
  static EventTypes: {
@@ -25,3 +29,4 @@ export declare class Preference<T extends Record<string, string | boolean | numb
25
29
  exportPreferences(): Partial<T>;
26
30
  togglePreference<K extends BooleanValueKeyOf<T>>(key: K): void;
27
31
  }
32
+ export {};
@@ -8,9 +8,29 @@ declare enum GameSettingsNamespace {
8
8
  game = "game"
9
9
  }
10
10
  export type GamePreference = {
11
+ /**
12
+ * If true, the game will automatically forward to the next sentence when the player has finished the current sentence
13
+ * @default false
14
+ */
11
15
  autoForward: boolean;
16
+ /**
17
+ * If true, the game will allow the player to skip the dialog
18
+ * @default true
19
+ */
12
20
  skip: boolean;
21
+ /**
22
+ * If true, the game will show the dialog
23
+ * @default true
24
+ */
13
25
  showDialog: boolean;
26
+ /**
27
+ * The multiplier of the dialog speed
28
+ *
29
+ * Dialog speed will apply to:
30
+ * - The text speed
31
+ * - The auto-forward delay
32
+ */
33
+ gameSpeed: number;
14
34
  };
15
35
  export type GameHooks = {
16
36
  /**
@@ -174,6 +174,13 @@ export type GameConfig = {
174
174
  * @default 3000
175
175
  */
176
176
  autoForwardDelay: number;
177
+ /**
178
+ * The default pause duration in milliseconds when auto-forward is enabled
179
+ *
180
+ * When auto-forward is enabled, any Pause without a custom duration will use this value
181
+ * @default 1000
182
+ */
183
+ autoForwardDefaultPause: number;
177
184
  /**
178
185
  * If true, when you press [GameConfig.player.skipKey], the game will skip the image transform
179
186
  * @default true
@@ -285,6 +292,31 @@ export type GameConfig = {
285
292
  */
286
293
  guard: GuardConfig;
287
294
  };
295
+ /**
296
+ * Default font size for the game
297
+ * @default "16px"
298
+ */
299
+ fontSize: React.CSSProperties["fontSize"];
300
+ /**
301
+ * Default font weight for the game
302
+ * @default 400
303
+ */
304
+ fontWeight: number;
305
+ /**
306
+ * Default font weight for the game
307
+ * @default 700
308
+ */
309
+ fontWeightBold: number;
310
+ /**
311
+ * Default font family for the game
312
+ * @default "sans-serif"
313
+ */
314
+ fontFamily: React.CSSProperties["fontFamily"];
315
+ /**
316
+ * Override the default stage
317
+ * @default null
318
+ */
319
+ stage: React.ReactNode | null;
288
320
  };
289
321
  export type GameSettings = {
290
322
  volume: number;
@@ -2,5 +2,11 @@ import React from "react";
2
2
  export interface ItemProps {
3
3
  className?: string;
4
4
  style?: React.CSSProperties;
5
+ /**
6
+ * The keyboard binding for this item, see [Key_Values](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values) for more information
7
+ *
8
+ * When this key is pressed, the item will be selected and the action will be executed
9
+ */
10
+ bindKey?: string;
5
11
  }
6
- export default function Item({ className, style }: ItemProps): React.JSX.Element;
12
+ export default function Item({ className, style, bindKey }: ItemProps): React.JSX.Element;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Represents the context of a dialog, containing information about its completion status
3
+ * and the text content.
4
+ */
5
+ export type DialogContext = {
6
+ /** Whether the dialog has finished displaying */
7
+ done: boolean;
8
+ /** The text content of the dialog */
9
+ text: string;
10
+ };
11
+ /**
12
+ * A custom hook that provides access to the current dialog's state and content.
13
+ * It retrieves the dialog information from the sentence context and processes
14
+ * the words to generate the final text.
15
+ *
16
+ * @returns {DialogContext} An object containing the dialog's completion status and text content
17
+ */
18
+ export declare function useDialog(): {
19
+ done: boolean;
20
+ text: string;
21
+ };
@@ -5,7 +5,7 @@ type PageRouterProps = Readonly<{
5
5
  /**
6
6
  * Page Router for NarraLeaf-React
7
7
  *
8
- * **Note**: only `Page` components are allowed as children, other components will be ignored.
8
+ * **Note**: only `Page` and `Stage` components are allowed as children, other components will be ignored.
9
9
  *
10
10
  * @example
11
11
  * ```tsx
@@ -7,5 +7,6 @@ import Item from "./elements/menu/UIMenu/Item";
7
7
  import Notifications from "./elements/notification/Notifications";
8
8
  import Texts from "./elements/say/Sentence";
9
9
  import Nametag from "./elements/say/Nametag";
10
- import Dialog from "../../game/player/elements/say/Dialog";
11
- export { Isolated, usePreference, Stage, Page, GameMenu, Item, Notifications, Texts, Nametag, Dialog, };
10
+ import Dialog from "./elements/say/Dialog";
11
+ import { useDialog } from "./elements/say/useDialog";
12
+ export { Isolated, usePreference, Stage, Page, GameMenu, Item, Notifications, Texts, Nametag, Dialog, useDialog, };