@momoyu-ink/kit 0.4.2 → 0.5.1

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 +1610 -0
  12. package/dist/lib.d.mts +668 -0
  13. package/dist/lib.d.ts +668 -15
  14. package/dist/lib.mjs +1641 -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 -35
  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
@@ -1,252 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.useNavigation = exports.OverlayParamsContext = exports.PageParamsContext = void 0;
37
- exports.createStackNavigator = createStackNavigator;
38
- exports.createStaticNavigation = createStaticNavigation;
39
- exports.getNavigator = getNavigator;
40
- exports.useNavigationParams = useNavigationParams;
41
- const react_1 = __importStar(require("react"));
42
- const valtio_1 = require("valtio");
43
- // ============================================================================
44
- // React Contexts for Parameters
45
- // ============================================================================
46
- /**
47
- * Context for page parameters
48
- * Used to provide params to page components via React tree
49
- */
50
- exports.PageParamsContext = (0, react_1.createContext)(undefined);
51
- /**
52
- * Context for overlay parameters
53
- * Used to provide params to overlay components via React tree
54
- */
55
- exports.OverlayParamsContext = (0, react_1.createContext)(undefined);
56
- // ============================================================================
57
- // Helper Functions
58
- // ============================================================================
59
- let overlayIdCounter = 0;
60
- const generateOverlayId = () => {
61
- return `overlay-${++overlayIdCounter}-${Date.now()}`;
62
- };
63
- /**
64
- * Validate navigation parameters against descriptor schema
65
- */
66
- function validateParams(type, name, descriptor, params) {
67
- if (!descriptor?.requiredParams)
68
- return;
69
- const actualParams = params ?? {};
70
- for (const key of descriptor.requiredParams) {
71
- if (actualParams[key] === undefined) {
72
- throw new Error(`Navigation Error: Missing required parameter "${key}" for ${type} "${name}". ` +
73
- `Expected: { ${descriptor.requiredParams.join(', ')} }`);
74
- }
75
- }
76
- }
77
- // ============================================================================
78
- // Global Navigation State and Navigator
79
- // ============================================================================
80
- let globalNavigator = null;
81
- /**
82
- * Normalize page/overlay config to descriptor format
83
- * Allows shorthand syntax: Component or { component: Component, options?: {} }
84
- */
85
- function normalizeDescriptor(config) {
86
- if (typeof config === 'function' || config.$$typeof) {
87
- // It's a component (function or React element)
88
- return { component: config };
89
- }
90
- // It's already a descriptor
91
- return config;
92
- }
93
- /**
94
- * Create a stack navigator
95
- * @param options Navigator configuration
96
- * @returns Navigator instance
97
- */
98
- function createStackNavigator(options) {
99
- // Normalize pages and overlays
100
- const normalizedPages = {};
101
- for (const [key, config] of Object.entries(options.pages)) {
102
- normalizedPages[key] = normalizeDescriptor(config);
103
- }
104
- const normalizedOverlays = {};
105
- if (options.overlays) {
106
- for (const [key, config] of Object.entries(options.overlays)) {
107
- normalizedOverlays[key] = normalizeDescriptor(config);
108
- }
109
- }
110
- // Initialize navigation state
111
- const navigationState = (0, valtio_1.proxy)({
112
- currentPage: options.initialPage,
113
- pageParams: {},
114
- overlayStack: [],
115
- overlayParams: {},
116
- });
117
- // Create navigator API
118
- const navigator = {
119
- navigate: (page, params) => {
120
- // Check if page exists
121
- if (!normalizedPages[page]) {
122
- console.error(`Navigation Error: Page "${page}" not found in navigator configuration.`);
123
- return;
124
- }
125
- // Validate parameters
126
- validateParams('page', page, normalizedPages[page], params);
127
- navigationState.currentPage = page;
128
- if (params !== undefined) {
129
- navigationState.pageParams[page] = params;
130
- }
131
- else {
132
- // Clear params if no params provided
133
- delete navigationState.pageParams[page];
134
- }
135
- },
136
- goBack: () => {
137
- // TODO: Implement history stack
138
- console.warn('goBack() not implemented yet');
139
- },
140
- pushOverlay: (overlay, params) => {
141
- // Check if overlay exists
142
- if (!normalizedOverlays[overlay]) {
143
- console.error(`Navigation Error: Overlay "${overlay}" not found in navigator configuration.`);
144
- return;
145
- }
146
- // Validate parameters
147
- validateParams('overlay', overlay, normalizedOverlays[overlay], params);
148
- const id = generateOverlayId();
149
- const overlayInfo = { type: overlay, id };
150
- navigationState.overlayStack.push(overlayInfo);
151
- if (params !== undefined) {
152
- navigationState.overlayParams[id] = params;
153
- }
154
- },
155
- popOverlay: () => {
156
- const overlay = navigationState.overlayStack.pop();
157
- if (overlay) {
158
- delete navigationState.overlayParams[overlay.id];
159
- }
160
- },
161
- clearOverlays: () => {
162
- // Clear all overlay params
163
- for (const overlay of navigationState.overlayStack) {
164
- delete navigationState.overlayParams[overlay.id];
165
- }
166
- // Clear stack
167
- navigationState.overlayStack = [];
168
- },
169
- getCurrentPage: () => {
170
- return navigationState.currentPage;
171
- },
172
- getParams: () => {
173
- return navigationState.pageParams[navigationState.currentPage];
174
- },
175
- getOverlayStack: () => {
176
- return [...navigationState.overlayStack];
177
- },
178
- isOverlayActive: (type) => {
179
- return navigationState.overlayStack.some((overlay) => overlay.type === type);
180
- },
181
- _descriptors: {
182
- pages: normalizedPages,
183
- overlays: normalizedOverlays,
184
- },
185
- _state: navigationState,
186
- };
187
- // Store as global navigator
188
- globalNavigator = navigator;
189
- return navigator;
190
- }
191
- /**
192
- * Create a navigation component for a navigator
193
- * @param navigator The navigator instance
194
- * @returns A React component that renders the navigation state
195
- */
196
- function createStaticNavigation(navigator) {
197
- return () => {
198
- // navigator._state is a Valtio proxy, useSnapshot makes it reactive
199
- const navState = (0, valtio_1.useSnapshot)(navigator._state);
200
- const { pages, overlays } = navigator._descriptors;
201
- // Get current page component
202
- const pageDescriptor = pages[navState.currentPage];
203
- const Page = pageDescriptor?.component || (() => null);
204
- return (react_1.default.createElement(react_1.default.Fragment, null,
205
- react_1.default.createElement(exports.PageParamsContext.Provider, { value: navState.pageParams[navState.currentPage] },
206
- react_1.default.createElement(Page, null)),
207
- navState.overlayStack.map((overlay) => {
208
- const overlayDescriptor = overlays[overlay.type];
209
- const OverlayComponent = overlayDescriptor?.component || (() => null);
210
- return (react_1.default.createElement(exports.OverlayParamsContext.Provider, { key: overlay.id, value: navState.overlayParams[overlay.id] },
211
- react_1.default.createElement(OverlayComponent, null)));
212
- })));
213
- };
214
- }
215
- // ============================================================================
216
- // React Hooks
217
- // ============================================================================
218
- /**
219
- * Get the navigator instance (stable reference)
220
- * Can be used in both components and state logic
221
- * @returns Navigator object
222
- */
223
- function getNavigator() {
224
- if (!globalNavigator) {
225
- throw new Error('Navigator not initialized. Call createStackNavigator first.');
226
- }
227
- return globalNavigator;
228
- }
229
- /**
230
- * Hook to get the navigator instance in components
231
- */
232
- exports.useNavigation = getNavigator;
233
- /**
234
- * Get navigation parameters for current component
235
- * @returns Parameters object (cast as T)
236
- *
237
- * This hook reads params from React Context, which is provided by the router.
238
- * - If called from within an overlay context, returns overlay params
239
- * - If called from within a page context, returns page params
240
- * - Supports multiple nested overlays (each gets its own params)
241
- *
242
- * Note: We cast the result to T and provide an empty object as fallback.
243
- * Since required parameters are validated at navigation entry points, we can
244
- * safely assume the runtime object matches T.
245
- */
246
- function useNavigationParams() {
247
- const overlayParams = (0, react_1.useContext)(exports.OverlayParamsContext);
248
- const pageParams = (0, react_1.useContext)(exports.PageParamsContext);
249
- // If in overlay context, return overlay params; otherwise return page params
250
- // Default to empty object if both are undefined
251
- return (overlayParams ?? pageParams ?? {});
252
- }
@@ -1,80 +0,0 @@
1
- import type { ClassAttributes, ReactNode } from 'react';
2
- import type { Node } from './node';
3
- import type { BubbleEvent } from './events/base';
4
- import type { MouseEvent } from './events/mouse';
5
- import type { TouchEvent } from './events/touch';
6
- import type { KeyboardEvent } from './events/keyboard';
7
- import { NodeProps } from './bindings/NodeProps';
8
- import { ClipProps } from './bindings/ClipProps';
9
- import { FilterProps } from './bindings/FilterProps';
10
- import { BackdropProps } from './bindings/BackdropProps';
11
- import { SpriteProps } from './bindings/SpriteProps';
12
- import { TextProps } from './bindings/TextProps';
13
- import { AnimationProps } from './bindings/AnimationProps';
14
- import { VideoProps } from './bindings/VideoProps';
15
- export type Tuple2 = [number, number];
16
- export type Tuple3 = [number, number, number];
17
- export type Tuple4 = [number, number, number, number];
18
- export type DetailedMoyuProps<E extends MoyuNodeAttributes> = ClassAttributes<Node> & E;
19
- export type MoyuEventHandler<T extends BubbleEvent> = (event: T) => void;
20
- export interface MoyuListenerAttributes {
21
- onClick?: MoyuEventHandler<MouseEvent>;
22
- onMouseEnter?: MoyuEventHandler<MouseEvent>;
23
- onMouseLeave?: MoyuEventHandler<MouseEvent>;
24
- onMouseDown?: MoyuEventHandler<MouseEvent>;
25
- onMouseUp?: MoyuEventHandler<MouseEvent>;
26
- onMouseMove?: MoyuEventHandler<MouseEvent>;
27
- onKeyDown?: MoyuEventHandler<KeyboardEvent>;
28
- onKeyUp?: MoyuEventHandler<KeyboardEvent>;
29
- onKeyPress?: MoyuEventHandler<KeyboardEvent>;
30
- onTouchStart?: MoyuEventHandler<TouchEvent>;
31
- onTouchMove?: MoyuEventHandler<TouchEvent>;
32
- onTouchEnd?: MoyuEventHandler<TouchEvent>;
33
- onTouchCancel?: MoyuEventHandler<TouchEvent>;
34
- }
35
- export type MoyuNodeAttributes = MoyuListenerAttributes & NodeProps & {
36
- children?: ReactNode;
37
- };
38
- export type MoyuContainerAttributes = MoyuNodeAttributes;
39
- export type MoyuClipAttributes = ClipProps & MoyuNodeAttributes;
40
- export type MoyuFilterAttributes = FilterProps & MoyuNodeAttributes;
41
- export type MoyuBackdropAttributes = BackdropProps & MoyuNodeAttributes;
42
- export type MoyuAnimationAttributes = AnimationProps & MoyuNodeAttributes;
43
- export type MoyuVideoAttributes = VideoProps & MoyuNodeAttributes & {
44
- onEnded?: () => void;
45
- onStateChange?: (state: string) => void;
46
- };
47
- export type MoyuSpriteAttributes = SpriteProps & MoyuNodeAttributes;
48
- export type MoyuTextAttributes = TextProps & MoyuNodeAttributes & {
49
- onStart?: () => void;
50
- onFinish?: () => void;
51
- onProgress?: (progress: number) => void;
52
- };
53
- export declare namespace JSX {
54
- type ElementType = string | React.JSXElementConstructor<any>;
55
- interface Element extends React.ReactElement<any, any> {
56
- }
57
- interface ElementClass extends React.Component<any> {
58
- render(): React.ReactNode;
59
- }
60
- interface ElementAttributesProperty {
61
- props: {};
62
- }
63
- interface ElementChildrenAttribute {
64
- children: {};
65
- }
66
- interface IntrinsicAttributes extends React.Attributes {
67
- }
68
- interface IntrinsicClassAttributes<T> extends React.ClassAttributes<T> {
69
- }
70
- interface IntrinsicElements {
71
- container: DetailedMoyuProps<MoyuContainerAttributes>;
72
- sprite: DetailedMoyuProps<MoyuSpriteAttributes>;
73
- text: DetailedMoyuProps<MoyuTextAttributes>;
74
- clip: DetailedMoyuProps<MoyuClipAttributes>;
75
- filter: DetailedMoyuProps<MoyuFilterAttributes>;
76
- backdrop: DetailedMoyuProps<MoyuBackdropAttributes>;
77
- animation: DetailedMoyuProps<MoyuAnimationAttributes>;
78
- video: DetailedMoyuProps<MoyuVideoAttributes>;
79
- }
80
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- export interface MoyuEvent<T extends Record<string, unknown> = Record<string, unknown>> {
2
- name: string;
3
- body: T;
4
- }
5
- export interface BubbleEvent {
6
- targetId: number;
7
- bubbleTargetIds: number[];
8
- currentTargetId: number;
9
- stopPropagation: () => void;
10
- preventDefault: () => void;
11
- defaultPrevented: boolean;
12
- bubbles: boolean;
13
- }
14
- export declare function createBubbleEvent<T extends BubbleEvent>(body: Record<string, any> & {
15
- bubbleTargetIds: number[];
16
- }, targetId: number): T;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createBubbleEvent = createBubbleEvent;
4
- function createBubbleEvent(body, targetId) {
5
- const event = {
6
- ...body,
7
- targetId,
8
- currentTargetId: targetId,
9
- stopPropagation: () => {
10
- event.bubbles = false;
11
- },
12
- preventDefault: () => {
13
- event.defaultPrevented = true;
14
- },
15
- defaultPrevented: false,
16
- bubbles: true,
17
- };
18
- return event;
19
- }
@@ -1,2 +0,0 @@
1
- export declare const globalEventListeners: Record<string, ((event: any) => void)[]>;
2
- export declare const globalRequestAnimationFrameListeners: FrameRequestCallback[];
@@ -1,122 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.globalRequestAnimationFrameListeners = exports.globalEventListeners = void 0;
4
- const state_1 = require("../state");
5
- const base_1 = require("./base");
6
- exports.globalEventListeners = {};
7
- exports.globalRequestAnimationFrameListeners = [];
8
- const BUBBLE_EVENT_NAMES = ['mouseevent', 'touchevent', 'keyboardevent', 'wheelevent'];
9
- globalThis.__moyu_receive_event = (raw_event) => {
10
- const { name, body } = raw_event;
11
- if (BUBBLE_EVENT_NAMES.includes(name)) {
12
- handleBubbleEvent(name, body);
13
- }
14
- else {
15
- // handles non-dom events and return
16
- switch (name) {
17
- case 'customevent': {
18
- const { name, body: _body, targetId } = body;
19
- // if targetId is 0, it is a global event (send to root node or send from plugin)
20
- if (targetId === 0) {
21
- for (const listener of exports.globalEventListeners[name.toLowerCase()] ?? []) {
22
- listener(_body);
23
- }
24
- return;
25
- }
26
- state_1.STATE.nodeMap[targetId]?.listeners?.[`on${name.charAt(0).toUpperCase() + name.slice(1)}`]?.(_body);
27
- return;
28
- }
29
- case 'nodeevent': {
30
- const { kind, targetId } = body;
31
- if (kind === 'Destory') {
32
- delete state_1.STATE.nodeMap[targetId];
33
- }
34
- return;
35
- }
36
- case 'animationframecallbackevent': {
37
- const listeners = exports.globalRequestAnimationFrameListeners.splice(0);
38
- const { timestamp } = body;
39
- for (const listener of listeners) {
40
- listener?.(timestamp);
41
- }
42
- return;
43
- }
44
- default: {
45
- exports.globalEventListeners[name]?.forEach((listener) => listener(body));
46
- return;
47
- }
48
- }
49
- }
50
- };
51
- function handleBubbleEvent(name, body) {
52
- const event = (0, base_1.createBubbleEvent)(body, body.targetId);
53
- const { kind, bubbleTargetIds } = body;
54
- // if targetId is 0, it is a global event (send to root node or send from plugin)
55
- if (body.targetId !== 0) {
56
- const node = state_1.STATE.nodeMap[body.targetId];
57
- if (!node) {
58
- return;
59
- }
60
- if (['mouseevent', 'keyboardevent', 'wheelevent'].includes(name)) {
61
- node?.listeners?.[`on${kind}`]?.(event);
62
- while (event.bubbles && bubbleTargetIds.length) {
63
- // biome-ignore lint/style/noNonNullAssertion: we are sure that the array is not empty, it is a bug of biomejs
64
- event.currentTargetId = bubbleTargetIds.pop();
65
- event.currentTargetLabel = state_1.STATE.nodeMap[event.currentTargetId]?.label;
66
- state_1.STATE.nodeMap[event.currentTargetId]?.listeners?.[`on${kind}`]?.(event);
67
- }
68
- }
69
- else if (name === 'touchevent') {
70
- const { identifier } = body;
71
- event.identifier = identifier;
72
- node?.listeners?.[`on${kind}`]?.(event);
73
- {
74
- const _bubbleTargetIds = [...bubbleTargetIds];
75
- while (event.bubbles && _bubbleTargetIds.length) {
76
- // biome-ignore lint/style/noNonNullAssertion: we are sure that the array is not empty, it is a bug of biomejs
77
- event.currentTargetId = _bubbleTargetIds.pop();
78
- event.currentTargetLabel = state_1.STATE.nodeMap[event.currentTargetId]?.label;
79
- state_1.STATE.nodeMap[event.currentTargetId]?.listeners?.[`on${kind}`]?.(event);
80
- }
81
- }
82
- // simulate mouse events as same as browsers
83
- // if (kind === TouchEventKind.TouchEnd && !STATE.touchMoved[identifier] && !event.defaultPrevented) {
84
- // for (const eventKind of ['MouseMove', 'MouseDown', 'MouseUp', 'Click'] as MouseEventKind[]) {
85
- // event.bubbles = true;
86
- // event.kind = eventKind;
87
- // node?.listeners?.[`on${eventKind}`]?.(event);
88
- // const _bubbleTargetIds = [...bubbleTargetIds];
89
- // while (event.bubbles && _bubbleTargetIds.length) {
90
- // // biome-ignore lint/style/noNonNullAssertion: we are sure that the array is not empty, it is a bug of biomejs
91
- // event.currentTargetId = _bubbleTargetIds.pop()!;
92
- // event.currentTargetLabel = STATE.nodeMap[event.currentTargetId]?.label;
93
- // STATE.nodeMap[event.currentTargetId]?.listeners?.[`on${eventKind}`]?.(event);
94
- // }
95
- // }
96
- // }
97
- if (kind === 'TouchStart') {
98
- state_1.STATE.touchMoved[identifier] = false;
99
- }
100
- else if (kind === 'TouchMove') {
101
- state_1.STATE.touchMoved[identifier] = true;
102
- }
103
- else if (kind === 'TouchEnd' || kind === 'TouchCancel') {
104
- delete state_1.STATE.touchMoved[identifier];
105
- }
106
- }
107
- }
108
- if (event.bubbles) {
109
- for (const listener of exports.globalEventListeners[kind.toLowerCase()] ?? []) {
110
- listener(event);
111
- }
112
- }
113
- }
114
- if (globalThis.__moyu_native) {
115
- // detect if it is running in browser, if not, polyfill requestAnimationFrame
116
- globalThis.requestAnimationFrame = (callback) => {
117
- return exports.globalRequestAnimationFrameListeners.push(callback) - 1;
118
- };
119
- globalThis.cancelAnimationFrame = (handle) => {
120
- exports.globalRequestAnimationFrameListeners.splice(handle, 1);
121
- };
122
- }
@@ -1,37 +0,0 @@
1
- import { KeyboardEventKind } from '../bindings/KeyboardEventKind';
2
- import type { BubbleEvent } from './base';
3
- /**
4
- * KeyboardEvent objects describe a user interaction with the keyboard; each event describes a single interaction between the user and a key (or combination of a key with modifier keys) on the keyboard.
5
- *
6
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent)
7
- */
8
- export interface KeyboardEvent extends BubbleEvent {
9
- readonly kind: KeyboardEventKind;
10
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/altKey) */
11
- readonly altKey: boolean;
12
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/code) */
13
- readonly code: string;
14
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/ctrlKey) */
15
- readonly ctrlKey: boolean;
16
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/isComposing) */
17
- readonly isComposing: boolean;
18
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/key) */
19
- readonly key: string;
20
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/location) */
21
- readonly location: number;
22
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/metaKey) */
23
- readonly metaKey: boolean;
24
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/repeat) */
25
- readonly repeat: boolean;
26
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/shiftKey) */
27
- readonly shiftKey: boolean;
28
- /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/getModifierState)
29
- *
30
- * Not implemented yet
31
- */
32
- getModifierState(keyArg: string): boolean;
33
- readonly DOM_KEY_LOCATION_STANDARD: 0x00;
34
- readonly DOM_KEY_LOCATION_LEFT: 0x01;
35
- readonly DOM_KEY_LOCATION_RIGHT: 0x02;
36
- readonly DOM_KEY_LOCATION_NUMPAD: 0x03;
37
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export declare function addEventListener(name: string, callback: (...args: any[]) => void): () => void;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addEventListener = addEventListener;
4
- const globals_1 = require("./globals");
5
- function addEventListener(name, callback) {
6
- if (!globals_1.globalEventListeners[name]) {
7
- globals_1.globalEventListeners[name] = [];
8
- }
9
- globals_1.globalEventListeners[name].push(callback);
10
- return () => {
11
- globals_1.globalEventListeners[name] = globals_1.globalEventListeners[name].filter((cb) => cb !== callback);
12
- };
13
- }
@@ -1,15 +0,0 @@
1
- import { MouseEventKind } from '../bindings/MouseEventKind';
2
- import type { BubbleEvent } from './base';
3
- export interface MouseEvent extends BubbleEvent {
4
- kind: MouseEventKind;
5
- targetId: number;
6
- currentTargetId: number;
7
- targetLabel?: string;
8
- currentTargetLabel?: string;
9
- clientX: number;
10
- clientY: number;
11
- screenX: number;
12
- screenY: number;
13
- offsetX: number;
14
- offsetY: number;
15
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- import { TouchEventKind } from '../bindings/TouchEventKind';
2
- import type { BubbleEvent } from './base';
3
- export interface TouchEvent extends BubbleEvent {
4
- kind: TouchEventKind;
5
- targetId: number;
6
- currentTargetId: number;
7
- targetLabel: string;
8
- currentTargetLabel: string;
9
- clientX: number;
10
- clientY: number;
11
- screenX: number;
12
- screenY: number;
13
- offsetX: number;
14
- offsetY: number;
15
- identifier: number;
16
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { WheelEventDeltaMode } from '../events';
2
- import type { MouseEvent } from './mouse';
3
- export interface WheelEvent extends Omit<MouseEvent, 'kind'> {
4
- kind: 'wheel';
5
- deltaX: number;
6
- deltaY: number;
7
- deltaZ: number;
8
- deltaMode: WheelEventDeltaMode;
9
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/events.d.ts DELETED
@@ -1,33 +0,0 @@
1
- export * from './events/base';
2
- export * from './events/globals';
3
- export * from './events/keyboard';
4
- export * from './events/listener';
5
- export * from './events/mouse';
6
- export * from './events/touch';
7
- export * from './events/wheel';
8
- export * from './bindings/AnimationFrameCallbackEvent';
9
- export * from './bindings/BeforeUnloadEvent';
10
- export * from './bindings/CustomEvent';
11
- export * from './bindings/FocusEvent';
12
- export * from './bindings/FocusEventKind';
13
- export * from './bindings/FullScreenEvent';
14
- export * from './bindings/FullscreenEventKind';
15
- export * from './bindings/GameEvent';
16
- export * from './bindings/Gamepad';
17
- export * from './bindings/GamepadButton';
18
- export * from './bindings/GamepadEvent';
19
- export * from './bindings/GamepadHapticActuator';
20
- export * from './bindings/KeyboardEventKind';
21
- export * from './bindings/KeyboardLocation';
22
- export * from './bindings/Literal';
23
- export * from './bindings/MouseEventKind';
24
- export * from './bindings/NodeEvent';
25
- export * from './bindings/ResizeEvent';
26
- export * from './bindings/ResolvedArgument';
27
- export * from './bindings/ResolvedCommandLine';
28
- export * from './bindings/ResolvedSystemCallLine';
29
- export * from './bindings/TextLine';
30
- export * from './bindings/ScenarioEvent';
31
- export * from './bindings/TextEvent';
32
- export * from './bindings/TouchEventKind';
33
- export * from './bindings/WheelEventDeltaMode';