@movk/nuxt 1.5.1 → 1.7.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.
Files changed (33) hide show
  1. package/dist/module.d.mts +25 -11
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +54 -5
  4. package/dist/runtime/components/AutoForm.vue +1 -1
  5. package/dist/runtime/components/DataTable.vue +1 -1
  6. package/dist/runtime/components/PillGroup.vue +1 -1
  7. package/dist/runtime/components/SearchForm.vue +1 -1
  8. package/dist/runtime/components/SlideVerify.vue +1 -1
  9. package/dist/runtime/components/Tree.vue +1 -1
  10. package/dist/runtime/components/theme-picker/ThemePicker.vue +0 -30
  11. package/dist/runtime/composables/useTheme.d.ts +0 -7
  12. package/dist/runtime/composables/useTheme.js +13 -39
  13. package/dist/runtime/domains/api/toast.d.ts +2 -0
  14. package/dist/runtime/domains/api/toast.js +7 -4
  15. package/dist/runtime/domains/auto-form/controls.d.ts +28 -3
  16. package/dist/runtime/domains/theme/theme-font.d.ts +44 -0
  17. package/dist/runtime/domains/theme/theme-font.js +48 -0
  18. package/dist/runtime/domains/theme/theme-radius.d.ts +7 -0
  19. package/dist/runtime/domains/theme/theme-radius.js +7 -0
  20. package/dist/runtime/index.css +1 -1
  21. package/dist/runtime/plugins/theme.js +2 -22
  22. package/dist/runtime/types/api/config.d.ts +1 -1
  23. package/dist/runtime/types/api/response.d.ts +5 -5
  24. package/dist/runtime/types/auto-form/zod-factory.d.ts +17 -3
  25. package/dist/runtime/utils/form-control.d.ts +14 -16
  26. package/dist/runtime/utils/theme-defaults.d.ts +1 -6
  27. package/dist/runtime/utils/theme-defaults.js +3 -13
  28. package/dist/shared/{nuxt.DJKBap-S.mjs → nuxt.BT5mXYjs.mjs} +81 -11
  29. package/dist/unplugin.d.mts +2 -1
  30. package/dist/unplugin.mjs +30 -1
  31. package/dist/vite.d.mts +1 -0
  32. package/dist/vite.mjs +3 -1
  33. package/package.json +15 -16
package/dist/module.d.mts CHANGED
@@ -1,17 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { MovkApiFullConfig } from '../dist/runtime/types/api/module.js';
3
+ import { MovkFontFamily, ThemeFontOption } from '../dist/runtime/domains/theme/theme-font.js';
3
4
  import { ModuleOptions as ModuleOptions$1 } from '@nuxt/ui';
4
5
  export * from '../dist/runtime/types/index.js';
5
6
 
6
- interface ThemeFontConfig {
7
- /** 字体名称 */
8
- name: string;
9
- /**
10
- * 字体 CSS 文件的完整 URL;未提供时运行时回退到 Google Fonts URL
11
- * @example 'https://cdn.mhaibaraai.cn/fonts/alibaba-puhuiti.css'
12
- */
13
- href?: string;
14
- }
15
7
  type StrictUiTheme = {
16
8
  [K in keyof NonNullable<ModuleOptions$1['theme']>]?: Exclude<NonNullable<ModuleOptions$1['theme']>[K], null>;
17
9
  };
