@yh-ui/nuxt 1.0.26 → 1.0.30

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/dist/module.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const crypto = require('node:crypto');
4
+ const node_module = require('node:module');
4
5
  const kit = require('@nuxt/kit');
5
6
 
6
7
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -14,6 +15,33 @@ if (typeof crypto__default.hash !== "function") {
14
15
  };
15
16
  }
16
17
  const PUBLISHED_CSS_ENTRY = "@yh-ui/components/style.css";
18
+ function getStylePathForComponent(componentName) {
19
+ const name = componentName.replace(/^Yh/, "");
20
+ const subComponentMap = {
21
+ Option: "select",
22
+ BreadcrumbItem: "breadcrumb",
23
+ DropdownItem: "dropdown",
24
+ DropdownMenu: "dropdown",
25
+ FormItem: "form",
26
+ FormSchema: "form",
27
+ GridItem: "grid",
28
+ Step: "steps",
29
+ TableColumn: "table",
30
+ TabPane: "tabs",
31
+ TreeNode: "tree",
32
+ CarouselItem: "carousel",
33
+ Header: "container",
34
+ Aside: "container",
35
+ Main: "container",
36
+ Footer: "container"
37
+ };
38
+ if (name.startsWith("Typography") && name !== "Typography") {
39
+ return "@yh-ui/components/dist/typography/src/typography.css";
40
+ }
41
+ const targetName = subComponentMap[name] || name;
42
+ const kebabName = targetName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
43
+ return `@yh-ui/components/dist/${kebabName}/src/${kebabName}.css`;
44
+ }
17
45
  const yhNuxtModule = kit.defineNuxtModule({
18
46
  meta: {
19
47
  name: "@yh-ui/nuxt",
@@ -33,11 +61,6 @@ const yhNuxtModule = kit.defineNuxtModule({
33
61
  setup(options, nuxt) {
34
62
  const { resolve } = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
35
63
  kit.addPlugin(resolve("./runtime/plugin.mjs"));
36
- if (options.importStyle) {
37
- if (!nuxt.options.css.includes(PUBLISHED_CSS_ENTRY)) {
38
- nuxt.options.css.push(PUBLISHED_CSS_ENTRY);
39
- }
40
- }
41
64
  if (options.buildTranspile) {
42
65
  nuxt.options.build.transpile = nuxt.options.build.transpile || [];
43
66
  const transpileList = ["@yh-ui/components", "@yh-ui/hooks", "@yh-ui/utils", "@yh-ui/theme"];
@@ -124,7 +147,7 @@ const yhNuxtModule = kit.defineNuxtModule({
124
147
  "Countdown",
125
148
  "Table",
126
149
  "TableColumn",
127
- // 新增组件
150
+ // 鏂板缁勪欢
128
151
  "Space",
129
152
  "Avatar",
130
153
  "Empty",
@@ -263,6 +286,80 @@ const yhNuxtModule = kit.defineNuxtModule({
263
286
  from: "@yh-ui/components"
264
287
  });
265
288
  });
289
+ if (options.importStyle === "all") {
290
+ if (!nuxt.options.css.includes(PUBLISHED_CSS_ENTRY)) {
291
+ nuxt.options.css.push(PUBLISHED_CSS_ENTRY);
292
+ }
293
+ } else if (options.importStyle === true) {
294
+ const existingStyles = /* @__PURE__ */ new Set();
295
+ try {
296
+ const _require = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
297
+ const fs = _require("node:fs");
298
+ const path = _require("node:path");
299
+ const pkgPath = _require.resolve("@yh-ui/components/package.json", {
300
+ paths: [nuxt.options.rootDir]
301
+ });
302
+ components.forEach((name) => {
303
+ const cssPath = getStylePathForComponent(`Yh${name}`);
304
+ if (cssPath) {
305
+ const localPath = cssPath.replace("@yh-ui/components", path.dirname(pkgPath));
306
+ if (fs.existsSync(localPath)) {
307
+ existingStyles.add(cssPath);
308
+ }
309
+ }
310
+ });
311
+ } catch {
312
+ }
313
+ kit.extendViteConfig((config) => {
314
+ config.plugins = config.plugins || [];
315
+ config.plugins.push({
316
+ name: "yh-ui:style-import",
317
+ enforce: "post",
318
+ transform(code, id) {
319
+ if (!id || !/\.(js|ts|vue|mjs|cjs)$/.test(id) || id.includes("node_modules")) {
320
+ return;
321
+ }
322
+ const importsMatch = code.match(
323
+ /import\s*\{([^}]+)\}\s*from\s*['"]@yh-ui\/components['"]/g
324
+ );
325
+ if (!importsMatch) {
326
+ return;
327
+ }
328
+ const componentsToInject = /* @__PURE__ */ new Set();
329
+ for (const matchStr of importsMatch) {
330
+ const innerMatch = matchStr.match(/\{([^}]+)\}/);
331
+ if (innerMatch) {
332
+ const specifiers = innerMatch[1].split(",");
333
+ for (const spec of specifiers) {
334
+ const name = spec.trim().split(/\s+as\s+/)[0].trim();
335
+ if (name.startsWith("Yh")) {
336
+ componentsToInject.add(name);
337
+ }
338
+ }
339
+ }
340
+ }
341
+ if (componentsToInject.size === 0) {
342
+ return;
343
+ }
344
+ const styleImports = [];
345
+ for (const comp of componentsToInject) {
346
+ const cssFile = getStylePathForComponent(comp);
347
+ if (cssFile) {
348
+ if (existingStyles.size === 0 || existingStyles.has(cssFile)) {
349
+ styleImports.push(`import '${cssFile}';`);
350
+ }
351
+ }
352
+ }
353
+ if (styleImports.length > 0) {
354
+ return {
355
+ code: code + "\n" + styleImports.join("\n"),
356
+ map: null
357
+ };
358
+ }
359
+ }
360
+ });
361
+ });
362
+ }
266
363
  kit.extendViteConfig((config) => {
267
364
  config.optimizeDeps ||= {};
268
365
  config.optimizeDeps.include ||= [];
package/dist/module.d.cts CHANGED
@@ -2,11 +2,13 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  /**
5
- * Whether to automatically inject published CSS styles.
6
- * If true, it will import the published CSS entry.
5
+ * Control how styles are imported:
6
+ * - `true` (default): Automatically inject styles on demand.
7
+ * - `'all'`: Inject the entire published style.css.
8
+ * - `false`: Disable automatic style injection.
7
9
  * @default true
8
10
  */
9
- importStyle?: boolean;
11
+ importStyle?: boolean | 'all';
10
12
  /**
11
13
  * Whether to transpile dependencies.
12
14
  * @default true
package/dist/module.d.mts CHANGED
@@ -2,11 +2,13 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  /**
5
- * Whether to automatically inject published CSS styles.
6
- * If true, it will import the published CSS entry.
5
+ * Control how styles are imported:
6
+ * - `true` (default): Automatically inject styles on demand.
7
+ * - `'all'`: Inject the entire published style.css.
8
+ * - `false`: Disable automatic style injection.
7
9
  * @default true
8
10
  */
9
- importStyle?: boolean;
11
+ importStyle?: boolean | 'all';
10
12
  /**
11
13
  * Whether to transpile dependencies.
12
14
  * @default true
package/dist/module.d.ts CHANGED
@@ -2,11 +2,13 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  /**
5
- * Whether to automatically inject published CSS styles.
6
- * If true, it will import the published CSS entry.
5
+ * Control how styles are imported:
6
+ * - `true` (default): Automatically inject styles on demand.
7
+ * - `'all'`: Inject the entire published style.css.
8
+ * - `false`: Disable automatic style injection.
7
9
  * @default true
8
10
  */
9
- importStyle?: boolean;
11
+ importStyle?: boolean | 'all';
10
12
  /**
11
13
  * Whether to transpile dependencies.
12
14
  * @default true
package/dist/module.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import crypto from 'node:crypto';
2
+ import { createRequire } from 'node:module';
2
3
  import { defineNuxtModule, createResolver, addPlugin, addComponent, addImports, extendViteConfig } from '@nuxt/kit';
3
4
 
4
5
  if (typeof crypto.hash !== "function") {
@@ -7,6 +8,33 @@ if (typeof crypto.hash !== "function") {
7
8
  };
8
9
  }
9
10
  const PUBLISHED_CSS_ENTRY = "@yh-ui/components/style.css";
11
+ function getStylePathForComponent(componentName) {
12
+ const name = componentName.replace(/^Yh/, "");
13
+ const subComponentMap = {
14
+ Option: "select",
15
+ BreadcrumbItem: "breadcrumb",
16
+ DropdownItem: "dropdown",
17
+ DropdownMenu: "dropdown",
18
+ FormItem: "form",
19
+ FormSchema: "form",
20
+ GridItem: "grid",
21
+ Step: "steps",
22
+ TableColumn: "table",
23
+ TabPane: "tabs",
24
+ TreeNode: "tree",
25
+ CarouselItem: "carousel",
26
+ Header: "container",
27
+ Aside: "container",
28
+ Main: "container",
29
+ Footer: "container"
30
+ };
31
+ if (name.startsWith("Typography") && name !== "Typography") {
32
+ return "@yh-ui/components/dist/typography/src/typography.css";
33
+ }
34
+ const targetName = subComponentMap[name] || name;
35
+ const kebabName = targetName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
36
+ return `@yh-ui/components/dist/${kebabName}/src/${kebabName}.css`;
37
+ }
10
38
  const yhNuxtModule = defineNuxtModule({
11
39
  meta: {
12
40
  name: "@yh-ui/nuxt",
@@ -26,11 +54,6 @@ const yhNuxtModule = defineNuxtModule({
26
54
  setup(options, nuxt) {
27
55
  const { resolve } = createResolver(import.meta.url);
28
56
  addPlugin(resolve("./runtime/plugin.mjs"));
29
- if (options.importStyle) {
30
- if (!nuxt.options.css.includes(PUBLISHED_CSS_ENTRY)) {
31
- nuxt.options.css.push(PUBLISHED_CSS_ENTRY);
32
- }
33
- }
34
57
  if (options.buildTranspile) {
35
58
  nuxt.options.build.transpile = nuxt.options.build.transpile || [];
36
59
  const transpileList = ["@yh-ui/components", "@yh-ui/hooks", "@yh-ui/utils", "@yh-ui/theme"];
@@ -117,7 +140,7 @@ const yhNuxtModule = defineNuxtModule({
117
140
  "Countdown",
118
141
  "Table",
119
142
  "TableColumn",
120
- // 新增组件
143
+ // 鏂板缁勪欢
121
144
  "Space",
122
145
  "Avatar",
123
146
  "Empty",
@@ -256,6 +279,80 @@ const yhNuxtModule = defineNuxtModule({
256
279
  from: "@yh-ui/components"
257
280
  });
258
281
  });
282
+ if (options.importStyle === "all") {
283
+ if (!nuxt.options.css.includes(PUBLISHED_CSS_ENTRY)) {
284
+ nuxt.options.css.push(PUBLISHED_CSS_ENTRY);
285
+ }
286
+ } else if (options.importStyle === true) {
287
+ const existingStyles = /* @__PURE__ */ new Set();
288
+ try {
289
+ const _require = createRequire(import.meta.url);
290
+ const fs = _require("node:fs");
291
+ const path = _require("node:path");
292
+ const pkgPath = _require.resolve("@yh-ui/components/package.json", {
293
+ paths: [nuxt.options.rootDir]
294
+ });
295
+ components.forEach((name) => {
296
+ const cssPath = getStylePathForComponent(`Yh${name}`);
297
+ if (cssPath) {
298
+ const localPath = cssPath.replace("@yh-ui/components", path.dirname(pkgPath));
299
+ if (fs.existsSync(localPath)) {
300
+ existingStyles.add(cssPath);
301
+ }
302
+ }
303
+ });
304
+ } catch {
305
+ }
306
+ extendViteConfig((config) => {
307
+ config.plugins = config.plugins || [];
308
+ config.plugins.push({
309
+ name: "yh-ui:style-import",
310
+ enforce: "post",
311
+ transform(code, id) {
312
+ if (!id || !/\.(js|ts|vue|mjs|cjs)$/.test(id) || id.includes("node_modules")) {
313
+ return;
314
+ }
315
+ const importsMatch = code.match(
316
+ /import\s*\{([^}]+)\}\s*from\s*['"]@yh-ui\/components['"]/g
317
+ );
318
+ if (!importsMatch) {
319
+ return;
320
+ }
321
+ const componentsToInject = /* @__PURE__ */ new Set();
322
+ for (const matchStr of importsMatch) {
323
+ const innerMatch = matchStr.match(/\{([^}]+)\}/);
324
+ if (innerMatch) {
325
+ const specifiers = innerMatch[1].split(",");
326
+ for (const spec of specifiers) {
327
+ const name = spec.trim().split(/\s+as\s+/)[0].trim();
328
+ if (name.startsWith("Yh")) {
329
+ componentsToInject.add(name);
330
+ }
331
+ }
332
+ }
333
+ }
334
+ if (componentsToInject.size === 0) {
335
+ return;
336
+ }
337
+ const styleImports = [];
338
+ for (const comp of componentsToInject) {
339
+ const cssFile = getStylePathForComponent(comp);
340
+ if (cssFile) {
341
+ if (existingStyles.size === 0 || existingStyles.has(cssFile)) {
342
+ styleImports.push(`import '${cssFile}';`);
343
+ }
344
+ }
345
+ }
346
+ if (styleImports.length > 0) {
347
+ return {
348
+ code: code + "\n" + styleImports.join("\n"),
349
+ map: null
350
+ };
351
+ }
352
+ }
353
+ });
354
+ });
355
+ }
259
356
  extendViteConfig((config) => {
260
357
  config.optimizeDeps ||= {};
261
358
  config.optimizeDeps.include ||= [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yh-ui/nuxt",
3
- "version": "1.0.26",
3
+ "version": "1.0.30",
4
4
  "description": "Nuxt module for YH-UI",
5
5
  "type": "module",
6
6
  "main": "./dist/module.cjs",
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@nuxt/kit": "^3.11.0 || ^4.0.0",
30
- "@yh-ui/components": "^1.0.26",
31
- "@yh-ui/hooks": "^1.0.26",
32
- "@yh-ui/theme": "^1.0.26"
30
+ "@yh-ui/components": "^1.0.30",
31
+ "@yh-ui/hooks": "^1.0.30",
32
+ "@yh-ui/theme": "^1.0.30"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@nuxt/schema": "^3.11.0 || ^4.0.0",