@momoyu-ink/kit 0.4.1 → 0.5.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.
Files changed (181) hide show
  1. package/dist/jsx-dev-runtime--ZXLAgUi.d.mts +600 -0
  2. package/dist/jsx-dev-runtime--ZXLAgUi.d.ts +600 -0
  3. package/dist/jsx-dev-runtime.cjs +27 -0
  4. package/dist/jsx-dev-runtime.d.mts +4 -0
  5. package/dist/jsx-dev-runtime.d.ts +4 -0
  6. package/dist/jsx-dev-runtime.mjs +6 -0
  7. package/dist/jsx-runtime.cjs +28 -0
  8. package/dist/jsx-runtime.d.mts +4 -0
  9. package/dist/jsx-runtime.d.ts +4 -0
  10. package/dist/jsx-runtime.mjs +7 -0
  11. package/dist/lib.cjs +1503 -0
  12. package/dist/lib.d.mts +667 -0
  13. package/dist/lib.d.ts +667 -15
  14. package/dist/lib.mjs +1534 -0
  15. package/package.json +29 -8
  16. package/dist/bindings/AnimationFormat.d.ts +0 -1
  17. package/dist/bindings/AnimationFormat.js +0 -3
  18. package/dist/bindings/AnimationFrameCallbackEvent.d.ts +0 -3
  19. package/dist/bindings/AnimationFrameCallbackEvent.js +0 -3
  20. package/dist/bindings/AnimationProps.d.ts +0 -6
  21. package/dist/bindings/AnimationProps.js +0 -2
  22. package/dist/bindings/AudioCommand.d.ts +0 -54
  23. package/dist/bindings/AudioCommand.js +0 -2
  24. package/dist/bindings/AudioSettings.d.ts +0 -42
  25. package/dist/bindings/AudioSettings.js +0 -3
  26. package/dist/bindings/BackdropProps.d.ts +0 -6
  27. package/dist/bindings/BackdropProps.js +0 -2
  28. package/dist/bindings/BeforeUnloadEvent.d.ts +0 -1
  29. package/dist/bindings/BeforeUnloadEvent.js +0 -3
  30. package/dist/bindings/ClipProps.d.ts +0 -4
  31. package/dist/bindings/ClipProps.js +0 -3
  32. package/dist/bindings/CustomEvent.d.ts +0 -18
  33. package/dist/bindings/CustomEvent.js +0 -3
  34. package/dist/bindings/EffectParams.d.ts +0 -6
  35. package/dist/bindings/EffectParams.js +0 -3
  36. package/dist/bindings/FilterKind.d.ts +0 -34
  37. package/dist/bindings/FilterKind.js +0 -3
  38. package/dist/bindings/FilterProps.d.ts +0 -4
  39. package/dist/bindings/FilterProps.js +0 -2
  40. package/dist/bindings/FocusEvent.d.ts +0 -5
  41. package/dist/bindings/FocusEvent.js +0 -2
  42. package/dist/bindings/FocusEventKind.d.ts +0 -1
  43. package/dist/bindings/FocusEventKind.js +0 -3
  44. package/dist/bindings/FullScreenEvent.d.ts +0 -4
  45. package/dist/bindings/FullScreenEvent.js +0 -2
  46. package/dist/bindings/FullscreenEventKind.d.ts +0 -1
  47. package/dist/bindings/FullscreenEventKind.js +0 -3
  48. package/dist/bindings/GameEvent.d.ts +0 -1
  49. package/dist/bindings/GameEvent.js +0 -3
  50. package/dist/bindings/Gamepad.d.ts +0 -44
  51. package/dist/bindings/Gamepad.js +0 -2
  52. package/dist/bindings/GamepadButton.d.ts +0 -20
  53. package/dist/bindings/GamepadButton.js +0 -3
  54. package/dist/bindings/GamepadCommand.d.ts +0 -9
  55. package/dist/bindings/GamepadCommand.js +0 -2
  56. package/dist/bindings/GamepadEvent.d.ts +0 -12
  57. package/dist/bindings/GamepadEvent.js +0 -2
  58. package/dist/bindings/GamepadHapticActuator.d.ts +0 -11
  59. package/dist/bindings/GamepadHapticActuator.js +0 -3
  60. package/dist/bindings/KeyboardEventKind.d.ts +0 -1
  61. package/dist/bindings/KeyboardEventKind.js +0 -3
  62. package/dist/bindings/KeyboardLocation.d.ts +0 -1
  63. package/dist/bindings/KeyboardLocation.js +0 -3
  64. package/dist/bindings/Literal.d.ts +0 -3
  65. package/dist/bindings/Literal.js +0 -3
  66. package/dist/bindings/MouseEventKind.d.ts +0 -1
  67. package/dist/bindings/MouseEventKind.js +0 -3
  68. package/dist/bindings/MoyuCursor.d.ts +0 -1
  69. package/dist/bindings/MoyuCursor.js +0 -3
  70. package/dist/bindings/NineSliceMode.d.ts +0 -1
  71. package/dist/bindings/NineSliceMode.js +0 -3
  72. package/dist/bindings/NodeEvent.d.ts +0 -4
  73. package/dist/bindings/NodeEvent.js +0 -3
  74. package/dist/bindings/NodeProps.d.ts +0 -20
  75. package/dist/bindings/NodeProps.js +0 -2
  76. package/dist/bindings/RawKeyboardEvent.d.ts +0 -16
  77. package/dist/bindings/RawKeyboardEvent.js +0 -2
  78. package/dist/bindings/RawMouseEvent.d.ts +0 -12
  79. package/dist/bindings/RawMouseEvent.js +0 -2
  80. package/dist/bindings/RawTouchEvent.d.ts +0 -13
  81. package/dist/bindings/RawTouchEvent.js +0 -2
  82. package/dist/bindings/RawWheelEvent.d.ts +0 -10
  83. package/dist/bindings/RawWheelEvent.js +0 -2
  84. package/dist/bindings/ResizeEvent.d.ts +0 -4
  85. package/dist/bindings/ResizeEvent.js +0 -3
  86. package/dist/bindings/ResolvedArgument.d.ts +0 -5
  87. package/dist/bindings/ResolvedArgument.js +0 -2
  88. package/dist/bindings/ResolvedCommandLine.d.ts +0 -5
  89. package/dist/bindings/ResolvedCommandLine.js +0 -2
  90. package/dist/bindings/ResolvedSystemCallLine.d.ts +0 -5
  91. package/dist/bindings/ResolvedSystemCallLine.js +0 -2
  92. package/dist/bindings/ScenarioCommand.d.ts +0 -103
  93. package/dist/bindings/ScenarioCommand.js +0 -2
  94. package/dist/bindings/ScenarioEvent.d.ts +0 -4
  95. package/dist/bindings/ScenarioEvent.js +0 -2
  96. package/dist/bindings/SpriteMode.d.ts +0 -1
  97. package/dist/bindings/SpriteMode.js +0 -3
  98. package/dist/bindings/SpriteProps.d.ts +0 -11
  99. package/dist/bindings/SpriteProps.js +0 -2
  100. package/dist/bindings/SystemCommand.d.ts +0 -30
  101. package/dist/bindings/SystemCommand.js +0 -2
  102. package/dist/bindings/TextCommand.d.ts +0 -9
  103. package/dist/bindings/TextCommand.js +0 -3
  104. package/dist/bindings/TextEvent.d.ts +0 -1
  105. package/dist/bindings/TextEvent.js +0 -3
  106. package/dist/bindings/TextLine.d.ts +0 -5
  107. package/dist/bindings/TextLine.js +0 -3
  108. package/dist/bindings/TextPrintMode.d.ts +0 -4
  109. package/dist/bindings/TextPrintMode.js +0 -3
  110. package/dist/bindings/TextProps.d.ts +0 -41
  111. package/dist/bindings/TextProps.js +0 -2
  112. package/dist/bindings/TouchEventKind.d.ts +0 -1
  113. package/dist/bindings/TouchEventKind.js +0 -3
  114. package/dist/bindings/VideoCommand.d.ts +0 -21
  115. package/dist/bindings/VideoCommand.js +0 -3
  116. package/dist/bindings/VideoEvent.d.ts +0 -1
  117. package/dist/bindings/VideoEvent.js +0 -3
  118. package/dist/bindings/VideoProps.d.ts +0 -7
  119. package/dist/bindings/VideoProps.js +0 -3
  120. package/dist/bindings/WheelEventDeltaMode.d.ts +0 -1
  121. package/dist/bindings/WheelEventDeltaMode.js +0 -3
  122. package/dist/bindings/WindowState.d.ts +0 -1
  123. package/dist/bindings/WindowState.js +0 -3
  124. package/dist/bindings/serde_json/JsonValue.d.ts +0 -3
  125. package/dist/bindings/serde_json/JsonValue.js +0 -3
  126. package/dist/commands.d.ts +0 -17
  127. package/dist/commands.js +0 -24
  128. package/dist/components/navigation.d.ts +0 -154
  129. package/dist/components/navigation.js +0 -252
  130. package/dist/declaration.d.ts +0 -80
  131. package/dist/declaration.js +0 -2
  132. package/dist/events/base.d.ts +0 -16
  133. package/dist/events/base.js +0 -19
  134. package/dist/events/globals.d.ts +0 -2
  135. package/dist/events/globals.js +0 -122
  136. package/dist/events/keyboard.d.ts +0 -37
  137. package/dist/events/keyboard.js +0 -2
  138. package/dist/events/listener.d.ts +0 -1
  139. package/dist/events/listener.js +0 -13
  140. package/dist/events/mouse.d.ts +0 -15
  141. package/dist/events/mouse.js +0 -2
  142. package/dist/events/touch.d.ts +0 -16
  143. package/dist/events/touch.js +0 -2
  144. package/dist/events/wheel.d.ts +0 -9
  145. package/dist/events/wheel.js +0 -2
  146. package/dist/events.d.ts +0 -33
  147. package/dist/events.js +0 -49
  148. package/dist/hooks/useFadeInOut.d.ts +0 -16
  149. package/dist/hooks/useFadeInOut.js +0 -62
  150. package/dist/hooks/useScenario.d.ts +0 -13
  151. package/dist/hooks/useScenario.js +0 -64
  152. package/dist/hooks/useSoundEffect.d.ts +0 -4
  153. package/dist/hooks/useSoundEffect.js +0 -63
  154. package/dist/hooks/useStage.d.ts +0 -126
  155. package/dist/hooks/useStage.js +0 -706
  156. package/dist/hooks.d.ts +0 -4
  157. package/dist/hooks.js +0 -20
  158. package/dist/lib.js +0 -54
  159. package/dist/moyu.d.ts +0 -19
  160. package/dist/moyu.js +0 -49
  161. package/dist/node.d.ts +0 -16
  162. package/dist/node.js +0 -105
  163. package/dist/react.d.ts +0 -20
  164. package/dist/react.js +0 -222
  165. package/dist/runtime-globals.d.ts +0 -65
  166. package/dist/runtime-globals.js +0 -2
  167. package/dist/sandbox.d.ts +0 -1
  168. package/dist/sandbox.js +0 -88
  169. package/dist/spring/animated.d.ts +0 -27
  170. package/dist/spring/animated.js +0 -2
  171. package/dist/spring/index.d.ts +0 -5
  172. package/dist/spring/index.js +0 -38
  173. package/dist/spring/primitives.d.ts +0 -3
  174. package/dist/spring/primitives.js +0 -13
  175. package/dist/state.d.ts +0 -6
  176. package/dist/state.js +0 -8
  177. package/dist/utils.d.ts +0 -10
  178. package/dist/utils.js +0 -10
  179. package/dist/zod-patch.d.ts +0 -10
  180. package/dist/zod-patch.js +0 -2
  181. package/jsx-runtime.d.ts +0 -1
