@returningai/widget-sdk 1.8.12 → 1.8.13

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.
@@ -14304,6 +14304,8 @@ class BaseWidget extends HTMLElement {
14304
14304
  return [
14305
14305
  "embed-token",
14306
14306
  "data-embed-token",
14307
+ "theme",
14308
+ "data-theme",
14307
14309
  "language",
14308
14310
  "data-language",
14309
14311
  "locale",
@@ -14326,16 +14328,8 @@ class BaseWidget extends HTMLElement {
14326
14328
  const style = document.createElement("style");
14327
14329
  style.textContent = widgetCSS;
14328
14330
  this.shadow.appendChild(style);
14329
- const theme = this.config.theme;
14330
- const accentColor = theme === "dark" ? "#ffffff" : "#000000";
14331
- const text4Color = theme === "dark" ? "#9ca3af" : "#6b7280";
14332
- const bgColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
14333
14331
  this.style.width = this.config.width;
14334
14332
  this.style.height = this.config.height;
14335
- this.style.setProperty("--rai-accent", accentColor);
14336
- this.style.setProperty("--rai-text4", text4Color);
14337
- this.style.setProperty("--rai-loader-bg", bgColor);
14338
- this.style.setProperty("--rai-error-bg", bgColor);
14339
14333
  this.applyFirstPaintColors();
14340
14334
  this.renderShell();
14341
14335
  if (this.hasAttribute("eager")) {
@@ -14378,6 +14372,8 @@ class BaseWidget extends HTMLElement {
14378
14372
  void this.reload();
14379
14373
  } else {
14380
14374
  this.config = readConfig(this, this.config.communityId);
14375
+ this.applyFirstPaintColors();
14376
+ this.renderLoaderAnimation();
14381
14377
  }
14382
14378
  }
14383
14379
  }
@@ -14453,6 +14449,17 @@ class BaseWidget extends HTMLElement {
14453
14449
  }
14454
14450
  }
14455
14451
  const theme = this.config.theme === "dark" ? "dark" : "light";
14452
+ this.style.setProperty(
14453
+ "--rai-accent",
14454
+ theme === "dark" ? "#ffffff" : "#000000"
14455
+ );
14456
+ this.style.setProperty(
14457
+ "--rai-text4",
14458
+ theme === "dark" ? "#9ca3af" : "#6b7280"
14459
+ );
14460
+ const bgColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
14461
+ this.style.setProperty("--rai-loader-bg", bgColor);
14462
+ this.style.setProperty("--rai-error-bg", bgColor);
14456
14463
  const cachedPalette = (_a = cached == null ? void 0 : cached.themePalette) == null ? void 0 : _a[theme];
14457
14464
  if (cachedPalette) this.applyPalette(cachedPalette);
14458
14465
  const cachedFont = typeof (cached == null ? void 0 : cached.font) === "string" ? cached.font : void 0;
@@ -14536,19 +14543,7 @@ class BaseWidget extends HTMLElement {
14536
14543
  }
14537
14544
  }
