@sybz-components/utils 1.0.10 → 1.0.12

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 (43) hide show
  1. package/dist/base.cjs +2 -1
  2. package/dist/base.d.cts +6 -1
  3. package/dist/base.d.mts +6 -1
  4. package/dist/base.d.ts +6 -1
  5. package/dist/base.mjs +2 -1
  6. package/dist/codeStandard.cjs +108 -0
  7. package/dist/codeStandard.d.cts +17 -0
  8. package/dist/codeStandard.d.mts +17 -0
  9. package/dist/codeStandard.d.ts +17 -0
  10. package/dist/codeStandard.mjs +93 -0
  11. package/dist/confirmSemantic.d.cts +3 -1
  12. package/dist/confirmSemantic.d.mts +3 -1
  13. package/dist/confirmSemantic.d.ts +3 -1
  14. package/dist/format.cjs +2 -1
  15. package/dist/format.mjs +2 -1
  16. package/dist/http.cjs +20 -0
  17. package/dist/http.d.cts +66 -0
  18. package/dist/http.d.mts +66 -0
  19. package/dist/http.d.ts +66 -0
  20. package/dist/http.mjs +8 -0
  21. package/dist/index.cjs +12 -1
  22. package/dist/index.d.cts +3 -0
  23. package/dist/index.d.mts +3 -0
  24. package/dist/index.d.ts +3 -0
  25. package/dist/index.mjs +3 -1
  26. package/dist/shared/{utils.V4Kpqes0.cjs → utils.-eWHeuS_.cjs} +134 -2
  27. package/dist/shared/{utils.JIlaBPw3.mjs → utils.S76wYqQ8.mjs} +129 -4
  28. package/dist/sybz-code-standard.cjs +119 -0
  29. package/dist/sybz-code-standard.d.cts +1 -0
  30. package/dist/sybz-code-standard.d.mts +1 -0
  31. package/dist/sybz-code-standard.d.ts +1 -0
  32. package/dist/sybz-code-standard.mjs +112 -0
  33. package/dist/theme.cjs +11 -0
  34. package/dist/theme.d.cts +12 -0
  35. package/dist/theme.d.mts +12 -0
  36. package/dist/theme.d.ts +12 -0
  37. package/dist/theme.mjs +8 -0
  38. package/dist/vite.cjs +8 -0
  39. package/dist/vite.d.cts +4 -1
  40. package/dist/vite.d.mts +4 -1
  41. package/dist/vite.d.ts +4 -1
  42. package/dist/vite.mjs +4 -0
  43. package/package.json +24 -2
package/dist/index.cjs CHANGED
@@ -1,21 +1,26 @@
1
1
  'use strict';
2
2
 
3
- const format = require('./shared/utils.V4Kpqes0.cjs');
3
+ const format = require('./shared/utils.-eWHeuS_.cjs');
4
4
  const confirmSemantic = require('./confirmSemantic.cjs');
5
5
  const is = require('./is.cjs');
6
+ const theme = require('./theme.cjs');
6
7
  require('vue');
7
8
  require('consola');
8
9
  require('es-toolkit');
9
10
  require('element-plus');
11
+ require('axios');
10
12
 
11
13
 
12
14
 
13
15
  exports.$toast = format.$toast;
16
+ exports.HttpError = format.HttpError;
14
17
  exports.clearStorage = format.clearStorage;
15
18
  exports.clone = format.clone;
19
+ exports.configureHttp = format.configureHttp;
16
20
  exports.configureUtils = format.configureUtils;
17
21
  exports.confirm = format.confirm;
18
22
  exports.copy = format.copy;
23
+ exports.createHttp = format.createHttp;
19
24
  exports.debounce = format.debounce;
20
25
  exports.delay = format.delay;
21
26
  exports.formatBytes = format.formatBytes;
@@ -29,6 +34,10 @@ exports.getStorage = format.getStorage;
29
34
  exports.getType = format.getType;
30
35
  exports.getUtilsBuildTime = format.getUtilsBuildTime;
