@unocss/transformer-attributify-jsx 0.58.9 → 0.59.0-beta.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/package.json +6 -6
- package/dist/index.cjs +0 -65
- package/dist/index.d.cts +0 -24
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/transformer-attributify-jsx",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.59.0-beta.1",
|
|
4
5
|
"description": "Support valueless attributify in JSX/TSX.",
|
|
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.
|
|
25
|
-
"
|
|
26
|
-
"require": "./dist/index.cjs"
|
|
25
|
+
"types": "./dist/index.d.mts",
|
|
26
|
+
"default": "./dist/index.mjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
"main": "./dist/index.
|
|
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.
|
|
36
|
+
"@unocss/core": "0.59.0-beta.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"magic-string": "^0.30.8"
|
package/dist/index.cjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const core = require('@unocss/core');
|
|
4
|
-
|
|
5
|
-
function createFilter(include, exclude) {
|
|
6
|
-
const includePattern = core.toArray(include || []);
|
|
7
|
-
const excludePattern = core.toArray(exclude || []);
|
|
8
|
-
return (id) => {
|
|
9
|
-
if (excludePattern.some((p) => id.match(p)))
|
|
10
|
-
return false;
|
|
11
|
-
return includePattern.some((p) => id.match(p));
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
const elementRE = /(<\w[\w:\.$-]*\s)([\s\S]*?)(?=>[\s\S]?<\/[\s\w:\.$-]*>|\/>)/g;
|
|
15
|
-
const attributeRE = /(?<![~`!$%^&*()_+\-=[{;':"|,.<>/?]\s*)([a-zA-Z()#][\[?a-zA-Z0-9-_:()#%\]?]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
|
|
16
|
-
const valuedAttributeRE = /((?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:!%-.~<]+)=(?:["]([^"]*)["]|[']([^']*)[']|[{]((?:[`(](?:[^`)]*)[`)]|[^}])+)[}])/gms;
|
|
17
|
-
function transformerAttributifyJsx(options = {}) {
|
|
18
|
-
const {
|
|
19
|
-
blocklist = []
|
|
20
|
-
} = options;
|
|
21
|
-
const isBlocked = (matchedRule) => {
|
|
22
|
-
for (const blockedRule of blocklist) {
|
|
23
|
-
if (blockedRule instanceof RegExp) {
|
|
24
|
-
if (blockedRule.test(matchedRule))
|
|
25
|
-
return true;
|
|
26
|
-
} else if (matchedRule === blockedRule) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
|
-
const idFilter = createFilter(
|
|
33
|
-
options.include || [/\.[jt]sx$/, /\.mdx$/],
|
|
34
|
-
options.exclude || []
|
|
35
|
-
);
|
|
36
|
-
return {
|
|
37
|
-
name: "@unocss/transformer-attributify-jsx",
|
|
38
|
-
enforce: "pre",
|
|
39
|
-
idFilter,
|
|
40
|
-
async transform(code, _, { uno }) {
|
|
41
|
-
const tasks = [];
|
|
42
|
-
for (const item of Array.from(code.original.matchAll(elementRE))) {
|
|
43
|
-
let attributifyPart = item[2];
|
|
44
|
-
if (valuedAttributeRE.test(attributifyPart))
|
|
45
|
-
attributifyPart = attributifyPart.replace(valuedAttributeRE, (match) => " ".repeat(match.length));
|
|
46
|
-
for (const attr of attributifyPart.matchAll(attributeRE)) {
|
|
47
|
-
const matchedRule = attr[0].replace(/\:/i, "-");
|
|
48
|
-
if (matchedRule.includes("=") || isBlocked(matchedRule))
|
|
49
|
-
continue;
|
|
50
|
-
tasks.push(uno.parseToken(matchedRule).then((matched) => {
|
|
51
|
-
if (matched) {
|
|
52
|
-
const tag = item[1];
|
|
53
|
-
const startIdx = (item.index || 0) + (attr.index || 0) + tag.length;
|
|
54
|
-
const endIdx = startIdx + matchedRule.length;
|
|
55
|
-
code.overwrite(startIdx, endIdx, `${matchedRule}=""`);
|
|
56
|
-
}
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
await Promise.all(tasks);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = transformerAttributifyJsx;
|
package/dist/index.d.cts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { SourceCodeTransformer } from '@unocss/core';
|
|
2
|
-
|
|
3
|
-
type FilterPattern = Array<string | RegExp> | string | RegExp | null;
|
|
4
|
-
interface TransformerAttributifyJsxOptions {
|
|
5
|
-
/**
|
|
6
|
-
* the list of attributes to ignore
|
|
7
|
-
* @default []
|
|
8
|
-
*/
|
|
9
|
-
blocklist?: (string | RegExp)[];
|
|
10
|
-
/**
|
|
11
|
-
* Regex of modules to be included from processing
|
|
12
|
-
* @default [/\.[jt]sx$/, /\.mdx$/]
|
|
13
|
-
*/
|
|
14
|
-
include?: FilterPattern;
|
|
15
|
-
/**
|
|
16
|
-
* Regex of modules to exclude from processing
|
|
17
|
-
*
|
|
18
|
-
* @default []
|
|
19
|
-
*/
|
|
20
|
-
exclude?: FilterPattern;
|
|
21
|
-
}
|
|
22
|
-
declare function transformerAttributifyJsx(options?: TransformerAttributifyJsxOptions): SourceCodeTransformer;
|
|
23
|
-
|
|
24
|
-
export { type FilterPattern, type TransformerAttributifyJsxOptions, transformerAttributifyJsx as default };
|