@pie-players/pie-calculator 0.1.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 ADDED
@@ -0,0 +1,142 @@
1
+ # @pie-players/pie-calculator
2
+
3
+ Calculator provider interfaces and types for PIE Assessment Toolkit - Pure TypeScript with no UI dependencies.
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
28
+ - **`TICalculatorConfig`** - TI calculator-specific configuration
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ npm install @pie-players/pie-calculator
34
+ # or
35
+ bun add @pie-players/pie-calculator
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### Implementing a Custom Calculator Provider
41
+
42
+ ```typescript
43
+ import type {
44
+ CalculatorProvider,
45
+ Calculator,
46
+ CalculatorType,
47
+ CalculatorProviderCapabilities,
48
+ CalculatorProviderConfig
49
+ } from '@pie-players/pie-calculator';
50
+
51
+ class MyCalculatorImpl implements Calculator {
52
+ readonly provider: CalculatorProvider;
53
+ readonly type: CalculatorType;
54
+
55
+ constructor(provider: CalculatorProvider, type: CalculatorType, container: HTMLElement) {
56
+ this.provider = provider;
57
+ this.type = type;
58
+ // Initialize calculator in container
59
+ }
60
+
61
+ getValue(): string { return '0'; }
62
+ setValue(value: string): void { /* ... */ }
63
+ clear(): void { /* ... */ }
64
+ exportState(): CalculatorState { /* ... */ }
65
+ importState(state: CalculatorState): void { /* ... */ }
66
+ destroy(): void { /* ... */ }
67
+ }
68
+
69
+ export class MyCalculatorProvider implements CalculatorProvider {
70
+ readonly providerId = 'my-calculator';
71
+ readonly providerName = 'My Calculator';
72
+ readonly supportedTypes: CalculatorType[] = ['basic', 'scientific'];
73
+ readonly version = '1.0.0';
74
+
75
+ async initialize(): Promise<void> {
76
+ // Load libraries, etc.
77
+ }
78
+
79
+ async createCalculator(
80
+ type: CalculatorType,
81
+ container: HTMLElement,
82
+ config?: CalculatorProviderConfig
83
+ ): Promise<Calculator> {
84
+ return new MyCalculatorImpl(this, type, container);
85
+ }
86
+
87
+ supportsType(type: CalculatorType): boolean {
88
+ return this.supportedTypes.includes(type);
89
+ }
90
+
91
+ getCapabilities(): CalculatorProviderCapabilities {
92
+ return {
93
+ supportsHistory: true,
94
+ supportsGraphing: false,
95
+ supportsExpressions: true,
96
+ canExport: true,
97
+ maxPrecision: 15,
98
+ inputMethods: ['keyboard', 'mouse', 'touch'],
99
+ };
100
+ }
101
+
102
+ destroy(): void {
103
+ // Cleanup
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Official Implementations
109
+
110
+ - **Math.js** (`@pie-players/pie-calculator-mathjs`) - Open-source, always available (built into toolkit)
111
+ - **Desmos** (`@pie-players/pie-calculator-desmos`) - Requires API key, graphing support
112
+ - **TI Emulators** (`@pie-players/pie-calculator-ti`) - Requires commercial license, TI-84/108/34
113
+
114
+ ## Calculator Types
115
+
116
+ Supported calculator types:
117
+
118
+ - `"basic"` - Four-function calculator (add, subtract, multiply, divide)
119
+ - `"scientific"` - Scientific calculator with trigonometry, logarithms, etc.
120
+ - `"graphing"` - Graphing calculator with coordinate plane
121
+ - `"ti-84"` - Texas Instruments TI-84 Plus CE
122
+ - `"ti-108"` - Texas Instruments TI-108
123
+ - `"ti-34-mv"` - Texas Instruments TI-34 MultiView
124
+
125
+ ## Design Philosophy
126
+
127
+ This core package intentionally:
128
+ - ✅ Has **zero runtime dependencies**
129
+ - ✅ Contains **only TypeScript interfaces and types**
130
+ - ✅ Is **framework-agnostic** (no React, Svelte, Vue, etc.)
131
+ - ✅ Supports **pluggable architecture**
132
+ - ✅ Enables **type-safe calculator implementations**
133
+
134
+ ## License
135
+
136
+ MIT
137
+
138
+ ## Related Packages
139
+
140
+ - [@pie-players/pie-calculator-mathjs](../calculator-mathjs) - Open-source Math.js provider (default)
141
+ - [@pie-players/pie-calculator-desmos](../calculator-desmos) - Desmos graphing calculator provider
142
+ - [@pie-players/pie-calculator-ti](../calculator-ti) - Texas Instruments emulator provider
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @pie-players/pie-calculator
3
+ *
4
+ * Calculator provider interfaces and types for PIE Assessment Toolkit.
5
+ * No UI dependencies - pure TypeScript interfaces.
6
+ */
7
+ export type { CalculationHistoryEntry, Calculator, CalculatorProvider, CalculatorProviderCapabilities, CalculatorProviderConfig, CalculatorState, CalculatorType, DesmosCalculatorConfig, TICalculatorConfig, } from "./provider-interface";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EACX,uBAAuB,EACvB,UAAU,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,kBAAkB,GAClB,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @pie-players/pie-calculator
3
+ *
4
+ * Calculator provider interfaces and types for PIE Assessment Toolkit.
5
+ * No UI dependencies - pure TypeScript interfaces.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Calculator Provider Interfaces
3
+ *
4
+ * Defines the contract for calculator providers.
5
+ * Providers are stateless factories that create configured calculator implementations.
6
+ *
7
+ * Part of PIE Calculator - No UI dependencies.
8
+ */
9
+ /**
10
+ * Calculator types
11
+ */
12
+ export type CalculatorType = "basic" | "scientific" | "graphing" | "ti-84" | "ti-108" | "ti-34-mv";
13
+ /**
14
+ * TI-specific calculator configuration options
15
+ */
16
+ export interface TICalculatorConfig {
17
+ restrictedMode?: boolean;
18
+ [key: string]: any;
19
+ }
20
+ /**
21
+ * Desmos-specific calculator configuration options
22
+ * Based on production implementation patterns and Desmos API documentation
23
+ */
24
+ export interface DesmosCalculatorConfig {
25
+ apiKey?: string;
26
+ proxyEndpoint?: string;
27
+ border?: boolean;
28
+ degreeMode?: boolean | "degree" | "radian";
29
+ decimalToFraction?: boolean;
30
+ links?: boolean;
31
+ settingsMenu?: boolean;
32
+ expressions?: boolean;
33
+ zoomButtons?: boolean;
34
+ expressionsTopbar?: boolean;
35
+ notes?: boolean;
36
+ folders?: boolean;
37
+ images?: boolean;
38
+ qwertyKeyboard?: boolean;
39
+ restrictedFunctions?: boolean;
40
+ plotSingleVariableImplicitEquations?: boolean;
41
+ distributions?: boolean;
42
+ plotImplicits?: boolean;
43
+ plotInequalities?: boolean;
44
+ geometryComputationFunctions?: boolean;
45
+ sliders?: boolean;
46
+ expressionsCollapsed?: boolean;
47
+ administerSecretFolders?: boolean;
48
+ lockViewport?: boolean;
49
+ functionDefinition?: boolean;
50
+ brailleExpressionDownload?: boolean;
51
+ keypad?: boolean;
52
+ graphpaper?: boolean;
53
+ additionalFunctions?: string[];
54
+ }
55
+ /**
56
+ * Calculator provider configuration
57
+ */
58
+ export interface CalculatorProviderConfig {
59
+ settings?: Record<string, any>;
60
+ restrictedMode?: boolean;
61
+ locale?: string;
62
+ theme?: "light" | "dark" | "auto";
63
+ desmos?: DesmosCalculatorConfig;
64
+ ti?: TICalculatorConfig;
65
+ }
66
+ /**
67
+ * Calculator provider capabilities
68
+ */
69
+ export interface CalculatorProviderCapabilities {
70
+ supportsHistory: boolean;
71
+ supportsGraphing: boolean;
72
+ supportsExpressions: boolean;
73
+ canExport: boolean;
74
+ maxPrecision?: number;
75
+ inputMethods: ("keyboard" | "mouse" | "touch")[];
76
+ }
77
+ /**
78
+ * Calculation history entry
79
+ */
80
+ export interface CalculationHistoryEntry {
81
+ expression: string;
82
+ result: string;
83
+ timestamp: number;
84
+ }
85
+ /**
86
+ * Calculator state for persistence
87
+ */
88
+ export interface CalculatorState {
89
+ type: CalculatorType;
90
+ provider: string;
91
+ value: string;
92
+ history?: CalculationHistoryEntry[];
93
+ providerState?: any;
94
+ }
95
+ /**
96
+ * Calculator Provider interface
97
+ *
98
+ * Providers are stateless factories that create calculator implementations.
99
+ * They describe capabilities and create configured instances.
100
+ */
101
+ export interface CalculatorProvider {
102
+ /**
103
+ * Unique identifier for this provider
104
+ */
105
+ readonly providerId: string;
106
+ /**
107
+ * Human-readable provider name
108
+ */
109
+ readonly providerName: string;
110
+ /**
111
+ * Supported calculator types
112
+ */
113
+ readonly supportedTypes: CalculatorType[];
114
+ /**
115
+ * Provider version
116
+ */
117
+ readonly version: string;
118
+ /**
119
+ * Initialize the provider (load libraries, etc.)
120
+ */
121
+ initialize(): Promise<void>;
122
+ /**
123
+ * Create a calculator instance
124
+ */
125
+ createCalculator(type: CalculatorType, container: HTMLElement, config?: CalculatorProviderConfig): Promise<Calculator>;
126
+ /**
127
+ * Check if a calculator type is supported
128
+ */
129
+ supportsType(type: CalculatorType): boolean;
130
+ /**
131
+ * Clean up provider resources
132
+ */
133
+ destroy(): void;
134
+ /**
135
+ * Get provider capabilities
136
+ */
137
+ getCapabilities(): CalculatorProviderCapabilities;
138
+ }
139
+ /**
140
+ * Calculator instance interface (provider-agnostic)
141
+ *
142
+ * The actual calculator implementation that handles calculations.
143
+ * Created by CalculatorProvider.createCalculator()
144
+ */
145
+ export interface Calculator {
146
+ /**
147
+ * The provider that created this calculator
148
+ */
149
+ readonly provider: CalculatorProvider;
150
+ /**
151
+ * The calculator type
152
+ */
153
+ readonly type: CalculatorType;
154
+ /**
155
+ * Get current value/result
156
+ */
157
+ getValue(): string;
158
+ /**
159
+ * Set value
160
+ */
161
+ setValue(value: string): void;
162
+ /**
163
+ * Clear calculator
164
+ */
165
+ clear(): void;
166
+ /**
167
+ * Get calculation history (if supported)
168
+ */
169
+ getHistory?(): CalculationHistoryEntry[];
170
+ /**
171
+ * Clear calculation history (if supported)
172
+ */
173
+ clearHistory?(): void;
174
+ /**
175
+ * Evaluate an expression (if supported)
176
+ */
177
+ evaluate?(expression: string): Promise<string>;
178
+ /**
179
+ * Resize calculator (when container size changes)
180
+ */
181
+ resize?(): void;
182
+ /**
183
+ * Export calculator state for persistence
184
+ */
185
+ exportState(): CalculatorState;
186
+ /**
187
+ * Import calculator state from persistence
188
+ */
189
+ importState(state: CalculatorState): void;
190
+ /**
191
+ * Destroy calculator and clean up resources
192
+ */
193
+ destroy(): void;
194
+ }
195
+ //# sourceMappingURL=provider-interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-interface.d.ts","sourceRoot":"","sources":["../src/provider-interface.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GACvB,OAAO,GACP,YAAY,GACZ,UAAU,GACV,OAAO,GACP,QAAQ,GACR,UAAU,CAAC;AAEd;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAElC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IAKtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,MAAM,CAAC,EAAE,OAAO,C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ACH,YAAY,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC;IAE5C;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;IAEhB;;OAEG;IACH,eAAe,IAAI,8BAA8B,CAAC;CAClD;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IAEtC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAE9B;;OAEG;IACH,QAAQ,IAAI,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;OAEG;IACH,UAAU,CAAC,IAAI,uBAAuB,EAAE,CAAC;IAEzC;;OAEG;IACH,YAAY,CAAC,IAAI,IAAI,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/C;;OAEG;IACH,MAAM,CAAC,IAAI,IAAI,CAAC;IAEhB;;OAEG;IACH,WAAW,IAAI,eAAe,CAAC;IAE/B;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAE1C;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CAChB"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Calculator Provider Interfaces
3
+ *
4
+ * Defines the contract for calculator providers.
5
+ * Providers are stateless factories that create configured calculator implementations.
6
+ *
7
+ * Part of PIE Calculator - No UI dependencies.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=provider-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-interface.js","sourceRoot":"","sources":["../src/provider-interface.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@pie-players/pie-calculator",
3
+ "version": "0.1.0",
4
+ "description": "Calculator provider interfaces and types for PIE Assessment Toolkit - No UI dependencies",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "typecheck": "tsc --noEmit"
21
+ },
22
+ "keywords": [
23
+ "pie",
24
+ "calculator",
25
+ "math",
26
+ "interfaces",
27
+ "accessibility"
28
+ ],
29
+ "author": "PIE Framework",
30
+ "license": "MIT",
31
+ "devDependencies": {
32
+ "typescript": "^5.7.2"
33
+ }
34
+ }