@sybz-components/utils 1.0.12 → 1.0.14

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.-eWHeuS_.cjs');
6
+ const format = require('./shared/utils.Cp3n3FrB.cjs');
7
7
  require('./confirmSemantic.cjs');
8
8
  require('element-plus');
9
9
  require('axios');
package/dist/base.d.cts CHANGED
@@ -481,7 +481,7 @@ declare function toLine(text: string, connect?: string): string;
481
481
  /**
482
482
  * 将宽度值规范化为可直接用于样式的结果。
483
483
  *
484
- * @param initValue 宽度值,支持数字、数字字符串、CSS 长度字符串和 `ref`。
484
+ * @param initValue 宽度值,支持数字、数字字符串、CSS 长度、CSS 计算函数和 `ref`。
485
485
  * @param isBase 为 `true` 时直接返回宽度字符串;否则返回 `{ width }` 对象。
486
486
  * @returns 宽度字符串或宽度样式对象;无效值返回空字符串或空对象。
487
487
  *
@@ -492,6 +492,10 @@ declare function toLine(text: string, connect?: string): string;
492
492
  * @example
493
493
  * processWidth('50%', true)
494
494
  * // => '50%'
495
+ *
496
+ * @example
497
+ * processWidth('calc(100% - 24px)', true)
498
+ * // => 'calc(100% - 24px)'
495
499
  */
496
500
  declare function processWidth(initValue: WidthInput, isBase: true): string;
497
501
  declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
package/dist/base.d.mts CHANGED
@@ -481,7 +481,7 @@ declare function toLine(text: string, connect?: string): string;
481
481
  /**
482
482
  * 将宽度值规范化为可直接用于样式的结果。
483
483
  *
484
- * @param initValue 宽度值,支持数字、数字字符串、CSS 长度字符串和 `ref`。
484
+ * @param initValue 宽度值,支持数字、数字字符串、CSS 长度、CSS 计算函数和 `ref`。
485
485
  * @param isBase 为 `true` 时直接返回宽度字符串;否则返回 `{ width }` 对象。
486
486
  * @returns 宽度字符串或宽度样式对象;无效值返回空字符串或空对象。
487
487
  *
@@ -492,6 +492,10 @@ declare function toLine(text: string, connect?: string): string;
492
492
  * @example
493
493
  * processWidth('50%', true)
494
494
  * // => '50%'
495
+ *
496
+ * @example
497
+ * processWidth('calc(100% - 24px)', true)
498
+ * // => 'calc(100% - 24px)'
495
499
  */
496
500
  declare function processWidth(initValue: WidthInput, isBase: true): string;
497
501
  declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
package/dist/base.d.ts CHANGED
@@ -481,7 +481,7 @@ declare function toLine(text: string, connect?: string): string;
481
481
  /**
482
482
  * 将宽度值规范化为可直接用于样式的结果。
483
483
  *
484
- * @param initValue 宽度值,支持数字、数字字符串、CSS 长度字符串和 `ref`。
484
+ * @param initValue 宽度值,支持数字、数字字符串、CSS 长度、CSS 计算函数和 `ref`。
485
485
  * @param isBase 为 `true` 时直接返回宽度字符串;否则返回 `{ width }` 对象。
486
486
  * @returns 宽度字符串或宽度样式对象;无效值返回空字符串或空对象。
487
487
  *
@@ -492,6 +492,10 @@ declare function toLine(text: string, connect?: string): string;
492
492
  * @example
493
493
  * processWidth('50%', true)
494
494
  * // => '50%'
495
+ *
496
+ * @example
497
+ * processWidth('calc(100% - 24px)', true)
498
+ * // => 'calc(100% - 24px)'
495
499
  */
496
500
  declare function processWidth(initValue: WidthInput, isBase: true): string;
497
501
  declare function processWidth(initValue: WidthInput, isBase?: false): WidthStyleResult | {};
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.S76wYqQ8.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.Dx5Dp11G.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.-eWHeuS_.cjs');
3
+ const format = require('./shared/utils.Cp3n3FrB.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.S76wYqQ8.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.Dx5Dp11G.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.-eWHeuS_.cjs');
4
+ const format = require('./shared/utils.Cp3n3FrB.cjs');
5
5
  require('vue');
