@unocss/preset-typography 0.65.1 → 0.65.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/dist/index.d.mts CHANGED
@@ -20,13 +20,13 @@ interface TypographyOptions {
20
20
  *
21
21
  * Note: `not` utility is only available in class mode.
22
22
  *
23
- * @defaultValue `prose`
23
+ * @default `prose`
24
24
  */
25
25
  selectorName?: string;
26
26
  /**
27
27
  * Extend or override CSS selectors with CSS declaration block.
28
28
  *
29
- * @defaultValue undefined
29
+ * @default undefined
30
30
  */
31
31
  cssExtend?: Record<string, CSSObject> | ((theme: Theme) => Record<string, CSSObject>);
32
32
  /**
@@ -34,13 +34,19 @@ interface TypographyOptions {
34
34
  * For more instructions, see
35
35
  * [README](https://github.com/unocss/unocss/tree/main/packages/preset-typography)
36
36
  *
37
- * @defaultValue undefined
37
+ * @default undefined
38
38
  */
39
39
  compatibility?: TypographyCompatibilityOptions;
40
40
  /**
41
41
  * @deprecated use `selectorName` instead. It will be removed in 1.0.
42
42
  */
43
43
  className?: string;
44
+ /**
45
+ * Control whether prose's utilities should be marked with !important.
46
+ *
47
+ * @default false
48
+ */
49
+ important?: boolean | string;
44
50
  }
45
51
  /**
46
52
  * UnoCSS Preset for Typography
package/dist/index.d.ts CHANGED
@@ -20,13 +20,13 @@ interface TypographyOptions {
20
20
  *
21
21
  * Note: `not` utility is only available in class mode.
22
22
  *
23
- * @defaultValue `prose`
23
+ * @default `prose`
24
24
  */
25
25
  selectorName?: string;
26
26
  /**
27
27
  * Extend or override CSS selectors with CSS declaration block.
28
28
  *
29
- * @defaultValue undefined
29
+ * @default undefined
30
30
  */
31
31
  cssExtend?: Record<string, CSSObject> | ((theme: Theme) => Record<string, CSSObject>);
32
32
  /**
@@ -34,13 +34,19 @@ interface TypographyOptions {
34
34
  * For more instructions, see
35
35
  * [README](https://github.com/unocss/unocss/tree/main/packages/preset-typography)
36
36
  *
37
- * @defaultValue undefined
37
+ * @default undefined
38
38
  */
39
39
  compatibility?: TypographyCompatibilityOptions;
40
40
  /**
41
41
  * @deprecated use `selectorName` instead. It will be removed in 1.0.
42
42
  */
43
43
  className?: string;
44
+ /**
45
+ * Control whether prose's utilities should be marked with !important.
46
+ *
47
+ * @default false
48
+ */
49
+ important?: boolean | string;
44
50
  }
45
51
  /**
46
52
  * UnoCSS Preset for Typography
package/dist/index.mjs CHANGED
@@ -161,10 +161,46 @@ function DEFAULT(theme) {
161
161
  }
162
162
  };
163
163
  }
164
+ const modifiers = [
165
+ ["headings", "h1", "h2", "h3", "h4", "h5", "h6", "th"],
166
+ ["h1"],
167
+ ["h2"],
168
+ ["h3"],
169
+ ["h4"],
170
+ ["h5"],
171
+ ["h6"],
172
+ ["p"],
173
+ ["a"],
174
+ ["blockquote"],
175
+ ["figure"],
176
+ ["figcaption"],
177
+ ["strong"],
178
+ ["em"],
179
+ ["kbd"],
180
+ ["code"],
181
+ ["pre"],
182
+ ["ol"],
183
+ ["ul"],
184
+ ["li"],
185
+ ["table"],
186
+ ["thead"],
187
+ ["tr"],
188
+ ["th"],
189
+ ["td"],
190
+ ["img"],
191
+ ["video"],
192
+ ["hr"]
193
+ ];
194
+ function getElements(modifier) {
195
+ for (const [name, ...selectors] of modifiers) {
196
+ if (name === modifier)
197
+ return selectors.length > 0 ? selectors : [name];
198
+ }
199
+ }
164
200
 
165
201
  function getCSS(options) {
166
202
  let css = "";
167
- const { escapedSelector, selectorName, preflights, compatibility } = options;
203
+ const { escapedSelector, selectorName, preflights, compatibility, important } = options;
168
204
  const disableNotUtility = compatibility?.noColonNot || compatibility?.noColonWhere;
169
205
  for (const selector in preflights) {
170
206
  const cssDeclarationBlock = preflights[selector];
@@ -186,32 +222,35 @@ function getCSS(options) {
186
222
  css += "{";
187
223
  for (const k in cssDeclarationBlock) {
188
224
  const v = cssDeclarationBlock[k];
189
- css += `${k}:${v};`;
225
+ css += `${k}:${v}${important ? " !important" : ""};`;
190
226
  }
191
227
  css += "}";
192
228
  }
193
229
  return css;
194
230
  }
195
231
  function getPreflights(context, options) {
196
- const { escapedSelectors, selectorName, cssExtend, compatibility } = options;
197
- let escapedSelector = Array.from(escapedSelectors);
232
+ const { compatibility, selectorName, important = false } = options;
233
+ const cssExtend = typeof options?.cssExtend === "function" ? options.cssExtend(context.theme) : options?.cssExtend;
234
+ let escapedSelector = Array.from(options.escapedSelectors);
198
235
  if (!escapedSelector[escapedSelector.length - 1].startsWith(".") && !compatibility?.noColonIs)
199
- escapedSelector = [`:is(${escapedSelector[escapedSelector.length - 1]},.${selectorName})`];
236
+ escapedSelector = [`:is(${escapedSelector[escapedSelector.length - 1]},.${options.selectorName})`];
237
+ if (typeof important === "string") {
238
+ escapedSelector = escapedSelector.map((e) => !compatibility?.noColonIs ? `:is(${important}) ${e}` : `${important} ${e}`);
239
+ }
200
240
  if (cssExtend)
201
- return getCSS({ escapedSelector, selectorName, preflights: mergeDeep(DEFAULT(context.theme), cssExtend), compatibility });
202
- return getCSS({ escapedSelector, selectorName, preflights: DEFAULT(context.theme), compatibility });
241
+ return getCSS({ escapedSelector, selectorName, preflights: mergeDeep(DEFAULT(context.theme), cssExtend), compatibility, important: important === true });
242
+ return getCSS({ escapedSelector, selectorName, preflights: DEFAULT(context.theme), compatibility, important: important === true });
203
243
  }
204
244
 
205
245
  const presetTypography = definePreset((options) => {
206
- if (options?.className) {
207
- console.warn('[unocss:preset-typography] "className" is deprecated. Use "selectorName" instead.');
208
- }
246
+ if (options?.className)
247
+ console.warn('[unocss:preset-typography] "className" is deprecated. Please use "selectorName" instead.');
209
248
  const escapedSelectors = /* @__PURE__ */ new Set();
