@tmagic/utils 1.4.4 → 1.4.5

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.4",
2
+ "version": "1.4.5",
3
3
  "name": "@tmagic/utils",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-utils.umd.cjs",
@@ -25,23 +25,23 @@
25
25
  "url": "https://github.com/Tencent/tmagic-editor.git"
26
26
  },
27
27
  "dependencies": {
28
- "@tmagic/schema": "1.4.4",
29
- "dayjs": "^1.11.4",
28
+ "dayjs": "^1.11.11",
30
29
  "lodash-es": "^4.17.21"
31
30
  },
32
31
  "peerDependencies": {
33
- "dayjs": "^1.11.4"
32
+ "@tmagic/schema": "1.4.5"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@types/lodash-es": "^4.17.4",
37
36
  "@types/node": "^18.19.0",
38
37
  "rimraf": "^3.0.2",
39
38
  "typescript": "^5.4.2",
40
- "vite": "^5.1.6"
39
+ "vite": "^5.2.11"
41
40
  },
42
41
  "scripts": {
43
42
  "build": "rimraf ./dist && npm run build:type && vite build --mode=es && vite build --mode=umd",
44
43
  "build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
45
- "clear:type": "rimraf ./types"
44
+ "clear:type": "rimraf ./types",
45
+ "check:type": "tsc --noEmit --project tsconfig.build.json"
46
46
  }
47
47
  }
package/src/dom.ts CHANGED
@@ -110,3 +110,15 @@ export const createDiv = ({ className, cssText }: { className: string; cssText:
110
110
  };
111
111
 
112
112
  export const getDocument = () => globalThis.document;
113
+
114
+ export const calcValueByFontsize = (doc: Document | undefined, value: number) => {
115
+ if (!doc) return value;
116
+ const { fontSize } = doc.documentElement.style;
117
+
118
+ if (fontSize) {
119
+ const times = globalThis.parseFloat(fontSize) / 100;
120
+ return Number((value / times).toFixed(2));
121
+ }
122
+
123
+ return value;
124
+ };
package/src/index.ts CHANGED
@@ -390,6 +390,8 @@ export const getDefaultValueFromFields = (fields: DataSchema[]) => {
390
390
 
391
391
  export const DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = 'ds-field::';
392
392
 
393
+ export const DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX = 'ds-field-changed';
394
+
393
395
  export const getKeys = Object.keys as <T extends object>(obj: T) => Array<keyof T>;
394
396
 
395
397
  export const calculatePercentage = (value: number, percentageStr: string) => {
package/types/dom.d.ts CHANGED
@@ -9,3 +9,4 @@ export declare const createDiv: ({ className, cssText }: {
9
9
  cssText: string;
10
10
  }) => HTMLDivElement;
11
11
  export declare const getDocument: () => Document;
12
+ export declare const calcValueByFontsize: (doc: Document | undefined, value: number) => number;
package/types/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export declare const compiledNode: (compile: (value: any) => any, node: MNode, d
44
44
  export declare const compiledCond: (op: string, fieldValue: any, inputValue: any, range?: number[]) => boolean;
45
45
  export declare const getDefaultValueFromFields: (fields: DataSchema[]) => Record<string, any>;
46
46
  export declare const DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = "ds-field::";
47
+ export declare const DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX = "ds-field-changed";
47
48
  export declare const getKeys: <T extends object>(obj: T) => Array<keyof T>;
48
49
  export declare const calculatePercentage: (value: number, percentageStr: string) => number;
49
50
  export declare const isPercentage: (value: number | string) => boolean;