31
36
  exports.getVariable = format.getVariable;
37
+ Object.defineProperty(exports, "http", {
38
+ enumerable: true,
39
+ get: function () { return format.http; }
40
+ });
32
41
  exports.isEmpty = format.isEmpty;
33
42
  exports.log = format.log;
34
43
  exports.merge = format.merge;
@@ -66,3 +75,5 @@ exports.isUrl = is.isUrl;
66
75
  exports.objectToString = is.objectToString;
67
76
  exports.toRawType = is.toRawType;
68
77
  exports.toTypeString = is.toTypeString;
78
+ exports.SYBZ_THEME_PREFIX = theme.SYBZ_THEME_PREFIX;
79
+ exports.isSybzTheme = theme.isSybzTheme;
package/dist/index.d.cts CHANGED
@@ -2,5 +2,8 @@ export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTh
2
2
  export { ConfirmSemanticButtonType, ConfirmSemanticOptions, ConfirmSemanticResult, ConfirmSemanticTheme, ConfirmTarget, ConfirmVariant, resolveConfirmSemantic } from './confirmSemantic.cjs';
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.cjs';
4
4
  export { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.cjs';
5
+ export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme } from './theme.cjs';
6
+ export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.cjs';
5
7
  import 'vue';
6
8
  import 'element-plus';
