phaser-wind 0.3.0 → 0.4.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 (77) hide show
  1. package/README.md +136 -97
  2. package/dist/components/column.d.ts +1 -0
  3. package/dist/components/column.d.ts.map +1 -0
  4. package/dist/components/column.js +7 -0
  5. package/dist/components/column.js.map +1 -0
  6. package/dist/core/color.d.ts +149 -282
  7. package/dist/core/color.d.ts.map +1 -1
  8. package/dist/core/color.js +117 -298
  9. package/dist/core/color.js.map +1 -1
  10. package/dist/core/color.spec.js +46 -55
  11. package/dist/core/color.spec.js.map +1 -1
  12. package/dist/core/font-size.d.ts +36 -15
  13. package/dist/core/font-size.d.ts.map +1 -1
  14. package/dist/core/font-size.js +42 -47
  15. package/dist/core/font-size.js.map +1 -1
  16. package/dist/core/font-size.spec.js +55 -43
  17. package/dist/core/font-size.spec.js.map +1 -1
  18. package/dist/core/font.d.ts +18 -91
  19. package/dist/core/font.d.ts.map +1 -1
  20. package/dist/core/font.js +33 -174
  21. package/dist/core/font.js.map +1 -1
  22. package/dist/core/font.spec.js +45 -49
  23. package/dist/core/font.spec.js.map +1 -1
  24. package/dist/core/index.d.ts +1 -1
  25. package/dist/core/index.js +1 -1
  26. package/dist/core/{pallete.d.ts → palette.d.ts} +2 -2
  27. package/dist/core/{pallete.d.ts.map → palette.d.ts.map} +1 -1
  28. package/dist/core/{pallete.js → palette.js} +2 -2
  29. package/dist/core/{pallete.js.map → palette.js.map} +1 -1
  30. package/dist/core/radius.d.ts +19 -24
  31. package/dist/core/radius.d.ts.map +1 -1
  32. package/dist/core/radius.js +20 -28
  33. package/dist/core/radius.js.map +1 -1
  34. package/dist/core/radius.spec.js +28 -33
  35. package/dist/core/radius.spec.js.map +1 -1
  36. package/dist/core/shadow.d.ts +18 -10
  37. package/dist/core/shadow.d.ts.map +1 -1
  38. package/dist/core/shadow.js +29 -19
  39. package/dist/core/shadow.js.map +1 -1
  40. package/dist/core/shadow.spec.d.ts +2 -0
  41. package/dist/core/shadow.spec.d.ts.map +1 -0
  42. package/dist/core/shadow.spec.js +21 -0
  43. package/dist/core/shadow.spec.js.map +1 -0
  44. package/dist/core/spacing.d.ts +22 -29
  45. package/dist/core/spacing.d.ts.map +1 -1
  46. package/dist/core/spacing.js +27 -39
  47. package/dist/core/spacing.js.map +1 -1
  48. package/dist/core/spacing.spec.js +18 -29
  49. package/dist/core/spacing.spec.js.map +1 -1
  50. package/dist/exceptions.d.ts +1 -0
  51. package/dist/exceptions.d.ts.map +1 -0
  52. package/dist/exceptions.js +2 -0
  53. package/dist/exceptions.js.map +1 -0
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +1 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/plugin/index.d.ts +2 -0
  59. package/dist/plugin/index.d.ts.map +1 -0
  60. package/dist/plugin/index.js +2 -0
  61. package/dist/plugin/index.js.map +1 -0
  62. package/dist/plugin/plugin.d.ts +71 -0
  63. package/dist/plugin/plugin.d.ts.map +1 -0
  64. package/dist/plugin/plugin.js +91 -0
  65. package/dist/plugin/plugin.js.map +1 -0
  66. package/dist/theme/theme-config.d.ts +24 -48
  67. package/dist/theme/theme-config.d.ts.map +1 -1
  68. package/dist/theme/theme-config.js +4 -1
  69. package/dist/theme/theme-config.js.map +1 -1
  70. package/dist/theme/theme-manager.d.ts +1 -106
  71. package/dist/theme/theme-manager.d.ts.map +1 -1
  72. package/dist/theme/theme-manager.js +1 -187
  73. package/dist/theme/theme-manager.js.map +1 -1
  74. package/dist/theme/type.d.ts +48 -0
  75. package/dist/theme/type.d.ts.map +1 -1
  76. package/dist/theme/type.js +1 -1
  77. package/package.json +3 -3
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  >
9
9
  > **Love Tailwind CSS but stuck with Phaser?**
