@momoyu-ink/kit 0.8.2 → 0.9.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.
@@ -266,6 +266,24 @@ type ScenarioCommand = {
266
266
  pattern?: string;
267
267
  };
268
268
 
269
+ type RetainMode = 'static' | 'live';
270
+
271
+ type ShaderCommand = {
272
+ subCommand: 'prepare';
273
+ fromChannel: number;
274
+ toChannel: number;
275
+ mode?: RetainMode;
276
+ } | {
277
+ subCommand: 'perform';
278
+ duration: number;
279
+ } | {
280
+ subCommand: 'start';
281
+ } | {
282
+ subCommand: 'stop';
283
+ } | {
284
+ subCommand: 'reset';
285
+ };
286
+
269
287
  type ReadFormat = 'text' | 'binary';
270
288
 
271
289
  type WindowState = 'idle' | 'maximized' | 'minimized' | 'fullscreen';
@@ -325,7 +343,58 @@ type MakeNullOptional<T> = T extends any ? {
325
343
  [K in keyof T as null extends T[K] ? K : never]?: T[K];
326
344
  } : never;
327
345
 
328
- type _Command = AudioCommand | TextCommand | GamepadCommand | ScenarioCommand | SystemCommand;
346
+ type ShaderDirection = 'left' | 'right' | 'up' | 'down';
347
+
348
+ type ShaderParamType = 'float' | 'int';
349
+
350
+ type ShaderParam = {
351
+ name: string;
352
+ type: ShaderParamType;
353
+ value: number;
354
+ };
355
+
356
+ type ShaderSource = ({
357
+ type: 'builtin';
358
+ } & ({
359
+ name: 'crossfade';
360
+ } | {
361
+ name: 'wipe';
362
+ softness: number;
363
+ direction: ShaderDirection;
364
+ } | {
365
+ name: 'fade';
366
+ out: number;
367
+ hold: number;
368
+ in: number;
369
+ color: string;
370
+ } | {
371
+ name: 'push';
372
+ direction: ShaderDirection;
373
+ } | {
374
+ name: 'slideaway';
375
+ direction: ShaderDirection;
376
+ } | {
377
+ name: 'zoom';
378
+ startScale: number;
379
+ endScale: number;
380
+ origin: [number, number];
381
+ } | {
382
+ name: 'pixellate';
383
+ steps: number;
384
+ } | {
385
+ name: 'mask';
386
+ rule: string;
387
+ softness: number;
388
+ reverse: boolean;
389
+ })) | {
390
+ type: 'raw';
391
+ content: string;
392
+ params?: Array<ShaderParam>;
393
+ };
394
+
395
+ type ShaderTimeControl = 'auto' | 'manual' | 'transition';
396
+
397
+ type _Command = AudioCommand | TextCommand | GamepadCommand | ScenarioCommand | ShaderCommand | SystemCommand;
329
398
  type Command = MakeNullOptional<_Command>;
330
399
  type MaybePromise = any;
331
400
 
@@ -564,6 +633,23 @@ type TextProps = {
564
633
  shadowWidth?: number;
565
634
  };
566
635
 
636
+ type ShaderProps = {
637
+ shader?: ShaderSource;
638
+ timeControl?: ShaderTimeControl;
639
+ displayChannel?: number | null;
640
+ };
641
+
642
+ type ShaderSlotSpace = 'normal' | 'shader';
643
+
644
+ type ShaderSlotProps = {
645
+ channel?: number;
646
+ empty?: boolean;
647
+ static?: boolean;
648
+ space?: ShaderSlotSpace;
649
+ width?: number;
650
+ height?: number;
651
+ };
652
+
567
653
  type AnimationFormat = 'apng' | 'webp';
568
654
 
