@sybz-components/utils 1.0.15 → 1.0.17

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/base.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  require('vue');
4
4
  require('consola');
5
5
  require('es-toolkit');
6
- const format = require('./shared/utils.RNNXtrF5.cjs');
6
+ const format = require('./shared/utils.CC08jxyG.cjs');
7
7
  require('./confirmSemantic.cjs');
8
8
  require('element-plus');
9
9
  require('axios');
package/dist/base.d.cts CHANGED
@@ -39,6 +39,8 @@ interface SybzUtilsConfig {
39
39
  http?: CreateHttpOptions;
40
40
  }
41
41
  interface ToastOptions extends Partial<MessageOptions> {
42
+ /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
+ showClose?: boolean;
42
44
  /**
43
45
  * 调用前是否先关闭全部消息提示。
44
46
  */
@@ -130,7 +132,7 @@ interface CopyOptions extends ToastOptions {
130
132
  */
131
133
  hideToast?: boolean;
132
134
  }
133
- type WidthInput = string | number | Ref<string | number>;
135
+ type WidthInput = string | number | boolean | Ref<string | number | boolean>;
134
136
  type ConfirmMessage = string | VNode | (() => VNode);
135
137
  type ConfirmTheme = UtilsTheme;
136
138
  interface ConfirmCustomOptions {
package/dist/base.d.mts CHANGED
@@ -39,6 +39,8 @@ interface SybzUtilsConfig {
39
39
  http?: CreateHttpOptions;
40
40
  }
41
41
  interface ToastOptions extends Partial<MessageOptions> {
42
+ /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
+ showClose?: boolean;
42
44
  /**
43
45
  * 调用前是否先关闭全部消息提示。
44
46
  */
@@ -130,7 +132,7 @@ interface CopyOptions extends ToastOptions {
130
132
  */
131
133
  hideToast?: boolean;
132
134
  }
133
- type WidthInput = string | number | Ref<string | number>;
135
+ type WidthInput = string | number | boolean | Ref<string | number | boolean>;
134
136
  type ConfirmMessage = string | VNode | (() => VNode);
135
137
  type ConfirmTheme = UtilsTheme;
136
138
  interface ConfirmCustomOptions {
package/dist/base.d.ts CHANGED
@@ -39,6 +39,8 @@ interface SybzUtilsConfig {
39
39
  http?: CreateHttpOptions;
40
40
  }
41
41
  interface ToastOptions extends Partial<MessageOptions> {
42
+ /** 是否启用仅在悬停关闭区域时出现的关闭按钮,默认 `true`。 */
43
+ showClose?: boolean;
42
44
  /**
43
45
  * 调用前是否先关闭全部消息提示。
44
46
  */
@@ -130,7 +132,7 @@ interface CopyOptions extends ToastOptions {
130
132
  */
131
133
  hideToast?: boolean;
132
134
  }
133
- type WidthInput = string | number | Ref<string | number>;
135
+ type WidthInput = string | number | boolean | Ref<string | number | boolean>;
134
136
  type ConfirmMessage = string | VNode | (() => VNode);
135
137
  type ConfirmTheme = UtilsTheme;
136
138
  interface ConfirmCustomOptions {
package/dist/base.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import 'vue';
2
2
  import 'consola';
3
3
  import 'es-toolkit';
4
- export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.2cNhEypm.mjs';
4
+ export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, f as debounce, g as delay, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.E1TDYt7o.mjs';
5
5
  import './confirmSemantic.mjs';
6
6
  import 'element-plus';
7
7
  import 'axios';
package/dist/format.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.RNNXtrF5.cjs');
3
+ const format = require('./shared/utils.CC08jxyG.cjs');
4
4
  require('./is.cjs');
5
5
  require('consola');
6
6
  require('vue');
package/dist/format.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.2cNhEypm.mjs';
1
+ export { z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed } from './shared/utils.E1TDYt7o.mjs';
2
2
  import './is.mjs';
3
3
  import 'consola';
4
4
  import 'vue';
package/dist/http.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  require('axios');
4
- const format = require('./shared/utils.RNNXtrF5.cjs');
4
+ const format = require('./shared/utils.CC08jxyG.cjs');
5
5
  require('vue');
6
6
  require('consola');
7
7
  require('es-toolkit');
package/dist/http.d.cts CHANGED
@@ -42,7 +42,6 @@ interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
42
42
  }
43
43
  type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
44
44
  <T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
45
- <T = unknown, D = unknown>(url: string, params?: unknown, config?: HttpRequestConfig<D>): Promise<T>;
46
45
  send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
47
46
  rawResponse: true;
48
47
  }): Promise<AxiosResponse<T>>;
@@ -50,12 +49,11 @@ type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete
50
49
  rawResponse?: false;
51
50
  }): Promise<T>;
52
51
  get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
53
- get<T = unknown>(url: string, params?: unknown, config?: HttpRequestConfig): Promise<T>;
54
- post<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
55
- put<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
56
- patch<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
52
+ post<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
53
+ put<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
54
+ patch<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
57
55
  delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
58
- download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
56
+ download(url: string, config?: HttpRequestConfig): Promise<Blob>;
59
57
  };
