@plumeria/core 13.0.2 → 13.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/lib/css.d.ts CHANGED
@@ -3,11 +3,11 @@
3
3
  * Bundler plugin required.
4
4
  * ```ts
5
5
  * type create = <const T extends Record<string, CreateStyleValue>>(rule: T)=> CreateReturnType<T>;
6
+ * type variants = <T extends Variants>(rule: T) => (props: { [K in keyof T]?: keyof T[K] }) => VariantStyles<T>;
6
7
  * type createTheme = <const T extends CreateTheme>(themeSelector: string, rule: T) => CreateThemeReturnType<T>;
7
8
  * type createStatic = <const T extends CreateStatic>(rule: T)=> T;
8
9
  * type keyframes = <const T extends Keyframes>(rule: T) => string;
9
10
  * type viewTransition = <const T extends ViewTransition>(rule: T) => string;
10
- * type variants = <T extends Variants>(rule: T) => (props: { [K in keyof T]?: keyof T[K] }) => CSSProperties;
11
11
  * type marker = (id: string, pseudo: string) => Marker;
12
12
  * type extended = <I extends string, P extends string>(id: I, pseudo: P) => Extended<I, P>;
13
13
  * type use = (...rules: (false | CSSProperties | null | undefined)[])=> string;
@@ -23,6 +23,7 @@ declare module '@plumeria/core' {
23
23
  CreateThemeReturnType,
24
24
  CreateStatic,
25
25
  Variants,
26
+ VariantStyles,
26
27
  Keyframes,
27
28
  ViewTransition,
28
29
  Marker,
@@ -44,6 +45,11 @@ declare module '@plumeria/core' {
44
45
  rule: T,
45
46
  ) => CreateReturnType<T>;
46
47
 
48
+ export const variants: variants;
49
+ export type variants = <T extends Variants>(
50
+ rule: T,
51
+ ) => (props: { [K in keyof T]?: keyof T[K] }) => VariantStyles<T>;
52
+
47
53
  export const createTheme: createTheme;
48
54
  export type createTheme = <const T extends CreateTheme>(
49
55
  themeSelector: string,
@@ -61,11 +67,6 @@ declare module '@plumeria/core' {
61
67
  rule: T,
62
68
  ) => string;
63
69
 
64
- export const variants: variants;
65
- export type variants = <T extends Variants>(
66
- rule: T,
67
- ) => (props: { [K in keyof T]?: keyof T[K] }) => CSSProperties;
68
-
69
70
  export const marker: marker;
70
71
  export type marker = (id: string, pseudo: string) => Marker;
71
72
 
package/lib/types.d.ts CHANGED
@@ -42,23 +42,39 @@ type CSSProperties =
42
42
 
43
43
  type CreateStyleValue = CSSProperties | ((...args: any[]) => CSSProperties);
44
44
 
45
- type CreateReturnType<T> = {
46
- [K in keyof T]: T[K] extends (...args: infer A) => infer R
47
- ? (...args: A) => Readonly<R>
48
- : Readonly<T[K]>;
45
+ const ClassNameTag: unique symbol;
46
+
47
+ type AtomicClassNameFor<out P extends string, out V> = string & {
48
+ readonly _ident: typeof ClassNameTag;
49
+ readonly _key: P;
50
+ readonly _value: V;
49
51
  };
50
52
 
53
+ type MapNamespace<T> = Readonly<{
54
+ [key in keyof T]: T[key] extends Record<string, unknown>
55
+ ? key extends `:${string}` | `@${string}` | `[${string}`
56
+ ? MapNamespace<T[key]>
57
+ : AtomicClassNameFor<key & string, T[key]>
58
+ : key extends string
59
+ ? AtomicClassNameFor<key, T[key]>
60
+ : never;
61
+ }>;
62
+
63
+ type CreateReturnType<T> = Readonly<{
64
+ [K in keyof T]: T[K] extends (...args: infer A) => infer R
65
+ ? (...args: A) => MapNamespace<R>
66
+ : MapNamespace<T[K]>;
67
+ }>;
68
+
51
69
  type StyleName = CSSProperties | (false | CSSProperties | null | undefined)[];
52
70
 
53
71
  type CreateStatic = Record<string, string | number>;
54
72
 
55
- type ReadonlyTheme<T> = Readonly<T> & CSSVariableValue;
56
-
57
73
  type CreateTheme = {
58
74
  [key: string]: ThemeValue;
59
75
  };
60
76
  type CreateThemeReturnType<T> = {
61
- readonly [K in keyof T]: ReadonlyTheme<T[K]>;
77
+ readonly [K in keyof T]: Readonly<T[K]>;
62
78
  };
63
79
 
64
80
  type KeyframesInSelector = 'from' | 'to' | `${number}%`;
@@ -75,6 +91,23 @@ type ViewTransition = {
75
91
 
76
92
  type Variants = Record<string, Record<string, CSSProperties>>;
77
93
 
94
+ type AllOptionsOf<T> = {
95
+ [G in keyof T]: T[G][keyof T[G]];
96
+ }[keyof T];
97
+
98
+ type KeysOfUnion<U> = U extends unknown ? keyof U : never;
99
+ type ValueForKeyInUnion<U, K> = U extends unknown
100
+ ? K extends keyof U
101
+ ? U[K]
102
+ : never
103
+ : never;
104
+
105
+ type MergeVariants<U> = Readonly<{
106
+ [K in KeysOfUnion<U>]?: ValueForKeyInUnion<U, K>;
107
+ }>;
108
+
109
+ type VariantStyles<T> = MergeVariants<AllOptionsOf<T>>;
110
+
78
111
  type Marker = Record<string, CSSProperties>;
79
112
 
80
113
  type StripColon<T extends string> = T extends `:${infer R}` ? StripColon<R> : T;
@@ -93,8 +126,10 @@ export type {
93
126
  CreateThemeReturnType,
94
127
  CreateStatic,
95
128
  Variants,
129
+ VariantStyles,
96
130
  Keyframes,
97
131
  ViewTransition,
98
132
  Marker,
99
133
  Extended,
134
+ AtomicClassNameFor,
100
135
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/core",
3
- "version": "13.0.2",
3
+ "version": "13.1.1",
4
4
  "description": "Zero-cost abstraction layer for styling React components.",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",