@pie-players/pie-section-player 0.3.17 → 0.3.20
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 +76 -2
- package/dist/components/shared/player-action.d.ts +0 -2
- package/dist/components/shared/player-action.d.ts.map +1 -1
- package/dist/components/shared/player-preload.d.ts.map +1 -1
- package/dist/components/shared/section-player-runtime.d.ts +38 -7
- package/dist/components/shared/section-player-runtime.d.ts.map +1 -1
- package/dist/components/shared/section-player-view-state.d.ts.map +1 -1
- package/dist/contracts/layout-contract.d.ts +1 -1
- package/dist/contracts/layout-contract.d.ts.map +1 -1
- package/dist/contracts/layout-parity-metadata.d.ts.map +1 -1
- package/dist/controllers/SectionController.d.ts.map +1 -1
- package/dist/defineProperty-CyepwRr5-eHUSgEtz.js +33 -0
- package/dist/defineProperty-CyepwRr5.js +33 -0
- package/dist/dist-BCuSaTvi.js +393 -0
- package/dist/dist-BIgX-aC4-C5B4fLQK.js +389 -0
- package/dist/dist-DwP27yIs-gkxodgFn.js +201 -0
- package/dist/dist-S3IAfazl.js +201 -0
- package/dist/{index-BZq66Ke6-D8dZwpj4.js → module-COIydQYl-2o-TlgiW.js} +38152 -30086
- package/dist/pie-section-player.js +7438 -8680
- package/dist/player-preload-C_CjM5hv.js +6317 -0
- package/dist/tool-annotation-toolbar-BS_MjvXd.js +3974 -0
- package/dist/utils/player-preload.js +5 -5
- package/package.json +14 -14
- package/dist/index-CGqExkh0-DYpgzOOU.js +0 -338
- package/dist/index-CGqExkh0.js +0 -354
- package/dist/index-DF-Dk87f-lxErM8bo.js +0 -178
- package/dist/index-DF-Dk87f.js +0 -192
- package/dist/player-preload-Dxvgw3gW.js +0 -7023
- package/dist/tool-annotation-toolbar-BOoJpOXj.js +0 -4845
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { t as s } from "./defineProperty-CyepwRr5.js";
|
|
2
|
+
var n = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
s(this, "providerId", "desmos"), s(this, "providerName", "Desmos"), s(this, "supportedTypes", [
|
|
5
|
+
"basic",
|
|
6
|
+
"scientific",
|
|
7
|
+
"graphing"
|
|
8
|
+
]), s(this, "version", "1.10"), s(this, "initialized", !1), s(this, "apiKey", void 0), s(this, "proxyEndpoint", void 0), s(this, "isDevelopment", !1), s(this, "onTelemetry", void 0);
|
|
9
|
+
}
|
|
10
|
+
async emitTelemetry(e, o) {
|
|
11
|
+
try {
|
|
12
|
+
await this.onTelemetry?.(e, o);
|
|
13
|
+
} catch (t) {
|
|
14
|
+
console.warn("[DesmosProvider] telemetry callback failed:", t);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getApiKey() {
|
|
18
|
+
return this.apiKey;
|
|
19
|
+
}
|
|
20
|
+
async loadDesmosScript() {
|
|
21
|
+
return new Promise((e, o) => {
|
|
22
|
+
const t = document.createElement("script");
|
|
23
|
+
t.src = this.apiKey ? `https://www.desmos.com/api/v1.10/calculator.js?apiKey=${this.apiKey}` : "https://www.desmos.com/api/v1.10/calculator.js", t.async = !0, t.onload = () => {
|
|
24
|
+
window.Desmos ? (console.log("[DesmosProvider] Desmos API loaded successfully"), e()) : o(/* @__PURE__ */ new Error("Desmos API loaded but window.Desmos is undefined"));
|
|
25
|
+
}, t.onerror = () => {
|
|
26
|
+
o(/* @__PURE__ */ new Error("Failed to load Desmos API from CDN"));
|
|
27
|
+
}, document.head.appendChild(t);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async initialize(e) {
|
|
31
|
+
if (!this.initialized) {
|
|
32
|
+
if (this.onTelemetry = e?.onTelemetry, typeof window > "u") throw new Error("Desmos calculators can only be initialized in the browser");
|
|
33
|
+
if (this.isDevelopment = process.env.NODE_ENV === "development" || typeof process > "u" || !process.env.NODE_ENV, e?.proxyEndpoint) {
|
|
34
|
+
this.proxyEndpoint = e.proxyEndpoint;
|
|
35
|
+
const o = Date.now();
|
|
36
|
+
await this.emitTelemetry("pie-tool-backend-call-start", {
|
|
37
|
+
toolId: "calculator",
|
|
38
|
+
backend: "desmos",
|
|
39
|
+
operation: "proxy-auth-fetch"
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
const t = await fetch(e.proxyEndpoint);
|
|
43
|
+
if (!t.ok) throw new Error(`Proxy endpoint returned ${t.status}`);
|
|
44
|
+
this.apiKey = (await t.json()).apiKey, await this.emitTelemetry("pie-tool-backend-call-success", {
|
|
45
|
+
toolId: "calculator",
|
|
46
|
+
backend: "desmos",
|
|
47
|
+
operation: "proxy-auth-fetch",
|
|
48
|
+
duration: Date.now() - o
|
|
49
|
+
}), console.log("[DesmosProvider] Initialized with server-side proxy (SECURE)");
|
|
50
|
+
} catch (t) {
|
|
51
|
+
throw await this.emitTelemetry("pie-tool-backend-call-error", {
|
|
52
|
+
toolId: "calculator",
|
|
53
|
+
backend: "desmos",
|
|
54
|
+
operation: "proxy-auth-fetch",
|
|
55
|
+
duration: Date.now() - o,
|
|
56
|
+
errorType: "CalculatorProxyAuthError",
|
|
57
|
+
message: t instanceof Error ? t.message : String(t)
|
|
58
|
+
}), new Error(`[DesmosProvider] Failed to fetch API key from proxy: ${t}`);
|
|
59
|
+
}
|
|
60
|
+
} else e?.apiKey ? (this.apiKey = e.apiKey, this.isDevelopment ? console.log("[DesmosProvider] Initialized with direct API key (DEVELOPMENT MODE)") : console.error(`⚠️ [DesmosProvider] SECURITY WARNING: API key exposed in client-side code!
|
|
61
|
+
This is insecure for production. Use proxyEndpoint instead.
|
|
62
|
+
See: https://pie-players.dev/docs/calculator-desmos#security`)) : console.warn(`[DesmosProvider] No API key or proxy endpoint provided.
|
|
63
|
+
Production usage requires authentication. Obtain API key from https://www.desmos.com/api
|
|
64
|
+
Recommended: Use proxyEndpoint for production, apiKey for development only.`);
|
|
65
|
+
if (!window.Desmos) {
|
|
66
|
+
console.log("[DesmosProvider] Loading Desmos API library...");
|
|
67
|
+
const o = Date.now();
|
|
68
|
+
await this.emitTelemetry("pie-tool-library-load-start", {
|
|
69
|
+
toolId: "calculator",
|
|
70
|
+
backend: "desmos",
|
|
71
|
+
operation: "desmos-script-load"
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
await this.loadDesmosScript(), await this.emitTelemetry("pie-tool-library-load-success", {
|
|
75
|
+
toolId: "calculator",
|
|
76
|
+
backend: "desmos",
|
|
77
|
+
operation: "desmos-script-load",
|
|
78
|
+
duration: Date.now() - o
|
|
79
|
+
});
|
|
80
|
+
} catch (t) {
|
|
81
|
+
throw await this.emitTelemetry("pie-tool-library-load-error", {
|
|
82
|
+
toolId: "calculator",
|
|
83
|
+
backend: "desmos",
|
|
84
|
+
operation: "desmos-script-load",
|
|
85
|
+
duration: Date.now() - o,
|
|
86
|
+
errorType: "ToolLibraryLoadError",
|
|
87
|
+
message: t instanceof Error ? t.message : String(t)
|
|
88
|
+
}), t;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
this.initialized = !0;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async createCalculator(e, o, t) {
|
|
95
|
+
if (this.initialized || await this.initialize(), !this.supportsType(e)) throw new Error(`Desmos does not support calculator type: ${e}`);
|
|
96
|
+
return new a(this, e, o, t, this.apiKey);
|
|
97
|
+
}
|
|
98
|
+
supportsType(e) {
|
|
99
|
+
return this.supportedTypes.includes(e);
|
|
100
|
+
}
|
|
101
|
+
destroy() {
|
|
102
|
+
this.initialized = !1, this.onTelemetry = void 0;
|
|
103
|
+
}
|
|
104
|
+
getCapabilities() {
|
|
105
|
+
return {
|
|
106
|
+
supportsHistory: !1,
|
|
107
|
+
supportsGraphing: !0,
|
|
108
|
+
supportsExpressions: !0,
|
|
109
|
+
canExport: !0,
|
|
110
|
+
maxPrecision: 15,
|
|
111
|
+
inputMethods: [
|
|
112
|
+
"keyboard",
|
|
113
|
+
"mouse",
|
|
114
|
+
"touch"
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}, a = class {
|
|
119
|
+
constructor(e, o, t, r, i) {
|
|
120
|
+
if (s(this, "provider", void 0), s(this, "type", void 0), s(this, "Desmos", void 0), s(this, "calculator", void 0), s(this, "container", void 0), this.provider = e, this.type = o, this.container = t, this.Desmos = window.Desmos, !this.Desmos) throw new Error("Desmos API not available");
|
|
121
|
+
this._initializeCalculator(r, i);
|
|
122
|
+
}
|
|
123
|
+
_initializeCalculator(e, o) {
|
|
124
|
+
const t = {
|
|
125
|
+
...e?.desmos || {},
|
|
126
|
+
apiKey: o || e?.desmos?.apiKey
|
|
127
|
+
};
|
|
128
|
+
switch (e?.restrictedMode && Object.assign(t, {
|
|
129
|
+
expressionsTopbar: !1,
|
|
130
|
+
settingsMenu: !1,
|
|
131
|
+
zoomButtons: !1,
|
|
132
|
+
expressions: !1,
|
|
133
|
+
links: !1
|
|
134
|
+
}), this.type) {
|
|
135
|
+
case "graphing":
|
|
136
|
+
this.calculator = this.Desmos.GraphingCalculator(this.container, t);
|
|
137
|
+
break;
|
|
138
|
+
case "scientific":
|
|
139
|
+
this.calculator = this.Desmos.ScientificCalculator(this.container, t);
|
|
140
|
+
break;
|
|
141
|
+
case "basic":
|
|
142
|
+
this.calculator = this.Desmos.FourFunctionCalculator(this.container, t);
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
throw new Error(`Unsupported calculator type: ${this.type}`);
|
|
146
|
+
}
|
|
147
|
+
console.log(`[DesmosCalculator] Created ${this.type} calculator`);
|
|
148
|
+
}
|
|
149
|
+
getValue() {
|
|
150
|
+
if (this.type === "graphing" && this.calculator.getState) {
|
|
151
|
+
const e = this.calculator.getState();
|
|
152
|
+
return JSON.stringify(e);
|
|
153
|
+
}
|
|
154
|
+
return "";
|
|
155
|
+
}
|
|
156
|
+
setValue(e) {
|
|
157
|
+
if (this.type === "graphing" && this.calculator.setState) try {
|
|
158
|
+
const o = JSON.parse(e);
|
|
159
|
+
this.calculator.setState(o);
|
|
160
|
+
} catch (o) {
|
|
161
|
+
console.error("[DesmosCalculator] Failed to set state:", o);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
clear() {
|
|
165
|
+
this.calculator.setBlank && this.calculator.setBlank();
|
|
166
|
+
}
|
|
167
|
+
async evaluate(e) {
|
|
168
|
+
return this.type === "graphing" ? new Promise((o) => {
|
|
169
|
+
const t = `eval_${Date.now()}`;
|
|
170
|
+
this.calculator.setExpression({
|
|
171
|
+
id: t,
|
|
172
|
+
latex: e
|
|
173
|
+
}), setTimeout(() => {
|
|
174
|
+
const r = this.calculator.HelperExpression({ latex: e }).numericValue || e;
|
|
175
|
+
this.calculator.removeExpression({ id: t }), o(String(r));
|
|
176
|
+
}, 100);
|
|
177
|
+
}) : e;
|
|
178
|
+
}
|
|
179
|
+
resize() {
|
|
180
|
+
this.calculator.resize && this.calculator.resize();
|
|
181
|
+
}
|
|
182
|
+
exportState() {
|
|
183
|
+
let e = {};
|
|
184
|
+
return this.type === "graphing" && this.calculator.getState && (e = this.calculator.getState()), {
|
|
185
|
+
type: this.type,
|
|
186
|
+
provider: "desmos",
|
|
187
|
+
value: this.getValue(),
|
|
188
|
+
providerState: e
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
importState(e) {
|
|
192
|
+
if (e.provider !== "desmos") throw new Error(`Cannot import state from provider: ${e.provider}`);
|
|
193
|
+
e.providerState && this.calculator.setState ? this.calculator.setState(e.providerState) : e.value && this.setValue(e.value);
|
|
194
|
+
}
|
|
195
|
+
destroy() {
|
|
196
|
+
this.calculator && this.calculator.destroy && this.calculator.destroy(), this.container.replaceChildren(), console.log("[DesmosCalculator] destroyed");
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
export {
|
|
200
|
+
n as DesmosCalculatorProvider
|
|
201
|
+
};
|