@pie-players/pie-section-player 0.3.17 → 0.3.19

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.
@@ -1,20 +1,28 @@
1
1
  var l = Object.defineProperty;
2
- var n = (i, e, t) => e in i ? l(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var o = (i, e, t) => n(i, typeof e != "symbol" ? e + "" : e, t);
4
- class d {
2
+ var n = (s, e, o) => e in s ? l(s, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : s[e] = o;
3
+ var r = (s, e, o) => n(s, typeof e != "symbol" ? e + "" : e, o);
4
+ class p {
5
5
  constructor() {
6
- o(this, "providerId", "desmos");
7
- o(this, "providerName", "Desmos");
8
- o(this, "supportedTypes", [
6
+ r(this, "providerId", "desmos");
7
+ r(this, "providerName", "Desmos");
8
+ r(this, "supportedTypes", [
9
9
  "basic",
10
10
  "scientific",
11
11
  "graphing"
12
12
  ]);
13
- o(this, "version", "1.10");
14
- o(this, "initialized", !1);
15
- o(this, "apiKey");
16
- o(this, "proxyEndpoint");
17
- o(this, "isDevelopment", !1);
13
+ r(this, "version", "1.10");
14
+ r(this, "initialized", !1);
15
+ r(this, "apiKey");
16
+ r(this, "proxyEndpoint");
17
+ r(this, "isDevelopment", !1);
18
+ r(this, "onTelemetry");
19
+ }
20
+ async emitTelemetry(e, o) {
21
+ try {
22
+ await this.onTelemetry?.(e, o);
23
+ } catch (t) {
24
+ console.warn("[DesmosProvider] telemetry callback failed:", t);
25
+ }
18
26
  }
19
27
  /**
20
28
  * Get the configured API key
@@ -28,13 +36,13 @@ class d {
28
36
  * @private
29
37
  */
30
38
  async loadDesmosScript() {
31
- return new Promise((e, t) => {
32
- const s = document.createElement("script"), r = this.apiKey ? `https://www.desmos.com/api/v1.10/calculator.js?apiKey=${this.apiKey}` : "https://www.desmos.com/api/v1.10/calculator.js";
33
- s.src = r, s.async = !0, s.onload = () => {
34
- window.Desmos ? (console.log("[DesmosProvider] Desmos API loaded successfully"), e()) : t(new Error("Desmos API loaded but window.Desmos is undefined"));
35
- }, s.onerror = () => {
36
- t(new Error("Failed to load Desmos API from CDN"));
37
- }, document.head.appendChild(s);
39
+ return new Promise((e, o) => {
40
+ const t = document.createElement("script"), i = this.apiKey ? `https://www.desmos.com/api/v1.10/calculator.js?apiKey=${this.apiKey}` : "https://www.desmos.com/api/v1.10/calculator.js";
41
+ t.src = i, t.async = !0, t.onload = () => {
42
+ window.Desmos ? (console.log("[DesmosProvider] Desmos API loaded successfully"), e()) : o(new Error("Desmos API loaded but window.Desmos is undefined"));
43
+ }, t.onerror = () => {
44
+ o(new Error("Failed to load Desmos API from CDN"));
45
+ }, document.head.appendChild(t);
38
46
  });
39
47
  }
40
48
  /**
@@ -43,34 +51,78 @@ class d {
43
51
  */
44
52
  async initialize(e) {
45
53
  if (!this.initialized) {
46
- if (typeof window > "u")
54
+ if (this.onTelemetry = e?.onTelemetry, typeof window > "u")
47
55
  throw new Error("Desmos calculators can only be initialized in the browser");
48
56
  if (this.isDevelopment = process.env.NODE_ENV === "development" || typeof process > "u" || !process.env.NODE_ENV, e?.proxyEndpoint) {
49
57
  this.proxyEndpoint = e.proxyEndpoint;
58
+ const o = Date.now();
59
+ await this.emitTelemetry("pie-tool-backend-call-start", {
60
+ toolId: "calculator",
61
+ backend: "desmos",
62
+ operation: "proxy-auth-fetch"
63
+ });
50
64
  try {
51
65
  const t = await fetch(e.proxyEndpoint);
52
66
  if (!t.ok)
53
67
  throw new Error(`Proxy endpoint returned ${t.status}`);
54
- const s = await t.json();
55
- this.apiKey = s.apiKey, console.log("[DesmosProvider] Initialized with server-side proxy (SECURE)");
68
+ const i = await t.json();
69
+ this.apiKey = i.apiKey, await this.emitTelemetry("pie-tool-backend-call-success", {
70
+ toolId: "calculator",
71
+ backend: "desmos",
72
+ operation: "proxy-auth-fetch",
73
+ duration: Date.now() - o
74
+ }), console.log("[DesmosProvider] Initialized with server-side proxy (SECURE)");
56
75
  } catch (t) {
57
- throw new Error(`[DesmosProvider] Failed to fetch API key from proxy: ${t}`);
76
+ throw await this.emitTelemetry("pie-tool-backend-call-error", {
77
+ toolId: "calculator",
78
+ backend: "desmos",
79
+ operation: "proxy-auth-fetch",
80
+ duration: Date.now() - o,
81
+ errorType: "CalculatorProxyAuthError",
82
+ message: t instanceof Error ? t.message : String(t)
83
+ }), new Error(`[DesmosProvider] Failed to fetch API key from proxy: ${t}`);
58
84
  }
59
85
  } 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!
60
86
  This is insecure for production. Use proxyEndpoint instead.
61
87
  See: https://pie-players.dev/docs/calculator-desmos#security`)) : console.warn(`[DesmosProvider] No API key or proxy endpoint provided.
62
88
  Production usage requires authentication. Obtain API key from https://www.desmos.com/api
63
89
  Recommended: Use proxyEndpoint for production, apiKey for development only.`);
64
- window.Desmos || (console.log("[DesmosProvider] Loading Desmos API library..."), await this.loadDesmosScript()), this.initialized = !0;
90
+ if (!window.Desmos) {
91
+ console.log("[DesmosProvider] Loading Desmos API library...");
92
+ const o = Date.now();
93
+ await this.emitTelemetry("pie-tool-library-load-start", {
94
+ toolId: "calculator",
95
+ backend: "desmos",
96
+ operation: "desmos-script-load"
97
+ });
98
+ try {
99
+ await this.loadDesmosScript(), await this.emitTelemetry("pie-tool-library-load-success", {
100
+ toolId: "calculator",
101
+ backend: "desmos",
102
+ operation: "desmos-script-load",
103
+ duration: Date.now() - o
104
+ });
105
+ } catch (t) {
106
+ throw await this.emitTelemetry("pie-tool-library-load-error", {
107
+ toolId: "calculator",
108
+ backend: "desmos",
109
+ operation: "desmos-script-load",
110
+ duration: Date.now() - o,
111
+ errorType: "ToolLibraryLoadError",
112
+ message: t instanceof Error ? t.message : String(t)
113
+ }), t;
114
+ }
115
+ }
116
+ this.initialized = !0;
65
117
  }
66
118
  }
67
119
  /**
68
120
  * Create a calculator instance
69
121
  */
70
- async createCalculator(e, t, s) {
122
+ async createCalculator(e, o, t) {
71
123
  if (this.initialized || await this.initialize(), !this.supportsType(e))
72
124
  throw new Error(`Desmos does not support calculator type: ${e}`);
73
- return new c(this, e, t, s, this.apiKey);
125
+ return new c(this, e, o, t, this.apiKey);
74
126
  }
75
127
  /**
76
128
  * Check if type is supported
@@ -82,7 +134,7 @@ Recommended: Use proxyEndpoint for production, apiKey for development only.`);
82
134
  * Cleanup
83
135
  */
84
136
  destroy() {
85
- this.initialized = !1;
137
+ this.initialized = !1, this.onTelemetry = void 0;
86
138
  }
87
139
  /**
88
140
  * Get provider capabilities
@@ -100,22 +152,22 @@ Recommended: Use proxyEndpoint for production, apiKey for development only.`);
100
152
  }
101
153
  }
102
154
  class c {
103
- constructor(e, t, s, r, a) {
104
- o(this, "provider");
105
- o(this, "type");
106
- o(this, "Desmos");
107
- o(this, "calculator");
108
- o(this, "container");
109
- if (this.provider = e, this.type = t, this.container = s, this.Desmos = window.Desmos, !this.Desmos)
155
+ constructor(e, o, t, i, a) {
156
+ r(this, "provider");
157
+ r(this, "type");
158
+ r(this, "Desmos");
159
+ r(this, "calculator");
160
+ r(this, "container");
161
+ if (this.provider = e, this.type = o, this.container = t, this.Desmos = window.Desmos, !this.Desmos)
110
162
  throw new Error("Desmos API not available");
111
- this._initializeCalculator(r, a);
163
+ this._initializeCalculator(i, a);
112
164
  }
113
- _initializeCalculator(e, t) {
114
- const s = {
165
+ _initializeCalculator(e, o) {
166
+ const t = {
115
167
  ...e?.desmos || {},
116
- apiKey: t || e?.desmos?.apiKey
168
+ apiKey: o || e?.desmos?.apiKey
117
169
  };
118
- switch (e?.restrictedMode && Object.assign(s, {
170
+ switch (e?.restrictedMode && Object.assign(t, {
119
171
  expressionsTopbar: !1,
120
172
  settingsMenu: !1,
121
173
  zoomButtons: !1,
@@ -123,13 +175,13 @@ class c {
123
175
  links: !1
124
176
  }), this.type) {
125
177
  case "graphing":
126
- this.calculator = this.Desmos.GraphingCalculator(this.container, s);
178
+ this.calculator = this.Desmos.GraphingCalculator(this.container, t);
127
179
  break;
128
180
  case "scientific":
129
- this.calculator = this.Desmos.ScientificCalculator(this.container, s);
181
+ this.calculator = this.Desmos.ScientificCalculator(this.container, t);
130
182
  break;
131
183
  case "basic":
132
- this.calculator = this.Desmos.FourFunctionCalculator(this.container, s);
184
+ this.calculator = this.Desmos.FourFunctionCalculator(this.container, t);
133
185
  break;
134
186
  default:
135
187
  throw new Error(`Unsupported calculator type: ${this.type}`);
@@ -146,23 +198,23 @@ class c {
146
198
  setValue(e) {
147
199
  if (this.type === "graphing" && this.calculator.setState)
148
200
  try {
149
- const t = JSON.parse(e);
150
- this.calculator.setState(t);
151
- } catch (t) {
152
- console.error("[DesmosCalculator] Failed to set state:", t);
201
+ const o = JSON.parse(e);
202
+ this.calculator.setState(o);
203
+ } catch (o) {
204
+ console.error("[DesmosCalculator] Failed to set state:", o);
153
205
  }
154
206
  }
155
207
  clear() {
156
208
  this.calculator.setBlank && this.calculator.setBlank();
157
209
  }
158
210
  async evaluate(e) {
159
- return this.type === "graphing" ? new Promise((t) => {
160
- const s = `eval_${Date.now()}`;
161
- this.calculator.setExpression({ id: s, latex: e }), setTimeout(() => {
211
+ return this.type === "graphing" ? new Promise((o) => {
212
+ const t = `eval_${Date.now()}`;
213
+ this.calculator.setExpression({ id: t, latex: e }), setTimeout(() => {
162
214
  const a = this.calculator.HelperExpression({
163
215
  latex: e
164
216
  }).numericValue || e;
165
- this.calculator.removeExpression({ id: s }), t(String(a));
217
+ this.calculator.removeExpression({ id: t }), o(String(a));
166
218
  }, 100);
167
219
  }) : e;
168
220
  }
@@ -188,5 +240,5 @@ class c {
188
240
  }
189
241
  }
190
242
  export {
191
- d as DesmosCalculatorProvider
243
+ p as DesmosCalculatorProvider
192
244
  };