Skip to content

Commit 0a4f402

Browse files
authored
Use attribute selector for not-prose to avoid over-generating CSS (#208)
1 parent e2e0183 commit 0a4f402

File tree

2 files changed

+11424
-43935
lines changed

2 files changed

+11424
-43935
lines changed

src/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ const computed = {
1010
// bulletColor: (color) => ({ 'ul > li::before': { backgroundColor: color } }),
1111
}
1212

13-
function inWhere(selector, className) {
13+
function inWhere(selector, { className, prefix }) {
14+
let prefixedNot = prefix(`.not-${className}`).slice(1)
15+
1416
if (selector.endsWith('::before')) {
15-
return `:where(${selector.slice(0, -8)}):not(:where(.not-${className} *))::before`
17+
return `:where(${selector.slice(0, -8)}):not(:where([class~="${prefixedNot}"] *))::before`
1618
}
1719

1820
if (selector.endsWith('::after')) {
19-
return `:where(${selector.slice(0, -7)}):not(:where(.not-${className} *))::after`
21+
return `:where(${selector.slice(0, -7)}):not(:where([class~="${prefixedNot}"] *))::after`
2022
}
2123

22-
return `:where(${selector}):not(:where(.not-${className} *))`
24+
return `:where(${selector}):not(:where([class~="${prefixedNot}"] *))`
2325
}
2426

25-
function configToCss(config = {}, { target, className }) {
27+
function configToCss(config = {}, { target, className, prefix }) {
2628
return Object.fromEntries(
2729
Object.entries(
2830
merge(
@@ -38,7 +40,7 @@ function configToCss(config = {}, { target, className }) {
3840
}
3941

4042
if (typeof v == 'object' && v.constructor == Object) {
41-
return [inWhere(k, className), v]
43+
return [inWhere(k, { className, prefix }), v]
4244
}
4345

4446
return [k, v]
@@ -48,7 +50,7 @@ function configToCss(config = {}, { target, className }) {
4850

4951
module.exports = plugin.withOptions(
5052
({ modifiers, className = 'prose', target = 'modern' } = {}) => {
51-
return function ({ addComponents, theme, variants }) {
53+
return function ({ addComponents, theme, variants, prefix }) {
5254
const DEFAULT_MODIFIERS = [
5355
'DEFAULT',
5456
'sm',
@@ -74,7 +76,7 @@ module.exports = plugin.withOptions(
7476
all.map((modifier) => ({
7577
[modifier === 'DEFAULT' ? `.${className}` : `.${className}-${modifier}`]: configToCss(
7678
config[modifier],
77-
{ target, className },
79+
{ target, className, prefix }
7880
),
7981
})),
8082
variants('typography')

0 commit comments

Comments
 (0)