@easemate/web-kit 0.3.0 → 0.3.2
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 +203 -7
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +2 -2
- package/build/index.d.ts +2 -2
- package/build/index.js.map +1 -1
- package/build/{init-B7gNNyTd.d.ts → init-CaP7khA2.d.ts} +1 -1
- package/build/{init-DwVGVxkx.d.cts → init-DmqoRv6_.d.cts} +1 -1
- package/build/jsx.cjs.map +1 -1
- package/build/jsx.d.cts +1 -0
- package/build/jsx.d.ts +1 -0
- package/build/jsx.js.map +1 -1
- package/build/react.cjs.map +1 -1
- package/build/react.d.cts +2 -2
- package/build/react.d.ts +2 -2
- package/build/react.js.map +1 -1
- package/build/{registry-9GX9KTG1.d.cts → registry-YCv1Ctoe.d.cts} +32 -24
- package/build/{registry-9GX9KTG1.d.ts → registry-YCv1Ctoe.d.ts} +32 -24
- package/build/theme.cjs.map +1 -1
- package/build/theme.d.cts +2 -2
- package/build/theme.d.ts +2 -2
- package/build/theme.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,10 +26,13 @@ A modern, framework-agnostic UI kit of web components for building animation con
|
|
|
26
26
|
- [Selective Loading](#selective-loading)
|
|
27
27
|
- [Theme Switching](#theme-switching)
|
|
28
28
|
- [React & Next.js](#react--nextjs)
|
|
29
|
+
- [JSX Types](#jsx-types)
|
|
29
30
|
- [Basic Setup](#basic-setup)
|
|
30
31
|
- [Next.js App Router](#nextjs-app-router)
|
|
32
|
+
- [useWebKit Hook](#usewebkit-hook)
|
|
31
33
|
- [useEaseState Hook](#useeasestate-hook)
|
|
32
34
|
- [WebKit Provider](#webkit-provider)
|
|
35
|
+
- [Event Utilities](#event-utilities)
|
|
33
36
|
- [Components](#components)
|
|
34
37
|
- [Controls](#controls)
|
|
35
38
|
- [Layout & Display](#layout--display)
|
|
@@ -45,6 +48,10 @@ A modern, framework-agnostic UI kit of web components for building animation con
|
|
|
45
48
|
- [Configuration](#configuration)
|
|
46
49
|
- [initWebKit Options](#initwebkit-options)
|
|
47
50
|
- [Theme Configuration](#theme-configuration)
|
|
51
|
+
- [Custom Theme Registration](#custom-theme-registration)
|
|
52
|
+
- [Theme Inheritance](#theme-inheritance)
|
|
53
|
+
- [Creating a Theme from Scratch](#creating-a-theme-from-scratch)
|
|
54
|
+
- [Theme Utilities](#theme-utilities)
|
|
48
55
|
- [Font Configuration](#font-configuration)
|
|
49
56
|
- [Lazy Loading](#lazy-loading)
|
|
50
57
|
- [Component Replacement](#component-replacement)
|
|
@@ -177,6 +184,25 @@ kit.theme?.set('light');
|
|
|
177
184
|
|
|
178
185
|
The library provides first-class React integration via `@easemate/web-kit/react`.
|
|
179
186
|
|
|
187
|
+
### JSX Types
|
|
188
|
+
|
|
189
|
+
Importing `@easemate/web-kit/react` automatically adds JSX types for all `ease-*` custom elements:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import '@easemate/web-kit/react';
|
|
193
|
+
|
|
194
|
+
// Now ease-* elements are typed in JSX
|
|
195
|
+
<ease-panel>
|
|
196
|
+
<ease-slider name="volume" value={50} />
|
|
197
|
+
</ease-panel>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
You can also import just the JSX types separately:
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
import '@easemate/web-kit/react/jsx';
|
|
204
|
+
```
|
|
205
|
+
|
|
180
206
|
### Basic Setup
|
|
181
207
|
|
|
182
208
|
```tsx
|
|
@@ -225,6 +251,39 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
225
251
|
}
|
|
226
252
|
```
|
|
227
253
|
|
|
254
|
+
### useWebKit Hook
|
|
255
|
+
|
|
256
|
+
The `useWebKit` hook initializes the web kit and tracks readiness:
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
'use client';
|
|
260
|
+
|
|
261
|
+
import { useState, useEffect, useRef } from 'react';
|
|
262
|
+
import { useWebKit } from '@easemate/web-kit/react';
|
|
263
|
+
|
|
264
|
+
function App() {
|
|
265
|
+
const { ready, theme, dispose } = useWebKit(
|
|
266
|
+
{
|
|
267
|
+
theme: 'default',
|
|
268
|
+
styles: 'main',
|
|
269
|
+
fonts: 'default',
|
|
270
|
+
skip: false // Optional: skip initialization
|
|
271
|
+
},
|
|
272
|
+
{ useState, useEffect, useRef }
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
if (!ready) return <div>Loading...</div>;
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<ease-panel>
|
|
279
|
+
<ease-slider name="value" value="0.5" />
|
|
280
|
+
</ease-panel>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The hook manages a singleton controller internally, so multiple components using `useWebKit` will share the same initialization.
|
|
286
|
+
|
|
228
287
|
### useEaseState Hook
|
|
229
288
|
|
|
230
289
|
The `useEaseState` hook provides reactive state management for controls:
|
|
@@ -242,8 +301,18 @@ interface AnimationState {
|
|
|
242
301
|
}
|
|
243
302
|
|
|
244
303
|
function AnimationControls() {
|
|
245
|
-
const {
|
|
304
|
+
const {
|
|
305
|
+
stateRef,
|
|
306
|
+
panelRef,
|
|
307
|
+
state,
|
|
308
|
+
get,
|
|
309
|
+
set,
|
|
310
|
+
reset,
|
|
311
|
+
setTab,
|
|
312
|
+
activeTab
|
|
313
|
+
} = useEaseState<AnimationState>(
|
|
246
314
|
{
|
|
315
|
+
initialState: { duration: 1, easing: 'ease-out', loop: false },
|
|
247
316
|
onChange: ({ name, value }) => {
|
|
248
317
|
console.log(`${name} changed to ${value}`);
|
|
249
318
|
},
|
|
@@ -279,9 +348,22 @@ function AnimationControls() {
|
|
|
279
348
|
}
|
|
280
349
|
```
|
|
281
350
|
|
|
351
|
+
#### useEaseState Return Values
|
|
352
|
+
|
|
353
|
+
| Property | Type | Description |
|
|
354
|
+
|----------|------|-------------|
|
|
355
|
+
| `stateRef` | `(element: EaseStateRef \| null) => void` | Ref callback for `<ease-state>` |
|
|
356
|
+
| `panelRef` | `(element: EasePanelRef \| null) => void` | Ref callback for `<ease-panel>` |
|
|
357
|
+
| `state` | `T` | Current state values (reactive) |
|
|
358
|
+
| `get` | `(name: keyof T) => T[keyof T]` | Get a specific control value |
|
|
359
|
+
| `set` | `(name: keyof T, value: T[keyof T]) => void` | Set a control value |
|
|
360
|
+
| `reset` | `() => void` | Reset all controls to initial values |
|
|
361
|
+
| `setTab` | `(index: number) => void` | Switch panel tab |
|
|
362
|
+
| `activeTab` | `number` | Current active tab index |
|
|
363
|
+
|
|
282
364
|
### WebKit Provider
|
|
283
365
|
|
|
284
|
-
For
|
|
366
|
+
For apps needing shared context, use `createWebKitProvider`:
|
|
285
367
|
|
|
286
368
|
```tsx
|
|
287
369
|
// providers.tsx
|
|
@@ -301,7 +383,10 @@ import { WebKitProvider } from './providers';
|
|
|
301
383
|
|
|
302
384
|
export default function Layout({ children }: { children: React.ReactNode }) {
|
|
303
385
|
return (
|
|
304
|
-
<WebKitProvider
|
|
386
|
+
<WebKitProvider
|
|
387
|
+
options={{ theme: 'default', styles: 'main', fonts: 'default' }}
|
|
388
|
+
immediate={true} // Render children before ready (default: true)
|
|
389
|
+
>
|
|
305
390
|
{children}
|
|
306
391
|
</WebKitProvider>
|
|
307
392
|
);
|
|
@@ -321,6 +406,19 @@ function MyComponent() {
|
|
|
321
406
|
}
|
|
322
407
|
```
|
|
323
408
|
|
|
409
|
+
### Event Utilities
|
|
410
|
+
|
|
411
|
+
The React module exports typed event creators:
|
|
412
|
+
|
|
413
|
+
```tsx
|
|
414
|
+
import { createEventHandler, type ControlChangeEvent, type StateChangeEvent, type TabChangeEvent } from '@easemate/web-kit/react';
|
|
415
|
+
|
|
416
|
+
// Create typed event handlers
|
|
417
|
+
const handleChange = createEventHandler<ControlChangeEvent>((e) => {
|
|
418
|
+
console.log(e.detail.name, e.detail.value);
|
|
419
|
+
});
|
|
420
|
+
```
|
|
421
|
+
|
|
324
422
|
---
|
|
325
423
|
|
|
326
424
|
## Components
|
|
@@ -691,12 +789,18 @@ interface ThemeModeConfig {
|
|
|
691
789
|
dark: ThemeInput;
|
|
692
790
|
persist?: { key: string }; // Coming soon
|
|
693
791
|
}
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
#### Custom Theme Registration
|
|
694
795
|
|
|
695
|
-
|
|
796
|
+
Register custom themes using `registerTheme()`. No TypeScript declaration files needed - custom theme names are fully supported:
|
|
797
|
+
|
|
798
|
+
```typescript
|
|
696
799
|
import { initWebKit, registerTheme } from '@easemate/web-kit';
|
|
697
800
|
|
|
801
|
+
// Register a custom theme - returns a typed theme ref
|
|
698
802
|
const brandTheme = registerTheme('brand', {
|
|
699
|
-
base: 'default', // Inherit from default
|
|
803
|
+
base: 'default', // Inherit from built-in theme ('default' or 'dark')
|
|
700
804
|
config: {
|
|
701
805
|
typography: {
|
|
702
806
|
fontFamily: '"Inter", system-ui, sans-serif'
|
|
@@ -708,7 +812,99 @@ const brandTheme = registerTheme('brand', {
|
|
|
708
812
|
}
|
|
709
813
|
});
|
|
710
814
|
|
|
815
|
+
// Use the theme ref (type-safe)
|
|
711
816
|
initWebKit({ theme: brandTheme });
|
|
817
|
+
|
|
818
|
+
// Or use the string name directly (also works!)
|
|
819
|
+
initWebKit({ theme: 'brand' });
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
#### Theme Inheritance
|
|
823
|
+
|
|
824
|
+
Themes can extend other themes using the `base` option:
|
|
825
|
+
|
|
826
|
+
```typescript
|
|
827
|
+
// Create a base brand theme
|
|
828
|
+
const brandBase = registerTheme('brand-base', {
|
|
829
|
+
base: 'default',
|
|
830
|
+
config: {
|
|
831
|
+
typography: { fontFamily: '"Inter", sans-serif' },
|
|
832
|
+
vars: { '--ease-panel-radius': '16px' }
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// Create variants that extend brand-base
|
|
837
|
+
const brandLight = registerTheme('brand-light', {
|
|
838
|
+
base: brandBase, // Can use theme ref or string name
|
|
839
|
+
config: {
|
|
840
|
+
colors: {
|
|
841
|
+
gray: { 900: 'oklab(98% 0 0)', 0: 'oklab(20% 0 0)' }
|
|
842
|
+
},
|
|
843
|
+
vars: { '--ease-panel-background': 'white' }
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
const brandDark = registerTheme('brand-dark', {
|
|
848
|
+
base: 'brand-base', // String name works too
|
|
849
|
+
config: {
|
|
850
|
+
vars: { '--ease-panel-background': 'var(--color-gray-1000)' }
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
// Use with theme mode switching
|
|
855
|
+
initWebKit({
|
|
856
|
+
theme: {
|
|
857
|
+
mode: 'system',
|
|
858
|
+
light: brandLight,
|
|
859
|
+
dark: brandDark
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
#### Creating a Theme from Scratch
|
|
865
|
+
|
|
866
|
+
Use `base: null` to create a theme without inheriting defaults:
|
|
867
|
+
|
|
868
|
+
```typescript
|
|
869
|
+
const minimalTheme = registerTheme('minimal', {
|
|
870
|
+
base: null, // Start fresh, no inheritance
|
|
871
|
+
config: {
|
|
872
|
+
colors: {
|
|
873
|
+
gray: { 900: '#f5f5f5', 0: '#171717' },
|
|
874
|
+
blue: { 500: '#3b82f6' }
|
|
875
|
+
},
|
|
876
|
+
vars: {
|
|
877
|
+
'--ease-panel-background': 'white',
|
|
878
|
+
'--ease-panel-border-color': '#e5e5e5'
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
#### Theme Utilities
|
|
885
|
+
|
|
886
|
+
```typescript
|
|
887
|
+
import {
|
|
888
|
+
registerTheme,
|
|
889
|
+
getTheme,
|
|
890
|
+
hasTheme,
|
|
891
|
+
getThemeNames,
|
|
892
|
+
themeRef
|
|
893
|
+
} from '@easemate/web-kit';
|
|
894
|
+
|
|
895
|
+
// Check if a theme exists
|
|
896
|
+
if (hasTheme('brand')) {
|
|
897
|
+
console.log('Brand theme is registered');
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// Get all registered theme names
|
|
901
|
+
const themes = getThemeNames(); // ['default', 'dark', 'brand', ...]
|
|
902
|
+
|
|
903
|
+
// Get resolved theme config (with inheritance applied)
|
|
904
|
+
const config = getTheme('brand');
|
|
905
|
+
|
|
906
|
+
// Get a theme ref for an already-registered theme
|
|
907
|
+
const ref = themeRef('brand');
|
|
712
908
|
```
|
|
713
909
|
|
|
714
910
|
### Font Configuration
|
|
@@ -865,13 +1061,13 @@ interface WebKitController {
|
|
|
865
1061
|
| Export | Description |
|
|
866
1062
|
|--------|-------------|
|
|
867
1063
|
| `@easemate/web-kit` | Main entry (initWebKit + theme + types) |
|
|
868
|
-
| `@easemate/web-kit/react` | React hooks and
|
|
1064
|
+
| `@easemate/web-kit/react` | React hooks, utilities, and JSX types |
|
|
1065
|
+
| `@easemate/web-kit/react/jsx` | JSX type augmentation only |
|
|
869
1066
|
| `@easemate/web-kit/register` | Side-effect registration (all components) |
|
|
870
1067
|
| `@easemate/web-kit/elements` | UI components only |
|
|
871
1068
|
| `@easemate/web-kit/decorators` | Component decorators |
|
|
872
1069
|
| `@easemate/web-kit/theme` | Theming utilities |
|
|
873
1070
|
| `@easemate/web-kit/utils` | Utility functions |
|
|
874
|
-
| `@easemate/web-kit/styles/*` | CSS assets (optional) |
|
|
875
1071
|
|
|
876
1072
|
### Panel API
|
|
877
1073
|
|