a-calc 3.0.0-beta.20260130.2 → 3.0.0-beta.20260201.1
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/a-calc.versions.js +4 -3
- package/browser/index.js +2 -4
- package/cjs/index.js +2 -4
- package/es/index.js +2 -4
- package/mcp-server/src/index.js +0 -0
- package/package.json +130 -128
- package/ts-plugin/dist/config_extractor.d.ts +9 -0
- package/ts-plugin/dist/config_extractor.js +104 -0
- package/ts-plugin/dist/constants.d.ts +34 -0
- package/ts-plugin/dist/constants.js +274 -0
- package/ts-plugin/dist/index.d.ts +7 -0
- package/ts-plugin/dist/index.js +294 -0
- package/ts-plugin/dist/utils.d.ts +49 -0
- package/ts-plugin/dist/utils.js +204 -0
- package/ts-plugin/dist/variable_extractor.d.ts +16 -0
- package/ts-plugin/dist/variable_extractor.js +138 -0
package/mcp-server/src/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,132 +1,134 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
"name": "a-calc",
|
|
3
|
+
"version": "3.0.0-beta.20260201.1",
|
|
4
|
+
"description": "A very powerful and easy-to-use number precision calculation and formatting library.",
|
|
5
|
+
"main": "./cjs/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./calc.d.ts",
|
|
9
|
+
"import": "./es/index.js",
|
|
10
|
+
"require": "./cjs/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./es": {
|
|
13
|
+
"types": "./calc.d.ts",
|
|
14
|
+
"import": "./es/index.js",
|
|
15
|
+
"default": "./es/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./cjs": {
|
|
18
|
+
"types": "./calc.d.ts",
|
|
19
|
+
"require": "./cjs/index.js",
|
|
20
|
+
"default": "./cjs/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./mcp-server/src/index.js": "./mcp-server/src/index.js",
|
|
23
|
+
"./ts-plugin": "./ts-plugin/dist/index.js"
|
|
11
24
|
},
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
"browser": "browser/index.js",
|
|
26
|
+
"module": "es/index.js",
|
|
27
|
+
"types": "calc.d.ts",
|
|
28
|
+
"typings": "calc.d.ts",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"dev": "rollup -c --environment build:dev",
|
|
31
|
+
"dev:w": "rollup -c -w --environment build:dev",
|
|
32
|
+
"build": "run-p gen:version build-test",
|
|
33
|
+
"build-test": "rollup -c --environment build:build & npm run test",
|
|
34
|
+
"build-only": "rollup -c --environment build:build",
|
|
35
|
+
"build:w": "rollup -c -w --environment build:build",
|
|
36
|
+
"build:docs": "pnpm install --frozen-lockfile=false && vitepress build docs",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:type": "tsc --noEmit type-check.ts",
|
|
39
|
+
"gen:version": "node gen_version_info.cjs",
|
|
40
|
+
"docs:dev": "vitepress dev docs",
|
|
41
|
+
"docs:build": "vitepress build docs",
|
|
42
|
+
"docs:preview": "vitepress preview docs"
|
|
16
43
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"require": "./cjs/index.js",
|
|
20
|
-
"default": "./cjs/index.js"
|
|
44
|
+
"bin": {
|
|
45
|
+
"a-calc-mcp": "./mcp-server/src/index.js"
|
|
21
46
|
},
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
"vue": "^3.5.25",
|
|
111
|
-
"@uiw/codemirror-themes-all": "^4.25.4"
|
|
112
|
-
},
|
|
113
|
-
"dependencies": {
|
|
114
|
-
"typescript-treasure": "0.0.9",
|
|
115
|
-
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
116
|
-
},
|
|
117
|
-
"scripts": {
|
|
118
|
-
"dev": "rollup -c --environment build:dev",
|
|
119
|
-
"dev:w": "rollup -c -w --environment build:dev",
|
|
120
|
-
"build": "run-p gen:version build-test",
|
|
121
|
-
"build-test": "rollup -c --environment build:build & npm run test",
|
|
122
|
-
"build-only": "rollup -c --environment build:build",
|
|
123
|
-
"build:w": "rollup -c -w --environment build:build",
|
|
124
|
-
"build:docs": "pnpm install --frozen-lockfile=false && vitepress build docs",
|
|
125
|
-
"test": "vitest run",
|
|
126
|
-
"test:type": "tsc --noEmit type-check.ts",
|
|
127
|
-
"gen:version": "node gen_version_info.cjs",
|
|
128
|
-
"docs:dev": "vitepress dev docs",
|
|
129
|
-
"docs:build": "vitepress build docs",
|
|
130
|
-
"docs:preview": "vitepress preview docs"
|
|
131
|
-
}
|
|
132
|
-
}
|
|
47
|
+
"files": [
|
|
48
|
+
"es",
|
|
49
|
+
"cjs",
|
|
50
|
+
"browser",
|
|
51
|
+
"calc.d.ts",
|
|
52
|
+
"a-calc.versions.js",
|
|
53
|
+
"mcp-server/src",
|
|
54
|
+
"mcp-server/package.json",
|
|
55
|
+
"mcp-server/README.md",
|
|
56
|
+
"ts-plugin/dist"
|
|
57
|
+
],
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/Autumn-one/a-calc-old.git"
|
|
61
|
+
},
|
|
62
|
+
"keywords": [
|
|
63
|
+
"decimal",
|
|
64
|
+
"math",
|
|
65
|
+
"expression",
|
|
66
|
+
"evaluator",
|
|
67
|
+
"arbitrary",
|
|
68
|
+
"precision",
|
|
69
|
+
"arithmetic",
|
|
70
|
+
"big",
|
|
71
|
+
"number",
|
|
72
|
+
"parser",
|
|
73
|
+
"float",
|
|
74
|
+
"biginteger",
|
|
75
|
+
"bigdecimal",
|
|
76
|
+
"bignumber",
|
|
77
|
+
"bigint",
|
|
78
|
+
"bignum",
|
|
79
|
+
"a-calc",
|
|
80
|
+
"四则运算",
|
|
81
|
+
"数学",
|
|
82
|
+
"运算",
|
|
83
|
+
"浮点数",
|
|
84
|
+
"精度",
|
|
85
|
+
"金融计算"
|
|
86
|
+
],
|
|
87
|
+
"author": "Autumn",
|
|
88
|
+
"bugs": {
|
|
89
|
+
"url": "https://github.com/Autumn-one/a-calc-old/issues"
|
|
90
|
+
},
|
|
91
|
+
"homepage": "https://github.com/Autumn-one/a-calc-old#readme",
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@babel/core": "^7.21.4",
|
|
94
|
+
"@babel/preset-env": "^7.21.4",
|
|
95
|
+
"@codemirror/commands": "^6.10.1",
|
|
96
|
+
"@codemirror/lang-javascript": "^6.2.4",
|
|
97
|
+
"@codemirror/language": "^6.12.1",
|
|
98
|
+
"@codemirror/state": "^6.5.3",
|
|
99
|
+
"@codemirror/theme-one-dark": "^6.1.3",
|
|
100
|
+
"@codemirror/view": "^6.39.8",
|
|
101
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
102
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
103
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
104
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
105
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
106
|
+
"@uiw/codemirror-themes-all": "^4.25.4",
|
|
107
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
108
|
+
"a-calc": "^2.2.15",
|
|
109
|
+
"benchmark": "^2.1.4",
|
|
110
|
+
"bignumber.js": "^9.3.1",
|
|
111
|
+
"codemirror": "^6.0.2",
|
|
112
|
+
"cross-env": "^7.0.3",
|
|
113
|
+
"decimal.js": "^10.6.0",
|
|
114
|
+
"fast-deep-equal": "^3.1.3",
|
|
115
|
+
"glob": "^8.1.0",
|
|
116
|
+
"husky": "^9.1.7",
|
|
117
|
+
"json-stringify-safe": "^5.0.1",
|
|
118
|
+
"lodash-es": "^4.17.21",
|
|
119
|
+
"math-expression-evaluator": "^2.0.7",
|
|
120
|
+
"mathjs": "^15.1.0",
|
|
121
|
+
"npm-run-all": "^4.1.5",
|
|
122
|
+
"rollup": "^4.6.0",
|
|
123
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
124
|
+
"rollup-plugin-serve": "^1.1.0",
|
|
125
|
+
"typescript": "^5.1.6",
|
|
126
|
+
"vitepress": "^1.6.4",
|
|
127
|
+
"vitest": "^2.1.0",
|
|
128
|
+
"vue": "^3.5.25"
|
|
129
|
+
},
|
|
130
|
+
"dependencies": {
|
|
131
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
132
|
+
"typescript-treasure": "0.0.9"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
/**
|
|
3
|
+
* 从项目中提取 set_config 配置的类型信息
|
|
4
|
+
*/
|
|
5
|
+
export declare function extract_config_from_project(ts_module: typeof ts, program: ts.Program, logger: ts.server.Logger): ExtractedConfig;
|
|
6
|
+
export interface ExtractedConfig {
|
|
7
|
+
units: string[];
|
|
8
|
+
shortcut_prefix: string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extract_config_from_project = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 从项目中提取 set_config 配置的类型信息
|
|
6
|
+
*/
|
|
7
|
+
function extract_config_from_project(ts_module, program, logger) {
|
|
8
|
+
const result = {
|
|
9
|
+
units: [],
|
|
10
|
+
shortcut_prefix: '!u',
|
|
11
|
+
};
|
|
12
|
+
const type_checker = program.getTypeChecker();
|
|
13
|
+
for (const source_file of program.getSourceFiles()) {
|
|
14
|
+
// 跳过 node_modules
|
|
15
|
+
if (source_file.fileName.includes('node_modules'))
|
|
16
|
+
continue;
|
|
17
|
+
visit_node(ts_module, source_file, type_checker, result, logger);
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
exports.extract_config_from_project = extract_config_from_project;
|
|
22
|
+
function visit_node(ts_module, node, type_checker, result, logger) {
|
|
23
|
+
// 查找 set_config 调用
|
|
24
|
+
if (ts_module.isCallExpression(node)) {
|
|
25
|
+
const func_name = get_call_name(ts_module, node);
|
|
26
|
+
if (func_name === 'set_config' && node.arguments.length > 0) {
|
|
27
|
+
const arg = node.arguments[0];
|
|
28
|
+
extract_from_config_arg(ts_module, arg, type_checker, result, logger);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
ts_module.forEachChild(node, child => {
|
|
32
|
+
visit_node(ts_module, child, type_checker, result, logger);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function get_call_name(ts_module, node) {
|
|
36
|
+
if (ts_module.isIdentifier(node.expression)) {
|
|
37
|
+
return node.expression.text;
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
function extract_from_config_arg(ts_module, arg, type_checker, result, logger) {
|
|
42
|
+
const type = type_checker.getTypeAtLocation(arg);
|
|
43
|
+
const properties = type.getProperties();
|
|
44
|
+
for (const prop of properties) {
|
|
45
|
+
const prop_name = prop.getName();
|
|
46
|
+
if (prop_name === '_unit_convert_out') {
|
|
47
|
+
extract_units_from_convert_out(ts_module, prop, type_checker, result, logger);
|
|
48
|
+
}
|
|
49
|
+
else if (prop_name === '_unit_convert_in') {
|
|
50
|
+
extract_units_from_convert_in(ts_module, prop, type_checker, result, logger);
|
|
51
|
+
}
|
|
52
|
+
else if (prop_name === '_shortcut_prefix') {
|
|
53
|
+
extract_shortcut_prefix(ts_module, prop, type_checker, result, logger);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function extract_units_from_convert_out(ts_module, prop, type_checker, result, logger) {
|
|
58
|
+
const prop_type = type_checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration);
|
|
59
|
+
// 获取 _unit_convert_out 对象的所有 key
|
|
60
|
+
const unit_props = prop_type.getProperties();
|
|
61
|
+
for (const unit_prop of unit_props) {
|
|
62
|
+
const unit_name = unit_prop.getName();
|
|
63
|
+
if (!result.units.includes(unit_name)) {
|
|
64
|
+
result.units.push(unit_name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
logger.info(`a-calc-ts-plugin: extracted units from _unit_convert_out = ${result.units.join(', ')}`);
|
|
68
|
+
}
|
|
69
|
+
function extract_units_from_convert_in(ts_module, prop, type_checker, result, logger) {
|
|
70
|
+
const prop_type = type_checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration);
|
|
71
|
+
// _unit_convert_in 结构: { 输入单位: { 输出单位: 转换规则 } }
|
|
72
|
+
// 需要提取输出单位(内层的 key)
|
|
73
|
+
const input_unit_props = prop_type.getProperties();
|
|
74
|
+
for (const input_prop of input_unit_props) {
|
|
75
|
+
const input_type = type_checker.getTypeOfSymbolAtLocation(input_prop, input_prop.valueDeclaration);
|
|
76
|
+
// 获取内层的输出单位
|
|
77
|
+
const output_props = input_type.getProperties();
|
|
78
|
+
for (const output_prop of output_props) {
|
|
79
|
+
const unit_name = output_prop.getName();
|
|
80
|
+
if (!result.units.includes(unit_name)) {
|
|
81
|
+
result.units.push(unit_name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
logger.info(`a-calc-ts-plugin: extracted units from _unit_convert_in = ${result.units.join(', ')}`);
|
|
86
|
+
}
|
|
87
|
+
function extract_shortcut_prefix(ts_module, prop, type_checker, result, logger) {
|
|
88
|
+
const prop_type = type_checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration);
|
|
89
|
+
// 尝试获取字符串字面量类型的值
|
|
90
|
+
if (prop_type.isStringLiteral()) {
|
|
91
|
+
result.shortcut_prefix = prop_type.value;
|
|
92
|
+
logger.info(`a-calc-ts-plugin: shortcut_prefix (literal) = ${result.shortcut_prefix}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// 尝试从声明中直接获取值
|
|
96
|
+
const decl = prop.valueDeclaration;
|
|
97
|
+
if (decl && ts_module.isPropertyAssignment(decl)) {
|
|
98
|
+
const init = decl.initializer;
|
|
99
|
+
if (ts_module.isStringLiteral(init)) {
|
|
100
|
+
result.shortcut_prefix = init.text;
|
|
101
|
+
logger.info(`a-calc-ts-plugin: shortcut_prefix (init) = ${result.shortcut_prefix}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* a-calc ! 系统预设
|
|
3
|
+
*/
|
|
4
|
+
export declare const ACALC_PRESETS: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
has_value: boolean;
|
|
8
|
+
value_required: boolean;
|
|
9
|
+
example: string;
|
|
10
|
+
}[];
|
|
11
|
+
/**
|
|
12
|
+
* 千分位预设值
|
|
13
|
+
*/
|
|
14
|
+
export declare const THOUSANDS_PRESETS: {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
}[];
|
|
18
|
+
/**
|
|
19
|
+
* 紧凑格式预设值
|
|
20
|
+
*/
|
|
21
|
+
export declare const COMPACT_PRESETS: {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
}[];
|
|
25
|
+
/**
|
|
26
|
+
* 格式化语法列表(用于 | 后的补全)
|
|
27
|
+
* insert_text: 实际插入的文本(不含占位符)
|
|
28
|
+
*/
|
|
29
|
+
export declare const FORMAT_SYNTAX: {
|
|
30
|
+
name: string;
|
|
31
|
+
insert_text: string;
|
|
32
|
+
description: string;
|
|
33
|
+
example: string;
|
|
34
|
+
}[];
|