@vertz/ui 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,157 @@
1
+ /** A style entry in the array: either a shorthand string or an object for nested selectors. */
2
+ type StyleEntry = string | Record<string, string[]>;
3
+ /** Input to css(): a record of named style blocks. */
4
+ type CSSInput = Record<string, StyleEntry[]>;
5
+ /** Output of css(): a record of block names to class names, plus extracted CSS. */
6
+ interface CSSOutput {
7
+ /** Map of block name → generated class name. */
8
+ classNames: Record<string, string>;
9
+ /** The extracted CSS string. */
10
+ css: string;
11
+ }
12
+ /**
13
+ * Process a css() call and produce class names + extracted CSS.
14
+ *
15
+ * In production, the compiler replaces css() calls at build time.
16
+ * This runtime implementation is used for:
17
+ * - Development mode
18
+ * - Testing
19
+ * - SSR fallback
20
+ *
21
+ * @param input - Named style blocks.
22
+ * @param filePath - Source file path for deterministic hashing.
23
+ * @returns Class names map and extracted CSS.
24
+ */
25
+ declare function css(input: CSSInput, filePath?: string): CSSOutput;
26
+ /** Input to globalCss(): selector → property-value map. */
27
+ type GlobalCSSInput = Record<string, Record<string, string>>;
28
+ /** Output of globalCss(): extracted CSS string. */
29
+ interface GlobalCSSOutput {
30
+ /** The extracted global CSS string. */
31
+ css: string;
32
+ }
33
+ /**
34
+ * Process a globalCss() call and produce global CSS rules.
35
+ *
36
+ * Properties use camelCase and are converted to kebab-case.
37
+ * CSS custom properties (--*) are passed through as-is.
38
+ *
39
+ * @param input - Selector-to-properties map.
40
+ * @returns Extracted CSS.
41
+ */
42
+ declare function globalCss(input: GlobalCSSInput): GlobalCSSOutput;
43
+ /**
44
+ * Convert an array of shorthand strings into a CSS properties object
45
+ * suitable for inline styles.
46
+ *
47
+ * Note: Pseudo-states are not supported in inline styles and will
48
+ * cause an error. Use css() for pseudo-states.
49
+ *
50
+ * @param entries - Array of shorthand strings.
51
+ * @returns A Record of CSS property → value pairs (kebab-case keys).
52
+ */
53
+ declare function s(entries: string[]): Record<string, string>;
54
+ /** Color tokens: a map of color names to their raw/contextual values. */
55
+ type ColorTokens = Record<string, Record<string, string>>;
56
+ /** Spacing tokens: a flat map of names to CSS values. */
57
+ type SpacingTokens = Record<string, string>;
58
+ /** Input to defineTheme(). */
59
+ interface ThemeInput {
60
+ /** Color design tokens (raw shades and contextual variants). */
61
+ colors: ColorTokens;
62
+ /** Spacing scale tokens. */
63
+ spacing?: SpacingTokens;
64
+ }
65
+ /** The structured theme object returned by defineTheme(). */
66
+ interface Theme {
67
+ /** Color design tokens. */
68
+ colors: ColorTokens;
69
+ /** Spacing scale tokens. */
70
+ spacing?: SpacingTokens;
71
+ }
72
+ /** Output of compileTheme(). */
73
+ interface CompiledTheme {
74
+ /** The generated CSS string with :root and [data-theme] blocks. */
75
+ css: string;
76
+ /** Flat list of token dot-paths (e.g., 'primary.500', 'background'). */
77
+ tokens: string[];
78
+ }
79
+ /**
80
+ * Define a theme with raw and contextual design tokens.
81
+ *
82
+ * @param input - Theme token definitions.
83
+ * @returns A structured theme object.
84
+ */
85
+ declare function defineTheme(input: ThemeInput): Theme;
86
+ /**
87
+ * Compile a theme into CSS custom properties.
88
+ *
89
+ * Generates:
90
+ * - `:root { ... }` block with default/raw token values
91
+ * - `[data-theme="dark"] { ... }` block with dark overrides (if any)
92
+ *
93
+ * @param theme - A theme object from defineTheme().
94
+ * @returns Compiled CSS and token list.
95
+ */
96
+ declare function compileTheme(theme: Theme): CompiledTheme;
97
+ /**
98
+ * ThemeProvider — Sets `data-theme` attribute for contextual token switching.
99
+ *
100
+ * Creates a wrapper div element with the appropriate `data-theme` attribute
101
+ * so that contextual CSS custom properties (generated by compileTheme) resolve
102
+ * to the correct variant values.
103
+ *
104
+ * Usage:
105
+ * ```ts
106
+ * ThemeProvider({ theme: 'dark', children: [myApp] });
107
+ * ```
108
+ */
109
+ /** A child node: either a DOM Node or a string (text content). */
110
+ type ThemeChild = Node | string;
111
+ /** Props for ThemeProvider. */
112
+ interface ThemeProviderProps {
113
+ /** The theme variant name (e.g., 'light', 'dark'). Defaults to 'light'. */
114
+ theme?: string;
115
+ /** Child elements to render inside the provider. */
116
+ children: ThemeChild[];
117
+ }
118
+ /**
119
+ * Create a wrapper div with `data-theme` attribute for theme switching.
120
+ *
121
+ * @param props - Theme and children.
122
+ * @returns A div element with `data-theme` set and children appended.
123
+ */
124
+ declare function ThemeProvider(props: ThemeProviderProps): HTMLDivElement;
125
+ /** A record of variant names to their possible values (each value maps to style entries). */
126
+ type VariantDefinitions = Record<string, Record<string, StyleEntry[]>>;
127
+ /** Extract the variant props type from a variant definitions object. */
128
+ type VariantProps<V extends VariantDefinitions> = { [K in keyof V]? : keyof V[K] };
129
+ /** A compound variant rule: matches when all specified variant values are active. */
130
+ type CompoundVariant<V extends VariantDefinitions> = { [K in keyof V]? : keyof V[K] } & {
131
+ styles: StyleEntry[];
132
+ };
133
+ /** Configuration for the variants() function. */
134
+ interface VariantsConfig<V extends VariantDefinitions> {
135
+ /** Base styles applied to all variants. */
136
+ base: StyleEntry[];
137
+ /** Variant definitions: each key is a variant name, each value is a map of option to styles. */
138
+ variants: V;
139
+ /** Default variant values used when no override is provided. */
140
+ defaultVariants?: { [K in keyof V]? : keyof V[K] };
141
+ /** Compound variants: styles applied when multiple variant values match simultaneously. */
142
+ compoundVariants?: CompoundVariant<V>[];
143
+ }
144
+ /** The function returned by variants(). Takes optional variant props and returns a className string. */
145
+ interface VariantFunction<V extends VariantDefinitions> {
146
+ (props?: VariantProps<V>): string;
147
+ /** The extracted CSS for all variant combinations. */
148
+ css: string;
149
+ }
150
+ /**
151
+ * Create a typed variant function from a config object.
152
+ *
153
+ * @param config - Variant configuration (base, variants, defaultVariants, compoundVariants).
154
+ * @returns A function that accepts variant props and returns a className string.
155
+ */
156
+ declare function variants<V extends VariantDefinitions>(config: VariantsConfig<V>): VariantFunction<V>;
157
+ export { variants, s, globalCss, defineTheme, css, compileTheme, VariantsConfig, VariantProps, VariantFunction, ThemeProviderProps, ThemeProvider, ThemeInput, Theme, StyleEntry, GlobalCSSOutput, GlobalCSSInput, CompiledTheme, CSSOutput, CSSInput };
@@ -0,0 +1,18 @@
1
+ import {
2
+ ThemeProvider,
3
+ compileTheme,
4
+ css,
5
+ defineTheme,
6
+ globalCss,
7
+ s,
8
+ variants
9
+ } from "../shared/chunk-f1ynwam4.js";
10
+ export {
11
+ variants,
12
+ s,
13
+ globalCss,
14
+ defineTheme,
15
+ css,
16
+ compileTheme,
17
+ ThemeProvider
18
+ };
@@ -0,0 +1,111 @@
1
+ /**
2
+ * A reactive signal that holds a value and notifies subscribers on change.
3
+ */
4
+ interface Signal<T> {
5
+ /** Get the current value and subscribe to changes (when inside a tracking context). */
6
+ get value(): T;
7
+ /** Set the current value and notify subscribers if changed. */
8
+ set value(newValue: T);
9
+ /** Read the current value without subscribing (no tracking). */
10
+ peek(): T;
11
+ /** Manually notify all subscribers (useful after mutating the value in place). */
12
+ notify(): void;
13
+ }
14
+ /**
15
+ * Minimal schema interface compatible with @vertz/schema.
16
+ * Any object with a `parse(data: unknown): T` method satisfies this.
17
+ */
18
+ interface FormSchema<T> {
19
+ parse(data: unknown): T;
20
+ }
21
+ /** Result of a validation attempt. */
22
+ type ValidationResult<T> = {
23
+ success: true;
24
+ data: T;
25
+ errors: Record<string, never>;
26
+ } | {
27
+ success: false;
28
+ data: undefined;
29
+ errors: Record<string, string>;
30
+ };
31
+ /**
32
+ * Validate data against a schema.
33
+ *
34
+ * - On success, returns `{ success: true, data, errors: {} }`.
35
+ * - On failure, extracts field errors from `error.fieldErrors` if present,
36
+ * otherwise falls back to a generic `_form` error.
37
+ */
38
+ declare function validate<T>(schema: FormSchema<T>, data: unknown): ValidationResult<T>;
39
+ /**
40
+ * An SDK method with endpoint metadata attached.
41
+ * Generated SDK methods expose `.url` and `.method` for progressive enhancement.
42
+ */
43
+ interface SdkMethod<
44
+ TBody,
45
+ TResult
46
+ > {
47
+ (body: TBody): Promise<TResult>;
48
+ url: string;
49
+ method: string;
50
+ }
51
+ /** Options for creating a form instance. */
52
+ interface FormOptions<TBody> {
53
+ /** Explicit schema for client-side validation before submission. */
54
+ schema: FormSchema<TBody>;
55
+ }
56
+ /** Callbacks for form submission. Both are optional per spec. */
57
+ interface SubmitCallbacks<TResult> {
58
+ onSuccess?: (result: TResult) => void;
59
+ onError?: (errors: Record<string, string>) => void;
60
+ }
61
+ /** A form instance bound to an SDK method. */
62
+ interface FormInstance<
63
+ TBody,
64
+ TResult
65
+ > {
66
+ /** Returns `{ action, method }` for progressive enhancement in HTML forms. */
67
+ attrs(): {
68
+ action: string;
69
+ method: string;
70
+ };
71
+ /** Reactive signal indicating whether a submission is in progress. */
72
+ submitting: Signal<boolean>;
73
+ /**
74
+ * Returns an event handler that extracts FormData, validates, and submits.
75
+ * Assignable to onSubmit: `onSubmit={userForm.handleSubmit({ onSuccess })}`.
76
+ *
77
+ * Can also be called directly with FormData for non-DOM usage:
78
+ * `userForm.handleSubmit({ onSuccess })(formData)`.
79
+ */
80
+ handleSubmit(callbacks?: SubmitCallbacks<TResult>): (formDataOrEvent: FormData | Event) => Promise<void>;
81
+ /** Returns the error message for a field reactively, or undefined if no error. Type-safe field names. */
82
+ error(field: keyof TBody & string): string | undefined;
83
+ }
84
+ /**
85
+ * Create a form instance bound to an SDK method with schema validation.
86
+ *
87
+ * The form provides:
88
+ * - `attrs()` for progressive enhancement (returns action/method from SDK metadata)
89
+ * - `handleSubmit()` returns an event handler for FormData extraction, validation, and SDK submission
90
+ * - `error()` for reactive field-level error access
91
+ * - `submitting` signal for loading state
92
+ */
93
+ declare function form<
94
+ TBody,
95
+ TResult
96
+ >(sdkMethod: SdkMethod<TBody, TResult>, options: FormOptions<TBody>): FormInstance<TBody, TResult>;
97
+ /** Options for formDataToObject conversion. */
98
+ interface FormDataOptions {
99
+ /** When true, coerces numeric strings to numbers and "true"/"false" to booleans. */
100
+ coerce?: boolean;
101
+ }
102
+ /**
103
+ * Convert FormData to a plain object.
104
+ *
105
+ * - File entries are skipped (only string values are included).
106
+ * - Duplicate keys use the last value.
107
+ * - When `coerce` is true, numeric strings become numbers and
108
+ * "true"/"false" become booleans.
109
+ */
110
+ declare function formDataToObject(formData: FormData, options?: FormDataOptions): Record<string, unknown>;
111
+ export { validate, formDataToObject, form, ValidationResult, SubmitCallbacks, SdkMethod, FormSchema, FormOptions, FormInstance, FormDataOptions };
@@ -0,0 +1,11 @@
1
+ import {
2
+ form,
3
+ formDataToObject,
4
+ validate
5
+ } from "../shared/chunk-tsdpgmks.js";
6
+ import"../shared/chunk-pgymxpn1.js";
7
+ export {
8
+ validate,
9
+ formDataToObject,
10
+ form
11
+ };