@ziztechnology/dial-library 0.0.5 → 0.0.7

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.
Files changed (2) hide show
  1. package/dist/index.mjs +1823 -292
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1,32 @@
1
1
  import { Gunzip } from "fflate";
2
+ //#region src/helper/debugger.ts
3
+ const stringifyDebugData = (data) => {
4
+ const seen = /* @__PURE__ */ new WeakSet();
5
+ return JSON.stringify(data, (_key, value) => {
6
+ if (value instanceof Error) return {
7
+ name: value.name,
8
+ message: value.message,
9
+ stack: value.stack
10
+ };
11
+ if (typeof value === "function") return `[Function ${value.name || "anonymous"}]`;
12
+ if (typeof value === "bigint") return value.toString();
13
+ if (typeof value === "object" && value !== null) {
14
+ if (seen.has(value)) return "[Circular]";
15
+ seen.add(value);
16
+ }
17
+ return value;
18
+ }) ?? String(data);
19
+ };
20
+ const dialSdkDebugWarn = (moduleName, scope, phase, data) => {
21
+ const message = `[DIAL_SDK_DEBUG - ${moduleName}] ${scope}: ${phase}`;
22
+ try {
23
+ if (data === void 0) console.warn(message);
24
+ else console.warn(message, stringifyDebugData(data));
25
+ } catch {}
26
+ };
27
+ //#endregion
2
28
  //#region src/sensor/check_status.ts
29
+ const DEBUG_MODULE$5 = "check_status.ts";
3
30
  const DEFAULT_DRIVING_STATUS_TUNING = Object.freeze({
4
31
  version: "driving-status-v1",
5
32
  maxSampleAgeMs: 1e3,
@@ -36,12 +63,23 @@ const DEFAULT_DRIVING_STATUS_TUNING = Object.freeze({
36
63
  })
37
64
  });
38
65
  const classifyDrivingSnapshot = (info, tuningOverrides) => {
66
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingSnapshot", "called", {
67
+ info,
68
+ tuningOverrides
69
+ });
39
70
  const tuning = resolveDrivingStatusTuning(tuningOverrides);
40
71
  const metrics = extractDrivingSnapshotMetrics(info, tuning);
41
- return metrics === null ? null : classifyDrivingMetrics(metrics, tuning);
72
+ const result = metrics === null ? null : classifyDrivingMetrics(metrics, tuning);
73
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingSnapshot", "returned", {
74
+ tuning,
75
+ metrics,
76
+ result
77
+ });
78
+ return result;
42
79
  };
43
80
  const checkRunningStatus = classifyDrivingSnapshot;
44
81
  const resolveDrivingStatusTuning = (overrides = {}) => {
82
+ dialSdkDebugWarn(DEBUG_MODULE$5, "resolveDrivingStatusTuning", "called", { overrides });
45
83
  const tuning = {
46
84
  ...DEFAULT_DRIVING_STATUS_TUNING,
47
85
  ...overrides,
@@ -70,19 +108,36 @@ const resolveDrivingStatusTuning = (overrides = {}) => {
70
108
  if (!Number.isFinite(tuning.hysteresisRatio) || tuning.hysteresisRatio <= 0 || tuning.hysteresisRatio >= 1) throw new RangeError("hysteresisRatio must be greater than 0 and less than 1");
71
109
  for (const [status, value] of Object.entries(tuning.confirmationSamples)) if (!Number.isInteger(value) || value < 1) throw new RangeError(`confirmationSamples.${status} must be a positive integer`);
72
110
  for (const [status, value] of Object.entries(tuning.minimumDisplayMs)) if (!Number.isFinite(value) || value < 0) throw new RangeError(`minimumDisplayMs.${status} must be a non-negative finite number`);
111
+ dialSdkDebugWarn(DEBUG_MODULE$5, "resolveDrivingStatusTuning", "returned", { tuning });
73
112
  return tuning;
74
113
  };
75
114
  const extractDrivingSnapshotMetrics = (info, tuning = DEFAULT_DRIVING_STATUS_TUNING) => {
76
- if (!info || !Number.isFinite(info.capturedAtMs)) return null;
115
+ dialSdkDebugWarn(DEBUG_MODULE$5, "extractDrivingSnapshotMetrics", "called", {
116
+ info,
117
+ tuning
118
+ });
119
+ if (!info || !Number.isFinite(info.capturedAtMs)) {
120
+ dialSdkDebugWarn(DEBUG_MODULE$5, "extractDrivingSnapshotMetrics", "returned invalid capture time", { info });
121
+ return null;
122
+ }
77
123
  const linearAcceleration = availableFreshVector(info.linearAcceleration, info.capturedAtMs, tuning.maxSampleAgeMs);
78
124
  const gyroscope = availableFreshVector(info.gyroscope, info.capturedAtMs, tuning.maxSampleAgeMs);
79
- if (linearAcceleration === null || gyroscope === null) return null;
125
+ if (linearAcceleration === null || gyroscope === null) {
126
+ dialSdkDebugWarn(DEBUG_MODULE$5, "extractDrivingSnapshotMetrics", "returned unavailable vectors", {
127
+ linearAcceleration,
128
+ gyroscope
129
+ });
130
+ return null;
131
+ }
80
132
  const longitudinal = -linearAcceleration.z;
81
133
  const lateral = linearAcceleration.x;
82
134
  const yaw = gyroscope.y;
83
135
  const motionIntensity = info.motionIntensity === void 0 ? vectorMagnitude(linearAcceleration) : availableFreshNumber(info.motionIntensity, info.capturedAtMs, tuning.maxSampleAgeMs);
84
- if (motionIntensity === null) return null;
85
- return {
136
+ if (motionIntensity === null) {
137
+ dialSdkDebugWarn(DEBUG_MODULE$5, "extractDrivingSnapshotMetrics", "returned unavailable motion intensity", { motionIntensity: info.motionIntensity });
138
+ return null;
139
+ }
140
+ const result = {
86
141
  capturedAtMs: info.capturedAtMs,
87
142
  longitudinal,
88
143
  lateral,
@@ -90,44 +145,144 @@ const extractDrivingSnapshotMetrics = (info, tuning = DEFAULT_DRIVING_STATUS_TUN
90
145
  motionIntensity,
91
146
  gyroMagnitude: vectorMagnitude(gyroscope)
92
147
  };
148
+ dialSdkDebugWarn(DEBUG_MODULE$5, "extractDrivingSnapshotMetrics", "returned", { result });
149
+ return result;
93
150
  };
94
151
  const classifyDrivingMetrics = (metrics, tuning = DEFAULT_DRIVING_STATUS_TUNING) => {
152
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "called", {
153
+ metrics,
154
+ tuning
155
+ });
95
156
  const { longitudinal, lateral, yaw, motionIntensity, gyroMagnitude } = metrics;
96
- if (longitudinal <= -tuning.rapidLongitudinalThreshold) return "SUDDEN_BRAKING";
97
- if (longitudinal >= tuning.rapidLongitudinalThreshold) return "RAPID_ACCELERATION";
98
- if (Math.abs(yaw) >= tuning.turnYawThreshold) return yaw > 0 ? "LEFT_TURN" : "RIGHT_TURN";
99
- if (Math.abs(lateral) >= tuning.turnLateralThreshold) return lateral < 0 ? "LEFT_TURN" : "RIGHT_TURN";
100
- if (longitudinal <= -tuning.longitudinalThreshold) return "BRAKING";
101
- if (longitudinal >= tuning.longitudinalThreshold) return "ACCELERATION";
102
- if (motionIntensity < tuning.drivingMotionThreshold && gyroMagnitude <= tuning.stoppedGyroThreshold) return "STOPPED";
157
+ if (longitudinal <= -tuning.rapidLongitudinalThreshold) {
158
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", { result: "SUDDEN_BRAKING" });
159
+ return "SUDDEN_BRAKING";
160
+ }
161
+ if (longitudinal >= tuning.rapidLongitudinalThreshold) {
162
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", { result: "RAPID_ACCELERATION" });
163
+ return "RAPID_ACCELERATION";
164
+ }
165
+ if (Math.abs(yaw) >= tuning.turnYawThreshold) {
166
+ const result = yaw > 0 ? "LEFT_TURN" : "RIGHT_TURN";
167
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", {
168
+ result,
169
+ basis: "yaw"
170
+ });
171
+ return result;
172
+ }
173
+ if (Math.abs(lateral) >= tuning.turnLateralThreshold) {
174
+ const result = lateral < 0 ? "LEFT_TURN" : "RIGHT_TURN";
175
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", {
176
+ result,
177
+ basis: "lateral"
178
+ });
179
+ return result;
180
+ }
181
+ if (longitudinal <= -tuning.longitudinalThreshold) {
182
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", { result: "BRAKING" });
183
+ return "BRAKING";
184
+ }
185
+ if (longitudinal >= tuning.longitudinalThreshold) {
186
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", { result: "ACCELERATION" });
187
+ return "ACCELERATION";
188
+ }
189
+ if (motionIntensity < tuning.drivingMotionThreshold && gyroMagnitude <= tuning.stoppedGyroThreshold) {
190
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", { result: "STOPPED" });
191
+ return "STOPPED";
192
+ }
193
+ dialSdkDebugWarn(DEBUG_MODULE$5, "classifyDrivingMetrics", "returned", { result: "STEADY_DRIVING" });
103
194
  return "STEADY_DRIVING";
104
195
  };