60
58
  declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
61
59
  /** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
package/dist/http.d.mts CHANGED
@@ -42,7 +42,6 @@ interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
42
42
  }
43
43
  type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
44
44
  <T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
45
- <T = unknown, D = unknown>(url: string, params?: unknown, config?: HttpRequestConfig<D>): Promise<T>;
46
45
  send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
47
46
  rawResponse: true;
48
47
  }): Promise<AxiosResponse<T>>;
@@ -50,12 +49,11 @@ type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete
50
49
  rawResponse?: false;
51
50
  }): Promise<T>;
52
51
  get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
53
- get<T = unknown>(url: string, params?: unknown, config?: HttpRequestConfig): Promise<T>;
54
- post<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
55
- put<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
56
- patch<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
52
+ post<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
53
+ put<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
54
+ patch<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
57
55
  delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
58
- download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
56
+ download(url: string, config?: HttpRequestConfig): Promise<Blob>;
59
57
  };
60
58
  declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
61
59
  /** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
package/dist/http.d.ts CHANGED
@@ -42,7 +42,6 @@ interface CreateHttpOptions<D = unknown> extends CreateAxiosDefaults<D> {
42
42
  }
43
43
  type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete'> & {
44
44
  <T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
45
- <T = unknown, D = unknown>(url: string, params?: unknown, config?: HttpRequestConfig<D>): Promise<T>;
46
45
  send<T = unknown, D = unknown>(config: HttpRequestConfig<D> & {
47
46
  rawResponse: true;
48
47
  }): Promise<AxiosResponse<T>>;
@@ -50,12 +49,11 @@ type HttpClient = Omit<AxiosInstance, 'get' | 'post' | 'put' | 'patch' | 'delete
50
49
  rawResponse?: false;
51
50
  }): Promise<T>;
52
51
  get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
53
- get<T = unknown>(url: string, params?: unknown, config?: HttpRequestConfig): Promise<T>;
54
- post<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
55
- put<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
56
- patch<T = unknown, D = unknown>(url: string, data?: D, config?: HttpRequestConfig<D>): Promise<T>;
52
+ post<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
53
+ put<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
54
+ patch<T = unknown, D = unknown>(url: string, config?: HttpRequestConfig<D>): Promise<T>;
57
55
  delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<T>;
58
- download(url: string, params?: unknown, config?: HttpRequestConfig): Promise<Blob>;
56
+ download(url: string, config?: HttpRequestConfig): Promise<Blob>;
59
57
  };
60
58
  declare function createHttp<D = unknown>(options?: CreateHttpOptions<D>): HttpClient;
61
59
  /** 全局 HTTP 客户端;通过 configureUtils({ http: ... }) 配置一次。 */
package/dist/http.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'axios';
2
- export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.2cNhEypm.mjs';
2
+ export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.E1TDYt7o.mjs';
3
3
  import 'vue';
