@cssui/unplugin 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.
@@ -0,0 +1,4 @@
1
+ export declare const cssUIComponentPaths: readonly ["button", "input", "checkbox", "radio", "switch", "divider", "modal", "toast", "icon", "slider", "tabs", "carousel", "input-number", "tooltip", "select", "steps", "toolbars", "input-bar", "date-picker", "time-picker"];
2
+ export type CssUIComponentPath = (typeof cssUIComponentPaths)[number];
3
+ export declare function isCssUIComponentPath(value: string): value is CssUIComponentPath;
4
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,qOAqBtB,CAAA;AAEV,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;AAIrE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,kBAAkB,CAE/E"}
@@ -0,0 +1,26 @@
1
+ export const cssUIComponentPaths = [
2
+ 'button',
3
+ 'input',
4
+ 'checkbox',
5
+ 'radio',
6
+ 'switch',
7
+ 'divider',
8
+ 'modal',
9
+ 'toast',
10
+ 'icon',
11
+ 'slider',
12
+ 'tabs',
13
+ 'carousel',
14
+ 'input-number',
15
+ 'tooltip',
16
+ 'select',
17
+ 'steps',
18
+ 'toolbars',
19
+ 'input-bar',
20
+ 'date-picker',
21
+ 'time-picker',
22
+ ];
23
+ const cssUIComponentPathSet = new Set(cssUIComponentPaths);
24
+ export function isCssUIComponentPath(value) {
25
+ return cssUIComponentPathSet.has(value);
26
+ }
@@ -0,0 +1,12 @@
1
+ export interface CssUiUnpluginOptions {
2
+ prefix?: string;
3
+ type?: 'react' | 'vue';
4
+ importStyle?: boolean;
5
+ }
6
+ export declare const unplugin: import("unplugin").UnpluginInstance<CssUiUnpluginOptions, boolean>;
7
+ export { CssUIResolver, createResolver } from './resolver';
8
+ export type { ComponentResolveResult, CssUIComponentResolver, ComponentResolverOptions, } from './resolver';
9
+ export { cssUIComponentPaths, isCssUIComponentPath } from './components';
10
+ export type { CssUIComponentPath } from './components';
11
+ export default unplugin;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;IACtB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,eAAO,MAAM,QAAQ,oEAuBnB,CAAA;AAEF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC1D,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtD,eAAe,QAAQ,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import { createUnplugin } from 'unplugin';
2
+ export const unplugin = createUnplugin((_options = {}) => {
3
+ return {
4
+ name: '@cssui/unplugin',
5
+ enforce: 'pre',
6
+ transformInclude(id) {
7
+ return /\.[jt]sx?$/.test(id) || /\.vue$/.test(id);
8
+ },
9
+ transform(_code, _id) {
10
+ return null;
11
+ },
12
+ vite: {
13
+ config(_config) {
14
+ return {
15
+ optimizeDeps: {
16
+ include: ['@cssui/react', '@cssui/vue'],
17
+ },
18
+ };
19
+ },
20
+ },
21
+ };
22
+ });
23
+ export { CssUIResolver, createResolver } from './resolver';
24
+ export { cssUIComponentPaths, isCssUIComponentPath } from './components';
25
+ export default unplugin;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG,OAAO,GAAG,KAAK,CAAA;AASnC,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,WAAW,CAAA;IACjB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,sBAAsB,GAAG,SAAS,CAAA;CAC9D;AAkBD,wBAAgB,aAAa,CAAC,OAAO,GAAE,wBAA6B,GAAG,sBAAsB,CA+B5F;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,wBAA6B,UApDnD,MAAM,KAAK,sBAAsB,GAAG,SAAS,CAsD9D;AAED,eAAO,MAAM,aAAa,wBAA+C,CAAA;AACzE,eAAO,MAAM,WAAW,wBAA6C,CAAA;AAErE,eAAe,aAAa,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { isCssUIComponentPath } from './components';
2
+ const componentPathAliases = {
3
+ 'checkbox-group': 'checkbox',
4
+ 'radio-group': 'radio',
5
+ };
6
+ function normalizeComponentName(name) {
7
+ return name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
8
+ }
9
+ function stripPrefix(name, prefix) {
10
+ if (!prefix) {
11
+ return name;
12
+ }
13
+ if (!name.startsWith(prefix) || name.length === prefix.length) {
14
+ return undefined;
15
+ }
16
+ return name.slice(prefix.length);
17
+ }
18
+ export function CssUIResolver(options = {}) {
19
+ const { prefix = 'Css', type = 'vue', importStyle = true } = options;
20
+ return {
21
+ type: 'component',
22
+ resolve(componentName) {
23
+ const resolvedName = stripPrefix(componentName, prefix);
24
+ if (!resolvedName) {
25
+ return undefined;
26
+ }
27
+ const normalizedComponentPath = normalizeComponentName(resolvedName);
28
+ const componentPath = componentPathAliases[normalizedComponentPath] ?? normalizedComponentPath;
29
+ if (!isCssUIComponentPath(componentPath)) {
30
+ return undefined;
31
+ }
32
+ let sideEffects;
33
+ if (importStyle) {
34
+ sideEffects = [`@cssui/components/${componentPath}/style.css`];
35
+ }
36
+ return {
37
+ from: `@cssui/${type}/${componentPath}`,
38
+ name: resolvedName,
39
+ sideEffects,
40
+ };
41
+ },
42
+ };
43
+ }
44
+ export function createResolver(options = {}) {
45
+ return CssUIResolver(options).resolve;
46
+ }
47
+ export const resolverReact = CssUIResolver({ type: 'react', prefix: '' });
48
+ export const resolverVue = CssUIResolver({ type: 'vue', prefix: '' });
49
+ export default CssUIResolver;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@cssui/unplugin",
3
+ "version": "1.0.0",
4
+ "description": "周生生 UI 自动引入插件",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": ["dist"],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "dev": "tsc -p tsconfig.json --watch",
19
+ "clean": "rimraf dist"
20
+ },
21
+ "dependencies": {
22
+ "unplugin": "^1.6.0"
23
+ },
24
+ "peerDependencies": {
25
+ "vite": ">=3.0.0",
26
+ "webpack": ">=5.0.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "vite": {
30
+ "optional": true
31
+ },
32
+ "webpack": {
33
+ "optional": true
34
+ }
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^20.11.5",
38
+ "vite": "^5.0.12",
39
+ "webpack": "^5.90.1"
40
+ },
41
+ "keywords": [
42
+ "unplugin",
43
+ "auto-import",
44
+ "resolver"
45
+ ],
46
+ "author": "3lin9",
47
+ "license": "MIT"
48
+ }