@stylexjs/stylex 0.16.3 → 0.17.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.
@@ -7,5 +7,10 @@
7
7
  *
8
8
  */
9
9
 
10
- declare function inject(cssText: string, priority: number): string;
10
+ declare function inject(
11
+ cssText: string,
12
+ priority: number,
13
+ constKey?: string,
14
+ constVal?: string | number,
15
+ ): string;
11
16
  export default inject;
package/lib/cjs/inject.js CHANGED
@@ -9,8 +9,11 @@ function addSpecificityLevel(cssText, index) {
9
9
  length: index
10
10
  }).map(() => ':not(#\\#)').join('');
11
11
  const lastOpenCurly = cssText.includes('::') ? cssText.indexOf('::') : cssText.lastIndexOf('{');
12
- const beforeCurly = cssText.slice(0, lastOpenCurly);
12
+ let beforeCurly = cssText.slice(0, lastOpenCurly);
13
13
  const afterCurly = cssText.slice(lastOpenCurly);
14
+ if (index > 0) {
15
+ beforeCurly = beforeCurly.trimEnd();
16
+ }
14
17
  return `${beforeCurly}${pseudoSelector}${afterCurly}`;
15
18
  }
16
19
 
@@ -82,6 +85,74 @@ function createOrderedCSSStyleSheet(sheet) {
82
85
  }
83
86
  return isInserted;
84
87
  }
88
+ function insert(cssText, groupValue) {
89
+ const group = Number(groupValue);
90
+ if (groups[group] == null) {
91
+ const markerRule = encodeGroupRule(group);
92
+ groups[group] = {
93
+ start: null,
94
+ rules: [markerRule]
95
+ };
96
+ if (sheet != null) {
97
+ sheetInsert(sheet, group, markerRule);
98
+ }
99
+ }
100
+ const key = getSeenRuleKey(cssText);
101
+ if (key != null && seenRules[key] == null) {
102
+ seenRules[key] = true;
103
+ let shouldUpdate = true;
104
+ if (sheet != null) {
105
+ const isInserted = sheetInsert(sheet, group, cssText);
106
+ if (!isInserted) {
107
+ shouldUpdate = false;
108
+ }
109
+ }
110
+ if (shouldUpdate) {
111
+ groups[group].rules.push(cssText);
112
+ }
113
+ }
114
+ }
115
+ function update(oldCssText, newCssText, groupValue) {
116
+ const group = Number(groupValue);
117
+ const oldKey = getSeenRuleKey(oldCssText);
118
+ const newKey = getSeenRuleKey(newCssText);
119
+ if (oldKey !== newKey || oldKey == null) {
120
+ insert(newCssText, groupValue);
121
+ return;
122
+ }
123
+ if (seenRules[oldKey]) {
124
+ if (groups[group] && groups[group].rules) {
125
+ const rules = groups[group].rules;
126
+ let foundIndex = -1;
127
+ for (let i = 0; i < rules.length; i++) {
128
+ if (getSeenRuleKey(rules[i]) === oldKey) {
129
+ foundIndex = i;
130
+ break;
131
+ }
132
+ }
133
+ if (foundIndex !== -1) {
134
+ rules[foundIndex] = newCssText;
135
+ }
136
+ }
137
+ if (sheet != null) {
138
+ const cssRules = sheet.cssRules;
139
+ for (let i = cssRules.length - 1; i >= 0; i--) {
140
+ const rule = cssRules[i];
141
+ const ruleCssText = rule.cssText;
142
+ const ruleKey = getSeenRuleKey(ruleCssText);
143
+ if (ruleKey === oldKey) {
144
+ try {
145
+ sheet.deleteRule(i);
146
+ sheetInsert(sheet, group, newCssText);
147
+ break;
148
+ } catch (e) {}
149
+ }
150
+ }
151
+ }
152
+ } else {
153
+ insert(newCssText, groupValue);
154
+ }
155
+ }
85
156
  const OrderedCSSStyleSheet = {
86
157
  getTextContent() {
87
158
  return getOrderedGroups(groups).map(group => {
@@ -94,33 +165,8 @@ function createOrderedCSSStyleSheet(sheet) {
94
165
  return rules.join('\n');
95
166
  }).join('\n');
96
167
  },
97
- insert(cssText, groupValue) {
98
- const group = Number(groupValue);
99
- if (groups[group] == null) {
100
- const markerRule = encodeGroupRule(group);
101
- groups[group] = {
102
- start: null,
103
- rules: [markerRule]
104
- };
105
- if (sheet != null) {
106
- sheetInsert(sheet, group, markerRule);
107
- }
108
- }
109
- const key = getSeenRuleKey(cssText);
110
- if (key != null && seenRules[key] == null) {
111
- seenRules[key] = true;
112
- let shouldUpdate = true;
113
- if (sheet != null) {
114
- const isInserted = sheetInsert(sheet, group, cssText);
115
- if (!isInserted) {
116
- shouldUpdate = false;
117
- }
118
- }
119
- if (shouldUpdate) {
120
- groups[group].rules.push(cssText);
121
- }
122
- }
123
- }
168
+ insert,
169
+ update
124
170
  };
125
171
  return OrderedCSSStyleSheet;
126
172
  }
@@ -196,14 +242,92 @@ function createSheet(root) {
196
242
  sheets.forEach(s => {
197
243
  s.insert(cssText, groupValue);
198
244
  });
245
+ },
246
+ update(oldCssText, newCssText, groupValue) {
247
+ sheets.forEach(s => {
248
+ s.update(oldCssText, newCssText, groupValue);
249
+ });
199
250
  }
200
251
  };
201
252
  }
202
253
 
203
254
  const sheet = createSheet();
