@moonwitness/ui 0.0.0-stage → 0.1.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.
@@ -0,0 +1,2044 @@
1
+ 'use client';
2
+
3
+ import React, { createContext, forwardRef, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from 'react';
4
+ import { skins } from './skins.js';
5
+ import { useTheme } from './theme.js';
6
+
7
+ const h = React.createElement;
8
+ const cx = (...values) => values.filter(Boolean).join(' ');
9
+
10
+ function mergeRefs(...refs) {
11
+ return (node) => {
12
+ for (const ref of refs) {
13
+ if (typeof ref === 'function') ref(node);
14
+ else if (ref && typeof ref === 'object') ref.current = node;
15
+ }
16
+ };
17
+ }
18
+
19
+ /**
20
+ * Polymorphic Slot primitive for Next.js `<Link>` (`asChild`) composition.
21
+ * Merges classNames, styles, refs, and event handlers onto the single child element.
22
+ */
23
+ export const Slot = forwardRef(function Slot({ children, className, style, ...slotProps }, forwardedRef) {
24
+ if (!React.isValidElement(children)) return null;
25
+ const childProps = children.props || {};
26
+ const mergedProps = { ...slotProps, ...childProps };
27
+
28
+ for (const key of Object.keys(slotProps)) {
29
+ if (/^on[A-Z]/.test(key) && typeof slotProps[key] === 'function' && typeof childProps[key] === 'function') {
30
+ mergedProps[key] = (...args) => {
31
+ childProps[key](...args);
32
+ slotProps[key](...args);
33
+ };
34
+ }
35
+ }
36
+
37
+ mergedProps.className = cx(className, childProps.className) || undefined;
38
+ if (style || childProps.style) {
39
+ mergedProps.style = { ...(style || {}), ...(childProps.style || {}) };
40
+ }
41
+ const childRef = children.ref ?? childProps.ref;
42
+ mergedProps.ref = childRef ? mergeRefs(forwardedRef, childRef) : forwardedRef;
43
+
44
+ return React.cloneElement(children, mergedProps);
45
+ });
46
+
47
+ const element = (tag, baseClass) => forwardRef(function Element({ className, asChild = false, ...props }, ref) {
48
+ const Comp = asChild ? Slot : tag;
49
+ return h(Comp, { ...props, className: cx(baseClass, className), ref });
50
+ });
51
+
52
+ function useControllable(value, defaultValue, onChange) {
53
+ const [internal, setInternal] = useState(defaultValue);
54
+ const controlled = value !== undefined;
55
+ const current = controlled ? value : internal;
56
+ const set = useCallback((next) => {
57
+ if (!controlled) setInternal(next);
58
+ if (next !== current) onChange?.(next);
59
+ }, [controlled, current, onChange]);
60
+ return [current, set];
61
+ }
62
+
63
+ export const Button = forwardRef(function Button({ className, variant = 'primary', size = 'md', type = 'button', asChild = false, loading = false, disabled, children, ...props }, ref) {
64
+ if (asChild) {
65
+ return h(Slot, {
66
+ ...props,
67
+ ref,
68
+ className: cx('mf-button', className),
69
+ 'data-variant': variant,
70
+ 'data-size': size,
71
+ 'data-loading': loading || undefined,
72
+ 'aria-busy': loading || undefined,
73
+ 'aria-disabled': (disabled || loading) || undefined,
74
+ }, children);
75
+ }
76
+ return h('button', {
77
+ ...props,
78
+ type,
79
+ ref,
80
+ disabled: disabled || loading,
81
+ 'aria-busy': loading || undefined,
82
+ 'data-loading': loading || undefined,
83
+ className: cx('mf-button', className),
84
+ 'data-variant': variant,
85
+ 'data-size': size,
86
+ }, children);
87
+ });
88
+
89
+ export const Card = element('section', 'mf-card');
90
+ export const CardHeader = element('div', 'mf-card-header');
91
+ export const CardTitle = element('h2', 'mf-card-title');
92
+ export const CardDescription = element('p', 'mf-card-description');
93
+ export const CardContent = element('div', 'mf-card-content');
94
+ export const CardFooter = element('div', 'mf-card-footer');
95
+
96
+ export const Input = forwardRef(function Input({ className, type = 'text', ...props }, ref) {
97
+ return h('input', { ...props, type, ref, className: cx('mf-input', className) });
98
+ });
99
+ export const Textarea = element('textarea', 'mf-textarea');
100
+ export const Label = element('label', 'mf-label');
101
+ export const Select = element('select', 'mf-select');
102
+
103
+ export const Badge = forwardRef(function Badge({ className, variant = 'secondary', asChild = false, ...props }, ref) {
104
+ const Comp = asChild ? Slot : 'span';
105
+ return h(Comp, { ...props, ref, className: cx('mf-badge', className), 'data-variant': variant });
106
+ });
107
+
108
+ export const Table = element('table', 'mf-table');
109
+ export const TableHeader = element('thead', 'mf-table-header');
110
+ export const TableBody = element('tbody', 'mf-table-body');
111
+ export const TableFooter = element('tfoot', 'mf-table-footer');
112
+ export const TableRow = element('tr', 'mf-table-row');
113
+ export const TableHead = forwardRef(function TableHead({ scope = 'col', ...props }, ref) {
114
+ return h('th', { ...props, scope, ref });
115
+ });
116
+ export const TableCell = element('td', 'mf-table-cell');
117
+ export const TableCaption = element('caption', 'mf-table-caption');
118
+
119
+ function checkable(baseClass, role) {
120
+ return forwardRef(function Checkable({ label, className, id: providedId, onCheckedChange, onChange, ...props }, ref) {
121
+ const generatedId = useId();
122
+ const id = providedId ?? generatedId;
123
+ const handleChange = (event) => {
124
+ onChange?.(event);
125
+ onCheckedChange?.(event.currentTarget.checked);
126
+ };
127
+ const input = h('input', { ...props, id, type: 'checkbox', role, className: cx(baseClass, className), onChange: handleChange, ref });
128
+ return label == null ? input : h('label', { htmlFor: id, className: 'mf-check-label' }, input, h('span', null, label));
129
+ });
130
+ }
131
+ export const Checkbox = checkable('mf-checkbox');
132
+ export const Switch = checkable('mf-switch', 'switch');
133
+
134
+ export const Progress = forwardRef(function Progress({ value = 0, max = 100, label = 'Progress', className, ...props }, ref) {
135
+ const limit = Number.isFinite(max) && max > 0 ? max : 100;
136
+ const amount = Math.min(limit, Math.max(0, Number.isFinite(value) ? value : 0));
137
+ return h('div', { 'aria-label': label, ...props, ref, role: 'progressbar', 'aria-valuemin': 0, 'aria-valuemax': limit, 'aria-valuenow': amount, className: cx('mf-progress', className) },
138
+ h('span', { className: 'mf-progress-fill', style: { width: `${amount / limit * 100}%` } }));
139
+ });
140
+
141
+ export const Avatar = forwardRef(function Avatar({ src, alt = '', fallback = '?', className, ...props }, ref) {
142
+ const [failedSource, setFailedSource] = useState(null);
143
+ return h('span', { ...props, ref, className: cx('mf-avatar', className) },
144
+ src && src !== failedSource
145
+ ? h('img', { src, alt, onError: () => setFailedSource(src) })
146
+ : h('span', { role: alt ? 'img' : undefined, 'aria-label': alt || undefined }, fallback));
147
+ });
148
+
149
+ export const Separator = forwardRef(function Separator({ orientation = 'horizontal', decorative = true, className, ...props }, ref) {
150
+ return h('div', { ...props, ref, className: cx('mf-separator', className), role: decorative ? 'none' : 'separator', 'aria-orientation': decorative ? undefined : orientation, 'data-orientation': orientation });
151
+ });
152
+
153
+ export const Alert = forwardRef(function Alert({ title, variant = 'secondary', className, children, role = 'status', ...props }, ref) {
154
+ return h('div', { ...props, role, ref, className: cx('mf-alert', className), 'data-variant': variant }, title && h('strong', { className: 'mf-alert-title' }, title), children);
155
+ });
156
+
157
+ export const Skeleton = forwardRef(function Skeleton({ className, ...props }, ref) {
158
+ return h('div', { ...props, ref, className: cx('mf-skeleton', className), 'aria-hidden': true });
159
+ });
160
+
161
+ /** Automatic-activation tabs. Item values must be unique stable strings. */
162
+ export const Tabs = forwardRef(function Tabs({ items, value, defaultValue, onValueChange, orientation = 'horizontal', label = 'Sections', className, ...props }, ref) {
163
+ const id = useId();
164
+ const buttons = useRef([]);
165
+ const [selected, setSelected] = useControllable(value, defaultValue ?? items.find(item => !item.disabled)?.value, onValueChange);
166
+ const effective = items.some(item => item.value === selected && !item.disabled) ? selected : items.find(item => !item.disabled)?.value;
167
+ function onKeyDown(event, index) {
168
+ const enabled = items.map((item, i) => item.disabled ? -1 : i).filter(i => i >= 0);
169
+ let target;
170
+ const current = enabled.indexOf(index);
171
+ const rtl = typeof getComputedStyle === 'function' && getComputedStyle(event.currentTarget).direction === 'rtl';
172
+ const nextKey = orientation === 'vertical' ? 'ArrowDown' : rtl ? 'ArrowLeft' : 'ArrowRight';
173
+ const previousKey = orientation === 'vertical' ? 'ArrowUp' : rtl ? 'ArrowRight' : 'ArrowLeft';
174
+ if (event.key === nextKey) target = enabled[(current + 1) % enabled.length];
175
+ if (event.key === previousKey) target = enabled[(current - 1 + enabled.length) % enabled.length];
176
+ if (event.key === 'Home') target = enabled[0];
177
+ if (event.key === 'End') target = enabled.at(-1);
178
+ if (target !== undefined) {
179
+ event.preventDefault();
180
+ setSelected(items[target].value);
181
+ buttons.current[target]?.focus();
182
+ }
183
+ }
184
+ return h('div', { ...props, ref, className: cx('mf-tabs', className), 'data-orientation': orientation },
185
+ h('div', { role: 'tablist', 'aria-label': label, 'aria-orientation': orientation, className: 'mf-tabs-list' }, items.map((item, index) => h('button', {
186
+ key: item.value, ref: node => { buttons.current[index] = node; }, type: 'button', role: 'tab', className: 'mf-tabs-trigger',
187
+ id: `${id}-tab-${index}`, 'aria-controls': `${id}-panel-${index}`, 'aria-selected': effective === item.value,
188
+ tabIndex: effective === item.value ? 0 : -1, disabled: item.disabled, onClick: () => setSelected(item.value), onKeyDown: event => onKeyDown(event, index),
189
+ }, item.label))),
190
+ items.map((item, index) => h('div', { key: item.value, role: 'tabpanel', className: 'mf-tabs-content', id: `${id}-panel-${index}`, 'aria-labelledby': `${id}-tab-${index}`, hidden: effective !== item.value, tabIndex: 0 }, item.content)));
191
+ });
192
+
193
+ /** Native top-layer modal: focus trapping, inert background and Escape support. */
194
+ export const Dialog = forwardRef(function Dialog({ open, defaultOpen = false, onOpenChange, title, description, trigger, closeLabel = 'Close dialog', children, className, onCancel, onClose, ...props }, forwardedRef) {
195
+ const id = useId();
196
+ const dialog = useRef(null);
197
+ const returnFocus = useRef(null);
198
+ const programmaticCloses = useRef([]);
199
+ const [isOpen, setOpen] = useControllable(open, defaultOpen, onOpenChange);
200
+ const currentOpen = useRef(isOpen);
201
+ currentOpen.current = isOpen;
202
+ const setRef = useCallback(node => {
203
+ dialog.current = node;
204
+ if (typeof forwardedRef === 'function') forwardedRef(node);
205
+ else if (forwardedRef) forwardedRef.current = node;
206
+ }, [forwardedRef]);
207
+ useEffect(() => {
208
+ const node = dialog.current;
209
+ if (!node) return;
210
+ if (isOpen && !node.open) {
211
+ returnFocus.current = node.ownerDocument.activeElement;
212
+ node.showModal();
213
+ } else if (!isOpen && node.open) {
214
+ programmaticCloses.current.push(false);
215
+ node.close();
216
+ returnFocus.current?.focus?.();
217
+ }
218
+ }, [isOpen]);
219
+ useEffect(() => {
220
+ const node = dialog.current;
221
+ return () => {
222
+ if (node?.open) {
223
+ programmaticCloses.current.push(true);
224
+ node.close();
225
+ returnFocus.current?.focus?.();
226
+ }
227
+ };
228
+ }, []);
229
+ const triggerElement = React.isValidElement(trigger) ? React.cloneElement(trigger, {
230
+ 'aria-haspopup': 'dialog', 'aria-expanded': Boolean(isOpen),
231
+ onClick: event => { trigger.props.onClick?.(event); if (!event.defaultPrevented) setOpen(true); },
232
+ }) : null;
233
+ return h(React.Fragment, null, triggerElement,
234
+ h('dialog', { ...props, ref: setRef, className: cx('mf-dialog', className), 'aria-labelledby': `${id}-title`, 'aria-describedby': description ? `${id}-description` : undefined,
235
+ onKeyDown: event => {
236
+ props.onKeyDown?.(event);
237
+ if (event.defaultPrevented || event.key !== 'Tab') return;
238
+ const node = dialog.current;
239
+ if (!node) return;
240
+ const focusables = Array.from(node.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')).filter(el => !el.disabled && (el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0));
241
+ if (focusables.length === 0) return;
242
+ const first = focusables[0];
243
+ const last = focusables[focusables.length - 1];
244
+ if (!event.shiftKey && (node.ownerDocument.activeElement === last || !node.contains(node.ownerDocument.activeElement))) {
245
+ event.preventDefault();
246
+ first.focus();
247
+ } else if (event.shiftKey && (node.ownerDocument.activeElement === first || node.ownerDocument.activeElement === node)) {
248
+ event.preventDefault();
249
+ last.focus();
250
+ }
251
+ },
252
+ onCancel: event => { onCancel?.(event); if (!event.defaultPrevented) { event.preventDefault(); setOpen(false); } },
253
+ onClose: event => {
254
+ const cleanupClose = programmaticCloses.current.shift();
255
+ if (cleanupClose !== true) onClose?.(event);
256
+ if (cleanupClose === undefined && currentOpen.current) setOpen(false);
257
+ },
258
+ },
259
+ h('div', { className: 'mf-dialog-header' }, h('h2', { className: 'mf-dialog-title', id: `${id}-title` }, title), h(Button, { variant: 'ghost', className: 'mf-dialog-close', 'aria-label': closeLabel, onClick: () => setOpen(false) }, '×')),
260
+ description && h('p', { className: 'mf-dialog-description', id: `${id}-description` }, description),
261
+ h('div', { className: 'mf-dialog-content' }, children)));
262
+ });
263
+
264
+ /** Semantic disclosure group; native summary keyboard behavior is preserved. */
265
+ export const Accordion = forwardRef(function Accordion({ items, multiple = false, defaultValue = [], className, ...props }, ref) {
266
+ const [expanded, setExpanded] = useState(() => new Set(multiple ? defaultValue : defaultValue.slice(0, 1)));
267
+ return h('div', { ...props, ref, className: cx('mf-accordion', className) }, items.map(item => h('details', {
268
+ key: item.value, className: 'mf-accordion-item', open: expanded.has(item.value),
269
+ onToggle: event => {
270
+ const isExpanded = event.currentTarget.open;
271
+ setExpanded(previous => {
272
+ if (previous.has(item.value) === isExpanded) return previous;
273
+ const next = isExpanded && !multiple ? new Set() : new Set(previous);
274
+ if (isExpanded) next.add(item.value); else next.delete(item.value);
275
+ return next;
276
+ });
277
+ },
278
+ }, h('summary', { className: 'mf-accordion-trigger', 'aria-disabled': item.disabled || undefined, tabIndex: item.disabled ? -1 : undefined, onClick: event => { if (item.disabled) event.preventDefault(); } }, item.title), h('div', { className: 'mf-accordion-content' }, item.content))));
279
+ });
280
+
281
+ /* ============================================================================
282
+ * Layout, Shell & Theme Controls for Next.js Consumers
283
+ * ========================================================================== */
284
+
285
+ export const AppShell = element('div', 'mf-shell');
286
+ export const Sidebar = element('aside', 'mf-sidebar');
287
+ export const Main = element('main', 'mf-main');
288
+ export const Header = element('header', 'mf-header');
289
+ export const Nav = element('nav', 'mf-nav');
290
+ export const Hero = element('section', 'mf-hero');
291
+
292
+ export const Grid = forwardRef(function Grid({ columns, className, style, ...props }, ref) {
293
+ const gridStyle = columns ? { ...style, gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))` } : style;
294
+ return h('div', { ...props, ref, className: cx('mf-grid', className), style: gridStyle });
295
+ });
296
+
297
+ export const NavItem = forwardRef(function NavItem({ active = false, asChild = false, href, className, children, ...props }, ref) {
298
+ const shared = {
299
+ ...props,
300
+ ref,
301
+ href,
302
+ className: cx('mf-nav-item', className),
303
+ 'aria-current': active ? 'page' : props['aria-current'],
304
+ 'data-active': active ? 'true' : undefined,
305
+ };
306
+ if (asChild) return h(Slot, shared, children);
307
+ if (href) return h('a', shared, children);
308
+ return h('button', { type: 'button', ...shared }, children);
309
+ });
310
+
311
+ export const StatCard = forwardRef(function StatCard({ label, value, detail, icon, className, children, ...props }, ref) {
312
+ return h('section', { ...props, ref, className: cx('mf-card mf-stat', className) },
313
+ (label || icon) && h('div', { className: 'mf-stat-header' }, label && h('span', { className: 'mf-stat-label' }, label), icon),
314
+ value !== undefined && h('strong', { className: 'mf-stat-value' }, value),
315
+ detail && h('span', { className: 'mf-stat-detail' }, detail),
316
+ children
317
+ );
318
+ });
319
+
320
+ export const SkinSelector = forwardRef(function SkinSelector({ value, onValueChange, variant = 'select', label = 'Skin', className, ...props }, ref) {
321
+ const theme = useTheme();
322
+ const activeSkin = value ?? theme.skin;
323
+ const setSkin = onValueChange ?? theme.setSkin;
324
+
325
+ if (variant === 'list') {
326
+ return h('div', { ...props, ref, role: 'group', 'aria-label': label, className: cx('mf-skin-selector-list', className) },
327
+ skins.map(skin => h('button', {
328
+ key: skin.id,
329
+ type: 'button',
330
+ className: 'mf-nav-item',
331
+ 'aria-pressed': activeSkin === skin.id,
332
+ 'data-active': activeSkin === skin.id ? 'true' : undefined,
333
+ onClick: () => setSkin(skin.id),
334
+ }, skin.name))
335
+ );
336
+ }
337
+
338
+ return h(Select, {
339
+ 'aria-label': label,
340
+ ...props,
341
+ ref,
342
+ className,
343
+ value: activeSkin,
344
+ onChange: event => {
345
+ props.onChange?.(event);
346
+ setSkin(event.currentTarget.value);
347
+ },
348
+ }, skins.map(skin => h('option', { key: skin.id, value: skin.id }, skin.name)));
349
+ });
350
+
351
+ export const ModeSelector = forwardRef(function ModeSelector({ value, onValueChange, variant = 'select', label = 'Appearance', className, ...props }, ref) {
352
+ const theme = useTheme();
353
+ const activeMode = value ?? theme.mode;
354
+ const setMode = onValueChange ?? theme.setMode;
355
+ const modes = [
356
+ { value: 'light', label: 'Light' },
357
+ { value: 'dark', label: 'Dark' },
358
+ { value: 'system', label: 'System' },
359
+ ];
360
+
361
+ if (variant === 'segmented') {
362
+ return h('div', { ...props, ref, role: 'group', 'aria-label': label, className: cx('mf-mode-segmented', className) },
363
+ modes.map(m => h('button', {
364
+ key: m.value,
365
+ type: 'button',
366
+ className: 'mf-tabs-trigger',
367
+ 'aria-pressed': activeMode === m.value,
368
+ 'aria-selected': activeMode === m.value,
369
+ onClick: () => setMode(m.value),
370
+ }, m.label))
371
+ );
372
+ }
373
+
374
+ return h(Select, {
375
+ 'aria-label': label,
376
+ ...props,
377
+ ref,
378
+ className,
379
+ value: activeMode,
380
+ onChange: event => {
381
+ props.onChange?.(event);
382
+ setMode(event.currentTarget.value);
383
+ },
384
+ }, modes.map(m => h('option', { key: m.value, value: m.value }, m.label)));
385
+ });
386
+
387
+ /* ============================================================================
388
+ * Form Field & RadioGroup
389
+ * ========================================================================== */
390
+
391
+ export const FieldDescription = element('p', 'mf-field-description');
392
+ export const FieldError = forwardRef(function FieldError({ className, role = 'alert', ...props }, ref) {
393
+ return h('p', { ...props, role, ref, className: cx('mf-field-error', className) });
394
+ });
395
+
396
+ export const Field = forwardRef(function Field({ label, description, error, required = false, htmlFor, className, children, ...props }, ref) {
397
+ const generatedId = useId();
398
+ const controlId = htmlFor ?? `${generatedId}-control`;
399
+ const descId = description ? `${generatedId}-desc` : undefined;
400
+ const errId = error ? `${generatedId}-err` : undefined;
401
+ const describedBy = [descId, errId].filter(Boolean).join(' ') || undefined;
402
+
403
+ const enhancedChildren = React.Children.map(children, child => {
404
+ if (!React.isValidElement(child)) return child;
405
+ return React.cloneElement(child, {
406
+ id: child.props.id ?? controlId,
407
+ 'aria-describedby': [child.props['aria-describedby'], describedBy].filter(Boolean).join(' ') || undefined,
408
+ 'aria-invalid': error ? true : child.props['aria-invalid'],
409
+ required: required || child.props.required,
410
+ });
411
+ });
412
+
413
+ return h('div', { ...props, ref, className: cx('mf-field', className) },
414
+ label && h(Label, { htmlFor: controlId }, label, required && h('span', { 'aria-hidden': true, className: 'mf-field-required' }, ' *')),
415
+ enhancedChildren,
416
+ description && h(FieldDescription, { id: descId }, description),
417
+ error && h(FieldError, { id: errId }, error)
418
+ );
419
+ });
420
+
421
+ export const RadioGroup = forwardRef(function RadioGroup({ items = [], name, value, defaultValue, onValueChange, label, orientation = 'vertical', className, ...props }, ref) {
422
+ const generatedName = useId();
423
+ const groupName = name ?? generatedName;
424
+ const [selected, setSelected] = useControllable(value, defaultValue ?? items.find(i => !i.disabled)?.value, onValueChange);
425
+
426
+ return h('div', {
427
+ ...props,
428
+ ref,
429
+ role: 'radiogroup',
430
+ 'aria-label': label,
431
+ 'data-orientation': orientation,
432
+ className: cx('mf-radio-group', className),
433
+ }, items.map(item => {
434
+ const id = `${groupName}-${item.value}`;
435
+ const isChecked = selected === item.value;
436
+ return h('label', { key: item.value, htmlFor: id, className: 'mf-check-label mf-radio-option', 'data-disabled': item.disabled || undefined },
437
+ h('input', {
438
+ id,
439
+ type: 'radio',
440
+ name: groupName,
441
+ value: item.value,
442
+ checked: isChecked,
443
+ disabled: item.disabled,
444
+ className: 'mf-radio',
445
+ onChange: () => setSelected(item.value),
446
+ }),
447
+ h('span', { className: 'mf-radio-copy' },
448
+ h('span', { className: 'mf-radio-label' }, item.label),
449
+ item.description && h('small', { className: 'mf-field-description' }, item.description)
450
+ )
451
+ );
452
+ }));
453
+ });
454
+
455
+ /* ============================================================================
456
+ * Navigation, Overlays, Feedback & Data Display
457
+ * ========================================================================== */
458
+
459
+ export const Breadcrumb = forwardRef(function Breadcrumb({ label = 'Breadcrumb', className, children, ...props }, ref) {
460
+ return h('nav', { ...props, ref, 'aria-label': label, className: cx('mf-breadcrumb', className) },
461
+ h('ol', { className: 'mf-breadcrumb-list' }, children)
462
+ );
463
+ });
464
+
465
+ export const BreadcrumbItem = element('li', 'mf-breadcrumb-item');
466
+
467
+ export const BreadcrumbLink = forwardRef(function BreadcrumbLink({ current = false, asChild = false, href, className, children, ...props }, ref) {
468
+ const shared = {
469
+ ...props,
470
+ ref,
471
+ href: current ? undefined : href,
472
+ 'aria-current': current ? 'page' : undefined,
473
+ className: cx('mf-breadcrumb-link', className),
474
+ };
475
+ if (asChild) return h(Slot, shared, children);
476
+ if (current || !href) return h('span', shared, children);
477
+ return h('a', shared, children);
478
+ });
479
+
480
+ export const Pagination = forwardRef(function Pagination({ page = 1, totalPages = 1, onPageChange, label = 'Pagination', className, ...props }, ref) {
481
+ const total = Math.max(1, Number(totalPages) || 1);
482
+ const current = Math.min(total, Math.max(1, Number(page) || 1));
483
+ const pages = Array.from({ length: total }, (_, idx) => idx + 1);
484
+
485
+ return h('nav', { ...props, ref, 'aria-label': label, className: cx('mf-pagination', className) },
486
+ h(Button, {
487
+ variant: 'secondary',
488
+ size: 'sm',
489
+ disabled: current <= 1,
490
+ onClick: () => onPageChange?.(current - 1),
491
+ }, 'Previous'),
492
+ h('div', { className: 'mf-pagination-pages' },
493
+ pages.map(num => h(Button, {
494
+ key: num,
495
+ variant: num === current ? 'primary' : 'ghost',
496
+ size: 'sm',
497
+ 'aria-current': num === current ? 'page' : undefined,
498
+ onClick: () => onPageChange?.(num),
499
+ }, String(num)))
500
+ ),
501
+ h(Button, {
502
+ variant: 'secondary',
503
+ size: 'sm',
504
+ disabled: current >= total,
505
+ onClick: () => onPageChange?.(current + 1),
506
+ }, 'Next')
507
+ );
508
+ });
509
+
510
+ export const Drawer = forwardRef(function Drawer({ side = 'right', className, ...props }, ref) {
511
+ return h(Dialog, {
512
+ ...props,
513
+ ref,
514
+ 'data-side': side,
515
+ className: cx('mf-drawer', className),
516
+ });
517
+ });
518
+
519
+ export const Popover = forwardRef(function Popover({ trigger, title, open, defaultOpen = false, onOpenChange, align = 'start', className, children, ...props }, ref) {
520
+ const id = useId();
521
+ const wrapperRef = useRef(null);
522
+ const [isOpen, setOpen] = useControllable(open, defaultOpen, onOpenChange);
523
+
524
+ useEffect(() => {
525
+ if (!isOpen) return;
526
+ const onPointerDown = (event) => {
527
+ if (wrapperRef.current && !wrapperRef.current.contains(event.target)) setOpen(false);
528
+ };
529
+ const onKeyDown = (event) => {
530
+ if (event.key === 'Escape') setOpen(false);
531
+ };
532
+ document.addEventListener('pointerdown', onPointerDown);
533
+ document.addEventListener('keydown', onKeyDown);
534
+ return () => {
535
+ document.removeEventListener('pointerdown', onPointerDown);
536
+ document.removeEventListener('keydown', onKeyDown);
537
+ };
538
+ }, [isOpen, setOpen]);
539
+
540
+ const triggerElement = React.isValidElement(trigger) ? React.cloneElement(trigger, {
541
+ 'aria-expanded': Boolean(isOpen),
542
+ 'aria-controls': `${id}-popover`,
543
+ onClick: event => {
544
+ trigger.props.onClick?.(event);
545
+ if (!event.defaultPrevented) setOpen(!isOpen);
546
+ },
547
+ }) : null;
548
+
549
+ return h('div', { ref: mergeRefs(wrapperRef, ref), className: cx('mf-popover-root', className) },
550
+ triggerElement,
551
+ isOpen && h('div', {
552
+ ...props,
553
+ id: `${id}-popover`,
554
+ role: 'dialog',
555
+ 'aria-label': typeof title === 'string' ? title : undefined,
556
+ 'data-align': align,
557
+ className: 'mf-popover-content',
558
+ }, title && h('strong', { className: 'mf-popover-title' }, title), children)
559
+ );
560
+ });
561
+
562
+ export const DropdownMenu = forwardRef(function DropdownMenu({ trigger, items = [], label = 'Menu', align = 'start', className, ...props }, ref) {
563
+ const id = useId();
564
+ const wrapperRef = useRef(null);
565
+ const itemRefs = useRef([]);
566
+ const [isOpen, setOpen] = useState(false);
567
+
568
+ useEffect(() => {
569
+ if (!isOpen) return;
570
+ const onPointerDown = (event) => {
571
+ if (wrapperRef.current && !wrapperRef.current.contains(event.target)) setOpen(false);
572
+ };
573
+ const onKeyDown = (event) => {
574
+ if (event.key === 'Escape') setOpen(false);
575
+ };
576
+ document.addEventListener('pointerdown', onPointerDown);
577
+ document.addEventListener('keydown', onKeyDown);
578
+ return () => {
579
+ document.removeEventListener('pointerdown', onPointerDown);
580
+ document.removeEventListener('keydown', onKeyDown);
581
+ };
582
+ }, [isOpen]);
583
+
584
+ function onMenuKeyDown(event, index) {
585
+ const enabled = items.map((it, i) => it.disabled ? -1 : i).filter(i => i >= 0);
586
+ if (!enabled.length) return;
587
+ const pos = enabled.indexOf(index);
588
+ if (event.key === 'ArrowDown') {
589
+ event.preventDefault();
590
+ itemRefs.current[enabled[(pos + 1) % enabled.length]]?.focus();
591
+ } else if (event.key === 'ArrowUp') {
592
+ event.preventDefault();
593
+ itemRefs.current[enabled[(pos - 1 + enabled.length) % enabled.length]]?.focus();
594
+ } else if (event.key === 'Home') {
595
+ event.preventDefault();
596
+ itemRefs.current[enabled[0]]?.focus();
597
+ } else if (event.key === 'End') {
598
+ event.preventDefault();
599
+ itemRefs.current[enabled.at(-1)]?.focus();
600
+ }
601
+ }
602
+
603
+ const triggerElement = React.isValidElement(trigger) ? React.cloneElement(trigger, {
604
+ 'aria-haspopup': 'menu',
605
+ 'aria-expanded': isOpen,
606
+ 'aria-controls': `${id}-menu`,
607
+ onClick: event => {
608
+ trigger.props.onClick?.(event);
609
+ if (!event.defaultPrevented) setOpen(prev => !prev);
610
+ },
611
+ }) : null;
612
+
613
+ return h('div', { ref: mergeRefs(wrapperRef, ref), className: cx('mf-popover-root', className) },
614
+ triggerElement,
615
+ isOpen && h('div', {
616
+ ...props,
617
+ id: `${id}-menu`,
618
+ role: 'menu',
619
+ 'aria-label': label,
620
+ 'data-align': align,
621
+ className: 'mf-popover-content mf-dropdown-menu',
622
+ }, items.map((item, index) => h('button', {
623
+ key: item.value ?? index,
624
+ ref: node => { itemRefs.current[index] = node; },
625
+ type: 'button',
626
+ role: 'menuitem',
627
+ disabled: item.disabled,
628
+ 'data-variant': item.variant,
629
+ className: 'mf-dropdown-item',
630
+ onKeyDown: event => onMenuKeyDown(event, index),
631
+ onClick: () => {
632
+ if (item.disabled) return;
633
+ item.onSelect?.(item.value);
634
+ setOpen(false);
635
+ },
636
+ }, item.label)))
637
+ );
638
+ });
639
+
640
+ export const Tooltip = forwardRef(function Tooltip({ content, className, children, ...props }, ref) {
641
+ const id = useId();
642
+ const [visible, setVisible] = useState(false);
643
+ const trigger = React.isValidElement(children) ? React.cloneElement(children, {
644
+ 'aria-describedby': visible ? id : children.props['aria-describedby'],
645
+ onMouseEnter: e => { children.props.onMouseEnter?.(e); setVisible(true); },
646
+ onMouseLeave: e => { children.props.onMouseLeave?.(e); setVisible(false); },
647
+ onFocus: e => { children.props.onFocus?.(e); setVisible(true); },
648
+ onBlur: e => { children.props.onBlur?.(e); setVisible(false); },
649
+ onKeyDown: e => {
650
+ children.props.onKeyDown?.(e);
651
+ if (e.key === 'Escape') setVisible(false);
652
+ },
653
+ }) : children;
654
+
655
+ return h('span', { ...props, ref, className: cx('mf-tooltip-root', className) },
656
+ trigger,
657
+ visible && h('span', { id, role: 'tooltip', className: 'mf-tooltip-bubble' }, content)
658
+ );
659
+ });
660
+
661
+ export const EmptyState = forwardRef(function EmptyState({ icon, title, description, action, className, children, ...props }, ref) {
662
+ return h('div', { ...props, ref, className: cx('mf-empty-state', className) },
663
+ icon && h('div', { className: 'mf-empty-icon', 'aria-hidden': true }, icon),
664
+ title && h('strong', { className: 'mf-empty-title' }, title),
665
+ description && h('p', { className: 'mf-empty-description' }, description),
666
+ action && h('div', { className: 'mf-empty-action' }, action),
667
+ children
668
+ );
669
+ });
670
+
671
+ export const Kbd = element('kbd', 'mf-kbd');
672
+
673
+ export const CodeBlock = forwardRef(function CodeBlock({ code, language, className, children, ...props }, ref) {
674
+ return h('pre', { ...props, ref, 'data-language': language, className: cx('mf-code-block', className) },
675
+ h('code', null, code ?? children)
676
+ );
677
+ });
678
+
679
+ const ToastContext = createContext(null);
680
+
681
+ export function ToastProvider({ children }) {
682
+ const [toasts, setToasts] = useState([]);
683
+ const dismiss = useCallback((id) => {
684
+ setToasts(prev => prev.filter(item => item.id !== id));
685
+ }, []);
686
+ const toast = useCallback(({ title, description, variant = 'secondary', duration = 4500 }) => {
687
+ const id = Math.random().toString(36).slice(2, 10);
688
+ setToasts(prev => [...prev, { id, title, description, variant }]);
689
+ if (duration > 0 && typeof window !== 'undefined') {
690
+ window.setTimeout(() => dismiss(id), duration);
691
+ }
692
+ return id;
693
+ }, [dismiss]);
694
+
695
+ const value = useMemo(() => ({ toasts, toast, dismiss }), [toasts, toast, dismiss]);
696
+
697
+ return h(ToastContext.Provider, { value },
698
+ children,
699
+ h('div', { className: 'mf-toast-viewport', role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' },
700
+ toasts.map(item => h('div', { key: item.id, className: 'mf-toast', 'data-variant': item.variant },
701
+ h('div', { className: 'mf-toast-body' },
702
+ item.title && h('strong', { className: 'mf-toast-title' }, item.title),
703
+ item.description && h('div', { className: 'mf-toast-description' }, item.description)
704
+ ),
705
+ h('button', { type: 'button', className: 'mf-toast-close', 'aria-label': 'Dismiss notification', onClick: () => dismiss(item.id) }, '×')
706
+ ))
707
+ )
708
+ );
709
+ }
710
+
711
+ export function useToast() {
712
+ const ctx = useContext(ToastContext);
713
+ if (!ctx) throw new Error('useToast must be used within a Moonframe ToastProvider.');
714
+ return ctx;
715
+ }
716
+
717
+ /**
718
+ * Interactive DataTable component for Next.js data workspaces.
719
+ * Supports searching, column sorting, pagination, and empty state out of the box.
720
+ */
721
+ export const DataTable = forwardRef(function DataTable({
722
+ columns = [],
723
+ data = [],
724
+ rowKey = 'id',
725
+ caption,
726
+ searchable = false,
727
+ searchPlaceholder = 'Search records…',
728
+ emptyTitle = 'No matching records',
729
+ emptyDescription = 'Try adjusting your search or filter criteria.',
730
+ pageSize = 0,
731
+ className,
732
+ ...props
733
+ }, ref) {
734
+ const [query, setQuery] = useState('');
735
+ const [sortBy, setSortBy] = useState(null);
736
+ const [sortDirection, setSortDirection] = useState('asc');
737
+ const [page, setPage] = useState(1);
738
+
739
+ const filtered = useMemo(() => {
740
+ const q = query.trim().toLowerCase();
741
+ const rows = !q
742
+ ? [...data]
743
+ : data.filter(row => columns.some(col => {
744
+ const val = col.accessor ? col.accessor(row) : row?.[col.key];
745
+ return val != null && String(val).toLowerCase().includes(q);
746
+ }));
747
+
748
+ if (sortBy) {
749
+ const col = columns.find(c => c.key === sortBy);
750
+ rows.sort((a, b) => {
751
+ const av = col?.accessor ? col.accessor(a) : a?.[sortBy];
752
+ const bv = col?.accessor ? col.accessor(b) : b?.[sortBy];
753
+ const cmp = typeof av === 'number' && typeof bv === 'number'
754
+ ? av - bv
755
+ : String(av ?? '').localeCompare(String(bv ?? ''));
756
+ return sortDirection === 'asc' ? cmp : -cmp;
757
+ });
758
+ }
759
+ return rows;
760
+ }, [data, columns, query, sortBy, sortDirection]);
761
+
762
+ const totalPages = pageSize > 0 ? Math.max(1, Math.ceil(filtered.length / pageSize)) : 1;
763
+ const effectivePage = Math.min(page, totalPages);
764
+ const visibleRows = pageSize > 0
765
+ ? filtered.slice((effectivePage - 1) * pageSize, effectivePage * pageSize)
766
+ : filtered;
767
+
768
+ function toggleSort(key) {
769
+ if (sortBy === key) {
770
+ setSortDirection(prev => prev === 'asc' ? 'desc' : 'asc');
771
+ } else {
772
+ setSortBy(key);
773
+ setSortDirection('asc');
774
+ }
775
+ }
776
+
777
+ return h('div', { ...props, ref, className: cx('mf-data-table', className) },
778
+ searchable && h('div', { className: 'mf-data-table-toolbar' },
779
+ h(Input, {
780
+ type: 'search',
781
+ 'aria-label': searchPlaceholder,
782
+ placeholder: searchPlaceholder,
783
+ value: query,
784
+ onChange: e => { setQuery(e.currentTarget.value); setPage(1); },
785
+ })
786
+ ),
787
+ h('div', { className: 'mf-table-wrapper' },
788
+ h(Table, null,
789
+ caption && h(TableCaption, null, caption),
790
+ h(TableHeader, null,
791
+ h(TableRow, null,
792
+ columns.map(col => h(TableHead, {
793
+ key: col.key,
794
+ 'aria-sort': sortBy === col.key ? (sortDirection === 'asc' ? 'ascending' : 'descending') : undefined,
795
+ }, col.sortable
796
+ ? h('button', {
797
+ type: 'button',
798
+ className: 'mf-table-sort',
799
+ onClick: () => toggleSort(col.key),
800
+ }, col.header, sortBy === col.key ? (sortDirection === 'asc' ? ' ↑' : ' ↓') : '')
801
+ : col.header))
802
+ )
803
+ ),
804
+ h(TableBody, null,
805
+ visibleRows.length > 0
806
+ ? visibleRows.map((row, index) => {
807
+ const key = typeof rowKey === 'function' ? rowKey(row, index) : (row?.[rowKey] ?? index);
808
+ return h(TableRow, { key },
809
+ columns.map(col => h(TableCell, { key: col.key },
810
+ col.render ? col.render(row, index) : String((col.accessor ? col.accessor(row) : row?.[col.key]) ?? '')
811
+ ))
812
+ );
813
+ })
814
+ : h(TableRow, null,
815
+ h(TableCell, { colSpan: Math.max(1, columns.length) },
816
+ h(EmptyState, { title: emptyTitle, description: emptyDescription })
817
+ )
818
+ )
819
+ )
820
+ )
821
+ ),
822
+ pageSize > 0 && totalPages > 1 && h('div', { className: 'mf-data-table-footer' },
823
+ h(Pagination, { page: effectivePage, totalPages, onPageChange: setPage })
824
+ )
825
+ );
826
+ });
827
+
828
+ /* ============================================================================
829
+ * Extended Inputs, Charts, Navigation & Level C Reusable Composite Blocks
830
+ * ========================================================================== */
831
+
832
+ export const OTPInput = forwardRef(function OTPInput({
833
+ length = 6,
834
+ value,
835
+ defaultValue = '',
836
+ onValueChange,
837
+ onComplete,
838
+ disabled = false,
839
+ label = 'Verification code',
840
+ className,
841
+ ...props
842
+ }, ref) {
843
+ const count = Math.max(4, Math.min(8, Number(length) || 6));
844
+ const [code, setCode] = useControllable(value, defaultValue, onValueChange);
845
+ const inputsRef = useRef([]);
846
+ const digits = Array.from({ length: count }, (_, idx) => (code || '')[idx] || '');
847
+
848
+ function updateAt(index, char) {
849
+ const clean = char.replace(/\D/g, '').slice(-1);
850
+ const next = digits.slice();
851
+ next[index] = clean;
852
+ const joined = next.join('');
853
+ setCode(joined);
854
+ if (clean && index < count - 1) {
855
+ inputsRef.current[index + 1]?.focus();
856
+ }
857
+ if (joined.length === count && !next.includes('')) {
858
+ onComplete?.(joined);
859
+ }
860
+ }
861
+
862
+ function onPaste(event) {
863
+ const pasted = (event.clipboardData?.getData('text') || '').replace(/\D/g, '').slice(0, count);
864
+ if (!pasted) return;
865
+ event.preventDefault();
866
+ setCode(pasted);
867
+ const focusIdx = Math.min(pasted.length, count - 1);
868
+ inputsRef.current[focusIdx]?.focus();
869
+ if (pasted.length === count) {
870
+ onComplete?.(pasted);
871
+ }
872
+ }
873
+
874
+ return h('div', {
875
+ ...props,
876
+ ref,
877
+ role: 'group',
878
+ 'aria-label': label,
879
+ className: cx('mf-otp-group', className),
880
+ }, digits.map((digit, index) => h('input', {
881
+ key: index,
882
+ ref: node => { inputsRef.current[index] = node; },
883
+ type: 'text',
884
+ inputMode: 'numeric',
885
+ pattern: '[0-9]*',
886
+ maxLength: 1,
887
+ disabled,
888
+ value: digit,
889
+ autoComplete: index === 0 ? 'one-time-code' : 'off',
890
+ 'aria-label': `${label} digit ${index + 1} of ${count}`,
891
+ className: 'mf-input mf-otp-slot',
892
+ onPaste,
893
+ onChange: e => updateAt(index, e.currentTarget.value),
894
+ onKeyDown: e => {
895
+ if (e.key === 'Backspace' && !digit && index > 0) {
896
+ inputsRef.current[index - 1]?.focus();
897
+ } else if (e.key === 'ArrowLeft' && index > 0) {
898
+ e.preventDefault();
899
+ inputsRef.current[index - 1]?.focus();
900
+ } else if (e.key === 'ArrowRight' && index < count - 1) {
901
+ e.preventDefault();
902
+ inputsRef.current[index + 1]?.focus();
903
+ }
904
+ },
905
+ })));
906
+ });
907
+
908
+ export const PasswordField = forwardRef(function PasswordField({
909
+ defaultVisible = false,
910
+ showStrength = false,
911
+ toggleLabel,
912
+ value,
913
+ defaultValue,
914
+ onChange,
915
+ className,
916
+ ...props
917
+ }, ref) {
918
+ const [visible, setVisible] = useState(defaultVisible);
919
+ const [internal, setInternal] = useState(defaultValue ?? '');
920
+ const current = value !== undefined ? String(value) : String(internal);
921
+
922
+ const score = useMemo(() => {
923
+ if (!current) return 0;
924
+ let pts = 0;
925
+ if (current.length >= 8) pts += 1;
926
+ if (/[A-Z]/.test(current) && /[a-z]/.test(current)) pts += 1;
927
+ if (/\d/.test(current)) pts += 1;
928
+ if (/[^A-Za-z0-9]/.test(current)) pts += 1;
929
+ return pts;
930
+ }, [current]);
931
+
932
+ const strengthLabels = ['Too short', 'Weak', 'Fair', 'Good', 'Strong'];
933
+
934
+ return h('div', { className: cx('mf-password-root', className) },
935
+ h('div', { className: 'mf-password-row' },
936
+ h(Input, {
937
+ ...props,
938
+ ref,
939
+ type: visible ? 'text' : 'password',
940
+ value: value !== undefined ? value : internal,
941
+ onChange: e => {
942
+ if (value === undefined) setInternal(e.currentTarget.value);
943
+ onChange?.(e);
944
+ },
945
+ }),
946
+ h(Button, {
947
+ type: 'button',
948
+ variant: 'secondary',
949
+ size: 'sm',
950
+ className: 'mf-password-toggle',
951
+ 'aria-label': toggleLabel ?? (visible ? 'Hide password' : 'Show password'),
952
+ onClick: () => setVisible(v => !v),
953
+ }, visible ? 'Hide' : 'Show')
954
+ ),
955
+ showStrength && h('div', { className: 'mf-password-strength', 'aria-live': 'polite' },
956
+ h('div', { className: 'mf-password-bars' },
957
+ [1, 2, 3, 4].map(level => h('span', {
958
+ key: level,
959
+ className: 'mf-password-bar',
960
+ 'data-active': score >= level ? 'true' : undefined,
961
+ }))
962
+ ),
963
+ h('span', { className: 'mf-field-description' }, strengthLabels[score])
964
+ )
965
+ );
966
+ });
967
+
968
+ export const SearchInput = forwardRef(function SearchInput({
969
+ value,
970
+ defaultValue = '',
971
+ onValueChange,
972
+ onClear,
973
+ shortcut,
974
+ placeholder = 'Search…',
975
+ className,
976
+ onChange,
977
+ ...props
978
+ }, ref) {
979
+ const [query, setQuery] = useControllable(value, defaultValue, onValueChange);
980
+
981
+ return h('div', { className: cx('mf-search-input-wrap', className) },
982
+ h('span', { className: 'mf-search-icon', 'aria-hidden': true }, '⌕'),
983
+ h(Input, {
984
+ ...props,
985
+ ref,
986
+ type: 'search',
987
+ placeholder,
988
+ value: query,
989
+ className: 'mf-search-input',
990
+ onChange: e => {
991
+ setQuery(e.currentTarget.value);
992
+ onChange?.(e);
993
+ },
994
+ onKeyDown: e => {
995
+ props.onKeyDown?.(e);
996
+ if (e.key === 'Escape' && query) {
997
+ setQuery('');
998
+ onClear?.();
999
+ }
1000
+ },
1001
+ }),
1002
+ query
1003
+ ? h('button', {
1004
+ type: 'button',
1005
+ className: 'mf-search-clear',
1006
+ 'aria-label': 'Clear search',
1007
+ onClick: () => {
1008
+ setQuery('');
1009
+ onClear?.();
1010
+ },
1011
+ }, '×')
1012
+ : shortcut && h(Kbd, { className: 'mf-search-shortcut' }, shortcut)
1013
+ );
1014
+ });
1015
+
1016
+ export const Slider = forwardRef(function Slider({
1017
+ min = 0,
1018
+ max = 100,
1019
+ step = 1,
1020
+ value,
1021
+ defaultValue = 50,
1022
+ onValueChange,
1023
+ label,
1024
+ showValue = false,
1025
+ formatValue,
1026
+ className,
1027
+ onChange,
1028
+ ...props
1029
+ }, ref) {
1030
+ const [current, setCurrent] = useControllable(value, defaultValue, onValueChange);
1031
+ const display = formatValue ? formatValue(Number(current)) : `${current}`;
1032
+
1033
+ return h('div', { className: cx('mf-slider-wrap', className) },
1034
+ (label || showValue) && h('div', { className: 'mf-slider-header' },
1035
+ label && h('span', { className: 'mf-label' }, label),
1036
+ showValue && h('output', { className: 'mf-slider-output' }, display)
1037
+ ),
1038
+ h('input', {
1039
+ ...props,
1040
+ ref,
1041
+ type: 'range',
1042
+ min,
1043
+ max,
1044
+ step,
1045
+ value: current,
1046
+ 'aria-label': props['aria-label'] ?? (typeof label === 'string' ? label : 'Slider'),
1047
+ className: 'mf-slider',
1048
+ onChange: e => {
1049
+ const next = Number(e.currentTarget.value);
1050
+ setCurrent(next);
1051
+ onChange?.(e);
1052
+ },
1053
+ })
1054
+ );
1055
+ });
1056
+
1057
+ export const TagInput = forwardRef(function TagInput({
1058
+ value,
1059
+ defaultValue = [],
1060
+ onValueChange,
1061
+ placeholder = 'Add tag and press Enter…',
1062
+ disabled = false,
1063
+ label = 'Tags',
1064
+ className,
1065
+ ...props
1066
+ }, ref) {
1067
+ const [tags, setTags] = useControllable(value, defaultValue, onValueChange);
1068
+ const [draft, setDraft] = useState('');
1069
+
1070
+ function addTag(raw) {
1071
+ const trimmed = String(raw || '').trim();
1072
+ if (!trimmed) return;
1073
+ if (!tags.includes(trimmed)) {
1074
+ setTags([...tags, trimmed]);
1075
+ }
1076
+ setDraft('');
1077
+ }
1078
+
1079
+ function removeTag(target) {
1080
+ setTags(tags.filter(t => t !== target));
1081
+ }
1082
+
1083
+ return h('div', {
1084
+ ...props,
1085
+ ref,
1086
+ role: 'group',
1087
+ 'aria-label': label,
1088
+ className: cx('mf-tag-input', className),
1089
+ },
1090
+ tags.map(tag => h(Badge, { key: tag, variant: 'secondary', className: 'mf-tag-chip' },
1091
+ h('span', null, tag),
1092
+ !disabled && h('button', {
1093
+ type: 'button',
1094
+ className: 'mf-tag-remove',
1095
+ 'aria-label': `Remove ${tag}`,
1096
+ onClick: () => removeTag(tag),
1097
+ }, '×')
1098
+ )),
1099
+ h('input', {
1100
+ type: 'text',
1101
+ disabled,
1102
+ value: draft,
1103
+ placeholder,
1104
+ 'aria-label': placeholder,
1105
+ className: 'mf-tag-field',
1106
+ onChange: e => setDraft(e.currentTarget.value),
1107
+ onKeyDown: e => {
1108
+ if (e.key === 'Enter' || e.key === ',') {
1109
+ e.preventDefault();
1110
+ addTag(draft);
1111
+ } else if (e.key === 'Backspace' && !draft && tags.length > 0) {
1112
+ removeTag(tags[tags.length - 1]);
1113
+ }
1114
+ },
1115
+ onBlur: () => {
1116
+ if (draft.trim()) addTag(draft);
1117
+ },
1118
+ })
1119
+ );
1120
+ });
1121
+
1122
+ export const SegmentedControl = forwardRef(function SegmentedControl({
1123
+ items = [],
1124
+ value,
1125
+ defaultValue,
1126
+ onValueChange,
1127
+ label = 'Options',
1128
+ size = 'md',
1129
+ className,
1130
+ ...props
1131
+ }, ref) {
1132
+ const [selected, setSelected] = useControllable(
1133
+ value,
1134
+ defaultValue ?? items.find(i => !i.disabled)?.value,
1135
+ onValueChange,
1136
+ );
1137
+
1138
+ return h('div', {
1139
+ ...props,
1140
+ ref,
1141
+ role: 'group',
1142
+ 'aria-label': label,
1143
+ 'data-size': size,
1144
+ className: cx('mf-segmented', className),
1145
+ }, items.map(item => {
1146
+ const active = selected === item.value;
1147
+ return h('button', {
1148
+ key: item.value,
1149
+ type: 'button',
1150
+ disabled: item.disabled,
1151
+ 'aria-pressed': active,
1152
+ 'data-active': active ? 'true' : undefined,
1153
+ className: 'mf-segmented-item',
1154
+ onClick: () => setSelected(item.value),
1155
+ }, item.label);
1156
+ }));
1157
+ });
1158
+
1159
+ export const FileDropzone = forwardRef(function FileDropzone({
1160
+ accept,
1161
+ multiple = false,
1162
+ disabled = false,
1163
+ title = 'Drop files here or click to browse',
1164
+ description = 'Supports standard documents and media files.',
1165
+ onFilesSelected,
1166
+ className,
1167
+ ...props
1168
+ }, ref) {
1169
+ const inputRef = useRef(null);
1170
+ const [dragging, setDragging] = useState(false);
1171
+ const [selectedNames, setSelectedNames] = useState([]);
1172
+
1173
+ function handleFiles(fileList) {
1174
+ if (!fileList || disabled) return;
1175
+ const files = Array.from(fileList);
1176
+ setSelectedNames(files.map(f => f.name));
1177
+ onFilesSelected?.(files);
1178
+ }
1179
+
1180
+ return h('div', {
1181
+ ...props,
1182
+ ref,
1183
+ role: 'button',
1184
+ tabIndex: disabled ? -1 : 0,
1185
+ 'aria-disabled': disabled || undefined,
1186
+ 'data-dragging': dragging ? 'true' : undefined,
1187
+ className: cx('mf-dropzone', className),
1188
+ onClick: () => { if (!disabled) inputRef.current?.click(); },
1189
+ onKeyDown: e => {
1190
+ if (!disabled && (e.key === 'Enter' || e.key === ' ')) {
1191
+ e.preventDefault();
1192
+ inputRef.current?.click();
1193
+ }
1194
+ },
1195
+ onDragOver: e => {
1196
+ e.preventDefault();
1197
+ if (!disabled) setDragging(true);
1198
+ },
1199
+ onDragLeave: () => setDragging(false),
1200
+ onDrop: e => {
1201
+ e.preventDefault();
1202
+ setDragging(false);
1203
+ handleFiles(e.dataTransfer?.files);
1204
+ },
1205
+ },
1206
+ h('input', {
1207
+ ref: inputRef,
1208
+ type: 'file',
1209
+ accept,
1210
+ multiple,
1211
+ disabled,
1212
+ hidden: true,
1213
+ onChange: e => handleFiles(e.currentTarget.files),
1214
+ }),
1215
+ h('strong', { className: 'mf-dropzone-title' }, title),
1216
+ description && h('span', { className: 'mf-dropzone-description' }, description),
1217
+ selectedNames.length > 0 && h('div', { className: 'mf-dropzone-files' },
1218
+ selectedNames.map(name => h(Badge, { key: name, variant: 'primary' }, name))
1219
+ )
1220
+ );
1221
+ });
1222
+
1223
+ export const BarChart = forwardRef(function BarChart({
1224
+ data = [],
1225
+ height = 180,
1226
+ label = 'Bar chart',
1227
+ formatValue,
1228
+ className,
1229
+ ...props
1230
+ }, ref) {
1231
+ const maxVal = Math.max(1, ...data.map(d => Number(d.value) || 0));
1232
+ const width = Math.max(240, data.length * 56);
1233
+ const chartHeight = Math.max(120, Number(height) || 180);
1234
+ const plotHeight = chartHeight - 36;
1235
+
1236
+ return h('div', { ...props, ref, className: cx('mf-chart-wrap', className) },
1237
+ h('svg', {
1238
+ role: 'img',
1239
+ 'aria-label': label,
1240
+ viewBox: `0 0 ${width} ${chartHeight}`,
1241
+ className: 'mf-bar-chart',
1242
+ },
1243
+ h('title', null, label),
1244
+ data.map((item, index) => {
1245
+ const val = Math.max(0, Number(item.value) || 0);
1246
+ const barHeight = Math.max(4, Math.round((val / maxVal) * (plotHeight - 20)));
1247
+ const slotWidth = width / Math.max(1, data.length);
1248
+ const barWidth = Math.max(16, Math.min(40, slotWidth * 0.58));
1249
+ const x = index * slotWidth + (slotWidth - barWidth) / 2;
1250
+ const y = plotHeight - barHeight;
1251
+ return h('g', { key: item.label ?? index, className: 'mf-bar-group' },
1252
+ h('rect', {
1253
+ x,
1254
+ y,
1255
+ width: barWidth,
1256
+ height: barHeight,
1257
+ rx: 3,
1258
+ className: 'mf-bar-rect',
1259
+ 'data-tone': item.tone,
1260
+ }),
1261
+ h('text', {
1262
+ x: x + barWidth / 2,
1263
+ y: Math.max(12, y - 6),
1264
+ textAnchor: 'middle',
1265
+ className: 'mf-bar-value',
1266
+ }, formatValue ? formatValue(val) : String(val)),
1267
+ h('text', {
1268
+ x: x + barWidth / 2,
1269
+ y: chartHeight - 10,
1270
+ textAnchor: 'middle',
1271
+ className: 'mf-bar-label',
1272
+ }, item.label)
1273
+ );
1274
+ })
1275
+ )
1276
+ );
1277
+ });
1278
+
1279
+ export const Sparkline = forwardRef(function Sparkline({
1280
+ data = [],
1281
+ width = 120,
1282
+ height = 36,
1283
+ label = 'Trend sparkline',
1284
+ variant = 'primary',
1285
+ className,
1286
+ ...props
1287
+ }, ref) {
1288
+ const points = data.length >= 2 ? data.map(Number) : [0, 0];
1289
+ const min = Math.min(...points);
1290
+ const max = Math.max(...points);
1291
+ const span = max - min || 1;
1292
+ const pad = 4;
1293
+ const w = Math.max(48, Number(width) || 120);
1294
+ const hgt = Math.max(20, Number(height) || 36);
1295
+
1296
+ const coords = points.map((val, idx) => {
1297
+ const x = pad + (idx / (points.length - 1)) * (w - pad * 2);
1298
+ const y = hgt - pad - ((val - min) / span) * (hgt - pad * 2);
1299
+ return [Number(x.toFixed(1)), Number(y.toFixed(1))];
1300
+ });
1301
+ const polyline = coords.map(([x, y]) => `${x},${y}`).join(' ');
1302
+ const area = `${coords[0][0]},${hgt - pad} ${polyline} ${coords[coords.length - 1][0]},${hgt - pad}`;
1303
+
1304
+ return h('svg', {
1305
+ ...props,
1306
+ ref,
1307
+ role: 'img',
1308
+ 'aria-label': label,
1309
+ viewBox: `0 0 ${w} ${hgt}`,
1310
+ width: w,
1311
+ height: hgt,
1312
+ 'data-variant': variant,
1313
+ className: cx('mf-sparkline', className),
1314
+ },
1315
+ h('title', null, label),
1316
+ h('polygon', { points: area, className: 'mf-sparkline-area' }),
1317
+ h('polyline', { points: polyline, fill: 'none', className: 'mf-sparkline-line' })
1318
+ );
1319
+ });
1320
+
1321
+ export const Stepper = forwardRef(function Stepper({
1322
+ steps = [],
1323
+ currentStep = 0,
1324
+ orientation = 'horizontal',
1325
+ label = 'Progress steps',
1326
+ className,
1327
+ ...props
1328
+ }, ref) {
1329
+ return h('ol', {
1330
+ ...props,
1331
+ ref,
1332
+ 'aria-label': label,
1333
+ 'data-orientation': orientation,
1334
+ className: cx('mf-stepper', className),
1335
+ }, steps.map((step, index) => {
1336
+ const status = step.status ?? (index < currentStep ? 'complete' : index === currentStep ? 'current' : 'upcoming');
1337
+ return h('li', {
1338
+ key: step.id ?? step.title ?? index,
1339
+ 'aria-current': status === 'current' ? 'step' : undefined,
1340
+ 'data-status': status,
1341
+ className: 'mf-stepper-item',
1342
+ },
1343
+ h('span', { className: 'mf-stepper-indicator', 'aria-hidden': true },
1344
+ status === 'complete' ? '✓' : String(index + 1)
1345
+ ),
1346
+ h('div', { className: 'mf-stepper-copy' },
1347
+ h('strong', { className: 'mf-stepper-title' }, step.title),
1348
+ step.description && h('span', { className: 'mf-stepper-description' }, step.description)
1349
+ )
1350
+ );
1351
+ }));
1352
+ });
1353
+
1354
+ export const Timeline = forwardRef(function Timeline({
1355
+ items = [],
1356
+ className,
1357
+ ...props
1358
+ }, ref) {
1359
+ return h('ol', { ...props, ref, className: cx('mf-timeline', className) },
1360
+ items.map((item, index) => h('li', {
1361
+ key: item.id ?? index,
1362
+ 'data-tone': item.tone,
1363
+ className: 'mf-timeline-item',
1364
+ },
1365
+ h('span', { className: 'mf-timeline-marker', 'aria-hidden': true }, item.icon ?? '•'),
1366
+ h('div', { className: 'mf-timeline-body' },
1367
+ h('div', { className: 'mf-timeline-header' },
1368
+ h('strong', { className: 'mf-timeline-title' }, item.title),
1369
+ item.badge && h(Badge, { variant: item.tone ?? 'secondary' }, item.badge),
1370
+ item.time && h('time', { className: 'mf-timeline-time' }, item.time)
1371
+ ),
1372
+ item.description && h('p', { className: 'mf-timeline-description' }, item.description)
1373
+ )
1374
+ ))
1375
+ );
1376
+ });
1377
+
1378
+ export const AvatarGroup = forwardRef(function AvatarGroup({
1379
+ items = [],
1380
+ max = 4,
1381
+ label = 'Team members',
1382
+ className,
1383
+ ...props
1384
+ }, ref) {
1385
+ const limit = Math.max(1, Number(max) || 4);
1386
+ const visible = items.slice(0, limit);
1387
+ const remaining = Math.max(0, items.length - visible.length);
1388
+
1389
+ return h('div', {
1390
+ ...props,
1391
+ ref,
1392
+ role: 'group',
1393
+ 'aria-label': label,
1394
+ className: cx('mf-avatar-group', className),
1395
+ },
1396
+ visible.map((item, idx) => h(Avatar, {
1397
+ key: item.id ?? item.alt ?? idx,
1398
+ src: item.src,
1399
+ alt: item.alt,
1400
+ fallback: item.fallback,
1401
+ className: 'mf-avatar-group-item',
1402
+ })),
1403
+ remaining > 0 && h('span', {
1404
+ className: 'mf-avatar mf-avatar-group-item mf-avatar-overflow',
1405
+ 'aria-label': `${remaining} more members`,
1406
+ }, `+${remaining}`)
1407
+ );
1408
+ });
1409
+
1410
+ export const DescriptionTerm = element('dt', 'mf-dl-term');
1411
+ export const DescriptionDetails = element('dd', 'mf-dl-details');
1412
+
1413
+ export const DescriptionList = forwardRef(function DescriptionList({
1414
+ items,
1415
+ columns = 2,
1416
+ className,
1417
+ children,
1418
+ ...props
1419
+ }, ref) {
1420
+ return h('dl', {
1421
+ ...props,
1422
+ ref,
1423
+ 'data-columns': columns,
1424
+ className: cx('mf-dl', className),
1425
+ },
1426
+ Array.isArray(items)
1427
+ ? items.map((item, idx) => h('div', { key: item.term ?? idx, className: 'mf-dl-row' },
1428
+ h(DescriptionTerm, null, item.term),
1429
+ h(DescriptionDetails, null, item.details)
1430
+ ))
1431
+ : children
1432
+ );
1433
+ });
1434
+
1435
+ export const Callout = forwardRef(function Callout({
1436
+ title,
1437
+ variant = 'secondary',
1438
+ icon,
1439
+ action,
1440
+ dismissible = false,
1441
+ onDismiss,
1442
+ className,
1443
+ children,
1444
+ ...props
1445
+ }, ref) {
1446
+ const [dismissed, setDismissed] = useState(false);
1447
+ if (dismissed) return null;
1448
+
1449
+ return h('section', {
1450
+ ...props,
1451
+ ref,
1452
+ role: 'region',
1453
+ 'aria-label': typeof title === 'string' ? title : 'Notice',
1454
+ 'data-variant': variant,
1455
+ className: cx('mf-callout', className),
1456
+ },
1457
+ icon && h('span', { className: 'mf-callout-icon', 'aria-hidden': true }, icon),
1458
+ h('div', { className: 'mf-callout-body' },
1459
+ title && h('strong', { className: 'mf-callout-title' }, title),
1460
+ children && h('div', { className: 'mf-callout-content' }, children)
1461
+ ),
1462
+ action && h('div', { className: 'mf-callout-action' }, action),
1463
+ dismissible && h('button', {
1464
+ type: 'button',
1465
+ className: 'mf-callout-dismiss',
1466
+ 'aria-label': 'Dismiss notice',
1467
+ onClick: () => {
1468
+ setDismissed(true);
1469
+ onDismiss?.();
1470
+ },
1471
+ }, '×')
1472
+ );
1473
+ });
1474
+
1475
+ export const Banner = Callout;
1476
+
1477
+ export const CommandPalette = forwardRef(function CommandPalette({
1478
+ open,
1479
+ defaultOpen = false,
1480
+ onOpenChange,
1481
+ items = [],
1482
+ placeholder = 'Type a command or search…',
1483
+ emptyText = 'No matching commands.',
1484
+ title = 'Command Palette',
1485
+ trigger,
1486
+ enableHotkey = false,
1487
+ className,
1488
+ ...props
1489
+ }, ref) {
1490
+ const [isOpen, setOpen] = useControllable(open, defaultOpen, onOpenChange);
1491
+ const [query, setQuery] = useState('');
1492
+ const [activeIndex, setActiveIndex] = useState(0);
1493
+
1494
+ useEffect(() => {
1495
+ if (!enableHotkey) return;
1496
+ const onKeyDown = (event) => {
1497
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k') {
1498
+ event.preventDefault();
1499
+ setOpen(!isOpen);
1500
+ }
1501
+ };
1502
+ window.addEventListener('keydown', onKeyDown);
1503
+ return () => window.removeEventListener('keydown', onKeyDown);
1504
+ }, [enableHotkey, isOpen, setOpen]);
1505
+
1506
+ const filtered = useMemo(() => {
1507
+ const q = query.trim().toLowerCase();
1508
+ if (!q) return items;
1509
+ return items.filter(item => {
1510
+ const hay = [item.label, item.group, ...(item.keywords || [])].filter(Boolean).join(' ').toLowerCase();
1511
+ return hay.includes(q);
1512
+ });
1513
+ }, [items, query]);
1514
+
1515
+ const enabledItems = filtered.filter(i => !i.disabled);
1516
+
1517
+ return h(Dialog, {
1518
+ ...props,
1519
+ ref,
1520
+ open: isOpen,
1521
+ onOpenChange: next => {
1522
+ setOpen(next);
1523
+ if (!next) setQuery('');
1524
+ },
1525
+ title,
1526
+ trigger,
1527
+ className: cx('mf-command-palette', className),
1528
+ },
1529
+ h('div', { className: 'mf-command-search' },
1530
+ h(SearchInput, {
1531
+ placeholder,
1532
+ value: query,
1533
+ onValueChange: val => {
1534
+ setQuery(val);
1535
+ setActiveIndex(0);
1536
+ },
1537
+ onKeyDown: e => {
1538
+ if (!enabledItems.length) return;
1539
+ if (e.key === 'ArrowDown') {
1540
+ e.preventDefault();
1541
+ setActiveIndex(i => (i + 1) % enabledItems.length);
1542
+ } else if (e.key === 'ArrowUp') {
1543
+ e.preventDefault();
1544
+ setActiveIndex(i => (i - 1 + enabledItems.length) % enabledItems.length);
1545
+ } else if (e.key === 'Enter') {
1546
+ const chosen = enabledItems[activeIndex];
1547
+ if (chosen) {
1548
+ e.preventDefault();
1549
+ chosen.onSelect?.(chosen);
1550
+ setOpen(false);
1551
+ }
1552
+ }
1553
+ },
1554
+ })
1555
+ ),
1556
+ h('div', { role: 'listbox', 'aria-label': title, className: 'mf-command-list' },
1557
+ filtered.length > 0
1558
+ ? filtered.map((item, idx) => {
1559
+ const isSelected = enabledItems[activeIndex]?.id === item.id;
1560
+ return h('button', {
1561
+ key: item.id ?? idx,
1562
+ type: 'button',
1563
+ role: 'option',
1564
+ disabled: item.disabled,
1565
+ 'aria-selected': isSelected,
1566
+ 'data-active': isSelected ? 'true' : undefined,
1567
+ className: 'mf-command-item',
1568
+ onClick: () => {
1569
+ if (item.disabled) return;
1570
+ item.onSelect?.(item);
1571
+ setOpen(false);
1572
+ },
1573
+ },
1574
+ h('div', { className: 'mf-command-item-copy' },
1575
+ item.group && h('small', { className: 'mf-command-group' }, item.group),
1576
+ h('span', { className: 'mf-command-label' }, item.label)
1577
+ ),
1578
+ item.shortcut && h(Kbd, null, item.shortcut)
1579
+ );
1580
+ })
1581
+ : h('p', { className: 'mf-command-empty' }, emptyText)
1582
+ )
1583
+ );
1584
+ });
1585
+
1586
+ /* ============================================================================
1587
+ * Level C Reusable Composite Blocks (Exported from @moonframe/ui)
1588
+ * ========================================================================== */
1589
+
1590
+ export const PageHeader = forwardRef(function PageHeader({
1591
+ breadcrumbs,
1592
+ eyebrow,
1593
+ title,
1594
+ description,
1595
+ badge,
1596
+ actions,
1597
+ className,
1598
+ children,
1599
+ ...props
1600
+ }, ref) {
1601
+ return h('header', { ...props, ref, className: cx('mf-page-header', className) },
1602
+ Array.isArray(breadcrumbs) && breadcrumbs.length > 0 && h(Breadcrumb, null,
1603
+ breadcrumbs.map((bc, idx) => h(BreadcrumbItem, { key: bc.label ?? idx },
1604
+ h(BreadcrumbLink, { href: bc.href, current: bc.current ?? idx === breadcrumbs.length - 1 }, bc.label)
1605
+ ))
1606
+ ),
1607
+ !Array.isArray(breadcrumbs) && breadcrumbs,
1608
+ h('div', { className: 'mf-page-header-row' },
1609
+ h('div', { className: 'mf-page-header-copy' },
1610
+ eyebrow && h('span', { className: 'mf-page-header-eyebrow' }, eyebrow),
1611
+ h('div', { className: 'mf-page-header-title-row' },
1612
+ h('h1', { className: 'mf-page-header-title' }, title),
1613
+ badge && h(Badge, { variant: 'primary' }, badge)
1614
+ ),
1615
+ description && h('p', { className: 'mf-page-header-description' }, description)
1616
+ ),
1617
+ actions && h('div', { className: 'mf-page-header-actions' }, actions)
1618
+ ),
1619
+ children
1620
+ );
1621
+ });
1622
+
1623
+ export const MetricGrid = forwardRef(function MetricGrid({
1624
+ items = [],
1625
+ columns,
1626
+ className,
1627
+ ...props
1628
+ }, ref) {
1629
+ return h(Grid, { ...props, ref, columns, className: cx('mf-metric-grid', className) },
1630
+ items.map((item, idx) => h(StatCard, {
1631
+ key: item.id ?? item.label ?? idx,
1632
+ label: item.label,
1633
+ value: item.value,
1634
+ detail: item.detail,
1635
+ icon: item.delta ? h(Badge, { variant: item.deltaTone ?? 'primary' }, item.delta) : item.icon,
1636
+ },
1637
+ Array.isArray(item.trend) && item.trend.length >= 2 && h('div', { className: 'mf-metric-spark' },
1638
+ h(Sparkline, { data: item.trend, label: `${item.label} trend` })
1639
+ )
1640
+ ))
1641
+ );
1642
+ });
1643
+
1644
+ export const AuthCard = forwardRef(function AuthCard({
1645
+ eyebrow,
1646
+ title,
1647
+ description,
1648
+ logo,
1649
+ error,
1650
+ status,
1651
+ socialActions,
1652
+ footer,
1653
+ className,
1654
+ children,
1655
+ ...props
1656
+ }, ref) {
1657
+ return h(Card, { ...props, ref, className: cx('mf-auth-card', className) },
1658
+ h(CardHeader, { className: 'mf-auth-card-header' },
1659
+ logo && h('div', { className: 'mf-auth-logo' }, logo),
1660
+ eyebrow && h(Badge, { variant: 'secondary' }, eyebrow),
1661
+ h(CardTitle, null, title),
1662
+ description && h(CardDescription, null, description)
1663
+ ),
1664
+ h(CardContent, { className: 'mf-auth-card-body' },
1665
+ error && h(Alert, { variant: 'danger', title: 'Authentication error', role: 'alert' }, error),
1666
+ status && h(Alert, { variant: 'primary', title: 'Status' }, status),
1667
+ children,
1668
+ socialActions && h('div', { className: 'mf-auth-social' },
1669
+ h(Separator, null),
1670
+ h('div', { className: 'mf-auth-social-buttons' }, socialActions)
1671
+ )
1672
+ ),
1673
+ footer && h(CardFooter, { className: 'mf-auth-card-footer' }, footer)
1674
+ );
1675
+ });
1676
+
1677
+ export const PricingCard = forwardRef(function PricingCard({
1678
+ name,
1679
+ price,
1680
+ period = '/month',
1681
+ description,
1682
+ badge,
1683
+ featured = false,
1684
+ features = [],
1685
+ ctaLabel = 'Select plan',
1686
+ onSelect,
1687
+ footer,
1688
+ className,
1689
+ ...props
1690
+ }, ref) {
1691
+ return h(Card, {
1692
+ ...props,
1693
+ ref,
1694
+ 'data-featured': featured ? 'true' : undefined,
1695
+ className: cx('mf-pricing-card', className),
1696
+ },
1697
+ h(CardHeader, null,
1698
+ h('div', { className: 'mf-pricing-header-top' },
1699
+ h(CardTitle, null, name),
1700
+ badge && h(Badge, { variant: featured ? 'primary' : 'secondary' }, badge)
1701
+ ),
1702
+ description && h(CardDescription, null, description),
1703
+ h('div', { className: 'mf-pricing-price' },
1704
+ h('strong', { className: 'mf-pricing-amount' }, price),
1705
+ period && h('span', { className: 'mf-pricing-period' }, period)
1706
+ )
1707
+ ),
1708
+ h(CardContent, null,
1709
+ h('ul', { className: 'mf-pricing-features' },
1710
+ features.map((feat, idx) => h('li', { key: idx, className: 'mf-pricing-feature' },
1711
+ h('span', { 'aria-hidden': true, className: 'mf-pricing-check' }, '✓'),
1712
+ h('span', null, feat)
1713
+ ))
1714
+ )
1715
+ ),
1716
+ h(CardFooter, { className: 'mf-pricing-footer' },
1717
+ h(Button, {
1718
+ variant: featured ? 'primary' : 'secondary',
1719
+ className: 'mf-pricing-cta',
1720
+ onClick: onSelect,
1721
+ }, ctaLabel),
1722
+ footer
1723
+ )
1724
+ );
1725
+ });
1726
+
1727
+ export const SettingsSection = forwardRef(function SettingsSection({
1728
+ title,
1729
+ description,
1730
+ badge,
1731
+ footer,
1732
+ action,
1733
+ className,
1734
+ children,
1735
+ ...props
1736
+ }, ref) {
1737
+ return h('section', { ...props, ref, className: cx('mf-settings-section', className) },
1738
+ h('div', { className: 'mf-settings-meta' },
1739
+ h('div', { className: 'mf-settings-title-row' },
1740
+ h('h2', { className: 'mf-settings-title' }, title),
1741
+ badge && h(Badge, { variant: 'secondary' }, badge)
1742
+ ),
1743
+ description && h('p', { className: 'mf-settings-description' }, description)
1744
+ ),
1745
+ h(Card, { className: 'mf-settings-card' },
1746
+ h(CardContent, { className: 'mf-settings-body' }, children),
1747
+ (footer || action) && h(CardFooter, { className: 'mf-settings-footer' },
1748
+ footer && h('span', { className: 'mf-field-description' }, footer),
1749
+ action && h('div', { className: 'mf-settings-action' }, action)
1750
+ )
1751
+ )
1752
+ );
1753
+ });
1754
+
1755
+ export const ActivityFeed = forwardRef(function ActivityFeed({
1756
+ title = 'Recent activity',
1757
+ description,
1758
+ items = [],
1759
+ action,
1760
+ emptyTitle = 'No recent activity',
1761
+ emptyDescription = 'Events and audit entries will appear here.',
1762
+ className,
1763
+ ...props
1764
+ }, ref) {
1765
+ return h(Card, { ...props, ref, className: cx('mf-activity-feed', className) },
1766
+ h(CardHeader, { className: 'mf-activity-header' },
1767
+ h('div', null,
1768
+ h(CardTitle, null, title),
1769
+ description && h(CardDescription, null, description)
1770
+ ),
1771
+ action
1772
+ ),
1773
+ h(CardContent, null,
1774
+ items.length > 0
1775
+ ? h(Timeline, { items })
1776
+ : h(EmptyState, { title: emptyTitle, description: emptyDescription })
1777
+ )
1778
+ );
1779
+ });
1780
+
1781
+ /* M10 Original 15-Skin Vector Brand Marks & Decorative Artwork */
1782
+
1783
+ const SKIN_VECTOR_PATHS = {
1784
+ moonpunk: [
1785
+ { tag: 'polygon', attrs: { points: '6,4 26,2 28,22 18,28 4,24', fill: 'none', stroke: 'currentColor', strokeWidth: '2.5' } },
1786
+ { tag: 'path', attrs: { d: 'M18 5L10 17H16L13 27L23 14H16L18 5Z', fill: 'currentColor' } },
1787
+ ],
1788
+ moonriot: [
1789
+ { tag: 'polygon', attrs: { points: '3,6 29,3 25,27 3,22', fill: 'none', stroke: 'currentColor', strokeWidth: '2.2' } },
1790
+ { tag: 'polygon', attrs: { points: '8,11 24,8 20,21 8,19', fill: 'currentColor' } },
1791
+ ],
1792
+ moonzine: [
1793
+ { tag: 'rect', attrs: { x: '4', y: '5', width: '22', height: '22', fill: 'none', stroke: 'currentColor', strokeWidth: '1.8', strokeDasharray: '4 2' } },
1794
+ { tag: 'path', attrs: { d: 'M8 11H22M8 16H19M8 21H15', stroke: 'currentColor', strokeWidth: '2', strokeLinecap: 'square' } },
1795
+ ],
1796
+ moonhalftone: [
1797
+ { tag: 'rect', attrs: { x: '3', y: '3', width: '26', height: '26', fill: 'none', stroke: 'currentColor', strokeWidth: '2.5' } },
1798
+ { tag: 'circle', attrs: { cx: '10', cy: '10', r: '2.5', fill: 'currentColor' } },
1799
+ { tag: 'circle', attrs: { cx: '20', cy: '10', r: '1.8', fill: 'currentColor' } },
1800
+ { tag: 'circle', attrs: { cx: '10', cy: '20', r: '1.8', fill: 'currentColor' } },
1801
+ { tag: 'circle', attrs: { cx: '20', cy: '20', r: '3.2', fill: 'currentColor' } },
1802
+ ],
1803
+ moonglitch: [
1804
+ { tag: 'path', attrs: { d: 'M4 10V4H10M22 4H28V10M28 22V28H22M10 28H4V22', fill: 'none', stroke: 'currentColor', strokeWidth: '2' } },
1805
+ { tag: 'path', attrs: { d: 'M7 16H13L15 11L18 21L20 16H25', fill: 'none', stroke: 'currentColor', strokeWidth: '2' } },
1806
+ ],
1807
+ moonsmash: [
1808
+ { tag: 'polygon', attrs: { points: '16,2 20,11 30,9 23,17 29,26 19,23 15,30 12,21 3,24 9,15 3,7 13,10', fill: 'currentColor' } },
1809
+ ],
1810
+ moonink: [
1811
+ { tag: 'path', attrs: { d: 'M24 9C20 5 11 6 8 13C5 20 11 27 19 26C24 25 27 21 26 17', fill: 'none', stroke: 'currentColor', strokeWidth: '3.2', strokeLinecap: 'round' } },
1812
+ { tag: 'circle', attrs: { cx: '18', cy: '15', r: '2.5', fill: 'currentColor' } },
1813
+ ],
1814
+ mooncrash: [
1815
+ { tag: 'polygon', attrs: { points: '9,3 23,3 29,9 29,23 23,29 9,29 3,23 3,9', fill: 'none', stroke: 'currentColor', strokeWidth: '2.4' } },
1816
+ { tag: 'path', attrs: { d: 'M9 21L16 10L23 21H9Z', fill: 'currentColor' } },
1817
+ ],
1818
+ moonpanel: [
1819
+ { tag: 'rect', attrs: { x: '3', y: '3', width: '11', height: '11', fill: 'currentColor' } },
1820
+ { tag: 'rect', attrs: { x: '17', y: '3', width: '12', height: '11', fill: 'none', stroke: 'currentColor', strokeWidth: '2.2' } },
1821
+ { tag: 'rect', attrs: { x: '3', y: '17', width: '26', height: '12', fill: 'none', stroke: 'currentColor', strokeWidth: '2.2' } },
1822
+ ],
1823
+ moonscrawl: [
1824
+ { tag: 'path', attrs: { d: 'M6 24C4 14 11 5 21 7C28 9 28 21 20 24C13 26 9 19 13 13C16 9 22 11 20 16', fill: 'none', stroke: 'currentColor', strokeWidth: '2.2', strokeLinecap: 'round' } },
1825
+ ],
1826
+ moonraw: [
1827
+ { tag: 'rect', attrs: { x: '3', y: '3', width: '26', height: '26', fill: 'none', stroke: 'currentColor', strokeWidth: '2.5' } },
1828
+ { tag: 'path', attrs: { d: 'M3 16H29M16 3V29', stroke: 'currentColor', strokeWidth: '2.5' } },
1829
+ ],
1830
+ moonchrome: [
1831
+ { tag: 'polygon', attrs: { points: '16,3 29,16 16,29 3,16', fill: 'none', stroke: 'currentColor', strokeWidth: '2' } },
1832
+ { tag: 'polygon', attrs: { points: '16,8 24,16 16,24 8,16', fill: 'currentColor' } },
1833
+ ],
1834
+ classic: [
1835
+ { tag: 'rect', attrs: { x: '4', y: '4', width: '24', height: '24', rx: '6', fill: 'none', stroke: 'currentColor', strokeWidth: '2.2' } },
1836
+ { tag: 'circle', attrs: { cx: '16', cy: '16', r: '5', fill: 'currentColor' } },
1837
+ ],
1838
+ moonquest: [
1839
+ { tag: 'path', attrs: { d: 'M16 3L27 7V16C27 23 22 27 16 29C10 27 5 23 5 16V7L16 3Z', fill: 'none', stroke: 'currentColor', strokeWidth: '2.2' } },
1840
+ { tag: 'polygon', attrs: { points: '16,8 18,14 24,16 18,18 16,24 14,18 8,16 14,14', fill: 'currentColor' } },
1841
+ ],
1842
+ moonledger: [
1843
+ { tag: 'rect', attrs: { x: '4', y: '4', width: '24', height: '24', rx: '2', fill: 'none', stroke: 'currentColor', strokeWidth: '2' } },
1844
+ { tag: 'path', attrs: { d: 'M4 11H28M12 11V28M20 11V28M4 19H28', stroke: 'currentColor', strokeWidth: '1.8' } },
1845
+ ],
1846
+ };
1847
+
1848
+ export const SkinBrandMark = forwardRef(function SkinBrandMark({
1849
+ skin: skinProp,
1850
+ size = 28,
1851
+ decorative = true,
1852
+ label,
1853
+ className,
1854
+ ...props
1855
+ }, ref) {
1856
+ let themeSkin = 'classic';
1857
+ try {
1858
+ const theme = useTheme();
1859
+ if (theme?.skin) themeSkin = theme.skin;
1860
+ } catch {
1861
+ themeSkin = 'classic';
1862
+ }
1863
+ const activeSkin = skinProp && SKIN_VECTOR_PATHS[skinProp] ? skinProp : themeSkin;
1864
+ const shapes = SKIN_VECTOR_PATHS[activeSkin] || SKIN_VECTOR_PATHS.classic;
1865
+ const ariaLabel = label || `${activeSkin} brand mark`;
1866
+
1867
+ return h('svg', {
1868
+ ...props,
1869
+ ref,
1870
+ width: size,
1871
+ height: size,
1872
+ viewBox: '0 0 32 32',
1873
+ role: decorative ? undefined : 'img',
1874
+ 'aria-hidden': decorative ? 'true' : undefined,
1875
+ 'aria-label': decorative ? undefined : ariaLabel,
1876
+ 'data-skin-mark': activeSkin,
1877
+ className: cx('mf-brand-mark', className),
1878
+ }, shapes.map((shape, idx) => h(shape.tag, { key: idx, ...shape.attrs })));
1879
+ });
1880
+
1881
+ export const SkinArtwork = forwardRef(function SkinArtwork({
1882
+ skin: skinProp,
1883
+ title,
1884
+ caption,
1885
+ className,
1886
+ ...props
1887
+ }, ref) {
1888
+ let themeSkin = 'classic';
1889
+ try {
1890
+ const theme = useTheme();
1891
+ if (theme?.skin) themeSkin = theme.skin;
1892
+ } catch {
1893
+ themeSkin = 'classic';
1894
+ }
1895
+ const activeSkin = skinProp && SKIN_VECTOR_PATHS[skinProp] ? skinProp : themeSkin;
1896
+
1897
+ return h('figure', {
1898
+ ...props,
1899
+ ref,
1900
+ 'data-skin-artwork': activeSkin,
1901
+ className: cx('mf-skin-artwork', className),
1902
+ },
1903
+ h('div', { className: 'mf-skin-artwork-canvas', 'aria-hidden': 'true' },
1904
+ h(SkinBrandMark, { skin: activeSkin, size: 56, decorative: true }),
1905
+ h('div', { className: 'mf-skin-artwork-grid' })
1906
+ ),
1907
+ (title || caption) && h('figcaption', { className: 'mf-skin-artwork-caption' },
1908
+ title && h('strong', null, title),
1909
+ caption && h('span', null, caption)
1910
+ )
1911
+ );
1912
+ });
1913
+
1914
+ /* M10 Opt-In, Muted-by-Default WebAudio Synthesizer SFX Runtime (MF-SFX-001) */
1915
+
1916
+ const SFX_EVENT_PROFILES = {
1917
+ success: { freq: [523.25, 659.25], durationMs: 110, type: 'sine' },
1918
+ warning: { freq: [392.0, 349.23], durationMs: 130, type: 'triangle' },
1919
+ error: { freq: [293.66, 246.94], durationMs: 140, type: 'triangle' },
1920
+ notification: { freq: [587.33, 880.0], durationMs: 95, type: 'sine' },
1921
+ confirmation: { freq: [440.0, 554.37], durationMs: 90, type: 'sine' },
1922
+ 'quest-reward': { freq: [523.25, 659.25, 783.99], durationMs: 160, type: 'triangle' },
1923
+ };
1924
+
1925
+ const SFX_ALIASES = {
1926
+ 'confirm.success': 'success',
1927
+ 'confirm.warning': 'warning',
1928
+ 'confirm.error': 'error',
1929
+ 'notification.incoming': 'notification',
1930
+ 'operation.progress-complete': 'success',
1931
+ 'game.reward': 'quest-reward',
1932
+ };
1933
+
1934
+ const SFXContext = createContext({
1935
+ enabled: false,
1936
+ muted: true,
1937
+ volume: 0.35,
1938
+ consentGranted: false,
1939
+ lastEvent: null,
1940
+ grantConsent: () => {},
1941
+ revokeConsent: () => {},
1942
+ setMuted: () => {},
1943
+ setVolume: () => {},
1944
+ play: () => ({ played: false, reason: 'provider-missing' }),
1945
+ });
1946
+
1947
+ export function SFXProvider({
1948
+ defaultEnabled = false,
1949
+ defaultMuted = true,
1950
+ defaultVolume = 0.35,
1951
+ children,
1952
+ }) {
1953
+ const [consentGranted, setConsentGranted] = useState(Boolean(defaultEnabled));
1954
+ const [muted, setMutedState] = useState(defaultEnabled ? Boolean(defaultMuted) : true);
1955
+ const [volume, setVolumeState] = useState(() => Math.max(0, Math.min(1, Number(defaultVolume) || 0.35)));
1956
+ const [lastEvent, setLastEvent] = useState(null);
1957
+ const timingRef = useRef({ lastPlayedAt: 0, byEvent: {} });
1958
+
1959
+ function setVolume(next) {
1960
+ const clamped = Math.max(0, Math.min(1, Number(next)));
1961
+ if (Number.isFinite(clamped)) setVolumeState(clamped);
1962
+ }
1963
+
1964
+ function grantConsent() {
1965
+ setConsentGranted(true);
1966
+ setMutedState(false);
1967
+ }
1968
+
1969
+ function revokeConsent() {
1970
+ setConsentGranted(false);
1971
+ setMutedState(true);
1972
+ }
1973
+
1974
+ function play(rawEventId) {
1975
+ const canonicalId = SFX_ALIASES[rawEventId] || rawEventId;
1976
+ const profile = SFX_EVENT_PROFILES[canonicalId];
1977
+ if (!profile) return { played: false, reason: 'unknown-event' };
1978
+ if (!consentGranted || muted || volume <= 0) return { played: false, reason: 'muted-or-no-consent' };
1979
+ if (typeof window === 'undefined' || typeof document === 'undefined') return { played: false, reason: 'ssr' };
1980
+ if (document.visibilityState === 'hidden') return { played: false, reason: 'background-tab' };
1981
+
1982
+ const rootMotion = document.documentElement?.getAttribute('data-motion');
1983
+ const prefersReduced = typeof window.matchMedia === 'function' &&
1984
+ window.matchMedia('(prefers-reduced-motion: reduce)').matches;
1985
+ if (rootMotion === 'reduced' || prefersReduced) {
1986
+ return { played: false, reason: 'reduced-motion' };
1987
+ }
1988
+
1989
+ const now = Date.now();
1990
+ const lastGlobal = timingRef.current.lastPlayedAt || 0;
1991
+ const lastSame = timingRef.current.byEvent[canonicalId] || 0;
1992
+ if (now - lastGlobal < 1000) return { played: false, reason: 'rate-limited' };
1993
+ if (now - lastSame < 2000) return { played: false, reason: 'deduplicated' };
1994
+
1995
+ timingRef.current.lastPlayedAt = now;
1996
+ timingRef.current.byEvent[canonicalId] = now;
1997
+ setLastEvent({ id: canonicalId, timestamp: now });
1998
+
1999
+ try {
2000
+ const AudioCtx = window.AudioContext || window.webkitAudioContext;
2001
+ if (AudioCtx) {
2002
+ const ctx = new AudioCtx();
2003
+ const gain = ctx.createGain();
2004
+ gain.gain.setValueAtTime(Math.max(0.01, volume * 0.25), ctx.currentTime);
2005
+ gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + profile.durationMs / 1000);
2006
+ gain.connect(ctx.destination);
2007
+
2008
+ profile.freq.forEach((f, idx) => {
2009
+ const osc = ctx.createOscillator();
2010
+ osc.type = profile.type;
2011
+ osc.frequency.setValueAtTime(f, ctx.currentTime + idx * 0.045);
2012
+ osc.connect(gain);
2013
+ osc.start(ctx.currentTime + idx * 0.045);
2014
+ osc.stop(ctx.currentTime + (profile.durationMs / 1000) + idx * 0.045);
2015
+ });
2016
+ }
2017
+ } catch {
2018
+ // Graceful silent fallback per MF-SFX-001
2019
+ }
2020
+
2021
+ return { played: true, eventId: canonicalId };
2022
+ }
2023
+
2024
+ const value = useMemo(() => ({
2025
+ enabled: consentGranted && !muted,
2026
+ muted,
2027
+ volume,
2028
+ consentGranted,
2029
+ lastEvent,
2030
+ grantConsent,
2031
+ revokeConsent,
2032
+ setMuted: setMutedState,
2033
+ setVolume,
2034
+ play,
2035
+ }), [consentGranted, muted, volume, lastEvent]);
2036
+
2037
+ return h(SFXContext.Provider, { value }, children);
2038
+ }
2039
+
2040
+ export function useSFX() {
2041
+ return useContext(SFXContext);
2042
+ }
2043
+
2044
+