@hulla/style 0.0.2 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +34 -17
- package/dist/cjs/index.js +1 -1
- package/dist/es/index.d.mts +34 -17
- package/dist/es/index.mjs +1 -1
- package/package.json +4 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,38 +1,55 @@
|
|
|
1
1
|
import { HTMLAttributes } from 'astro/types';
|
|
2
2
|
|
|
3
|
-
type Variants = Record<string, string
|
|
3
|
+
type Variants = Record<string, Record<string, string>>;
|
|
4
4
|
type Compose = <const CS extends any[] = ClassName[]>(...classes: CS) => string;
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
type ClassName = string | null | undefined | false | 0 | 0n | typeof NaN | Record<string, any>;
|
|
6
|
+
type Config<V extends Variants, DV extends {
|
|
7
|
+
[K in keyof V]?: keyof V[K];
|
|
8
|
+
}, B extends string, C extends Compose> = {
|
|
9
|
+
props: V;
|
|
10
|
+
defaults?: DV;
|
|
10
11
|
base?: B;
|
|
11
12
|
compose?: C;
|
|
12
13
|
transform?: Transform;
|
|
13
14
|
};
|
|
14
|
-
type
|
|
15
|
-
variant?: keyof V;
|
|
15
|
+
type BaseProps = {
|
|
16
16
|
class?: string | null;
|
|
17
17
|
className?: string | null;
|
|
18
18
|
"class:list"?: HTMLAttributes<"div">["class:list"];
|
|
19
19
|
};
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} : Incorrect : Incorrect;
|
|
24
|
-
type Variant<S> = S extends Fn ? (Parameters<S>[0] extends Props<infer V> ? keyof V : Incorrect) : Incorrect;
|
|
20
|
+
type Props<V extends Variants, _DV extends Defaults<V>, Extra extends Record<string, unknown>> = BaseProps & {
|
|
21
|
+
[K in keyof V]?: keyof V[K];
|
|
22
|
+
} & Extra;
|
|
25
23
|
type Transform = (css: string) => string;
|
|
26
24
|
type Setup<C extends Compose> = {
|
|
27
25
|
compose?: C;
|
|
28
26
|
transform?: (css: string) => string;
|
|
29
27
|
};
|
|
28
|
+
type Defaults<V extends Variants> = {
|
|
29
|
+
[K in keyof V]?: keyof V[K];
|
|
30
|
+
};
|
|
31
|
+
type VariantFunction<ExtraProps extends Record<string, unknown> = {}> = <const V extends Variants, const DV extends Defaults<V>, const B extends string, const C extends Compose>(config: Config<V, DV, B, C>, modifier?: (data: {
|
|
32
|
+
config: Config<V, DV, B, Compose>;
|
|
33
|
+
props: Props<V, DV, ExtraProps>;
|
|
34
|
+
}) => Partial<Config<V, DV, B, Compose>>) => (props: Props<V, DV, ExtraProps>) => string;
|
|
30
35
|
type StyleFunctions = {
|
|
31
36
|
cn: Compose;
|
|
32
|
-
vn: <
|
|
37
|
+
vn: VariantFunction<{}>;
|
|
38
|
+
};
|
|
39
|
+
type NotNeverKeys<T extends Record<string, unknown>> = {
|
|
40
|
+
[K in keyof T]: T[K] extends never ? never : K;
|
|
41
|
+
}[keyof T];
|
|
42
|
+
type HideNever<T extends Record<string, unknown>> = {
|
|
43
|
+
[K in NotNeverKeys<T>]: T[K];
|
|
33
44
|
};
|
|
45
|
+
type VariantProps<S extends (props: Props<Variants, Defaults<Variants>, Record<string, unknown>>) => string> = Parameters<S>[0] extends Props<infer V, infer DV, Record<string, unknown>> ? Omit<{
|
|
46
|
+
[K in keyof V]: K extends keyof DV ? never : keyof V[K];
|
|
47
|
+
}, {
|
|
48
|
+
[K in keyof DV]: K extends keyof V ? K : never;
|
|
49
|
+
}[keyof DV]> & {
|
|
50
|
+
[K in keyof DV]?: K extends keyof V ? keyof V[K] : never;
|
|
51
|
+
} : never;
|
|
34
52
|
|
|
35
|
-
declare function style(): StyleFunctions;
|
|
36
|
-
declare function style<C extends Compose>(setup: Setup<C>): StyleFunctions;
|
|
53
|
+
declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions;
|
|
37
54
|
|
|
38
|
-
export { type ClassName, type Compose, type Config, type Props, type Setup, type StyleFunctions, type Transform, type
|
|
55
|
+
export { type BaseProps, type ClassName, type Compose, type Config, type Defaults, type HideNever, type NotNeverKeys, type Props, type Setup, type StyleFunctions, type Transform, type VariantFunction, type VariantProps, type Variants, style };
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function e(...t){let r=[];for(let e of t.filter(Boolean))if("string"==typeof e)for(let t of e.split(" ")){let e=t.trim();e&&r.push(e)}else if("object"==typeof e&&null!==e)for(let[t,o]of Object.entries(e))o&&r.push(t);return Array.from(new Set(r).values()).join(" ")}exports.style=function(t){let{compose:r=e,transform:o}=t??{},n=r===e?r:(...e)=>r(...function(e){let t=[];for(let r of e)if(r){if("string"==typeof r)t.push(r);else if("object"==typeof r&&null!==r)for(let[e,o]of Object.entries(r))o&&t.push(e)}return t}(e));return{vn:(e,t)=>r=>{let f=t?{...e,...t({config:e,props:r})??{}}:e,s="";for(let e in f.props){let t=void 0!==r[e]?f.props[e][r[e]]:f.defaults?.[e]?f.props[e][f.defaults[e]]:void 0;t&&(s+=""===s?t:` ${t}`)}let i=[r.class,r.className,...function(e){switch(typeof e){case"string":return[e];case"object":if(e instanceof Array)return e;if(e instanceof Set||e instanceof Map)return Array.from(e);return Object.entries(e).map(([e,t])=>t?e:void 0);default:return}}(r["class:list"])??[]],l=(f.compose??n)(f.base,s,...i),u=o??f.transform;return u?u(l):l},cn:o?(...e)=>o(n(...e)):n}};
|
package/dist/es/index.d.mts
CHANGED
|
@@ -1,38 +1,55 @@
|
|
|
1
1
|
import { HTMLAttributes } from 'astro/types';
|
|
2
2
|
|
|
3
|
-
type Variants = Record<string, string
|
|
3
|
+
type Variants = Record<string, Record<string, string>>;
|
|
4
4
|
type Compose = <const CS extends any[] = ClassName[]>(...classes: CS) => string;
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
type ClassName = string | null | undefined | false | 0 | 0n | typeof NaN | Record<string, any>;
|
|
6
|
+
type Config<V extends Variants, DV extends {
|
|
7
|
+
[K in keyof V]?: keyof V[K];
|
|
8
|
+
}, B extends string, C extends Compose> = {
|
|
9
|
+
props: V;
|
|
10
|
+
defaults?: DV;
|
|
10
11
|
base?: B;
|
|
11
12
|
compose?: C;
|
|
12
13
|
transform?: Transform;
|
|
13
14
|
};
|
|
14
|
-
type
|
|
15
|
-
variant?: keyof V;
|
|
15
|
+
type BaseProps = {
|
|
16
16
|
class?: string | null;
|
|
17
17
|
className?: string | null;
|
|
18
18
|
"class:list"?: HTMLAttributes<"div">["class:list"];
|
|
19
19
|
};
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} : Incorrect : Incorrect;
|
|
24
|
-
type Variant<S> = S extends Fn ? (Parameters<S>[0] extends Props<infer V> ? keyof V : Incorrect) : Incorrect;
|
|
20
|
+
type Props<V extends Variants, _DV extends Defaults<V>, Extra extends Record<string, unknown>> = BaseProps & {
|
|
21
|
+
[K in keyof V]?: keyof V[K];
|
|
22
|
+
} & Extra;
|
|
25
23
|
type Transform = (css: string) => string;
|
|
26
24
|
type Setup<C extends Compose> = {
|
|
27
25
|
compose?: C;
|
|
28
26
|
transform?: (css: string) => string;
|
|
29
27
|
};
|
|
28
|
+
type Defaults<V extends Variants> = {
|
|
29
|
+
[K in keyof V]?: keyof V[K];
|
|
30
|
+
};
|
|
31
|
+
type VariantFunction<ExtraProps extends Record<string, unknown> = {}> = <const V extends Variants, const DV extends Defaults<V>, const B extends string, const C extends Compose>(config: Config<V, DV, B, C>, modifier?: (data: {
|
|
32
|
+
config: Config<V, DV, B, Compose>;
|
|
33
|
+
props: Props<V, DV, ExtraProps>;
|
|
34
|
+
}) => Partial<Config<V, DV, B, Compose>>) => (props: Props<V, DV, ExtraProps>) => string;
|
|
30
35
|
type StyleFunctions = {
|
|
31
36
|
cn: Compose;
|
|
32
|
-
vn: <
|
|
37
|
+
vn: VariantFunction<{}>;
|
|
38
|
+
};
|
|
39
|
+
type NotNeverKeys<T extends Record<string, unknown>> = {
|
|
40
|
+
[K in keyof T]: T[K] extends never ? never : K;
|
|
41
|
+
}[keyof T];
|
|
42
|
+
type HideNever<T extends Record<string, unknown>> = {
|
|
43
|
+
[K in NotNeverKeys<T>]: T[K];
|
|
33
44
|
};
|
|
45
|
+
type VariantProps<S extends (props: Props<Variants, Defaults<Variants>, Record<string, unknown>>) => string> = Parameters<S>[0] extends Props<infer V, infer DV, Record<string, unknown>> ? Omit<{
|
|
46
|
+
[K in keyof V]: K extends keyof DV ? never : keyof V[K];
|
|
47
|
+
}, {
|
|
48
|
+
[K in keyof DV]: K extends keyof V ? K : never;
|
|
49
|
+
}[keyof DV]> & {
|
|
50
|
+
[K in keyof DV]?: K extends keyof V ? keyof V[K] : never;
|
|
51
|
+
} : never;
|
|
34
52
|
|
|
35
|
-
declare function style(): StyleFunctions;
|
|
36
|
-
declare function style<C extends Compose>(setup: Setup<C>): StyleFunctions;
|
|
53
|
+
declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions;
|
|
37
54
|
|
|
38
|
-
export { type ClassName, type Compose, type Config, type Props, type Setup, type StyleFunctions, type Transform, type
|
|
55
|
+
export { type BaseProps, type ClassName, type Compose, type Config, type Defaults, type HideNever, type NotNeverKeys, type Props, type Setup, type StyleFunctions, type Transform, type VariantFunction, type VariantProps, type Variants, style };
|
package/dist/es/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function e(...t){let r=[];for(let e of t.filter(Boolean))if("string"==typeof e)for(let t of e.split(" ")){let e=t.trim();e&&r.push(e)}else if("object"==typeof e&&null!==e)for(let[t,o]of Object.entries(e))o&&r.push(t);return Array.from(new Set(r).values()).join(" ")}function t(t){let{compose:r=e,transform:o}=t??{},n=r===e?r:(...e)=>r(...function(e){let t=[];for(let r of e)if(r){if("string"==typeof r)t.push(r);else if("object"==typeof r&&null!==r)for(let[e,o]of Object.entries(r))o&&t.push(e)}return t}(e));return{vn:(e,t)=>r=>{let f=t?{...e,...t({config:e,props:r})??{}}:e,s="";for(let e in f.props){let t=void 0!==r[e]?f.props[e][r[e]]:f.defaults?.[e]?f.props[e][f.defaults[e]]:void 0;t&&(s+=""===s?t:` ${t}`)}let i=[r.class,r.className,...function(e){switch(typeof e){case"string":return[e];case"object":if(e instanceof Array)return e;if(e instanceof Set||e instanceof Map)return Array.from(e);return Object.entries(e).map(([e,t])=>t?e:void 0);default:return}}(r["class:list"])??[]],l=(f.compose??n)(f.base,s,...i),u=o??f.transform;return u?u(l):l},cn:o?(...e)=>o(n(...e)):n}}export{t as style};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hulla/style",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Styling made easy 🎨",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Samuel Hulla",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
+
"main": "./dist/cjs/index.js",
|
|
23
|
+
"module": "./dist/es/index.mjs",
|
|
24
|
+
"types": "./dist/cjs/index.d.ts",
|
|
22
25
|
"exports": {
|
|
23
26
|
"import": {
|
|
24
27
|
"types": "./dist/es/index.d.mts",
|