@pie-players/pie-calculator 0.3.67 → 0.3.69
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 +41 -86
- package/dist/index.d.ts +1 -1
- package/dist/provider-interface.d.ts +35 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,86 +1,61 @@
|
|
|
1
1
|
# @pie-players/pie-calculator
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Purpose
|
|
6
|
-
|
|
7
|
-
This package provides the foundational interfaces and types for building calculator providers in the PIE ecosystem. It has **zero dependencies** and no UI framework requirements, making it suitable for:
|
|
8
|
-
|
|
9
|
-
- Implementing custom calculator providers
|
|
10
|
-
- Type-safe calculator integration
|
|
11
|
-
- Framework-agnostic calculator solutions
|
|
12
|
-
|
|
13
|
-
## What's Included
|
|
14
|
-
|
|
15
|
-
### Interfaces
|
|
16
|
-
|
|
17
|
-
- **`CalculatorProvider`** - Stateless factory for creating calculator implementations
|
|
18
|
-
- **`Calculator`** - Actual calculator instance interface
|
|
19
|
-
- **`CalculatorProviderCapabilities`** - Feature support description
|
|
20
|
-
- **`CalculatorProviderConfig`** - Provider configuration
|
|
21
|
-
|
|
22
|
-
### Types
|
|
23
|
-
|
|
24
|
-
- **`CalculatorType`** - Union type of supported calculator types
|
|
25
|
-
- **`CalculatorState`** - State for persistence
|
|
26
|
-
- **`CalculationHistoryEntry`** - History entry format
|
|
27
|
-
- **`DesmosCalculatorConfig`** - Desmos-specific configuration
|
|
3
|
+
Provider-neutral calculator contracts for PIE Players. This package has no UI
|
|
4
|
+
or vendor implementation code.
|
|
28
5
|
|
|
29
6
|
## Installation
|
|
30
7
|
|
|
31
8
|
```bash
|
|
32
|
-
npm install @pie-players/pie-calculator
|
|
33
|
-
# or
|
|
34
9
|
bun add @pie-players/pie-calculator
|
|
35
10
|
```
|
|
36
11
|
|
|
37
|
-
##
|
|
12
|
+
## Contract
|
|
13
|
+
|
|
14
|
+
The package exports:
|
|
38
15
|
|
|
39
|
-
|
|
16
|
+
- `CalculatorProvider`, the factory and capability contract implemented by a
|
|
17
|
+
calculator adapter;
|
|
18
|
+
- `Calculator`, the lifecycle, value, state, resize, and focus contract for one
|
|
19
|
+
mounted calculator;
|
|
20
|
+
- `CalculatorProviderInit`, the provider-level credential and instrumentation
|
|
21
|
+
surface;
|
|
22
|
+
- `CalculatorProviderConfig`, whose `settings` object is interpreted by the
|
|
23
|
+
selected implementation; and
|
|
24
|
+
- `CalculatorType`, with `basic`, `scientific`, and `graphing` modes.
|
|
40
25
|
|
|
41
|
-
|
|
26
|
+
Provider-specific settings belong to the provider package. Generic code passes
|
|
27
|
+
them through without importing or naming Desmos, GeoGebra, or another vendor.
|
|
28
|
+
|
|
29
|
+
```ts
|
|
42
30
|
import type {
|
|
43
|
-
CalculatorProvider,
|
|
44
31
|
Calculator,
|
|
45
|
-
|
|
32
|
+
CalculatorProvider,
|
|
46
33
|
CalculatorProviderCapabilities,
|
|
47
|
-
CalculatorProviderConfig
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
readonly provider: CalculatorProvider;
|
|
52
|
-
readonly type: CalculatorType;
|
|
53
|
-
|
|
54
|
-
constructor(provider: CalculatorProvider, type: CalculatorType, container: HTMLElement) {
|
|
55
|
-
this.provider = provider;
|
|
56
|
-
this.type = type;
|
|
57
|
-
// Initialize calculator in container
|
|
58
|
-
}
|
|
34
|
+
CalculatorProviderConfig,
|
|
35
|
+
CalculatorProviderInit,
|
|
36
|
+
CalculatorType,
|
|
37
|
+
} from "@pie-players/pie-calculator";
|
|
59
38
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
clear(): void { /* ... */ }
|
|
63
|
-
exportState(): CalculatorState { /* ... */ }
|
|
64
|
-
importState(state: CalculatorState): void { /* ... */ }
|
|
65
|
-
destroy(): void { /* ... */ }
|
|
39
|
+
interface MyCalculatorProviderConfig extends CalculatorProviderConfig {
|
|
40
|
+
precision?: number;
|
|
66
41
|
}
|
|
67
42
|
|
|
68
43
|
export class MyCalculatorProvider implements CalculatorProvider {
|
|
69
|
-
readonly providerId =
|
|
70
|
-
readonly providerName =
|
|
71
|
-
readonly supportedTypes: CalculatorType[] = [
|
|
72
|
-
readonly version =
|
|
44
|
+
readonly providerId = "my-calculator";
|
|
45
|
+
readonly providerName = "My Calculator";
|
|
46
|
+
readonly supportedTypes: CalculatorType[] = ["basic", "scientific"];
|
|
47
|
+
readonly version = "1";
|
|
73
48
|
|
|
74
|
-
async initialize(): Promise<void> {
|
|
75
|
-
// Load libraries
|
|
49
|
+
async initialize(config?: CalculatorProviderInit): Promise<void> {
|
|
50
|
+
// Load libraries and initialize provider-level services.
|
|
76
51
|
}
|
|
77
52
|
|
|
78
53
|
async createCalculator(
|
|
79
54
|
type: CalculatorType,
|
|
80
55
|
container: HTMLElement,
|
|
81
|
-
config?:
|
|
56
|
+
config?: MyCalculatorProviderConfig,
|
|
82
57
|
): Promise<Calculator> {
|
|
83
|
-
return
|
|
58
|
+
return createMyCalculator({ provider: this, type, container, config });
|
|
84
59
|
}
|
|
85
60
|
|
|
86
61
|
supportsType(type: CalculatorType): boolean {
|
|
@@ -93,42 +68,22 @@ export class MyCalculatorProvider implements CalculatorProvider {
|
|
|
93
68
|
supportsGraphing: false,
|
|
94
69
|
supportsExpressions: true,
|
|
95
70
|
canExport: true,
|
|
96
|
-
|
|
97
|
-
inputMethods: ['keyboard', 'mouse', 'touch'],
|
|
71
|
+
inputMethods: ["keyboard", "mouse", "touch"],
|
|
98
72
|
};
|
|
99
73
|
}
|
|
100
74
|
|
|
101
|
-
destroy(): void {
|
|
102
|
-
// Cleanup
|
|
103
|
-
}
|
|
75
|
+
destroy(): void {}
|
|
104
76
|
}
|
|
105
77
|
```
|
|
106
78
|
|
|
107
|
-
##
|
|
79
|
+
## Implementations
|
|
108
80
|
|
|
109
|
-
-
|
|
81
|
+
- `@pie-players/pie-calculator-desmos`
|
|
82
|
+
- `@pie-players/pie-calculator-geogebra`
|
|
110
83
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Supported calculator types:
|
|
114
|
-
|
|
115
|
-
- `"basic"` - Four-function calculator (add, subtract, multiply, divide)
|
|
116
|
-
- `"scientific"` - Scientific calculator with trigonometry, logarithms, etc.
|
|
117
|
-
- `"graphing"` - Graphing calculator with coordinate plane
|
|
118
|
-
|
|
119
|
-
## Design Philosophy
|
|
120
|
-
|
|
121
|
-
This core package intentionally:
|
|
122
|
-
- ✅ Has **zero runtime dependencies**
|
|
123
|
-
- ✅ Contains **only TypeScript interfaces and types**
|
|
124
|
-
- ✅ Is **framework-agnostic** (no React, Svelte, Vue, etc.)
|
|
125
|
-
- ✅ Supports **pluggable architecture**
|
|
126
|
-
- ✅ Enables **type-safe calculator implementations**
|
|
84
|
+
Each implementation and its underlying calculator product has its own package
|
|
85
|
+
and licensing boundary. No vendor library is bundled by this contract package.
|
|
127
86
|
|
|
128
87
|
## License
|
|
129
88
|
|
|
130
|
-
MIT
|
|
131
|
-
|
|
132
|
-
## Related Packages
|
|
133
|
-
|
|
134
|
-
- [@pie-players/pie-calculator-desmos](../calculator-desmos) - Desmos graphing calculator provider
|
|
89
|
+
PIE-authored code in this package is MIT licensed.
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* Calculator provider interfaces and types for PIE Assessment Toolkit.
|
|
5
5
|
* No UI dependencies - pure TypeScript interfaces.
|
|
6
6
|
*/
|
|
7
|
-
export type { CalculationHistoryEntry, Calculator, CalculatorProvider, CalculatorProviderCapabilities, CalculatorProviderConfig, CalculatorState, CalculatorType,
|
|
7
|
+
export type { CalculationHistoryEntry, Calculator, CalculatorProvider, CalculatorProviderCapabilities, CalculatorProviderConfig, CalculatorProviderInit, CalculatorState, CalculatorType, } from "./provider-interface.js";
|
|
@@ -11,50 +11,41 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export type CalculatorType = "basic" | "scientific" | "graphing";
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Provider-level initialization: credentials and instrumentation.
|
|
15
|
+
*
|
|
16
|
+
* Distinct from `CalculatorProviderConfig`, which configures one calculator
|
|
17
|
+
* instance. A hosted calculator vendor needs a key, or a server endpoint that
|
|
18
|
+
* mints one — never both in production, since `apiKey` puts the key in the
|
|
19
|
+
* browser.
|
|
20
|
+
*
|
|
21
|
+
* Naming across adapters, so a host reading one knows where to look in the
|
|
22
|
+
* others: `<Vendor>CalculatorSettings` is the vendor option shape,
|
|
23
|
+
* `<Vendor>CalculatorProviderConfig` is `CalculatorProviderConfig` with
|
|
24
|
+
* `settings` narrowed to it, and `<Vendor>CalculatorProviderInit` appears only
|
|
25
|
+
* where the adapter narrows or extends this interface — Cortex and GeoGebra take
|
|
26
|
+
* no credential, Desmos takes this type whole and declares no alias for it.
|
|
16
27
|
*/
|
|
17
|
-
export interface
|
|
28
|
+
export interface CalculatorProviderInit {
|
|
29
|
+
/** Vendor API key. Development only — it reaches the browser. */
|
|
18
30
|
apiKey?: string;
|
|
31
|
+
/** Host endpoint that serves the vendor credential. Production. */
|
|
19
32
|
proxyEndpoint?: string;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
decimalToFraction?: boolean;
|
|
23
|
-
links?: boolean;
|
|
24
|
-
settingsMenu?: boolean;
|
|
25
|
-
expressions?: boolean;
|
|
26
|
-
zoomButtons?: boolean;
|
|
27
|
-
expressionsTopbar?: boolean;
|
|
28
|
-
notes?: boolean;
|
|
29
|
-
folders?: boolean;
|
|
30
|
-
images?: boolean;
|
|
31
|
-
qwertyKeyboard?: boolean;
|
|
32
|
-
restrictedFunctions?: boolean;
|
|
33
|
-
plotSingleVariableImplicitEquations?: boolean;
|
|
34
|
-
distributions?: boolean;
|
|
35
|
-
plotImplicits?: boolean;
|
|
36
|
-
plotInequalities?: boolean;
|
|
37
|
-
geometryComputationFunctions?: boolean;
|
|
38
|
-
sliders?: boolean;
|
|
39
|
-
tables?: boolean;
|
|
40
|
-
expressionsCollapsed?: boolean;
|
|
41
|
-
administerSecretFolders?: boolean;
|
|
42
|
-
lockViewport?: boolean;
|
|
43
|
-
functionDefinition?: boolean;
|
|
44
|
-
brailleExpressionDownload?: boolean;
|
|
45
|
-
keypad?: boolean;
|
|
46
|
-
graphpaper?: boolean;
|
|
47
|
-
additionalFunctions?: string[];
|
|
33
|
+
/** Instrumentation callback for library-load and auth events. */
|
|
34
|
+
onTelemetry?: (eventName: string, payload?: Record<string, unknown>) => void | Promise<void>;
|
|
48
35
|
}
|
|
49
36
|
/**
|
|
50
|
-
*
|
|
37
|
+
* Provider-neutral calculator configuration.
|
|
38
|
+
*
|
|
39
|
+
* Adapters own the shape and interpretation of `settings`; the generic
|
|
40
|
+
* calculator seam deliberately does not name an implementation. An adapter
|
|
41
|
+
* narrows `settings` in its own `<Vendor>CalculatorProviderConfig`, which is the
|
|
42
|
+
* only reason a caller ever gets vendor option names.
|
|
51
43
|
*/
|
|
52
44
|
export interface CalculatorProviderConfig {
|
|
53
|
-
settings?: Record<string,
|
|
45
|
+
settings?: Record<string, unknown>;
|
|
54
46
|
restrictedMode?: boolean;
|
|
55
47
|
locale?: string;
|
|
56
48
|
theme?: "light" | "dark" | "auto";
|
|
57
|
-
desmos?: DesmosCalculatorConfig;
|
|
58
49
|
}
|
|
59
50
|
/**
|
|
60
51
|
* Calculator provider capabilities
|
|
@@ -90,6 +81,14 @@ export interface CalculatorState {
|
|
|
90
81
|
*
|
|
91
82
|
* Providers are stateless factories that create calculator implementations.
|
|
92
83
|
* They describe capabilities and create configured instances.
|
|
84
|
+
*
|
|
85
|
+
* Not parameterized by its configuration type, matching `ITTSProvider` in
|
|
86
|
+
* `@pie-players/pie-tts`. An adapter extends `CalculatorProviderConfig` and
|
|
87
|
+
* narrows `createCalculator`'s argument in its own class signature — see
|
|
88
|
+
* `DesmosCalculatorProviderConfig` in `@pie-players/pie-calculator-desmos` —
|
|
89
|
+
* which is what gives a caller holding the concrete provider the precise type.
|
|
90
|
+
* A type parameter here would add one, since a provider narrowing that argument
|
|
91
|
+
* satisfies this interface either way.
|
|
93
92
|
*/
|
|
94
93
|
export interface CalculatorProvider {
|
|
95
94
|
/**
|
|
@@ -109,9 +108,9 @@ export interface CalculatorProvider {
|
|
|
109
108
|
*/
|
|
110
109
|
readonly version: string;
|
|
111
110
|
/**
|
|
112
|
-
* Initialize the provider
|
|
111
|
+
* Initialize the provider: load the vendor library and authenticate.
|
|
113
112
|
*/
|
|
114
|
-
initialize(): Promise<void>;
|
|
113
|
+
initialize(config?: CalculatorProviderInit): Promise<void>;
|
|
115
114
|
/**
|
|
116
115
|
* Create a calculator instance
|
|
117
116
|
*/
|