@unocss/preset-typography 0.34.0 → 0.34.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/README.md CHANGED
@@ -134,8 +134,8 @@ export default defineConfig({
134
134
 
135
135
  ## Configurations
136
136
 
137
- This preset has `className` and `cssExtend` configurations for users who like to
138
- override or extend.
137
+ This preset has `selectorName` and `cssExtend` configurations for users who like
138
+ to override or extend.
139
139
 
140
140
  The CSS declarations passed to `cssExtend` will
141
141
 
@@ -150,13 +150,13 @@ export interface TypographyOptions {
150
150
  /**
151
151
  * The class name to use the typographic utilities.
152
152
  * To undo the styles to the elements, use it like
153
- * `not-${className}` which is by default `not-prose`.
153
+ * `not-${selectorName}` which is by default `not-prose`.
154
154
  *
155
155
  * Note: `not` utility is only available in class.
156
156
  *
157
157
  * @defaultValue `prose`
158
158
  */
159
- className?: string
159
+ selectorName?: string
160
160
 
161
161
  /**
162
162
  * Extend or override CSS selectors with CSS declaration block.
@@ -179,7 +179,7 @@ export default defineConfig({
179
179
  presetAttributify(), // required if using attributify mode
180
180
  presetUno(), // required
181
181
  presetTypography({
182
- className: 'markdown', // now use like `markdown markdown-gray`, `not-markdown`
182
+ selectorName: 'markdown', // now use like `markdown markdown-gray`, `not-markdown`
183
183
  // cssExtend is an object with CSS selector as key and
184
184
  // CSS declaration block as value like writing normal CSS.
185
185
  cssExtend: {
package/dist/index.cjs CHANGED
@@ -58,7 +58,7 @@ const DEFAULT = {
58
58
  "color": "var(--un-prose-code)",
59
59
  "font-size": ".875em",
60
60
  "font-weight": 600,
61
- "font-family": "ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation-Mono,Courier-New,monospace"
61
+ "font-family": "var(--un-prose-font-mono)"
62
62
  },
63
63
  ":not(pre) > code::before,:not(pre) > code::after": {
64
64
  content: '"`"'
@@ -161,7 +161,7 @@ const DEFAULT = {
161
161
  }
162
162
  };
163
163
 
164
- function getCSS(selectorProse, className, preflights) {
164
+ function getCSS(escapedSelector, selectorName, preflights) {
165
165
  let css = "";
166
166
  for (const selector in preflights) {
167
167
  const cssDeclarationBlock = preflights[selector];
@@ -170,14 +170,14 @@ function getCSS(selectorProse, className, preflights) {
170
170
  if (match) {
171
171
  const matchStr = match[0];
172
172
  s = s.replace(matchStr, "");
173
- return `${selectorProse} :where(${s}):not(.not-${className})${matchStr}`;
173
+ return `${escapedSelector} :where(${s}):not(.not-${selectorName})${matchStr}`;
174
174
  }
175
175
  return null;
176
176
  }).filter((v) => v);
177
177
  if (pseudoCSSMatchArray.length) {
178
178
  css += pseudoCSSMatchArray.join(",");
179
179
  } else {
180
- css += `${selectorProse} :where(${selector}):not(.not-${className})`;
180
+ css += `${escapedSelector} :where(${selector}):not(.not-${selectorName})`;
181
181
  }
182
182
  css += "{";
183
183
  for (const k in cssDeclarationBlock) {
@@ -188,21 +188,24 @@ function getCSS(selectorProse, className, preflights) {
188
188
  }
189
189
  return css;
190
190
  }
191
- function getPreflights(selectorProse, className, cssExtend) {
192
- if (!selectorProse.startsWith("."))
193
- selectorProse = `:is(${selectorProse},.${className})`;
191
+ function getPreflights(escapedSelector, selectorName, cssExtend) {
192
+ if (!escapedSelector.startsWith("."))
193
+ escapedSelector = `:is(${escapedSelector},.${selectorName})`;
194
194
  if (cssExtend)
195
- return getCSS(selectorProse, className, core.mergeDeep(DEFAULT, cssExtend));
196
- return getCSS(selectorProse, className, DEFAULT);
195
+ return getCSS(escapedSelector, selectorName, core.mergeDeep(DEFAULT, cssExtend));
196
+ return getCSS(escapedSelector, selectorName, DEFAULT);
197
197
  }
198
198
 
199
199
  function presetTypography(options) {
200
+ if (options?.className) {
201
+ console.warn('[unocss:preset-typography] "className" is deprecated. Use "selectorName" instead.');
202
+ }
200
203
  let hasProseClass = false;
201
- let selectorProse = "";
202
- const className = options?.className || "prose";
203
- const classNameRE = new RegExp(`^${className}$`);
204
- const colorsRE = new RegExp(`^${className}-([-\\w]+)$`);
205
- const invertRE = new RegExp(`^${className}-invert$`);
204
+ let escapedSelector = "";
205
+ const selectorName = options?.selectorName || options?.className || "prose";
206
+ const selectorNameRE = new RegExp(`^${selectorName}$`);
207
+ const colorsRE = new RegExp(`^${selectorName}-([-\\w]+)$`);
208
+ const invertRE = new RegExp(`^${selectorName}-invert$`);
206
209
  const cssExtend = options?.cssExtend;
207
210
  return {
208
211
  name: "@unocss/preset-typography",
@@ -210,10 +213,10 @@ function presetTypography(options) {
210
213
  layers: { typography: -1 },
211
214
  rules: [
212
215
  [
213
- classNameRE,
216
+ selectorNameRE,
214
217
  (_, { rawSelector }) => {
215
218
  hasProseClass = true;
216
- selectorProse = core.toEscapedSelector(rawSelector);
219
+ escapedSelector = core.toEscapedSelector(rawSelector);
217
220
  return { "color": "var(--un-prose-body)", "max-width": "65ch" };
218
221
  },
219
222
  { layer: "typography" }
@@ -243,7 +246,8 @@ function presetTypography(options) {
243
246
  "--un-prose-invert-captions": colorObject[400] ?? baseColor,
244
247
  "--un-prose-invert-code": colorObject[100] ?? baseColor,
245
248
  "--un-prose-invert-borders": colorObject[700] ?? baseColor,
246
- "--un-prose-invert-bg-soft": colorObject[800] ?? baseColor
249
+ "--un-prose-invert-bg-soft": colorObject[800] ?? baseColor,
250
+ "--un-prose-font-mono": theme.fontFamily?.mono
247
251
  };
248
252
  },
249
253
  { layer: "typography" }
@@ -269,7 +273,7 @@ function presetTypography(options) {
269
273
  preflights: [
270
274
  {
271
275
  layer: "typography",
272
- getCSS: () => hasProseClass ? getPreflights(selectorProse, className, cssExtend) : void 0
276
+ getCSS: () => hasProseClass ? getPreflights(escapedSelector, selectorName, cssExtend) : void 0
273
277
  }
274
278
  ]
275
279
  };
package/dist/index.d.ts CHANGED
@@ -5,21 +5,25 @@ import { CSSObject, Preset } from '@unocss/core';
5
5
  */
6
6
  interface TypographyOptions {
7
7
  /**
8
- * The class name to use the typographic utilities.
8
+ * The selector name to use the typographic utilities.
9
9
  * To undo the styles to the elements, use it like
10
- * `not-${className}` which is by default `not-prose`.
10
+ * `not-${selectorName}` which is by default `not-prose`.
11
11
  *
12
- * Note: `not` utility is only available in class.
12
+ * Note: `not` utility is only available in class mode.
13
13
  *
14
14
  * @defaultValue `prose`
15
15
  */
16
- className?: string;
16
+ selectorName?: string;
17
17
  /**
18
18
  * Extend or override CSS selectors with CSS declaration block.
19
19
  *
20
20
  * @defaultValue undefined
21
21
  */
22
22
  cssExtend?: Record<string, CSSObject>;
23
+ /**
24
+ * @deprecated use `selectorName` instead. It will be removed in 1.0.
25
+ */
26
+ className?: string;
23
27
  }
24
28
  /**
25
29
  * UnoCSS Preset for Typography
package/dist/index.mjs CHANGED
@@ -54,7 +54,7 @@ const DEFAULT = {
54
54
  "color": "var(--un-prose-code)",
55
55
  "font-size": ".875em",
56
56
  "font-weight": 600,
57
- "font-family": "ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation-Mono,Courier-New,monospace"
57
+ "font-family": "var(--un-prose-font-mono)"
58
58
  },
59
59
  ":not(pre) > code::before,:not(pre) > code::after": {
60
60
  content: '"`"'
@@ -157,7 +157,7 @@ const DEFAULT = {
157
157
  }
158
158
  };
159
159
 
160
- function getCSS(selectorProse, className, preflights) {
160
+ function getCSS(escapedSelector, selectorName, preflights) {
161
161
  let css = "";
162
162
  for (const selector in preflights) {
163
163
  const cssDeclarationBlock = preflights[selector];
@@ -166,14 +166,14 @@ function getCSS(selectorProse, className, preflights) {
166
166
  if (match) {
167
167
  const matchStr = match[0];
168
168
  s = s.replace(matchStr, "");
169
- return `${selectorProse} :where(${s}):not(.not-${className})${matchStr}`;
169
+ return `${escapedSelector} :where(${s}):not(.not-${selectorName})${matchStr}`;
170
170
  }
171
171
  return null;
172
172
  }).filter((v) => v);
173
173
  if (pseudoCSSMatchArray.length) {
174
174
  css += pseudoCSSMatchArray.join(",");
175
175
  } else {
176
- css += `${selectorProse} :where(${selector}):not(.not-${className})`;
176
+ css += `${escapedSelector} :where(${selector}):not(.not-${selectorName})`;
177
177
  }
178
178
  css += "{";
179
179
  for (const k in cssDeclarationBlock) {
@@ -184,21 +184,24 @@ function getCSS(selectorProse, className, preflights) {
184
184
  }
185
185
  return css;
186
186
  }
187
- function getPreflights(selectorProse, className, cssExtend) {
188
- if (!selectorProse.startsWith("."))
189
- selectorProse = `:is(${selectorProse},.${className})`;
187
+ function getPreflights(escapedSelector, selectorName, cssExtend) {
188
+ if (!escapedSelector.startsWith("."))
189
+ escapedSelector = `:is(${escapedSelector},.${selectorName})`;
190
190
  if (cssExtend)
191
- return getCSS(selectorProse, className, mergeDeep(DEFAULT, cssExtend));
192
- return getCSS(selectorProse, className, DEFAULT);
191
+ return getCSS(escapedSelector, selectorName, mergeDeep(DEFAULT, cssExtend));
192
+ return getCSS(escapedSelector, selectorName, DEFAULT);
193
193
  }
194
194
 
195
195
  function presetTypography(options) {
196
+ if (options?.className) {
197
+ console.warn('[unocss:preset-typography] "className" is deprecated. Use "selectorName" instead.');
198
+ }
196
199
  let hasProseClass = false;
197
- let selectorProse = "";
198
- const className = options?.className || "prose";
199
- const classNameRE = new RegExp(`^${className}$`);
200
- const colorsRE = new RegExp(`^${className}-([-\\w]+)$`);
201
- const invertRE = new RegExp(`^${className}-invert$`);
200
+ let escapedSelector = "";
201
+ const selectorName = options?.selectorName || options?.className || "prose";
202
+ const selectorNameRE = new RegExp(`^${selectorName}$`);
203
+ const colorsRE = new RegExp(`^${selectorName}-([-\\w]+)$`);
204
+ const invertRE = new RegExp(`^${selectorName}-invert$`);
202
205
  const cssExtend = options?.cssExtend;
203
206
  return {
204
207
  name: "@unocss/preset-typography",
@@ -206,10 +209,10 @@ function presetTypography(options) {
206
209
  layers: { typography: -1 },
207
210
  rules: [
208
211
  [
209
- classNameRE,
212
+ selectorNameRE,
210
213
  (_, { rawSelector }) => {
211
214
  hasProseClass = true;
212
- selectorProse = toEscapedSelector(rawSelector);
215
+ escapedSelector = toEscapedSelector(rawSelector);
213
216
  return { "color": "var(--un-prose-body)", "max-width": "65ch" };
214
217
  },
215
218
  { layer: "typography" }
@@ -239,7 +242,8 @@ function presetTypography(options) {
239
242
  "--un-prose-invert-captions": colorObject[400] ?? baseColor,
240
243
  "--un-prose-invert-code": colorObject[100] ?? baseColor,
241
244
  "--un-prose-invert-borders": colorObject[700] ?? baseColor,
242
- "--un-prose-invert-bg-soft": colorObject[800] ?? baseColor
245
+ "--un-prose-invert-bg-soft": colorObject[800] ?? baseColor,
246
+ "--un-prose-font-mono": theme.fontFamily?.mono
243
247
  };
244
248
  },
245
249
  { layer: "typography" }
@@ -265,7 +269,7 @@ function presetTypography(options) {
265
269
  preflights: [
266
270
  {
267
271
  layer: "typography",
268
- getCSS: () => hasProseClass ? getPreflights(selectorProse, className, cssExtend) : void 0
272
+ getCSS: () => hasProseClass ? getPreflights(escapedSelector, selectorName, cssExtend) : void 0
269
273
  }
270
274
  ]
271
275
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-typography",
3
- "version": "0.34.0",
3
+ "version": "0.34.1",
4
4
  "description": "Typography preset for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "sideEffects": false,
34
34
  "dependencies": {
35
- "@unocss/core": "0.34.0"
35
+ "@unocss/core": "0.34.1"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "unbuild",