14538
14545
  renderShell() {
14539
- this.loaderEl = document.createElement("div");
14540
- this.loaderEl.className = "rai-loader";
14541
- if (this.config.widgetType === "custom" && !loadErrorSettingsFromStorage(this.config)) {
14542
- this.loaderEl.classList.add("rai-loader-pending-settings");
14543
- }
14544
- const textEl = document.createElement("h1");
14545
- textEl.className = "rai-loader-text";
14546
- textEl.textContent = this.config.loadingText;
14547
- this.loaderEl.appendChild(textEl);
14548
- this.shadow.appendChild(this.loaderEl);
14549
- this.freezeIframeLoaderHeight();
14550
- this.applyLoadingSettings();
14551
- this.fetchAndRenderLoader();
14546
+ this.showLoader();
14552
14547
  this.errorEl = document.createElement("div");
14553
14548
  this.errorEl.className = "rai-error";
14554
14549
  this.msgEl = document.createElement("span");
@@ -14563,6 +14558,26 @@ class BaseWidget extends HTMLElement {
14563
14558
  this.errorEl.appendChild(btn);
14564
14559
  this.shadow.appendChild(this.errorEl);
14565
14560
  }
14561
+ showLoader() {
14562
+ var _a;
14563
+ this.clearLottieInstances();
14564
+ this.shadow.querySelectorAll(".rai-loader").forEach((el2) => el2.remove());
14565
+ (_a = this.errorEl) == null ? void 0 : _a.classList.remove("visible");
14566
+ this.shadow.querySelectorAll(".rai-custom-error").forEach((el2) => el2.remove());
14567
+ this.loaderEl = document.createElement("div");
14568
+ this.loaderEl.className = "rai-loader";
14569
+ if (this.config.widgetType === "custom" && !loadErrorSettingsFromStorage(this.config)) {
14570
+ this.loaderEl.classList.add("rai-loader-pending-settings");
14571
+ }
14572
+ const textEl = document.createElement("h1");
14573
+ textEl.className = "rai-loader-text";
14574
+ textEl.textContent = this.config.loadingText;
14575
+ this.loaderEl.appendChild(textEl);
14576
+ this.shadow.appendChild(this.loaderEl);
14577
+ this.freezeIframeLoaderHeight();
14578
+ this.applyLoadingSettings();
14579
+ void this.fetchAndRenderLoader();
14580
+ }
14566
14581
  /**
14567
14582
  * Loads the community loading animation + theme palette from cache or API
14568
14583
  * and renders the configured animation above the loading text.
@@ -14573,6 +14588,7 @@ class BaseWidget extends HTMLElement {
14573
14588
  */
14574
14589
  async fetchAndRenderLoader() {
14575
14590
  var _a;
14591
+ const loaderEl = this.loaderEl;
14576
14592
  const cached = loadErrorSettingsFromStorage(this.config);
14577
14593
  if (cached) {
14578
14594
  applyErrorSettingsToState(this.state, cached);
@@ -14584,8 +14600,7 @@ class BaseWidget extends HTMLElement {
14584
14600
  await fetchErrorSettings(this.config, this.state);
14585
14601
  } catch {
14586
14602
  }
14587
- const loaderEl = this.loaderEl;
14588
- if (!loaderEl) return;
14603
+ if (!loaderEl || loaderEl !== this.loaderEl || !this.isConnected) return;
14589
14604
  if (!this.config.themeExplicit && (this.state.defaultColorSchema === "light" || this.state.defaultColorSchema === "dark") && this.state.defaultColorSchema !== this.config.theme) {
14590
14605
  this.config.theme = this.state.defaultColorSchema;
14591
14606
  }
@@ -14690,7 +14705,7 @@ class BaseWidget extends HTMLElement {
14690
14705
  setTimeout(() => {
14691
14706
  loader.remove();
14692
14707
  lottieInstances.forEach((instance) => instance.destroy());
14693
- this.restoreLoaderHeight();
14708
+ if (!this.loaderEl) this.restoreLoaderHeight();
14694
14709
  }, 300);
14695
14710
  this.loaderEl = null;
14696
14711
  }
@@ -15436,6 +15451,8 @@ class BaseWidget extends HTMLElement {
15436
15451
  this.teardownMountedWidget();
15437
15452
  this.removeBanner();
15438
15453
  clearState(this.state);
15454
+ this.applyFirstPaintColors();
15455
+ this.showLoader();
15439
15456
  await this.init();
15440
15457
  }
15441
15458
  async logoutPublic() {
@@ -15571,7 +15588,7 @@ class CustomWidget extends BaseWidget {
15571
15588
  }
15572
15589
  }
15573
15590
  }
15574
- console.log(`[rai-widget] v${"1.8.12"}`);
15591
+ console.log(`[rai-widget] v${"1.8.13"}`);
15575
15592
  class StoreWidgetCompat extends StoreWidget {
15576
15593
  }
15577
15594
  const WIDGET_REGISTRY = [
@@ -15635,7 +15652,7 @@ function exposePublicApi() {
15635
15652
  })();
15636
15653
  const widget = container == null ? void 0 : container.querySelector(ALL_WIDGET_SELECTOR);
15637
15654
  window.ReturningAIWidget = {
15638
- version: "1.8.12",
15655
+ version: "1.8.13",
15639
15656
  reload: () => (widget == null ? void 0 : widget.reload()) ?? Promise.resolve(),
15640
15657
  logout: () => (widget == null ? void 0 : widget.logoutPublic()) ?? Promise.resolve(),
15641
15658
  isAuthenticated: () => (widget == null ? void 0 : widget.isAuthenticated()) ?? false,
@@ -59,6 +59,7 @@ export declare abstract class BaseWidget extends HTMLElement {
59
59
  private applyPalette;
60
60
  private applyLoadingSettings;
61
61
  private renderShell;
62
+ private showLoader;
62
63
  /**
63
64
  * Loads the community loading animation + theme palette from cache or API
64
65
  * and renders the configured animation above the loading text.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@returningai/widget-sdk",
3
- "version": "1.8.12",
3
+ "version": "1.8.13",
4
4
  "description": "Shadow DOM isolated widget SDK for ReturningAI",
5
5
  "main": "dist/rai-widget.iife.js",
6
6
  "module": "dist/rai-widget.js",
@@ -42,7 +42,7 @@
42
42
  "build:all": "npm run build && npm run build:banner",
43
43
  "build:all:min": "npm run build:min && npm run build:banner:min",
44
44
  "types": "tsc --emitDeclarationOnly --outDir dist/types && cp src/jsx.d.ts src/react18.d.ts src/react19.d.ts dist/types/",
45
- "test": "npm run test:host-callback && npm run test:bundle-readiness && npm run test:bundle-runtime-cache && npm run test:bundle-token-sync && npm run test:auth-bootstrap && npm run test:auth-error-reporting && npm run test:auth-refresh-state && npm run test:auth-renewal-recovery && npm run test:auth-session-coordinator && npm run test:startup-performance && npm run test:widget-error-presentation && npm run test:fonts && npm run test:jsx-types",
45
+ "test": "npm run test:host-callback && npm run test:bundle-readiness && npm run test:bundle-runtime-cache && npm run test:bundle-token-sync && npm run test:auth-bootstrap && npm run test:auth-error-reporting && npm run test:auth-refresh-state && npm run test:auth-renewal-recovery && npm run test:auth-session-coordinator && npm run test:startup-performance && npm run test:widget-error-presentation && npm run test:fonts && npm run test:jsx-types && npm run test:loader-lifecycle",
46
46
  "test:host-callback": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/postmessage-host-callback.test.js",
47
47
  "test:bundle-readiness": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/bundle-readiness.test.js",
48
48
  "test:bundle-runtime-cache": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/bundle-runtime-cache.test.js",
@@ -59,7 +59,8 @@
59
59
  "coverage:repowise": "rm -rf coverage && npm run coverage:host-callback && npm run coverage:bundle-readiness && npm run test:jsx-types",
60
60
  "coverage:host-callback": "rm -rf test/.tmp && tsc -p test/tsconfig.json && c8 --reporter=lcov --reports-dir=coverage/host-callback --exclude-after-remap --exclude='**/*.test.ts' node test/.tmp/test/postmessage-host-callback.test.js && node scripts/name-lcov-test.mjs coverage/host-callback/lcov.info test/postmessage-host-callback.test.ts",
61
61
  "coverage:bundle-readiness": "rm -rf test/.tmp && tsc -p test/tsconfig.json && c8 --reporter=lcov --reports-dir=coverage/bundle-readiness --exclude-after-remap --exclude='**/*.test.ts' node test/.tmp/test/bundle-readiness.test.js && node scripts/name-lcov-test.mjs coverage/bundle-readiness/lcov.info test/bundle-readiness.test.ts",
62
- "prepublishOnly": "npm run build:all:min && npm run types"
62
+ "prepublishOnly": "npm run build:all:min && npm run types",
63
+ "test:loader-lifecycle": "node --test test/loader-lifecycle.test.mjs"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@types/react": "^19.1.10",