105
196
  const availableFreshVector = (metric, capturedAtMs, maxSampleAgeMs) => {
106
- if (!metric?.available || !isFresh(metric.sampledAtMs, capturedAtMs, maxSampleAgeMs)) return null;
197
+ dialSdkDebugWarn(DEBUG_MODULE$5, "availableFreshVector", "called", {
198
+ metric,
199
+ capturedAtMs,
200
+ maxSampleAgeMs
201
+ });
202
+ if (!metric?.available || !isFresh(metric.sampledAtMs, capturedAtMs, maxSampleAgeMs)) {
203
+ dialSdkDebugWarn(DEBUG_MODULE$5, "availableFreshVector", "returned", { result: null });
204
+ return null;
205
+ }
107
206
  const { x, y, z } = metric.value;
108
- return [
207
+ const result = [
109
208
  x,
110
209
  y,
111
210
  z
112
211
  ].every(Number.isFinite) ? metric.value : null;
212
+ dialSdkDebugWarn(DEBUG_MODULE$5, "availableFreshVector", "returned", { result });
213
+ return result;
113
214
  };
114
215
  const availableFreshNumber = (metric, capturedAtMs, maxSampleAgeMs) => {
115
- if (!metric?.available || !isFresh(metric.sampledAtMs, capturedAtMs, maxSampleAgeMs)) return null;
116
- return Number.isFinite(metric.value) && metric.value >= 0 ? metric.value : null;
216
+ dialSdkDebugWarn(DEBUG_MODULE$5, "availableFreshNumber", "called", {
217
+ metric,
218
+ capturedAtMs,
219
+ maxSampleAgeMs
220
+ });
221
+ if (!metric?.available || !isFresh(metric.sampledAtMs, capturedAtMs, maxSampleAgeMs)) {
222
+ dialSdkDebugWarn(DEBUG_MODULE$5, "availableFreshNumber", "returned", { result: null });
223
+ return null;
224
+ }
225
+ const result = Number.isFinite(metric.value) && metric.value >= 0 ? metric.value : null;
226
+ dialSdkDebugWarn(DEBUG_MODULE$5, "availableFreshNumber", "returned", { result });
227
+ return result;
117
228
  };
118
229
  const isFresh = (sampledAtMs, capturedAtMs, maxSampleAgeMs) => {
119
- if (sampledAtMs === null || !Number.isFinite(sampledAtMs)) return false;
230
+ dialSdkDebugWarn(DEBUG_MODULE$5, "isFresh", "called", {
231
+ sampledAtMs,
232
+ capturedAtMs,
233
+ maxSampleAgeMs
234
+ });
235
+ if (sampledAtMs === null || !Number.isFinite(sampledAtMs)) {
236
+ dialSdkDebugWarn(DEBUG_MODULE$5, "isFresh", "returned", { result: false });
237
+ return false;
238
+ }
120
239
  const age = capturedAtMs - sampledAtMs;
121
- return age >= 0 && age <= maxSampleAgeMs;
240
+ const result = age >= 0 && age <= maxSampleAgeMs;
241
+ dialSdkDebugWarn(DEBUG_MODULE$5, "isFresh", "returned", {
242
+ age,
243
+ result
244
+ });
245
+ return result;
246
+ };
247
+ const vectorMagnitude = ({ x, y, z }) => {
248
+ const result = Math.hypot(x, y, z);
249
+ dialSdkDebugWarn(DEBUG_MODULE$5, "vectorMagnitude", "returned", {
250
+ x,
251
+ y,
252
+ z,
253
+ result
254
+ });
255
+ return result;
122
256
  };
123
- const vectorMagnitude = ({ x, y, z }) => Math.hypot(x, y, z);
124
257
  const assertPositiveFinite = (name, value) => {
125
- if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${name} must be a positive finite number`);
258
+ dialSdkDebugWarn(DEBUG_MODULE$5, "assertPositiveFinite", "called", {
259
+ name,
260
+ value
261
+ });
262
+ if (!Number.isFinite(value) || value <= 0) {
263
+ const error = /* @__PURE__ */ new RangeError(`${name} must be a positive finite number`);
264
+ dialSdkDebugWarn(DEBUG_MODULE$5, "assertPositiveFinite", "threw", error);
265
+ throw error;
266
+ }
267
+ dialSdkDebugWarn(DEBUG_MODULE$5, "assertPositiveFinite", "returned");
126
268
  };
127
269
  //#endregion
128
270
  //#region src/sensor/unified_info.ts
271
+ const DEBUG_MODULE$4 = "unified_info.ts";
129
272
  const unifiedSensorInfo = () => {
130
- return window.unifiedSensorInfo();
273
+ dialSdkDebugWarn(DEBUG_MODULE$4, "unifiedSensorInfo", "called");
274
+ try {
275
+ return window.unifiedSensorInfo().then((payload) => {
276
+ dialSdkDebugWarn(DEBUG_MODULE$4, "unifiedSensorInfo", "resolved", { payload });
277
+ return payload;
278
+ }, (error) => {
279
+ dialSdkDebugWarn(DEBUG_MODULE$4, "unifiedSensorInfo", "rejected", error);
280
+ throw error;
281
+ });
282
+ } catch (error) {
283
+ dialSdkDebugWarn(DEBUG_MODULE$4, "unifiedSensorInfo", "threw", error);
284
+ throw error;
285
+ }
131
286
  };
132
287
  //#endregion
133
288
  //#region src/sensor/constants.ts
@@ -172,6 +327,7 @@ const CAR_RUNNING_STATUS_PRIORITY = {
172
327
  };
173
328
  //#endregion
174
329
  //#region src/sensor/driving_expressions.ts
330
+ const DEBUG_MODULE$3 = "driving_expressions.ts";
175
331
  const OFFICIAL_DRIVING_EXPRESSION_FALLBACKS = Object.freeze({
176
332
  STOPPED: Object.freeze({
177
333
  kind: "emoji",
@@ -212,20 +368,32 @@ const OFFICIAL_DRIVING_EXPRESSIONS_CONFIG = Object.freeze({
212
368
  });
213
369
  var DrivingExpressionsConfigError = class extends Error {
214
370
  constructor(code, message, state) {
371
+ dialSdkDebugWarn(DEBUG_MODULE$3, "DrivingExpressionsConfigError.constructor", "called", {
372
+ code,
373
+ message,
374
+ state
375
+ });
215
376
  super(message);
216
377
  this.name = "DrivingExpressionsConfigError";
217
378
  this.code = code;
218
379
  this.state = state;
380
+ dialSdkDebugWarn(DEBUG_MODULE$3, "DrivingExpressionsConfigError.constructor", "created", { error: this });
219
381
  }
220
382
  };
221
383
  var DrivingExpressionResolutionError = class extends Error {
222
384
  constructor(status) {
385
+ dialSdkDebugWarn(DEBUG_MODULE$3, "DrivingExpressionResolutionError.constructor", "called", { status });
223
386
  super(`No driving expression is configured for ${status}`);
224
387
  this.name = "DrivingExpressionResolutionError";
225
388
  this.status = status;
389
+ dialSdkDebugWarn(DEBUG_MODULE$3, "DrivingExpressionResolutionError.constructor", "created", { error: this });
226
390
  }
227
391
  };
228
392
  const parseDrivingExpressionsConfig = (raw, options = {}) => {
393
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionsConfig", "called", {
394
+ raw,
395
+ options
396
+ });
229
397
  const parsed = parseJsonObject(raw);
230
398
  if (parsed.schemaVersion !== 1 || !isRecord$1(parsed.states)) throw new DrivingExpressionsConfigError("DRIVING_EXPRESSIONS_INVALID_SCHEMA", "drivingExpressions must use schemaVersion 1 and contain a states object");
231
399
  const knownStatuses = new Set(CAR_RUNNING_STATUSES);
@@ -236,15 +404,24 @@ const parseDrivingExpressionsConfig = (raw, options = {}) => {
236
404
  if (!Object.prototype.hasOwnProperty.call(parsed.states, status)) throw new DrivingExpressionsConfigError("DRIVING_EXPRESSIONS_INCOMPLETE", `drivingExpressions.states is missing ${status}`, status);
237
405
  states[status] = parseDrivingExpressionMedia(parsed.states[status], status, options);
238
406
  }
239
- return {
407
+ const result = {
240
408
  schemaVersion: 1,
241
409
  states
242
410
  };
411
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionsConfig", "returned", { result });
412
+ return result;
243
413
  };
244
414
  const tryParseDrivingExpressionsConfig = (raw, options) => {
415
+ dialSdkDebugWarn(DEBUG_MODULE$3, "tryParseDrivingExpressionsConfig", "called", {
416
+ raw,
417
+ options
418
+ });
245
419
  try {
246
- return parseDrivingExpressionsConfig(raw, options);
247
- } catch {
420
+ const result = parseDrivingExpressionsConfig(raw, options);
421
+ dialSdkDebugWarn(DEBUG_MODULE$3, "tryParseDrivingExpressionsConfig", "returned", { result });
422
+ return result;
423
+ } catch (error) {
424
+ dialSdkDebugWarn(DEBUG_MODULE$3, "tryParseDrivingExpressionsConfig", "returned null after parse error", error);
248
425
  return null;
249
426
  }
250
427
  };
@@ -253,14 +430,24 @@ const tryParseDrivingExpressionsConfig = (raw, options) => {
253
430
  * It never installs official fallbacks implicitly.
254
431
  */
255
432
  const readDrivingExpressionsConfig = (raw, options) => {
433
+ dialSdkDebugWarn(DEBUG_MODULE$3, "readDrivingExpressionsConfig", "called", {
434
+ raw,
435
+ options
436
+ });
256
437
  const source = raw === void 0 ? readRuntimeDrivingExpressionsValue() : raw;
257
- return source === void 0 ? null : tryParseDrivingExpressionsConfig(source, options);
438
+ const result = source === void 0 ? null : tryParseDrivingExpressionsConfig(source, options);
439
+ dialSdkDebugWarn(DEBUG_MODULE$3, "readDrivingExpressionsConfig", "returned", {
440
+ source,
441
+ result
442
+ });
443
+ return result;
258
444
  };
259
445
  /**
260
446
  * Waits for a valid Runtime-injected configuration using bounded polling.
261
447
  * It never installs official fallbacks implicitly.
262
448
  */
263
449
  const waitForDrivingExpressionsConfig = (options = {}) => {
450
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig", "called", { options });
264
451
  const timeoutMs = requireNonNegativeFinite("timeoutMs", options.timeoutMs ?? 3e3);
265
452
  const pollIntervalMs = requirePositiveFinite$1("pollIntervalMs", options.pollIntervalMs ?? 100);
266
453
  const { signal } = options;
@@ -269,30 +456,61 @@ const waitForDrivingExpressionsConfig = (options = {}) => {
269
456
  let timer;
270
457
  let settled = false;
271
458
  const cleanup = () => {
459
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.cleanup", "called", {
460
+ timer,
461
+ settled
462
+ });
272
463
  if (timer !== void 0) {
273
464
  globalThis.clearTimeout(timer);
274
465
  timer = void 0;
275
466
  }
276
467
  signal?.removeEventListener("abort", handleAbort);
468
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.cleanup", "returned");
277
469
  };
278
470
  const finish = (config) => {
279
- if (settled) return;
471
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.finish", "called", {
472
+ config,
473
+ settled
474
+ });
475
+ if (settled) {
476
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.finish", "ignored");
477
+ return;
478
+ }
280
479
  settled = true;
281
480
  cleanup();
282
481
  resolve(config);
482
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.finish", "resolved", { config });
283
483
  };
284
484
  const fail = (error) => {
285
- if (settled) return;
485
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.fail", "called", {
486
+ error,
487
+ settled
488
+ });
489
+ if (settled) {
490
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.fail", "ignored");
491
+ return;
492
+ }
286
493
  settled = true;
287
494
  cleanup();
288
495
  reject(error);
496
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.fail", "rejected", error);
289
497
  };
290
498
  const handleAbort = () => {
499
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.handleAbort", "called");
291
500
  fail(createAbortError$1());
292
501
  };
293
- const read = () => readDrivingExpressionsConfig(void 0, options.parseOptions);
502
+ const read = () => {
503
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.read", "called");
504
+ const result = readDrivingExpressionsConfig(void 0, options.parseOptions);
505
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.read", "returned", { result });
506
+ return result;
507
+ };
294
508
  const poll = () => {
295
- if (settled) return;
509
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.poll", "called", { settled });
510
+ if (settled) {
511
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.poll", "ignored");
512
+ return;
513
+ }
296
514
  if (signal?.aborted) {
297
515
  handleAbort();
298
516
  return;
@@ -308,41 +526,125 @@ const waitForDrivingExpressionsConfig = (options = {}) => {
308
526
  return;
309
527
  }
310
528
  timer = globalThis.setTimeout(poll, Math.min(pollIntervalMs, remainingMs));
529
+ dialSdkDebugWarn(DEBUG_MODULE$3, "waitForDrivingExpressionsConfig.poll", "scheduled", {
530
+ remainingMs,
531
+ delayMs: Math.min(pollIntervalMs, remainingMs)
532
+ });
311
533
  };
312
534
  signal?.addEventListener("abort", handleAbort, { once: true });
313
535
  poll();
314
536
  });
315
537
  };
316
538
  /** Original resolver behavior: missing legacy slots fall back to STEADY_DRIVING. */
317
- const resolveDrivingExpression = (config, status) => config.states[status] ?? config.states.STEADY_DRIVING;
539
+ const resolveDrivingExpression = (config, status) => {
540
+ const result = config.states[status] ?? config.states.STEADY_DRIVING;
541
+ dialSdkDebugWarn(DEBUG_MODULE$3, "resolveDrivingExpression", "returned", {
542
+ config,
543
+ status,
544
+ result
545
+ });
546
+ return result;
547
+ };
318
548
  /** Strict resolver used by the player; official fallbacks are opt-in. */
319
549
  const resolveDrivingExpressionStrict = (config, status, fallbacks) => {
550
+ dialSdkDebugWarn(DEBUG_MODULE$3, "resolveDrivingExpressionStrict", "called", {
551
+ config,
552
+ status,
553
+ fallbacks
554
+ });
320
555
  const configured = config.states[status];
321
- if (configured !== void 0) return configured;
556
+ if (configured !== void 0) {
557
+ dialSdkDebugWarn(DEBUG_MODULE$3, "resolveDrivingExpressionStrict", "returned configured media", { configured });
558
+ return configured;
559
+ }
322
560
  const fallback = fallbacks?.[status];
323
- if (fallback !== void 0) return fallback;
324
- throw new DrivingExpressionResolutionError(status);
561
+ if (fallback !== void 0) {
562
+ dialSdkDebugWarn(DEBUG_MODULE$3, "resolveDrivingExpressionStrict", "returned fallback media", { fallback });
563
+ return fallback;
564
+ }
565
+ const error = new DrivingExpressionResolutionError(status);
566
+ dialSdkDebugWarn(DEBUG_MODULE$3, "resolveDrivingExpressionStrict", "threw", error);
567
+ throw error;
325
568
  };
326
569
  const isPublicDrivingMediaUrl = (value) => {
570
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicDrivingMediaUrl", "called", { value });
327
571
  try {
328
572
  const url = new URL(value);
329
- if (url.protocol !== "https:" || url.username !== "" || url.password !== "") return false;
330
- if (!isPublicHostname(url.hostname)) return false;
331
- for (const key of url.searchParams.keys()) if (TEMPORARY_SIGNATURE_QUERY_KEYS.has(key.toLowerCase())) return false;
573
+ if (url.protocol !== "https:" || url.username !== "" || url.password !== "") {
574
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicDrivingMediaUrl", "returned", {
575
+ result: false,
576
+ reason: "protocol_or_auth"
577
+ });
578
+ return false;
579
+ }
580
+ if (!isPublicHostname(url.hostname)) {
581
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicDrivingMediaUrl", "returned", {
582
+ result: false,
583
+ reason: "hostname"
584
+ });
585
+ return false;
586
+ }
587
+ for (const key of url.searchParams.keys()) if (TEMPORARY_SIGNATURE_QUERY_KEYS.has(key.toLowerCase())) {
588
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicDrivingMediaUrl", "returned", {
589
+ result: false,
590
+ reason: "temporary_signature",
591
+ key
592
+ });
593
+ return false;
594
+ }
595
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicDrivingMediaUrl", "returned", { result: true });
332
596
  return true;
333
- } catch {
597
+ } catch (error) {
598
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicDrivingMediaUrl", "returned after URL parse error", {
599
+ result: false,
600
+ error
601
+ });
334
602
  return false;
335
603
  }
336
604
  };
337
605
  const isPublicHostname = (rawHostname) => {
606
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicHostname", "called", { rawHostname });
338
607
  const hostname = rawHostname.toLowerCase().replace(/^\[|\]$/gu, "").replace(/\.+$/gu, "");
339
- if (hostname === "") return false;
608
+ if (hostname === "") {
609
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicHostname", "returned", {
610
+ result: false,
611
+ hostname
612
+ });
613
+ return false;
614
+ }
340
615
  const ipv4 = parseIpv4(hostname);
341
- if (ipv4 !== null) return !isRestrictedIpv4(ipv4);
616
+ if (ipv4 !== null) {
617
+ const result = !isRestrictedIpv4(ipv4);
618
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicHostname", "returned IPv4 result", {
619
+ hostname,
620
+ ipv4,
621
+ result
622
+ });
623
+ return result;
624
+ }
342
625
  const ipv6 = parseIpv6(hostname);
343
- if (ipv6 !== null) return !isRestrictedIpv6(ipv6);
344
- if (!hostname.includes(".")) return false;
345
- return !INTERNAL_HOST_SUFFIXES.some((suffix) => hostname === suffix || hostname.endsWith(`.${suffix}`));
626
+ if (ipv6 !== null) {
627
+ const result = !isRestrictedIpv6(ipv6);
628
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicHostname", "returned IPv6 result", {
629
+ hostname,
630
+ ipv6,
631
+ result
632
+ });
633
+ return result;
634
+ }
635
+ if (!hostname.includes(".")) {
636
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicHostname", "returned", {
637
+ hostname,
638
+ result: false
639
+ });
640
+ return false;
641
+ }
642
+ const result = !INTERNAL_HOST_SUFFIXES.some((suffix) => hostname === suffix || hostname.endsWith(`.${suffix}`));
643
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isPublicHostname", "returned DNS result", {
644
+ hostname,
645
+ result
646
+ });
647
+ return result;
346
648
  };
347
649
  const INTERNAL_HOST_SUFFIXES = [
348
650
  "corp",
@@ -357,57 +659,108 @@ const INTERNAL_HOST_SUFFIXES = [
357
659
  "private"
358
660
  ];
359
661
  const parseIpv4 = (hostname) => {
662
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv4", "called", { hostname });
360
663
  const parts = hostname.split(".");
361
- if (parts.length !== 4 || parts.some((part) => !/^\d{1,3}$/u.test(part))) return null;
664
+ if (parts.length !== 4 || parts.some((part) => !/^\d{1,3}$/u.test(part))) {
665
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv4", "returned", { result: null });
666
+ return null;
667
+ }
362
668
  const octets = parts.map(Number);
363
- if (octets.some((octet) => octet > 255)) return null;
364
- return octets;
669
+ if (octets.some((octet) => octet > 255)) {
670
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv4", "returned", {
671
+ result: null,
672
+ octets
673
+ });
674
+ return null;
675
+ }
676
+ const result = octets;
677
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv4", "returned", { result });
678
+ return result;
679
+ };
680
+ const isRestrictedIpv4 = (value) => {
681
+ const [a, b, c] = value;
682
+ const result = a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 0 && c === 0 || a === 192 && b === 0 && c === 2 || a === 192 && b === 31 && c === 196 || a === 192 && b === 52 && c === 193 || a === 192 && b === 88 && c === 99 || a === 192 && b === 168 || a === 192 && b === 175 && c === 48 || a === 198 && (b === 18 || b === 19) || a === 198 && b === 51 && c === 100 || a === 203 && b === 0 && c === 113 || a >= 224;
683
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isRestrictedIpv4", "returned", {
684
+ value,
685
+ result
686
+ });
687
+ return result;
365
688
  };
366
- const isRestrictedIpv4 = ([a, b, c]) => a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 0 && c === 0 || a === 192 && b === 0 && c === 2 || a === 192 && b === 31 && c === 196 || a === 192 && b === 52 && c === 193 || a === 192 && b === 88 && c === 99 || a === 192 && b === 168 || a === 192 && b === 175 && c === 48 || a === 198 && (b === 18 || b === 19) || a === 198 && b === 51 && c === 100 || a === 203 && b === 0 && c === 113 || a >= 224;
367
689
  const parseIpv6 = (hostname) => {
368
- if (!hostname.includes(":")) return null;
690
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "called", { hostname });
691
+ if (!hostname.includes(":")) {
692
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "returned", { result: null });
693
+ return null;
694
+ }
369
695
  let normalized = hostname;
370
696
  if (normalized.includes(".")) {
371
697
  const lastColon = normalized.lastIndexOf(":");
372
698
  const ipv4 = parseIpv4(normalized.slice(lastColon + 1));
373
- if (ipv4 === null) return null;
699
+ if (ipv4 === null) {
700
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "returned invalid embedded IPv4", { result: null });
701
+ return null;
702
+ }
374
703
  normalized = `${normalized.slice(0, lastColon)}:${(ipv4[0] << 8 | ipv4[1]).toString(16)}:${(ipv4[2] << 8 | ipv4[3]).toString(16)}`;
375
704
  }
376
705
  const halves = normalized.split("::");
377
- if (halves.length > 2) return null;
706
+ if (halves.length > 2) {
707
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "returned invalid halves", {
708
+ result: null,
709
+ halves
710
+ });
711
+ return null;
712
+ }
378
713
  const left = halves[0] === "" ? [] : halves[0].split(":");
379
714
  const right = halves.length === 1 || halves[1] === "" ? [] : halves[1].split(":");
380
- if ([...left, ...right].some((part) => !/^[\da-f]{1,4}$/u.test(part))) return null;
715
+ if ([...left, ...right].some((part) => !/^[\da-f]{1,4}$/u.test(part))) {
716
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "returned invalid group", {
717
+ result: null,
718
+ left,
719
+ right
720
+ });
721
+ return null;
722
+ }
381
723
  const omitted = 8 - left.length - right.length;
382
- if (halves.length === 1 && omitted !== 0 || halves.length === 2 && omitted < 1) return null;
724
+ if (halves.length === 1 && omitted !== 0 || halves.length === 2 && omitted < 1) {
725
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "returned invalid omission", {
726
+ result: null,
727
+ omitted
728
+ });
729
+ return null;
730
+ }
383
731
  const groups = [
384
732
  ...left,
385
733
  ...Array.from({ length: omitted }, () => "0"),
386
734
  ...right
387
735
  ].map((part) => Number.parseInt(part, 16));
388
- if (groups.length !== 8) return null;
736
+ if (groups.length !== 8) {
737
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "returned invalid group count", {
738
+ result: null,
739
+ groups
740
+ });
741
+ return null;
742
+ }
389
743
  const bytes = /* @__PURE__ */ new Uint8Array(16);
390
744
  groups.forEach((group, index) => {
391
745
  bytes[index * 2] = group >>> 8;
392
746
  bytes[index * 2 + 1] = group & 255;
393
747
  });
748
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseIpv6", "returned", { result: bytes });
394
749
  return bytes;
395
750
  };
396
751
  const isRestrictedIpv6 = (bytes) => {
397
- const allZeroPrefix = (length) => bytes.subarray(0, length).every((value) => value === 0);
398
- if (bytes.every((value) => value === 0)) return true;
399
- if (allZeroPrefix(15) && bytes[15] === 1) return true;
400
- if (allZeroPrefix(12)) return true;
401
- if (allZeroPrefix(10) && bytes[10] === 255 && bytes[11] === 255) return true;
402
- if (bytes[0] === 0 && bytes[1] === 100 && bytes[2] === 255 && bytes[3] === 155) return true;
403
- if ((bytes[0] & 254) === 252) return true;
404
- if (bytes[0] === 254 && (bytes[1] & 192) === 128) return true;
405
- if (bytes[0] === 255) return true;
406
- if (bytes[0] === 1 && bytes.subarray(1, 8).every((value) => value === 0)) return true;
407
- if (bytes[0] === 32 && bytes[1] === 1 && bytes[2] === 13 && bytes[3] === 184) return true;
408
- if (bytes[0] === 32 && bytes[1] === 1 && bytes[2] <= 1) return true;
409
- if (bytes[0] === 32 && bytes[1] === 2) return true;
410
- return bytes[0] === 63 && bytes[1] === 254;
752
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isRestrictedIpv6", "called", { bytes });
753
+ const allZeroPrefix = (length) => {
754
+ const result = bytes.subarray(0, length).every((value) => value === 0);
755
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isRestrictedIpv6.allZeroPrefix", "returned", {
756
+ length,
757
+ result
758
+ });
759
+ return result;
760
+ };
761
+ const result = bytes.every((value) => value === 0) || allZeroPrefix(15) && bytes[15] === 1 || allZeroPrefix(12) || allZeroPrefix(10) && bytes[10] === 255 && bytes[11] === 255 || bytes[0] === 0 && bytes[1] === 100 && bytes[2] === 255 && bytes[3] === 155 || (bytes[0] & 254) === 252 || bytes[0] === 254 && (bytes[1] & 192) === 128 || bytes[0] === 255 || bytes[0] === 1 && bytes.subarray(1, 8).every((value) => value === 0) || bytes[0] === 32 && bytes[1] === 1 && bytes[2] === 13 && bytes[3] === 184 || bytes[0] === 32 && bytes[1] === 1 && bytes[2] <= 1 || bytes[0] === 32 && bytes[1] === 2 || bytes[0] === 63 && bytes[1] === 254;
762
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isRestrictedIpv6", "returned", { result });
763
+ return result;
411
764
  };
412
765
  const TEMPORARY_SIGNATURE_QUERY_KEYS = /* @__PURE__ */ new Set([
413
766
  "expires",
@@ -443,12 +796,19 @@ const TEMPORARY_SIGNATURE_QUERY_KEYS = /* @__PURE__ */ new Set([
443
796
  "x-oss-signature"
444
797
  ]);
445
798
  const parseDrivingExpressionMedia = (raw, status, options) => {
799
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionMedia", "called", {
800
+ raw,
801
+ status,
802
+ options
803
+ });
446
804
  if (typeof raw === "string" && options.allowLegacyImageUrls) {
447
805
  assertPublicUrl(raw, status, "url");
448
- return {
806
+ const result = {
449
807
  kind: "image",
450
808
  url: raw
451
809
  };
810
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionMedia", "returned legacy image", { result });
811
+ return result;
452
812
  }
453
813
  if (!isRecord$1(raw) || typeof raw.kind !== "string") throw invalidMedia(status, "media must be a structured object with a supported kind");
454
814
  const mediaAssetId = parseMediaAssetId(raw.mediaAssetId, status);
@@ -458,7 +818,7 @@ const parseDrivingExpressionMedia = (raw, status, options) => {
458
818
  "duration"
459
819
  ]);
460
820
  switch (raw.kind) {
461
- case "emoji":
821
+ case "emoji": {
462
822
  assertFieldsAbsent(raw, status, [
463
823
  "mediaAssetId",
464
824
  "url",
@@ -467,10 +827,13 @@ const parseDrivingExpressionMedia = (raw, status, options) => {
467
827
  "mimeType"
468
828
  ]);
469
829
  if (typeof raw.text !== "string" || !isOneVisibleGrapheme(raw.text)) throw invalidMedia(status, "emoji.text must contain exactly one visible grapheme");
470
- return {
830
+ const result = {
471
831
  kind: "emoji",
472
832
  text: raw.text.trim()
473
833
  };
834
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionMedia", "returned emoji", { result });
835
+ return result;
836
+ }
474
837
  case "image": {
475
838
  assertFieldsAbsent(raw, status, [
476
839
  "text",
@@ -479,25 +842,29 @@ const parseDrivingExpressionMedia = (raw, status, options) => {
479
842
  ]);
480
843
  const url = parseRequiredUrl(raw.url, status, "url");
481
844
  const mimeType = parseOptionalString(raw.mimeType, status, "mimeType");
482
- return compact({
845
+ const result = compact({
483
846
  kind: "image",
484
847
  mediaAssetId,
485
848
  url,
486
849
  mimeType
487
850
  });
851
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionMedia", "returned image", { result });
852
+ return result;
488
853
  }
489
854
  case "video": {
490
855
  assertFieldsAbsent(raw, status, ["text", "motionUrl"]);
491
856
  const url = parseRequiredUrl(raw.url, status, "url");
492
857
  const coverUrl = parseOptionalUrl(raw.coverUrl, status, "coverUrl");
493
858
  const mimeType = parseOptionalString(raw.mimeType, status, "mimeType");
494
- return compact({
859
+ const result = compact({
495
860
  kind: "video",
496
861
  mediaAssetId,
497
862
  url,
498
863
  coverUrl,
499
864
  mimeType
500
865
  });
866
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionMedia", "returned video", { result });
867
+ return result;
501
868
  }
502
869
  case "live_photo": {
503
870
  assertFieldsAbsent(raw, status, [
@@ -507,12 +874,14 @@ const parseDrivingExpressionMedia = (raw, status, options) => {
507
874
  ]);
508
875
  const coverUrl = parseRequiredUrl(raw.coverUrl, status, "coverUrl");
509
876
  const motionUrl = parseRequiredUrl(raw.motionUrl, status, "motionUrl");
510
- return compact({
877
+ const result = compact({
511
878
  kind: "live_photo",
512
879
  mediaAssetId,
513
880
  coverUrl,
514
881
  motionUrl
515
882
  });
883
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionMedia", "returned live photo", { result });
884
+ return result;
516
885
  }
517
886
  case "tgs": {
518
887
  assertFieldsAbsent(raw, status, [
@@ -522,88 +891,228 @@ const parseDrivingExpressionMedia = (raw, status, options) => {
522
891
  ]);
523
892
  const url = parseRequiredUrl(raw.url, status, "url");
524
893
  const coverUrl = parseOptionalUrl(raw.coverUrl, status, "coverUrl");
525
- return compact({
894
+ const result = compact({
526
895
  kind: "tgs",
527
896
  mediaAssetId,
528
897
  url,
529
898
  coverUrl
530
899
  });
900
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseDrivingExpressionMedia", "returned TGS", { result });
901
+ return result;
531
902
  }
532
903
  default: throw invalidMedia(status, `unsupported media kind: ${raw.kind}`);
533
904
  }
534
905
  };
535
906
  const parseJsonObject = (raw) => {
907
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseJsonObject", "called", { raw });
536
908
  let value = raw;
537
909
  if (typeof value === "string") try {
538
910
  value = JSON.parse(value);
539
- } catch {
540
- throw new DrivingExpressionsConfigError("DRIVING_EXPRESSIONS_INVALID_SCHEMA", "drivingExpressions is not valid JSON");
911
+ } catch (cause) {
912
+ const error = new DrivingExpressionsConfigError("DRIVING_EXPRESSIONS_INVALID_SCHEMA", "drivingExpressions is not valid JSON");
913
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseJsonObject", "threw", {
914
+ error,
915
+ cause
916
+ });
917
+ throw error;
918
+ }
919
+ if (!isRecord$1(value)) {
920
+ const error = new DrivingExpressionsConfigError("DRIVING_EXPRESSIONS_INVALID_SCHEMA", "drivingExpressions must be a JSON object or JSON object string");
921
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseJsonObject", "threw", error);
922
+ throw error;
541
923
  }
542
- if (!isRecord$1(value)) throw new DrivingExpressionsConfigError("DRIVING_EXPRESSIONS_INVALID_SCHEMA", "drivingExpressions must be a JSON object or JSON object string");
924
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseJsonObject", "returned", { value });
543
925
  return value;
544
926
  };
545
927
  const readRuntimeDrivingExpressionsValue = () => {
928
+ dialSdkDebugWarn(DEBUG_MODULE$3, "readRuntimeDrivingExpressionsValue", "called");
546
929
  const runtimeGlobal = globalThis;
547
- if (runtimeGlobal.__TOOOONY_DRIVING_EXPRESSIONS__ !== void 0) return runtimeGlobal.__TOOOONY_DRIVING_EXPRESSIONS__;
930
+ if (runtimeGlobal.__TOOOONY_DRIVING_EXPRESSIONS__ !== void 0) {
931
+ const result = runtimeGlobal.__TOOOONY_DRIVING_EXPRESSIONS__;
932
+ dialSdkDebugWarn(DEBUG_MODULE$3, "readRuntimeDrivingExpressionsValue", "returned typed injection", { result });
933
+ return result;
934
+ }
548
935
  const faceConfig = runtimeGlobal.__TOOOONY_FACE_CONFIG__;
549
- if (!isRecord$1(faceConfig)) return void 0;
550
- if (faceConfig.drivingExpressions !== void 0) return faceConfig.drivingExpressions;
551
- return isRecord$1(faceConfig.values) ? faceConfig.values.drivingExpressions : void 0;
936
+ if (!isRecord$1(faceConfig)) {
937
+ dialSdkDebugWarn(DEBUG_MODULE$3, "readRuntimeDrivingExpressionsValue", "returned", { result: void 0 });
938
+ return;
939
+ }
940
+ if (faceConfig.drivingExpressions !== void 0) {
941
+ const result = faceConfig.drivingExpressions;
942
+ dialSdkDebugWarn(DEBUG_MODULE$3, "readRuntimeDrivingExpressionsValue", "returned face config", { result });
943
+ return result;
944
+ }
945
+ const result = isRecord$1(faceConfig.values) ? faceConfig.values.drivingExpressions : void 0;
946
+ dialSdkDebugWarn(DEBUG_MODULE$3, "readRuntimeDrivingExpressionsValue", "returned legacy face config", { result });
947
+ return result;
552
948
  };
553
949
  const parseMediaAssetId = (raw, status) => {
554
- if (raw === void 0) return void 0;
950
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseMediaAssetId", "called", {
951
+ raw,
952
+ status
953
+ });
954
+ if (raw === void 0) {
955
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseMediaAssetId", "returned", { result: void 0 });
956
+ return;
957
+ }
555
958
  if (!Number.isSafeInteger(raw) || raw <= 0) throw invalidMedia(status, "mediaAssetId must be a positive safe integer when present");
556
- return raw;
959
+ const result = raw;
960
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseMediaAssetId", "returned", { result });
961
+ return result;
557
962
  };
558
963
  const assertFieldsAbsent = (value, status, fields) => {
964
+ dialSdkDebugWarn(DEBUG_MODULE$3, "assertFieldsAbsent", "called", {
965
+ value,
966
+ status,
967
+ fields
968
+ });
559
969
  const present = fields.find((field) => Object.prototype.hasOwnProperty.call(value, field));
560
- if (present !== void 0) throw invalidMedia(status, `${present} is not allowed for this media kind`);
970
+ if (present !== void 0) {
971
+ const error = invalidMedia(status, `${present} is not allowed for this media kind`);
972
+ dialSdkDebugWarn(DEBUG_MODULE$3, "assertFieldsAbsent", "threw", error);
973
+ throw error;
974
+ }
975
+ dialSdkDebugWarn(DEBUG_MODULE$3, "assertFieldsAbsent", "returned");
561
976
  };
562
977
  const parseRequiredUrl = (raw, status, field) => {
563
- if (typeof raw !== "string" || raw.length === 0) throw invalidMedia(status, `${field} is required`);
978
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseRequiredUrl", "called", {
979
+ raw,
980
+ status,
981
+ field
982
+ });
983
+ if (typeof raw !== "string" || raw.length === 0) {
984
+ const error = invalidMedia(status, `${field} is required`);
985
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseRequiredUrl", "threw", error);
986
+ throw error;
987
+ }
564
988
  assertPublicUrl(raw, status, field);
989
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseRequiredUrl", "returned", { result: raw });
565
990
  return raw;
566
991
  };
567
992
  const parseOptionalUrl = (raw, status, field) => {
568
- if (raw === void 0) return void 0;
569
- return parseRequiredUrl(raw, status, field);
993
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseOptionalUrl", "called", {
994
+ raw,
995
+ status,
996
+ field
997
+ });
998
+ if (raw === void 0) {
999
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseOptionalUrl", "returned", { result: void 0 });
1000
+ return;
1001
+ }
1002
+ const result = parseRequiredUrl(raw, status, field);
1003
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseOptionalUrl", "returned", { result });
1004
+ return result;
570
1005
  };
571
1006
  const parseOptionalString = (raw, status, field) => {
572
- if (raw === void 0) return void 0;
1007
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseOptionalString", "called", {
1008
+ raw,
1009
+ status,
1010
+ field
1011
+ });
1012
+ if (raw === void 0) {
1013
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseOptionalString", "returned", { result: void 0 });
1014
+ return;
1015
+ }
573
1016
  if (typeof raw !== "string" || raw.trim() === "" || raw.length > 255) throw invalidMedia(status, `${field} must be a non-empty string of at most 255 characters`);
1017
+ dialSdkDebugWarn(DEBUG_MODULE$3, "parseOptionalString", "returned", { result: raw });
574
1018
  return raw;
575
1019
  };
576
1020
  const assertPublicUrl = (value, status, field) => {
577
- if (!isPublicDrivingMediaUrl(value)) throw new DrivingExpressionsConfigError("MEDIA_URL_NOT_PUBLIC_HTTPS", `${status}.${field} must be a long-lived public HTTPS URL`, status);
1021
+ dialSdkDebugWarn(DEBUG_MODULE$3, "assertPublicUrl", "called", {
1022
+ value,
1023
+ status,
1024
+ field
1025
+ });
1026
+ if (!isPublicDrivingMediaUrl(value)) {
1027
+ const error = new DrivingExpressionsConfigError("MEDIA_URL_NOT_PUBLIC_HTTPS", `${status}.${field} must be a long-lived public HTTPS URL`, status);
1028
+ dialSdkDebugWarn(DEBUG_MODULE$3, "assertPublicUrl", "threw", error);
1029
+ throw error;
1030
+ }
1031
+ dialSdkDebugWarn(DEBUG_MODULE$3, "assertPublicUrl", "returned");
578
1032
  };
579
1033
  const isOneVisibleGrapheme = (value) => {
1034
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isOneVisibleGrapheme", "called", { value });
580
1035
  const trimmed = value.trim();
581
- if (trimmed === "" || trimmed.length > 32) return false;
1036
+ if (trimmed === "" || trimmed.length > 32) {
1037
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isOneVisibleGrapheme", "returned", {
1038
+ result: false,
1039
+ trimmed
1040
+ });
1041
+ return false;
1042
+ }
582
1043
  const Segmenter = Intl.Segmenter;
583
- return (Segmenter ? Array.from(new Segmenter(void 0, { granularity: "grapheme" }).segment(trimmed)) : Array.from(trimmed)).length === 1;
1044
+ const graphemes = Segmenter ? Array.from(new Segmenter(void 0, { granularity: "grapheme" }).segment(trimmed)) : Array.from(trimmed);
1045
+ const result = graphemes.length === 1;
1046
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isOneVisibleGrapheme", "returned", {
1047
+ graphemes,
1048
+ result
1049
+ });
1050
+ return result;
1051
+ };
1052
+ const invalidMedia = (status, detail) => {
1053
+ const result = new DrivingExpressionsConfigError("DRIVING_EXPRESSION_INVALID_MEDIA", `Invalid driving expression for ${status}: ${detail}`, status);
1054
+ dialSdkDebugWarn(DEBUG_MODULE$3, "invalidMedia", "returned", {
1055
+ status,
1056
+ detail,
1057
+ result
1058
+ });
1059
+ return result;
584
1060
  };
585
- const invalidMedia = (status, detail) => new DrivingExpressionsConfigError("DRIVING_EXPRESSION_INVALID_MEDIA", `Invalid driving expression for ${status}: ${detail}`, status);
586
1061
  const compact = (value) => {
1062
+ dialSdkDebugWarn(DEBUG_MODULE$3, "compact", "called", { value });
587
1063
  for (const key of Object.keys(value)) if (value[key] === void 0) delete value[key];
1064
+ dialSdkDebugWarn(DEBUG_MODULE$3, "compact", "returned", { result: value });
588
1065
  return value;
589
1066
  };
590
- const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1067
+ const isRecord$1 = (value) => {
1068
+ const result = typeof value === "object" && value !== null && !Array.isArray(value);
1069
+ dialSdkDebugWarn(DEBUG_MODULE$3, "isRecord", "returned", {
1070
+ value,
1071
+ result
1072
+ });
1073
+ return result;
1074
+ };
591
1075
  const requireNonNegativeFinite = (name, value) => {
592
- if (!Number.isFinite(value) || value < 0) throw new RangeError(`${name} must be a non-negative finite number`);
1076
+ dialSdkDebugWarn(DEBUG_MODULE$3, "requireNonNegativeFinite", "called", {
1077
+ name,
1078
+ value
1079
+ });
1080
+ if (!Number.isFinite(value) || value < 0) {
1081
+ const error = /* @__PURE__ */ new RangeError(`${name} must be a non-negative finite number`);
1082
+ dialSdkDebugWarn(DEBUG_MODULE$3, "requireNonNegativeFinite", "threw", error);
1083
+ throw error;
1084
+ }
1085
+ dialSdkDebugWarn(DEBUG_MODULE$3, "requireNonNegativeFinite", "returned", { result: value });
593
1086
  return value;
594
1087
  };
595
1088
  const requirePositiveFinite$1 = (name, value) => {
596
- if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${name} must be a positive finite number`);
1089
+ dialSdkDebugWarn(DEBUG_MODULE$3, "requirePositiveFinite", "called", {
1090
+ name,
1091
+ value
1092
+ });
1093
+ if (!Number.isFinite(value) || value <= 0) {
1094
+ const error = /* @__PURE__ */ new RangeError(`${name} must be a positive finite number`);
1095
+ dialSdkDebugWarn(DEBUG_MODULE$3, "requirePositiveFinite", "threw", error);
1096
+ throw error;
1097
+ }
1098
+ dialSdkDebugWarn(DEBUG_MODULE$3, "requirePositiveFinite", "returned", { result: value });
597
1099
  return value;
598
1100
  };
