what-core 0.6.2 → 0.6.3

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 (50) hide show
  1. package/README.md +2 -0
  2. package/compiler.d.ts +30 -0
  3. package/devtools.d.ts +2 -0
  4. package/dist/compiler.js +1787 -0
  5. package/dist/compiler.js.map +7 -0
  6. package/dist/compiler.min.js +2 -0
  7. package/dist/compiler.min.js.map +7 -0
  8. package/dist/devtools.js +10 -0
  9. package/dist/devtools.js.map +7 -0
  10. package/dist/devtools.min.js +2 -0
  11. package/dist/devtools.min.js.map +7 -0
  12. package/dist/index.js +330 -382
  13. package/dist/index.js.map +4 -4
  14. package/dist/index.min.js +62 -62
  15. package/dist/index.min.js.map +4 -4
  16. package/dist/render.js +262 -21
  17. package/dist/render.js.map +4 -4
  18. package/dist/render.min.js +58 -1
  19. package/dist/render.min.js.map +4 -4
  20. package/dist/testing.js +3 -0
  21. package/dist/testing.js.map +2 -2
  22. package/dist/testing.min.js +1 -1
  23. package/dist/testing.min.js.map +2 -2
  24. package/index.d.ts +176 -1
  25. package/jsx-runtime.d.ts +622 -0
  26. package/package.json +20 -2
  27. package/src/agent-context.js +1 -1
  28. package/src/compiler.js +18 -0
  29. package/src/components.js +73 -27
  30. package/src/devtools.js +4 -0
  31. package/src/dom.js +7 -0
  32. package/src/guardrails.js +3 -4
  33. package/src/hooks.js +0 -11
  34. package/src/index.js +5 -9
  35. package/src/render.js +91 -24
  36. package/dist/a11y.js +0 -440
  37. package/dist/animation.js +0 -548
  38. package/dist/components.js +0 -229
  39. package/dist/data.js +0 -638
  40. package/dist/dom.js +0 -439
  41. package/dist/form.js +0 -509
  42. package/dist/h.js +0 -152
  43. package/dist/head.js +0 -51
  44. package/dist/helpers.js +0 -140
  45. package/dist/hooks.js +0 -210
  46. package/dist/reactive.js +0 -432
  47. package/dist/scheduler.js +0 -246
  48. package/dist/skeleton.js +0 -363
  49. package/dist/store.js +0 -83
  50. package/dist/what.js +0 -117
