@unocss/preset-attributify 0.50.7 → 0.51.0
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 +2 -214
- package/dist/index.cjs +7 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +7 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,221 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Attributify Mode for [UnoCSS](https://github.com/unocss/unocss).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Documentation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm i -D @unocss/preset-attributify
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import presetAttributify from '@unocss/preset-attributify'
|
|
13
|
-
|
|
14
|
-
UnoCSS({
|
|
15
|
-
presets: [
|
|
16
|
-
presetAttributify({ /* options */ }),
|
|
17
|
-
// ...other presets
|
|
18
|
-
],
|
|
19
|
-
})
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Attributify Mode
|
|
23
|
-
|
|
24
|
-
This preset enabled [Windi CSS's Attributify Mode](https://windicss.org/posts/v30.html#attributify-mode) for **other presets**.
|
|
25
|
-
|
|
26
|
-
Imagine you have this button using Tailwind's utilities. When the list gets long, it becomes really hard to read and maintain.
|
|
27
|
-
|
|
28
|
-
```html
|
|
29
|
-
<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">
|
|
30
|
-
Button
|
|
31
|
-
</button>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
With attributify mode, you can separate utilities into attributes:
|
|
35
|
-
|
|
36
|
-
```html
|
|
37
|
-
<button
|
|
38
|
-
bg="blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600"
|
|
39
|
-
text="sm white"
|
|
40
|
-
font="mono light"
|
|
41
|
-
p="y-2 x-4"
|
|
42
|
-
border="2 rounded blue-200"
|
|
43
|
-
>
|
|
44
|
-
Button
|
|
45
|
-
</button>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
For example, `text-sm text-white` could be grouped into `text="sm white"` without duplicating the same prefix.
|
|
49
|
-
|
|
50
|
-
### Prefix Self-referencing
|
|
51
|
-
|
|
52
|
-
For utilities like `flex`, `grid`, `border`, that have the utilities same as the prefix, a special `~` value is provided.
|
|
53
|
-
|
|
54
|
-
For example:
|
|
55
|
-
|
|
56
|
-
```html
|
|
57
|
-
<button class="border border-red">
|
|
58
|
-
Button
|
|
59
|
-
</button>
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Can be written as
|
|
63
|
-
|
|
64
|
-
```html
|
|
65
|
-
<button border="~ red">
|
|
66
|
-
Button
|
|
67
|
-
</button>
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Valueless Attributify
|
|
71
|
-
|
|
72
|
-
In addition to Windi CSS's Attributify Mode, this presets also supports valueless attributes.
|
|
73
|
-
|
|
74
|
-
For example,
|
|
75
|
-
|
|
76
|
-
```html
|
|
77
|
-
<div class="m-2 rounded text-teal-400" />
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
now can be
|
|
81
|
-
|
|
82
|
-
```html
|
|
83
|
-
<div m-2 rounded text-teal-400 />
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
> Note: If you are using JSX, `<div foo>` might be transformed to `<div foo={true}>` which will make the generate CSS from UnoCSS failed to match the attributes. To solve this, you might want to try [`transformer-attributify-jsx`](https://github.com/unocss/unocss/tree/main/packages/transformer-attributify-jsx) along with this preset.
|
|
87
|
-
|
|
88
|
-
### Properties Conflicts
|
|
89
|
-
|
|
90
|
-
If the name of the attributes mode ever conflicts with the elements' or components' properties, you can add `un-` prefix to be specific to UnoCSS's attributify mode.
|
|
91
|
-
|
|
92
|
-
For example:
|
|
93
|
-
|
|
94
|
-
```html
|
|
95
|
-
<a text="red">This conflicts with links' `text` prop</a>
|
|
96
|
-
<!-- to -->
|
|
97
|
-
<a un-text="red">Text color to red</a>
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Prefix is optional by default, if you want to enforce the usage of prefix, set
|
|
101
|
-
|
|
102
|
-
```ts
|
|
103
|
-
presetAttributify({
|
|
104
|
-
prefix: 'un-',
|
|
105
|
-
prefixedOnly: true, // <--
|
|
106
|
-
})
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
You can also disable the scanning for certain attributes by:
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
presetAttributify({
|
|
113
|
-
ignoreAttributes: [
|
|
114
|
-
'text'
|
|
115
|
-
// ...
|
|
116
|
-
]
|
|
117
|
-
})
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## TypeScript Support (JSX/TSX)
|
|
121
|
-
|
|
122
|
-
Create `shims.d.ts` with the following content:
|
|
123
|
-
|
|
124
|
-
> 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.
|
|
125
|
-
|
|
126
|
-
### Vue
|
|
127
|
-
|
|
128
|
-
Since Volar 0.36, [it's now strict to unknown attributes](https://github.com/johnsoncodehk/volar/issues/1077#issuecomment-1145361472). To opt-out, you can add the following file to your project:
|
|
129
|
-
|
|
130
|
-
```ts
|
|
131
|
-
// html.d.ts
|
|
132
|
-
declare module '@vue/runtime-dom' {
|
|
133
|
-
interface HTMLAttributes {
|
|
134
|
-
[key: string]: any
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
declare module '@vue/runtime-core' {
|
|
138
|
-
interface AllowedComponentProps {
|
|
139
|
-
[key: string]: any
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
export {}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### React
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
149
|
-
|
|
150
|
-
declare module 'react' {
|
|
151
|
-
interface HTMLAttributes<T> extends AttributifyAttributes {}
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Vue 3
|
|
156
|
-
|
|
157
|
-
```ts
|
|
158
|
-
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
159
|
-
|
|
160
|
-
declare module '@vue/runtime-dom' {
|
|
161
|
-
interface HTMLAttributes extends AttributifyAttributes {}
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### SolidJS
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
169
|
-
|
|
170
|
-
declare module 'solid-js' {
|
|
171
|
-
namespace JSX {
|
|
172
|
-
interface HTMLAttributes<T> extends AttributifyAttributes {}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### Svelte & SvelteKit
|
|
178
|
-
|
|
179
|
-
```ts
|
|
180
|
-
declare namespace svelteHTML {
|
|
181
|
-
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
182
|
-
|
|
183
|
-
type HTMLAttributes = AttributifyAttributes
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Astro
|
|
188
|
-
|
|
189
|
-
```ts
|
|
190
|
-
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
191
|
-
|
|
192
|
-
declare global {
|
|
193
|
-
namespace astroHTML.JSX {
|
|
194
|
-
interface HTMLAttributes extends AttributifyAttributes { }
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Preact
|
|
200
|
-
|
|
201
|
-
```ts
|
|
202
|
-
import type { AttributifyAttributes } from '@unocss/preset-attributify'
|
|
203
|
-
|
|
204
|
-
declare module 'preact' {
|
|
205
|
-
namespace JSX {
|
|
206
|
-
interface HTMLAttributes extends AttributifyAttributes {}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
### Attributify with Prefix
|
|
212
|
-
|
|
213
|
-
```ts
|
|
214
|
-
import type { AttributifyNames } from '@unocss/preset-attributify'
|
|
215
|
-
|
|
216
|
-
type Prefix = 'uno:' // change it to your prefix
|
|
217
|
-
|
|
218
|
-
interface HTMLAttributes extends Partial<Record<AttributifyNames<Prefix>, string>> {}
|
|
219
|
-
```
|
|
7
|
+
Please refer to the [documentation](https://unocss.dev/presets/attributify).
|
|
220
8
|
|
|
221
9
|
## Credits
|
|
222
10
|
|
package/dist/index.cjs
CHANGED
|
@@ -137,7 +137,7 @@ function extractorAttributify(options) {
|
|
|
137
137
|
const nonValuedAttribute = options?.nonValuedAttribute ?? true;
|
|
138
138
|
const trueToNonValued = options?.trueToNonValued ?? false;
|
|
139
139
|
return {
|
|
140
|
-
name: "attributify",
|
|
140
|
+
name: "@unocss/preset-attributify/extractor",
|
|
141
141
|
extract({ code }) {
|
|
142
142
|
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, ...contents]) => {
|
|
143
143
|
const content = contents.filter(Boolean).join("");
|
|
@@ -172,7 +172,7 @@ function extractorAttributify(options) {
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
function
|
|
175
|
+
function presetAttributify(options = {}) {
|
|
176
176
|
options.strict = options.strict ?? false;
|
|
177
177
|
options.prefix = options.prefix ?? "un-";
|
|
178
178
|
options.prefixedOnly = options.prefixedOnly ?? false;
|
|
@@ -187,22 +187,23 @@ function preset(options = {}) {
|
|
|
187
187
|
const autocompleteExtractors = [
|
|
188
188
|
autocompleteExtractorAttributify
|
|
189
189
|
];
|
|
190
|
-
if (!options.strict)
|
|
191
|
-
extractors.unshift(core.extractorSplit);
|
|
192
190
|
return {
|
|
193
191
|
name: "@unocss/preset-attributify",
|
|
192
|
+
enforce: "post",
|
|
194
193
|
variants,
|
|
195
194
|
extractors,
|
|
196
195
|
options,
|
|
197
196
|
autocomplete: {
|
|
198
197
|
extractors: autocompleteExtractors
|
|
199
|
-
}
|
|
198
|
+
},
|
|
199
|
+
extractorDefault: options.strict ? false : void 0
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
exports.autocompleteExtractorAttributify = autocompleteExtractorAttributify;
|
|
204
|
-
exports["default"] =
|
|
204
|
+
exports["default"] = presetAttributify;
|
|
205
205
|
exports.defaultIgnoreAttributes = defaultIgnoreAttributes;
|
|
206
206
|
exports.extractorAttributify = extractorAttributify;
|
|
207
|
+
exports.presetAttributify = presetAttributify;
|
|
207
208
|
exports.variantAttributify = variantAttributify;
|
|
208
209
|
exports.variantsRE = variantsRE;
|
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,6 @@ type AttributifyNames<Prefix extends string = ''> = `${Prefix}${BasicAttributes}
|
|
|
67
67
|
interface AttributifyAttributes extends Partial<Record<AttributifyNames, string | boolean>> {
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
declare function
|
|
70
|
+
declare function presetAttributify(options?: AttributifyOptions): Preset;
|
|
71
71
|
|
|
72
|
-
export { AttributifyAttributes, AttributifyNames, AttributifyOptions, BasicAttributes, PseudoPrefix, SeparateEnabled, SpecialSingleWord, StringNumberComposition, StringNumberCompositionPrefix, TwoStringsComposition, TwoStringsCompositionPrefix, TwoStringsCompositionSuffix, autocompleteExtractorAttributify,
|
|
72
|
+
export { AttributifyAttributes, AttributifyNames, AttributifyOptions, BasicAttributes, PseudoPrefix, SeparateEnabled, SpecialSingleWord, StringNumberComposition, StringNumberCompositionPrefix, TwoStringsComposition, TwoStringsCompositionPrefix, TwoStringsCompositionSuffix, autocompleteExtractorAttributify, presetAttributify as default, defaultIgnoreAttributes, extractorAttributify, presetAttributify, variantAttributify, variantsRE };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAttributifySelector, isValidSelector
|
|
1
|
+
import { isAttributifySelector, isValidSelector } from '@unocss/core';
|
|
2
2
|
|
|
3
3
|
const variantsRE = /^(?!.*\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
|
|
4
4
|
function variantAttributify(options = {}) {
|
|
@@ -133,7 +133,7 @@ function extractorAttributify(options) {
|
|
|
133
133
|
const nonValuedAttribute = options?.nonValuedAttribute ?? true;
|
|
134
134
|
const trueToNonValued = options?.trueToNonValued ?? false;
|
|
135
135
|
return {
|
|
136
|
-
name: "attributify",
|
|
136
|
+
name: "@unocss/preset-attributify/extractor",
|
|
137
137
|
extract({ code }) {
|
|
138
138
|
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, ...contents]) => {
|
|
139
139
|
const content = contents.filter(Boolean).join("");
|
|
@@ -168,7 +168,7 @@ function extractorAttributify(options) {
|
|
|
168
168
|
};
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
function
|
|
171
|
+
function presetAttributify(options = {}) {
|
|
172
172
|
options.strict = options.strict ?? false;
|
|
173
173
|
options.prefix = options.prefix ?? "un-";
|
|
174
174
|
options.prefixedOnly = options.prefixedOnly ?? false;
|
|
@@ -183,17 +183,17 @@ function preset(options = {}) {
|
|
|
183
183
|
const autocompleteExtractors = [
|
|
184
184
|
autocompleteExtractorAttributify
|
|
185
185
|
];
|
|
186
|
-
if (!options.strict)
|
|
187
|
-
extractors.unshift(extractorSplit);
|
|
188
186
|
return {
|
|
189
187
|
name: "@unocss/preset-attributify",
|
|
188
|
+
enforce: "post",
|
|
190
189
|
variants,
|
|
191
190
|
extractors,
|
|
192
191
|
options,
|
|
193
192
|
autocomplete: {
|
|
194
193
|
extractors: autocompleteExtractors
|
|
195
|
-
}
|
|
194
|
+
},
|
|
195
|
+
extractorDefault: options.strict ? false : void 0
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
export { autocompleteExtractorAttributify,
|
|
199
|
+
export { autocompleteExtractorAttributify, presetAttributify as default, defaultIgnoreAttributes, extractorAttributify, presetAttributify, variantAttributify, variantsRE };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-attributify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Attributify preset for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unocss/core": "0.
|
|
36
|
+
"@unocss/core": "0.51.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "unbuild",
|