204
- function inject(cssText, priority) {
205
- const text = addSpecificityLevel(cssText, Math.floor(priority / 1000));
255
+ const constants = {};
256
+ const dependencies = {};
257
+ function escapeRegex(str) {
258
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
259
+ }
260
+ function resolveConstants(cssText) {
261
+ let resolved = cssText;
262
+ const varPattern = /var\(--([a-z0-9]+)\)/gi;
263
+ varPattern.lastIndex = 0;
264
+ const replacements = [];
265
+ let match = varPattern.exec(cssText);
266
+ while (match != null) {
267
+ const constKey = match[1];
268
+ if (constKey != null && constants[constKey] !== undefined) {
269
+ const constVal = constants[constKey];
270
+ const constValStr = String(constVal);
271
+ replacements.push([`var(--${constKey})`, constValStr]);
272
+ }
273
+ match = varPattern.exec(cssText);
274
+ }
275
+ for (const [search, replace] of replacements) {
276
+ const regex = new RegExp(escapeRegex(search), 'g');
277
+ resolved = resolved.replace(regex, replace);
278
+ }
279
+ return resolved;
280
+ }
281
+ function trackDependencies(originalCssText, priority, resolvedCss) {
282
+ const varPattern = /var\(--([a-z0-9]+)\)/gi;
283
+ let match = varPattern.exec(originalCssText);
284
+ while (match != null) {
285
+ const constKey = match[1];
286
+ if (constKey != null && constants[constKey] !== undefined) {
287
+ if (!dependencies[constKey]) {
288
+ dependencies[constKey] = new Map();
289
+ }
290
+ dependencies[constKey].set(originalCssText, {
291
+ priority,
292
+ resolvedCss
293
+ });
294
+ }
295
+ match = varPattern.exec(originalCssText);
296
+ }
297
+ }
298
+ function updateDependentRules(constKey) {
299
+ const deps = dependencies[constKey];
300
+ if (!deps || deps.size === 0) {
301
+ return;
302
+ }
303
+ deps.forEach(({
304
+ priority,
305
+ resolvedCss: oldResolvedCss
306
+ }, cssText) => {
307
+ const newResolvedCss = resolveConstants(cssText);
308
+ const oldText = addSpecificityLevel(oldResolvedCss, Math.floor(priority / 1000));
309
+ const newText = addSpecificityLevel(newResolvedCss, Math.floor(priority / 1000));
310
+ deps.set(cssText, {
311
+ priority,
312
+ resolvedCss: newResolvedCss
313
+ });
314
+ sheet.update(oldText, newText, priority);
315
+ });
316
+ }
317
+ function inject(cssText, priority, constKey, constVal) {
318
+ if (constKey !== undefined && constVal !== undefined) {
319
+ const hadPreviousValue = constants[constKey] !== undefined;
320
+ const valueChanged = hadPreviousValue && constants[constKey] !== constVal;
321
+ constants[constKey] = constVal;
322
+ if (valueChanged) {
323
+ updateDependentRules(constKey);
324
+ }
325
+ return '';
326
+ }
327
+ const resolved = resolveConstants(cssText);
328
+ const text = addSpecificityLevel(resolved, Math.floor(priority / 1000));
206
329
  sheet.insert(text, priority);
330
+ trackDependencies(cssText, priority, resolved);
207
331
  return text;
208
332
  }
209
333
 
@@ -10,4 +10,6 @@
10
10
  declare export default function inject(
11
11
  cssText: string,
12
12
  priority: number,
13
+ constKey?: string,
14
+ constVal?: string | number,
13
15
  ): string;
@@ -10,6 +10,7 @@
10
10
  export type OrderedCSSStyleSheet = Readonly<{
11
11
  getTextContent: () => string;
12
12
  insert: (cssText: string, groupValue: number) => void;
13
+ update: (oldCssText: string, newCssText: string, groupValue: number) => void;
13
14
  }>;
14
15
  /**
15
16
  * Order-based insertion of CSS.
@@ -10,6 +10,7 @@
10
10
  export type OrderedCSSStyleSheet = $ReadOnly<{
11
11
  getTextContent: () => string,
12
12
  insert: (cssText: string, groupValue: number) => void,
13
+ update: (oldCssText: string, newCssText: string, groupValue: number) => void,
13
14
  }>;
14
15
 
15
16
  /**
@@ -8,5 +8,5 @@
8
8
  */
9
9
 
10
10
  import type { OrderedCSSStyleSheet } from './createOrderedCSSStyleSheet';
11
- type Sheet = Readonly<Omit<OrderedCSSStyleSheet, keyof ({})> & {}>;
11
+ type Sheet = Readonly<Omit<OrderedCSSStyleSheet, keyof {}> & {}>;
12
12
  export declare function createSheet(root?: HTMLElement): Sheet;
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  export declare const canUseDOM: boolean;
11
+ export declare type canUseDOM = typeof canUseDOM;
11
12
  /**
12
13
  * Adds :not(#\#) to selectors to increase their specificity.
13
14
  * This is used to polyfill @layer
@@ -27,6 +27,9 @@ import type {
27
27
  VarGroup,
28
28
  PositionTry,
29
29
  ViewTransitionClass,
30
+ StyleX$When,
31
+ MapNamespace,
32
+ StyleX$DefineMarker,
30
33
  } from './types/StyleXTypes';
31
34
  import type { ValueWithDefault } from './types/StyleXUtils';
32
35
  import * as Types from './types/VarTypes';
@@ -48,14 +51,23 @@ export type {
48
51
  PositionTry,
49
52
  };
50
53
  export declare const create: StyleX$Create;
54
+ export declare type create = typeof create;
51
55
  export declare const createTheme: StyleX$CreateTheme;
56
+ export declare type createTheme = typeof createTheme;
52
57
  export declare const defineConsts: StyleX$DefineConsts;
58
+ export declare type defineConsts = typeof defineConsts;
53
59
  export declare const defineVars: StyleX$DefineVars;
60
+ export declare type defineVars = typeof defineVars;
61
+ export declare const defineMarker: StyleX$DefineMarker;
62
+ export declare type defineMarker = typeof defineMarker;
54
63
  export declare const firstThatWorks: <T extends string | number>(
55
64
  ..._styles: ReadonlyArray<T>
56
65
  ) => ReadonlyArray<T>;
66
+ export declare type firstThatWorks = typeof firstThatWorks;
57
67
  export declare const keyframes: (_keyframes: Keyframes) => string;
68
+ export declare type keyframes = typeof keyframes;
58
69
  export declare const positionTry: (_positionTry: PositionTry) => string;
70
+ export declare type positionTry = typeof positionTry;
59
71
  export declare function props(
60
72
  this: null | undefined | unknown,
61
73
  ...styles: ReadonlyArray<
@@ -73,14 +85,13 @@ export declare function props(
73
85
  export declare const viewTransitionClass: (
74
86
  _viewTransitionClass: ViewTransitionClass,
75
87
  ) => string;
76
- export declare const defaultMarker: () => StaticStyles;
77
- export declare const when: {
78
- ancestor: (_pseudo?: string) => string;
79
- descendant: (_pseudo?: string) => string;
80
- siblingBefore: (_pseudo?: string) => string;
81
- siblingAfter: (_pseudo?: string) => string;
82
- anySibling: (_pseudo?: string) => string;
83
- };
88
+ export declare type viewTransitionClass = typeof viewTransitionClass;
89
+ export declare const defaultMarker: () => MapNamespace<
90
+ Readonly<{ marker: 'default-marker' }>
91
+ >;
92
+ export declare type defaultMarker = typeof defaultMarker;
93
+ export declare const when: StyleX$When;
94
+ export declare type when = typeof when;
84
95
  export declare const types: {
85
96
  angle: <T extends string | 0 = string | 0>(
86
97
  _v: ValueWithDefault<T>,
@@ -114,6 +125,7 @@ export declare const types: {
114
125
  _v: ValueWithDefault<T>,
115
126
  ) => Types.TransformList<T>;
116
127
  };
128
+ export declare type types = typeof types;
117
129
  /**
118
130
  * DO NOT USE. Legacy export for Meta
119
131
  */
@@ -132,7 +144,8 @@ type IStyleX = {
132
144
  createTheme: StyleX$CreateTheme;
133
145
  defineConsts: StyleX$DefineConsts;
134
146
  defineVars: StyleX$DefineVars;
135
- defaultMarker: () => StaticStyles;
147
+ defaultMarker: () => MapNamespace<Readonly<{ marker: 'default-marker' }>>;
148
+ defineMarker: StyleX$DefineMarker;
136
149
  firstThatWorks: <T extends string | number>(
137
150
  ...v: ReadonlyArray<T>
138
151
  ) => ReadonlyArray<T>;
@@ -158,3 +171,4 @@ type IStyleX = {
158
171
  __customProperties?: { [$$Key$$: string]: unknown };
159
172
  };
160
173
  export declare const legacyMerge: IStyleX;
174
+ export declare type legacyMerge = typeof legacyMerge;
package/lib/cjs/stylex.js CHANGED
@@ -146,6 +146,9 @@ const defineConsts = function stylexDefineConsts(_styles) {
146
146
  const defineVars = function stylexDefineVars(_styles) {
147
147
  throw errorForFn('defineVars');
148
148
  };
149
+ const defineMarker = () => {
150
+ throw errorForFn('defineMarker');
151
+ };
149
152
  const firstThatWorks = (..._styles) => {
150
153
  throw errorForFn('firstThatWorks');
151
154
  };
@@ -176,19 +179,19 @@ const defaultMarker = () => {
176
179
  throw errorForFn('defaultMarker');
177
180
  };
178
181
  const when = {
179
- ancestor: _pseudo => {
182
+ ancestor: _p => {
180
183
  throw errorForFn('when.ancestor');
181
184
  },
182
- descendant: _pseudo => {
185
+ descendant: _p => {
183
186
  throw errorForFn('when.descendant');
184
187
  },
185
- siblingBefore: _pseudo => {
188
+ siblingBefore: _p => {
186
189
  throw errorForFn('when.siblingBefore');
187
190
  },
188
- siblingAfter: _pseudo => {
191
+ siblingAfter: _p => {
189
192
  throw errorForFn('when.siblingAfter');
190
193
  },
191
- anySibling: _pseudo => {
194
+ anySibling: _p => {
192
195
  throw errorForFn('when.anySibling');
193
196
  }
194
197
  };
@@ -240,6 +243,7 @@ function _legacyMerge(...styles) {
240
243
  _legacyMerge.create = create;
241
244
  _legacyMerge.createTheme = createTheme;
242
245
  _legacyMerge.defineConsts = defineConsts;
246
+ _legacyMerge.defineMarker = defineMarker;
243
247
  _legacyMerge.defineVars = defineVars;
244
248
  _legacyMerge.defaultMarker = defaultMarker;
245
249
  _legacyMerge.firstThatWorks = firstThatWorks;
@@ -255,6 +259,7 @@ exports.create = create;
255
259
  exports.createTheme = createTheme;
256
260
  exports.defaultMarker = defaultMarker;
257
261
  exports.defineConsts = defineConsts;
262
+ exports.defineMarker = defineMarker;
258
263
  exports.defineVars = defineVars;
259
264
  exports.firstThatWorks = firstThatWorks;
260
265
  exports.keyframes = keyframes;
@@ -27,6 +27,9 @@ import type {
27
27
  VarGroup,
28
28
  PositionTry,
29
29
  ViewTransitionClass,
30
+ StyleX$When,
31
+ MapNamespace,
32
+ StyleX$DefineMarker,
30
33
  } from './types/StyleXTypes';
31
34
  import type { ValueWithDefault } from './types/StyleXUtils';
32
35
  import * as Types from './types/VarTypes';
@@ -57,6 +60,8 @@ declare export const defineConsts: StyleX$DefineConsts;
57
60
 
58
61
  declare export const defineVars: StyleX$DefineVars;
59
62
 
63
+ declare export const defineMarker: StyleX$DefineMarker;
64
+
60
65
  declare export const firstThatWorks: <T: string | number>(
61
66
  ..._styles: $ReadOnlyArray<T>
62
67
  ) => $ReadOnlyArray<T>;
@@ -82,15 +87,13 @@ declare export const viewTransitionClass: (
82
87
  _viewTransitionClass: ViewTransitionClass,
83
88
  ) => string;
84
89
 
85
- declare export const defaultMarker: () => StaticStyles<>;
90
+ declare export const defaultMarker: () => MapNamespace<
91
+ $ReadOnly<{
92
+ marker: 'default-marker',
93
+ }>,
94
+ >;
86
95
 
87
- declare export const when: {
88
- ancestor: (_pseudo?: string) => string,
89
- descendant: (_pseudo?: string) => string,
90
- siblingBefore: (_pseudo?: string) => string,
91
- siblingAfter: (_pseudo?: string) => string,
92
- anySibling: (_pseudo?: string) => string,
93
- };
96
+ declare export const when: StyleX$When;
94
97
 
95
98
  declare export const types: {
96
99
  angle: <T: string | 0 = string | 0>(
@@ -132,7 +135,12 @@ type IStyleX = {
132
135
  createTheme: StyleX$CreateTheme,
133
136
  defineConsts: StyleX$DefineConsts,
134
137
  defineVars: StyleX$DefineVars,
135
- defaultMarker: () => StaticStyles<>,
138
+ defaultMarker: () => MapNamespace<
139
+ $ReadOnly<{
140
+ marker: 'default-marker',
141
+ }>,
142
+ >,
143
+ defineMarker: StyleX$DefineMarker,
136
144
  firstThatWorks: <T: string | number>(
137
145
  ...v: $ReadOnlyArray<T>
138
146
  ) => $ReadOnlyArray<T>,
@@ -153,7 +153,7 @@ type ComplexStyleValueType<T> =
153
153
  ? U extends CSSType<infer V>
154
154
  ? V
155
155
  : U
156
- : T extends string | number | null
156
+ : T extends string | number | null | symbol
157
157
  ? T
158
158
  : T extends ReadonlyArray<infer U>
159
159
  ? ComplexStyleValueType<U>
@@ -199,12 +199,13 @@ export type InlineStyles = {
199
199
 
200
200
  type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
201
201
  [Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
202
- }>;
202
+ }> &
203
+ Partial<{
204
+ [Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
205
+ }>;
206
+
203
207
  type GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<
204
- _GenStylePropType<CSS> &
205
- Partial<{
206
- [Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
207
- }>
208
+ _GenStylePropType<CSS>
208
209
  >;
209
210
 
210
211
  // Replace `XStyle` with this.
@@ -301,3 +302,47 @@ export type StyleX$CreateTheme = <
301
302
  baseTokens: TVars,
302
303
  overrides: OverridesForTokenType<TokensFromVarGroup<TVars>>,
303
304
  ) => Theme<TVars, ThemeID>;
305
+
306
+ export type StyleX$DefineMarker = () => MapNamespace<{
307
+ readonly marker: unique symbol;
308
+ }>;
309
+
310
+ export type StyleX$When = {
311
+ ancestor: <const Pseudo extends string, MarkerSymbol extends symbol = symbol>(
312
+ _pseudo?: Pseudo,
313
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
314
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
315
+ ) => `:where-ancestor(${Pseudo}, ${MarkerSymbol})`;
316
+ descendant: <
317
+ const Pseudo extends string,
318
+ MarkerSymbol extends symbol = symbol,
319
+ >(
320
+ _pseudo?: Pseudo,
321
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
322
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
323
+ ) => `:where-descendant(${Pseudo}, ${MarkerSymbol})`;
324
+ siblingBefore: <
325
+ const Pseudo extends string,
326
+ MarkerSymbol extends symbol = symbol,
327
+ >(
328
+ _pseudo?: Pseudo,
329
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
330
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
331
+ ) => `:where-sibling-before(${Pseudo}, ${MarkerSymbol})`;
332
+ siblingAfter: <
333
+ const Pseudo extends string,
334
+ MarkerSymbol extends symbol = symbol,
335
+ >(
336
+ _pseudo?: Pseudo,
337
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
338
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
339
+ ) => `:where-sibling-after(${Pseudo}, ${MarkerSymbol})`;
340
+ anySibling: <
341
+ const Pseudo extends string,
342
+ MarkerSymbol extends symbol = symbol,
343
+ >(
344
+ _pseudo?: Pseudo,
345
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
346
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
347
+ ) => `:where-any-sibling(${Pseudo}, ${MarkerSymbol})`;
348
+ };
@@ -143,7 +143,7 @@ export type MapNamespaces<+S: { +[string]: mixed }> = $ReadOnly<{
143
143
  ? (...args: Args) => $ReadOnly<[MapNamespace<Obj>, InlineStyles]>
144
144
  : MapNamespace<S[Key]>,
145
145
  }>;
146
- export type StyleX$Create = <S: { +[string]: { ... } }>(
146
+ export type StyleX$Create = <const S: { +[string]: { ... } }>(
147
147
  styles: S,
148
148
  ) => MapNamespaces<S>;
149
149
 
@@ -224,7 +224,7 @@ export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
224
224
  ) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
225
225
 
226
226
  export type StyleX$DefineConsts = <
227
- DefaultTokens: { +[string]: number | string },
227
+ const DefaultTokens: { +[string]: number | string },
228
228
  >(
229
229
  tokens: DefaultTokens,
230
230
  ) => DefaultTokens;
@@ -249,3 +249,30 @@ export type StyleX$CreateTheme = <
249
249
  baseTokens: BaseTokens,
250
250
  overrides: OverridesForTokenType<TokensFromVarGroup<BaseTokens>>,
251
251
  ) => Theme<BaseTokens, ID>;
252
+
253
+ export type StyleX$DefineMarker = () => MapNamespace<{
254
+ +marker: 'custom-marker',
255
+ }>;
256
+
257
+ export type StyleX$When = {
258
+ ancestor: (
259
+ _pseudo?: StringPrefix<':'>,
260
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
261
+ ) => ':where-ancestor',
262
+ descendant: (
263
+ _pseudo?: StringPrefix<':'>,
264
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
265
+ ) => ':where-descendant',
266
+ siblingBefore: (
267
+ _pseudo?: StringPrefix<':'>,
268
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
269
+ ) => ':where-sibling-before',
270
+ siblingAfter: (
271
+ _pseudo?: StringPrefix<':'>,
272
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
273
+ ) => ':where-sibling-after',
274
+ anySibling: (
275
+ _pseudo?: StringPrefix<':'>,
276
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
277
+ ) => ':where-any-sibling',
278
+ };
@@ -46,7 +46,7 @@ export declare class Image<T extends InnerValue> implements ICSSType<T> {
46
46
  readonly value: ValueWithDefault<string>;
47
47
  readonly syntax: CSSSyntaxType;
48
48
  }
49
- export declare class Integer<T extends number> implements ICSSType<T> {
49
+ export declare class Integer<T extends InnerValue> implements ICSSType<T> {
50
50
  readonly value: ValueWithDefault<string>;
51
51
  readonly syntax: CSSSyntaxType;
52
52
  }
@@ -64,7 +64,7 @@ export declare class Percentage<T extends InnerValue> implements ICSSType<T> {
64
64
  readonly value: ValueWithDefault<string>;
65
65
  readonly syntax: CSSSyntaxType;
66
66
  }
67
- export declare class Num<T extends number> implements ICSSType<T> {
67
+ export declare class Num<T extends InnerValue> implements ICSSType<T> {
68
68
  readonly value: ValueWithDefault<string>;
69
69
  readonly syntax: CSSSyntaxType;
70
70
  }
@@ -49,7 +49,7 @@ declare export class Image<+T: InnerValue> implements ICSSType<T> {
49
49
  +value: ValueWithDefault<string>;
50
50
  +syntax: CSSSyntaxType;
51
51
  }
52
- declare export class Integer<+T: number> implements ICSSType<T> {
52
+ declare export class Integer<+T: InnerValue> implements ICSSType<T> {
53
53
  +value: ValueWithDefault<string>;
54
54
  +syntax: CSSSyntaxType;
55
55
  }
@@ -65,7 +65,7 @@ declare export class Percentage<+T: InnerValue> implements ICSSType<T> {
65
65
  +value: ValueWithDefault<string>;
66
66
  +syntax: CSSSyntaxType;
67
67
  }
68
- declare export class Num<+T: number> implements ICSSType<T> {
68
+ declare export class Num<+T: InnerValue> implements ICSSType<T> {
69
69
  +value: ValueWithDefault<string>;
70
70
  +syntax: CSSSyntaxType;
71
71
  }
@@ -7,5 +7,10 @@
7
7
  *
8
8
  */
9
9
 
10
- declare function inject(cssText: string, priority: number): string;
10
+ declare function inject(
11
+ cssText: string,
12
+ priority: number,
13
+ constKey?: string,
14
+ constVal?: string | number,
15
+ ): string;
11
16
  export default inject;
@@ -10,4 +10,6 @@
10
10
  declare export default function inject(
11
11
  cssText: string,
12
12
  priority: number,
13
+ constKey?: string,
14
+ constVal?: string | number,
13
15
  ): string;
package/lib/es/inject.mjs CHANGED
@@ -7,8 +7,11 @@ function addSpecificityLevel(cssText, index) {
7
7
  length: index
8
8
  }).map(() => ':not(#\\#)').join('');
9
9
  const lastOpenCurly = cssText.includes('::') ? cssText.indexOf('::') : cssText.lastIndexOf('{');
10
- const beforeCurly = cssText.slice(0, lastOpenCurly);
10
+ let beforeCurly = cssText.slice(0, lastOpenCurly);
11
11
  const afterCurly = cssText.slice(lastOpenCurly);
12
+ if (index > 0) {
13
+ beforeCurly = beforeCurly.trimEnd();
14
+ }
12
15
  return `${beforeCurly}${pseudoSelector}${afterCurly}`;
13
16
  }
14
17
 
@@ -80,6 +83,74 @@ function createOrderedCSSStyleSheet(sheet) {
80
83
  }
81
84
  return isInserted;
82
85
  }
86
+ function insert(cssText, groupValue) {
87
+ const group = Number(groupValue);
88
+ if (groups[group] == null) {
89
+ const markerRule = encodeGroupRule(group);
90
+ groups[group] = {
91
+ start: null,
92
+ rules: [markerRule]
93
+ };
94
+ if (sheet != null) {
95
+ sheetInsert(sheet, group, markerRule);
96
+ }
97
+ }
98
+ const key = getSeenRuleKey(cssText);
99
+ if (key != null && seenRules[key] == null) {
100
+ seenRules[key] = true;
101
+ let shouldUpdate = true;
102
+ if (sheet != null) {
103
+ const isInserted = sheetInsert(sheet, group, cssText);
104
+ if (!isInserted) {
105
+ shouldUpdate = false;
106
+ }
107
+ }
108
+ if (shouldUpdate) {
109
+ groups[group].rules.push(cssText);
110
+ }
111
+ }
112
+ }
113
+ function update(oldCssText, newCssText, groupValue) {
114
+ const group = Number(groupValue);
115
+ const oldKey = getSeenRuleKey(oldCssText);
116
+ const newKey = getSeenRuleKey(newCssText);
117
+ if (oldKey !== newKey || oldKey == null) {
118
+ insert(newCssText, groupValue);
119
+ return;
120
+ }
121
+ if (seenRules[oldKey]) {
122
+ if (groups[group] && groups[group].rules) {
123
+ const rules = groups[group].rules;
124
+ let foundIndex = -1;
125
+ for (let i = 0; i < rules.length; i++) {
126
+ if (getSeenRuleKey(rules[i]) === oldKey) {
127
+ foundIndex = i;
128
+ break;
129
+ }
130
+ }
131
+ if (foundIndex !== -1) {
132
+ rules[foundIndex] = newCssText;
133
+ }
134
+ }
135
+ if (sheet != null) {
136
+ const cssRules = sheet.cssRules;
137
+ for (let i = cssRules.length - 1; i >= 0; i--) {
138
+ const rule = cssRules[i];
139
+ const ruleCssText = rule.cssText;
140
+ const ruleKey = getSeenRuleKey(ruleCssText);
141
+ if (ruleKey === oldKey) {
142
+ try {
143
+ sheet.deleteRule(i);
144
+ sheetInsert(sheet, group, newCssText);
145
+ break;
146
+ } catch (e) {}
147
+ }
148
+ }
149
+ }
150
+ } else {
151
+ insert(newCssText, groupValue);
152
+ }
153
+ }
83
154
  const OrderedCSSStyleSheet = {
84
155
  getTextContent() {
85
156
  return getOrderedGroups(groups).map(group => {
@@ -92,33 +163,8 @@ function createOrderedCSSStyleSheet(sheet) {
92
163
  return rules.join('\n');
93
164
  }).join('\n');
94
165
  },
95
- insert(cssText, groupValue) {
96
- const group = Number(groupValue);
97
- if (groups[group] == null) {
98
- const markerRule = encodeGroupRule(group);
99
- groups[group] = {
100
- start: null,
101
- rules: [markerRule]
102
- };
103
- if (sheet != null) {
104
- sheetInsert(sheet, group, markerRule);
105
- }
106
- }
107
- const key = getSeenRuleKey(cssText);
108
- if (key != null && seenRules[key] == null) {
109
- seenRules[key] = true;
110
- let shouldUpdate = true;
111
- if (sheet != null) {
112
- const isInserted = sheetInsert(sheet, group, cssText);
113
- if (!isInserted) {
114
- shouldUpdate = false;
115
- }
116
- }
117
- if (shouldUpdate) {
118
- groups[group].rules.push(cssText);
119
- }
120
- }
121
- }
166
+ insert,
167
+ update
122
168
  };
123
169
  return OrderedCSSStyleSheet;
124
170
  }
@@ -194,14 +240,92 @@ function createSheet(root) {
194
240
  sheets.forEach(s => {
195
241
  s.insert(cssText, groupValue);
196
242
  });
243
+ },
244
+ update(oldCssText, newCssText, groupValue) {
245
+ sheets.forEach(s => {
246
+ s.update(oldCssText, newCssText, groupValue);
247
+ });
197
248
  }
198
249
  };
199
250
  }
200
251
 
201
252
  const sheet = createSheet();
202
- function inject(cssText, priority) {
203
- const text = addSpecificityLevel(cssText, Math.floor(priority / 1000));
253
+ const constants = {};
254
+ const dependencies = {};
255
+ function escapeRegex(str) {
256
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
257
+ }
258
+ function resolveConstants(cssText) {
259
+ let resolved = cssText;
260
+ const varPattern = /var\(--([a-z0-9]+)\)/gi;
261
+ varPattern.lastIndex = 0;
262
+ const replacements = [];
263
+ let match = varPattern.exec(cssText);
264
+ while (match != null) {
265
+ const constKey = match[1];
266
+ if (constKey != null && constants[constKey] !== undefined) {
267
+ const constVal = constants[constKey];
268
+ const constValStr = String(constVal);
269
+ replacements.push([`var(--${constKey})`, constValStr]);
270
+ }
271
+ match = varPattern.exec(cssText);
272
+ }
273
+ for (const [search, replace] of replacements) {
274
+ const regex = new RegExp(escapeRegex(search), 'g');
275
+ resolved = resolved.replace(regex, replace);
276
+ }
277
+ return resolved;
278
+ }
279
+ function trackDependencies(originalCssText, priority, resolvedCss) {
280
+ const varPattern = /var\(--([a-z0-9]+)\)/gi;
281
+ let match = varPattern.exec(originalCssText);
282
+ while (match != null) {
283
+ const constKey = match[1];
284
+ if (constKey != null && constants[constKey] !== undefined) {
285
+ if (!dependencies[constKey]) {
286
+ dependencies[constKey] = new Map();
287
+ }
288
+ dependencies[constKey].set(originalCssText, {
289
+ priority,
290
+ resolvedCss
291
+ });
292
+ }
293
+ match = varPattern.exec(originalCssText);
294
+ }
295
+ }
296
+ function updateDependentRules(constKey) {
297
+ const deps = dependencies[constKey];
298
+ if (!deps || deps.size === 0) {
299
+ return;
300
+ }
301
+ deps.forEach(({
302
+ priority,
303
+ resolvedCss: oldResolvedCss
304
+ }, cssText) => {
305
+ const newResolvedCss = resolveConstants(cssText);
306
+ const oldText = addSpecificityLevel(oldResolvedCss, Math.floor(priority / 1000));
307
+ const newText = addSpecificityLevel(newResolvedCss, Math.floor(priority / 1000));
308
+ deps.set(cssText, {
309
+ priority,
310
+ resolvedCss: newResolvedCss
311
+ });
312
+ sheet.update(oldText, newText, priority);
313
+ });
314
+ }
315
+ function inject(cssText, priority, constKey, constVal) {
316
+ if (constKey !== undefined && constVal !== undefined) {
317
+ const hadPreviousValue = constants[constKey] !== undefined;
318
+ const valueChanged = hadPreviousValue && constants[constKey] !== constVal;
319
+ constants[constKey] = constVal;
320
+ if (valueChanged) {
321
+ updateDependentRules(constKey);
322
+ }
323
+ return '';
324
+ }
325
+ const resolved = resolveConstants(cssText);
326
+ const text = addSpecificityLevel(resolved, Math.floor(priority / 1000));
204
327
  sheet.insert(text, priority);
328
+ trackDependencies(cssText, priority, resolved);
205
329
  return text;
206
330
  }
207
331
 
@@ -10,6 +10,7 @@
10
10
  export type OrderedCSSStyleSheet = Readonly<{
11
11
  getTextContent: () => string;
12
12
  insert: (cssText: string, groupValue: number) => void;
13
+ update: (oldCssText: string, newCssText: string, groupValue: number) => void;
13
14
  }>;
14
15
  /**
15
16
  * Order-based insertion of CSS.
@@ -10,6 +10,7 @@
10
10
  export type OrderedCSSStyleSheet = $ReadOnly<{
11
11
  getTextContent: () => string,
12
12
  insert: (cssText: string, groupValue: number) => void,
13
+ update: (oldCssText: string, newCssText: string, groupValue: number) => void,
13
14
  }>;
14
15
 
15
16
  /**
@@ -8,5 +8,5 @@
8
8
  */
9
9
 
10
10
  import type { OrderedCSSStyleSheet } from './createOrderedCSSStyleSheet';
11
- type Sheet = Readonly<Omit<OrderedCSSStyleSheet, keyof ({})> & {}>;
11
+ type Sheet = Readonly<Omit<OrderedCSSStyleSheet, keyof {}> & {}>;
12
12
  export declare function createSheet(root?: HTMLElement): Sheet;
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  export declare const canUseDOM: boolean;
11
+ export declare type canUseDOM = typeof canUseDOM;
11
12
  /**
12
13
  * Adds :not(#\#) to selectors to increase their specificity.
13
14
  * This is used to polyfill @layer
@@ -27,6 +27,9 @@ import type {
27
27
  VarGroup,
28
28
  PositionTry,
29
29
  ViewTransitionClass,
30
+ StyleX$When,
31
+ MapNamespace,
32
+ StyleX$DefineMarker,
30
33
  } from './types/StyleXTypes';
31
34
  import type { ValueWithDefault } from './types/StyleXUtils';
32
35
  import * as Types from './types/VarTypes';
@@ -48,14 +51,23 @@ export type {
48
51
  PositionTry,
49
52
  };
50
53
  export declare const create: StyleX$Create;
54
+ export declare type create = typeof create;
51
55
  export declare const createTheme: StyleX$CreateTheme;
56
+ export declare type createTheme = typeof createTheme;
52
57
  export declare const defineConsts: StyleX$DefineConsts;
58
+ export declare type defineConsts = typeof defineConsts;
53
59
  export declare const defineVars: StyleX$DefineVars;
60
+ export declare type defineVars = typeof defineVars;
61
+ export declare const defineMarker: StyleX$DefineMarker;
62
+ export declare type defineMarker = typeof defineMarker;
54
63
  export declare const firstThatWorks: <T extends string | number>(
55
64
  ..._styles: ReadonlyArray<T>
56
65
  ) => ReadonlyArray<T>;
66
+ export declare type firstThatWorks = typeof firstThatWorks;
57
67
  export declare const keyframes: (_keyframes: Keyframes) => string;
68
+ export declare type keyframes = typeof keyframes;
58
69
  export declare const positionTry: (_positionTry: PositionTry) => string;
70
+ export declare type positionTry = typeof positionTry;
59
71
  export declare function props(
60
72
  this: null | undefined | unknown,
61
73
  ...styles: ReadonlyArray<
@@ -73,14 +85,13 @@ export declare function props(
73
85
  export declare const viewTransitionClass: (
74
86
  _viewTransitionClass: ViewTransitionClass,
75
87
  ) => string;
76
- export declare const defaultMarker: () => StaticStyles;
77
- export declare const when: {
78
- ancestor: (_pseudo?: string) => string;
79
- descendant: (_pseudo?: string) => string;
80
- siblingBefore: (_pseudo?: string) => string;
81
- siblingAfter: (_pseudo?: string) => string;
82
- anySibling: (_pseudo?: string) => string;
83
- };
88
+ export declare type viewTransitionClass = typeof viewTransitionClass;
89
+ export declare const defaultMarker: () => MapNamespace<
90
+ Readonly<{ marker: 'default-marker' }>
91
+ >;
92
+ export declare type defaultMarker = typeof defaultMarker;
93
+ export declare const when: StyleX$When;
94
+ export declare type when = typeof when;
84
95
  export declare const types: {
85
96
  angle: <T extends string | 0 = string | 0>(
86
97
  _v: ValueWithDefault<T>,
@@ -114,6 +125,7 @@ export declare const types: {
114
125
  _v: ValueWithDefault<T>,
115
126
  ) => Types.TransformList<T>;
116
127
  };
128
+ export declare type types = typeof types;
117
129
  /**
118
130
  * DO NOT USE. Legacy export for Meta
119
131
  */
@@ -132,7 +144,8 @@ type IStyleX = {
132
144
  createTheme: StyleX$CreateTheme;
133
145
  defineConsts: StyleX$DefineConsts;
134
146
  defineVars: StyleX$DefineVars;
135
- defaultMarker: () => StaticStyles;
147
+ defaultMarker: () => MapNamespace<Readonly<{ marker: 'default-marker' }>>;
148
+ defineMarker: StyleX$DefineMarker;
136
149
  firstThatWorks: <T extends string | number>(
137
150
  ...v: ReadonlyArray<T>
138
151
  ) => ReadonlyArray<T>;
@@ -158,3 +171,4 @@ type IStyleX = {
158
171
  __customProperties?: { [$$Key$$: string]: unknown };
159
172
  };
160
173
  export declare const legacyMerge: IStyleX;
174
+ export declare type legacyMerge = typeof legacyMerge;
@@ -27,6 +27,9 @@ import type {
27
27
  VarGroup,
28
28
  PositionTry,
29
29
  ViewTransitionClass,
30
+ StyleX$When,
31
+ MapNamespace,
32
+ StyleX$DefineMarker,
30
33
  } from './types/StyleXTypes';
31
34
  import type { ValueWithDefault } from './types/StyleXUtils';
32
35
  import * as Types from './types/VarTypes';
@@ -57,6 +60,8 @@ declare export const defineConsts: StyleX$DefineConsts;
57
60
 
58
61
  declare export const defineVars: StyleX$DefineVars;
59
62
 
63
+ declare export const defineMarker: StyleX$DefineMarker;
64
+
60
65
  declare export const firstThatWorks: <T: string | number>(
61
66
  ..._styles: $ReadOnlyArray<T>
62
67
  ) => $ReadOnlyArray<T>;
@@ -82,15 +87,13 @@ declare export const viewTransitionClass: (
82
87
  _viewTransitionClass: ViewTransitionClass,
83
88
  ) => string;
84
89
 
85
- declare export const defaultMarker: () => StaticStyles<>;
90
+ declare export const defaultMarker: () => MapNamespace<
91
+ $ReadOnly<{
92
+ marker: 'default-marker',
93
+ }>,
94
+ >;
86
95
 
87
- declare export const when: {
88
- ancestor: (_pseudo?: string) => string,
89
- descendant: (_pseudo?: string) => string,
90
- siblingBefore: (_pseudo?: string) => string,
91
- siblingAfter: (_pseudo?: string) => string,
92
- anySibling: (_pseudo?: string) => string,
93
- };
96
+ declare export const when: StyleX$When;
94
97
 
95
98
  declare export const types: {
96
99
  angle: <T: string | 0 = string | 0>(
@@ -132,7 +135,12 @@ type IStyleX = {
132
135
  createTheme: StyleX$CreateTheme,
133
136
  defineConsts: StyleX$DefineConsts,
134
137
  defineVars: StyleX$DefineVars,
135
- defaultMarker: () => StaticStyles<>,
138
+ defaultMarker: () => MapNamespace<
139
+ $ReadOnly<{
140
+ marker: 'default-marker',
141
+ }>,
142
+ >,
143
+ defineMarker: StyleX$DefineMarker,
136
144
  firstThatWorks: <T: string | number>(
137
145
  ...v: $ReadOnlyArray<T>
138
146
  ) => $ReadOnlyArray<T>,
package/lib/es/stylex.mjs CHANGED
@@ -144,6 +144,9 @@ const defineConsts = function stylexDefineConsts(_styles) {
144
144
  const defineVars = function stylexDefineVars(_styles) {
145
145
  throw errorForFn('defineVars');
146
146
  };
147
+ const defineMarker = () => {
148
+ throw errorForFn('defineMarker');
149
+ };
147
150
  const firstThatWorks = (..._styles) => {
148
151
  throw errorForFn('firstThatWorks');
149
152
  };
@@ -174,19 +177,19 @@ const defaultMarker = () => {
174
177
  throw errorForFn('defaultMarker');
175
178
  };
176
179
  const when = {
177
- ancestor: _pseudo => {
180
+ ancestor: _p => {
178
181
  throw errorForFn('when.ancestor');
179
182
  },
180
- descendant: _pseudo => {
183
+ descendant: _p => {
181
184
  throw errorForFn('when.descendant');
182
185
  },
183
- siblingBefore: _pseudo => {
186
+ siblingBefore: _p => {
184
187
  throw errorForFn('when.siblingBefore');
185
188
  },
186
- siblingAfter: _pseudo => {
189
+ siblingAfter: _p => {
187
190
  throw errorForFn('when.siblingAfter');
188
191
  },
189
- anySibling: _pseudo => {
192
+ anySibling: _p => {
190
193
  throw errorForFn('when.anySibling');
191
194
  }
192
195
  };
@@ -238,6 +241,7 @@ function _legacyMerge(...styles) {
238
241
  _legacyMerge.create = create;
239
242
  _legacyMerge.createTheme = createTheme;
240
243
  _legacyMerge.defineConsts = defineConsts;
244
+ _legacyMerge.defineMarker = defineMarker;
241
245
  _legacyMerge.defineVars = defineVars;
242
246
  _legacyMerge.defaultMarker = defaultMarker;
243
247
  _legacyMerge.firstThatWorks = firstThatWorks;
@@ -249,4 +253,4 @@ _legacyMerge.when = when;
249
253
  _legacyMerge.viewTransitionClass = viewTransitionClass;
250
254
  const legacyMerge = _legacyMerge;
251
255
 
252
- export { create, createTheme, defaultMarker, defineConsts, defineVars, firstThatWorks, keyframes, legacyMerge, positionTry, props, types, viewTransitionClass, when };
256
+ export { create, createTheme, defaultMarker, defineConsts, defineMarker, defineVars, firstThatWorks, keyframes, legacyMerge, positionTry, props, types, viewTransitionClass, when };
@@ -153,7 +153,7 @@ type ComplexStyleValueType<T> =
153
153
  ? U extends CSSType<infer V>
154
154
  ? V
155
155
  : U
156
- : T extends string | number | null
156
+ : T extends string | number | null | symbol
157
157
  ? T
158
158
  : T extends ReadonlyArray<infer U>
159
159
  ? ComplexStyleValueType<U>
@@ -199,12 +199,13 @@ export type InlineStyles = {
199
199
 
200
200
  type _GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<{
201
201
  [Key in keyof CSS]: StyleXClassNameFor<Key, Readonly<CSS[Key]>>;
202
- }>;
202
+ }> &
203
+ Partial<{
204
+ [Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
205
+ }>;
206
+
203
207
  type GenStylePropType<CSS extends UserAuthoredStyles> = Readonly<
204
- _GenStylePropType<CSS> &
205
- Partial<{
206
- [Key in Exclude<keyof CSSPropertiesWithExtras, keyof CSS>]: never;
207
- }>
208
+ _GenStylePropType<CSS>
208
209
  >;
209
210
 
210
211
  // Replace `XStyle` with this.
@@ -301,3 +302,47 @@ export type StyleX$CreateTheme = <
301
302
  baseTokens: TVars,
302
303
  overrides: OverridesForTokenType<TokensFromVarGroup<TVars>>,
303
304
  ) => Theme<TVars, ThemeID>;
305
+
306
+ export type StyleX$DefineMarker = () => MapNamespace<{
307
+ readonly marker: unique symbol;
308
+ }>;
309
+
310
+ export type StyleX$When = {
311
+ ancestor: <const Pseudo extends string, MarkerSymbol extends symbol = symbol>(
312
+ _pseudo?: Pseudo,
313
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
314
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
315
+ ) => `:where-ancestor(${Pseudo}, ${MarkerSymbol})`;
316
+ descendant: <
317
+ const Pseudo extends string,
318
+ MarkerSymbol extends symbol = symbol,
319
+ >(
320
+ _pseudo?: Pseudo,
321
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
322
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
323
+ ) => `:where-descendant(${Pseudo}, ${MarkerSymbol})`;
324
+ siblingBefore: <
325
+ const Pseudo extends string,
326
+ MarkerSymbol extends symbol = symbol,
327
+ >(
328
+ _pseudo?: Pseudo,
329
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
330
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
331
+ ) => `:where-sibling-before(${Pseudo}, ${MarkerSymbol})`;
332
+ siblingAfter: <
333
+ const Pseudo extends string,
334
+ MarkerSymbol extends symbol = symbol,
335
+ >(
336
+ _pseudo?: Pseudo,
337
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
338
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
339
+ ) => `:where-sibling-after(${Pseudo}, ${MarkerSymbol})`;
340
+ anySibling: <
341
+ const Pseudo extends string,
342
+ MarkerSymbol extends symbol = symbol,
343
+ >(
344
+ _pseudo?: Pseudo,
345
+ _customMarker?: MapNamespace<{ readonly marker: MarkerSymbol }>,
346
+ // @ts-expect-error - Trying to use a symbol in a string is not normally allowed
347
+ ) => `:where-any-sibling(${Pseudo}, ${MarkerSymbol})`;
348
+ };
@@ -143,7 +143,7 @@ export type MapNamespaces<+S: { +[string]: mixed }> = $ReadOnly<{
143
143
  ? (...args: Args) => $ReadOnly<[MapNamespace<Obj>, InlineStyles]>
144
144
  : MapNamespace<S[Key]>,
145
145
  }>;
146
- export type StyleX$Create = <S: { +[string]: { ... } }>(
146
+ export type StyleX$Create = <const S: { +[string]: { ... } }>(
147
147
  styles: S,
148
148
  ) => MapNamespaces<S>;
149
149
 
@@ -224,7 +224,7 @@ export type StyleX$DefineVars = <DefaultTokens: TTokens, ID: string = string>(
224
224
  ) => VarGroup<FlattenTokens<DefaultTokens>, ID>;
225
225
 
226
226
  export type StyleX$DefineConsts = <
227
- DefaultTokens: { +[string]: number | string },
227
+ const DefaultTokens: { +[string]: number | string },
228
228
  >(
229
229
  tokens: DefaultTokens,
230
230
  ) => DefaultTokens;
@@ -249,3 +249,30 @@ export type StyleX$CreateTheme = <
249
249
  baseTokens: BaseTokens,
250
250
  overrides: OverridesForTokenType<TokensFromVarGroup<BaseTokens>>,
251
251
  ) => Theme<BaseTokens, ID>;
252
+
253
+ export type StyleX$DefineMarker = () => MapNamespace<{
254
+ +marker: 'custom-marker',
255
+ }>;
256
+
257
+ export type StyleX$When = {
258
+ ancestor: (
259
+ _pseudo?: StringPrefix<':'>,
260
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
261
+ ) => ':where-ancestor',
262
+ descendant: (
263
+ _pseudo?: StringPrefix<':'>,
264
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
265
+ ) => ':where-descendant',
266
+ siblingBefore: (
267
+ _pseudo?: StringPrefix<':'>,
268
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
269
+ ) => ':where-sibling-before',
270
+ siblingAfter: (
271
+ _pseudo?: StringPrefix<':'>,
272
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
273
+ ) => ':where-sibling-after',
274
+ anySibling: (
275
+ _pseudo?: StringPrefix<':'>,
276
+ _customMarker?: MapNamespace<{ +marker: 'custom-marker' }>,
277
+ ) => ':where-any-sibling',
278
+ };
@@ -46,7 +46,7 @@ export declare class Image<T extends InnerValue> implements ICSSType<T> {
46
46
  readonly value: ValueWithDefault<string>;
47
47
  readonly syntax: CSSSyntaxType;
48
48
  }
49
- export declare class Integer<T extends number> implements ICSSType<T> {
49
+ export declare class Integer<T extends InnerValue> implements ICSSType<T> {
50
50
  readonly value: ValueWithDefault<string>;
51
51
  readonly syntax: CSSSyntaxType;
52
52
  }
@@ -64,7 +64,7 @@ export declare class Percentage<T extends InnerValue> implements ICSSType<T> {
64
64
  readonly value: ValueWithDefault<string>;
65
65
  readonly syntax: CSSSyntaxType;
66
66
  }
67
- export declare class Num<T extends number> implements ICSSType<T> {
67
+ export declare class Num<T extends InnerValue> implements ICSSType<T> {
68
68
  readonly value: ValueWithDefault<string>;
69
69
  readonly syntax: CSSSyntaxType;
70
70
  }
@@ -49,7 +49,7 @@ declare export class Image<+T: InnerValue> implements ICSSType<T> {
49
49
  +value: ValueWithDefault<string>;
50
50
  +syntax: CSSSyntaxType;
51
51
  }
52
- declare export class Integer<+T: number> implements ICSSType<T> {
52
+ declare export class Integer<+T: InnerValue> implements ICSSType<T> {
53
53
  +value: ValueWithDefault<string>;
54
54
  +syntax: CSSSyntaxType;
55
55
  }
@@ -65,7 +65,7 @@ declare export class Percentage<+T: InnerValue> implements ICSSType<T> {
65
65
  +value: ValueWithDefault<string>;
66
66
  +syntax: CSSSyntaxType;
67
67
  }
68
- declare export class Num<+T: number> implements ICSSType<T> {
68
+ declare export class Num<+T: InnerValue> implements ICSSType<T> {
69
69
  +value: ValueWithDefault<string>;
70
70
  +syntax: CSSSyntaxType;
71
71
  }
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@stylexjs/stylex",
3
- "version": "0.16.3",
3
+ "version": "0.17.1",
4
4
  "description": "A library for defining styles for optimized user interfaces.",
5
5
  "main": "./lib/cjs/stylex.js",
6
6
  "module": "./lib/es/stylex.mjs",
7
7
  "types": "./lib/cjs/stylex.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./lib/es/stylex.d.ts",
10
11
  "import": "./lib/es/stylex.mjs",
11
- "require": "./lib/cjs/stylex.js",
12
- "types": "./lib/es/stylex.d.ts"
12
+ "require": "./lib/cjs/stylex.js"
13
13
  },
14
14
  "./lib/stylex-inject": {
15
+ "types": "./lib/es/inject.d.ts",
15
16
  "import": "./lib/es/inject.mjs",
16
- "require": "./lib/cjs/inject.js",
17
- "types": "./lib/es/inject.d.ts"
17
+ "require": "./lib/cjs/inject.js"
18
18
  },
19
19
  "./lib/types/StyleXTypes": {
20
+ "types": "./lib/es/types/StyleXTypes.d.ts",
20
21
  "import": "./lib/es/types/StyleXTypes.mjs",
21
- "require": "./lib/cjs/types/StyleXTypes.js",
22
- "types": "./lib/es/types/StyleXTypes.d.ts"
22
+ "require": "./lib/cjs/types/StyleXTypes.js"
23
23
  },
24
24
  "./package.json": "./package.json"
25
25
  },
@@ -57,11 +57,11 @@
57
57
  "@rollup/plugin-json": "^6.1.0",
58
58
  "@rollup/plugin-node-resolve": "^15.3.0",
59
59
  "@rollup/plugin-replace": "^6.0.1",
60
- "babel-plugin-syntax-hermes-parser": "^0.26.0",
61
- "cross-env": "^7.0.3",
62
- "rimraf": "^5.0.10",
60
+ "babel-plugin-syntax-hermes-parser": "^0.32.1",
61
+ "cross-env": "^10.1.0",
62
+ "rimraf": "^6.1.2",
63
63
  "rollup": "^4.24.0",
64
- "scripts": "0.16.3"
64
+ "scripts": "0.17.1"
65
65
  },
66
66
  "files": [
67
67
  "lib/*"