6
6
  require('consola');
7
7
  require('es-toolkit');
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.S76wYqQ8.mjs';
2
+ export { H as HttpError, G as configureHttp, I as createHttp, J as http } from './shared/utils.Dx5Dp11G.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.-eWHeuS_.cjs');
3
+ const format = require('./shared/utils.Cp3n3FrB.cjs');
4
4
  const confirmSemantic = require('./confirmSemantic.cjs');
5
5
  const is = require('./is.cjs');
6
6
  const theme = require('./theme.cjs');
@@ -77,3 +77,4 @@ exports.toRawType = is.toRawType;
77
77
  exports.toTypeString = is.toTypeString;
78
78
  exports.SYBZ_THEME_PREFIX = theme.SYBZ_THEME_PREFIX;
79
79
  exports.isSybzTheme = theme.isSybzTheme;
80
+ exports.resolveSybzComponentTheme = theme.resolveSybzComponentTheme;
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ 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';
5
+ export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme, resolveSybzComponentTheme } from './theme.cjs';
6
6
  export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.cjs';
7
7
  import 'vue';
8
8
  import 'element-plus';
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ 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';
5
+ export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme, resolveSybzComponentTheme } from './theme.mjs';
6
6
  export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.mjs';
7
7
  import 'vue';
8
8
  import 'element-plus';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ 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';
5
+ export { SYBZ_THEME_PREFIX, SybzComponentTheme, SybzThemeName, isSybzTheme, resolveSybzComponentTheme } from './theme.js';
6
6
  export { CreateHttpOptions, HttpClient, HttpError, HttpRequestConfig, configureHttp, createHttp, http } from './http.js';
7
7
  import 'vue';
8
8
  import 'element-plus';
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
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';
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.Dx5Dp11G.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
+ export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme } from './theme.mjs';
5
5
  import 'vue';
6
6
  import 'consola';
7
7
  import 'es-toolkit';
@@ -925,6 +925,7 @@ function toLine(text, connect = "-") {
925
925
  return translateText;
926
926
  }
927
927
  const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
