@hulla/style 0.0.2 → 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.
@@ -1,38 +1,90 @@
1
- import { HTMLAttributes } from 'astro/types';
1
+ import { HTMLAttributes } from "astro/types"
2
2
 
3
- type Variants = Record<string, string>;
4
- type Compose = <const CS extends any[] = ClassName[]>(...classes: CS) => string;
5
- type Fn = (...args: any[]) => any;
6
- type ClassName = string | null | undefined | false | 0 | 0n | typeof NaN;
7
- type Config<V extends Variants, DV extends keyof V, B extends string, C extends Compose> = {
8
- variants?: V;
9
- defaultVariant?: DV;
10
- base?: B;
11
- compose?: C;
12
- transform?: Transform;
13
- };
14
- type Props<V extends Variants> = {
15
- variant?: keyof V;
16
- class?: string | null;
17
- className?: string | null;
18
- "class:list"?: HTMLAttributes<"div">["class:list"];
19
- };
20
- type Incorrect<S extends string = "[@hulla/style]: Invalid style configuration passed. Refer to https://hulla.dev/docs/style for help"> = S;
21
- type VariantProps<S> = S extends Fn ? Parameters<S>[0] extends Props<infer V> ? {
22
- variant?: keyof V;
23
- } : Incorrect : Incorrect;
24
- type Variant<S> = S extends Fn ? (Parameters<S>[0] extends Props<infer V> ? keyof V : Incorrect) : Incorrect;
25
- type Transform = (css: string) => string;
3
+ type Variants = Record<string, Record<string, string>>
4
+ type Compose = <const CS extends any[] = ClassName[]>(...classes: CS) => string
5
+ type ClassName = string | null | undefined | false | 0 | 0n | typeof NaN
6
+ type Config<
7
+ V extends Variants,
8
+ DV extends {
9
+ [K in keyof V]?: keyof V[K]
10
+ },
11
+ B extends string,
12
+ C extends Compose,
13
+ > = {
14
+ props: V
15
+ defaults?: DV
16
+ base?: B
17
+ compose?: C
18
+ transform?: Transform
19
+ }
20
+ type BaseProps = {
21
+ class?: string | null
22
+ className?: string | null
23
+ "class:list"?: HTMLAttributes<"div">["class:list"]
24
+ }
25
+ type Props<V extends Variants, _DV extends Defaults<V>, Extra extends Record<string, unknown>> = BaseProps & {
26
+ [K in keyof V]?: keyof V[K]
27
+ } & Extra
28
+ type Transform = (css: string) => string
26
29
  type Setup<C extends Compose> = {
27
- compose?: C;
28
- transform?: (css: string) => string;
29
- };
30
+ compose?: C
31
+ transform?: (css: string) => string
32
+ }
33
+ type Defaults<V extends Variants> = {
34
+ [K in keyof V]?: keyof V[K]
35
+ }
36
+ type VariantFunction<ExtraProps extends Record<string, unknown> = {}> = <
37
+ const V extends Variants,
38
+ const DV extends Defaults<V>,
39
+ const B extends string,
40
+ const C extends Compose,
41
+ >(
42
+ config: Config<V, DV, B, C>,
43
+ modifier?: (data: {
44
+ config: Config<V, DV, B, Compose>
45
+ props: Props<V, DV, ExtraProps>
46
+ }) => Partial<Config<V, DV, B, Compose>>
47
+ ) => (props: Props<V, DV, ExtraProps>) => string
30
48
  type StyleFunctions = {
31
- cn: Compose;
32
- vn: <V extends Variants, DV extends keyof V, B extends string>(config: Config<V, DV, B, Compose>) => (props: Props<V>) => string;
33
- };
49
+ cn: Compose
50
+ vn: VariantFunction<{}>
51
+ }
52
+ type NotNeverKeys<T extends Record<string, unknown>> = {
53
+ [K in keyof T]: T[K] extends never ? never : K
54
+ }[keyof T]
55
+ type HideNever<T extends Record<string, unknown>> = {
56
+ [K in NotNeverKeys<T>]: T[K]
57
+ }
58
+ type VariantProps<S extends (props: Props<Variants, Defaults<Variants>, Record<string, unknown>>) => string> =
59
+ Parameters<S>[0] extends Props<infer V, infer DV, Record<string, unknown>>
60
+ ? Omit<
61
+ {
62
+ [K in keyof V]: K extends keyof DV ? never : keyof V[K]
63
+ },
64
+ {
65
+ [K in keyof DV]: K extends keyof V ? K : never
66
+ }[keyof DV]
67
+ > & {
68
+ [K in keyof DV]?: K extends keyof V ? keyof V[K] : never
69
+ }
70
+ : never
34
71
 
