@unocss/preset-attributify 0.14.2 → 0.14.3

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 ADDED
@@ -0,0 +1,79 @@
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
+ for (const prefix of strippedPrefixes) {
19
+ if (name.startsWith(prefix)) {
20
+ name = name.slice(prefix.length);
21
+ break;
22
+ }
23
+ }
24
+ if (!content) {
25
+ if (core.isValidSelector(name) && options?.nonValuedAttribute !== false)
26
+ return [`[${name}=""]`];
27
+ return [];
28
+ }
29
+ if (["class", "className"].includes(name)) {
30
+ return content.split(splitterRE).filter(core.isValidSelector);
31
+ } else {
32
+ return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
33
+ }
34
+ });
35
+ return new Set(result);
36
+ }
37
+ });
38
+
39
+ const variantsRE = /^(.+\:\!?)?(.*?)$/;
40
+ const variantAttributify = (options = {}) => {
41
+ const prefix = options.prefix ?? "un-";
42
+ return (input) => {
43
+ const match = core.isAttributifySelector(input);
44
+ if (!match)
45
+ return;
46
+ let name = match[1];
47
+ if (name.startsWith(prefix))
48
+ name = name.slice(prefix.length);
49
+ else if (options.prefixedOnly)
50
+ return;
51
+ const content = match[2];
52
+ const [, variants = "", body = content] = content.match(variantsRE) || [];
53
+ if (body === "~" || !body)
54
+ return `${variants}${name}`;
55
+ else
56
+ return `${variants}${name}-${body}`;
57
+ };
58
+ };
59
+
60
+ const preset = (options) => {
61
+ const variants = [
62
+ variantAttributify(options)
63
+ ];
64
+ const extractors = [
65
+ extractorAttributify(options)
66
+ ];
67
+ if (!options?.strict)
68
+ extractors.unshift(core.extractorSplit);
69
+ return {
70
+ name: "@unocss/preset-attributify",
71
+ variants,
72
+ extractors,
73
+ options
74
+ };
75
+ };
76
+
77
+ exports["default"] = preset;
78
+ exports.extractorAttributify = extractorAttributify;
79
+ exports.variantAttributify = variantAttributify;
package/dist/index.mjs CHANGED
@@ -1,16 +1,13 @@
1
- // src/index.ts
2
- import { extractorSplit } from "@unocss/core";
1
+ import { isValidSelector, isAttributifySelector, extractorSplit } from '@unocss/core';
3
2
 
4
- // src/extractor.ts
5
- import { isValidSelector } from "@unocss/core";
6
- var strippedPrefixes = [
3
+ const strippedPrefixes = [
7
4
  "v-bind:",
8
5
  ":"
9
6
  ];
10
- var splitterRE = /[\s'"`;]+/g;
11
- var elementRE = /<\w[\w:\.$-]*\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
12
- var valuedAttributeRE = /([?]|[\w:%-]+)(?:=(["'])([^\2]+?)\2)?/g;
13
- var extractorAttributify = (options) => ({
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]) => {
@@ -21,7 +18,7 @@ var extractorAttributify = (options) => ({
21
18
  }
22
19
  }
23
20
  if (!content) {
24
- if (isValidSelector(name) && (options == null ? void 0 : options.nonValuedAttribute) !== false)
21
+ if (isValidSelector(name) && options?.nonValuedAttribute !== false)
25
22
  return [`[${name}=""]`];
26
23
  return [];
27
24
  }
@@ -35,12 +32,9 @@ var extractorAttributify = (options) => ({
35
32
  }
36
33
  });
37
34
 
38
- // src/variant.ts
39
- import { isAttributifySelector } from "@unocss/core";
40
- var variantsRE = /^(.+\:\!?)?(.*?)$/;
41
- var variantAttributify = (options = {}) => {
42
- var _a;
43
- const prefix = (_a = options.prefix) != null ? _a : "un-";
35
+ const variantsRE = /^(.+\:\!?)?(.*?)$/;
36
+ const variantAttributify = (options = {}) => {
37
+ const prefix = options.prefix ?? "un-";
44
38
  return (input) => {
45
39
  const match = isAttributifySelector(input);
46
40
  if (!match)
@@ -59,15 +53,14 @@ var variantAttributify = (options = {}) => {
59
53
  };
60
54
  };
61
55
 
62
- // src/index.ts
63
- var preset = (options) => {
56
+ const preset = (options) => {
64
57
  const variants = [
65
58
  variantAttributify(options)
66
59
  ];
67
60
  const extractors = [
68
61
  extractorAttributify(options)
69
62
  ];
70
- if (!(options == null ? void 0 : options.strict))
63
+ if (!options?.strict)
71
64
  extractors.unshift(extractorSplit);
72
65
  return {
73
66
  name: "@unocss/preset-attributify",
@@ -76,9 +69,5 @@ var preset = (options) => {
76
69
  options
77
70
  };
78
71
  };
79
- var src_default = preset;
80
- export {
81
- src_default as default,
82
- extractorAttributify,
83
- variantAttributify
84
- };
72
+
73
+ 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.14.2",
3
+ "version": "0.14.3",
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.js",
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.js",
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.14.2"
36
+ "@unocss/core": "0.14.3"
37
37
  },
38
38
  "scripts": {
39
- "build": "tsup",
40
- "dev": "tsup --watch src"
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
- });