10
10
  >
11
- > **Welcome to Phaser Wind** - bringing the joy and simplicity of Tailwind CSS design tokens to Phaser games! 🎮✨
11
+ > **Welcome to Phaser Wind** - bring the joy and simplicity of Tailwind-like design tokens to Phaser games! 🎮✨
12
12
 
13
13
  [![NPM Version](https://img.shields.io/npm/v/phaser-wind)](https://www.npmjs.com/package/phaser-wind)
14
14
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -37,6 +37,7 @@ const title = this.add.text(200, 100, 'Game Title', {
37
37
  ### The Solution 🌟
38
38
 
39
39
  ```typescript
40
+ // No theme needed. Just import and go!
40
41
  import { Color, FontSize } from 'phaser-wind';
41
42
 
42
43
  // Clean, semantic, consistent!
@@ -56,15 +57,14 @@ const title = this.add.text(200, 100, 'Game Title', {
56
57
 
57
58
  ## 🚀 Features
58
59
 
59
- - 🎨 **Complete Tailwind Color Palette** - All 22 color families with 11 shades each
60
- - 📐 **Semantic Font Sizes** - From `xs` to `6xl`, just like Tailwind
61
- - 🎨 **Structured Theme System** - Nested design tokens for colors, fonts, spacing, typography, and effects
62
- - 🔄 **Dynamic Theme Switching** - Change themes at runtime with full type safety
63
- - 🎯 **Smart Token Resolution** - Themes can reference other theme tokens automatically
60
+ - 🎨 **Complete Tailwind-like Color Palette** - 22 families × 11 shades
61
+ - 📐 **Semantic Font Sizes** - From `xs` to `6xl`
62
+ - 🧩 **Default constants ready-to-use** - `Color`, `FontSize`, `Spacing`, `Radius`, `Shadow`
63
+ - 🧭 **Optional theme system (typed)** - Add your own tokens with strong typing
64
64
  - 🔧 **TypeScript First** - Full type safety and IntelliSense
65
- - 🎮 **Phaser Ready** - Designed specifically for Phaser 3 games
65
+ - 🎮 **Phaser Ready** - Global plugin for easy access in scenes
66
66
  - 🌈 **Consistent Design** - No more guessing colors and sizes
67
- - 📦 **Tiny Bundle** - Zero runtime overhead, just better DX
67
+ - 📦 **Tiny Bundle** - Great DX, minimal overhead
68
68
 
69
69
  ---
70
70
 
@@ -80,9 +80,9 @@ pnpm add phaser-wind
80
80
 
81
81
  ---
82
82
 
83
- ## 🎨 Color System
83
+ ## 🎨 Color System (no theme)
84
84
 
85
- ### Complete Tailwind Palette
85
+ ### Complete Palette
86
86
 
87
87
  Access all Tailwind colors with semantic naming:
88
88
 
@@ -110,7 +110,7 @@ const whiteBackground = Color.hex('white'); // 0xFFFFFF
110
110
 
111
111
  ---
112
112
 
113
- ## 📏 Font Size System
113
+ ## 📏 Font Size System (no theme)
114
114
 
115
115
  ### Semantic Sizing
116
116
 
@@ -149,116 +149,155 @@ const responsiveText = FontSize.rem('xl'); // 1.25
149
149
 
150
150
  ---
151
151
 
152
- ## 🎨 Theme System
152
+ ## 🧪 Strong typing (no theme)
153
153
 
154
- Phaser Wind includes a powerful **structured theme system** that lets you organize your design tokens into logical categories and create consistent, reusable designs.
154
+ All APIs are strongly typed. Invalid tokens break at compile time:
155
155
 
156
- ### 🏗️ **Theme Structure**
156
+ ```ts
157
+ import { Color, FontSize, Spacing, Radius, Shadow } from 'phaser-wind';
157
158
 
158
- ```typescript
159
- import { createTheme, ThemeManager } from 'phaser-wind';
159
+ // ✅ OK
160
+ Color.rgb('blue-500');
161
+ FontSize.css('lg');
162
+ Spacing.px('16');
163
+ Radius.css('sm');
164
+ Shadow.get('md');
165
+
166
+ // ❌ Compile-time errors
167
+ // Color.rgb('blue-501');
168
+ // FontSize.css('huge');
169
+ // Spacing.px('97');
170
+ // Radius.css('xxl');
171
+ // Shadow.get('mega');
172
+ ```
173
+
174
+ ---
175
+
176
+ ## 🧱 Token Reference
177
+
178
+ ### Colors
179
+
180
+ - Families: `slate`, `gray`, `zinc`, `neutral`, `stone`, `red`, `orange`, `amber`, `yellow`, `lime`, `green`, `emerald`, `teal`, `cyan`, `sky`, `blue`, `indigo`, `violet`, `purple`, `fuchsia`, `pink`, `rose`
181
+ - Shades: `50`, `100`, `200`, `300`, `400`, `500`, `600`, `700`, `800`, `900`, `950`
182
+ - Special: `black`, `white`
183
+
184
+ ### Font Size
185
+
186
+ - Keys: `xs`, `sm`, `base`, `lg`, `xl`, `2xl`, `3xl`, `4xl`, `5xl`, `6xl`
187
+
188
+ ### Spacing
189
+
190
+ - Keys (px scale ×4): `0`, `px(=1)`, `0.5`, `1`, `1.5`, `2`, `2.5`, `3`, `3.5`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `14`, `16`, `20`, `24`, `28`, `32`, `36`, `40`, `44`, `48`, `52`, `56`, `60`, `64`, `72`, `80`, `96`
191
+
192
+ ### Radius
160
193
 
161
- const gameTheme = createTheme({
194
+ - Keys: `none`, `sm`, `default`, `md`, `lg`, `xl`, `2xl`, `3xl`, `full`
195
+
196
+ ### Shadow
197
+
198
+ - Default keys: `sm`, `md`, `lg`, `xl`, `2xl`, `inner`
199
+
200
+ ---
201
+
202
+ ## 🎨 Theming (optional, typed)
203
+
204
+ Phaser Wind also provides a typed theme system via a Phaser plugin. You get the same API surface (`color`, `fontSize`, `spacing`, `radius`, `font`, `shadow`) but narrowed to your custom tokens.
205
+
206
+ ### 1) Create a theme
207
+
208
+ ```ts
209
+ import { createTheme, type CreateTheme } from 'phaser-wind';
210
+
211
+ export const theme = createTheme({
162
212
  fonts: {
163
213
  primary: 'Inter, system-ui, sans-serif',
164
- display: 'Orbitron, monospace', // Sci-fi font for headers
165
- ui: 'Roboto, Arial, sans-serif',
214
+ display: 'Orbitron, monospace',
215
+ },
216
+ fontSizes: {
217
+ // optional overrides
166
218
  },
167
219
  colors: {
168
- primary: 'purple-600',
169
- secondary: 'cyan-500',
170
- 'ui-background': 'slate-900',
171
- 'player-health': 'green-500',
172
- 'enemy-health': 'red-600',
220
+ primary: 'blue-600',
221
+ background: 'slate-900',
222
+ danger: 'red-500',
173
223
  },
174
224
  spacing: {
175
- xs: 4,
176
- sm: 8,
177
- md: 16,
178
- lg: 24,
179
- xl: 32,
225
+ gutter: 24,
180
226
  },
181
- typography: {
182
- heading: {
183
- fontSize: '2xl',
184
- fontFamily: 'fonts.display', // 🔗 References fonts.display!
185
- fontWeight: 600,
186
- lineHeight: 1.2,
187
- },
188
- body: {
189
- fontSize: 'md',
190
- fontFamily: 'fonts.primary',
191
- fontWeight: 400,
192
- lineHeight: 1.5,
193
- },
227
+ radius: {
228
+ card: 12,
194
229
  },
195
230
  effects: {
196
- 'glow-primary': {
197
- blur: 8,
198
- color: 'colors.primary', // 🔗 References colors.primary!
199
- alpha: 0.6,
200
- },
231
+ glow: { blur: 8, offsetX: 0, offsetY: 0, alpha: 0.6 },
201
232
  },
202
- // Custom categories work too!
203
- animations: {
204
- duration: 300,
205
- easing: 'ease-out',
206
- },
207
- });
233
+ } satisfies CreateTheme<any>);
208
234
 
209
- // Initialize your theme
210
- ThemeManager.init(gameTheme);
235
+ export type ThemeType = typeof theme;
211
236
  ```
212
237
 
213
- ### 🎯 **Using Theme Tokens**
214
-
215
- ```typescript
216
- import { Color, Font, FontSize, Spacing, ThemeManager } from 'phaser-wind';
217
-
218
- // Colors - automatically looks in colors.*
219
- const primaryColor = Color.rgb('primary'); // Gets colors.primary
220
- const uiBackground = Color.hex('ui-background'); // Gets colors.ui-background
221
-
222
- // Fonts
223
- const displayFont = Font.family('display'); // Gets fonts.display
224
- const primaryFont = Font.family('primary'); // Gets fonts.primary
238
+ ### 2) Install the plugin in Phaser
239
+
240
+ ```ts
241
+ import {
242
+ PhaserWindPlugin,
243
+ PHASER_WIND_KEY,
244
+ defaultLightTheme,
245
+ } from 'phaser-wind';
246
+ import { theme } from './theme';
247
+
248
+ new Phaser.Game({
249
+ plugins: {
250
+ global: [
251
+ {
252
+ key: PHASER_WIND_KEY,
253
+ plugin: PhaserWindPlugin,
254
+ mapping: PHASER_WIND_KEY, // scene.pw
255
+ data: { theme }, // or { theme: defaultLightTheme }
256
+ },
257
+ ],
258
+ },
259
+ });
260
+ ```
225
261
 
226
- // Spacing
227
- const mediumSpace = Spacing.px('md'); // Gets spacing.md (16px)
228
- const largeSpace = Spacing.px('lg'); // Gets spacing.lg (24px)
262
+ ### 3) (Optional) Module augmentation for better typing in scenes
229
263
 
230
- // Complete typography styles - using basic components for now
231
- const headingStyle = {
232
- fontSize: FontSize.css('2xl'),
233
- fontFamily: Font.family('display'),
234
- fontWeight: 'bold',
235
- };
264
+ ```ts
265
+ // types/phaser-wind.d.ts
266
+ import 'phaser';
267
+ import type { PhaserWindPlugin } from 'phaser-wind';
268
+ import type { ThemeType } from './theme';
236
269
 
237
- // Custom tokens
238
- const animDuration = ThemeManager.getToken('animations.duration'); // 300
270
+ declare module 'phaser' {
271
+ interface Scene {
272
+ pw: PhaserWindPlugin<ThemeType>;
273
+ }
274
+ }
239
275
  ```
240
276
 
241
- ### 🔄 **Dynamic Theme Switching**
242
-
243
- ```typescript
244
- // Register multiple themes
245
- ThemeManager.registerTheme('light', lightTheme);
246
- ThemeManager.registerTheme('dark', darkTheme);
247
- ThemeManager.registerTheme('cyberpunk', cyberpunkTheme);
248
-
249
- // Switch themes instantly
250
- ThemeManager.setTheme('dark');
251
-
252
- // Listen for theme changes
253
- ThemeManager.onThemeChange(newTheme => {
254
- console.log('Theme changed!', newTheme);
255
- // Update your game UI here
256
- });
277
+ ### 4) Typed usage in scenes
257
278
 
258
- // Get available themes
259
- const themes = ThemeManager.getRegisteredThemes(); // ['light', 'dark', 'cyberpunk']
279
+ ```ts
280
+ export class GameScene extends Phaser.Scene {
281
+ create() {
282
+ const { color, fontSize, spacing, radius, font, shadow } = this.pw;
283
+
284
+ // ✅ Type-narrowed to your theme
285
+ color.rgb('primary');
286
+ fontSize.css('lg');
287
+ spacing.px('gutter');
288
+ radius.css('card');
289
+ font.family('display');
290
+ shadow.get('glow');
291
+
292
+ // ❌ Compile-time errors
293
+ // color.rgb('blue-501');
294
+ // spacing.px('unknown');
295
+ }
296
+ }
260
297
  ```
261
298
 
299
+ > Note: The old `ThemeManager` API is deprecated and has been removed from the docs.
300
+
262
301
  ### 🎮 **Real Game Example**
263
302
 
264
303
  ```typescript
@@ -494,7 +533,7 @@ this.add.particles(player.x, player.y, 'sparkle', {
494
533
 
495
534
  ---
496
535
 
497
- ## 🎮 Integration with Phaser
536
+ ## 🎮 Integration with Phaser (no theme)
498
537
 
499
538
  ### Scene Setup
500
539
 
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../src/components/column.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ // export class Column extends Phaser.GameObjects.Container {
3
+ // constructor(scene: Scene, x: number, y: number, width: number, height: number, children: GameObjects.Container[]) {
4
+ // super(scene, x, y, width, height);
5
+ // }
6
+ // }
7
+ //# sourceMappingURL=column.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.js","sourceRoot":"","sources":["../../src/components/column.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,wHAAwH;AACxH,yCAAyC;AACzC,MAAM;AACN,IAAI"}