@sciexpr/core 0.1.0 → 0.1.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/dist/index.cjs +2 -1
- package/dist/index.d.cts +38 -4
- package/dist/index.d.ts +38 -4
- package/dist/index.js +2 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -67,6 +67,7 @@ var ExpressionKind = /* @__PURE__ */ ((ExpressionKind2) => {
|
|
|
67
67
|
ExpressionKind2["Matrix"] = "matrix";
|
|
68
68
|
ExpressionKind2["Text"] = "text";
|
|
69
69
|
ExpressionKind2["Mixed"] = "mixed";
|
|
70
|
+
ExpressionKind2["Physics"] = "physics";
|
|
70
71
|
return ExpressionKind2;
|
|
71
72
|
})(ExpressionKind || {});
|
|
72
73
|
var SymbolType = /* @__PURE__ */ ((SymbolType2) => {
|
|
@@ -528,7 +529,7 @@ var ExpressionClassifier = class {
|
|
|
528
529
|
hasMathNodes(root) {
|
|
529
530
|
return collectNodes(
|
|
530
531
|
root,
|
|
531
|
-
(n) => ["frac", "script", "radical", "delimiter", "matrix", "accent", "largeop"].includes(n.kind)
|
|
532
|
+
(n) => ["frac", "script", "radical", "delimiter", "matrix", "accent", "largeop", "symbol", "group"].includes(n.kind)
|
|
532
533
|
).length > 0;
|
|
533
534
|
}
|
|
534
535
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -11,7 +11,9 @@ declare enum ExpressionKind {
|
|
|
11
11
|
/** 纯文本 */
|
|
12
12
|
Text = "text",
|
|
13
13
|
/** 混合表达式(含多种类型片段) */
|
|
14
|
-
Mixed = "mixed"
|
|
14
|
+
Mixed = "mixed",
|
|
15
|
+
/** 物理表达式(公式/方程式/矢量表示) */
|
|
16
|
+
Physics = "physics"
|
|
15
17
|
}
|
|
16
18
|
/** 源码位置(用于错误提示和高亮) */
|
|
17
19
|
interface SourceLocation {
|
|
@@ -26,10 +28,12 @@ interface SourceLocation {
|
|
|
26
28
|
offset: number;
|
|
27
29
|
};
|
|
28
30
|
}
|
|
31
|
+
/** 所有 AST 节点 kind 的字面量联合 */
|
|
32
|
+
type ExpressionNodeKind = 'root' | 'symbol' | 'frac' | 'script' | 'radical' | 'delimiter' | 'matrix' | 'text' | 'space' | 'accent' | 'largeop' | 'color' | 'group' | 'chem-element' | 'chem-bond' | 'chem-reaction' | 'chem-group';
|
|
29
33
|
/** 所有 AST 节点的基类 */
|
|
30
34
|
interface ExpressionNode {
|
|
31
35
|
/** 节点类型标识(discriminant) */
|
|
32
|
-
kind:
|
|
36
|
+
kind: ExpressionNodeKind;
|
|
33
37
|
/** 可选的唯一标识 */
|
|
34
38
|
id?: string;
|
|
35
39
|
/** 源码位置 */
|
|
@@ -282,17 +286,47 @@ interface PipelineOptions {
|
|
|
282
286
|
params?: Record<string, unknown>;
|
|
283
287
|
}
|
|
284
288
|
|
|
285
|
-
/**
|
|
289
|
+
/**
|
|
290
|
+
* 生成唯一节点 ID
|
|
291
|
+
* @returns 格式为 `n{序号}` 的唯一标识字符串
|
|
292
|
+
*/
|
|
286
293
|
declare function generateNodeId(): string;
|
|
287
294
|
/** 重置节点 ID 计数器(主要用于测试) */
|
|
288
295
|
declare function resetNodeIdCounter(): void;
|
|
296
|
+
/**
|
|
297
|
+
* 创建表达式根节点
|
|
298
|
+
* @param type - 表达式分类 (math/molecule/chemical-equation/matrix/text/mixed)
|
|
299
|
+
* @param children - 子节点列表
|
|
300
|
+
* @param metadata - 可选的元数据 (displayMode/label/style/originalSource)
|
|
301
|
+
*/
|
|
289
302
|
declare function createRoot(type: ExpressionKind, children: ExpressionNode[], metadata?: ExpressionMetadata): ExpressionRoot;
|
|
303
|
+
/**
|
|
304
|
+
* 创建符号节点
|
|
305
|
+
* @param value - 符号文本 (LaTeX 命令或 Unicode 字符)
|
|
306
|
+
* @param symbolType - 符号分类 (greek/operator/relation/arrow/variable/number 等)
|
|
307
|
+
*/
|
|
290
308
|
declare function createSymbol(value: string, symbolType: SymbolType): SymbolNode;
|
|
309
|
+
/**
|
|
310
|
+
* 创建分数节点
|
|
311
|
+
* @param numerator - 分子
|
|
312
|
+
* @param denominator - 分母
|
|
313
|
+
*/
|
|
291
314
|
declare function createFraction(numerator: ExpressionNode, denominator: ExpressionNode): FractionNode;
|
|
315
|
+
/**
|
|
316
|
+
* 创建上下标节点
|
|
317
|
+
* @param base - 基础表达式
|
|
318
|
+
* @param options.sub - 下标表达式
|
|
319
|
+
* @param options.super - 上标表达式
|
|
320
|
+
*/
|
|
292
321
|
declare function createScript(base: ExpressionNode, options?: {
|
|
293
322
|
sub?: ExpressionNode;
|
|
294
323
|
super?: ExpressionNode;
|
|
295
324
|
}): ScriptNode;
|
|
325
|
+
/**
|
|
326
|
+
* 创建根式节点
|
|
327
|
+
* @param radicand - 被开方数
|
|
328
|
+
* @param index - 可选的根指数 (省略则为平方根)
|
|
329
|
+
*/
|
|
296
330
|
declare function createRadical(radicand: ExpressionNode, index?: ExpressionNode): RadicalNode;
|
|
297
331
|
declare function createDelimiter(left: string, right: string, body: ExpressionNode): DelimiterNode;
|
|
298
332
|
declare function createMatrix(rows: ExpressionNode[][], options?: {
|
|
@@ -417,4 +451,4 @@ declare class ExpressionClassifier {
|
|
|
417
451
|
isDisplayMode(root: ExpressionRoot): boolean;
|
|
418
452
|
}
|
|
419
453
|
|
|
420
|
-
export { type ASTNode, type ASTVisitor, type AccentNode, type ChemArrowType, type ChemBondNode, type ChemElementNode, type ChemGroupNode, type ChemReactionNode, type ColorNode, type DelimiterNode, ExpressionClassifier, ExpressionKind, type ExpressionMetadata, type ExpressionNode, type ExpressionRoot, type FractionNode, type GroupNode, type IValidator, type LargeOpNode, type MatrixNode, type NodeByKind, type PipelineContext, type PipelineError, type PipelineOptions, type PipelineStage, type RadicalNode, type ScriptNode, type SourceLocation, type SpaceNode, type SymbolNode, SymbolType, type TextNode, type TraverseOptions, type ValidationError, ValidationErrorCode, type ValidationResult, type ValidationWarning, cloneNode, collectNodes, countNodes, createAccent, createChemBond, createChemElement, createChemGroup, createChemReaction, createColor, createDelimiter, createFraction, createGroup, createLargeOp, createMatrix, createRadical, createRoot, createScript, createSpace, createSymbol, createText, deserializeAST, findNode, flattenNode, generateNodeId, getNodeChildren, isNodeType, resetNodeIdCounter, safeDeserializeAST, serializeAST, serializeASTCompact, serializeASTPretty, traverseAST };
|
|
454
|
+
export { type ASTNode, type ASTVisitor, type AccentNode, type ChemArrowType, type ChemBondNode, type ChemElementNode, type ChemGroupNode, type ChemReactionNode, type ColorNode, type DelimiterNode, ExpressionClassifier, ExpressionKind, type ExpressionMetadata, type ExpressionNode, type ExpressionNodeKind, type ExpressionRoot, type FractionNode, type GroupNode, type IValidator, type LargeOpNode, type MatrixNode, type NodeByKind, type PipelineContext, type PipelineError, type PipelineOptions, type PipelineStage, type RadicalNode, type ScriptNode, type SourceLocation, type SpaceNode, type SymbolNode, SymbolType, type TextNode, type TraverseOptions, type ValidationError, ValidationErrorCode, type ValidationResult, type ValidationWarning, cloneNode, collectNodes, countNodes, createAccent, createChemBond, createChemElement, createChemGroup, createChemReaction, createColor, createDelimiter, createFraction, createGroup, createLargeOp, createMatrix, createRadical, createRoot, createScript, createSpace, createSymbol, createText, deserializeAST, findNode, flattenNode, generateNodeId, getNodeChildren, isNodeType, resetNodeIdCounter, safeDeserializeAST, serializeAST, serializeASTCompact, serializeASTPretty, traverseAST };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ declare enum ExpressionKind {
|
|
|
11
11
|
/** 纯文本 */
|
|
12
12
|
Text = "text",
|
|
13
13
|
/** 混合表达式(含多种类型片段) */
|
|
14
|
-
Mixed = "mixed"
|
|
14
|
+
Mixed = "mixed",
|
|
15
|
+
/** 物理表达式(公式/方程式/矢量表示) */
|
|
16
|
+
Physics = "physics"
|
|
15
17
|
}
|
|
16
18
|
/** 源码位置(用于错误提示和高亮) */
|
|
17
19
|
interface SourceLocation {
|
|
@@ -26,10 +28,12 @@ interface SourceLocation {
|
|
|
26
28
|
offset: number;
|
|
27
29
|
};
|
|
28
30
|
}
|
|
31
|
+
/** 所有 AST 节点 kind 的字面量联合 */
|
|
32
|
+
type ExpressionNodeKind = 'root' | 'symbol' | 'frac' | 'script' | 'radical' | 'delimiter' | 'matrix' | 'text' | 'space' | 'accent' | 'largeop' | 'color' | 'group' | 'chem-element' | 'chem-bond' | 'chem-reaction' | 'chem-group';
|
|
29
33
|
/** 所有 AST 节点的基类 */
|
|
30
34
|
interface ExpressionNode {
|
|
31
35
|
/** 节点类型标识(discriminant) */
|
|
32
|
-
kind:
|
|
36
|
+
kind: ExpressionNodeKind;
|
|
33
37
|
/** 可选的唯一标识 */
|
|
34
38
|
id?: string;
|
|
35
39
|
/** 源码位置 */
|
|
@@ -282,17 +286,47 @@ interface PipelineOptions {
|
|
|
282
286
|
params?: Record<string, unknown>;
|
|
283
287
|
}
|
|
284
288
|
|
|
285
|
-
/**
|
|
289
|
+
/**
|
|
290
|
+
* 生成唯一节点 ID
|
|
291
|
+
* @returns 格式为 `n{序号}` 的唯一标识字符串
|
|
292
|
+
*/
|
|
286
293
|
declare function generateNodeId(): string;
|
|
287
294
|
/** 重置节点 ID 计数器(主要用于测试) */
|
|
288
295
|
declare function resetNodeIdCounter(): void;
|
|
296
|
+
/**
|
|
297
|
+
* 创建表达式根节点
|
|
298
|
+
* @param type - 表达式分类 (math/molecule/chemical-equation/matrix/text/mixed)
|
|
299
|
+
* @param children - 子节点列表
|
|
300
|
+
* @param metadata - 可选的元数据 (displayMode/label/style/originalSource)
|
|
301
|
+
*/
|
|
289
302
|
declare function createRoot(type: ExpressionKind, children: ExpressionNode[], metadata?: ExpressionMetadata): ExpressionRoot;
|
|
303
|
+
/**
|
|
304
|
+
* 创建符号节点
|
|
305
|
+
* @param value - 符号文本 (LaTeX 命令或 Unicode 字符)
|
|
306
|
+
* @param symbolType - 符号分类 (greek/operator/relation/arrow/variable/number 等)
|
|
307
|
+
*/
|
|
290
308
|
declare function createSymbol(value: string, symbolType: SymbolType): SymbolNode;
|
|
309
|
+
/**
|
|
310
|
+
* 创建分数节点
|
|
311
|
+
* @param numerator - 分子
|
|
312
|
+
* @param denominator - 分母
|
|
313
|
+
*/
|
|
291
314
|
declare function createFraction(numerator: ExpressionNode, denominator: ExpressionNode): FractionNode;
|
|
315
|
+
/**
|
|
316
|
+
* 创建上下标节点
|
|
317
|
+
* @param base - 基础表达式
|
|
318
|
+
* @param options.sub - 下标表达式
|
|
319
|
+
* @param options.super - 上标表达式
|
|
320
|
+
*/
|
|
292
321
|
declare function createScript(base: ExpressionNode, options?: {
|
|
293
322
|
sub?: ExpressionNode;
|
|
294
323
|
super?: ExpressionNode;
|
|
295
324
|
}): ScriptNode;
|
|
325
|
+
/**
|
|
326
|
+
* 创建根式节点
|
|
327
|
+
* @param radicand - 被开方数
|
|
328
|
+
* @param index - 可选的根指数 (省略则为平方根)
|
|
329
|
+
*/
|
|
296
330
|
declare function createRadical(radicand: ExpressionNode, index?: ExpressionNode): RadicalNode;
|
|
297
331
|
declare function createDelimiter(left: string, right: string, body: ExpressionNode): DelimiterNode;
|
|
298
332
|
declare function createMatrix(rows: ExpressionNode[][], options?: {
|
|
@@ -417,4 +451,4 @@ declare class ExpressionClassifier {
|
|
|
417
451
|
isDisplayMode(root: ExpressionRoot): boolean;
|
|
418
452
|
}
|
|
419
453
|
|
|
420
|
-
export { type ASTNode, type ASTVisitor, type AccentNode, type ChemArrowType, type ChemBondNode, type ChemElementNode, type ChemGroupNode, type ChemReactionNode, type ColorNode, type DelimiterNode, ExpressionClassifier, ExpressionKind, type ExpressionMetadata, type ExpressionNode, type ExpressionRoot, type FractionNode, type GroupNode, type IValidator, type LargeOpNode, type MatrixNode, type NodeByKind, type PipelineContext, type PipelineError, type PipelineOptions, type PipelineStage, type RadicalNode, type ScriptNode, type SourceLocation, type SpaceNode, type SymbolNode, SymbolType, type TextNode, type TraverseOptions, type ValidationError, ValidationErrorCode, type ValidationResult, type ValidationWarning, cloneNode, collectNodes, countNodes, createAccent, createChemBond, createChemElement, createChemGroup, createChemReaction, createColor, createDelimiter, createFraction, createGroup, createLargeOp, createMatrix, createRadical, createRoot, createScript, createSpace, createSymbol, createText, deserializeAST, findNode, flattenNode, generateNodeId, getNodeChildren, isNodeType, resetNodeIdCounter, safeDeserializeAST, serializeAST, serializeASTCompact, serializeASTPretty, traverseAST };
|
|
454
|
+
export { type ASTNode, type ASTVisitor, type AccentNode, type ChemArrowType, type ChemBondNode, type ChemElementNode, type ChemGroupNode, type ChemReactionNode, type ColorNode, type DelimiterNode, ExpressionClassifier, ExpressionKind, type ExpressionMetadata, type ExpressionNode, type ExpressionNodeKind, type ExpressionRoot, type FractionNode, type GroupNode, type IValidator, type LargeOpNode, type MatrixNode, type NodeByKind, type PipelineContext, type PipelineError, type PipelineOptions, type PipelineStage, type RadicalNode, type ScriptNode, type SourceLocation, type SpaceNode, type SymbolNode, SymbolType, type TextNode, type TraverseOptions, type ValidationError, ValidationErrorCode, type ValidationResult, type ValidationWarning, cloneNode, collectNodes, countNodes, createAccent, createChemBond, createChemElement, createChemGroup, createChemReaction, createColor, createDelimiter, createFraction, createGroup, createLargeOp, createMatrix, createRadical, createRoot, createScript, createSpace, createSymbol, createText, deserializeAST, findNode, flattenNode, generateNodeId, getNodeChildren, isNodeType, resetNodeIdCounter, safeDeserializeAST, serializeAST, serializeASTCompact, serializeASTPretty, traverseAST };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var ExpressionKind = /* @__PURE__ */ ((ExpressionKind2) => {
|
|
|
6
6
|
ExpressionKind2["Matrix"] = "matrix";
|
|
7
7
|
ExpressionKind2["Text"] = "text";
|
|
8
8
|
ExpressionKind2["Mixed"] = "mixed";
|
|
9
|
+
ExpressionKind2["Physics"] = "physics";
|
|
9
10
|
return ExpressionKind2;
|
|
10
11
|
})(ExpressionKind || {});
|
|
11
12
|
var SymbolType = /* @__PURE__ */ ((SymbolType2) => {
|
|
@@ -467,7 +468,7 @@ var ExpressionClassifier = class {
|
|
|
467
468
|
hasMathNodes(root) {
|
|
468
469
|
return collectNodes(
|
|
469
470
|
root,
|
|
470
|
-
(n) => ["frac", "script", "radical", "delimiter", "matrix", "accent", "largeop"].includes(n.kind)
|
|
471
|
+
(n) => ["frac", "script", "radical", "delimiter", "matrix", "accent", "largeop", "symbol", "group"].includes(n.kind)
|
|
471
472
|
).length > 0;
|
|
472
473
|
}
|
|
473
474
|
/**
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sciexpr/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Scientific Expression Engine - Core types, AST, schema and validators",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|