210
249
  const selectorName = options?.selectorName || options?.className || "prose";
211
250
  const selectorNameRE = new RegExp(`^${selectorName}$`);
212
251
  const colorsRE = new RegExp(`^${selectorName}-([-\\w]+)$`);
213
252
  const invertRE = new RegExp(`^${selectorName}-invert$`);
214
- const compatibility = options?.compatibility;
253
+ const disableNotUtility = options?.compatibility?.noColonNot || options?.compatibility?.noColonWhere;
215
254
  return {
216
255
  name: "@unocss/preset-typography",
217
256
  enforce: "post",
@@ -274,13 +313,36 @@ const presetTypography = definePreset((options) => {
274
313
  { layer: "typography" }
275
314
  ]
276
315
  ],
316
+ variants: [
317
+ {
318
+ name: "typography element modifiers",
319
+ match: (matcher) => {
320
+ if (matcher.startsWith(`${selectorName}-`)) {
321
+ const modifyRe = new RegExp(`^${selectorName}-(\\w+)[:-].+$`);
322
+ const modifier = matcher.match(modifyRe)?.[1];
323
+ if (modifier) {
324
+ const elements = getElements(modifier);
325
+ if (elements?.length) {
326
+ return {
327
+ matcher: matcher.slice(selectorName.length + modifier.length + 2),
328
+ selector: (s) => {
329
+ const notProseSelector = `:not(:where(.not-${selectorName},.not-${selectorName} *))`;
330
+ const escapedSelector = disableNotUtility ? elements.map((e) => `${s} ${e}`).join(",") : `${s} :is(:where(${elements})${notProseSelector})`;
331
+ return escapedSelector;
332
+ }
333
+ };
334
+ }
335
+ }
336
+ }
337
+ }
338
+ }
339
+ ],
277
340
  preflights: [
278
341
  {
279
342
  layer: "typography",
280
343
  getCSS: (context) => {
281
344
  if (escapedSelectors.size > 0) {
282
- const cssExtend = typeof options?.cssExtend === "function" ? options.cssExtend(context.theme) : options?.cssExtend;
283
- return getPreflights(context, { escapedSelectors, selectorName, cssExtend, compatibility });
345
+ return getPreflights(context, { escapedSelectors, ...options, selectorName });
284
346
  }
285
347
  }
286
348
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/preset-typography",
3
3
  "type": "module",
4
- "version": "0.65.1",
4
+ "version": "0.65.3",
5
5
  "description": "Typography preset for UnoCSS",
6
6
  "author": "Jeff Yang",
7
7
  "license": "MIT",
@@ -32,11 +32,12 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@unocss/core": "0.65.1",
36
- "@unocss/preset-mini": "0.65.1"
35
+ "@unocss/core": "0.65.3",
36
+ "@unocss/preset-mini": "0.65.3"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "unbuild",
40
- "stub": "unbuild --stub"
40
+ "stub": "unbuild --stub",
41
+ "test:attw": "attw --pack --config-path ../../.attw-esm-only.json"
41
42
  }
42
43
  }