35
- declare function style(): StyleFunctions;
36
- declare function style<C extends Compose>(setup: Setup<C>): StyleFunctions;
72
+ declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions
37
73
 
38
- export { type ClassName, type Compose, type Config, type Props, type Setup, type StyleFunctions, type Transform, type Variant, type VariantProps, type Variants, style };
74
+ export {
75
+ type BaseProps,
76
+ type ClassName,
77
+ type Compose,
78
+ type Config,
79
+ type Defaults,
80
+ type HideNever,
81
+ type NotNeverKeys,
82
+ type Props,
83
+ type Setup,
84
+ type StyleFunctions,
85
+ type Transform,
86
+ type VariantFunction,
87
+ type VariantProps,
88
+ type Variants,
89
+ style,
90
+ }
package/dist/cjs/index.js CHANGED
@@ -1 +1,38 @@
1
- function t(...a){let r=[];for(let t of a.filter(Boolean))for(let a of t.split(" "))r.push(a);return Array.from(new Set(r).values()).join(" ")}exports.style=function(a){let{compose:r=t,transform:e}=a??{};return{vn:t=>a=>{let n=a.variant?t.variants?.[a.variant]:t.defaultVariant?t.variants?.[t.defaultVariant]:void 0,s=[a.class,a.className,...a["class:list"]??[]],l=(t.compose??r)(t.base,n,...s),o=e??t.transform;return o?o(l):l},cn:e?(...t)=>e(r(...t)):r}};
1
+ function e(...t) {
2
+ let r = []
3
+ for (let e of t.filter(Boolean)) for (let t of e.split(" ")) r.push(t)
4
+ return Array.from(new Set(r).values()).join(" ")
5
+ }
6
+ exports.style = function (t) {
7
+ let { compose: r = e, transform: n } = t ?? {}
8
+ return {
9
+ vn: (e, t) => (o) => {
10
+ let s = t ? { ...e, ...(t({ config: e, props: o }) ?? {}) } : e,
11
+ f = ""
12
+ for (let e in s.props) {
13
+ let t = void 0 !== o[e] ? s.props[e][o[e]] : s.defaults?.[e] ? s.props[e][s.defaults[e]] : void 0
14
+ t && (f += "" === f ? t : ` ${t}`)
15
+ }
16
+ let a = [
17
+ o.class,
18
+ o.className,
19
+ ...((function (e) {
20
+ switch (typeof e) {
21
+ case "string":
22
+ return [e]
23
+ case "object":
24
+ if (e instanceof Array) return e
25
+ if (e instanceof Set || e instanceof Map) return Array.from(e)
26
+ return Object.entries(e).map(([e, t]) => (t ? e : void 0))
27
+ default:
28
+ return
29
+ }
30
+ })(o["class:list"]) ?? []),
31
+ ],
32
+ i = (s.compose ?? r)(s.base, f, ...a),
33
+ l = n ?? s.transform
34
+ return l ? l(i) : i
35
+ },
36
+ cn: n ? (...e) => n(r(...e)) : r,
37
+ }
38
+ }
@@ -1,38 +1,90 @@
1
- import { HTMLAttributes } from 'astro/types';
1
+ import { HTMLAttributes } from "astro/types"
2
2
 
