@wix/web5-embed 0.1.2 → 0.1.3

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.
package/dist/index.js CHANGED
@@ -1,345 +1,322 @@
1
- const f = "__web5InputFocusShortcut__", v = 'input, textarea, [contenteditable=""], [contenteditable="true"]', T = '[role="dialog"][aria-modal="true"]';
2
- function I(t) {
3
- if (t.hasAttribute("inert")) return !1;
4
- if (typeof t.checkVisibility == "function")
5
- return t.checkVisibility({
1
+ const l = "__web5InputFocusShortcut__", v = 'input, textarea, [contenteditable=""], [contenteditable="true"]', C = '[role="dialog"][aria-modal="true"]';
2
+ function E(e) {
3
+ if (e.hasAttribute("inert")) return !1;
4
+ if (typeof e.checkVisibility == "function")
5
+ return e.checkVisibility({
6
6
  checkOpacity: !0,
7
7
  checkVisibilityCSS: !0
8
8
  });
9
- const e = getComputedStyle(t);
10
- return !(e.visibility === "hidden" || e.display === "none" || parseFloat(e.opacity) === 0);
9
+ const t = getComputedStyle(e);
10
+ return !(t.visibility === "hidden" || t.display === "none" || parseFloat(t.opacity) === 0);
11
11
  }
12
- function k(t) {
13
- const e = t.composedPath();
14
- for (const n of e)
12
+ function T(e) {
13
+ const t = e.composedPath();
14
+ for (const n of t)
15
15
  if (n instanceof Element && typeof n.matches == "function" && n.matches(v))
16
16
  return !0;
17
17
  return !1;
18
18
  }
19
- function K() {
20
- const t = window;
21
- if (t[f]) return t[f];
22
- const e = [];
19
+ function j() {
20
+ const e = window;
21
+ if (e[l]) return e[l];
22
+ const t = [];
23
23
  let n = !1;
24
- const r = (i) => {
24
+ const o = (i) => {
25
25
  if (i.defaultPrevented || i.isComposing) return;
26
- const c = i.key === "/" && !i.metaKey && !i.ctrlKey && !i.altKey && !i.shiftKey, l = (i.metaKey || i.ctrlKey) && !i.altKey && i.key.toLowerCase() === "k";
27
- if (!c && !l || c && k(i)) return;
28
- const m = document.querySelectorAll(T);
29
- for (const u of m)
30
- if (I(u)) return;
31
- const w = e.find((u) => u.isVisible());
32
- if (!w) return;
26
+ const c = i.key === "/" && !i.metaKey && !i.ctrlKey && !i.altKey && !i.shiftKey, u = (i.metaKey || i.ctrlKey) && !i.altKey && i.key.toLowerCase() === "k";
27
+ if (!c && !u || c && T(i)) return;
28
+ const b = document.querySelectorAll(C);
29
+ for (const d of b)
30
+ if (E(d)) return;
31
+ const f = t.find((d) => d.isVisible());
32
+ if (!f) return;
33
33
  i.preventDefault();
34
- const d = document.activeElement instanceof HTMLElement ? document.activeElement : null;
35
- w.focus(d);
36
- }, o = () => {
37
- n || (window.addEventListener("keydown", r), n = !0);
38
- }, s = () => {
39
- !n || e.length > 0 || (window.removeEventListener("keydown", r), n = !1);
40
- }, a = {
34
+ const y = document.activeElement instanceof HTMLElement ? document.activeElement : null;
35
+ f.focus(y);
36
+ }, r = () => {
37
+ n || (window.addEventListener("keydown", o), n = !0);
38
+ }, a = () => {
39
+ !n || t.length > 0 || (window.removeEventListener("keydown", o), n = !1);
40
+ }, s = {
41
41
  register(i) {
42
- e.includes(i) || e.push(i), o();
42
+ t.includes(i) || t.push(i), r();
43
43
  },
44
44
  unregister(i) {
45
- const c = e.indexOf(i);
46
- c >= 0 && e.splice(c, 1), s();
45
+ const c = t.indexOf(i);
46
+ c >= 0 && t.splice(c, 1), a();
47
47
  },
48
48
  __teardown() {
49
- e.length = 0, n && (window.removeEventListener("keydown", r), n = !1);
49
+ t.length = 0, n && (window.removeEventListener("keydown", o), n = !1);
50
50
  }
51
51
  };
52
- return t[f] = a, a;
52
+ return e[l] = s, s;
53
53
  }
54
- function q() {
55
- const t = window;
56
- t[f]?.__teardown(), delete t[f];
54
+ function J() {
55
+ const e = window;
56
+ e[l]?.__teardown(), delete e[l];
57
57
  }
58
- const A = "https://www.wixapis.com/web50-server/static-versions", g = "__web5_static_versions";
59
- async function S(t = A) {
60
- const e = await fetch(t, {
58
+ const I = "https://www.wixapis.com/web50-server/static-versions", m = "__web5_static_versions";
59
+ async function _(e = I) {
60
+ const t = await fetch(e, {
61
61
  method: "GET",
62
62
  headers: { Accept: "application/json" },
63
63
  mode: "cors",
64
64
  credentials: "omit"
65
65
  });
66
- if (!e.ok)
67
- throw new Error(`[Web5Embed] static-versions returned ${e.status}`);
68
- return e.json();
66
+ if (!t.ok)
67
+ throw new Error(`[Web5Embed] static-versions returned ${t.status}`);
68
+ return t.json();
69
69
  }
70
- function h(t, e) {
71
- const n = t.find((r) => r.artifactId === e);
70
+ function w(e, t) {
71
+ const n = e.find((o) => o.artifactId === t);
72
72
  if (!n)
73
73
  throw new Error(
74
- `[Web5Embed] artifact ${e} not found in static-versions`
74
+ `[Web5Embed] artifact ${t} not found in static-versions`
75
75
  );
76
76
  return n.version;
77
77
  }
78
- function _() {
79
- return window[g];
78
+ function S() {
79
+ return window[m];
80
80
  }
81
- function L(t) {
82
- window[g] = t;
81
+ function A(e) {
82
+ window[m] = e;
83
83
  }
84
- const x = {
84
+ const k = {
85
85
  staticVersionsUrl: "https://www.wixapis.com/web50-server/static-versions",
86
86
  tokensCdnBase: "https://static.parastorage.com/services/web50-server-ui",
87
87
  tokensArtifactId: "com.wixpress.web50-server-ui",
88
88
  tokensFileName: "prompt-input-tokens.css",
89
89
  fallbackVersion: "1.459.0"
90
90
  };
91
- function b(t) {
92
- return { ...x, ...t ?? {} };
91
+ function p(e) {
92
+ return { ...k, ...e ?? {} };
93
93
  }
94
- function F(t, e) {
95
- const { tokensCdnBase: n, tokensFileName: r } = b(e);
96
- return `${n}/${t}/${r}`;
94
+ function L(e, t) {
95
+ const { tokensCdnBase: n, tokensFileName: o } = p(t);
96
+ return `${n}/${e}/${o}`;
97
97
  }
98
- async function M(t) {
99
- const e = b(t);
98
+ async function M(e) {
99
+ const t = p(e);
100
100
  try {
101
- const n = _();
102
- if (n) return h(n, e.tokensArtifactId);
103
- const r = await S(e.staticVersionsUrl);
104
- return L(r), h(r, e.tokensArtifactId);
101
+ const n = S();
102
+ if (n) return w(n, t.tokensArtifactId);
103
+ const o = await _(t.staticVersionsUrl);
104
+ return A(o), w(o, t.tokensArtifactId);
105
105
  } catch (n) {
106
106
  return console.warn(
107
107
  "[Web5Embed] Failed to resolve prompt token version, using fallback:",
108
108
  n
109
- ), e.fallbackVersion;
109
+ ), t.fallbackVersion;
110
110
  }
111
111
  }
112
- async function P(t) {
113
- const e = await M(t);
114
- return F(e, t);
112
+ async function H(e) {
113
+ const t = await M(e);
114
+ return L(t, e);
115
115
  }
116
- async function j(t, e) {
117
- if (t.querySelector(
116
+ async function X(e, t) {
117
+ if (e.querySelector(
118
118
  'link[data-web5-prompt-input-tokens="true"]'
119
119
  )) return;
120
- const r = document.createElement("link");
121
- r.rel = "stylesheet", r.dataset.web5PromptInputTokens = "true", r.href = await P(e), t.prepend(r);
120
+ const o = document.createElement("link");
121
+ o.rel = "stylesheet", o.dataset.web5PromptInputTokens = "true", o.href = await H(t), e.prepend(o);
122
122
  }
123
- const J = `
123
+ const Y = `
124
124
  <svg class="web5-submit-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none" aria-hidden="true">
125
125
  <path d="M13.0306 7.53114C12.9609 7.60106 12.8781 7.65654 12.787 7.69439C12.6958 7.73224 12.5981 7.75173 12.4993 7.75173C12.4006 7.75173 12.3029 7.73224 12.2117 7.69439C12.1206 7.65654 12.0378 7.60106 11.9681 7.53114L8.74997 4.31301V13.5005C8.74997 13.6994 8.67095 13.8902 8.5303 14.0308C8.38965 14.1715 8.19888 14.2505 7.99997 14.2505C7.80106 14.2505 7.61029 14.1715 7.46964 14.0308C7.32899 13.8902 7.24997 13.6994 7.24997 13.5005V4.31301L4.0306 7.53114C3.8897 7.67203 3.69861 7.75119 3.49935 7.75119C3.30009 7.75119 3.10899 7.67203 2.9681 7.53114C2.8272 7.39024 2.74805 7.19915 2.74805 6.99989C2.74805 6.80063 2.8272 6.60953 2.9681 6.46864L7.4681 1.96864C7.53778 1.89872 7.62057 1.84324 7.71173 1.80539C7.8029 1.76753 7.90064 1.74805 7.99935 1.74805C8.09806 1.74805 8.1958 1.76753 8.28696 1.80539C8.37813 1.84324 8.46092 1.89872 8.5306 1.96864L13.0306 6.46864C13.1005 6.53832 13.156 6.62111 13.1938 6.71227C13.2317 6.80344 13.2512 6.90118 13.2512 6.99989C13.2512 7.0986 13.2317 7.19634 13.1938 7.2875C13.156 7.37867 13.1005 7.46146 13.0306 7.53114Z" fill="currentColor" />
126
126
  </svg>
127
127
  `;
128
- function U(t) {
129
- return `${t}?initialQuestion=`;
130
- }
131
- function Y(t) {
132
- return t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
133
- }
134
- const O = "/_api/page-enrichment/v1/page-meta-data/chips", y = 5e3, H = "https://www.wixapis.com/wix-assistant-web5/v1/turn", V = "https://www.wixapis.com/wix-assistant-web5/v1/conversation", p = "pdpChips";
135
- async function G(t, e = {}) {
136
- if (e.conversation?.web5Id)
137
- return $({
138
- ...e.conversation,
139
- timeoutMs: e.timeoutMs,
140
- fetchImpl: e.fetchImpl
128
+ function x(e) {
129
+ return `${e}?initialQuestion=`;
130
+ }
131
+ function z(e) {
132
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
133
+ }
134
+ const F = "/_api/page-enrichment/v1/page-meta-data/chips", h = 5e3, O = "https://www.wixapis.com/wix-assistant-web5/v1/turn", P = "pdpChips";
135
+ async function G(e, t = {}) {
136
+ if (t.conversation?.web5Id)
137
+ return U({
138
+ ...t.conversation,
139
+ timeoutMs: t.timeoutMs,
140
+ fetchImpl: t.fetchImpl
141
141
  });
142
- const n = e.endpoint ?? O, r = e.timeoutMs ?? y, o = C(e.fetchImpl), s = new AbortController(), a = setTimeout(() => s.abort(), r);
142
+ const n = t.endpoint ?? F, o = t.timeoutMs ?? h, r = g(t.fetchImpl), a = new AbortController(), s = setTimeout(() => a.abort(), o);
143
143
  try {
144
- const i = await o(
145
- `${n}?url=${encodeURIComponent(t)}`,
146
- { signal: s.signal }
144
+ const i = await r(
145
+ `${n}?url=${encodeURIComponent(e)}`,
146
+ { signal: a.signal }
147
147
  );
148
148
  if (!i.ok)
149
149
  throw new Error(`HTTP ${i.status}`);
150
- return (await i.json()).chips?.map((l) => l.label).filter(Boolean) ?? [];
150
+ return (await i.json()).chips?.map((u) => u.label).filter(Boolean) ?? [];
151
151
  } finally {
152
- clearTimeout(a);
152
+ clearTimeout(s);
153
153
  }
154
154
  }
155
- async function $(t) {
156
- const n = (t.api ?? "turn") === "conversation", r = t.endpoint ?? (n ? V : H), o = t.timeoutMs ?? y, s = C(t.fetchImpl), a = new AbortController(), i = setTimeout(() => a.abort(), o);
155
+ async function U(e) {
156
+ const t = e.endpoint ?? O, n = e.timeoutMs ?? h, o = g(e.fetchImpl), r = new AbortController(), a = setTimeout(() => r.abort(), n);
157
157
  try {
158
- const c = t.handle ?? "<unknown>", m = `Tell me about the ${t.entityType ?? "product"} with handle "${c}" from the user's current page.`, w = n ? {
159
- // `/v1/conversation` shape — same as the placements POST.
160
- ...t.chatId ? { chatId: t.chatId } : {},
161
- query: m,
162
- additionalData: {
163
- ...t.mode ? { mode: t.mode } : {},
164
- // Per-placement running-context key, like the placements use.
165
- ...t.sessionId ? { sessionId: `${t.sessionId}-${p}` } : {},
166
- placement: p,
167
- ...t.web5Id ? { predecessorTriggerId: t.web5Id } : {}
168
- }
169
- } : {
170
- // `TurnRequest` shape (DL #110) — lock-free.
171
- text: m,
172
- ...t.sessionId ? { sessionId: t.sessionId } : {},
173
- ...t.web5Id ? { parentMessageId: t.web5Id } : {},
174
- placement: p
175
- }, d = await s(r, {
158
+ const s = e.handle ? { handle: e.handle } : void 0, i = {
159
+ ...e.sessionId ? { sessionId: e.sessionId } : {},
160
+ ...e.web5Id ? { parentMessageId: e.web5Id } : {},
161
+ placement: P,
162
+ ...s ? { additionalData: s } : {}
163
+ }, c = await o(t, {
176
164
  method: "POST",
177
165
  headers: {
178
166
  "Content-Type": "application/json",
179
167
  Accept: "text/event-stream"
180
168
  },
181
- body: JSON.stringify(w),
182
- signal: a.signal
169
+ body: JSON.stringify(i),
170
+ signal: r.signal
183
171
  });
184
- if (!d.ok)
185
- throw new Error(`HTTP ${d.status}`);
186
- const u = await d.text(), E = n ? D(u) : N(u);
187
- return W(E);
172
+ if (!c.ok)
173
+ throw new Error(`HTTP ${c.status}`);
174
+ const u = await c.text();
175
+ return N(V(u));
188
176
  } finally {
189
- clearTimeout(i);
177
+ clearTimeout(a);
190
178
  }
191
179
  }
192
- function C(t) {
193
- return t || (typeof window < "u" ? fetch.bind(window) : fetch);
180
+ function g(e) {
181
+ return e || (typeof window < "u" ? fetch.bind(window) : fetch);
194
182
  }
195
- function N(t) {
196
- let e = t.trim();
197
- if (!e) return "";
198
- e.endsWith(",") && (e = e.slice(0, -1)), e.startsWith("[") || (e = `[${e}`), e.endsWith("]") || (e += "]");
183
+ function V(e) {
184
+ let t = e.trim();
185
+ if (!t) return "";
186
+ t.endsWith(",") && (t = t.slice(0, -1)), t.startsWith("[") || (t = `[${t}`), t.endsWith("]") || (t += "]");
199
187
  try {
200
- const n = JSON.parse(e);
188
+ const n = JSON.parse(t);
201
189
  if (!Array.isArray(n)) return "";
202
- const r = n.find(
203
- (o) => typeof o?.completed?.markdown == "string"
190
+ const o = n.find(
191
+ (r) => typeof r?.completed?.markdown == "string"
204
192
  )?.completed?.markdown;
205
- return r || n.map((o) => typeof o?.markdown == "string" ? o.markdown : "").join("");
193
+ return o || n.map((r) => typeof r?.markdown == "string" ? r.markdown : "").join("");
206
194
  } catch {
207
195
  return "";
208
196
  }
209
197
  }
210
- function D(t) {
211
- let e = t.trim();
212
- if (!e) return "";
213
- e.endsWith(",") && (e = e.slice(0, -1)), e.startsWith("[") || (e = `[${e}`), e.endsWith("]") || (e += "]");
198
+ function N(e) {
199
+ const t = e.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "").trim();
200
+ if (!t) return [];
214
201
  try {
215
- const n = JSON.parse(e);
216
- return Array.isArray(n) ? n.map((r) => typeof r?.markdown == "string" ? r.markdown : "").join("") : "";
217
- } catch {
218
- return "";
219
- }
220
- }
221
- function W(t) {
222
- const e = t.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, "").trim();
223
- if (!e) return [];
224
- try {
225
- return JSON.parse(e).chips?.map((r) => r.label).filter(Boolean) ?? [];
202
+ return JSON.parse(t).chips?.map((o) => o.label).filter(Boolean) ?? [];
226
203
  } catch {
227
204
  return [];
228
205
  }
229
206
  }
230
- function Z(t) {
231
- if (t instanceof HTMLElement) return t;
232
- if (typeof t == "string") {
233
- const r = document.querySelector(t);
234
- if (!r)
235
- throw new Error(`[Web5Embed] Target element not found: ${t}`);
236
- return r;
207
+ function Z(e) {
208
+ if (e instanceof HTMLElement) return e;
209
+ if (typeof e == "string") {
210
+ const o = document.querySelector(e);
211
+ if (!o)
212
+ throw new Error(`[Web5Embed] Target element not found: ${e}`);
213
+ return o;
237
214
  }
238
- const e = document.currentScript, n = document.createElement("div");
239
- return e?.parentElement ? e.parentElement.insertBefore(n, e) : document.body.appendChild(n), n;
240
- }
241
- function Q(t) {
242
- return t ? new URLSearchParams(window.location.search).has(t) : !0;
243
- }
244
- function X(t, e = []) {
245
- return !(Array.isArray(t) ? t : t != null ? [t] : e).includes(window.location.pathname);
246
- }
247
- function B(t) {
248
- if (!t) return {};
249
- const e = {}, n = t.getAttribute("data-target");
250
- n && (e.target = n);
251
- const r = t.getAttribute("data-placeholder");
252
- r && (e.placeholder = r);
253
- const o = t.getAttribute("data-base-url");
254
- o && (e.baseUrl = o);
255
- const s = t.getAttribute("data-require-param");
256
- s && (e.requireParam = s);
257
- const a = t.getAttribute("data-suggestions");
258
- if (a)
215
+ const t = document.currentScript, n = document.createElement("div");
216
+ return t?.parentElement ? t.parentElement.insertBefore(n, t) : document.body.appendChild(n), n;
217
+ }
218
+ function Q(e) {
219
+ return e ? new URLSearchParams(window.location.search).has(e) : !0;
220
+ }
221
+ function ee(e, t = []) {
222
+ return !(Array.isArray(e) ? e : e != null ? [e] : t).includes(window.location.pathname);
223
+ }
224
+ function R(e) {
225
+ if (!e) return {};
226
+ const t = {}, n = e.getAttribute("data-target");
227
+ n && (t.target = n);
228
+ const o = e.getAttribute("data-placeholder");
229
+ o && (t.placeholder = o);
230
+ const r = e.getAttribute("data-base-url");
231
+ r && (t.baseUrl = r);
232
+ const a = e.getAttribute("data-require-param");
233
+ a && (t.requireParam = a);
234
+ const s = e.getAttribute("data-suggestions");
235
+ if (s)
259
236
  try {
260
- const i = JSON.parse(a);
261
- Array.isArray(i) && i.length && (e.suggestions = i);
237
+ const i = JSON.parse(s);
238
+ Array.isArray(i) && i.length && (t.suggestions = i);
262
239
  } catch {
263
240
  console.warn("[Web5Embed] Invalid data-suggestions JSON, ignoring.");
264
241
  }
265
- return e;
266
- }
267
- function z(t) {
268
- const e = B(t);
269
- if (!t) return e;
270
- const n = t.getAttribute("data-visibility-mode");
271
- (n === "always" || n === "after-target") && (e.visibilityMode = n);
272
- const r = t.getAttribute("data-show-after-target");
273
- r && (e.showAfterTarget = r);
274
- const o = t.getAttribute("data-exclude-paths");
275
- return o && (e.excludePaths = o.includes(",") ? o.split(",").map((s) => s.trim()) : o), e;
276
- }
277
- function tt(t) {
242
+ return t;
243
+ }
244
+ function te(e) {
245
+ const t = R(e);
246
+ if (!e) return t;
247
+ const n = e.getAttribute("data-visibility-mode");
248
+ (n === "always" || n === "after-target") && (t.visibilityMode = n);
249
+ const o = e.getAttribute("data-show-after-target");
250
+ o && (t.showAfterTarget = o);
251
+ const r = e.getAttribute("data-exclude-paths");
252
+ return r && (t.excludePaths = r.includes(",") ? r.split(",").map((a) => a.trim()) : r), t;
253
+ }
254
+ function ne(e) {
278
255
  if (typeof window > "u") return;
279
- const e = window.__web5Loader__;
280
- if (!e) {
256
+ const t = window.__web5Loader__;
257
+ if (!t) {
281
258
  console.warn(
282
- `[Web5Embed] window.__web5Loader__ not present; widget "${t.widgetId}" will not mount`
259
+ `[Web5Embed] window.__web5Loader__ not present; widget "${e.widgetId}" will not mount`
283
260
  );
284
261
  return;
285
262
  }
286
- const n = async (r) => t.mount(r, t.parseOptions(r.options));
287
- e.register(t.widgetId, n);
288
- }
289
- function et(t) {
290
- return (e, n) => {
291
- const r = n.variant;
292
- if (!r || r === "default")
293
- return t.default(e, n);
294
- const o = t.variants?.[r];
295
- return o ? o(e, n) : (console.warn(
296
- `[Web5Embed] unknown variant "${r}" — falling back to default`
297
- ), t.default(e, n));
263
+ const n = async (o) => e.mount(o, e.parseOptions(o.options));
264
+ t.register(e.widgetId, n);
265
+ }
266
+ function oe(e) {
267
+ return (t, n) => {
268
+ const o = n.variant;
269
+ if (!o || o === "default")
270
+ return e.default(t, n);
271
+ const r = e.variants?.[o];
272
+ return r ? r(t, n) : (console.warn(
273
+ `[Web5Embed] unknown variant "${o}" — falling back to default`
274
+ ), e.default(t, n));
298
275
  };
299
276
  }
300
- function nt(t) {
301
- const e = (n) => t?.[n];
277
+ function re(e) {
278
+ const t = (n) => e?.[n];
302
279
  return {
303
280
  isEnabled: (n) => {
304
- const r = e(n);
305
- return r?.status === "SUCCESSFUL" && r.enabled === !0;
281
+ const o = t(n);
282
+ return o?.status === "SUCCESSFUL" && o.enabled === !0;
306
283
  },
307
- get: e
284
+ get: t
308
285
  };
309
286
  }
310
- function rt(t) {
287
+ function ie(e) {
311
288
  const {
312
- input: e,
289
+ input: t,
313
290
  wrapper: n,
314
- multilineClass: r,
315
- maxHeightPx: o,
316
- multilineThresholdMultiplier: s = 1,
317
- fallbackLineHeightPx: a = 32
318
- } = t;
291
+ multilineClass: o,
292
+ maxHeightPx: r,
293
+ multilineThresholdMultiplier: a = 1,
294
+ fallbackLineHeightPx: s = 32
295
+ } = e;
319
296
  return {
320
297
  sync() {
321
298
  if (!n) return;
322
- const i = window.getComputedStyle(e), c = Number.parseFloat(i.lineHeight) || a;
323
- e.style.height = "auto";
324
- const l = e.value.trim().length === 0 ? c : Math.min(Math.max(e.scrollHeight, c), o);
325
- e.style.height = `${l}px`, n.classList.toggle(
326
- r,
327
- l > c * s
299
+ const i = window.getComputedStyle(t), c = Number.parseFloat(i.lineHeight) || s;
300
+ t.style.height = "auto";
301
+ const u = t.value.trim().length === 0 ? c : Math.min(Math.max(t.scrollHeight, c), r);
302
+ t.style.height = `${u}px`, n.classList.toggle(
303
+ o,
304
+ u > c * a
328
305
  );
329
306
  }
330
307
  };
331
308
  }
332
- const R = 400;
333
- function ot(t = {}) {
334
- const e = t.thresholdPx ?? R;
309
+ const B = 400;
310
+ function se(e = {}) {
311
+ const t = e.thresholdPx ?? B;
335
312
  let n = !1;
336
- function r() {
337
- const o = document.documentElement, s = window.scrollY || o.scrollTop || 0, a = s + window.innerHeight, i = o.scrollHeight - a;
338
- return o.scrollHeight > window.innerHeight + e && s > 0 && i <= e;
313
+ function o() {
314
+ const r = document.documentElement, a = window.scrollY || r.scrollTop || 0, s = a + window.innerHeight, i = r.scrollHeight - s;
315
+ return r.scrollHeight > window.innerHeight + t && a > 0 && i <= t;
339
316
  }
340
317
  return {
341
- evaluate(o) {
342
- return !o.isCoordinatorVisible() || !r() ? (n = !1, !1) : o.hasFocusInside() || n ? o.isCollapsed() : !0;
318
+ evaluate(r) {
319
+ return !r.isCoordinatorVisible() || !o() ? (n = !1, !1) : r.hasFocusInside() || n ? r.isCollapsed() : !0;
343
320
  },
344
321
  markManuallyExpanded() {
345
322
  n = !0;
@@ -349,45 +326,90 @@ function ot(t = {}) {
349
326
  }
350
327
  };
351
328
  }
352
- function it(t) {
353
- if (!t.baseUrl)
329
+ function ae(e) {
330
+ if (!e.baseUrl)
354
331
  throw new Error(
355
332
  "[Web5Embed] createSubmitFlow requires a non-empty baseUrl."
356
333
  );
357
- const e = U(t.baseUrl), n = t.windowTarget ?? "_self";
334
+ const t = x(e.baseUrl), n = e.windowTarget ?? "_self";
358
335
  return {
359
- open(r) {
360
- return window.open(e + encodeURIComponent(r), n), !0;
336
+ open(o) {
337
+ return window.open(t + encodeURIComponent(o), n), !0;
361
338
  }
362
339
  };
363
340
  }
341
+ const D = 100, $ = 0.5, W = 0.8, K = "--web5-host-bottom-inset";
342
+ function q(e) {
343
+ if (typeof document > "u" || typeof window > "u")
344
+ return 0;
345
+ const t = /* @__PURE__ */ new Set();
346
+ for (const o of ["body > *", "body > * > *"])
347
+ document.querySelectorAll(o).forEach((r) => t.add(r));
348
+ let n = 0;
349
+ for (const o of t) {
350
+ if (e != null && (e.contains(o) || o.contains(e)))
351
+ continue;
352
+ const r = window.getComputedStyle(o);
353
+ if (r.position !== "fixed" && r.position !== "sticky" || r.visibility === "hidden" || r.bottom === "auto")
354
+ continue;
355
+ const a = Number.parseFloat(r.bottom);
356
+ if (!Number.isFinite(a) || a > D)
357
+ continue;
358
+ const s = o.getBoundingClientRect();
359
+ if (s.height <= 0 || s.width < window.innerWidth * W)
360
+ continue;
361
+ const i = window.innerHeight - s.top;
362
+ i <= 0 || i > window.innerHeight * $ || (n = Math.max(n, i));
363
+ }
364
+ return Math.round(n);
365
+ }
366
+ function ce(e, t = {}) {
367
+ if (typeof window > "u")
368
+ return () => {
369
+ };
370
+ const n = t.exclude === void 0 ? e : t.exclude;
371
+ let o = 0, r = !1;
372
+ const a = () => {
373
+ o = 0, !r && e.style.setProperty(K, `${q(n)}px`);
374
+ }, s = () => {
375
+ r || o !== 0 || (o = window.requestAnimationFrame(a));
376
+ };
377
+ a(), window.addEventListener("resize", s, { passive: !0 }), window.addEventListener("orientationchange", s, { passive: !0 });
378
+ let i;
379
+ return typeof MutationObserver < "u" && document.body != null && (i = new MutationObserver(s), i.observe(document.body, { childList: !0, subtree: !1 })), () => {
380
+ r = !0, o !== 0 && (window.cancelAnimationFrame(o), o = 0), window.removeEventListener("resize", s), window.removeEventListener("orientationchange", s), i?.disconnect();
381
+ };
382
+ }
364
383
  export {
365
- A as DEFAULT_STATIC_VERSIONS_URL,
366
- q as __resetFocusShortcutCoordinatorForTests,
367
- j as attachPromptInputTokensStylesheet,
368
- U as buildUrl,
369
- L as cacheVersions,
370
- ot as createCollapseController,
371
- nt as createFeatureToggleReader,
372
- rt as createInputHeightSync,
373
- it as createSubmitFlow,
374
- et as createVariantMount,
375
- Y as escapeHtml,
384
+ I as DEFAULT_STATIC_VERSIONS_URL,
385
+ K as HOST_BOTTOM_INSET_VAR,
386
+ J as __resetFocusShortcutCoordinatorForTests,
387
+ X as attachPromptInputTokensStylesheet,
388
+ x as buildUrl,
389
+ A as cacheVersions,
390
+ se as createCollapseController,
391
+ re as createFeatureToggleReader,
392
+ ie as createInputHeightSync,
393
+ ae as createSubmitFlow,
394
+ oe as createVariantMount,
395
+ z as escapeHtml,
376
396
  G as fetchChipSuggestions,
377
- $ as fetchContextualChips,
378
- S as fetchStaticVersions,
379
- h as findVersion,
380
- _ as getCachedVersions,
381
- K as getFocusShortcutCoordinator,
382
- F as getPromptInputTokensUrl,
383
- B as readBaseConfigFromScript,
384
- z as readBottomConfigFromScript,
385
- tt as registerWeb5Widget,
386
- P as resolvePromptInputTokensUrl,
397
+ U as fetchContextualChips,
398
+ _ as fetchStaticVersions,
399
+ w as findVersion,
400
+ S as getCachedVersions,
401
+ j as getFocusShortcutCoordinator,
402
+ L as getPromptInputTokensUrl,
403
+ q as measureHostBottomInset,
404
+ R as readBaseConfigFromScript,
405
+ te as readBottomConfigFromScript,
406
+ ne as registerWeb5Widget,
407
+ H as resolvePromptInputTokensUrl,
387
408
  M as resolvePromptInputTokensVersion,
388
409
  Z as resolveTarget,
389
- J as sendIconSvg,
410
+ Y as sendIconSvg,
390
411
  Q as shouldInit,
391
- X as shouldInitForPath
412
+ ee as shouldInitForPath,
413
+ ce as trackHostBottomInset
392
414
  };
393
415
  //# sourceMappingURL=index.js.map