@returningai/widget-sdk 1.8.11 → 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.
@@ -13365,6 +13365,90 @@ class WidgetCallbackRegistry {
13365
13365
  return { ...this.registeredCallbacks };
13366
13366
  }
13367
13367
  }
13368
+ const loadedGoogleFontFamilies = /* @__PURE__ */ new Set();
13369
+ const LOCAL_OR_SYSTEM_FONT_FAMILIES = /* @__PURE__ */ new Set([
13370
+ "aeonik",
13371
+ "courier",
13372
+ "courier new",
13373
+ "monaco",
13374
+ "monospace",
13375
+ "sans-serif",
13376
+ "serif",
13377
+ "system-ui"
13378
+ ]);
13379
+ const SERIF_FONT_FAMILIES = /* @__PURE__ */ new Set(["lora", "playfair display", "prata"]);
13380
+ const GOOGLE_FONT_VARIANTS = ":ital,wght@0,300;0,400;0,500;0,600;0,700;1,400;1,700";
13381
+ function normalizeFontFamily(family) {
13382
+ return family.trim() === "Noto" ? "Noto Sans" : family.trim();
13383
+ }
13384
+ function getFontStack(family) {
13385
+ const normalizedFamily = normalizeFontFamily(family);
13386
+ if (normalizedFamily.includes(",")) return normalizedFamily;
13387
+ const normalizedKey = normalizedFamily.toLowerCase();
13388
+ switch (normalizedKey) {
13389
+ case "monospace":
13390
+ return "monospace";
13391
+ case "courier":
13392
+ case "courier new":
13393
+ return '"Courier New", Courier, monospace';
13394
+ case "monaco":
13395
+ return "Monaco, Menlo, Consolas, monospace";
13396
+ case "system-ui":
13397
+ return "system-ui, -apple-system, sans-serif";
13398
+ case "sans-serif":
13399
+ case "serif":
13400
+ return normalizedKey;
13401
+ default:
13402
+ return `'${normalizedFamily.replace(/[\\']/g, "\\\\$&")}', ${SERIF_FONT_FAMILIES.has(normalizedKey) ? "Georgia, 'Times New Roman', serif" : "system-ui, -apple-system, sans-serif"}`;
13403
+ }
13404
+ }
13405
+ function ensureGoogleFontPreconnect() {
13406
+ if (!document.getElementById("rai-fonts-preconnect")) {
13407
+ const link = document.createElement("link");
13408
+ link.id = "rai-fonts-preconnect";
13409
+ link.rel = "preconnect";
13410
+ link.href = "https://fonts.googleapis.com";
13411
+ document.head.appendChild(link);
13412
+ }
13413
+ if (!document.getElementById("rai-fonts-static-preconnect")) {
13414
+ const link = document.createElement("link");
13415
+ link.id = "rai-fonts-static-preconnect";
13416
+ link.rel = "preconnect";
13417
+ link.href = "https://fonts.gstatic.com";
13418
+ link.crossOrigin = "anonymous";
13419
+ document.head.appendChild(link);
13420
+ }
13421
+ }
13422
+ function ensureGoogleFontLoaded(family) {
13423
+ const normalizedFamily = normalizeFontFamily(family);
13424
+ const fontKey = normalizedFamily.toLowerCase();
13425
+ if (!normalizedFamily || normalizedFamily.includes(",") || LOCAL_OR_SYSTEM_FONT_FAMILIES.has(fontKey)) {
13426
+ return;
13427
+ }
13428
+ if (loadedGoogleFontFamilies.has(fontKey)) return;
13429
+ ensureGoogleFontPreconnect();
13430
+ const linkId = `rai-font-${normalizedFamily.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`;
13431
+ const fontUrl = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(
13432
+ normalizedFamily
13433
+ )}${GOOGLE_FONT_VARIANTS}&display=swap`;
13434
+ let link = document.getElementById(linkId);
13435
+ if (link && link.href !== fontUrl) {
13436
+ link.remove();
13437
+ link = null;
13438
+ }
13439
+ if (!link) {
13440
+ link = document.createElement("link");
13441
+ link.id = linkId;
13442
+ link.rel = "stylesheet";
13443
+ link.href = fontUrl;
13444
+ document.head.appendChild(link);
13445
+ }
13446
+ loadedGoogleFontFamilies.add(fontKey);
13447
+ link.onerror = () => {
13448
+ loadedGoogleFontFamilies.delete(fontKey);
13449
+ link == null ? void 0 : link.remove();
13450
+ };
13451
+ }
13368
13452
  const STORE_CALLBACK_FIELD_OPTIONS_SCOPE = "store.callback_field_options";
13369
13453
  const STORE_CALLBACK_FIELD_OPTIONS_CALLBACK_NAME = "callbackFieldOptions";
13370
13454
  const STORE_CALLBACK_FIELD_OPTIONS_TIMEOUT_MS = 15e3;
@@ -14003,89 +14087,6 @@ function resolveWidgetServerUrl(domainKey) {
14003
14087
  function resolveV2ApiUrl(domainKey) {
14004
14088
  return DOMAIN_KEY_TO_V2_API_URL[domainKey] || DOMAIN_KEY_TO_V2_API_URL.PROD;
14005
14089
  }
14006
- const loadedGoogleFontFamilies = /* @__PURE__ */ new Set();
14007
- const LOCAL_OR_SYSTEM_FONT_FAMILIES = /* @__PURE__ */ new Set([
14008
- "aeonik",
14009
- "courier",
14010
- "courier new",
14011
- "monaco",
14012
- "monospace",
14013
- "sans-serif",
14014
- "serif",
14015
- "system-ui"
14016
- ]);
14017
- const SERIF_FONT_FAMILIES = /* @__PURE__ */ new Set(["lora", "playfair display", "prata"]);
14018
- const GOOGLE_FONT_VARIANTS = ":ital,wght@0,300;0,400;0,500;0,600;0,700;1,400;1,700";
14019
- function normalizeFontFamily(family) {
14020
- return family.trim() === "Noto" ? "Noto Sans" : family.trim();
14021
- }
14022
- function getFontStack(family) {
14023
- const normalizedFamily = normalizeFontFamily(family);
14024
- const normalizedKey = normalizedFamily.toLowerCase();
14025
- switch (normalizedKey) {
14026
- case "monospace":
14027
- return "monospace";
14028
- case "courier":
14029
- case "courier new":
14030
- return '"Courier New", Courier, monospace';
14031
- case "monaco":
14032
- return "Monaco, Menlo, Consolas, monospace";
14033
- case "system-ui":
14034
- return "system-ui, -apple-system, sans-serif";
14035
- case "sans-serif":
14036
- case "serif":
14037
- return normalizedKey;
14038
- default:
14039
- return `'${normalizedFamily.replace(/[\\']/g, "\\\\$&")}', ${SERIF_FONT_FAMILIES.has(normalizedKey) ? "Georgia, 'Times New Roman', serif" : "system-ui, -apple-system, sans-serif"}`;
14040
- }
14041
- }
14042
- function ensureGoogleFontPreconnect() {
14043
- if (!document.getElementById("rai-fonts-preconnect")) {
14044
- const link = document.createElement("link");
14045
- link.id = "rai-fonts-preconnect";
14046
- link.rel = "preconnect";
14047
- link.href = "https://fonts.googleapis.com";
14048
- document.head.appendChild(link);
14049
- }
14050
- if (!document.getElementById("rai-fonts-static-preconnect")) {
14051
- const link = document.createElement("link");
14052
- link.id = "rai-fonts-static-preconnect";
14053
- link.rel = "preconnect";
14054
- link.href = "https://fonts.gstatic.com";
14055
- link.crossOrigin = "anonymous";
14056
- document.head.appendChild(link);
14057
- }
14058
- }
14059
- function ensureGoogleFontLoaded(family) {
14060
- const normalizedFamily = normalizeFontFamily(family);
14061
- const fontKey = normalizedFamily.toLowerCase();
14062
- if (!normalizedFamily || LOCAL_OR_SYSTEM_FONT_FAMILIES.has(fontKey)) {
14063
- return;
14064
- }
14065
- if (loadedGoogleFontFamilies.has(fontKey)) return;
14066
- ensureGoogleFontPreconnect();
14067
- const linkId = `rai-font-${normalizedFamily.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`;
14068
- const fontUrl = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(
14069
- normalizedFamily
14070
- )}${GOOGLE_FONT_VARIANTS}&display=swap`;
14071
- let link = document.getElementById(linkId);
14072
- if (link && link.href !== fontUrl) {
14073
- link.remove();
14074
- link = null;
14075
- }
14076
- if (!link) {
14077
- link = document.createElement("link");
14078
- link.id = linkId;
14079
- link.rel = "stylesheet";
14080
- link.href = fontUrl;
14081
- document.head.appendChild(link);
14082
- }
14083
- loadedGoogleFontFamilies.add(fontKey);
14084
- link.onerror = () => {
14085
- loadedGoogleFontFamilies.delete(fontKey);
14086
- link == null ? void 0 : link.remove();
14087
- };
14088
- }
14089
14090
  const DANGEROUS_ELEMENTS = ["script", "iframe", "object", "embed"];
14090
14091
  const URL_ATTRS = ["src", "href", "xlink:href"];
14091
14092
  function sanitizeLoaderHtml(html2) {
@@ -14303,6 +14304,8 @@ class BaseWidget extends HTMLElement {
14303
14304
  return [
14304
14305
  "embed-token",
14305
14306
  "data-embed-token",
14307
+ "theme",
14308
+ "data-theme",
14306
14309
  "language",
14307
14310
  "data-language",
14308
14311
  "locale",
@@ -14325,16 +14328,8 @@ class BaseWidget extends HTMLElement {
14325
14328
  const style = document.createElement("style");
14326
14329
  style.textContent = widgetCSS;
14327
14330
  this.shadow.appendChild(style);
14328
- const theme = this.config.theme;
14329
- const accentColor = theme === "dark" ? "#ffffff" : "#000000";
14330
- const text4Color = theme === "dark" ? "#9ca3af" : "#6b7280";
14331
- const bgColor = theme === "dark" ? "#1a1a1a" : "#ffffff";
14332
14331
  this.style.width = this.config.width;
14333
14332
  this.style.height = this.config.height;
14334
- this.style.setProperty("--rai-accent", accentColor);
14335
- this.style.setProperty("--rai-text4", text4Color);
14336
- this.style.setProperty("--rai-loader-bg", bgColor);
14337
- this.style.setProperty("--rai-error-bg", bgColor);
14338
14333
  this.applyFirstPaintColors();
14339
14334
  this.renderShell();
14340
14335
  if (this.hasAttribute("eager")) {
@@ -14377,6 +14372,8 @@ class BaseWidget extends HTMLElement {
14377
14372
  void this.reload();
14378
14373
  } else {
14379
14374
  this.config = readConfig(this, this.config.communityId);
14375
+ this.applyFirstPaintColors();
14376
+ this.renderLoaderAnimation();
14380
14377
  }
14381
14378
  }
14382
14379
  }
@@ -14452,6 +14449,17 @@ class BaseWidget extends HTMLElement {
14452
14449
  }
14453
14450
  }
14454
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);
14455
14463
  const cachedPalette = (_a = cached == null ? void 0 : cached.themePalette) == null ? void 0 : _a[theme];
14456
14464
  if (cachedPalette) this.applyPalette(cachedPalette);
14457
14465
  const cachedFont = typeof (cached == null ? void 0 : cached.font) === "string" ? cached.font : void 0;
@@ -14535,19 +14543,7 @@ class BaseWidget extends HTMLElement {
14535
14543
  }
14536
14544
  }
14537
14545
  renderShell() {
14538
- this.loaderEl = document.createElement("div");
14539
- this.loaderEl.className = "rai-loader";
14540
- if (this.config.widgetType === "custom" && !loadErrorSettingsFromStorage(this.config)) {
14541
- this.loaderEl.classList.add("rai-loader-pending-settings");
14542
- }
14543
- const textEl = document.createElement("h1");
14544
- textEl.className = "rai-loader-text";
14545
- textEl.textContent = this.config.loadingText;
14546
- this.loaderEl.appendChild(textEl);
14547
- this.shadow.appendChild(this.loaderEl);
14548
- this.freezeIframeLoaderHeight();
14549
- this.applyLoadingSettings();
14550
- this.fetchAndRenderLoader();
14546
+ this.showLoader();
14551
14547
  this.errorEl = document.createElement("div");
14552
14548
  this.errorEl.className = "rai-error";
14553
14549
  this.msgEl = document.createElement("span");
@@ -14562,6 +14558,26 @@ class BaseWidget extends HTMLElement {
14562
14558
  this.errorEl.appendChild(btn);
14563
14559
  this.shadow.appendChild(this.errorEl);
14564
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
+ }
14565
14581
  /**
14566
14582
  * Loads the community loading animation + theme palette from cache or API
14567
14583
  * and renders the configured animation above the loading text.
@@ -14572,6 +14588,7 @@ class BaseWidget extends HTMLElement {
14572
14588
  */
14573
14589
  async fetchAndRenderLoader() {
14574
14590
  var _a;
14591
+ const loaderEl = this.loaderEl;
14575
14592
  const cached = loadErrorSettingsFromStorage(this.config);
14576
14593
  if (cached) {
14577
14594
  applyErrorSettingsToState(this.state, cached);
@@ -14583,8 +14600,7 @@ class BaseWidget extends HTMLElement {
14583
14600
  await fetchErrorSettings(this.config, this.state);
14584
14601
  } catch {
14585
14602
  }
14586
- const loaderEl = this.loaderEl;
14587
- if (!loaderEl) return;
14603
+ if (!loaderEl || loaderEl !== this.loaderEl || !this.isConnected) return;
14588
14604
  if (!this.config.themeExplicit && (this.state.defaultColorSchema === "light" || this.state.defaultColorSchema === "dark") && this.state.defaultColorSchema !== this.config.theme) {
14589
14605
  this.config.theme = this.state.defaultColorSchema;
14590
14606
  }
@@ -14689,7 +14705,7 @@ class BaseWidget extends HTMLElement {
14689
14705
  setTimeout(() => {
14690
14706
  loader.remove();
14691
14707
  lottieInstances.forEach((instance) => instance.destroy());
14692
- this.restoreLoaderHeight();
14708
+ if (!this.loaderEl) this.restoreLoaderHeight();
14693
14709
  }, 300);
14694
14710
  this.loaderEl = null;
14695
14711
  }
@@ -15435,6 +15451,8 @@ class BaseWidget extends HTMLElement {
15435
15451
  this.teardownMountedWidget();
15436
15452
  this.removeBanner();
15437
15453
  clearState(this.state);
15454
+ this.applyFirstPaintColors();
15455
+ this.showLoader();
15438
15456
  await this.init();
15439
15457
  }
15440
15458
  async logoutPublic() {
@@ -15570,7 +15588,7 @@ class CustomWidget extends BaseWidget {
15570
15588
  }
15571
15589
  }
15572
15590
  }
15573
- console.log(`[rai-widget] v${"1.8.11"}`);
15591
+ console.log(`[rai-widget] v${"1.8.13"}`);
15574
15592
  class StoreWidgetCompat extends StoreWidget {
15575
15593
  }
15576
15594
  const WIDGET_REGISTRY = [
@@ -15634,7 +15652,7 @@ function exposePublicApi() {
15634
15652
  })();
15635
15653
  const widget = container == null ? void 0 : container.querySelector(ALL_WIDGET_SELECTOR);
15636
15654
  window.ReturningAIWidget = {
15637
- version: "1.8.11",
15655
+ version: "1.8.13",
15638
15656
  reload: () => (widget == null ? void 0 : widget.reload()) ?? Promise.resolve(),
15639
15657
  logout: () => (widget == null ? void 0 : widget.logoutPublic()) ?? Promise.resolve(),
15640
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.
@@ -0,0 +1,3 @@
1
+ export declare function normalizeFontFamily(family: string): string;
2
+ export declare function getFontStack(family: string): string;
3
+ export declare function ensureGoogleFontLoaded(family: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@returningai/widget-sdk",
3
- "version": "1.8.11",
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: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",
@@ -54,11 +54,13 @@
54
54
  "test:auth-session-coordinator": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/auth-session-coordinator.test.js",
55
55
  "test:startup-performance": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/startup-performance.test.js",
56
56
  "test:widget-error-presentation": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/widget-error-presentation.test.js",
57
+ "test:fonts": "rm -rf test/.tmp && tsc -p test/tsconfig.json && node test/.tmp/test/fonts.test.js",
57
58
  "test:jsx-types": "npm run types && node --test test/jsx/declaration-shape.test.mjs test/jsx/packed-consumer.test.mjs && tsc -p test/jsx/tsconfig.react.json && tsc -p test/jsx/tsconfig.vue.json",
58
59
  "coverage:repowise": "rm -rf coverage && npm run coverage:host-callback && npm run coverage:bundle-readiness && npm run test:jsx-types",
59
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",
60
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",
61
- "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"
62
64
  },
63
65
  "devDependencies": {
64
66
  "@types/react": "^19.1.10",