unplugin-quicktvui 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-PRESENT Element Plus (https://github.com/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/README.md ADDED
@@ -0,0 +1,249 @@
1
+ <p align="center">
2
+ <img width="300px" src="https://user-images.githubusercontent.com/10731096/95823103-9ce15780-0d5f-11eb-8010-1bd1b5910d4f.png">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.org/package/unplugin-element-plus">
7
+ <img src="https://img.shields.io/npm/v/unplugin-element-plus.svg">
8
+ </a>
9
+ <a href="https://npmcharts.com/compare/unplugin-element-plus?minimal=true">
10
+ <img src="http://img.shields.io/npm/dm/unplugin-element-plus.svg">
11
+ </a>
12
+ <br>
13
+ </p>
14
+
15
+ # unplugin-element-plus
16
+
17
+ [![Unit Test](https://github.com/element-plus/unplugin-element-plus/actions/workflows/unit-test.yml/badge.svg)](https://github.com/element-plus/unplugin-element-plus/actions/workflows/unit-test.yml)
18
+
19
+ [English](README.md) | [中文](README.zh-CN.md)
20
+
21
+ This repo is for element-plus related [unplugin](https://github.com/unjs/unplugin). Thanks [@antfu](https://github.com/antfu).
22
+
23
+ ###### Features
24
+
25
+ - 💚 On-demand import style for Element Plus.
26
+ - 🌎 Replace default locale.
27
+ - ⚡️ Supports Vite, Webpack, Vue CLI, Rollup, esbuild and more, powered by <a href="https://github.com/unjs/unplugin">unplugin</a>.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ npm i unplugin-element-plus -D
33
+ ```
34
+
35
+ <details>
36
+ <summary>Vite</summary><br>
37
+
38
+ ```ts
39
+ // vite.config.ts
40
+ import ElementPlus from 'unplugin-element-plus/vite'
41
+
42
+ export default {
43
+ plugins: [
44
+ ElementPlus({
45
+ // options
46
+ }),
47
+ ],
48
+ }
49
+ ```
50
+
51
+ <br></details>
52
+
53
+ <details>
54
+ <summary>Rollup</summary><br>
55
+
56
+ ```ts
57
+ // rollup.config.js
58
+ import ElementPlus from 'unplugin-element-plus/rollup'
59
+
60
+ export default {
61
+ plugins: [
62
+ ElementPlus({
63
+ // options
64
+ }),
65
+ ],
66
+ }
67
+ ```
68
+
69
+ <br></details>
70
+
71
+ <details>
72
+ <summary>esbuild</summary><br>
73
+
74
+ ```ts
75
+ // esbuild.config.js
76
+ import { build } from 'esbuild'
77
+
78
+ build({
79
+ plugins: [
80
+ require('unplugin-element-plus/esbuild')({
81
+ // options
82
+ }),
83
+ ],
84
+ })
85
+ ```
86
+
87
+ <br></details>
88
+
89
+ <details>
90
+ <summary>Webpack</summary><br>
91
+
92
+ ```ts
93
+ // webpack.config.js
94
+ module.exports = {
95
+ /* ... */
96
+ plugins: [
97
+ require('unplugin-element-plus/webpack')({
98
+ // options
99
+ }),
100
+ ],
101
+ }
102
+ ```
103
+
104
+ <br></details>
105
+
106
+ <details>
107
+ <summary>Vue CLI</summary><br>
108
+
109
+ ```ts
110
+ // vue.config.js
111
+ module.exports = {
112
+ configureWebpack: {
113
+ plugins: [
114
+ require('unplugin-element-plus/webpack')({
115
+ // options
116
+ }),
117
+ ],
118
+ },
119
+ }
120
+ ```
121
+
122
+ <br></details>
123
+
124
+ ## Usage
125
+
126
+ It will automatically transform:
127
+
128
+ ```javascript
129
+ import { ElButton } from 'element-plus'
130
+
131
+ // ↓ ↓ ↓ ↓ ↓ ↓
132
+
133
+ import { ElButton } from 'element-plus'
134
+ import 'element-plus/es/components/button/style/css'
135
+ ```
136
+
137
+ ## Options
138
+
139
+ ### `useSource`
140
+
141
+ ```ts
142
+ type UseSource = boolean
143
+ ```
144
+
145
+ default: `false`
146
+
147
+ ```javascript
148
+ // useSource: false
149
+ import { ElButton } from 'element-plus'
150
+
151
+ // ↓ ↓ ↓ ↓ ↓ ↓
152
+
153
+ import { ElButton } from 'element-plus'
154
+ import 'element-plus/es/components/button/style/css'
155
+
156
+ // useSource: true
157
+ import { ElButton } from 'element-plus'
158
+
159
+ // ↓ ↓ ↓ ↓ ↓ ↓
160
+
161
+ import { ElButton } from 'element-plus'
162
+ import 'element-plus/es/components/button/style/index'
163
+ ```
164
+
165
+ ### `lib`
166
+
167
+ Normally you wouldn't use this option but as a general option we exposed it anyway.
168
+ When using this your bundle structure should be the same as ElementPlus.
169
+ See [unpkg.com](https://unpkg.com/element-plus) for more information.
170
+
171
+ ```ts
172
+ type Lib = string
173
+ ```
174
+
175
+ default: 'element-plus'
176
+
177
+ ```javascript
178
+ // lib: 'other-lib'
179
+ import { ElButton } from 'other-lib'
180
+
181
+ // ↓ ↓ ↓ ↓ ↓ ↓
182
+
183
+ import { ElButton } from 'other-lib'
184
+ import 'other-lib/es/components/button/style/css'
185
+ ```
186
+
187
+ ### `format`
188
+
189
+ ```ts
190
+ type Format = 'esm' | 'cjs'
191
+ ```
192
+
193
+ default: 'esm'
194
+
195
+ `esm` for `element-plus/es/components/*`
196
+
197
+ `cjs` for `element-plus/lib/components/*`
198
+
199
+ - `/es` for ES Module
200
+ - `/lib` for CommonJS
201
+
202
+ This option is for which format to use
203
+
204
+ ```javascript
205
+ // format: 'cjs'
206
+ import { ElButton } from 'element-plus'
207
+
208
+ // ↓ ↓ ↓ ↓ ↓ ↓
209
+
210
+ import { ElButton } from 'element-plus'
211
+ import 'element-plus/lib/components/button/style/css'
212
+ ```
213
+
214
+ ### `prefix`
215
+
216
+ ```ts
217
+ type Prefix = string
218
+ ```
219
+
220
+ ```javascript
221
+ // prefix = Al
222
+ import { AlButton } from 'xx-lib'
223
+ ```
224
+
225
+ ### `ignoreComponents`
226
+
227
+ ```ts
228
+ type IgnoreComponents = string[]
229
+ ```
230
+
231
+ Skip style imports for a list of components. Useful for Element Plus components which do not have a style file.
232
+ At the time of writing, this is only the `AutoResizer` component.
233
+
234
+ ```javascript
235
+ // format: 'cjs'
236
+ import { ElAutoResizer } from 'element-plus'
237
+
238
+ // ↓ ↓ ↓ ↓ ↓ ↓
239
+
240
+ import { ElAutoResizer } from 'element-plus'
241
+ ```
242
+
243
+ ### `defaultLocale`
244
+
245
+ Replace default locale, you can find locale list [here](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang).
246
+
247
+ ## Alternate
248
+
249
+ - [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components)
@@ -0,0 +1,245 @@
1
+ <p align="center">
2
+ <img width="300px" src="https://user-images.githubusercontent.com/10731096/95823103-9ce15780-0d5f-11eb-8010-1bd1b5910d4f.png">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://www.npmjs.org/package/unplugin-element-plus">
7
+ <img src="https://img.shields.io/npm/v/unplugin-element-plus.svg">
8
+ </a>
9
+ <a href="https://npmcharts.com/compare/unplugin-element-plus?minimal=true">
10
+ <img src="http://img.shields.io/npm/dm/unplugin-element-plus.svg">
11
+ </a>
12
+ <br>
13
+ </p>
14
+
15
+ # unplugin-element-plus
16
+
17
+ [![Unit Test](https://github.com/element-plus/unplugin-element-plus/actions/workflows/unit-test.yml/badge.svg)](https://github.com/element-plus/unplugin-element-plus/actions/workflows/unit-test.yml)
18
+
19
+ [English](README.md) | [中文](README.zh-CN.md)
20
+
21
+ 这个仓库是用于 `Element Plus` 相关的 [unplugin](https://github.com/unjs/unplugin) 插件工具。感谢 [@antfu](https://github.com/antfu)。
22
+
23
+ ###### 功能
24
+
25
+ - 💚 为 Element Plus 按需引入样式。
26
+ - 🌎 替换默认语言。
27
+ - ⚡️ 使用 <a href="https://github.com/unjs/unplugin">unplugin</a> 以支持 Vite, Webpack, Vue CLI, Rollup, esbuild 等。
28
+
29
+ ## 安装
30
+
31
+ ```bash
32
+ npm i unplugin-element-plus -D
33
+ ```
34
+
35
+ <details>
36
+ <summary>Vite</summary><br>
37
+
38
+ ```ts
39
+ // vite.config.ts
40
+ import ElementPlus from 'unplugin-element-plus/vite'
41
+
42
+ export default {
43
+ plugins: [
44
+ ElementPlus({
45
+ // options
46
+ }),
47
+ ],
48
+ }
49
+ ```
50
+
51
+ <br></details>
52
+
53
+ <details>
54
+ <summary>Rollup</summary><br>
55
+
56
+ ```ts
57
+ // rollup.config.js
58
+ import ElementPlus from 'unplugin-element-plus/rollup'
59
+
60
+ export default {
61
+ plugins: [
62
+ ElementPlus({
63
+ // options
64
+ }),
65
+ ],
66
+ }
67
+ ```
68
+
69
+ <br></details>
70
+
71
+ <details>
72
+ <summary>esbuild</summary><br>
73
+
74
+ ```ts
75
+ // esbuild.config.js
76
+ import { build } from 'esbuild'
77
+
78
+ build({
79
+ plugins: [
80
+ require('unplugin-element-plus/esbuild')({
81
+ // options
82
+ }),
83
+ ],
84
+ })
85
+ ```
86
+
87
+ <br></details>
88
+
89
+ <details>
90
+ <summary>Webpack</summary><br>
91
+
92
+ ```ts
93
+ // webpack.config.js
94
+ module.exports = {
95
+ /* ... */
96
+ plugins: [
97
+ require('unplugin-element-plus/webpack')({
98
+ // options
99
+ }),
100
+ ],
101
+ }
102
+ ```
103
+
104
+ <br></details>
105
+
106
+ <details>
107
+ <summary>Vue CLI</summary><br>
108
+
109
+ ```ts
110
+ // vue.config.js
111
+ module.exports = {
112
+ configureWebpack: {
113
+ plugins: [
114
+ require('unplugin-element-plus/webpack')({
115
+ // options
116
+ }),
117
+ ],
118
+ },
119
+ }
120
+ ```
121
+
122
+ <br></details>
123
+
124
+ ## 使用
125
+
126
+ 插件会自动转换:
127
+
128
+ ```javascript
129
+ import { ElButton } from 'element-plus'
130
+
131
+ // ↓ ↓ ↓ ↓ ↓ ↓
132
+
133
+ import { ElButton } from 'element-plus'
134
+ import 'element-plus/es/components/button/style/css'
135
+ ```
136
+
137
+ ## 选项
138
+
139
+ ### `useSource`
140
+
141
+ ```ts
142
+ type UseSource = boolean
143
+ ```
144
+
145
+ ```javascript
146
+ // useSource: false
147
+ import { ElButton } from 'element-plus'
148
+
149
+ // ↓ ↓ ↓ ↓ ↓ ↓
150
+
151
+ import { ElButton } from 'element-plus'
152
+ import 'element-plus/es/components/button/style/css'
153
+
154
+ // useSource: true
155
+ import { ElButton } from 'element-plus'
156
+
157
+ // ↓ ↓ ↓ ↓ ↓ ↓
158
+
159
+ import { ElButton } from 'element-plus'
160
+ import 'element-plus/es/components/button/style/index'
161
+ ```
162
+
163
+ ### `lib`
164
+
165
+ 一般这个是用不到的,不过作为一个通用选项,还是暴露了出来,如果有用到这个的结构一定要和
166
+ ElementPlus 的输出包结构一致,详见 [unpkg.com](https://unpkg.com/element-plus)
167
+
168
+ ```ts
169
+ type Lib = string
170
+ ```
171
+
172
+ default: 'element-plus'
173
+
174
+ ```javascript
175
+ // lib: 'other-lib'
176
+ import { ElButton } from 'other-lib'
177
+
178
+ // ↓ ↓ ↓ ↓ ↓ ↓
179
+
180
+ import { ElButton } from 'other-lib'
181
+ import 'other-lib/es/components/button/style/css'
182
+ ```
183
+
184
+ ### format
185
+
186
+ ```ts
187
+ type Format = 'esm' | 'cjs'
188
+ ```
189
+
190
+ default: 'esm'
191
+
192
+ `esm` 对应 `[lib]/es/components/*`
193
+
194
+ `cjs` 对应 `[lib]/lib/components/*`
195
+
196
+ - `/es` 对应 ES Module 输出
197
+ - `/lib` 对应 CommonJS 的输出
198
+
199
+ 使用该选项来选择使用哪一个包。
200
+
201
+ ```javascript
202
+ // format: 'cjs'
203
+ import { ElButton } from 'element-plus'
204
+
205
+ // ↓ ↓ ↓ ↓ ↓ ↓
206
+
207
+ import { ElButton } from 'element-plus'
208
+ import 'element-plus/lib/components/button/style/css'
209
+ ```
210
+
211
+ ### prefix
212
+
213
+ ```ts
214
+ type Prefix = string
215
+ ```
216
+
217
+ ```javascript
218
+ // prefix = Al
219
+ import { AlButton } from 'xx-lib'
220
+ ```
221
+ ### `ignoreComponents`
222
+
223
+ ```ts
224
+ type IgnoreComponents = string[]
225
+ ```
226
+
227
+ 跳过组件列表的样式导入。 对于没有样式文件的 Element Plus 组件很有用。
228
+ 在编写此文档时,仅有“AutoResizer”组件。
229
+
230
+ ```javascript
231
+ // format: 'cjs'
232
+ import { ElAutoResizer } from 'element-plus'
233
+
234
+ // ↓ ↓ ↓ ↓ ↓ ↓
235
+
236
+ import { ElAutoResizer } from 'element-plus'
237
+ ```
238
+
239
+ ### `defaultLocale`
240
+
241
+ 替换默认语言,你可以 [在这](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang) 查看所有语言列表。
242
+
243
+ ## 其他插件
244
+
245
+ - [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components)
@@ -0,0 +1,188 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/index.ts
2
+ var _pluginutils = require('@rollup/pluginutils');
3
+ var _unplugin = require('unplugin');
4
+
5
+ // src/core/style.ts
6
+ var _esmodulelexer = require('es-module-lexer');
7
+ var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
8
+ var hyphenateRE = /\B([A-Z])/g;
9
+ var hyphenate = (str) => str.replaceAll(hyphenateRE, "-$1").toLowerCase();
10
+ var formatMap = {
11
+ cjs: "lib",
12
+ esm: "es"
13
+ };
14
+ var multilineCommentsRE = /\/\*\s(.|[\n\r])*?\*\//gm;
15
+ var singlelineCommentsRE = /\/\/\s.*/g;
16
+ function stripeComments(code) {
17
+ return code.replaceAll(multilineCommentsRE, "").replaceAll(singlelineCommentsRE, "");
18
+ }
19
+ var transformImportStyle = (specifier, source, useSource = false, options) => {
20
+ const { prefix, lib, format, ignoreComponents } = options;
21
+ const statement = stripeComments(source.slice(specifier.ss, specifier.se));
22
+ const leftBracket = statement.indexOf("{");
23
+ if (leftBracket > -1) {
24
+ const identifiers = statement.slice(leftBracket + 1, statement.indexOf("}"));
25
+ const components = identifiers.split(",");
26
+ const styleImports = [];
27
+ components.forEach((c) => {
28
+ const trimmed = c.replace(/\sas\s.+/, "").trim();
29
+ if (trimmed.startsWith(prefix)) {
30
+ const component = trimmed.slice(prefix.length);
31
+ if (ignoreComponents.includes(component))
32
+ return;
33
+ if (useSource) {
34
+ styleImports.push(
35
+ `import '${lib}/${formatMap[format]}/components/${hyphenate(
36
+ component
37
+ )}/style/index'`
38
+ );
39
+ } else {
40
+ styleImports.push(
41
+ `import '${lib}/${formatMap[format]}/components/${hyphenate(
42
+ component
43
+ )}/style/css'`
44
+ );
45
+ }
46
+ }
47
+ });
48
+ return styleImports.join("\n");
49
+ }
50
+ };
51
+ var transformStyle = async (source, options) => {
52
+ const { useSource, lib, prefix, format, ignoreComponents } = options;
53
+ if (!source)
54
+ return;
55
+ await _esmodulelexer.init;
56
+ const specifiers = _esmodulelexer.parse.call(void 0, source)[0].filter(({ n }) => {
57
+ return n === lib || n === `${lib}/es/components` || n === `${lib}/lib/components`;
58
+ });
59
+ if (specifiers.length === 0)
60
+ return;
61
+ const styleImports = specifiers.map((s2) => {
62
+ const ret = transformImportStyle(s2, source, useSource, {
63
+ lib,
64
+ prefix,
65
+ format,
66
+ ignoreComponents
67
+ });
68
+ return ret;
69
+ }).filter((s2) => s2).join("\n");
70
+ const lastSpecifier = specifiers.at(-1);
71
+ const s = new (0, _magicstring2.default)(source);
72
+ s.appendLeft(lastSpecifier.se + 1, `
73
+ ${styleImports}
74
+ `);
75
+ return {
76
+ code: s.toString(),
77
+ get map() {
78
+ return s.generateMap({ hires: true, includeContent: true });
79
+ }
80
+ };
81
+ };
82
+
83
+ // node_modules/escape-string-regexp/index.js
84
+ function escapeStringRegexp(string) {
85
+ if (typeof string !== "string") {
86
+ throw new TypeError("Expected a string");
87
+ }
88
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
89
+ }
90
+
91
+ // src/core/default-locale.ts
92
+ var getLocaleRE = (options) => new RegExp(
93
+ `${escapeStringRegexp(`${options.lib}/`)}(es|lib)${escapeStringRegexp(
94
+ "/hooks/use-locale/index"
95
+ )}`
96
+ );
97
+ var transformDefaultLocale = (options, source, id) => {
98
+ if (!id.match(getLocaleRE(options)))
99
+ return;
100
+ return source.replace(
101
+ "locale/lang/en",
102
+ `locale/lang/${options.defaultLocale}`
103
+ );
104
+ };
105
+ var getViteDepPlugin = (options) => {
106
+ const localeImporterRE = new RegExp(
107
+ `${escapeStringRegexp(
108
+ `node_modules/${options.lib}/`
109
+ )}(es|lib)${escapeStringRegexp("/hooks/use-locale/index")}`
110
+ );
111
+ const localePath = "/locale/lang/en";
112
+ const localePathFixed = `/locale/lang/${options.defaultLocale}`;
113
+ return {
114
+ name: "unplugin-quicktvui:default-locale",
115
+ setup(build) {
116
+ build.onResolve(
117
+ {
118
+ filter: new RegExp(escapeStringRegexp(localePath)),
119
+ namespace: "file"
120
+ },
121
+ ({ path, importer, kind, resolveDir }) => {
122
+ if (localeImporterRE.test(importer))
123
+ return build.resolve(path.replace(localePath, localePathFixed), {
124
+ importer,
125
+ kind,
126
+ resolveDir
127
+ });
128
+ }
129
+ );
130
+ }
131
+ };
132
+ };
133
+
134
+ // src/index.ts
135
+ var defaultOptions = {
136
+ include: [
137
+ "**/*.vue",
138
+ "**/*.ts",
139
+ "**/*.js",
140
+ "**/*.tsx",
141
+ "**/*.jsx",
142
+ "**/*.vue?vue&type=script*"
143
+ ],
144
+ exclude: [/[/\\]node_modules[/\\]/, /[/\\]\.git[/\\]/, /[/\\]\.nuxt[/\\]/],
145
+ lib: "quicktvui",
146
+ ignoreComponents: [],
147
+ useSource: false,
148
+ defaultLocale: "",
149
+ format: "esm",
150
+ prefix: "El",
151
+ sourceMap: false
152
+ };
153
+ var src_default = _unplugin.createUnplugin.call(void 0, (userOptions = {}) => {
154
+ const options = Object.assign(defaultOptions, userOptions);
155
+ const filter = _pluginutils.createFilter.call(void 0, options.include, options.exclude);
156
+ return {
157
+ name: "unplugin-quicktvui",
158
+ enforce: "post",
159
+ transformInclude(id) {
160
+ return getLocaleRE(options).test(id) || filter(id);
161
+ },
162
+ transform(source, id) {
163
+ if (options.defaultLocale) {
164
+ const result = transformDefaultLocale(options, source, id);
165
+ if (result)
166
+ return result;
167
+ }
168
+ return transformStyle(source, options);
169
+ },
170
+ vite: {
171
+ config() {
172
+ if (options.defaultLocale) {
173
+ return {
174
+ optimizeDeps: {
175
+ esbuildOptions: {
176
+ plugins: [getViteDepPlugin(options)]
177
+ }
178
+ }
179
+ };
180
+ }
181
+ }
182
+ }
183
+ };
184
+ });
185
+
186
+
187
+
188
+ exports.src_default = src_default;
@@ -0,0 +1,188 @@
1
+ // src/index.ts
2
+ import { createFilter } from "@rollup/pluginutils";
3
+ import { createUnplugin } from "unplugin";
4
+
5
+ // src/core/style.ts
6
+ import { init, parse } from "es-module-lexer";
7
+ import MagicString from "magic-string";
8
+ var hyphenateRE = /\B([A-Z])/g;
9
+ var hyphenate = (str) => str.replaceAll(hyphenateRE, "-$1").toLowerCase();
10
+ var formatMap = {
11
+ cjs: "lib",
12
+ esm: "es"
13
+ };
14
+ var multilineCommentsRE = /\/\*\s(.|[\n\r])*?\*\//gm;
15
+ var singlelineCommentsRE = /\/\/\s.*/g;
16
+ function stripeComments(code) {
17
+ return code.replaceAll(multilineCommentsRE, "").replaceAll(singlelineCommentsRE, "");
18
+ }
19
+ var transformImportStyle = (specifier, source, useSource = false, options) => {
20
+ const { prefix, lib, format, ignoreComponents } = options;
21
+ const statement = stripeComments(source.slice(specifier.ss, specifier.se));
22
+ const leftBracket = statement.indexOf("{");
23
+ if (leftBracket > -1) {
24
+ const identifiers = statement.slice(leftBracket + 1, statement.indexOf("}"));
25
+ const components = identifiers.split(",");
26
+ const styleImports = [];
27
+ components.forEach((c) => {
28
+ const trimmed = c.replace(/\sas\s.+/, "").trim();
29
+ if (trimmed.startsWith(prefix)) {
30
+ const component = trimmed.slice(prefix.length);
31
+ if (ignoreComponents.includes(component))
32
+ return;
33
+ if (useSource) {
34
+ styleImports.push(
35
+ `import '${lib}/${formatMap[format]}/components/${hyphenate(
36
+ component
37
+ )}/style/index'`
38
+ );
39
+ } else {
40
+ styleImports.push(
41
+ `import '${lib}/${formatMap[format]}/components/${hyphenate(
42
+ component
43
+ )}/style/css'`
44
+ );
45
+ }
46
+ }
47
+ });
48
+ return styleImports.join("\n");
49
+ }
50
+ };
51
+ var transformStyle = async (source, options) => {
52
+ const { useSource, lib, prefix, format, ignoreComponents } = options;
53
+ if (!source)
54
+ return;
55
+ await init;
56
+ const specifiers = parse(source)[0].filter(({ n }) => {
57
+ return n === lib || n === `${lib}/es/components` || n === `${lib}/lib/components`;
58
+ });
59
+ if (specifiers.length === 0)
60
+ return;
61
+ const styleImports = specifiers.map((s2) => {
62
+ const ret = transformImportStyle(s2, source, useSource, {
63
+ lib,
64
+ prefix,
65
+ format,
66
+ ignoreComponents
67
+ });
68
+ return ret;
69
+ }).filter((s2) => s2).join("\n");
70
+ const lastSpecifier = specifiers.at(-1);
71
+ const s = new MagicString(source);
72
+ s.appendLeft(lastSpecifier.se + 1, `
73
+ ${styleImports}
74
+ `);
75
+ return {
76
+ code: s.toString(),
77
+ get map() {
78
+ return s.generateMap({ hires: true, includeContent: true });
79
+ }
80
+ };
81
+ };
82
+
83
+ // node_modules/escape-string-regexp/index.js
84
+ function escapeStringRegexp(string) {
85
+ if (typeof string !== "string") {
86
+ throw new TypeError("Expected a string");
87
+ }
88
+ return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
89
+ }
90
+
91
+ // src/core/default-locale.ts
92
+ var getLocaleRE = (options) => new RegExp(
93
+ `${escapeStringRegexp(`${options.lib}/`)}(es|lib)${escapeStringRegexp(
94
+ "/hooks/use-locale/index"
95
+ )}`
96
+ );
97
+ var transformDefaultLocale = (options, source, id) => {
98
+ if (!id.match(getLocaleRE(options)))
99
+ return;
100
+ return source.replace(
101
+ "locale/lang/en",
102
+ `locale/lang/${options.defaultLocale}`
103
+ );
104
+ };
105
+ var getViteDepPlugin = (options) => {
106
+ const localeImporterRE = new RegExp(
107
+ `${escapeStringRegexp(
108
+ `node_modules/${options.lib}/`
109
+ )}(es|lib)${escapeStringRegexp("/hooks/use-locale/index")}`
110
+ );
111
+ const localePath = "/locale/lang/en";
112
+ const localePathFixed = `/locale/lang/${options.defaultLocale}`;
113
+ return {
114
+ name: "unplugin-quicktvui:default-locale",
115
+ setup(build) {
116
+ build.onResolve(
117
+ {
118
+ filter: new RegExp(escapeStringRegexp(localePath)),
119
+ namespace: "file"
120
+ },
121
+ ({ path, importer, kind, resolveDir }) => {
122
+ if (localeImporterRE.test(importer))
123
+ return build.resolve(path.replace(localePath, localePathFixed), {
124
+ importer,
125
+ kind,
126
+ resolveDir
127
+ });
128
+ }
129
+ );
130
+ }
131
+ };
132
+ };
133
+
134
+ // src/index.ts
135
+ var defaultOptions = {
136
+ include: [
137
+ "**/*.vue",
138
+ "**/*.ts",
139
+ "**/*.js",
140
+ "**/*.tsx",
141
+ "**/*.jsx",
142
+ "**/*.vue?vue&type=script*"
143
+ ],
144
+ exclude: [/[/\\]node_modules[/\\]/, /[/\\]\.git[/\\]/, /[/\\]\.nuxt[/\\]/],
145
+ lib: "quicktvui",
146
+ ignoreComponents: [],
147
+ useSource: false,
148
+ defaultLocale: "",
149
+ format: "esm",
150
+ prefix: "El",
151
+ sourceMap: false
152
+ };
153
+ var src_default = createUnplugin((userOptions = {}) => {
154
+ const options = Object.assign(defaultOptions, userOptions);
155
+ const filter = createFilter(options.include, options.exclude);
156
+ return {
157
+ name: "unplugin-quicktvui",
158
+ enforce: "post",
159
+ transformInclude(id) {
160
+ return getLocaleRE(options).test(id) || filter(id);
161
+ },
162
+ transform(source, id) {
163
+ if (options.defaultLocale) {
164
+ const result = transformDefaultLocale(options, source, id);
165
+ if (result)
166
+ return result;
167
+ }
168
+ return transformStyle(source, options);
169
+ },
170
+ vite: {
171
+ config() {
172
+ if (options.defaultLocale) {
173
+ return {
174
+ optimizeDeps: {
175
+ esbuildOptions: {
176
+ plugins: [getViteDepPlugin(options)]
177
+ }
178
+ }
179
+ };
180
+ }
181
+ }
182
+ }
183
+ };
184
+ });
185
+
186
+ export {
187
+ src_default
188
+ };
@@ -0,0 +1,7 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: (options: Partial<Options>) => esbuild.Plugin;
6
+
7
+ export { _default as default };
@@ -0,0 +1,7 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: (options: Partial<Options>) => esbuild.Plugin;
6
+
7
+ export = _default;
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2E2E54E7js = require('./chunk-2E2E54E7.js');
4
+
5
+ // src/esbuild.ts
6
+ var esbuild_default = _chunk2E2E54E7js.src_default.esbuild;
7
+
8
+
9
+ exports.default = esbuild_default;
10
+
11
+ module.exports = exports.default;
@@ -0,0 +1,9 @@
1
+ import {
2
+ src_default
3
+ } from "./chunk-UGLK7JWU.mjs";
4
+
5
+ // src/esbuild.ts
6
+ var esbuild_default = src_default.esbuild;
7
+ export {
8
+ esbuild_default as default
9
+ };
@@ -0,0 +1,7 @@
1
+ import * as unplugin from 'unplugin';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: unplugin.UnpluginInstance<Partial<Options>, boolean>;
6
+
7
+ export { Options, _default as default };
@@ -0,0 +1,7 @@
1
+ import * as unplugin from 'unplugin';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: unplugin.UnpluginInstance<Partial<Options>, boolean>;
6
+
7
+ export { Options, _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2E2E54E7js = require('./chunk-2E2E54E7.js');
4
+
5
+
6
+ exports.default = _chunk2E2E54E7js.src_default;
7
+
8
+ module.exports = exports.default;
package/dist/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ src_default
3
+ } from "./chunk-UGLK7JWU.mjs";
4
+ export {
5
+ src_default as default
6
+ };
@@ -0,0 +1,6 @@
1
+ import { O as Options } from './types-oZBgfVRA.js';
2
+ import '@rollup/pluginutils';
3
+
4
+ declare function export_default(this: any, options: Options): void;
5
+
6
+ export { export_default as default };
package/dist/nuxt.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { O as Options } from './types-oZBgfVRA.js';
2
+ import '@rollup/pluginutils';
3
+
4
+ declare function export_default(this: any, options: Options): void;
5
+
6
+ export = export_default;
package/dist/nuxt.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2E2E54E7js = require('./chunk-2E2E54E7.js');
4
+
5
+ // src/nuxt.ts
6
+ function nuxt_default(options) {
7
+ this.extendBuild((config) => {
8
+ config.plugins = config.plugins || [];
9
+ config.plugins.unshift(_chunk2E2E54E7js.src_default.webpack(options));
10
+ });
11
+ this.nuxt.hook("vite:extend", (vite) => {
12
+ vite.config.plugins = vite.config.plugins || [];
13
+ vite.config.plugins.push(_chunk2E2E54E7js.src_default.vite(options));
14
+ });
15
+ }
16
+
17
+
18
+ exports.default = nuxt_default;
19
+
20
+ module.exports = exports.default;
package/dist/nuxt.mjs ADDED
@@ -0,0 +1,18 @@
1
+ import {
2
+ src_default
3
+ } from "./chunk-UGLK7JWU.mjs";
4
+
5
+ // src/nuxt.ts
6
+ function nuxt_default(options) {
7
+ this.extendBuild((config) => {
8
+ config.plugins = config.plugins || [];
9
+ config.plugins.unshift(src_default.webpack(options));
10
+ });
11
+ this.nuxt.hook("vite:extend", (vite) => {
12
+ vite.config.plugins = vite.config.plugins || [];
13
+ vite.config.plugins.push(src_default.vite(options));
14
+ });
15
+ }
16
+ export {
17
+ nuxt_default as default
18
+ };
@@ -0,0 +1,7 @@
1
+ import * as rollup from 'rollup';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: (options: Partial<Options>) => rollup.Plugin<any> | rollup.Plugin<any>[];
6
+
7
+ export { _default as default };
@@ -0,0 +1,7 @@
1
+ import * as rollup from 'rollup';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: (options: Partial<Options>) => rollup.Plugin<any> | rollup.Plugin<any>[];
6
+
7
+ export = _default;
package/dist/rollup.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2E2E54E7js = require('./chunk-2E2E54E7.js');
4
+
5
+ // src/rollup.ts
6
+ var rollup_default = _chunk2E2E54E7js.src_default.rollup;
7
+
8
+
9
+ exports.default = rollup_default;
10
+
11
+ module.exports = exports.default;
@@ -0,0 +1,9 @@
1
+ import {
2
+ src_default
3
+ } from "./chunk-UGLK7JWU.mjs";
4
+
5
+ // src/rollup.ts
6
+ var rollup_default = src_default.rollup;
7
+ export {
8
+ rollup_default as default
9
+ };
@@ -0,0 +1,27 @@
1
+ import { FilterPattern } from '@rollup/pluginutils';
2
+
3
+ type Options = {
4
+ /**
5
+ * RegExp or glob to match files to be transformed
6
+ */
7
+ include: FilterPattern;
8
+ /**
9
+ * RegExp or glob to match files to NOT be transformed
10
+ */
11
+ exclude: FilterPattern;
12
+ useSource: boolean;
13
+ /** replace default locale */
14
+ defaultLocale: string;
15
+ /**
16
+ * Array of component names that will not be transformed.
17
+ * Can be useful for components that do not have an associated style file.
18
+ * Do not include the prefix in the name.
19
+ */
20
+ ignoreComponents: string[];
21
+ lib: string;
22
+ prefix: string;
23
+ format: 'cjs' | 'esm';
24
+ sourceMap: boolean;
25
+ };
26
+
27
+ export type { Options as O };
@@ -0,0 +1,7 @@
1
+ import * as vite from 'vite';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: (options: Partial<Options>) => vite.Plugin | vite.Plugin[];
6
+
7
+ export { _default as default };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import * as vite from 'vite';
2
+ import { O as Options } from './types-oZBgfVRA.js';
3
+ import '@rollup/pluginutils';
4
+
5
+ declare const _default: (options: Partial<Options>) => vite.Plugin | vite.Plugin[];
6
+
7
+ export = _default;
package/dist/vite.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2E2E54E7js = require('./chunk-2E2E54E7.js');
4
+
5
+ // src/vite.ts
6
+ var vite_default = _chunk2E2E54E7js.src_default.vite;
7
+
8
+
9
+ exports.default = vite_default;
10
+
11
+ module.exports = exports.default;
package/dist/vite.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ src_default
3
+ } from "./chunk-UGLK7JWU.mjs";
4
+
5
+ // src/vite.ts
6
+ var vite_default = src_default.vite;
7
+ export {
8
+ vite_default as default
9
+ };
@@ -0,0 +1,6 @@
1
+ import { O as Options } from './types-oZBgfVRA.js';
2
+ import '@rollup/pluginutils';
3
+
4
+ declare const _default: (options: Partial<Options>) => WebpackPluginInstance;
5
+
6
+ export { _default as default };
@@ -0,0 +1,6 @@
1
+ import { O as Options } from './types-oZBgfVRA.js';
2
+ import '@rollup/pluginutils';
3
+
4
+ declare const _default: (options: Partial<Options>) => WebpackPluginInstance;
5
+
6
+ export = _default;
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2E2E54E7js = require('./chunk-2E2E54E7.js');
4
+
5
+ // src/webpack.ts
6
+ var webpack_default = _chunk2E2E54E7js.src_default.webpack;
7
+
8
+
9
+ exports.default = webpack_default;
10
+
11
+ module.exports = exports.default;
@@ -0,0 +1,9 @@
1
+ import {
2
+ src_default
3
+ } from "./chunk-UGLK7JWU.mjs";
4
+
5
+ // src/webpack.ts
6
+ var webpack_default = src_default.webpack;
7
+ export {
8
+ webpack_default as default
9
+ };
package/package.json ADDED
@@ -0,0 +1,130 @@
1
+ {
2
+ "name": "unplugin-quicktvui",
3
+ "version": "0.0.1",
4
+ "packageManager": "pnpm@8.6.6",
5
+ "keywords": [
6
+ "element-plus",
7
+ "unplugin",
8
+ "vite",
9
+ "webpack",
10
+ "rollup",
11
+ "esbuild",
12
+ "plugin"
13
+ ],
14
+ "homepage": "https://github.com/element-plus/unplugin-element-plus/tree/main/#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/element-plus/unplugin-element-plus/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/element-plus/unplugin-element-plus"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "main": "dist/index.js",
26
+ "module": "dist/index.mjs",
27
+ "types": "dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": {
31
+ "require": "./dist/index.d.ts",
32
+ "import": "./dist/index.d.mts"
33
+ },
34
+ "require": "./dist/index.js",
35
+ "import": "./dist/index.mjs"
36
+ },
37
+ "./vite": {
38
+ "types": {
39
+ "require": "./dist/vite.d.ts",
40
+ "import": "./dist/vite.d.mts"
41
+ },
42
+ "require": "./dist/vite.js",
43
+ "import": "./dist/vite.mjs"
44
+ },
45
+ "./webpack": {
46
+ "types": {
47
+ "require": "./dist/webpack.d.ts",
48
+ "import": "./dist/webpack.d.mts"
49
+ },
50
+ "require": "./dist/webpack.js",
51
+ "import": "./dist/webpack.mjs"
52
+ },
53
+ "./rollup": {
54
+ "types": {
55
+ "require": "./dist/rollup.d.ts",
56
+ "import": "./dist/rollup.d.mts"
57
+ },
58
+ "require": "./dist/rollup.js",
59
+ "import": "./dist/rollup.mjs"
60
+ },
61
+ "./esbuild": {
62
+ "types": {
63
+ "require": "./dist/esbuild.d.ts",
64
+ "import": "./dist/esbuild.d.mts"
65
+ },
66
+ "require": "./dist/esbuild.js",
67
+ "import": "./dist/esbuild.mjs"
68
+ },
69
+ "./nuxt": {
70
+ "types": {
71
+ "require": "./dist/nuxt.d.ts",
72
+ "import": "./dist/nuxt.d.mts"
73
+ },
74
+ "require": "./dist/nuxt.js",
75
+ "import": "./dist/nuxt.mjs"
76
+ },
77
+ "./*": "./*"
78
+ },
79
+ "typesVersions": {
80
+ "*": {
81
+ "*": [
82
+ "./dist/*",
83
+ "./*"
84
+ ]
85
+ }
86
+ },
87
+ "publishConfig": {
88
+ "access": "public"
89
+ },
90
+ "scripts": {
91
+ "lint": "eslint .",
92
+ "lint:fix": "pnpm run lint --fix",
93
+ "build": "tsup",
94
+ "build:examples": "pnpm --filter \"./examples/*\" build",
95
+ "dev": "tsup --watch",
96
+ "release": "bumpp",
97
+ "vite:build": "npm -C examples/vite run build",
98
+ "vite:dev": "npm -C examples/vite run dev",
99
+ "test": "vitest"
100
+ },
101
+ "dependencies": {
102
+ "@rollup/pluginutils": "^5.0.2",
103
+ "es-module-lexer": "^1.3.0",
104
+ "magic-string": "^0.30.1",
105
+ "unplugin": "^1.3.2"
106
+ },
107
+ "devDependencies": {
108
+ "@sxzz/eslint-config": "^3.1.0",
109
+ "@sxzz/prettier-config": "^1.0.3",
110
+ "@types/node": "^20.4.0",
111
+ "@vitest/ui": "^0.33.0",
112
+ "bumpp": "^9.1.1",
113
+ "esbuild": "~0.18.11",
114
+ "escape-string-regexp": "^5.0.0",
115
+ "eslint": "^8.44.0",
116
+ "fast-glob": "^3.3.0",
117
+ "prettier": "^3.0.0",
118
+ "rollup": "^3.26.2",
119
+ "rollup-plugin-esbuild": "^5.0.0",
120
+ "tsup": "^7.2.0",
121
+ "tsx": "^3.12.7",
122
+ "typescript": "^5.1.6",
123
+ "vite": "^4.4.1",
124
+ "vitest": "^0.33.0"
125
+ },
126
+ "engines": {
127
+ "node": ">=14.19.0"
128
+ },
129
+ "prettier": "@sxzz/prettier-config"
130
+ }