esm-styles 0.3.9 → 0.3.11
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/dist/lib/index.js +23 -69
- package/dist/lib/utils/selector.js +1 -1
- package/doc/usage-guide.md +1 -1
- package/package.json +1 -1
package/dist/lib/index.js
CHANGED
|
@@ -4,6 +4,19 @@ function flatWalk(obj, selectorPath = [], result = { rules: [], media: {}, layer
|
|
|
4
4
|
const props = {};
|
|
5
5
|
for (const key in obj) {
|
|
6
6
|
const value = obj[key];
|
|
7
|
+
if (key === '@layer' && typeof value === 'string') {
|
|
8
|
+
const directive = `@layer ${value};`;
|
|
9
|
+
if (currentMedia.length > 0) {
|
|
10
|
+
const mediaKey = currentMedia.join(' && ');
|
|
11
|
+
if (!result.media[mediaKey])
|
|
12
|
+
result.media[mediaKey] = [];
|
|
13
|
+
result.media[mediaKey].push(directive);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
result.rules.push(directive);
|
|
17
|
+
}
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
7
20
|
if (utils.isEndValue(value)) {
|
|
8
21
|
const cssKey = utils.jsKeyToCssKey(key);
|
|
9
22
|
if (cssKey === 'content') {
|
|
@@ -128,8 +141,13 @@ function flatWalk(obj, selectorPath = [], result = { rules: [], media: {}, layer
|
|
|
128
141
|
}
|
|
129
142
|
function renderRules(rules) {
|
|
130
143
|
let css = '';
|
|
144
|
+
const directives = rules.filter((r) => typeof r === 'string');
|
|
145
|
+
const normalRules = rules.filter((r) => typeof r !== 'string');
|
|
146
|
+
if (directives.length > 0) {
|
|
147
|
+
css += directives.join('\n') + '\n';
|
|
148
|
+
}
|
|
131
149
|
const groups = {};
|
|
132
|
-
for (const rule of
|
|
150
|
+
for (const rule of normalRules) {
|
|
133
151
|
const declKey = JSON.stringify(rule.declarations);
|
|
134
152
|
if (!groups[declKey])
|
|
135
153
|
groups[declKey] = [];
|
|
@@ -167,43 +185,11 @@ function renderFlatMedia(media) {
|
|
|
167
185
|
}
|
|
168
186
|
else if (key === '') {
|
|
169
187
|
// Render rules directly, no block
|
|
170
|
-
|
|
171
|
-
const groups = {};
|
|
172
|
-
for (const rule of media[key]) {
|
|
173
|
-
const declKey = JSON.stringify(rule.declarations);
|
|
174
|
-
if (!groups[declKey])
|
|
175
|
-
groups[declKey] = [];
|
|
176
|
-
groups[declKey].push(rule.selector);
|
|
177
|
-
}
|
|
178
|
-
for (const declKey in groups) {
|
|
179
|
-
const selectors = groups[declKey].join(', ');
|
|
180
|
-
const declarations = JSON.parse(declKey);
|
|
181
|
-
css += `${selectors} {\n`;
|
|
182
|
-
for (const k in declarations) {
|
|
183
|
-
css += ` ${k}: ${declarations[k]};\n`;
|
|
184
|
-
}
|
|
185
|
-
css += '}\n';
|
|
186
|
-
}
|
|
188
|
+
css += renderRules(media[key]);
|
|
187
189
|
}
|
|
188
190
|
else {
|
|
189
191
|
css += `${key} {\n`;
|
|
190
|
-
|
|
191
|
-
const groups = {};
|
|
192
|
-
for (const rule of media[key]) {
|
|
193
|
-
const declKey = JSON.stringify(rule.declarations);
|
|
194
|
-
if (!groups[declKey])
|
|
195
|
-
groups[declKey] = [];
|
|
196
|
-
groups[declKey].push(rule.selector);
|
|
197
|
-
}
|
|
198
|
-
for (const declKey in groups) {
|
|
199
|
-
const selectors = groups[declKey].join(', ');
|
|
200
|
-
const declarations = JSON.parse(declKey);
|
|
201
|
-
css += `${selectors} {\n`;
|
|
202
|
-
for (const k in declarations) {
|
|
203
|
-
css += ` ${k}: ${declarations[k]};\n`;
|
|
204
|
-
}
|
|
205
|
-
css += '}\n';
|
|
206
|
-
}
|
|
192
|
+
css += renderRules(media[key]);
|
|
207
193
|
css += '}\n';
|
|
208
194
|
}
|
|
209
195
|
}
|
|
@@ -219,43 +205,11 @@ function renderFlatContainers(containers) {
|
|
|
219
205
|
}
|
|
220
206
|
else if (key === '') {
|
|
221
207
|
// Render rules directly, no block
|
|
222
|
-
|
|
223
|
-
const groups = {};
|
|
224
|
-
for (const rule of containers[key]) {
|
|
225
|
-
const declKey = JSON.stringify(rule.declarations);
|
|
226
|
-
if (!groups[declKey])
|
|
227
|
-
groups[declKey] = [];
|
|
228
|
-
groups[declKey].push(rule.selector);
|
|
229
|
-
}
|
|
230
|
-
for (const declKey in groups) {
|
|
231
|
-
const selectors = groups[declKey].join(', ');
|
|
232
|
-
const declarations = JSON.parse(declKey);
|
|
233
|
-
css += `${selectors} {\n`;
|
|
234
|
-
for (const k in declarations) {
|
|
235
|
-
css += ` ${k}: ${declarations[k]};\n`;
|
|
236
|
-
}
|
|
237
|
-
css += '}\n';
|
|
238
|
-
}
|
|
208
|
+
css += renderRules(containers[key]);
|
|
239
209
|
}
|
|
240
210
|
else {
|
|
241
211
|
css += `${key} {\n`;
|
|
242
|
-
|
|
243
|
-
const groups = {};
|
|
244
|
-
for (const rule of containers[key]) {
|
|
245
|
-
const declKey = JSON.stringify(rule.declarations);
|
|
246
|
-
if (!groups[declKey])
|
|
247
|
-
groups[declKey] = [];
|
|
248
|
-
groups[declKey].push(rule.selector);
|
|
249
|
-
}
|
|
250
|
-
for (const declKey in groups) {
|
|
251
|
-
const selectors = groups[declKey].join(', ');
|
|
252
|
-
const declarations = JSON.parse(declKey);
|
|
253
|
-
css += `${selectors} {\n`;
|
|
254
|
-
for (const k in declarations) {
|
|
255
|
-
css += ` ${k}: ${declarations[k]};\n`;
|
|
256
|
-
}
|
|
257
|
-
css += '}\n';
|
|
258
|
-
}
|
|
212
|
+
css += renderRules(containers[key]);
|
|
259
213
|
css += '}\n';
|
|
260
214
|
}
|
|
261
215
|
}
|
|
@@ -247,7 +247,7 @@ export const joinSelectorPath = (path) => {
|
|
|
247
247
|
part.startsWith('+') ||
|
|
248
248
|
part.startsWith('~'):
|
|
249
249
|
// Combinators: always join with a space
|
|
250
|
-
return acc + ' ' + part;
|
|
250
|
+
return acc + ' ' + transformExplicitClasses(part);
|
|
251
251
|
case part.startsWith(':') ||
|
|
252
252
|
part.startsWith('::') ||
|
|
253
253
|
part.startsWith('#') ||
|
package/doc/usage-guide.md
CHANGED
|
@@ -321,7 +321,7 @@ Use commas to target multiple selectors:
|
|
|
321
321
|
|
|
322
322
|
### T9: Automatic Kebab-case Conversion
|
|
323
323
|
|
|
324
|
-
Class names in selectors are automatically converted from camelCase to kebab-case
|
|
324
|
+
Class names in selectors are automatically converted from camelCase and snake_case to kebab-case. The PascalCase class names (starting with an uppercase letter) are preserved as-is.
|
|
325
325
|
|
|
326
326
|
```js
|
|
327
327
|
{
|