9
+ import 'axios';
package/dist/index.d.mts CHANGED
@@ -2,5 +2,8 @@ export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTh
2
2
  export { ConfirmSemanticButtonType, ConfirmSemanticOptions, ConfirmSemanticResult, ConfirmSemanticTheme, ConfirmTarget, ConfirmVariant, 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 { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.mjs';
5
+ export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme } from './theme.mjs';
6
+ export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.mjs';
5
7
  import 'vue';
6
8
  import 'element-plus';
9
+ import 'axios';
package/dist/index.d.ts CHANGED
@@ -2,5 +2,8 @@ export { $toast, ConfirmCustomOptions, ConfirmMessage, ConfirmOptions, ConfirmTh
2
2
  export { ConfirmSemanticButtonType, ConfirmSemanticOptions, ConfirmSemanticResult, ConfirmSemanticTheme, ConfirmTarget, ConfirmVariant, resolveConfirmSemantic } from './confirmSemantic.js';
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.js';
4
4
  export { FormatBytesConvertOptions, FormatBytesOptions, FormatTimeFallback, FormatTimeInput, FormatToFixedOptions, formatBytes, formatBytesConvert, formatDurationTime, formatTextToHtml, formatThousands, formatTime, formatToFixed } from './format.js';
5
+ export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme } from './theme.js';
6
+ export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.js';
5
7
  import 'vue';
6
8
  import 'element-plus';
9
+ import 'axios';
package/dist/index.mjs CHANGED
@@ -1,7 +1,9 @@
1
- export { $ as $toast, c as clearStorage, a as clone, b as configureUtils, d as confirm, e as copy, 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, 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.JIlaBPw3.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.S76wYqQ8.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
+ export { SYBZ_THEME_PREFIX, isSybzTheme } from './theme.mjs';
4
5
  import 'vue';
5
6
  import 'consola';
6
7
  import 'es-toolkit';
7
8
  import 'element-plus';
9
+ import 'axios';
@@ -5,8 +5,13 @@ const consola = require('consola');
5
5
  const esToolkit = require('es-toolkit');
6
6
  const confirmSemantic = require('../confirmSemantic.cjs');
7
7
  const elementPlus = require('element-plus');
8
+ const axios = require('axios');
8
9
  const is = require('../is.cjs');
9
10
 
11
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
+
13
+ const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
14
+
10
15
  function formatBytes(bytes, options = {}) {
11
16
  let { digit = 2, thousands = false, prefix = "", suffix = "", roundType = "floor" } = options;
12
17
  if (is.isStringNumber(bytes) || is.isNumber(bytes)) {
@@ -220,21 +225,141 @@ function formatTextToHtml(str) {
220
225
  return withBreaks.replace(/\t/g, "    ");
221
226
  }
222
227
 
228
+ class HttpError extends Error {
229
+ status;
230
+ code;
231
+ data;
232
+ cause;
233
+ constructor(message, options = {}) {
234
+ super(message);
235
+ this.name = "HttpError";
236
+ Object.assign(this, options);
237
+ }
238
+ }
239
+ const record = (value) => typeof value === "object" && value !== null;
240
+ const defaultMessage = (data, fallback) => {
241
+ if (!record(data)) return fallback;
242
+ for (const key of ["detail", "error", "message"])
243
+ if (typeof data[key] === "string" && data[key]) return data[key];
244
+ return fallback;
245
+ };
246
+ function createHttp(options = {}) {
247
+ const {
248
+ isBusinessSuccess = (data) => !(record(data) && data.success === false),
249
+ getBusinessMessage = defaultMessage,
250
+ transformResponseData,
251
+ showErrorToast = true,
252
+ toast = (message) => $toast.error(message),
253
+ normalizeError,
254
+ getToken,
255
+ onRequest,
256
+ onResponse,
257
+ onError,
258
+ ...axiosOptions
259
+ } = options;
260
+ const instance = axios__default.create(axiosOptions);
261
+ const normalize = (error) => {
262
+ if (error instanceof HttpError) return error;
263
+ if (!axios__default.isAxiosError(error))
264
+ return new HttpError(error instanceof Error ? error.message : "\u8BF7\u6C42\u5931\u8D25", { cause: error });
265
+ const response = error.response;
266
+ const message = error.code === axios.AxiosError.ECONNABORTED || error.code === "ETIMEDOUT" ? "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5" : error.code === axios.AxiosError.ERR_CANCELED ? "\u8BF7\u6C42\u5DF2\u53D6\u6D88" : response ? `\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09` : "\u7F51\u7EDC\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5";
267
+ return new HttpError(getBusinessMessage(response?.data, message), {
268
+ status: response?.status,
269
+ code: error.code,
270
+ data: response?.data,
271
+ cause: error
272
+ });
273
+ };
274
+ instance.interceptors.request.use((config) => {
275
+ const requestConfig = config;
276
+ requestConfig.headers = axios.AxiosHeaders.from(requestConfig.headers);
277
+ if (!requestConfig.skipAuth) {
278
+ const token = getToken?.();
279
+ if (token && !requestConfig.headers.has("Authorization"))
280
+ requestConfig.headers.set("Authorization", `Bearer ${token}`);
281
+ }
282
+ return onRequest?.(requestConfig) || requestConfig;
283
+ });
284
+ instance.interceptors.response.use(
285
+ (response) => {
286
+ const config = response.config;
287
+ if (!isBusinessSuccess(response.data, response))
288
+ throw new HttpError(getBusinessMessage(response.data, "\u8BF7\u6C42\u5931\u8D25"), {
289
+ status: response.status,
290
+ data: response.data
291
+ });
292
+ if (transformResponseData && !config.rawResponse)
293
+ response.data = transformResponseData(
294
+ response.data,
295
+ response
296
+ );
297
+ onResponse?.(response);
298
+ return response;
299
+ },
300
+ async (error) => {
301
+ const normalized = normalizeError ? normalizeError(error) : normalize(error);
302
+ const response = axios__default.isAxiosError(error) ? error.response : void 0;
303
+ const requestConfig = response?.config;
304
+ const customMessage = requestConfig?.message;
305
+ const message = typeof customMessage === "function" ? customMessage(normalized) : customMessage || normalized.message;
306
+ if (requestConfig?.showErrorToast ?? showErrorToast) toast?.(message);
307
+ await onError?.(normalized, response);
308
+ throw normalized;
309
+ }
310
+ );
311
+ const send = async (config) => {
312
+ const response = await instance.request(config);
313
+ return config.rawResponse ? response : response.data;
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
+ };
323
+ const client = Object.assign(request, instance, {
324
+ 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 }),
329
+ 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 })
331
+ });
332
+ return client;
333
+ }
334
+ exports.http = createHttp();
335
+ function configureHttp(options = {}) {
336
+ exports.http = createHttp(options);
337
+ return exports.http;
338
+ }
339
+
223
340
  const DEFAULT_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn";