599
1101
  const createAbortError$1 = () => {
600
- if (typeof DOMException === "function") return new DOMException("The operation was aborted", "AbortError");
1102
+ dialSdkDebugWarn(DEBUG_MODULE$3, "createAbortError", "called");
1103
+ if (typeof DOMException === "function") {
1104
+ const result = new DOMException("The operation was aborted", "AbortError");
1105
+ dialSdkDebugWarn(DEBUG_MODULE$3, "createAbortError", "returned DOMException", { result });
1106
+ return result;
1107
+ }
601
1108
  const error = /* @__PURE__ */ new Error("The operation was aborted");
602
1109
  error.name = "AbortError";
1110
+ dialSdkDebugWarn(DEBUG_MODULE$3, "createAbortError", "returned Error", { result: error });
603
1111
  return error;
604
1112
  };
605
1113
  //#endregion
606
1114
  //#region src/sensor/page_lifecycle.ts
1115
+ const DEBUG_MODULE$2 = "page_lifecycle.ts";
607
1116
  const subscribers = /* @__PURE__ */ new Set();
608
1117
  let installedWindow = null;
609
1118
  let installedDocument = null;
@@ -614,6 +1123,7 @@ let hadOwnResumeHook = false;
614
1123
  let pauseHook = null;
615
1124
  let resumeHook = null;
616
1125
  const subscribeDrivingPageLifecycle = (pause, resume) => {
1126
+ dialSdkDebugWarn(DEBUG_MODULE$2, "subscribeDrivingPageLifecycle", "called", { subscriberCount: subscribers.size });
617
1127
  const subscriber = {
618
1128
  pause,
619
1129
  resume
@@ -622,15 +1132,29 @@ const subscribeDrivingPageLifecycle = (pause, resume) => {
622
1132
  if (subscribers.size === 1) installLifecycleHooks();
623
1133
  if (isDrivingPageHidden()) safeInvoke(pause);
624
1134
  let subscribed = true;
1135
+ dialSdkDebugWarn(DEBUG_MODULE$2, "subscribeDrivingPageLifecycle", "subscribed", { subscriberCount: subscribers.size });
625
1136
  return () => {
626
- if (!subscribed) return;
1137
+ dialSdkDebugWarn(DEBUG_MODULE$2, "subscribeDrivingPageLifecycle.unsubscribe", "called", { subscribed });
1138
+ if (!subscribed) {
1139
+ dialSdkDebugWarn(DEBUG_MODULE$2, "subscribeDrivingPageLifecycle.unsubscribe", "ignored");
1140
+ return;
1141
+ }
627
1142
  subscribed = false;
628
1143
  subscribers.delete(subscriber);
629
1144
  if (subscribers.size === 0) uninstallLifecycleHooks();
1145
+ dialSdkDebugWarn(DEBUG_MODULE$2, "subscribeDrivingPageLifecycle.unsubscribe", "returned", { subscriberCount: subscribers.size });
630
1146
  };
631
1147
  };
632
- const isDrivingPageHidden = () => typeof document !== "undefined" && document.visibilityState === "hidden";
1148
+ const isDrivingPageHidden = () => {
1149
+ const result = typeof document !== "undefined" && document.visibilityState === "hidden";
1150
+ dialSdkDebugWarn(DEBUG_MODULE$2, "isDrivingPageHidden", "returned", {
1151
+ visibilityState: typeof document === "undefined" ? void 0 : document.visibilityState,
1152
+ result
1153
+ });
1154
+ return result;
1155
+ };
633
1156
  const installLifecycleHooks = () => {
1157
+ dialSdkDebugWarn(DEBUG_MODULE$2, "installLifecycleHooks", "called");
634
1158
  installedDocument = typeof document === "undefined" ? null : document;
635
1159
  installedWindow = typeof window === "undefined" ? null : window;
636
1160
  installedDocument?.addEventListener("visibilitychange", handleVisibilityChange);
@@ -640,29 +1164,43 @@ const installLifecycleHooks = () => {
640
1164
  installedWindow?.addEventListener("resume", dispatchResume);
641
1165
  installedWindow?.addEventListener("toooony-device-sensors-release", dispatchPause);
642
1166
  installedWindow?.addEventListener("toooony-device-sensors-resume", dispatchResume);
643
- if (!installedWindow) return;
1167
+ if (!installedWindow) {
1168
+ dialSdkDebugWarn(DEBUG_MODULE$2, "installLifecycleHooks", "returned without window");
1169
+ return;
1170
+ }
644
1171
  hadOwnPauseHook = Object.prototype.hasOwnProperty.call(installedWindow, "__watchFaceRuntimePause");
645
1172
  hadOwnResumeHook = Object.prototype.hasOwnProperty.call(installedWindow, "__watchFaceRuntimeResume");
646
1173
  previousPauseHook = installedWindow.__watchFaceRuntimePause;
647
1174
  previousResumeHook = installedWindow.__watchFaceRuntimeResume;
648
1175
  pauseHook = function(...args) {
1176
+ dialSdkDebugWarn(DEBUG_MODULE$2, "runtimePauseHook", "called", { args });
649
1177
  try {
650
- return typeof previousPauseHook === "function" ? previousPauseHook.apply(this, args) : void 0;
1178
+ const result = typeof previousPauseHook === "function" ? previousPauseHook.apply(this, args) : void 0;
1179
+ dialSdkDebugWarn(DEBUG_MODULE$2, "runtimePauseHook", "returned", { result });
1180
+ return result;
651
1181
  } finally {
652
1182
  dispatchPause();
653
1183
  }
654
1184
  };
655
1185
  resumeHook = function(...args) {
1186
+ dialSdkDebugWarn(DEBUG_MODULE$2, "runtimeResumeHook", "called", { args });
656
1187
  try {
657
- return typeof previousResumeHook === "function" ? previousResumeHook.apply(this, args) : void 0;
1188
+ const result = typeof previousResumeHook === "function" ? previousResumeHook.apply(this, args) : void 0;
1189
+ dialSdkDebugWarn(DEBUG_MODULE$2, "runtimeResumeHook", "returned", { result });
1190
+ return result;
658
1191
  } finally {
659
1192
  dispatchResume();
660
1193
  }
661
1194
  };
662
1195
  installedWindow.__watchFaceRuntimePause = pauseHook;
663
1196
  installedWindow.__watchFaceRuntimeResume = resumeHook;
1197
+ dialSdkDebugWarn(DEBUG_MODULE$2, "installLifecycleHooks", "returned", {
1198
+ hadOwnPauseHook,
1199
+ hadOwnResumeHook
1200
+ });
664
1201
  };
665
1202
  const uninstallLifecycleHooks = () => {
1203
+ dialSdkDebugWarn(DEBUG_MODULE$2, "uninstallLifecycleHooks", "called");
666
1204
  installedDocument?.removeEventListener("visibilitychange", handleVisibilityChange);
667
1205
  installedWindow?.removeEventListener("pagehide", dispatchPause);
668
1206
  installedWindow?.removeEventListener("freeze", dispatchPause);
@@ -682,26 +1220,46 @@ const uninstallLifecycleHooks = () => {
682
1220
  hadOwnResumeHook = false;
683
1221
  pauseHook = null;
684
1222
  resumeHook = null;
1223
+ dialSdkDebugWarn(DEBUG_MODULE$2, "uninstallLifecycleHooks", "returned");
685
1224
  };
686
1225
  const handleVisibilityChange = () => {
1226
+ dialSdkDebugWarn(DEBUG_MODULE$2, "handleVisibilityChange", "called");
687
1227
  if (isDrivingPageHidden()) dispatchPause();
688
1228
  else dispatchResume();
1229
+ dialSdkDebugWarn(DEBUG_MODULE$2, "handleVisibilityChange", "returned");
689
1230
  };
690
1231
  const dispatchPause = () => {
1232
+ dialSdkDebugWarn(DEBUG_MODULE$2, "dispatchPause", "called", { subscriberCount: subscribers.size });
691
1233
  for (const subscriber of [...subscribers]) safeInvoke(subscriber.pause);
1234
+ dialSdkDebugWarn(DEBUG_MODULE$2, "dispatchPause", "returned");
692
1235
  };
693
1236
  const dispatchResume = () => {
694
- if (isDrivingPageHidden()) return;
1237
+ dialSdkDebugWarn(DEBUG_MODULE$2, "dispatchResume", "called", { subscriberCount: subscribers.size });
1238
+ if (isDrivingPageHidden()) {
1239
+ dialSdkDebugWarn(DEBUG_MODULE$2, "dispatchResume", "ignored while hidden");
1240
+ return;
1241
+ }
695
1242
  for (const subscriber of [...subscribers]) safeInvoke(subscriber.resume);
1243
+ dialSdkDebugWarn(DEBUG_MODULE$2, "dispatchResume", "returned");
696
1244
  };
697
1245
  const safeInvoke = (callback) => {
1246
+ dialSdkDebugWarn(DEBUG_MODULE$2, "safeInvoke", "called");
698
1247
  try {
699
1248
  callback();
700
- } catch {}
1249
+ dialSdkDebugWarn(DEBUG_MODULE$2, "safeInvoke", "returned");
1250
+ } catch (error) {
1251
+ dialSdkDebugWarn(DEBUG_MODULE$2, "safeInvoke", "callback threw", error);
1252
+ }
701
1253
  };
702
1254
  //#endregion
703
1255
  //#region src/sensor/driving_status_controller.ts
704
- const createDrivingStatusController = (options = {}) => new DefaultDrivingStatusController(options);
1256
+ const DEBUG_MODULE$1 = "driving_status_controller.ts";
1257
+ const createDrivingStatusController = (options = {}) => {
1258
+ dialSdkDebugWarn(DEBUG_MODULE$1, "createDrivingStatusController", "called", { options });
1259
+ const result = new DefaultDrivingStatusController(options);
1260
+ dialSdkDebugWarn(DEBUG_MODULE$1, "createDrivingStatusController", "returned", { snapshot: result.getSnapshot() });
1261
+ return result;
1262
+ };
705
1263
  var DefaultDrivingStatusController = class {
706
1264
  constructor(options) {
707
1265
  this.listeners = /* @__PURE__ */ new Set();
@@ -721,16 +1279,34 @@ var DefaultDrivingStatusController = class {
721
1279
  this.pendingRead = null;
722
1280
  this.unsubscribePageLifecycle = null;
723
1281
  this.handleLifecyclePause = () => {
724
- if (!this.requestedRunning || this.lifecycleSuspended) return;
1282
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.handleLifecyclePause", "called", {
1283
+ requestedRunning: this.requestedRunning,
1284
+ lifecycleSuspended: this.lifecycleSuspended
1285
+ });
1286
+ if (!this.requestedRunning || this.lifecycleSuspended) {
1287
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.handleLifecyclePause", "ignored");
1288
+ return;
1289
+ }
725
1290
  this.lifecycleSuspended = true;
726
1291
  this.deactivatePolling();
727
1292
  this.resetTransientRecognition();
1293
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.handleLifecyclePause", "returned");
728
1294
  };
729
1295
  this.handleLifecycleResume = () => {
730
- if (!this.requestedRunning || !this.lifecycleSuspended || this.destroyed || isDrivingPageHidden()) return;
1296
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.handleLifecycleResume", "called", {
1297
+ requestedRunning: this.requestedRunning,
1298
+ lifecycleSuspended: this.lifecycleSuspended,
1299
+ destroyed: this.destroyed
1300
+ });
1301
+ if (!this.requestedRunning || !this.lifecycleSuspended || this.destroyed || isDrivingPageHidden()) {
1302
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.handleLifecycleResume", "ignored");
1303
+ return;
1304
+ }
731
1305
  this.lifecycleSuspended = false;
732
1306
  this.activatePolling();
1307
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.handleLifecycleResume", "returned");
733
1308
  };
1309
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.constructor", "called", { options });
734
1310
  this.sensorProvider = options.sensorProvider ?? defaultSensorProvider;
735
1311
  this.pollIntervalMs = requirePositiveFinite("pollIntervalMs", options.pollIntervalMs ?? 200);
736
1312
  this.unavailableFallbackMs = requirePositiveFinite("unavailableFallbackMs", options.unavailableFallbackMs ?? 3e3);
@@ -743,23 +1319,51 @@ var DefaultDrivingStatusController = class {
743
1319
  this.status = initialStatus;
744
1320
  this.baseStatus = isBaseStatus(initialStatus) ? initialStatus : "STOPPED";
745
1321
  this.statusCommittedAtMs = this.clock.now();
1322
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.constructor", "created", {
1323
+ initialStatus,
1324
+ baseStatus: this.baseStatus,
1325
+ pollIntervalMs: this.pollIntervalMs,
1326
+ unavailableFallbackMs: this.unavailableFallbackMs,
1327
+ tuning: this.tuning,
1328
+ managePageLifecycle: this.managePageLifecycle
1329
+ });
746
1330
  }
