@stylexjs/stylex 0.2.0-beta.19 → 0.2.0-beta.20

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.
@@ -21,6 +21,42 @@ export type StyleXClassName = StyleXClassNameFor<unknown, unknown>;
21
21
  // Type for arbitrarily nested Array.
22
22
  export type StyleXArray<T> = T | ReadonlyArray<StyleXArray<T>>;
23
23
 
24
+ type lowerCaseAlphabet =
25
+ | 'a'
26
+ | 'b'
27
+ | 'c'
28
+ | 'd'
29
+ | 'e'
30
+ | 'f'
31
+ | 'g'
32
+ | 'h'
33
+ | 'i'
34
+ | 'j'
35
+ | 'k'
36
+ | 'l'
37
+ | 'm'
38
+ | 'n'
39
+ | 'o'
40
+ | 'p'
41
+ | 'q'
42
+ | 'r'
43
+ | 's'
44
+ | 't'
45
+ | 'u'
46
+ | 'v'
47
+ | 'w'
48
+ | 'x'
49
+ | 'y'
50
+ | 'z'
51
+ | '-'
52
+ | '_'
53
+ | '@'
54
+ | ':';
55
+
56
+ // Strings that don't start with a dollar sign.
57
+ // So that we can `&` with {$$css: true} without type errors.
58
+ type NonDollarStr = `${lowerCaseAlphabet}${string}`;
59
+
24
60
  type CSSPropTypes = {
25
61
  [Key in keyof CSSProperties]: StyleXClassNameFor<Key, CSSProperties[Key]>;
26
62
  };
@@ -70,18 +106,23 @@ export type StyleXSingleStyle = false | (null | undefined | NestedCSSPropTypes);
70
106
  export type XStyle<T = NestedCSSPropTypes> = StyleXArray<
71
107
  false | (null | undefined | T)
72
108
  >;
73
- export type XStyleWithout<T extends { [$$Key$$: string]: void }> = XStyle<
109
+ export type XStyleWithout<T extends { [$$Key$$: NonDollarStr]: void }> = XStyle<
74
110
  Readonly<Pick<NestedCSSPropTypes, Exclude<keyof NestedCSSPropTypes, keyof T>>>
75
111
  >;
76
112
 
77
- export type Keyframes = Readonly<{ [name: string]: CSSProperties }>;
78
- export type LegacyTheme = Readonly<{ [constantName: string]: string }>;
113
+ export type Keyframes = Readonly<{ [name: NonDollarStr]: CSSProperties }>;
114
+ export type LegacyTheme = Readonly<{ [constantName: NonDollarStr]: string }>;
79
115
 
80
116
  type RawStyles = {
81
- [key: string]: null | string | number | Array<string | number> | RawStyles;
117
+ [key: NonDollarStr]:
118
+ | null
119
+ | string
120
+ | number
121
+ | Array<string | number>
122
+ | RawStyles;
82
123
  };
83
124
 
84
- type CompiledNamespace<N extends RawStyles> = {
125
+ type CompiledNamespace<const N extends RawStyles> = {
85
126
  [K in keyof N]: N[K] extends string | number | null
86
127
  ? StyleXClassNameFor<K, N[K]>
87
128
  : N[K] extends ReadonlyArray<infer T>
@@ -95,23 +136,25 @@ type CompiledNamespace<N extends RawStyles> = {
95
136
  : never;
96
137
  };
97
138
 
98
- export type Stylex$Create = <const S extends { [n: string]: RawStyles }>(
139
+ export type Stylex$Create = <const S extends { [n: NonDollarStr]: RawStyles }>(
99
140
  styles: S,
100
141
  ) => Readonly<{
101
- [N in keyof S]: CompiledNamespace<S[N]>;
142
+ [N in keyof S]: CompiledNamespace<S[N]> & { $$css: true };
102
143
  }>;
103
144
 
104
145
  export type CompiledStyles = Readonly<{
105
- [key: string]: StyleXClassName | Readonly<{ [key: string]: StyleXClassName }>;
106
- }>;
146
+ [key: NonDollarStr]:
147
+ | StyleXClassName
148
+ | Readonly<{ [key: NonDollarStr]: StyleXClassName }>;
149
+ }> & { $$css: true };
107
150
 
108
151
  type TTokens = {
109
- [key: string]: string | { default: string; [key: string]: string };
152
+ [key: NonDollarStr]: string | { default: string; [key: string]: string };
110
153
  };
111
154
 
112
155
  export type FlattenTokens<
113
156
  T extends {
114
- [key: string]: string | { default: string; [key: string]: string };
157
+ [key: NonDollarStr]: string | { default: string; [key: string]: string };
115
158
  },
116
159
  > = {
117
160
  [Key in keyof T]: T[Key] extends { default: infer X } & {
@@ -107,7 +107,11 @@ export type MapNamespace<CSS: { ... }> = $ReadOnly<{
107
107
  // Rule,
108
108
  // ) => $ObjMap<Rule, MapCSSValueToClassName>) &
109
109
  // MapCSSValueToClassName;
110
- export type MapNamespaces = <CSS: { ... }>(CSS) => MapNamespace<CSS>;
110
+
111
+ export type MapNamespaces = (<CSS: { ... }>(CSS) => MapNamespace<CSS>) &
112
+ (<Args: $ReadOnlyArray<mixed>, CSS: { ... }>(
113
+ fn: (...args: Args) => CSS,
114
+ ) => MapNamespace<CSS>);
111
115
 
112
116
  export type Stylex$Create = <S: { ... }>(
113
117
  styles: S,
@@ -9,7 +9,7 @@
9
9
 
10
10
  type CSSLengthUnitType = 'em' | 'px' | 'rem' | 'vh' | 'vmax' | 'vmin' | 'vw';
11
11
  export declare class CSSLengthUnitValue {
12
- static parse(inp: string): CSSLengthUnitValue | null;
12
+ static parse(inp: string): [number, CSSLengthUnitType] | null;
13
13
  value: number;
14
14
  unit: CSSLengthUnitType;
15
15
  constructor(value: number, unit: CSSLengthUnitType);
@@ -13,7 +13,7 @@ class CSSLengthUnitValue {
13
13
  }
14
14
  const [, value, unit] = match;
15
15
  const parsedValue = parseFloat(value);
16
- return new CSSLengthUnitValue(parsedValue, unit);
16
+ return [parsedValue, unit];
17
17
  }
18
18
  constructor(value, unit) {
19
19
  this.value = value;
@@ -11,7 +11,7 @@ type CSSLengthUnitType = 'em' | 'px' | 'rem' | 'vh' | 'vmax' | 'vmin' | 'vw';
11
11
 
12
12
  // TODO: this only works on simple values
13
13
  declare export class CSSLengthUnitValue {
14
- static parse(inp: string): CSSLengthUnitValue | null;
14
+ static parse(inp: string): [number, CSSLengthUnitType] | null;
15
15
  value: number;
16
16
  unit: CSSLengthUnitType;
17
17
  constructor(value: number, unit: CSSLengthUnitType): void;