@stylexjs/stylex 0.17.0 → 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.
- package/lib/cjs/inject.d.ts +6 -1
- package/lib/cjs/inject.js +154 -30
- package/lib/cjs/inject.js.flow +2 -0
- package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.d.ts +1 -0
- package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.js.flow +1 -0
- package/lib/cjs/stylesheet/createSheet.d.ts +1 -1
- package/lib/cjs/stylesheet/utils.d.ts +1 -0
- package/lib/cjs/stylex.d.ts +13 -0
- package/lib/es/inject.d.ts +6 -1
- package/lib/es/inject.js.flow +2 -0
- package/lib/es/inject.mjs +154 -30
- package/lib/es/stylesheet/createOrderedCSSStyleSheet.d.ts +1 -0
- package/lib/es/stylesheet/createOrderedCSSStyleSheet.js.flow +1 -0
- package/lib/es/stylesheet/createSheet.d.ts +1 -1
- package/lib/es/stylesheet/utils.d.ts +1 -0
- package/lib/es/stylex.d.ts +13 -0
- package/package.json +5 -5
package/lib/cjs/inject.d.ts
CHANGED
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
|
-
|
|
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
|
|
98
|
-
|
|
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
|
-
|
|
205
|
-
|
|
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
|
|
package/lib/cjs/inject.js.flow
CHANGED
|
@@ -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.
|
|
@@ -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;
|
package/lib/cjs/stylex.d.ts
CHANGED
|
@@ -51,15 +51,23 @@ export type {
|
|
|
51
51
|
PositionTry,
|
|
52
52
|
};
|
|
53
53
|
export declare const create: StyleX$Create;
|
|
54
|
+
export declare type create = typeof create;
|
|
54
55
|
export declare const createTheme: StyleX$CreateTheme;
|
|
56
|
+
export declare type createTheme = typeof createTheme;
|
|
55
57
|
export declare const defineConsts: StyleX$DefineConsts;
|
|
58
|
+
export declare type defineConsts = typeof defineConsts;
|
|
56
59
|
export declare const defineVars: StyleX$DefineVars;
|
|
60
|
+
export declare type defineVars = typeof defineVars;
|
|
57
61
|
export declare const defineMarker: StyleX$DefineMarker;
|
|
62
|
+
export declare type defineMarker = typeof defineMarker;
|
|
58
63
|
export declare const firstThatWorks: <T extends string | number>(
|
|
59
64
|
..._styles: ReadonlyArray<T>
|
|
60
65
|
) => ReadonlyArray<T>;
|
|
66
|
+
export declare type firstThatWorks = typeof firstThatWorks;
|
|
61
67
|
export declare const keyframes: (_keyframes: Keyframes) => string;
|
|
68
|
+
export declare type keyframes = typeof keyframes;
|
|
62
69
|
export declare const positionTry: (_positionTry: PositionTry) => string;
|
|
70
|
+
export declare type positionTry = typeof positionTry;
|
|
63
71
|
export declare function props(
|
|
64
72
|
this: null | undefined | unknown,
|
|
65
73
|
...styles: ReadonlyArray<
|
|
@@ -77,10 +85,13 @@ export declare function props(
|
|
|
77
85
|
export declare const viewTransitionClass: (
|
|
78
86
|
_viewTransitionClass: ViewTransitionClass,
|
|
79
87
|
) => string;
|
|
88
|
+
export declare type viewTransitionClass = typeof viewTransitionClass;
|
|
80
89
|
export declare const defaultMarker: () => MapNamespace<
|
|
81
90
|
Readonly<{ marker: 'default-marker' }>
|
|
82
91
|
>;
|
|
92
|
+
export declare type defaultMarker = typeof defaultMarker;
|
|
83
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
|
*/
|
|
@@ -159,3 +171,4 @@ type IStyleX = {
|
|
|
159
171
|
__customProperties?: { [$$Key$$: string]: unknown };
|
|
160
172
|
};
|
|
161
173
|
export declare const legacyMerge: IStyleX;
|
|
174
|
+
export declare type legacyMerge = typeof legacyMerge;
|
package/lib/es/inject.d.ts
CHANGED
package/lib/es/inject.js.flow
CHANGED
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
|
-
|
|
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
|
|
96
|
-
|
|
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
|
-
|
|
203
|
-
|
|
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.
|
|
@@ -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;
|
package/lib/es/stylex.d.ts
CHANGED
|
@@ -51,15 +51,23 @@ export type {
|
|
|
51
51
|
PositionTry,
|
|
52
52
|
};
|
|
53
53
|
export declare const create: StyleX$Create;
|
|
54
|
+
export declare type create = typeof create;
|
|
54
55
|
export declare const createTheme: StyleX$CreateTheme;
|
|
56
|
+
export declare type createTheme = typeof createTheme;
|
|
55
57
|
export declare const defineConsts: StyleX$DefineConsts;
|
|
58
|
+
export declare type defineConsts = typeof defineConsts;
|
|
56
59
|
export declare const defineVars: StyleX$DefineVars;
|
|
60
|
+
export declare type defineVars = typeof defineVars;
|
|
57
61
|
export declare const defineMarker: StyleX$DefineMarker;
|
|
62
|
+
export declare type defineMarker = typeof defineMarker;
|
|
58
63
|
export declare const firstThatWorks: <T extends string | number>(
|
|
59
64
|
..._styles: ReadonlyArray<T>
|
|
60
65
|
) => ReadonlyArray<T>;
|
|
66
|
+
export declare type firstThatWorks = typeof firstThatWorks;
|
|
61
67
|
export declare const keyframes: (_keyframes: Keyframes) => string;
|
|
68
|
+
export declare type keyframes = typeof keyframes;
|
|
62
69
|
export declare const positionTry: (_positionTry: PositionTry) => string;
|
|
70
|
+
export declare type positionTry = typeof positionTry;
|
|
63
71
|
export declare function props(
|
|
64
72
|
this: null | undefined | unknown,
|
|
65
73
|
...styles: ReadonlyArray<
|
|
@@ -77,10 +85,13 @@ export declare function props(
|
|
|
77
85
|
export declare const viewTransitionClass: (
|
|
78
86
|
_viewTransitionClass: ViewTransitionClass,
|
|
79
87
|
) => string;
|
|
88
|
+
export declare type viewTransitionClass = typeof viewTransitionClass;
|
|
80
89
|
export declare const defaultMarker: () => MapNamespace<
|
|
81
90
|
Readonly<{ marker: 'default-marker' }>
|
|
82
91
|
>;
|
|
92
|
+
export declare type defaultMarker = typeof defaultMarker;
|
|
83
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
|
*/
|
|
@@ -159,3 +171,4 @@ type IStyleX = {
|
|
|
159
171
|
__customProperties?: { [$$Key$$: string]: unknown };
|
|
160
172
|
};
|
|
161
173
|
export declare const legacyMerge: IStyleX;
|
|
174
|
+
export declare type legacyMerge = typeof legacyMerge;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/stylex",
|
|
3
|
-
"version": "0.17.
|
|
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",
|
|
@@ -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.
|
|
61
|
-
"cross-env": "^
|
|
62
|
-
"rimraf": "^
|
|
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.17.
|
|
64
|
+
"scripts": "0.17.1"
|
|
65
65
|
},
|
|
66
66
|
"files": [
|
|
67
67
|
"lib/*"
|