747
1331
  start() {
748
- if (this.destroyed || this.requestedRunning) return;
1332
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.start", "called", this.getSnapshot());
1333
+ if (this.destroyed || this.requestedRunning) {
1334
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.start", "ignored", {
1335
+ destroyed: this.destroyed,
1336
+ requestedRunning: this.requestedRunning
1337
+ });
1338
+ return;
1339
+ }
749
1340
  this.requestedRunning = true;
750
1341
  this.attachLifecycleListeners();
751
1342
  if (!this.lifecycleSuspended) this.activatePolling();
1343
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.start", "returned", this.getSnapshot());
752
1344
  }
753
1345
  stop() {
754
- if (this.destroyed || !this.requestedRunning) return;
1346
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.stop", "called", this.getSnapshot());
1347
+ if (this.destroyed || !this.requestedRunning) {
1348
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.stop", "ignored", {
1349
+ destroyed: this.destroyed,
1350
+ requestedRunning: this.requestedRunning
1351
+ });
1352
+ return;
1353
+ }
755
1354
  this.requestedRunning = false;
756
1355
  this.lifecycleSuspended = false;
757
1356
  this.detachLifecycleListeners();
758
1357
  this.deactivatePolling();
759
1358
  this.resetTransientRecognition();
1359
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.stop", "returned", this.getSnapshot());
760
1360
  }
761
1361
  destroy() {
762
- if (this.destroyed) return;
1362
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.destroy", "called", this.getSnapshot());
1363
+ if (this.destroyed) {
1364
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.destroy", "ignored");
1365
+ return;
1366
+ }
763
1367
  if (this.requestedRunning) this.stop();
764
1368
  else {
765
1369
  this.detachLifecycleListeners();
@@ -769,9 +1373,10 @@ var DefaultDrivingStatusController = class {
769
1373
  this.listeners.clear();
770
1374
  this.metricWindow.length = 0;
771
1375
  this.motionWindow.length = 0;
1376
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.destroy", "returned", this.getSnapshot());
772
1377
  }
773
1378
  getSnapshot() {
774
- return {
1379
+ const result = {
775
1380
  lifecycle: this.destroyed ? "destroyed" : this.polling ? "running" : "stopped",
776
1381
  status: this.status,
777
1382
  candidate: this.candidate,
@@ -781,25 +1386,59 @@ var DefaultDrivingStatusController = class {
781
1386
  unavailableSinceMs: this.unavailableSinceMs,
782
1387
  tuningVersion: this.tuning.version
783
1388
  };
1389
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.getSnapshot", "returned", { result });
1390
+ return result;
784
1391
  }
785
1392
  subscribe(listener) {
786
- if (this.destroyed) return noop;
1393
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.subscribe", "called", {
1394
+ destroyed: this.destroyed,
1395
+ listenerCount: this.listeners.size
1396
+ });
1397
+ if (this.destroyed) {
1398
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.subscribe", "returned noop");
1399
+ return noop;
1400
+ }
787
1401
  this.listeners.add(listener);
788
1402
  let subscribed = true;
1403
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.subscribe", "subscribed", { listenerCount: this.listeners.size });
789
1404
  return () => {
790
- if (!subscribed) return;
1405
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.unsubscribe", "called", { subscribed });
1406
+ if (!subscribed) {
1407
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.unsubscribe", "ignored");
1408
+ return;
1409
+ }
791
1410
  subscribed = false;
792
1411
  this.listeners.delete(listener);
1412
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.unsubscribe", "returned", { listenerCount: this.listeners.size });
793
1413
  };
794
1414
  }
795
1415
  activatePolling() {
796
- if (this.destroyed || this.polling || !this.requestedRunning || this.lifecycleSuspended) return;
1416
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.activatePolling", "called", {
1417
+ destroyed: this.destroyed,
1418
+ polling: this.polling,
1419
+ requestedRunning: this.requestedRunning,
1420
+ lifecycleSuspended: this.lifecycleSuspended,
1421
+ generation: this.generation
1422
+ });
1423
+ if (this.destroyed || this.polling || !this.requestedRunning || this.lifecycleSuspended) {
1424
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.activatePolling", "ignored");
1425
+ return;
1426
+ }
797
1427
  this.polling = true;
798
1428
  this.generation += 1;
799
1429
  this.schedulePoll(0, this.generation);
1430
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.activatePolling", "returned", { generation: this.generation });
800
1431
  }
801
1432
  deactivatePolling() {
802
- if (!this.polling && this.timer === void 0 && this.pendingRead === null) return;
1433
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.deactivatePolling", "called", {
1434
+ polling: this.polling,
1435
+ timer: this.timer,
1436
+ hasPendingRead: this.pendingRead !== null
1437
+ });
1438
+ if (!this.polling && this.timer === void 0 && this.pendingRead === null) {
1439
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.deactivatePolling", "ignored");
1440
+ return;
1441
+ }
803
1442
  this.polling = false;
804
1443
  this.generation += 1;
805
1444
  if (this.timer !== void 0) {
@@ -808,34 +1447,77 @@ var DefaultDrivingStatusController = class {
808
1447
  }
809
1448
  this.pendingRead?.abort();
810
1449
  this.pendingRead = null;
1450
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.deactivatePolling", "returned", { generation: this.generation });
811
1451
  }
812
1452
  schedulePoll(delayMs, generation) {
813
- if (!this.polling || generation !== this.generation || this.timer !== void 0) return;
1453
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.schedulePoll", "called", {
1454
+ delayMs,
1455
+ generation,
1456
+ currentGeneration: this.generation,
1457
+ polling: this.polling,
1458
+ timer: this.timer
1459
+ });
1460
+ if (!this.polling || generation !== this.generation || this.timer !== void 0) {
1461
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.schedulePoll", "ignored");
1462
+ return;
1463
+ }
814
1464
  this.timer = this.clock.setTimeout(() => {
1465
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.schedulePoll.callback", "called", { generation });
815
1466
  this.timer = void 0;
816
1467
  this.poll(generation);
817
1468
  }, delayMs);
1469
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.schedulePoll", "scheduled", {
1470
+ delayMs,
1471
+ generation,
1472
+ timer: this.timer
1473
+ });
818
1474
  }
819
1475
  async poll(generation) {
820
- if (!this.polling || generation !== this.generation || this.pendingRead !== null) return;
1476
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.poll", "called", {
1477
+ generation,
1478
+ currentGeneration: this.generation,
1479
+ polling: this.polling,
1480
+ hasPendingRead: this.pendingRead !== null
1481
+ });
1482
+ if (!this.polling || generation !== this.generation || this.pendingRead !== null) {
1483
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.poll", "ignored");
1484
+ return;
1485
+ }
821
1486
  const pendingRead = new AbortController();
822
1487
  this.pendingRead = pendingRead;
823
1488
  try {
824
1489
  const payload = await this.sensorProvider(pendingRead.signal);
825
- if (!this.polling || generation !== this.generation || pendingRead.signal.aborted) return;
1490
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.poll", "provider resolved", { payload });
1491
+ if (!this.polling || generation !== this.generation || pendingRead.signal.aborted) {
1492
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.poll", "discarded provider result");
1493
+ return;
1494
+ }
826
1495
  const metrics = extractDrivingSnapshotMetrics(payload, this.tuning);
827
1496
  const accelerometerSample = extractFreshAccelerometerSample(payload, this.tuning.maxSampleAgeMs);
828
1497
  if (metrics === null || accelerometerSample === null) this.processUnavailable("invalid_or_stale_snapshot");
829
1498
  else this.processAvailable(metrics, accelerometerSample);
830
1499
  } catch (error) {
831
- if (!this.polling || generation !== this.generation || pendingRead.signal.aborted || isAbortError$1(error)) return;
1500
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.poll", "provider rejected", error);
1501
+ if (!this.polling || generation !== this.generation || pendingRead.signal.aborted || isAbortError$1(error)) {
1502
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.poll", "ignored rejection");
1503
+ return;
1504
+ }
832
1505
  this.processUnavailable("provider_error");
833
1506
  } finally {
834
1507
  if (this.pendingRead === pendingRead) this.pendingRead = null;
835
1508
  if (this.polling && generation === this.generation) this.schedulePoll(this.pollIntervalMs, generation);
1509
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.poll", "completed", {
1510
+ generation,
1511
+ polling: this.polling,
1512
+ currentGeneration: this.generation
1513
+ });
836
1514
  }
837
1515
  }
838
1516
  processAvailable(rawMetrics, accelerometerSample) {
1517
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processAvailable", "called", {
1518
+ rawMetrics,
1519
+ accelerometerSample
1520
+ });
839
1521
  const now = this.clock.now();
840
1522
  this.lastAvailableAtMs = now;
841
1523
  this.unavailableSinceMs = null;
@@ -852,18 +1534,42 @@ var DefaultDrivingStatusController = class {
852
1534
  const motionIntensity = this.recordMotionSample(accelerometerSample, rawMetrics.capturedAtMs);
853
1535
  const nextCandidate = classifyControllerCandidate(rawMetrics, smoothedMetrics, motionIntensity, this.status, this.baseStatus, this.tuning);
854
1536
  this.processCandidate(nextCandidate, now);
1537
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processAvailable", "returned", {
1538
+ rawMetrics,
1539
+ smoothedMetrics,
1540
+ motionIntensity,
1541
+ nextCandidate,
1542
+ snapshot: this.getSnapshot()
1543
+ });
855
1544
  }
856
1545
  recordMotionSample(sample, capturedAtMs) {
1546
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.recordMotionSample", "called", {
1547
+ sample,
1548
+ capturedAtMs,
1549
+ motionWindow: this.motionWindow
1550
+ });
857
1551
  if (!this.motionWindow.some((existing) => existing.sampledAtMs === sample.sampledAtMs)) {
858
1552
  this.motionWindow.push(sample);
859
1553
  this.motionWindow.sort((left, right) => left.sampledAtMs - right.sampledAtMs);
860
1554
  }
861
1555
  const cutoffMs = capturedAtMs - this.tuning.motionWindowMs;
862
1556
  while (this.motionWindow[0] && this.motionWindow[0].sampledAtMs <= cutoffMs) this.motionWindow.shift();
863
- if (this.motionWindow.length < this.tuning.motionMinimumSamples) return null;
864
- return combinedAxisStandardDeviation(this.motionWindow);
1557
+ if (this.motionWindow.length < this.tuning.motionMinimumSamples) {
1558
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.recordMotionSample", "returned warmup", {
1559
+ result: null,
1560
+ motionWindow: this.motionWindow
1561
+ });
1562
+ return null;
1563
+ }
1564
+ const result = combinedAxisStandardDeviation(this.motionWindow);
1565
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.recordMotionSample", "returned", {
1566
+ result,
1567
+ motionWindow: this.motionWindow
1568
+ });
1569
+ return result;
865
1570
  }
866
1571
  processUnavailable(category) {
1572
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processUnavailable", "called", { category });
867
1573
  const now = this.clock.now();
868
1574
  if (this.unavailableSinceMs === null) this.unavailableSinceMs = now;
869
1575
  const unavailableForMs = Math.max(0, now - this.unavailableSinceMs);
@@ -877,7 +1583,13 @@ var DefaultDrivingStatusController = class {
877
1583
  category,
878
1584
  tuningVersion: this.tuning.version
879
1585
  });
880
- if (unavailableForMs < this.unavailableFallbackMs || this.fallbackApplied) return;
1586
+ if (unavailableForMs < this.unavailableFallbackMs || this.fallbackApplied) {
1587
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processUnavailable", "returned while holding", {
1588
+ unavailableForMs,
1589
+ fallbackApplied: this.fallbackApplied
1590
+ });
1591
+ return;
1592
+ }
881
1593
  this.fallbackApplied = true;
882
1594
  this.emitDiagnostic({
883
1595
  type: "fallback_to_stopped",
@@ -886,10 +1598,22 @@ var DefaultDrivingStatusController = class {
886
1598
  tuningVersion: this.tuning.version
887
1599
  });
888
1600
  this.commit("STOPPED", now, "unavailable_fallback", true);
1601
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processUnavailable", "returned after fallback", {
1602
+ unavailableForMs,
1603
+ snapshot: this.getSnapshot()
1604
+ });
889
1605
  }
890
1606
  processCandidate(nextCandidate, now) {
1607
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processCandidate", "called", {
1608
+ nextCandidate,
1609
+ now,
1610
+ currentStatus: this.status,
1611
+ candidate: this.candidate,
1612
+ candidateConfirmationCount: this.candidateConfirmationCount
1613
+ });
891
1614
  if (nextCandidate === this.status) {
892
1615
  this.setCandidate(null, now);
1616
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processCandidate", "returned current status");
893
1617
  return;
894
1618
  }
895
1619
  if (nextCandidate !== this.candidate) {
@@ -897,7 +1621,14 @@ var DefaultDrivingStatusController = class {
897
1621
  this.candidateConfirmationCount = 1;
898
1622
  this.heldCandidate = null;
899
1623
  } else this.candidateConfirmationCount += 1;
900
- if (this.candidateConfirmationCount < this.tuning.confirmationSamples[nextCandidate]) return;
1624
+ if (this.candidateConfirmationCount < this.tuning.confirmationSamples[nextCandidate]) {
1625
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processCandidate", "awaiting confirmation", {
1626
+ nextCandidate,
1627
+ candidateConfirmationCount: this.candidateConfirmationCount,
1628
+ required: this.tuning.confirmationSamples[nextCandidate]
1629
+ });
1630
+ return;
1631
+ }
901
1632
  const elapsedMs = Math.max(0, now - this.statusCommittedAtMs);
902
1633
  const remainingMs = Math.max(0, this.tuning.minimumDisplayMs[this.status] - elapsedMs);
903
1634
  const canPreempt = CAR_RUNNING_STATUS_PRIORITY[nextCandidate] > CAR_RUNNING_STATUS_PRIORITY[this.status];
@@ -913,13 +1644,31 @@ var DefaultDrivingStatusController = class {
913
1644
  tuningVersion: this.tuning.version
914
1645
  });
915
1646
  }
1647
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processCandidate", "held by minimum duration", {
1648
+ nextCandidate,
1649
+ remainingMs
1650
+ });
916
1651
  return;
917
1652
  }
918
1653
  this.commit(nextCandidate, now, "candidate_confirmed");
1654
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.processCandidate", "returned after commit", { snapshot: this.getSnapshot() });
919
1655
  }
920
1656
  commit(nextStatus, now, reason, force = false) {
921
- if (!force && nextStatus === this.status) return;
922
- if (nextStatus === this.status) return;
1657
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.commit", "called", {
1658
+ nextStatus,
1659
+ now,
1660
+ reason,
1661
+ force,
1662
+ currentStatus: this.status
1663
+ });
1664
+ if (!force && nextStatus === this.status) {
1665
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.commit", "ignored unchanged status");
1666
+ return;
1667
+ }
1668
+ if (nextStatus === this.status) {
1669
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.commit", "ignored forced unchanged status");
1670
+ return;
1671
+ }
923
1672
  const previousStatus = this.status;
924
1673
  this.status = nextStatus;
925
1674
  if (isBaseStatus(nextStatus)) this.baseStatus = nextStatus;
@@ -942,10 +1691,21 @@ var DefaultDrivingStatusController = class {
942
1691
  reason,
943
1692
  tuningVersion: this.tuning.version
944
1693
  });
1694
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.commit", "returned", {
1695
+ event,
1696
+ listenerCount: this.listeners.size,
1697
+ snapshot: this.getSnapshot()
1698
+ });
945
1699
  }
946
1700
  setCandidate(candidate, now) {
1701
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.setCandidate", "called", {
1702
+ candidate,
1703
+ now,
1704
+ currentCandidate: this.candidate
1705
+ });
947
1706
  if (candidate === this.candidate) {
948
1707
  if (candidate === null) this.candidateConfirmationCount = 0;
1708
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.setCandidate", "returned unchanged", { candidateConfirmationCount: this.candidateConfirmationCount });
949
1709
  return;
950
1710
  }
951
1711
  const previousCandidate = this.candidate;
@@ -959,8 +1719,17 @@ var DefaultDrivingStatusController = class {
959
1719
  previousCandidate,
960
1720
  tuningVersion: this.tuning.version
961
1721
  });
1722
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.setCandidate", "returned", {
1723
+ candidate,
1724
+ previousCandidate
1725
+ });
962
1726
  }
963
1727
  resetTransientRecognition() {
1728
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.resetTransientRecognition", "called", {
1729
+ metricWindow: this.metricWindow,
1730
+ motionWindow: this.motionWindow,
1731
+ candidate: this.candidate
1732
+ });
964
1733
  this.metricWindow.length = 0;
