@unocss/preset-attributify 0.58.9 → 0.59.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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/preset-attributify",
3
- "version": "0.58.9",
3
+ "type": "module",
4
+ "version": "0.59.0",
4
5
  "description": "Attributify preset for UnoCSS",
5
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
7
  "license": "MIT",
@@ -21,19 +22,18 @@
21
22
  "sideEffects": false,
22
23
  "exports": {
23
24
  ".": {
24
- "types": "./dist/index.d.ts",
25
- "import": "./dist/index.mjs",
26
- "require": "./dist/index.cjs"
25
+ "types": "./dist/index.d.mts",
26
+ "default": "./dist/index.mjs"
27
27
  }
28
28
  },
29
- "main": "dist/index.cjs",
29
+ "main": "dist/index.mjs",
30
30
  "module": "dist/index.mjs",
31
31
  "types": "dist/index.d.ts",
32
32
  "files": [
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@unocss/core": "0.58.9"
36
+ "@unocss/core": "0.59.0"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "unbuild",
package/dist/index.cjs DELETED
@@ -1,217 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const core = require('@unocss/core');
6
-
7
- const variantsRE = /^(?!.*\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
8
- function variantAttributify(options = {}) {
9
- const prefix = options.prefix ?? "un-";
10
- const prefixedOnly = options.prefixedOnly ?? false;
11
- const trueToNonValued = options.trueToNonValued ?? false;
12
- let variantsValueRE;
13
- return {
14
- name: "attributify",
15
- match(input, { generator }) {
16
- const match = core.isAttributifySelector(input);
17
- if (!match)
18
- return;
19
- let name = match[1];
20
- if (name.startsWith(prefix))
21
- name = name.slice(prefix.length);
22
- else if (prefixedOnly)
23
- return;
24
- const content = match[2];
25
- const [, variants = "", body = content] = content.match(variantsRE) || [];
26
- if (body === "~" || trueToNonValued && body === "true" || !body)
27
- return `${variants}${name}`;
28
- if (variantsValueRE == null) {
29
- const separators = generator?.config?.separators?.join("|");
30
- if (separators)
31
- variantsValueRE = new RegExp(`^(.*\\](?:${separators}))(\\[[^\\]]+?\\])$`);
32
- else
33
- variantsValueRE = false;
34
- }
35
- if (variantsValueRE) {
36
- const [, bodyVariant, bracketValue] = content.match(variantsValueRE) || [];
37
- if (bracketValue)
38
- return `${bodyVariant}${variants}${name}-${bracketValue}`;
39
- }
40
- return `${variants}${name}-${body}`;
41
- }
42
- };
43
- }
44
-
45
- const elementRE$1 = /(<\w[\w:\.$-]*\s)((?:'[^>]*?'|"[^>]*?"|`[^>]*?`|\{[^>]*?\}|[^>]*?)*)/g;
46
- const valuedAttributeRE$1 = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=("[^"]*|'[^']*))?/g;
47
- const splitterRE$1 = /[\s'"`;>]+/;
48
- function autocompleteExtractorAttributify(options) {
49
- return {
50
- name: "attributify",
51
- extract: ({ content, cursor }) => {
52
- const matchedElements = content.matchAll(elementRE$1);
53
- let attrs;
54
- let elPos = 0;
55
- for (const match of matchedElements) {
56
- const [, prefix, content2] = match;
57
- const currentPos2 = match.index + prefix.length;
58
- if (cursor > currentPos2 && cursor <= currentPos2 + content2.length) {
59
- elPos = currentPos2;
60
- attrs = content2;
61
- break;
62
- }
63
- }
64
- if (!attrs)
65
- return null;
66
- const matchedAttributes = attrs.matchAll(valuedAttributeRE$1);
67
- let attrsPos = 0;
68
- let attrName;
69
- let attrValues;
70
- for (const match of matchedAttributes) {
71
- const [matched, name, rawValues] = match;
72
- const currentPos2 = elPos + match.index;
73
- if (cursor > currentPos2 && cursor <= currentPos2 + matched.length) {
74
- attrsPos = currentPos2;
75
- attrName = name;
76
- attrValues = rawValues?.slice(1);
77
- break;
78
- }
79
- }
80
- if (!attrName)
81
- return null;
82
- if (attrName === "class" || attrName === "className" || attrName === ":class")
83
- return null;
84
- const hasPrefix = !!options?.prefix && attrName.startsWith(options.prefix);
85
- if (options?.prefixedOnly && !hasPrefix)
86
- return null;
87
- const attrNameWithoutPrefix = hasPrefix ? attrName.slice(options.prefix.length) : attrName;
88
- if (attrValues === void 0) {
89
- return {
90
- extracted: attrNameWithoutPrefix,
91
- resolveReplacement(suggestion) {
92
- const startOffset = hasPrefix ? options.prefix.length : 0;
93
- return {
94
- start: attrsPos + startOffset,
95
- end: attrsPos + attrName.length,
96
- replacement: suggestion
97
- };
98
- }
99
- };
100
- }
101
- const attrValuePos = attrsPos + attrName.length + 2;
102
- let matchSplit = splitterRE$1.exec(attrValues);
103
- let currentPos = 0;
104
- let value;
105
- while (matchSplit) {
106
- const [matched] = matchSplit;
107
- if (cursor > attrValuePos + currentPos && cursor <= attrValuePos + currentPos + matchSplit.index) {
108
- value = attrValues.slice(currentPos, currentPos + matchSplit.index);
109
- break;
110
- }
111
- currentPos += matchSplit.index + matched.length;
112
- matchSplit = splitterRE$1.exec(attrValues.slice(currentPos));
113
- }
114
- if (value === void 0)
115
- value = attrValues.slice(currentPos);
116
- const [, variants = "", body] = value.match(variantsRE) || [];
117
- return {
118
- extracted: `${variants}${attrNameWithoutPrefix}-${body}`,
119
- transformSuggestions(suggestions) {
120
- return suggestions.filter((v) => v.startsWith(`${variants}${attrNameWithoutPrefix}-`)).map((v) => variants + v.slice(variants.length + attrNameWithoutPrefix.length + 1));
121
- },
122
- resolveReplacement(suggestion) {
123
- return {
124
- start: currentPos + attrValuePos,
125
- end: currentPos + attrValuePos + value.length,
126
- replacement: variants + suggestion.slice(variants.length + attrNameWithoutPrefix.length + 1)
127
- };
128
- }
129
- };
130
- }
131
- };
132
- }
133
-
134
- const strippedPrefixes = [
135
- "v-bind:",
136
- ":"
137
- ];
138
- const splitterRE = /[\s'"`;]+/g;
139
- const elementRE = /<[^>\s]*\s((?:'.*?'|".*?"|`.*?`|\{.*?\}|=>|[^>]*?)*)/g;
140
- const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-.~<]+)=?(?:["]([^"]*)["]|[']([^']*)[']|[{]([^}]*)[}])?/gms;
141
- const defaultIgnoreAttributes = ["placeholder", "fill", "opacity", "stroke-opacity"];
142
- function extractorAttributify(options) {
143
- const ignoreAttributes = options?.ignoreAttributes ?? defaultIgnoreAttributes;
144
- const nonValuedAttribute = options?.nonValuedAttribute ?? true;
145
- const trueToNonValued = options?.trueToNonValued ?? false;
146
- return {
147
- name: "@unocss/preset-attributify/extractor",
148
- extract({ code }) {
149
- return Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, ...contents]) => {
150
- const content = contents.filter(Boolean).join("");
151
- if (ignoreAttributes.includes(name))
152
- return [];
153
- for (const prefix of strippedPrefixes) {
154
- if (name.startsWith(prefix)) {
155
- name = name.slice(prefix.length);
156
- break;
157
- }
158
- }
159
- if (!content) {
160
- if (core.isValidSelector(name) && nonValuedAttribute !== false) {
161
- const result = [`[${name}=""]`];
162
- if (trueToNonValued)
163
- result.push(`[${name}="true"]`);
164
- return result;
165
- }
166
- return [];
167
- }
168
- if (["class", "className"].includes(name)) {
169
- return content.split(splitterRE).filter(core.isValidSelector);
170
- } else if (elementRE.test(content)) {
171
- elementRE.lastIndex = 0;
172
- return this.extract({ code: content });
173
- } else {
174
- if (options?.prefixedOnly && options.prefix && !name.startsWith(options.prefix))
175
- return [];
176
- return content.split(splitterRE).filter((v) => Boolean(v) && v !== ":").map((v) => `[${name}~="${v}"]`);
177
- }
178
- });
179
- }
180
- };
181
- }
182
-
183
- const presetAttributify = core.definePreset((options = {}) => {
184
- options.strict = options.strict ?? false;
185
- options.prefix = options.prefix ?? "un-";
186
- options.prefixedOnly = options.prefixedOnly ?? false;
187
- options.nonValuedAttribute = options.nonValuedAttribute ?? true;
188
- options.ignoreAttributes = options.ignoreAttributes ?? defaultIgnoreAttributes;
189
- const variants = [
190
- variantAttributify(options)
191
- ];
192
- const extractors = [
193
- extractorAttributify(options)
194
- ];
195
- const autocompleteExtractors = [
196
- autocompleteExtractorAttributify(options)
197
- ];
198
- return {
199
- name: "@unocss/preset-attributify",
200
- enforce: "post",
201
- variants,
202
- extractors,
203
- options,
204
- autocomplete: {
205
- extractors: autocompleteExtractors
206
- },
207
- extractorDefault: options.strict ? false : void 0
208
- };
209
- });
210
-
211
- exports.autocompleteExtractorAttributify = autocompleteExtractorAttributify;
212
- exports.default = presetAttributify;
213
- exports.defaultIgnoreAttributes = defaultIgnoreAttributes;
214
- exports.extractorAttributify = extractorAttributify;
215
- exports.presetAttributify = presetAttributify;
216
- exports.variantAttributify = variantAttributify;
217
- exports.variantsRE = variantsRE;
package/dist/index.d.cts DELETED
@@ -1,89 +0,0 @@
1
- import * as _unocss_core from '@unocss/core';
2
- import { PresetOptions, AutoCompleteExtractor, Extractor, VariantObject } from '@unocss/core';
3
-
4
- interface AttributifyOptions extends PresetOptions {
5
- /**
6
- * Only generate CSS for attributify or class
7
- *
8
- * @default false
9
- */
10
- strict?: boolean;
11
- /**
12
- * @default 'un-'
13
- */
14
- prefix?: string;
15
- /**
16
- * Only match for prefixed attributes
17
- *
18
- * @default false
19
- */
20
- prefixedOnly?: boolean;
21
- /**
22
- * Support matching non-valued attributes
23
- *
24
- * For example
25
- * ```html
26
- * <div mt-2 />
27
- * ```
28
- *
29
- * @default true
30
- */
31
- nonValuedAttribute?: boolean;
32
- /**
33
- * A list of attributes to be ignored from extracting.
34
- */
35
- ignoreAttributes?: string[];
36
- /**
37
- * Non-valued attributes will also match if the actual value represented in DOM is `true`.
38
- * This option exists for supporting frameworks that encodes non-valued attributes as `true`.
39
- * Enabling this option will break rules that ends with `true`.
40
- *
41
- * @default false
42
- */
43
- trueToNonValued?: boolean;
44
- }
45
-
46
- declare function autocompleteExtractorAttributify(options?: AttributifyOptions): AutoCompleteExtractor;
47
-
48
- declare const defaultIgnoreAttributes: string[];
49
- declare function extractorAttributify(options?: AttributifyOptions): Extractor;
50
-
51
- declare const variantsRE: RegExp;
52
- declare function variantAttributify(options?: AttributifyOptions): VariantObject;
53
-
54
- type TwoStringsCompositionPrefix = 'm' | 'p';
55
- type TwoStringsCompositionSuffix = 'r' | 'b' | 'l' | 't' | 'a' | 'x' | 'y';
56
- /** Some words can compose with two strings to become a complete unocss rule such as ha, mr, mb */
57
- type TwoStringsComposition = `${TwoStringsCompositionPrefix}${TwoStringsCompositionSuffix}` | 'ha' | 'wa';
58
- /** Some words can be a complete unocss rule by itself */
59
- type SpecialSingleWord = 'container' | 'flex' | 'block' | 'inline' | 'table' | 'isolate' | 'absolute' | 'relative' | 'fixed' | 'sticky' | 'static' | 'visible' | 'invisible' | 'grow' | 'shrink' | 'antialiased' | 'italic' | 'ordinal' | 'overline' | 'underline' | 'uppercase' | 'lowercase' | 'capitalize' | 'truncate' | 'border' | 'rounded' | 'outline' | 'ring' | 'shadow' | 'blur' | 'grayscale' | 'invert' | 'sepia' | 'transition' | 'resize' | 'transform' | 'filter';
60
- type PseudoPrefix = 'active' | 'before' | 'after' | 'dark' | 'light' | 'first' | 'last' | 'focus' | 'hover' | 'link' | 'root' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'enabled' | 'disabled' | 'all' | 'children';
61
- /** Some words can be used to separate utilities, such as font="mono light", text="sm white" */
62
- type SeparateEnabled = 'align' | 'animate' | 'backdrop' | 'bg' | 'blend' | 'border' | 'box' | 'container' | 'content' | 'cursor' | 'display' | 'divide' | 'filter' | 'flex' | 'font' | 'fw' | 'gap' | 'gradient' | 'grid' | 'h' | 'icon' | 'items' | 'justify' | 'list' | 'm' | 'op' | 'opacity' | 'order' | 'outline' | 'overflow' | 'p' | 'place' | 'pos' | 'position' | 'ring' | 'select' | 'shadow' | 'size' | 'space' | 'table' | 'text' | 'transform' | 'transition' | 'underline' | 'w' | 'z' | PseudoPrefix;
63
- type BasicAttributes = SpecialSingleWord | TwoStringsComposition | SeparateEnabled;
64
- type AttributifyNames<Prefix extends string = ''> = `${Prefix}${BasicAttributes}` | `${Prefix}${PseudoPrefix}:${BasicAttributes}`;
65
- interface AttributifyAttributes extends Partial<Record<AttributifyNames, string | boolean>> {
66
- }
67
-
68
- /**
69
- * This enables the attributify mode for other presets.
70
- *
71
- * @example
72
- *
73
- * ```html
74
- * <button
75
- * bg="blue-400 hover:blue-500 dark:blue-500 dark:hover:blue-600"
76
- * text="sm white"
77
- * font="mono light"
78
- * p="y-2 x-4"
79
- * border="2 rounded blue-200"
80
- * >
81
- * Button
82
- * </button>
83
- * ```
84
- *
85
- * @see https://unocss.dev/presets/attributify
86
- */
87
- declare const presetAttributify: _unocss_core.PresetFactory<object, AttributifyOptions>;
88
-
89
- export { type AttributifyAttributes, type AttributifyNames, type AttributifyOptions, type BasicAttributes, type PseudoPrefix, type SeparateEnabled, type SpecialSingleWord, type TwoStringsComposition, type TwoStringsCompositionPrefix, type TwoStringsCompositionSuffix, autocompleteExtractorAttributify, presetAttributify as default, defaultIgnoreAttributes, extractorAttributify, presetAttributify, variantAttributify, variantsRE };