@pie-qti/player-elements 0.1.23 → 0.1.25
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/ItemToolBar-d36g3aw4-B6TGPyKt.js +3079 -0
- package/dist/ItemToolBar-d36g3aw4-B6TGPyKt.js.map +1 -0
- package/dist/ar-SA-BDmOol_3.js +854 -0
- package/dist/ar-SA-BDmOol_3.js.map +1 -0
- package/dist/{define-CqE08oOW.js → define-D80uAEx4.js} +2891 -4399
- package/dist/define-D80uAEx4.js.map +1 -0
- package/dist/dist-BSG0NOza.js +229 -0
- package/dist/dist-BSG0NOza.js.map +1 -0
- package/dist/{dist-CsEP48m1.js → dist-C8BDh5vZ.js} +1129 -760
- package/dist/dist-C8BDh5vZ.js.map +1 -0
- package/dist/dist-CQel8-vi.js +2507 -0
- package/dist/dist-CQel8-vi.js.map +1 -0
- package/dist/{dist-DQ_jFQFX.js → dist-L-bDDBry.js} +231 -147
- package/dist/dist-L-bDDBry.js.map +1 -0
- package/dist/{element-DU-n15ch.js → element-C5rTAwch.js} +2 -2
- package/dist/{element-DU-n15ch.js.map → element-C5rTAwch.js.map} +1 -1
- package/dist/{element-class-DBV-1lkb-BeszDwN_.js → element-class-B_qAd8ET-DGj15cBY.js} +4404 -3503
- package/dist/element-class-B_qAd8ET-DGj15cBY.js.map +1 -0
- package/dist/elements/BaseSvelteMountElement.d.ts +1 -0
- package/dist/elements/QtiAssessmentPlayerElement.d.ts +1 -0
- package/dist/elements.js +3 -3
- package/dist/es-ES-C98YtDtb.js +802 -0
- package/dist/es-ES-C98YtDtb.js.map +1 -0
- package/dist/fr-FR-CrmmiRPf.js +802 -0
- package/dist/fr-FR-CrmmiRPf.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/item-toolbar-element-BgqPFwsS.js +1990 -0
- package/dist/item-toolbar-element-BgqPFwsS.js.map +1 -0
- package/dist/{types-BFOGFD4R.js → language-tags-BwFWXo71.js} +24 -3
- package/dist/language-tags-BwFWXo71.js.map +1 -0
- package/dist/nl-NL-BRA_1Wcl.js +507 -0
- package/dist/nl-NL-BRA_1Wcl.js.map +1 -0
- package/dist/nl-NL-CAR7pgVz.js +802 -0
- package/dist/nl-NL-CAR7pgVz.js.map +1 -0
- package/dist/pie-DwmznDHb.js +363 -0
- package/dist/pie-DwmznDHb.js.map +1 -0
- package/dist/pie-assessment-toolkit-Cruxm385.js +5 -0
- package/dist/pie-assessment-toolkit-Cruxm385.js.map +1 -0
- package/dist/pie-assessment-toolkit-DJfg6laX.js +5 -0
- package/dist/pie-assessment-toolkit-DJfg6laX.js.map +1 -0
- package/dist/{pie-assessment-toolkit-element-BGOTMhdG.js → pie-assessment-toolkit-element-CT5UuvVY.js} +1679 -1245
- package/dist/pie-assessment-toolkit-element-CT5UuvVY.js.map +1 -0
- package/dist/pie-tool-calculator-Crfk-IZe.js +378 -0
- package/dist/pie-tool-calculator-Crfk-IZe.js.map +1 -0
- package/dist/{root-Dqg3cyBt.js → provider-gBXlGb0d.js} +4 -44
- package/dist/provider-gBXlGb0d.js.map +1 -0
- package/dist/register-players.js +1 -1
- package/dist/register.js +10603 -10162
- package/dist/register.js.map +1 -1
- package/dist/{resolveItems-DhQQhD2k.js → resolveItems-CNMvD8LP.js} +2 -2
- package/dist/{resolveItems-DhQQhD2k.js.map → resolveItems-CNMvD8LP.js.map} +1 -1
- package/dist/ro-RO-DTZbhL0e.js +802 -0
- package/dist/ro-RO-DTZbhL0e.js.map +1 -0
- package/dist/root-dCY6j_Hh.js +47 -0
- package/dist/root-dCY6j_Hh.js.map +1 -0
- package/dist/tag-names-DZGvnAgd.js +2495 -0
- package/dist/tag-names-DZGvnAgd.js.map +1 -0
- package/dist/th-TH-aqlT_oK3.js +802 -0
- package/dist/th-TH-aqlT_oK3.js.map +1 -0
- package/dist/tool-tts-inline-k3hLJUfp.js +4447 -0
- package/dist/tool-tts-inline-k3hLJUfp.js.map +1 -0
- package/dist/zh-CN-DCqaRRhU.js +802 -0
- package/dist/zh-CN-DCqaRRhU.js.map +1 -0
- package/package.json +8 -8
- package/dist/define-CqE08oOW.js.map +0 -1
- package/dist/dist-B1Rc9Jhz.js +0 -220
- package/dist/dist-B1Rc9Jhz.js.map +0 -1
- package/dist/dist-CQEJemjs.js +0 -5061
- package/dist/dist-CQEJemjs.js.map +0 -1
- package/dist/dist-CsEP48m1.js.map +0 -1
- package/dist/dist-DQ_jFQFX.js.map +0 -1
- package/dist/element-class-DBV-1lkb-BeszDwN_.js.map +0 -1
- package/dist/item-toolbar-element-iE73NEkH.js +0 -1922
- package/dist/item-toolbar-element-iE73NEkH.js.map +0 -1
- package/dist/pie-assessment-toolkit-element-BGOTMhdG.js.map +0 -1
- package/dist/pie-tool-calculator-CkQb5qxg.js +0 -2243
- package/dist/pie-tool-calculator-CkQb5qxg.js.map +0 -1
- package/dist/root-Dqg3cyBt.js.map +0 -1
- package/dist/tool-tts-inline-CA3VjWU4.js +0 -3670
- package/dist/tool-tts-inline-CA3VjWU4.js.map +0 -1
- package/dist/types-BFOGFD4R.js.map +0 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
//#region ../../node_modules/.bun/@pie-players+pie-calculator-desmos@0.3.73/node_modules/@pie-players/pie-calculator-desmos/dist/desmos-provider.js
|
|
2
|
+
var e = class {
|
|
3
|
+
providerId = "desmos";
|
|
4
|
+
providerName = "Desmos";
|
|
5
|
+
supportedTypes = [
|
|
6
|
+
"basic",
|
|
7
|
+
"scientific",
|
|
8
|
+
"graphing"
|
|
9
|
+
];
|
|
10
|
+
version = "1.12";
|
|
11
|
+
initialized = !1;
|
|
12
|
+
apiKey;
|
|
13
|
+
instances = /* @__PURE__ */ new Set();
|
|
14
|
+
onTelemetry;
|
|
15
|
+
async emitTelemetry(e, t) {
|
|
16
|
+
try {
|
|
17
|
+
await this.onTelemetry?.(e, t);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.warn("[DesmosProvider] telemetry callback failed:", e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async loadDesmosScript(e) {
|
|
23
|
+
return new Promise((t, n) => {
|
|
24
|
+
let r = document.createElement("script"), i = new URL("https://www.desmos.com/api/v1.12/calculator.js");
|
|
25
|
+
e && i.searchParams.set("apiKey", e), r.src = i.toString(), r.async = !0, r.onload = () => {
|
|
26
|
+
window.Desmos ? t() : n(/* @__PURE__ */ Error("Desmos API loaded but window.Desmos is undefined"));
|
|
27
|
+
}, r.onerror = () => {
|
|
28
|
+
n(/* @__PURE__ */ Error("Failed to load Desmos API from CDN"));
|
|
29
|
+
}, document.head.appendChild(r);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async initialize(e = {}) {
|
|
33
|
+
if (this.initialized) return;
|
|
34
|
+
if (this.onTelemetry = e?.onTelemetry, typeof window > "u") throw Error("Desmos calculators can only be initialized in the browser");
|
|
35
|
+
this.apiKey = e.apiKey?.trim() || void 0;
|
|
36
|
+
let t = e.proxyEndpoint?.trim();
|
|
37
|
+
if (t) {
|
|
38
|
+
let e = Date.now();
|
|
39
|
+
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
40
|
+
toolId: "calculator",
|
|
41
|
+
backend: "desmos",
|
|
42
|
+
operation: "proxy-auth-fetch"
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
let n = await fetch(t);
|
|
46
|
+
if (!n.ok) throw Error(`Runtime endpoint returned ${n.status}`);
|
|
47
|
+
let r = await n.json();
|
|
48
|
+
if (typeof r.apiKey != "string" || !r.apiKey.trim()) throw Error("Runtime endpoint did not return a non-empty apiKey");
|
|
49
|
+
this.apiKey = r.apiKey.trim(), await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
50
|
+
toolId: "calculator",
|
|
51
|
+
backend: "desmos",
|
|
52
|
+
operation: "proxy-auth-fetch",
|
|
53
|
+
duration: Date.now() - e
|
|
54
|
+
});
|
|
55
|
+
} catch (t) {
|
|
56
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
57
|
+
toolId: "calculator",
|
|
58
|
+
backend: "desmos",
|
|
59
|
+
operation: "proxy-auth-fetch",
|
|
60
|
+
duration: Date.now() - e,
|
|
61
|
+
errorType: "CalculatorProxyAuthError",
|
|
62
|
+
message: t instanceof Error ? t.message : String(t)
|
|
63
|
+
}), Error(`[DesmosProvider] Failed to fetch API key from runtime endpoint: ${t instanceof Error ? t.message : String(t)}`, { cause: t });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!window.Desmos) {
|
|
67
|
+
this.apiKey || console.warn("[DesmosProvider] Loading the legacy unkeyed Desmos URL for compatibility. Configure an application API key for licensed deployments.");
|
|
68
|
+
let e = Date.now();
|
|
69
|
+
await this.emitTelemetry("pie-tool-library-load-start", {
|
|
70
|
+
toolId: "calculator",
|
|
71
|
+
backend: "desmos",
|
|
72
|
+
operation: "desmos-script-load"
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
await this.loadDesmosScript(this.apiKey), await this.emitTelemetry("pie-tool-library-load-success", {
|
|
76
|
+
toolId: "calculator",
|
|
77
|
+
backend: "desmos",
|
|
78
|
+
operation: "desmos-script-load",
|
|
79
|
+
duration: Date.now() - e
|
|
80
|
+
});
|
|
81
|
+
} catch (t) {
|
|
82
|
+
throw await this.emitTelemetry("pie-tool-library-load-error", {
|
|
83
|
+
toolId: "calculator",
|
|
84
|
+
backend: "desmos",
|
|
85
|
+
operation: "desmos-script-load",
|
|
86
|
+
duration: Date.now() - e,
|
|
87
|
+
errorType: "ToolLibraryLoadError",
|
|
88
|
+
message: t instanceof Error ? t.message : String(t)
|
|
89
|
+
}), t;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
this.initialized = !0;
|
|
93
|
+
}
|
|
94
|
+
async createCalculator(e, t, n) {
|
|
95
|
+
if (this.initialized || await this.initialize(), !this.supportsType(e)) throw Error(`Desmos does not support calculator type: ${e}`);
|
|
96
|
+
let i = new r(this, e, t, n, () => this.instances.delete(i));
|
|
97
|
+
return this.instances.add(i), i;
|
|
98
|
+
}
|
|
99
|
+
supportsType(e) {
|
|
100
|
+
return this.supportedTypes.includes(e);
|
|
101
|
+
}
|
|
102
|
+
destroy() {
|
|
103
|
+
for (let e of [...this.instances]) e.destroy();
|
|
104
|
+
this.instances.clear(), this.initialized = !1, this.apiKey = void 0, this.onTelemetry = void 0;
|
|
105
|
+
}
|
|
106
|
+
getCapabilities() {
|
|
107
|
+
return {
|
|
108
|
+
supportsHistory: !1,
|
|
109
|
+
supportsGraphing: !0,
|
|
110
|
+
supportsExpressions: !0,
|
|
111
|
+
canExport: !0,
|
|
112
|
+
maxPrecision: 15,
|
|
113
|
+
inputMethods: [
|
|
114
|
+
"keyboard",
|
|
115
|
+
"mouse",
|
|
116
|
+
"touch"
|
|
117
|
+
]
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}, t = ["apiKey", "proxyEndpoint"];
|
|
121
|
+
function n(e) {
|
|
122
|
+
for (let n of t) delete e[n];
|
|
123
|
+
}
|
|
124
|
+
var r = class {
|
|
125
|
+
onDestroy;
|
|
126
|
+
provider;
|
|
127
|
+
type;
|
|
128
|
+
Desmos;
|
|
129
|
+
calculator;
|
|
130
|
+
container;
|
|
131
|
+
destroyed = !1;
|
|
132
|
+
constructor(e, t, n, r, i) {
|
|
133
|
+
if (this.onDestroy = i, this.provider = e, this.type = t, this.container = n, this.Desmos = window.Desmos, !this.Desmos) throw Error("Desmos API not available");
|
|
134
|
+
this._initializeCalculator(r);
|
|
135
|
+
}
|
|
136
|
+
_initializeCalculator(e) {
|
|
137
|
+
let t = this.type === "graphing", r = {
|
|
138
|
+
degreeMode: !0,
|
|
139
|
+
settingsMenu: t,
|
|
140
|
+
qwertyKeyboard: !1,
|
|
141
|
+
notes: t,
|
|
142
|
+
folders: t,
|
|
143
|
+
sliders: t,
|
|
144
|
+
tables: t,
|
|
145
|
+
...e?.settings || {}
|
|
146
|
+
};
|
|
147
|
+
switch (n(r), e?.restrictedMode && Object.assign(r, {
|
|
148
|
+
expressionsTopbar: !1,
|
|
149
|
+
settingsMenu: !1,
|
|
150
|
+
zoomButtons: !1,
|
|
151
|
+
links: !1
|
|
152
|
+
}), this.type) {
|
|
153
|
+
case "graphing":
|
|
154
|
+
this.calculator = this.Desmos.GraphingCalculator(this.container, r);
|
|
155
|
+
break;
|
|
156
|
+
case "scientific":
|
|
157
|
+
this.calculator = this.Desmos.ScientificCalculator(this.container, r);
|
|
158
|
+
break;
|
|
159
|
+
case "basic":
|
|
160
|
+
this.calculator = this.Desmos.FourFunctionCalculator(this.container, r);
|
|
161
|
+
break;
|
|
162
|
+
default: throw Error(`Unsupported calculator type: ${this.type}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
getValue() {
|
|
166
|
+
if (this.type === "graphing" && this.calculator.getState) {
|
|
167
|
+
let e = this.calculator.getState();
|
|
168
|
+
return JSON.stringify(e);
|
|
169
|
+
}
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
setValue(e) {
|
|
173
|
+
if (this.type === "graphing" && this.calculator.setState) try {
|
|
174
|
+
let t = JSON.parse(e);
|
|
175
|
+
this.calculator.setState(t);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
console.error("[DesmosCalculator] Failed to set state:", e);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
clear() {
|
|
181
|
+
this.calculator.setBlank && this.calculator.setBlank();
|
|
182
|
+
}
|
|
183
|
+
async evaluate(e) {
|
|
184
|
+
return this.type === "graphing" ? new Promise((t) => {
|
|
185
|
+
let n = `eval_${Date.now()}`;
|
|
186
|
+
this.calculator.setExpression({
|
|
187
|
+
id: n,
|
|
188
|
+
latex: e
|
|
189
|
+
}), setTimeout(() => {
|
|
190
|
+
let r = this.calculator.HelperExpression({ latex: e }).numericValue || e;
|
|
191
|
+
this.calculator.removeExpression({ id: n }), t(String(r));
|
|
192
|
+
}, 100);
|
|
193
|
+
}) : e;
|
|
194
|
+
}
|
|
195
|
+
resize() {
|
|
196
|
+
this.calculator.resize && this.calculator.resize();
|
|
197
|
+
}
|
|
198
|
+
focus() {
|
|
199
|
+
try {
|
|
200
|
+
if (this.type === "graphing" && typeof this.calculator?.focusFirstExpression == "function") {
|
|
201
|
+
this.calculator.focusFirstExpression();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.container.querySelector(".dcg-mq-editable-field[tabindex=\"0\"], textarea, [contenteditable=\"true\"], [tabindex]:not([tabindex=\"-1\"])")?.focus();
|
|
205
|
+
} catch (e) {
|
|
206
|
+
console.warn("[DesmosCalculator] focus() failed:", e);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
exportState() {
|
|
210
|
+
let e = {};
|
|
211
|
+
return this.type === "graphing" && this.calculator.getState && (e = this.calculator.getState()), {
|
|
212
|
+
type: this.type,
|
|
213
|
+
provider: "desmos",
|
|
214
|
+
value: this.getValue(),
|
|
215
|
+
providerState: e
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
importState(e) {
|
|
219
|
+
if (e.provider !== "desmos") throw Error(`Cannot import state from provider: ${e.provider}`);
|
|
220
|
+
e.providerState && this.calculator.setState ? this.calculator.setState(e.providerState) : e.value && this.setValue(e.value);
|
|
221
|
+
}
|
|
222
|
+
destroy() {
|
|
223
|
+
this.destroyed || (this.destroyed = !0, this.calculator && this.calculator.destroy && this.calculator.destroy(), this.container.replaceChildren(), this.onDestroy());
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
//#endregion
|
|
227
|
+
export { e as DesmosCalculatorProvider };
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=dist-BSG0NOza.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dist-BSG0NOza.js","names":[],"sources":["../../../node_modules/.bun/@pie-players+pie-calculator-desmos@0.3.73/node_modules/@pie-players/pie-calculator-desmos/dist/desmos-provider.js"],"sourcesContent":["/**\n * Desmos Calculator Provider\n * Implementation of CalculatorProvider for Desmos calculators\n *\n * Supports: Basic, Scientific, and Graphing calculators\n * Based on Desmos API v1.12+\n * Requires: A Desmos API key when this provider loads the API from desmos.com\n *\n * Desmos's documented browser integration places the key in the calculator.js\n * URL. A runtime credential endpoint can keep the key out of source and static\n * bundles, but cannot keep it secret from a browser that loads the API.\n */\n/**\n * Desmos Calculator Provider Implementation\n */\nexport class DesmosCalculatorProvider {\n providerId = \"desmos\";\n providerName = \"Desmos\";\n supportedTypes = [\n \"basic\",\n \"scientific\",\n \"graphing\",\n ];\n version = \"1.12\";\n initialized = false;\n apiKey;\n /*\n * Every calculator this provider handed out and that has not destroyed itself.\n *\n * `destroy()` is a host's one call to release the provider, and without this it\n * released only the provider's own fields: every calculator it created stayed\n * mounted, with its vendor instance alive and its container populated. A host\n * that swaps providers, or tears a section down without walking its calculators\n * first, leaked all of them.\n */\n instances = new Set();\n onTelemetry;\n async emitTelemetry(eventName, payload) {\n try {\n await this.onTelemetry?.(eventName, payload);\n }\n catch (error) {\n console.warn(\"[DesmosProvider] telemetry callback failed:\", error);\n }\n }\n /**\n * Dynamically load the Desmos calculator library\n * @private\n */\n async loadDesmosScript(apiKey) {\n return new Promise((resolve, reject) => {\n const script = document.createElement(\"script\");\n const scriptUrl = new URL(\"https://www.desmos.com/api/v1.12/calculator.js\");\n if (apiKey)\n scriptUrl.searchParams.set(\"apiKey\", apiKey);\n script.src = scriptUrl.toString();\n script.async = true;\n script.onload = () => {\n if (window.Desmos) {\n resolve();\n }\n else {\n reject(new Error(\"Desmos API loaded but window.Desmos is undefined\"));\n }\n };\n script.onerror = () => {\n reject(new Error(\"Failed to load Desmos API from CDN\"));\n };\n document.head.appendChild(script);\n });\n }\n /** Initialize Desmos with provider-level credentials and instrumentation. */\n async initialize(config = {}) {\n if (this.initialized)\n return;\n this.onTelemetry = config?.onTelemetry;\n // SSR guard\n if (typeof window === \"undefined\") {\n throw new Error(\"Desmos calculators can only be initialized in the browser\");\n }\n this.apiKey = config.apiKey?.trim() || undefined;\n const proxyEndpoint = config.proxyEndpoint?.trim();\n if (proxyEndpoint) {\n const authStartedAt = Date.now();\n await this.emitTelemetry(\"pie-tool-backend-call-start\", {\n toolId: \"calculator\",\n backend: \"desmos\",\n operation: \"proxy-auth-fetch\",\n });\n try {\n const response = await fetch(proxyEndpoint);\n if (!response.ok) {\n throw new Error(`Runtime endpoint returned ${response.status}`);\n }\n const body = (await response.json());\n if (typeof body.apiKey !== \"string\" || !body.apiKey.trim()) {\n throw new Error(\"Runtime endpoint did not return a non-empty apiKey\");\n }\n this.apiKey = body.apiKey.trim();\n await this.emitTelemetry(\"pie-tool-backend-call-success\", {\n toolId: \"calculator\",\n backend: \"desmos\",\n operation: \"proxy-auth-fetch\",\n duration: Date.now() - authStartedAt,\n });\n }\n catch (error) {\n await this.emitTelemetry(\"pie-tool-backend-call-error\", {\n toolId: \"calculator\",\n backend: \"desmos\",\n operation: \"proxy-auth-fetch\",\n duration: Date.now() - authStartedAt,\n errorType: \"CalculatorProxyAuthError\",\n message: error instanceof Error ? error.message : String(error),\n });\n throw new Error(`[DesmosProvider] Failed to fetch API key from runtime endpoint: ${error instanceof Error ? error.message : String(error)}`, { cause: error });\n }\n }\n // Load Desmos API if not already loaded\n if (!window.Desmos) {\n if (!this.apiKey) {\n console.warn(\"[DesmosProvider] Loading the legacy unkeyed Desmos URL for compatibility. Configure an application API key for licensed deployments.\");\n }\n const libraryLoadStartedAt = Date.now();\n await this.emitTelemetry(\"pie-tool-library-load-start\", {\n toolId: \"calculator\",\n backend: \"desmos\",\n operation: \"desmos-script-load\",\n });\n try {\n await this.loadDesmosScript(this.apiKey);\n await this.emitTelemetry(\"pie-tool-library-load-success\", {\n toolId: \"calculator\",\n backend: \"desmos\",\n operation: \"desmos-script-load\",\n duration: Date.now() - libraryLoadStartedAt,\n });\n }\n catch (error) {\n await this.emitTelemetry(\"pie-tool-library-load-error\", {\n toolId: \"calculator\",\n backend: \"desmos\",\n operation: \"desmos-script-load\",\n duration: Date.now() - libraryLoadStartedAt,\n errorType: \"ToolLibraryLoadError\",\n message: error instanceof Error ? error.message : String(error),\n });\n throw error;\n }\n }\n this.initialized = true;\n }\n /**\n * Create a calculator instance\n */\n async createCalculator(type, container, config) {\n if (!this.initialized) {\n await this.initialize();\n }\n if (!this.supportsType(type)) {\n throw new Error(`Desmos does not support calculator type: ${type}`);\n }\n const calculator = new DesmosCalculator(this, type, container, config, () => this.instances.delete(calculator));\n this.instances.add(calculator);\n return calculator;\n }\n /**\n * Check if type is supported\n */\n supportsType(type) {\n return this.supportedTypes.includes(type);\n }\n /**\n * Cleanup\n */\n destroy() {\n // A copy: each `destroy()` calls back to remove itself from the set.\n for (const instance of [...this.instances])\n instance.destroy();\n this.instances.clear();\n this.initialized = false;\n this.apiKey = undefined;\n this.onTelemetry = undefined;\n }\n /**\n * Get provider capabilities\n */\n getCapabilities() {\n return {\n supportsHistory: false, // Desmos doesn't expose history API\n supportsGraphing: true,\n supportsExpressions: true,\n canExport: true,\n maxPrecision: 15,\n inputMethods: [\"keyboard\", \"mouse\", \"touch\"],\n };\n }\n}\n/**\n * Credentials are provider-level (`initialize()`), never per-instance options.\n *\n * `DesmosCalculatorSettings` carries an index signature, so `settings` still\n * *accepts* both names from a caller that has not moved them yet. Desmos treats\n * an unknown option as an error, and a key there reaches nothing that would use\n * it, so both are dropped before `settings` reaches the vendor constructor.\n */\nconst CREDENTIAL_KEYS = [\"apiKey\", \"proxyEndpoint\"];\nfunction stripCredentialKeys(config) {\n for (const key of CREDENTIAL_KEYS)\n delete config[key];\n}\n/**\n * Desmos Calculator Instance\n */\nclass DesmosCalculator {\n onDestroy;\n provider;\n type;\n Desmos;\n calculator;\n container;\n destroyed = false;\n constructor(provider, type, container, config, onDestroy) {\n this.onDestroy = onDestroy;\n this.provider = provider;\n this.type = type;\n this.container = container;\n this.Desmos = window.Desmos;\n if (!this.Desmos) {\n throw new Error(\"Desmos API not available\");\n }\n this._initializeCalculator(config);\n }\n _initializeCalculator(config) {\n const isGraphing = this.type === \"graphing\";\n const desmosConfig = {\n degreeMode: true,\n settingsMenu: isGraphing,\n qwertyKeyboard: false,\n notes: isGraphing,\n folders: isGraphing,\n sliders: isGraphing,\n tables: isGraphing,\n ...(config?.settings || {}),\n };\n stripCredentialKeys(desmosConfig);\n /*\n * Restricted mode is monotonic: it lands after the host's own `settings` and a\n * host cannot relax it, which is the same contract the Cortex adapter states\n * for its own flag. It suppresses chrome a learner has no use for mid-item and\n * routes out of the tool.\n *\n * `expressions: false` is deliberately not among them. It removes the whole\n * expression list, which on a `GraphingCalculator` is the only way to enter a\n * function, so a restricted graphing calculator was graph paper with nothing to\n * plot on it — the call this package's own README documents. Basic and\n * scientific never noticed: `expressions` is a graphing option their\n * constructors ignore. A host that does want the list gone passes\n * `settings: { expressions: false }` and sets the flags below itself, since\n * those are honoured whenever `restrictedMode` is not what overrides them.\n */\n if (config?.restrictedMode) {\n Object.assign(desmosConfig, {\n expressionsTopbar: false,\n settingsMenu: false,\n zoomButtons: false,\n links: false,\n });\n }\n // Create appropriate calculator type\n switch (this.type) {\n case \"graphing\":\n this.calculator = this.Desmos.GraphingCalculator(this.container, desmosConfig);\n break;\n case \"scientific\":\n this.calculator = this.Desmos.ScientificCalculator(this.container, desmosConfig);\n break;\n case \"basic\":\n this.calculator = this.Desmos.FourFunctionCalculator(this.container, desmosConfig);\n break;\n default:\n throw new Error(`Unsupported calculator type: ${this.type}`);\n }\n }\n getValue() {\n // For graphing calculator, get the state\n if (this.type === \"graphing\" && this.calculator.getState) {\n const state = this.calculator.getState();\n return JSON.stringify(state);\n }\n // For other calculators, return empty (Desmos doesn't expose value API)\n return \"\";\n }\n setValue(value) {\n // For graphing calculator, set the state\n if (this.type === \"graphing\" && this.calculator.setState) {\n try {\n const state = JSON.parse(value);\n this.calculator.setState(state);\n }\n catch (error) {\n console.error(\"[DesmosCalculator] Failed to set state:\", error);\n }\n }\n }\n clear() {\n if (this.calculator.setBlank) {\n this.calculator.setBlank();\n }\n }\n async evaluate(expression) {\n // Desmos doesn't provide a direct evaluate API\n // For graphing calculator, add expression and observe\n if (this.type === \"graphing\") {\n return new Promise((resolve) => {\n const id = `eval_${Date.now()}`;\n this.calculator.setExpression({ id, latex: expression });\n // Give Desmos time to process\n setTimeout(() => {\n const helperExpression = this.calculator.HelperExpression({\n latex: expression,\n });\n const result = helperExpression.numericValue || expression;\n this.calculator.removeExpression({ id });\n resolve(String(result));\n }, 100);\n });\n }\n return expression;\n }\n resize() {\n if (this.calculator.resize) {\n this.calculator.resize();\n }\n }\n focus() {\n try {\n if (this.type === \"graphing\" &&\n typeof this.calculator?.focusFirstExpression === \"function\") {\n this.calculator.focusFirstExpression();\n return;\n }\n const target = this.container.querySelector('.dcg-mq-editable-field[tabindex=\"0\"], textarea, [contenteditable=\"true\"], [tabindex]:not([tabindex=\"-1\"])');\n target?.focus();\n }\n catch (error) {\n console.warn(\"[DesmosCalculator] focus() failed:\", error);\n }\n }\n exportState() {\n let providerState = {};\n if (this.type === \"graphing\" && this.calculator.getState) {\n providerState = this.calculator.getState();\n }\n return {\n type: this.type,\n provider: \"desmos\",\n value: this.getValue(),\n providerState,\n };\n }\n importState(state) {\n if (state.provider !== \"desmos\") {\n throw new Error(`Cannot import state from provider: ${state.provider}`);\n }\n if (state.providerState && this.calculator.setState) {\n this.calculator.setState(state.providerState);\n }\n else if (state.value) {\n this.setValue(state.value);\n }\n }\n destroy() {\n if (this.destroyed)\n return;\n this.destroyed = true;\n if (this.calculator && this.calculator.destroy) {\n this.calculator.destroy();\n }\n this.container.replaceChildren();\n this.onDestroy();\n }\n}\n"],"x_google_ignoreList":[0],"mappings":";AAeA,IAAa,IAAb,MAAsC;CAClC,aAAa;CACb,eAAe;CACf,iBAAiB;EACb;EACA;EACA;CACJ;CACA,UAAU;CACV,cAAc;CACd;CAUA,4BAAY,IAAI,IAAI;CACpB;CACA,MAAM,cAAc,GAAW,GAAS;EACpC,IAAI;GACA,MAAM,KAAK,cAAc,GAAW,CAAO;EAC/C,SACO,GAAO;GAC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