965
1734
  this.motionWindow.length = 0;
966
1735
  this.candidate = null;
@@ -968,54 +1737,144 @@ var DefaultDrivingStatusController = class {
968
1737
  this.unavailableSinceMs = null;
969
1738
  this.fallbackApplied = false;
970
1739
  this.heldCandidate = null;
1740
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.resetTransientRecognition", "returned");
971
1741
  }
972
1742
  emitDiagnostic(event) {
1743
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.emitDiagnostic", "called", {
1744
+ event,
1745
+ hasListener: this.onDiagnostic !== void 0
1746
+ });
973
1747
  if (this.onDiagnostic) safeCall(this.onDiagnostic, event);
1748
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.emitDiagnostic", "returned", { event });
974
1749
  }
975
1750
  attachLifecycleListeners() {
976
- if (!this.managePageLifecycle || this.unsubscribePageLifecycle !== null) return;
1751
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.attachLifecycleListeners", "called", {
1752
+ managePageLifecycle: this.managePageLifecycle,
1753
+ attached: this.unsubscribePageLifecycle !== null
1754
+ });
1755
+ if (!this.managePageLifecycle || this.unsubscribePageLifecycle !== null) {
1756
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.attachLifecycleListeners", "ignored");
1757
+ return;
1758
+ }
977
1759
  this.unsubscribePageLifecycle = subscribeDrivingPageLifecycle(this.handleLifecyclePause, this.handleLifecycleResume);
1760
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.attachLifecycleListeners", "returned");
978
1761
  }
979
1762
  detachLifecycleListeners() {
1763
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.detachLifecycleListeners", "called", { attached: this.unsubscribePageLifecycle !== null });
980
1764
  this.unsubscribePageLifecycle?.();
981
1765
  this.unsubscribePageLifecycle = null;
1766
+ dialSdkDebugWarn(DEBUG_MODULE$1, "DefaultDrivingStatusController.detachLifecycleListeners", "returned");
982
1767
  }
983
1768
  };
984
1769
  const classifyControllerCandidate = (raw, smoothed, motionIntensity, current, baseStatus, tuning) => {
1770
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyControllerCandidate", "called", {
1771
+ raw,
1772
+ smoothed,
1773
+ motionIntensity,
1774
+ current,
1775
+ baseStatus,
1776
+ tuning
1777
+ });
985
1778
  const entry = classifyEntryCandidate(raw, smoothed, motionIntensity, baseStatus, tuning);
986
- if (!retainsCurrentStatus(raw, smoothed, motionIntensity, current, tuning)) return entry;
987
- if (entry === current) return current;
988
- if (CAR_RUNNING_STATUS_PRIORITY[entry] > CAR_RUNNING_STATUS_PRIORITY[current]) return entry;
989
- if (isOppositeTurn(entry, current)) return entry;
990
- if ((entry === "STOPPED" || entry === "STEADY_DRIVING") && (current === "STOPPED" || current === "STEADY_DRIVING")) return entry;
991
- return current;
1779
+ const retained = retainsCurrentStatus(raw, smoothed, motionIntensity, current, tuning);
1780
+ const result = !retained || CAR_RUNNING_STATUS_PRIORITY[entry] > CAR_RUNNING_STATUS_PRIORITY[current] || isOppositeTurn(entry, current) || (entry === "STOPPED" || entry === "STEADY_DRIVING") && (current === "STOPPED" || current === "STEADY_DRIVING") ? entry : current;
1781
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyControllerCandidate", "returned", {
1782
+ entry,
1783
+ retained,
1784
+ result
1785
+ });
1786
+ return result;
992
1787
  };
993
1788
  const classifyEntryCandidate = (raw, smoothed, motionIntensity, baseStatus, tuning) => {
994
- if (raw.longitudinal <= -tuning.rapidLongitudinalThreshold) return "SUDDEN_BRAKING";
995
- if (raw.longitudinal >= tuning.rapidLongitudinalThreshold) return "RAPID_ACCELERATION";
996
- if (Math.abs(smoothed.yaw) >= tuning.turnYawThreshold) return smoothed.yaw > 0 ? "LEFT_TURN" : "RIGHT_TURN";
997
- if (Math.abs(smoothed.lateral) >= tuning.turnLateralThreshold) return smoothed.lateral < 0 ? "LEFT_TURN" : "RIGHT_TURN";
998
- if (smoothed.longitudinal <= -tuning.longitudinalThreshold) return "BRAKING";
999
- if (smoothed.longitudinal >= tuning.longitudinalThreshold) return "ACCELERATION";
1000
- if (motionIntensity === null) return baseStatus;
1001
- if (motionIntensity > tuning.drivingMotionThreshold || smoothed.gyroMagnitude > tuning.stoppedGyroThreshold) return "STEADY_DRIVING";
1002
- if (motionIntensity < tuning.stoppedMotionThreshold) return "STOPPED";
1789
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "called", {
1790
+ raw,
1791
+ smoothed,
1792
+ motionIntensity,
1793
+ baseStatus,
1794
+ tuning
1795
+ });
1796
+ if (raw.longitudinal <= -tuning.rapidLongitudinalThreshold) {
1797
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result: "SUDDEN_BRAKING" });
1798
+ return "SUDDEN_BRAKING";
1799
+ }
1800
+ if (raw.longitudinal >= tuning.rapidLongitudinalThreshold) {
1801
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result: "RAPID_ACCELERATION" });
1802
+ return "RAPID_ACCELERATION";
1803
+ }
1804
+ if (Math.abs(smoothed.yaw) >= tuning.turnYawThreshold) {
1805
+ const result = smoothed.yaw > 0 ? "LEFT_TURN" : "RIGHT_TURN";
1806
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result });
1807
+ return result;
1808
+ }
1809
+ if (Math.abs(smoothed.lateral) >= tuning.turnLateralThreshold) {
1810
+ const result = smoothed.lateral < 0 ? "LEFT_TURN" : "RIGHT_TURN";
1811
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result });
1812
+ return result;
1813
+ }
1814
+ if (smoothed.longitudinal <= -tuning.longitudinalThreshold) {
1815
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result: "BRAKING" });
1816
+ return "BRAKING";
1817
+ }
1818
+ if (smoothed.longitudinal >= tuning.longitudinalThreshold) {
1819
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result: "ACCELERATION" });
1820
+ return "ACCELERATION";
1821
+ }
1822
+ if (motionIntensity === null) {
1823
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned base status", { result: baseStatus });
1824
+ return baseStatus;
1825
+ }
1826
+ if (motionIntensity > tuning.drivingMotionThreshold || smoothed.gyroMagnitude > tuning.stoppedGyroThreshold) {
1827
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result: "STEADY_DRIVING" });
1828
+ return "STEADY_DRIVING";
1829
+ }
1830
+ if (motionIntensity < tuning.stoppedMotionThreshold) {
1831
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned", { result: "STOPPED" });
1832
+ return "STOPPED";
1833
+ }
1834
+ dialSdkDebugWarn(DEBUG_MODULE$1, "classifyEntryCandidate", "returned base status", { result: baseStatus });
1003
1835
  return baseStatus;
1004
1836
  };
1005
1837
  const retainsCurrentStatus = (raw, smoothed, motionIntensity, current, tuning) => {
1838
+ dialSdkDebugWarn(DEBUG_MODULE$1, "retainsCurrentStatus", "called", {
1839
+ raw,
1840
+ smoothed,
1841
+ motionIntensity,
1842
+ current,
1843
+ tuning
1844
+ });
1006
1845
  const ratio = tuning.hysteresisRatio;
1846
+ let result;
1007
1847
  switch (current) {
1008
- case "SUDDEN_BRAKING": return raw.longitudinal <= -tuning.rapidLongitudinalThreshold * ratio;
1009
- case "RAPID_ACCELERATION": return raw.longitudinal >= tuning.rapidLongitudinalThreshold * ratio;
1010
- case "LEFT_TURN": return smoothed.yaw >= tuning.turnYawThreshold * ratio || smoothed.lateral <= -tuning.turnLateralThreshold * ratio;
1011
- case "RIGHT_TURN": return smoothed.yaw <= -tuning.turnYawThreshold * ratio || smoothed.lateral >= tuning.turnLateralThreshold * ratio;
1012
- case "BRAKING": return smoothed.longitudinal <= -tuning.longitudinalThreshold * ratio;
1013
- case "ACCELERATION": return smoothed.longitudinal >= tuning.longitudinalThreshold * ratio;
1014
- case "STOPPED": return (motionIntensity === null || motionIntensity <= tuning.drivingMotionThreshold) && smoothed.gyroMagnitude <= tuning.stoppedGyroThreshold;
1015
- case "STEADY_DRIVING": return motionIntensity === null || motionIntensity >= tuning.stoppedMotionThreshold || smoothed.gyroMagnitude > tuning.stoppedGyroThreshold;
1848
+ case "SUDDEN_BRAKING":
1849
+ result = raw.longitudinal <= -tuning.rapidLongitudinalThreshold * ratio;
1850
+ break;
1851
+ case "RAPID_ACCELERATION":
1852
+ result = raw.longitudinal >= tuning.rapidLongitudinalThreshold * ratio;
1853
+ break;
1854
+ case "LEFT_TURN":
1855
+ result = smoothed.yaw >= tuning.turnYawThreshold * ratio || smoothed.lateral <= -tuning.turnLateralThreshold * ratio;
1856
+ break;
1857
+ case "RIGHT_TURN":
1858
+ result = smoothed.yaw <= -tuning.turnYawThreshold * ratio || smoothed.lateral >= tuning.turnLateralThreshold * ratio;
1859
+ break;
1860
+ case "BRAKING":
1861
+ result = smoothed.longitudinal <= -tuning.longitudinalThreshold * ratio;
1862
+ break;
1863
+ case "ACCELERATION":
1864
+ result = smoothed.longitudinal >= tuning.longitudinalThreshold * ratio;
1865
+ break;
1866
+ case "STOPPED":
1867
+ result = (motionIntensity === null || motionIntensity <= tuning.drivingMotionThreshold) && smoothed.gyroMagnitude <= tuning.stoppedGyroThreshold;
1868
+ break;
1869
+ case "STEADY_DRIVING":
1870
+ result = motionIntensity === null || motionIntensity >= tuning.stoppedMotionThreshold || smoothed.gyroMagnitude > tuning.stoppedGyroThreshold;
1871
+ break;
1016
1872
  }
1873
+ dialSdkDebugWarn(DEBUG_MODULE$1, "retainsCurrentStatus", "returned", { result });
1874
+ return result;
1017
1875
  };
