@resenty/widget 0.0.0

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.
@@ -0,0 +1,214 @@
1
+ import { i as __toESM, n as require_react, r as __commonJSMin } from "./react-dom-B4CdVWWC.js";
2
+ /**
3
+ * @license React
4
+ * react-jsx-runtime.production.js
5
+ *
6
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((e) => {
12
+ var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
13
+ function r(e, n, r) {
14
+ var i = null;
15
+ if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
16
+ else r = n;
17
+ return n = r.ref, {
18
+ $$typeof: t,
19
+ type: e,
20
+ key: i,
21
+ ref: n === void 0 ? null : n,
22
+ props: r
23
+ };
24
+ }
25
+ e.Fragment = n, e.jsx = r, e.jsxs = r;
26
+ })), require_react_jsx_runtime_development = /* @__PURE__ */ __commonJSMin(((e) => {
27
+ process.env.NODE_ENV !== "production" && (function() {
28
+ function n(e) {
29
+ if (e == null) return null;
30
+ if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
31
+ if (typeof e == "string") return e;
32
+ switch (e) {
33
+ case v: return "Fragment";
34
+ case b: return "Profiler";
35
+ case y: return "StrictMode";
36
+ case w: return "Suspense";
37
+ case T: return "SuspenseList";
38
+ case O: return "Activity";
39
+ }
40
+ if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
41
+ case _: return "Portal";
42
+ case S: return e.displayName || "Context";
43
+ case x: return (e._context.displayName || "Context") + ".Consumer";
44
+ case C:
45
+ var t = e.render;
46
+ return e = e.displayName, e ||= (e = t.displayName || t.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
47
+ case E: return t = e.displayName || null, t === null ? n(e.type) || "Memo" : t;
48
+ case D:
49
+ t = e._payload, e = e._init;
50
+ try {
51
+ return n(e(t));
52
+ } catch {}
53
+ }
54
+ return null;
55
+ }
56
+ function r(e) {
57
+ return "" + e;
58
+ }
59
+ function i(e) {
60
+ try {
61
+ r(e);
62
+ var t = !1;
63
+ } catch {
64
+ t = !0;
65
+ }
66
+ if (t) {
67
+ t = console;
68
+ var n = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
69
+ return n.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), r(e);
70
+ }
71
+ }
72
+ function a(e) {
73
+ if (e === v) return "<>";
74
+ if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
75
+ try {
76
+ var t = n(e);
77
+ return t ? "<" + t + ">" : "<...>";
78
+ } catch {
79
+ return "<...>";
80
+ }
81
+ }
82
+ function o() {
83
+ var e = A.A;
84
+ return e === null ? null : e.getOwner();
85
+ }
86
+ function s() {
87
+ return Error("react-stack-top-frame");
88
+ }
89
+ function c(e) {
90
+ if (j.call(e, "key")) {
91
+ var t = Object.getOwnPropertyDescriptor(e, "key").get;
92
+ if (t && t.isReactWarning) return !1;
93
+ }
94
+ return e.key !== void 0;
95
+ }
96
+ function l(e, t) {
97
+ function n() {
98
+ P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
99
+ }
100
+ n.isReactWarning = !0, Object.defineProperty(e, "key", {
101
+ get: n,
102
+ configurable: !0
103
+ });
104
+ }
105
+ function u() {
106
+ var e = n(this.type);
107
+ return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
108
+ }
109
+ function d(e, t, n, r, i, a) {
110
+ var o = n.ref;
111
+ return e = {
112
+ $$typeof: g,
113
+ type: e,
114
+ key: t,
115
+ props: n,
116
+ _owner: r
117
+ }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
118
+ enumerable: !1,
119
+ value: null
120
+ }) : Object.defineProperty(e, "ref", {
121
+ enumerable: !1,
122
+ get: u
123
+ }), e._store = {}, Object.defineProperty(e._store, "validated", {
124
+ configurable: !1,
125
+ enumerable: !1,
126
+ writable: !0,
127
+ value: 0
128
+ }), Object.defineProperty(e, "_debugInfo", {
129
+ configurable: !1,
130
+ enumerable: !1,
131
+ writable: !0,
132
+ value: null
133
+ }), Object.defineProperty(e, "_debugStack", {
134
+ configurable: !1,
135
+ enumerable: !1,
136
+ writable: !0,
137
+ value: i
138
+ }), Object.defineProperty(e, "_debugTask", {
139
+ configurable: !1,
140
+ enumerable: !1,
141
+ writable: !0,
142
+ value: a
143
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
144
+ }
145
+ function f(e, t, r, a, s, u) {
146
+ var f = t.children;
147
+ if (f !== void 0) if (a) if (M(f)) {
148
+ for (a = 0; a < f.length; a++) p(f[a]);
149
+ Object.freeze && Object.freeze(f);
150
+ } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
151
+ else p(f);
152
+ if (j.call(t, "key")) {
153
+ f = n(e);
154
+ var m = Object.keys(t).filter(function(e) {
155
+ return e !== "key";
156
+ });
157
+ a = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + a] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, f, m, f), R[f + a] = !0);
158
+ }
159
+ if (f = null, r !== void 0 && (i(r), f = "" + r), c(t) && (i(t.key), f = "" + t.key), "key" in t) for (var h in r = {}, t) h !== "key" && (r[h] = t[h]);
160
+ else r = t;
161
+ return f && l(r, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, r, o(), s, u);
162
+ }
163
+ function p(e) {
164
+ m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
165
+ }
166
+ function m(e) {
167
+ return typeof e == "object" && !!e && e.$$typeof === g;
168
+ }
169
+ var h = require_react(), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
170
+ return null;
171
+ };
172
+ h = { react_stack_bottom_frame: function(e) {
173
+ return e();
174
+ } };
175
+ var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(a(s)), R = {};
176
+ e.Fragment = v, e.jsx = function(e, t, n) {
177
+ var r = 1e4 > A.recentlyCreatedOwnerStacks++;
178
+ return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(a(e)) : L);
179
+ }, e.jsxs = function(e, t, n) {
180
+ var r = 1e4 > A.recentlyCreatedOwnerStacks++;
181
+ return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(a(e)) : L);
182
+ };
183
+ })();
184
+ })), require_jsx_runtime = /* @__PURE__ */ __commonJSMin(((e, t) => {
185
+ process.env.NODE_ENV === "production" ? t.exports = require_react_jsx_runtime_production() : t.exports = require_react_jsx_runtime_development();
186
+ })), import_react = /* @__PURE__ */ __toESM(require_react(), 1), import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1), QueryClientContext = import_react.createContext(void 0), useQueryClient = (e) => {
187
+ let t = import_react.useContext(QueryClientContext);
188
+ if (e) return e;
189
+ if (!t) throw Error("No QueryClient set, use QueryClientProvider to set one");
190
+ return t;
191
+ }, QueryClientProvider = ({ client: e, children: t }) => (import_react.useEffect(() => (e.mount(), () => {
192
+ e.unmount();
193
+ }), [e]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QueryClientContext.Provider, {
194
+ value: e,
195
+ children: t
196
+ }));
197
+ function assertContextExists(e, t) {
198
+ if (!e) throw typeof t == "string" ? Error(t) : /* @__PURE__ */ Error(`${t.displayName} not found`);
199
+ }
200
+ const createContextAndHook = (e, t) => {
201
+ let { assertCtxFn: n = assertContextExists } = t || {}, r = import_react.createContext(void 0);
202
+ return r.displayName = e, [
203
+ r,
204
+ () => {
205
+ let t = import_react.useContext(r);
206
+ return n(t, `${e} not found`), t.value;
207
+ },
208
+ () => {
209
+ let e = import_react.useContext(r);
210
+ return e ? e.value : {};
211
+ }
212
+ ];
213
+ }, [CoreContext, useCore] = createContextAndHook("CoreContext", { assertCtxFn: assertContextExists });
214
+ export { QueryClientProvider as a, createContextAndHook as i, useCore as n, useQueryClient as o, assertContextExists as r, require_jsx_runtime as s, CoreContext as t };
@@ -0,0 +1,348 @@
1
+ import { n as __toESM } from "./rolldown-runtime-B_fQOXul.js";
2
+ import { F as merge, M as record, N as string, P as toMerged, j as object } from "./vendor-CAJw9nfJ.js";
3
+ import { C as Client, S as QueryClient, b as require_jsx_runtime, g as require_react_dom, w as client, x as require_react, y as QueryClientProvider } from "./query-common-D_G8O-M_.js";
4
+ import { p as CoreContext } from "./ui-common-DfZ7eP4u.js";
5
+ var DefaultMessages = Object.freeze({
6
+ MissingWidgetIdErrorMessage: "Missing widgetId. You can get your key at https://app.resenty.com/widget.",
7
+ NotInBrowserErrorMessage: "Widget can only be used in a browser for the time being."
8
+ }), ResentyError = class extends Error {
9
+ constructor(b) {
10
+ super(b), this.name = "ResentyError";
11
+ }
12
+ };
13
+ function buildErrorThrower({ packageName: b }) {
14
+ let Y = b;
15
+ function X(b) {
16
+ return `${Y}: ${b}`;
17
+ }
18
+ return {
19
+ setPackageName({ packageName: b }) {
20
+ return typeof b == "string" && (Y = b), this;
21
+ },
22
+ throwMissingWidgetIdError() {
23
+ return this.throw(DefaultMessages.MissingWidgetIdErrorMessage);
24
+ },
25
+ throwNotInBrowserError() {
26
+ return this.throw(DefaultMessages.NotInBrowserErrorMessage);
27
+ },
28
+ throw(b) {
29
+ throw new ResentyError(X(b));
30
+ }
31
+ };
32
+ }
33
+ function mitt(b) {
34
+ return b ||= /* @__PURE__ */ new Map(), {
35
+ all: b,
36
+ on(Y, X) {
37
+ let Z = b.get(Y);
38
+ Z ? Z.push(X) : b.set(Y, [X]);
39
+ },
40
+ off(Y, X) {
41
+ let Z = b.get(Y);
42
+ Z && (X ? Z.splice(Z.indexOf(X) >>> 0, 1) : b.set(Y, []));
43
+ },
44
+ emit(Y, X) {
45
+ let Z = b.get(Y);
46
+ Z && Z.slice().map((b) => {
47
+ b(X);
48
+ }), Z = b.get("*"), Z && Z.slice().map((b) => {
49
+ b(Y, X);
50
+ });
51
+ }
52
+ };
53
+ }
54
+ const createEventEmitter = () => mitt();
55
+ var DEFAULT_TRIGGER_VISIBILITY = !0;
56
+ const DEFAULT_PUBLIC_OPTIONS = {
57
+ baseUrl: "https://api.resenty.com/__internal",
58
+ showTrigger: DEFAULT_TRIGGER_VISIBILITY,
59
+ appearance: {
60
+ theme: "light",
61
+ chat: {}
62
+ }
63
+ }, resolveShowTrigger = (b) => b.appearance?.chat?.showTrigger ?? b.showTrigger ?? DEFAULT_TRIGGER_VISIBILITY, normalizeOptions = (b) => {
64
+ let Y = resolveShowTrigger(b);
65
+ return {
66
+ appId: b.appId,
67
+ baseUrl: b.baseUrl ?? DEFAULT_PUBLIC_OPTIONS.baseUrl,
68
+ customer: b.customer,
69
+ userJwt: b.userJwt,
70
+ appearance: {
71
+ theme: b.appearance?.theme ?? "light",
72
+ chat: { showTrigger: Y }
73
+ }
74
+ };
75
+ };
76
+ function isBrowser() {
77
+ return typeof window < "u";
78
+ }
79
+ new RegExp((/* @__PURE__ */ "bot.spider.crawl.APIs-Google.AdsBot.Googlebot.mediapartners.Google Favicon.FeedFetcher.Google-Read-Aloud.DuplexWeb-Google.googleweblight.bing.yandex.baidu.duckduck.yahoo.ecosia.ia_archiver.facebook.instagram.pinterest.reddit.slack.twitter.whatsapp.youtube.semrush".split(".")).join("|"), "i");
80
+ var DEFAULTS = {
81
+ baseMs: 500,
82
+ factor: 2,
83
+ shouldRetry: () => !0,
84
+ onRetry: () => {}
85
+ };
86
+ function sleep(b) {
87
+ return new Promise((Y) => setTimeout(Y, b));
88
+ }
89
+ async function withRetry(b, Y) {
90
+ let X = {
91
+ ...DEFAULTS,
92
+ ...Y
93
+ }, Z;
94
+ for (let Q = 0; Q < X.attempts; Q++) try {
95
+ return await b(Q);
96
+ } catch (b) {
97
+ if (Z = b, Q === X.attempts - 1 || !X.shouldRetry(b, Q)) throw b;
98
+ let $ = Y.computeDelay ? Y.computeDelay(Q, X) : X.baseMs * X.factor ** Q;
99
+ X.onRetry(b, Q, $), await sleep($);
100
+ }
101
+ throw Z;
102
+ }
103
+ var errorThrower = buildErrorThrower({ packageName: "💬 Resenty" }), createResentyUI = null;
104
+ const configureResentyUI = (b) => {
105
+ createResentyUI = b;
106
+ };
107
+ var persistedStateSchema = object({ state: record(string(), object({ sessionId: string() })).optional() });
108
+ function buildState(b, Y) {
109
+ return { state: { [b]: { sessionId: Y } } };
110
+ }
111
+ const SESSION_STORAGE_KEY = "resenty:session";
112
+ var SESSION_RETRY_ATTEMPTS = 3, SESSION_RETRY_BASE_MS = 500, SESSION_CREATE_PATH = "/widget/sessions", Resenty = class {
113
+ constructor() {
114
+ this.options = normalizeOptions(DEFAULT_PUBLIC_OPTIONS), this.resolvedOptions = normalizeOptions(DEFAULT_PUBLIC_OPTIONS), this.events = createEventEmitter(), this.queryClient = new QueryClient({ defaultOptions: { queries: {
115
+ refetchOnWindowFocus: !1,
116
+ refetchOnReconnect: !1,
117
+ throwOnError: !1
118
+ } } });
119
+ }
120
+ #e;
121
+ #t;
122
+ #n = null;
123
+ get session() {
124
+ return this.#e;
125
+ }
126
+ load(b, Y) {
127
+ if (b || errorThrower.throwMissingWidgetIdError(), this.appId = b, this.options = this.buildOptions({ ...Y }), this.setAccessors(this.options), this.client = new Client({ client: this.createClient(this.options.baseUrl) }), isBrowser()) {
128
+ let Y = this.getState();
129
+ Y.state?.[b] && (this.#e = Y.state?.[b]?.sessionId);
130
+ }
131
+ client.interceptors.request.use(async (b) => {
132
+ if (b.headers.set("x-resenty-widget-id", this.appId), isSessionCreationRequest(b)) return b;
133
+ let Y = await this.ensureSession();
134
+ return Y && b.headers.set("x-resenty-widget-client-session-id", Y), b;
135
+ }), this.ensureSession(), this.#n = createResentyUI?.(this) ?? null;
136
+ }
137
+ async ensureSession(b) {
138
+ if (this.session && !b) return this.session;
139
+ if (this.#t && !b) return this.#t;
140
+ let Y = this.bootstrapSession();
141
+ this.#t = Y;
142
+ try {
143
+ return await Y;
144
+ } finally {
145
+ this.#t === Y && (this.#t = void 0);
146
+ }
147
+ }
148
+ async bootstrapSession() {
149
+ let b = this.resolvedOptions.userJwt, Y = b ? { body: { user_jwt: b } } : void 0;
150
+ try {
151
+ return this.#e = await withRetry(async () => {
152
+ let b = await this.client?.widget.sessions.createSession(Y);
153
+ if (!b || b.error) throw Error(b?.error?.message ?? "Session creation failed");
154
+ return b.data?.client_session_id;
155
+ }, {
156
+ attempts: SESSION_RETRY_ATTEMPTS,
157
+ baseMs: SESSION_RETRY_BASE_MS
158
+ }) ?? void 0, isBrowser() && this.#e && this.saveState(), this.#e;
159
+ } catch (b) {
160
+ console.warn("[Resenty] Failed to establish a session after retries", b);
161
+ return;
162
+ }
163
+ }
164
+ createClient(b) {
165
+ return client.setConfig({ baseUrl: b }), client;
166
+ }
167
+ setAccessors(b) {
168
+ this.customer = b.customer, this.resolvedOptions = normalizeOptions(b);
169
+ }
170
+ updateCustomer(b) {
171
+ this.options = this.buildOptions({ customer: b }), this.setAccessors(this.options);
172
+ }
173
+ update(b) {
174
+ let Y = this.resolvedOptions.userJwt;
175
+ this.options = this.buildOptions(b), this.setAccessors(this.options), b.userJwt && b.userJwt !== Y && this.ensureSession(!0);
176
+ }
177
+ buildOptions(b) {
178
+ return normalizeOptions(toMerged(this.options, b));
179
+ }
180
+ openChat() {
181
+ this.#n && this.events.emit("chat:toggle");
182
+ }
183
+ mountChat(b) {
184
+ this.#n && this.#n.ensureMounted({ preloadHint: "chat" }).then((Y) => {
185
+ Y.mountComponent({
186
+ name: "chat",
187
+ node: b,
188
+ props: {}
189
+ });
190
+ });
191
+ }
192
+ saveState() {
193
+ let b = this.getState();
194
+ localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(merge(b, buildState(this.appId, this.session))));
195
+ }
196
+ getState() {
197
+ let b = localStorage.getItem(SESSION_STORAGE_KEY);
198
+ if (!b) return {};
199
+ try {
200
+ let Y = persistedStateSchema.safeParse(JSON.parse(b));
201
+ return Y.success ? Y.data : {};
202
+ } catch {
203
+ return {};
204
+ }
205
+ }
206
+ };
207
+ function isSessionCreationRequest(b) {
208
+ if (b.method !== "POST") return !1;
209
+ try {
210
+ return new URL(b.url).pathname.endsWith(SESSION_CREATE_PATH);
211
+ } catch {
212
+ return !1;
213
+ }
214
+ }
215
+ var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
216
+ const noop = (...b) => {}, createDeferredPromise = () => {
217
+ let b = noop, Y = noop;
218
+ return {
219
+ promise: new Promise((X, Z) => {
220
+ b = X, Y = Z;
221
+ }),
222
+ resolve: b,
223
+ reject: Y
224
+ };
225
+ };
226
+ var componentImportPaths = { chat: () => import("./chat-CJ6R7eoG.js") };
227
+ const Components = { chat: (0, import_react.lazy)(() => componentImportPaths.chat().then((b) => ({ default: b.Chat }))) }, preloadComponent = async (b) => componentImportPaths[b]?.();
228
+ var import_react_dom$1 = /* @__PURE__ */ __toESM(require_react_dom(), 1);
229
+ const Portal = (b) => {
230
+ let { node: Y, component: X, props: Z } = b;
231
+ return import_react_dom$1.createPortal((0, import_react.createElement)(X, Z), Y);
232
+ };
233
+ var import_react_dom = /* @__PURE__ */ __toESM(require_react_dom()), import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime()), ROOT_ELEMENT_ID = "resenty-components", useSafeLayoutEffect = typeof window < "u" ? import_react.useLayoutEffect : import_react.useEffect;
234
+ const mountComponentRenderer = (b) => {
235
+ let Y = document.getElementById(ROOT_ELEMENT_ID);
236
+ Y || (Y = document.createElement("div"), Y.id = ROOT_ELEMENT_ID, document.body.appendChild(Y));
237
+ let X;
238
+ return { ensureMounted: async (Z) => {
239
+ let { preloadHint: Q } = Z || {};
240
+ if (!X) {
241
+ let Z = createDeferredPromise();
242
+ Q && preloadComponent(Q), X = import("./react-root-BBU2MuNT.js").then(({ createRoot: X }) => (X(Y, {
243
+ onCaughtError(b, Y) {
244
+ console.error(b, Y);
245
+ },
246
+ onRecoverableError(b, Y) {
247
+ console.error(b, Y);
248
+ },
249
+ onUncaughtError(b, Y) {
250
+ console.error(b, Y);
251
+ }
252
+ }).render(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(QueryClientProvider, {
253
+ client: b.queryClient,
254
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ComponentRenderer, {
255
+ core: b,
256
+ root: Y,
257
+ onComponentsMounted: Z.resolve
258
+ })
259
+ })), Z.promise.then(() => componentsControls)));
260
+ }
261
+ return X.then((b) => b);
262
+ } };
263
+ };
264
+ function assertDOMElement(b) {
265
+ if (!b) throw Error("DOM element not found");
266
+ }
267
+ var portalCt = 0, componentsControls = {}, ComponentRenderer = (b) => {
268
+ let { core: Y, onComponentsMounted: X } = b, [Z, Q] = import_react.useState({
269
+ nodes: /* @__PURE__ */ new Map(),
270
+ appearance: void 0,
271
+ options: void 0,
272
+ chat: {
273
+ shown: !1,
274
+ props: void 0
275
+ }
276
+ }), { nodes: $ } = Z;
277
+ return useSafeLayoutEffect(() => {
278
+ componentsControls.mountComponent = (b) => {
279
+ let { node: Y, name: X, props: Z } = b;
280
+ assertDOMElement(Y), Q((b) => {
281
+ let Q = new Map(b.nodes);
282
+ return Q.set(Y, {
283
+ key: `p${++portalCt}`,
284
+ name: X,
285
+ props: Z
286
+ }), {
287
+ ...b,
288
+ nodes: Q
289
+ };
290
+ });
291
+ }, componentsControls.unmountComponent = (b) => {
292
+ let { node: Y } = b;
293
+ Q((b) => {
294
+ let X = new Map(b.nodes);
295
+ return X.delete(Y), {
296
+ ...b,
297
+ nodes: X
298
+ };
299
+ });
300
+ }, componentsControls.updateProps = ({ node: b, props: Y,...X }) => {
301
+ if (b && Y && typeof Y == "object") {
302
+ let X = Z.nodes.get(b);
303
+ if (X) {
304
+ X.props = { ...Y }, Q((b) => ({ ...b }));
305
+ return;
306
+ }
307
+ }
308
+ Q((b) => ({
309
+ ...b,
310
+ ...X
311
+ }));
312
+ }, X();
313
+ }, []), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(CoreContext.Provider, {
314
+ value: { value: Y },
315
+ children: [[...$].map(([b, Y]) => {
316
+ let X = b.querySelector(".resenty-namespace");
317
+ X || (X = document.createElement("div"), X.classList.add("resenty-namespace"), X.id = buildName(Y.name), b.appendChild(X));
318
+ let Z = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
319
+ fallback: "",
320
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portal, {
321
+ node: X,
322
+ component: Components[Y.name],
323
+ props: Y.props,
324
+ componentName: Y.name
325
+ })
326
+ });
327
+ return import_react_dom.createPortal(Z, b);
328
+ }), Z.chat.shown && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, {
329
+ fallback: "",
330
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
331
+ id: buildName("chat"),
332
+ className: "resenty-namespace",
333
+ children: import_react.createElement(Components.chat, Z.chat.props)
334
+ })
335
+ })]
336
+ });
337
+ }, buildName = (b) => `resenty-${b}`, ResentyUI = class {
338
+ #e;
339
+ #t;
340
+ constructor(b) {
341
+ this.#t = b, this.#e = mountComponentRenderer(this.#t);
342
+ }
343
+ async ensureMounted(b) {
344
+ return this.#e.ensureMounted(b);
345
+ }
346
+ };
347
+ configureResentyUI((b) => new ResentyUI(b));
348
+ export { Resenty, ResentyUI };