@plumeria/core 18.5.3 → 19.0.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,16 @@
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
18
  Style,
19
+ StyleProps,
20
+ StaticStyles,
21
+ WithoutProperties,
19
22
  CSSProperties,
20
23
  CreateStyleValue,
21
24
  CreateReturnType,
@@ -29,7 +32,14 @@ declare module '@plumeria/core' {
29
32
  Extended,
30
33
  } from '#types';
31
34
 
32
- export type { AtomicClassNameFor, Style, CSSProperties };
35
+ export type {
36
+ AtomicClassNameFor,
37
+ Style,
38
+ StyleProps,
39
+ StaticStyles,
40
+ WithoutProperties,
41
+ CSSProperties,
42
+ };
33
43
 
34
44
  export const create: create;
35
45
  export type create = <const T extends Record<string, CreateStyleValue>>(
@@ -63,5 +73,5 @@ declare module '@plumeria/core' {
63
73
  ) => Extended<I, P>;
64
74
 
65
75
  export const use: use;
66
- export type use = (...rules: Style) => string;
76
+ export type use = (...rules: Style[]) => string;
67
77
  }
package/lib/types.d.ts CHANGED
@@ -31,6 +31,9 @@ type AtRule =
31
31
  | `@layer ${string}`
32
32
  | `@scope ${string}`;
33
33
 
34
+ type StyleKey = keyof CSSTypes;
35
+ type NestedKey = ColonString | ArrayString | AtRule;
36
+
34
37
  type AtRuleSelector = {
35
38
  [K in AtRule]:
36
39
  | CommonProperties
@@ -56,10 +59,9 @@ type AtomicClassNameFor<P extends string, V> = string & {
56
59
  readonly _value: V;
57
60
  };
58
61
 
59
- type AtString = `@${string}`;
60
62
  type MapNamespace<T> = Readonly<{
61
63
  [key in keyof T]: T[key] extends Record<string, unknown>
62
- ? key extends ColonString | ArrayString | AtString
64
+ ? key extends NestedKey
63
65
  ? MapNamespace<T[key]>
64
66
  : AtomicClassNameFor<key & string, T[key]>
65
67
  : key extends string
@@ -67,13 +69,46 @@ type MapNamespace<T> = Readonly<{
67
69
  : never;
68
70
  }>;
69
71
 
72
+ declare const DynamicTag: unique symbol;
73
+
74
+ type DynamicNamespace<T> = MapNamespace<T> & {
75
+ readonly [DynamicTag]: true;
76
+ };
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>
80
+ ? (...args: A) => DynamicNamespace<R>
73
81
  : MapNamespace<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
+
96
+ type StyleList<T> = T | false | null | undefined | StyleList<T>[];
97
+
98
+ type StyleNamespace = AllowedNamespace<StyleKey>;
99
+ type Style = StyleList<StyleNamespace>;
100
+
101
+ type StyleProps<K extends StyleKey> = StyleList<AllowedNamespace<K>>;
102
+
103
+ type WithoutProperties<K extends StyleKey> = StyleProps<Exclude<StyleKey, K>>;
104
+
105
+ type StaticNamespace<K extends StyleKey> = AllowedNamespace<K> & {
106
+ readonly [DynamicTag]?: never;
107
+ };
108
+
109
+ type StaticStyles<K extends StyleKey = StyleKey> = StyleList<
110
+ StaticNamespace<K>
111
+ >;
77
112
 
78
113
  type CreateStatic = Record<string, string | number>;
79
114
 
@@ -99,8 +134,6 @@ type ViewTransition = {
99
134
  old?: CSSProperties;
100
135
  };
101
136
 
102
- type Marker = Record<string, CSSProperties>;
103
-
104
137
  type StripColon<T extends string> = T extends `:${infer R}` ? StripColon<R> : T;
105
138
 
106
139
  type Extended<
@@ -108,9 +141,14 @@ type Extended<
108
141
  P extends string,
109
142
  > = `@container style(--${I}-${StripColon<P>}: 1)`;
110
143
 
144
+ type Marker = Record<Extended<string, string>, CSSProperties>;
145
+
111
146
  export type {
112
147
  AtomicClassNameFor,
113
148
  Style,
149
+ StyleProps,
150
+ StaticStyles,
151
+ WithoutProperties,
114
152
  CSSProperties,
115
153
  CreateStyleValue,
116
154
  CreateReturnType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/core",
3
- "version": "18.5.3",
3
+ "version": "19.0.0",
4
4
  "description": "Zero-cost abstraction layer for styling React components.",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",