@gct-paas/core 0.1.5-dev.1 → 0.1.5-dev.10

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 (79) hide show
  1. package/dist/index.esm.min.js +1 -1
  2. package/es/enums/app-designer/index.d.ts +11 -0
  3. package/es/enums/app-designer/index.mjs +14 -1
  4. package/es/enums/appEnum.d.ts +8 -0
  5. package/es/enums/appEnum.mjs +10 -1
  6. package/es/enums/page-designer/designer.d.ts +13 -13
  7. package/es/enums/page-designer/widget.d.ts +2 -2
  8. package/es/global/gct/gct.d.ts +108 -107
  9. package/es/hooks/index.d.ts +1 -0
  10. package/es/hooks/index.mjs +1 -0
  11. package/es/hooks/useFile.d.ts +4 -0
  12. package/es/hooks/useFile.mjs +22 -0
  13. package/es/index.mjs +14 -6
  14. package/es/interface/i-kit-plugin-module/i-kit-plugin-module.d.ts +23 -0
  15. package/es/interface/i-pinia-action/i-global-actions.d.ts +3 -0
  16. package/es/interface/i-popover-options/i-popover-options.d.ts +98 -0
  17. package/es/interface/index.d.ts +3 -2
  18. package/es/interface/index.mjs +1 -0
  19. package/es/interface/model-designer/entity.d.ts +87 -79
  20. package/es/interface/model-designer/serial.d.ts +22 -0
  21. package/es/interface/model-designer/serial.mjs +49 -0
  22. package/es/interface/open-util/i-app-full-screen-container-options/i-app-full-screen-container-options.d.ts +26 -0
  23. package/es/interface/open-util/i-overlay-controller/i-overlay-controller.d.ts +52 -0
  24. package/es/interface/open-util/i-overlay-popover-container/i-overlay-popover-container.d.ts +21 -0
  25. package/es/interface/open-util/index.d.ts +3 -1
  26. package/es/locale/index.d.ts +26 -1
  27. package/es/locale/index.mjs +51 -3
  28. package/es/locale/sys/model.d.ts +5 -0
  29. package/es/locale/sys.d.ts +5 -0
  30. package/es/modules/mqtt/enums/mqtt-status.enum.d.ts +1 -0
  31. package/es/modules/mqtt/enums/mqtt-status.enum.mjs +2 -1
  32. package/es/modules/mqtt/mqtt-manager.d.ts +1 -1
  33. package/es/modules/mqtt/mqtt-manager.mjs +2 -1
  34. package/es/modules/platform-config/store.d.ts +106 -106
  35. package/es/modules/platform-config/store.mjs +0 -1
  36. package/es/modules/platform-config/useSecuritySetting.d.ts +1 -1
  37. package/es/modules/user-stores/store/tenant.store.d.ts +6 -8
  38. package/es/modules/user-stores/store/tenant.store.mjs +12 -14
  39. package/es/modules/user-stores/store/user.store.d.ts +11 -2
  40. package/es/modules/user-stores/store/user.store.mjs +15 -4
  41. package/es/modules/user-stores/types/tenant.d.ts +7 -1
  42. package/es/router/index.mjs +2 -2
  43. package/es/setup-app.mjs +6 -2
  44. package/es/store/global-store.mjs +3 -0
  45. package/es/store/index.d.ts +1 -0
  46. package/es/store/index.mjs +1 -0
  47. package/es/store/session-store.d.ts +7 -0
  48. package/es/store/session-store.mjs +7 -0
  49. package/es/store/storage-store.d.ts +2 -0
  50. package/es/store/storage-store.mjs +3 -2
  51. package/es/types/index.d.ts +0 -1
  52. package/es/utils/file/download.d.ts +1 -1
  53. package/es/utils/file/parser.d.ts +1 -1
  54. package/es/utils/i18n/index.mjs +3 -0
  55. package/es/utils/index.d.ts +3 -0
  56. package/es/utils/index.mjs +4 -0
  57. package/es/utils/kit-pkg-util/kit-pkg-util.d.ts +34 -13
  58. package/es/utils/kit-pkg-util/kit-pkg-util.mjs +51 -40
  59. package/es/utils/openUtil/index.d.ts +1 -0
  60. package/es/utils/openUtil/index.mjs +1 -0
  61. package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.d.ts +15 -0
  62. package/es/utils/openUtil/overlay-popover-container/overlay-popover-container.mjs +19 -0
  63. package/es/utils/plugin-pkg-util/plugin-pkg-util.d.ts +3 -3
  64. package/es/utils/plugin-pkg-util/plugin-pkg-util.mjs +1 -1
  65. package/es/utils/script-loader/script-loader.d.ts +62 -0
  66. package/es/utils/script-loader/script-loader.mjs +92 -0
  67. package/es/utils/style/index.d.ts +8 -0
  68. package/es/utils/style/index.mjs +67 -1
  69. package/es/utils/text-measure/text-measure.d.ts +141 -0
  70. package/es/utils/text-measure/text-measure.mjs +191 -0
  71. package/es/utils/tools/tools.d.ts +1 -1
  72. package/es/utils/uploader/uploader.mjs +3 -5
  73. package/es/utils/util.d.ts +1 -0
  74. package/es/utils/util.mjs +9 -1
  75. package/es/utils/vue-component-code.d.ts +8 -0
  76. package/es/utils/vue-component-code.mjs +37 -0
  77. package/package.json +20 -20
  78. package/es/interface/i-import-style-map/i-import-style-map.d.ts +0 -15
  79. package/es/interface/i-kit-info/i-kit-info.d.ts +0 -20