1018
1876
  const averageMetrics = (metrics) => {
1877
+ dialSdkDebugWarn(DEBUG_MODULE$1, "averageMetrics", "called", { metrics });
1019
1878
  const result = {
1020
1879
  capturedAtMs: metrics[metrics.length - 1]?.capturedAtMs ?? 0,
1021
1880
  longitudinal: 0,
@@ -1037,25 +1896,45 @@ const averageMetrics = (metrics) => {
1037
1896
  result.yaw /= count;
1038
1897
  result.motionIntensity /= count;
1039
1898
  result.gyroMagnitude /= count;
1899
+ dialSdkDebugWarn(DEBUG_MODULE$1, "averageMetrics", "returned", { result });
1040
1900
  return result;
1041
1901
  };
1042
1902
  const extractFreshAccelerometerSample = (info, maxSampleAgeMs) => {
1903
+ dialSdkDebugWarn(DEBUG_MODULE$1, "extractFreshAccelerometerSample", "called", {
1904
+ info,
1905
+ maxSampleAgeMs
1906
+ });
1043
1907
  const metric = info?.accelerometer;
1044
- if (!metric?.available || !Number.isFinite(info.capturedAtMs) || !Number.isFinite(metric.sampledAtMs)) return null;
1908
+ if (!metric?.available || !Number.isFinite(info.capturedAtMs) || !Number.isFinite(metric.sampledAtMs)) {
1909
+ dialSdkDebugWarn(DEBUG_MODULE$1, "extractFreshAccelerometerSample", "returned", { result: null });
1910
+ return null;
1911
+ }
1045
1912
  const ageMs = info.capturedAtMs - metric.sampledAtMs;
1046
- if (ageMs < 0 || ageMs > maxSampleAgeMs) return null;
1913
+ if (ageMs < 0 || ageMs > maxSampleAgeMs) {
1914
+ dialSdkDebugWarn(DEBUG_MODULE$1, "extractFreshAccelerometerSample", "returned stale sample", {
1915
+ result: null,
1916
+ ageMs
1917
+ });
1918
+ return null;
1919
+ }
1047
1920
  const { x, y, z } = metric.value;
1048
1921
  if (![
1049
1922
  x,
1050
1923
  y,
1051
1924
  z
1052
- ].every(Number.isFinite)) return null;
1053
- return {
1925
+ ].every(Number.isFinite)) {
1926
+ dialSdkDebugWarn(DEBUG_MODULE$1, "extractFreshAccelerometerSample", "returned invalid vector", { result: null });
1927
+ return null;
1928
+ }
1929
+ const result = {
1054
1930
  sampledAtMs: metric.sampledAtMs,
1055
1931
  value: metric.value
1056
1932
  };
1933
+ dialSdkDebugWarn(DEBUG_MODULE$1, "extractFreshAccelerometerSample", "returned", { result });
1934
+ return result;
1057
1935
  };
1058
1936
  const combinedAxisStandardDeviation = (samples) => {
1937
+ dialSdkDebugWarn(DEBUG_MODULE$1, "combinedAxisStandardDeviation", "called", { samples });
1059
1938
  const count = samples.length;
1060
1939
  let meanX = 0;
1061
1940
  let meanY = 0;
@@ -1076,34 +1955,118 @@ const combinedAxisStandardDeviation = (samples) => {
1076
1955
  varianceY += (sample.value.y - meanY) ** 2;
1077
1956
  varianceZ += (sample.value.z - meanZ) ** 2;
1078
1957
  }
1079
- return Math.sqrt((varianceX + varianceY + varianceZ) / count);
1958
+ const result = Math.sqrt((varianceX + varianceY + varianceZ) / count);
1959
+ dialSdkDebugWarn(DEBUG_MODULE$1, "combinedAxisStandardDeviation", "returned", {
1960
+ meanX,
1961
+ meanY,
1962
+ meanZ,
1963
+ varianceX,
1964
+ varianceY,
1965
+ varianceZ,
1966
+ result
1967
+ });
1968
+ return result;
1080
1969
  };
1081
1970
  const defaultSensorProvider = () => {
1971
+ dialSdkDebugWarn(DEBUG_MODULE$1, "defaultSensorProvider", "called");
1082
1972
  const runtimeGlobal = globalThis;
1083
- if (typeof runtimeGlobal.unifiedSensorInfo !== "function") return Promise.reject(/* @__PURE__ */ new Error("window.unifiedSensorInfo is unavailable"));
1084
- return runtimeGlobal.unifiedSensorInfo();
1973
+ if (typeof runtimeGlobal.unifiedSensorInfo !== "function") {
1974
+ const error = /* @__PURE__ */ new Error("window.unifiedSensorInfo is unavailable");
1975
+ dialSdkDebugWarn(DEBUG_MODULE$1, "defaultSensorProvider", "rejected", error);
1976
+ return Promise.reject(error);
1977
+ }
1978
+ try {
1979
+ const result = runtimeGlobal.unifiedSensorInfo();
1980
+ result.then((payload) => dialSdkDebugWarn(DEBUG_MODULE$1, "defaultSensorProvider", "resolved", { payload }), (error) => dialSdkDebugWarn(DEBUG_MODULE$1, "defaultSensorProvider", "rejected", error));
1981
+ return result;
1982
+ } catch (error) {
1983
+ dialSdkDebugWarn(DEBUG_MODULE$1, "defaultSensorProvider", "threw", error);
1984
+ throw error;
1985
+ }
1085
1986
  };
1086
1987
  const systemClock = {
1087
- now: () => Date.now(),
1088
- setTimeout: (callback, delayMs) => globalThis.setTimeout(callback, delayMs),
1089
- clearTimeout: (handle) => globalThis.clearTimeout(handle)
1988
+ now: () => {
1989
+ const result = Date.now();
1990
+ dialSdkDebugWarn(DEBUG_MODULE$1, "systemClock.now", "returned", { result });
1991
+ return result;
1992
+ },
1993
+ setTimeout: (callback, delayMs) => {
1994
+ const result = globalThis.setTimeout(callback, delayMs);
1995
+ dialSdkDebugWarn(DEBUG_MODULE$1, "systemClock.setTimeout", "returned", {
1996
+ delayMs,
1997
+ result
1998
+ });
1999
+ return result;
2000
+ },
2001
+ clearTimeout: (handle) => {
2002
+ dialSdkDebugWarn(DEBUG_MODULE$1, "systemClock.clearTimeout", "called", { handle });
2003
+ globalThis.clearTimeout(handle);
2004
+ dialSdkDebugWarn(DEBUG_MODULE$1, "systemClock.clearTimeout", "returned");
2005
+ }
2006
+ };
2007
+ const isOppositeTurn = (candidate, current) => {
2008
+ const result = candidate === "LEFT_TURN" && current === "RIGHT_TURN" || candidate === "RIGHT_TURN" && current === "LEFT_TURN";
2009
+ dialSdkDebugWarn(DEBUG_MODULE$1, "isOppositeTurn", "returned", {
2010
+ candidate,
2011
+ current,
2012
+ result
2013
+ });
2014
+ return result;
2015
+ };
2016
+ const isBaseStatus = (status) => {
2017
+ const result = status === "STOPPED" || status === "STEADY_DRIVING";
2018
+ dialSdkDebugWarn(DEBUG_MODULE$1, "isBaseStatus", "returned", {
2019
+ status,
2020
+ result
2021
+ });
2022
+ return result;
2023
+ };
2024
+ const isAbortError$1 = (error) => {
2025
+ const result = error instanceof Error && error.name === "AbortError";
2026
+ dialSdkDebugWarn(DEBUG_MODULE$1, "isAbortError", "returned", {
2027
+ error,
2028
+ result
2029
+ });
2030
+ return result;
1090
2031
  };
1091
- const isOppositeTurn = (candidate, current) => candidate === "LEFT_TURN" && current === "RIGHT_TURN" || candidate === "RIGHT_TURN" && current === "LEFT_TURN";
1092
- const isBaseStatus = (status) => status === "STOPPED" || status === "STEADY_DRIVING";
1093
- const isAbortError$1 = (error) => error instanceof Error && error.name === "AbortError";
1094
2032
  const requirePositiveFinite = (name, value) => {
1095
- if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${name} must be a positive finite number`);
2033
+ dialSdkDebugWarn(DEBUG_MODULE$1, "requirePositiveFinite", "called", {
2034
+ name,
2035
+ value
2036
+ });
2037
+ if (!Number.isFinite(value) || value <= 0) {
2038
+ const error = /* @__PURE__ */ new RangeError(`${name} must be a positive finite number`);
2039
+ dialSdkDebugWarn(DEBUG_MODULE$1, "requirePositiveFinite", "threw", error);
2040
+ throw error;
2041
+ }
2042
+ dialSdkDebugWarn(DEBUG_MODULE$1, "requirePositiveFinite", "returned", { result: value });
1096
2043
  return value;
1097
2044
  };
1098
2045
  const safeCall = (callback, value) => {
2046
+ dialSdkDebugWarn(DEBUG_MODULE$1, "safeCall", "called", { value });
1099
2047
  try {
1100
2048
  callback(value);
1101
- } catch {}
2049
+ dialSdkDebugWarn(DEBUG_MODULE$1, "safeCall", "returned");
2050
+ } catch (error) {
2051
+ dialSdkDebugWarn(DEBUG_MODULE$1, "safeCall", "callback threw", error);
2052
+ }
2053
+ };
2054
+ const noop = () => {
2055
+ dialSdkDebugWarn(DEBUG_MODULE$1, "noop", "called and returned");
1102
2056
  };
1103
- const noop = () => {};
1104
2057
  //#endregion
1105
2058
  //#region src/sensor/driving_expression_player.ts
1106
- const createDrivingExpressionPlayer = (container, options) => new DefaultDrivingExpressionPlayer(container, options);
2059
+ const DEBUG_MODULE = "driving_expression_player.ts";
2060
+ const MAX_RETAINED_IMAGES = 3;
2061
+ const createDrivingExpressionPlayer = (container, options) => {
2062
+ dialSdkDebugWarn(DEBUG_MODULE, "createDrivingExpressionPlayer", "called", {
2063
+ container,
2064
+ options
2065
+ });
2066
+ const result = new DefaultDrivingExpressionPlayer(container, options);
2067
+ dialSdkDebugWarn(DEBUG_MODULE, "createDrivingExpressionPlayer", "returned", { snapshot: result.getSnapshot() });
2068
+ return result;
2069
+ };
1107
2070
  var DefaultDrivingExpressionPlayer = class {
1108
2071
  constructor(container, options) {
1109
2072
  this.status = null;
@@ -1124,17 +2087,37 @@ var DefaultDrivingExpressionPlayer = class {
1124
2087
  this.reusableVideo = null;
1125
2088
  this.activeTgs = null;
1126
2089
  this.unsubscribePageLifecycle = null;
2090
+ this.retainedImages = /* @__PURE__ */ new Map();
2091
+ this.preloadedHintUrls = /* @__PURE__ */ new Set();
1127
2092
  this.handleLifecyclePause = () => {
1128
- if (this.destroyed || this.lifecycleSuspended) return;
2093
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleLifecyclePause", "called");
2094
+ if (this.destroyed || this.lifecycleSuspended) {
2095
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleLifecyclePause", "ignored");
2096
+ return;
2097
+ }
1129
2098
  this.lifecycleSuspended = true;
1130
2099
  this.updatePauseState();
2100
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleLifecyclePause", "returned");
1131
2101
  };
1132
2102
  this.handleLifecycleResume = () => {
1133
- if (this.destroyed || !this.lifecycleSuspended) return;
2103
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleLifecycleResume", "called");
2104
+ if (this.destroyed || !this.lifecycleSuspended) {
2105
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleLifecycleResume", "ignored");
2106
+ return;
2107
+ }
1134
2108
  this.lifecycleSuspended = false;
1135
2109
  this.updatePauseState();
2110
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleLifecycleResume", "returned");
1136
2111
  };
1137
- if (!container || typeof container.replaceChildren !== "function") throw new TypeError("container must be an HTMLElement-like DOM container");
2112
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.constructor", "called", {
2113
+ container,
2114
+ options
2115
+ });
2116
+ if (!container || typeof container.replaceChildren !== "function") {
2117
+ const error = /* @__PURE__ */ new TypeError("container must be an HTMLElement-like DOM container");
2118
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.constructor", "threw", error);
2119
+ throw error;
2120
+ }
1138
2121
  this.container = container;
1139
2122
  this.document = container.ownerDocument;
1140
2123
  this.config = options.config;
@@ -1149,9 +2132,25 @@ var DefaultDrivingExpressionPlayer = class {
1149
2132
  this.maxTgsJsonBytes = positiveFinite("maxTgsJsonBytes", options.maxTgsJsonBytes ?? 8 * 1024 * 1024);
1150
2133
  this.maxTgsLayers = positiveFinite("maxTgsLayers", options.maxTgsLayers ?? 500);
1151
2134
  if (options.managePageLifecycle ?? true) this.unsubscribePageLifecycle = subscribeDrivingPageLifecycle(this.handleLifecyclePause, this.handleLifecycleResume);
2135
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.constructor", "created", {
2136
+ loadTimeoutMs: this.loadTimeoutMs,
2137
+ retryBackoffMs: this.retryBackoffMs,
2138
+ fit: this.fit,
2139
+ maxTgsCompressedBytes: this.maxTgsCompressedBytes,
2140
+ maxTgsJsonBytes: this.maxTgsJsonBytes,
2141
+ maxTgsLayers: this.maxTgsLayers,
2142
+ managesPageLifecycle: this.unsubscribePageLifecycle !== null
2143
+ });
1152
2144
  }
1153
2145
  async show(status) {
1154
- if (this.destroyed || status === this.status && this.phase !== "idle") return;
2146
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.show", "called", {
2147
+ status,
2148
+ snapshot: this.getSnapshot()
2149
+ });
2150
+ if (this.destroyed || status === this.status && this.phase !== "idle") {
2151
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.show", "ignored");
2152
+ return;
2153
+ }
1155
2154
  this.status = status;
1156
2155
  const operation = this.beginOperation();
1157
2156
  const configured = this.config.states[status];
@@ -1159,36 +2158,59 @@ var DefaultDrivingExpressionPlayer = class {
1159
2158
  const fallback = this.fallbacks?.[status];
1160
2159
  if (fallback === void 0) {
1161
2160
  this.handleFailure(status, null, new DrivingExpressionResolutionError(status), "invalid_config", operation, false);
2161
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.show", "returned after missing config");
1162
2162
  return;
1163
2163
  }
1164
2164
  this.desiredMedia = fallback;
1165
2165
  if (this.paused) {
1166
2166
  this.phase = "idle";
2167
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.show", "deferred fallback while paused");
1167
2168
  return;
1168
2169
  }
1169
2170
  this.renderFallback(status, fallback);
2171
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.show", "returned fallback", { snapshot: this.getSnapshot() });
1170
2172
  return;
1171
2173
  }
1172
2174
  const media = normalizeMedia(configured);
1173
2175
  this.desiredMedia = media;
1174
2176
  if (this.paused) {
1175
2177
  this.phase = "idle";
2178
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.show", "deferred media while paused", { media });
1176
2179
  return;
1177
2180
  }
1178
2181
  await this.load(status, media, operation);
2182
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.show", "resolved", {
2183
+ status,
2184
+ media,
2185
+ snapshot: this.getSnapshot()
2186
+ });
1179
2187
  }
1180
2188
  pause() {
1181
- if (this.destroyed || this.userPaused) return;
2189
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.pause", "called", this.getSnapshot());
2190
+ if (this.destroyed || this.userPaused) {
2191
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.pause", "ignored");
2192
+ return;
2193
+ }
1182
2194
  this.userPaused = true;
1183
2195
  this.updatePauseState();
2196
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.pause", "returned", this.getSnapshot());
1184
2197
  }
1185
2198
  resume() {
1186
- if (this.destroyed || !this.userPaused) return;
2199
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.resume", "called", this.getSnapshot());
2200
+ if (this.destroyed || !this.userPaused) {
2201
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.resume", "ignored");
2202
+ return;
2203
+ }
1187
2204
  this.userPaused = false;
1188
2205
  this.updatePauseState();
2206
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.resume", "returned", this.getSnapshot());
1189
2207
  }
1190
2208
  destroy() {
1191
- if (this.destroyed) return;
2209
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.destroy", "called", this.getSnapshot());
2210
+ if (this.destroyed) {
2211
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.destroy", "ignored");
2212
+ return;
2213
+ }
1192
2214
  this.destroyed = true;
1193
2215
  this.unsubscribePageLifecycle?.();
1194
2216
  this.unsubscribePageLifecycle = null;
@@ -1196,23 +2218,32 @@ var DefaultDrivingExpressionPlayer = class {
1196
2218
  this.failedOperation = null;
1197
2219
  this.cancelPendingWork();
1198
2220
  this.releaseActiveMedia();
2221
+ this.clearRetainedImages();
2222
+ this.preloadedHintUrls.clear();
1199
2223
  this.container.replaceChildren();
1200
2224
  this.status = null;
1201
2225
  this.desiredMedia = null;
1202
2226
  this.phase = "idle";
1203
2227
  this.mediaKind = null;
1204
2228
  this.errorCategory = null;
2229
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.destroy", "returned", this.getSnapshot());
1205
2230
  }
1206
2231
  getSnapshot() {
1207
- return {
2232
+ const result = {
1208
2233
  lifecycle: this.destroyed ? "destroyed" : this.paused ? "paused" : "active",
1209
2234
  status: this.status,
1210
2235
  phase: this.phase,
1211
2236
  mediaKind: this.mediaKind,
1212
2237
  errorCategory: this.errorCategory
1213
2238
  };
2239
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.getSnapshot", "returned", { result });
2240
+ return result;
1214
2241
  }
1215
2242
  beginOperation() {
2243
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.beginOperation", "called", {
2244
+ operation: this.operation,
2245
+ snapshot: this.getSnapshot()
2246
+ });
1216
2247
  this.operation += 1;
1217
2248
  this.failedOperation = null;
1218
2249
  this.cancelPendingWork();
@@ -1221,17 +2252,28 @@ var DefaultDrivingExpressionPlayer = class {
1221
2252
  this.phase = "loading";
1222
2253
  this.mediaKind = null;
1223
2254
  this.errorCategory = null;
2255
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.beginOperation", "returned", { operation: this.operation });
1224
2256
  return this.operation;
1225
2257
  }
1226
2258
  updatePauseState() {
2259
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.updatePauseState", "called", {
2260
+ userPaused: this.userPaused,
2261
+ lifecycleSuspended: this.lifecycleSuspended,
2262
+ paused: this.paused,
2263
+ snapshot: this.getSnapshot()
2264
+ });
1227
2265
  const shouldPause = this.userPaused || this.lifecycleSuspended;
1228
- if (shouldPause === this.paused) return;
2266
+ if (shouldPause === this.paused) {
2267
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.updatePauseState", "ignored unchanged state");
2268
+ return;
2269
+ }
1229
2270
  this.paused = shouldPause;
1230
2271
  if (shouldPause) {
1231
2272
  this.operation += 1;
1232
2273
  this.cancelPendingWork();
1233
2274
  this.activeVideo?.pause();
1234
2275
  this.activeTgs?.pause?.();
2276
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.updatePauseState", "paused", this.getSnapshot());
1235
2277
  return;
1236
2278
  }
1237
2279
  if (this.phase === "ready") {
@@ -1244,23 +2286,33 @@ var DefaultDrivingExpressionPlayer = class {
1244
2286
  video.play().catch((error) => this.handleActiveVideoFailure(video, status, media, operation, "decode", error));
1245
2287
  }
1246
2288
  this.activeTgs?.play?.();
2289
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.updatePauseState", "resumed ready media");
1247
2290
  return;
1248
2291
  }
1249
2292
  if (this.status !== null && this.desiredMedia !== null) {
1250
2293
  const operation = this.beginOperation();
1251
2294
  this.load(this.status, this.desiredMedia, operation);
1252
2295
  }
2296
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.updatePauseState", "returned", this.getSnapshot());
1253
2297
  }
1254
2298
  async load(status, media, operation) {
2299
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "called", {
2300
+ status,
2301
+ media,
2302
+ operation
2303
+ });
1255
2304
  const startedAt = Date.now();
1256
2305
  this.mediaKind = media.kind;
1257
2306
  if (media.kind === "emoji") {
1258
2307
  this.renderEmoji(media.text);
1259
2308
  this.markReady(status, media.kind, startedAt, operation);
2309
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "resolved emoji", { snapshot: this.getSnapshot() });
1260
2310
  return;
1261
2311
  }
1262
- if (firstInvalidMediaUrl(media) !== null) {
2312
+ const invalidUrl = firstInvalidMediaUrl(media);
2313
+ if (invalidUrl !== null) {
1263
2314
  this.handleFailure(status, media, /* @__PURE__ */ new Error("One or more media URLs are not long-lived public HTTPS URLs"), "invalid_config", operation);
2315
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "returned invalid URL", { invalidUrl });
1264
2316
  return;
1265
2317
  }
1266
2318
  const loadAbort = new AbortController();
@@ -1268,8 +2320,7 @@ var DefaultDrivingExpressionPlayer = class {
1268
2320
  try {
1269
2321
  switch (media.kind) {
1270
2322
  case "image":
1271
- this.renderConfiguredFallback(status, false);
1272
- await this.loadImage(media.url, loadAbort.signal, operation);
2323
+ await this.loadImage(status, media, loadAbort.signal, operation);
1273
2324
  break;
1274
2325
  case "video":
1275
2326
  this.renderLoadingPlaceholder(status, media.coverUrl, operation, loadAbort.signal);
@@ -1283,26 +2334,106 @@ var DefaultDrivingExpressionPlayer = class {
1283
2334
  await this.loadTgs(media.url, loadAbort.signal, operation);
1284
2335
  break;
1285
2336
  }
1286
- if (!this.isCurrent(operation) || this.failedOperation === operation) return;
2337
+ if (!this.isCurrent(operation) || this.failedOperation === operation) {
2338
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "discarded completed load", {
2339
+ operation,
2340
+ failedOperation: this.failedOperation
2341
+ });
2342
+ return;
2343
+ }
1287
2344
  this.markReady(status, media.kind, startedAt, operation);
1288
2345
  this.startPreloading(status, operation);
2346
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "resolved", {
2347
+ status,
2348
+ media,
2349
+ operation,
2350
+ snapshot: this.getSnapshot()
2351
+ });
1289
2352
  } catch (error) {
1290
- if (!this.isCurrent(operation) || isAbortError(error)) return;
2353
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "caught error", {
2354
+ error,
2355
+ operation
2356
+ });
2357
+ if (!this.isCurrent(operation) || isAbortError(error)) {
2358
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "ignored error");
2359
+ return;
2360
+ }
1291
2361
  this.handleFailure(status, media, error, categorizeMediaError(error), operation);
1292
2362
  } finally {
1293
2363
  loadAbort.abort();
1294
2364
  if (this.loadAbort === loadAbort) this.loadAbort = null;
2365
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.load", "completed", { operation });
1295
2366
  }
1296
2367
  }
1297
- async loadImage(url, signal, operation) {
2368
+ async loadImage(status, media, signal, operation) {
2369
+ const { url } = media;
2370
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "called", {
2371
+ status,
2372
+ media,
2373
+ signal,
2374
+ operation
2375
+ });
2376
+ if (isRetainableImage(media)) {
2377
+ const retained = this.takeRetainedImage(url);
2378
+ if (retained !== null) {
2379
+ this.container.replaceChildren(retained);
2380
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "resolved retained image", {
2381
+ url,
2382
+ operation,
2383
+ image: retained
2384
+ });
2385
+ return;
2386
+ }
2387
+ }
2388
+ this.renderConfiguredFallback(status, false);
1298
2389
  const image = this.createImage();
1299
2390
  await waitForElementEvent(image, "load", "error", signal, this.loadTimeoutMs, () => {
1300
2391
  image.src = url;
1301
2392
  });
1302
- if (!this.isCurrent(operation)) return;
2393
+ if (!this.isCurrent(operation)) {
2394
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "discarded", { operation });
2395
+ return;
2396
+ }
2397
+ if (isRetainableImage(media)) this.retainImage(url, image);
1303
2398
  this.container.replaceChildren(image);
2399
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadImage", "resolved", {
2400
+ url,
2401
+ operation,
2402
+ image
2403
+ });
2404
+ }
2405
+ takeRetainedImage(url) {
2406
+ const image = this.retainedImages.get(url) ?? null;
2407
+ if (image === null) return null;
2408
+ this.retainedImages.delete(url);
2409
+ this.retainedImages.set(url, image);
2410
+ return image;
2411
+ }
2412
+ retainImage(url, image) {
2413
+ const previous = this.retainedImages.get(url);
2414
+ if (previous && previous !== image) previous.removeAttribute("src");
2415
+ this.retainedImages.delete(url);
2416
+ this.retainedImages.set(url, image);
2417
+ while (this.retainedImages.size > MAX_RETAINED_IMAGES) {
2418
+ const oldest = this.retainedImages.entries().next().value;
2419
+ if (!oldest) break;
2420
+ this.retainedImages.delete(oldest[0]);
2421
+ oldest[1].removeAttribute("src");
2422
+ }
2423
+ }
2424
+ clearRetainedImages() {
2425
+ for (const image of this.retainedImages.values()) image.removeAttribute("src");
2426
+ this.retainedImages.clear();
1304
2427
  }
1305
2428
  async loadVideo(url, mimeType, status, media, signal, operation) {
2429
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadVideo", "called", {
2430
+ url,
2431
+ mimeType,
2432
+ status,
2433
+ media,
2434
+ signal,
2435
+ operation
2436
+ });
1306
2437
  const video = this.getReusableVideo();
1307
2438
  resetVideo(video);
1308
2439
  video.preload = "auto";
@@ -1311,25 +2442,55 @@ var DefaultDrivingExpressionPlayer = class {
1311
2442
  video.src = url;
1312
2443
  video.load();
1313
2444
  });
1314
- if (!this.isCurrent(operation)) return;
2445
+ if (!this.isCurrent(operation)) {
2446
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadVideo", "discarded", { operation });
2447
+ return;
2448
+ }
1315
2449
  video.currentTime = 0;
1316
2450
  this.container.replaceChildren(video);
1317
2451
  this.activeVideo = video;
1318
2452
  this.attachActiveVideoFailureListeners(video, status, media, operation);
1319
2453
  await video.play();
2454
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadVideo", "resolved", {
2455
+ url,
2456
+ operation,
2457
+ video
2458
+ });
1320
2459
  }
1321
2460
  async loadLivePhoto(media, status, signal, operation) {
2461
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadLivePhoto", "called", {
2462
+ media,
2463
+ status,
2464
+ signal,
2465
+ operation
2466
+ });
1322
2467
  this.renderConfiguredFallback(status, false);
1323
2468
  const cover = this.createImage();
1324
2469
  await waitForElementEvent(cover, "load", "error", signal, this.loadTimeoutMs, () => {
1325
2470
  cover.src = media.coverUrl;
1326
2471
  });
1327
- if (!this.isCurrent(operation)) return;
2472
+ if (!this.isCurrent(operation)) {
2473
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadLivePhoto", "discarded", { operation });
2474
+ return;
2475
+ }
1328
2476
  this.container.replaceChildren(cover);
1329
2477
  await this.loadVideo(media.motionUrl, void 0, status, media, signal, operation);
2478
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadLivePhoto", "resolved", {
2479
+ media,
2480
+ operation
2481
+ });
1330
2482
  }
1331
2483
  async loadTgs(url, signal, operation) {
1332
- if (!this.fetchImplementation) throw new MediaPlayerError("unsupported", "fetch is unavailable");
2484
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadTgs", "called", {
2485
+ url,
2486
+ signal,
2487
+ operation
2488
+ });
2489
+ if (!this.fetchImplementation) {
2490
+ const error = new MediaPlayerError("unsupported", "fetch is unavailable");
2491
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadTgs", "threw", error);
2492
+ throw error;
2493
+ }
1333
2494
  const response = await withTimeout(this.fetchImplementation(url, {
1334
2495
  credentials: "omit",
1335
2496
  mode: "cors",
@@ -1337,6 +2498,12 @@ var DefaultDrivingExpressionPlayer = class {
1337
2498
  }), this.loadTimeoutMs, signal);
1338
2499
  if (!response.ok) throw new MediaPlayerError("network", `TGS request failed with HTTP ${response.status}`);
1339
2500
  const contentType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() ?? "";
2501
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadTgs", "received response", {
2502
+ ok: response.ok,
2503
+ status: response.status,
2504
+ contentType,
2505
+ contentLength: response.headers.get("content-length")
2506
+ });
1340
2507
  if (!SUPPORTED_TGS_CONTENT_TYPES.has(contentType)) throw new MediaPlayerError("unsupported", `Unsupported TGS Content-Type: ${contentType || "missing"}`);
1341
2508
  const contentLength = Number(response.headers.get("content-length"));
1342
2509
  if (Number.isFinite(contentLength) && contentLength > this.maxTgsCompressedBytes) throw new MediaPlayerError("decode", "TGS compressed payload exceeds the configured limit");
@@ -1347,8 +2514,13 @@ var DefaultDrivingExpressionPlayer = class {
1347
2514
  let animationData;
1348
2515
  try {
1349
2516
  animationData = JSON.parse(new TextDecoder().decode(bytes));
1350
- } catch {
1351
- throw new MediaPlayerError("decode", "TGS JSON is malformed");
2517
+ } catch (cause) {
2518
+ const error = new MediaPlayerError("decode", "TGS JSON is malformed");
2519
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadTgs", "threw", {
2520
+ error,
2521
+ cause
2522
+ });
2523
+ throw error;
1352
2524
  }
1353
2525
  validateTgsAnimation(animationData, this.maxTgsLayers);
1354
2526
  const host = this.document.createElement("div");
@@ -1356,33 +2528,72 @@ var DefaultDrivingExpressionPlayer = class {
1356
2528
  const handle = await withTimeout(Promise.resolve(this.tgsRenderer(host, animationData, signal)), this.loadTimeoutMs, signal);
1357
2529
  if (!this.isCurrent(operation)) {
1358
2530
  handle.destroy();
2531
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadTgs", "discarded", { operation });
1359
2532
  return;
1360
2533
  }
1361
2534
  this.activeTgs = handle;
1362
2535
  this.container.replaceChildren(host);
2536
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.loadTgs", "resolved", {
2537
+ url,
2538
+ operation,
2539
+ animationData,
2540
+ host
2541
+ });
1363
2542
  }
1364
2543
  renderLoadingPlaceholder(status, coverUrl, operation, signal) {
2544
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderLoadingPlaceholder", "called", {
2545
+ status,
2546
+ coverUrl,
2547
+ operation,
2548
+ signal
2549
+ });
1365
2550
  this.renderConfiguredFallback(status, false);
1366
- if (!coverUrl) return;
2551
+ if (!coverUrl) {
2552
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderLoadingPlaceholder", "returned no cover");
2553
+ return;
2554
+ }
1367
2555
  const cover = this.createImage();
1368
2556
  waitForElementEvent(cover, "load", "error", signal, this.loadTimeoutMs, () => {
1369
2557
  cover.src = coverUrl;
1370
2558
  }).then(() => {
2559
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderLoadingPlaceholder.then", "called", {
2560
+ operation,
2561
+ cover
2562
+ });
1371
2563
  if (this.isCurrent(operation) && this.phase === "loading") this.container.replaceChildren(cover);
1372
- }).catch(() => {
2564
+ }).catch((error) => {
2565
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderLoadingPlaceholder.catch", "called", {
2566
+ operation,
2567
+ error
2568
+ });
1373
2569
  if (this.isCurrent(operation) && this.phase === "loading") this.renderConfiguredFallback(status, false);
1374
2570
  });
2571
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderLoadingPlaceholder", "returned");
1375
2572
  }
1376
2573
  renderConfiguredFallback(status, report = true) {
2574
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderConfiguredFallback", "called", {
2575
+ status,
2576
+ report
2577
+ });
1377
2578
  const fallback = this.fallbacks?.[status];
1378
2579
  if (!fallback) {
1379
2580
  this.container.replaceChildren();
2581
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderConfiguredFallback", "returned", { result: false });
1380
2582
  return false;
1381
2583
  }
1382
2584
  this.renderFallback(status, fallback, report);
2585
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderConfiguredFallback", "returned", {
2586
+ result: true,
2587
+ fallback
2588
+ });
1383
2589
  return true;
1384
2590
  }
1385
2591
  renderFallback(status, fallback, report = true) {
2592
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderFallback", "called", {
2593
+ status,
2594
+ fallback,
2595
+ report
2596
+ });
1386
2597
  if (report) {
1387
2598
  this.phase = "fallback";
1388
2599
  this.mediaKind = fallback.kind;
@@ -1399,8 +2610,10 @@ var DefaultDrivingExpressionPlayer = class {
1399
2610
  status,
1400
2611
  kind: fallback.kind
1401
2612
  });
2613
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderFallback", "returned", { snapshot: this.getSnapshot() });
1402
2614
  }
1403
2615
  renderEmoji(text) {
2616
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderEmoji", "called", { text });
1404
2617
  const emoji = this.document.createElement("span");
1405
2618
  emoji.textContent = text;
1406
2619
  emoji.setAttribute("role", "img");
@@ -1416,9 +2629,19 @@ var DefaultDrivingExpressionPlayer = class {
1416
2629
  width: "100%"
1417
2630
  });
1418
2631
  this.container.replaceChildren(emoji);
2632
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.renderEmoji", "returned", { emoji });
1419
2633
  }
1420
2634
  markReady(status, kind, startedAt, operation) {
1421
- if (!this.isCurrent(operation) || this.failedOperation === operation) return;
2635
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.markReady", "called", {
2636
+ status,
2637
+ kind,
2638
+ startedAt,
2639
+ operation
2640
+ });
2641
+ if (!this.isCurrent(operation) || this.failedOperation === operation) {
2642
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.markReady", "ignored");
2643
+ return;
2644
+ }
1422
2645
  this.phase = "ready";
1423
2646
  this.mediaKind = kind;
1424
2647
  this.errorCategory = null;
@@ -1428,9 +2651,21 @@ var DefaultDrivingExpressionPlayer = class {
1428
2651
  kind,
1429
2652
  elapsedMs: Math.max(0, Date.now() - startedAt)
1430
2653
  });
2654
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.markReady", "returned", this.getSnapshot());
1431
2655
  }
1432
2656
  handleFailure(status, media, error, category, operation, scheduleRetry = true) {
1433
- if (!this.isCurrent(operation) || this.failedOperation === operation) return;
2657
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleFailure", "called", {
2658
+ status,
2659
+ media,
2660
+ error,
2661
+ category,
2662
+ operation,
2663
+ scheduleRetry
2664
+ });
2665
+ if (!this.isCurrent(operation) || this.failedOperation === operation) {
2666
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleFailure", "ignored");
2667
+ return;
2668
+ }
1434
2669
  this.failedOperation = operation;
1435
2670
  this.stopActiveVideo();
1436
2671
  this.phase = "error";
@@ -1442,22 +2677,51 @@ var DefaultDrivingExpressionPlayer = class {
1442
2677
  category,
1443
2678
  message: safeErrorMessage(error)
1444
2679
  });
1445
- if (!this.renderConfiguredFallback(status)) {
2680
+ const fallbackApplied = this.renderConfiguredFallback(status);
2681
+ if (!fallbackApplied) {
1446
2682
  this.phase = "error";
1447
2683
  this.errorCategory = category;
1448
2684
  }
1449
2685
  if (scheduleRetry && media !== null) this.scheduleRetry(status, media, operation);
2686
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleFailure", "returned", {
2687
+ fallbackApplied,
2688
+ snapshot: this.getSnapshot()
2689
+ });
1450
2690
  }
1451
2691
  scheduleRetry(status, media, failedOperation) {
1452
- if (this.destroyed || this.paused || !this.isCurrent(failedOperation)) return;
2692
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.scheduleRetry", "called", {
2693
+ status,
2694
+ media,
2695
+ failedOperation
2696
+ });
2697
+ if (this.destroyed || this.paused || !this.isCurrent(failedOperation)) {
2698
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.scheduleRetry", "ignored");
2699
+ return;
2700
+ }
1453
2701
  this.retryTimer = globalThis.setTimeout(() => {
2702
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.scheduleRetry.callback", "called", {
2703
+ status,
2704
+ media,
2705
+ failedOperation
2706
+ });
1454
2707
  this.retryTimer = void 0;
1455
- if (this.destroyed || this.paused || this.status !== status || !this.isCurrent(failedOperation)) return;
2708
+ if (this.destroyed || this.paused || this.status !== status || !this.isCurrent(failedOperation)) {
2709
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.scheduleRetry.callback", "ignored");
2710
+ return;
2711
+ }
1456
2712
  const operation = this.beginOperation();
1457
2713
  this.load(status, media, operation);
1458
2714
  }, this.retryBackoffMs);
2715
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.scheduleRetry", "scheduled", {
2716
+ retryTimer: this.retryTimer,
2717
+ retryBackoffMs: this.retryBackoffMs
2718
+ });
1459
2719
  }
1460
2720
  startPreloading(currentStatus, operation) {
2721
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading", "called", {
2722
+ currentStatus,
2723
+ operation
2724
+ });
1461
2725
  this.preloadAbort?.abort();
1462
2726
  const preloadAbort = new AbortController();
1463
2727
  this.preloadAbort = preloadAbort;
@@ -1467,33 +2731,59 @@ var DefaultDrivingExpressionPlayer = class {
1467
2731
  ...CAR_RUNNING_STATUSES
1468
2732
  ].filter((status, index, all) => all.indexOf(status) === index);
1469
2733
  (async () => {
2734
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading.worker", "started", {
2735
+ statuses,
2736
+ operation
2737
+ });
1470
2738
  for (const status of statuses) {
1471
- if (!this.isCurrent(operation) || preloadAbort.signal.aborted) return;
2739
+ if (!this.isCurrent(operation) || preloadAbort.signal.aborted) {
2740
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading.worker", "cancelled", {
2741
+ status,
2742
+ operation
2743
+ });
2744
+ return;
2745
+ }
1472
2746
  const configured = this.config.states[status];
1473
2747
  if (configured === void 0 || status === currentStatus) continue;
1474
2748
  const media = normalizeMedia(configured);
1475
2749
  const hintUrl = mediaPreloadHint(media);
1476
2750
  if (!hintUrl || !isPublicDrivingMediaUrl(hintUrl)) continue;
2751
+ if (this.preloadedHintUrls.has(hintUrl) || this.retainedImages.has(hintUrl)) continue;
1477
2752
  try {
1478
2753
  const image = this.createImage();
1479
2754
  await waitForElementEvent(image, "load", "error", preloadAbort.signal, this.loadTimeoutMs, () => {
1480
2755
  image.src = hintUrl;
1481
2756
  });
2757
+ this.preloadedHintUrls.add(hintUrl);
1482
2758
  image.removeAttribute("src");
1483
- } catch {
2759
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading.worker", "preloaded", {
2760
+ status,
2761
+ hintUrl
2762
+ });
2763
+ } catch (error) {
2764
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading.worker", "preload failed", {
2765
+ status,
2766
+ hintUrl,
2767
+ error
2768
+ });
1484
2769
  if (preloadAbort.signal.aborted) return;
1485
2770
  }
1486
2771
  }
2772
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading.worker", "completed", { operation });
1487
2773
  })();
2774
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.startPreloading", "returned", { statuses });
1488
2775
  }
1489
2776
  createImage() {
2777
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.createImage", "called");
1490
2778
  const image = this.document.createElement("img");
1491
2779
  image.alt = "";
1492
2780
  image.decoding = "async";
1493
2781
  styleMediaElement(image, this.fit);
2782
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.createImage", "returned", { image });
1494
2783
  return image;
1495
2784
  }
1496
2785
  getReusableVideo() {
2786
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.getReusableVideo", "called", { hasReusableVideo: this.reusableVideo !== null });
1497
2787
  if (!this.reusableVideo) {
1498
2788
  this.reusableVideo = this.document.createElement("video");
1499
2789
  this.reusableVideo.muted = true;
@@ -1503,52 +2793,105 @@ var DefaultDrivingExpressionPlayer = class {
1503
2793
  this.reusableVideo.setAttribute("playsinline", "");
1504
2794
  styleMediaElement(this.reusableVideo, this.fit);
1505
2795
  }
2796
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.getReusableVideo", "returned", { video: this.reusableVideo });
1506
2797
  return this.reusableVideo;
1507
2798
  }
1508
2799
  attachActiveVideoFailureListeners(video, status, media, operation) {
2800
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.attachActiveVideoFailureListeners", "called", {
2801
+ video,
2802
+ status,
2803
+ media,
2804
+ operation
2805
+ });
1509
2806
  this.detachActiveVideoFailureListeners();
1510
2807
  let attached = true;
1511
2808
  const cleanup = () => {
1512
- if (!attached) return;
2809
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.videoListenerCleanup", "called", { attached });
2810
+ if (!attached) {
2811
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.videoListenerCleanup", "ignored");
2812
+ return;
2813
+ }
1513
2814
  attached = false;
1514
2815
  video.removeEventListener("error", handleError);
1515
2816
  video.removeEventListener("stalled", handleStalled);
1516
2817
  if (this.activeVideoListenersCleanup === cleanup) this.activeVideoListenersCleanup = null;
2818
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.videoListenerCleanup", "returned");
1517
2819
  };
1518
2820
  const failed = (category, event) => {
2821
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.videoListenerFailed", "called", {
2822
+ category,
2823
+ event,
2824
+ attached
2825
+ });
1519
2826
  if (!attached) return;
1520
2827
  this.handleActiveVideoFailure(video, status, media, operation, category, new MediaPlayerError(category, `${event.type} after video playback started`));
1521
2828
  };
1522
- const handleError = (event) => failed("decode", event);
1523
- const handleStalled = (event) => failed("network", event);
2829
+ const handleError = (event) => {
2830
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleVideoError", "called", { event });
2831
+ failed("decode", event);
2832
+ };
2833
+ const handleStalled = (event) => {
2834
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleVideoStalled", "called", { event });
2835
+ failed("network", event);
2836
+ };
1524
2837
  video.addEventListener("error", handleError);
1525
2838
  video.addEventListener("stalled", handleStalled);
1526
2839
  this.activeVideoListenersCleanup = cleanup;
2840
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.attachActiveVideoFailureListeners", "returned");
1527
2841
  }
1528
2842
  handleActiveVideoFailure(video, status, media, operation, category, error) {
1529
- if (this.activeVideo !== video || !this.isCurrent(operation)) return;
2843
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleActiveVideoFailure", "called", {
2844
+ video,
2845
+ status,
2846
+ media,
2847
+ operation,
2848
+ category,
2849
+ error
2850
+ });
2851
+ if (this.activeVideo !== video || !this.isCurrent(operation)) {
2852
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleActiveVideoFailure", "ignored");
2853
+ return;
2854
+ }
1530
2855
  this.stopActiveVideo();
1531
2856
  this.handleFailure(status, media, error, category, operation);
2857
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.handleActiveVideoFailure", "returned");
1532
2858
  }
1533
2859
  detachActiveVideoFailureListeners() {
2860
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.detachActiveVideoFailureListeners", "called");
1534
2861
  const cleanup = this.activeVideoListenersCleanup;
1535
2862
  this.activeVideoListenersCleanup = null;
1536
2863
  cleanup?.();
2864
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.detachActiveVideoFailureListeners", "returned");
1537
2865
  }
1538
2866
  stopActiveVideo() {
2867
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.stopActiveVideo", "called", { activeVideo: this.activeVideo });
1539
2868
  this.detachActiveVideoFailureListeners();
1540
- if (!this.activeVideo) return;
2869
+ if (!this.activeVideo) {
2870
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.stopActiveVideo", "returned no active video");
2871
+ return;
2872
+ }
1541
2873
  resetVideo(this.activeVideo);
1542
2874
  this.activeVideo = null;
2875
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.stopActiveVideo", "returned");
1543
2876
  }
1544
2877
  releaseActiveMedia() {
2878
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.releaseActiveMedia", "called", {
2879
+ activeVideo: this.activeVideo,
2880
+ activeTgs: this.activeTgs
2881
+ });
1545
2882
  this.stopActiveVideo();
1546
2883
  if (this.activeTgs) {
1547
2884
  safeDestroy(this.activeTgs);
1548
2885
  this.activeTgs = null;
1549
2886
  }
2887
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.releaseActiveMedia", "returned");
1550
2888
  }
1551
2889
  cancelPendingWork() {
2890
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.cancelPendingWork", "called", {
2891
+ hasLoad: this.loadAbort !== null,
2892
+ hasPreload: this.preloadAbort !== null,
2893
+ retryTimer: this.retryTimer
2894
+ });
1552
2895
  this.loadAbort?.abort();
1553
2896
  this.loadAbort = null;
1554
2897
  this.detachActiveVideoFailureListeners();
@@ -1559,22 +2902,46 @@ var DefaultDrivingExpressionPlayer = class {
1559
2902
  globalThis.clearTimeout(this.retryTimer);
1560
2903
  this.retryTimer = void 0;
1561
2904
  }
2905
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.cancelPendingWork", "returned");
1562
2906
  }
1563
2907
  isCurrent(operation) {
1564
- return !this.destroyed && !this.paused && operation === this.operation;
2908
+ const result = !this.destroyed && !this.paused && operation === this.operation;
2909
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.isCurrent", "returned", {
2910
+ operation,
2911
+ currentOperation: this.operation,
2912
+ destroyed: this.destroyed,
2913
+ paused: this.paused,
2914
+ result
2915
+ });
2916
+ return result;
1565
2917
  }
1566
2918
  emitDiagnostic(event) {
1567
- if (!this.onDiagnostic) return;
2919
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.emitDiagnostic", "called", {
2920
+ event,
2921
+ hasListener: this.onDiagnostic !== void 0
2922
+ });
2923
+ if (!this.onDiagnostic) {
2924
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.emitDiagnostic", "returned no listener");
2925
+ return;
2926
+ }
1568
2927
  try {
1569
2928
  this.onDiagnostic(event);
1570
- } catch {}
2929
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.emitDiagnostic", "returned", { event });
2930
+ } catch (error) {
2931
+ dialSdkDebugWarn(DEBUG_MODULE, "DefaultDrivingExpressionPlayer.emitDiagnostic", "listener threw", error);
2932
+ }
1571
2933
  }
1572
2934
  };
1573
2935
  var MediaPlayerError = class extends Error {
1574
2936
  constructor(category, message) {
2937
+ dialSdkDebugWarn(DEBUG_MODULE, "MediaPlayerError.constructor", "called", {
2938
+ category,
2939
+ message
2940
+ });
1575
2941
  super(message);
1576
2942
  this.name = "MediaPlayerError";
1577
2943
  this.category = category;
2944
+ dialSdkDebugWarn(DEBUG_MODULE, "MediaPlayerError.constructor", "created", { error: this });
1578
2945
  }
1579
2946
  };
1580
2947
  const SUPPORTED_TGS_CONTENT_TYPES = /* @__PURE__ */ new Set([
@@ -1584,11 +2951,27 @@ const SUPPORTED_TGS_CONTENT_TYPES = /* @__PURE__ */ new Set([
1584
2951
  "application/x-gzip",
1585
2952
  "application/x-tgsticker"
1586
2953
  ]);
1587
- const normalizeMedia = (media) => typeof media === "string" ? {
1588
- kind: "image",
1589
- url: media
1590
- } : media;
2954
+ const normalizeMedia = (media) => {
2955
+ const result = typeof media === "string" ? {
2956
+ kind: "image",
2957
+ url: media
2958
+ } : media;
2959
+ dialSdkDebugWarn(DEBUG_MODULE, "normalizeMedia", "returned", {
2960
+ media,
2961
+ result
2962
+ });
2963
+ return result;
2964
+ };
2965
+ const isRetainableImage = (media) => {
2966
+ if (media.mimeType?.split(";", 1)[0]?.trim().toLowerCase() === "image/gif") return false;
2967
+ try {
2968
+ return !new URL(media.url).pathname.toLowerCase().endsWith(".gif");
2969
+ } catch {
2970
+ return false;
2971
+ }
2972
+ };
1591
2973
  const firstInvalidMediaUrl = (media) => {
2974
+ dialSdkDebugWarn(DEBUG_MODULE, "firstInvalidMediaUrl", "called", { media });
1592
2975
  let values;
1593
2976
  switch (media.kind) {
1594
2977
  case "emoji":
@@ -1605,75 +2988,129 @@ const firstInvalidMediaUrl = (media) => {
1605
2988
  values = [media.url, media.coverUrl];
1606
2989
  break;
1607
2990
  }
1608
- return values.find((value) => typeof value === "string" && !isPublicDrivingMediaUrl(value)) ?? null;
2991
+ const result = values.find((value) => typeof value === "string" && !isPublicDrivingMediaUrl(value)) ?? null;
2992
+ dialSdkDebugWarn(DEBUG_MODULE, "firstInvalidMediaUrl", "returned", {
2993
+ values,
2994
+ result
2995
+ });
2996
+ return result;
1609
2997
  };
1610
2998
  const mediaPreloadHint = (media) => {
2999
+ dialSdkDebugWarn(DEBUG_MODULE, "mediaPreloadHint", "called", { media });
3000
+ let result;
1611
3001
  switch (media.kind) {
1612
- case "image": return media.url;
3002
+ case "image":
3003
+ result = media.url;
3004
+ break;
1613
3005
  case "video":
1614
- case "tgs": return media.coverUrl;
1615
- case "live_photo": return media.coverUrl;
1616
- case "emoji": return;
1617
- }
1618
- };
1619
- const waitForElementEvent = (element, successEvent, failureEvent, signal, timeoutMs, start) => new Promise((resolve, reject) => {
1620
- let timer;
1621
- const cleanup = () => {
1622
- element.removeEventListener(successEvent, handleSuccess);
1623
- element.removeEventListener(failureEvent, handleFailure);
1624
- signal.removeEventListener("abort", handleAbort);
1625
- if (timer !== void 0) globalThis.clearTimeout(timer);
1626
- };
1627
- const handleSuccess = () => {
1628
- cleanup();
1629
- resolve();
1630
- };
1631
- const handleFailure = () => {
1632
- cleanup();
1633
- reject(new MediaPlayerError("decode", `${failureEvent} while loading media`));
1634
- };
1635
- const handleAbort = () => {
1636
- cleanup();
1637
- reject(createAbortError());
1638
- };
1639
- element.addEventListener(successEvent, handleSuccess, { once: true });
1640
- element.addEventListener(failureEvent, handleFailure, { once: true });
1641
- signal.addEventListener("abort", handleAbort, { once: true });
1642
- timer = globalThis.setTimeout(() => {
1643
- cleanup();
1644
- reject(new MediaPlayerError("timeout", `media load timed out after ${timeoutMs}ms`));
1645
- }, timeoutMs);
1646
- try {
1647
- start();
1648
- } catch (error) {
1649
- cleanup();
1650
- reject(error);
3006
+ case "tgs":
3007
+ result = media.coverUrl;
3008
+ break;
3009
+ case "live_photo":
3010
+ result = media.coverUrl;
3011
+ break;
3012
+ case "emoji":
3013
+ result = void 0;
3014
+ break;
1651
3015
  }
1652
- });
1653
- const withTimeout = (promise, timeoutMs, signal) => new Promise((resolve, reject) => {
1654
- let timer;
1655
- const cleanup = () => {
1656
- signal.removeEventListener("abort", handleAbort);
1657
- if (timer !== void 0) globalThis.clearTimeout(timer);
1658
- };
1659
- const handleAbort = () => {
1660
- cleanup();
1661
- reject(createAbortError());
1662
- };
1663
- signal.addEventListener("abort", handleAbort, { once: true });
1664
- timer = globalThis.setTimeout(() => {
1665
- cleanup();
1666
- reject(new MediaPlayerError("timeout", `media load timed out after ${timeoutMs}ms`));
1667
- }, timeoutMs);
1668
- promise.then((value) => {
1669
- cleanup();
1670
- resolve(value);
1671
- }, (error) => {
1672
- cleanup();
1673
- reject(error);
3016
+ dialSdkDebugWarn(DEBUG_MODULE, "mediaPreloadHint", "returned", { result });
3017
+ return result;
3018
+ };
3019
+ const waitForElementEvent = (element, successEvent, failureEvent, signal, timeoutMs, start) => {
3020
+ dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent", "called", {
3021
+ element,
3022
+ successEvent,
3023
+ failureEvent,
3024
+ signal,
3025
+ timeoutMs
1674
3026
  });
1675
- });
3027
+ const result = new Promise((resolve, reject) => {
3028
+ let timer;
3029
+ const cleanup = () => {
3030
+ dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent.cleanup", "called", { timer });
3031
+ element.removeEventListener(successEvent, handleSuccess);
3032
+ element.removeEventListener(failureEvent, handleFailure);
3033
+ signal.removeEventListener("abort", handleAbort);
3034
+ if (timer !== void 0) globalThis.clearTimeout(timer);
3035
+ dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent.cleanup", "returned");
3036
+ };
3037
+ const handleSuccess = () => {
3038
+ dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent.handleSuccess", "called", { successEvent });
3039
+ cleanup();
3040
+ resolve();
3041
+ };
3042
+ const handleFailure = () => {
3043
+ dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent.handleFailure", "called", { failureEvent });
3044
+ cleanup();
3045
+ reject(new MediaPlayerError("decode", `${failureEvent} while loading media`));
3046
+ };
3047
+ const handleAbort = () => {
3048
+ dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent.handleAbort", "called");
3049
+ cleanup();
3050
+ reject(createAbortError());
3051
+ };
3052
+ element.addEventListener(successEvent, handleSuccess, { once: true });
3053
+ element.addEventListener(failureEvent, handleFailure, { once: true });
3054
+ signal.addEventListener("abort", handleAbort, { once: true });
3055
+ timer = globalThis.setTimeout(() => {
3056
+ dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent.timeout", "called", { timeoutMs });
3057
+ cleanup();
3058
+ reject(new MediaPlayerError("timeout", `media load timed out after ${timeoutMs}ms`));
3059
+ }, timeoutMs);
3060
+ try {
3061
+ start();
3062
+ } catch (error) {
3063
+ cleanup();
3064
+ reject(error);
3065
+ }
3066
+ });
3067
+ result.then(() => dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent", "resolved"), (error) => dialSdkDebugWarn(DEBUG_MODULE, "waitForElementEvent", "rejected", error));
3068
+ return result;
3069
+ };
3070
+ const withTimeout = (promise, timeoutMs, signal) => {
3071
+ dialSdkDebugWarn(DEBUG_MODULE, "withTimeout", "called", {
3072
+ promise,
3073
+ timeoutMs,
3074
+ signal
3075
+ });
3076
+ const result = new Promise((resolve, reject) => {
3077
+ let timer;
3078
+ const cleanup = () => {
3079
+ dialSdkDebugWarn(DEBUG_MODULE, "withTimeout.cleanup", "called", { timer });
3080
+ signal.removeEventListener("abort", handleAbort);
3081
+ if (timer !== void 0) globalThis.clearTimeout(timer);
3082
+ dialSdkDebugWarn(DEBUG_MODULE, "withTimeout.cleanup", "returned");
3083
+ };
3084
+ const handleAbort = () => {
3085
+ dialSdkDebugWarn(DEBUG_MODULE, "withTimeout.handleAbort", "called");
3086
+ cleanup();
3087
+ reject(createAbortError());
3088
+ };
3089
+ signal.addEventListener("abort", handleAbort, { once: true });
3090
+ timer = globalThis.setTimeout(() => {
3091
+ dialSdkDebugWarn(DEBUG_MODULE, "withTimeout.timeout", "called", { timeoutMs });
3092
+ cleanup();
3093
+ reject(new MediaPlayerError("timeout", `media load timed out after ${timeoutMs}ms`));
3094
+ }, timeoutMs);
3095
+ promise.then((value) => {
3096
+ dialSdkDebugWarn(DEBUG_MODULE, "withTimeout.promiseResolved", "called", { value });
3097
+ cleanup();
3098
+ resolve(value);
3099
+ }, (error) => {
3100
+ dialSdkDebugWarn(DEBUG_MODULE, "withTimeout.promiseRejected", "called", { error });
3101
+ cleanup();
3102
+ reject(error);
3103
+ });
3104
+ });
3105
+ result.then((value) => dialSdkDebugWarn(DEBUG_MODULE, "withTimeout", "resolved", { value }), (error) => dialSdkDebugWarn(DEBUG_MODULE, "withTimeout", "rejected", error));
3106
+ return result;
3107
+ };
1676
3108
  const defaultTgsRenderer = async (container, animationData, signal) => {
3109
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer", "called", {
3110
+ container,
3111
+ animationData,
3112
+ signal
3113
+ });
1677
3114
  if (signal.aborted) throw createAbortError();
1678
3115
  const module = await import("lottie-web/build/player/lottie_light.js");
1679
3116
  if (signal.aborted) throw createAbortError();
@@ -1687,47 +3124,80 @@ const defaultTgsRenderer = async (container, animationData, signal) => {
1687
3124
  });
1688
3125
  await new Promise((resolve, reject) => {
1689
3126
  const ready = () => {
3127
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.ready", "called");
1690
3128
  cleanup();
1691
3129
  resolve();
1692
3130
  };
1693
3131
  const failed = () => {
3132
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.failed", "called");
1694
3133
  cleanup();
1695
3134
  reject(new MediaPlayerError("decode", "Lottie could not initialize the TGS animation"));
1696
3135
  };
1697
3136
  const aborted = () => {
3137
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.aborted", "called");
1698
3138
  cleanup();
1699
3139
  animation.destroy();
1700
3140
  reject(createAbortError());
1701
3141
  };
1702
3142
  const cleanup = () => {
3143
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.cleanup", "called");
1703
3144
  animation.removeEventListener("DOMLoaded", ready);
1704
3145
  animation.removeEventListener("data_failed", failed);
1705
3146
  signal.removeEventListener("abort", aborted);
3147
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.cleanup", "returned");
1706
3148
  };
1707
3149
  animation.addEventListener("DOMLoaded", ready);
1708
3150
  animation.addEventListener("data_failed", failed);
1709
3151
  signal.addEventListener("abort", aborted, { once: true });
1710
3152
  });
1711
- return {
1712
- destroy: () => animation.destroy(),
1713
- pause: () => animation.pause(),
1714
- play: () => animation.play(),
1715
- restart: () => animation.goToAndPlay(0, true)
3153
+ const result = {
3154
+ destroy: () => {
3155
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.handle.destroy", "called");
3156
+ animation.destroy();
3157
+ },
3158
+ pause: () => {
3159
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.handle.pause", "called");
3160
+ animation.pause();
3161
+ },
3162
+ play: () => {
3163
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.handle.play", "called");
3164
+ animation.play();
3165
+ },
3166
+ restart: () => {
3167
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer.handle.restart", "called");
3168
+ animation.goToAndPlay(0, true);
3169
+ }
1716
3170
  };
3171
+ dialSdkDebugWarn(DEBUG_MODULE, "defaultTgsRenderer", "resolved", { result });
3172
+ return result;
1717
3173
  };
1718
3174
  function validateTgsAnimation(value, maxLayers) {
3175
+ dialSdkDebugWarn(DEBUG_MODULE, "validateTgsAnimation", "called", {
3176
+ value,
3177
+ maxLayers
3178
+ });
1719
3179
  if (!isRecord(value) || !Array.isArray(value.layers)) throw new MediaPlayerError("decode", "TGS animation does not contain a layers array");
1720
3180
  if (value.layers.length > maxLayers) throw new MediaPlayerError("decode", "TGS animation has too many layers");
1721
3181
  if (typeof value.fr === "number" && (!Number.isFinite(value.fr) || value.fr <= 0 || value.fr > 120)) throw new MediaPlayerError("decode", "TGS animation frame rate is outside the supported range");
1722
3182
  if (typeof value.ip === "number" && typeof value.op === "number" && (value.op <= value.ip || value.op - value.ip > 3e4)) throw new MediaPlayerError("decode", "TGS animation duration is outside the supported range");
3183
+ dialSdkDebugWarn(DEBUG_MODULE, "validateTgsAnimation", "returned");
1723
3184
  }
1724
3185
  const gunzipWithLimit = (compressed, maxOutputBytes) => {
3186
+ dialSdkDebugWarn(DEBUG_MODULE, "gunzipWithLimit", "called", {
3187
+ compressed,
3188
+ maxOutputBytes
3189
+ });
1725
3190
  if (compressed.byteLength < 18) throw new MediaPlayerError("decode", "TGS gzip payload is truncated");
1726
3191
  if (new DataView(compressed.buffer, compressed.byteOffset + compressed.byteLength - 4, 4).getUint32(0, true) > maxOutputBytes) throw new MediaPlayerError("decode", "TGS JSON payload exceeds the configured limit");
1727
3192
  const chunks = [];
1728
3193
  let outputBytes = 0;
1729
3194
  try {
1730
3195
  const gunzip = new Gunzip((chunk) => {
3196
+ dialSdkDebugWarn(DEBUG_MODULE, "gunzipWithLimit.onChunk", "called", {
3197
+ chunk,
3198
+ outputBytes,
3199
+ maxOutputBytes
3200
+ });
1731
3201
  outputBytes += chunk.byteLength;
1732
3202
  if (outputBytes > maxOutputBytes) throw new MediaPlayerError("decode", "TGS JSON payload exceeds the configured limit");
1733
3203
  if (chunk.byteLength > 0) chunks.push(chunk);
@@ -1738,8 +3208,11 @@ const gunzipWithLimit = (compressed, maxOutputBytes) => {
1738
3208
  gunzip.push(compressed.subarray(offset, end), end === compressed.byteLength);
1739
3209
  }
1740
3210
  } catch (error) {
3211
+ dialSdkDebugWarn(DEBUG_MODULE, "gunzipWithLimit", "caught error", error);
1741
3212
  if (error instanceof MediaPlayerError) throw error;
1742
- throw new MediaPlayerError("decode", "TGS gzip decompression failed");
3213
+ const wrapped = new MediaPlayerError("decode", "TGS gzip decompression failed");
3214
+ dialSdkDebugWarn(DEBUG_MODULE, "gunzipWithLimit", "threw", wrapped);
3215
+ throw wrapped;
1743
3216
  }
1744
3217
  const output = new Uint8Array(outputBytes);
1745
3218
  let offset = 0;
@@ -1747,17 +3220,29 @@ const gunzipWithLimit = (compressed, maxOutputBytes) => {
1747
3220
  output.set(chunk, offset);
1748
3221
  offset += chunk.byteLength;
1749
3222
  }
3223
+ dialSdkDebugWarn(DEBUG_MODULE, "gunzipWithLimit", "returned", {
3224
+ output,
3225
+ outputBytes
3226
+ });
1750
3227
  return output;
1751
3228
  };
1752
3229
  const resetVideo = (video) => {
3230
+ dialSdkDebugWarn(DEBUG_MODULE, "resetVideo", "called", { video });
1753
3231
  video.pause();
1754
3232
  video.removeAttribute("src");
1755
3233
  video.removeAttribute("type");
1756
3234
  try {
1757
3235
  video.load();
1758
- } catch {}
3236
+ } catch (error) {
3237
+ dialSdkDebugWarn(DEBUG_MODULE, "resetVideo", "load threw", error);
3238
+ }
3239
+ dialSdkDebugWarn(DEBUG_MODULE, "resetVideo", "returned", { video });
1759
3240
  };
1760
3241
  const styleMediaElement = (element, fit) => {
3242
+ dialSdkDebugWarn(DEBUG_MODULE, "styleMediaElement", "called", {
3243
+ element,
3244
+ fit
3245
+ });
1761
3246
  Object.assign(element.style, {
1762
3247
  display: "block",
1763
3248
  height: "100%",
@@ -1766,40 +3251,86 @@ const styleMediaElement = (element, fit) => {
1766
3251
  objectFit: fit,
1767
3252
  width: "100%"
1768
3253
  });
3254
+ dialSdkDebugWarn(DEBUG_MODULE, "styleMediaElement", "returned", { element });
1769
3255
  };
1770
3256
  const categorizeMediaError = (error) => {
1771
- if (error instanceof MediaPlayerError) return error.category;
1772
- if (error instanceof TypeError) return "network";
1773
- return "decode";
3257
+ const result = error instanceof MediaPlayerError ? error.category : error instanceof TypeError ? "network" : "decode";
3258
+ dialSdkDebugWarn(DEBUG_MODULE, "categorizeMediaError", "returned", {
3259
+ error,
3260
+ result
3261
+ });
3262
+ return result;
1774
3263
  };
1775
3264
  const safeErrorMessage = (error) => {
3265
+ dialSdkDebugWarn(DEBUG_MODULE, "safeErrorMessage", "called", { error });
1776
3266
  const message = error instanceof Error ? error.message : String(error);
1777
- return redactUrlQueries(message).slice(0, 240);
3267
+ const result = redactUrlQueries(message).slice(0, 240);
3268
+ dialSdkDebugWarn(DEBUG_MODULE, "safeErrorMessage", "returned", { result });
3269
+ return result;
3270
+ };
3271
+ const redactUrlQueries = (message) => {
3272
+ dialSdkDebugWarn(DEBUG_MODULE, "redactUrlQueries", "called", { message });
3273
+ const result = message.replace(/https:\/\/[^\s"'<>]+/gu, (candidate) => {
3274
+ dialSdkDebugWarn(DEBUG_MODULE, "redactUrlQueries.replace", "called", { candidate });
3275
+ try {
3276
+ const url = new URL(candidate);
3277
+ return `${url.origin}${url.pathname}`;
3278
+ } catch {
3279
+ return "[url]";
3280
+ }
3281
+ });
3282
+ dialSdkDebugWarn(DEBUG_MODULE, "redactUrlQueries", "returned", { result });
3283
+ return result;
1778
3284
  };
1779
- const redactUrlQueries = (message) => message.replace(/https:\/\/[^\s"'<>]+/gu, (candidate) => {
1780
- try {
1781
- const url = new URL(candidate);
1782
- return `${url.origin}${url.pathname}`;
1783
- } catch {
1784
- return "[url]";
1785
- }
1786
- });
1787
3285
  const createAbortError = () => {
1788
- if (typeof DOMException !== "undefined") return new DOMException("Aborted", "AbortError");
3286
+ dialSdkDebugWarn(DEBUG_MODULE, "createAbortError", "called");
3287
+ if (typeof DOMException !== "undefined") {
3288
+ const result = new DOMException("Aborted", "AbortError");
3289
+ dialSdkDebugWarn(DEBUG_MODULE, "createAbortError", "returned DOMException", { result });
3290
+ return result;
3291
+ }
1789
3292
  const error = /* @__PURE__ */ new Error("Aborted");
1790
3293
  error.name = "AbortError";
3294
+ dialSdkDebugWarn(DEBUG_MODULE, "createAbortError", "returned Error", { result: error });
1791
3295
  return error;
1792
3296
  };
1793
- const isAbortError = (error) => error instanceof Error && error.name === "AbortError";
3297
+ const isAbortError = (error) => {
3298
+ const result = error instanceof Error && error.name === "AbortError";
3299
+ dialSdkDebugWarn(DEBUG_MODULE, "isAbortError", "returned", {
3300
+ error,
3301
+ result
3302
+ });
3303
+ return result;
3304
+ };
1794
3305
  const positiveFinite = (name, value) => {
1795
- if (!Number.isFinite(value) || value <= 0) throw new RangeError(`${name} must be a positive finite number`);
3306
+ dialSdkDebugWarn(DEBUG_MODULE, "positiveFinite", "called", {
3307
+ name,
3308
+ value
3309
+ });
3310
+ if (!Number.isFinite(value) || value <= 0) {
3311
+ const error = /* @__PURE__ */ new RangeError(`${name} must be a positive finite number`);
3312
+ dialSdkDebugWarn(DEBUG_MODULE, "positiveFinite", "threw", error);
3313
+ throw error;
3314
+ }
3315
+ dialSdkDebugWarn(DEBUG_MODULE, "positiveFinite", "returned", { result: value });
1796
3316
  return value;
1797
3317
  };
1798
3318
  const safeDestroy = (handle) => {
3319
+ dialSdkDebugWarn(DEBUG_MODULE, "safeDestroy", "called", { handle });
1799
3320
  try {
1800
3321
  handle.destroy();
1801
- } catch {}
3322
+ dialSdkDebugWarn(DEBUG_MODULE, "safeDestroy", "returned");
3323
+ } catch (error) {
3324
+ dialSdkDebugWarn(DEBUG_MODULE, "safeDestroy", "destroy threw", error);
3325
+ }
3326
+ };
3327
+ const isRecord = (value) => {
3328
+ const result = typeof value === "object" && value !== null && !Array.isArray(value);
3329
+ dialSdkDebugWarn(DEBUG_MODULE, "isRecord", "returned", {
3330
+ value,
3331
+ result
3332
+ });
3333
+ return result;
1802
3334
  };
1803
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1804
3335
  //#endregion
1805
3336
  export { BATTERY_HEALTH_LABELS, CAR_RUNNING_LABELS, CAR_RUNNING_STATUSES, CAR_RUNNING_STATUS_PRIORITY, DEFAULT_DRIVING_STATUS_TUNING, DrivingExpressionResolutionError, DrivingExpressionsConfigError, OFFICIAL_DRIVING_EXPRESSIONS_CONFIG, OFFICIAL_DRIVING_EXPRESSION_FALLBACKS, checkRunningStatus, classifyDrivingMetrics, classifyDrivingSnapshot, createDrivingExpressionPlayer, createDrivingStatusController, extractDrivingSnapshotMetrics, isPublicDrivingMediaUrl, parseDrivingExpressionsConfig, readDrivingExpressionsConfig, resolveDrivingExpression, resolveDrivingExpressionStrict, resolveDrivingStatusTuning, tryParseDrivingExpressionsConfig, unifiedSensorInfo, waitForDrivingExpressionsConfig };