224
341
  const DEFAULT_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn";
225
342
  const CHENGHUA_CONFIRM_BOX_CLASS = "s-message-box--chenghua";
226
343
  const CHENGHUA_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--chenghua";
227
344
  const CHENGHUA_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--chenghua";
228
345
  const SHIJINGSHAN_CONFIRM_BOX_CLASS = "s-message-box--shijingshan";
346
+ const SYBZ_CONFIRM_BOX_CLASS = "s-message-box--sybz";
229
347
  const SHIJINGSHAN_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--shijingshan";
348
+ const SYBZ_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--sybz";
230
349
  const SHIJINGSHAN_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--shijingshan";
350
+ const SYBZ_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--sybz";
231
351
  const utilsConfig = {
232
- theme: "default"
352
+ theme: "default",
353
+ http: {}
233
354
  };
234
355
  function configureUtils(config) {
235
356
  if (config.theme !== void 0) {
236
357
  utilsConfig.theme = config.theme;
237
358
  }
359
+ if (config.http !== void 0) {
360
+ utilsConfig.http = config.http;
361
+ configureHttp(config.http);
362
+ }
238
363
  return { ...utilsConfig };
239
364
  }
240
365
  function _getBrowserStorage(isSession = false) {
@@ -976,6 +1101,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
976
1101
  const resolvedAppContext = _resolveAppContext(optionAppContext || argumentAppContext);
977
1102
  const isChenghuaTheme = theme === "chenghua";
978
1103
  const isShijingshanTheme = theme === "shijingshan";
1104
+ const isSybzTheme = theme === "sybz";
979
1105
  const mergeOptions = {
980
1106
  title: semantic.title,
981
1107
  draggable: true,
@@ -989,6 +1115,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
989
1115
  customClass: _mergeClassNames(
990
1116
  isChenghuaTheme && CHENGHUA_CONFIRM_BOX_CLASS,
991
1117
  isShijingshanTheme && SHIJINGSHAN_CONFIRM_BOX_CLASS,
1118
+ isSybzTheme && SYBZ_CONFIRM_BOX_CLASS,
992
1119
  variant !== "default" && `s-message-box--${variant}`,
993
1120
  customClass
994
1121
  ),
@@ -996,12 +1123,14 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
996
1123
  DEFAULT_CONFIRM_BUTTON_CLASS,
997
1124
  isChenghuaTheme && CHENGHUA_CONFIRM_BUTTON_CLASS,
998
1125
  isShijingshanTheme && SHIJINGSHAN_CONFIRM_BUTTON_CLASS,
1126
+ isSybzTheme && SYBZ_CONFIRM_BUTTON_CLASS,
999
1127
  confirmButtonClass
1000
1128
  ),
1001
1129
  cancelButtonClass: _mergeClassNames(
1002
1130
  DEFAULT_CANCEL_BUTTON_CLASS,
1003
1131
  isChenghuaTheme && CHENGHUA_CANCEL_BUTTON_CLASS,
1004
1132
  isShijingshanTheme && SHIJINGSHAN_CANCEL_BUTTON_CLASS,
1133
+ isSybzTheme && SYBZ_CANCEL_BUTTON_CLASS,
1005
1134
  cancelButtonClass
1006
1135
  )
1007
1136
  };
@@ -1072,7 +1201,7 @@ function getVariable(propertyName, fallback = "") {
1072
1201
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1073
1202
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1074
1203
  {
1075
- return "2026-09-03 15:20:19";
1204
+ return "2026-09-12 22:29:37";
1076
1205
  }
1077
1206
  }
