@easemate/web-kit 0.1.5 → 0.2.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 (46) hide show
  1. package/README.md +360 -168
  2. package/build/elements/index.cjs +5 -2
  3. package/build/elements/index.d.cts +2 -1
  4. package/build/elements/index.d.ts +2 -1
  5. package/build/elements/index.js +2 -1
  6. package/build/elements/panel/index.cjs +496 -0
  7. package/build/elements/panel/index.d.cts +67 -0
  8. package/build/elements/panel/index.d.ts +67 -0
  9. package/build/elements/panel/index.js +492 -0
  10. package/build/elements/state/index.cjs +57 -464
  11. package/build/elements/state/index.d.cts +34 -25
  12. package/build/elements/state/index.d.ts +34 -25
  13. package/build/elements/state/index.js +59 -466
  14. package/build/internal/component-loaders.cjs +2 -0
  15. package/build/internal/component-loaders.d.cts +2 -2
  16. package/build/internal/component-loaders.d.ts +2 -2
  17. package/build/internal/component-loaders.js +2 -0
  18. package/build/react/events.cjs +25 -0
  19. package/build/react/events.d.cts +39 -0
  20. package/build/react/events.d.ts +39 -0
  21. package/build/react/events.js +22 -0
  22. package/build/react/index.cjs +19 -0
  23. package/build/react/index.d.cts +13 -0
  24. package/build/react/index.d.ts +13 -0
  25. package/build/react/index.js +12 -0
  26. package/build/react/provider.cjs +134 -0
  27. package/build/react/provider.d.cts +81 -0
  28. package/build/react/provider.d.ts +81 -0
  29. package/build/react/provider.js +98 -0
  30. package/build/react/types.cjs +8 -0
  31. package/build/react/types.d.cts +55 -0
  32. package/build/react/types.d.ts +55 -0
  33. package/build/react/types.js +7 -0
  34. package/build/react/use-ease-state.cjs +129 -0
  35. package/build/react/use-ease-state.d.cts +95 -0
  36. package/build/react/use-ease-state.d.ts +95 -0
  37. package/build/react/use-ease-state.js +126 -0
  38. package/build/react/use-web-kit.cjs +150 -0
  39. package/build/react/use-web-kit.d.cts +80 -0
  40. package/build/react/use-web-kit.d.ts +80 -0
  41. package/build/react/use-web-kit.js +114 -0
  42. package/build/register.cjs +1 -0
  43. package/build/register.d.cts +1 -0
  44. package/build/register.d.ts +1 -0
  45. package/build/register.js +1 -0
  46. package/package.json +15 -1
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ /**
3
+ * React hook for initializing @easemate/web-kit
4
+ *
5
+ * This module provides hooks for React integration.
6
+ * React is a peer dependency - users must install it separately.
7
+ *
8
+ * @module
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.useWebKit = useWebKit;
45
+ // Singleton to track if web-kit has been initialized globally
46
+ let globalController = null;
47
+ let initCount = 0;
48
+ /**
49
+ * React hook for initializing @easemate/web-kit.
50
+ *
51
+ * This hook handles initialization and cleanup of the web kit,
52
+ * ensuring components are registered before rendering.
53
+ *
54
+ * **Important for Next.js App Router:**
55
+ * - Use this hook in a client component (`'use client'`)
56
+ * - Place it at the top of your component tree (e.g., in a layout)
57
+ * - The hook is SSR-safe and will only initialize on the client
58
+ *
59
+ * **Note:** This hook requires React to be installed. Import React hooks
60
+ * directly in your component and pass them to this function, or use the
61
+ * imperative `initWebKit()` function directly.
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * // app/providers.tsx
66
+ * 'use client';
67
+ *
68
+ * import { useEffect, useState, useRef } from '../react';
69
+ * import { initWebKit } from '@easemate/web-kit';
70
+ *
71
+ * export function Providers({ children }: { children: React.ReactNode }) {
72
+ * const [ready, setReady] = useState(false);
73
+ * const controllerRef = useRef<WebKitController | null>(null);
74
+ *
75
+ * useEffect(() => {
76
+ * const controller = initWebKit({
77
+ * theme: 'default',
78
+ * styles: 'main',
79
+ * fonts: 'default'
80
+ * });
81
+ * controllerRef.current = controller;
82
+ * controller.ready.then(() => setReady(true));
83
+ *
84
+ * return () => controller.dispose();
85
+ * }, []);
86
+ *
87
+ * return <>{children}</>;
88
+ * }
89
+ * ```
90
+ */
91
+ function useWebKit(options, hooks) {
92
+ const isSSR = typeof window === 'undefined';
93
+ const { useState, useEffect, useRef } = hooks;
94
+ const { skip = false, ...initOptions } = options;
95
+ const [ready, setReady] = useState(false);
96
+ const controllerRef = useRef(null);
97
+ const optionsRef = useRef(initOptions);
98
+ useEffect(() => {
99
+ // Skip on SSR or if explicitly skipped
100
+ if (isSSR || skip) {
101
+ return;
102
+ }
103
+ let isMounted = true;
104
+ const initialize = async () => {
105
+ // If already initialized globally, reuse the controller
106
+ if (globalController) {
107
+ initCount++;
108
+ controllerRef.current = globalController;
109
+ await globalController.ready;
110
+ if (isMounted) {
111
+ setReady(true);
112
+ }
113
+ return;
114
+ }
115
+ // Dynamic import to ensure this only runs on client
116
+ const { initWebKit } = await Promise.resolve().then(() => __importStar(require('../init')));
117
+ const controller = initWebKit(optionsRef.current);
118
+ globalController = controller;
119
+ initCount++;
120
+ controllerRef.current = controller;
121
+ await controller.ready;
122
+ if (isMounted) {
123
+ setReady(true);
124
+ }
125
+ };
126
+ initialize();
127
+ return () => {
128
+ isMounted = false;
129
+ initCount--;
130
+ // Only dispose if this was the last user of the global controller
131
+ if (initCount <= 0 && globalController) {
132
+ globalController.dispose();
133
+ globalController = null;
134
+ initCount = 0;
135
+ }
136
+ };
137
+ }, [skip]);
138
+ return {
139
+ ready,
140
+ theme: controllerRef.current?.theme,
141
+ dispose: () => {
142
+ controllerRef.current?.dispose();
143
+ if (controllerRef.current === globalController) {
144
+ globalController = null;
145
+ initCount = 0;
146
+ }
147
+ controllerRef.current = null;
148
+ }
149
+ };
150
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * React hook for initializing @easemate/web-kit
3
+ *
4
+ * This module provides hooks for React integration.
5
+ * React is a peer dependency - users must install it separately.
6
+ *
7
+ * @module
8
+ */
9
+ import type { InitWebKitOptions, WebKitController } from '../init';
10
+ /**
11
+ * Options for useWebKit hook
12
+ */
13
+ export interface UseWebKitOptions extends InitWebKitOptions {
14
+ /**
15
+ * Skip initialization (useful for conditional rendering)
16
+ * @default false
17
+ */
18
+ skip?: boolean;
19
+ }
20
+ /**
21
+ * Return type for useWebKit hook
22
+ */
23
+ export interface UseWebKitReturn {
24
+ /** Whether the web kit is ready */
25
+ ready: boolean;
26
+ /** Theme controller (if theme was configured) */
27
+ theme?: WebKitController['theme'];
28
+ /** Dispose function for cleanup */
29
+ dispose: () => void;
30
+ }
31
+ /**
32
+ * React hook for initializing @easemate/web-kit.
33
+ *
34
+ * This hook handles initialization and cleanup of the web kit,
35
+ * ensuring components are registered before rendering.
36
+ *
37
+ * **Important for Next.js App Router:**
38
+ * - Use this hook in a client component (`'use client'`)
39
+ * - Place it at the top of your component tree (e.g., in a layout)
40
+ * - The hook is SSR-safe and will only initialize on the client
41
+ *
42
+ * **Note:** This hook requires React to be installed. Import React hooks
43
+ * directly in your component and pass them to this function, or use the
44
+ * imperative `initWebKit()` function directly.
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * // app/providers.tsx
49
+ * 'use client';
50
+ *
51
+ * import { useEffect, useState, useRef } from '../react';
52
+ * import { initWebKit } from '@easemate/web-kit';
53
+ *
54
+ * export function Providers({ children }: { children: React.ReactNode }) {
55
+ * const [ready, setReady] = useState(false);
56
+ * const controllerRef = useRef<WebKitController | null>(null);
57
+ *
58
+ * useEffect(() => {
59
+ * const controller = initWebKit({
60
+ * theme: 'default',
61
+ * styles: 'main',
62
+ * fonts: 'default'
63
+ * });
64
+ * controllerRef.current = controller;
65
+ * controller.ready.then(() => setReady(true));
66
+ *
67
+ * return () => controller.dispose();
68
+ * }, []);
69
+ *
70
+ * return <>{children}</>;
71
+ * }
72
+ * ```
73
+ */
74
+ export declare function useWebKit(options: UseWebKitOptions, hooks: {
75
+ useState: <T>(initial: T) => [T, (value: T) => void];
76
+ useEffect: (effect: () => (() => void) | undefined, deps?: unknown[]) => void;
77
+ useRef: <T>(initial: T) => {
78
+ current: T;
79
+ };
80
+ }): UseWebKitReturn;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * React hook for initializing @easemate/web-kit
3
+ *
4
+ * This module provides hooks for React integration.
5
+ * React is a peer dependency - users must install it separately.
6
+ *
7
+ * @module
8
+ */
9
+ import type { InitWebKitOptions, WebKitController } from '../init';
10
+ /**
11
+ * Options for useWebKit hook
12
+ */
13
+ export interface UseWebKitOptions extends InitWebKitOptions {
14
+ /**
15
+ * Skip initialization (useful for conditional rendering)
16
+ * @default false
17
+ */
18
+ skip?: boolean;
19
+ }
20
+ /**
21
+ * Return type for useWebKit hook
22
+ */
23
+ export interface UseWebKitReturn {
24
+ /** Whether the web kit is ready */
25
+ ready: boolean;
26
+ /** Theme controller (if theme was configured) */
27
+ theme?: WebKitController['theme'];
28
+ /** Dispose function for cleanup */
29
+ dispose: () => void;
30
+ }
31
+ /**
32
+ * React hook for initializing @easemate/web-kit.
33
+ *
34
+ * This hook handles initialization and cleanup of the web kit,
35
+ * ensuring components are registered before rendering.
36
+ *
37
+ * **Important for Next.js App Router:**
38
+ * - Use this hook in a client component (`'use client'`)
39
+ * - Place it at the top of your component tree (e.g., in a layout)
40
+ * - The hook is SSR-safe and will only initialize on the client
41
+ *
42
+ * **Note:** This hook requires React to be installed. Import React hooks
43
+ * directly in your component and pass them to this function, or use the
44
+ * imperative `initWebKit()` function directly.
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * // app/providers.tsx
49
+ * 'use client';
50
+ *
51
+ * import { useEffect, useState, useRef } from '../react';
52
+ * import { initWebKit } from '@easemate/web-kit';
53
+ *
54
+ * export function Providers({ children }: { children: React.ReactNode }) {
55
+ * const [ready, setReady] = useState(false);
56
+ * const controllerRef = useRef<WebKitController | null>(null);
57
+ *
58
+ * useEffect(() => {
59
+ * const controller = initWebKit({
60
+ * theme: 'default',
61
+ * styles: 'main',
62
+ * fonts: 'default'
63
+ * });
64
+ * controllerRef.current = controller;
65
+ * controller.ready.then(() => setReady(true));
66
+ *
67
+ * return () => controller.dispose();
68
+ * }, []);
69
+ *
70
+ * return <>{children}</>;
71
+ * }
72
+ * ```
73
+ */
74
+ export declare function useWebKit(options: UseWebKitOptions, hooks: {
75
+ useState: <T>(initial: T) => [T, (value: T) => void];
76
+ useEffect: (effect: () => (() => void) | undefined, deps?: unknown[]) => void;
77
+ useRef: <T>(initial: T) => {
78
+ current: T;
79
+ };
80
+ }): UseWebKitReturn;
@@ -0,0 +1,114 @@
1
+ /**
2
+ * React hook for initializing @easemate/web-kit
3
+ *
4
+ * This module provides hooks for React integration.
5
+ * React is a peer dependency - users must install it separately.
6
+ *
7
+ * @module
8
+ */
9
+ // Singleton to track if web-kit has been initialized globally
10
+ let globalController = null;
11
+ let initCount = 0;
12
+ /**
13
+ * React hook for initializing @easemate/web-kit.
14
+ *
15
+ * This hook handles initialization and cleanup of the web kit,
16
+ * ensuring components are registered before rendering.
17
+ *
18
+ * **Important for Next.js App Router:**
19
+ * - Use this hook in a client component (`'use client'`)
20
+ * - Place it at the top of your component tree (e.g., in a layout)
21
+ * - The hook is SSR-safe and will only initialize on the client
22
+ *
23
+ * **Note:** This hook requires React to be installed. Import React hooks
24
+ * directly in your component and pass them to this function, or use the
25
+ * imperative `initWebKit()` function directly.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * // app/providers.tsx
30
+ * 'use client';
31
+ *
32
+ * import { useEffect, useState, useRef } from '../react';
33
+ * import { initWebKit } from '@easemate/web-kit';
34
+ *
35
+ * export function Providers({ children }: { children: React.ReactNode }) {
36
+ * const [ready, setReady] = useState(false);
37
+ * const controllerRef = useRef<WebKitController | null>(null);
38
+ *
39
+ * useEffect(() => {
40
+ * const controller = initWebKit({
41
+ * theme: 'default',
42
+ * styles: 'main',
43
+ * fonts: 'default'
44
+ * });
45
+ * controllerRef.current = controller;
46
+ * controller.ready.then(() => setReady(true));
47
+ *
48
+ * return () => controller.dispose();
49
+ * }, []);
50
+ *
51
+ * return <>{children}</>;
52
+ * }
53
+ * ```
54
+ */
55
+ export function useWebKit(options, hooks) {
56
+ const isSSR = typeof window === 'undefined';
57
+ const { useState, useEffect, useRef } = hooks;
58
+ const { skip = false, ...initOptions } = options;
59
+ const [ready, setReady] = useState(false);
60
+ const controllerRef = useRef(null);
61
+ const optionsRef = useRef(initOptions);
62
+ useEffect(() => {
63
+ // Skip on SSR or if explicitly skipped
64
+ if (isSSR || skip) {
65
+ return;
66
+ }
67
+ let isMounted = true;
68
+ const initialize = async () => {
69
+ // If already initialized globally, reuse the controller
70
+ if (globalController) {
71
+ initCount++;
72
+ controllerRef.current = globalController;
73
+ await globalController.ready;
74
+ if (isMounted) {
75
+ setReady(true);
76
+ }
77
+ return;
78
+ }
79
+ // Dynamic import to ensure this only runs on client
80
+ const { initWebKit } = await import('../init');
81
+ const controller = initWebKit(optionsRef.current);
82
+ globalController = controller;
83
+ initCount++;
84
+ controllerRef.current = controller;
85
+ await controller.ready;
86
+ if (isMounted) {
87
+ setReady(true);
88
+ }
89
+ };
90
+ initialize();
91
+ return () => {
92
+ isMounted = false;
93
+ initCount--;
94
+ // Only dispose if this was the last user of the global controller
95
+ if (initCount <= 0 && globalController) {
96
+ globalController.dispose();
97
+ globalController = null;
98
+ initCount = 0;
99
+ }
100
+ };
101
+ }, [skip]);
102
+ return {
103
+ ready,
104
+ theme: controllerRef.current?.theme,
105
+ dispose: () => {
106
+ controllerRef.current?.dispose();
107
+ if (controllerRef.current === globalController) {
108
+ globalController = null;
109
+ initCount = 0;
110
+ }
111
+ controllerRef.current = null;
112
+ }
113
+ };
114
+ }
@@ -23,6 +23,7 @@ require("./elements/monitor/index.cjs");
23
23
  require("./elements/monitor/fps.cjs");
24
24
  require("./elements/number/index.cjs");
25
25
  require("./elements/origin/index.cjs");
26
+ require("./elements/panel/index.cjs");
26
27
  require("./elements/popover/index.cjs");
27
28
  require("./elements/radio/index.cjs");
28
29
  require("./elements/radio/input.cjs");
@@ -20,6 +20,7 @@ import "./elements/monitor/index.cjs";
20
20
  import "./elements/monitor/fps.cjs";
21
21
  import "./elements/number/index.cjs";
22
22
  import "./elements/origin/index.cjs";
23
+ import "./elements/panel/index.cjs";
23
24
  import "./elements/popover/index.cjs";
24
25
  import "./elements/radio/index.cjs";
25
26
  import "./elements/radio/input.cjs";
@@ -20,6 +20,7 @@ import "./elements/monitor/index.js";
20
20
  import "./elements/monitor/fps.js";
21
21
  import "./elements/number/index.js";
22
22
  import "./elements/origin/index.js";
23
+ import "./elements/panel/index.js";
23
24
  import "./elements/popover/index.js";
24
25
  import "./elements/radio/index.js";
25
26
  import "./elements/radio/input.js";
package/build/register.js CHANGED
@@ -21,6 +21,7 @@ import "./elements/monitor/index.js";
21
21
  import "./elements/monitor/fps.js";
22
22
  import "./elements/number/index.js";
23
23
  import "./elements/origin/index.js";
24
+ import "./elements/panel/index.js";
24
25
  import "./elements/popover/index.js";
25
26
  import "./elements/radio/index.js";
26
27
  import "./elements/radio/input.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easemate/web-kit",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "UI kit of web components for easemate - a typescript animation library",
5
5
  "type": "module",
6
6
  "files": [
@@ -55,6 +55,7 @@
55
55
  "./decorators": "./src/decorators/index.ts",
56
56
  "./utils": "./src/utils/index.ts",
57
57
  "./theme": "./src/theme/index.ts",
58
+ "./react": "./src/react/index.ts",
58
59
  "./register": "./src/register.ts"
59
60
  }
60
61
  },
@@ -84,12 +85,25 @@
84
85
  "import": "./build/theme/index.js",
85
86
  "require": "./build/theme/index.cjs"
86
87
  },
88
+ "./react": {
89
+ "types": "./build/react/index.d.cts",
90
+ "import": "./build/react/index.js",
91
+ "require": "./build/react/index.cjs"
92
+ },
87
93
  "./register": {
88
94
  "types": "./build/register.d.cts",
89
95
  "import": "./build/register.js",
90
96
  "require": "./build/register.cjs"
91
97
  }
92
98
  },
99
+ "peerDependencies": {
100
+ "react": ">=17.0.0"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "react": {
104
+ "optional": true
105
+ }
106
+ },
93
107
  "main": "./build/index.cjs",
94
108
  "types": "./build/index.d.cts",
95
109
  "module": "./build/index.js",