@pie-players/pie-calculator-cortex 0.3.68
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/LICENSE.md +14 -0
- package/README.md +256 -0
- package/dist/assets/evaluation-worker-BI6KdSur.js +115523 -0
- package/dist/chunks/runtime-BiXEoJDs.js +163543 -0
- package/dist/chunks/settings-C0zxv5EL.js +389 -0
- package/dist/chunks/src-D05hiMPJ.js +31307 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +63 -0
- package/dist/src/CalculatorView.svelte.d.ts +1 -0
- package/dist/src/GraphView.svelte.d.ts +1 -0
- package/dist/src/Icon.svelte.d.ts +1 -0
- package/dist/src/Keypad.svelte.d.ts +1 -0
- package/dist/src/MathFieldInput.svelte.d.ts +1 -0
- package/dist/src/calculator-controller.d.ts +65 -0
- package/dist/src/cortex-provider.d.ts +18 -0
- package/dist/src/errors.d.ts +10 -0
- package/dist/src/evaluation-client.d.ts +26 -0
- package/dist/src/evaluation-engine.d.ts +9 -0
- package/dist/src/evaluation-worker.d.ts +1 -0
- package/dist/src/function-policy.d.ts +15 -0
- package/dist/src/icons.d.ts +33 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/keypad-layouts.d.ts +70 -0
- package/dist/src/localization.d.ts +35 -0
- package/dist/src/mathlive-runtime.d.ts +17 -0
- package/dist/src/runtime.d.ts +5 -0
- package/dist/src/settings.d.ts +29 -0
- package/dist/src/state-codec.d.ts +10 -0
- package/dist/src/types.d.ts +157 -0
- package/dist/src/worker-protocol.d.ts +58 -0
- package/package.json +74 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { i as d, n as l, o as u, r as p, s as t } from "./chunks/settings-C0zxv5EL.js";
|
|
2
|
+
var h = class {
|
|
3
|
+
providerId = "cortex";
|
|
4
|
+
providerName = "PIE Open-Source Calculator";
|
|
5
|
+
supportedTypes = [
|
|
6
|
+
"basic",
|
|
7
|
+
"scientific",
|
|
8
|
+
"graphing"
|
|
9
|
+
];
|
|
10
|
+
version = "1";
|
|
11
|
+
initialized = !1;
|
|
12
|
+
destroyed = !1;
|
|
13
|
+
instances = /* @__PURE__ */ new Set();
|
|
14
|
+
onTelemetry;
|
|
15
|
+
constructor(e = {}) {
|
|
16
|
+
this.onTelemetry = e.onTelemetry;
|
|
17
|
+
}
|
|
18
|
+
async initialize(e = {}) {
|
|
19
|
+
if (!this.initialized) {
|
|
20
|
+
if (this.destroyed) throw new t("worker-unavailable", "This calculator provider has been destroyed.", { recoverable: !1 });
|
|
21
|
+
if (typeof window > "u" || typeof document > "u") throw new t("worker-unavailable", "Cortex calculators can only be initialized in a browser.", { recoverable: !1 });
|
|
22
|
+
if (typeof Worker > "u") throw new t("worker-unavailable", "This browser does not support module workers.", { recoverable: !1 });
|
|
23
|
+
this.onTelemetry = e.onTelemetry ?? this.onTelemetry, this.initialized = !0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async createCalculator(e, r, s = {}) {
|
|
27
|
+
if (this.initialized || await this.initialize(), !this.supportsType(e)) throw new t("unsupported-expression", `Cortex does not support calculator type: ${e}.`);
|
|
28
|
+
if (!(r instanceof HTMLElement)) throw new t("invalid-state", "A valid HTML container is required.");
|
|
29
|
+
const o = l(e, s), { createCortexCalculator: a } = await import("./chunks/runtime-BiXEoJDs.js"), i = a(this, r, o, this.onTelemetry, (n) => this.instances.delete(n));
|
|
30
|
+
return this.instances.add(i), i;
|
|
31
|
+
}
|
|
32
|
+
supportsType(e) {
|
|
33
|
+
return this.supportedTypes.includes(e);
|
|
34
|
+
}
|
|
35
|
+
destroy() {
|
|
36
|
+
if (!this.destroyed) {
|
|
37
|
+
this.destroyed = !0;
|
|
38
|
+
for (const e of [...this.instances]) e.destroy();
|
|
39
|
+
this.instances.clear(), this.initialized = !1, this.onTelemetry = void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getCapabilities() {
|
|
43
|
+
return {
|
|
44
|
+
supportsHistory: !0,
|
|
45
|
+
supportsGraphing: !0,
|
|
46
|
+
supportsExpressions: !0,
|
|
47
|
+
canExport: !0,
|
|
48
|
+
maxPrecision: 21,
|
|
49
|
+
inputMethods: [
|
|
50
|
+
"keyboard",
|
|
51
|
+
"mouse",
|
|
52
|
+
"touch"
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
t as CortexCalculatorError,
|
|
59
|
+
h as CortexCalculatorProvider,
|
|
60
|
+
p as cortexDutchMessages,
|
|
61
|
+
d as cortexEnglishMessages,
|
|
62
|
+
u as localeDirection
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvelteComponent as default } from 'svelte';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CalculationHistoryEntry, CalculatorState } from '@pie-players/pie-calculator';
|
|
2
|
+
import { CortexCalculatorErrorCode } from './errors.js';
|
|
3
|
+
import { ResolvedCortexSettings } from './settings.js';
|
|
4
|
+
import { CortexAngleMode, CortexGraphState, CortexGraphViewport, CortexOuterCalculatorState } from './types.js';
|
|
5
|
+
import { SampledSeries } from './worker-protocol.js';
|
|
6
|
+
export interface CortexCalculatorSnapshot {
|
|
7
|
+
readonly inputLatex: string;
|
|
8
|
+
readonly result: string;
|
|
9
|
+
readonly errorCode: CortexCalculatorErrorCode | null;
|
|
10
|
+
readonly busy: boolean;
|
|
11
|
+
readonly graphUpdating: boolean;
|
|
12
|
+
readonly history: readonly CalculationHistoryEntry[];
|
|
13
|
+
readonly angleMode: CortexAngleMode;
|
|
14
|
+
readonly graph: CortexGraphState | null;
|
|
15
|
+
readonly series: readonly SampledSeries[];
|
|
16
|
+
readonly focusRequest: number;
|
|
17
|
+
readonly resizeRequest: number;
|
|
18
|
+
}
|
|
19
|
+
type Subscriber = (snapshot: CortexCalculatorSnapshot) => void;
|
|
20
|
+
type TelemetryCallback = (eventName: string, payload?: Record<string, unknown>) => void | Promise<void>;
|
|
21
|
+
export declare class CortexCalculatorController {
|
|
22
|
+
readonly settings: ResolvedCortexSettings;
|
|
23
|
+
private readonly onTelemetry?;
|
|
24
|
+
private readonly subscribers;
|
|
25
|
+
private readonly mainEngine;
|
|
26
|
+
private evaluationClient;
|
|
27
|
+
private destroyed;
|
|
28
|
+
private operationGeneration;
|
|
29
|
+
private currentAngleMode;
|
|
30
|
+
private inputLatex;
|
|
31
|
+
private result;
|
|
32
|
+
private errorCode;
|
|
33
|
+
private busy;
|
|
34
|
+
private inFlightEvaluations;
|
|
35
|
+
private graphUpdating;
|
|
36
|
+
private history;
|
|
37
|
+
private graph;
|
|
38
|
+
private series;
|
|
39
|
+
private focusRequest;
|
|
40
|
+
private resizeRequest;
|
|
41
|
+
constructor(settings: ResolvedCortexSettings, onTelemetry?: TelemetryCallback | undefined);
|
|
42
|
+
private effectiveSettings;
|
|
43
|
+
getSnapshot(): CortexCalculatorSnapshot;
|
|
44
|
+
private publish;
|
|
45
|
+
private telemetry;
|
|
46
|
+
subscribe(subscriber: Subscriber): () => void;
|
|
47
|
+
getValue(): string;
|
|
48
|
+
setValue(latex: string): void;
|
|
49
|
+
setGraphExpression(id: string, latex: string): void;
|
|
50
|
+
addGraphExpression(): void;
|
|
51
|
+
removeGraphExpression(id: string): void;
|
|
52
|
+
toggleGraphExpression(id: string): void;
|
|
53
|
+
setAngleMode(mode: CortexAngleMode): void;
|
|
54
|
+
evaluate(latex?: string): Promise<string>;
|
|
55
|
+
sampleGraph(viewport: CortexGraphViewport, pixelWidth: number): Promise<void>;
|
|
56
|
+
clear(): void;
|
|
57
|
+
getHistory(): CalculationHistoryEntry[];
|
|
58
|
+
clearHistory(): void;
|
|
59
|
+
exportState(): CortexOuterCalculatorState;
|
|
60
|
+
importState(state: CalculatorState): void;
|
|
61
|
+
requestFocus(): void;
|
|
62
|
+
requestResize(): void;
|
|
63
|
+
destroy(): void;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Calculator, CalculatorProvider, CalculatorProviderCapabilities, CalculatorType } from '@pie-players/pie-calculator';
|
|
2
|
+
import { CortexCalculatorProviderConfig, CortexCalculatorProviderInit } from './types.js';
|
|
3
|
+
export declare class CortexCalculatorProvider implements CalculatorProvider {
|
|
4
|
+
readonly providerId = "cortex";
|
|
5
|
+
readonly providerName = "PIE Open-Source Calculator";
|
|
6
|
+
readonly supportedTypes: CalculatorType[];
|
|
7
|
+
readonly version = "1";
|
|
8
|
+
private initialized;
|
|
9
|
+
private destroyed;
|
|
10
|
+
private readonly instances;
|
|
11
|
+
private onTelemetry;
|
|
12
|
+
constructor(config?: CortexCalculatorProviderInit);
|
|
13
|
+
initialize(config?: CortexCalculatorProviderInit): Promise<void>;
|
|
14
|
+
createCalculator(type: CalculatorType, container: HTMLElement, config?: CortexCalculatorProviderConfig): Promise<Calculator>;
|
|
15
|
+
supportsType(type: CalculatorType): boolean;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
getCapabilities(): CalculatorProviderCapabilities;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type CortexCalculatorErrorCode = "invalid-expression" | "unsupported-expression" | "expression-too-complex" | "evaluation-timeout" | "invalid-state" | "worker-unavailable";
|
|
2
|
+
export declare class CortexCalculatorError extends Error {
|
|
3
|
+
readonly code: CortexCalculatorErrorCode;
|
|
4
|
+
readonly recoverable: boolean;
|
|
5
|
+
constructor(code: CortexCalculatorErrorCode, message: string, options?: {
|
|
6
|
+
recoverable?: boolean;
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export declare function asCortexError(error: unknown, fallbackCode: CortexCalculatorErrorCode, fallbackMessage: string): CortexCalculatorError;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ResolvedCortexSettings } from './settings.js';
|
|
2
|
+
import { CortexGraphViewport } from './types.js';
|
|
3
|
+
import { EvaluationResult, SampledSeries } from './worker-protocol.js';
|
|
4
|
+
export declare class EvaluationClient {
|
|
5
|
+
private settings;
|
|
6
|
+
private worker;
|
|
7
|
+
private readonly pending;
|
|
8
|
+
private readonly instanceId;
|
|
9
|
+
private nextRequestId;
|
|
10
|
+
private generation;
|
|
11
|
+
private destroyed;
|
|
12
|
+
constructor(settings: ResolvedCortexSettings);
|
|
13
|
+
updateSettings(settings: ResolvedCortexSettings): void;
|
|
14
|
+
private workerSettings;
|
|
15
|
+
private ensureWorker;
|
|
16
|
+
private readonly handleMessage;
|
|
17
|
+
private readonly handleWorkerError;
|
|
18
|
+
private resetWorker;
|
|
19
|
+
private request;
|
|
20
|
+
evaluate(latex: string): Promise<EvaluationResult>;
|
|
21
|
+
sample(expressions: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
latex: string;
|
|
24
|
+
}>, viewport: CortexGraphViewport, pixelWidth: number): Promise<SampledSeries[]>;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ResolvedCortexSettings } from './settings.js';
|
|
2
|
+
import { CortexGraphViewport } from './types.js';
|
|
3
|
+
import { EvaluationResult, SampledSeries, WorkerEvaluationSettings } from './worker-protocol.js';
|
|
4
|
+
export declare function workerSettingsToResolved(type: "basic" | "scientific" | "graphing", settings: WorkerEvaluationSettings): ResolvedCortexSettings;
|
|
5
|
+
export declare function evaluateLatex(type: "basic" | "scientific" | "graphing", latex: string, settings: WorkerEvaluationSettings): EvaluationResult;
|
|
6
|
+
export declare function sampleLatex(expressions: Array<{
|
|
7
|
+
id: string;
|
|
8
|
+
latex: string;
|
|
9
|
+
}>, viewport: CortexGraphViewport, pixelWidth: number, settings: WorkerEvaluationSettings): SampledSeries[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComputeEngine, Expression } from '@cortex-js/compute-engine';
|
|
2
|
+
import { ResolvedCortexSettings } from './settings.js';
|
|
3
|
+
export interface EditBufferInspection {
|
|
4
|
+
readonly latex: string;
|
|
5
|
+
readonly empty: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidatedExpression {
|
|
8
|
+
readonly latex: string;
|
|
9
|
+
readonly expression: Expression;
|
|
10
|
+
readonly nodeCount: number;
|
|
11
|
+
readonly depth: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function inspectEditBuffer(latex: string): EditBufferInspection;
|
|
14
|
+
export declare function unwrapGraphExpression(latex: string): string;
|
|
15
|
+
export declare function validateExpression(engine: ComputeEngine, latex: string, settings: ResolvedCortexSettings): ValidatedExpression;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icon geometry for the tool's glyph-faced buttons.
|
|
3
|
+
*
|
|
4
|
+
* Paths rather than font characters: `⌫` (U+232B) is the face a backspace button
|
|
5
|
+
* wants and the one least likely to be in a host's font stack, and a missing glyph
|
|
6
|
+
* renders as a notdef box — a control with no legible face at all. The arrows and
|
|
7
|
+
* math signs elsewhere in this package stay as text, since those code points are
|
|
8
|
+
* in every font a browser will fall back to.
|
|
9
|
+
*
|
|
10
|
+
* Drawn on a 24x24 grid and stroked in `currentColor`, so a button's own colour
|
|
11
|
+
* carries the icon — including under forced colours, where these buttons take
|
|
12
|
+
* `ButtonText`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ICON_VIEW_BOX = "0 0 24 24";
|
|
15
|
+
/** Stroke geometry shared by every icon here. */
|
|
16
|
+
export declare const ICON_STROKE: {
|
|
17
|
+
readonly fill: "none";
|
|
18
|
+
readonly stroke: "currentColor";
|
|
19
|
+
readonly "stroke-width": "1.75";
|
|
20
|
+
readonly "stroke-linecap": "round";
|
|
21
|
+
readonly "stroke-linejoin": "round";
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A key with a cross in it, pointing at what it deletes. The point sits at x=4 so
|
|
25
|
+
* the shape reads as directional at 20px, which a symmetrical box does not.
|
|
26
|
+
*/
|
|
27
|
+
export declare const BACKSPACE_ICON: string[];
|
|
28
|
+
/**
|
|
29
|
+
* A cross in a circle — the affordance a browser puts in its own search fields for
|
|
30
|
+
* exactly this, and deliberately not the bare cross the tool shell's close button
|
|
31
|
+
* uses, which sits a few pixels away in the same panel.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CLEAR_ICON: string[];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CortexCalculatorProvider } from './cortex-provider.js';
|
|
2
|
+
export { cortexDutchMessages, cortexEnglishMessages, localeDirection, } from './localization.js';
|
|
3
|
+
export { CortexCalculatorError, type CortexCalculatorErrorCode, } from './errors.js';
|
|
4
|
+
export type { CortexAngleMode, CortexCalculatorMessageKey, CortexCalculatorMessageOverrides, CortexCalculatorMessages, CortexCalculatorProviderConfig, CortexCalculatorProviderInit, CortexCalculatorSettings, CortexCalculatorState, CortexCalculatorStateV1, CortexFunctionId, CortexGraphExpressionState, CortexGraphLineStyle, CortexGraphSettings, CortexGraphState, CortexGraphViewport, CortexTextDirection, } from './types.js';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CortexCalculatorLocalization } from './localization.js';
|
|
2
|
+
import { ResolvedCortexSettings } from './settings.js';
|
|
3
|
+
import { CortexCalculatorMessageKey, CortexFunctionId } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The keypad this package renders itself.
|
|
6
|
+
*
|
|
7
|
+
* It is not MathLive's virtual keyboard, and that is deliberate. MathLive's is a
|
|
8
|
+
* viewport-fixed singleton whose keycaps are `div[tabindex="-1"]` with no `role`,
|
|
9
|
+
* whose toggle carries `role="button"` with no `tabindex`, and which therefore
|
|
10
|
+
* contains zero focusable elements — it cannot be opened or operated by keyboard
|
|
11
|
+
* or switch access at all. Its `container` setter also throws inside an iframe
|
|
12
|
+
* (`VirtualKeyboardProxy`), which is how assessments are commonly delivered. So
|
|
13
|
+
* the layouts live here as data and render as real buttons.
|
|
14
|
+
*
|
|
15
|
+
* `visualLabel` is what a learner sees. Keys labelled with a word carry that word
|
|
16
|
+
* inside their accessible name (WCAG 2.5.3 Label in Name, and what voice control
|
|
17
|
+
* speaks); keys labelled with a glyph are named freely.
|
|
18
|
+
*
|
|
19
|
+
* `requires` gates a key on `settings.allowedFunctions`. A host may narrow that
|
|
20
|
+
* set, and `validateExpression` throws `unsupported-expression` for anything
|
|
21
|
+
* outside it — so an ungated keypad would offer keys that raise a `role="alert"`
|
|
22
|
+
* error when pressed.
|
|
23
|
+
*/
|
|
24
|
+
export interface KeypadKey {
|
|
25
|
+
/** Stable id, used for keyed iteration and the roving tab index. */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/** LaTeX handed to the mathfield, `#0` marking where the caret lands. */
|
|
28
|
+
readonly latex: string;
|
|
29
|
+
/** Rendered as the key's face. `math` is typeset by MathLive, `text` is not. */
|
|
30
|
+
readonly visualLabel: string;
|
|
31
|
+
readonly labelKind: "math" | "text" | "glyph";
|
|
32
|
+
/** Message key for the accessible name. */
|
|
33
|
+
readonly nameKey: CortexCalculatorMessageKey;
|
|
34
|
+
readonly nameValues?: Readonly<Record<string, string | number>>;
|
|
35
|
+
/** Key class, which drives grouping and emphasis rather than decoration. */
|
|
36
|
+
readonly role: "digit" | "operator" | "function" | "commit" | "edit";
|
|
37
|
+
/** Omit the key unless every listed capability is allowed. */
|
|
38
|
+
readonly requires?: readonly CortexFunctionId[];
|
|
39
|
+
/** Basic mode rejects constants outright (`validateSymbol`). */
|
|
40
|
+
readonly scientificOnly?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Grid column to place the key in, 1-based over the five key columns, instead
|
|
43
|
+
* of the position its index implies. The commit key uses it to hold the same
|
|
44
|
+
* corner on a short row as it does on a full one.
|
|
45
|
+
*/
|
|
46
|
+
readonly column?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface KeypadLayer {
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly labelKey: CortexCalculatorMessageKey;
|
|
51
|
+
readonly rows: readonly (readonly KeypadKey[])[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The layers for one calculator, already filtered to what the host permits.
|
|
55
|
+
*
|
|
56
|
+
* Scientific stacks its functions in a *second layer* rather than extra rows. The
|
|
57
|
+
* shipped panels are 380x500 basic, 380x560 scientific and 720x660 graphing, with a
|
|
58
|
+
* 480px floor for the first two (see `registrations/calculator.ts`). Row count is a
|
|
59
|
+
* layout budget rather than a target-size one: keys hold 44px from a token whose
|
|
60
|
+
* value the density tiers in `CalculatorView.svelte` step down only in a panel too
|
|
61
|
+
* short for it, so an extra row costs panel height at every size that ships. Eight
|
|
62
|
+
* rows in one layer would put the keypad 250px past the floor, which is a scroll to
|
|
63
|
+
* reach `sin`.
|
|
64
|
+
*
|
|
65
|
+
* Four rows is the budget; the graphing layer spends five because it carries the
|
|
66
|
+
* five graph keys as well. Both fit the shipped panels with no scroll in either
|
|
67
|
+
* axis, and the e2e suite measures every layer at both the size the panel opens at
|
|
68
|
+
* and its resizable minimum.
|
|
69
|
+
*/
|
|
70
|
+
export declare function keypadLayers(settings: ResolvedCortexSettings, localization: CortexCalculatorLocalization): readonly KeypadLayer[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CortexCalculatorErrorCode } from './errors.js';
|
|
2
|
+
import { CortexCalculatorMessageKey, CortexCalculatorMessageOverrides, CortexCalculatorMessages, CortexGraphLineStyle, CortexTextDirection } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The decimal separator this locale writes, `.` or `,`.
|
|
5
|
+
*
|
|
6
|
+
* One resolver for the whole package: the mathfield class is configured with it,
|
|
7
|
+
* the keypad's separator key is labelled with it, and a displayed result is
|
|
8
|
+
* punctuated with it, so a tapped key, a typed character and an answer all agree.
|
|
9
|
+
*/
|
|
10
|
+
export declare function localeDecimalSeparator(locale: string): "." | ",";
|
|
11
|
+
export declare function localeDirection(locale: string): CortexTextDirection;
|
|
12
|
+
export interface CortexCalculatorLocalization {
|
|
13
|
+
readonly locale: string;
|
|
14
|
+
readonly direction: CortexTextDirection;
|
|
15
|
+
readonly messages: CortexCalculatorMessages;
|
|
16
|
+
t(key: CortexCalculatorMessageKey, values?: Readonly<Record<string, string | number>>): string;
|
|
17
|
+
formatNumber(value: number, maximumSignificantDigits?: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* Punctuate an already-formatted result for this locale.
|
|
20
|
+
*
|
|
21
|
+
* A separator swap, not a reformat. `formatted` carries the host's
|
|
22
|
+
* `displayPrecision` and, past the exponential thresholds, an exponent
|
|
23
|
+
* (`2.432902008e+18`); handing that to `Intl.NumberFormat` would re-round it to
|
|
24
|
+
* `maximumSignificantDigits` and expand the exponent into nineteen digits. The
|
|
25
|
+
* model value keeps `.` -- `getResult`, the history entries and the serialized
|
|
26
|
+
* state are read back by hosts and across locales, so only the display is
|
|
27
|
+
* punctuated.
|
|
28
|
+
*/
|
|
29
|
+
formatResult(text: string): string;
|
|
30
|
+
errorMessage(code: CortexCalculatorErrorCode): string;
|
|
31
|
+
lineStyle(style: CortexGraphLineStyle): string;
|
|
32
|
+
}
|
|
33
|
+
export declare function createCortexLocalization(locale: string, overrides?: CortexCalculatorMessageOverrides, direction?: CortexTextDirection | "auto"): CortexCalculatorLocalization;
|
|
34
|
+
export declare const cortexEnglishMessages: Readonly<CortexCalculatorMessages>;
|
|
35
|
+
export declare const cortexDutchMessages: Readonly<CortexCalculatorMessages>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MathfieldElement } from 'mathlive';
|
|
2
|
+
import { CortexCalculatorLocalization, localeDecimalSeparator } from './localization.js';
|
|
3
|
+
interface MathfieldSettings {
|
|
4
|
+
locale: string;
|
|
5
|
+
decimalSeparator: "." | ",";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Point the mathfield class at this calculator's locale, and return the release
|
|
9
|
+
* that puts the page's own setting back.
|
|
10
|
+
*
|
|
11
|
+
* Idempotent per owner: re-acquiring only moves ownership, so a caller that
|
|
12
|
+
* acquires on every focus does not rebuild anything.
|
|
13
|
+
*/
|
|
14
|
+
export declare function acquireMathfieldSettings(owner: symbol, localization: CortexCalculatorLocalization, mathfieldConstructor: MathfieldSettings): () => void;
|
|
15
|
+
/** Which decimal separator a locale writes, exposed for the keypad's own key. */
|
|
16
|
+
export { localeDecimalSeparator as mathfieldDecimalSeparator };
|
|
17
|
+
export declare function configureMathfield(mathfield: MathfieldElement, label: string, restrictedMode: boolean): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Calculator, CalculatorProvider } from '@pie-players/pie-calculator';
|
|
2
|
+
import { ResolvedCortexSettings } from './settings.js';
|
|
3
|
+
type TelemetryCallback = (eventName: string, payload?: Record<string, unknown>) => void | Promise<void>;
|
|
4
|
+
export declare function createCortexCalculator(provider: CalculatorProvider, container: HTMLElement, settings: ResolvedCortexSettings, onTelemetry: TelemetryCallback | undefined, onDestroy: (calculator: Calculator) => void): Calculator;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CalculatorType } from '@pie-players/pie-calculator';
|
|
2
|
+
import { CortexCalculatorLocalization } from './localization.js';
|
|
3
|
+
import { CortexAngleMode, CortexCalculatorProviderConfig, CortexFunctionId, CortexGraphViewport } from './types.js';
|
|
4
|
+
export declare const CORTEX_INPUT_LENGTH_LIMIT = 1024;
|
|
5
|
+
export declare const CORTEX_AST_NODE_LIMIT = 256;
|
|
6
|
+
export declare const CORTEX_AST_DEPTH_LIMIT = 32;
|
|
7
|
+
export declare const CORTEX_GRAPH_EXPRESSION_LIMIT = 6;
|
|
8
|
+
export declare const CORTEX_GRAPH_SAMPLE_LIMIT = 1200;
|
|
9
|
+
export interface ResolvedCortexSettings {
|
|
10
|
+
readonly type: CalculatorType;
|
|
11
|
+
readonly angleMode: CortexAngleMode;
|
|
12
|
+
readonly calculationPrecision: number;
|
|
13
|
+
readonly displayPrecision: number;
|
|
14
|
+
readonly historyLimit: number;
|
|
15
|
+
readonly evaluationTimeLimitMs: number;
|
|
16
|
+
readonly allowedFunctions: ReadonlySet<CortexFunctionId>;
|
|
17
|
+
readonly allowClipboard: boolean;
|
|
18
|
+
readonly restrictedMode: boolean;
|
|
19
|
+
readonly locale: string;
|
|
20
|
+
readonly theme: "light" | "dark" | "auto";
|
|
21
|
+
readonly localization: CortexCalculatorLocalization;
|
|
22
|
+
readonly graph: {
|
|
23
|
+
readonly viewport: CortexGraphViewport;
|
|
24
|
+
readonly showAxes: boolean;
|
|
25
|
+
readonly showGrid: boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export declare function resolveCortexSettings(type: CalculatorType, config?: CortexCalculatorProviderConfig): ResolvedCortexSettings;
|
|
29
|
+
export declare function isCortexFunctionId(value: unknown): value is CortexFunctionId;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ComputeEngine } from '@cortex-js/compute-engine';
|
|
2
|
+
import { CalculationHistoryEntry, CalculatorState, CalculatorType } from '@pie-players/pie-calculator';
|
|
3
|
+
import { ResolvedCortexSettings } from './settings.js';
|
|
4
|
+
import { CortexCalculatorStateV1, CortexGraphState, CortexOuterCalculatorState } from './types.js';
|
|
5
|
+
export interface DecodedCortexState {
|
|
6
|
+
readonly state: CortexCalculatorStateV1;
|
|
7
|
+
readonly history: CalculationHistoryEntry[];
|
|
8
|
+
}
|
|
9
|
+
export declare function decodeCortexState(value: CalculatorState, type: CalculatorType, engine: ComputeEngine, settings: ResolvedCortexSettings): DecodedCortexState;
|
|
10
|
+
export declare function encodeCortexState(type: CalculatorType, inputLatex: string, history: readonly CalculationHistoryEntry[], settings: ResolvedCortexSettings, angleMode: "degree" | "radian", graph?: CortexGraphState): CortexOuterCalculatorState;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { CalculatorProviderConfig, CalculatorProviderInit, CalculatorState, CalculatorType } from '@pie-players/pie-calculator';
|
|
2
|
+
export type CortexAngleMode = "degree" | "radian";
|
|
3
|
+
export type CortexFunctionId = "square-root" | "power" | "root" | "exponential" | "natural-log" | "common-log" | "log-base-n" | "sine" | "cosine" | "tangent" | "inverse-sine" | "inverse-cosine" | "inverse-tangent" | "absolute-value" | "factorial";
|
|
4
|
+
export interface CortexGraphViewport {
|
|
5
|
+
xMin: number;
|
|
6
|
+
xMax: number;
|
|
7
|
+
yMin: number;
|
|
8
|
+
yMax: number;
|
|
9
|
+
}
|
|
10
|
+
export interface CortexGraphSettings {
|
|
11
|
+
viewport?: CortexGraphViewport;
|
|
12
|
+
showAxes?: boolean;
|
|
13
|
+
showGrid?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type CortexTextDirection = "ltr" | "rtl";
|
|
16
|
+
export interface CortexCalculatorMessages {
|
|
17
|
+
basicCalculator: string;
|
|
18
|
+
scientificCalculator: string;
|
|
19
|
+
graphingCalculator: string;
|
|
20
|
+
expressionLabel: string;
|
|
21
|
+
angleMode: string;
|
|
22
|
+
degrees: string;
|
|
23
|
+
radians: string;
|
|
24
|
+
calculate: string;
|
|
25
|
+
calculating: string;
|
|
26
|
+
backspace: string;
|
|
27
|
+
clear: string;
|
|
28
|
+
result: string;
|
|
29
|
+
calculationHistory: string;
|
|
30
|
+
clearHistory: string;
|
|
31
|
+
virtualKeyboardBasic: string;
|
|
32
|
+
virtualKeyboardScientific: string;
|
|
33
|
+
virtualKeyboardGraphing: string;
|
|
34
|
+
keypad: string;
|
|
35
|
+
keypadLayer: string;
|
|
36
|
+
angleModeDegreesShort: string;
|
|
37
|
+
angleModeRadiansShort: string;
|
|
38
|
+
angleModeChanged: string;
|
|
39
|
+
inserted: string;
|
|
40
|
+
keySine: string;
|
|
41
|
+
keyCosine: string;
|
|
42
|
+
keyTangent: string;
|
|
43
|
+
keyInverseSine: string;
|
|
44
|
+
keyInverseCosine: string;
|
|
45
|
+
keyInverseTangent: string;
|
|
46
|
+
keyNaturalLog: string;
|
|
47
|
+
keyCommonLog: string;
|
|
48
|
+
keyLogBaseN: string;
|
|
49
|
+
keyFraction: string;
|
|
50
|
+
keySquareRoot: string;
|
|
51
|
+
keyNthRoot: string;
|
|
52
|
+
keyPower: string;
|
|
53
|
+
keySquared: string;
|
|
54
|
+
keyCubed: string;
|
|
55
|
+
keyExponential: string;
|
|
56
|
+
keyAbsoluteValue: string;
|
|
57
|
+
keyFactorial: string;
|
|
58
|
+
keyPi: string;
|
|
59
|
+
keyEuler: string;
|
|
60
|
+
keyPercent: string;
|
|
61
|
+
keyOpenParenthesis: string;
|
|
62
|
+
keyCloseParenthesis: string;
|
|
63
|
+
keyDecimalSeparator: string;
|
|
64
|
+
keyDigit: string;
|
|
65
|
+
keyAdd: string;
|
|
66
|
+
keySubtract: string;
|
|
67
|
+
keyMultiply: string;
|
|
68
|
+
keyDivide: string;
|
|
69
|
+
keyVariableX: string;
|
|
70
|
+
graphExpressions: string;
|
|
71
|
+
graphExpressionLabel: string;
|
|
72
|
+
seriesDescription: string;
|
|
73
|
+
showExpression: string;
|
|
74
|
+
hideExpression: string;
|
|
75
|
+
show: string;
|
|
76
|
+
hide: string;
|
|
77
|
+
removeExpression: string;
|
|
78
|
+
remove: string;
|
|
79
|
+
addExpression: string;
|
|
80
|
+
graph: string;
|
|
81
|
+
viewportControls: string;
|
|
82
|
+
zoomIn: string;
|
|
83
|
+
zoomOut: string;
|
|
84
|
+
panLeft: string;
|
|
85
|
+
panRight: string;
|
|
86
|
+
panUp: string;
|
|
87
|
+
panDown: string;
|
|
88
|
+
resetView: string;
|
|
89
|
+
updatingGraph: string;
|
|
90
|
+
graphSummary: string;
|
|
91
|
+
viewportSummary: string;
|
|
92
|
+
seriesSummary: string;
|
|
93
|
+
keyboardGraphTrace: string;
|
|
94
|
+
keyboardTrace: string;
|
|
95
|
+
series: string;
|
|
96
|
+
seriesOption: string;
|
|
97
|
+
previousPoint: string;
|
|
98
|
+
nextPoint: string;
|
|
99
|
+
tracePoint: string;
|
|
100
|
+
noSampledPoint: string;
|
|
101
|
+
lineStyleSolid: string;
|
|
102
|
+
lineStyleDashed: string;
|
|
103
|
+
lineStyleDotted: string;
|
|
104
|
+
errorInvalidExpression: string;
|
|
105
|
+
errorUnsupportedExpression: string;
|
|
106
|
+
errorExpressionTooComplex: string;
|
|
107
|
+
errorEvaluationTimeout: string;
|
|
108
|
+
errorInvalidState: string;
|
|
109
|
+
errorWorkerUnavailable: string;
|
|
110
|
+
}
|
|
111
|
+
export type CortexCalculatorMessageKey = keyof CortexCalculatorMessages;
|
|
112
|
+
export type CortexCalculatorMessageOverrides = Partial<CortexCalculatorMessages>;
|
|
113
|
+
export interface CortexCalculatorSettings extends Record<string, unknown> {
|
|
114
|
+
angleMode?: CortexAngleMode;
|
|
115
|
+
calculationPrecision?: number;
|
|
116
|
+
displayPrecision?: number;
|
|
117
|
+
historyLimit?: number;
|
|
118
|
+
evaluationTimeLimitMs?: number;
|
|
119
|
+
allowedFunctions?: readonly CortexFunctionId[];
|
|
120
|
+
allowClipboard?: boolean;
|
|
121
|
+
/** Override any package-owned visible or assistive label for this instance. */
|
|
122
|
+
messages?: CortexCalculatorMessageOverrides;
|
|
123
|
+
/** Derive direction from `locale` by default; override only for host policy. */
|
|
124
|
+
direction?: CortexTextDirection | "auto";
|
|
125
|
+
graph?: CortexGraphSettings;
|
|
126
|
+
}
|
|
127
|
+
export type CortexCalculatorProviderInit = Pick<CalculatorProviderInit, "onTelemetry">;
|
|
128
|
+
export interface CortexCalculatorProviderConfig extends Omit<CalculatorProviderConfig, "settings"> {
|
|
129
|
+
settings?: CortexCalculatorSettings;
|
|
130
|
+
}
|
|
131
|
+
export type CortexGraphLineStyle = "solid" | "dashed" | "dotted";
|
|
132
|
+
export interface CortexGraphExpressionState {
|
|
133
|
+
id: string;
|
|
134
|
+
latex: string;
|
|
135
|
+
colorIndex: number;
|
|
136
|
+
lineStyle: CortexGraphLineStyle;
|
|
137
|
+
hidden: boolean;
|
|
138
|
+
}
|
|
139
|
+
export interface CortexGraphState {
|
|
140
|
+
viewport: CortexGraphViewport;
|
|
141
|
+
expressions: CortexGraphExpressionState[];
|
|
142
|
+
}
|
|
143
|
+
export interface CortexCalculatorStateV1 {
|
|
144
|
+
schema: "pie-calculator-cortex";
|
|
145
|
+
version: 1;
|
|
146
|
+
type: CalculatorType;
|
|
147
|
+
angleMode: CortexAngleMode;
|
|
148
|
+
calculationPrecision: number;
|
|
149
|
+
displayPrecision: number;
|
|
150
|
+
inputLatex: string;
|
|
151
|
+
graph?: CortexGraphState;
|
|
152
|
+
}
|
|
153
|
+
export type CortexCalculatorState = CortexCalculatorStateV1;
|
|
154
|
+
export type CortexOuterCalculatorState = CalculatorState & {
|
|
155
|
+
provider: "cortex";
|
|
156
|
+
providerState: CortexCalculatorState;
|
|
157
|
+
};
|