@easemate/web-kit 0.3.0 → 0.3.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/README.md +99 -5
- 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)
|
|
@@ -177,6 +180,25 @@ kit.theme?.set('light');
|
|
|
177
180
|
|
|
178
181
|
The library provides first-class React integration via `@easemate/web-kit/react`.
|
|
179
182
|
|
|
183
|
+
### JSX Types
|
|
184
|
+
|
|
185
|
+
Importing `@easemate/web-kit/react` automatically adds JSX types for all `ease-*` custom elements:
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
import '@easemate/web-kit/react';
|
|
189
|
+
|
|
190
|
+
// Now ease-* elements are typed in JSX
|
|
191
|
+
<ease-panel>
|
|
192
|
+
<ease-slider name="volume" value={50} />
|
|
193
|
+
</ease-panel>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
You can also import just the JSX types separately:
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
import '@easemate/web-kit/react/jsx';
|
|
200
|
+
```
|
|
201
|
+
|
|
180
202
|
### Basic Setup
|
|
181
203
|
|
|
182
204
|
```tsx
|
|
@@ -225,6 +247,39 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|
|
225
247
|
}
|
|
226
248
|
```
|
|
227
249
|
|
|
250
|
+
### useWebKit Hook
|
|
251
|
+
|
|
252
|
+
The `useWebKit` hook initializes the web kit and tracks readiness:
|
|
253
|
+
|
|
254
|
+
```tsx
|
|
255
|
+
'use client';
|
|
256
|
+
|
|
257
|
+
import { useState, useEffect, useRef } from 'react';
|
|
258
|
+
import { useWebKit } from '@easemate/web-kit/react';
|
|
259
|
+
|
|
260
|
+
function App() {
|
|
261
|
+
const { ready, theme, dispose } = useWebKit(
|
|
262
|
+
{
|
|
263
|
+
theme: 'default',
|
|
264
|
+
styles: 'main',
|
|
265
|
+
fonts: 'default',
|
|
266
|
+
skip: false // Optional: skip initialization
|
|
267
|
+
},
|
|
268
|
+
{ useState, useEffect, useRef }
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
if (!ready) return <div>Loading...</div>;
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<ease-panel>
|
|
275
|
+
<ease-slider name="value" value="0.5" />
|
|
276
|
+
</ease-panel>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
The hook manages a singleton controller internally, so multiple components using `useWebKit` will share the same initialization.
|
|
282
|
+
|
|
228
283
|
### useEaseState Hook
|
|
229
284
|
|
|
230
285
|
The `useEaseState` hook provides reactive state management for controls:
|
|
@@ -242,8 +297,18 @@ interface AnimationState {
|
|
|
242
297
|
}
|
|
243
298
|
|
|
244
299
|
function AnimationControls() {
|
|
245
|
-
const {
|
|
300
|
+
const {
|
|
301
|
+
stateRef,
|
|
302
|
+
panelRef,
|
|
303
|
+
state,
|
|
304
|
+
get,
|
|
305
|
+
set,
|
|
306
|
+
reset,
|
|
307
|
+
setTab,
|
|
308
|
+
activeTab
|
|
309
|
+
} = useEaseState<AnimationState>(
|
|
246
310
|
{
|
|
311
|
+
initialState: { duration: 1, easing: 'ease-out', loop: false },
|
|
247
312
|
onChange: ({ name, value }) => {
|
|
248
313
|
console.log(`${name} changed to ${value}`);
|
|
249
314
|
},
|
|
@@ -279,9 +344,22 @@ function AnimationControls() {
|
|
|
279
344
|
}
|
|
280
345
|
```
|
|
281
346
|
|
|
347
|
+
#### useEaseState Return Values
|
|
348
|
+
|
|
349
|
+
| Property | Type | Description |
|
|
350
|
+
|----------|------|-------------|
|
|
351
|
+
| `stateRef` | `(element: EaseStateRef \| null) => void` | Ref callback for `<ease-state>` |
|
|
352
|
+
| `panelRef` | `(element: EasePanelRef \| null) => void` | Ref callback for `<ease-panel>` |
|
|
353
|
+
| `state` | `T` | Current state values (reactive) |
|
|
354
|
+
| `get` | `(name: keyof T) => T[keyof T]` | Get a specific control value |
|
|
355
|
+
| `set` | `(name: keyof T, value: T[keyof T]) => void` | Set a control value |
|
|
356
|
+
| `reset` | `() => void` | Reset all controls to initial values |
|
|
357
|
+
| `setTab` | `(index: number) => void` | Switch panel tab |
|
|
358
|
+
| `activeTab` | `number` | Current active tab index |
|
|
359
|
+
|
|
282
360
|
### WebKit Provider
|
|
283
361
|
|
|
284
|
-
For
|
|
362
|
+
For apps needing shared context, use `createWebKitProvider`:
|
|
285
363
|
|
|
286
364
|
```tsx
|
|
287
365
|
// providers.tsx
|
|
@@ -301,7 +379,10 @@ import { WebKitProvider } from './providers';
|
|
|
301
379
|
|
|
302
380
|
export default function Layout({ children }: { children: React.ReactNode }) {
|
|
303
381
|
return (
|
|
304
|
-
<WebKitProvider
|
|
382
|
+
<WebKitProvider
|
|
383
|
+
options={{ theme: 'default', styles: 'main', fonts: 'default' }}
|
|
384
|
+
immediate={true} // Render children before ready (default: true)
|
|
385
|
+
>
|
|
305
386
|
{children}
|
|
306
387
|
</WebKitProvider>
|
|
307
388
|
);
|
|
@@ -321,6 +402,19 @@ function MyComponent() {
|
|
|
321
402
|
}
|
|
322
403
|
```
|
|
323
404
|
|
|
405
|
+
### Event Utilities
|
|
406
|
+
|
|
407
|
+
The React module exports typed event creators:
|
|
408
|
+
|
|
409
|
+
```tsx
|
|
410
|
+
import { createEventHandler, type ControlChangeEvent, type StateChangeEvent, type TabChangeEvent } from '@easemate/web-kit/react';
|
|
411
|
+
|
|
412
|
+
// Create typed event handlers
|
|
413
|
+
const handleChange = createEventHandler<ControlChangeEvent>((e) => {
|
|
414
|
+
console.log(e.detail.name, e.detail.value);
|
|
415
|
+
});
|
|
416
|
+
```
|
|
417
|
+
|
|
324
418
|
---
|
|
325
419
|
|
|
326
420
|
## Components
|
|
@@ -865,13 +959,13 @@ interface WebKitController {
|
|
|
865
959
|
| Export | Description |
|
|
866
960
|
|--------|-------------|
|
|
867
961
|
| `@easemate/web-kit` | Main entry (initWebKit + theme + types) |
|
|
868
|
-
| `@easemate/web-kit/react` | React hooks and
|
|
962
|
+
| `@easemate/web-kit/react` | React hooks, utilities, and JSX types |
|
|
963
|
+
| `@easemate/web-kit/react/jsx` | JSX type augmentation only |
|
|
869
964
|
| `@easemate/web-kit/register` | Side-effect registration (all components) |
|
|
870
965
|
| `@easemate/web-kit/elements` | UI components only |
|
|
871
966
|
| `@easemate/web-kit/decorators` | Component decorators |
|
|
872
967
|
| `@easemate/web-kit/theme` | Theming utilities |
|
|
873
968
|
| `@easemate/web-kit/utils` | Utility functions |
|
|
874
|
-
| `@easemate/web-kit/styles/*` | CSS assets (optional) |
|
|
875
969
|
|
|
876
970
|
### Panel API
|
|
877
971
|
|