@@ -1,6 +1,5 @@
1
1
  import { PluginModeEnum } from '../../enums';
2
- import { IKitInfo } from '../../interface';
3
- import { App } from 'vue';
2
+ import { IPluginKitModule } from '../../interface';
4
3
  /**
5
4
  * 用于加载套件包的工具类
6
5
  *
@@ -8,25 +7,47 @@ import { App } from 'vue';
8
7
  * @class KitPkgUtil
9
8
  */
10
9
  export declare class KitPkgUtil {
11
- protected static readonly KIT_PKG_BASE_PATH = "/kits";
12
- protected static cache: Map<string, IKitInfo>;
10
+ protected static readonly KIT_PKG_BASE_PATH = "/plugin-kit";
13
11
  protected static joinPaths(...paths: string[]): string;
14
12
  /**
15
- * 加载套件包配置
13
+ * 加载套件包,返回套件包入口实例
16
14
  *
17
15
  * @static
18
16
  * @param {string} kit
19
- * @return {*} {(Promise<IKitInfo | undefined>)}
17
+ * @param {PluginModeEnum} mode
18
+ * @return {*} {(Promise<IPluginKitModule | null>)}
20
19
  */
21
- static loadKitPkgInfo(kit: string): Promise<IKitInfo | undefined>;
20
+ static loadKit(kit: string, mode: PluginModeEnum): Promise<IPluginKitModule | null>;
22
21
  /**
23
- * 加载套件包内的插件
22
+ * 加载设计模式套件包
24
23
  *
25
24
  * @static
26
- * @param {App} app
27
- * @param {(string | string[])} kit
28
- * @param {PluginModeEnum} mode
29
- * @return {*} {Promise<void>}
25
+ * @param {string} kit
26
+ * @return {*} {(Promise<IPluginKitModule | null>)}
27
+ */
28
+ static loadDesign(kit: string): Promise<IPluginKitModule | null>;
29
+ /**
30
+ * 加载移动端绘制模式套件包
31
+ *
32
+ * @static
33
+ * @param {string} kit
34
+ * @return {*} {(Promise<IPluginKitModule | null>)}
35
+ */
36
+ static loadMobile(kit: string): Promise<IPluginKitModule | null>;
37
+ /**
38
+ * 加载平板端绘制模式套件包
39
+ *
40
+ * @static
41
+ * @param {string} kit
42
+ * @return {*} {(Promise<IPluginKitModule | null>)}
43
+ */
44
+ static loadPad(kit: string): Promise<IPluginKitModule | null>;
45
+ /**
46
+ * 加载网页端绘制模式套件包
47
+ *
48
+ * @static
49
+ * @param {string} kit
50
+ * @return {*} {(Promise<IPluginKitModule | null>)}
30
51
  */
31
- static loadKits(app: App, kit: string | string[], mode: PluginModeEnum): Promise<void>;
52
+ static loadWeb(kit: string): Promise<IPluginKitModule | null>;
32
53
  }
@@ -1,3 +1,5 @@
1
+ import { PluginModeEnum } from "../../enums/plugin-enum.mjs";
2
+ import "../../enums/index.mjs";
1
3
  //#region src/utils/kit-pkg-util/kit-pkg-util.ts
2
4
  /**
3
5
  * 用于加载套件包的工具类
@@ -6,8 +8,7 @@
6
8
  * @class KitPkgUtil
7
9
  */
