narraleaf-react 0.7.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.
- package/dist/game/nlcore/common/core.d.ts +1 -0
- package/dist/game/nlcore/common/interface.d.ts +1 -0
- package/dist/game/nlcore/common/player.d.ts +0 -1
- package/dist/game/nlcore/elements/built-in/Gallery.d.ts +151 -0
- package/dist/game/nlcore/elements/built-in/built-in.d.ts +1 -0
- package/dist/game/nlcore/elements/displayable/displayable.d.ts +26 -6
- package/dist/game/nlcore/elements/service.d.ts +0 -4
- package/dist/game/nlcore/elements/transform/transform.d.ts +19 -10
- package/dist/game/nlcore/game/liveGame.d.ts +2 -0
- package/dist/game/nlcore/types.d.ts +15 -5
- package/dist/game/player/libElements.d.ts +2 -1
- package/dist/main.js +35 -35
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Gallery } from "../elements/built-in/Gallery";
|
|
@@ -6,4 +6,3 @@ import { usePathname, useParams, useQueryParams } from "../../player/lib/PageRou
|
|
|
6
6
|
export * from "../../player/type";
|
|
7
7
|
export * from "../../player/libElements";
|
|
8
8
|
export { GameProviders, Player, useGame, useRouter, usePathname, useParams, useQueryParams, };
|
|
9
|
-
export { PresenceContext } from "motion/react";
|
|
@@ -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
|
|
19
|
-
* @param
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
90
|
-
* @param
|
|
91
|
-
|
|
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(
|
|
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.
|
|
@@ -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
|
/**
|
|
@@ -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;
|
|
@@ -12,4 +12,5 @@ import { Page, PageInjectContext } from "./lib/PageRouter/Page";
|
|
|
12
12
|
import { Layout, LayoutRouterProvider } from "./lib/PageRouter/Layout";
|
|
13
13
|
import { RootPath } from "./lib/PageRouter/router";
|
|
14
14
|
import { useKeyBinding } from "./lib/keyMap";
|
|
15
|
-
|
|
15
|
+
import { useLiveGame } from "./lib/useLiveGame";
|
|
16
|
+
export { Isolated, usePreference, Stage, GameMenu, Item, Notifications, Texts, Nametag, Dialog, useDialog, Page, Layout, LayoutRouterProvider, PageInjectContext, RootPath, useKeyBinding, useLiveGame, };
|