@maple-design/resolver-vue 0.0.0-stage → 1.1.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/README.md CHANGED
@@ -1,3 +1,153 @@
1
- # Temporary Holding Version
1
+ # Maple Resolver
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ `@maple-design/resolver-vue` is a resolver for [unplugin-vue-components](https://github.com/unplugin/unplugin-vue-components) that enables on-demand importing of Maple components.
6
+
7
+ ## Features
8
+
9
+ - Supports `Vite`, `Webpack`, `Vue CLI`, `Rollup`, `esbuild`, and more.
10
+ - Automatically imports the corresponding CSS styles for the components.
11
+ - Supports SSR (Server-Side Rendering).
12
+
13
+ ## Automatic Import
14
+
15
+ via plugin
16
+ [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) and
17
+ [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
18
+ Implement components to automatically import on demand, This is our most recommended way.
19
+
20
+ ### Install Plugin
21
+
22
+ ```shell
23
+ # npm
24
+ npm i @maple-design/resolver-vue unplugin-vue-components unplugin-auto-import -D
25
+
26
+ # yarn
27
+ yarn add @maple-design/resolver-vue unplugin-vue-components unplugin-auto-import -D
28
+
29
+ # pnpm
30
+ pnpm add @maple-design/resolver-vue unplugin-vue-components unplugin-auto-import -D
31
+ ```
32
+
33
+ ### Vite
34
+
35
+ ```js
36
+ // vite.config.js
37
+ import vue from '@vitejs/plugin-vue'
38
+ import components from 'unplugin-vue-components/vite'
39
+ import autoImport from 'unplugin-auto-import/vite'
40
+ import { MapleResolver, MapleStyleImports } from '@maple-design/resolver-vue'
41
+ import { defineConfig } from 'vite'
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ vue(),
46
+ MapleStyleImports(),
47
+ components({
48
+ resolvers: [MapleResolver()]
49
+ }),
50
+ autoImport({
51
+ resolvers: [MapleResolver()]
52
+ })
53
+ ]
54
+ })
55
+ ```
56
+
57
+ ### Vue CLI
58
+
59
+ ```js
60
+ // vue.config.js
61
+ const Components = require('unplugin-vue-components/webpack')
62
+ const AutoImport = require('unplugin-auto-import/webpack')
63
+ const { MapleResolver } = require('@maple-design/resolver-vue')
64
+
65
+ module.exports = {
66
+ configureWebpack: {
67
+ plugins: [
68
+ Components.default({
69
+ resolvers: [MapleResolver()]
70
+ }),
71
+ AutoImport.default({
72
+ resolvers: [MapleResolver()]
73
+ })
74
+ ]
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### Typescript configuration note
80
+
81
+ In order to get good IDE syntax highlighting,
82
+ please make sure that the type declaration files generated by the above two plugins are include by `typescript`,
83
+ which can be configured as follows in `tsconfig.json`:
84
+
85
+ ```json
86
+ {
87
+ "include": ["auto-imports.d.ts", "components.d.ts"]
88
+ }
89
+ ```
90
+
91
+ ### Manual import
92
+
93
+ Each component is a `Vue plugin` and consists of `component logic` and `style files`, which are manually imported and used as follows.
94
+
95
+ ```js
96
+ import App from './App.vue'
97
+ import { createApp } from 'vue'
98
+ import { Button } from '@maple-design/ui-vue'
99
+ import '@maple-design/ui-vue/button/style'
100
+
101
+ createApp(App).use(Button)
102
+ ```
103
+
104
+ OR
105
+
106
+ ```html
107
+ <script setup>
108
+ import { Button as VarButton } from '@maple-design/ui-vue'
109
+ import '@maple-design/ui-vue/button/style'
110
+ </script>
111
+
112
+ <template>
113
+ <mp-button>Say Hello</mp-button>
114
+ </template>
115
+ ```
116
+
117
+ ### Manual import and automatic import comparison
118
+
119
+ #### Comparison-Manual import
120
+
121
+ ```html
122
+ <script setup>
123
+ import { Button as VarButton, Message } from '@maple-design/ui-vue'
124
+ import '@maple-design/ui-vue/button/style'
125
+ import '@maple-design/ui-vue/message/style'
126
+
127
+ function handleClick() {
128
+ Message('Hello!')
129
+ }
130
+ </script>
131
+
132
+ <template>
133
+ <mp-button @click="handleClick">Say Hello</mp-button>
134
+ </template>
135
+ ```
136
+
137
+ #### Comparison-Automatic import
138
+
139
+ ```html
140
+ <script setup>
141
+ function handleClick() {
142
+ Message('Hello!')
143
+ }
144
+ </script>
145
+
146
+ <template>
147
+ <mp-button @click="handleClick">Say Hello</mp-button>
148
+ </template>
149
+ ```
150
+
151
+ ## Explicit-import styles (Vite)
152
+
153
+ MapleStyleImports() handles named value imports from @maple-design/ui-vue after Vue/TypeScript compilation, using the same style mapping as MapleResolver. It supports aliases, components, deduplication and importStyle:false. Type-only, namespace and default imports are excluded. Add it to Vite plugins, not the resolvers array. Maple CLI docs include it by default; restart the dev server after updating CLI plugins.
@@ -0,0 +1,151 @@
1
+ # Maple Resolver
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ `@maple-design/resolver-vue` 是 [unplugin-vue-components](https://github.com/unplugin/unplugin-vue-components) 的一个解析器,用于实现 Maple 按需引入。
6
+
7
+ ## 特性
8
+
9
+ - 支持 `Vite`, `Webpack`, `Vue CLI`, `Rollup`, `esbuild` 等
10
+ - 支持自动引入组件对应的 CSS 样式
11
+ - 支持 SSR(服务端渲染)
12
+
13
+ ## 自动引入
14
+
15
+ 通过插件
16
+ [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components) 和
17
+ [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
18
+ 实现组件自动按需导入,这也是我们最推荐的方式。
19
+
20
+ ## 安装插件
21
+
22
+ ```shell
23
+ # npm
24
+ npm i @maple-design/resolver-vue unplugin-vue-components unplugin-auto-import -D
25
+
26
+ # yarn
27
+ yarn add @maple-design/resolver-vue unplugin-vue-components unplugin-auto-import -D
28
+
29
+ # pnpm
30
+ pnpm add @maple-design/resolver-vue unplugin-vue-components unplugin-auto-import -D
31
+ ```
32
+
33
+ ### Vite
34
+
35
+ ```js
36
+ // vite.config.js
37
+ import vue from '@vitejs/plugin-vue'
38
+ import components from 'unplugin-vue-components/vite'
39
+ import autoImport from 'unplugin-auto-import/vite'
40
+ import { MapleResolver, MapleStyleImports } from '@maple-design/resolver-vue'
41
+ import { defineConfig } from 'vite'
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ vue(),
46
+ MapleStyleImports(),
47
+ components({
48
+ resolvers: [MapleResolver()]
49
+ }),
50
+ autoImport({
51
+ resolvers: [MapleResolver()]
52
+ })
53
+ ]
54
+ })
55
+ ```
56
+
57
+ ### Vue CLI
58
+
59
+ ```js
60
+ // vue.config.js
61
+ const Components = require('unplugin-vue-components/webpack')
62
+ const AutoImport = require('unplugin-auto-import/webpack')
63
+ const { MapleResolver } = require('@maple-design/resolver-vue')
64
+
65
+ module.exports = {
66
+ configureWebpack: {
67
+ plugins: [
68
+ Components.default({
69
+ resolvers: [MapleResolver()]
70
+ }),
71
+ AutoImport.default({
72
+ resolvers: [MapleResolver()]
73
+ })
74
+ ]
75
+ }
76
+ }
77
+ ```
78
+
79
+ ### Typescript 配置注意
80
+
81
+ 为了得到良好的 IDE 语法高亮,请确保上述两个插件生成的类型声明文件被 `typescript` 识别,可在 `tsconfig.json` 中进行如下配置:
82
+
83
+ ```json
84
+ {
85
+ "include": ["auto-imports.d.ts", "components.d.ts"]
86
+ }
87
+ ```
88
+
89
+ ### 手动引入
90
+
91
+ 每一个组件都是一个 `Vue插件`,并由 `组件逻辑` 和 `样式文件` 组成,手动引入的使用方式如下。
92
+
93
+ ```js
94
+ import App from './App.vue'
95
+ import { createApp } from 'vue'
96
+ import { Button } from '@maple-design/ui-vue'
97
+ import '@maple-design/ui-vue/button/style'
98
+
99
+ createApp(App).use(Button)
100
+ ```
101
+
102
+ 或
103
+
104
+ ```html
105
+ <script setup>
106
+ import { Button as VarButton } from '@maple-design/ui-vue'
107
+ import '@maple-design/ui-vue/button/style'
108
+ </script>
109
+
110
+ <template>
111
+ <mp-button>说你好</mp-button>
112
+ </template>
113
+ ```
114
+
115
+ ### 手动引入和自动引入对比
116
+
117
+ #### 对比-手动引入
118
+
119
+ ```html
120
+ <script setup>
121
+ import { Button as VarButton, Message } from '@maple-design/ui-vue'
122
+ import '@maple-design/ui-vue/button/style'
123
+ import '@maple-design/ui-vue/message/style'
124
+
125
+ function handleClick() {
126
+ Message('你好!')
127
+ }
128
+ </script>
129
+
130
+ <template>
131
+ <mp-button @click="handleClick">说你好</mp-button>
132
+ </template>
133
+ ```
134
+
135
+ #### 对比-自动引入
136
+
137
+ ```html
138
+ <script setup>
139
+ function handleClick() {
140
+ Message('你好!')
141
+ }
142
+ </script>
143
+
144
+ <template>
145
+ <mp-button @click="handleClick">说你好</mp-button>
146
+ </template>
147
+ ```
148
+
149
+ ## 显式 import 自动样式(Vite)
150
+
151
+ MapleResolver 为模板组件和未声明的函数标识符提供解析;已经手动 import 的函数不会再次触发自动导入。配套 MapleStyleImports() 在 Vue/TypeScript 编译后处理来自 @maple-design/ui-vue 的具名值导入,复用 resolver 的样式映射。支持 Message 别名、普通组件、去重及 importStyle:false;跳过类型、命名空间和默认导入。它是 Vite 插件,不要放进 resolvers 数组。Maple CLI 文档开发已内置该插件,应用项目按上方 Vite 示例配置。更改 CLI 插件配置后需重启开发服务。
package/lib/index.cjs ADDED
@@ -0,0 +1,363 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // src/index.ts
38
+ var src_exports = {};
39
+ __export(src_exports, {
40
+ MapleResolver: () => MapleResolver,
41
+ MapleStyleImports: () => MapleStyleImports,
42
+ resolveMapleComponent: () => resolveMapleComponent
43
+ });
44
+ module.exports = __toCommonJS(src_exports);
45
+ var import_icons_vue = require("@maple-design/icons-vue");
46
+ var import_shared_vue = require("@maple-design/shared-vue");
47
+ var mapleFunctions = [
48
+ "ImagePreview",
49
+ "imagePreview",
50
+ "Message",
51
+ "Picker",
52
+ "ActionSheet",
53
+ "Dialog",
54
+ "Locale",
55
+ "ThemeProvider",
56
+ "SafeArea",
57
+ "LoadingBar"
58
+ ];
59
+ var mapleDirectives = {
60
+ Hover: "_HoverComponent",
61
+ Lazy: "_LazyComponent",
62
+ MpLoading: "vLoading",
63
+ Ripple: "_RippleComponent"
64
+ };
65
+ var mapleIcons = new Set(import_icons_vue.iconNames);
66
+ var mapleComponents = /* @__PURE__ */ new Set([
67
+ "ActionSheet",
68
+ "Alert",
69
+ "PageHeader",
70
+ "AutoComplete",
71
+ "PeopleSelect",
72
+ "Avatar",
73
+ "AvatarGroup",
74
+ "BackTop",
75
+ "Badge",
76
+ "TabBar",
77
+ "TabBarItem",
78
+ "Breadcrumb",
79
+ "BreadcrumbItem",
80
+ "Button",
81
+ "ButtonGroup",
82
+ "Card",
83
+ "Carousel",
84
+ "CarouselItem",
85
+ "Cascader",
86
+ "CascaderPanel",
87
+ "Cell",
88
+ "Checkbox",
89
+ "CheckboxGroup",
90
+ "Code",
91
+ "Col",
92
+ "Collapse",
93
+ "CollapseItem",
94
+ "Context",
95
+ "CountTo",
96
+ "Countdown",
97
+ "Date",
98
+ "DatePicker",
99
+ "DateRange",
100
+ "DateRangePicker",
101
+ "Dialog",
102
+ "Divider",
103
+ "Drag",
104
+ "Menu",
105
+ "Ellipsis",
106
+ "Empty",
107
+ "Fab",
108
+ "FieldDecorator",
109
+ "FloatingPanel",
110
+ "Form",
111
+ "FormDetails",
112
+ "FormItem",
113
+ "Grid",
114
+ "GridItem",
115
+ "HighlighterProvider",
116
+ "Hover",
117
+ "HoverOverlay",
118
+ "Icon",
119
+ "Image",
120
+ "ImagePreview",
121
+ "ImagePreviewAction",
122
+ "ImagePreviewGroup",
123
+ "IndexAnchor",
124
+ "IndexBar",
125
+ "InfiniteScroll",
126
+ "Input",
127
+ "InputGroup",
128
+ "InputGroupLabel",
129
+ "InputPassword",
130
+ "InputNumber",
131
+ "Lazy",
132
+ "Link",
133
+ "List",
134
+ "ListItem",
135
+ "Loading",
136
+ "LoadingBar",
137
+ "Locale",
138
+ "LocaleProvider",
139
+ "MenuOption",
140
+ "Message",
141
+ "NavMenu",
142
+ "NavMenuItem",
143
+ "NoticeBar",
144
+ "NumberKeyboard",
145
+ "Option",
146
+ "Optgroup",
147
+ "Overlay",
148
+ "Pagination",
149
+ "Paper",
150
+ "Picker",
151
+ "Popover",
152
+ "Popup",
153
+ "Progress",
154
+ "ProgressGroup",
155
+ "PullRefresh",
156
+ "Radio",
157
+ "RadioGroup",
158
+ "Rate",
159
+ "Result",
160
+ "Ripple",
161
+ "Row",
162
+ "Search",
163
+ "Select",
164
+ "Signature",
165
+ "Skeleton",
166
+ "SkeletonLine",
167
+ "SkeletonShape",
168
+ "Slider",
169
+ "Space",
170
+ "Step",
171
+ "Steps",
172
+ "Affix",
173
+ "ThemeProvider",
174
+ "SafeArea",
175
+ "SwipeCell",
176
+ "Switch",
177
+ "SplitButton",
178
+ "Statistic",
179
+ "TabPane",
180
+ "TabNav",
181
+ "TabsNavs",
182
+ "TabItem",
183
+ "Table",
184
+ "Tabs",
185
+ "TabsItems",
186
+ "Tag",
187
+ "Textarea",
188
+ "Themes",
189
+ "Time",
190
+ "TimePicker",
191
+ "TimeRange",
192
+ "TimeRangePicker",
193
+ "Tooltip",
194
+ "Trigger",
195
+ "Upload",
196
+ "VerificationCode",
197
+ "Watermark"
198
+ ]);
199
+ var styleDirAliases = {
200
+ CascaderPanel: "cascader",
201
+ Optgroup: "select",
202
+ imagePreview: "image",
203
+ CollapseItem: "collapse",
204
+ Row: "row",
205
+ Col: "col",
206
+ GridItem: "grid",
207
+ ImagePreview: "image",
208
+ ImagePreviewAction: "image",
209
+ ImagePreviewGroup: "image",
210
+ CarouselItem: "carousel",
211
+ AvatarGroup: "avatar",
212
+ ButtonGroup: "button",
213
+ BreadcrumbItem: "breadcrumb",
214
+ TabPane: "tabs",
215
+ TabBarItem: "tab-bar",
216
+ TabNav: "tabs",
217
+ TabsNavs: "tabs",
218
+ TabItem: "tabs",
219
+ TabsItems: "tabs",
220
+ CheckboxGroup: "checkbox",
221
+ RadioGroup: "radio",
222
+ MenuOption: "menu",
223
+ NavMenuItem: "nav-menu",
224
+ Step: "steps",
225
+ ListItem: "list",
226
+ FormItem: "form",
227
+ InputGroup: "input",
228
+ InputGroupLabel: "input",
229
+ InputPassword: "input",
230
+ IndexAnchor: "index-bar",
231
+ Option: "select",
232
+ DatePicker: "date",
233
+ DateRangePicker: "date-range",
234
+ TimePicker: "time",
235
+ TimeRangePicker: "time-range",
236
+ HoverOverlay: "hover",
237
+ SkeletonLine: "skeleton",
238
+ SkeletonShape: "skeleton"
239
+ };
240
+ var stylelessComponents = /* @__PURE__ */ new Set([
241
+ "Context",
242
+ "HighlighterProvider",
243
+ "Lazy",
244
+ "Locale",
245
+ "LocaleProvider",
246
+ "Themes",
247
+ "Trigger"
248
+ ]);
249
+ function getStyleSideEffects(name, importStyle = true) {
250
+ var _a;
251
+ if (!importStyle || stylelessComponents.has(name)) {
252
+ return void 0;
253
+ }
254
+ const dir = (_a = styleDirAliases[name]) != null ? _a : (0, import_shared_vue.kebabCase)(name);
255
+ return [`@maple-design/ui-vue/${dir}/style`];
256
+ }
257
+ function resolveMapleComponent(name, options = {}, programmatic = false) {
258
+ return {
259
+ from: "@maple-design/ui-vue",
260
+ name: programmatic ? name : `_${name}Component`,
261
+ sideEffects: getStyleSideEffects(name, options.importStyle)
262
+ };
263
+ }
264
+ function resolveMapleIcon(name, importStyle = true) {
265
+ const iconName = name.slice("MIcon".length);
266
+ const iconPath = (0, import_shared_vue.kebabCase)(iconName);
267
+ if (!mapleIcons.has(iconPath)) {
268
+ throw new Error(
269
+ `[MapleResolver] Unknown icon component <m-icon-${iconPath}>. Choose a name exported by @maple-design/icons-vue.`
270
+ );
271
+ }
272
+ return {
273
+ from: `@maple-design/icons-vue/icon-${iconPath}`,
274
+ name: `Icon${iconName}`,
275
+ sideEffects: importStyle ? ["@maple-design/icons-vue/style.css"] : void 0
276
+ };
277
+ }
278
+ function MapleResolver(options = {}) {
279
+ return [
280
+ {
281
+ type: "component",
282
+ resolve(name) {
283
+ if (name.startsWith("MIcon") && name.length > "MIcon".length) {
284
+ return resolveMapleIcon(name, options.importStyle);
285
+ }
286
+ if (name.startsWith("Mp")) {
287
+ const componentName = name.slice(2);
288
+ if (mapleComponents.has(componentName)) {
289
+ return resolveMapleComponent(componentName, options);
290
+ }
291
+ }
292
+ if (options.autoImport !== false && mapleFunctions.includes(name)) {
293
+ return resolveMapleComponent(name, options, true);
294
+ }
295
+ }
296
+ },
297
+ {
298
+ type: "directive",
299
+ resolve(name) {
300
+ if (options.directives === false || !mapleDirectives[name]) {
301
+ return;
302
+ }
303
+ const styleName = name === "MpLoading" ? "Loading" : name;
304
+ return __spreadProps(__spreadValues({}, resolveMapleComponent(styleName, options)), {
305
+ name: mapleDirectives[name]
306
+ });
307
+ }
308
+ }
309
+ ];
310
+ }
311
+ function MapleStyleImports(options = {}) {
312
+ return {
313
+ name: "maple:explicit-import-styles",
314
+ enforce: "post",
315
+ transform(code, id) {
316
+ var _a, _b, _c, _d, _e, _f, _g;
317
+ if (options.importStyle === false || !/\.(?:[cm]?[jt]sx?|vue|md)(?:\?|$)/.test(id) || /[?&](?:type=style|raw(?:&|$)|url(?:&|$))/.test(id) || !code.includes("@maple-design/ui-vue")) {
318
+ return;
319
+ }
320
+ const ast = this.parse(code);
321
+ const existing = new Set(
322
+ ast.body.filter((node) => node.type === "ImportDeclaration").map((node) => {
323
+ var _a2;
324
+ return (_a2 = node.source) == null ? void 0 : _a2.value;
325
+ })
326
+ );
327
+ const styles = /* @__PURE__ */ new Set();
328
+ for (const node of ast.body) {
329
+ if (node.type !== "ImportDeclaration" || ((_a = node.source) == null ? void 0 : _a.value) !== "@maple-design/ui-vue") {
330
+ continue;
331
+ }
332
+ for (const specifier of (_b = node.specifiers) != null ? _b : []) {
333
+ if (specifier.type !== "ImportSpecifier") {
334
+ continue;
335
+ }
336
+ const imported = (_f = (_e = (_c = specifier.imported) == null ? void 0 : _c.name) != null ? _e : (_d = specifier.imported) == null ? void 0 : _d.value) != null ? _f : "";
337
+ const name = imported.replace(/^_(.+)Component$/, "$1");
338
+ if (!mapleComponents.has(name) && !mapleFunctions.includes(name)) {
339
+ continue;
340
+ }
341
+ for (const style of (_g = getStyleSideEffects(name, true)) != null ? _g : []) {
342
+ if (!existing.has(style)) {
343
+ styles.add(style);
344
+ }
345
+ }
346
+ }
347
+ }
348
+ if (!styles.size) {
349
+ return;
350
+ }
351
+ return {
352
+ code: code + "\n" + [...styles].map((style) => "import " + JSON.stringify(style) + ";").join("\n"),
353
+ map: null
354
+ };
355
+ }
356
+ };
357
+ }
358
+ // Annotate the CommonJS export names for ESM import in node:
359
+ 0 && (module.exports = {
360
+ MapleResolver,
361
+ MapleStyleImports,
362
+ resolveMapleComponent
363
+ });
@@ -0,0 +1,48 @@
1
+ interface MapleResolverOptions {
2
+ /** Resolve programmatic APIs for unplugin-auto-import. @default true */
3
+ autoImport?: boolean;
4
+ /** Automatically import component styles. @default true */
5
+ importStyle?: boolean;
6
+ /** Resolve Maple directives such as `v-ripple`. @default true */
7
+ directives?: boolean;
8
+ }
9
+ declare function resolveMapleComponent(name: string, options?: MapleResolverOptions, programmatic?: boolean): {
10
+ from: string;
11
+ name: string;
12
+ sideEffects: string[] | undefined;
13
+ };
14
+ /**
15
+ * Resolver for Maple components, SVG icons, directives, and programmatic APIs.
16
+ * Use the same resolver with unplugin-vue-components and unplugin-auto-import.
17
+ */
18
+ declare function MapleResolver(options?: MapleResolverOptions): ({
19
+ type: "component";
20
+ resolve(name: string): {
21
+ from: string;
22
+ name: string;
23
+ sideEffects: string[] | undefined;
24
+ } | undefined;
25
+ } | {
26
+ type: "directive";
27
+ resolve(name: string): {
28
+ name: string;
29
+ from: string;
30
+ sideEffects: string[] | undefined;
31
+ } | undefined;
32
+ })[];
33
+ /**
34
+ * Add styles for explicit named imports after Vue/TypeScript compilation.
35
+ * Component/auto-import resolvers alone only handle imports they generate.
36
+ */
37
+ declare function MapleStyleImports(options?: Pick<MapleResolverOptions, 'importStyle'>): {
38
+ name: string;
39
+ enforce: "post";
40
+ transform(this: {
41
+ parse: (code: string) => unknown;
42
+ }, code: string, id: string): {
43
+ code: string;
44
+ map: null;
45
+ } | undefined;
46
+ };
47
+
48
+ export { MapleResolver, MapleResolverOptions, MapleStyleImports, resolveMapleComponent };
package/lib/index.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ interface MapleResolverOptions {
2
+ /** Resolve programmatic APIs for unplugin-auto-import. @default true */
3
+ autoImport?: boolean;
4
+ /** Automatically import component styles. @default true */
5
+ importStyle?: boolean;
6
+ /** Resolve Maple directives such as `v-ripple`. @default true */
7
+ directives?: boolean;
8
+ }
9
+ declare function resolveMapleComponent(name: string, options?: MapleResolverOptions, programmatic?: boolean): {
10
+ from: string;
11
+ name: string;
12
+ sideEffects: string[] | undefined;
13
+ };
14
+ /**
15
+ * Resolver for Maple components, SVG icons, directives, and programmatic APIs.
16
+ * Use the same resolver with unplugin-vue-components and unplugin-auto-import.
17
+ */
18
+ declare function MapleResolver(options?: MapleResolverOptions): ({
19
+ type: "component";
20
+ resolve(name: string): {
21
+ from: string;
22
+ name: string;
23
+ sideEffects: string[] | undefined;
24
+ } | undefined;
25
+ } | {
26
+ type: "directive";
27
+ resolve(name: string): {
28
+ name: string;
29
+ from: string;
30
+ sideEffects: string[] | undefined;
31
+ } | undefined;
32
+ })[];
33
+ /**
34
+ * Add styles for explicit named imports after Vue/TypeScript compilation.
35
+ * Component/auto-import resolvers alone only handle imports they generate.
36
+ */
37
+ declare function MapleStyleImports(options?: Pick<MapleResolverOptions, 'importStyle'>): {
38
+ name: string;
39
+ enforce: "post";
40
+ transform(this: {
41
+ parse: (code: string) => unknown;
42
+ }, code: string, id: string): {
43
+ code: string;
44
+ map: null;
45
+ } | undefined;
46
+ };
47
+
48
+ export { MapleResolver, MapleResolverOptions, MapleStyleImports, resolveMapleComponent };
package/lib/index.js ADDED
@@ -0,0 +1,339 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/index.ts
22
+ import { iconNames } from "@maple-design/icons-vue";
23
+ import { kebabCase } from "@maple-design/shared-vue";
24
+ var mapleFunctions = [
25
+ "ImagePreview",
26
+ "imagePreview",
27
+ "Message",
28
+ "Picker",
29
+ "ActionSheet",
30
+ "Dialog",
31
+ "Locale",
32
+ "ThemeProvider",
33
+ "SafeArea",
34
+ "LoadingBar"
35
+ ];
36
+ var mapleDirectives = {
37
+ Hover: "_HoverComponent",
38
+ Lazy: "_LazyComponent",
39
+ MpLoading: "vLoading",
40
+ Ripple: "_RippleComponent"
41
+ };
42
+ var mapleIcons = new Set(iconNames);
43
+ var mapleComponents = /* @__PURE__ */ new Set([
44
+ "ActionSheet",
45
+ "Alert",
46
+ "PageHeader",
47
+ "AutoComplete",
48
+ "PeopleSelect",
49
+ "Avatar",
50
+ "AvatarGroup",
51
+ "BackTop",
52
+ "Badge",
53
+ "TabBar",
54
+ "TabBarItem",
55
+ "Breadcrumb",
56
+ "BreadcrumbItem",
57
+ "Button",
58
+ "ButtonGroup",
59
+ "Card",
60
+ "Carousel",
61
+ "CarouselItem",
62
+ "Cascader",
63
+ "CascaderPanel",
64
+ "Cell",
65
+ "Checkbox",
66
+ "CheckboxGroup",
67
+ "Code",
68
+ "Col",
69
+ "Collapse",
70
+ "CollapseItem",
71
+ "Context",
72
+ "CountTo",
73
+ "Countdown",
74
+ "Date",
75
+ "DatePicker",
76
+ "DateRange",
77
+ "DateRangePicker",
78
+ "Dialog",
79
+ "Divider",
80
+ "Drag",
81
+ "Menu",
82
+ "Ellipsis",
83
+ "Empty",
84
+ "Fab",
85
+ "FieldDecorator",
86
+ "FloatingPanel",
87
+ "Form",
88
+ "FormDetails",
89
+ "FormItem",
90
+ "Grid",
91
+ "GridItem",
92
+ "HighlighterProvider",
93
+ "Hover",
94
+ "HoverOverlay",
95
+ "Icon",
96
+ "Image",
97
+ "ImagePreview",
98
+ "ImagePreviewAction",
99
+ "ImagePreviewGroup",
100
+ "IndexAnchor",
101
+ "IndexBar",
102
+ "InfiniteScroll",
103
+ "Input",
104
+ "InputGroup",
105
+ "InputGroupLabel",
106
+ "InputPassword",
107
+ "InputNumber",
108
+ "Lazy",
109
+ "Link",
110
+ "List",
111
+ "ListItem",
112
+ "Loading",
113
+ "LoadingBar",
114
+ "Locale",
115
+ "LocaleProvider",
116
+ "MenuOption",
117
+ "Message",
118
+ "NavMenu",
119
+ "NavMenuItem",
120
+ "NoticeBar",
121
+ "NumberKeyboard",
122
+ "Option",
123
+ "Optgroup",
124
+ "Overlay",
125
+ "Pagination",
126
+ "Paper",
127
+ "Picker",
128
+ "Popover",
129
+ "Popup",
130
+ "Progress",
131
+ "ProgressGroup",
132
+ "PullRefresh",
133
+ "Radio",
134
+ "RadioGroup",
135
+ "Rate",
136
+ "Result",
137
+ "Ripple",
138
+ "Row",
139
+ "Search",
140
+ "Select",
141
+ "Signature",
142
+ "Skeleton",
143
+ "SkeletonLine",
144
+ "SkeletonShape",
145
+ "Slider",
146
+ "Space",
147
+ "Step",
148
+ "Steps",
149
+ "Affix",
150
+ "ThemeProvider",
151
+ "SafeArea",
152
+ "SwipeCell",
153
+ "Switch",
154
+ "SplitButton",
155
+ "Statistic",
156
+ "TabPane",
157
+ "TabNav",
158
+ "TabsNavs",
159
+ "TabItem",
160
+ "Table",
161
+ "Tabs",
162
+ "TabsItems",
163
+ "Tag",
164
+ "Textarea",
165
+ "Themes",
166
+ "Time",
167
+ "TimePicker",
168
+ "TimeRange",
169
+ "TimeRangePicker",
170
+ "Tooltip",
171
+ "Trigger",
172
+ "Upload",
173
+ "VerificationCode",
174
+ "Watermark"
175
+ ]);
176
+ var styleDirAliases = {
177
+ CascaderPanel: "cascader",
178
+ Optgroup: "select",
179
+ imagePreview: "image",
180
+ CollapseItem: "collapse",
181
+ Row: "row",
182
+ Col: "col",
183
+ GridItem: "grid",
184
+ ImagePreview: "image",
185
+ ImagePreviewAction: "image",
186
+ ImagePreviewGroup: "image",
187
+ CarouselItem: "carousel",
188
+ AvatarGroup: "avatar",
189
+ ButtonGroup: "button",
190
+ BreadcrumbItem: "breadcrumb",
191
+ TabPane: "tabs",
192
+ TabBarItem: "tab-bar",
193
+ TabNav: "tabs",
194
+ TabsNavs: "tabs",
195
+ TabItem: "tabs",
196
+ TabsItems: "tabs",
197
+ CheckboxGroup: "checkbox",
198
+ RadioGroup: "radio",
199
+ MenuOption: "menu",
200
+ NavMenuItem: "nav-menu",
201
+ Step: "steps",
202
+ ListItem: "list",
203
+ FormItem: "form",
204
+ InputGroup: "input",
205
+ InputGroupLabel: "input",
206
+ InputPassword: "input",
207
+ IndexAnchor: "index-bar",
208
+ Option: "select",
209
+ DatePicker: "date",
210
+ DateRangePicker: "date-range",
211
+ TimePicker: "time",
212
+ TimeRangePicker: "time-range",
213
+ HoverOverlay: "hover",
214
+ SkeletonLine: "skeleton",
215
+ SkeletonShape: "skeleton"
216
+ };
217
+ var stylelessComponents = /* @__PURE__ */ new Set([
218
+ "Context",
219
+ "HighlighterProvider",
220
+ "Lazy",
221
+ "Locale",
222
+ "LocaleProvider",
223
+ "Themes",
224
+ "Trigger"
225
+ ]);
226
+ function getStyleSideEffects(name, importStyle = true) {
227
+ var _a;
228
+ if (!importStyle || stylelessComponents.has(name)) {
229
+ return void 0;
230
+ }
231
+ const dir = (_a = styleDirAliases[name]) != null ? _a : kebabCase(name);
232
+ return [`@maple-design/ui-vue/${dir}/style`];
233
+ }
234
+ function resolveMapleComponent(name, options = {}, programmatic = false) {
235
+ return {
236
+ from: "@maple-design/ui-vue",
237
+ name: programmatic ? name : `_${name}Component`,
238
+ sideEffects: getStyleSideEffects(name, options.importStyle)
239
+ };
240
+ }
241
+ function resolveMapleIcon(name, importStyle = true) {
242
+ const iconName = name.slice("MIcon".length);
243
+ const iconPath = kebabCase(iconName);
244
+ if (!mapleIcons.has(iconPath)) {
245
+ throw new Error(
246
+ `[MapleResolver] Unknown icon component <m-icon-${iconPath}>. Choose a name exported by @maple-design/icons-vue.`
247
+ );
248
+ }
249
+ return {
250
+ from: `@maple-design/icons-vue/icon-${iconPath}`,
251
+ name: `Icon${iconName}`,
252
+ sideEffects: importStyle ? ["@maple-design/icons-vue/style.css"] : void 0
253
+ };
254
+ }
255
+ function MapleResolver(options = {}) {
256
+ return [
257
+ {
258
+ type: "component",
259
+ resolve(name) {
260
+ if (name.startsWith("MIcon") && name.length > "MIcon".length) {
261
+ return resolveMapleIcon(name, options.importStyle);
262
+ }
263
+ if (name.startsWith("Mp")) {
264
+ const componentName = name.slice(2);
265
+ if (mapleComponents.has(componentName)) {
266
+ return resolveMapleComponent(componentName, options);
267
+ }
268
+ }
269
+ if (options.autoImport !== false && mapleFunctions.includes(name)) {
270
+ return resolveMapleComponent(name, options, true);
271
+ }
272
+ }
273
+ },
274
+ {
275
+ type: "directive",
276
+ resolve(name) {
277
+ if (options.directives === false || !mapleDirectives[name]) {
278
+ return;
279
+ }
280
+ const styleName = name === "MpLoading" ? "Loading" : name;
281
+ return __spreadProps(__spreadValues({}, resolveMapleComponent(styleName, options)), {
282
+ name: mapleDirectives[name]
283
+ });
284
+ }
285
+ }
286
+ ];
287
+ }
288
+ function MapleStyleImports(options = {}) {
289
+ return {
290
+ name: "maple:explicit-import-styles",
291
+ enforce: "post",
292
+ transform(code, id) {
293
+ var _a, _b, _c, _d, _e, _f, _g;
294
+ if (options.importStyle === false || !/\.(?:[cm]?[jt]sx?|vue|md)(?:\?|$)/.test(id) || /[?&](?:type=style|raw(?:&|$)|url(?:&|$))/.test(id) || !code.includes("@maple-design/ui-vue")) {
295
+ return;
296
+ }
297
+ const ast = this.parse(code);
298
+ const existing = new Set(
299
+ ast.body.filter((node) => node.type === "ImportDeclaration").map((node) => {
300
+ var _a2;
301
+ return (_a2 = node.source) == null ? void 0 : _a2.value;
302
+ })
303
+ );
304
+ const styles = /* @__PURE__ */ new Set();
305
+ for (const node of ast.body) {
306
+ if (node.type !== "ImportDeclaration" || ((_a = node.source) == null ? void 0 : _a.value) !== "@maple-design/ui-vue") {
307
+ continue;
308
+ }
309
+ for (const specifier of (_b = node.specifiers) != null ? _b : []) {
310
+ if (specifier.type !== "ImportSpecifier") {
311
+ continue;
312
+ }
313
+ const imported = (_f = (_e = (_c = specifier.imported) == null ? void 0 : _c.name) != null ? _e : (_d = specifier.imported) == null ? void 0 : _d.value) != null ? _f : "";
314
+ const name = imported.replace(/^_(.+)Component$/, "$1");
315
+ if (!mapleComponents.has(name) && !mapleFunctions.includes(name)) {
316
+ continue;
317
+ }
318
+ for (const style of (_g = getStyleSideEffects(name, true)) != null ? _g : []) {
319
+ if (!existing.has(style)) {
320
+ styles.add(style);
321
+ }
322
+ }
323
+ }
324
+ }
325
+ if (!styles.size) {
326
+ return;
327
+ }
328
+ return {
329
+ code: code + "\n" + [...styles].map((style) => "import " + JSON.stringify(style) + ";").join("\n"),
330
+ map: null
331
+ };
332
+ }
333
+ };
334
+ }
335
+ export {
336
+ MapleResolver,
337
+ MapleStyleImports,
338
+ resolveMapleComponent
339
+ };
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@maple-design/resolver-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.1.1",
4
+ "description": "Maple resolver for unplugin-vue-components and unplugin-auto-import",
5
+ "keywords": [
6
+ "maple",
7
+ "resolver",
8
+ "unplugin-vue-components",
9
+ "unplugin-auto-import"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/loca-spirit/maple-design-mobile/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/loca-spirit/maple-design-mobile.git",
17
+ "directory": "packages/resolver"
18
+ },
19
+ "license": "MIT",
20
+ "author": "shuai.meng",
21
+ "sideEffects": false,
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./lib/index.js",
26
+ "require": "./lib/index.cjs",
27
+ "types": "./lib/index.d.ts"
28
+ },
29
+ "./*": "./*"
30
+ },
31
+ "main": "lib/index.cjs",
32
+ "module": "lib/index.js",
33
+ "types": "lib/index.d.ts",
34
+ "files": [
35
+ "lib"
36
+ ],
37
+ "dependencies": {
38
+ "@maple-design/shared-vue": "1.1.1",
39
+ "@maple-design/icons-vue": "1.1.2"
40
+ },
41
+ "devDependencies": {
42
+ "@types/node": "^18.7.20",
43
+ "tsup": "7.2.0",
44
+ "typescript": "5.3.3"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public",
48
+ "registry": "https://registry.npmjs.org/"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup src/index.ts --format esm,cjs --out-dir=lib --dts --clean",
52
+ "dev": "tsup src/index.ts --format esm --out-dir=lib --watch --dts",
53
+ "test": "pnpm build && node --test test/*.test.mjs"
54
+ }
6
55
  }