3
- type Variants = Record<string, string>;
4
- type Compose = <const CS extends any[] = ClassName[]>(...classes: CS) => string;
5
- type Fn = (...args: any[]) => any;
6
- type ClassName = string | null | undefined | false | 0 | 0n | typeof NaN;
7
- type Config<V extends Variants, DV extends keyof V, B extends string, C extends Compose> = {
8
- variants?: V;
9
- defaultVariant?: DV;
10
- base?: B;
11
- compose?: C;
12
- transform?: Transform;
13
- };
14
- type Props<V extends Variants> = {
15
- variant?: keyof V;
16
- class?: string | null;
17
- className?: string | null;
18
- "class:list"?: HTMLAttributes<"div">["class:list"];
19
- };
20
- type Incorrect<S extends string = "[@hulla/style]: Invalid style configuration passed. Refer to https://hulla.dev/docs/style for help"> = S;
21
- type VariantProps<S> = S extends Fn ? Parameters<S>[0] extends Props<infer V> ? {
22
- variant?: keyof V;
23
- } : Incorrect : Incorrect;
24
- type Variant<S> = S extends Fn ? (Parameters<S>[0] extends Props<infer V> ? keyof V : Incorrect) : Incorrect;
25
- type Transform = (css: string) => string;
3
+ type Variants = Record<string, Record<string, string>>
4
+ type Compose = <const CS extends any[] = ClassName[]>(...classes: CS) => string
5
+ type ClassName = string | null | undefined | false | 0 | 0n | typeof NaN
6
+ type Config<
7
+ V extends Variants,
8
+ DV extends {
9
+ [K in keyof V]?: keyof V[K]
10
+ },
11
+ B extends string,
12
+ C extends Compose,
13
+ > = {
14
+ props: V
15
+ defaults?: DV
16
+ base?: B
17
+ compose?: C
18
+ transform?: Transform
19
+ }
20
+ type BaseProps = {
21
+ class?: string | null
22
+ className?: string | null
23
+ "class:list"?: HTMLAttributes<"div">["class:list"]
24
+ }
25
+ type Props<V extends Variants, _DV extends Defaults<V>, Extra extends Record<string, unknown>> = BaseProps & {
26
+ [K in keyof V]?: keyof V[K]
27
+ } & Extra
28
+ type Transform = (css: string) => string
26
29
  type Setup<C extends Compose> = {
27
- compose?: C;
28
- transform?: (css: string) => string;
29
- };
30
+ compose?: C
31
+ transform?: (css: string) => string
32
+ }
33
+ type Defaults<V extends Variants> = {
34
+ [K in keyof V]?: keyof V[K]
35
+ }
36
+ type VariantFunction<ExtraProps extends Record<string, unknown> = {}> = <
37
+ const V extends Variants,
38
+ const DV extends Defaults<V>,
39
+ const B extends string,
40
+ const C extends Compose,
41
+ >(
42
+ config: Config<V, DV, B, C>,
43
+ modifier?: (data: {
44
+ config: Config<V, DV, B, Compose>
45
+ props: Props<V, DV, ExtraProps>
46
+ }) => Partial<Config<V, DV, B, Compose>>
47
+ ) => (props: Props<V, DV, ExtraProps>) => string
30
48
  type StyleFunctions = {
31
- cn: Compose;
32
- vn: <V extends Variants, DV extends keyof V, B extends string>(config: Config<V, DV, B, Compose>) => (props: Props<V>) => string;
33
- };
49
+ cn: Compose
50
+ vn: VariantFunction<{}>
51
+ }
52
+ type NotNeverKeys<T extends Record<string, unknown>> = {
53
+ [K in keyof T]: T[K] extends never ? never : K
54
+ }[keyof T]
55
+ type HideNever<T extends Record<string, unknown>> = {
56
+ [K in NotNeverKeys<T>]: T[K]
57
+ }
58
+ type VariantProps<S extends (props: Props<Variants, Defaults<Variants>, Record<string, unknown>>) => string> =
59
+ Parameters<S>[0] extends Props<infer V, infer DV, Record<string, unknown>>
60
+ ? Omit<
61
+ {
62
+ [K in keyof V]: K extends keyof DV ? never : keyof V[K]
63
+ },
64
+ {
65
+ [K in keyof DV]: K extends keyof V ? K : never
66
+ }[keyof DV]
67
+ > & {
68
+ [K in keyof DV]?: K extends keyof V ? keyof V[K] : never
69
+ }
70
+ : never
34
71
 
