@plumeria/core 18.5.4 → 19.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,6 +1,6 @@
1
1
  import type { Style } from '#types';
2
2
 
3
- global {
3
+ declare global {
4
4
  namespace React {
5
5
  interface HTMLAttributes<T> {
6
6
  classStyle?: Style;
package/lib/css.d.ts CHANGED
@@ -9,13 +9,18 @@
9
9
  * type viewTransition = <const T extends ViewTransition>(rule: T) => string;
10
10
  * type marker = (id: string, pseudo: string) => Marker;
11
11
  * type extended = <I extends string, P extends string>(id: I, pseudo: P) => Extended<I, P>;
12
- * type use = (...rules: Style) => string;
12
+ * type use = (...rules: Style[]) => string;
13
13
  * ```
14
14
  */
15
15
  declare module '@plumeria/core' {
16
16
  import type {
17
17
  AtomicClassNameFor,
18
+ AtomicStyle,
19
+ AtomicDynamicStyle,
18
20
  Style,
21
+ StyleProps,
22
+ StaticStyles,
23
+ WithoutProperties,
19
24
  CSSProperties,
20
25
  CreateStyleValue,
21
26
  CreateReturnType,
@@ -29,7 +34,16 @@ declare module '@plumeria/core' {
29
34
  Extended,
30
35
  } from '#types';
31
36
 
32
- export type { AtomicClassNameFor, Style, CSSProperties };
37
+ export type {
38
+ AtomicClassNameFor,
39
+ AtomicStyle,
40
+ AtomicDynamicStyle,
41
+ Style,
42
+ StyleProps,
43
+ StaticStyles,
44
+ WithoutProperties,
45
+ CSSProperties,
46
+ };
33
47
 
34
48
  export const create: create;
35
49
  export type create = <const T extends Record<string, CreateStyleValue>>(
@@ -63,5 +77,5 @@ declare module '@plumeria/core' {
63
77
  ) => Extended<I, P>;
64
78
 
65
79
  export const use: use;
66
- export type use = (...rules: Style) => string;
80
+ export type use = (...rules: Style[]) => string;
67
81
  }
package/lib/types.d.ts CHANGED
@@ -24,12 +24,11 @@ type ColonSelector = {
24
24
  [key in ColonString]: CommonProperties | CSSVariableProperty;
25
25
  };
26
26
 
27
- type AtRule =
28
- | `@media ${string}`
29
- | `@container ${string}`
30
- | `@supports ${string}`
31
- | `@layer ${string}`
32
- | `@scope ${string}`;
27
+ type AtKeyword = '@media' | '@container' | '@supports' | '@layer' | '@scope';
28
+ type AtRule = `${AtKeyword} ${string}` | `${AtKeyword}(${string}`;
29
+
30
+ type StyleKey = keyof CSSTypes;
31
+ type NestedKey = ColonString | ArrayString | AtRule;
33
32
 
34
33
  type AtRuleSelector = {
35
34
  [K in AtRule]:
@@ -56,24 +55,62 @@ type AtomicClassNameFor<P extends string, V> = string & {
56
55
  readonly _value: V;
57
56
  };
58
57
 
59
- type AtString = `@${string}`;
60
- type MapNamespace<T> = Readonly<{
58
+ declare const StyleTag: unique symbol;
59
+
60
+ type AtomicStyle<T> = Readonly<{
61
61
  [key in keyof T]: T[key] extends Record<string, unknown>
62
- ? key extends ColonString | ArrayString | AtString
63
- ? MapNamespace<T[key]>
62
+ ? key extends NestedKey
63
+ ? AtomicStyle<T[key]>
64
64
  : AtomicClassNameFor<key & string, T[key]>
65
65
  : key extends string
66
66
  ? AtomicClassNameFor<key, T[key]>
67
67
  : never;
68
- }>;
68
+ }> & {
69
+ readonly [StyleTag]: true;
70
+ };
71
+
72
+ declare const DynamicTag: unique symbol;
73
+
74
+ type AtomicDynamicStyle<T> = AtomicStyle<T> & {
75
+ readonly [DynamicTag]: true;
76
+ };
69
77
 
70
78
  type CreateReturnType<T> = Readonly<{
71
79
  [K in keyof T]: T[K] extends (...args: infer A) => infer R
72
- ? (...args: A) => MapNamespace<R>
73
- : MapNamespace<T[K]>;
80
+ ? (...args: A) => AtomicDynamicStyle<R>
81
+ : AtomicStyle<T[K]>;
74
82
  }>;
75
- type Conditional = false | CSSProperties | null | undefined;
76
- type Style = Conditional | Style[];
83
+ type FlatNamespace<K extends StyleKey> = {
84
+ readonly [P in StyleKey]?: P extends K
85
+ ? AtomicClassNameFor<P & string, unknown>
86
+ : never;
87
+ };
88
+
89
+ interface NestedNamespace<K extends StyleKey> {
90
+ readonly [P: NestedKey]: AllowedNamespace<K> | undefined;
91
+ }
92
+
93
+ type AllowedNamespace<K extends StyleKey> = FlatNamespace<K> &
94
+ NestedNamespace<K> & {
95
+ readonly [StyleTag]: true;
96
+ };
97
+
98
+ type StyleList<T> = T | false | null | undefined | StyleList<T>[];
99
+
100
+ type StyleNamespace = AllowedNamespace<StyleKey>;
101
+ type Style = StyleList<StyleNamespace>;
102
+
103
+ type StyleProps<K extends StyleKey> = StyleList<AllowedNamespace<K>>;
104
+
105
+ type WithoutProperties<K extends StyleKey> = StyleProps<Exclude<StyleKey, K>>;
106
+
107
+ type StaticNamespace<K extends StyleKey> = AllowedNamespace<K> & {
108
+ readonly [DynamicTag]?: never;
109
+ };
110
+
111
+ type StaticStyles<K extends StyleKey = StyleKey> = StyleList<
112
+ StaticNamespace<K>
113
+ >;
77
114
 
78
115
  type CreateStatic = Record<string, string | number>;
79
116
 
@@ -99,8 +136,6 @@ type ViewTransition = {
99
136
  old?: CSSProperties;
100
137
  };
101
138
 
102
- type Marker = Record<string, CSSProperties>;
103
-
104
139
  type StripColon<T extends string> = T extends `:${infer R}` ? StripColon<R> : T;
105
140
 
106
141
  type Extended<
@@ -108,9 +143,16 @@ type Extended<
108
143
  P extends string,
109
144
  > = `@container style(--${I}-${StripColon<P>}: 1)`;
110
145
 
146
+ type Marker = Readonly<Record<ColonString, CSSVariableProperty>>;
147
+
111
148
  export type {
112
149
  AtomicClassNameFor,
150
+ AtomicStyle,
151
+ AtomicDynamicStyle,
113
152
  Style,
153
+ StyleProps,
154
+ StaticStyles,
155
+ WithoutProperties,
114
156
  CSSProperties,
115
157
  CreateStyleValue,
116
158
  CreateReturnType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/core",
3
- "version": "18.5.4",
3
+ "version": "19.1.0",
4
4
  "description": "Zero-cost abstraction layer for styling React components.",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",