928
+ const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
928
929
  function processWidth(initValue, isBase = false) {
929
930
  const raw = vue.unref(initValue);
930
931
  if (raw === void 0 || raw === null || raw === "") {
@@ -934,7 +935,7 @@ function processWidth(initValue, isBase = false) {
934
935
  let res;
935
936
  if (!isNaN(Number(str))) {
936
937
  res = str + "px";
937
- } else if (_CSS_UNIT_RE.test(str)) {
938
+ } else if (_CSS_UNIT_RE.test(str) || _CSS_LENGTH_FUNCTION_RE.test(str)) {
938
939
  res = str;
939
940
  } else {
940
941
  return isBase ? "" : {};
@@ -1201,7 +1202,7 @@ function getVariable(propertyName, fallback = "") {
1201
1202
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1202
1203
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1203
1204
  {
1204
- return "2026-09-12 22:29:37";
1205
+ return "2026-09-23 17:35:43";
1205
1206
  }
1206
1207
  }
1207
1208
  function test() {
@@ -919,6 +919,7 @@ function toLine(text, connect = "-") {
919
919
  return translateText;
920
920
  }
921
921
  const _CSS_UNIT_RE = /^[0-9]+(\.[0-9]+)?(px|%|em|rem|vw|vh|ch)$/;
922
+ const _CSS_LENGTH_FUNCTION_RE = /^(?:calc|min|max|clamp|var)\(.+\)$/;
922
923
  function processWidth(initValue, isBase = false) {
923
924
  const raw = unref(initValue);
924
925
  if (raw === void 0 || raw === null || raw === "") {
@@ -928,7 +929,7 @@ function processWidth(initValue, isBase = false) {
928
929
  let res;
929
930
  if (!isNaN(Number(str))) {
930
931
  res = str + "px";
931
- } else if (_CSS_UNIT_RE.test(str)) {
932
+ } else if (_CSS_UNIT_RE.test(str) || _CSS_LENGTH_FUNCTION_RE.test(str)) {
932
933
  res = str;
933
934
  } else {
934
935
  return isBase ? "" : {};
@@ -1195,7 +1196,7 @@ function getVariable(propertyName, fallback = "") {
1195
1196
  const DEFAULT_BUILD_TIME_FALLBACK = "\u672A\u6CE8\u5165";
1196
1197
  function getUtilsBuildTime(fallback = DEFAULT_BUILD_TIME_FALLBACK) {
1197
1198
  {
1198
- return "2026-09-12 22:29:37";
1199
+ return "2026-09-23 17:35:43";
1199
1200
  }
1200
1201
  }
1201
1202
  function test() {
@@ -45,30 +45,47 @@ const runPackageBin = (packageName, binPath, args2) => {
45
45
  const executablePath = node_path.resolve(packageJsonPath, "..", binPath);
46
46
  node_child_process.execFileSync(process.execPath, [executablePath, ...args2], { cwd, stdio: "inherit" });
47
47
  };
48
- const writeIfMissing = (relativePath, content) => {
48
+ const backupFile = (filePath) => {
49
+ const backupPath = `${filePath}.sybz-code-standard.bak`;
50
+ node_fs.copyFileSync(filePath, backupPath);
51
+ return backupPath;
52
+ };
53
+ const writeConfigFile = (relativePath, content, force) => {
49
54
  const filePath = node_path.resolve(cwd, relativePath);
50
55
  if (!node_fs.existsSync(filePath)) {
51
56
  node_fs.writeFileSync(filePath, content, "utf8");
52
57
  console.log(`\u521B\u5EFA ${relativePath}`);
53
58
  return;
54
59
  }
55
- if (node_fs.readFileSync(filePath, "utf8") !== content) {
56
- console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9`);
60
+ if (node_fs.readFileSync(filePath, "utf8") === content) return;
61
+ if (!force) {
62
+ console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
63
+ return;
57
64
  }
65
+ const backupPath = backupFile(filePath);
66
+ node_fs.writeFileSync(filePath, content, "utf8");
67
+ console.log(`\u8986\u76D6 ${relativePath}\uFF08\u539F\u6587\u4EF6\u5DF2\u5907\u4EFD\u4E3A ${backupPath}\uFF09`);
58
68
  };
59
- const configurePackageJson = () => {
69
+ const configurePackageJson = (force) => {
60
70
  const packageJsonPath = node_path.resolve(cwd, "package.json");
61
71
  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"));
72
+ const packageJsonContent = node_fs.readFileSync(packageJsonPath, "utf8");
73
+ const packageJson = JSON.parse(packageJsonContent);
63
74
  packageJson.scripts ??= {};
75
+ let shouldBackup = false;
64
76
  for (const [name, command2] of Object.entries(scripts)) {
65
77
  const current = packageJson.scripts[name];
66
- if (!current || current === command2) {
78
+ if (!current || current === command2 || force) {
79
+ if (force && current && current !== command2) shouldBackup = true;
67
80
  packageJson.scripts[name] = command2;
68
81
  } else {
69
- console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4`);
82
+ console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
70
83
  }
71
84
  }
85
+ if (shouldBackup) {
86
+ const backupPath = backupFile(packageJsonPath);
87
+ console.log(`\u5907\u4EFD package.json \u4E3A ${backupPath}`);
88
+ }
72
89
  node_fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
73
90
  `, "utf8");
74
91
  console.log("\u66F4\u65B0 package.json scripts");
@@ -90,16 +107,18 @@ const configurePreCommit = () => {
90
107
  `, { encoding: "utf8", mode: 493 });
91
108
  console.log("\u66F4\u65B0 .husky/pre-commit");
92
109
  };
93
- const init = () => {
94
- configurePackageJson();
95
- for (const [filePath, content] of Object.entries(generatedFiles)) writeIfMissing(filePath, content);
110
+ const init = (args2) => {
111
+ const force = args2.includes("--force");
112
+ configurePackageJson(force);
113
+ for (const [filePath, content] of Object.entries(generatedFiles)) writeConfigFile(filePath, content, force);
96
114
  configurePreCommit();
97
- console.log("\n\u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2\u63A5\u5165\u3002");
115
+ console.log(`
116
+ \u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2${force ? "\u5F3A\u5236\u8986\u76D6\u5E76" : ""}\u63A5\u5165\u3002`);
98
117
  };
99
118
  const [command = "init", ...args] = process.argv.slice(2);
100
119
  switch (command) {
101
120
  case "init":
102
- init();
121
+ init(args);
103
122
  break;
104
123
  case "prepare":
105
124
  prepareHusky();
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { execFileSync } from 'node:child_process';
3
- import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
3
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from 'node:fs';
4
4
  import { createRequire } from 'node:module';
5
5
  import { resolve } from 'node:path';
6
6
  import husky from 'husky';
@@ -38,30 +38,47 @@ const runPackageBin = (packageName, binPath, args2) => {
38
38
  const executablePath = resolve(packageJsonPath, "..", binPath);
39
39
  execFileSync(process.execPath, [executablePath, ...args2], { cwd, stdio: "inherit" });
40
40
  };
41
- const writeIfMissing = (relativePath, content) => {
41
+ const backupFile = (filePath) => {
42
+ const backupPath = `${filePath}.sybz-code-standard.bak`;
43
+ copyFileSync(filePath, backupPath);
44
+ return backupPath;
45
+ };
46
+ const writeConfigFile = (relativePath, content, force) => {
42
47
  const filePath = resolve(cwd, relativePath);
43
48
  if (!existsSync(filePath)) {
44
49
  writeFileSync(filePath, content, "utf8");
45
50
  console.log(`\u521B\u5EFA ${relativePath}`);
46
51
  return;
47
52
  }
48
- if (readFileSync(filePath, "utf8") !== content) {
49
- console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9`);
53
+ if (readFileSync(filePath, "utf8") === content) return;
54
+ if (!force) {
55
+ console.warn(`\u8DF3\u8FC7 ${relativePath}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u5185\u5BB9\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
56
+ return;
50
57
  }
58
+ const backupPath = backupFile(filePath);
59
+ writeFileSync(filePath, content, "utf8");
60
+ console.log(`\u8986\u76D6 ${relativePath}\uFF08\u539F\u6587\u4EF6\u5DF2\u5907\u4EFD\u4E3A ${backupPath}\uFF09`);
51
61
  };
52
- const configurePackageJson = () => {
62
+ const configurePackageJson = (force) => {
53
63
  const packageJsonPath = resolve(cwd, "package.json");
54
64
  if (!existsSync(packageJsonPath)) throw new Error(`\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728 package.json\uFF1A${cwd}`);
55
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
65
+ const packageJsonContent = readFileSync(packageJsonPath, "utf8");
66
+ const packageJson = JSON.parse(packageJsonContent);
56
67
  packageJson.scripts ??= {};
68
+ let shouldBackup = false;
57
69
  for (const [name, command2] of Object.entries(scripts)) {
58
70
  const current = packageJson.scripts[name];
59
- if (!current || current === command2) {
71
+ if (!current || current === command2 || force) {
72
+ if (force && current && current !== command2) shouldBackup = true;
60
73
  packageJson.scripts[name] = command2;
61
74
  } else {
62
- console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4`);
75
+ console.warn(`\u4FDD\u7559 scripts.${name}\uFF1A\u5DF2\u5B58\u5728\u81EA\u5B9A\u4E49\u547D\u4EE4\uFF0C\u53EF\u4F7F\u7528 init --force \u5F3A\u5236\u8986\u76D6`);
63
76
  }
64
77
  }
78
+ if (shouldBackup) {
79
+ const backupPath = backupFile(packageJsonPath);
80
+ console.log(`\u5907\u4EFD package.json \u4E3A ${backupPath}`);
81
+ }
65
82
  writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
66
83
  `, "utf8");
67
84
  console.log("\u66F4\u65B0 package.json scripts");
@@ -83,16 +100,18 @@ const configurePreCommit = () => {
83
100
  `, { encoding: "utf8", mode: 493 });
84
101
  console.log("\u66F4\u65B0 .husky/pre-commit");
85
102
  };
86
- const init = () => {
87
- configurePackageJson();
88
- for (const [filePath, content] of Object.entries(generatedFiles)) writeIfMissing(filePath, content);
103
+ const init = (args2) => {
104
+ const force = args2.includes("--force");
105
+ configurePackageJson(force);
106
+ for (const [filePath, content] of Object.entries(generatedFiles)) writeConfigFile(filePath, content, force);
89
107
  configurePreCommit();
90
- console.log("\n\u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2\u63A5\u5165\u3002");
108
+ console.log(`
109
+ \u524D\u7AEF\u4EE3\u7801\u7EDF\u4E00\u89C4\u8303\u5DF2${force ? "\u5F3A\u5236\u8986\u76D6\u5E76" : ""}\u63A5\u5165\u3002`);
91
110
  };
92
111
  const [command = "init", ...args] = process.argv.slice(2);
93
112
  switch (command) {
94
113
  case "init":
95
- init();
114
+ init(args);
96
115
  break;
97
116
  case "prepare":
98
117
  prepareHusky();
package/dist/theme.cjs CHANGED
@@ -3,9 +3,15 @@
3
3
  const SYBZ_THEME_PREFIX = {
4
4
  chenghua: "--s-ch-",
5
5
  shijingshan: "--s-sjs-",
6
- sybz: "--s-sybz-"
6
+ sybz: "--s-sybz-",
7
+ // 鼓楼是石景山布局主题的换色预设,共用组件结构和 token 前缀。
8
+ gulou: "--s-sjs-"
7
9
  };
8
10
  const isSybzTheme = (theme) => typeof theme === "string" && Object.prototype.hasOwnProperty.call(SYBZ_THEME_PREFIX, theme);
11
+ function resolveSybzComponentTheme(theme) {
12
+ return theme === "gulou" ? "shijingshan" : theme;
13
+ }
9
14
 
10
15
  exports.SYBZ_THEME_PREFIX = SYBZ_THEME_PREFIX;
11
16
  exports.isSybzTheme = isSybzTheme;
17
+ exports.resolveSybzComponentTheme = resolveSybzComponentTheme;
package/dist/theme.d.cts CHANGED
@@ -3,10 +3,14 @@ declare const SYBZ_THEME_PREFIX: {
3
3
  readonly chenghua: "--s-ch-";
4
4
  readonly shijingshan: "--s-sjs-";
5
5
  readonly sybz: "--s-sybz-";
6
+ readonly gulou: "--s-sjs-";
6
7
  };
7
8
  type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
8
9
  type SybzComponentTheme = 'default' | SybzThemeName;
9
- declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz";
10
+ declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz" | "gulou";
11
+ /** 颜色预设对应的基础组件主题。新增同结构换色主题时只需在这里登记。 */
12
+ declare function resolveSybzComponentTheme(theme: SybzComponentTheme): SybzComponentTheme;
13
+ declare function resolveSybzComponentTheme(theme: unknown): unknown;
10
14
 
11
- export { SYBZ_THEME_PREFIX, isSybzTheme };
15
+ export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
12
16
  export type { SybzComponentTheme, SybzThemeName };
package/dist/theme.d.mts CHANGED
@@ -3,10 +3,14 @@ declare const SYBZ_THEME_PREFIX: {
3
3
  readonly chenghua: "--s-ch-";
4
4
  readonly shijingshan: "--s-sjs-";
5
5
  readonly sybz: "--s-sybz-";
6
+ readonly gulou: "--s-sjs-";
6
7
  };
7
8
  type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
8
9
  type SybzComponentTheme = 'default' | SybzThemeName;
9
- declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz";
10
+ declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz" | "gulou";
11
+ /** 颜色预设对应的基础组件主题。新增同结构换色主题时只需在这里登记。 */
12
+ declare function resolveSybzComponentTheme(theme: SybzComponentTheme): SybzComponentTheme;
13
+ declare function resolveSybzComponentTheme(theme: unknown): unknown;
10
14
 
11
- export { SYBZ_THEME_PREFIX, isSybzTheme };
15
+ export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
12
16
  export type { SybzComponentTheme, SybzThemeName };
package/dist/theme.d.ts CHANGED
@@ -3,10 +3,14 @@ declare const SYBZ_THEME_PREFIX: {
3
3
  readonly chenghua: "--s-ch-";
4
4
  readonly shijingshan: "--s-sjs-";
5
5
  readonly sybz: "--s-sybz-";
6
+ readonly gulou: "--s-sjs-";
6
7
  };
7
8
  type SybzThemeName = keyof typeof SYBZ_THEME_PREFIX;
8
9
  type SybzComponentTheme = 'default' | SybzThemeName;
9
- declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz";
10
+ declare const isSybzTheme: (theme: unknown) => theme is "chenghua" | "shijingshan" | "sybz" | "gulou";
11
+ /** 颜色预设对应的基础组件主题。新增同结构换色主题时只需在这里登记。 */
12
+ declare function resolveSybzComponentTheme(theme: SybzComponentTheme): SybzComponentTheme;
13
+ declare function resolveSybzComponentTheme(theme: unknown): unknown;
10
14
 
11
- export { SYBZ_THEME_PREFIX, isSybzTheme };
15
+ export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
12
16
  export type { SybzComponentTheme, SybzThemeName };
package/dist/theme.mjs CHANGED
@@ -1,8 +1,13 @@
1
1
  const SYBZ_THEME_PREFIX = {
2
2
  chenghua: "--s-ch-",
3
3
  shijingshan: "--s-sjs-",
4
- sybz: "--s-sybz-"
4
+ sybz: "--s-sybz-",
5
+ // 鼓楼是石景山布局主题的换色预设,共用组件结构和 token 前缀。
6
+ gulou: "--s-sjs-"
5
7
  };
6
8
  const isSybzTheme = (theme) => typeof theme === "string" && Object.prototype.hasOwnProperty.call(SYBZ_THEME_PREFIX, theme);
9
+ function resolveSybzComponentTheme(theme) {
10
+ return theme === "gulou" ? "shijingshan" : theme;
11
+ }
7
12
 
8
- export { SYBZ_THEME_PREFIX, isSybzTheme };
13
+ export { SYBZ_THEME_PREFIX, isSybzTheme, resolveSybzComponentTheme };
package/dist/vite.cjs CHANGED
@@ -11,7 +11,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
11
11
 
12
12
  const tailwindcss__default = /*#__PURE__*/_interopDefaultCompat(tailwindcss);
13
13
 
14
- const createCodeInspector = (options = {}) => codeInspectorPlugin.codeInspectorPlugin({ ...options, bundler: "vite" });
14
+ const createCodeInspector = (options = {}) => codeInspectorPlugin.codeInspectorPlugin({ editor: "code", ...options, bundler: "vite" });
15
15
  const formatBuildTime = (date) => {
16
16
  const pad = (value) => String(value).padStart(2, "0");
17
17
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(
package/dist/vite.mjs CHANGED
@@ -5,7 +5,7 @@ import 'node:child_process';
5
5
  import 'node:fs';
6
6
  import 'node:path';
7
7
 
8
- const createCodeInspector = (options = {}) => codeInspectorPlugin({ ...options, bundler: "vite" });
8
+ const createCodeInspector = (options = {}) => codeInspectorPlugin({ editor: "code", ...options, bundler: "vite" });
9
9
  const formatBuildTime = (date) => {
10
10
  const pad = (value) => String(value).padStart(2, "0");
11
11
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sybz-components/utils",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "utils of sybz-components",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -54,24 +54,24 @@
54
54
  },
55
55
  "author": "",
56
56
  "dependencies": {
57
- "axios": "^1.19.0",
58
57
  "@eslint/js": "9.39.4",
59
58
  "@tailwindcss/vite": "^4.3.3",
60
59
  "@typescript-eslint/eslint-plugin": "8.62.0",
61
60
  "@typescript-eslint/parser": "8.62.0",
62
61
  "@vue/reactivity": "^3.5.18",
63
62
  "@vue/shared": "^3.5.18",
64
- "code-inspector-plugin": "^0.10.1",
63
+ "axios": "^1.19.0",
64
+ "code-inspector-plugin": "^2.0.9",
65
65
  "consola": "^3.4.2",
66
66
  "element-plus": "^2.11.5",
67
+ "es-toolkit": "^1.39.10",
67
68
  "eslint": "9.39.4",
68
69
  "eslint-config-prettier": "9.1.2",
69
70
  "eslint-plugin-vue": "10.9.2",
70
- "es-toolkit": "^1.39.10",
71
- "lodash-es": "^4.17.21",
72
71
  "globals": "16.5.0",
73
72
  "husky": "9.1.7",
74
73
  "lint-staged": "15.5.2",
74
+ "lodash-es": "^4.17.21",
75
75
  "prettier": "3.8.4",
76
76
  "tailwindcss": "^4.3.3",
77
77
  "vue": "3.4.15",