4
4
  import 'consola';
5
5
  import 'es-toolkit';
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.RNNXtrF5.cjs');
3
+ const format = require('./shared/utils.CC08jxyG.cjs');
4
4
  const confirmSemantic = require('./confirmSemantic.cjs');
5
5
  const is = require('./is.cjs');
6
6
  const theme = require('./theme.cjs');
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { $ as $toast, H as HttpError, c as clearStorage, a as clone, G as configureHttp, b as configureUtils, d as confirm, e as copy, I as createHttp, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, J as http, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.2cNhEypm.mjs';
1
+ export { $ as $toast, H as HttpError, c as clearStorage, a as clone, G as configureHttp, b as configureUtils, d as confirm, e as copy, I as createHttp, f as debounce, g as delay, z as formatBytes, A as formatBytesConvert, B as formatDurationTime, C as formatTextToHtml, D as formatThousands, E as formatTime, F as formatToFixed, h as getStorage, i as getType, j as getUtilsBuildTime, k as getVariable, J as http, l as isEmpty, m as log, n as merge, o as mockValue, p as processWidth, r as random, s as setStorage, t as test, q as throttle, u as toLine, v as tryCatch, w as validate, x as validateForm, y as validateOnSubmit } from './shared/utils.E1TDYt7o.mjs';
2
2
  export { resolveConfirmSemantic } from './confirmSemantic.mjs';
3
3
  export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString } from './is.mjs';
4
4
  export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme } from './theme.mjs';
@@ -312,22 +312,15 @@ function createHttp(options = {}) {
312
312
  const response = await instance.request(config);
313
313
  return config.rawResponse ? response : response.data;
314
314
  };
315
- const isRequestConfig = (value) => record(value) && ["url", "method", "headers", "timeout", "rawResponse", "skipAuth", "showErrorToast", "message"].some(
316
- (key) => key in value
317
- );
318
- const request = (url, paramsOrConfig, config = {}) => {
319
- const params = isRequestConfig(paramsOrConfig) ? void 0 : paramsOrConfig;
320
- const requestConfig = isRequestConfig(paramsOrConfig) ? paramsOrConfig : config;
321
- return send({ ...requestConfig, method: "GET", url, params, rawResponse: false });
322
- };
315
+ const request = (url, config = {}) => send({ ...config, method: "GET", url, rawResponse: false });
323
316
  const client = Object.assign(request, instance, {
324
317
  send,
325
- get: (url, paramsOrConfig, config) => request(url, paramsOrConfig, config),
326
- post: (url, data, config) => send({ ...config, method: "POST", url, data, rawResponse: false }),
327
- put: (url, data, config) => send({ ...config, method: "PUT", url, data, rawResponse: false }),
328
- patch: (url, data, config) => send({ ...config, method: "PATCH", url, data, rawResponse: false }),
318
+ get: (url, config) => request(url, config),
319
+ post: (url, config) => send({ ...config, method: "POST", url, rawResponse: false }),
320
+ put: (url, config) => send({ ...config, method: "PUT", url, rawResponse: false }),
321
+ patch: (url, config) => send({ ...config, method: "PATCH", url, rawResponse: false }),
329
322
  delete: (url, config) => send({ ...config, method: "DELETE", url, rawResponse: false }),
330
- download: (url, params, config) => send({ ...config, method: "GET", url, params, responseType: "blob", rawResponse: false })
323
+ download: (url, config) => send({ ...config, method: "GET", url, responseType: "blob", rawResponse: false })
331
324
  });
332
325
  return client;
333
326
  }
