@unocss/preset-attributify 0.31.17 → 0.32.7
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 +5 -5
- package/dist/index.cjs +26 -17
- package/dist/index.d.ts +10 -2
- package/dist/index.mjs +26 -17
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ Create `shims.d.ts` with the following content:
|
|
|
72
72
|
### React
|
|
73
73
|
|
|
74
74
|
```ts
|
|
75
|
-
import { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
75
|
+
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
76
76
|
|
|
77
77
|
declare module 'react' {
|
|
78
78
|
interface HTMLAttributes<T> extends AttributifyAttributes {}
|
|
@@ -82,7 +82,7 @@ declare module 'react' {
|
|
|
82
82
|
### Vue 3
|
|
83
83
|
|
|
84
84
|
```ts
|
|
85
|
-
import { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
85
|
+
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
86
86
|
|
|
87
87
|
declare module '@vue/runtime-dom' {
|
|
88
88
|
interface HTMLAttributes extends AttributifyAttributes {}
|
|
@@ -92,9 +92,9 @@ declare module '@vue/runtime-dom' {
|
|
|
92
92
|
### SolidJS
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
|
-
import { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
95
|
+
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
96
96
|
|
|
97
|
-
declare module
|
|
97
|
+
declare module 'solid-js' {
|
|
98
98
|
namespace JSX {
|
|
99
99
|
interface HTMLAttributes<T> extends AttributifyAttributes {}
|
|
100
100
|
}
|
|
@@ -104,7 +104,7 @@ declare module "solid-js" {
|
|
|
104
104
|
### Attributify with Prefix
|
|
105
105
|
|
|
106
106
|
```ts
|
|
107
|
-
import { AttributifyNames } from '@unocss/preset-attributify'
|
|
107
|
+
import type { AttributifyNames } from '@unocss/preset-attributify'
|
|
108
108
|
|
|
109
109
|
type Prefix = 'uno:' // change it to your prefix
|
|
110
110
|
|
package/dist/index.cjs
CHANGED
|
@@ -8,21 +8,25 @@ const variantsRE = /^(?!\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
|
|
|
8
8
|
const variantAttributify = (options = {}) => {
|
|
9
9
|
const prefix = options.prefix ?? "un-";
|
|
10
10
|
const prefixedOnly = options.prefixedOnly ?? false;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
const trueToNonValued = options.trueToNonValued ?? false;
|
|
12
|
+
return {
|
|
13
|
+
name: "attributify",
|
|
14
|
+
match(input) {
|
|
15
|
+
const match = core.isAttributifySelector(input);
|
|
16
|
+
if (!match)
|
|
17
|
+
return;
|
|
18
|
+
let name = match[1];
|
|
19
|
+
if (name.startsWith(prefix))
|
|
20
|
+
name = name.slice(prefix.length);
|
|
21
|
+
else if (prefixedOnly)
|
|
22
|
+
return;
|
|
23
|
+
const content = match[2];
|
|
24
|
+
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
25
|
+
if (body === "~" || trueToNonValued && body === "true" || !body)
|
|
26
|
+
return `${variants}${name}`;
|
|
27
|
+
else
|
|
28
|
+
return `${variants}${name}-${body}`;
|
|
29
|
+
}
|
|
26
30
|
};
|
|
27
31
|
};
|
|
28
32
|
|
|
@@ -118,6 +122,7 @@ const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-]+)(
|
|
|
118
122
|
const extractorAttributify = (options) => {
|
|
119
123
|
const ignoreAttributes = options?.ignoreAttributes ?? [];
|
|
120
124
|
const nonValuedAttribute = options?.nonValuedAttribute ?? true;
|
|
125
|
+
const trueToNonValued = options?.trueToNonValued ?? false;
|
|
121
126
|
return {
|
|
122
127
|
name: "attributify",
|
|
123
128
|
extract({ code }) {
|
|
@@ -131,8 +136,12 @@ const extractorAttributify = (options) => {
|
|
|
131
136
|
}
|
|
132
137
|
}
|
|
133
138
|
if (!content) {
|
|
134
|
-
if (core.isValidSelector(name) && nonValuedAttribute !== false)
|
|
135
|
-
|
|
139
|
+
if (core.isValidSelector(name) && nonValuedAttribute !== false) {
|
|
140
|
+
const result2 = [`[${name}=""]`];
|
|
141
|
+
if (trueToNonValued)
|
|
142
|
+
result2.push(`[${name}="true"]`);
|
|
143
|
+
return result2;
|
|
144
|
+
}
|
|
136
145
|
return [];
|
|
137
146
|
}
|
|
138
147
|
if (["class", "className"].includes(name)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PresetOptions, AutoCompleteExtractor, Extractor,
|
|
1
|
+
import { PresetOptions, AutoCompleteExtractor, Extractor, VariantObject, Preset } from '@unocss/core';
|
|
2
2
|
|
|
3
3
|
interface AttributifyOptions extends PresetOptions {
|
|
4
4
|
/**
|
|
@@ -32,6 +32,14 @@ interface AttributifyOptions extends PresetOptions {
|
|
|
32
32
|
* A list of attributes to be ignored from extracting.
|
|
33
33
|
*/
|
|
34
34
|
ignoreAttributes?: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Non-valued attributes will also match if the actual value represented in DOM is `true`.
|
|
37
|
+
* This option exists for supporting frameworks that encodes non-valued attributes as `true`.
|
|
38
|
+
* Enabling this option will break rules that ends with `true`.
|
|
39
|
+
*
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
trueToNonValued?: boolean;
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
declare const autocompleteExtractorAttributify: AutoCompleteExtractor;
|
|
@@ -39,7 +47,7 @@ declare const autocompleteExtractorAttributify: AutoCompleteExtractor;
|
|
|
39
47
|
declare const extractorAttributify: (options?: AttributifyOptions | undefined) => Extractor;
|
|
40
48
|
|
|
41
49
|
declare const variantsRE: RegExp;
|
|
42
|
-
declare const variantAttributify: (options?: AttributifyOptions) =>
|
|
50
|
+
declare const variantAttributify: (options?: AttributifyOptions) => VariantObject;
|
|
43
51
|
|
|
44
52
|
declare type UtilityNames = 'align' | 'animate' | 'backdrop' | 'bg' | 'blend' | 'border' | 'box' | 'container' | 'content' | 'cursor' | 'display' | 'divide' | 'filter' | 'flex' | 'font' | 'gap' | 'gradient' | 'grid' | 'h' | 'icon' | 'justify' | 'list' | 'm' | 'opacity' | 'order' | 'outline' | 'overflow' | 'p' | 'place' | 'pos' | 'ring' | 'select' | 'shadow' | 'space' | 'table' | 'text' | 'transform' | 'transition' | 'underline' | 'w' | 'z';
|
|
45
53
|
declare type VariantNames = 'active' | 'after' | 'all' | 'before' | 'child' | 'dark' | 'enabled' | 'first' | 'focus' | 'hover' | 'last' | 'lg' | 'light' | 'md' | 'root' | 'sm' | 'xl' | 'xxl';
|
package/dist/index.mjs
CHANGED
|
@@ -4,21 +4,25 @@ const variantsRE = /^(?!\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
|
|
|
4
4
|
const variantAttributify = (options = {}) => {
|
|
5
5
|
const prefix = options.prefix ?? "un-";
|
|
6
6
|
const prefixedOnly = options.prefixedOnly ?? false;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
const trueToNonValued = options.trueToNonValued ?? false;
|
|
8
|
+
return {
|
|
9
|
+
name: "attributify",
|
|
10
|
+
match(input) {
|
|
11
|
+
const match = isAttributifySelector(input);
|
|
12
|
+
if (!match)
|
|
13
|
+
return;
|
|
14
|
+
let name = match[1];
|
|
15
|
+
if (name.startsWith(prefix))
|
|
16
|
+
name = name.slice(prefix.length);
|
|
17
|
+
else if (prefixedOnly)
|
|
18
|
+
return;
|
|
19
|
+
const content = match[2];
|
|
20
|
+
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
21
|
+
if (body === "~" || trueToNonValued && body === "true" || !body)
|
|
22
|
+
return `${variants}${name}`;
|
|
23
|
+
else
|
|
24
|
+
return `${variants}${name}-${body}`;
|
|
25
|
+
}
|
|
22
26
|
};
|
|
23
27
|
};
|
|
24
28
|
|
|
@@ -114,6 +118,7 @@ const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-]+)(
|
|
|
114
118
|
const extractorAttributify = (options) => {
|
|
115
119
|
const ignoreAttributes = options?.ignoreAttributes ?? [];
|
|
116
120
|
const nonValuedAttribute = options?.nonValuedAttribute ?? true;
|
|
121
|
+
const trueToNonValued = options?.trueToNonValued ?? false;
|
|
117
122
|
return {
|
|
118
123
|
name: "attributify",
|
|
119
124
|
extract({ code }) {
|
|
@@ -127,8 +132,12 @@ const extractorAttributify = (options) => {
|
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
if (!content) {
|
|
130
|
-
if (isValidSelector(name) && nonValuedAttribute !== false)
|
|
131
|
-
|
|
135
|
+
if (isValidSelector(name) && nonValuedAttribute !== false) {
|
|
136
|
+
const result2 = [`[${name}=""]`];
|
|
137
|
+
if (trueToNonValued)
|
|
138
|
+
result2.push(`[${name}="true"]`);
|
|
139
|
+
return result2;
|
|
140
|
+
}
|
|
132
141
|
return [];
|
|
133
142
|
}
|
|
134
143
|
if (["class", "className"].includes(name)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-attributify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.7",
|
|
4
4
|
"description": "Attributify preset for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
],
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unocss/core": "0.
|
|
36
|
+
"@unocss/core": "0.32.7"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "unbuild",
|
|
40
40
|
"stub": "unbuild --stub"
|
|
41
41
|
},
|
|
42
|
-
"readme": "# @unocss/preset-attributify\n\nAttributify Mode for [UnoCSS](https://github.com/unocss/unocss).\n\n## Installation\n\n```bash\nnpm i -D @unocss/preset-attributify\n```\n\n```ts\nimport presetAttributify from '@unocss/preset-attributify'\n\nUnocss({\n presets: [\n presetAttributify({ /* options */ }),\n // ...other presets\n ],\n})\n```\n\n## Attributify Mode\n\nThis preset enabled [Windi CSS's Attributify Mode](https://windicss.org/posts/v30.html#attributify-mode) for **other presets**.\n\nImagine you have this button using Tailwind's utilities. When the list gets long, it becomes really hard to read and maintain.\n\n```html\n<button class=\"bg-blue-400 hover:bg-blue-500 text-sm text-white font-mono font-light py-2 px-4 rounded border-2 border-blue-200 dark:bg-blue-500 dark:hover:bg-blue-600\">\n Button\n</button>\n```\n\nWith attributify mode, you can separate utilities into attributes:\n\n```html\n<button \n bg=\"blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600\"\n text=\"sm white\"\n font=\"mono light\"\n p=\"y-2 x-4\"\n border=\"2 rounded blue-200\"\n>\n Button\n</button>\n```\n\nFor example, `text-sm text-white` could be grouped into `text=\"sm white\"` without duplicating the same prefix.\n\n###### Valueless Attributify\n\nIn addition to Windi CSS's Attributify Mode, this presets also supports valueless attributes.\n\nFor example, \n\n```html\n<div class=\"m-2 rounded text-teal-400\" />\n```\n\nnow can be\n\n```html\n<div m-2 rounded text-teal-400 />\n```\n\n## TypeScript Support (JSX/TSX)\n\nCreate `shims.d.ts` with the following content:\n\n> By default, the type includes common attributes from `@unocss/preset-uno`. If you need custom attributes, refer to the [type source](https://github.com/antfu/unocss/blob/main/packages/preset-attributify/src/jsx.ts) to implement your own type.\n\n### React\n\n```ts\nimport { AttributifyAttributes } from '@unocss/preset-attributify'\n\ndeclare module 'react' {\n interface HTMLAttributes<T> extends AttributifyAttributes {}\n}\n```\n\n### Vue 3\n\n```ts\nimport { AttributifyAttributes } from '@unocss/preset-attributify'\n\ndeclare module '@vue/runtime-dom' {\n interface HTMLAttributes extends AttributifyAttributes {}\n}\n```\n\n### SolidJS\n\n```ts\nimport { AttributifyAttributes } from '@unocss/preset-attributify'\n\ndeclare module
|
|
42
|
+
"readme": "# @unocss/preset-attributify\n\nAttributify Mode for [UnoCSS](https://github.com/unocss/unocss).\n\n## Installation\n\n```bash\nnpm i -D @unocss/preset-attributify\n```\n\n```ts\nimport presetAttributify from '@unocss/preset-attributify'\n\nUnocss({\n presets: [\n presetAttributify({ /* options */ }),\n // ...other presets\n ],\n})\n```\n\n## Attributify Mode\n\nThis preset enabled [Windi CSS's Attributify Mode](https://windicss.org/posts/v30.html#attributify-mode) for **other presets**.\n\nImagine you have this button using Tailwind's utilities. When the list gets long, it becomes really hard to read and maintain.\n\n```html\n<button class=\"bg-blue-400 hover:bg-blue-500 text-sm text-white font-mono font-light py-2 px-4 rounded border-2 border-blue-200 dark:bg-blue-500 dark:hover:bg-blue-600\">\n Button\n</button>\n```\n\nWith attributify mode, you can separate utilities into attributes:\n\n```html\n<button \n bg=\"blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600\"\n text=\"sm white\"\n font=\"mono light\"\n p=\"y-2 x-4\"\n border=\"2 rounded blue-200\"\n>\n Button\n</button>\n```\n\nFor example, `text-sm text-white` could be grouped into `text=\"sm white\"` without duplicating the same prefix.\n\n###### Valueless Attributify\n\nIn addition to Windi CSS's Attributify Mode, this presets also supports valueless attributes.\n\nFor example, \n\n```html\n<div class=\"m-2 rounded text-teal-400\" />\n```\n\nnow can be\n\n```html\n<div m-2 rounded text-teal-400 />\n```\n\n## TypeScript Support (JSX/TSX)\n\nCreate `shims.d.ts` with the following content:\n\n> By default, the type includes common attributes from `@unocss/preset-uno`. If you need custom attributes, refer to the [type source](https://github.com/antfu/unocss/blob/main/packages/preset-attributify/src/jsx.ts) to implement your own type.\n\n### React\n\n```ts\nimport type { AttributifyAttributes } from '@unocss/preset-attributify'\n\ndeclare module 'react' {\n interface HTMLAttributes<T> extends AttributifyAttributes {}\n}\n```\n\n### Vue 3\n\n```ts\nimport type { AttributifyAttributes } from '@unocss/preset-attributify'\n\ndeclare module '@vue/runtime-dom' {\n interface HTMLAttributes extends AttributifyAttributes {}\n}\n```\n\n### SolidJS\n\n```ts\nimport type { AttributifyAttributes } from '@unocss/preset-attributify'\n\ndeclare module 'solid-js' {\n namespace JSX {\n interface HTMLAttributes<T> extends AttributifyAttributes {}\n }\n}\n```\n\n### Attributify with Prefix\n\n```ts\nimport type { AttributifyNames } from '@unocss/preset-attributify'\n\ntype Prefix = 'uno:' // change it to your prefix\n\ninterface HTMLAttributes extends Partial<Record<AttributifyNames<Prefix>, string>> {}\n```\n\n## Credits\n\nInitial idea by [@Tahul](https://github.com/Tahul) and [@antfu](https://github.com/antfu). Pior implementation in Windi CSS by [@voorjaar](https://github.com/voorjaar).\n\n## License\n\nMIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)\n"
|
|
43
43
|
}
|