35
- declare function style(): StyleFunctions;
36
- declare function style<C extends Compose>(setup: Setup<C>): StyleFunctions;
72
+ declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions
37
73
 
38
- export { type ClassName, type Compose, type Config, type Props, type Setup, type StyleFunctions, type Transform, type Variant, type VariantProps, type Variants, style };
74
+ export {
75
+ type BaseProps,
76
+ type ClassName,
77
+ type Compose,
78
+ type Config,
79
+ type Defaults,
80
+ type HideNever,
81
+ type NotNeverKeys,
82
+ type Props,
83
+ type Setup,
84
+ type StyleFunctions,
85
+ type Transform,
86
+ type VariantFunction,
87
+ type VariantProps,
88
+ type Variants,
89
+ style,
90
+ }
package/dist/es/index.mjs CHANGED
@@ -1 +1,39 @@
1
- function t(...a){let r=[];for(let t of a.filter(Boolean))for(let a of t.split(" "))r.push(a);return Array.from(new Set(r).values()).join(" ")}function a(a){let{compose:r=t,transform:e}=a??{};return{vn:t=>a=>{let n=a.variant?t.variants?.[a.variant]:t.defaultVariant?t.variants?.[t.defaultVariant]:void 0,l=[a.class,a.className,...a["class:list"]??[]],s=(t.compose??r)(t.base,n,...l),o=e??t.transform;return o?o(s):s},cn:e?(...t)=>e(r(...t)):r}}export{a as style};
1
+ function e(...t) {
2
+ let r = []
3
+ for (let e of t.filter(Boolean)) for (let t of e.split(" ")) r.push(t)
4
+ return Array.from(new Set(r).values()).join(" ")
5
+ }
6
+ function t(t) {
7
+ let { compose: r = e, transform: n } = t ?? {}
8
+ return {
9
+ vn: (e, t) => (o) => {
10
+ let s = t ? { ...e, ...(t({ config: e, props: o }) ?? {}) } : e,
11
+ f = ""
12
+ for (let e in s.props) {
13
+ let t = void 0 !== o[e] ? s.props[e][o[e]] : s.defaults?.[e] ? s.props[e][s.defaults[e]] : void 0
14
+ t && (f += "" === f ? t : ` ${t}`)
15
+ }
16
+ let a = [
17
+ o.class,
18
+ o.className,
19
+ ...((function (e) {
20
+ switch (typeof e) {
21
+ case "string":
22
+ return [e]
23
+ case "object":
24
+ if (e instanceof Array) return e
25
+ if (e instanceof Set || e instanceof Map) return Array.from(e)
26
+ return Object.entries(e).map(([e, t]) => (t ? e : void 0))
27
+ default:
28
+ return
29
+ }
30
+ })(o["class:list"]) ?? []),
31
+ ],
32
+ i = (s.compose ?? r)(s.base, f, ...a),
33
+ l = n ?? s.transform
34
+ return l ? l(i) : i
35
+ },
36
+ cn: n ? (...e) => n(r(...e)) : r,
37
+ }
38
+ }
39
+ export { t as style }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hulla/style",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Styling made easy 🎨",
5
5
  "author": {
6
6
  "name": "Samuel Hulla",