569
655
  type AnimationProps = {
@@ -608,6 +694,10 @@ type MoyuClipAttributes = ClipProps & MoyuNodeAttributes;
608
694
  type MoyuFilterAttributes = FilterProps & MoyuNodeAttributes;
609
695
  type MoyuBackdropAttributes = BackdropProps & MoyuNodeAttributes;
610
696
  type MoyuAnimationAttributes = AnimationProps & MoyuNodeAttributes;
697
+ type MoyuShaderAttributes = ShaderProps & MoyuNodeAttributes & {
698
+ onFinished?: () => void;
699
+ };
700
+ type MoyuShaderSlotAttributes = ShaderSlotProps & MoyuNodeAttributes;
611
701
  type MoyuVideoAttributes = VideoProps & MoyuNodeAttributes & {
612
702
  onEnded?: () => void;
613
703
  onStateChange?: (state: string) => void;
@@ -643,8 +733,10 @@ declare namespace JSX {
643
733
  filter: DetailedMoyuProps<MoyuFilterAttributes>;
644
734
  backdrop: DetailedMoyuProps<MoyuBackdropAttributes>;
645
735
  animation: DetailedMoyuProps<MoyuAnimationAttributes>;
736
+ shader: DetailedMoyuProps<MoyuShaderAttributes>;
737
+ 'shader-slot': DetailedMoyuProps<MoyuShaderSlotAttributes>;
646
738
  video: DetailedMoyuProps<MoyuVideoAttributes>;
647
739
  }
648
740
  }
649
741
 
650
- export { type AudioCommand as A, type BubbleEvent as B, type Command as C, type DetailedMoyuProps as D, type EffectParams as E, type GamepadCommand as G, JSX as J, type KeyboardEvent as K, type MouseEvent as M, Node as N, type ScenarioCommand as S, type TextCommand as T, type WindowState as W, type MoyuEvent as a, type MaybePromise as b, type JsonValue as c, type AudioSettings as d, type KeyboardEventKind as e, type MakeNullOptional as f, type MouseEventKind as g, type MoyuAnimationAttributes as h, type MoyuBackdropAttributes as i, type MoyuClipAttributes as j, type MoyuContainerAttributes as k, type MoyuEventHandler as l, type MoyuFilterAttributes as m, type MoyuListenerAttributes as n, type MoyuNodeAttributes as o, type MoyuSpriteAttributes as p, type MoyuTextAttributes as q, type MoyuVideoAttributes as r, type SystemCommand as s, type TouchEvent as t, type TouchEventKind as u, type Tuple2 as v, type Tuple3 as w, type Tuple4 as x, createBubbleEvent as y, getStageSize as z };
742
+ export { type AudioCommand as A, type BubbleEvent as B, type Command as C, type DetailedMoyuProps as D, type EffectParams as E, type SystemCommand as F, type GamepadCommand as G, type TouchEvent as H, type TouchEventKind as I, JSX as J, type KeyboardEvent as K, type Tuple2 as L, type MouseEvent as M, Node as N, type Tuple3 as O, type Tuple4 as P, createBubbleEvent as Q, type RetainMode as R, type ShaderDirection as S, type TextCommand as T, getStageSize as U, type WindowState as W, type MoyuEvent as a, type MaybePromise as b, type JsonValue as c, type AudioSettings as d, type KeyboardEventKind as e, type MakeNullOptional as f, type MouseEventKind as g, type MoyuAnimationAttributes as h, type MoyuBackdropAttributes as i, type MoyuClipAttributes as j, type MoyuContainerAttributes as k, type MoyuEventHandler as l, type MoyuFilterAttributes as m, type MoyuListenerAttributes as n, type MoyuNodeAttributes as o, type MoyuShaderAttributes as p, type MoyuShaderSlotAttributes as q, type MoyuSpriteAttributes as r, type MoyuTextAttributes as s, type MoyuVideoAttributes as t, type ScenarioCommand as u, type ShaderCommand as v, type ShaderParam as w, type ShaderParamType as x, type ShaderSource as y, type ShaderTimeControl as z };
@@ -266,6 +266,24 @@ type ScenarioCommand = {
266
266
  pattern?: string;
267
267
  };
268
268
 
269
+ type RetainMode = 'static' | 'live';
270
+
271
+ type ShaderCommand = {
272
+ subCommand: 'prepare';
273
+ fromChannel: number;
274
+ toChannel: number;
275
+ mode?: RetainMode;
276
+ } | {
277
+ subCommand: 'perform';
278
+ duration: number;
279
+ } | {
280
+ subCommand: 'start';
281
+ } | {
282
+ subCommand: 'stop';
283
+ } | {
284
+ subCommand: 'reset';
285
+ };
286
+
269
287
  type ReadFormat = 'text' | 'binary';
270
288
 
271
289
  type WindowState = 'idle' | 'maximized' | 'minimized' | 'fullscreen';
@@ -325,7 +343,58 @@ type MakeNullOptional<T> = T extends any ? {
325
343
  [K in keyof T as null extends T[K] ? K : never]?: T[K];
326
344
  } : never;
327
345
 
328
- type _Command = AudioCommand | TextCommand | GamepadCommand | ScenarioCommand | SystemCommand;
346
+ type ShaderDirection = 'left' | 'right' | 'up' | 'down';
347
+
348
+ type ShaderParamType = 'float' | 'int';
349
+
350
+ type ShaderParam = {
351
+ name: string;
352
+ type: ShaderParamType;
353
+ value: number;
354
+ };
355
+
356
+ type ShaderSource = ({
357
+ type: 'builtin';
358
+ } & ({
359
+ name: 'crossfade';
360
+ } | {
361
+ name: 'wipe';
362
+ softness: number;
363
+ direction: ShaderDirection;
364
+ } | {
365
+ name: 'fade';
366
+ out: number;
367
+ hold: number;
368
+ in: number;
369
+ color: string;
370
+ } | {
371
+ name: 'push';
372
+ direction: ShaderDirection;
373
+ } | {
374
+ name: 'slideaway';
375
+ direction: ShaderDirection;
376
+ } | {
377
+ name: 'zoom';
378
+ startScale: number;
379
+ endScale: number;
380
+ origin: [number, number];
381
+ } | {
382
+ name: 'pixellate';
383
+ steps: number;
384
+ } | {
385
+ name: 'mask';
386
+ rule: string;
387
+ softness: number;
388
+ reverse: boolean;
389
+ })) | {
390
+ type: 'raw';
391
+ content: string;
392
+ params?: Array<ShaderParam>;
393
+ };
394
+
395
+ type ShaderTimeControl = 'auto' | 'manual' | 'transition';
396
+
397
+ type _Command = AudioCommand | TextCommand | GamepadCommand | ScenarioCommand | ShaderCommand | SystemCommand;
329
398
  type Command = MakeNullOptional<_Command>;
330
399
  type MaybePromise = any;
331
400
 
@@ -564,6 +633,23 @@ type TextProps = {
564
633
  shadowWidth?: number;
565
634
  };
566
635
 
636
+ type ShaderProps = {
637
+ shader?: ShaderSource;
638
+ timeControl?: ShaderTimeControl;
639
+ displayChannel?: number | null;
640
+ };
641
+
642
+ type ShaderSlotSpace = 'normal' | 'shader';
643
+
644
+ type ShaderSlotProps = {
645
+ channel?: number;
646
+ empty?: boolean;
647
+ static?: boolean;
648
+ space?: ShaderSlotSpace;
649
+ width?: number;
650
+ height?: number;
651
+ };
652
+
567
653
  type AnimationFormat = 'apng' | 'webp';
568
654
 
569
655
  type AnimationProps = {
@@ -608,6 +694,10 @@ type MoyuClipAttributes = ClipProps & MoyuNodeAttributes;
608
694
  type MoyuFilterAttributes = FilterProps & MoyuNodeAttributes;
609
695
  type MoyuBackdropAttributes = BackdropProps & MoyuNodeAttributes;
610
696
  type MoyuAnimationAttributes = AnimationProps & MoyuNodeAttributes;
697
+ type MoyuShaderAttributes = ShaderProps & MoyuNodeAttributes & {
698
+ onFinished?: () => void;
699
+ };
700
+ type MoyuShaderSlotAttributes = ShaderSlotProps & MoyuNodeAttributes;
611
701
  type MoyuVideoAttributes = VideoProps & MoyuNodeAttributes & {
612
702
  onEnded?: () => void;
613
703
  onStateChange?: (state: string) => void;
@@ -643,8 +733,10 @@ declare namespace JSX {
643
733
  filter: DetailedMoyuProps<MoyuFilterAttributes>;
644
734
  backdrop: DetailedMoyuProps<MoyuBackdropAttributes>;
645
735
  animation: DetailedMoyuProps<MoyuAnimationAttributes>;
736
+ shader: DetailedMoyuProps<MoyuShaderAttributes>;
737
+ 'shader-slot': DetailedMoyuProps<MoyuShaderSlotAttributes>;
646
738
  video: DetailedMoyuProps<MoyuVideoAttributes>;
647
739
  }
648
740
  }
649
741
 
650
- export { type AudioCommand as A, type BubbleEvent as B, type Command as C, type DetailedMoyuProps as D, type EffectParams as E, type GamepadCommand as G, JSX as J, type KeyboardEvent as K, type MouseEvent as M, Node as N, type ScenarioCommand as S, type TextCommand as T, type WindowState as W, type MoyuEvent as a, type MaybePromise as b, type JsonValue as c, type AudioSettings as d, type KeyboardEventKind as e, type MakeNullOptional as f, type MouseEventKind as g, type MoyuAnimationAttributes as h, type MoyuBackdropAttributes as i, type MoyuClipAttributes as j, type MoyuContainerAttributes as k, type MoyuEventHandler as l, type MoyuFilterAttributes as m, type MoyuListenerAttributes as n, type MoyuNodeAttributes as o, type MoyuSpriteAttributes as p, type MoyuTextAttributes as q, type MoyuVideoAttributes as r, type SystemCommand as s, type TouchEvent as t, type TouchEventKind as u, type Tuple2 as v, type Tuple3 as w, type Tuple4 as x, createBubbleEvent as y, getStageSize as z };
742
+ export { type AudioCommand as A, type BubbleEvent as B, type Command as C, type DetailedMoyuProps as D, type EffectParams as E, type SystemCommand as F, type GamepadCommand as G, type TouchEvent as H, type TouchEventKind as I, JSX as J, type KeyboardEvent as K, type Tuple2 as L, type MouseEvent as M, Node as N, type Tuple3 as O, type Tuple4 as P, createBubbleEvent as Q, type RetainMode as R, type ShaderDirection as S, type TextCommand as T, getStageSize as U, type WindowState as W, type MoyuEvent as a, type MaybePromise as b, type JsonValue as c, type AudioSettings as d, type KeyboardEventKind as e, type MakeNullOptional as f, type MouseEventKind as g, type MoyuAnimationAttributes as h, type MoyuBackdropAttributes as i, type MoyuClipAttributes as j, type MoyuContainerAttributes as k, type MoyuEventHandler as l, type MoyuFilterAttributes as m, type MoyuListenerAttributes as n, type MoyuNodeAttributes as o, type MoyuShaderAttributes as p, type MoyuShaderSlotAttributes as q, type MoyuSpriteAttributes as r, type MoyuTextAttributes as s, type MoyuVideoAttributes as t, type ScenarioCommand as u, type ShaderCommand as v, type ShaderParam as w, type ShaderParamType as x, type ShaderSource as y, type ShaderTimeControl as z };
@@ -1,4 +1,4 @@
1
1
  export { Fragment, jsxDEV } from 'react/jsx-dev-runtime';
2
- export { J as JSX } from './jsx-dev-runtime-BCxm528Z.mjs';
2
+ export { J as JSX } from './jsx-dev-runtime-De053cfK.mjs';
3
3
  import 'react/jsx-runtime';
4
4
  import 'react';
@@ -1,4 +1,4 @@
1
1
  export { Fragment, jsxDEV } from 'react/jsx-dev-runtime';
2
- export { J as JSX } from './jsx-dev-runtime-BCxm528Z.js';
2
+ export { J as JSX } from './jsx-dev-runtime-De053cfK.js';
3
3
  import 'react/jsx-runtime';
4
4
  import 'react';
@@ -1,4 +1,4 @@
1
1
  export { Fragment, jsx, jsxs } from 'react/jsx-runtime';
2
- export { J as JSX } from './jsx-dev-runtime-BCxm528Z.mjs';
2
+ export { J as JSX } from './jsx-dev-runtime-De053cfK.mjs';
3
3
  import 'react/jsx-dev-runtime';
4
4
  import 'react';
@@ -1,4 +1,4 @@
1
1
  export { Fragment, jsx, jsxs } from 'react/jsx-runtime';
2
- export { J as JSX } from './jsx-dev-runtime-BCxm528Z.js';
2
+ export { J as JSX } from './jsx-dev-runtime-De053cfK.js';
3
3
  import 'react/jsx-dev-runtime';
4
4
  import 'react';
package/dist/lib.cjs CHANGED
@@ -40,6 +40,7 @@ __export(lib_exports, {
40
40
  animated: () => animated,
41
41
  autoState: () => autoState,
42
42
  createBubbleEvent: () => createBubbleEvent,
43
+ createGameStateContext: () => createGameStateContext,
43
44
  createRoot: () => createRoot,
44
45
  createStackNavigator: () => createStackNavigator,
45
46
  createStage: () => createStage,
@@ -751,7 +752,7 @@ var globalVariables = new Proxy(
751
752
  }
752
753
  );
753
754
  function safeEval(code, sandbox) {
754
- const proxy5 = new Proxy(sandbox, {
755
+ const proxy6 = new Proxy(sandbox, {
755
756
  has(target, key) {
756
757
  if (typeof key === "string" && JS_GLOBAL_KEYS.has(key)) {
757
758
  return false;
@@ -759,7 +760,7 @@ function safeEval(code, sandbox) {
759
760
  return key in target || key === "LOCAL" || key === "ARCHIVE" || key === "GLOBAL" || key === "window" || key === "globalThis";
760
761
  },
761
762
  get(target, key) {
762
- if (key === "window" || key === "globalThis") return proxy5;
763
+ if (key === "window" || key === "globalThis") return proxy6;
763
764
  if (key === "LOCAL") return localVariables;
764
765
  if (key === "ARCHIVE") return archiveVariables;
765
766
  if (key === "GLOBAL") return globalVariables;
@@ -771,7 +772,7 @@ function safeEval(code, sandbox) {
771
772
  return true;
772
773
  }
773
774
  });
774
- return new Function("sandbox", `with(sandbox) { return (${code}) }`).bind(proxy5)(proxy5);
775
+ return new Function("sandbox", `with(sandbox) { return (${code}) }`).bind(proxy6)(proxy6);
775
776
  }
776
777
  globalThis.__moyu_eval_sandbox = (code) => {
777
778
  try {
@@ -952,12 +953,85 @@ function getStageSize() {
952
953
  return stageSize;
953
954
  }
954
955
 
955
- // src/components/navigation.tsx
956
+ // src/gameState.ts
956
957
  var import_react2 = require("react");
957
958
  var import_valtio = require("valtio");
959
+ function cloneStateValue(value) {
960
+ return JSON.parse(JSON.stringify(value));
961
+ }
962
+ function isPlainObject(value) {
963
+ return typeof value === "object" && value !== null && !Array.isArray(value);
964
+ }
965
+ function syncStateValue(target, source) {
966
+ if (Array.isArray(source)) {
967
+ if (!Array.isArray(target)) {
968
+ return cloneStateValue(source);
969
+ }
970
+ target.length = source.length;
971
+ for (let index = 0; index < source.length; index += 1) {
972
+ target[index] = syncStateValue(target[index], source[index]);
973
+ }
974
+ return target;
975
+ }
976
+ if (isPlainObject(source)) {
977
+ if (!isPlainObject(target)) {
978
+ return cloneStateValue(source);
979
+ }
980
+ for (const key of Object.keys(target)) {
981
+ if (!Object.hasOwn(source, key)) {
982
+ delete target[key];
983
+ }
984
+ }
985
+ for (const [key, nextValue] of Object.entries(source)) {
986
+ target[key] = syncStateValue(target[key], nextValue);
987
+ }
988
+ return target;
989
+ }
990
+ return source;
991
+ }
992
+ function createGameStateContext(defaults) {
993
+ const defaultState = cloneStateValue(defaults);
994
+ const gameState = (0, import_valtio.proxy)(cloneStateValue(defaults));
995
+ function snapshotGameState() {
996
+ return (0, import_valtio.snapshot)(gameState);
997
+ }
998
+ function syncGameState(source) {
999
+ const target = gameState;
1000
+ for (const key of Object.keys(source)) {
1001
+ target[key] = syncStateValue(target[key], source[key]);
1002
+ }
1003
+ }
1004
+ function resetGameState() {
1005
+ syncGameState(defaultState);
1006
+ }
1007
+ const StoreContext = (0, import_react2.createContext)(gameState);
1008
+ function GameStateProvider({ store, children }) {
1009
+ return (0, import_react2.createElement)(StoreContext.Provider, { value: store }, children);
1010
+ }
1011
+ function useGameStateStore() {
1012
+ return (0, import_react2.useContext)(StoreContext);
1013
+ }
1014
+ function useGameStateSection(key) {
1015
+ const store = useGameStateStore();
1016
+ return (0, import_valtio.useSnapshot)(store)[key];
1017
+ }
1018
+ return {
1019
+ gameState,
1020
+ snapshotGameState,
1021
+ syncGameState,
1022
+ resetGameState,
1023
+ GameStateProvider,
1024
+ useGameStateStore,
1025
+ useGameStateSection
1026
+ };
1027
+ }
1028
+
1029
+ // src/components/navigation.tsx
1030
+ var import_react3 = require("react");
1031
+ var import_valtio2 = require("valtio");
958
1032
  var import_jsx_runtime = require("react/jsx-runtime");
959
- var PageParamsContext = (0, import_react2.createContext)(void 0);
960
- var OverlayParamsContext = (0, import_react2.createContext)(void 0);
1033
+ var PageParamsContext = (0, import_react3.createContext)(void 0);
1034
+ var OverlayParamsContext = (0, import_react3.createContext)(void 0);
961
1035
  var DEBUG_EMPTY_PAGE = "debug-empty";
962
1036
  var overlayIdCounter = 0;
963
1037
  var generateOverlayId = () => {
@@ -998,7 +1072,7 @@ function createStackNavigator(options) {
998
1072
  normalizedOverlays[key] = normalizeDescriptor(config);
999
1073
  }
1000
1074
  }
1001
- const navigationState = (0, import_valtio.proxy)({
1075
+ const navigationState = (0, import_valtio2.proxy)({
1002
1076
  currentPage: options.initialPage,
1003
1077
  pageParams: {},
1004
1078
  overlayStack: [],
@@ -1081,7 +1155,7 @@ function createStackNavigator(options) {
1081
1155
  }
1082
1156
  function createStaticNavigation(navigator) {
1083
1157
  return () => {
1084
- const navState = (0, import_valtio.useSnapshot)(navigator._state);
1158
+ const navState = (0, import_valtio2.useSnapshot)(navigator._state);
1085
1159
  const { pages, overlays } = navigator._descriptors;
1086
1160
  const pageDescriptor = pages[navState.currentPage];
1087
1161
  const Page = pageDescriptor?.component || (() => null);
@@ -1103,17 +1177,17 @@ function getNavigator() {
1103
1177
  }
1104
1178
  var useNavigation = getNavigator;
1105
1179
  function useNavigationState() {
1106
- return (0, import_valtio.useSnapshot)(getNavigator()._state);
1180
+ return (0, import_valtio2.useSnapshot)(getNavigator()._state);
1107
1181
  }
1108
1182
  function useNavigationParams() {
1109
- const overlayParams = (0, import_react2.useContext)(OverlayParamsContext);
1110
- const pageParams = (0, import_react2.useContext)(PageParamsContext);
1183
+ const overlayParams = (0, import_react3.useContext)(OverlayParamsContext);
1184
+ const pageParams = (0, import_react3.useContext)(PageParamsContext);
1111
1185
  return overlayParams ?? pageParams ?? {};
1112
1186
  }
1113
1187
 
1114
1188
  // src/debug/session.ts
1115
- var import_valtio2 = require("valtio");
1116
- var debugState = (0, import_valtio2.proxy)({
1189
+ var import_valtio3 = require("valtio");
1190
+ var debugState = (0, import_valtio3.proxy)({
1117
1191
  active: false,
1118
1192
  checkpoints: {},
1119
1193
  currentCursor: null,
@@ -1628,9 +1702,9 @@ async function stopDebugSession() {
1628
1702
  clearLocalRuntimeState();
1629
1703
  }
1630
1704
  function useDebugSession() {
1631
- const snapshot = (0, import_valtio2.useSnapshot)(debugState);
1705
+ const snapshot2 = (0, import_valtio3.useSnapshot)(debugState);
1632
1706
  return {
1633
- ...snapshot,
1707
+ ...snapshot2,
1634
1708
  startDebugSession,
1635
1709
  stopDebugSession,
1636
1710
  restoreCheckpoint: debugSessionController.restoreCheckpoint,
@@ -1641,11 +1715,11 @@ function useDebugSession() {
1641
1715
  }
1642
1716
 
1643
1717
  // src/ui.ts
1644
- var import_valtio3 = require("valtio");
1718
+ var import_valtio4 = require("valtio");
1645
1719
  var UI_DATA_ASSET_PATH = "assets:///data/ui.json";
1646
1720
  var activeUiSchema = null;
1647
- var uiDataState = (0, import_valtio3.proxy)({});
1648
- var uiRuntimeState = (0, import_valtio3.proxy)({
1721
+ var uiDataState = (0, import_valtio4.proxy)({});
1722
+ var uiRuntimeState = (0, import_valtio4.proxy)({
1649
1723
  initialized: false,
1650
1724
  error: null
1651
1725
  });
@@ -1706,11 +1780,11 @@ function useUiData(name) {
1706
1780
  if (!uiRuntimeState.initialized) {
1707
1781
  throw new Error("UI data has not been initialized. Call initUiData() before rendering UI pages.");
1708
1782
  }
1709
- const snapshot = (0, import_valtio3.useSnapshot)(uiDataState);
1710
- if (!(name in snapshot)) {
1783
+ const snapshot2 = (0, import_valtio4.useSnapshot)(uiDataState);
1784
+ if (!(name in snapshot2)) {
1711
1785
  throw new Error(`UI data "${name}" is not available.`);
1712
1786
  }
1713
- return snapshot[name];
1787
+ return snapshot2[name];
1714
1788
  }
1715
1789
 
1716
1790
  // src/debug/runtime.ts
@@ -2065,7 +2139,7 @@ function useFadeOut(outTime, pause = false, onFinished) {
2065
2139
  }
2066
2140
 
2067
2141
  // src/hooks/useScenario.ts
2068
- var import_react3 = require("react");
2142
+ var import_react4 = require("react");
2069
2143
  var currentScenarioSession = null;
2070
2144
  var scenarioSessionId = 0;
2071
2145
  var scenarioLifecycleQueue = Promise.resolve();
@@ -2207,7 +2281,7 @@ function setWaiting(time, skippable) {
2207
2281
  executePluginCommand("scenario", { subCommand: "setWaiting", time, skippable });
2208
2282
  }
2209
2283
  function useScenario(stories, startName, entryName, goNextOnLoad = false) {
2210
- (0, import_react3.useEffect)(() => {
2284
+ (0, import_react4.useEffect)(() => {
2211
2285
  const session = acquireScenarioSession({
2212
2286
  stories: normalizeStories(stories),
2213
2287
  startName,
@@ -2221,9 +2295,9 @@ function useScenario(stories, startName, entryName, goNextOnLoad = false) {
2221
2295
  }
2222
2296
 
2223
2297
  // src/hooks/useSoundEffect.ts
2224
- var import_react4 = require("react");
2298
+ var import_react5 = require("react");
2225
2299
  function useSoundEffect(src) {
2226
- (0, import_react4.useEffect)(() => {
2300
+ (0, import_react5.useEffect)(() => {
2227
2301
  return () => {
2228
2302
  try {
2229
2303
  if (src) {
@@ -2238,7 +2312,7 @@ function useSoundEffect(src) {
2238
2312
  }
2239
2313
  };
2240
2314
  }, [src]);
2241
- return (0, import_react4.useCallback)(() => {
2315
+ return (0, import_react5.useCallback)(() => {
2242
2316
  try {
2243
2317
  if (src) {
2244
2318
  executePluginCommand("audio", {
@@ -2254,26 +2328,26 @@ function useSoundEffect(src) {
2254
2328
  }
2255
2329
 
2256
2330
  // src/hooks/useStage.ts
2257
- var import_react5 = require("react");
2258
- var import_valtio4 = require("valtio");
2331
+ var import_react6 = require("react");
2332
+ var import_valtio5 = require("valtio");
2259
2333
  var SKIP_INTERVAL_MS = 80;
2260
2334
  var DEFAULT_FAST_FORWARD_STEP_LIMIT = 1e4;
2261
2335
  var DEFAULT_FAST_FORWARD_TIME_LIMIT_MS = 3e3;
2262
2336
  var autoRuntime = {
2263
2337
  defaultTailMs: 0
2264
2338
  };
2265
- var skipState = (0, import_valtio4.proxy)({ active: false });
2266
- var autoState = (0, import_valtio4.proxy)({ active: false });
2267
- var fastForwardState = (0, import_valtio4.proxy)({ active: false });
2268
- var warpState = (0, import_valtio4.proxy)({ active: false });
2339
+ var skipState = (0, import_valtio5.proxy)({ active: false });
2340
+ var autoState = (0, import_valtio5.proxy)({ active: false });
2341
+ var fastForwardState = (0, import_valtio5.proxy)({ active: false });
2342
+ var warpState = (0, import_valtio5.proxy)({ active: false });
2269
2343
  function useIsSkipping() {
2270
- return (0, import_valtio4.useSnapshot)(skipState).active;
2344
+ return (0, import_valtio5.useSnapshot)(skipState).active;
2271
2345
  }
2272
2346
  function useIsAutoing() {
2273
- return (0, import_valtio4.useSnapshot)(autoState).active;
2347
+ return (0, import_valtio5.useSnapshot)(autoState).active;
2274
2348
  }
2275
2349
  function useIsSeeking() {
2276
- return (0, import_valtio4.useSnapshot)(fastForwardState).active;
2350
+ return (0, import_valtio5.useSnapshot)(fastForwardState).active;
2277
2351
  }
2278
2352
  function getSeekingType() {
2279
2353
  if (warpState.active) return "warp";
@@ -2924,45 +2998,45 @@ function createStage() {
2924
2998
  bindEvents
2925
2999
  };
2926
3000
  }
2927
- var StageContext = (0, import_react5.createContext)(null);
3001
+ var StageContext = (0, import_react6.createContext)(null);
2928
3002
  function useStageContext() {
2929
- const ctx = (0, import_react5.useContext)(StageContext);
3003
+ const ctx = (0, import_react6.useContext)(StageContext);
2930
3004
  if (!ctx) throw new Error("useStageContext must be used within StageContextProvider");
2931
3005
  return ctx;
2932
3006
  }
2933
3007
  function StageContextProvider({ stage, children }) {
2934
- (0, import_react5.useEffect)(() => {
3008
+ (0, import_react6.useEffect)(() => {
2935
3009
  return stage.bindEvents();
2936
3010
  }, [stage]);
2937
- return (0, import_react5.createElement)(StageContext.Provider, { value: stage }, children);
3011
+ return (0, import_react6.createElement)(StageContext.Provider, { value: stage }, children);
2938
3012
  }
2939
3013
  function useSkipCallback(callback) {
2940
3014
  const stage = useStageContext();
2941
- (0, import_react5.useEffect)(() => {
3015
+ (0, import_react6.useEffect)(() => {
2942
3016
  return stage.addSkipCallback(callback);
2943
3017
  }, [stage, callback]);
2944
3018
  }
2945
3019
  function useInterruptCallback(callback) {
2946
3020
  const stage = useStageContext();
2947
- (0, import_react5.useEffect)(() => {
3021
+ (0, import_react6.useEffect)(() => {
2948
3022
  return stage.addInterruptCallback(callback);
2949
3023
  }, [stage, callback]);
2950
3024
  }
2951
3025
  function useSkipBlocker(callback) {
2952
3026
  const stage = useStageContext();
2953
- (0, import_react5.useEffect)(() => {
3027
+ (0, import_react6.useEffect)(() => {
2954
3028
  return stage.addSkipBlocker(callback);
2955
3029
  }, [stage, callback]);
2956
3030
  }
2957
3031
  function useAutoBlocker(callback) {
2958
3032
  const stage = useStageContext();
2959
- (0, import_react5.useEffect)(() => {
3033
+ (0, import_react6.useEffect)(() => {
2960
3034
  return stage.addAutoBlocker(callback);
2961
3035
  }, [stage, callback]);
2962
3036
  }
2963
3037
  function useAutoTicket() {
2964
3038
  const stage = useStageContext();
2965
- return (0, import_react5.useCallback)(
3039
+ return (0, import_react6.useCallback)(
2966
3040
  (options) => {
2967
3041
  return stage.issueAutoTicket(options);
2968
3042
  },
@@ -2971,7 +3045,7 @@ function useAutoTicket() {
2971
3045
  }
2972
3046
  function useBeforeHandleCommandCallback(callback) {
2973
3047
  const stage = useStageContext();
2974
- (0, import_react5.useEffect)(() => {
3048
+ (0, import_react6.useEffect)(() => {
2975
3049
  return stage.addBeforeHandleCommandCallback(callback);
2976
3050
  }, [stage, callback]);
2977
3051
  }
package/dist/lib.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ReactElement, Component, ForwardRefExoticComponent, CSSProperties, FC, ComponentType } from 'react';
3
- import { M as MouseEvent, a as MoyuEvent, C as Command, b as MaybePromise, J as JSX, c as JsonValue } from './jsx-dev-runtime-BCxm528Z.mjs';
4
- export { A as AudioCommand, d as AudioSettings, B as BubbleEvent, D as DetailedMoyuProps, E as EffectParams, G as GamepadCommand, K as KeyboardEvent, e as KeyboardEventKind, f as MakeNullOptional, g as MouseEventKind, h as MoyuAnimationAttributes, i as MoyuBackdropAttributes, j as MoyuClipAttributes, k as MoyuContainerAttributes, l as MoyuEventHandler, m as MoyuFilterAttributes, n as MoyuListenerAttributes, o as MoyuNodeAttributes, p as MoyuSpriteAttributes, q as MoyuTextAttributes, r as MoyuVideoAttributes, N as Node, S as ScenarioCommand, s as SystemCommand, T as TextCommand, t as TouchEvent, u as TouchEventKind, v as Tuple2, w as Tuple3, x as Tuple4, W as WindowState, y as createBubbleEvent, z as getStageSize } from './jsx-dev-runtime-BCxm528Z.mjs';
2
+ import { ReactElement, Component, ForwardRefExoticComponent, CSSProperties, FC, ReactNode, ComponentType } from 'react';
3
+ import { S as ShaderDirection, M as MouseEvent, a as MoyuEvent, C as Command, b as MaybePromise, J as JSX, c as JsonValue } from './jsx-dev-runtime-De053cfK.mjs';
4
+ export { A as AudioCommand, d as AudioSettings, B as BubbleEvent, D as DetailedMoyuProps, E as EffectParams, G as GamepadCommand, K as KeyboardEvent, e as KeyboardEventKind, f as MakeNullOptional, g as MouseEventKind, h as MoyuAnimationAttributes, i as MoyuBackdropAttributes, j as MoyuClipAttributes, k as MoyuContainerAttributes, l as MoyuEventHandler, m as MoyuFilterAttributes, n as MoyuListenerAttributes, o as MoyuNodeAttributes, p as MoyuShaderAttributes, q as MoyuShaderSlotAttributes, r as MoyuSpriteAttributes, s as MoyuTextAttributes, t as MoyuVideoAttributes, N as Node, R as RetainMode, u as ScenarioCommand, v as ShaderCommand, w as ShaderParam, x as ShaderParamType, y as ShaderSource, z as ShaderTimeControl, F as SystemCommand, T as TextCommand, H as TouchEvent, I as TouchEventKind, L as Tuple2, O as Tuple3, P as Tuple4, W as WindowState, Q as createBubbleEvent, U as getStageSize } from './jsx-dev-runtime-De053cfK.mjs';
5
5
  import { FluidValue } from '@react-spring/shared';
6
6
  import { ElementType, AssignableKeys, ComponentPropsWithRef } from '@react-spring/types';
7
7
  import { Snapshot } from 'valtio';
@@ -32,6 +32,41 @@ interface RootOptions {
32
32
  }
33
33
  declare function createRoot(options?: RootOptions): RootHandle;
34
34
 
35
+ type ShaderBuiltin = {
36
+ name: 'crossfade';
37
+ } | {
38
+ name: 'wipe';
39
+ softness: number;
40
+ direction: ShaderDirection;
41
+ } | {
42
+ name: 'fade';
43
+ out: number;
44
+ hold: number;
45
+ in: number;
46
+ color: string;
47
+ } | {
48
+ name: 'push';
49
+ direction: ShaderDirection;
50
+ } | {
51
+ name: 'slideaway';
52
+ direction: ShaderDirection;
53
+ } | {
54
+ name: 'zoom';
55
+ startScale: number;
56
+ endScale: number;
57
+ origin: [number, number];
58
+ } | {
59
+ name: 'pixellate';
60
+ steps: number;
61
+ } | {
62
+ name: 'mask';
63
+ rule: string;
64
+ softness: number;
65
+ reverse: boolean;
66
+ };
67
+
68
+ type ShaderBuiltinName = 'crossfade' | 'wipe' | 'fade' | 'push' | 'slideaway' | 'zoom' | 'pixellate' | 'mask';
69
+
35
70
  declare const globalEventListeners: Record<string, ((event: unknown) => void)[]>;
36
71
  declare const globalRequestAnimationFrameListeners: FrameRequestCallback[];
37
72
 
@@ -211,6 +246,8 @@ type ResolvedSystemCallLine = {
211
246
  arguments: Array<ResolvedArgument>;
212
247
  };
213
248
 
249
+ type ShaderEvent = null;
250
+
214
251
  type TextLine = {
215
252
  leading: string | null;
216
253
  text: string | null;
@@ -285,6 +322,21 @@ type AnimatedLeaf<T> = Exclude<T, object | undefined> | Extract<T, ReadonlyArray
285
322
 
286
323
  declare const animated: WithAnimated;
287
324
 
325
+ type GameStateStore<TState extends object> = TState;
326
+ interface GameStateSourceProps<TState extends object> {
327
+ store: GameStateStore<TState>;
328
+ children: ReactNode;
329
+ }
330
+ declare function createGameStateContext<TState extends object>(defaults: TState): {
331
+ gameState: TState;
332
+ snapshotGameState: () => TState;
333
+ syncGameState: (source: TState) => void;
334
+ resetGameState: () => void;
335
+ GameStateProvider: ({ store, children }: GameStateSourceProps<TState>) => react.FunctionComponentElement<react.ProviderProps<TState>>;
336
+ useGameStateStore: () => GameStateStore<TState>;
337
+ useGameStateSection: <K extends keyof TState>(key: K) => TState[K];
338
+ };
339
+
288
340
  declare global {
289
341
  /**
290
342
  * The **`console`** object provides access to the debugging console (e.g., the Web console in Firefox).
@@ -860,4 +912,4 @@ declare module 'zod' {
860
912
  }
861
913
  }
862
914
 
863
- export { type AnimatedComponent, type AnimatedProps, type AnimationFrameCallbackEvent, type AppStateAdapter, type AutoTicketHandle, type AutoTicketOptions, type BeforeUnloadEvent, type CombinedCheckpoint, Command, type CommandHandler, type CustomEvent, DEBUG_EMPTY_PAGE, type DebugSessionConfig, type DebugSessionController, type DebugWarpBoundary, type DebugWarpOptions, type DefaultOverlayName, type DefaultPageName, type FastForwardOptions, type FocusEvent, type FocusEventKind, type FullScreenEvent, type FullscreenEventKind, type GameControl, type GameEvent, type Gamepad, type GamepadButton, type GamepadEvent, type GamepadHapticActuator, JSX, type KeyboardLocation, type Literal, MaybePromise, MouseEvent, MoyuEvent, type NavigationState, type Navigator, type NodeEvent, type OverlayConfig, type OverlayDescriptor, type OverlayInfo, OverlayParamsContext, type PageConfig, type PageDescriptor, PageParamsContext, type RegisterNavigator, type ResizeEvent, type ResolvedArgument, type ResolvedCommandLine, type ResolvedSystemCallLine, type RootErrorInfo, type RootHandle, type RootNavigatorList, type RootOptions, type RootUiDataMap, type RootUncaughtErrorInfo, type ScenarioCommandBaseType, type ScenarioEvent, type StackNavigatorOptions, StageContextProvider, type StageInstance, type TextLine, type TextLineHandler, type WheelEvent, type WheelEventDeltaMode, type WithAnimated, animated as a, addEventListener, animated, autoState, createRoot, createStackNavigator, createStage, createStaticNavigation, ensureArchiveVariableDefaults, executeNodeCommand, executePluginCommand, fastForwardState, getAppStateAdapter, getNavigator, getSeekingType, getUiData, globalEventListeners, globalRequestAnimationFrameListeners, initGlobalVariableDefaults, initUiData, loadVariablesDocument, moyu, nextLine, registerAppStateAdapter, replaceUiData, setDefaultAutoTailMs, setWaiting, skipState, startDebugSession, startRuntimeDebugSession, stopDebugSession, stopRuntimeDebugSession, useAutoBlocker, useAutoTicket, useBeforeHandleCommandCallback, useDebugSession, useFadeIn, useFadeInOut, useFadeOut, useInterruptCallback, useIsAutoing, useIsSeeking, useIsSkipping, useNavigation, useNavigationParams, useNavigationState, useScenario, useSkipBlocker, useSkipCallback, useSoundEffect, useStageContext, useUiData, warpState };
915
+ export { type AnimatedComponent, type AnimatedProps, type AnimationFrameCallbackEvent, type AppStateAdapter, type AutoTicketHandle, type AutoTicketOptions, type BeforeUnloadEvent, type CombinedCheckpoint, Command, type CommandHandler, type CustomEvent, DEBUG_EMPTY_PAGE, type DebugSessionConfig, type DebugSessionController, type DebugWarpBoundary, type DebugWarpOptions, type DefaultOverlayName, type DefaultPageName, type FastForwardOptions, type FocusEvent, type FocusEventKind, type FullScreenEvent, type FullscreenEventKind, type GameControl, type GameEvent, type GameStateSourceProps, type GameStateStore, type Gamepad, type GamepadButton, type GamepadEvent, type GamepadHapticActuator, JSX, type KeyboardLocation, type Literal, MaybePromise, MouseEvent, MoyuEvent, type NavigationState, type Navigator, type NodeEvent, type OverlayConfig, type OverlayDescriptor, type OverlayInfo, OverlayParamsContext, type PageConfig, type PageDescriptor, PageParamsContext, type RegisterNavigator, type ResizeEvent, type ResolvedArgument, type ResolvedCommandLine, type ResolvedSystemCallLine, type RootErrorInfo, type RootHandle, type RootNavigatorList, type RootOptions, type RootUiDataMap, type RootUncaughtErrorInfo, type ScenarioCommandBaseType, type ScenarioEvent, type ShaderBuiltin, type ShaderBuiltinName, type ShaderEvent, type StackNavigatorOptions, StageContextProvider, type StageInstance, type TextLine, type TextLineHandler, type WheelEvent, type WheelEventDeltaMode, type WithAnimated, animated as a, addEventListener, animated, autoState, createGameStateContext, createRoot, createStackNavigator, createStage, createStaticNavigation, ensureArchiveVariableDefaults, executeNodeCommand, executePluginCommand, fastForwardState, getAppStateAdapter, getNavigator, getSeekingType, getUiData, globalEventListeners, globalRequestAnimationFrameListeners, initGlobalVariableDefaults, initUiData, loadVariablesDocument, moyu, nextLine, registerAppStateAdapter, replaceUiData, setDefaultAutoTailMs, setWaiting, skipState, startDebugSession, startRuntimeDebugSession, stopDebugSession, stopRuntimeDebugSession, useAutoBlocker, useAutoTicket, useBeforeHandleCommandCallback, useDebugSession, useFadeIn, useFadeInOut, useFadeOut, useInterruptCallback, useIsAutoing, useIsSeeking, useIsSkipping, useNavigation, useNavigationParams, useNavigationState, useScenario, useSkipBlocker, useSkipCallback, useSoundEffect, useStageContext, useUiData, warpState };
package/dist/lib.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
- import { ReactElement, Component, ForwardRefExoticComponent, CSSProperties, FC, ComponentType } from 'react';
3
- import { M as MouseEvent, a as MoyuEvent, C as Command, b as MaybePromise, J as JSX, c as JsonValue } from './jsx-dev-runtime-BCxm528Z.js';
4
- export { A as AudioCommand, d as AudioSettings, B as BubbleEvent, D as DetailedMoyuProps, E as EffectParams, G as GamepadCommand, K as KeyboardEvent, e as KeyboardEventKind, f as MakeNullOptional, g as MouseEventKind, h as MoyuAnimationAttributes, i as MoyuBackdropAttributes, j as MoyuClipAttributes, k as MoyuContainerAttributes, l as MoyuEventHandler, m as MoyuFilterAttributes, n as MoyuListenerAttributes, o as MoyuNodeAttributes, p as MoyuSpriteAttributes, q as MoyuTextAttributes, r as MoyuVideoAttributes, N as Node, S as ScenarioCommand, s as SystemCommand, T as TextCommand, t as TouchEvent, u as TouchEventKind, v as Tuple2, w as Tuple3, x as Tuple4, W as WindowState, y as createBubbleEvent, z as getStageSize } from './jsx-dev-runtime-BCxm528Z.js';
2
+ import { ReactElement, Component, ForwardRefExoticComponent, CSSProperties, FC, ReactNode, ComponentType } from 'react';
3
+ import { S as ShaderDirection, M as MouseEvent, a as MoyuEvent, C as Command, b as MaybePromise, J as JSX, c as JsonValue } from './jsx-dev-runtime-De053cfK.js';
4
+ export { A as AudioCommand, d as AudioSettings, B as BubbleEvent, D as DetailedMoyuProps, E as EffectParams, G as GamepadCommand, K as KeyboardEvent, e as KeyboardEventKind, f as MakeNullOptional, g as MouseEventKind, h as MoyuAnimationAttributes, i as MoyuBackdropAttributes, j as MoyuClipAttributes, k as MoyuContainerAttributes, l as MoyuEventHandler, m as MoyuFilterAttributes, n as MoyuListenerAttributes, o as MoyuNodeAttributes, p as MoyuShaderAttributes, q as MoyuShaderSlotAttributes, r as MoyuSpriteAttributes, s as MoyuTextAttributes, t as MoyuVideoAttributes, N as Node, R as RetainMode, u as ScenarioCommand, v as ShaderCommand, w as ShaderParam, x as ShaderParamType, y as ShaderSource, z as ShaderTimeControl, F as SystemCommand, T as TextCommand, H as TouchEvent, I as TouchEventKind, L as Tuple2, O as Tuple3, P as Tuple4, W as WindowState, Q as createBubbleEvent, U as getStageSize } from './jsx-dev-runtime-De053cfK.js';
5
5
  import { FluidValue } from '@react-spring/shared';
6
6
  import { ElementType, AssignableKeys, ComponentPropsWithRef } from '@react-spring/types';
7
7
  import { Snapshot } from 'valtio';
@@ -32,6 +32,41 @@ interface RootOptions {
32
32
  }
33
33
  declare function createRoot(options?: RootOptions): RootHandle;
34
34
 
35
+ type ShaderBuiltin = {
36
+ name: 'crossfade';
37
+ } | {
38
+ name: 'wipe';
39
+ softness: number;
40
+ direction: ShaderDirection;
41
+ } | {
42
+ name: 'fade';
43
+ out: number;
44
+ hold: number;
45
+ in: number;
46
+ color: string;
47
+ } | {
48
+ name: 'push';
49
+ direction: ShaderDirection;
50
+ } | {
51
+ name: 'slideaway';
52
+ direction: ShaderDirection;
53
+ } | {
54
+ name: 'zoom';
55
+ startScale: number;
56
+ endScale: number;
57
+ origin: [number, number];
58
+ } | {
59
+ name: 'pixellate';
60
+ steps: number;
61
+ } | {
62
+ name: 'mask';
63
+ rule: string;
64
+ softness: number;
65
+ reverse: boolean;
66
+ };
67
+
68
+ type ShaderBuiltinName = 'crossfade' | 'wipe' | 'fade' | 'push' | 'slideaway' | 'zoom' | 'pixellate' | 'mask';
69
+
35
70
  declare const globalEventListeners: Record<string, ((event: unknown) => void)[]>;
36
71
  declare const globalRequestAnimationFrameListeners: FrameRequestCallback[];
37
72
 
@@ -211,6 +246,8 @@ type ResolvedSystemCallLine = {
211
246
  arguments: Array<ResolvedArgument>;
212
247
  };
213
248
 
249
+ type ShaderEvent = null;
250
+
214
251
  type TextLine = {
215
252
  leading: string | null;
216
253
  text: string | null;
@@ -285,6 +322,21 @@ type AnimatedLeaf<T> = Exclude<T, object | undefined> | Extract<T, ReadonlyArray
285
322
 
286
323
  declare const animated: WithAnimated;
287
324
 
325
+ type GameStateStore<TState extends object> = TState;
326
+ interface GameStateSourceProps<TState extends object> {
327
+ store: GameStateStore<TState>;
328
+ children: ReactNode;
329
+ }
330
+ declare function createGameStateContext<TState extends object>(defaults: TState): {
331
+ gameState: TState;
332
+ snapshotGameState: () => TState;
333
+ syncGameState: (source: TState) => void;
334
+ resetGameState: () => void;
335
+ GameStateProvider: ({ store, children }: GameStateSourceProps<TState>) => react.FunctionComponentElement<react.ProviderProps<TState>>;
336
+ useGameStateStore: () => GameStateStore<TState>;
337
+ useGameStateSection: <K extends keyof TState>(key: K) => TState[K];
338
+ };
339
+
288
340
  declare global {
289
341
  /**
290
342
  * The **`console`** object provides access to the debugging console (e.g., the Web console in Firefox).
@@ -860,4 +912,4 @@ declare module 'zod' {
860
912
  }
861
913
  }
862
914
 
863
- export { type AnimatedComponent, type AnimatedProps, type AnimationFrameCallbackEvent, type AppStateAdapter, type AutoTicketHandle, type AutoTicketOptions, type BeforeUnloadEvent, type CombinedCheckpoint, Command, type CommandHandler, type CustomEvent, DEBUG_EMPTY_PAGE, type DebugSessionConfig, type DebugSessionController, type DebugWarpBoundary, type DebugWarpOptions, type DefaultOverlayName, type DefaultPageName, type FastForwardOptions, type FocusEvent, type FocusEventKind, type FullScreenEvent, type FullscreenEventKind, type GameControl, type GameEvent, type Gamepad, type GamepadButton, type GamepadEvent, type GamepadHapticActuator, JSX, type KeyboardLocation, type Literal, MaybePromise, MouseEvent, MoyuEvent, type NavigationState, type Navigator, type NodeEvent, type OverlayConfig, type OverlayDescriptor, type OverlayInfo, OverlayParamsContext, type PageConfig, type PageDescriptor, PageParamsContext, type RegisterNavigator, type ResizeEvent, type ResolvedArgument, type ResolvedCommandLine, type ResolvedSystemCallLine, type RootErrorInfo, type RootHandle, type RootNavigatorList, type RootOptions, type RootUiDataMap, type RootUncaughtErrorInfo, type ScenarioCommandBaseType, type ScenarioEvent, type StackNavigatorOptions, StageContextProvider, type StageInstance, type TextLine, type TextLineHandler, type WheelEvent, type WheelEventDeltaMode, type WithAnimated, animated as a, addEventListener, animated, autoState, createRoot, createStackNavigator, createStage, createStaticNavigation, ensureArchiveVariableDefaults, executeNodeCommand, executePluginCommand, fastForwardState, getAppStateAdapter, getNavigator, getSeekingType, getUiData, globalEventListeners, globalRequestAnimationFrameListeners, initGlobalVariableDefaults, initUiData, loadVariablesDocument, moyu, nextLine, registerAppStateAdapter, replaceUiData, setDefaultAutoTailMs, setWaiting, skipState, startDebugSession, startRuntimeDebugSession, stopDebugSession, stopRuntimeDebugSession, useAutoBlocker, useAutoTicket, useBeforeHandleCommandCallback, useDebugSession, useFadeIn, useFadeInOut, useFadeOut, useInterruptCallback, useIsAutoing, useIsSeeking, useIsSkipping, useNavigation, useNavigationParams, useNavigationState, useScenario, useSkipBlocker, useSkipCallback, useSoundEffect, useStageContext, useUiData, warpState };
915
+ export { type AnimatedComponent, type AnimatedProps, type AnimationFrameCallbackEvent, type AppStateAdapter, type AutoTicketHandle, type AutoTicketOptions, type BeforeUnloadEvent, type CombinedCheckpoint, Command, type CommandHandler, type CustomEvent, DEBUG_EMPTY_PAGE, type DebugSessionConfig, type DebugSessionController, type DebugWarpBoundary, type DebugWarpOptions, type DefaultOverlayName, type DefaultPageName, type FastForwardOptions, type FocusEvent, type FocusEventKind, type FullScreenEvent, type FullscreenEventKind, type GameControl, type GameEvent, type GameStateSourceProps, type GameStateStore, type Gamepad, type GamepadButton, type GamepadEvent, type GamepadHapticActuator, JSX, type KeyboardLocation, type Literal, MaybePromise, MouseEvent, MoyuEvent, type NavigationState, type Navigator, type NodeEvent, type OverlayConfig, type OverlayDescriptor, type OverlayInfo, OverlayParamsContext, type PageConfig, type PageDescriptor, PageParamsContext, type RegisterNavigator, type ResizeEvent, type ResolvedArgument, type ResolvedCommandLine, type ResolvedSystemCallLine, type RootErrorInfo, type RootHandle, type RootNavigatorList, type RootOptions, type RootUiDataMap, type RootUncaughtErrorInfo, type ScenarioCommandBaseType, type ScenarioEvent, type ShaderBuiltin, type ShaderBuiltinName, type ShaderEvent, type StackNavigatorOptions, StageContextProvider, type StageInstance, type TextLine, type TextLineHandler, type WheelEvent, type WheelEventDeltaMode, type WithAnimated, animated as a, addEventListener, animated, autoState, createGameStateContext, createRoot, createStackNavigator, createStage, createStaticNavigation, ensureArchiveVariableDefaults, executeNodeCommand, executePluginCommand, fastForwardState, getAppStateAdapter, getNavigator, getSeekingType, getUiData, globalEventListeners, globalRequestAnimationFrameListeners, initGlobalVariableDefaults, initUiData, loadVariablesDocument, moyu, nextLine, registerAppStateAdapter, replaceUiData, setDefaultAutoTailMs, setWaiting, skipState, startDebugSession, startRuntimeDebugSession, stopDebugSession, stopRuntimeDebugSession, useAutoBlocker, useAutoTicket, useBeforeHandleCommandCallback, useDebugSession, useFadeIn, useFadeInOut, useFadeOut, useInterruptCallback, useIsAutoing, useIsSeeking, useIsSkipping, useNavigation, useNavigationParams, useNavigationState, useScenario, useSkipBlocker, useSkipCallback, useSoundEffect, useStageContext, useUiData, warpState };
package/dist/lib.mjs CHANGED
@@ -28,6 +28,7 @@ __export(lib_exports, {
28
28
  animated: () => animated,
29
29
  autoState: () => autoState,
30
30
  createBubbleEvent: () => createBubbleEvent,
31
+ createGameStateContext: () => createGameStateContext,
31
32
  createRoot: () => createRoot,
32
33
  createStackNavigator: () => createStackNavigator,
33
34
  createStage: () => createStage,
@@ -738,7 +739,7 @@ var globalVariables = new Proxy(
738
739
  }
739
740
  );
740
741
  function safeEval(code, sandbox) {
741
- const proxy5 = new Proxy(sandbox, {
742
+ const proxy6 = new Proxy(sandbox, {
742
743
  has(target, key) {
743
744
  if (typeof key === "string" && JS_GLOBAL_KEYS.has(key)) {
744
745
  return false;
@@ -746,7 +747,7 @@ function safeEval(code, sandbox) {
746
747
  return key in target || key === "LOCAL" || key === "ARCHIVE" || key === "GLOBAL" || key === "window" || key === "globalThis";
747
748
  },
748
749
  get(target, key) {
749
- if (key === "window" || key === "globalThis") return proxy5;
750
+ if (key === "window" || key === "globalThis") return proxy6;
750
751
  if (key === "LOCAL") return localVariables;
751
752
  if (key === "ARCHIVE") return archiveVariables;
752
753
  if (key === "GLOBAL") return globalVariables;
@@ -758,7 +759,7 @@ function safeEval(code, sandbox) {
758
759
  return true;
759
760
  }
760
761
  });
761
- return new Function("sandbox", `with(sandbox) { return (${code}) }`).bind(proxy5)(proxy5);
762
+ return new Function("sandbox", `with(sandbox) { return (${code}) }`).bind(proxy6)(proxy6);
762
763
  }
763
764
  globalThis.__moyu_eval_sandbox = (code) => {
764
765
  try {
@@ -940,12 +941,85 @@ function getStageSize() {
940
941
  return stageSize;
941
942
  }
942
943
 
944
+ // src/gameState.ts
945
+ import { createContext, createElement, useContext } from "react";
946
+ import { proxy, snapshot, useSnapshot } from "valtio";
947
+ function cloneStateValue(value) {
948
+ return JSON.parse(JSON.stringify(value));
949
+ }
950
+ function isPlainObject(value) {
951
+ return typeof value === "object" && value !== null && !Array.isArray(value);
952
+ }
953
+ function syncStateValue(target, source) {
954
+ if (Array.isArray(source)) {
955
+ if (!Array.isArray(target)) {
956
+ return cloneStateValue(source);
957
+ }
958
+ target.length = source.length;
959
+ for (let index = 0; index < source.length; index += 1) {
960
+ target[index] = syncStateValue(target[index], source[index]);
961
+ }
962
+ return target;
963
+ }
964
+ if (isPlainObject(source)) {
965
+ if (!isPlainObject(target)) {
966
+ return cloneStateValue(source);
967
+ }
968
+ for (const key of Object.keys(target)) {
969
+ if (!Object.hasOwn(source, key)) {
970
+ delete target[key];
971
+ }
972
+ }
973
+ for (const [key, nextValue] of Object.entries(source)) {
974
+ target[key] = syncStateValue(target[key], nextValue);
975
+ }
976
+ return target;
977
+ }
978
+ return source;
979
+ }
980
+ function createGameStateContext(defaults) {
981
+ const defaultState = cloneStateValue(defaults);
982
+ const gameState = proxy(cloneStateValue(defaults));
983
+ function snapshotGameState() {
984
+ return snapshot(gameState);
985
+ }
986
+ function syncGameState(source) {
987
+ const target = gameState;
988
+ for (const key of Object.keys(source)) {
989
+ target[key] = syncStateValue(target[key], source[key]);
990
+ }
991
+ }
992
+ function resetGameState() {
993
+ syncGameState(defaultState);
994
+ }
995
+ const StoreContext = createContext(gameState);
996
+ function GameStateProvider({ store, children }) {
997
+ return createElement(StoreContext.Provider, { value: store }, children);
998
+ }
999
+ function useGameStateStore() {
1000
+ return useContext(StoreContext);
1001
+ }
1002
+ function useGameStateSection(key) {
1003
+ const store = useGameStateStore();
1004
+ return useSnapshot(store)[key];
1005
+ }
1006
+ return {
1007
+ gameState,
1008
+ snapshotGameState,
1009
+ syncGameState,
1010
+ resetGameState,
1011
+ GameStateProvider,
1012
+ useGameStateStore,
1013
+ useGameStateSection
1014
+ };
1015
+ }
1016
+
943
1017
  // src/components/navigation.tsx
944
- import { createContext, useContext } from "react";
945
- import { proxy, useSnapshot } from "valtio";
1018
+ import { createContext as createContext2, useContext as useContext2 } from "react";
1019
+ import { proxy as proxy2, useSnapshot as useSnapshot2 } from "valtio";
946
1020
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
947
- var PageParamsContext = createContext(void 0);
948
- var OverlayParamsContext = createContext(void 0);
1021
+ var PageParamsContext = createContext2(void 0);
1022
+ var OverlayParamsContext = createContext2(void 0);
949
1023
  var DEBUG_EMPTY_PAGE = "debug-empty";
950
1024
  var overlayIdCounter = 0;
951
1025
  var generateOverlayId = () => {
@@ -986,7 +1060,7 @@ function createStackNavigator(options) {
986
1060
  normalizedOverlays[key] = normalizeDescriptor(config);
987
1061
  }
988
1062
  }
989
- const navigationState = proxy({
1063
+ const navigationState = proxy2({
990
1064
  currentPage: options.initialPage,
991
1065
  pageParams: {},
992
1066
  overlayStack: [],
@@ -1069,7 +1143,7 @@ function createStackNavigator(options) {
1069
1143
  }
1070
1144
  function createStaticNavigation(navigator) {
1071
1145
  return () => {
1072
- const navState = useSnapshot(navigator._state);
1146
+ const navState = useSnapshot2(navigator._state);
1073
1147
  const { pages, overlays } = navigator._descriptors;
1074
1148
  const pageDescriptor = pages[navState.currentPage];
1075
1149
  const Page = pageDescriptor?.component || (() => null);
@@ -1091,17 +1165,17 @@ function getNavigator() {
1091
1165
  }
1092
1166
  var useNavigation = getNavigator;
1093
1167
  function useNavigationState() {
1094
- return useSnapshot(getNavigator()._state);
1168
+ return useSnapshot2(getNavigator()._state);
1095
1169
  }
1096
1170
  function useNavigationParams() {
1097
- const overlayParams = useContext(OverlayParamsContext);
1098
- const pageParams = useContext(PageParamsContext);
1171
+ const overlayParams = useContext2(OverlayParamsContext);
1172
+ const pageParams = useContext2(PageParamsContext);
1099
1173
  return overlayParams ?? pageParams ?? {};
1100
1174
  }
1101
1175
 
1102
1176
  // src/debug/session.ts
1103
- import { useSnapshot as useSnapshot2, proxy as proxy2 } from "valtio";
1104
- var debugState = proxy2({
1177
+ import { useSnapshot as useSnapshot3, proxy as proxy3 } from "valtio";
1178
+ var debugState = proxy3({
1105
1179
  active: false,
1106
1180
  checkpoints: {},
1107
1181
  currentCursor: null,
@@ -1616,9 +1690,9 @@ async function stopDebugSession() {
1616
1690
  clearLocalRuntimeState();
1617
1691
  }
1618
1692
  function useDebugSession() {
1619
- const snapshot = useSnapshot2(debugState);
1693
+ const snapshot2 = useSnapshot3(debugState);
1620
1694
  return {
1621
- ...snapshot,
1695
+ ...snapshot2,
1622
1696
  startDebugSession,
1623
1697
  stopDebugSession,
1624
1698
  restoreCheckpoint: debugSessionController.restoreCheckpoint,
@@ -1629,11 +1703,11 @@ function useDebugSession() {
1629
1703
  }
1630
1704
 
1631
1705
  // src/ui.ts
1632
- import { proxy as proxy3, useSnapshot as useSnapshot3 } from "valtio";
1706
+ import { proxy as proxy4, useSnapshot as useSnapshot4 } from "valtio";
1633
1707
  var UI_DATA_ASSET_PATH = "assets:///data/ui.json";
1634
1708
  var activeUiSchema = null;
1635
- var uiDataState = proxy3({});
1636
- var uiRuntimeState = proxy3({
1709
+ var uiDataState = proxy4({});
1710
+ var uiRuntimeState = proxy4({
1637
1711
  initialized: false,
1638
1712
  error: null
1639
1713
  });
@@ -1694,11 +1768,11 @@ function useUiData(name) {
1694
1768
  if (!uiRuntimeState.initialized) {
1695
1769
  throw new Error("UI data has not been initialized. Call initUiData() before rendering UI pages.");
1696
1770
  }
1697
- const snapshot = useSnapshot3(uiDataState);
1698
- if (!(name in snapshot)) {
1771
+ const snapshot2 = useSnapshot4(uiDataState);
1772
+ if (!(name in snapshot2)) {
1699
1773
  throw new Error(`UI data "${name}" is not available.`);
1700
1774
  }
1701
- return snapshot[name];
1775
+ return snapshot2[name];
1702
1776
  }
1703
1777
 
1704
1778
  // src/debug/runtime.ts
@@ -2242,26 +2316,26 @@ function useSoundEffect(src) {
2242
2316
  }
2243
2317
 
2244
2318
  // src/hooks/useStage.ts
2245
- import { createContext as createContext2, useContext as useContext2, useEffect as useEffect3, createElement, useCallback as useCallback2 } from "react";
2246
- import { proxy as proxy4, useSnapshot as useSnapshot4 } from "valtio";
2319
+ import { createContext as createContext3, useContext as useContext3, useEffect as useEffect3, createElement as createElement2, useCallback as useCallback2 } from "react";
2320
+ import { proxy as proxy5, useSnapshot as useSnapshot5 } from "valtio";
2247
2321
  var SKIP_INTERVAL_MS = 80;
2248
2322
  var DEFAULT_FAST_FORWARD_STEP_LIMIT = 1e4;
2249
2323
  var DEFAULT_FAST_FORWARD_TIME_LIMIT_MS = 3e3;
2250
2324
  var autoRuntime = {
2251
2325
  defaultTailMs: 0
2252
2326
  };
2253
- var skipState = proxy4({ active: false });
2254
- var autoState = proxy4({ active: false });
2255
- var fastForwardState = proxy4({ active: false });
2256
- var warpState = proxy4({ active: false });
2327
+ var skipState = proxy5({ active: false });
2328
+ var autoState = proxy5({ active: false });
2329
+ var fastForwardState = proxy5({ active: false });
2330
+ var warpState = proxy5({ active: false });
2257
2331
  function useIsSkipping() {
2258
- return useSnapshot4(skipState).active;
2332
+ return useSnapshot5(skipState).active;
2259
2333
  }
2260
2334
  function useIsAutoing() {
2261
- return useSnapshot4(autoState).active;
2335
+ return useSnapshot5(autoState).active;
2262
2336
  }
2263
2337
  function useIsSeeking() {
2264
- return useSnapshot4(fastForwardState).active;
2338
+ return useSnapshot5(fastForwardState).active;
2265
2339
  }
2266
2340
  function getSeekingType() {
2267
2341
  if (warpState.active) return "warp";
@@ -2912,9 +2986,9 @@ function createStage() {
2912
2986
  bindEvents
2913
2987
  };
2914
2988
  }
2915
- var StageContext = createContext2(null);
2989
+ var StageContext = createContext3(null);
2916
2990
  function useStageContext() {
2917
- const ctx = useContext2(StageContext);
2991
+ const ctx = useContext3(StageContext);
2918
2992
  if (!ctx) throw new Error("useStageContext must be used within StageContextProvider");
2919
2993
  return ctx;
2920
2994
  }
@@ -2922,7 +2996,7 @@ function StageContextProvider({ stage, children }) {
2922
2996
  useEffect3(() => {
2923
2997
  return stage.bindEvents();
2924
2998
  }, [stage]);
2925
- return createElement(StageContext.Provider, { value: stage }, children);
2999
+ return createElement2(StageContext.Provider, { value: stage }, children);
2926
3000
  }
2927
3001
  function useSkipCallback(callback) {
2928
3002
  const stage = useStageContext();
@@ -2976,6 +3050,7 @@ export {
2976
3050
  animated,
2977
3051
  autoState,
2978
3052
  createBubbleEvent,
3053
+ createGameStateContext,
2979
3054
  createRoot,
2980
3055
  createStackNavigator,
2981
3056
  createStage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momoyu-ink/kit",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "Software Development Kit of Moyu Visual Novel Engine",
5
5
  "main": "dist/lib.cjs",
6
6
  "module": "dist/lib.mjs",