package/dist/lib.mjs ADDED
@@ -0,0 +1,1534 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+
19
+ // src/lib.ts
20
+ var lib_exports = {};
21
+ __export(lib_exports, {
22
+ MoyuRenderer: () => MoyuRenderer,
23
+ OverlayParamsContext: () => OverlayParamsContext,
24
+ PageParamsContext: () => PageParamsContext,
25
+ StageContextProvider: () => StageContextProvider,
26
+ a: () => animated,
27
+ addEventListener: () => addEventListener,
28
+ animated: () => animated,
29
+ autoState: () => autoState,
30
+ createBubbleEvent: () => createBubbleEvent,
31
+ createRoot: () => createRoot,
32
+ createStackNavigator: () => createStackNavigator,
33
+ createStage: () => createStage,
34
+ createStaticNavigation: () => createStaticNavigation,
35
+ executeNodeCommand: () => executeNodeCommand,
36
+ executePluginCommand: () => executePluginCommand,
37
+ getNavigator: () => getNavigator,
38
+ getStageSize: () => getStageSize,
39
+ globalEventListeners: () => globalEventListeners,
40
+ globalRequestAnimationFrameListeners: () => globalRequestAnimationFrameListeners,
41
+ moyu: () => moyu_exports,
42
+ nextLine: () => nextLine,
43
+ setDefaultAutoTailMs: () => setDefaultAutoTailMs,
44
+ setWaiting: () => setWaiting,
45
+ skipState: () => skipState,
46
+ useAutoBlocker: () => useAutoBlocker,
47
+ useAutoTicket: () => useAutoTicket,
48
+ useBeforeHandleCommandCallback: () => useBeforeHandleCommandCallback,
49
+ useFadeIn: () => useFadeIn,
50
+ useFadeInOut: () => useFadeInOut,
51
+ useFadeOut: () => useFadeOut,
52
+ useInterruptCallback: () => useInterruptCallback,
53
+ useIsAutoing: () => useIsAutoing,
54
+ useIsSkipping: () => useIsSkipping,
55
+ useNavigation: () => useNavigation,
56
+ useNavigationParams: () => useNavigationParams,
57
+ useNavigationState: () => useNavigationState,
58
+ useScenario: () => useScenario,
59
+ useSkipBlocker: () => useSkipBlocker,
60
+ useSkipCallback: () => useSkipCallback,
61
+ useSoundEffect: () => useSoundEffect,
62
+ useStageContext: () => useStageContext
63
+ });
64
+
65
+ // src/react.ts
66
+ import React from "react";
67
+ import Reconciler from "react-reconciler";
68
+ import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants.js";
69
+
70
+ // src/moyu.ts
71
+ var moyu_exports = {};
72
+ __export(moyu_exports, {
73
+ addChild: () => addChild,
74
+ createInstance: () => createInstance,
75
+ destroyInstance: () => destroyInstance,
76
+ executeNodeCommand: () => executeNodeCommand,
77
+ executePluginCommand: () => executePluginCommand,
78
+ insertChild: () => insertChild,
79
+ insertChildBefore: () => insertChildBefore,
80
+ removeChild: () => removeChild,
81
+ removeChildAt: () => removeChildAt,
82
+ updateProps: () => updateProps
83
+ });
84
+ function createInstance(nodeType, label, props) {
85
+ let node_id = 0;
86
+ const ret = moyu.pushCommand("create_instance", [nodeType, label, props], (id) => {
87
+ node_id = id;
88
+ });
89
+ if (ret) {
90
+ return ret;
91
+ }
92
+ return node_id;
93
+ }
94
+ function destroyInstance(nodeId) {
95
+ moyu.pushCommand("destroy_instance", [nodeId]);
96
+ }
97
+ function addChild(nodeId, childNodeId) {
98
+ moyu.pushCommand("add_child", [nodeId, childNodeId]);
99
+ }
100
+ function insertChild(nodeId, index, childNodeId) {
101
+ moyu.pushCommand("insert_child", [nodeId, index, childNodeId]);
102
+ }
103
+ function insertChildBefore(nodeId, beforeChildNodeId, childNodeId) {
104
+ moyu.pushCommand("insert_child_before", [nodeId, beforeChildNodeId, childNodeId]);
105
+ }
106
+ function removeChildAt(nodeId, index) {
107
+ moyu.pushCommand("remove_child_at", [nodeId, index]);
108
+ }
109
+ function removeChild(nodeId, childNodeId) {
110
+ moyu.pushCommand("remove_child", [nodeId, childNodeId]);
111
+ }
112
+ function updateProps(nodeId, props) {
113
+ moyu.pushCommand("update_props", [nodeId, props]);
114
+ }
115
+ function executeNodeCommand(nodeId, payload) {
116
+ return moyu.executeNodeCommand(nodeId, payload);
117
+ }
118
+ function executePluginCommand(pluginName, payload) {
119
+ return moyu.executePluginCommand(pluginName, payload);
120
+ }
121
+
122
+ // src/state.ts
123
+ var STATE = {
124
+ nodeMap: {},
125
+ touchMoved: {}
126
+ };
127
+
128
+ // src/node.ts
129
+ var Node = class _Node {
130
+ nodeId;
131
+ label;
132
+ props = {};
133
+ listeners = {};
134
+ static create(label, type, props) {
135
+ const { children: _, ...rest } = props;
136
+ const node = new _Node();
137
+ node.label = label;
138
+ const [restProps, listeners] = filterProps(rest);
139
+ node.props = restProps;
140
+ node.listeners = listeners;
141
+ node.nodeId = createInstance(type, label, restProps);
142
+ STATE.nodeMap[node.nodeId] = node;
143
+ return node;
144
+ }
145
+ static rootNode() {
146
+ const node = new _Node();
147
+ node.label = "rootNode";
148
+ node.nodeId = 0;
149
+ return node;
150
+ }
151
+ addChild(child) {
152
+ addChild(this.nodeId, child.nodeId);
153
+ }
154
+ insertChild(_index, child) {
155
+ insertChild(this.nodeId, 0, child.nodeId);
156
+ }
157
+ insertChildBefore(beforeChild, child) {
158
+ insertChildBefore(this.nodeId, beforeChild.nodeId, child.nodeId);
159
+ }
160
+ // removeChildAt(index: number): Node | undefined {
161
+ // return this.children.splice(index, 1)[0];
162
+ // }
163
+ removeChild(child) {
164
+ removeChild(this.nodeId, child.nodeId);
165
+ destroyInstance(child.nodeId);
166
+ }
167
+ updateProps(props) {
168
+ const [restProps, listeners] = filterProps(props);
169
+ Object.assign(this.props, restProps);
170
+ Object.assign(this.listeners, listeners);
171
+ if (Object.keys(restProps).length > 0) {
172
+ updateProps(this.nodeId, restProps);
173
+ }
174
+ }
175
+ executeCommand(payload) {
176
+ return executeNodeCommand(this.nodeId, payload);
177
+ }
178
+ };
179
+ function filterProps(props) {
180
+ const ret = {};
181
+ const listeners = {};
182
+ for (const key in props) {
183
+ if (key.startsWith("on")) {
184
+ listeners[key] = props[key];
185
+ } else {
186
+ ret[key] = props[key];
187
+ }
188
+ }
189
+ return [ret, listeners];
190
+ }
191
+
192
+ // src/react.ts
193
+ var currentUpdatePriority = NoEventPriority;
194
+ var hostConfig = {
195
+ isPrimaryRenderer: true,
196
+ supportsHydration: false,
197
+ supportsMutation: true,
198
+ supportsPersistence: false,
199
+ /**
200
+ * @required
201
+ */
202
+ createInstance(type, props, _root, _hostContext, _internalInstanceHandle) {
203
+ const node = Node.create(props.label ?? "", type, props);
204
+ return node;
205
+ },
206
+ /**
207
+ * throw if not supported
208
+ * @required
209
+ */
210
+ createTextInstance(_text, _rootContainerInstance, _hostContext, _internalInstanceHandle) {
211
+ throw new Error("Text nodes are not supported yet");
212
+ },
213
+ /**
214
+ * @required
215
+ */
216
+ appendInitialChild(parentInstance, child) {
217
+ parentInstance.addChild(child);
218
+ },
219
+ /**
220
+ * return true if needs `commitMount`
221
+ * @required
222
+ */
223
+ finalizeInitialChildren(_parentInstance, _type, _props, _rootContainerInstance, _hostContext) {
224
+ return true;
225
+ },
226
+ shouldSetTextContent(_type, _props) {
227
+ return false;
228
+ },
229
+ getRootHostContext: (_rootContainerInstance) => {
230
+ return {};
231
+ },
232
+ getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {
233
+ return _parentHostContext;
234
+ },
235
+ getPublicInstance(node) {
236
+ return node;
237
+ },
238
+ prepareForCommit(_containerInfo) {
239
+ return null;
240
+ },
241
+ resetAfterCommit(_container) {
242
+ },
243
+ preparePortalMount: () => {
244
+ },
245
+ scheduleTimeout: setTimeout,
246
+ cancelTimeout: clearTimeout,
247
+ noTimeout: -1,
248
+ // optional
249
+ appendChild(parent, child) {
250
+ parent.addChild(child);
251
+ },
252
+ appendChildToContainer(container, child) {
253
+ container.addChild(child);
254
+ },
255
+ insertBefore: (parent, child, before) => {
256
+ parent.insertChildBefore(before, child);
257
+ },
258
+ insertInContainerBefore: (parent, child, before) => {
259
+ parent.insertChildBefore(before, child);
260
+ },
261
+ removeChild: (parent, child) => {
262
+ parent.removeChild(child);
263
+ },
264
+ removeChildFromContainer: (parent, child) => {
265
+ parent.removeChild(child);
266
+ },
267
+ finalizeContainerChildren: () => {
268
+ },
269
+ commitMount(_instance, _type, _props, _internalInstanceHandle) {
270
+ },
271
+ commitUpdate(instance, _type, prevProps, nextProps, _internalHandle) {
272
+ const { label: _oldLabel, children: _oldChildren, ...oldProps } = prevProps;
273
+ const { label, children, ...newProps } = nextProps;
274
+ const changedProps = {};
275
+ for (const key in newProps) {
276
+ if (newProps[key] !== oldProps[key]) {
277
+ changedProps[key] = newProps[key];
278
+ }
279
+ }
280
+ for (const key in oldProps) {
281
+ if (!(key in newProps)) {
282
+ changedProps[key] = null;
283
+ }
284
+ }
285
+ if (label !== _oldLabel) {
286
+ changedProps.label = label ?? null;
287
+ }
288
+ if (Object.keys(changedProps).length) {
289
+ instance.updateProps(changedProps);
290
+ }
291
+ },
292
+ commitTextUpdate: (_textInstance, _oldText, _newText) => {
293
+ },
294
+ clearContainer: (_container) => {
295
+ },
296
+ getInstanceFromNode(_node) {
297
+ console.error("getInstanceFromNode not implement");
298
+ throw new Error("Function not implemented.");
299
+ },
300
+ beforeActiveInstanceBlur: () => {
301
+ console.error("beforeActiveInstanceBlur not implement");
302
+ },
303
+ afterActiveInstanceBlur: () => {
304
+ console.error("afterActiveInstanceBlur not implement");
305
+ },
306
+ prepareScopeUpdate: (_scopeInstance, _instance) => {
307
+ console.error("prepareScopeUpdate not implement");
308
+ },
309
+ getInstanceFromScope: (_scopeInstance) => {
310
+ console.error("getInstanceFromScope not implement");
311
+ return null;
312
+ },
313
+ detachDeletedInstance: (_node) => {
314
+ },
315
+ NotPendingTransition: void 0,
316
+ // see https://github.com/pmndrs/react-three-fiber/blob/2541e81fb6ddc22d0869b9eb5cdbedcbbc62324c/packages/fiber/src/core/reconciler.tsx#L570
317
+ HostTransitionContext: /* @__PURE__ */ React.createContext(
318
+ null
319
+ ),
320
+ setCurrentUpdatePriority(newPriority) {
321
+ currentUpdatePriority = newPriority;
322
+ },
323
+ getCurrentUpdatePriority() {
324
+ return currentUpdatePriority;
325
+ },
326
+ resolveUpdatePriority() {
327
+ if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
328
+ return DefaultEventPriority;
329
+ },
330
+ resetFormInstance() {
331
+ },
332
+ requestPostPaintCallback() {
333
+ },
334
+ shouldAttemptEagerTransition: () => false,
335
+ trackSchedulerEvent: () => {
336
+ },
337
+ resolveEventType: () => null,
338
+ resolveEventTimeStamp: () => -1.1,
339
+ maySuspendCommit: () => false,
340
+ preloadInstance: () => true,
341
+ startSuspendingCommit() {
342
+ },
343
+ suspendInstance() {
344
+ },
345
+ waitForCommitToBeReady: () => null
346
+ };
347
+ var MoyuRenderer = Reconciler(hostConfig);
348
+ function createRoot(options) {
349
+ const rootNode = Node.rootNode();
350
+ const rootElement = MoyuRenderer.createContainer(
351
+ rootNode,
352
+ 0,
353
+ null,
354
+ false,
355
+ false,
356
+ options?.identifierPrefix ?? "moyu",
357
+ options?.onUncaughtError ?? ((err) => {
358
+ console.error("uncaught error: ", err);
359
+ }),
360
+ options?.onCaughtError ?? ((err) => {
361
+ console.error("caught error: ", err);
362
+ }),
363
+ options?.onRecoverableError ?? ((err) => {
364
+ console.error("unrecoverable error: ", err);
365
+ }),
366
+ options?.onDefaultTransitionIndicator ?? (() => {
367
+ })
368
+ );
369
+ MoyuRenderer.injectIntoDevTools({
370
+ bundleType: process.env.NODE_ENV === "production" ? 0 : 1,
371
+ version: "0.1.0",
372
+ rendererPackageName: "@momoyu-ink/kit",
373
+ // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
374
+ findFiberByHostInstance: (instance) => {
375
+ return instance;
376
+ }
377
+ });
378
+ return {
379
+ render: (reactElement, callback) => {
380
+ return MoyuRenderer.updateContainer(reactElement, rootElement, null, callback);
381
+ }
382
+ };
383
+ }
384
+
385
+ // src/sandbox.ts
386
+ var JS_GLOBAL_KEYS = new Set(Object.getOwnPropertyNames(globalThis));
387
+ var JS_GLOBAL_KEYS_EXCLUDED = /* @__PURE__ */ new Set(["window", "globalThis", "ARCHIVE", "GLOBAL"]);
388
+ JS_GLOBAL_KEYS_EXCLUDED.forEach((key) => JS_GLOBAL_KEYS.delete(key));
389
+ var archiveVariables = new Proxy(
390
+ {},
391
+ {
392
+ get(_, key) {
393
+ if (typeof key === "string") {
394
+ return executePluginCommand("scenario", {
395
+ subCommand: "getVariable",
396
+ name: key
397
+ });
398
+ }
399
+ return void 0;
400
+ },
401
+ set(_, key, value) {
402
+ if (typeof key === "string") {
403
+ executePluginCommand("scenario", {
404
+ subCommand: "setVariable",
405
+ name: key,
406
+ value
407
+ });
408
+ return true;
409
+ }
410
+ return false;
411
+ }
412
+ }
413
+ );
414
+ var globalVariables = new Proxy(
415
+ {},
416
+ {
417
+ get(_, key) {
418
+ if (typeof key === "string") {
419
+ return executePluginCommand("scenario", {
420
+ subCommand: "getPermanentVariable",
421
+ key
422
+ });
423
+ }
424
+ return void 0;
425
+ },
426
+ set(_, key, value) {
427
+ if (typeof key === "string") {
428
+ executePluginCommand("scenario", {
429
+ subCommand: "setPermanentVariable",
430
+ key,
431
+ value
432
+ });
433
+ return true;
434
+ }
435
+ return false;
436
+ }
437
+ }
438
+ );
439
+ function safeEval(code, sandbox) {
440
+ const proxy3 = new Proxy(sandbox, {
441
+ has(target, key) {
442
+ if (typeof key === "string" && JS_GLOBAL_KEYS.has(key)) {
443
+ return false;
444
+ }
445
+ return key in target || key === "ARCHIVE" || key === "GLOBAL" || key === "window" || key === "globalThis";
446
+ },
447
+ get(target, key) {
448
+ if (key === "window" || key === "globalThis") return proxy3;
449
+ if (key === "ARCHIVE") return archiveVariables;
450
+ if (key === "GLOBAL") return globalVariables;
451
+ if (key === Symbol.unscopables) return void 0;
452
+ return target[key];
453
+ },
454
+ set(target, key, value) {
455
+ target[key] = value;
456
+ return true;
457
+ }
458
+ });
459
+ return new Function("sandbox", `with(sandbox) { return (${code}) }`).bind(proxy3)(proxy3);
460
+ }
461
+ globalThis.__moyu_eval_sandbox = (code) => {
462
+ try {
463
+ return safeEval(code, {});
464
+ } catch (err) {
465
+ console.error("Error evaluating code in sandbox:", err);
466
+ throw err;
467
+ }
468
+ };
469
+
470
+ // src/spring/index.ts
471
+ var spring_exports = {};
472
+ __export(spring_exports, {
473
+ a: () => animated,
474
+ animated: () => animated
475
+ });
476
+ import { createHost } from "@react-spring/animated";
477
+ import { Globals, colors, createStringInterpolator } from "@react-spring/shared";
478
+
479
+ // src/spring/primitives.ts
480
+ var primitives = [
481
+ "container",
482
+ "sprite",
483
+ "text",
484
+ "clip",
485
+ "filter",
486
+ "backdrop",
487
+ "animation",
488
+ "video"
489
+ ];
490
+
491
+ // src/spring/index.ts
492
+ __reExport(spring_exports, core_star);
493
+ import * as core_star from "@react-spring/core";
494
+ Globals.assign({
495
+ createStringInterpolator,
496
+ colors,
497
+ frameLoop: "always",
498
+ requestAnimationFrame: (cb) => requestAnimationFrame(cb)
499
+ });
500
+ var host = createHost(primitives, {
501
+ applyAnimatedValues(instance, props) {
502
+ instance.updateProps(props);
503
+ }
504
+ });
505
+ var animated = host.animated;
506
+
507
+ // src/lib.ts
508
+ __reExport(lib_exports, spring_exports);
509
+
510
+ // src/events/base.ts
511
+ function createBubbleEvent(body, targetId) {
512
+ const event = {
513
+ ...body,
514
+ targetId,
515
+ currentTargetId: targetId,
516
+ stopPropagation: () => {
517
+ event.bubbles = false;
518
+ },
519
+ preventDefault: () => {
520
+ event.defaultPrevented = true;
521
+ },
522
+ defaultPrevented: false,
523
+ bubbles: true
524
+ };
525
+ return event;
526
+ }
527
+
528
+ // src/events/globals.ts
529
+ var globalEventListeners = {};
530
+ var globalRequestAnimationFrameListeners = [];
531
+ var BUBBLE_EVENT_NAMES = ["mouseevent", "touchevent", "keyboardevent", "wheelevent"];
532
+ globalThis.__moyu_receive_event = (raw_event) => {
533
+ const { name, body } = raw_event;
534
+ if (BUBBLE_EVENT_NAMES.includes(name)) {
535
+ handleBubbleEvent(name, body);
536
+ } else {
537
+ switch (name) {
538
+ case "customevent": {
539
+ const { name: name2, body: _body, targetId } = body;
540
+ if (targetId === 0) {
541
+ for (const listener of globalEventListeners[name2.toLowerCase()] ?? []) {
542
+ listener(_body);
543
+ }
544
+ return;
545
+ }
546
+ STATE.nodeMap[targetId]?.listeners?.[`on${name2.charAt(0).toUpperCase() + name2.slice(1)}`]?.(_body);
547
+ return;
548
+ }
549
+ case "nodeevent": {
550
+ const { kind, targetId } = body;
551
+ if (kind === "Destory") {
552
+ delete STATE.nodeMap[targetId];
553
+ }
554
+ return;
555
+ }
556
+ case "animationframecallbackevent": {
557
+ const listeners = globalRequestAnimationFrameListeners.splice(0);
558
+ const { timestamp } = body;
559
+ for (const listener of listeners) {
560
+ listener?.(timestamp);
561
+ }
562
+ return;
563
+ }
564
+ default: {
565
+ globalEventListeners[name]?.forEach((listener) => void listener(body));
566
+ return;
567
+ }
568
+ }
569
+ }
570
+ };
571
+ function handleBubbleEvent(name, body) {
572
+ const event = createBubbleEvent(body, body.targetId);
573
+ const { kind, bubbleTargetIds } = body;
574
+ if (body.targetId !== 0) {
575
+ const node = STATE.nodeMap[body.targetId];
576
+ if (!node) {
577
+ return;
578
+ }
579
+ if (["mouseevent", "keyboardevent", "wheelevent"].includes(name)) {
580
+ node?.listeners?.[`on${kind}`]?.(event);
581
+ while (event.bubbles && bubbleTargetIds.length) {
582
+ event.currentTargetId = bubbleTargetIds.pop();
583
+ event.currentTargetLabel = STATE.nodeMap[event.currentTargetId]?.label;
584
+ STATE.nodeMap[event.currentTargetId]?.listeners?.[`on${kind}`]?.(event);
585
+ }
586
+ } else if (name === "touchevent") {
587
+ const { identifier } = body;
588
+ event.identifier = identifier;
589
+ node?.listeners?.[`on${kind}`]?.(event);
590
+ {
591
+ const _bubbleTargetIds = [...bubbleTargetIds];
592
+ while (event.bubbles && _bubbleTargetIds.length) {
593
+ event.currentTargetId = _bubbleTargetIds.pop();
594
+ event.currentTargetLabel = STATE.nodeMap[event.currentTargetId]?.label;
595
+ STATE.nodeMap[event.currentTargetId]?.listeners?.[`on${kind}`]?.(event);
596
+ }
597
+ }
598
+ if (kind === "TouchStart") {
599
+ STATE.touchMoved[identifier] = false;
600
+ } else if (kind === "TouchMove") {
601
+ STATE.touchMoved[identifier] = true;
602
+ } else if (kind === "TouchEnd" || kind === "TouchCancel") {
603
+ delete STATE.touchMoved[identifier];
604
+ }
605
+ }
606
+ }
607
+ if (event.bubbles) {
608
+ for (const listener of globalEventListeners[kind.toLowerCase()] ?? []) {
609
+ listener(event);
610
+ }
611
+ }
612
+ }
613
+ if (globalThis.__moyu_native) {
614
+ globalThis.requestAnimationFrame = (callback) => {
615
+ return globalRequestAnimationFrameListeners.push(callback) - 1;
616
+ };
617
+ globalThis.cancelAnimationFrame = (handle) => {
618
+ globalRequestAnimationFrameListeners.splice(handle, 1);
619
+ };
620
+ }
621
+
622
+ // src/events/listener.ts
623
+ function addEventListener(name, callback) {
624
+ if (!globalEventListeners[name]) {
625
+ globalEventListeners[name] = [];
626
+ }
627
+ globalEventListeners[name].push(callback);
628
+ return () => {
629
+ globalEventListeners[name] = globalEventListeners[name].filter((cb) => cb !== callback);
630
+ };
631
+ }
632
+
633
+ // src/utils.ts
634
+ function getStageSize() {
635
+ const stageSize = executePluginCommand("system", {
636
+ subCommand: "getStageSize"
637
+ });
638
+ return stageSize;
639
+ }
640
+
641
+ // src/components/navigation.tsx
642
+ import React2 from "react";
643
+ import { createContext, useContext } from "react";
644
+ import { proxy, useSnapshot } from "valtio";
645
+ var PageParamsContext = createContext(void 0);
646
+ var OverlayParamsContext = createContext(void 0);
647
+ var overlayIdCounter = 0;
648
+ var generateOverlayId = () => {
649
+ return `overlay-${++overlayIdCounter}-${Date.now()}`;
650
+ };
651
+ function validateParams(type, name, descriptor, params) {
652
+ if (!descriptor?.requiredParams) return;
653
+ const actualParams = params ?? {};
654
+ for (const key of descriptor.requiredParams) {
655
+ if (actualParams[key] === void 0) {
656
+ throw new Error(
657
+ `Navigation Error: Missing required parameter "${key}" for ${type} "${name}". Expected: { ${descriptor.requiredParams.join(", ")} }`
658
+ );
659
+ }
660
+ }
661
+ }
662
+ var globalNavigator = null;
663
+ function normalizeDescriptor(config) {
664
+ if (typeof config === "function" || config.$$typeof) {
665
+ return { component: config };
666
+ }
667
+ return config;
668
+ }
669
+ function createStackNavigator(options) {
670
+ const normalizedPages = {};
671
+ for (const [key, config] of Object.entries(options.pages)) {
672
+ normalizedPages[key] = normalizeDescriptor(config);
673
+ }
674
+ const normalizedOverlays = {};
675
+ if (options.overlays) {
676
+ for (const [key, config] of Object.entries(options.overlays)) {
677
+ normalizedOverlays[key] = normalizeDescriptor(config);
678
+ }
679
+ }
680
+ const navigationState = proxy({
681
+ currentPage: options.initialPage,
682
+ pageParams: {},
683
+ overlayStack: [],
684
+ overlayParams: {}
685
+ });
686
+ const navigator = {
687
+ navigate: (page, params) => {
688
+ if (!normalizedPages[page]) {
689
+ console.error(`Navigation Error: Page "${page}" not found in navigator configuration.`);
690
+ return;
691
+ }
692
+ validateParams("page", page, normalizedPages[page], params);
693
+ navigationState.currentPage = page;
694
+ if (params !== void 0) {
695
+ navigationState.pageParams[page] = params;
696
+ } else {
697
+ delete navigationState.pageParams[page];
698
+ }
699
+ },
700
+ goBack: () => {
701
+ console.warn("goBack() not implemented yet");
702
+ },
703
+ pushOverlay: (overlay, params) => {
704
+ if (!normalizedOverlays[overlay]) {
705
+ console.error(`Navigation Error: Overlay "${overlay}" not found in navigator configuration.`);
706
+ return;
707
+ }
708
+ validateParams("overlay", overlay, normalizedOverlays[overlay], params);
709
+ const id = generateOverlayId();
710
+ const overlayInfo = { type: overlay, id };
711
+ navigationState.overlayStack.push(overlayInfo);
712
+ if (params !== void 0) {
713
+ navigationState.overlayParams[id] = params;
714
+ }
715
+ },
716
+ popOverlay: () => {
717
+ const overlay = navigationState.overlayStack.pop();
718
+ if (overlay) {
719
+ delete navigationState.overlayParams[overlay.id];
720
+ }
721
+ },
722
+ clearOverlays: () => {
723
+ for (const overlay of navigationState.overlayStack) {
724
+ delete navigationState.overlayParams[overlay.id];
725
+ }
726
+ navigationState.overlayStack = [];
727
+ },
728
+ getCurrentPage: () => {
729
+ return navigationState.currentPage;
730
+ },
731
+ getParams: () => {
732
+ return navigationState.pageParams[navigationState.currentPage];
733
+ },
734
+ getOverlayStack: () => {
735
+ return [...navigationState.overlayStack];
736
+ },
737
+ isOverlayActive: (type) => {
738
+ return navigationState.overlayStack.some((overlay) => overlay.type === type);
739
+ },
740
+ _descriptors: {
741
+ pages: normalizedPages,
742
+ overlays: normalizedOverlays
743
+ },
744
+ _state: navigationState
745
+ };
746
+ globalNavigator = navigator;
747
+ return navigator;
748
+ }
749
+ function createStaticNavigation(navigator) {
750
+ return () => {
751
+ const navState = useSnapshot(navigator._state);
752
+ const { pages, overlays } = navigator._descriptors;
753
+ const pageDescriptor = pages[navState.currentPage];
754
+ const Page = pageDescriptor?.component || (() => null);
755
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(PageParamsContext.Provider, { value: navState.pageParams[navState.currentPage] }, /* @__PURE__ */ React2.createElement(Page, null)), navState.overlayStack.map((overlay) => {
756
+ const overlayDescriptor = overlays[overlay.type];
757
+ const OverlayComponent = overlayDescriptor?.component || (() => null);
758
+ return /* @__PURE__ */ React2.createElement(OverlayParamsContext.Provider, { key: overlay.id, value: navState.overlayParams[overlay.id] }, /* @__PURE__ */ React2.createElement(OverlayComponent, null));
759
+ }));
760
+ };
761
+ }
762
+ function getNavigator() {
763
+ if (!globalNavigator) {
764
+ throw new Error("Navigator not initialized. Call createStackNavigator first.");
765
+ }
766
+ return globalNavigator;
767
+ }
768
+ var useNavigation = getNavigator;
769
+ function useNavigationState() {
770
+ return useSnapshot(getNavigator()._state);
771
+ }
772
+ function useNavigationParams() {
773
+ const overlayParams = useContext(OverlayParamsContext);
774
+ const pageParams = useContext(PageParamsContext);
775
+ return overlayParams ?? pageParams ?? {};
776
+ }
777
+
778
+ // src/hooks/useFadeInOut.ts
779
+ function useFadeInOut(inTime, _keepTime, _outTime, pause = false, onFinished) {
780
+ const [style, api] = (0, spring_exports.useSpring)(
781
+ () => ({
782
+ from: { opacity: 0 },
783
+ to: { opacity: 1 },
784
+ config: { duration: inTime },
785
+ pause,
786
+ onRest: (result) => {
787
+ if (result.value.opacity === 1) {
788
+ void api.start({ reverse: true, delay: 1500, config: { duration: 1e3 } });
789
+ } else {
790
+ onFinished?.();
791
+ }
792
+ }
793
+ }),
794
+ []
795
+ );
796
+ const skip = () => {
797
+ api.stop();
798
+ api.set({ opacity: 0 });
799
+ onFinished?.();
800
+ };
801
+ return [style, api, skip];
802
+ }
803
+ function useFadeIn(inTime, pause = false, onFinished) {
804
+ const [style, api] = (0, spring_exports.useSpring)(
805
+ () => ({
806
+ from: { opacity: 0 },
807
+ to: { opacity: 1 },
808
+ config: { duration: inTime },
809
+ pause,
810
+ onRest: () => {
811
+ onFinished?.();
812
+ }
813
+ }),
814
+ []
815
+ );
816
+ const skip = () => {
817
+ api.stop();
818
+ api.set({ opacity: 1 });
819
+ onFinished?.();
820
+ };
821
+ return [style, api, skip];
822
+ }
823
+ function useFadeOut(outTime, pause = false, onFinished) {
824
+ const [style, api] = (0, spring_exports.useSpring)(
825
+ () => ({
826
+ from: { opacity: 1 },
827
+ to: { opacity: 0 },
828
+ config: { duration: outTime },
829
+ pause,
830
+ onRest: () => {
831
+ onFinished?.();
832
+ }
833
+ }),
834
+ []
835
+ );
836
+ const skip = () => {
837
+ api.stop();
838
+ api.set({ opacity: 1 });
839
+ onFinished?.();
840
+ };
841
+ return [style, api, skip];
842
+ }
843
+
844
+ // src/hooks/useScenario.ts
845
+ import { useEffect } from "react";
846
+ function nextLine() {
847
+ return executePluginCommand("scenario", { subCommand: "nextLine" });
848
+ }
849
+ function setWaiting(time, skippable) {
850
+ executePluginCommand("scenario", { subCommand: "setWaiting", time, skippable });
851
+ }
852
+ function useScenario(stories, startName, entryName, goNextOnLoad = false) {
853
+ useEffect(() => {
854
+ const loadScenario = async () => {
855
+ for (const story of stories) {
856
+ if (!story) continue;
857
+ try {
858
+ await executePluginCommand("scenario", {
859
+ subCommand: "addStory",
860
+ name: story
861
+ });
862
+ } catch (error) {
863
+ console.error(`Failed to load scenario:`, error);
864
+ }
865
+ }
866
+ };
867
+ void loadScenario().then(async () => {
868
+ try {
869
+ if (startName) {
870
+ await executePluginCommand("scenario", {
871
+ subCommand: "startStory",
872
+ name: startName,
873
+ entry: entryName
874
+ });
875
+ }
876
+ if (goNextOnLoad) {
877
+ await nextLine();
878
+ }
879
+ } catch (error) {
880
+ console.error(`Failed to start scenario ${startName}:`, error);
881
+ }
882
+ });
883
+ return () => {
884
+ executePluginCommand("scenario", {
885
+ subCommand: "terminateStory"
886
+ });
887
+ };
888
+ }, [stories, startName, entryName, goNextOnLoad]);
889
+ }
890
+
891
+ // src/hooks/useSoundEffect.ts
892
+ import { useCallback, useEffect as useEffect2 } from "react";
893
+ var LOADED_SOUNDS = /* @__PURE__ */ new Set();
894
+ function useSoundEffect(src) {
895
+ useEffect2(() => {
896
+ const loadSound = async () => {
897
+ try {
898
+ await executePluginCommand("audio", {
899
+ subCommand: "load",
900
+ name: src,
901
+ src
902
+ });
903
+ } catch (error) {
904
+ console.error(`Failed to load sound effect ${src}:`, error);
905
+ }
906
+ LOADED_SOUNDS.add(src);
907
+ };
908
+ let needRelease = false;
909
+ if (!LOADED_SOUNDS.has(src)) {
910
+ void loadSound();
911
+ needRelease = true;
912
+ }
913
+ return () => {
914
+ const releaseSound = () => {
915
+ try {
916
+ executePluginCommand("audio", {
917
+ subCommand: "release",
918
+ name: src
919
+ });
920
+ } catch (error) {
921
+ console.error(`Failed to release sound effect ${src}:`, error);
922
+ }
923
+ LOADED_SOUNDS.delete(src);
924
+ };
925
+ if (needRelease) {
926
+ releaseSound();
927
+ }
928
+ };
929
+ }, [src]);
930
+ return useCallback(() => {
931
+ try {
932
+ executePluginCommand("audio", {
933
+ subCommand: "play",
934
+ name: src
935
+ });
936
+ } catch (error) {
937
+ console.error(`Failed to play sound effect ${src}:`, error);
938
+ }
939
+ }, [src]);
940
+ }
941
+
942
+ // src/hooks/useStage.ts
943
+ import { createContext as createContext2, useContext as useContext2, useEffect as useEffect3, createElement, useCallback as useCallback2 } from "react";
944
+ import { proxy as proxy2, useSnapshot as useSnapshot2 } from "valtio";
945
+ var SKIP_INTERVAL_MS = 80;
946
+ var autoRuntime = {
947
+ defaultTailMs: 0
948
+ };
949
+ var skipState = proxy2({ active: false });
950
+ var autoState = proxy2({ active: false });
951
+ function useIsSkipping() {
952
+ return useSnapshot2(skipState).active;
953
+ }
954
+ function useIsAutoing() {
955
+ return useSnapshot2(autoState).active;
956
+ }
957
+ function setDefaultAutoTailMs(ms) {
958
+ if (!Number.isFinite(ms)) {
959
+ autoRuntime.defaultTailMs = 0;
960
+ return;
961
+ }
962
+ autoRuntime.defaultTailMs = Math.max(0, ms);
963
+ }
964
+ function createStage() {
965
+ let commandSchema = null;
966
+ const commandHandlers = /* @__PURE__ */ new Map();
967
+ const textLineHandlers = [];
968
+ const skipCallbacks = [];
969
+ const interruptCallbacks = [];
970
+ const skipBlockers = [];
971
+ const autoBlockers = [];
972
+ const beforeHandleCommandCallbacks = [];
973
+ function addToRegistry(registry, item) {
974
+ registry.push(item);
975
+ return () => {
976
+ const idx = registry.indexOf(item);
977
+ if (idx !== -1) registry.splice(idx, 1);
978
+ };
979
+ }
980
+ function registerCommandSchema(schema) {
981
+ if (commandSchema !== null) {
982
+ console.warn("[Stage] Command schema is already registered \u2014 overwriting.");
983
+ }
984
+ commandSchema = schema;
985
+ return () => {
986
+ if (commandSchema === schema) {
987
+ commandSchema = null;
988
+ }
989
+ };
990
+ }
991
+ function registerCommand(commands, handler) {
992
+ const names = Array.isArray(commands) ? commands : [commands];
993
+ for (const name of names) {
994
+ if (commandHandlers.has(name)) {
995
+ console.warn(`[Stage] Command handler for "${name}" is already registered \u2014 overwriting.`);
996
+ }
997
+ commandHandlers.set(name, handler);
998
+ }
999
+ return () => {
1000
+ for (const name of names) {
1001
+ if (commandHandlers.get(name) === handler) {
1002
+ commandHandlers.delete(name);
1003
+ }
1004
+ }
1005
+ };
1006
+ }
1007
+ function registerTextLine(handler) {
1008
+ return addToRegistry(textLineHandlers, handler);
1009
+ }
1010
+ function addSkipCallback(cb) {
1011
+ return addToRegistry(skipCallbacks, cb);
1012
+ }
1013
+ function addInterruptCallback(cb) {
1014
+ return addToRegistry(interruptCallbacks, cb);
1015
+ }
1016
+ function tryInterrupt() {
1017
+ for (const cb of interruptCallbacks) {
1018
+ try {
1019
+ if (cb()) return true;
1020
+ } catch (err) {
1021
+ console.error("Error in interrupt callback:", err);
1022
+ }
1023
+ }
1024
+ return false;
1025
+ }
1026
+ function addSkipBlocker(cb) {
1027
+ return addToRegistry(skipBlockers, cb);
1028
+ }
1029
+ function isAnyBlockerActive() {
1030
+ for (const cb of skipBlockers) {
1031
+ try {
1032
+ if (cb()) return true;
1033
+ } catch (err) {
1034
+ console.error("Error in skip blocker callback:", err);
1035
+ }
1036
+ }
1037
+ return false;
1038
+ }
1039
+ function addAutoBlocker(cb) {
1040
+ return addToRegistry(autoBlockers, cb);
1041
+ }
1042
+ function isAnyAutoBlockerActive() {
1043
+ for (const cb of autoBlockers) {
1044
+ try {
1045
+ if (cb()) return true;
1046
+ } catch (err) {
1047
+ console.error("Error in auto blocker callback:", err);
1048
+ }
1049
+ }
1050
+ return false;
1051
+ }
1052
+ function addBeforeHandleCommandCallback(cb) {
1053
+ return addToRegistry(beforeHandleCommandCallbacks, cb);
1054
+ }
1055
+ let _skipTimer = null;
1056
+ let _autoTimer = null;
1057
+ let _autoBarrier = null;
1058
+ let _autoResumeTimer = null;
1059
+ let _autoCollectFrame = null;
1060
+ let _autoBarrierSeq = 0;
1061
+ let _autoTicketSeq = 0;
1062
+ const _pendingAutoTickets = /* @__PURE__ */ new Map();
1063
+ function clearAutoResumeTimer() {
1064
+ if (_autoResumeTimer !== null) {
1065
+ clearTimeout(_autoResumeTimer);
1066
+ _autoResumeTimer = null;
1067
+ }
1068
+ }
1069
+ function clearAutoCollectFrame() {
1070
+ if (_autoCollectFrame !== null) {
1071
+ cancelAnimationFrame(_autoCollectFrame);
1072
+ _autoCollectFrame = null;
1073
+ }
1074
+ }
1075
+ function clearAutoBarrier() {
1076
+ clearAutoCollectFrame();
1077
+ clearAutoResumeTimer();
1078
+ _autoBarrier = null;
1079
+ }
1080
+ function clearPendingAutoTickets() {
1081
+ _pendingAutoTickets.clear();
1082
+ }
1083
+ function getActiveAutoBarrier(barrierId) {
1084
+ if (_autoBarrier === null || _autoBarrier.id !== barrierId) {
1085
+ return null;
1086
+ }
1087
+ return _autoBarrier;
1088
+ }
1089
+ function scheduleAutoResume(barrierId, delayMs) {
1090
+ clearAutoResumeTimer();
1091
+ const safeDelayMs = Number.isFinite(delayMs) ? Math.max(0, delayMs) : 0;
1092
+ _autoResumeTimer = setTimeout(() => {
1093
+ _autoResumeTimer = null;
1094
+ if (!autoState.active) return;
1095
+ if (_autoBarrier === null || _autoBarrier.id !== barrierId) return;
1096
+ _autoBarrier = null;
1097
+ void nextLine();
1098
+ }, safeDelayMs);
1099
+ }
1100
+ function trySettleAutoBarrier(barrier) {
1101
+ if (barrier.collecting || barrier.settled) return;
1102
+ const activeTickets = [...barrier.tickets.values()].filter((ticket) => !ticket.canceled);
1103
+ const hasPending = activeTickets.some((ticket) => ticket.doneAt === null);
1104
+ if (hasPending) return;
1105
+ const latestTicketReadyAt = activeTickets.reduce((maxReadyAt, ticket) => {
1106
+ const ticketReadyAt = (ticket.doneAt ?? barrier.openedAt) + ticket.tailMs;
1107
+ return Math.max(maxReadyAt, ticketReadyAt);
1108
+ }, barrier.fallbackReadyAt);
1109
+ barrier.settled = true;
1110
+ scheduleAutoResume(barrier.id, latestTicketReadyAt - Date.now());
1111
+ }
1112
+ function closeAutoCollection(barrierId) {
1113
+ const barrier = getActiveAutoBarrier(barrierId);
1114
+ if (barrier === null || barrier.settled) return;
1115
+ barrier.collecting = false;
1116
+ trySettleAutoBarrier(barrier);
1117
+ }
1118
+ function scheduleAutoCollectionClose(barrierId) {
1119
+ queueMicrotask(() => {
1120
+ const barrier = getActiveAutoBarrier(barrierId);
1121
+ if (barrier === null || barrier.settled) return;
1122
+ _autoCollectFrame = requestAnimationFrame(() => {
1123
+ _autoCollectFrame = null;
1124
+ closeAutoCollection(barrierId);
1125
+ });
1126
+ });
1127
+ }
1128
+ function markAutoTicketDone(ticket) {
1129
+ if (ticket.canceled || ticket.doneAt !== null) return;
1130
+ ticket.doneAt = Date.now();
1131
+ if (ticket.barrierId === null) return;
1132
+ const barrier = getActiveAutoBarrier(ticket.barrierId);
1133
+ if (barrier === null || barrier.settled) return;
1134
+ trySettleAutoBarrier(barrier);
1135
+ }
1136
+ function cancelAutoTicket(ticket) {
1137
+ if (ticket.canceled) return;
1138
+ ticket.canceled = true;
1139
+ if (ticket.barrierId === null) {
1140
+ _pendingAutoTickets.delete(ticket.id);
1141
+ return;
1142
+ }
1143
+ const barrier = getActiveAutoBarrier(ticket.barrierId);
1144
+ if (barrier === null || barrier.settled) return;
1145
+ trySettleAutoBarrier(barrier);
1146
+ }
1147
+ function createAutoTicketHandle(ticket) {
1148
+ return {
1149
+ done() {
1150
+ markAutoTicketDone(ticket);
1151
+ },
1152
+ cancel() {
1153
+ cancelAutoTicket(ticket);
1154
+ }
1155
+ };
1156
+ }
1157
+ function schedulePendingAutoTicketExpiry(ticketId) {
1158
+ queueMicrotask(() => {
1159
+ requestAnimationFrame(() => {
1160
+ _pendingAutoTickets.delete(ticketId);
1161
+ });
1162
+ });
1163
+ }
1164
+ function createPendingAutoTicket(options) {
1165
+ const ticketId = ++_autoTicketSeq;
1166
+ const ticket = {
1167
+ id: ticketId,
1168
+ label: options?.label,
1169
+ tailMs: options?.tailMs ?? autoRuntime.defaultTailMs,
1170
+ doneAt: null,
1171
+ canceled: false,
1172
+ barrierId: null
1173
+ };
1174
+ _pendingAutoTickets.set(ticketId, ticket);
1175
+ schedulePendingAutoTicketExpiry(ticketId);
1176
+ return createAutoTicketHandle(ticket);
1177
+ }
1178
+ function adoptPendingAutoTickets(barrier) {
1179
+ for (const [ticketId, ticket] of _pendingAutoTickets) {
1180
+ _pendingAutoTickets.delete(ticketId);
1181
+ if (ticket.canceled) continue;
1182
+ ticket.barrierId = barrier.id;
1183
+ barrier.tickets.set(ticketId, ticket);
1184
+ }
1185
+ }
1186
+ function openAutoBarrier(reason, fallbackMs) {
1187
+ const safeFallbackMs = Number.isFinite(fallbackMs) ? Math.max(0, fallbackMs) : 0;
1188
+ clearAutoBarrier();
1189
+ _autoBarrier = {
1190
+ id: ++_autoBarrierSeq,
1191
+ reason,
1192
+ collecting: true,
1193
+ openedAt: Date.now(),
1194
+ fallbackReadyAt: Date.now() + safeFallbackMs,
1195
+ tickets: /* @__PURE__ */ new Map(),
1196
+ settled: false
1197
+ };
1198
+ adoptPendingAutoTickets(_autoBarrier);
1199
+ scheduleAutoCollectionClose(_autoBarrier.id);
1200
+ }
1201
+ function issueAutoTicket(options) {
1202
+ if (!autoState.active) {
1203
+ return null;
1204
+ }
1205
+ if (_autoBarrier === null) {
1206
+ return createPendingAutoTicket(options);
1207
+ }
1208
+ if (!_autoBarrier.collecting || _autoBarrier.settled) {
1209
+ return null;
1210
+ }
1211
+ const ticketId = ++_autoTicketSeq;
1212
+ const ticket = {
1213
+ id: ticketId,
1214
+ label: options?.label,
1215
+ tailMs: options?.tailMs ?? autoRuntime.defaultTailMs,
1216
+ doneAt: null,
1217
+ canceled: false,
1218
+ barrierId: _autoBarrier.id
1219
+ };
1220
+ _autoBarrier.tickets.set(ticketId, ticket);
1221
+ return createAutoTicketHandle(ticket);
1222
+ }
1223
+ function scheduleAutoNextLine() {
1224
+ if (_autoTimer !== null) clearTimeout(_autoTimer);
1225
+ _autoTimer = setTimeout(() => {
1226
+ _autoTimer = null;
1227
+ if (!autoState.active) return;
1228
+ if (isAnyAutoBlockerActive()) {
1229
+ stopAuto();
1230
+ return;
1231
+ }
1232
+ if (_autoBarrier === null) {
1233
+ void nextLine();
1234
+ }
1235
+ }, autoRuntime.defaultTailMs);
1236
+ }
1237
+ function scheduleSkipNextLine() {
1238
+ if (_skipTimer !== null) clearTimeout(_skipTimer);
1239
+ _skipTimer = setTimeout(() => {
1240
+ _skipTimer = null;
1241
+ if (skipState.active) nextLine();
1242
+ }, SKIP_INTERVAL_MS);
1243
+ }
1244
+ function startSkip() {
1245
+ if (skipState.active) return;
1246
+ if (isAnyBlockerActive()) return;
1247
+ skipState.active = true;
1248
+ invokeSkipCallbacks();
1249
+ tryInterrupt();
1250
+ scheduleSkipNextLine();
1251
+ }
1252
+ function stopSkip() {
1253
+ skipState.active = false;
1254
+ if (_skipTimer !== null) {
1255
+ clearTimeout(_skipTimer);
1256
+ _skipTimer = null;
1257
+ nextLine();
1258
+ }
1259
+ }
1260
+ function isSkipping() {
1261
+ return skipState.active;
1262
+ }
1263
+ function startAuto() {
1264
+ if (autoState.active) return;
1265
+ if (isAnyAutoBlockerActive()) return;
1266
+ autoState.active = true;
1267
+ tryInterrupt();
1268
+ scheduleAutoNextLine();
1269
+ }
1270
+ function stopAuto() {
1271
+ autoState.active = false;
1272
+ if (_autoTimer !== null) {
1273
+ clearTimeout(_autoTimer);
1274
+ _autoTimer = null;
1275
+ }
1276
+ clearAutoBarrier();
1277
+ clearPendingAutoTickets();
1278
+ }
1279
+ function isAutoing() {
1280
+ return autoState.active;
1281
+ }
1282
+ function buildControl() {
1283
+ let handled = false;
1284
+ let unskippableFlag = false;
1285
+ const control = {
1286
+ setWaiting(time, skippable) {
1287
+ handled = true;
1288
+ if (skipState.active) {
1289
+ invokeSkipCallbacks();
1290
+ scheduleSkipNextLine();
1291
+ } else if (autoState.active) {
1292
+ if (isAnyAutoBlockerActive()) {
1293
+ stopAuto();
1294
+ setWaiting(time, skippable);
1295
+ } else {
1296
+ openAutoBarrier("wait", time);
1297
+ }
1298
+ } else {
1299
+ setWaiting(time, skippable);
1300
+ }
1301
+ },
1302
+ hold() {
1303
+ handled = true;
1304
+ if (skipState.active && !unskippableFlag) {
1305
+ if (isAnyBlockerActive()) {
1306
+ stopSkip();
1307
+ } else {
1308
+ scheduleSkipNextLine();
1309
+ }
1310
+ } else if (skipState.active && unskippableFlag) {
1311
+ stopSkip();
1312
+ } else if (autoState.active) {
1313
+ if (isAnyAutoBlockerActive()) {
1314
+ stopAuto();
1315
+ } else {
1316
+ openAutoBarrier("hold", 0);
1317
+ }
1318
+ }
1319
+ },
1320
+ nextLine() {
1321
+ handled = true;
1322
+ void nextLine();
1323
+ },
1324
+ unskippable() {
1325
+ unskippableFlag = true;
1326
+ },
1327
+ record(meta) {
1328
+ const result = executePluginCommand("scenario", {
1329
+ subCommand: "record",
1330
+ meta
1331
+ });
1332
+ if (result && typeof result.then === "function") {
1333
+ throw new Error("Scenario record command unexpectedly returned a Promise");
1334
+ }
1335
+ return result;
1336
+ }
1337
+ };
1338
+ return { control, wasHandled: () => handled };
1339
+ }
1340
+ function transformCommand(command) {
1341
+ if (commandSchema === null) {
1342
+ throw new Error("No command schema registered in Stage");
1343
+ }
1344
+ const parsed = commandSchema.safeParse({
1345
+ command: command.command,
1346
+ ...Object.fromEntries(command.arguments.map((arg) => [arg.name, arg.value]))
1347
+ });
1348
+ if (!parsed.success) {
1349
+ throw new Error(`Invalid command: ${command.command} with arguments ${JSON.stringify(command.arguments)}`);
1350
+ }
1351
+ return parsed.data;
1352
+ }
1353
+ function dispatchCommand(e) {
1354
+ for (const cb of beforeHandleCommandCallbacks) {
1355
+ try {
1356
+ cb(e);
1357
+ } catch (err) {
1358
+ console.error("Error in beforeHandleCommand callback:", err);
1359
+ }
1360
+ }
1361
+ let cmd;
1362
+ try {
1363
+ cmd = transformCommand(e);
1364
+ } catch (err) {
1365
+ console.error("Failed to transform scenario command:", err);
1366
+ void nextLine();
1367
+ return;
1368
+ }
1369
+ const handler = commandHandlers.get(cmd.command);
1370
+ if (!handler) {
1371
+ console.warn(`[Stage] No handler registered for command "${cmd.command}". Auto-advancing.`);
1372
+ void nextLine();
1373
+ return;
1374
+ }
1375
+ const { control, wasHandled } = buildControl();
1376
+ handler(cmd, control);
1377
+ if (!wasHandled()) {
1378
+ void nextLine();
1379
+ }
1380
+ }
1381
+ function dispatchTextLine(e) {
1382
+ const { control, wasHandled } = buildControl();
1383
+ for (const handler of textLineHandlers) {
1384
+ handler(e, control);
1385
+ }
1386
+ if (!wasHandled()) {
1387
+ void nextLine();
1388
+ }
1389
+ }
1390
+ function invokeSkipCallbacks() {
1391
+ for (const cb of skipCallbacks) {
1392
+ try {
1393
+ cb();
1394
+ } catch (err) {
1395
+ console.error("Error in skip callback:", err);
1396
+ }
1397
+ }
1398
+ }
1399
+ function bindEvents() {
1400
+ const cleanups = [
1401
+ addEventListener("scenariocommandline", (e) => {
1402
+ dispatchCommand(e);
1403
+ }),
1404
+ addEventListener("scenariotext", (e) => {
1405
+ dispatchTextLine(e);
1406
+ }),
1407
+ addEventListener("scenariowaiting", () => {
1408
+ console.log("still waiting...");
1409
+ }),
1410
+ addEventListener("scenariowaitingcancelled", () => {
1411
+ invokeSkipCallbacks();
1412
+ })
1413
+ ];
1414
+ return () => {
1415
+ for (const cleanup of cleanups) cleanup();
1416
+ };
1417
+ }
1418
+ return {
1419
+ registerCommandSchema,
1420
+ registerCommand,
1421
+ registerTextLine,
1422
+ addSkipCallback,
1423
+ addInterruptCallback,
1424
+ addSkipBlocker,
1425
+ addAutoBlocker,
1426
+ addBeforeHandleCommandCallback,
1427
+ issueAutoTicket,
1428
+ tryInterrupt,
1429
+ startSkip,
1430
+ stopSkip,
1431
+ isSkipping,
1432
+ startAuto,
1433
+ stopAuto,
1434
+ isAutoing,
1435
+ bindEvents
1436
+ };
1437
+ }
1438
+ var StageContext = createContext2(null);
1439
+ function useStageContext() {
1440
+ const ctx = useContext2(StageContext);
1441
+ if (!ctx) throw new Error("useStageContext must be used within StageContextProvider");
1442
+ return ctx;
1443
+ }
1444
+ function StageContextProvider({ stage, children }) {
1445
+ useEffect3(() => {
1446
+ return stage.bindEvents();
1447
+ }, [stage]);
1448
+ return createElement(StageContext.Provider, { value: stage }, children);
1449
+ }
1450
+ function useSkipCallback(callback) {
1451
+ const stage = useStageContext();
1452
+ useEffect3(() => {
1453
+ return stage.addSkipCallback(callback);
1454
+ }, [stage, callback]);
1455
+ }
1456
+ function useInterruptCallback(callback) {
1457
+ const stage = useStageContext();
1458
+ useEffect3(() => {
1459
+ return stage.addInterruptCallback(callback);
1460
+ }, [stage, callback]);
1461
+ }
1462
+ function useSkipBlocker(callback) {
1463
+ const stage = useStageContext();
1464
+ useEffect3(() => {
1465
+ return stage.addSkipBlocker(callback);
1466
+ }, [stage, callback]);
1467
+ }
1468
+ function useAutoBlocker(callback) {
1469
+ const stage = useStageContext();
1470
+ useEffect3(() => {
1471
+ return stage.addAutoBlocker(callback);
1472
+ }, [stage, callback]);
1473
+ }
1474
+ function useAutoTicket() {
1475
+ const stage = useStageContext();
1476
+ return useCallback2(
1477
+ (options) => {
1478
+ return stage.issueAutoTicket(options);
1479
+ },
1480
+ [stage]
1481
+ );
1482
+ }
1483
+ function useBeforeHandleCommandCallback(callback) {
1484
+ const stage = useStageContext();
1485
+ useEffect3(() => {
1486
+ return stage.addBeforeHandleCommandCallback(callback);
1487
+ }, [stage, callback]);
1488
+ }
1489
+
1490
+ // src/lib.ts
1491
+ export * from "@react-spring/core";
1492
+ export {
1493
+ MoyuRenderer,
1494
+ OverlayParamsContext,
1495
+ PageParamsContext,
1496
+ StageContextProvider,
1497
+ animated as a,
1498
+ addEventListener,
1499
+ animated,
1500
+ autoState,
1501
+ createBubbleEvent,
1502
+ createRoot,
1503
+ createStackNavigator,
1504
+ createStage,
1505
+ createStaticNavigation,
1506
+ executeNodeCommand,
1507
+ executePluginCommand,
1508
+ getNavigator,
1509
+ getStageSize,
1510
+ globalEventListeners,
1511
+ globalRequestAnimationFrameListeners,
1512
+ moyu_exports as moyu,
1513
+ nextLine,
1514
+ setDefaultAutoTailMs,
1515
+ setWaiting,
1516
+ skipState,
1517
+ useAutoBlocker,
1518
+ useAutoTicket,
1519
+ useBeforeHandleCommandCallback,
1520
+ useFadeIn,
1521
+ useFadeInOut,
1522
+ useFadeOut,
1523
+ useInterruptCallback,
1524
+ useIsAutoing,
1525
+ useIsSkipping,
1526
+ useNavigation,
1527
+ useNavigationParams,
1528
+ useNavigationState,
1529
+ useScenario,
1530
+ useSkipBlocker,
1531
+ useSkipCallback,
1532
+ useSoundEffect,
1533
+ useStageContext
1534
+ };