obi-sdk 0.3.13 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { A, S } from "./chunks/types-82772f00.js";
1
+ import { A, S } from "./chunks/types-e0297e7b.js";
2
2
  var util;
3
3
  (function(util2) {
4
4
  util2.assertEqual = (val) => val;
@@ -1,8 +1,38 @@
1
- import { O as ObiWidget } from "./chunks/obi-widget-d7e7c6bf.js";
2
- import "./chunks/types-82772f00.js";
1
+ import { O as ObiWidget } from "./chunks/obi-widget-58dc98b0.js";
2
+ import "./chunks/types-e0297e7b.js";
3
3
  if (!customElements.get("obi-widget")) {
4
4
  customElements.define("obi-widget", ObiWidget);
5
5
  }
6
+ const RETRY_CONFIG = {
7
+ maxAttempts: 3,
8
+ baseDelay: 200,
9
+ // ms
10
+ maxDelay: 2e3
11
+ // ms
12
+ };
13
+ function delay(ms) {
14
+ return new Promise((resolve) => setTimeout(resolve, ms));
15
+ }
16
+ function getRetryDelay(attempt) {
17
+ const exponentialDelay = RETRY_CONFIG.baseDelay * Math.pow(2, attempt);
18
+ return Math.min(exponentialDelay, RETRY_CONFIG.maxDelay);
19
+ }
20
+ async function retryOperation(operation, operationName, maxAttempts = RETRY_CONFIG.maxAttempts) {
21
+ let lastError = null;
22
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
23
+ try {
24
+ return await operation();
25
+ } catch (error) {
26
+ lastError = error;
27
+ console.warn(`${operationName} failed (attempt ${attempt + 1}/${maxAttempts}):`, error);
28
+ if (attempt < maxAttempts - 1) {
29
+ const delayMs = getRetryDelay(attempt);
30
+ await delay(delayMs);
31
+ }
32
+ }
33
+ }
34
+ throw new Error(`${operationName} failed after ${maxAttempts} attempts: ${lastError?.message}`);
35
+ }
6
36
  function mountSDK() {
7
37
  const w = window;
8
38
  if (typeof w.ObiSDK === "function" || typeof w.ObiSDK === "object") {
@@ -18,12 +48,18 @@ function mountSDK() {
18
48
  };
19
49
  w.ObiSDK.q = [];
20
50
  }
21
- function mountWidget() {
22
- if (!document.querySelector("obi-widget")) {
51
+ async function mountWidget() {
52
+ return retryOperation(async () => {
53
+ if (document.querySelector("obi-widget")) {
54
+ return;
55
+ }
56
+ if (!document.body) {
57
+ throw new Error("document.body not available");
58
+ }
23
59
  const widget = document.createElement("obi-widget");
24
60
  document.body.appendChild(widget);
25
61
  console.log("Obi Widget mounted");
26
- }
62
+ }, "Widget mounting");
27
63
  }
28
64
  function processQueue() {
29
65
  const w = window;
@@ -40,17 +76,62 @@ function processQueue() {
40
76
  w.ObiSDK.q = [];
41
77
  }
42
78
  }
43
- function loadFonts() {
44
- const link = document.createElement("link");
45
- link.href = "https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Syne:wght@400..800&display=swap";
46
- link.rel = "stylesheet";
47
- document.head.appendChild(link);
79
+ async function loadFonts() {
80
+ return retryOperation(async () => {
81
+ if (!document.head) {
82
+ throw new Error("document.head not available");
83
+ }
84
+ const existingLink = document.head.querySelector('link[href*="fonts.googleapis.com"]');
85
+ if (existingLink) {
86
+ return;
87
+ }
88
+ const link = document.createElement("link");
89
+ document.head.querySelectorAll("link[data-obi-font]").forEach((node) => node.remove());
90
+ link.setAttribute("data-obi-font", "true");
91
+ link.href = "https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Syne:wght@400..800&display=swap";
92
+ link.rel = "stylesheet";
93
+ return new Promise((resolve, reject) => {
94
+ const timeout = setTimeout(() => {
95
+ reject(new Error("Font loading timeout"));
96
+ }, 5e3);
97
+ link.onload = () => {
98
+ clearTimeout(timeout);
99
+ resolve();
100
+ };
101
+ link.onerror = () => {
102
+ clearTimeout(timeout);
103
+ reject(new Error("Font loading failed"));
104
+ };
105
+ document.head.appendChild(link);
106
+ });
107
+ }, "Font loading");
108
+ }
109
+ async function safeInitialize() {
110
+ try {
111
+ mountSDK();
112
+ await loadFonts();
113
+ await mountWidget();
114
+ processQueue();
115
+ console.log("Obi Widget initialized successfully");
116
+ } catch (error) {
117
+ console.error("Obi Widget initialization failed:", error);
118
+ try {
119
+ mountSDK();
120
+ processQueue();
121
+ console.log("Obi Widget fallback initialization completed");
122
+ } catch (fallbackError) {
123
+ console.error("Obi Widget fallback initialization failed:", fallbackError);
124
+ }
125
+ }
48
126
  }
49
127
  function initializeObiWidget() {
50
- loadFonts();
51
- mountSDK();
52
- mountWidget();
53
- processQueue();
128
+ if (document.readyState === "loading") {
129
+ document.addEventListener("DOMContentLoaded", () => {
130
+ safeInitialize();
131
+ });
132
+ } else {
133
+ safeInitialize();
134
+ }
54
135
  }
55
136
  initializeObiWidget();
56
137
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/core/init.ts"],"sourcesContent":["import { ObiWidget } from \"../ui/components/obi-widget\"\n\nif (!customElements.get(\"obi-widget\")) {\n customElements.define(\"obi-widget\", ObiWidget)\n}\n\nfunction mountSDK(): void {\n const w = window as any\n if (typeof w.ObiSDK === \"function\" || typeof w.ObiSDK === \"object\") {\n return\n }\n\n // Initialize the SDK\n w.ObiSDK = function (command: string, config?: any) {\n if (command === \"update\" && config) {\n w.obiWidgetConfig = {\n ...w.obiWidgetConfig,\n ...config,\n }\n }\n }\n w.ObiSDK.q = []\n}\n\n// Mount the widget if not already present\nfunction mountWidget() {\n if (!document.querySelector(\"obi-widget\")) {\n const widget = document.createElement(\"obi-widget\")\n document.body.appendChild(widget)\n console.log(\"Obi Widget mounted\")\n }\n}\n\n// Optionally process a queue if you want to support it\nfunction processQueue() {\n const w = window as any\n if (w.ObiSDK && Array.isArray(w.ObiSDK.q)) {\n // Process each command in the queue\n w.ObiSDK.q.forEach((args: any[]) => {\n const [command, config] = args\n if (command === \"update\" && config) {\n w.obiWidgetConfig = {\n ...w.obiWidgetConfig,\n ...config,\n }\n }\n })\n w.ObiSDK.q = []\n }\n}\n\nfunction loadFonts() {\n const link = document.createElement(\"link\")\n link.href =\n \"https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Syne:wght@400..800&display=swap\"\n link.rel = \"stylesheet\"\n document.head.appendChild(link)\n}\n\n// Main init\nexport function initializeObiWidget() {\n loadFonts()\n mountSDK()\n mountWidget()\n processQueue()\n}\n\n// Auto-initialize\ninitializeObiWidget()\n"],"names":[],"mappings":"AAEA,SAAA,KAAA,iBAAA;AAAA,OAAA;AAAA,IAAI,CAAC,eAAe,IAAI,YAAY,GAAG;AACtB,iBAAA,OAAO,cAAc,SAAS;AAC/C;AAEA,SAAS,WAAiB;AACxB,QAAM,IAAI;AACV,MAAI,OAAO,EAAE,WAAW,cAAc,OAAO,EAAE,WAAW,UAAU;AAClE;AAAA,EACF;AAGE,IAAA,SAAS,SAAU,SAAiB,QAAc;AAC9C,QAAA,YAAY,YAAY,QAAQ;AAClC,QAAE,kBAAkB;AAAA,QAClB,GAAG,EAAE;AAAA,QACL,GAAG;AAAA,MAAA;AAAA,IAEP;AAAA,EAAA;AAEA,IAAA,OAAO,IAAI;AACf;AAGA,SAAS,cAAc;AACrB,MAAI,CAAC,SAAS,cAAc,YAAY,GAAG;AACnC,UAAA,SAAS,SAAS,cAAc,YAAY;AACzC,aAAA,KAAK,YAAY,MAAM;AAChC,YAAQ,IAAI,oBAAoB;AAAA,EAClC;AACF;AAGA,SAAS,eAAe;AACtB,QAAM,IAAI;AACV,MAAI,EAAE,UAAU,MAAM,QAAQ,EAAE,OAAO,CAAC,GAAG;AAEzC,MAAE,OAAO,EAAE,QAAQ,CAAC,SAAgB;AAC5B,YAAA,CAAC,SAAS,MAAM,IAAI;AACtB,UAAA,YAAY,YAAY,QAAQ;AAClC,UAAE,kBAAkB;AAAA,UAClB,GAAG,EAAE;AAAA,UACL,GAAG;AAAA,QAAA;AAAA,MAEP;AAAA,IAAA,CACD;AACC,MAAA,OAAO,IAAI;EACf;AACF;AAEA,SAAS,YAAY;AACb,QAAA,OAAO,SAAS,cAAc,MAAM;AAC1C,OAAK,OACH;AACF,OAAK,MAAM;AACF,WAAA,KAAK,YAAY,IAAI;AAChC;AAGO,SAAS,sBAAsB;AAC1B;AACD;AACG;AACC;AACf;AAGA,oBAAoB;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/core/init.ts"],"sourcesContent":["import { ObiWidget } from \"../ui/components/obi-widget\"\n\nif (!customElements.get(\"obi-widget\")) {\n customElements.define(\"obi-widget\", ObiWidget)\n}\n\n// Retry configuration\nconst RETRY_CONFIG = {\n maxAttempts: 3,\n baseDelay: 200, // ms\n maxDelay: 2000, // ms\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nfunction getRetryDelay(attempt: number): number {\n const exponentialDelay = RETRY_CONFIG.baseDelay * Math.pow(2, attempt)\n return Math.min(exponentialDelay, RETRY_CONFIG.maxDelay)\n}\n\nasync function retryOperation<T>(\n operation: () => Promise<T> | T,\n operationName: string,\n maxAttempts: number = RETRY_CONFIG.maxAttempts\n): Promise<T> {\n let lastError: Error | null = null\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n try {\n return await operation()\n } catch (error) {\n lastError = error as Error\n console.warn(`${operationName} failed (attempt ${attempt + 1}/${maxAttempts}):`, error)\n\n if (attempt < maxAttempts - 1) {\n const delayMs = getRetryDelay(attempt)\n await delay(delayMs)\n }\n }\n }\n\n throw new Error(`${operationName} failed after ${maxAttempts} attempts: ${lastError?.message}`)\n}\n\nfunction mountSDK(): void {\n const w = window as any\n if (typeof w.ObiSDK === \"function\" || typeof w.ObiSDK === \"object\") {\n return\n }\n\n // Initialize the SDK\n w.ObiSDK = function (command: string, config?: any) {\n if (command === \"update\" && config) {\n w.obiWidgetConfig = {\n ...w.obiWidgetConfig,\n ...config,\n }\n }\n }\n w.ObiSDK.q = []\n}\n\n// Mount the widget if not already present\nasync function mountWidget(): Promise<void> {\n return retryOperation(async () => {\n if (document.querySelector(\"obi-widget\")) {\n return // Already mounted\n }\n\n if (!document.body) {\n throw new Error(\"document.body not available\")\n }\n\n const widget = document.createElement(\"obi-widget\")\n document.body.appendChild(widget)\n console.log(\"Obi Widget mounted\")\n }, \"Widget mounting\")\n}\n\n// Optionally process a queue if you want to support it\nfunction processQueue() {\n const w = window as any\n if (w.ObiSDK && Array.isArray(w.ObiSDK.q)) {\n // Process each command in the queue\n w.ObiSDK.q.forEach((args: any[]) => {\n const [command, config] = args\n if (command === \"update\" && config) {\n w.obiWidgetConfig = {\n ...w.obiWidgetConfig,\n ...config,\n }\n }\n })\n w.ObiSDK.q = []\n }\n}\n\nasync function loadFonts(): Promise<void> {\n return retryOperation(async () => {\n if (!document.head) {\n throw new Error(\"document.head not available\")\n }\n\n // Check if fonts are already loaded\n const existingLink = document.head.querySelector('link[href*=\"fonts.googleapis.com\"]')\n if (existingLink) {\n return // Already loaded\n }\n\n const link = document.createElement(\"link\")\n // Remove any previous failed link for a clean retry\n document.head.querySelectorAll(\"link[data-obi-font]\").forEach((node) => node.remove())\n link.setAttribute(\"data-obi-font\", \"true\")\n\n link.href =\n \"https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Syne:wght@400..800&display=swap\"\n link.rel = \"stylesheet\"\n\n // Wait for font load or timeout\n return new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error(\"Font loading timeout\"))\n }, 5000)\n\n link.onload = () => {\n clearTimeout(timeout)\n resolve()\n }\n\n link.onerror = () => {\n clearTimeout(timeout)\n reject(new Error(\"Font loading failed\"))\n }\n\n document.head.appendChild(link)\n })\n }, \"Font loading\")\n}\n\nasync function safeInitialize(): Promise<void> {\n try {\n mountSDK()\n await loadFonts()\n await mountWidget()\n processQueue()\n console.log(\"Obi Widget initialized successfully\")\n } catch (error) {\n console.error(\"Obi Widget initialization failed:\", error)\n // Still try to mount basic functionality\n try {\n mountSDK()\n processQueue()\n console.log(\"Obi Widget fallback initialization completed\")\n } catch (fallbackError) {\n console.error(\"Obi Widget fallback initialization failed:\", fallbackError)\n }\n }\n}\n\n// Main init\nexport function initializeObiWidget() {\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", () => {\n safeInitialize()\n })\n } else {\n safeInitialize()\n }\n}\n\n// Auto-initialize\ninitializeObiWidget()\n"],"names":[],"mappings":"AAEA,SAAA,KAAA,iBAAA;AAAA,OAAA;AAAA,IAAI,CAAC,eAAe,IAAI,YAAY,GAAG;AACtB,iBAAA,OAAO,cAAc,SAAS;AAC/C;AAGA,MAAM,eAAe;AAAA,EACnB,aAAa;AAAA,EACb,WAAW;AAAA;AAAA,EACX,UAAU;AAAA;AACZ;AAEA,SAAS,MAAM,IAA2B;AACxC,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD;AAEA,SAAS,cAAc,SAAyB;AAC9C,QAAM,mBAAmB,aAAa,YAAY,KAAK,IAAI,GAAG,OAAO;AACrE,SAAO,KAAK,IAAI,kBAAkB,aAAa,QAAQ;AACzD;AAEA,eAAe,eACb,WACA,eACA,cAAsB,aAAa,aACvB;AACZ,MAAI,YAA0B;AAE9B,WAAS,UAAU,GAAG,UAAU,aAAa,WAAW;AAClD,QAAA;AACF,aAAO,MAAM,UAAU;AAAA,aAChB,OAAO;AACF,kBAAA;AACJ,cAAA,KAAK,GAAG,aAAa,oBAAoB,UAAU,CAAC,IAAI,WAAW,MAAM,KAAK;AAElF,UAAA,UAAU,cAAc,GAAG;AACvB,cAAA,UAAU,cAAc,OAAO;AACrC,cAAM,MAAM,OAAO;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEM,QAAA,IAAI,MAAM,GAAG,aAAa,iBAAiB,WAAW,cAAc,WAAW,OAAO,EAAE;AAChG;AAEA,SAAS,WAAiB;AACxB,QAAM,IAAI;AACV,MAAI,OAAO,EAAE,WAAW,cAAc,OAAO,EAAE,WAAW,UAAU;AAClE;AAAA,EACF;AAGE,I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QAAc,CAAC,SAAS,WAAW;AACtC,YAAA,UAAU,WAAW,MAAM;AACxB,eAAA,IAAI,MAAM,sBAAsB,CAAC;AAAA,SACvC,GAAI;AAEP,WAAK,SAAS,MAAM;AAClB,qBAAa,OAAO;AACZ;MAAA;AAGV,WAAK,UAAU,MAAM;AACnB,qBAAa,OAAO;AACb,eAAA,IAAI,MAAM,qBAAqB,CAAC;AAAA,MAAA;AAGhC,eAAA,KAAK,YAAY,IAAI;AAAA,IAAA,CAC/B;AAAA,KACA,cAAc;AACnB;AAEA,eAAe,iBAAgC;AACzC,MAAA;AACO;AACT,UAAM,UAAU;AAChB,UAAM,YAAY;AACL;AACb,YAAQ,IAAI,qCAAqC;AAAA,WAC1C,OAAO;AACN,YAAA,MAAM,qCAAqC,KAAK;AAEpD,QAAA;AACO;AACI;AACb,cAAQ,IAAI,8CAA8C;AAAA,aACnD,eAAe;AACd,cAAA,MAAM,8CAA8C,aAAa;AAAA,IAC3E;AAAA,EACF;AACF;AAGO,SAAS,sBAAsB;AAChC,MAAA,SAAS,eAAe,WAAW;AAC5B,aAAA,iBAAiB,oBAAoB,MAAM;AACnC;IAAA,CAChB;AAAA,EAAA,OACI;AACU;EACjB;AACF;AAGA,oBAAoB;"}
@@ -1,6 +1,6 @@
1
- import { S as SDKState } from "./chunks/types-82772f00.js";
2
- import { i, n, a as i$1, x } from "./chunks/obi-widget-d7e7c6bf.js";
3
- import { A, C, c, d, D, N, b, O, S } from "./chunks/obi-widget-d7e7c6bf.js";
1
+ import { S as SDKState } from "./chunks/types-e0297e7b.js";
2
+ import { i, n, a as i$1, x } from "./chunks/obi-widget-58dc98b0.js";
3
+ import { A, C, c, d, D, N, b, O, S } from "./chunks/obi-widget-58dc98b0.js";
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __decorateClass = (decorators, target, key, kind) => {
@@ -85,14 +85,14 @@ if (!customElements.get("obi-status-widget")) {
85
85
  const statusWidget = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ObiStatusWidget }, Symbol.toStringTag, { value: "Module" }));
86
86
  function defineCustomElements() {
87
87
  Promise.resolve().then(() => statusWidget);
88
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.o);
89
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.j);
90
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.k);
91
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.e);
92
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.f);
93
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.s);
94
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.g);
95
- import("./chunks/obi-widget-d7e7c6bf.js").then((n2) => n2.h);
88
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.o);
89
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.j);
90
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.k);
91
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.e);
92
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.f);
93
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.s);
94
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.g);
95
+ import("./chunks/obi-widget-58dc98b0.js").then((n2) => n2.h);
96
96
  }
97
97
  export {
98
98
  A as AudioEqualizer,