@maomaolabs/core 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MaoMao Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,239 @@
1
+ <div align="center">
2
+ <h1>@maomaolabs/core</h1>
3
+
4
+ <p>
5
+ <strong>A standalone lightweight React library that brings a complete, performant, and responsive desktop window management experience to the web.</strong>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <img src="./docs/assets/0.gif" alt="MaoMao OS Desktop Experience" width="100%" style="border-radius: 8px;" />
10
+ </p>
11
+
12
+ <p>
13
+ <a href="https://www.npmjs.com/package/@maomaolabs/core"><img src="https://img.shields.io/npm/v/@maomaolabs/core?style=for-the-badge&color=000000" alt="NPM Version" /></a>
14
+ <a href="https://github.com/maomaolabs/core/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@maomaolabs/core?style=for-the-badge&color=000000" alt="License" /></a>
15
+ <img src="https://img.shields.io/badge/React-18.0.0+-blue?style=for-the-badge&logo=react&color=000000" alt="React 18+" />
16
+ </p>
17
+ </div>
18
+
19
+ <br />
20
+
21
+ ## ✨ Key Features
22
+
23
+ **Uncompromised performance**
24
+ Zero unnecessary re-renders thanks to context splitting (`useWindows` vs `useWindowActions`).
25
+ <p align="center">
26
+ <img src="./docs/assets/1.png" alt="Performance architecture diagram" width="100%" style="border-radius: 8px;" />
27
+ </p>
28
+
29
+ **Complete window lifecycle**
30
+ Seamlessly open, close, minimize, maximize, resize, and drag windows.
31
+ <p align="center">
32
+ <img src="./docs/assets/4.gif" alt="Window lifecycle demonstration" width="100%" style="border-radius: 8px;" />
33
+ </p>
34
+
35
+ **Built-in snapping**
36
+ Native-feeling edge snapping (half screen) and corner snapping (quarter screen) functionality.
37
+ <p align="center">
38
+ <img src="./docs/assets/5.gif" alt="Window snapping demonstration" width="100%" style="border-radius: 8px;" />
39
+ </p>
40
+
41
+ **Responsive design**
42
+ Automatically adapts interactions for mobile and desktop environments.
43
+ <p align="center">
44
+ <img src="./docs/assets/6.png" alt="Responsive design showcase" width="300" style="border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1);" />
45
+ </p>
46
+
47
+ **Out-of-the-box Toolbar**
48
+ A highly customizable taskbar handling both individual apps and folder groupings.
49
+ <p align="center">
50
+ <img src="./docs/assets/7.png" alt="Toolbar demonstration" width="100%" style="border-radius: 8px;" />
51
+ </p>
52
+
53
+ ---
54
+
55
+ ## 📦 Installation
56
+
57
+ Install via your preferred package manager (requires `react` and `react-dom` >= 18.0.0):
58
+
59
+ ```bash
60
+ npm install @maomaolabs/core
61
+ # or
62
+ yarn add @maomaolabs/core
63
+ # or
64
+ pnpm add @maomaolabs/core
65
+ ```
66
+
67
+ ---
68
+
69
+ ## 🚀 Quick Start
70
+
71
+ Get a window running in under 30 seconds:
72
+
73
+ ```tsx
74
+ import { WindowSystemProvider, WindowManager, useWindowActions } from '@maomaolabs/core';
75
+ import '@maomaolabs/core/dist/style.css'; // Critical for native feeling interactions
76
+
77
+ const AppLauncher = () => {
78
+ const { openWindow } = useWindowActions();
79
+
80
+ return (
81
+ <button onClick={() => openWindow({
82
+ id: 'hello',
83
+ title: 'Hello',
84
+ component: <div>World!</div>
85
+ })}>
86
+ Launch App
87
+ </button>
88
+ );
89
+ };
90
+
91
+ export default function App() {
92
+ return (
93
+ <WindowSystemProvider>
94
+ <WindowManager />
95
+ <AppLauncher />
96
+ </WindowSystemProvider>
97
+ );
98
+ }
99
+ ```
100
+
101
+ ---
102
+
103
+ ## 📖 Detailed Usage Guide
104
+
105
+ ### Integrating the Toolbar
106
+
107
+ For a full desktop experience, include the `Toolbar` component to manage minimized windows and app launchers, including folder support.
108
+
109
+ <p align="center">
110
+ <img src="./docs/assets/2.png" alt="Toolbar integration overview" width="100%" style="border-radius: 8px;" />
111
+ </p>
112
+
113
+ ```tsx
114
+ import { WindowSystemProvider, WindowManager, Toolbar } from '@maomaolabs/core';
115
+
116
+ const DESKTOP_ITEMS = [
117
+ {
118
+ id: 'browser-app',
119
+ title: 'Browser',
120
+ component: <div />, // Your app component
121
+ initialSize: { width: 800, height: 600 }
122
+ },
123
+ {
124
+ id: 'games-folder',
125
+ title: 'Games',
126
+ apps: [
127
+ { id: 'minesweeper', title: 'Minesweeper', component: <div /> }
128
+ ]
129
+ }
130
+ ];
131
+
132
+ export default function Desktop() {
133
+ return (
134
+ <WindowSystemProvider>
135
+ <WindowManager />
136
+ <Toolbar toolbarItems={DESKTOP_ITEMS} showLogo={true} />
137
+ </WindowSystemProvider>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ### Accessing Window State
143
+
144
+ If you need to render UI based on currently open windows (e.g., a custom taskbar), use the `useWindows` hook. **Warning**: This triggers a re-render on any window state change (drag, resize, etc).
145
+
146
+ <p align="center">
147
+ <img src="./docs/assets/3.png" alt="Window state management diagram" width="100%" style="border-radius: 8px;" />
148
+ </p>
149
+
150
+ ```tsx
151
+ import { useWindows } from '@maomaolabs/core';
152
+
153
+ const OpenAppCounter = () => {
154
+ const windows = useWindows();
155
+ return <div>Active apps: {windows.length}</div>;
156
+ };
157
+ ```
158
+
159
+ ---
160
+
161
+ ## 📚 API Reference
162
+
163
+ ### Core Components
164
+
165
+ | Component | Description | Props |
166
+ | :--- | :--- | :--- |
167
+ | `WindowSystemProvider` | Context provider required for the window system. Wrap your app with this. | `children: ReactNode` |
168
+ | `WindowManager` | Renders active windows and snap overlays. Must be inside the provider. | *None* |
169
+ | `Toolbar` | Renders the taskbar with app launchers and manages minimized windows. | `toolbarItems: ToolbarItem[]`, `showLogo?: boolean` |
170
+
171
+ ### Core Hooks
172
+
173
+ **`useWindowActions()`**
174
+ Returns an object with methods to manipulate windows without subscribing to window state changes.
175
+ - `openWindow(window: WindowDefinition): void` - Opens a new window or focuses it if already open.
176
+ - `closeWindow(id: string): void` - Destroys a window instance.
177
+ - `focusWindow(id: string): void` - Brings a window to the top of the z-index stack.
178
+ - `updateWindow(id: string, data: Partial<WindowInstance>): void` - Patches an existing window's state.
179
+
180
+ **`useWindows()`**
181
+ - Returns: `WindowInstance[]` - The list of all currently active window instances.
182
+
183
+ **`useWindowSnap()`**
184
+ - Returns: `{ snapPreview: { side: 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' } | null, setSnapPreview: Function }`
185
+
186
+ ### Interfaces
187
+
188
+ **`WindowDefinition`** *(Used for opening windows)*
189
+
190
+ | Property | Type | Description |
191
+ | :--- | :--- | :--- |
192
+ | `id` | `string` | **Required.** Unique identifier for the window instance. |
193
+ | `title` | `string` | **Required.** Text displayed in the window header. |
194
+ | `component` | `React.ReactNode` | **Required.** The view to be rendered inside the window. |
195
+ | `icon` | `React.ReactNode` | Optional element (e.g., SVG/image) for headers/toolbars. |
196
+ | `initialSize` | `{ width: number; height: number }` | Optional starting dimensions. |
197
+ | `initialPosition` | `{ x: number; y: number }` | Optional starting coordinates. |
198
+ | `layer` | `'base' \| 'normal' \| 'alwaysOnTop' \| 'modal'` | Window render priority layer. |
199
+ | `isMaximized` | `boolean` | If true, spawns the window spanning the screen. |
200
+ | `canMinimize` | `boolean` | Allows the user to hide the window. |
201
+ | `canMaximize` | `boolean` | Allows the user to toggle screen-spanning. |
202
+ | `canClose` | `boolean` | Allows the user to destroy the window. |
203
+
204
+ **`FolderDefinition`** *(Used within Toolbars to group apps)*
205
+
206
+ | Property | Type | Description |
207
+ | :--- | :--- | :--- |
208
+ | `id` | `string` | **Required.** Unique identifier for the folder. |
209
+ | `title` | `string` | **Required.** Folder name. |
210
+ | `apps` | `WindowDefinition[]` | **Required.** Array of windows contained within. |
211
+ | `icon` | `React.ReactNode` | Optional visual descriptor. |
212
+
213
+ > **Note:** `ToolbarItem` is a union type of `WindowDefinition | FolderDefinition`.
214
+
215
+ ---
216
+
217
+ ## ⚙️ Configuration
218
+
219
+ This library does not use environment variables. Styling behavior is primarily managed via the required CSS import:
220
+
221
+ ```tsx
222
+ import '@maomaolabs/core/dist/style.css';
223
+ ```
224
+ Ensure your Vite/Webpack setup is configured to import and bundle CSS from `node_modules`.
225
+
226
+ ---
227
+
228
+ ## 🤝 Contribution
229
+
230
+ We welcome PRs. To run locally:
231
+ 1. `npm install`
232
+ 2. `npm run dev` to watch changes and test locally.
233
+ 3. `npm run test` before committing to ensure Vitest suites pass.
234
+
235
+ ---
236
+
237
+ ## 📝 License
238
+
239
+ MIT License. See `LICENSE` for more information.
@@ -0,0 +1,176 @@
1
+ import type { JSX as JSX_2 } from 'react/jsx-runtime';
2
+ import { default as React_2 } from 'react';
3
+ import { ReactNode } from 'react';
4
+
5
+ export declare type FolderDefinition = {
6
+ id: string;
7
+ title: string;
8
+ icon?: React_2.ReactNode;
9
+ apps: WindowDefinition[];
10
+ };
11
+
12
+ /**
13
+ * Main toolbar component. Provides all options available to open windows.
14
+ * @param windows - Array of window instances to be displayed in the toolbar.
15
+ */
16
+ export declare function Toolbar({ toolbarItems, ...props }: ToolbarProps): JSX_2.Element;
17
+
18
+ export declare type ToolbarItem = WindowDefinition | FolderDefinition;
19
+
20
+ /**
21
+ * ToolbarProps type.
22
+ * Defines the properties of the toolbar.
23
+ *
24
+ * @property {ToolbarItem[]} toolbarItems - The windows to be displayed in the toolbar.
25
+ */
26
+ declare type ToolbarProps = {
27
+ toolbarItems: ToolbarItem[];
28
+ showLogo?: boolean;
29
+ };
30
+
31
+ /**
32
+ * useWindowActions hook.
33
+ * Provides access to window actions WITHOUT triggering re-renders on state changes.
34
+ */
35
+ export declare function useWindowActions(): {
36
+ openWindow: (windowDef: WindowDefinition) => void;
37
+ closeWindow: (id: string) => void;
38
+ focusWindow: (id: string) => void;
39
+ updateWindow: (id: string, data: Partial<WindowInstance>) => void;
40
+ };
41
+
42
+ /**
43
+ * useWindows hook.
44
+ * Optimized hook for components that ONLY need the list of windows.
45
+ */
46
+ export declare function useWindows(): WindowInstance[];
47
+
48
+ /**
49
+ * useWindowSnap hook.
50
+ * Provides access to snap preview state.
51
+ */
52
+ export declare function useWindowSnap(): {
53
+ snapPreview: {
54
+ side: "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
55
+ } | null;
56
+ setSnapPreview: (preview: {
57
+ side: "left" | "right" | "top-left" | "top-right" | "bottom-left" | "bottom-right";
58
+ } | null) => void;
59
+ };
60
+
61
+ declare const Window_2: React_2.NamedExoticComponent<WindowProps>;
62
+ export { Window_2 as Window }
63
+
64
+ export declare type WindowContextState = {
65
+ size: {
66
+ width: number;
67
+ height: number;
68
+ };
69
+ position: {
70
+ x: number;
71
+ y: number;
72
+ };
73
+ isDragging: boolean;
74
+ isResizing: boolean;
75
+ drag: (e: React_2.MouseEvent) => void;
76
+ resize: (e: React_2.MouseEvent) => void;
77
+ isMinimized: boolean;
78
+ isMaximized: boolean;
79
+ isSnapped: boolean;
80
+ minimize: () => void;
81
+ maximize: () => void;
82
+ restore: () => void;
83
+ windowRef: React_2.RefObject<HTMLDivElement>;
84
+ };
85
+
86
+ /**
87
+ * WindowDefinition type.
88
+ * Defines the properties of a window.
89
+ */
90
+ export declare type WindowDefinition = {
91
+ id: string;
92
+ title: string;
93
+ icon?: React_2.ReactNode;
94
+ component: React_2.ReactNode;
95
+ initialSize?: {
96
+ width: number;
97
+ height: number;
98
+ };
99
+ initialPosition?: {
100
+ x: number;
101
+ y: number;
102
+ };
103
+ layer?: 'base' | 'normal' | 'alwaysOnTop' | 'modal';
104
+ isMaximized?: boolean;
105
+ canMinimize?: boolean;
106
+ canMaximize?: boolean;
107
+ canClose?: boolean;
108
+ };
109
+
110
+ export declare type WindowDispatch = Omit<WindowSystemProvider_2, 'windows' | 'snapPreview' | 'setSnapPreview'>;
111
+
112
+ export declare type WindowHeaderProps = {
113
+ onClose: () => void;
114
+ title: string;
115
+ icon?: React_2.ReactNode;
116
+ canMinimize?: boolean;
117
+ canMaximize?: boolean;
118
+ canClose?: boolean;
119
+ };
120
+
121
+ /**
122
+ * WindowInstance type.
123
+ * Defines the properties of a window instance.
124
+ */
125
+ export declare type WindowInstance = Omit<WindowDefinition, 'initialSize' | 'initialPosition'> & {
126
+ size: {
127
+ width: number;
128
+ height: number;
129
+ };
130
+ position: {
131
+ x: number;
132
+ y: number;
133
+ };
134
+ isMinimized?: boolean;
135
+ isMaximized?: boolean;
136
+ isSnapped?: boolean;
137
+ zIndex: number;
138
+ };
139
+
140
+ /**
141
+ * Main window manager component.
142
+ * Renders all active windows managed by the WindowSystemProvider.
143
+ *
144
+ * @returns {JSX.Element} The window manager container.
145
+ */
146
+ export declare function WindowManager(): JSX_2.Element;
147
+
148
+ export declare type WindowProps = {
149
+ window: WindowInstance;
150
+ };
151
+
152
+ export declare function WindowSystemProvider({ children }: WindowSystemProviderProps): JSX_2.Element;
153
+
154
+ /**
155
+ * WindowSystemProvider type.
156
+ * Defines the properties of the window store.
157
+ */
158
+ declare type WindowSystemProvider_2 = {
159
+ windows: WindowInstance[];
160
+ snapPreview: {
161
+ side: 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
162
+ } | null;
163
+ setSnapPreview: (preview: {
164
+ side: 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
165
+ } | null) => void;
166
+ openWindow: (window: WindowDefinition) => void;
167
+ closeWindow: (id: string) => void;
168
+ focusWindow: (id: string) => void;
169
+ updateWindow: (id: string, data: Partial<WindowInstance>) => void;
170
+ };
171
+
172
+ declare interface WindowSystemProviderProps {
173
+ children: ReactNode;
174
+ }
175
+
176
+ export { }