esm-styles 0.2.2 → 0.2.3
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/README.md +20 -15
- package/dist/lib/utils/selector.js +17 -1
- package/doc/usage-guide.md +8 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,16 +185,18 @@ p strong {
|
|
|
185
185
|
|
|
186
186
|
```js
|
|
187
187
|
{
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
188
|
+
div: {
|
|
189
|
+
highlighted: {
|
|
190
|
+
// highlighted is not a tag
|
|
191
|
+
border: '1px solid red',
|
|
192
|
+
},
|
|
193
|
+
p: {
|
|
194
|
+
// p is a tag
|
|
195
|
+
fontSize: '16px',
|
|
196
|
+
},
|
|
197
|
+
_video: {
|
|
198
|
+
// video is a tag, but the class is meant, use single underscore prefix
|
|
199
|
+
aspectRatio: 1.77,
|
|
198
200
|
}
|
|
199
201
|
}
|
|
200
202
|
}
|
|
@@ -203,13 +205,16 @@ p strong {
|
|
|
203
205
|
Compiles to:
|
|
204
206
|
|
|
205
207
|
```css
|
|
206
|
-
.
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
div.highlighted {
|
|
209
|
+
border: 1px solid red;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
div p {
|
|
213
|
+
font-size: 16px;
|
|
209
214
|
}
|
|
210
215
|
|
|
211
|
-
|
|
212
|
-
|
|
216
|
+
div.video {
|
|
217
|
+
aspect-ratio: 1.77;
|
|
213
218
|
}
|
|
214
219
|
```
|
|
215
220
|
|
|
@@ -195,7 +195,16 @@ export const joinSelectorPath = (path) => {
|
|
|
195
195
|
return acc + (acc ? ' ' : '') + '.' + part.slice(2);
|
|
196
196
|
}
|
|
197
197
|
else if (part.startsWith('_')) {
|
|
198
|
-
|
|
198
|
+
// Attach class directly to previous part unless prev is combinator or root
|
|
199
|
+
const combinators = ['>', '+', '~'];
|
|
200
|
+
const isPrevCombinator = prev && combinators.some((c) => prev.startsWith(c));
|
|
201
|
+
if (isPrevRoot || isPrevCombinator || !acc) {
|
|
202
|
+
return acc + (acc ? ' ' : '') + '.' + part.slice(1);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// Attach directly (no space)
|
|
206
|
+
return acc + '.' + part.slice(1);
|
|
207
|
+
}
|
|
199
208
|
}
|
|
200
209
|
else if (part.startsWith('>') ||
|
|
201
210
|
part.startsWith('+') ||
|
|
@@ -224,6 +233,13 @@ export const joinSelectorPath = (path) => {
|
|
|
224
233
|
return acc + (acc ? ' ' : '') + match[1] + '.' + match[2];
|
|
225
234
|
}
|
|
226
235
|
}
|
|
236
|
+
else if (/^([a-z][a-z0-9]*)#([\w-]+)$/.test(part)) {
|
|
237
|
+
// If part matches 'tag#id' and tag is an HTML tag
|
|
238
|
+
const match = part.match(/^([a-z][a-z0-9]*)#([\w-]+)$/);
|
|
239
|
+
if (match && isHtmlTag(match[1])) {
|
|
240
|
+
return acc + (acc ? ' ' : '') + match[1] + '#' + match[2];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
227
243
|
// Not a tag, not a special selector: treat as class or custom element
|
|
228
244
|
// If previous part is a root selector, insert a space
|
|
229
245
|
if (isPrevRoot) {
|
package/doc/usage-guide.md
CHANGED
|
@@ -307,21 +307,9 @@ Use commas to target multiple selectors:
|
|
|
307
307
|
}
|
|
308
308
|
```
|
|
309
309
|
|
|
310
|
-
### T9: Content Property
|
|
311
|
-
|
|
312
|
-
For the `content` property, use JavaScript unicode notation for special characters:
|
|
313
|
-
|
|
314
|
-
```js
|
|
315
|
-
{
|
|
316
|
-
'::before': {
|
|
317
|
-
content: '\u2022', // Bullet character
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
```
|
|
321
|
-
|
|
322
310
|
## Layers
|
|
323
311
|
|
|
324
|
-
|
|
312
|
+
ESM Styles supports @layer directives:
|
|
325
313
|
|
|
326
314
|
```js
|
|
327
315
|
{
|
|
@@ -551,12 +539,14 @@ The build process automatically generates modules like `$theme.mjs`:
|
|
|
551
539
|
export default {
|
|
552
540
|
colors: {
|
|
553
541
|
background: {
|
|
554
|
-
var: '--colors-background',
|
|
542
|
+
var: 'var(--colors-background)',
|
|
543
|
+
name: '--colors-background',
|
|
555
544
|
light: '#ffffff',
|
|
556
545
|
dark: '#121212',
|
|
557
546
|
},
|
|
558
547
|
surface: {
|
|
559
|
-
var: '--colors-surface',
|
|
548
|
+
var: 'var(--colors-surface)',
|
|
549
|
+
name: '--colors-surface',
|
|
560
550
|
light: '#f5f5f5',
|
|
561
551
|
dark: '#222222',
|
|
562
552
|
},
|
|
@@ -575,10 +565,11 @@ import $theme from './$theme.mjs'
|
|
|
575
565
|
|
|
576
566
|
export default {
|
|
577
567
|
button: {
|
|
578
|
-
backgroundColor: $theme.colors.primary,
|
|
568
|
+
backgroundColor: $theme.colors.primary, // automatically replaced with var(--colors-primary) by compiler
|
|
579
569
|
color: $theme.colors.background,
|
|
580
570
|
padding: '10px 20px',
|
|
581
571
|
borderRadius: '4px',
|
|
572
|
+
border: `1px solid ${$theme.colors.surface.var}`, // in case of concatenation, use .var property, otherwise it will be [object Object], sorry
|
|
582
573
|
},
|
|
583
574
|
}
|
|
584
575
|
```
|
|
@@ -591,6 +582,7 @@ button {
|
|
|
591
582
|
color: var(--colors-background);
|
|
592
583
|
padding: 10px 20px;
|
|
593
584
|
border-radius: 4px;
|
|
585
|
+
border: 1px solid var(--colors-surface);
|
|
594
586
|
}
|
|
595
587
|
```
|
|
596
588
|
|