@unocss/preset-typography 0.65.1 → 0.65.2

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
@@ -164,7 +164,7 @@ function DEFAULT(theme) {
164
164
 
165
165
  function getCSS(options) {
166
166
  let css = "";
167
- const { escapedSelector, selectorName, preflights, compatibility } = options;
167
+ const { escapedSelector, selectorName, preflights, compatibility, important } = options;
168
168
  const disableNotUtility = compatibility?.noColonNot || compatibility?.noColonWhere;
169
169
  for (const selector in preflights) {
170
170
  const cssDeclarationBlock = preflights[selector];
@@ -186,32 +186,34 @@ function getCSS(options) {
186
186
  css += "{";
187
187
  for (const k in cssDeclarationBlock) {
188
188
  const v = cssDeclarationBlock[k];
189
- css += `${k}:${v};`;
189
+ css += `${k}:${v}${important ? " !important" : ""};`;
190
190
  }
191
191
  css += "}";
192
192
  }
193
193
  return css;
194
194
  }
195
195
  function getPreflights(context, options) {
196
- const { escapedSelectors, selectorName, cssExtend, compatibility } = options;
197
- let escapedSelector = Array.from(escapedSelectors);
196
+ const { compatibility, selectorName, important = false } = options;
197
+ const cssExtend = typeof options?.cssExtend === "function" ? options.cssExtend(context.theme) : options?.cssExtend;
198
+ let escapedSelector = Array.from(options.escapedSelectors);
198
199
  if (!escapedSelector[escapedSelector.length - 1].startsWith(".") && !compatibility?.noColonIs)
199
- escapedSelector = [`:is(${escapedSelector[escapedSelector.length - 1]},.${selectorName})`];
200
+ escapedSelector = [`:is(${escapedSelector[escapedSelector.length - 1]},.${options.selectorName})`];
201
+ if (typeof important === "string") {
202
+ escapedSelector = escapedSelector.map((e) => !compatibility?.noColonIs ? `:is(${important}) ${e}` : `${important} ${e}`);
203
+ }
200
204
  if (cssExtend)
201
- return getCSS({ escapedSelector, selectorName, preflights: mergeDeep(DEFAULT(context.theme), cssExtend), compatibility });
202
- return getCSS({ escapedSelector, selectorName, preflights: DEFAULT(context.theme), compatibility });
205
+ return getCSS({ escapedSelector, selectorName, preflights: mergeDeep(DEFAULT(context.theme), cssExtend), compatibility, important: important === true });
206
+ return getCSS({ escapedSelector, selectorName, preflights: DEFAULT(context.theme), compatibility, important: important === true });
203
207
  }
204
208
 
205
209
  const presetTypography = definePreset((options) => {
206
- if (options?.className) {
207
- console.warn('[unocss:preset-typography] "className" is deprecated. Use "selectorName" instead.');
208
- }
210
+ if (options?.className)
211
+ console.warn('[unocss:preset-typography] "className" is deprecated. Please use "selectorName" instead.');
209
212
  const escapedSelectors = /* @__PURE__ */ new Set();
210
213
  const selectorName = options?.selectorName || options?.className || "prose";
211
214
  const selectorNameRE = new RegExp(`^${selectorName}$`);
212
215
  const colorsRE = new RegExp(`^${selectorName}-([-\\w]+)$`);
213
216
  const invertRE = new RegExp(`^${selectorName}-invert$`);
214
- const compatibility = options?.compatibility;
215
217
  return {
216
218
  name: "@unocss/preset-typography",
217
219
  enforce: "post",
@@ -279,8 +281,7 @@ const presetTypography = definePreset((options) => {
279
281
  layer: "typography",
280
282
  getCSS: (context) => {
281
283
  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 });
284
+ return getPreflights(context, { escapedSelectors, ...options, selectorName });
284
285
  }
285
286
  }
286
287
  }
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.2",
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.2",
36
+ "@unocss/preset-mini": "0.65.2"
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
  }