@maomaolabs/core 1.0.2 → 1.1.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.
package/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
  <p>
10
10
  <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>
11
11
  <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=000" alt="License" /></a>
12
+ <a href="./CHANGELOG.md"><img src="https://img.shields.io/badge/Changelog-📖-000000?style=for-the-badge" alt="Changelog" /></a>
12
13
  <img src="https://img.shields.io/badge/React-18.0.0+-blue?style=for-the-badge&logo=react&color=000000" alt="React 18+" />
13
14
  </p>
14
15
 
@@ -168,7 +169,7 @@ const OpenAppCounter = () => {
168
169
 
169
170
  | Component | Description | Props |
170
171
  | :--- | :--- | :--- |
171
- | `WindowSystemProvider` | Root context provider. Wrap your entire app with this. | `children: ReactNode` |
172
+ | `WindowSystemProvider` | Root context provider. Wrap your entire app with this. | `children: ReactNode`, `systemStyle?: SystemStyle` |
172
173
  | `WindowManager` | Renders all active windows and snap preview overlays. | — |
173
174
  | `Toolbar` | Taskbar with app launchers and folder support. | `toolbarItems: ToolbarItem[]`, `showLogo?: boolean` |
174
175
 
@@ -209,6 +210,8 @@ Returns `{ snapPreview, setSnapPreview }` for reading and controlling the active
209
210
  | `canMinimize` | `boolean` | — | Shows the minimize control. |
210
211
  | `canMaximize` | `boolean` | — | Shows the maximize/restore control. |
211
212
  | `canClose` | `boolean` | — | Shows the close control. |
213
+ | `className` | `string` | — | Inject custom CSS classes directly into the window container. |
214
+ | `style` | `React.CSSProperties` | — | Inject inline styles overriding or extending window container styles. |
212
215
 
213
216
  #### `FolderDefinition`
214
217
 
@@ -221,6 +224,15 @@ Returns `{ snapPreview, setSnapPreview }` for reading and controlling the active
221
224
 
222
225
  > `ToolbarItem = WindowDefinition | FolderDefinition`
223
226
 
227
+ #### `WindowStyling`
228
+
229
+ Exported type available for reuse in your own components:
230
+
231
+ ```ts
232
+ import type { WindowStyling } from '@maomaolabs/core';
233
+ // { className?: string; style?: React.CSSProperties }
234
+ ```
235
+
224
236
  ---
225
237
 
226
238
  ## ⚙️ Styling
@@ -233,6 +245,94 @@ import '@maomaolabs/core/dist/style.css';
233
245
 
234
246
  Ensure your bundler (Vite, Webpack, etc.) is configured to process CSS from `node_modules`.
235
247
 
248
+ ### Theming System (`systemStyle`)
249
+
250
+ The context provider accepts a `systemStyle` prop that governs the aesthetics of the entire rendered window manager system:
251
+
252
+ ```tsx
253
+ <WindowSystemProvider systemStyle="aero">
254
+ ```
255
+
256
+ Pre-bundled themes include:
257
+ - `default`
258
+ - `traffic` (colored dot buttons concept)
259
+ - `linux` (modern dark/light gradient adaptation)
260
+ - `yk2000` (classic 90s/00s retro styling)
261
+ - `aero` (translucent glass blurring)
262
+
263
+ **Note on Custom Themes**: `SystemStyle` strictly autocompletes the pre-built themes above, but mathematically permits *any* string to be passed via Type relaxation. You can pass your own `systemStyle="my-custom-theme"` alongside injected custom CSS.
264
+
265
+ ### Custom Theme Injection
266
+
267
+ You can define your own theme by creating a CSS file that targets the `data-system-style` attribute.
268
+
269
+ > ⚠️ Use standard CSS attribute selectors — **avoid `:global()`** unless your bundler explicitly supports it (e.g. CSS Modules with PostCSS).
270
+
271
+ ```css
272
+ /* my-custom-theme.css */
273
+ [data-system-style="my-custom-theme"] .window-header {
274
+ background: #1a1a2e;
275
+ color: #e0e0e0;
276
+ }
277
+
278
+ [data-system-style="my-custom-theme"] .window-controls {
279
+ gap: 6px;
280
+ }
281
+ ```
282
+
283
+ Import the CSS file anywhere in your app (e.g. `src/index.tsx`) before the provider renders:
284
+
285
+ ```tsx
286
+ import './my-custom-theme.css';
287
+ ```
288
+
289
+ Then pass the identifier to the provider:
290
+
291
+ ```tsx
292
+ <WindowSystemProvider systemStyle="my-custom-theme">
293
+ {/* ... */}
294
+ </WindowSystemProvider>
295
+ ```
296
+
297
+ #### Available CSS selectors
298
+
299
+ The following global class names are always present on the window DOM and safe to target in your theme:
300
+
301
+ | Selector | Element |
302
+ | :--- | :--- |
303
+ | `.window-container` | Root window wrapper |
304
+ | `.window-header` | Title bar (drag area) |
305
+ | `.window-title` | Title text container |
306
+ | `.window-icon` | Icon inside the title bar |
307
+ | `.window-controls` | Button group (minimize / maximize / close) |
308
+ | `.terminal-btn` | Generic control button |
309
+ | `.window-scrollbar` | Scrollable content area |
310
+ | `.window-resize-handle` | Bottom-right resize grip |
311
+
312
+ You can also target individual buttons via the `data-action` attribute:
313
+
314
+ ```css
315
+ [data-system-style="my-custom-theme"] [data-action="close"] { background: red; }
316
+ [data-system-style="my-custom-theme"] [data-action="maximize"] { background: green; }
317
+ [data-system-style="my-custom-theme"] [data-action="minimize"] { background: yellow; }
318
+ ```
319
+
320
+ #### Per-window inline overrides
321
+
322
+ Custom `className` and `style` props are accepted on each individual window definition via `openWindow()`, allowing per-instance overrides on top of the global theme:
323
+
324
+ ```tsx
325
+ openWindow({
326
+ id: 'my-app',
327
+ title: 'My App',
328
+ component: <div />,
329
+ className: 'my-extra-class',
330
+ style: { borderRadius: '16px', border: '1px solid #444' },
331
+ });
332
+ ```
333
+
334
+ These are merged after the global theme styles, so they always take precedence.
335
+
236
336
  ---
237
337
 
238
338
  ## 🤝 Contributing
package/dist/index.d.ts CHANGED
@@ -9,6 +9,8 @@ export declare type FolderDefinition = {
9
9
  apps: WindowDefinition[];
10
10
  };
11
11
 
12
+ declare type SystemStyle = (string & {}) | 'default' | 'traffic' | 'linux' | 'yk2000' | 'aero';
13
+
12
14
  /**
13
15
  * Main toolbar component. Provides all options available to open windows.
14
16
  * @param windows - Array of window instances to be displayed in the toolbar.
@@ -61,6 +63,12 @@ export declare function useWindowSnap(): {
61
63
  declare const Window_2: React_2.NamedExoticComponent<WindowProps>;
62
64
  export { Window_2 as Window }
63
65
 
66
+ export declare type WindowBehavior = {
67
+ canMinimize?: boolean;
68
+ canMaximize?: boolean;
69
+ canClose?: boolean;
70
+ };
71
+
64
72
  export declare type WindowContextState = {
65
73
  size: {
66
74
  width: number;
@@ -83,15 +91,17 @@ export declare type WindowContextState = {
83
91
  windowRef: React_2.RefObject<HTMLDivElement>;
84
92
  };
85
93
 
86
- /**
87
- * WindowDefinition type.
88
- * Defines the properties of a window.
89
- */
90
- export declare type WindowDefinition = {
94
+ export declare type WindowCore = {
91
95
  id: string;
92
- title: string;
93
- icon?: React_2.ReactNode;
94
- component: React_2.ReactNode;
96
+ layer?: 'base' | 'normal' | 'alwaysOnTop' | 'modal';
97
+ isMaximized?: boolean;
98
+ };
99
+
100
+ export declare type WindowDefinition = WindowCore & WindowPresentation & WindowGeometry & WindowBehavior & WindowStyling;
101
+
102
+ export declare type WindowDispatch = Omit<WindowSystemProvider_2, 'windows' | 'snapPreview' | 'setSnapPreview'>;
103
+
104
+ export declare type WindowGeometry = {
95
105
  initialSize?: {
96
106
  width: number;
97
107
  height: number;
@@ -100,15 +110,8 @@ export declare type WindowDefinition = {
100
110
  x: number;
101
111
  y: number;
102
112
  };
103
- layer?: 'base' | 'normal' | 'alwaysOnTop' | 'modal';
104
- isMaximized?: boolean;
105
- canMinimize?: boolean;
106
- canMaximize?: boolean;
107
- canClose?: boolean;
108
113
  };
109
114
 
110
- export declare type WindowDispatch = Omit<WindowSystemProvider_2, 'windows' | 'snapPreview' | 'setSnapPreview'>;
111
-
112
115
  export declare type WindowHeaderProps = {
113
116
  onClose: () => void;
114
117
  title: string;
@@ -145,11 +148,31 @@ export declare type WindowInstance = Omit<WindowDefinition, 'initialSize' | 'ini
145
148
  */
146
149
  export declare function WindowManager(): JSX_2.Element;
147
150
 
151
+ /**
152
+ * WindowDefinition type.
153
+ * Defines the properties of a window.
154
+ */
155
+ export declare type WindowPresentation = {
156
+ title: string;
157
+ icon?: React_2.ReactNode;
158
+ component: React_2.ReactNode;
159
+ };
160
+
148
161
  export declare type WindowProps = {
149
162
  window: WindowInstance;
150
163
  };
151
164
 
152
- export declare function WindowSystemProvider({ children }: WindowSystemProviderProps): JSX_2.Element;
165
+ /**
166
+ * WindowStyling type.
167
+ * Allows consumers to inject custom className and style into the window container.
168
+ * Kept separate from WindowPresentation to avoid collisions with HTML attribute names (e.g. `title`).
169
+ */
170
+ export declare type WindowStyling = {
171
+ className?: string;
172
+ style?: React_2.CSSProperties;
173
+ };
174
+
175
+ export declare function WindowSystemProvider({ children, systemStyle }: WindowSystemProviderProps): JSX_2.Element;
153
176
 
154
177
  /**
155
178
  * WindowSystemProvider type.
@@ -167,10 +190,12 @@ declare type WindowSystemProvider_2 = {
167
190
  closeWindow: (id: string) => void;
168
191
  focusWindow: (id: string) => void;
169
192
  updateWindow: (id: string, data: Partial<WindowInstance>) => void;
193
+ systemStyle?: SystemStyle;
170
194
  };
171
195
 
172
196
  declare interface WindowSystemProviderProps {
173
197
  children: ReactNode;
198
+ systemStyle?: SystemStyle;
174
199
  }
175
200
 
176
201
  export { }