@@ -23,6 +15,16 @@ interface ModuleOptions {
23
15
  prefix?: string;
24
16
  /** API 模块配置 */
25
17
  api?: MovkApiFullConfig;
18
+ /** 图标模块配置 */
19
+ icon?: {
20
+ /**
21
+ * 是否把 movk 组件与内置图标集用到的图标注入 `@nuxt/icon` 的构建期图标包。
22
+ * 关闭后这些图标改为运行时按需请求
23
+ * @defaultValue true
24
+ * @see https://ui.nuxt.com/docs/getting-started/integrations/icons/nuxt
25
+ */
26
+ clientBundle?: boolean;
27
+ };
26
28
  /** 主题模块配置 */
27
29
  theme?: {
28
30
  /**
@@ -49,8 +51,20 @@ interface ModuleOptions {
49
51
  * @example 'tw'
50
52
  */
51
53
  prefix?: StrictUiTheme['prefix'];
52
- /** ThemePicker 字体可选项;提供时完整替换内置列表 */
53
- fonts?: ThemeFontConfig[];
54
+ /**
55
+ * 全局字体。内置字体给名字即可,模块在构建期注入样式表与带中文回退栈的 `--font-sans`;
56
+ * 自托管字体用 `{ name, href }` 形式补上入口 CSS 地址。
57
+ * 缺省时不注入 `--font-sans`,字体由项目 CSS 的 `@theme` 决定
58
+ * @example 'Alibaba PuHuiTi'
59
+ * @see https://github.com/mhaibaraai/movk-fonts
60
+ */
61
+ font?: MovkFontFamily | (string & {}) | ThemeFontOption;
62
+ /**
63
+ * 默认圆角(单位 rem)。缺省时不注入 `--ui-radius`,
64
+ * 沿用 `@nuxt/ui` 的默认值或项目 CSS 的声明
65
+ * @example 0.5
66
+ */
67
+ radius?: number;
54
68
  /** ThemePicker 圆角可选项 */
55
69
  radiuses?: number[];
56
70
  /** ThemePicker neutral 颜色可选项 */
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movk/nuxt",
3
- "version": "1.5.1",
3
+ "version": "1.7.0",
4
4
  "configKey": "movk",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.4.2"
package/dist/module.mjs CHANGED
@@ -1,15 +1,35 @@
1
- import { addPlugin, defineNuxtModule, createResolver, addComponentsDir, addImportsDir } from '@nuxt/kit';
1
+ import { resolveAlias, useLogger, addPlugin, defineNuxtModule, createResolver, addComponentsDir, addImportsDir } from '@nuxt/kit';
2
2
  import defu, { defu as defu$1 } from 'defu';
3
- import { U as UI_COMPONENTS, a as addTemplates } from './shared/nuxt.DJKBap-S.mjs';
3
+ import { U as UI_COMPONENTS, r as resolveMovkIcons, f as formatMissingCollections, a as addTemplates } from './shared/nuxt.BT5mXYjs.mjs';
4
4
  import { getPackageJsonMetadata } from '../dist/runtime/utils/meta.js';
5
5
  import { kebabCase } from 'scule';
6
6
  import { updateSiteConfig } from 'nuxt-site-config/kit';
7
+ import { readFile } from 'node:fs/promises';
7
8
  import { getDefaultConfig } from '../dist/runtime/utils/theme-defaults.js';
9
+ import { resolveFontSource, resolveFontLinks, resolveFontWarning } from '../dist/runtime/domains/theme/theme-font.js';
8
10
  export * from '../dist/runtime/types/index.js';
9
11
  import 'node:url';
12
+ import 'node:fs';
13
+ import 'node:module';
14
+ import 'pathe';
15
+ import 'tinyglobby';
10
16
 
11
17
  const name = "@movk/nuxt";
12
- const version = "1.5.1";
18
+ const version = "1.7.0";
19
+
20
+ const MOVK_CSS_IMPORT = /@import\s+["']@movk\/nuxt["']/;
21
+ async function checkMovkCss(nuxt) {
22
+ for (const entry of nuxt.options.css || []) {
23
+ if (entry === "@movk/nuxt") return;
24
+ try {
25
+ if (MOVK_CSS_IMPORT.test(await readFile(resolveAlias(entry), "utf-8"))) return;
26
+ } catch {
27
+ }
28
+ }
29
+ useLogger("movk").warn(
30
+ 'Movk styles are not imported. Add `@import "@movk/nuxt";` after `@import "tailwindcss";` in your main CSS file, and register that file in `nuxt.config.ts` under `css`.'
31
+ );
32
+ }
13
33
 
14
34
  function getDefaultApiConfig(apiConfig) {
15
35
  const publicEndpoints = {};
@@ -75,6 +95,9 @@ const defaultOptions = {
75
95
  prefix: "M",
76
96
  theme: {
77
97
  enabled: true
98
+ },
99
+ icon: {
100
+ clientBundle: true
78
101
  }
79
102
  };
80
103
 
@@ -85,6 +108,7 @@ function addTheme(nuxt, resolve, theme) {
85
108
  { charset: "utf-8" },
86
109
  { name: "viewport", content: "width=device-width, initial-scale=1" }
87
110
  );
111
+ addFontLinks(nuxt, theme?.font);
88
112
  nuxt.options.app.head.htmlAttrs = defu(nuxt.options.app.head.htmlAttrs || {}, {
89
113
  dir: "ltr"
90
114
  });
@@ -111,6 +135,17 @@ function addTheme(nuxt, resolve, theme) {
111
135
  mode: "all"
112
136
  });
113
137
  }
138
+ function addFontLinks(nuxt, font) {
139
+ const source = resolveFontSource(font);
140
+ if (!source) return;
141
+ const links = resolveFontLinks(source);
142
+ if (!links.length) {
143
+ useLogger("movk").warn(resolveFontWarning(source.name));
144
+ return;
145
+ }
146
+ nuxt.options.app.head.link = nuxt.options.app.head.link || [];
147
+ nuxt.options.app.head.link.push(...links);
148
+ }
114
149
 
115
150
  const module$1 = defineNuxtModule({
116
151
  meta: {
@@ -131,8 +166,6 @@ const module$1 = defineNuxtModule({
131
166
  const { resolve } = createResolver(import.meta.url);
132
167
  nuxt.options.movk = options;
133
168
  nuxt.options.alias["#movk"] = resolve("./runtime");
134
- nuxt.options.css = nuxt.options.css || [];
135
- nuxt.options.css.push(resolve("runtime/index.css"));
136
169
  const movkUiDeps = UI_COMPONENTS.map((name2) => name2.slice(1));
137
170
  const uiOptions = nuxt.options;
138
171
  const ui = uiOptions.ui ??= {};
@@ -154,6 +187,21 @@ const module$1 = defineNuxtModule({
154
187
  ignore: componentIgnore
155
188
  });
156
189
  addImportsDir(resolve("runtime/composables"));
190
+ if (options.icon?.clientBundle !== false) {
191
+ nuxt.hook("icon:clientBundleIcons", (icons) => {
192
+ const { icons: bundled, missing } = resolveMovkIcons(resolve("runtime"), {
193
+ theme: options.theme?.enabled !== false,
194
+ paths: [nuxt.options.rootDir, nuxt.options.workspaceDir].filter(Boolean)
195
+ });
196
+ for (const icon of bundled) {
197
+ icons.add(icon);
198
+ }
199
+ const logger = useLogger("movk");
200
+ const { warn, debug } = formatMissingCollections(missing);
201
+ if (warn) logger.warn(warn);
202
+ if (debug) logger.debug(debug);
203
+ });
204
+ }
157
205
  const apiConfig = options.api ?? {};
158
206
  if (apiConfig.enabled !== false) {
159
207
  const { publicConfig, privateConfig } = getDefaultApiConfig(apiConfig);
@@ -178,6 +226,7 @@ const module$1 = defineNuxtModule({
178
226
  options.theme = defu$1(options.theme || {}, themeDefaults);
179
227
  addTheme(nuxt, resolve, options.theme);
180
228
  await addTemplates(options, nuxt);
229
+ await checkMovkCss(nuxt);
181
230
  });
182
231
  nuxt.hook("prepare:types", ({ references }) => {
183
232
  references.push({ path: resolve("./runtime/types/app.config.d.ts") });
@@ -21,7 +21,7 @@ const props = defineProps({
21
21
  globalMeta: { type: Object, required: false },
22
22
  loadingAuto: { type: Boolean, required: false, default: true },
23
23
  validateOn: { type: Array, required: false, default: () => [] },
24
- class: { type: null, required: false },
24
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
25
25
  ui: { type: Object, required: false }
26
26
  });
27
27
  const emits = defineEmits(["error"]);
@@ -61,7 +61,7 @@ const props = defineProps({
61
61
  loadMore: { type: Function, required: false },
62
62
  canLoadMore: { type: Boolean, required: false },
63
63
  loadMoreDistance: { type: Number, required: false },
64
- class: { type: null, required: false },
64
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
65
65
  ui: { type: Object, required: false }
66
66
  });
67
67
  const paginationState = defineModel("pagination", { type: Object });
@@ -25,7 +25,7 @@ const props = defineProps({
25
25
  min: { type: Number, required: false },
26
26
  defaultValue: { type: null, required: false },
27
27
  modelValue: { type: null, required: false },
28
- class: { type: null, required: false },
28
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
29
29
  ui: { type: Object, required: false }
30
30
  });
31
31
  const modelValue = defineModel({ type: null });
@@ -27,7 +27,7 @@ const props = defineProps({
27
27
  globalMeta: { type: Object, required: false },
28
28
  loadingAuto: { type: Boolean, required: false, default: true },
29
29
  validateOn: { type: Array, required: false, default: () => [] },
30
- class: { type: null, required: false },
30
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
31
31
  ui: { type: Object, required: false }
32
32
  });
33
33
  const modelValue = defineModel({ type: Object, ...{ default: () => ({}) } });
@@ -16,7 +16,7 @@ const props = defineProps({
16
16
  icon: { type: null, required: false, default: "i-lucide-chevrons-right" },
17
17
  successIcon: { type: null, required: false, default: "i-lucide-check" },
18
18
  threshold: { type: Number, required: false, default: 0.9 },
19
- class: { type: null, required: false },
19
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true },
20
20
  ui: { type: Object, required: false }
21
21
  });
22
22
  const emits = defineEmits(["success", "dragStart", "dragEnd"]);
@@ -39,7 +39,7 @@ const props = defineProps({
39
39
  toolbar: { type: Boolean, required: false },
40
40
  checkable: { type: Boolean, required: false },
41
41
  ui: { type: Object, required: false },
42
- class: { type: null, required: false }
42
+ class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true }
43
43
  });
44
44
  const emit = defineEmits(["update:modelValue", "update:expanded", "update:search", "change"]);
45
45
  defineSlots();
@@ -30,8 +30,6 @@ const {
30
30
  setBlackAsPrimary,
31
31
  radiuses,
32
32
  radius,
33
- fonts,
34
- font,
35
33
  icon,
36
34
  icons,
37
35
  modes,
@@ -150,34 +148,6 @@ const {
150
148
  </div>
151
149
  </fieldset>
152
150
 
153
- <fieldset>
154
- <legend class="text-[11px] leading-none font-semibold mb-2 select-none flex items-center gap-1">
155
- Font
156
-
157
- <UButton
158
- to="https://ui.nuxt.com/docs/getting-started/integrations/fonts"
159
- size="xs"
160
- color="neutral"
161
- variant="link"
162
- icon="i-lucide-help-circle"
163
- class="p-0 -my-0.5"
164
- :ui="{ leadingIcon: 'size-3' }"
165
- />
166
- </legend>
167
-
168
- <div class="-mx-2">
169
- <USelect
170
- v-model="font"
171
- size="sm"
172
- color="neutral"
173
- icon="i-lucide-type"
174
- :items="fonts"
175
- class="w-full ring-default rounded-sm hover:bg-elevated/50 text-[11px] data-[state=open]:bg-elevated/50"
176
- :ui="{ trailingIcon: 'group-data-[state=open]:rotate-180 transition-transform duration-200' }"
177
- />
178
- </div>
179
- </fieldset>
180
-
181
151
  <fieldset>
182
152
  <legend class="text-[11px] leading-none font-semibold mb-2 select-none flex items-center gap-1">
183
153
  Icons
@@ -6,11 +6,6 @@ export declare function useTheme(): {
6
6
  id: string;
7
7
  tagPriority: number;
8
8
  }[];
9
- link: import("vue").ComputedRef<{
10
- rel: "stylesheet";
11
- href: string;
12
- id: string;
13
- }[]>;
14
9
  neutralColors: string[];
15
10
  neutral: import("vue").WritableComputedRef<string, string>;
16
11
  primaryColors: string[];
@@ -19,8 +14,6 @@ export declare function useTheme(): {
19
14
  setBlackAsPrimary: (value: boolean) => void;
20
15
  radiuses: number[];
21
16
  radius: import("vue").WritableComputedRef<number, number>;
22
- fonts: string[];
23
- font: import("vue").WritableComputedRef<string, string>;
24
17
  icon: import("vue").WritableComputedRef<IconSet, IconSet>;
25
18
  icons: {
26
19
  label: string;
@@ -1,21 +1,23 @@
1
1
  import { useAppConfig, useColorMode, useSiteConfig } from "#imports";
2
2
  import { resolveThemeIcons, themeIcons } from "../domains/theme/theme-icons.js";
3
+ import { resolveActiveRadius, resolveRadiusStyle } from "../domains/theme/theme-radius.js";
3
4
  import { omit, kebabCase } from "@movk/core";
4
5
  import { useLocalStorage } from "@vueuse/core";
5
6
  import colors from "tailwindcss/colors";
6
7
  import { computed } from "vue";
7
8
  import { getDefaultConfig } from "../utils/theme-defaults.js";
9
+ const UI_DEFAULT_RADIUS = 0.25;
8
10
  export function useTheme() {
9
11
  const { movk, ui } = useAppConfig();
10
12
  const colorMode = useColorMode();
11
13
  const name = kebabCase(useSiteConfig().name);
12
14
  const color = computed(() => colorMode.value === "dark" ? colors[ui.colors.neutral][900] : "white");
13
15
  const defaultConfig = getDefaultConfig();
14
- const _radius = useLocalStorage(`${name}-ui-radius`, movk?.radius ?? defaultConfig.radius);
15
- const _font = useLocalStorage(`${name}-ui-font`, movk?.font ?? defaultConfig.font);
16
+ const _radius = useLocalStorage(`${name}-ui-radius`, null, { writeDefaults: false });
16
17
  const _iconSet = useLocalStorage(`${name}-ui-icons`, movk?.icons ?? defaultConfig.icons);
17
18
  const _blackAsPrimary = useLocalStorage(`${name}-ui-black-as-primary`, defaultConfig.blackAsPrimary);
18
- const pickerFonts = movk?.picker?.fonts ?? [];
19
+ const configuredRadius = movk?.radius ?? defaultConfig.radius;
20
+ const activeRadius = computed(() => resolveActiveRadius(_radius.value, configuredRadius));
19
21
  const neutralColors = movk?.picker?.neutralColors ?? [];
20
22
  const neutral = computed({
21
23
  get() {
@@ -41,21 +43,12 @@ export function useTheme() {
41
43
  const radiuses = movk?.picker?.radiuses ?? [];
42
44
  const radius = computed({
43
45
  get() {
44
- return _radius.value;
46
+ return activeRadius.value ?? UI_DEFAULT_RADIUS;
45
47
  },
46
48
  set(option) {
47
49
  _radius.value = option;
48
50
  }
49
51
  });
50
- const fonts = pickerFonts.map((f) => f.name);
51
- const font = computed({
52
- get() {
53
- return _font.value;
54
- },
55
- set(option) {
56
- _font.value = option;
57
- }
58
- });
59
52
  const icons = [
60
53
  { label: "Lucide", icon: "i-lucide-feather", value: "lucide" },
61
54
  { label: "Phosphor", icon: "i-ph-phosphor-logo", value: "phosphor" },
@@ -87,26 +80,14 @@ export function useTheme() {
87
80
  function setBlackAsPrimary(value) {
88
81
  _blackAsPrimary.value = value;
89
82
  }
90
- const radiusStyle = computed(() => `:root { --ui-radius: ${_radius.value}rem; }`);
83
+ const radiusStyle = computed(() => resolveRadiusStyle(activeRadius.value));
91
84
  const blackAsPrimaryStyle = computed(() => _blackAsPrimary.value ? `:root { --ui-primary: black; } .dark { --ui-primary: white; }` : ":root {}");
92
- const fontStyle = computed(() => `:root { --font-sans: '${_font.value}', sans-serif; }`);
93
- const link = computed(() => {
94
- const fontName = _font.value;
95
- const fontConfig = pickerFonts.find((f) => f.name === fontName);
96
- const href = fontConfig?.href ?? `https://fonts.googleapis.com/css2?family=${encodeURIComponent(fontName)}:wght@400;500;600;700&display=swap`;
97
- return [{
98
- rel: "stylesheet",
99
- href,
100
- id: `font-${fontName.toLowerCase().replace(/\s+/g, "-")}`
101
- }];
102
- });
103
85
  const style = [
104
86
  { innerHTML: radiusStyle, id: `nuxt-ui-radius`, tagPriority: -2 },
105
- { innerHTML: blackAsPrimaryStyle, id: `nuxt-ui-black-as-primary`, tagPriority: -2 },
106
- { innerHTML: fontStyle, id: `nuxt-ui-font`, tagPriority: -2 }
87
+ { innerHTML: blackAsPrimaryStyle, id: `nuxt-ui-black-as-primary`, tagPriority: -2 }
107
88
  ];
108
89
  const hasCSSChanges = computed(() => {
109
- return _radius.value !== (movk?.radius ?? defaultConfig.radius) || _blackAsPrimary.value || _font.value !== (movk?.font ?? defaultConfig.font);
90
+ return activeRadius.value !== configuredRadius || _blackAsPrimary.value;
110
91
  });
111
92
  const hasConfigChanges = computed(() => {
112
93
  return ui.colors.primary !== "blue" || ui.colors.neutral !== "slate" || _iconSet.value !== (movk?.icons ?? defaultConfig.icons);
@@ -114,14 +95,11 @@ export function useTheme() {
114
95
  function exportCSS() {
115
96
  const lines = [
116
97
  '@import "tailwindcss";',
117
- '@import "@nuxt/ui";'
98
+ '@import "@movk/nuxt";'
118
99
  ];
119
- if (_font.value !== defaultConfig.font) {
120
- lines.push("", "@theme {", ` --font-sans: '${_font.value}', sans-serif;`, "}");
121
- }
122
100
  const rootLines = [];
123
- if (_radius.value !== defaultConfig.radius) {
124
- rootLines.push(` --ui-radius: ${_radius.value}rem;`);
101
+ if (activeRadius.value !== void 0 && activeRadius.value !== configuredRadius) {
102
+ rootLines.push(` --ui-radius: ${activeRadius.value}rem;`);
125
103
  }
126
104
  if (_blackAsPrimary.value) {
127
105
  rootLines.push(" --ui-primary: black;");
@@ -169,8 +147,7 @@ export function useTheme() {
169
147
  window.localStorage.removeItem(`${name}-ui-primary`);
170
148
  ui.colors.neutral = defaultNeutral;
171
149
  window.localStorage.removeItem(`${name}-ui-neutral`);
172
- _radius.value = movk?.radius ?? defaultConfig.radius;
173
- _font.value = movk?.font ?? defaultConfig.font;
150
+ _radius.value = null;
174
151
  _iconSet.value = defaultIcon;
175
152
  ui.icons = resolveThemeIcons(defaultIcon, ui.icons);
176
153
  _blackAsPrimary.value = movk?.blackAsPrimary ?? defaultConfig.blackAsPrimary;
@@ -178,7 +155,6 @@ export function useTheme() {
178
155
  return {
179
156
  color,
180
157
  style,
181
- link,
182
158
  neutralColors,
183
159
  neutral,
184
160
  primaryColors,
@@ -187,8 +163,6 @@ export function useTheme() {
187
163
  setBlackAsPrimary,
188
164
  radiuses,
189
165
  radius,
190
- fonts,
191
- font,
192
166
  icon,
193
167
  icons,
194
168
  modes,
@@ -10,6 +10,8 @@ type ToastType = 'success' | 'error';
10
10
  * @param requestOptions 单次请求覆盖配置;为 false 时整体禁用
11
11
  * @param globalConfig 全局 Toast 配置(已合并端点级覆盖)
12
12
  * @param responseConfig 用于从 ApiResponse 抽取 message 的字段映射;source 为字符串时可省略
13
+ * @description 开关优先级:请求级 show 显式声明 > 全局 typeConfig.show > 全局 enabled。
14
+ * 请求级 `show: true` 可在全局关闭时单次开启。
13
15
  */
14
16
  export declare function showToast(type: ToastType, source: ApiResponse | string | undefined, requestOptions: RequestToastOptions | false | undefined, globalConfig: Partial<ApiToastConfig>, responseConfig?: Partial<ApiResponseConfig>): void;
15
17
  export {};
@@ -28,16 +28,19 @@ function compact(obj) {
28
28
  return out;
29
29
  }
30
30
  export function showToast(type, source, requestOptions, globalConfig, responseConfig) {
31
- if (globalConfig.enabled === false || requestOptions === false) return;
31
+ if (requestOptions === false) return;
32
+ const requestTypeOptions = requestOptions?.[type];
33
+ if (requestTypeOptions === false) return;
32
34
  const typeConfig = globalConfig[type];
33
- if (typeConfig?.show === false) return;
34
- if (requestOptions?.[type] === false) return;
35
+ const requestShow = requestTypeOptions?.show;
36
+ const globalShow = globalConfig.enabled !== false && typeConfig?.show !== false;
37
+ if (requestShow === false || requestShow === void 0 && !globalShow) return;
35
38
  const message = pickMessage(type, source, requestOptions, responseConfig);
36
39
  if (!message) return;
37
40
  const toast = getToast();
38
41
  if (!toast) return;
39
42
  const { show: _show, ...typeConfigProps } = typeConfig ?? {};
40
- const requestTypeConfig = typeof requestOptions?.[type] === "object" ? requestOptions[type] : {};
43
+ const { show: _requestShow, ...requestTypeConfig } = requestTypeOptions ?? {};
41
44
  toast.add(compact({
42
45
  title: message,
43
46
  ...typeConfigProps,
@@ -1,8 +1,8 @@
1
1
  import type { IsComponent } from '@movk/core';
2
2
  import type { AutoFormControl, _Unset } from '../../types/auto-form/controls';
3
- import type { InputProps, InputSlots, TextareaProps, TextareaSlots } from '@nuxt/ui';
3
+ import type { CheckboxGroupProps, CheckboxGroupSlots, CheckboxProps, CheckboxSlots, FileUploadProps, FileUploadSlots, InputDateProps, InputDateSlots, InputMenuProps, InputMenuSlots, InputNumberProps, InputNumberSlots, InputProps, InputSlots, InputTagsProps, InputTagsSlots, InputTimeProps, InputTimeSlots, ListboxProps, ListboxSlots, PinInputProps, PinInputSlots, RadioGroupProps, RadioGroupSlots, SelectMenuProps, SelectMenuSlots, SelectProps, SelectSlots, SliderProps, SwitchProps, SwitchSlots, TextareaProps, TextareaSlots } from '@nuxt/ui';
4
4
  import type { CalendarDateControlProps } from '../../types/components/date-picker';
5
- import { UInput, UTextarea } from '#components';
5
+ import { UInput } from '#components';
6
6
  export declare function defineControl<C extends IsComponent, P = _Unset, S = _Unset>(e: AutoFormControl<C, P, S>): AutoFormControl<C, P, S>;
7
7
  declare const DEFAULT_CONTROL_COMPONENTS: {
8
8
  readonly string: any;
@@ -595,8 +595,33 @@ declare const DEFAULT_CONTROL_COMPONENTS: {
595
595
  };
596
596
  };
597
597
  type DefaultControlComponents = typeof DEFAULT_CONTROL_COMPONENTS;
598
+ /**
599
+ * Nuxt UI 控件的 `[props, slots]` 类型登记表。
600
+ *
601
+ * `#components` 在模块声明发射期无法解析,`U*` 组件类型会退化为 `any`,
602
+ * 使 `controlProps` / `controlSlots` 在消费端失去类型提示;此处显式登记以绕开组件推导。
603
+ */
604
+ interface NuxtUIControlTypes {
605
+ string: [InputProps, InputSlots];
606
+ number: [InputNumberProps, InputNumberSlots];
607
+ boolean: [CheckboxProps, CheckboxSlots];
608
+ enum: [SelectProps, SelectSlots];
609
+ file: [FileUploadProps, FileUploadSlots];
610
+ inputDate: [InputDateProps, InputDateSlots];
611
+ inputTime: [InputTimeProps, InputTimeSlots];
612
+ textarea: [TextareaProps, TextareaSlots];
613
+ switch: [SwitchProps, SwitchSlots];
614
+ slider: [SliderProps, _Unset];
615
+ selectMenu: [SelectMenuProps, SelectMenuSlots];
616
+ inputMenu: [InputMenuProps, InputMenuSlots];
617
+ checkboxGroup: [CheckboxGroupProps, CheckboxGroupSlots];
618
+ radioGroup: [RadioGroupProps, RadioGroupSlots];
619
+ inputTags: [InputTagsProps, InputTagsSlots];
620
+ pinInput: [PinInputProps, PinInputSlots];
621
+ listbox: [ListboxProps, ListboxSlots];
622
+ }
598
623
  type DefaultControlMap = {
599
- readonly [K in keyof DefaultControlComponents]: K extends 'string' ? AutoFormControl<typeof UInput, InputProps, InputSlots> : K extends 'textarea' ? AutoFormControl<typeof UTextarea, TextareaProps, TextareaSlots> : K extends 'calendarDate' ? AutoFormControl<DefaultControlComponents[K], CalendarDateControlProps> : AutoFormControl<DefaultControlComponents[K]>;
624
+ readonly [K in keyof DefaultControlComponents]: K extends keyof NuxtUIControlTypes ? AutoFormControl<DefaultControlComponents[K], NuxtUIControlTypes[K][0], NuxtUIControlTypes[K][1]> : K extends 'calendarDate' ? AutoFormControl<DefaultControlComponents[K], CalendarDateControlProps> : AutoFormControl<DefaultControlComponents[K]>;
600
625
  };
601
626
  export declare const DEFAULT_CONTROLS: DefaultControlMap;
602
627
  export {};
@@ -0,0 +1,44 @@
1
+ export interface ThemeFontOption {
2
+ /** `@font-face` 声明的 `font-family`,须与字体样式表逐字一致 */
3
+ name: string;
4
+ /** 字体样式表地址;内置字体可省略,自托管字体填入口 CSS 的路径 */
5
+ href?: string;
6
+ }
7
+ export type ThemeFontLink = {
8
+ rel: 'preconnect';
9
+ href: string;
10
+ crossorigin: '';
11
+ } | {
12
+ rel: 'stylesheet';
13
+ href: string;
14
+ id: string;
15
+ };
16
+ /**
17
+ * cdn.mhaibaraai.cn 提供的字体,key 即 `@font-face` 的 `font-family`。
18
+ * 新增字体须同时更新 movk-fonts 仓库的 `scripts/fonts.config.ts`,两处的名字必须逐字相同。
19
+ * @see https://github.com/mhaibaraai/movk-fonts
20
+ */
21
+ export declare const MOVK_FONTS: {
22
+ readonly 'Alibaba PuHuiTi': "https://cdn.mhaibaraai.cn/fonts/alibaba-puhuiti.css";
23
+ readonly 'OPPO Sans': "https://cdn.mhaibaraai.cn/fonts/oppo-sans.css";
24
+ };
25
+ export type MovkFontFamily = keyof typeof MOVK_FONTS;
26
+ export declare function resolveFontId(name: string): string;
27
+ /**
28
+ * 归一化 `theme.font`:字符串按内置清单查地址,对象形式用于自托管字体。
29
+ * 未登记且未给 `href` 的名字仍会产出 `--font-sans` 但不发请求——
30
+ * 其 `@font-face` 由项目自己提供,模块无从猜测来源。
31
+ */
32
+ export declare function resolveFontSource(font?: string | ThemeFontOption): ThemeFontOption | undefined;
33
+ /**
34
+ * 构建期写入 `<head>` 的字体资源。preconnect 必须带 `crossorigin`:
35
+ * woff2 经 CSS 加载是 anonymous CORS 请求,属性不匹配的预热连接不会被复用。
36
+ */
37
+ export declare function resolveFontLinks(source?: ThemeFontOption): ThemeFontLink[];
38
+ /**
39
+ * 未登记且未给 `href` 的字体只注入 `--font-sans`、不发请求时的提示。
40
+ * 两种模式共用同一份文案;不含前缀,由调用方按各自的 logger 补。
41
+ */
42
+ export declare function resolveFontWarning(name: string): string;
43
+ /** 拼接 `--font-sans` 的取值:首选字体在前,系统中文字体兜底在后 */
44
+ export declare function resolveFontFamily(name: string): string;
@@ -0,0 +1,48 @@
1
+ export const MOVK_FONTS = {
2
+ "Alibaba PuHuiTi": "https://cdn.mhaibaraai.cn/fonts/alibaba-puhuiti.css",
3
+ "OPPO Sans": "https://cdn.mhaibaraai.cn/fonts/oppo-sans.css"
4
+ };
5
+ const FALLBACK_STACK = [
6
+ "ui-sans-serif",
7
+ "system-ui",
8
+ "-apple-system",
9
+ '"PingFang SC"',
10
+ '"Hiragino Sans GB"',
11
+ '"Microsoft YaHei"',
12
+ '"Noto Sans CJK SC"',
13
+ "sans-serif"
14
+ ];
15
+ export function resolveFontId(name) {
16
+ return `font-${name.toLowerCase().replace(/\s+/g, "-")}`;
17
+ }
18
+ export function resolveFontSource(font) {
19
+ if (typeof font === "string") {
20
+ if (!font) return void 0;
21
+ const href = MOVK_FONTS[font];
22
+ return href ? { name: font, href } : { name: font };
23
+ }
24
+ if (!font?.name) return void 0;
25
+ return font.href ? { name: font.name, href: font.href } : { name: font.name };
26
+ }
27
+ function resolveOrigin(href) {
28
+ try {
29
+ return new URL(href).origin;
30
+ } catch {
31
+ return void 0;
32
+ }
33
+ }
34
+ export function resolveFontLinks(source) {
35
+ if (!source?.href) return [];
36
+ const origin = resolveOrigin(source.href);
37
+ const preconnect = origin ? [{ rel: "preconnect", href: origin, crossorigin: "" }] : [];
38
+ return [
39
+ ...preconnect,
40
+ { rel: "stylesheet", href: source.href, id: resolveFontId(source.name) }
41
+ ];
42
+ }
43
+ export function resolveFontWarning(name) {
44
+ return `Font "${name}" is not a built-in family and has no href, so only --font-sans is injected and no stylesheet is loaded. Use a built-in family name, or pass { name, href } with the stylesheet URL.`;
45
+ }
46
+ export function resolveFontFamily(name) {
47
+ return [JSON.stringify(name), ...FALLBACK_STACK].join(", ");
48
+ }
@@ -0,0 +1,7 @@
1
+ /** 合并用户选择与配置的默认圆角。0 是合法档位,仅 null/undefined 视为未选择 */
2
+ export declare function resolveActiveRadius(stored: number | null | undefined, configured: number | undefined): number | undefined;
3
+ /**
4
+ * 缺省时输出空规则。该 style 无层级(unlayered),会压过项目 CSS 写在
5
+ * `@theme` 中的 `--ui-radius`,因此只在圆角被显式配置或用户主动切换时才声明。
6
+ */
7
+ export declare function resolveRadiusStyle(radius: number | undefined): string;
@@ -0,0 +1,7 @@
1
+ export function resolveActiveRadius(stored, configured) {
2
+ return stored ?? configured;
3
+ }
4
+ export function resolveRadiusStyle(radius) {
5
+ if (radius === void 0) return ":root {}";
6
+ return `:root { --ui-radius: ${radius}rem; }`;
7
+ }
@@ -1 +1 @@
1
- @import "tailwindcss" theme(static);@import "@nuxt/ui";@import "#build/movk-ui.css";@source "./components";@theme static{--font-sans:"Alibaba PuHuiTi",sans-serif}@layer base{[role=button]:not(:disabled),button:not(:disabled){cursor:pointer}}
1
+ @import "@nuxt/ui";@import "#build/movk-ui.css";@source "./components";@layer base{[role=button]:not(:disabled),button:not(:disabled){cursor:pointer}}
@@ -16,12 +16,6 @@ export default defineNuxtPlugin({
16
16
  if (icons) appConfig.ui.icons = resolveThemeIcons(icons, appConfig.ui.icons);
17
17
  }
18
18
  if (import.meta.server) {
19
- const pickerFonts = appConfig.movk?.picker?.fonts ?? [];
20
- const fontHrefMap = {};
21
- for (const f of pickerFonts) {
22
- if (f.href) fontHrefMap[f.name] = f.href;
23
- }
24
- const fontHrefMapJson = JSON.stringify(fontHrefMap);
25
19
  useHead({
26
20
  script: [{
27
21
  innerHTML: `
@@ -69,8 +63,8 @@ export default defineNuxtPlugin({
69
63
  tagPriority: -1
70
64
  }, {
71
65
  innerHTML: `
72
- var r = localStorage.getItem('${name}-ui-radius');
73
- if (r) document.documentElement.style.setProperty('--ui-radius', r + 'rem');
66
+ var r = parseFloat(localStorage.getItem('${name}-ui-radius'));
67
+ if (isFinite(r)) document.documentElement.style.setProperty('--ui-radius', r + 'rem');
74
68
  `.replace(/\s+/g, " "),
75
69
  type: "text/javascript",
76
70
  tagPriority: -1
@@ -81,20 +75,6 @@ export default defineNuxtPlugin({
81
75
  document.documentElement.style.setProperty('--ui-primary', isDark ? 'white' : 'black');
82
76
  }
83
77
  `.replace(/\s+/g, " ")
84
- }, {
85
- innerHTML: [
86
- `if (localStorage.getItem('${name}-ui-font')) {`,
87
- `var font = localStorage.getItem('${name}-ui-font');`,
88
- `var fontEl = document.querySelector('style#nuxt-ui-font');`,
89
- `if (fontEl) { fontEl.innerHTML = ':root { --font-sans: \\'' + font + '\\', sans-serif; }'; }`,
90
- `var fontMap = ${fontHrefMapJson};`,
91
- `var lnk = document.createElement('link');`,
92
- `lnk.rel = 'stylesheet';`,
93
- `lnk.href = fontMap[font] || ('https://fonts.googleapis.com/css2?family=' + encodeURIComponent(font) + ':wght@400;500;600;700&display=swap');`,
94
- `lnk.id = 'font-' + font.toLowerCase().replace(/\\s+/g, '-');`,
95
- `document.head.appendChild(lnk);`,
96
- `}`
97
- ].join(" ")
98
78
  }]
99
79
  });
100
80
  }
@@ -79,7 +79,7 @@ export interface ApiAuthConfig {
79
79
  clearSession?: boolean;
80
80
  };
81
81
  }
82
- export interface ApiToast extends Toast {
82
+ export interface ApiToast extends Partial<Toast> {
83
83
  /**
84
84
  * 是否显示提示
85
85
  * @defaultValue true
@@ -1,4 +1,4 @@
1
- import type { Toast } from '@nuxt/ui/composables';
1
+ import type { ApiToast } from './config';
2
2
  declare module 'ofetch' {
3
3
  interface FetchOptions {
4
4
  context?: ApiFetchContext;
@@ -27,10 +27,10 @@ export interface ApiFetchContext {
27
27
  * @description 用于单个请求的 Toast 配置,可覆盖全局配置
28
28
  */
29
29
  export interface RequestToastOptions {
30
- /** 成功提示配置,设置为 false 禁用成功提示 */
31
- success?: Partial<Toast> | false;
32
- /** 错误提示配置,设置为 false 禁用错误提示 */
33
- error?: Partial<Toast> | false;
30
+ /** 成功提示配置,设置为 false 禁用成功提示;`show: true` 可覆盖全局关闭 */
31
+ success?: ApiToast | false;
32
+ /** 错误提示配置,设置为 false 禁用错误提示;`show: true` 可覆盖全局关闭 */
33
+ error?: ApiToast | false;
34
34
  /** 自定义成功消息 */
35
35
  successMessage?: string;
36
36
  /** 自定义错误消息 */
@@ -1,4 +1,5 @@
1
1
  import type { z } from 'zod';
2
+ import type { VNodeProps } from 'vue';
2
3
  import type { CalendarDate, Time } from '@internationalized/date';
3
4
  import type { ComponentProps, ComponentSlots, IsAny, IsComponent, KnownKeys, OmitByKey, Prettify, ReactiveValue, UnionToIntersection, WidenLiteral } from '@movk/core';
4
5
  import type { ValueFormat } from '../../composables/useDateFormatter';
@@ -20,16 +21,29 @@ type _HasLayoutMarker<S> = {
20
21
  }[keyof S] extends never ? false : true;
21
22
  type ExtractLayoutShape<S extends Record<string, any>> = _HasLayoutMarker<S> extends true ? LayoutRestShape<S> & LayoutFieldShape<S> : S;
22
23
  type StrictComponentProps<C extends IsComponent> = {
23
- [K in keyof ComponentProps<C> as {} extends Record<K, unknown> ? never : K]: ComponentProps<C>[K];
24
+ [K in keyof ComponentProps<C> as K extends keyof VNodeProps ? never : {} extends Record<K, unknown> ? never : K]: ComponentProps<C>[K];
25
+ };
26
+ /** 控件事件监听通道;回调由 enhanceEventProps 追加字段上下文作为末位参数 */
27
+ type ControlEventProps = {
28
+ [K in `on${string}`]?: (...args: any[]) => void;
24
29
  };
25
30
  type StrictComponentSlots<C extends IsComponent> = IsAny<ComponentSlots<C>> extends true ? {} : ComponentSlots<C>;
26
31
  type ControlKey<TControls extends AutoFormControls> = Extract<KnownKeys<TControls>, string>;
27
32
  type ControlEntryByKey<TControls extends AutoFormControls, K extends string> = K extends keyof TControls ? TControls[K] : never;
33
+ type _IsUnion<T, U = T> = T extends U ? ([U] extends [T] ? false : true) : never;
34
+ /**
35
+ * 单一字面量放宽、多成员联合保留。
36
+ *
37
+ * Nuxt UI 的 props 泛型默认值偏窄(`M extends boolean = false`、`VK = 'value'`),
38
+ * 不放宽会让 `multiple: true` 之类的合法取值报错;而 `size` / `color` / `orientation`
39
+ * 这类真实字面量联合必须原样保留,否则失去补全。
40
+ */
41
+ type _WidenNarrow<T> = IsAny<T> extends true ? T : [NonNullable<T>] extends [never] ? unknown : _IsUnion<NonNullable<T>> extends true ? T : WidenLiteral<T>;
28
42
  type _WidenForFactory<T> = {
29
- [K in keyof T]+?: WidenLiteral<T[K]>;
43
+ [K in keyof T]+?: _WidenNarrow<T[K]>;
30
44
  };
31
45
  type _IsUnsetLike<P> = [P] extends [_Unset] ? true : IsAny<P> extends true ? true : [unknown] extends [P] ? true : [keyof P] extends [never] ? true : false;
32
- type ResolveControlProps<C extends IsComponent, P> = _IsUnsetLike<P> extends true ? StrictComponentProps<C> : Prettify<_WidenForFactory<P> & {}>;
46
+ type ResolveControlProps<C extends IsComponent, P> = _IsUnsetLike<P> extends true ? StrictComponentProps<C> : Prettify<_WidenForFactory<P> & {}> & ControlEventProps;
33
47
  type ExtractControlProps<T> = T extends AutoFormControl<infer C, infer P, any> ? ResolveControlProps<C, P> : T extends {
34
48
  component: infer C extends IsComponent;
35
49
  } ? StrictComponentProps<C> : {};
@@ -1,10 +1,13 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import { useFormField } from '@nuxt/ui/composables/useFormField';
3
+ import { useFieldGroup } from '@nuxt/ui/composables/useFieldGroup';
1
4
  export declare function omitProps<T extends object, K extends keyof T>(props: T, keys: readonly K[]): Omit<T, K>;
2
- export declare function useForwardedProps<T extends object, K extends keyof T>(props: T, keys: readonly K[]): import("vue").ComputedRef<Omit<T, K>>;
5
+ export declare function useForwardedProps<T extends object, K extends keyof T>(props: T, keys: readonly K[]): ComputedRef<Omit<T, K>>;
3
6
  type SizeProps = {
4
7
  size?: unknown;
5
8
  };
6
9
  export declare function useFormFieldBridge<S = unknown, T extends SizeProps = SizeProps>(props?: T): {
7
- size: import("vue").ComputedRef<S | undefined>;
10
+ size: ComputedRef<S | undefined>;
8
11
  emitFormInput: () => void;
9
12
  emitFormBlur: () => void;
10
13
  emitFormChange: () => void;
@@ -15,19 +18,14 @@ type FieldControlProps = {
15
18
  color?: unknown;
16
19
  disabled?: boolean;
17
20
  };
18
- export declare function useFieldControl<T extends FieldControlProps>(props: T): {
19
- size: import("vue").ComputedRef<NonNullable<T["size"]> | undefined>;
20
- disabled: import("vue").ComputedRef<boolean>;
21
- color: import("vue").ComputedRef<"error" | NonNullable<T["color"]> | undefined>;
22
- fieldGroupSize: import("vue").ComputedRef<"xs" | "sm" | "md" | "lg" | "xl" | NonNullable<import("@nuxt/ui").GetObjectField<T, "size">> | undefined>;
23
- fieldGroupOrientation: import("vue").ComputedRef<"horizontal" | "vertical" | undefined>;
24
- id: import("vue").ComputedRef<string | undefined>;
25
- name: import("vue").ComputedRef<string | undefined>;
26
- highlight: import("vue").ComputedRef<boolean | undefined>;
27
- emitFormBlur: () => void;
28
- emitFormInput: import("@vueuse/core").UseDebounceFnReturn<() => void>;
29
- emitFormChange: () => void;
30
- emitFormFocus: () => void;
31
- ariaAttrs: import("vue").ComputedRef<Record<string, any> | undefined>;
21
+ type FieldSize<T extends FieldControlProps> = NonNullable<T['size']> | undefined;
22
+ type FieldColor<T extends FieldControlProps> = NonNullable<T['color']> | 'error' | undefined;
23
+ type FieldControl<T extends FieldControlProps> = Omit<ReturnType<typeof useFormField<T>>, 'size' | 'color' | 'disabled'> & {
24
+ size: ComputedRef<FieldSize<T>>;
25
+ disabled: ComputedRef<boolean>;
26
+ color: ComputedRef<FieldColor<T>>;
27
+ fieldGroupSize: ReturnType<typeof useFieldGroup<T>>['size'];
28
+ fieldGroupOrientation: ReturnType<typeof useFieldGroup<T>>['orientation'];
32
29
  };
30
+ export declare function useFieldControl<T extends FieldControlProps>(props: T): FieldControl<T>;
33
31
  export {};
@@ -6,9 +6,8 @@ import type { ModuleOptions } from '../../module';
6
6
  */
7
7
  export declare function getDefaultConfig(theme?: ModuleOptions['theme']): {
8
8
  dir: Direction;
9
- radius: number;
9
+ radius: number | undefined;
10
10
  blackAsPrimary: boolean;
11
- font: string;
12
11
  icons: string;
13
12
  prefix: string | undefined;
14
13
  tv: {
@@ -17,10 +16,6 @@ export declare function getDefaultConfig(theme?: ModuleOptions['theme']): {
17
16
  };
18
17
  };
19
18
  picker: {
20
- fonts: {
21
- name: string;
22
- href?: string;
23
- }[];
24
19
  radiuses: number[];
25
20
  neutralColors: string[];
26
21
  };
@@ -1,21 +1,11 @@
1
1
  export function getDefaultConfig(theme) {
2
- const pickerFonts = theme?.fonts ?? [
3
- { name: "Alibaba PuHuiTi", href: "https://cdn.mhaibaraai.cn/fonts/alibaba-puhuiti.css" },
4
- { name: "Public Sans" },
5
- { name: "DM Sans" },
6
- { name: "Geist" },
7
- { name: "Inter" },
8
- { name: "Poppins" },
9
- { name: "Outfit" },
10
- { name: "Raleway" }
11
- ];
12
2
  const pickerRadiuses = theme?.radiuses ?? [0, 0.125, 0.25, 0.375, 0.5];
13
3
  const pickerNeutralColors = theme?.neutralColors ?? ["slate", "gray", "zinc", "neutral", "stone", "taupe", "mauve", "mist", "olive"];
14
4
  return {
15
5
  dir: "ltr",
16
- radius: 0.25,
6
+ // 缺省不指定圆角:运行时不注入 --ui-radius,沿用 @nuxt/ui 默认值或项目 CSS
7
+ radius: theme?.radius,
17
8
  blackAsPrimary: false,
18
- font: "Alibaba PuHuiTi",
19
9
  icons: "lucide",
20
10
  prefix: theme?.prefix,
21
11
  tv: {
@@ -23,6 +13,6 @@ export function getDefaultConfig(theme) {
23
13
  prefix: theme?.prefix
24
14
  }
25
15
  },
26
- picker: { fonts: pickerFonts, radiuses: pickerRadiuses, neutralColors: pickerNeutralColors }
16
+ picker: { radiuses: pickerRadiuses, neutralColors: pickerNeutralColors }
27
17
  };
28
18
  }
@@ -1,6 +1,11 @@
1
1
  import 'node:url';
2
2
  import { kebabCase } from 'scule';
3
3
  import { addTypeTemplate, addTemplate, getLayerDirectories } from '@nuxt/kit';
4
+ import { resolveFontSource, resolveFontFamily } from '../../dist/runtime/domains/theme/theme-font.js';
5
+ import { readFileSync } from 'node:fs';
6
+ import { createRequire } from 'node:module';
7
+ import { join } from 'pathe';
8
+ import { globSync } from 'tinyglobby';
4
9
 
5
10
  const popconfirm = () => ({
6
11
  slots: {
@@ -539,14 +544,21 @@ function getTemplates(options, nuxt) {
539
544
  sources.push('@source "./movk-ui";');
540
545
  return sources.join("\n");
541
546
  }
547
+ function generateFontTheme() {
548
+ if (options.theme?.enabled === false) return "";
549
+ const source = resolveFontSource(options.theme?.font);
550
+ if (!source) return "";
551
+ return `@theme {
552
+ --font-sans: ${resolveFontFamily(source.name)};
553
+ }`;
554
+ }
542
555
  templates.push({
543
556
  filename: "movk-ui.css",
544
557
  write: true,
545
558
  getContents: async () => {
546
559
  const sources = await generateSources();
547
560
  const inlineSafelist = '@source inline("{,sm:,md:,lg:,xl:}grid-cols-{1,2,3,4,5,6,7,8,9,10,11,12}");';
548
- return `${sources}
549
- ${inlineSafelist}`;
561
+ return [sources, inlineSafelist, generateFontTheme()].filter(Boolean).join("\n");
550
562
  }
551
563
  });
552
564
  templates.push({
@@ -567,24 +579,16 @@ import type { HookResult } from '@nuxt/schema'
567
579
  import type { FetchContext } from 'ofetch'
568
580
 
569
581
  type Radius = 0 | 0.125 | 0.25 | 0.375 | 0.5
570
- type FontFamily = 'Alibaba PuHuiTi' | 'Public Sans' | 'DM Sans' | 'Geist' | 'Inter' | 'Poppins' | 'Outfit' | 'Raleway'
571
582
  type Icons = 'lucide' | 'phosphor' | 'tabler'
572
583
 
573
- interface PickerFontEntry {
574
- name: string
575
- href?: string
576
- }
577
-
578
584
  type AppConfigUI = {
579
585
  dir?: Direction,
580
586
  radius?: Radius | (number & {})
581
587
  blackAsPrimary?: boolean
582
- font?: FontFamily | (string & {})
583
588
  icons?: Icons | (string & {})
584
589
  prefix?: string
585
590
  tv?: typeof defaultConfig
586
591
  picker?: {
587
- fonts?: PickerFontEntry[]
588
592
  radiuses?: number[]
589
593
  neutralColors?: string[]
590
594
  }
@@ -672,6 +676,72 @@ async function addTemplates(options, nuxt) {
672
676
  }
673
677
  }
674
678
 
679
+ const DEFAULT_ICON_COLLECTION = "lucide";
680
+ const ICON_SOURCE_GLOB = ["**/*.{vue,ts,js,mjs}"];
681
+ const ICON_RE = /i-(lucide|ph|tabler)-([a-z\d]+(?:-[a-z\d]+)*)/g;
682
+ function scanMovkIcons(runtimeDir, options = {}) {
683
+ const ignore = options.theme === false ? ["domains/theme/**", "components/theme-picker/**"] : [];
684
+ const files = globSync(ICON_SOURCE_GLOB, { cwd: runtimeDir, ignore, absolute: true });
685
+ const icons = /* @__PURE__ */ new Set();
686
+ for (const file of files) {
687
+ let code;
688
+ try {
689
+ code = readFileSync(file, "utf-8");
690
+ } catch {
691
+ continue;
692
+ }
693
+ for (const match of code.matchAll(ICON_RE)) {
694
+ icons.add(`${match[1]}:${match[2]}`);
695
+ }
696
+ }
697
+ return [...icons].sort();
698
+ }
699
+ function isCollectionInstalled(prefix, paths) {
700
+ for (const dir of paths) {
701
+ try {
702
+ createRequire(join(dir, "index.js")).resolve(`@iconify-json/${prefix}/icons.json`);
703
+ return true;
704
+ } catch {
705
+ }
706
+ }
707
+ return false;
708
+ }
709
+ function filterResolvableIcons(icons, paths) {
710
+ const installed = /* @__PURE__ */ new Map();
711
+ const missing = /* @__PURE__ */ new Set();
712
+ const kept = [];
713
+ for (const icon of icons) {
714
+ const prefix = icon.split(":")[0];
715
+ if (!installed.has(prefix)) {
716
+ installed.set(prefix, isCollectionInstalled(prefix, paths));
717
+ }
718
+ if (installed.get(prefix)) {
719
+ kept.push(icon);
720
+ } else {
721
+ missing.add(prefix);
722
+ }
723
+ }
724
+ return { icons: kept, missing: [...missing] };
725
+ }
726
+ function resolveMovkIcons(runtimeDir, options) {
727
+ return filterResolvableIcons(
728
+ scanMovkIcons(runtimeDir, { theme: options.theme }),
729
+ options.paths
730
+ );
731
+ }
732
+ function formatMissingCollections(missing) {
733
+ const hint = (prefixes) => {
734
+ const packages = prefixes.map((prefix) => `@iconify-json/${prefix}`);
735
+ return `Missing ${packages.map((pkg) => `\`${pkg}\``).join(", ")}, so Movk icons from these collections are loaded at runtime. Install to bundle them at build time: \`npx nypm add -D ${packages.join(" ")}\``;
736
+ };
737
+ const required = missing.filter((prefix) => prefix === DEFAULT_ICON_COLLECTION);
738
+ const optional = missing.filter((prefix) => prefix !== DEFAULT_ICON_COLLECTION);
739
+ return {
740
+ warn: required.length ? hint(required) : void 0,
741
+ debug: optional.length ? hint(optional) : void 0
742
+ };
743
+ }
744
+
675
745
  const UI_COMPONENTS = [
676
746
  "UAccordion",
677
747
  "UButton",
@@ -708,4 +778,4 @@ const UI_COMPONENTS = [
708
778
  "UTree"
709
779
  ];
710
780
 
711
- export { UI_COMPONENTS as U, addTemplates as a, getTemplates as g };
781
+ export { UI_COMPONENTS as U, addTemplates as a, formatMissingCollections as f, getTemplates as g, resolveMovkIcons as r };
@@ -3,13 +3,14 @@ import { NuxtUIOptions } from '@nuxt/ui/unplugin';
3
3
  import { ModuleOptions } from './module.mjs';
4
4
  import '@nuxt/schema';
5
5
  import '../dist/runtime/types/api/module.js';
6
+ import '../dist/runtime/domains/theme/theme-font.js';
6
7
  import '@nuxt/ui';
7
8
  import '../dist/runtime/types/index.js';
8
9
 
9
10
  /** movk 组件层从 `#components` 具名导入的 @nuxt/ui 组件(去 U 前缀映射到 @nuxt/ui/components/<Name>.vue) */
10
11
  declare const UI_COMPONENTS: readonly ["UAccordion", "UButton", "UBadge", "UCheckbox", "UCollapsible", "UForm", "UDropdownMenu", "UIcon", "UInput", "UModal", "UPagination", "USelect", "UPopover", "UCalendar", "UColorPicker", "UTable", "UFormField", "UTooltip", "UInputNumber", "USwitch", "UTextarea", "USlider", "UPinInput", "UInputTags", "UFileUpload", "USelectMenu", "UInputMenu", "UCheckboxGroup", "URadioGroup", "UInputDate", "UInputTime", "UListbox", "UTree"];
11
12
 
12
- interface MovkUIOptions extends Pick<ModuleOptions, 'prefix' | 'theme'> {
13
+ interface MovkUIOptions extends Pick<ModuleOptions, 'prefix' | 'theme' | 'icon'> {
13
14
  /** 站点信息,注入 app.config.movkSite;name 作为主题 localStorage key 前缀 */
14
15
  site?: {
15
16
  url?: string;
package/dist/unplugin.mjs CHANGED
@@ -8,11 +8,13 @@ import MagicString from 'magic-string';
8
8
  import { resolvePathSync } from 'mlly';
9
9
  import fs from 'node:fs';
10
10
  import path from 'node:path';
11
- import { U as UI_COMPONENTS, g as getTemplates } from './shared/nuxt.DJKBap-S.mjs';
11
+ import { U as UI_COMPONENTS, g as getTemplates, r as resolveMovkIcons, f as formatMissingCollections } from './shared/nuxt.BT5mXYjs.mjs';
12
12
  import { kebabCase } from 'scule';
13
13
  import { getDefaultConfig } from '../dist/runtime/utils/theme-defaults.js';
14
14
  import { getPackageJsonMetadata } from '../dist/runtime/utils/meta.js';
15
+ import { resolveFontSource, resolveFontLinks, resolveFontWarning } from '../dist/runtime/domains/theme/theme-font.js';
15
16
  import '@nuxt/kit';
17
+ import 'node:module';
16
18
 
17
19
  function resolveRouterMode(options) {
18
20
  if (options.ui?.router === false) return "none";
@@ -201,6 +203,19 @@ function MovkPluginsPlugin(options) {
201
203
  };
202
204
  }
203
205
 
206
+ function MovkFontPlugin(options) {
207
+ const source = options.theme?.enabled === false ? void 0 : resolveFontSource(options.theme?.font);
208
+ const links = resolveFontLinks(source);
209
+ if (source && !links.length) {
210
+ console.warn(`[movk] ${resolveFontWarning(source.name)}`);
211
+ }
212
+ const tags = links.map((link) => ({ tag: "link", attrs: link, injectTo: "head" }));
213
+ return {
214
+ name: "movk:font",
215
+ vite: { transformIndexHtml: () => tags }
216
+ };
217
+ }
218
+
204
219
  const runtimeDir = normalize(fileURLToPath(new URL("./runtime", import.meta.url)));
205
220
  const MOVK_COMPOSABLES = {
206
221
  useAutoForm: ["useAutoForm", "defineControl", "DEFAULT_CONTROLS", "getAutoFormMetadata"],
@@ -208,6 +223,16 @@ const MOVK_COMPOSABLES = {
208
223
  useDateFormatter: ["useDateFormatter", "CalendarDate"],
209
224
  useMessageBox: ["useMessageBox"]
210
225
  };
226
+ function resolveMovkClientBundleIcons(options) {
227
+ if (options.icon?.clientBundle === false) return [];
228
+ const { icons, missing } = resolveMovkIcons(runtimeDir, {
229
+ theme: options.theme?.enabled !== false,
230
+ paths: [options.ui?.root || process.cwd()]
231
+ });
232
+ const { warn } = formatMissingCollections(missing);
233
+ if (warn) console.warn(`[movk] ${warn}`);
234
+ return icons;
235
+ }
211
236
  function createMovkComponentSource(cwd, prefix, ignore = []) {
212
237
  const files = globSync("**/*.vue", { cwd, ignore: ignore.filter(Boolean) });
213
238
  const paths = new Map(files.map((c) => {
@@ -227,10 +252,13 @@ const MovkPlugin = createUnplugin((_options = {}, meta) => {
227
252
  const componentIgnore = options.theme?.enabled === false ? ["theme-picker/**"] : [];
228
253
  const movkComponents = createMovkComponentSource(join(runtimeDir, "components"), options.prefix, componentIgnore);
229
254
  const ui = options.ui || {};
255
+ const movkIcons = resolveMovkClientBundleIcons(options);
230
256
  const uiOptions = defu(
231
257
  {
232
258
  prefix: "U",
233
259
  // movk 强制 U 前缀(U* shim 依赖),不可被 ui.prefix 覆盖
260
+ // movk 组件与内置图标集的图标进构建期图标包(ui.icon.clientBundle 为 false 时整体让位)
261
+ icon: movkIcons.length ? defu(ui.icon, { clientBundle: { icons: movkIcons } }) : ui.icon,
234
262
  // 把 movk 非服务端 composables 注入 @nuxt/ui 的 unplugin-auto-import 单实例(避免第二实例)
235
263
  autoImport: ui.autoImport === false ? false : defu(ui.autoImport, {
236
264
  // 对齐 Nuxt:允许在 <template> 内使用自动导入(如复用页里 :data="makePeople(30)")
@@ -251,6 +279,7 @@ const MovkPlugin = createUnplugin((_options = {}, meta) => {
251
279
  MovkAppConfigPlugin(options),
252
280
  ...Array.isArray(uiPlugins) ? uiPlugins : [uiPlugins],
253
281
  MovkTemplatePlugin(options),
282
+ MovkFontPlugin(options),
254
283
  MovkPluginsPlugin(options)
255
284
  ].flat(1);
256
285
  });
package/dist/vite.d.mts CHANGED
@@ -4,6 +4,7 @@ import '@nuxt/ui/unplugin';
4
4
  import './module.mjs';
5
5
  import '@nuxt/schema';
6
6
  import '../dist/runtime/types/api/module.js';
7
+ import '../dist/runtime/domains/theme/theme-font.js';
7
8
  import '@nuxt/ui';
8
9
  import '../dist/runtime/types/index.js';
9
10
 
package/dist/vite.mjs CHANGED
@@ -9,9 +9,11 @@ import 'magic-string';
9
9
  import 'mlly';
10
10
  import 'node:fs';
11
11
  import 'node:path';
12
- import './shared/nuxt.DJKBap-S.mjs';
12
+ import './shared/nuxt.BT5mXYjs.mjs';
13
13
  import 'scule';
14
14
  import '@nuxt/kit';
15
+ import '../dist/runtime/domains/theme/theme-font.js';
16
+ import 'node:module';
15
17
  import '../dist/runtime/utils/theme-defaults.js';
16
18
  import '../dist/runtime/utils/meta.js';
17
19
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@movk/nuxt",
3
3
  "type": "module",
4
- "version": "1.5.1",
5
- "packageManager": "pnpm@11.17.0",
4
+ "version": "1.7.0",
5
+ "packageManager": "pnpm@11.20.0",
6
6
  "description": "An engineering suite built on Nuxt UI: schema-driven AutoForm (Zod v4), a full-featured DataTable, standalone UI components and composables. Get the full capabilities — including API integration with auth & progress — in Nuxt 4, and use its UI, forms, tables and theming in plain Vue + Vite via the Vite plugin.",
7
7
  "author": "YiXuan <mhaibaraai@gmail.com>",
8
8
  "license": "MIT",
@@ -124,34 +124,33 @@
124
124
  "test:vue": "vitest --project vue"
125
125
  },
126
126
  "dependencies": {
127
- "@iconify-json/lucide": "^1.2.120",
128
- "@iconify-json/ph": "^1.2.2",
129
- "@iconify-json/tabler": "^1.2.37",
130
- "@internationalized/date": "^3.12.2",
127
+ "@internationalized/date": "^3.12.3",
131
128
  "@movk/core": "^1.4.1",
132
- "@nuxt/image": "^2.0.0",
129
+ "@nuxt/image": "^2.1.0",
133
130
  "@nuxt/ui": "^4.10.0",
134
131
  "@tanstack/vue-table": "^8.21.3",
135
- "@vueuse/core": "^14.3.0",
136
- "@vueuse/nuxt": "^14.3.0",
132
+ "@vueuse/core": "^14.4.0",
133
+ "@vueuse/nuxt": "^14.4.0",
137
134
  "colortranslator": "^6.1.1",
138
135
  "defu": "^6.1.7",
139
136
  "magic-string": "^1.1.0",
140
137
  "maska": "^3.2.0",
141
138
  "mlly": "^1.8.2",
142
- "nuxt-auth-utils": "^0.5.29",
143
- "nuxt-site-config": "^4.1.2",
139
+ "nuxt-auth-utils": "^0.5.30",
140
+ "nuxt-site-config": "^4.1.5",
144
141
  "pathe": "^2.0.3",
145
142
  "reka-ui": "2.10.1",
146
143
  "scule": "^1.3.0",
147
- "tailwind-variants": "^3.2.2",
144
+ "tailwind-variants": "^3.3.1",
148
145
  "tailwindcss": "^4.3.3",
149
146
  "tinyglobby": "^0.2.17",
150
- "unifont": "^0.7.4",
151
147
  "unplugin": "^3.3.0",
152
148
  "zod": "^4.4.3"
153
149
  },
154
150
  "devDependencies": {
151
+ "@iconify-json/lucide": "^1.2.121",
152
+ "@iconify-json/ph": "^1.2.2",
153
+ "@iconify-json/tabler": "^1.2.38",
155
154
  "@nuxt/eslint-config": "^1.16.0",
156
155
  "@nuxt/kit": "^4.5.1",
157
156
  "@nuxt/module-builder": "^1.0.3",
@@ -160,13 +159,13 @@
160
159
  "eslint": "^10.8.0",
161
160
  "happy-dom": "^20.11.1",
162
161
  "nuxt": "^4.5.1",
163
- "release-it": "^21.0.0",
162
+ "release-it": "^21.0.1",
164
163
  "typescript": "^6.0.3",
165
164
  "unbuild": "^3.6.1",
166
- "unplugin-auto-import": "^21.0.0",
165
+ "unplugin-auto-import": "^21.1.0",
167
166
  "unplugin-vue-components": "^32.1.0",
168
167
  "vitest": "^4.1.10",
169
168
  "vue": "^3.5.40",
170
- "vue-tsc": "^3.3.8"
169
+ "vue-tsc": "^3.3.9"
171
170
  }
172
171
  }