@@ -403,9 +396,15 @@ function $toast(message, type = "success", otherParams = {}) {
403
396
  if (options.closeAll) {
404
397
  elementPlus.ElMessage.closeAll();
405
398
  }
406
- const resolvedCustomClass = customClass === "el" ? "" : _mergeClassNames("s-antd-message", theme !== "default" && `s-antd-message--${theme}`, customClass);
399
+ const resolvedCustomClass = _mergeClassNames(
400
+ "s-toast",
401
+ customClass !== "el" && "s-antd-message",
402
+ customClass !== "el" && theme !== "default" && `s-antd-message--${theme}`,
403
+ customClass !== "el" && customClass
404
+ );
407
405
  elementPlus.ElMessage({
408
406
  ...messageOptions,
407
+ showClose: options.showClose ?? true,
409
408
  customClass: resolvedCustomClass
410
409
  });
411
410
  }
@@ -928,10 +927,10 @@ const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
928
927
  const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
929
928
  function processWidth(initValue, isBase = false) {
930
929
  const raw = vue.unref(initValue);
931
- if (raw === void 0 || raw === null || raw === "") {
930
+ if (raw === void 0 || raw === null || raw === "" || raw === false) {
932
931
  return isBase ? "" : {};
933
932
  }
934
- const str = typeof raw === "number" ? `${raw}` : raw;
933
+ const str = raw === true ? "100%" : typeof raw === "number" ? `${raw}` : raw;
935
934
  let res;
936
935
  if (!isNaN(Number(str))) {
937
936
  res = str + "px";
@@ -1202,7 +1201,7 @@ function getVariable(propertyName, fallback = "") {
1202
1201
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1203
1202
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1204
1203
  {
1205
- return "2026-09-24 16:01:50";
1204
+ return "2026-11-10 13:51:09";
1206
1205
  }
1207
1206
  }
1208
1207
  function test() {
@@ -306,22 +306,15 @@ function createHttp(options = {}) {
306
306
  const response = await instance.request(config);
307
307
  return config.rawResponse ? response : response.data;
308
308
  };
309
- const isRequestConfig = (value) => record(value) && ["url", "method", "headers", "timeout", "rawResponse", "skipAuth", "showErrorToast", "message"].some(
310
- (key) => key in value
311
- );
312
- const request = (url, paramsOrConfig, config = {}) => {
313
- const params = isRequestConfig(paramsOrConfig) ? void 0 : paramsOrConfig;
314
- const requestConfig = isRequestConfig(paramsOrConfig) ? paramsOrConfig : config;
315
- return send({ ...requestConfig, method: "GET", url, params, rawResponse: false });
316
- };
309
+ const request = (url, config = {}) => send({ ...config, method: "GET", url, rawResponse: false });
317
310
  const client = Object.assign(request, instance, {
318
311
  send,
319
- get: (url, paramsOrConfig, config) => request(url, paramsOrConfig, config),
320
- post: (url, data, config) => send({ ...config, method: "POST", url, data, rawResponse: false }),
321
- put: (url, data, config) => send({ ...config, method: "PUT", url, data, rawResponse: false }),
322
- patch: (url, data, config) => send({ ...config, method: "PATCH", url, data, rawResponse: false }),
312
+ get: (url, config) => request(url, config),
313
+ post: (url, config) => send({ ...config, method: "POST", url, rawResponse: false }),
314
+ put: (url, config) => send({ ...config, method: "PUT", url, rawResponse: false }),
315
+ patch: (url, config) => send({ ...config, method: "PATCH", url, rawResponse: false }),
323
316
  delete: (url, config) => send({ ...config, method: "DELETE", url, rawResponse: false }),
324
- download: (url, params, config) => send({ ...config, method: "GET", url, params, responseType: "blob", rawResponse: false })
317
+ download: (url, config) => send({ ...config, method: "GET", url, responseType: "blob", rawResponse: false })
325
318
  });
326
319
  return client;
327
320
  }
@@ -397,9 +390,15 @@ function $toast(message, type = "success", otherParams = {}) {
397
390
  if (options.closeAll) {
398
391
  ElMessage.closeAll();
399
392
  }
400
- const resolvedCustomClass = customClass === "el" ? "" : _mergeClassNames("s-antd-message", theme !== "default" && `s-antd-message--${theme}`, customClass);
393
+ const resolvedCustomClass = _mergeClassNames(
394
+ "s-toast",
395
+ customClass !== "el" && "s-antd-message",
396
+ customClass !== "el" && theme !== "default" && `s-antd-message--${theme}`,
397
+ customClass !== "el" && customClass
398
+ );
401
399
  ElMessage({
402
400
  ...messageOptions,
401
+ showClose: options.showClose ?? true,
403
402
  customClass: resolvedCustomClass
404
403
  });
405
404
  }
@@ -922,10 +921,10 @@ const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
922
921
  const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
923
922
  function processWidth(initValue, isBase = false) {
924
923
  const raw = unref(initValue);
925
- if (raw === void 0 || raw === null || raw === "") {
924
+ if (raw === void 0 || raw === null || raw === "" || raw === false) {
926
925
  return isBase ? "" : {};
927
926
  }
928
- const str = typeof raw === "number" ? `${raw}` : raw;
927
+ const str = raw === true ? "100%" : typeof raw === "number" ? `${raw}` : raw;
929
928
  let res;
930
929
  if (!isNaN(Number(str))) {
931
930
  res = str + "px";
@@ -1196,7 +1195,7 @@ function getVariable(propertyName, fallback = "") {
1196
1195
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1197
1196
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1198
1197
  {
1199
- return "2026-09-24 16:01:50";
1198
+ return "2026-11-10 13:51:09";
1200
1199
  }
1201
1200
  }
1202
1201
  function test() {
@@ -90,24 +90,59 @@ const configurePackageJson = (force) => {
90
90
  `, "utf8");
91
91
  console.log("\u66F4\u65B0 package.json scripts");
92
92
  };
93
+ const gitRoot = () => {
94
+ try {
95
+ return node_child_process.execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" }).trim();
96
+ } catch {
97
+ throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5728 Git \u4ED3\u5E93\u4E2D\uFF0C\u65E0\u6CD5\u5B89\u88C5 Husky\uFF1A${cwd}`);
98
+ }
99
+ };
93
100
  const prepareHusky = () => {
94
- const result = husky__default();
95
- if (result) console.warn(result);
101
+ const root = gitRoot();
102
+ const original = process.cwd();
103
+ try {
104
+ process.chdir(root);
105
+ const result = husky__default();
106
+ if (result && result !== "HUSKY=0 skip install") throw new Error(`Husky \u5B89\u88C5\u5931\u8D25\uFF1A${result}`);
107
+ if (result) console.warn(result);
108
+ } finally {
109
+ process.chdir(original);
110
+ }
111
+ return root;
96
112
  };
113
+ const shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
97
114
  const configurePreCommit = () => {
98
- prepareHusky();
99
- const huskyDir = node_path.resolve(cwd, ".husky");
115
+ const root = prepareHusky();
116
+ const projectPath = node_path.relative(root, cwd);
117
+ const huskyDir = node_path.resolve(root, ".husky");
100
118
  const hookPath = node_path.resolve(huskyDir, "pre-commit");
101
- const command2 = "pnpm exec sybz-code-standard staged";
119
+ const oldCommand = "pnpm exec sybz-code-standard staged";
120
+ const command2 = projectPath ? `pnpm --dir ${shellQuote(projectPath)} exec sybz-code-standard staged` : oldCommand;
102
121
  node_fs.mkdirSync(huskyDir, { recursive: true });
103
122
  const current = node_fs.existsSync(hookPath) ? node_fs.readFileSync(hookPath, "utf8").trimEnd() : "";
104
- if (current.includes("sybz-code-standard staged")) return;
105
- node_fs.writeFileSync(hookPath, `${current ? `${current}
106
- ` : ""}${command2}
123
+ const lines = current ? current.split("\n") : [];
124
+ if (!lines.some((line) => line.trim() === command2)) {
125
+ const oldIndex = lines.findIndex((line) => line.trim() === oldCommand);
126
+ if (oldIndex >= 0) lines[oldIndex] = command2;
127
+ else lines.push(command2);
128
+ node_fs.writeFileSync(hookPath, `${lines.join("\n")}
107
129
  `, { encoding: "utf8", mode: 493 });
108
- console.log("\u66F4\u65B0 .husky/pre-commit");
130
+ console.log(`\u66F4\u65B0 ${node_path.relative(root, hookPath)}`);
131
+ }
132
+ if (projectPath) {
133
+ const obsoleteDir = node_path.resolve(cwd, ".husky");
134
+ const obsoleteHook = node_path.resolve(obsoleteDir, "pre-commit");
135
+ if (node_fs.existsSync(obsoleteHook) && node_fs.readFileSync(obsoleteHook, "utf8").trim() === oldCommand) {
136
+ node_fs.unlinkSync(obsoleteHook);
137
+ try {
138
+ node_fs.rmdirSync(obsoleteDir);
139
+ } catch {
140
+ }
141
+ }
142
+ }
109
143
  };
110
144
  const init = (args2) => {
145
+ gitRoot();
111
146
  const force = args2.includes("--force");
112
147
  configurePackageJson(force);
113
148
  for (const [filePath, content] of Object.entries(generatedFiles)) writeConfigFile(filePath, content, force);
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { execFileSync } from 'node:child_process';
3
- import { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from 'node:fs';
3
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync, rmdirSync, copyFileSync } from 'node:fs';
4
4
  import { createRequire } from 'node:module';
5
- import { resolve } from 'node:path';
5
+ import { resolve, relative } from 'node:path';
6
6
  import husky from 'husky';
7
7
 
8
8
  const cwd = process.cwd();
@@ -83,24 +83,59 @@ const configurePackageJson = (force) => {
83
83
  `, "utf8");
84
84
  console.log("\u66F4\u65B0 package.json scripts");
85
85
  };
86
+ const gitRoot = () => {
87
+ try {
88
+ return execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" }).trim();
89
+ } catch {
90
+ throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5728 Git \u4ED3\u5E93\u4E2D\uFF0C\u65E0\u6CD5\u5B89\u88C5 Husky\uFF1A${cwd}`);
91
+ }
92
+ };
86
93
  const prepareHusky = () => {
87
- const result = husky();
88
- if (result) console.warn(result);
94
+ const root = gitRoot();
95
+ const original = process.cwd();
96
+ try {
97
+ process.chdir(root);
98
+ const result = husky();
99
+ if (result && result !== "HUSKY=0 skip install") throw new Error(`Husky \u5B89\u88C5\u5931\u8D25\uFF1A${result}`);
100
+ if (result) console.warn(result);
101
+ } finally {
102
+ process.chdir(original);
103
+ }
104
+ return root;
89
105
  };
106
+ const shellQuote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
90
107
  const configurePreCommit = () => {
91
- prepareHusky();
92
- const huskyDir = resolve(cwd, ".husky");
108
+ const root = prepareHusky();
109
+ const projectPath = relative(root, cwd);
110
+ const huskyDir = resolve(root, ".husky");
93
111
  const hookPath = resolve(huskyDir, "pre-commit");
94
- const command2 = "pnpm exec sybz-code-standard staged";
112
+ const oldCommand = "pnpm exec sybz-code-standard staged";
113
+ const command2 = projectPath ? `pnpm --dir ${shellQuote(projectPath)} exec sybz-code-standard staged` : oldCommand;
95
114
  mkdirSync(huskyDir, { recursive: true });
96
115
  const current = existsSync(hookPath) ? readFileSync(hookPath, "utf8").trimEnd() : "";
97
- if (current.includes("sybz-code-standard staged")) return;
98
- writeFileSync(hookPath, `${current ? `${current}
99
- ` : ""}${command2}
116
+ const lines = current ? current.split("\n") : [];
117
+ if (!lines.some((line) => line.trim() === command2)) {
118
+ const oldIndex = lines.findIndex((line) => line.trim() === oldCommand);
119
+ if (oldIndex >= 0) lines[oldIndex] = command2;
120
+ else lines.push(command2);
121
+ writeFileSync(hookPath, `${lines.join("\n")}
100
122
  `, { encoding: "utf8", mode: 493 });
101
- console.log("\u66F4\u65B0 .husky/pre-commit");
123
+ console.log(`\u66F4\u65B0 ${relative(root, hookPath)}`);
124
+ }
125
+ if (projectPath) {
126
+ const obsoleteDir = resolve(cwd, ".husky");
127
+ const obsoleteHook = resolve(obsoleteDir, "pre-commit");
128
+ if (existsSync(obsoleteHook) && readFileSync(obsoleteHook, "utf8").trim() === oldCommand) {
129
+ unlinkSync(obsoleteHook);
130
+ try {
131
+ rmdirSync(obsoleteDir);
132
+ } catch {
133
+ }
134
+ }
135
+ }
102
136
  };
103
137
  const init = (args2) => {
138
+ gitRoot();
104
139
  const force = args2.includes("--force");
105
140
  configurePackageJson(force);
106
141
  for (const [filePath, content] of Object.entries(generatedFiles)) writeConfigFile(filePath, content, force);
package/dist/vite.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const node_module = require('node:module');
3
4
  const codeInspectorPlugin = require('code-inspector-plugin');
4
5
  const tailwindcss = require('@tailwindcss/vite');
5
6
  const vueJsx = require('@vitejs/plugin-vue-jsx');
@@ -8,11 +9,40 @@ require('node:child_process');
8
9
  require('node:fs');
9
10
  require('node:path');
10
11
 
12
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
13
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
14
 
13
15
  const tailwindcss__default = /*#__PURE__*/_interopDefaultCompat(tailwindcss);
14
16
  const vueJsx__default = /*#__PURE__*/_interopDefaultCompat(vueJsx);
15
17
 
18
+ const require2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.cjs', document.baseURI).href)));
19
+ const virtualTailwindId = "virtual:sybz-tailwind";
20
+ const resolvedVirtualTailwindId = `\0${virtualTailwindId}`;
21
+ const createTailwindEntry = () => {
22
+ const tailwindCssPath = require2.resolve("tailwindcss/index.css");
23
+ return {
24
+ name: "sybz-tailwind-entry",
25
+ resolveId(id) {
26
+ if (id === virtualTailwindId) return resolvedVirtualTailwindId;
27
+ },
28
+ load(id) {
29
+ if (id === resolvedVirtualTailwindId) return `import ${JSON.stringify(tailwindCssPath)}`;
30
+ },
31
+ transformIndexHtml: {
32
+ order: "pre",
33
+ handler() {
34
+ return [
35
+ {
36
+ tag: "script",
37
+ attrs: { type: "module" },
38
+ children: `import '${virtualTailwindId}'`,
39
+ injectTo: "head-prepend"
40
+ }
41
+ ];
42
+ }
43
+ }
44
+ };
45
+ };
16
46
  const createCodeInspector = (options = {}) => codeInspectorPlugin.codeInspectorPlugin({ editor: "code", ...options, bundler: "vite" });
17
47
  const formatBuildTime = (date) => {
18
48
  const pad = (value) => String(value).padStart(2, "0");
@@ -50,6 +80,7 @@ const sybzVitePlugins = (options = {}) => {
50
80
  }
51
81
  if (options.tailwind !== false) {
52
82
  plugins.push(...tailwindcss__default(typeof options.tailwind === "object" ? options.tailwind : {}));
83
+ if (options.tailwindCss !== false) plugins.push(createTailwindEntry());
53
84
  }
54
85
  if (options.codeInspector !== false) {
55
86
  plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
package/dist/vite.d.cts CHANGED
@@ -15,6 +15,8 @@ interface SybzVitePluginsOptions {
15
15
  vueJsx?: boolean | Options;
16
16
  /** Tailwind CSS v4 Vite 插件配置;默认启用,设为 false 时关闭。 */
17
17
  tailwind?: boolean | PluginOptions;
18
+ /** 自动向 HTML 注入 Tailwind CSS;默认启用,已有手动 CSS 入口时可设为 false。 */
19
+ tailwindCss?: boolean;
18
20
  /** 代码定位插件配置;默认启用,设为 false 时关闭。 */
19
21
  codeInspector?: boolean | SybzCodeInspectorOptions;
20
22
  /** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
package/dist/vite.d.mts CHANGED
@@ -15,6 +15,8 @@ interface SybzVitePluginsOptions {
15
15
  vueJsx?: boolean | Options;
16
16
  /** Tailwind CSS v4 Vite 插件配置;默认启用,设为 false 时关闭。 */
17
17
  tailwind?: boolean | PluginOptions;
18
+ /** 自动向 HTML 注入 Tailwind CSS;默认启用,已有手动 CSS 入口时可设为 false。 */
19
+ tailwindCss?: boolean;
18
20
  /** 代码定位插件配置;默认启用,设为 false 时关闭。 */
19
21
  codeInspector?: boolean | SybzCodeInspectorOptions;
20
22
  /** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
package/dist/vite.d.ts CHANGED
@@ -15,6 +15,8 @@ interface SybzVitePluginsOptions {
15
15
  vueJsx?: boolean | Options;
16
16
  /** Tailwind CSS v4 Vite 插件配置;默认启用,设为 false 时关闭。 */
17
17
  tailwind?: boolean | PluginOptions;
18
+ /** 自动向 HTML 注入 Tailwind CSS;默认启用,已有手动 CSS 入口时可设为 false。 */
19
+ tailwindCss?: boolean;
18
20
  /** 代码定位插件配置;默认启用,设为 false 时关闭。 */
19
21
  codeInspector?: boolean | SybzCodeInspectorOptions;
20
22
  /** Git 提交信息插件配置;默认启用,设为 false 时关闭。 */
package/dist/vite.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from 'node:module';
1
2
  import { codeInspectorPlugin } from 'code-inspector-plugin';
2
3
  import tailwindcss from '@tailwindcss/vite';
3
4
  import vueJsx from '@vitejs/plugin-vue-jsx';
@@ -6,6 +7,34 @@ import 'node:child_process';
6
7
  import 'node:fs';
7
8
  import 'node:path';
8
9
 
10
+ const require2 = createRequire(import.meta.url);
11
+ const virtualTailwindId = "virtual:sybz-tailwind";
12
+ const resolvedVirtualTailwindId = `\0${virtualTailwindId}`;
13
+ const createTailwindEntry = () => {
14
+ const tailwindCssPath = require2.resolve("tailwindcss/index.css");
15
+ return {
16
+ name: "sybz-tailwind-entry",
17
+ resolveId(id) {
18
+ if (id === virtualTailwindId) return resolvedVirtualTailwindId;
19
+ },
20
+ load(id) {
21
+ if (id === resolvedVirtualTailwindId) return `import ${JSON.stringify(tailwindCssPath)}`;
22
+ },
23
+ transformIndexHtml: {
24
+ order: "pre",
25
+ handler() {
26
+ return [
27
+ {
28
+ tag: "script",
29
+ attrs: { type: "module" },
30
+ children: `import '${virtualTailwindId}'`,
31
+ injectTo: "head-prepend"
32
+ }
33
+ ];
34
+ }
35
+ }
36
+ };
37
+ };
9
38
  const createCodeInspector = (options = {}) => codeInspectorPlugin({ editor: "code", ...options, bundler: "vite" });
10
39
  const formatBuildTime = (date) => {
11
40
  const pad = (value) => String(value).padStart(2, "0");
@@ -43,6 +72,7 @@ const sybzVitePlugins = (options = {}) => {
43
72
  }
44
73
  if (options.tailwind !== false) {
45
74
  plugins.push(...tailwindcss(typeof options.tailwind === "object" ? options.tailwind : {}));
75
+ if (options.tailwindCss !== false) plugins.push(createTailwindEntry());
46
76
  }
47
77
  if (options.codeInspector !== false) {
48
78
  plugins.push(createCodeInspector(typeof options.codeInspector === "object" ? options.codeInspector : {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybz-components/utils",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",