@hulla/style 0.1.0 → 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.
@@ -1,90 +1,55 @@
1
- import { HTMLAttributes } from "astro/types"
1
+ import { HTMLAttributes } from 'astro/types';
2
2
 
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
- }
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 | 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;
11
+ base?: B;
12
+ compose?: C;
13
+ transform?: Transform;
14
+ };
20
15
  type BaseProps = {
21
- class?: string | null
22
- className?: string | null
23
- "class:list"?: HTMLAttributes<"div">["class:list"]
24
- }
16
+ class?: string | null;
17
+ className?: string | null;
18
+ "class:list"?: HTMLAttributes<"div">["class:list"];
19
+ };
25
20
  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
21
+ [K in keyof V]?: keyof V[K];
22
+ } & Extra;
23
+ type Transform = (css: string) => string;
29
24
  type Setup<C extends Compose> = {
30
- compose?: C
31
- transform?: (css: string) => string
32
- }
25
+ compose?: C;
26
+ transform?: (css: string) => string;
27
+ };
33
28
  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
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;
48
35
  type StyleFunctions = {
49
- cn: Compose
50
- vn: VariantFunction<{}>
51
- }
36
+ cn: Compose;
37
+ vn: VariantFunction<{}>;
38
+ };
52
39
  type NotNeverKeys<T extends Record<string, unknown>> = {
53
- [K in keyof T]: T[K] extends never ? never : K
54
- }[keyof T]
40
+ [K in keyof T]: T[K] extends never ? never : K;
41
+ }[keyof T];
55
42
  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
43
+ [K in NotNeverKeys<T>]: T[K];
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;
71
52
 
72
- declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions
53
+ declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions;
73
54
 
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
- }
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,38 +1 @@
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
+ 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}};
@@ -1,90 +1,55 @@
1
- import { HTMLAttributes } from "astro/types"
1
+ import { HTMLAttributes } from 'astro/types';
2
2
 
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
- }
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 | 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;
11
+ base?: B;
12
+ compose?: C;
13
+ transform?: Transform;
14
+ };
20
15
  type BaseProps = {
21
- class?: string | null
22
- className?: string | null
23
- "class:list"?: HTMLAttributes<"div">["class:list"]
24
- }
16
+ class?: string | null;
17
+ className?: string | null;
18
+ "class:list"?: HTMLAttributes<"div">["class:list"];
19
+ };
25
20
  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
21
+ [K in keyof V]?: keyof V[K];
22
+ } & Extra;
23
+ type Transform = (css: string) => string;
29
24
  type Setup<C extends Compose> = {
30
- compose?: C
31
- transform?: (css: string) => string
32
- }
25
+ compose?: C;
26
+ transform?: (css: string) => string;
27
+ };
33
28
  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
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;
48
35
  type StyleFunctions = {
49
- cn: Compose
50
- vn: VariantFunction<{}>
51
- }
36
+ cn: Compose;
37
+ vn: VariantFunction<{}>;
38
+ };
52
39
  type NotNeverKeys<T extends Record<string, unknown>> = {
53
- [K in keyof T]: T[K] extends never ? never : K
54
- }[keyof T]
40
+ [K in keyof T]: T[K] extends never ? never : K;
41
+ }[keyof T];
55
42
  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
43
+ [K in NotNeverKeys<T>]: T[K];
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;
71
52
 
72
- declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions
53
+ declare function style<C extends Compose>(setup?: Setup<C>): StyleFunctions;
73
54
 
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
- }
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,39 +1 @@
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 }
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.1.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",