1078
1207
  function test() {
@@ -1080,11 +1209,14 @@ function test() {
1080
1209
  }
1081
1210
 
1082
1211
  exports.$toast = $toast;
1212
+ exports.HttpError = HttpError;
1083
1213
  exports.clearStorage = clearStorage;
1084
1214
  exports.clone = clone;
1215
+ exports.configureHttp = configureHttp;
1085
1216
  exports.configureUtils = configureUtils;
1086
1217
  exports.confirm = confirm;
1087
1218
  exports.copy = copy;
1219
+ exports.createHttp = createHttp;
1088
1220
  exports.debounce = debounce;
1089
1221
  exports.delay = delay;
1090
1222
  exports.formatBytes = formatBytes;
@@ -2,7 +2,8 @@ import { isRef, unref, isVNode, toRaw } from 'vue';
2
2
  import { consola } from 'consola';
3
3
  import { cloneDeep } from 'es-toolkit';
4
4
  import { resolveConfirmSemantic } from '../confirmSemantic.mjs';
5
- import { ElMessageBox, ElMessage } from 'element-plus';
5
+ import { ElMessage, ElMessageBox } from 'element-plus';
6
+ import axios, { AxiosHeaders, AxiosError } from 'axios';
6
7
  import { isStringNumber, isNumber } from '../is.mjs';
7
8
 
8
9
  function formatBytes(bytes, options = {}) {
@@ -218,21 +219,141 @@ function formatTextToHtml(str) {
218
219
  return withBreaks.replace(/\t/g, "    ");
219
220
  }
220
221
 
222
+ class HttpError extends Error {
223
+ status;
224
+ code;
225
+ data;
226
+ cause;
227
+ constructor(message, options = {}) {
228
+ super(message);
229
+ this.name = "HttpError";
230
+ Object.assign(this, options);
231
+ }
232
+ }
233
+ const record = (value) => typeof value === "object" && value !== null;
234
+ const defaultMessage = (data, fallback) => {
235
+ if (!record(data)) return fallback;
236
+ for (const key of ["detail", "error", "message"])
237
+ if (typeof data[key] === "string" && data[key]) return data[key];
238
+ return fallback;
239
+ };
240
+ function createHttp(options = {}) {
241
+ const {
242
+ isBusinessSuccess = (data) => !(record(data) && data.success === false),
243
+ getBusinessMessage = defaultMessage,
244
+ transformResponseData,
245
+ showErrorToast = true,
246
+ toast = (message) => $toast.error(message),
247
+ normalizeError,
248
+ getToken,
249
+ onRequest,
250
+ onResponse,
251
+ onError,
252
+ ...axiosOptions
253
+ } = options;
254
+ const instance = axios.create(axiosOptions);
255
+ const normalize = (error) => {
256
+ if (error instanceof HttpError) return error;
257
+ if (!axios.isAxiosError(error))
258
+ return new HttpError(error instanceof Error ? error.message : "\u8BF7\u6C42\u5931\u8D25", { cause: error });
259
+ const response = error.response;
260
+ const message = error.code === AxiosError.ECONNABORTED || error.code === "ETIMEDOUT" ? "\u8BF7\u6C42\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5" : error.code === AxiosError.ERR_CANCELED ? "\u8BF7\u6C42\u5DF2\u53D6\u6D88" : response ? `\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09` : "\u7F51\u7EDC\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u540E\u91CD\u8BD5";
261
+ return new HttpError(getBusinessMessage(response?.data, message), {
262
+ status: response?.status,
263
+ code: error.code,
264
+ data: response?.data,
265
+ cause: error
266
+ });
267
+ };
268
+ instance.interceptors.request.use((config) => {
269
+ const requestConfig = config;
270
+ requestConfig.headers = AxiosHeaders.from(requestConfig.headers);
271
+ if (!requestConfig.skipAuth) {
272
+ const token = getToken?.();
273
+ if (token && !requestConfig.headers.has("Authorization"))
274
+ requestConfig.headers.set("Authorization", `Bearer ${token}`);
275
+ }
276
+ return onRequest?.(requestConfig) || requestConfig;
277
+ });
278
+ instance.interceptors.response.use(
279
+ (response) => {
280
+ const config = response.config;
281
+ if (!isBusinessSuccess(response.data, response))
282
+ throw new HttpError(getBusinessMessage(response.data, "\u8BF7\u6C42\u5931\u8D25"), {
283
+ status: response.status,
284
+ data: response.data
285
+ });
286
+ if (transformResponseData && !config.rawResponse)
287
+ response.data = transformResponseData(
288
+ response.data,
289
+ response
290
+ );
291
+ onResponse?.(response);
292
+ return response;
293
+ },
294
+ async (error) => {
295
+ const normalized = normalizeError ? normalizeError(error) : normalize(error);
296
+ const response = axios.isAxiosError(error) ? error.response : void 0;
297
+ const requestConfig = response?.config;
298
+ const customMessage = requestConfig?.message;
299
+ const message = typeof customMessage === "function" ? customMessage(normalized) : customMessage || normalized.message;
300
+ if (requestConfig?.showErrorToast ?? showErrorToast) toast?.(message);
301
+ await onError?.(normalized, response);
302
+ throw normalized;
303
+ }
304
+ );
305
+ const send = async (config) => {
306
+ const response = await instance.request(config);
307
+ return config.rawResponse ? response : response.data;
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
+ };
317
+ const client = Object.assign(request, instance, {
318
+ 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 }),
323
+ 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 })
325
+ });
326
+ return client;
327
+ }
328
+ let http = createHttp();
329
+ function configureHttp(options = {}) {
330
+ http = createHttp(options);
331
+ return http;
332
+ }
333
+
221
334
  const DEFAULT_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn";
