@unocss/preset-attributify 0.14.1 → 0.15.1
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.cjs +81 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +16 -25
- package/package.json +6 -6
- package/dist/index.js +0 -113
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const core = require('@unocss/core');
|
|
6
|
+
|
|
7
|
+
const strippedPrefixes = [
|
|
8
|
+
"v-bind:",
|
|
9
|
+
":"
|
|
10
|
+
];
|
|
11
|
+
const splitterRE = /[\s'"`;]+/g;
|
|
12
|
+
const elementRE = /<\w[\w:\.$-]*\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
|
|
13
|
+
const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=(["'])([^\2]+?)\2)?/g;
|
|
14
|
+
const extractorAttributify = (options) => ({
|
|
15
|
+
name: "attributify",
|
|
16
|
+
extract({ code }) {
|
|
17
|
+
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
|
|
18
|
+
if (options?.ignoreAttributes?.includes(name))
|
|
19
|
+
return [];
|
|
20
|
+
for (const prefix of strippedPrefixes) {
|
|
21
|
+
if (name.startsWith(prefix)) {
|
|
22
|
+
name = name.slice(prefix.length);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!content) {
|
|
27
|
+
if (core.isValidSelector(name) && options?.nonValuedAttribute !== false)
|
|
28
|
+
return [`[${name}=""]`];
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
if (["class", "className"].includes(name)) {
|
|
32
|
+
return content.split(splitterRE).filter(core.isValidSelector);
|
|
33
|
+
} else {
|
|
34
|
+
return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return new Set(result);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const variantsRE = /^(.+\:\!?)?(.*?)$/;
|
|
42
|
+
const variantAttributify = (options = {}) => {
|
|
43
|
+
const prefix = options.prefix ?? "un-";
|
|
44
|
+
return (input) => {
|
|
45
|
+
const match = core.isAttributifySelector(input);
|
|
46
|
+
if (!match)
|
|
47
|
+
return;
|
|
48
|
+
let name = match[1];
|
|
49
|
+
if (name.startsWith(prefix))
|
|
50
|
+
name = name.slice(prefix.length);
|
|
51
|
+
else if (options.prefixedOnly)
|
|
52
|
+
return;
|
|
53
|
+
const content = match[2];
|
|
54
|
+
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
55
|
+
if (body === "~" || !body)
|
|
56
|
+
return `${variants}${name}`;
|
|
57
|
+
else
|
|
58
|
+
return `${variants}${name}-${body}`;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const preset = (options) => {
|
|
63
|
+
const variants = [
|
|
64
|
+
variantAttributify(options)
|
|
65
|
+
];
|
|
66
|
+
const extractors = [
|
|
67
|
+
extractorAttributify(options)
|
|
68
|
+
];
|
|
69
|
+
if (!options?.strict)
|
|
70
|
+
extractors.unshift(core.extractorSplit);
|
|
71
|
+
return {
|
|
72
|
+
name: "@unocss/preset-attributify",
|
|
73
|
+
variants,
|
|
74
|
+
extractors,
|
|
75
|
+
options
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports["default"] = preset;
|
|
80
|
+
exports.extractorAttributify = extractorAttributify;
|
|
81
|
+
exports.variantAttributify = variantAttributify;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ interface AttributifyOptions {
|
|
|
28
28
|
* @default true
|
|
29
29
|
*/
|
|
30
30
|
nonValuedAttribute?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* A list of attributes to be ignored from extracting.
|
|
33
|
+
*/
|
|
34
|
+
ignoreAttributes?: string[];
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
declare const extractorAttributify: (options?: AttributifyOptions | undefined) => Extractor;
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import { extractorSplit } from "@unocss/core";
|
|
1
|
+
import { isValidSelector, isAttributifySelector, extractorSplit } from '@unocss/core';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
import { isValidSelector } from "@unocss/core";
|
|
6
|
-
var strippedPrefixes = [
|
|
3
|
+
const strippedPrefixes = [
|
|
7
4
|
"v-bind:",
|
|
8
5
|
":"
|
|
9
6
|
];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const splitterRE = /[\s'"`;]+/g;
|
|
8
|
+
const elementRE = /<\w[\w:\.$-]*\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
|
|
9
|
+
const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=(["'])([^\2]+?)\2)?/g;
|
|
10
|
+
const extractorAttributify = (options) => ({
|
|
14
11
|
name: "attributify",
|
|
15
12
|
extract({ code }) {
|
|
16
13
|
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
|
|
14
|
+
if (options?.ignoreAttributes?.includes(name))
|
|
15
|
+
return [];
|
|
17
16
|
for (const prefix of strippedPrefixes) {
|
|
18
17
|
if (name.startsWith(prefix)) {
|
|
19
18
|
name = name.slice(prefix.length);
|
|
@@ -21,7 +20,7 @@ var extractorAttributify = (options) => ({
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
if (!content) {
|
|
24
|
-
if (isValidSelector(name) &&
|
|
23
|
+
if (isValidSelector(name) && options?.nonValuedAttribute !== false)
|
|
25
24
|
return [`[${name}=""]`];
|
|
26
25
|
return [];
|
|
27
26
|
}
|
|
@@ -35,12 +34,9 @@ var extractorAttributify = (options) => ({
|
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var variantAttributify = (options = {}) => {
|
|
42
|
-
var _a;
|
|
43
|
-
const prefix = (_a = options.prefix) != null ? _a : "un-";
|
|
37
|
+
const variantsRE = /^(.+\:\!?)?(.*?)$/;
|
|
38
|
+
const variantAttributify = (options = {}) => {
|
|
39
|
+
const prefix = options.prefix ?? "un-";
|
|
44
40
|
return (input) => {
|
|
45
41
|
const match = isAttributifySelector(input);
|
|
46
42
|
if (!match)
|
|
@@ -59,15 +55,14 @@ var variantAttributify = (options = {}) => {
|
|
|
59
55
|
};
|
|
60
56
|
};
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
var preset = (options) => {
|
|
58
|
+
const preset = (options) => {
|
|
64
59
|
const variants = [
|
|
65
60
|
variantAttributify(options)
|
|
66
61
|
];
|
|
67
62
|
const extractors = [
|
|
68
63
|
extractorAttributify(options)
|
|
69
64
|
];
|
|
70
|
-
if (!
|
|
65
|
+
if (!options?.strict)
|
|
71
66
|
extractors.unshift(extractorSplit);
|
|
72
67
|
return {
|
|
73
68
|
name: "@unocss/preset-attributify",
|
|
@@ -76,9 +71,5 @@ var preset = (options) => {
|
|
|
76
71
|
options
|
|
77
72
|
};
|
|
78
73
|
};
|
|
79
|
-
|
|
80
|
-
export {
|
|
81
|
-
src_default as default,
|
|
82
|
-
extractorAttributify,
|
|
83
|
-
variantAttributify
|
|
84
|
-
};
|
|
74
|
+
|
|
75
|
+
export { preset as default, extractorAttributify, variantAttributify };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-attributify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "Attributify preset for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -21,22 +21,22 @@
|
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"require": "./dist/index.
|
|
24
|
+
"require": "./dist/index.cjs",
|
|
25
25
|
"import": "./dist/index.mjs",
|
|
26
26
|
"types": "./dist/index.d.ts"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
"main": "dist/index.
|
|
29
|
+
"main": "dist/index.cjs",
|
|
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.
|
|
36
|
+
"@unocss/core": "0.15.1"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "
|
|
40
|
-
"
|
|
39
|
+
"build": "unbuild",
|
|
40
|
+
"stub": "unbuild --stub"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/dist/index.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
__markAsModule(target);
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, module2, desc) => {
|
|
14
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(module2))
|
|
16
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
17
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return target;
|
|
20
|
-
};
|
|
21
|
-
var __toModule = (module2) => {
|
|
22
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// src/index.ts
|
|
26
|
-
__export(exports, {
|
|
27
|
-
default: () => src_default,
|
|
28
|
-
extractorAttributify: () => extractorAttributify,
|
|
29
|
-
variantAttributify: () => variantAttributify
|
|
30
|
-
});
|
|
31
|
-
var import_core3 = __toModule(require("@unocss/core"));
|
|
32
|
-
|
|
33
|
-
// src/extractor.ts
|
|
34
|
-
var import_core = __toModule(require("@unocss/core"));
|
|
35
|
-
var strippedPrefixes = [
|
|
36
|
-
"v-bind:",
|
|
37
|
-
":"
|
|
38
|
-
];
|
|
39
|
-
var splitterRE = /[\s'"`;]+/g;
|
|
40
|
-
var elementRE = /<\w[\w:\.$-]*\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
|
|
41
|
-
var valuedAttributeRE = /([?]|[\w:%-]+)(?:=(["'])([^\2]+?)\2)?/g;
|
|
42
|
-
var extractorAttributify = (options) => ({
|
|
43
|
-
name: "attributify",
|
|
44
|
-
extract({ code }) {
|
|
45
|
-
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
|
|
46
|
-
for (const prefix of strippedPrefixes) {
|
|
47
|
-
if (name.startsWith(prefix)) {
|
|
48
|
-
name = name.slice(prefix.length);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (!content) {
|
|
53
|
-
if ((0, import_core.isValidSelector)(name) && (options == null ? void 0 : options.nonValuedAttribute) !== false)
|
|
54
|
-
return [`[${name}=""]`];
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
if (["class", "className"].includes(name)) {
|
|
58
|
-
return content.split(splitterRE).filter(import_core.isValidSelector);
|
|
59
|
-
} else {
|
|
60
|
-
return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return new Set(result);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// src/variant.ts
|
|
68
|
-
var import_core2 = __toModule(require("@unocss/core"));
|
|
69
|
-
var variantsRE = /^(.+\:\!?)?(.*?)$/;
|
|
70
|
-
var variantAttributify = (options = {}) => {
|
|
71
|
-
var _a;
|
|
72
|
-
const prefix = (_a = options.prefix) != null ? _a : "un-";
|
|
73
|
-
return (input) => {
|
|
74
|
-
const match = (0, import_core2.isAttributifySelector)(input);
|
|
75
|
-
if (!match)
|
|
76
|
-
return;
|
|
77
|
-
let name = match[1];
|
|
78
|
-
if (name.startsWith(prefix))
|
|
79
|
-
name = name.slice(prefix.length);
|
|
80
|
-
else if (options.prefixedOnly)
|
|
81
|
-
return;
|
|
82
|
-
const content = match[2];
|
|
83
|
-
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
84
|
-
if (body === "~" || !body)
|
|
85
|
-
return `${variants}${name}`;
|
|
86
|
-
else
|
|
87
|
-
return `${variants}${name}-${body}`;
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// src/index.ts
|
|
92
|
-
var preset = (options) => {
|
|
93
|
-
const variants = [
|
|
94
|
-
variantAttributify(options)
|
|
95
|
-
];
|
|
96
|
-
const extractors = [
|
|
97
|
-
extractorAttributify(options)
|
|
98
|
-
];
|
|
99
|
-
if (!(options == null ? void 0 : options.strict))
|
|
100
|
-
extractors.unshift(import_core3.extractorSplit);
|
|
101
|
-
return {
|
|
102
|
-
name: "@unocss/preset-attributify",
|
|
103
|
-
variants,
|
|
104
|
-
extractors,
|
|
105
|
-
options
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
var src_default = preset;
|
|
109
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
-
0 && (module.exports = {
|
|
111
|
-
extractorAttributify,
|
|
112
|
-
variantAttributify
|
|
113
|
-
});
|