@una-ui/extractor-vue-script 0.2.0-beta.1 → 0.2.0-beta.4
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 +37 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.mjs +29 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const core = require('@unocss/core');
|
|
6
|
+
|
|
7
|
+
function generateSelectors(prefix, values) {
|
|
8
|
+
return values.filter((v) => Boolean(v) && v !== ":").map((v) => `[${prefix}~="${v}"]`);
|
|
9
|
+
}
|
|
10
|
+
function splitCodeWithArbitraryVariants(code, prefixes) {
|
|
11
|
+
const result = [];
|
|
12
|
+
for (const prefix of prefixes) {
|
|
13
|
+
const regex = new RegExp(`^\\s*${prefix}:\\s+'.*',?\\s*$`, "mg");
|
|
14
|
+
const matches = code.match(regex);
|
|
15
|
+
if (!matches)
|
|
16
|
+
continue;
|
|
17
|
+
for (const match of matches) {
|
|
18
|
+
const values = match.replace(/^.*:\s*'(.*)',?\s*$/, "$1").split(core.defaultSplitRE);
|
|
19
|
+
const selectors = generateSelectors(prefix, values);
|
|
20
|
+
result.push(...selectors);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
function extractor(options) {
|
|
26
|
+
return {
|
|
27
|
+
name: "@una-ui/extractor-vue-script",
|
|
28
|
+
order: 0,
|
|
29
|
+
async extract({ code }) {
|
|
30
|
+
return splitCodeWithArbitraryVariants(code, options?.prefixes ?? []);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.default = extractor;
|
|
36
|
+
exports.extractor = extractor;
|
|
37
|
+
exports.splitCodeWithArbitraryVariants = splitCodeWithArbitraryVariants;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Extractor } from '@unocss/core';
|
|
2
|
+
|
|
3
|
+
interface ExtractorVueScriptOptions {
|
|
4
|
+
/**
|
|
5
|
+
* @default []
|
|
6
|
+
* @description List of prefixes to extract from the vue-script code.
|
|
7
|
+
*/
|
|
8
|
+
prefixes?: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare function splitCodeWithArbitraryVariants(code: string, prefixes: string[]): string[];
|
|
12
|
+
declare function extractor(options?: ExtractorVueScriptOptions): Extractor;
|
|
13
|
+
|
|
14
|
+
export { extractor as default, extractor, splitCodeWithArbitraryVariants };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { defaultSplitRE } from '@unocss/core';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
function generateSelectors(prefix, values) {
|
|
4
|
+
return values.filter((v) => Boolean(v) && v !== ":").map((v) => `[${prefix}~="${v}"]`);
|
|
5
|
+
}
|
|
6
|
+
function splitCodeWithArbitraryVariants(code, prefixes) {
|
|
7
|
+
const result = [];
|
|
8
|
+
for (const prefix of prefixes) {
|
|
9
|
+
const regex = new RegExp(`^\\s*${prefix}:\\s+'.*',?\\s*$`, "mg");
|
|
10
|
+
const matches = code.match(regex);
|
|
11
|
+
if (!matches)
|
|
12
|
+
continue;
|
|
13
|
+
for (const match of matches) {
|
|
14
|
+
const values = match.replace(/^.*:\s*'(.*)',?\s*$/, "$1").split(defaultSplitRE);
|
|
15
|
+
const selectors = generateSelectors(prefix, values);
|
|
16
|
+
result.push(...selectors);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function extractor(options) {
|
|
22
|
+
return {
|
|
23
|
+
name: "@una-ui/extractor-vue-script",
|
|
24
|
+
order: 0,
|
|
25
|
+
async extract({ code }) {
|
|
26
|
+
return splitCodeWithArbitraryVariants(code, options?.prefixes ?? []);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
5
30
|
|
|
6
|
-
export default
|
|
7
|
-
export const splitCodeWithArbitraryVariants = _module.splitCodeWithArbitraryVariants;
|
|
8
|
-
export const extractor = _module.extractor;
|
|
31
|
+
export { extractor as default, extractor, splitCodeWithArbitraryVariants };
|