8
10
  var KitPkgUtil = class {
9
- static KIT_PKG_BASE_PATH = "/kits";
10
- static cache = /* @__PURE__ */ new Map();
11
+ static KIT_PKG_BASE_PATH = "/plugin-kit";
11
12
  static joinPaths(...paths) {
12
13
  return paths.filter((p) => p && p.length > 0).map((p, index) => {
13
14
  let normalized = p;
@@ -17,56 +18,66 @@ var KitPkgUtil = class {
17
18
  }).join("/");
18
19
  }
19
20
  /**
20
- * 加载套件包配置
21
+ * 加载套件包,返回套件包入口实例
21
22
  *
22
23
  * @static
23
24
  * @param {string} kit
24
- * @return {*} {(Promise<IKitInfo | undefined>)}
25
+ * @param {PluginModeEnum} mode
26
+ * @return {*} {(Promise<IPluginKitModule | null>)}
25
27
  */
26
- static async loadKitPkgInfo(kit) {
27
- if (this.cache.has(kit)) return this.cache.get(kit);
28
+ static async loadKit(kit, mode) {
29
+ const loaderUrl = this.joinPaths(this.KIT_PKG_BASE_PATH, kit, mode, "loader.esm.min.js");
28
30
  try {
29
- const url = this.joinPaths(this.KIT_PKG_BASE_PATH, kit.toUpperCase(), "kit-info.json");
30
- const response = await fetch(url);
31
- if (!response.ok) throw new Error(`Failed to load kit package from ${url}`);
32
- const config = await response.json();
33
- this.cache.set(kit, config);
34
- return config;
31
+ const module = await import(
32
+ /* @vite-ignore */
33
+ loaderUrl
34
+ );
35
+ if (module) return module;
36
+ else console.warn(`Kit ${kit} does not export a default function`);
35
37
  } catch (error) {
36
- console.error(`Error loading kit package ${kit}:`, error);
38
+ console.error(`Error loading kit ${kit} from ${loaderUrl}:`, error);
37
39
  }
40
+ return null;
38
41
  }
39
42
  /**
40
- * 加载套件包内的插件
43
+ * 加载设计模式套件包
41
44
  *
42
45
  * @static
43
- * @param {App} app
44
- * @param {(string | string[])} kit
45
- * @param {PluginModeEnum} mode
46
- * @return {*} {Promise<void>}
46
+ * @param {string} kit
47
+ * @return {*} {(Promise<IPluginKitModule | null>)}
47
48
  */
48
- static async loadKits(app, kit, mode) {
49
- const kits = Array.isArray(kit) ? kit : [kit];
50
- for (const k of kits) {
51
- if (this.cache.has(k)) {
52
- console.warn(`Kit package ${k} is already loaded, skipping.`);
53
- return;
54
- }
55
- const config = await this.loadKitPkgInfo(k);
56
- if (config) {
57
- const loaderUrl = this.joinPaths(this.KIT_PKG_BASE_PATH, config.kit.toUpperCase(), mode, `loader.esm.min.js?version=${config.version || "0.0.0"}`);
58
- try {
59
- const module = await import(
60
- /* @vite-ignore */
61
- loaderUrl
62
- );
63
- if (module && module.default) app.use(module.default);
64
- else console.warn(`Kit ${config.kit} does not export a default function`);
65
- } catch (error) {
66
- console.error(`Error loading kit ${config.kit} from ${loaderUrl}:`, error);
67
- }
68
- }
69
- }
49
+ static loadDesign(kit) {
50
+ return this.loadKit(kit, PluginModeEnum.DESIGN);
51
+ }
52
+ /**
53
+ * 加载移动端绘制模式套件包
54
+ *
55
+ * @static
56
+ * @param {string} kit
57
+ * @return {*} {(Promise<IPluginKitModule | null>)}
58
+ */
59
+ static loadMobile(kit) {
60
+ return this.loadKit(kit, PluginModeEnum.MOBILE);
61
+ }
62
+ /**
63
+ * 加载平板端绘制模式套件包
64
+ *
65
+ * @static
66
+ * @param {string} kit
67
+ * @return {*} {(Promise<IPluginKitModule | null>)}
68
+ */
69
+ static loadPad(kit) {
70
+ return this.loadKit(kit, PluginModeEnum.PAD);
71
+ }
72
+ /**
73
+ * 加载网页端绘制模式套件包
74
+ *
75
+ * @static
76
+ * @param {string} kit
77
+ * @return {*} {(Promise<IPluginKitModule | null>)}
78
+ */
79
+ static loadWeb(kit) {
80
+ return this.loadKit(kit, PluginModeEnum.WEB);
70
81
  }
71
82
  };
72
83
  //#endregion
@@ -1,2 +1,3 @@
1
1
  export { Modal } from './modal/modal';
2
2
  export { OverlayContainer } from './overlay-container/overlay-container';
3
+ export { OverlayPopoverContainer } from './overlay-popover-container/overlay-popover-container';
@@ -1,2 +1,3 @@
1
1
  import "./modal/modal.mjs";
2
2
  import "./overlay-container/overlay-container.mjs";
3
+ import "./overlay-popover-container/overlay-popover-container.mjs";
@@ -0,0 +1,15 @@
1
+ import { IOverlayPopoverContainer, IPopoverOptions } from '../../../interface';
2
+ import { OverlayContainer } from '../overlay-container/overlay-container';
3
+ /**
4
+ * 飘窗组件呈现容器
5
+ *
6
+ * @author zhanghanrui
7
+ * @date 2024-04-08 09:04:42
8
+ * @export
9
+ * @class OverlayPopoverContainer
10
+ * @extends {OverlayContainer<IPopoverOptions>}
11
+ * @implements {IOverlayPopoverContainer}
12
+ */
13
+ export declare class OverlayPopoverContainer extends OverlayContainer<IPopoverOptions> implements IOverlayPopoverContainer {
14
+ present(): Promise<void>;
15
+ }
@@ -0,0 +1,19 @@
1
+ import { OverlayContainer } from "../overlay-container/overlay-container.mjs";
2
+ //#region src/utils/openUtil/overlay-popover-container/overlay-popover-container.ts
3
+ /**
4
+ * 飘窗组件呈现容器
5
+ *
6
+ * @author zhanghanrui
7
+ * @date 2024-04-08 09:04:42
8
+ * @export
9
+ * @class OverlayPopoverContainer
10
+ * @extends {OverlayContainer<IPopoverOptions>}
11
+ * @implements {IOverlayPopoverContainer}
12
+ */
13
+ var OverlayPopoverContainer = class extends OverlayContainer {
14
+ present(target) {
15
+ return this.modal.present(target);
16
+ }
17
+ };
18
+ //#endregion
19
+ export { OverlayPopoverContainer };
@@ -1,6 +1,6 @@
1
1
  import { PluginModeEnum, Platform } from '../../enums';
2
2
  import { PluginTenant } from '@gct-paas/api/platform';
3
- export type IModuleMap = Record<string, System.Module>;
3
+ export type IModuleMap = Record<string, IObject>;
4
4
  export type LoadPluginResult = [PluginTenant[], IModuleMap];
5
5
  /**
6
6
  * 插件包处理工具类
@@ -28,7 +28,7 @@ export declare class PluginPgkUtil {
28
28
  *
29
29
  * @static
30
30
  */
31
- static readonly module: Map<string, System.Module>;
31
+ static readonly module: Map<string, IObject>;
32
32
  protected static joinPaths(...paths: string[]): string;
33
33
  /**
34
34
  * 加载插件包配置
@@ -47,7 +47,7 @@ export declare class PluginPgkUtil {
47
47
  * @protected
48
48
  * @static
49
49
  * @param {IStyleIMportMap[]} plugins
50
- * @returns {*} {Promise<System.Module[]>}
50
+ * @returns {*} {Promise<IObject[]>}
51
51
  */
52
52
  protected static loadPlugins(mode: PluginModeEnum, configs?: PluginTenant['plugins']): Promise<IModuleMap>;
53
53
  /**
@@ -60,7 +60,7 @@ var PluginPgkUtil = class {
60
60
  * @protected
61
61
  * @static
62
62
  * @param {IStyleIMportMap[]} plugins
63
- * @returns {*} {Promise<System.Module[]>}
63
+ * @returns {*} {Promise<IObject[]>}
64
64
  */
65
65
  static async loadPlugins(mode, configs = []) {
66
66
  const moduleMap = {};
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Script 动态加载工具类
3
+ *
4
+ * 从 CDN 动态加载 JS 脚本文件,具备以下特性:
5
+ * - 已成功加载的路径永久缓存,避免重复插入 script 标签
6
+ * - 同一时刻对同一路径的多次调用共享同一个 Promise(请求去重)
7
+ * - 加载失败不写入缓存,允许下次重试
8
+ * - 加载前检查 DOM 中是否已存在相同 src 的 script 标签
9
+ * - 支持配置 async、defer、crossOrigin、type 等脚本属性
10
+ *
11
+ * @author chitanda
12
+ * @date 2026-04-17
13
+ */
14
+ /** Script 加载选项 */
15
+ export interface IScriptOptions {
16
+ /** 是否异步加载,默认 true */
17
+ async?: boolean;
18
+ /** 是否延迟加载 */
19
+ defer?: boolean;
20
+ /** 跨域属性 */
21
+ crossOrigin?: 'anonymous' | 'use-credentials';
22
+ /** 脚本 MIME 类型,默认 'text/javascript' */
23
+ type?: string;
24
+ }
25
+ /**
26
+ * Script 动态加载工具类
27
+ *
28
+ * @class ScriptLoader
29
+ */
30
+ declare class ScriptLoader {
31
+ /** 已成功加载的脚本 URL 集合(永久缓存) */
32
+ private _loadedSet;
33
+ /** 正在加载中的脚本 URL 对应的 Promise(用于请求去重) */
34
+ private _pendingMap;
35
+ /**
36
+ * 动态加载单个 JS 脚本文件
37
+ *
38
+ * 同一 URL 只会加载一次,首次调用时的 options 生效。
39
+ *
40
+ * @param {string} url 脚本文件的完整 URL
41
+ * @param {IScriptOptions} [options] 脚本加载选项
42
+ * @returns {Promise<void>} 加载完成后 resolve;加载失败则 reject
43
+ */
44
+ load(url: string, options?: IScriptOptions): Promise<void>;
45
+ /**
46
+ * 加载 ExcelJS 库
47
+ *
48
+ * @return {*} {Promise<IObject>}
49
+ */
50
+ loadExcelsJs(): Promise<IObject>;
51
+ /**
52
+ * 并发加载多个 JS 脚本文件
53
+ *
54
+ * @param {string[]} urls 脚本文件 URL 列表
55
+ * @param {IScriptOptions} [options] 脚本加载选项,对所有 URL 生效
56
+ * @returns {Promise<void>} 所有文件均加载完成后 resolve;任一失败则 reject
57
+ */
58
+ loadBatch(urls: string[], options?: IScriptOptions): Promise<void>;
59
+ }
60
+ /** Script 动态加载工具单例 */
61
+ export declare const scriptLoader: ScriptLoader;
62
+ export {};
@@ -0,0 +1,92 @@
1
+ //#region src/utils/script-loader/script-loader.ts
2
+ /**
3
+ * Script 动态加载工具类
4
+ *
5
+ * @class ScriptLoader
6
+ */
7
+ var ScriptLoader = class {
8
+ /** 已成功加载的脚本 URL 集合(永久缓存) */
9
+ _loadedSet = /* @__PURE__ */ new Set();
10
+ /** 正在加载中的脚本 URL 对应的 Promise(用于请求去重) */
11
+ _pendingMap = /* @__PURE__ */ new Map();
12
+ /**
13
+ * 动态加载单个 JS 脚本文件
14
+ *
15
+ * 同一 URL 只会加载一次,首次调用时的 options 生效。
16
+ *
17
+ * @param {string} url 脚本文件的完整 URL
18
+ * @param {IScriptOptions} [options] 脚本加载选项
19
+ * @returns {Promise<void>} 加载完成后 resolve;加载失败则 reject
20
+ */
21
+ load(url, options) {
22
+ if (this._loadedSet.has(url)) return Promise.resolve();
23
+ if (this._pendingMap.has(url)) return this._pendingMap.get(url);
24
+ if (typeof document !== "undefined") {
25
+ const escaped = CSS.escape ? CSS.escape(url) : url;
26
+ if (document.querySelector(`script[src="${escaped}"]`)) {
27
+ this._loadedSet.add(url);
28
+ return Promise.resolve();
29
+ }
30
+ }
31
+ const promise = new Promise((resolve, reject) => {
32
+ if (typeof document === "undefined") {
33
+ reject(/* @__PURE__ */ new Error(`[ScriptLoader] 当前环境不支持 DOM,无法加载脚本: ${url}`));
34
+ return;
35
+ }
36
+ const script = document.createElement("script");
37
+ script.src = url;
38
+ script.type = options?.type ?? "text/javascript";
39
+ script.async = options?.async ?? true;
40
+ if (options?.defer !== void 0) script.defer = options.defer;
41
+ if (options?.crossOrigin !== void 0) script.crossOrigin = options.crossOrigin;
42
+ /** 加载成功回调 */
43
+ const onLoad = () => {
44
+ cleanup();
45
+ this._loadedSet.add(url);
46
+ this._pendingMap.delete(url);
47
+ resolve();
48
+ };
49
+ /** 加载失败回调 */
50
+ const onError = () => {
51
+ cleanup();
52
+ this._pendingMap.delete(url);
53
+ const err = /* @__PURE__ */ new Error(`[ScriptLoader] 脚本文件加载失败: ${url}`);
54
+ console.error(err.message);
55
+ reject(err);
56
+ };
57
+ /** 移除事件监听,防止内存泄漏 */
58
+ const cleanup = () => {
59
+ script.removeEventListener("load", onLoad);
60
+ script.removeEventListener("error", onError);
61
+ };
62
+ script.addEventListener("load", onLoad);
63
+ script.addEventListener("error", onError);
64
+ document.head.appendChild(script);
65
+ });
66
+ this._pendingMap.set(url, promise);
67
+ return promise;
68
+ }
69
+ /**
70
+ * 加载 ExcelJS 库
71
+ *
72
+ * @return {*} {Promise<IObject>}
73
+ */
74
+ async loadExcelsJs() {
75
+ await this.load("/extras/exceljs/4.4.0/exceljs.min.js");
76
+ return window.ExcelJS;
77
+ }
78
+ /**
79
+ * 并发加载多个 JS 脚本文件
80
+ *
81
+ * @param {string[]} urls 脚本文件 URL 列表
82
+ * @param {IScriptOptions} [options] 脚本加载选项,对所有 URL 生效
83
+ * @returns {Promise<void>} 所有文件均加载完成后 resolve;任一失败则 reject
84
+ */
85
+ async loadBatch(urls, options) {
86
+ await Promise.all(urls.map((url) => this.load(url, options)));
87
+ }
88
+ };
89
+ /** Script 动态加载工具单例 */
90
+ var scriptLoader = new ScriptLoader();
91
+ //#endregion
92
+ export { scriptLoader };
@@ -6,6 +6,14 @@
6
6
  * @returns
7
7
  */
8
8
  export declare const calcStyle: (data: IData, ignoringStyle?: string[]) => IObject;
9
+ /**
10
+ * 计算配置样式 补充px
11
+ *
12
+ * @param data
13
+ * @param ignoringStyle 忽略计算的样式
14
+ * @returns
15
+ */
16
+ export declare const calcStylePX: (data: IData, ignoringStyle?: string[]) => IObject;
9
17
  /**
10
18
  * 计算字体样式
11
19
  *
@@ -71,6 +71,72 @@ var calcStyle = (data, ignoringStyle = []) => {
71
71
  return style;
72
72
  };
73
73
  /**
74
+ * 计算配置样式 补充px
75
+ *
76
+ * @param data
77
+ * @param ignoringStyle 忽略计算的样式
78
+ * @returns
79
+ */
80
+ var calcStylePX = (data, ignoringStyle = []) => {
81
+ if (!data) return {};
82
+ const style = {};
83
+ if (data.paddingTop && data.paddingTop != "0" && !ignoringStyle.includes("paddingTop")) style["padding-top"] = `${data.paddingTop}px`;
84
+ if (data.paddingRight && data.paddingRight != "0" && !ignoringStyle.includes("paddingRight")) style["padding-right"] = `${data.paddingRight}px`;
85
+ if (data.paddingBottom && data.paddingBottom != "0" && !ignoringStyle.includes("paddingBottom")) style["padding-bottom"] = `${data.paddingBottom}px`;
86
+ if (data.paddingLeft && data.paddingLeft != "0" && !ignoringStyle.includes("paddingLeft")) style["padding-left"] = `${data.paddingLeft}px`;
87
+ if (data.marginTop && data.marginTop != "0" && !ignoringStyle.includes("marginTop")) style["margin-top"] = `${data.marginTop}px`;
88
+ if (data.marginRight && data.marginRight != "0" && !ignoringStyle.includes("marginRight")) style["margin-right"] = `${data.marginRight}px`;
89
+ if (data.marginBottom && data.marginBottom != "0" && !ignoringStyle.includes("marginBottom")) style["margin-bottom"] = `${data.marginBottom}px`;
90
+ if (data.marginLeft && data.marginLeft != "0" && !ignoringStyle.includes("marginLeft")) style["margin-left"] = `${data.marginLeft}px`;
91
+ if (data.backgroundColor && !ignoringStyle.includes("backgroundColor")) style["background-color"] = data.backgroundColor;
92
+ if (data.width != null && data.width != "" && !ignoringStyle.includes("width")) style.width = `${data.width}px`;
93
+ if (data.height != null && data.height != "" && !ignoringStyle.includes("height")) {
94
+ style.height = `${data.height}px`;
95
+ style.overflowX = "hidden";
96
+ style.overflowY = "auto";
97
+ }
98
+ const position = data.position;
99
+ if (position && !ignoringStyle.includes("zIndex")) {
100
+ style.position = position;
101
+ style["z-index"] = 1;
102
+ }
103
+ if (data.top && !ignoringStyle.includes("top")) style.top = `${data.top}px`;
104
+ if (data.right && !ignoringStyle.includes("right")) style.right = `${data.right}px`;
105
+ if (data.bottom && !ignoringStyle.includes("bottom")) style.bottom = `${data.bottom}px`;
106
+ if (data.left && !ignoringStyle.includes("left")) style.left = `${data.left}px`;
107
+ if (data.borderBottomLeftRadius && !ignoringStyle.includes("borderBottomLeftRadius")) style["border-top-left-radius"] = `${data.borderBottomLeftRadius}px`;
108
+ if (data.borderTopRightRadius && !ignoringStyle.includes("borderTopRightRadius")) style["border-top-right-radius"] = `${data.borderTopRightRadius}px`;
109
+ if (data.borderBottomLeftRadius && !ignoringStyle.includes("borderBottomLeftRadius")) style["border-bottom-left-radius"] = `${data.borderBottomLeftRadius}px`;
110
+ if (data.borderBottomRightRadius && !ignoringStyle.includes("borderBottomRightRadius")) style["border-bottom-right-radius"] = `${data.borderBottomRightRadius}px`;
111
+ {
112
+ const top = data.borderTop;
113
+ if (top) {
114
+ if (top.borderColor && !ignoringStyle.includes("borderTopColor")) style["border-top-color"] = top.borderColor;
115
+ if (top.borderWidth && !ignoringStyle.includes("borderTopWidth")) style["border-top-width"] = `${top.borderWidth}px`;
116
+ if (top.borderStyle && !ignoringStyle.includes("borderTopStyle")) style["border-top-style"] = top.borderStyle;
117
+ }
118
+ const right = data.borderRight;
119
+ if (right) {
120
+ if (right.borderColor && !ignoringStyle.includes("borderRightColor")) style["border-right-color"] = right.borderColor;
121
+ if (right.borderWidth && !ignoringStyle.includes("borderRightWidth")) style["border-right-width"] = `${right.borderWidth}px`;
122
+ if (right.borderStyle && !ignoringStyle.includes("borderRightStyle")) style["border-right-style"] = right.borderStyle;
123
+ }
124
+ const bottom = data.borderBottom;
125
+ if (bottom) {
126
+ if (bottom.borderColor && !ignoringStyle.includes("borderBottomColor")) style["border-bottom-color"] = bottom.borderColor;
127
+ if (bottom.borderWidth && !ignoringStyle.includes("borderBottomWidth")) style["border-bottom-width"] = `${bottom.borderWidth}px`;
128
+ if (bottom.borderStyle && !ignoringStyle.includes("borderBottomStyle")) style["border-bottom-style"] = bottom.borderStyle;
129
+ }
130
+ const left = data.borderLeft;
131
+ if (left) {
132
+ if (left.borderColor && !ignoringStyle.includes("borderLeftColor")) style["border-left-color"] = left.borderColor;
133
+ if (left.borderWidth && !ignoringStyle.includes("borderLeftWidth")) style["border-left-width"] = `${left.borderWidth}px`;
134
+ if (left.borderStyle && !ignoringStyle.includes("borderLeftStyle")) style["border-left-style"] = left.borderStyle;
135
+ }
136
+ }
137
+ return style;
138
+ };
139
+ /**
74
140
  * 计算字体样式
75
141
  *
76
142
  * @param data
@@ -94,4 +160,4 @@ var calcFontStyle = (data, ignoringStyle = []) => {
94
160
  return style;
95
161
  };
96
162
  //#endregion
97
- export { calcFontStyle, calcStyle };
163
+ export { calcFontStyle, calcStyle, calcStylePX };
@@ -0,0 +1,141 @@
1
+ /**
2
+ * 文本测量工具类
3
+ * 使用 Canvas 测量文本宽度,支持批量测量
4
+ */
5
+ interface TextMeasureOptions {
6
+ /** 字体大小,默认 14px */
7
+ fontSize?: string | number;
8
+ /** 字体族,默认 'Arial, sans-serif' */
9
+ fontFamily?: string;
10
+ /** 字体粗细,默认 'normal' */
11
+ fontWeight?: string | number;
12
+ /** 字体样式,默认 'normal' */
13
+ fontStyle?: string;
14
+ }
15
+ interface TextMeasureResult {
16
+ /** 文本内容 */
17
+ text: string;
18
+ /** 计算得到的宽度 */
19
+ width: number;
20
+ }
21
+ declare class TextMeasureUtil {
22
+ private canvas;
23
+ private ctx;
24
+ /**
25
+ * 获取 Canvas 上下文,懒加载创建
26
+ */
27
+ private getContext;
28
+ /**
29
+ * 设置字体样式
30
+ */
31
+ private setFont;
32
+ /**
33
+ * 测量单个文本的宽度
34
+ *
35
+ * @param text 要测量的文本
36
+ * @param options 字体选项
37
+ * @returns 文本宽度(像素)
38
+ */
39
+ measureText(text: string, options?: TextMeasureOptions): number;
40
+ /**
41
+ * 批量测量多段文本的宽度
42
+ *
43
+ * @param texts 要测量的文本数组
44
+ * @param options 字体选项
45
+ * @returns 包含每段文本和对应宽度的结果数组
46
+ */
47
+ measureTexts(texts: string[], options?: TextMeasureOptions): TextMeasureResult[];
48
+ /**
49
+ * 获取文本的最大宽度
50
+ *
51
+ * @param texts 要测量的文本数组
52
+ * @param options 字体选项
53
+ * @returns 最大宽度(像素)
54
+ */
55
+ getMaxWidth(texts: string[], options?: TextMeasureOptions): number;
56
+ /**
57
+ * 获取文本的最小宽度
58
+ *
59
+ * @param texts 要测量的文本数组
60
+ * @param options 字体选项
61
+ * @returns 最小宽度(像素)
62
+ */
63
+ getMinWidth(texts: string[], options?: TextMeasureOptions): number;
64
+ /**
65
+ * 计算文本的总宽度(用于水平排列的文本)
66
+ *
67
+ * @param texts 要测量的文本数组
68
+ * @param options 字体选项
69
+ * @param spacing 文本间的间距,默认 0
70
+ * @returns 总宽度(像素)
71
+ */
72
+ getTotalWidth(texts: string[], options?: TextMeasureOptions, spacing?: number): number;
73
+ /**
74
+ * 根据最大宽度截断文本,添加省略号
75
+ *
76
+ * @param text 原始文本
77
+ * @param maxWidth 最大宽度
78
+ * @param options 字体选项
79
+ * @param ellipsis 省略号,默认 '...'
80
+ * @param minChars 最少显示字符数,默认 0
81
+ * @returns 截断后的文本
82
+ */
83
+ truncateText(text: string, maxWidth: number, options?: TextMeasureOptions, ellipsis?: string, minChars?: number): string;
84
+ /**
85
+ * 销毁资源
86
+ */
87
+ destroy(): void;
88
+ }
89
+ /**
90
+ * 测量单个文本的宽度
91
+ *
92
+ * @param text 要测量的文本
93
+ * @param options 字体选项
94
+ * @returns 文本宽度(像素)
95
+ */
96
+ export declare function measureText(text: string, options?: TextMeasureOptions): number;
97
+ /**
98
+ * 批量测量多段文本的宽度
99
+ *
100
+ * @param texts 要测量的文本数组
101
+ * @param options 字体选项
102
+ * @returns 包含每段文本和对应宽度的结果数组
103
+ */
104
+ export declare function measureTexts(texts: string[], options?: TextMeasureOptions): TextMeasureResult[];
105
+ /**
106
+ * 获取文本的最大宽度
107
+ *
108
+ * @param texts 要测量的文本数组
109
+ * @param options 字体选项
110
+ * @returns 最大宽度(像素)
111
+ */
112
+ export declare function getMaxTextWidth(texts: string[], options?: TextMeasureOptions): number;
113
+ /**
114
+ * 获取文本的最小宽度
115
+ *
116
+ * @param texts 要测量的文本数组
117
+ * @param options 字体选项
118
+ * @returns 最小宽度(像素)
119
+ */
120
+ export declare function getMinTextWidth(texts: string[], options?: TextMeasureOptions): number;
121
+ /**
122
+ * 计算文本的总宽度(用于水平排列的文本)
123
+ *
124
+ * @param texts 要测量的文本数组
125
+ * @param options 字体选项
126
+ * @param spacing 文本间的间距,默认 0
127
+ * @returns 总宽度(像素)
128
+ */
129
+ export declare function getTotalTextWidth(texts: string[], options?: TextMeasureOptions, spacing?: number): number;
130
+ /**
131
+ * 根据最大宽度截断文本,添加省略号
132
+ *
133
+ * @param text 原始文本
134
+ * @param maxWidth 最大宽度
135
+ * @param options 字体选项
136
+ * @param ellipsis 省略号,默认 '...'
137
+ * @param minChars 最少显示字符数,默认 0
138
+ * @returns 截断后的文本
139
+ */
140
+ export declare function truncateText(text: string, maxWidth: number, options?: TextMeasureOptions, ellipsis?: string, minChars?: number): string;
141
+ export { TextMeasureUtil, type TextMeasureOptions, type TextMeasureResult };