222
335
  const DEFAULT_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn";
223
336
  const CHENGHUA_CONFIRM_BOX_CLASS = "s-message-box--chenghua";
224
337
  const CHENGHUA_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--chenghua";
225
338
  const CHENGHUA_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--chenghua";
226
339
  const SHIJINGSHAN_CONFIRM_BOX_CLASS = "s-message-box--shijingshan";
340
+ const SYBZ_CONFIRM_BOX_CLASS = "s-message-box--sybz";
227
341
  const SHIJINGSHAN_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--shijingshan";
342
+ const SYBZ_CONFIRM_BUTTON_CLASS = "s-message-box__confirm-btn--sybz";
228
343
  const SHIJINGSHAN_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--shijingshan";
344
+ const SYBZ_CANCEL_BUTTON_CLASS = "s-message-box__cancel-btn--sybz";
229
345
  const utilsConfig = {
230
- theme: "default"
346
+ theme: "default",
347
+ http: {}
231
348
  };
232
349
  function configureUtils(config) {
233
350
  if (config.theme !== void 0) {
234
351
  utilsConfig.theme = config.theme;
235
352
  }
353
+ if (config.http !== void 0) {
354
+ utilsConfig.http = config.http;
355
+ configureHttp(config.http);
356
+ }
236
357
  return { ...utilsConfig };
237
358
  }
