narraleaf-react 0.0.1-beta.1 → 0.0.1-beta.10

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 (44) hide show
  1. package/README.md +123 -0
  2. package/dist/game/nlcore/action/action.d.ts +1 -1
  3. package/dist/game/nlcore/action/actionTypes.d.ts +4 -2
  4. package/dist/game/nlcore/action/actions.d.ts +3 -1
  5. package/dist/game/nlcore/common/player.d.ts +4 -1
  6. package/dist/game/nlcore/common/transition.d.ts +2 -1
  7. package/dist/game/nlcore/elements/image.d.ts +8 -9
  8. package/dist/game/nlcore/elements/scene.d.ts +1 -1
  9. package/dist/game/nlcore/elements/sound.d.ts +3 -1
  10. package/dist/game/nlcore/elements/text.d.ts +17 -5
  11. package/dist/game/nlcore/elements/transform/position.d.ts +22 -8
  12. package/dist/game/nlcore/elements/transform/transform.d.ts +11 -6
  13. package/dist/game/nlcore/elements/transition/base.d.ts +2 -1
  14. package/dist/game/nlcore/elements/transition/type.d.ts +2 -1
  15. package/dist/game/nlcore/game.d.ts +18 -0
  16. package/dist/game/nlcore/gameTypes.d.ts +124 -0
  17. package/dist/game/nlcore/store/storable.d.ts +3 -3
  18. package/dist/game/nlcore/types.d.ts +4 -5
  19. package/dist/game/player/elements/Player.d.ts +2 -10
  20. package/dist/game/player/elements/elements.d.ts +6 -0
  21. package/dist/game/player/elements/menu/Menu.d.ts +2 -7
  22. package/dist/game/player/elements/menu/Sentence.d.ts +2 -1
  23. package/dist/game/player/elements/menu/type.d.ts +9 -0
  24. package/dist/game/player/elements/player/KeyEventAnnouncer.d.ts +5 -0
  25. package/dist/game/player/elements/say/Say.d.ts +2 -9
  26. package/dist/game/player/elements/say/TypingEffect.d.ts +1 -0
  27. package/dist/game/player/elements/say/type.d.ts +15 -0
  28. package/dist/game/player/elements/scene/Background.d.ts +1 -1
  29. package/dist/game/player/elements/type.d.ts +37 -0
  30. package/dist/game/player/gameState.d.ts +7 -16
  31. package/dist/game/player/gameState.type.d.ts +15 -0
  32. package/dist/game/player/lib/{main.d.ts → AspectRatio.d.ts} +1 -1
  33. package/dist/game/player/lib/Motion.d.ts +4 -0
  34. package/dist/game/player/lib/isolated.d.ts +1 -2
  35. package/dist/game/player/libElements.d.ts +4 -0
  36. package/dist/game/player/provider/game-state.d.ts +4 -0
  37. package/dist/game/player/provider/providers.d.ts +3 -1
  38. package/dist/game/player/provider/ratio.d.ts +41 -17
  39. package/dist/game/player/type.d.ts +1 -0
  40. package/dist/{index.js → main.js} +8540 -3494
  41. package/dist/main.js.map +1 -0
  42. package/dist/util/data.d.ts +36 -2
  43. package/package.json +8 -6
  44. package/dist/index.js.map +0 -1
@@ -1,13 +1,5 @@
1
1
  import "client-only";
2
2
  import "@player/lib/styles/style.css";
3
- import clsx from "clsx";
4
3
  import React from "react";
5
- import { Story } from "../../nlcore/elements/story";
6
- import { Game } from "../../nlcore/game";
7
- export default function Player({ story, onReady, width, height, className, }: Readonly<{
8
- story: Story;
9
- onReady?: (game: Game) => void;
10
- width?: string | number;
11
- height?: string | number;
12
- className?: clsx.ClassValue;
13
- }>): React.JSX.Element;
4
+ import { PlayerProps } from "../elements/type";
5
+ export default function Player({ story, width, height, className, onReady, onEnd, }: Readonly<PlayerProps>): React.JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { default as StageSay } from "../elements/say/Say";
2
+ import { default as StageMenu } from "../elements/menu/Menu";
3
+ export declare const DefaultElements: {
4
+ readonly say: typeof StageSay;
5
+ readonly menu: typeof StageMenu;
6
+ };
@@ -1,8 +1,3 @@
1
1
  import React from "react";
