@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.
- package/dist/cjs/index.d.ts +85 -33
- package/dist/cjs/index.js +38 -1
- package/dist/es/index.d.mts +85 -33
- package/dist/es/index.mjs +39 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,38 +1,90 @@
|
|
|
1
|
-
import { HTMLAttributes } from
|
|
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
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type
|
|
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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 {
|
|
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
|
|
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
|
+
}
|
package/dist/es/index.d.mts
CHANGED
|
@@ -1,38 +1,90 @@
|
|
|
1
|
-
import { HTMLAttributes } from
|
|
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
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type
|
|
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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 {
|
|
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
|
|
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 }
|