238
359
  function _getBrowserStorage(isSession = false) {
@@ -974,6 +1095,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
974
1095
  const resolvedAppContext = _resolveAppContext(optionAppContext || argumentAppContext);
975
1096
  const isChenghuaTheme = theme === "chenghua";
976
1097
  const isShijingshanTheme = theme === "shijingshan";
1098
+ const isSybzTheme = theme === "sybz";
977
1099
  const mergeOptions = {
978
1100
  title: semantic.title,
979
1101
  draggable: true,
@@ -987,6 +1109,7 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
987
1109
  customClass: _mergeClassNames(
988
1110
  isChenghuaTheme && CHENGHUA_CONFIRM_BOX_CLASS,
989
1111
  isShijingshanTheme && SHIJINGSHAN_CONFIRM_BOX_CLASS,
1112
+ isSybzTheme && SYBZ_CONFIRM_BOX_CLASS,
990
1113
  variant !== "default" && `s-message-box--${variant}`,
991
1114
  customClass
992
1115
  ),
@@ -994,12 +1117,14 @@ function confirm(messageOrOptions, optionsOrAppContext = null, appContext = null
994
1117
  DEFAULT_CONFIRM_BUTTON_CLASS,
995
1118
  isChenghuaTheme && CHENGHUA_CONFIRM_BUTTON_CLASS,
996
1119
  isShijingshanTheme && SHIJINGSHAN_CONFIRM_BUTTON_CLASS,
1120
+ isSybzTheme && SYBZ_CONFIRM_BUTTON_CLASS,
997
1121
  confirmButtonClass
998
1122
  ),
999
1123
  cancelButtonClass: _mergeClassNames(
1000
1124
  DEFAULT_CANCEL_BUTTON_CLASS,
1001
1125
  isChenghuaTheme && CHENGHUA_CANCEL_BUTTON_CLASS,
1002
1126
  isShijingshanTheme && SHIJINGSHAN_CANCEL_BUTTON_CLASS,
1127
+ isSybzTheme && SYBZ_CANCEL_BUTTON_CLASS,
1003
1128
  cancelButtonClass
1004
1129
  )
1005
1130
  };
@@ -1070,11 +1195,11 @@ function getVariable(propertyName, fallback = "") {
1070
1195
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1071
1196
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1072
1197
  {
1073
- return "2026-09-03 15:20:19";
1198
+ return "2026-09-12 22:29:37";
1074
1199
  }
1075
1200
  }
1076
1201
  function test() {
1077
1202
  return `build time: ${getUtilsBuildTime()}`;
1078
1203
  }
1079
1204
 
1080
- export { $toast as $, formatBytesConvert as A, formatDurationTime as B, formatTextToHtml as C, formatThousands as D, formatTime as E, formatToFixed as F, clone as a, configureUtils as b, clearStorage as c, confirm as d, copy as e, debounce as f, delay as g, getStorage as h, getType as i, getUtilsBuildTime as j, getVariable as k, isEmpty as l, log as m, merge as n, mockValue as o, processWidth as p, throttle as q, random as r, setStorage as s, test as t, toLine as u, tryCatch as v, validate as w, validateForm as x, validateOnSubmit as y, formatBytes as z };
1205
+ export { $toast as $, formatBytesConvert as A, formatDurationTime as B, formatTextToHtml as C, formatThousands as D, formatTime as E, formatToFixed as F, configureHttp as G, HttpError as H, createHttp as I, http as J, clone as a, configureUtils as b, clearStorage as c, confirm as d, copy as e, debounce as f, delay as g, getStorage as h, getType as i, getUtilsBuildTime as j, getVariable as k, isEmpty as l, log as m, merge as n, mockValue as o, processWidth as p, throttle as q, random as r, setStorage as s, test as t, toLine as u, tryCatch as v, validate as w, validateForm as x, validateOnSubmit as y, formatBytes as z };
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const node_child_process = require('node:child_process');
5
+ const node_fs = require('node:fs');
6
+ const node_module = require('node:module');
7
+ const node_path = require('node:path');
8
+ const husky = require('husky');
9
+
10
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
+
13
+ const husky__default = /*#__PURE__*/_interopDefaultCompat(husky);
14
+
15
+ const cwd = process.cwd();
16
+ const require2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('sybz-code-standard.cjs', document.baseURI).href)));
17
+ const generatedFiles = {
18
+ "eslint.config.js": "export { sybzEslintConfig as default } from '@sybz-components/utils/codeStandard'\n",
19
+ ".prettierrc.js": "export { sybzPrettierConfig as default } from '@sybz-components/utils/codeStandard'\n",
20
+ "lint-staged.config.js": "export { sybzLintStagedConfig as default } from '@sybz-components/utils/codeStandard'\n",
21
+ ".editorconfig": `root = true
22
+
23
+ [*]
24
+ charset = utf-8
25
+ end_of_line = lf
26
+ indent_style = space
27
+ indent_size = 2
28
+ insert_final_newline = true
29
+ trim_trailing_whitespace = true
30
+ max_line_length = 120
31
+
32
+ [*.md]
33
+ trim_trailing_whitespace = false
34
+ `
35
+ };
36
+ const scripts = {
37
+ prepare: "sybz-code-standard prepare",
38
+ lint: "sybz-code-standard eslint . --fix",
39
+ "lint:check": "sybz-code-standard eslint .",
40
+ "lint:prettier": "sybz-code-standard prettier . --write",
41
+ "lint:prettier:check": "sybz-code-standard prettier . --check"
42
+ };
43
+ const runPackageBin = (packageName, binPath, args2) => {
44
+ const packageJsonPath = require2.resolve(`${packageName}/package.json`);
45
+ const executablePath = node_path.resolve(packageJsonPath, "..", binPath);
46
+ node_child_process.execFileSync(process.execPath, [executablePath, ...args2], { cwd, stdio: "inherit" });
47
+ };
48
+ const writeIfMissing = (relativePath, content) => {
49
+ const filePath = node_path.resolve(cwd, relativePath);
50
+ if (!node_fs.existsSync(filePath)) {
51
+ node_fs.writeFileSync(filePath, content, "utf8");
52
+ console.log(`\u521B\u5EFA ${relativePath}`);
53
+ return;
54
+ }
55
+ if (node_fs.readFileSync(filePath, "utf8") !== content) {
56
+ console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9`);
57
+ }
58
+ };
59
+ const configurePackageJson = () => {
60
+ const packageJsonPath = node_path.resolve(cwd, "package.json");
61
+ if (!node_fs.existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
62
+ const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, "utf8"));
63
+ packageJson.scripts ??= {};
64
+ for (const [name, command2] of Object.entries(scripts)) {
65
+ const current = packageJson.scripts[name];
66
+ if (!current || current === command2) {
67
+ packageJson.scripts[name] = command2;
68
+ } else {
69
+ console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4`);
70
+ }
71
+ }
72
+ node_fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
73
+ `, "utf8");
74
+ console.log("\u66F4\u65B0 package.json scripts");
75
+ };
76
+ const prepareHusky = () => {
77
+ const result = husky__default();
78
+ if (result) console.warn(result);
79
+ };
80
+ const configurePreCommit = () => {
81
+ prepareHusky();
82
+ const huskyDir = node_path.resolve(cwd, ".husky");
83
+ const hookPath = node_path.resolve(huskyDir, "pre-commit");
84
+ const command2 = "pnpm exec sybz-code-standard staged";
85
+ node_fs.mkdirSync(huskyDir, { recursive: true });
86
+ const current = node_fs.existsSync(hookPath) ? node_fs.readFileSync(hookPath, "utf8").trimEnd() : "";
87
+ if (current.includes("sybz-code-standard staged")) return;
88
+ node_fs.writeFileSync(hookPath, `${current ? `${current}
89
+ ` : ""}${command2}
90
+ `, { encoding: "utf8", mode: 493 });
91
+ console.log("\u66F4\u65B0 .husky/pre-commit");
92
+ };
93
+ const init = () => {
94
+ configurePackageJson();
95
+ for (const [filePath, content] of Object.entries(generatedFiles)) writeIfMissing(filePath, content);
96
+ configurePreCommit();
97
+ console.log("\n\u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2\u63A5\u5165\u3002");
98
+ };
99
+ const [command = "init", ...args] = process.argv.slice(2);
100
+ switch (command) {
101
+ case "init":
102
+ init();
103
+ break;
104
+ case "prepare":
105
+ prepareHusky();
106
+ break;
107
+ case "eslint":
108
+ runPackageBin("eslint", "bin/eslint.js", args);
109
+ break;
110
+ case "prettier":
111
+ runPackageBin("prettier", "bin/prettier.cjs", args);
112
+ break;
113
+ case "staged":
114
+ runPackageBin("lint-staged", "bin/lint-staged.js", args);
115
+ break;
116
+ default:
117
+ console.error(`\u672A\u77E5\u547D\u4EE4\uFF1A${command}`);
118
+ process.exitCode = 1;
119
+ }
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+