@momoyu-ink/kit 0.8.1 → 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: [],
@@ -1029,7 +1103,6 @@ function createStackNavigator(options) {
1029
1103
  },
1030
1104
  hasActiveOverlay: (overlay, id) => {
1031
1105
  if (id) {
1032
- console.log(navigationState.overlayStack.some((o) => o.type === overlay && o.id === id));
1033
1106
  return navigationState.overlayStack.some((o) => o.type === overlay && o.id === id);
1034
1107
  }
1035
1108
  return navigationState.overlayStack.some((o) => o.type === overlay);
@@ -1082,7 +1155,7 @@ function createStackNavigator(options) {
1082
1155
  }
1083
1156
  function createStaticNavigation(navigator) {
1084
1157
  return () => {
1085
- const navState = (0, import_valtio.useSnapshot)(navigator._state);
1158
+ const navState = (0, import_valtio2.useSnapshot)(navigator._state);
1086
1159
  const { pages, overlays } = navigator._descriptors;
1087
1160
  const pageDescriptor = pages[navState.currentPage];
1088
1161
  const Page = pageDescriptor?.component || (() => null);
@@ -1104,17 +1177,17 @@ function getNavigator() {
1104
1177
  }
1105
1178
  var useNavigation = getNavigator;
1106
1179
  function useNavigationState() {
1107
- return (0, import_valtio.useSnapshot)(getNavigator()._state);
1180
+ return (0, import_valtio2.useSnapshot)(getNavigator()._state);
1108
1181
  }
1109
1182
  function useNavigationParams() {
1110
- const overlayParams = (0, import_react2.useContext)(OverlayParamsContext);
1111
- const pageParams = (0, import_react2.useContext)(PageParamsContext);
1183
+ const overlayParams = (0, import_react3.useContext)(OverlayParamsContext);
1184
+ const pageParams = (0, import_react3.useContext)(PageParamsContext);
1112
1185
  return overlayParams ?? pageParams ?? {};
1113
1186
  }
1114
1187
 
1115
1188
  // src/debug/session.ts
1116
- var import_valtio2 = require("valtio");
1117
- var debugState = (0, import_valtio2.proxy)({
1189
+ var import_valtio3 = require("valtio");
1190
+ var debugState = (0, import_valtio3.proxy)({
1118
1191
  active: false,
1119
1192
  checkpoints: {},
1120
1193
  currentCursor: null,
@@ -1629,9 +1702,9 @@ async function stopDebugSession() {
1629
1702
  clearLocalRuntimeState();
1630
1703
  }
1631
1704
  function useDebugSession() {
1632
- const snapshot = (0, import_valtio2.useSnapshot)(debugState);
1705
+ const snapshot2 = (0, import_valtio3.useSnapshot)(debugState);
1633
1706
  return {
1634
- ...snapshot,
1707
+ ...snapshot2,
1635
1708
  startDebugSession,
1636
1709
  stopDebugSession,
1637
1710
  restoreCheckpoint: debugSessionController.restoreCheckpoint,
@@ -1642,11 +1715,11 @@ function useDebugSession() {
1642
1715
  }
1643
1716
 
1644
1717
  // src/ui.ts
1645
- var import_valtio3 = require("valtio");
1718
+ var import_valtio4 = require("valtio");
1646
1719
  var UI_DATA_ASSET_PATH = "assets:///data/ui.json";
1647
1720
  var activeUiSchema = null;
1648
- var uiDataState = (0, import_valtio3.proxy)({});
1649
- var uiRuntimeState = (0, import_valtio3.proxy)({
1721
+ var uiDataState = (0, import_valtio4.proxy)({});
1722
+ var uiRuntimeState = (0, import_valtio4.proxy)({
1650
1723
  initialized: false,
1651
1724
  error: null
1652
1725
  });
@@ -1707,11 +1780,11 @@ function useUiData(name) {
1707
1780
  if (!uiRuntimeState.initialized) {
1708
1781
  throw new Error("UI data has not been initialized. Call initUiData() before rendering UI pages.");
1709
1782
  }
1710
- const snapshot = (0, import_valtio3.useSnapshot)(uiDataState);
1711
- if (!(name in snapshot)) {
1783
+ const snapshot2 = (0, import_valtio4.useSnapshot)(uiDataState);
1784
+ if (!(name in snapshot2)) {
1712
1785
  throw new Error(`UI data "${name}" is not available.`);
1713
1786
  }
1714
- return snapshot[name];
1787
+ return snapshot2[name];
1715
1788
  }
1716
1789
 
1717
1790
  // src/debug/runtime.ts
@@ -2066,7 +2139,7 @@ function useFadeOut(outTime, pause = false, onFinished) {
2066
2139
  }
2067
2140
 
2068
2141
  // src/hooks/useScenario.ts
2069
- var import_react3 = require("react");
2142
+ var import_react4 = require("react");
2070
2143
  var currentScenarioSession = null;
2071
2144
  var scenarioSessionId = 0;
2072
2145
  var scenarioLifecycleQueue = Promise.resolve();
@@ -2208,7 +2281,7 @@ function setWaiting(time, skippable) {
2208
2281
  executePluginCommand("scenario", { subCommand: "setWaiting", time, skippable });
2209
2282
  }
2210
2283
  function useScenario(stories, startName, entryName, goNextOnLoad = false) {
2211
- (0, import_react3.useEffect)(() => {
2284
+ (0, import_react4.useEffect)(() => {
2212
2285
  const session = acquireScenarioSession({
2213
2286
  stories: normalizeStories(stories),
2214
2287
  startName,
@@ -2222,9 +2295,9 @@ function useScenario(stories, startName, entryName, goNextOnLoad = false) {
2222
2295
  }
2223
2296
 
2224
2297
  // src/hooks/useSoundEffect.ts
2225
- var import_react4 = require("react");
2298
+ var import_react5 = require("react");
2226
2299
  function useSoundEffect(src) {
2227
- (0, import_react4.useEffect)(() => {
2300
+ (0, import_react5.useEffect)(() => {
2228
2301
  return () => {
2229
2302
  try {
2230
2303
  if (src) {
@@ -2239,7 +2312,7 @@ function useSoundEffect(src) {
2239
2312
  }
2240
2313
  };
2241
2314
  }, [src]);
2242
- return (0, import_react4.useCallback)(() => {
2315
+ return (0, import_react5.useCallback)(() => {
2243
2316
  try {
2244
2317
  if (src) {
2245
2318
  executePluginCommand("audio", {
@@ -2255,26 +2328,26 @@ function useSoundEffect(src) {
2255
2328
  }
2256
2329
 
2257
2330
  // src/hooks/useStage.ts
2258
- var import_react5 = require("react");
2259
- var import_valtio4 = require("valtio");
2331
+ var import_react6 = require("react");
2332
+ var import_valtio5 = require("valtio");
2260
2333
  var SKIP_INTERVAL_MS = 80;
2261
2334
  var DEFAULT_FAST_FORWARD_STEP_LIMIT = 1e4;
2262
2335
  var DEFAULT_FAST_FORWARD_TIME_LIMIT_MS = 3e3;
2263
2336
  var autoRuntime = {
2264
2337
  defaultTailMs: 0
2265
2338
  };
2266
- var skipState = (0, import_valtio4.proxy)({ active: false });
2267
- var autoState = (0, import_valtio4.proxy)({ active: false });
2268
- var fastForwardState = (0, import_valtio4.proxy)({ active: false });
2269
- 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 });
2270
2343
  function useIsSkipping() {
2271
- return (0, import_valtio4.useSnapshot)(skipState).active;
2344
+ return (0, import_valtio5.useSnapshot)(skipState).active;
2272
2345
  }
2273
2346
  function useIsAutoing() {
2274
- return (0, import_valtio4.useSnapshot)(autoState).active;
2347
+ return (0, import_valtio5.useSnapshot)(autoState).active;
2275
2348
  }
2276
2349
  function useIsSeeking() {
2277
- return (0, import_valtio4.useSnapshot)(fastForwardState).active;
2350
+ return (0, import_valtio5.useSnapshot)(fastForwardState).active;
2278
2351
  }
2279
2352
  function getSeekingType() {
2280
2353
  if (warpState.active) return "warp";
@@ -2925,45 +2998,45 @@ function createStage() {
2925
2998
  bindEvents
2926
2999
  };
2927
3000
  }
2928
- var StageContext = (0, import_react5.createContext)(null);
3001
+ var StageContext = (0, import_react6.createContext)(null);
2929
3002
  function useStageContext() {
2930
- const ctx = (0, import_react5.useContext)(StageContext);
3003
+ const ctx = (0, import_react6.useContext)(StageContext);
2931
3004
  if (!ctx) throw new Error("useStageContext must be used within StageContextProvider");
2932
3005
  return ctx;
2933
3006
  }
2934
3007
  function StageContextProvider({ stage, children }) {
2935
- (0, import_react5.useEffect)(() => {
3008
+ (0, import_react6.useEffect)(() => {
2936
3009
  return stage.bindEvents();
2937
3010
  }, [stage]);
2938
- return (0, import_react5.createElement)(StageContext.Provider, { value: stage }, children);
3011
+ return (0, import_react6.createElement)(StageContext.Provider, { value: stage }, children);
2939
3012
  }
2940
3013
  function useSkipCallback(callback) {
2941
3014
  const stage = useStageContext();
2942
- (0, import_react5.useEffect)(() => {
3015
+ (0, import_react6.useEffect)(() => {
2943
3016
  return stage.addSkipCallback(callback);
2944
3017
  }, [stage, callback]);
2945
3018
  }
2946
3019
  function useInterruptCallback(callback) {
2947
3020
  const stage = useStageContext();
2948
- (0, import_react5.useEffect)(() => {
3021
+ (0, import_react6.useEffect)(() => {
2949
3022
  return stage.addInterruptCallback(callback);
2950
3023
  }, [stage, callback]);
2951
3024
  }
2952
3025
  function useSkipBlocker(callback) {
2953
3026
  const stage = useStageContext();
2954
- (0, import_react5.useEffect)(() => {
3027
+ (0, import_react6.useEffect)(() => {
2955
3028
  return stage.addSkipBlocker(callback);
2956
3029
  }, [stage, callback]);
2957
3030
  }
2958
3031
  function useAutoBlocker(callback) {
2959
3032
  const stage = useStageContext();
2960
- (0, import_react5.useEffect)(() => {
3033
+ (0, import_react6.useEffect)(() => {
2961
3034
  return stage.addAutoBlocker(callback);
2962
3035
  }, [stage, callback]);
2963
3036
  }
2964
3037
  function useAutoTicket() {
2965
3038
  const stage = useStageContext();
2966
- return (0, import_react5.useCallback)(
3039
+ return (0, import_react6.useCallback)(
2967
3040
  (options) => {
2968
3041
  return stage.issueAutoTicket(options);
2969
3042
  },
@@ -2972,7 +3045,7 @@ function useAutoTicket() {
2972
3045
  }
2973
3046
  function useBeforeHandleCommandCallback(callback) {
2974
3047
  const stage = useStageContext();
2975
- (0, import_react5.useEffect)(() => {
3048
+ (0, import_react6.useEffect)(() => {
2976
3049
  return stage.addBeforeHandleCommandCallback(callback);
2977
3050
  }, [stage, callback]);
2978
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: [],
@@ -1017,7 +1091,6 @@ function createStackNavigator(options) {
1017
1091
  },
1018
1092
  hasActiveOverlay: (overlay, id) => {
1019
1093
  if (id) {
1020
- console.log(navigationState.overlayStack.some((o) => o.type === overlay && o.id === id));
1021
1094
  return navigationState.overlayStack.some((o) => o.type === overlay && o.id === id);
1022
1095
  }
1023
1096
  return navigationState.overlayStack.some((o) => o.type === overlay);
@@ -1070,7 +1143,7 @@ function createStackNavigator(options) {
1070
1143
  }
1071
1144
  function createStaticNavigation(navigator) {
1072
1145
  return () => {
1073
- const navState = useSnapshot(navigator._state);
1146
+ const navState = useSnapshot2(navigator._state);
1074
1147
  const { pages, overlays } = navigator._descriptors;
1075
1148
  const pageDescriptor = pages[navState.currentPage];
1076
1149
  const Page = pageDescriptor?.component || (() => null);
@@ -1092,17 +1165,17 @@ function getNavigator() {
1092
1165
  }
1093
1166
  var useNavigation = getNavigator;
1094
1167
  function useNavigationState() {
1095
- return useSnapshot(getNavigator()._state);
1168
+ return useSnapshot2(getNavigator()._state);
1096
1169
  }
1097
1170
  function useNavigationParams() {
1098
- const overlayParams = useContext(OverlayParamsContext);
1099
- const pageParams = useContext(PageParamsContext);
1171
+ const overlayParams = useContext2(OverlayParamsContext);
1172
+ const pageParams = useContext2(PageParamsContext);
1100
1173
  return overlayParams ?? pageParams ?? {};
1101
1174
  }
1102
1175
 
1103
1176
  // src/debug/session.ts
1104
- import { useSnapshot as useSnapshot2, proxy as proxy2 } from "valtio";
1105
- var debugState = proxy2({
1177
+ import { useSnapshot as useSnapshot3, proxy as proxy3 } from "valtio";
1178
+ var debugState = proxy3({
1106
1179
  active: false,
1107
1180
  checkpoints: {},
1108
1181
  currentCursor: null,
@@ -1617,9 +1690,9 @@ async function stopDebugSession() {
1617
1690
  clearLocalRuntimeState();
1618
1691
  }
1619
1692
  function useDebugSession() {
1620
- const snapshot = useSnapshot2(debugState);
1693
+ const snapshot2 = useSnapshot3(debugState);
1621
1694
  return {
1622
- ...snapshot,
1695
+ ...snapshot2,
1623
1696
  startDebugSession,
1624
1697
  stopDebugSession,
1625
1698
  restoreCheckpoint: debugSessionController.restoreCheckpoint,
@@ -1630,11 +1703,11 @@ function useDebugSession() {
1630
1703
  }
1631
1704
 
1632
1705
  // src/ui.ts
1633
- import { proxy as proxy3, useSnapshot as useSnapshot3 } from "valtio";
1706
+ import { proxy as proxy4, useSnapshot as useSnapshot4 } from "valtio";
1634
1707
  var UI_DATA_ASSET_PATH = "assets:///data/ui.json";
1635
1708
  var activeUiSchema = null;
1636
- var uiDataState = proxy3({});
1637
- var uiRuntimeState = proxy3({
1709
+ var uiDataState = proxy4({});
1710
+ var uiRuntimeState = proxy4({
1638
1711
  initialized: false,
1639
1712
  error: null
1640
1713
  });
@@ -1695,11 +1768,11 @@ function useUiData(name) {
1695
1768
  if (!uiRuntimeState.initialized) {
1696
1769
  throw new Error("UI data has not been initialized. Call initUiData() before rendering UI pages.");
1697
1770
  }
1698
- const snapshot = useSnapshot3(uiDataState);
1699
- if (!(name in snapshot)) {
1771
+ const snapshot2 = useSnapshot4(uiDataState);
1772
+ if (!(name in snapshot2)) {
1700
1773
  throw new Error(`UI data "${name}" is not available.`);
1701
1774
  }
1702
- return snapshot[name];
1775
+ return snapshot2[name];
1703
1776
  }
1704
1777
 
1705
1778
  // src/debug/runtime.ts
@@ -2243,26 +2316,26 @@ function useSoundEffect(src) {
2243
2316
  }
2244
2317
 
2245
2318
  // src/hooks/useStage.ts
2246
- import { createContext as createContext2, useContext as useContext2, useEffect as useEffect3, createElement, useCallback as useCallback2 } from "react";
2247
- 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";
2248
2321
  var SKIP_INTERVAL_MS = 80;
2249
2322
  var DEFAULT_FAST_FORWARD_STEP_LIMIT = 1e4;
2250
2323
  var DEFAULT_FAST_FORWARD_TIME_LIMIT_MS = 3e3;
2251
2324
  var autoRuntime = {
2252
2325
  defaultTailMs: 0
2253
2326
  };
2254
- var skipState = proxy4({ active: false });
2255
- var autoState = proxy4({ active: false });
2256
- var fastForwardState = proxy4({ active: false });
2257
- 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 });
2258
2331
  function useIsSkipping() {
2259
- return useSnapshot4(skipState).active;
2332
+ return useSnapshot5(skipState).active;
2260
2333
  }
2261
2334
  function useIsAutoing() {
2262
- return useSnapshot4(autoState).active;
2335
+ return useSnapshot5(autoState).active;
2263
2336
  }
2264
2337
  function useIsSeeking() {
2265
- return useSnapshot4(fastForwardState).active;
2338
+ return useSnapshot5(fastForwardState).active;
2266
2339
  }
2267
2340
  function getSeekingType() {
2268
2341
  if (warpState.active) return "warp";
@@ -2913,9 +2986,9 @@ function createStage() {
2913
2986
  bindEvents
2914
2987
  };
2915
2988
  }
2916
- var StageContext = createContext2(null);
2989
+ var StageContext = createContext3(null);
2917
2990
  function useStageContext() {
2918
- const ctx = useContext2(StageContext);
2991
+ const ctx = useContext3(StageContext);
2919
2992
  if (!ctx) throw new Error("useStageContext must be used within StageContextProvider");
2920
2993
  return ctx;
2921
2994
  }
@@ -2923,7 +2996,7 @@ function StageContextProvider({ stage, children }) {
2923
2996
  useEffect3(() => {
2924
2997
  return stage.bindEvents();
2925
2998
  }, [stage]);
2926
- return createElement(StageContext.Provider, { value: stage }, children);
2999
+ return createElement2(StageContext.Provider, { value: stage }, children);
2927
3000
  }
2928
3001
  function useSkipCallback(callback) {
2929
3002
  const stage = useStageContext();
@@ -2977,6 +3050,7 @@ export {
2977
3050
  animated,
2978
3051
  autoState,
2979
3052
  createBubbleEvent,
3053
+ createGameStateContext,
2980
3054
  createRoot,
2981
3055
  createStackNavigator,
2982
3056
  createStage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momoyu-ink/kit",
3
- "version": "0.8.1",
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",