2
- import { Choice } from "../../../nlcore/elements/menu";
3
- import { Sentence } from "../../../nlcore/elements/text";
4
- export default function Menu({ prompt, choices, afterChoose, }: Readonly<{
5
- prompt: Sentence;
6
- choices: Choice[];
7
- afterChoose: (choice: Choice) => void;
8
- }>): React.JSX.Element;
2
+ import { MenuElementProps } from "../../elements/menu/type";
3
+ export default function Menu({ prompt, choices, afterChoose, state, }: Readonly<MenuElementProps>): React.JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { Sentence } from "../../../nlcore/elements/text";
3
- export default function ColoredSentence({ sentence, }: Readonly<{
3
+ export default function ColoredSentence({ sentence, className, }: Readonly<{
4
4
  sentence: Sentence;
5
+ className?: string;
5
6
  }>): React.JSX.Element;
@@ -0,0 +1,9 @@
1
+ import type { Sentence } from "../../../nlcore/elements/text";
2
+ import type { Choice } from "../../../nlcore/elements/menu";
3
+ import type { GameState } from "../../gameState";
4
+ export interface MenuElementProps {
5
+ prompt: Sentence;
6
+ choices: Choice[];
7
+ afterChoose: (choice: Choice) => void;
8
+ state: GameState;
9
+ }
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ import { GameState } from "../../gameState";
3
+ export declare function KeyEventAnnouncer({ state }: Readonly<{
4
+ state: GameState;
5
+ }>): React.JSX.Element;
@@ -1,10 +1,3 @@
1
- import { Sentence } from "../../../nlcore/elements/text";
2
1
  import React from "react";
3
- export default function Say({ action, onClick, useTypeEffect, className, }: Readonly<{
4
- action: {
5
- sentence: Sentence;
6
- };
7
- onClick?: () => void;
8
- useTypeEffect?: boolean;
9
- className?: string;
10
- }>): React.JSX.Element;
2
+ import { SayElementProps } from "../../elements/say/type";
3
+ export default function Say({ action, onClick, useTypeEffect, className, state, }: Readonly<SayElementProps>): React.JSX.Element;
@@ -3,6 +3,7 @@ interface TypingEffectProps {
3
3
  text: string;
4
4
  speed: number;
5
5
  onComplete?: () => void;
6
+ className?: string;
6
7
  }
7
8
  declare const TypingEffect: React.FC<TypingEffectProps>;
8
9
  export default TypingEffect;
@@ -0,0 +1,15 @@
1
+ import type { Character, Sentence } from "../../../nlcore/elements/text";
2
+ import type { GameState } from "../../gameState";
3
+ export interface SayElementProps {
4
+ action: {
5
+ sentence: Sentence;
6
+ character: Character | null;
7
+ };
8
+ /**
9
+ * Callback function to be called when player triggers the next action
10
+ */
11
+ onClick?: () => void;
12
+ useTypeEffect?: boolean;
13
+ className?: string;
14
+ state: GameState;
15
+ }
@@ -1,5 +1,5 @@
1
- import React from "react";
2
1
  import type { ReactNode } from "react";
2
+ import React from "react";
3
3
  export default function Background({ children }: Readonly<{
4
4
  children: ReactNode;
5
5
  }>): React.JSX.Element;
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import { SayElementProps } from "../elements/say/type";
3
+ import { MenuElementProps } from "../elements/menu/type";
4
+ import { Story } from "../../nlcore/elements/story";
5
+ import clsx from "clsx";
6
+ import { Game } from "../../nlcore/game";
7
+ import { GameState } from "../gameState";
8
+ export type Components<T extends Record<string, any>> = (props: Readonly<T>) => React.JSX.Element;
9
+ export type SayComponent = Components<SayElementProps>;
10
+ export type MenuComponent = Components<MenuElementProps>;
11
+ export type ComponentsTypes = {
12
+ say: SayComponent;
13
+ menu: MenuComponent;
14
+ };
15
+ export type { SayElementProps, MenuElementProps, };
16
+ export type PlayerEventContext = {
17
+ game: Game;
18
+ state: GameState;
19
+ };
20
+ export interface PlayerProps {
21
+ story: Story;
22
+ width?: string | number;
23
+ height?: string | number;
24
+ className?: clsx.ClassValue;
25
+ /**
26
+ * Once the game is ready to be played
27
+ *
28
+ * only called once each lifecycle
29
+ */
30
+ onReady?: (ctx: PlayerEventContext) => void;
31
+ /**
32
+ * Once the game is ended
33
+ *
34
+ * only called once each lifecycle
35
+ */
36
+ onEnd?: (ctx: PlayerEventContext) => void;
37
+ }
@@ -1,6 +1,6 @@
1
- import { CalledActionResult } from "@core/gameTypes";
2
- import { EventDispatcher } from "../../util/data";
3
- import { Character, Sentence } from "../nlcore/elements/text";
1
+ import { CalledActionResult } from "../nlcore/gameTypes";
2
+ import { EventDispatcher, Logger } from "../../util/data";
3
+ import { Sentence } from "../nlcore/elements/text";
4
4
  import { Choice, MenuData } from "../nlcore/elements/menu";
5
5
  import { Image, ImageEventTypes } from "../nlcore/elements/image";
6
6
  import { Scene } from "../nlcore/elements/scene";
@@ -10,19 +10,7 @@ import { SrcManager } from "../nlcore/elements/srcManager";
10
10
  import { LogicAction } from "../nlcore/action/logicAction";
11
11
  import { Storable } from "../nlcore/store/storable";
12
12
  import { Game } from "../nlcore/game";
13
- type Clickable<T, U = undefined> = {
14
- action: T;
15
- onClick: U extends undefined ? () => void : (arg0: U) => void;
16
- };
17
- type TextElement = {
18
- character: Character | null;
19
- sentence: Sentence;
20
- id: string;
21
- };
22
- type MenuElement = {
23
- prompt: Sentence;
24
- choices: Choice[];
25
- };
13
+ import { Clickable, MenuElement, TextElement } from "./gameState.type";
26
14
  type PlayerStateElement = {
27
15
  texts: Clickable<TextElement>[];
28
16
  menus: Clickable<MenuElement, Choice>[];
@@ -52,6 +40,8 @@ interface StageUtils {
52
40
  }
53
41
  type GameStateEvents = {
54
42
  "event:state.ready": [];
43
+ "event:state.end": [];
44
+ "event:state.player.skip": [];
55
45
  };
56
46
  export declare class GameState {
57
47
  static EventTypes: {
@@ -62,6 +52,7 @@ export declare class GameState {
62
52
  stage: StageUtils;
63
53
  game: Game;
64
54
  readonly events: EventDispatcher<GameStateEvents>;
55
+ readonly logger: Logger;
65
56
  constructor(game: Game, stage: StageUtils);
66
57
  findElementByScene(scene: Scene): {
67
58
  scene: Scene;
@@ -0,0 +1,15 @@
1
+ import { Character, Sentence } from "../nlcore/elements/text";
2
+ import { Choice } from "../nlcore/elements/menu";
3
+ export type Clickable<T, U = undefined> = {
4
+ action: T;
5
+ onClick: U extends undefined ? () => void : (arg0: U) => void;
6
+ };
7
+ export type TextElement = {
8
+ character: Character | null;
9
+ sentence: Sentence;
10
+ id: string;
11
+ };
12
+ export type MenuElement = {
13
+ prompt: Sentence;
14
+ choices: Choice[];
15
+ };
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- export default function Main({ children, className }: {
2
+ export default function AspectRatio({ children, className }: {
3
3
  children: React.ReactNode;
4
4
  className?: string;
5
5
  }): React.JSX.Element;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ export default function Motion({ children }: Readonly<{
3
+ children: React.ReactNode;
4
+ }>): React.JSX.Element;
@@ -1,5 +1,4 @@
1
- import type { ReactNode } from "react";
2
- import React from "react";
1
+ import React, { ReactNode } from "react";
3
2
  export default function Isolated({ children, className }: Readonly<{
4
3
  children: ReactNode;
5
4
  className?: string;
@@ -0,0 +1,4 @@
1
+ import Isolated from "./lib/isolated";
2
+ import Say from "./elements/say/Say";
3
+ import ColoredSentence from "./elements/menu/Sentence";
4
+ export { Isolated, Say, ColoredSentence, };
@@ -8,5 +8,9 @@ export declare function GameProvider({ children, game }: {
8
8
  children?: ReactNode;
9
9
  game?: Game;
10
10
  }): React.JSX.Element;
11
+ /**
12
+ * use {@link Game} context
13
+ * @returns {GameContextType}
14
+ */
11
15
  export declare function useGame(): GameContextType;
12
16
  export {};
@@ -1,5 +1,7 @@
1
1
  import "client-only";
2
2
  import React from "react";
3
- export default function GameProviders({ children }: Readonly<{
3
+ import { Game } from "../../nlcore/game";
4
+ export default function GameProviders({ children, game }: Readonly<{
4
5
  children?: React.ReactNode;
6
+ game?: Game;
5
7
  }>): React.JSX.Element;
@@ -1,23 +1,47 @@
1
1
  import React from "react";
2
- type Ratio = {
3
- w: number;
4
- h: number;
5
- updateStyle: () => void;
6
- style: React.CSSProperties;
7
- s: {
8
- style: React.CSSProperties;
9
- };
10
- min: {
11
- w: number;
12
- h: number;
13
- };
2
+ import { EventDispatcher } from "../../../util/data";
3
+ export type AspectRatioState = {
4
+ width: number;
5
+ height: number;
6
+ minWidth: number;
7
+ minHeight: number;
8
+ paused: boolean;
14
9
  };
15
- type ThemeContextType = {
16
- ratio: Ratio;
17
- setRatio: (ratio: Ratio) => void;
10
+ type AspectRatioEvents = {
11
+ "event:aspectRatio.update": [width: number, height: number];
12
+ "event:aspectRatio.pause": [];
13
+ "event:aspectRatio.resume": [];
18
14
  };
19
- export declare function AspectRatioProvider({ children }: {
15
+ declare class AspectRatio {
16
+ static EventTypes: {
17
+ [K in keyof AspectRatioEvents]: K;
18
+ };
19
+ state: AspectRatioState;
20
+ readonly events: EventDispatcher<AspectRatioEvents, AspectRatioEvents & {
21
+ "event:EventDispatcher.register": [string | number, import("../../../util/data").EventListener<any>];
22
+ }>;
23
+ private lockers;
24
+ private updater;
25
+ constructor();
26
+ update(width: number, height: number): void;
27
+ updateMin(width: number, height: number): void;
28
+ lock(): symbol;
29
+ unlock(locker: symbol | null | undefined): null;
30
+ isLocked(): boolean;
31
+ getStyle(): {
32
+ width: string;
33
+ height: string;
34
+ };
35
+ setUpdate(updater: () => void): void;
36
+ pause(): void;
37
+ resume(): void;
38
+ onUpdate(callback: (width: number, height: number) => void): () => void;
39
+ private triggerUpdate;
40
+ }
41
+ export declare function RatioProvider({ children }: {
20
42
  children: React.ReactNode;
21
43
  }): React.JSX.Element;
22
- export declare function useAspectRatio(): ThemeContextType;
44
+ export declare function useRatio(): {
45
+ ratio: AspectRatio;
46
+ };
23
47
  export {};
@@ -0,0 +1 @@
1
+ export * from "./elements/type";