@tdh-ui/unplugin-resolver 1.0.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/LICENSE +21 -0
- package/dist/index.cjs +93 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.mts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.mjs +91 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-PRESENT TDH Element Plus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function kebabCase(key) {
|
|
4
|
+
const result = key.replace(/([A-Z])/g, " $1").trim();
|
|
5
|
+
return result.split(" ").join("-").toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getSideEffects(dirName, options) {
|
|
9
|
+
const { importStyle, ssr } = options;
|
|
10
|
+
const themeFolder = "@tdh-ui/base/theme-chalk";
|
|
11
|
+
const esComponentsFolder = `@tdh-ui/base/${ssr ? "lib" : "es"}/components`;
|
|
12
|
+
if (importStyle === "sass")
|
|
13
|
+
return ssr ? [`${themeFolder}/src/base.scss`, `${themeFolder}/src/${dirName}.scss`] : [
|
|
14
|
+
`${esComponentsFolder}/base/style/index`,
|
|
15
|
+
`${esComponentsFolder}/${dirName}/style/index`
|
|
16
|
+
];
|
|
17
|
+
else if (importStyle === true || importStyle === "css")
|
|
18
|
+
return ssr ? [`${themeFolder}/base.css`, `${themeFolder}/el-${dirName}.css`] : [
|
|
19
|
+
`${esComponentsFolder}/base/style/css`,
|
|
20
|
+
`${esComponentsFolder}/${dirName}/style/css`
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
function resolveComponent(name, options) {
|
|
24
|
+
if (options.exclude && name.match(options.exclude)) return;
|
|
25
|
+
if (!/^El[A-Z]/.test(name)) return;
|
|
26
|
+
if (/^ElIcon.+/.test(name)) {
|
|
27
|
+
return {
|
|
28
|
+
name: name.replace(/^ElIcon/, ""),
|
|
29
|
+
from: "@element-plus/icons-vue"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const partialName = kebabCase(name.slice(2));
|
|
33
|
+
const { ssr } = options;
|
|
34
|
+
return {
|
|
35
|
+
name,
|
|
36
|
+
from: `@tdh-ui/base/${ssr ? "lib" : "es"}`,
|
|
37
|
+
sideEffects: getSideEffects(partialName, options)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function resolveDirective(name, options) {
|
|
41
|
+
if (!options.directives) return;
|
|
42
|
+
const directives = {
|
|
43
|
+
Loading: { importName: "ElLoadingDirective", styleName: "loading" },
|
|
44
|
+
Popover: { importName: "ElPopoverDirective", styleName: "popover" },
|
|
45
|
+
InfiniteScroll: {
|
|
46
|
+
importName: "ElInfiniteScroll",
|
|
47
|
+
styleName: "infinite-scroll"
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const directive = directives[name];
|
|
51
|
+
if (!directive) return;
|
|
52
|
+
const { ssr } = options;
|
|
53
|
+
return {
|
|
54
|
+
name: directive.importName,
|
|
55
|
+
from: `@tdh-ui/base/${ssr ? "lib" : "es"}`,
|
|
56
|
+
sideEffects: getSideEffects(directive.styleName, options)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const noStylesComponents = ["ElAutoResizer"];
|
|
60
|
+
function TdhElementPlusResolver(options = {}) {
|
|
61
|
+
let optionsResolved;
|
|
62
|
+
async function resolveOptions() {
|
|
63
|
+
if (optionsResolved) return optionsResolved;
|
|
64
|
+
optionsResolved = {
|
|
65
|
+
ssr: false,
|
|
66
|
+
importStyle: "css",
|
|
67
|
+
directives: true,
|
|
68
|
+
exclude: void 0,
|
|
69
|
+
noStylesComponents: options.noStylesComponents || [],
|
|
70
|
+
...options
|
|
71
|
+
};
|
|
72
|
+
return optionsResolved;
|
|
73
|
+
}
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
type: "component",
|
|
77
|
+
resolve: async (name) => {
|
|
78
|
+
const options2 = await resolveOptions();
|
|
79
|
+
if ([...options2.noStylesComponents, ...noStylesComponents].includes(name))
|
|
80
|
+
return resolveComponent(name, { ...options2, importStyle: false });
|
|
81
|
+
else return resolveComponent(name, options2);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: "directive",
|
|
86
|
+
resolve: async (name) => {
|
|
87
|
+
return resolveDirective(name, await resolveOptions());
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
exports.TdhElementPlusResolver = TdhElementPlusResolver;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ComponentResolver } from 'unplugin-vue-components';
|
|
2
|
+
|
|
3
|
+
interface TdhElementPlusResolverOptions {
|
|
4
|
+
/**
|
|
5
|
+
* import style css or sass with components
|
|
6
|
+
*
|
|
7
|
+
* @default 'css'
|
|
8
|
+
*/
|
|
9
|
+
importStyle?: boolean | 'css' | 'sass';
|
|
10
|
+
/**
|
|
11
|
+
* use commonjs lib & source css or scss for ssr
|
|
12
|
+
*/
|
|
13
|
+
ssr?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* auto import for directives
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
directives?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* exclude component name, if match do not resolve the name
|
|
22
|
+
*/
|
|
23
|
+
exclude?: RegExp;
|
|
24
|
+
/**
|
|
25
|
+
* a list of component names that have no styles, so resolving their styles file should be prevented
|
|
26
|
+
*/
|
|
27
|
+
noStylesComponents?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolver for Element Plus
|
|
31
|
+
*
|
|
32
|
+
* See https://github.com/antfu/vite-plugin-components/pull/28 for more details
|
|
33
|
+
* See https://github.com/antfu/vite-plugin-components/issues/117 for more details
|
|
34
|
+
*
|
|
35
|
+
* @author @develar @nabaonan @sxzz
|
|
36
|
+
* @link for @tdh-ui/base
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
declare function TdhElementPlusResolver(options?: TdhElementPlusResolverOptions): ComponentResolver[];
|
|
40
|
+
|
|
41
|
+
export { TdhElementPlusResolver };
|
|
42
|
+
export type { TdhElementPlusResolverOptions };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ComponentResolver } from 'unplugin-vue-components';
|
|
2
|
+
|
|
3
|
+
interface TdhElementPlusResolverOptions {
|
|
4
|
+
/**
|
|
5
|
+
* import style css or sass with components
|
|
6
|
+
*
|
|
7
|
+
* @default 'css'
|
|
8
|
+
*/
|
|
9
|
+
importStyle?: boolean | 'css' | 'sass';
|
|
10
|
+
/**
|
|
11
|
+
* use commonjs lib & source css or scss for ssr
|
|
12
|
+
*/
|
|
13
|
+
ssr?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* auto import for directives
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
directives?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* exclude component name, if match do not resolve the name
|
|
22
|
+
*/
|
|
23
|
+
exclude?: RegExp;
|
|
24
|
+
/**
|
|
25
|
+
* a list of component names that have no styles, so resolving their styles file should be prevented
|
|
26
|
+
*/
|
|
27
|
+
noStylesComponents?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolver for Element Plus
|
|
31
|
+
*
|
|
32
|
+
* See https://github.com/antfu/vite-plugin-components/pull/28 for more details
|
|
33
|
+
* See https://github.com/antfu/vite-plugin-components/issues/117 for more details
|
|
34
|
+
*
|
|
35
|
+
* @author @develar @nabaonan @sxzz
|
|
36
|
+
* @link for @tdh-ui/base
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
declare function TdhElementPlusResolver(options?: TdhElementPlusResolverOptions): ComponentResolver[];
|
|
40
|
+
|
|
41
|
+
export { TdhElementPlusResolver };
|
|
42
|
+
export type { TdhElementPlusResolverOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ComponentResolver } from 'unplugin-vue-components';
|
|
2
|
+
|
|
3
|
+
interface TdhElementPlusResolverOptions {
|
|
4
|
+
/**
|
|
5
|
+
* import style css or sass with components
|
|
6
|
+
*
|
|
7
|
+
* @default 'css'
|
|
8
|
+
*/
|
|
9
|
+
importStyle?: boolean | 'css' | 'sass';
|
|
10
|
+
/**
|
|
11
|
+
* use commonjs lib & source css or scss for ssr
|
|
12
|
+
*/
|
|
13
|
+
ssr?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* auto import for directives
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
directives?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* exclude component name, if match do not resolve the name
|
|
22
|
+
*/
|
|
23
|
+
exclude?: RegExp;
|
|
24
|
+
/**
|
|
25
|
+
* a list of component names that have no styles, so resolving their styles file should be prevented
|
|
26
|
+
*/
|
|
27
|
+
noStylesComponents?: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolver for Element Plus
|
|
31
|
+
*
|
|
32
|
+
* See https://github.com/antfu/vite-plugin-components/pull/28 for more details
|
|
33
|
+
* See https://github.com/antfu/vite-plugin-components/issues/117 for more details
|
|
34
|
+
*
|
|
35
|
+
* @author @develar @nabaonan @sxzz
|
|
36
|
+
* @link for @tdh-ui/base
|
|
37
|
+
*
|
|
38
|
+
*/
|
|
39
|
+
declare function TdhElementPlusResolver(options?: TdhElementPlusResolverOptions): ComponentResolver[];
|
|
40
|
+
|
|
41
|
+
export { TdhElementPlusResolver };
|
|
42
|
+
export type { TdhElementPlusResolverOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
function kebabCase(key) {
|
|
2
|
+
const result = key.replace(/([A-Z])/g, " $1").trim();
|
|
3
|
+
return result.split(" ").join("-").toLowerCase();
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function getSideEffects(dirName, options) {
|
|
7
|
+
const { importStyle, ssr } = options;
|
|
8
|
+
const themeFolder = "@tdh-ui/base/theme-chalk";
|
|
9
|
+
const esComponentsFolder = `@tdh-ui/base/${ssr ? "lib" : "es"}/components`;
|
|
10
|
+
if (importStyle === "sass")
|
|
11
|
+
return ssr ? [`${themeFolder}/src/base.scss`, `${themeFolder}/src/${dirName}.scss`] : [
|
|
12
|
+
`${esComponentsFolder}/base/style/index`,
|
|
13
|
+
`${esComponentsFolder}/${dirName}/style/index`
|
|
14
|
+
];
|
|
15
|
+
else if (importStyle === true || importStyle === "css")
|
|
16
|
+
return ssr ? [`${themeFolder}/base.css`, `${themeFolder}/el-${dirName}.css`] : [
|
|
17
|
+
`${esComponentsFolder}/base/style/css`,
|
|
18
|
+
`${esComponentsFolder}/${dirName}/style/css`
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
function resolveComponent(name, options) {
|
|
22
|
+
if (options.exclude && name.match(options.exclude)) return;
|
|
23
|
+
if (!/^El[A-Z]/.test(name)) return;
|
|
24
|
+
if (/^ElIcon.+/.test(name)) {
|
|
25
|
+
return {
|
|
26
|
+
name: name.replace(/^ElIcon/, ""),
|
|
27
|
+
from: "@element-plus/icons-vue"
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const partialName = kebabCase(name.slice(2));
|
|
31
|
+
const { ssr } = options;
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
from: `@tdh-ui/base/${ssr ? "lib" : "es"}`,
|
|
35
|
+
sideEffects: getSideEffects(partialName, options)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function resolveDirective(name, options) {
|
|
39
|
+
if (!options.directives) return;
|
|
40
|
+
const directives = {
|
|
41
|
+
Loading: { importName: "ElLoadingDirective", styleName: "loading" },
|
|
42
|
+
Popover: { importName: "ElPopoverDirective", styleName: "popover" },
|
|
43
|
+
InfiniteScroll: {
|
|
44
|
+
importName: "ElInfiniteScroll",
|
|
45
|
+
styleName: "infinite-scroll"
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const directive = directives[name];
|
|
49
|
+
if (!directive) return;
|
|
50
|
+
const { ssr } = options;
|
|
51
|
+
return {
|
|
52
|
+
name: directive.importName,
|
|
53
|
+
from: `@tdh-ui/base/${ssr ? "lib" : "es"}`,
|
|
54
|
+
sideEffects: getSideEffects(directive.styleName, options)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const noStylesComponents = ["ElAutoResizer"];
|
|
58
|
+
function TdhElementPlusResolver(options = {}) {
|
|
59
|
+
let optionsResolved;
|
|
60
|
+
async function resolveOptions() {
|
|
61
|
+
if (optionsResolved) return optionsResolved;
|
|
62
|
+
optionsResolved = {
|
|
63
|
+
ssr: false,
|
|
64
|
+
importStyle: "css",
|
|
65
|
+
directives: true,
|
|
66
|
+
exclude: void 0,
|
|
67
|
+
noStylesComponents: options.noStylesComponents || [],
|
|
68
|
+
...options
|
|
69
|
+
};
|
|
70
|
+
return optionsResolved;
|
|
71
|
+
}
|
|
72
|
+
return [
|
|
73
|
+
{
|
|
74
|
+
type: "component",
|
|
75
|
+
resolve: async (name) => {
|
|
76
|
+
const options2 = await resolveOptions();
|
|
77
|
+
if ([...options2.noStylesComponents, ...noStylesComponents].includes(name))
|
|
78
|
+
return resolveComponent(name, { ...options2, importStyle: false });
|
|
79
|
+
else return resolveComponent(name, options2);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: "directive",
|
|
84
|
+
resolve: async (name) => {
|
|
85
|
+
return resolveDirective(name, await resolveOptions());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { TdhElementPlusResolver };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tdh-ui/unplugin-resolver",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.mjs",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"unplugin-vue-components": "^0.27.4"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "~5.5.4",
|
|
26
|
+
"unbuild": "^3.0.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "unbuild",
|
|
30
|
+
"stub": "unbuild --stub",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"clean:modules": "rimraf node_modules"
|
|
33
|
+
}
|
|
34
|
+
}
|