@jarenjs/calc 0.34.0
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/README.md +60 -0
- package/dist/types/ast.d.ts +65 -0
- package/dist/types/compile.d.ts +52 -0
- package/dist/types/component/index.d.ts +259 -0
- package/dist/types/component/rates/binance.d.ts +34 -0
- package/dist/types/component/rates/coingecko.d.ts +47 -0
- package/dist/types/component/rates/index.d.ts +84 -0
- package/dist/types/component/rules.d.ts +180 -0
- package/dist/types/component/schema.d.ts +38 -0
- package/dist/types/env.d.ts +24 -0
- package/dist/types/errors.d.ts +18 -0
- package/dist/types/index.d.ts +42 -0
- package/dist/types/modes/converter.d.ts +46 -0
- package/dist/types/modes/financial.d.ts +59 -0
- package/dist/types/modes/index.d.ts +38 -0
- package/dist/types/modes/programmer.d.ts +50 -0
- package/dist/types/modes/scientific.d.ts +28 -0
- package/dist/types/modes/standard.d.ts +32 -0
- package/dist/types/parser/index.d.ts +32 -0
- package/dist/types/plot/plot2d.d.ts +70 -0
- package/dist/types/plot/plot3d.d.ts +68 -0
- package/dist/types/render/error.d.ts +19 -0
- package/dist/types/theme.d.ts +35 -0
- package/dist/types/to-expr.d.ts +13 -0
- package/dist/types/utils.d.ts +9 -0
- package/docs/CALC-FORMAT.md +79 -0
- package/package.json +71 -0
- package/schemas/financial-inputs.schema.json +15 -0
- package/schemas/jaren-calc-ast.schema.json +91 -0
- package/schemas/jaren-calc-state.schema.json +52 -0
- package/src/ast.js +96 -0
- package/src/compile.js +119 -0
- package/src/component/index.js +352 -0
- package/src/component/rates/binance.js +44 -0
- package/src/component/rates/coingecko.js +63 -0
- package/src/component/rates/index.js +116 -0
- package/src/component/rules.js +118 -0
- package/src/component/schema.js +24 -0
- package/src/env.js +163 -0
- package/src/errors.js +23 -0
- package/src/index.js +85 -0
- package/src/modes/converter.js +73 -0
- package/src/modes/financial.js +89 -0
- package/src/modes/index.js +24 -0
- package/src/modes/programmer.js +69 -0
- package/src/modes/scientific.js +31 -0
- package/src/modes/standard.js +39 -0
- package/src/parser/index.js +220 -0
- package/src/plot/plot2d.js +221 -0
- package/src/plot/plot3d.js +177 -0
- package/src/render/error.js +25 -0
- package/src/theme.js +76 -0
- package/src/to-expr.js +84 -0
- package/src/utils.js +11 -0
- package/styles/calc.css +128 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The `calculator` JSLT view. Rules render the
|
|
3
|
+
* viewModel document produced by `contributeCalcViewModel`. Convention
|
|
4
|
+
* (mirrors the website views): `match` patterns are absolute from the
|
|
5
|
+
* document root; `$apply` paths and body `$` are relative to the matched
|
|
6
|
+
* node; list children wrap `[{ $apply: '…[*]' }]`; a ready-made vnode
|
|
7
|
+
* (the plot SVG, `$.plot.svg`) splices in verbatim as a query-string
|
|
8
|
+
* child.
|
|
9
|
+
*
|
|
10
|
+
* Mounted by the host with `{ $apply: ['$.ui.calculator', 'calculator'] }`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CALCULATOR_RULES: ({
|
|
13
|
+
match: string;
|
|
14
|
+
mode: string;
|
|
15
|
+
body: (string | (string | {
|
|
16
|
+
$apply: string;
|
|
17
|
+
}[] | {
|
|
18
|
+
class: string;
|
|
19
|
+
})[] | (string | (string | {
|
|
20
|
+
class: string;
|
|
21
|
+
})[] | {
|
|
22
|
+
class: string;
|
|
23
|
+
$if?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
class?: undefined;
|
|
26
|
+
$if: (string | (string | {
|
|
27
|
+
class: string;
|
|
28
|
+
})[])[];
|
|
29
|
+
})[] | {
|
|
30
|
+
class: string;
|
|
31
|
+
$if?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
class?: undefined;
|
|
34
|
+
$if: (string | (string | (string | {
|
|
35
|
+
$apply: string;
|
|
36
|
+
}[] | {
|
|
37
|
+
class: string;
|
|
38
|
+
})[] | (string | (string | {
|
|
39
|
+
class: string;
|
|
40
|
+
})[] | {
|
|
41
|
+
class: string;
|
|
42
|
+
})[] | {
|
|
43
|
+
class: string;
|
|
44
|
+
})[])[];
|
|
45
|
+
} | {
|
|
46
|
+
class?: undefined;
|
|
47
|
+
$if: (string | (string | (string | {
|
|
48
|
+
type: string;
|
|
49
|
+
class: string;
|
|
50
|
+
on: {
|
|
51
|
+
click: {
|
|
52
|
+
action: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
})[] | (string | {
|
|
56
|
+
class: string;
|
|
57
|
+
})[] | {
|
|
58
|
+
class: string;
|
|
59
|
+
})[])[];
|
|
60
|
+
} | {
|
|
61
|
+
class?: undefined;
|
|
62
|
+
$if: (string | (string | (string | {}[] | {
|
|
63
|
+
class: string;
|
|
64
|
+
})[] | (string | {
|
|
65
|
+
class: string;
|
|
66
|
+
$apply?: undefined;
|
|
67
|
+
} | {
|
|
68
|
+
class?: undefined;
|
|
69
|
+
$apply: string;
|
|
70
|
+
})[] | {
|
|
71
|
+
class: string;
|
|
72
|
+
})[])[];
|
|
73
|
+
} | {
|
|
74
|
+
class?: undefined;
|
|
75
|
+
$if: (string | (string | (string | {}[] | {
|
|
76
|
+
class: string;
|
|
77
|
+
})[] | (string | (string | {
|
|
78
|
+
type: string;
|
|
79
|
+
class: string;
|
|
80
|
+
value: string;
|
|
81
|
+
on: {
|
|
82
|
+
input: {
|
|
83
|
+
action: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
})[] | (string | {
|
|
87
|
+
type: string;
|
|
88
|
+
class: string;
|
|
89
|
+
on: {
|
|
90
|
+
click: {
|
|
91
|
+
action: string;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
})[] | (string | {
|
|
95
|
+
$apply: string;
|
|
96
|
+
}[] | {
|
|
97
|
+
class: string;
|
|
98
|
+
on: {
|
|
99
|
+
change: {
|
|
100
|
+
action: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
})[] | {
|
|
104
|
+
class: string;
|
|
105
|
+
})[] | {
|
|
106
|
+
$if?: undefined;
|
|
107
|
+
class: string;
|
|
108
|
+
} | {
|
|
109
|
+
class?: undefined;
|
|
110
|
+
$if: (string | (string | {}[] | (string | {
|
|
111
|
+
type: string;
|
|
112
|
+
class: string;
|
|
113
|
+
on: {
|
|
114
|
+
click: {
|
|
115
|
+
action: string;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
})[] | {
|
|
119
|
+
$if?: undefined;
|
|
120
|
+
class: string;
|
|
121
|
+
} | {
|
|
122
|
+
class?: undefined;
|
|
123
|
+
$if: (string | (string | {
|
|
124
|
+
class: string;
|
|
125
|
+
})[])[];
|
|
126
|
+
})[])[];
|
|
127
|
+
})[])[];
|
|
128
|
+
} | {
|
|
129
|
+
class?: undefined;
|
|
130
|
+
$if: (string | (string | (string | {
|
|
131
|
+
type: string;
|
|
132
|
+
class: string;
|
|
133
|
+
value: string;
|
|
134
|
+
on: {
|
|
135
|
+
input: {
|
|
136
|
+
action: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
})[] | (string | {
|
|
140
|
+
$apply: string;
|
|
141
|
+
}[] | {
|
|
142
|
+
class: string;
|
|
143
|
+
})[] | {
|
|
144
|
+
class: string;
|
|
145
|
+
})[])[];
|
|
146
|
+
})[];
|
|
147
|
+
} | {
|
|
148
|
+
match: string;
|
|
149
|
+
mode: string;
|
|
150
|
+
body: (string | {
|
|
151
|
+
type: string;
|
|
152
|
+
class: {
|
|
153
|
+
$if: string[];
|
|
154
|
+
};
|
|
155
|
+
on: string;
|
|
156
|
+
})[];
|
|
157
|
+
} | {
|
|
158
|
+
match: string;
|
|
159
|
+
mode: string;
|
|
160
|
+
body: (string | {
|
|
161
|
+
$apply: string;
|
|
162
|
+
}[] | {
|
|
163
|
+
class: string;
|
|
164
|
+
})[];
|
|
165
|
+
} | {
|
|
166
|
+
match: string;
|
|
167
|
+
mode: string;
|
|
168
|
+
body: (string | {
|
|
169
|
+
type: string;
|
|
170
|
+
class: string;
|
|
171
|
+
on: string;
|
|
172
|
+
})[];
|
|
173
|
+
} | {
|
|
174
|
+
match: string;
|
|
175
|
+
mode: string;
|
|
176
|
+
body: (string | {
|
|
177
|
+
value: string;
|
|
178
|
+
selected: string;
|
|
179
|
+
})[];
|
|
180
|
+
})[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The financial-inputs JSON Schema (draft-neutral). Rendered by
|
|
3
|
+
* `@jarenjs/forms` (`buildFormModel` → `buildFormViewModel`) in the
|
|
4
|
+
* viewModel, and available as `schemas/financial-inputs.schema.json` for
|
|
5
|
+
* `validateState`. The calculator holds no formulas — only these inputs.
|
|
6
|
+
*/
|
|
7
|
+
export declare const FINANCIAL_SCHEMA: {
|
|
8
|
+
type: string;
|
|
9
|
+
title: string;
|
|
10
|
+
properties: {
|
|
11
|
+
nper: {
|
|
12
|
+
type: string;
|
|
13
|
+
title: string;
|
|
14
|
+
minimum: number;
|
|
15
|
+
};
|
|
16
|
+
rate: {
|
|
17
|
+
type: string;
|
|
18
|
+
title: string;
|
|
19
|
+
};
|
|
20
|
+
pv: {
|
|
21
|
+
type: string;
|
|
22
|
+
title: string;
|
|
23
|
+
};
|
|
24
|
+
pmt: {
|
|
25
|
+
type: string;
|
|
26
|
+
title: string;
|
|
27
|
+
};
|
|
28
|
+
fv: {
|
|
29
|
+
type: string;
|
|
30
|
+
title: string;
|
|
31
|
+
};
|
|
32
|
+
solveFor: {
|
|
33
|
+
title: string;
|
|
34
|
+
enum: string[];
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
required: string[];
|
|
38
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Evaluation environments — the operator/function binding sets the
|
|
3
|
+
* compiler resolves against. The AST is neutral; an
|
|
4
|
+
* environment gives it meaning. `defaultEnv` covers standard/scientific
|
|
5
|
+
* (float, `^` = power, angle-aware trig); `programmerEnv` overrides the
|
|
6
|
+
* bitwise operators with `@jarenjs/core/math/word.js` word math and adds
|
|
7
|
+
* the programmer functions. Every binding closes over `scope` so angle
|
|
8
|
+
* mode and word size are read at evaluation time.
|
|
9
|
+
*
|
|
10
|
+
* Binding shapes (all monomorphic): `func(args[], scope)`,
|
|
11
|
+
* `binop(a, b, scope)`, `unop(a, scope)`, `postop(a, scope)`.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The default (standard/scientific) environment.
|
|
15
|
+
* @returns {any}
|
|
16
|
+
*/
|
|
17
|
+
export declare function defaultEnv(): any;
|
|
18
|
+
/**
|
|
19
|
+
* The programmer environment: word-masked bitwise operators plus the
|
|
20
|
+
* `and/or/xor/not/shl/shr/rol/ror/mod` functions, read against the
|
|
21
|
+
* scope's `wordBits`/`signed`.
|
|
22
|
+
* @returns {any}
|
|
23
|
+
*/
|
|
24
|
+
export declare function programmerEnv(): any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The engine's parse error, carrying a 1-based `line`/`column`
|
|
3
|
+
* (the `fail(message, position)` idiom from `packages/json/src/path.js`,
|
|
4
|
+
* adapted to line/column like the mermaid parser). The evaluate/render
|
|
5
|
+
* path catches it and never rethrows into the app loop.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CalcParseError extends Error {
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
position: number;
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} message
|
|
13
|
+
* @param {number} [line] 1-based line
|
|
14
|
+
* @param {number} [column] 1-based column
|
|
15
|
+
* @param {number} [position] 0-based char offset
|
|
16
|
+
*/
|
|
17
|
+
constructor(message: string, line?: number, column?: number, position?: number);
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `@jarenjs/calc` — the ENGINE (part one of the two-layer
|
|
3
|
+
* package). Pure functions over data — expression text ⇄ AST ⇄
|
|
4
|
+
* value, and AST/scene → pure-vnode SVG — that know only `@jarenjs/core`
|
|
5
|
+
* and `@jarenjs/view`. It imports nothing from the component,
|
|
6
|
+
* `@jarenjs/app`, `@jarenjs/forms` or the DOM. The boundary is one-way
|
|
7
|
+
* (the component imports the engine, never the reverse).
|
|
8
|
+
*
|
|
9
|
+
* The signature duality mirrors the rest of the suite:
|
|
10
|
+
* `parseExpression` ⇄ `toExpression` is a round-trip fixed point.
|
|
11
|
+
*/
|
|
12
|
+
export { parseExpression } from './parser/index.js';
|
|
13
|
+
export { toExpression } from './to-expr.js';
|
|
14
|
+
export { compileExpr, evaluate } from './compile.js';
|
|
15
|
+
export { defaultEnv, programmerEnv } from './env.js';
|
|
16
|
+
export { CalcParseError } from './errors.js';
|
|
17
|
+
export { num, constant, variable, unary, postfix, binary, call, CONSTANTS, isConstant, astEqual, CALC_AST_VERSION, } from './ast.js';
|
|
18
|
+
export { plot2d, buildScene2d, scene2dToVnode } from './plot/plot2d.js';
|
|
19
|
+
export { plot3d, buildScene3d, scene3dToVnode } from './plot/plot3d.js';
|
|
20
|
+
export { errorToVnode } from './render/error.js';
|
|
21
|
+
export { createTheme, THEMES, HOST_VARS } from './theme.js';
|
|
22
|
+
export { hashContent } from './utils.js';
|
|
23
|
+
export { MODES, MODE_BY_ID, standardMode, scientificMode, programmerMode, financialMode, converterMode, wordViews, solveTvm, buildAmortization, npvOf, irrOf, convertValue, unitOptions, converterDimensions, CURRENCY, } from './modes/index.js';
|
|
24
|
+
/**
|
|
25
|
+
* Render an expression to a plot vnode, choosing 2D or 3D by whether the
|
|
26
|
+
* expression's free variables include a second axis. Error-safe: a parse
|
|
27
|
+
* failure yields the error vnode, never a throw.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} source
|
|
30
|
+
* @param {{ kind?: '2d'|'3d', [k: string]: any }} [options]
|
|
31
|
+
* @returns {any} an SVG vnode
|
|
32
|
+
*/
|
|
33
|
+
export declare function calcToVnode(source: string, options?: {
|
|
34
|
+
kind?: '2d' | '3d';
|
|
35
|
+
[k: string]: any;
|
|
36
|
+
}): any;
|
|
37
|
+
/**
|
|
38
|
+
* Render any calc SVG vnode to a standalone SVG string (SSR / headless).
|
|
39
|
+
* @param {any} vnode
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
export declare function toSvgString(vnode: any): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The converter mode kernel. Contains
|
|
3
|
+
* **no factors** — static dimensions call `@jarenjs/core/convert`'s
|
|
4
|
+
* `convert(...)`, and the **currency** dimension calls the pure
|
|
5
|
+
* `convertCurrency(value, from, to, rateTable)` with the live table from
|
|
6
|
+
* `$.calc.rates`. The component's rates layer is the only place that
|
|
7
|
+
* fetches a rate; this module never does.
|
|
8
|
+
*/
|
|
9
|
+
/** Currency is a fifth, rate-table-backed dimension beside the static ones. */
|
|
10
|
+
export declare const CURRENCY = "currency";
|
|
11
|
+
/**
|
|
12
|
+
* All selectable dimensions (static core dimensions + currency).
|
|
13
|
+
* @returns {string[]}
|
|
14
|
+
*/
|
|
15
|
+
export declare function converterDimensions(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* The unit options for a dimension. Static dimensions come from core;
|
|
18
|
+
* the currency dimension enumerates the codes present in `rates`.
|
|
19
|
+
* @param {string} dimension
|
|
20
|
+
* @param {any} [rates] the rate table (currency only)
|
|
21
|
+
* @returns {Array<{ id: string, symbol: string }>}
|
|
22
|
+
*/
|
|
23
|
+
export declare function unitOptions(dimension: string, rates?: any): Array<{
|
|
24
|
+
id: string;
|
|
25
|
+
symbol: string;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Convert a value in a dimension. Delegates entirely to core: static
|
|
29
|
+
* dimensions to `convert`, currency to the pure `convertCurrency`.
|
|
30
|
+
* Returns `NaN` (never throws) so the display path stays total.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} dimension @param {number} value @param {string} from @param {string} to
|
|
33
|
+
* @param {any} [rates] the rate table (currency only)
|
|
34
|
+
* @returns {number}
|
|
35
|
+
*/
|
|
36
|
+
export declare function convertValue(dimension: string, value: number, from: string, to: string, rates?: any): number;
|
|
37
|
+
/** Format a converter result. @param {number} value */
|
|
38
|
+
export declare function format(value: number): string;
|
|
39
|
+
export declare const converterMode: {
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
dimensions: typeof converterDimensions;
|
|
43
|
+
unitOptions: typeof unitOptions;
|
|
44
|
+
convertValue: typeof convertValue;
|
|
45
|
+
format: typeof format;
|
|
46
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The financial mode kernel. Contains **no
|
|
3
|
+
* formulas** — every number comes from `@jarenjs/core/finance`. This is
|
|
4
|
+
* pure orchestration: the solve-for-unknown dispatcher (given any four of
|
|
5
|
+
* {N, I/Y, PV, PMT, FV}, pick the core function for the fifth) plus thin
|
|
6
|
+
* wrappers that turn a cash-flow / amortization request into core calls.
|
|
7
|
+
*/
|
|
8
|
+
/** The five TVM variables the panel exposes. */
|
|
9
|
+
export declare const TVM_FIELDS: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Solve for the one unknown TVM variable. `rate` is a **percent** per
|
|
12
|
+
* period on the way in and out (e.g. 6 ⇒ 6%); the other four are plain
|
|
13
|
+
* numbers under the standard sign convention.
|
|
14
|
+
*
|
|
15
|
+
* @param {{ nper?: number, rate?: number, pv?: number, pmt?: number, fv?: number, type?: number, solveFor: string }} inputs
|
|
16
|
+
* @returns {number}
|
|
17
|
+
*/
|
|
18
|
+
export declare function solveTvm(inputs: {
|
|
19
|
+
nper?: number;
|
|
20
|
+
rate?: number;
|
|
21
|
+
pv?: number;
|
|
22
|
+
pmt?: number;
|
|
23
|
+
fv?: number;
|
|
24
|
+
type?: number;
|
|
25
|
+
solveFor: string;
|
|
26
|
+
}): number;
|
|
27
|
+
/**
|
|
28
|
+
* Amortization series (delegates to core), ready to become a table/plot.
|
|
29
|
+
* @param {{ principal: number, rate: number, nper: number, type?: number }} inputs
|
|
30
|
+
* @returns {import('@jarenjs/core/finance/amortization').AmortRow[]}
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildAmortization(inputs: {
|
|
33
|
+
principal: number;
|
|
34
|
+
rate: number;
|
|
35
|
+
nper: number;
|
|
36
|
+
type?: number;
|
|
37
|
+
}): import('@jarenjs/core/finance/amortization').AmortRow[];
|
|
38
|
+
/**
|
|
39
|
+
* NPV of a discount rate (percent) and a comma/space-separated cash-flow
|
|
40
|
+
* string or array.
|
|
41
|
+
* @param {number} ratePct @param {number[]|string} cashflows
|
|
42
|
+
* @returns {number}
|
|
43
|
+
*/
|
|
44
|
+
export declare function npvOf(ratePct: number, cashflows: number[] | string): number;
|
|
45
|
+
/**
|
|
46
|
+
* IRR (percent) of a cash-flow series.
|
|
47
|
+
* @param {number[]|string} cashflows
|
|
48
|
+
* @returns {number}
|
|
49
|
+
*/
|
|
50
|
+
export declare function irrOf(cashflows: number[] | string): number;
|
|
51
|
+
/** Format a money-ish result. @param {number} value */
|
|
52
|
+
export declare function format(value: number): string;
|
|
53
|
+
export declare const financialMode: {
|
|
54
|
+
id: string;
|
|
55
|
+
label: string;
|
|
56
|
+
tvmFields: string[];
|
|
57
|
+
solveTvm: typeof solveTvm;
|
|
58
|
+
format: typeof format;
|
|
59
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Mode-kernel barrel. Each mode is a data-driven descriptor
|
|
3
|
+
* (keypad/panel + function-binding env + formatter); switching mode is a
|
|
4
|
+
* patch of `$.calc.mode`.
|
|
5
|
+
*/
|
|
6
|
+
export { standardMode } from './standard.js';
|
|
7
|
+
export { scientificMode } from './scientific.js';
|
|
8
|
+
export { programmerMode, wordViews, BASES, WORD_SIZES } from './programmer.js';
|
|
9
|
+
export { financialMode, solveTvm, buildAmortization, npvOf, irrOf } from './financial.js';
|
|
10
|
+
export { converterMode, convertValue, unitOptions, converterDimensions, CURRENCY } from './converter.js';
|
|
11
|
+
/** All modes, in selector order. */
|
|
12
|
+
export declare const MODES: ({
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
env: any;
|
|
16
|
+
keypad: {
|
|
17
|
+
label: string;
|
|
18
|
+
k: string;
|
|
19
|
+
tone?: string;
|
|
20
|
+
span?: number;
|
|
21
|
+
}[][];
|
|
22
|
+
format: typeof import("./standard.js").format;
|
|
23
|
+
} | {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
tvmFields: string[];
|
|
27
|
+
solveTvm: typeof import("./financial.js").solveTvm;
|
|
28
|
+
format: typeof import("./financial.js").format;
|
|
29
|
+
} | {
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
dimensions: typeof import("./converter.js").converterDimensions;
|
|
33
|
+
unitOptions: typeof import("./converter.js").unitOptions;
|
|
34
|
+
convertValue: typeof import("./converter.js").convertValue;
|
|
35
|
+
format: typeof import("./converter.js").format;
|
|
36
|
+
})[];
|
|
37
|
+
/** Mode descriptor by id. @type {Record<string, any>} */
|
|
38
|
+
export declare const MODE_BY_ID: Record<string, any>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The programmer mode kernel. Binds the
|
|
3
|
+
* word-math environment (`@jarenjs/core/math/word.js`) so `& | << >> ~`
|
|
4
|
+
* and the `and/or/xor/not/shl/shr/rol/ror/mod` functions operate at the
|
|
5
|
+
* chosen word size (8/16/32/64) and signedness. Literals are written with
|
|
6
|
+
* `0x`/`0o`/`0b` prefixes; the display shows all four bases live.
|
|
7
|
+
*
|
|
8
|
+
* No formulas live here — the reusable word math is in core; this module
|
|
9
|
+
* is the keypad + the four-base view derivation.
|
|
10
|
+
*/
|
|
11
|
+
export declare const BASES: string[];
|
|
12
|
+
export declare const WORD_SIZES: number[];
|
|
13
|
+
/** @type {Array<Array<{label:string,k:string,tone?:string,span?:number}>>} */
|
|
14
|
+
export declare const KEYPAD: Array<Array<{
|
|
15
|
+
label: string;
|
|
16
|
+
k: string;
|
|
17
|
+
tone?: string;
|
|
18
|
+
span?: number;
|
|
19
|
+
}>>;
|
|
20
|
+
/**
|
|
21
|
+
* The live four-base view of an integer value at the given word size.
|
|
22
|
+
* @param {number} value @param {number} [wordBits] @param {boolean} [signed]
|
|
23
|
+
* @returns {{ hex: string, dec: string, oct: string, bin: string }}
|
|
24
|
+
*/
|
|
25
|
+
export declare function wordViews(value: number, wordBits?: number, signed?: boolean): {
|
|
26
|
+
hex: string;
|
|
27
|
+
dec: string;
|
|
28
|
+
oct: string;
|
|
29
|
+
bin: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Format the primary display in the currently-selected base.
|
|
33
|
+
* @param {number} value @param {any} [state]
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export declare function format(value: number, state?: any): string;
|
|
37
|
+
export declare const programmerMode: {
|
|
38
|
+
id: string;
|
|
39
|
+
label: string;
|
|
40
|
+
env: any;
|
|
41
|
+
keypad: {
|
|
42
|
+
label: string;
|
|
43
|
+
k: string;
|
|
44
|
+
tone?: string;
|
|
45
|
+
span?: number;
|
|
46
|
+
}[][];
|
|
47
|
+
format: typeof format;
|
|
48
|
+
bases: string[];
|
|
49
|
+
wordSizes: number[];
|
|
50
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The scientific mode kernel: the standard keypad plus the
|
|
3
|
+
* A1 transcendentals as function-insert keys, constants, factorial and an
|
|
4
|
+
* angle-mode toggle. It binds the same float environment as standard —
|
|
5
|
+
* the transcendentals were already in it — so no formulas live here.
|
|
6
|
+
*/
|
|
7
|
+
import { format } from './standard.js';
|
|
8
|
+
/** @type {Array<Array<{label:string,k:string,tone?:string,span?:number}>>} */
|
|
9
|
+
export declare const KEYPAD: Array<Array<{
|
|
10
|
+
label: string;
|
|
11
|
+
k: string;
|
|
12
|
+
tone?: string;
|
|
13
|
+
span?: number;
|
|
14
|
+
}>>;
|
|
15
|
+
export declare const scientificMode: {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
env: any;
|
|
19
|
+
keypad: {
|
|
20
|
+
label: string;
|
|
21
|
+
k: string;
|
|
22
|
+
tone?: string;
|
|
23
|
+
span?: number;
|
|
24
|
+
}[][];
|
|
25
|
+
format: typeof format;
|
|
26
|
+
/** angle modes offered by the toggle */
|
|
27
|
+
angleModes: string[];
|
|
28
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The standard mode kernel: a data-driven
|
|
3
|
+
* keypad descriptor, the function-binding environment the compiler uses,
|
|
4
|
+
* and a display formatter. A key is `{ label, k, tone?, span? }`; `k` is
|
|
5
|
+
* the token appended to the expression entry, or a command (`=`, `C`,
|
|
6
|
+
* `back`). Switching mode is just a patch of `$.calc.mode`.
|
|
7
|
+
*/
|
|
8
|
+
/** @type {Array<Array<{label:string,k:string,tone?:string,span?:number}>>} */
|
|
9
|
+
export declare const KEYPAD: Array<Array<{
|
|
10
|
+
label: string;
|
|
11
|
+
k: string;
|
|
12
|
+
tone?: string;
|
|
13
|
+
span?: number;
|
|
14
|
+
}>>;
|
|
15
|
+
/**
|
|
16
|
+
* Format a numeric result for the display.
|
|
17
|
+
* @param {number} value @param {any} [state]
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export declare function format(value: number, state?: any): string;
|
|
21
|
+
export declare const standardMode: {
|
|
22
|
+
id: string;
|
|
23
|
+
label: string;
|
|
24
|
+
env: any;
|
|
25
|
+
keypad: {
|
|
26
|
+
label: string;
|
|
27
|
+
k: string;
|
|
28
|
+
tone?: string;
|
|
29
|
+
span?: number;
|
|
30
|
+
}[][];
|
|
31
|
+
format: typeof format;
|
|
32
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `parseExpression(text, opts) → ExprAST`. A char-offset
|
|
3
|
+
* recursive-descent, precedence-climbing parser in the repository idiom
|
|
4
|
+
* (module-const sticky regexes for the number/identifier leaves, a
|
|
5
|
+
* `fail(msg, pos)` that raises `CalcParseError` with 1-based line/column).
|
|
6
|
+
* No `eval`, no per-parse `RegExp` allocation.
|
|
7
|
+
*
|
|
8
|
+
* Grammar (low → high precedence), all left-associative except power
|
|
9
|
+
* (right) and the prefix unaries:
|
|
10
|
+
*
|
|
11
|
+
* or := and ('|' and)*
|
|
12
|
+
* and := shift ('&' shift)*
|
|
13
|
+
* shift := add (('<<'|'>>') add)*
|
|
14
|
+
* add := mul (('+'|'-') mul)*
|
|
15
|
+
* mul := unary (('*'|'/') unary)*
|
|
16
|
+
* unary := ('-'|'+'|'~') unary | power
|
|
17
|
+
* power := postfix ('^' unary)? // right-assoc via unary
|
|
18
|
+
* postfix := primary ('!' | '%')*
|
|
19
|
+
* primary := number | const | ident | ident '(' args ')' | '(' or ')'
|
|
20
|
+
*
|
|
21
|
+
* Number bases (`0x`/`0o`/`0b`) and scientific notation are recognized at
|
|
22
|
+
* the leaf; the AST keeps only the numeric value.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Parse an expression string into an `ExprAST`.
|
|
26
|
+
* @param {string} text
|
|
27
|
+
* @param {{ [k: string]: any }} [opts]
|
|
28
|
+
* @returns {any}
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseExpression(text: string, opts?: {
|
|
31
|
+
[k: string]: any;
|
|
32
|
+
}): any;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The x·y plotter. `plot2d` compiles `f(x)`
|
|
3
|
+
* ONCE, samples the domain into `Float64Array` buffers, maps them to the
|
|
4
|
+
* viewport with a standard linear remap, and emits axes/grid/ticks plus one
|
|
5
|
+
* `<path>` polyline per series — breaking the path on NaN/±Inf and at
|
|
6
|
+
* asymptote jumps. The intermediate **scene** is geometry-as-plain-JSON
|
|
7
|
+
* (deterministic → golden-geometry tests); `scene2dToVnode` turns it into
|
|
8
|
+
* pure-vnode SVG.
|
|
9
|
+
*/
|
|
10
|
+
export type Plot2dConfig = {
|
|
11
|
+
/**
|
|
12
|
+
* one or more source expressions
|
|
13
|
+
*/
|
|
14
|
+
expr?: string | string[];
|
|
15
|
+
domain?: [number, number];
|
|
16
|
+
/**
|
|
17
|
+
* omit for auto-range
|
|
18
|
+
*/
|
|
19
|
+
range?: [number, number];
|
|
20
|
+
samples?: number;
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
/**
|
|
24
|
+
* independent variable name (default 'x')
|
|
25
|
+
*/
|
|
26
|
+
variable?: string;
|
|
27
|
+
/**
|
|
28
|
+
* extra variables in scope
|
|
29
|
+
*/
|
|
30
|
+
scope?: any;
|
|
31
|
+
/**
|
|
32
|
+
* evaluation environment (default float)
|
|
33
|
+
*/
|
|
34
|
+
env?: any;
|
|
35
|
+
theme?: any;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {object} Plot2dConfig
|
|
39
|
+
* @property {string|string[]} [expr] one or more source expressions
|
|
40
|
+
* @property {[number,number]} [domain]
|
|
41
|
+
* @property {[number,number]} [range] omit for auto-range
|
|
42
|
+
* @property {number} [samples]
|
|
43
|
+
* @property {number} [width] @property {number} [height]
|
|
44
|
+
* @property {string} [variable] independent variable name (default 'x')
|
|
45
|
+
* @property {any} [scope] extra variables in scope
|
|
46
|
+
* @property {any} [env] evaluation environment (default float)
|
|
47
|
+
* @property {any} [theme]
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Build the geometry-as-JSON scene.
|
|
51
|
+
* @param {string|string[]|Plot2dConfig} exprOrConfig
|
|
52
|
+
* @param {Plot2dConfig} [options]
|
|
53
|
+
* @returns {any}
|
|
54
|
+
*/
|
|
55
|
+
export declare function buildScene2d(exprOrConfig: string | string[] | Plot2dConfig, options?: Plot2dConfig): any;
|
|
56
|
+
/**
|
|
57
|
+
* Render a 2D scene into a pure-vnode SVG.
|
|
58
|
+
* @param {any} scene @param {{ theme?: any }} [options]
|
|
59
|
+
* @returns {any}
|
|
60
|
+
*/
|
|
61
|
+
export declare function scene2dToVnode(scene: any, options?: {
|
|
62
|
+
theme?: any;
|
|
63
|
+
}): any;
|
|
64
|
+
/**
|
|
65
|
+
* Compile → sample → SVG vnode in one call.
|
|
66
|
+
* @param {string|string[]|Plot2dConfig} exprOrConfig
|
|
67
|
+
* @param {Plot2dConfig} [options]
|
|
68
|
+
* @returns {any}
|
|
69
|
+
*/
|
|
70
|
+
export declare function plot2d(exprOrConfig: string | string[] | Plot2dConfig, options?: Plot2dConfig): any;
|