package/dist/skeleton.js DELETED
@@ -1,363 +0,0 @@
1
- // What Framework - Skeleton Loaders
2
- // Loading placeholders for content, islands, and async data
3
-
4
- import { h } from './h.js';
5
- import { signal, effect } from './reactive.js';
6
-
7
- // --- Skeleton Base Styles ---
8
-
9
- const skeletonStyles = `
10
- .what-skeleton {
11
- background: linear-gradient(
12
- 90deg,
13
- var(--skeleton-base, #e0e0e0) 0%,
14
- var(--skeleton-highlight, #f0f0f0) 50%,
15
- var(--skeleton-base, #e0e0e0) 100%
16
- );
17
- background-size: 200% 100%;
18
- animation: what-skeleton-shimmer 1.5s infinite ease-in-out;
19
- border-radius: var(--skeleton-radius, 4px);
20
- }
21
-
22
- @keyframes what-skeleton-shimmer {
23
- 0% { background-position: 200% 0; }
24
- 100% { background-position: -200% 0; }
25
- }
26
-
27
- .what-skeleton-pulse {
28
- animation: what-skeleton-pulse 1.5s infinite ease-in-out;
29
- }
30
-
31
- @keyframes what-skeleton-pulse {
32
- 0%, 100% { opacity: 1; }
33
- 50% { opacity: 0.5; }
34
- }
35
-
36
- .what-skeleton-wave {
37
- position: relative;
38
- overflow: hidden;
39
- }
40
-
41
- .what-skeleton-wave::after {
42
- content: '';
43
- position: absolute;
44
- top: 0;
45
- right: 0;
46
- bottom: 0;
47
- left: 0;
48
- background: linear-gradient(
49
- 90deg,
50
- transparent 0%,
51
- rgba(255, 255, 255, 0.4) 50%,
52
- transparent 100%
53
- );
54
- animation: what-skeleton-wave 1.5s infinite;
55
- }
56
-
57
- @keyframes what-skeleton-wave {
58
- 0% { transform: translateX(-100%); }
59
- 100% { transform: translateX(100%); }
60
- }
61
- `;
62
-
63
- // Inject styles once
64
- let stylesInjected = false;
65
-
66
- function injectStyles() {
67
- if (stylesInjected || typeof document === 'undefined') return;
68
- stylesInjected = true;
69
-
70
- const style = document.createElement('style');
71
- style.textContent = skeletonStyles;
72
- document.head.appendChild(style);
73
- }
74
-
75
- // --- Skeleton Component ---
76
-
77
- export function Skeleton({
78
- width,
79
- height,
80
- variant = 'shimmer', // 'shimmer' | 'pulse' | 'wave'
81
- circle = false,
82
- class: className,
83
- style: customStyle,
84
- count = 1,
85
- }) {
86
- injectStyles();
87
-
88
- const baseClass = `what-skeleton ${variant === 'pulse' ? 'what-skeleton-pulse' : ''} ${variant === 'wave' ? 'what-skeleton-wave' : ''}`;
89
- const finalClass = className ? `${baseClass} ${className}` : baseClass;
90
-
91
- const style = {
92
- width: typeof width === 'number' ? `${width}px` : width,
93
- height: typeof height === 'number' ? `${height}px` : height,
94
- borderRadius: circle ? '50%' : undefined,
95
- ...customStyle,
96
- };
97
-
98
- if (count === 1) {
99
- return h('div', { class: finalClass, style, 'aria-hidden': 'true' });
100
- }
101
-
102
- return Array.from({ length: count }, (_, i) =>
103
- h('div', {
104
- key: i,
105
- class: finalClass,
106
- style: { ...style, marginBottom: i < count - 1 ? '8px' : undefined },
107
- 'aria-hidden': 'true',
108
- })
109
- );
110
- }
111
-
112
- // --- Skeleton Text ---
113
-
114
- export function SkeletonText({
115
- lines = 3,
116
- lastLineWidth = '60%',
117
- lineHeight = 16,
118
- gap = 8,
119
- variant = 'shimmer',
120
- }) {
121
- injectStyles();
122
-
123
- return h('div', { class: 'what-skeleton-text', 'aria-hidden': 'true' },
124
- Array.from({ length: lines }, (_, i) =>
125
- h('div', {
126
- key: i,
127
- class: `what-skeleton ${variant === 'pulse' ? 'what-skeleton-pulse' : ''}`,
128
- style: {
129
- height: `${lineHeight}px`,
130
- width: i === lines - 1 ? lastLineWidth : '100%',
131
- marginBottom: i < lines - 1 ? `${gap}px` : undefined,
132
- },
133
- })
134
- )
135
- );
136
- }
137
-
138
- // --- Skeleton Avatar ---
139
-
140
- export function SkeletonAvatar({
141
- size = 40,
142
- variant = 'shimmer',
143
- }) {
144
- return Skeleton({
145
- width: size,
146
- height: size,
147
- circle: true,
148
- variant,
149
- });
150
- }
151
-
152
- // --- Skeleton Card ---
153
-
154
- export function SkeletonCard({
155
- imageHeight = 200,
156
- lines = 3,
157
- variant = 'shimmer',
158
- }) {
159
- injectStyles();
160
-
161
- return h('div', { class: 'what-skeleton-card', 'aria-hidden': 'true' },
162
- // Image placeholder
163
- h('div', {
164
- class: `what-skeleton ${variant === 'pulse' ? 'what-skeleton-pulse' : ''}`,
165
- style: { height: `${imageHeight}px`, width: '100%', marginBottom: '16px' },
166
- }),
167
- // Title
168
- h('div', {
169
- class: `what-skeleton ${variant === 'pulse' ? 'what-skeleton-pulse' : ''}`,
170
- style: { height: '24px', width: '70%', marginBottom: '12px' },
171
- }),
172
- // Text lines
173
- SkeletonText({ lines, variant })
174
- );
175
- }
176
-
177
- // --- Skeleton Table ---
178
-
179
- export function SkeletonTable({
180
- rows = 5,
181
- columns = 4,
182
- variant = 'shimmer',
183
- }) {
184
- injectStyles();
185
-
186
- return h('div', { class: 'what-skeleton-table', 'aria-hidden': 'true' },
187
- // Header
188
- h('div', { style: { display: 'flex', gap: '16px', marginBottom: '16px' } },
189
- Array.from({ length: columns }, (_, i) =>
190
- h('div', {
191
- key: i,
192
- class: `what-skeleton ${variant === 'pulse' ? 'what-skeleton-pulse' : ''}`,
193
- style: { height: '20px', flex: 1 },
194
- })
195
- )
196
- ),
197
- // Rows
198
- Array.from({ length: rows }, (_, rowIndex) =>
199
- h('div', {
200
- key: rowIndex,
201
- style: {
202
- display: 'flex',
203
- gap: '16px',
204
- marginBottom: rowIndex < rows - 1 ? '12px' : undefined,
205
- },
206
- },
207
- Array.from({ length: columns }, (_, colIndex) =>
208
- h('div', {
209
- key: colIndex,
210
- class: `what-skeleton ${variant === 'pulse' ? 'what-skeleton-pulse' : ''}`,
211
- style: { height: '16px', flex: 1 },
212
- })
213
- )
214
- )
215
- )
216
- );
217
- }
218
-
219
- // --- Island Skeleton ---
220
- // Specific skeleton for island placeholders
221
-
222
- export function IslandSkeleton({
223
- type = 'default', // 'default' | 'card' | 'text' | 'custom'
224
- height,
225
- children,
226
- }) {
227
- injectStyles();
228
-
229
- if (type === 'card') {
230
- return SkeletonCard({});
231
- }
232
-
233
- if (type === 'text') {
234
- return SkeletonText({});
235
- }
236
-
237
- if (children) {
238
- return children;
239
- }
240
-
241
- return h('div', {
242
- class: 'what-skeleton what-island-skeleton',
243
- style: {
244
- height: typeof height === 'number' ? `${height}px` : height || '100px',
245
- width: '100%',
246
- },
247
- 'aria-hidden': 'true',
248
- });
249
- }
250
-
251
- // --- useSkeleton Hook ---
252
- // Show skeleton while loading data
253
-
254
- export function useSkeleton(asyncFn, deps = []) {
255
- const isLoading = signal(true);
256
- const data = signal(null);
257
- const error = signal(null);
258
-
259
- effect(() => {
260
- isLoading.set(true);
261
- error.set(null);
262
-
263
- Promise.resolve(asyncFn())
264
- .then(result => {
265
- data.set(result);
266
- isLoading.set(false);
267
- })
268
- .catch(err => {
269
- error.set(err);
270
- isLoading.set(false);
271
- });
272
- });
273
-
274
- return {
275
- isLoading: () => isLoading(),
276
- data: () => data(),
277
- error: () => error(),
278
- Skeleton: (props) => isLoading() ? Skeleton(props) : null,
279
- };
280
- }
281
-
282
- // --- Placeholder ---
283
- // Generic placeholder with optional shimmer
284
-
285
- export function Placeholder({
286
- width = '100%',
287
- height = 100,
288
- label = 'Loading...',
289
- showLabel = false,
290
- variant = 'shimmer',
291
- }) {
292
- injectStyles();
293
-
294
- return h('div', {
295
- class: `what-skeleton ${variant === 'pulse' ? 'what-skeleton-pulse' : ''}`,
296
- style: {
297
- width: typeof width === 'number' ? `${width}px` : width,
298
- height: typeof height === 'number' ? `${height}px` : height,
299
- display: 'flex',
300
- alignItems: 'center',
301
- justifyContent: 'center',
302
- },
303
- 'aria-label': label,
304
- role: 'status',
305
- },
306
- showLabel && h('span', {
307
- style: {
308
- color: 'var(--skeleton-text, #999)',
309
- fontSize: '14px',
310
- },
311
- }, label)
312
- );
313
- }
314
-
315
- // --- Loading Dots ---
316
-
317
- export function LoadingDots({ size = 8, color = '#666' }) {
318
- injectStyles();
319
-
320
- const dotStyle = {
321
- width: `${size}px`,
322
- height: `${size}px`,
323
- borderRadius: '50%',
324
- backgroundColor: color,
325
- animation: 'what-skeleton-pulse 1s infinite ease-in-out',
326
- };
327
-
328
- return h('div', {
329
- class: 'what-loading-dots',
330
- style: { display: 'flex', gap: `${size / 2}px` },
331
- 'aria-label': 'Loading',
332
- role: 'status',
333
- },
334
- h('div', { style: { ...dotStyle, animationDelay: '0s' } }),
335
- h('div', { style: { ...dotStyle, animationDelay: '0.2s' } }),
336
- h('div', { style: { ...dotStyle, animationDelay: '0.4s' } })
337
- );
338
- }
339
-
340
- // --- Spinner ---
341
-
342
- export function Spinner({ size = 24, color = '#666', strokeWidth = 2 }) {
343
- return h('svg', {
344
- width: size,
345
- height: size,
346
- viewBox: '0 0 24 24',
347
- style: { animation: 'spin 1s linear infinite' },
348
- 'aria-label': 'Loading',
349
- role: 'status',
350
- },
351
- h('style', null, '@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }'),
352
- h('circle', {
353
- cx: 12,
354
- cy: 12,
355
- r: 10,
356
- stroke: color,
357
- strokeWidth,
358
- fill: 'none',
359
- strokeDasharray: '31.4 31.4',
360
- strokeLinecap: 'round',
361
- })
362
- );
363
- }
package/dist/store.js DELETED
@@ -1,83 +0,0 @@
1
- import { signal, computed, batch, __DEV__ } from './reactive.js';
2
- export function derived(fn) {
3
- fn._storeComputed = true;
4
- return fn;
5
- }
6
- let _storeComputedWarned = false;
7
- export function storeComputed(fn) {
8
- if (!_storeComputedWarned) {
9
- _storeComputedWarned = true;
10
- console.warn('[what] storeComputed() is deprecated. Use derived() instead.');
11
- }
12
- return derived(fn);
13
- }
14
- export function createStore(definition) {
15
- const signals = {};
16
- const computeds = {};
17
- const actions = {};
18
- const state = {};
19
- for (const [key, value] of Object.entries(definition)) {
20
- if (typeof value === 'function' && value._storeComputed) {
21
- if (__DEV__ && value.length === 0) {
22
- console.warn(
23
- `[what] derived() for "${key}" should accept the state parameter, e.g. derived(state => ...).`
24
- );
25
- }
26
- computeds[key] = value;
27
- } else if (typeof value === 'function') {
28
- actions[key] = value;
29
- } else {
30
- signals[key] = signal(value);
31
- }
32
- }
33
- for (const [key, fn] of Object.entries(computeds)) {
34
- const proxy = new Proxy({}, {
35
- get(_, prop) {
36
- if (signals[prop]) return signals[prop]();
37
- if (computeds[prop]) return computeds[prop]();
38
- return undefined;
39
- },
40
- });
41
- computeds[key] = computed(() => fn(proxy));
42
- }
43
- for (const [key, fn] of Object.entries(actions)) {
44
- actions[key] = (...args) => {
45
- batch(() => {
46
- const proxy = new Proxy({}, {
47
- get(_, prop) {
48
- if (signals[prop]) return signals[prop].peek();
49
- if (computeds[prop]) return computeds[prop].peek();
50
- if (actions[prop]) return actions[prop];
51
- return undefined;
52
- },
53
- set(_, prop, val) {
54
- if (signals[prop]) signals[prop].set(val);
55
- return true;
56
- },
57
- });
58
- fn.apply(proxy, args);
59
- });
60
- };
61
- }
62
- return function useStore() {
63
- const result = {};
64
- for (const [key, s] of Object.entries(signals)) {
65
- Object.defineProperty(result, key, { get: () => s(), enumerable: true });
66
- }
67
- for (const [key, c] of Object.entries(computeds)) {
68
- Object.defineProperty(result, key, { get: () => c(), enumerable: true });
69
- }
70
- for (const [key, fn] of Object.entries(actions)) {
71
- result[key] = fn;
72
- }
73
- return result;
74
- };
75
- }
76
- let _atomWarned = false;
77
- export function atom(initial) {
78
- if (!_atomWarned) {
79
- _atomWarned = true;
80
- console.warn('[what] atom() is deprecated. Use signal() directly instead.');
81
- }
82
- return signal(initial);
83
- }
package/dist/what.js DELETED
@@ -1,117 +0,0 @@
1
- export { signal, computed, effect, memo as signalMemo, batch, untrack, flushSync, createRoot, getOwner, runWithOwner, onCleanup as onRootCleanup, __setDevToolsHooks } from './reactive.js';
2
- export { template, _template, insert, mapArray, spread, setProp, delegateEvents, on, classList, hydrate, isHydrating } from './render.js';
3
- export { h, Fragment, html } from './h.js';
4
- export { mount } from './dom.js';
5
- export {
6
- useState,
7
- useSignal,
8
- useComputed,
9
- useEffect,
10
- useMemo,
11
- useCallback,
12
- useRef,
13
- useContext,
14
- useReducer,
15
- createContext,
16
- onMount,
17
- onCleanup,
18
- createResource,
19
- } from './hooks.js';
20
- export { memo, lazy, Suspense, ErrorBoundary, Show, For, Switch, Match, Island } from './components.js';
21
- export { createStore, derived, storeComputed, atom } from './store.js';
22
- export { Head, clearHead } from './head.js';
23
- export {
24
- each,
25
- cls,
26
- style,
27
- debounce,
28
- throttle,
29
- useMediaQuery,
30
- useLocalStorage,
31
- useClickOutside,
32
- Portal,
33
- transition,
34
- } from './helpers.js';
35
- export {
36
- scheduleRead,
37
- scheduleWrite,
38
- flushScheduler,
39
- measure,
40
- mutate,
41
- useScheduledEffect,
42
- nextFrame,
43
- raf,
44
- onResize,
45
- onIntersect,
46
- smoothScrollTo,
47
- } from './scheduler.js';
48
- export {
49
- spring,
50
- tween,
51
- easings,
52
- useTransition,
53
- useGesture,
54
- useAnimatedValue,
55
- createTransitionClasses,
56
- cssTransition,
57
- } from './animation.js';
58
- export {
59
- useFocus,
60
- useFocusRestore,
61
- useFocusTrap,
62
- FocusTrap,
63
- announce,
64
- announceAssertive,
65
- SkipLink,
66
- useAriaExpanded,
67
- useAriaSelected,
68
- useAriaChecked,
69
- useRovingTabIndex,
70
- VisuallyHidden,
71
- LiveRegion,
72
- useId,
73
- useIds,
74
- useDescribedBy,
75
- useLabelledBy,
76
- Keys,
77
- onKey,
78
- onKeys,
79
- } from './a11y.js';
80
- export {
81
- Skeleton,
82
- SkeletonText,
83
- SkeletonAvatar,
84
- SkeletonCard,
85
- SkeletonTable,
86
- IslandSkeleton,
87
- useSkeleton,
88
- Placeholder,
89
- LoadingDots,
90
- Spinner,
91
- } from './skeleton.js';
92
- export {
93
- useFetch,
94
- useSWR,
95
- useQuery,
96
- useInfiniteQuery,
97
- invalidateQueries,
98
- prefetchQuery,
99
- setQueryData,
100
- getQueryData,
101
- clearCache,
102
- __getCacheSnapshot,
103
- } from './data.js';
104
- export {
105
- useForm,
106
- useField,
107
- rules,
108
- simpleResolver,
109
- zodResolver,
110
- yupResolver,
111
- Input,
112
- Textarea,
113
- Select,
114
- Checkbox,
115
- Radio,
116
- ErrorMessage,
117
- } from './form.js';