@mrrocket/sdk 0.27.0 → 0.28.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.
- package/CHANGELOG.md +9 -0
- package/dist/api-client.d.ts +2 -0
- package/dist/api-client.js.map +1 -1
- package/dist/browser/mrrocket-messenger.js +6 -3
- package/dist/browser/mrrocket.js +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/messenger-ui.js +8 -4
- package/dist/messenger-ui.js.map +1 -1
- package/dist/react-native/index.d.cts +3 -1
- package/dist/react-native/index.d.ts +3 -1
- package/dist/react-native/index.js +1 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/styles-css.d.ts +1 -1
- package/dist/styles-css.js +3 -0
- package/dist/styles-css.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this package. It follows semantic versioning; before 1.0 a minor version may change an API.
|
|
4
4
|
|
|
5
|
+
## 0.28.0
|
|
6
|
+
|
|
7
|
+
The messenger shows when the team's AI agent is writing. Web and script tag; React Native is unchanged.
|
|
8
|
+
|
|
9
|
+
- **Typing dots:** while MRRocket's agent writes an answer in the chat on screen, three soft dots stand where its answer will come (announced as "Typing…"). They show right after the visitor sends, so the chat is never silent for the seconds the answer takes, and they go when the answer arrives or the agent stops. It needs MRRocket's side of this release (`conversation.typing` in the chat); against an older MRRocket nothing shows, as before.
|
|
10
|
+
- While the agent writes, the chat on screen is read every 1.5 s instead of every 4 s, so its answer appears as soon as it is there.
|
|
11
|
+
- New word for translations: "Typing…".
|
|
12
|
+
- Version reported in event batches: `0.28.0`.
|
|
13
|
+
|
|
5
14
|
## 0.27.0
|
|
6
15
|
|
|
7
16
|
The messenger's Help tab and its articles, on the web and with the script tag. React Native is unchanged. Tables need MRRocket's side of this release (it answers `blocks=table`); against an older MRRocket an article reads as before.
|
package/dist/api-client.d.ts
CHANGED
|
@@ -233,10 +233,12 @@ export interface ChatSummary {
|
|
|
233
233
|
}
|
|
234
234
|
/** One chat (the one asked for, else the visitor's newest, open or closed) and its messages. */
|
|
235
235
|
export interface ChatThread {
|
|
236
|
+
/** `typing`: the team's AI agent is writing an answer in it right now (server 2026-11-27; older servers leave it out). */
|
|
236
237
|
conversation: {
|
|
237
238
|
id: string;
|
|
238
239
|
status: "open" | "solved";
|
|
239
240
|
seenAt?: string;
|
|
241
|
+
typing?: boolean;
|
|
240
242
|
} | null;
|
|
241
243
|
messages: ChatMessage[];
|
|
242
244
|
/** All the visitor's conversations, the latest activity first (0.19). */
|
package/dist/api-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api-client.ts"],"sourcesContent":["/**\n * The SDK's fetch client and the shapes it reads, without React, so the script tag's widgets (src/script) use it too.\n * `./api` re-exports all of it with the `useApi` hook.\n */\nimport { warnUnsigned } from \"./identity\";\nimport { currentLocale, t } from \"./i18n\";\n\nexport type PostStatus = \"review\" | \"planned\" | \"progress\" | \"shipped\";\n\n/** Read at the moment it is shown, so it follows the visitor's language. */\nexport const STATUS_LABEL: Record<PostStatus, string> = {\n get review() {\n return t(\"Under review\");\n },\n get planned() {\n return t(\"Planned\");\n },\n get progress() {\n return t(\"In progress\");\n },\n get shipped() {\n return t(\"Shipped\");\n },\n};\n\nexport interface FeedbackBoardInfo {\n id: string;\n label: string;\n}\n\nexport interface FeedbackPost {\n id: string;\n title: string;\n body: string;\n board: string;\n status: PostStatus;\n votes: number;\n comments: number;\n voted: boolean;\n createdAt: string;\n /** \"Lena K.\", \"Anonymous\" or \"Team\". Missing from servers before SDK 0.6. */\n author?: string;\n}\n\n/** The product's public face for the board's header. */\nexport interface FeedbackProduct {\n name: string;\n logo: string | null;\n /** The domain's favicon, tried when `logo` does not load. Older servers leave it out. */\n logoFallback?: string | null;\n}\n\nexport interface FeedbackList {\n boards: FeedbackBoardInfo[];\n posts: FeedbackPost[];\n product?: FeedbackProduct;\n}\n\nexport interface FeedbackRoadmap {\n /** `review` (Backlog) comes from servers of SDK 0.6 on. */\n columns: { review?: FeedbackPost[]; planned: FeedbackPost[]; progress: FeedbackPost[]; shipped: FeedbackPost[] };\n}\n\nexport interface ChangelogEntry {\n id: string;\n title: string;\n body: string;\n publishedAt: string;\n}\n\nexport interface FeedbackComment {\n id: string;\n body: string;\n author: string;\n isTeam: boolean;\n postedAt: string;\n}\n\nexport type SurveyQuestionKind = \"nps\" | \"rating\" | \"single\" | \"multi\" | \"text\";\n\nexport interface SurveyQuestion {\n key: string;\n kind: SurveyQuestionKind;\n title: string;\n description?: string;\n required: boolean;\n options?: string[];\n /**\n * 0.21.0: what each option says in the visitor's language, parallel to `options`. An answer is still recorded as the\n * `options` value, so rules and numbers do not split by language.\n */\n labels?: string[];\n scale?: number;\n low?: string;\n high?: string;\n placeholder?: string;\n}\n\nexport interface SurveyDefinition {\n id: string;\n name: string;\n type: string;\n thanks: string;\n questions: SurveyQuestion[];\n}\n\nexport type SurveyAnswer = number | string | string[];\n\n/** A file in the messenger's chat: a screenshot, a photo or a PDF the visitor sent (servers from SDK 0.15 on). */\nexport interface ChatFile {\n /** From an upload: the signed id a message sends. In a message: the file's own id (`attachmentUrl` reads it). */\n id: string;\n name: string;\n type: \"image/png\" | \"image/jpeg\" | \"image/webp\" | \"image/gif\" | \"application/pdf\";\n /** Bytes. */\n size: number;\n}\n\n/** What the messenger can send: pictures and PDFs, at most 10 MB each, 4 per message. */\nexport const CHAT_FILE_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\", \"application/pdf\"] as const;\nexport const CHAT_FILE_MAX_BYTES = 10 * 1024 * 1024;\nexport const CHAT_FILES_PER_MESSAGE = 4;\n\n/** A file to upload: a Blob or File on the web, the image picker's `{ uri, name, type }` in React Native. */\nexport type ChatUpload = Blob | { uri: string; name: string; type: string };\n\n/** The bug context a visitor message carries; the server fills browser and system from the user agent when left out. */\nexport interface ChatContext {\n browser?: string;\n os?: string;\n /** \"1440×900\". */\n viewport?: string;\n}\n\n/** One message of the messenger's chat. \"visitor\" is the person on the site; the rest come from the product's team. */\nexport interface ChatMessage {\n id: string;\n from: \"visitor\" | \"team\" | \"ai\" | \"auto\";\n body: string;\n at: string;\n /** A team reply's sender, by first name (servers from 2026-11-19 on): \"Lukas · Team\". */\n name?: string;\n /** Help articles an answer drew on (servers from SDK 0.9 on). */\n articles?: { id: string; title: string }[];\n /** Files sent with it (servers from SDK 0.15 on). */\n attachments?: ChatFile[];\n}\n\n/** A published help article in a list (the messenger's Help tab). */\nexport interface ArticleSummary {\n id: string;\n title: string;\n collection: string;\n excerpt: string;\n updatedAt: string;\n}\n\n/** A run of text inside an article block. Links are http(s), mailto or tel only. */\nexport interface ArticleSpan {\n text: string;\n href?: string;\n bold?: boolean;\n italic?: boolean;\n code?: boolean;\n}\n\n/** An article's content as blocks, written with textContent (never parsed as HTML). */\nexport type ArticleBlock =\n | { type: \"h2\" | \"h3\" | \"p\" | \"quote\"; spans: ArticleSpan[] }\n | { type: \"ul\" | \"ol\"; items: ArticleSpan[][] }\n | { type: \"code\"; text: string }\n | { type: \"hr\" }\n /**\n * A table (0.27.0): `head` is its first row when it has one (else empty), every row has the same number of cells.\n * Sent only to a widget that asks for it (`article(id, signal, \"table\")`); every other one gets the rows as a list.\n */\n | { type: \"table\"; head: ArticleSpan[][]; rows: ArticleSpan[][][] };\n\nexport interface Article {\n id: string;\n title: string;\n collection: string;\n updatedAt: string;\n blocks: ArticleBlock[];\n}\n\n/** Where the chat button sits: a corner, the middle of the top or bottom edge, or the middle of a side. */\nexport type MessengerPosition = \"top-left\" | \"top-center\" | \"top-right\" | \"middle-left\" | \"middle-right\" | \"bottom-left\" | \"bottom-center\" | \"bottom-right\";\n\n/** How round the messenger is. */\nexport type MessengerCorners = \"round\" | \"soft\" | \"square\";\n\n/** The radii per corner style, in px: the panel or sheet, message bubbles (and their tail), cards, fields and buttons. */\nexport const CORNERS: Record<MessengerCorners, { panel: number; bubble: number; tail: number; card: number; field: number }> = {\n round: { panel: 22, bubble: 18, tail: 6, card: 16, field: 20 },\n soft: { panel: 14, bubble: 12, tail: 4, card: 10, field: 10 },\n square: { panel: 6, bubble: 6, tail: 2, card: 4, field: 4 },\n};\n\n/** The messenger's look and texts as set in MRRocket › Support › Messenger (servers from SDK 0.9 on). */\nexport interface MessengerLook {\n accent: string;\n /** Up to two more colors blended into Home's background glow (MRRocket from 0.16; older servers leave it out). */\n glow?: string[];\n theme: \"light\" | \"dark\" | \"auto\";\n position: MessengerPosition;\n title: string;\n greeting: string;\n label: string;\n /** How soon the team usually answers (MRRocket from 0.10; older servers leave it out). */\n replyTime?: \"minutes\" | \"hours\" | \"day\";\n /** A round chat button in the app (React Native) too. */\n appLauncher?: boolean;\n help: boolean;\n /** The Updates tab with the published changelog (MRRocket from 0.22; older servers leave it out). */\n updates?: boolean;\n sound: boolean;\n preview: boolean;\n askEmail: boolean;\n /** How round panel, bubbles, cards and fields are (MRRocket from 0.15; older servers leave it out: round). */\n corners?: MessengerCorners;\n /** The site's own font (the default) or the system's (web only; from 0.15). */\n font?: \"site\" | \"system\";\n /** Home's top: plain like the rest, or in the accent color (from 0.15; older servers leave it out: plain). */\n header?: \"plain\" | \"color\";\n /** \"Powered by MRRocket\" at the bottom; the server sends false only on plans that may hide it (from 0.15). */\n branding?: boolean;\n /** The logo at the top left of Home: the one uploaded in MRRocket, else the product's favicon; without it the title's first letter. */\n logo?: string;\n /** The product's favicon, the round mark in the chat's head (from 0.17; without it the title's first letter). */\n icon?: string;\n /** The AI agent's name on its answers (from 0.17; empty or left out: \"AI agent\"). */\n agentName?: string;\n /** The AI agent's picture beside its answers (from 0.17). */\n agentPhoto?: string;\n}\n\n/** The link behind \"Powered by MRRocket\". */\nexport const BRAND_URL = \"https://mrrocket.dev/?utm_source=messenger&utm_medium=powered-by\";\n\n/** The line under \"Send us a message\" and in the chat's head. */\nexport const replyLine = (time: MessengerLook[\"replyTime\"]) =>\n time === \"minutes\" ? t(\"We usually reply in a few minutes\") : time === \"day\" ? t(\"We usually reply within a day\") : t(\"We usually reply in a few hours\");\n\n/** Black or white, whichever reads better on the accent (a light custom color gets dark text). */\nexport const inkOn = (hex: string) => {\n const m = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);\n if (!m) return \"#ffffff\";\n const [r, g, b] = [m[1], m[2], m[3]].map((x) => {\n const c = parseInt(x, 16) / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.45 ? \"#111214\" : \"#ffffff\";\n};\n\n/** One of the visitor's conversations in their list (0.19). */\nexport interface ChatSummary {\n id: string;\n status: \"open\" | \"solved\";\n /** The visitor's first words. */\n subject: string;\n /** The newest message, its body cut to a preview. */\n last: ChatMessage | null;\n /** Up to when the visitor read it, on any device (servers from 0.24.0). */\n seenAt?: string;\n}\n\n/** One chat (the one asked for, else the visitor's newest, open or closed) and its messages. */\nexport interface ChatThread {\n conversation: { id: string; status: \"open\" | \"solved\"; seenAt?: string } | null;\n messages: ChatMessage[];\n /** All the visitor's conversations, the latest activity first (0.19). */\n conversations?: ChatSummary[];\n /** The visitor gave an email already: the messenger stops asking. */\n hasEmail: boolean;\n}\n\n/**\n * For the count and the preview of unread answers, after a read: an answer the team took back and a conversation it\n * archived leave them. Of a conversation that is not on screen the list brings only the newest message, so an answer\n * newer than that one is gone.\n */\nexport const stillThere = (t: ChatThread, chats: ChatSummary[]) => (m: { id: string; at: string; chat: string }) => {\n if (m.chat === t.conversation?.id) return t.messages.some((x) => x.id === m.id);\n const last = chats.find((c) => c.id === m.chat)?.last;\n return !!last && m.at <= last.at;\n};\n\nexport class ApiError extends Error {\n status: number;\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n}\n\ninterface Conn {\n host: string;\n apiKey: string;\n distinctId: string;\n user?: { id?: string; [key: string]: unknown };\n /**\n * The identity hash of `distinctId` (0.16.0, see identity.ts), sent with every request that names the visitor: a\n * JSON field next to `distinctId`, a query parameter, a form field. Leave it out for any other id.\n */\n userHash?: string;\n}\n\n// Not URLSearchParams: React Native's lacks `set` in older versions, and the apps use this client too.\n// `lang` goes along so the answer's words can be in the visitor's language; \"\" leaves it out.\nconst qs = (params: Record<string, string | undefined>, lang = currentLocale()) =>\n Object.entries({ ...params, lang })\n .filter((e): e is [string, string] => !!e[1])\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n\n/** A POST's address: its body names the visitor, the query only the language of the words in its answer. */\nconst withLang = (url: string) => {\n const q = qs({});\n return q ? `${url}?${q}` : url;\n};\n\nconst call = async <T>(url: string, init: RequestInit | undefined, signal?: AbortSignal): Promise<T> => {\n let res: Response;\n try {\n res = await fetch(url, {\n ...init,\n signal,\n // A form (a file upload) sets its own multipart type with the boundary.\n headers: typeof init?.body === \"string\" ? { \"content-type\": \"application/json\" } : undefined,\n });\n } catch (e) {\n if ((e as Error).name === \"AbortError\") throw e;\n throw new ApiError(t(\"Could not reach the server. Check your connection and try again.\"), 0);\n }\n if (!res.ok) {\n // A missing or wrong identity hash: the console says once how to sign the user id.\n warnUnsigned(res.status);\n let detail = \"\";\n try {\n detail = ((await res.json()) as { error?: string }).error ?? \"\";\n } catch {\n // Not JSON; the status is enough.\n }\n throw new ApiError(detail || (res.status === 429 ? t(\"Too many requests. Try again in a minute.\") : t(\"Something went wrong. Please try again.\")), res.status);\n }\n return (await res.json()) as T;\n};\n\n/** The small fetch client behind the widgets. Every read takes an AbortSignal so unmounting cancels it. */\nexport const createApi = (c: Conn) => {\n const base = `${c.host}/api/sdk`;\n const who = { key: c.apiKey, distinctId: c.distinctId, user: c.user, userHash: c.userHash };\n // Every query that names the visitor names its hash too.\n const me = { key: c.apiKey, distinctId: c.distinctId, userHash: c.userHash };\n const post = <T>(path: string, body: Record<string, unknown>, signal?: AbortSignal) =>\n call<T>(withLang(`${base}${path}`), { method: \"POST\", body: JSON.stringify({ ...who, ...body }) }, signal);\n return {\n list: (o: { board?: string; sort?: \"top\" | \"new\"; q?: string }, signal?: AbortSignal) =>\n call<FeedbackList>(`${base}/feedback?${qs({ ...me, board: o.board, sort: o.sort, q: o.q })}`, undefined, signal),\n post: (id: string, signal?: AbortSignal) =>\n call<FeedbackPost>(`${base}/feedback/${encodeURIComponent(id)}?${qs(me)}`, undefined, signal),\n roadmap: (signal?: AbortSignal) => call<FeedbackRoadmap>(`${base}/feedback/roadmap?${qs(me)}`, undefined, signal),\n changelog: (signal?: AbortSignal) => call<{ entries: ChangelogEntry[] }>(`${base}/feedback/changelog?${qs({ key: c.apiKey })}`, undefined, signal),\n submit: (p: { title: string; body?: string; board: string }) => post<FeedbackPost>(\"/feedback\", p),\n vote: (id: string) => post<{ voted: boolean; votes: number }>(`/feedback/${encodeURIComponent(id)}/vote`, {}),\n comments: (id: string, signal?: AbortSignal) =>\n call<{ comments: FeedbackComment[] }>(`${base}/feedback/${encodeURIComponent(id)}/comments?${qs({ key: c.apiKey })}`, undefined, signal),\n comment: (id: string, body: string) => post<FeedbackComment>(`/feedback/${encodeURIComponent(id)}/comments`, { body }),\n survey: (url: string, signal?: AbortSignal) =>\n call<{ survey: SurveyDefinition | null }>(`${base}/surveys?${qs({ ...me, url })}`, undefined, signal),\n seen: (id: string) => post<unknown>(`/surveys/${encodeURIComponent(id)}/seen`, { user: undefined }),\n respond: (id: string, r: { answers: Record<string, SurveyAnswer>; completed: boolean; seconds: number }) =>\n post<unknown>(`/surveys/${encodeURIComponent(id)}/respond`, r),\n /**\n * One chat by id, else the visitor's newest; `conversations` lists them all. `aiLabel`: the messenger says \"AI agent\"\n * beside an answer's name, so the answer comes without its AI notice line (from 0.22.0).\n */\n chat: (signal?: AbortSignal, conversation?: string) => call<ChatThread>(`${base}/messages?${qs({ ...me, conversation, aiLabel: \"1\" })}`, undefined, signal),\n /**\n * A message; `attachments` are upload ids from `uploadChatFile` (then the body may be empty). `conversation` is\n * the chat it answers, or \"new\" to start one; without it, the running chat or else a new one.\n */\n sendChat: (m: { body: string; conversation?: string; email?: string; url?: string; attachments?: string[]; context?: ChatContext }) => post<ChatThread>(\"/messages\", { ...m, aiLabel: true }),\n /** The visitor read a chat up to `at` (the newest message they saw): MRRocket counts it read on every device and shows \"Seen\" to the team (0.24.0). */\n seenChat: (conversation: string, at: string) => post<{ seenAt: string | null }>(\"/messages/seen\", { conversation, at, user: undefined }),\n /** Uploads one picked file for the next message (pictures and PDFs, at most 10 MB); answers its upload id. */\n uploadChatFile: (file: ChatUpload, signal?: AbortSignal) => {\n const form = new FormData();\n form.append(\"key\", c.apiKey);\n form.append(\"distinctId\", c.distinctId);\n if (c.userHash) form.append(\"userHash\", c.userHash);\n if (\"uri\" in file) form.append(\"file\", file as unknown as Blob);\n else form.append(\"file\", file, (file as Blob & { name?: string }).name || \"file\");\n return call<ChatFile>(withLang(`${base}/messages/attachments`), { method: \"POST\", body: form }, signal);\n },\n /** Where a sent file of this visitor's chat is read (an image's src, a PDF's link). */\n attachmentUrl: (id: string) => `${base}/messages/attachments/${encodeURIComponent(id)}?${qs(me, \"\")}`,\n articles: (q?: string, signal?: AbortSignal) => call<{ articles: ArticleSummary[] }>(`${base}/articles?${qs({ key: c.apiKey, q })}`, undefined, signal),\n /**\n * One article as blocks. `blocks` names the newer kinds of block this widget draws (\"table\", 0.27.0): MRRocket\n * sends those only when asked, so a widget that draws none (older versions, the apps) keeps getting lines of text.\n */\n article: (id: string, signal?: AbortSignal, blocks?: string) =>\n call<Article>(`${base}/articles/${encodeURIComponent(id)}?${qs({ ...me, blocks })}`, undefined, signal),\n messengerLook: (signal?: AbortSignal) => call<MessengerLook>(`${base}/messenger?${qs({ key: c.apiKey })}`, undefined, signal),\n rateArticle: (id: string, helpful: boolean) => post<{ counted: boolean }>(`/articles/${encodeURIComponent(id)}/rate`, { helpful }),\n };\n};\n\nexport type Api = ReturnType<typeof createApi>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,UAAI,SAAS,KAAM,MAAK,OAAO,QAAQ,IAAuB;AAAA,UACzD,MAAK,OAAO,QAAQ,MAAO,KAAkC,QAAQ,MAAM;AAChF,aAAO,KAAe,SAAS,GAAG,IAAI,uBAAuB,GAAG,EAAE,QAAQ,QAAQ,MAAM,KAAK,GAAG,MAAM;AAAA,IAC1G;AAAA;AAAA,IAEA,eAAe,CAAC,OAAe,GAAG,IAAI,yBAAyB,mBAAmB,EAAE,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC;AAAA,IACnG,UAAU,CAAC,GAAY,WAAyB,KAAqC,GAAG,IAAI,aAAa,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,QAAW,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,IAKtJ,SAAS,CAAC,IAAY,QAAsB,WACxC,KAAc,GAAG,IAAI,aAAa,mBAAmB,EAAE,CAAC,IAAI,GAAG,EAAE,GAAG,IAAI,OAAO,CAAC,CAAC,IAAI,QAAW,MAAM;AAAA,IAC1G,eAAe,CAAC,WAAyB,KAAoB,GAAG,IAAI,cAAc,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,QAAW,MAAM;AAAA,IAC5H,aAAa,CAAC,IAAY,YAAqB,KAA2B,aAAa,mBAAmB,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;AAAA,EACrI;AACJ;","names":["t"]}
|
|
1
|
+
{"version":3,"sources":["../src/api-client.ts"],"sourcesContent":["/**\n * The SDK's fetch client and the shapes it reads, without React, so the script tag's widgets (src/script) use it too.\n * `./api` re-exports all of it with the `useApi` hook.\n */\nimport { warnUnsigned } from \"./identity\";\nimport { currentLocale, t } from \"./i18n\";\n\nexport type PostStatus = \"review\" | \"planned\" | \"progress\" | \"shipped\";\n\n/** Read at the moment it is shown, so it follows the visitor's language. */\nexport const STATUS_LABEL: Record<PostStatus, string> = {\n get review() {\n return t(\"Under review\");\n },\n get planned() {\n return t(\"Planned\");\n },\n get progress() {\n return t(\"In progress\");\n },\n get shipped() {\n return t(\"Shipped\");\n },\n};\n\nexport interface FeedbackBoardInfo {\n id: string;\n label: string;\n}\n\nexport interface FeedbackPost {\n id: string;\n title: string;\n body: string;\n board: string;\n status: PostStatus;\n votes: number;\n comments: number;\n voted: boolean;\n createdAt: string;\n /** \"Lena K.\", \"Anonymous\" or \"Team\". Missing from servers before SDK 0.6. */\n author?: string;\n}\n\n/** The product's public face for the board's header. */\nexport interface FeedbackProduct {\n name: string;\n logo: string | null;\n /** The domain's favicon, tried when `logo` does not load. Older servers leave it out. */\n logoFallback?: string | null;\n}\n\nexport interface FeedbackList {\n boards: FeedbackBoardInfo[];\n posts: FeedbackPost[];\n product?: FeedbackProduct;\n}\n\nexport interface FeedbackRoadmap {\n /** `review` (Backlog) comes from servers of SDK 0.6 on. */\n columns: { review?: FeedbackPost[]; planned: FeedbackPost[]; progress: FeedbackPost[]; shipped: FeedbackPost[] };\n}\n\nexport interface ChangelogEntry {\n id: string;\n title: string;\n body: string;\n publishedAt: string;\n}\n\nexport interface FeedbackComment {\n id: string;\n body: string;\n author: string;\n isTeam: boolean;\n postedAt: string;\n}\n\nexport type SurveyQuestionKind = \"nps\" | \"rating\" | \"single\" | \"multi\" | \"text\";\n\nexport interface SurveyQuestion {\n key: string;\n kind: SurveyQuestionKind;\n title: string;\n description?: string;\n required: boolean;\n options?: string[];\n /**\n * 0.21.0: what each option says in the visitor's language, parallel to `options`. An answer is still recorded as the\n * `options` value, so rules and numbers do not split by language.\n */\n labels?: string[];\n scale?: number;\n low?: string;\n high?: string;\n placeholder?: string;\n}\n\nexport interface SurveyDefinition {\n id: string;\n name: string;\n type: string;\n thanks: string;\n questions: SurveyQuestion[];\n}\n\nexport type SurveyAnswer = number | string | string[];\n\n/** A file in the messenger's chat: a screenshot, a photo or a PDF the visitor sent (servers from SDK 0.15 on). */\nexport interface ChatFile {\n /** From an upload: the signed id a message sends. In a message: the file's own id (`attachmentUrl` reads it). */\n id: string;\n name: string;\n type: \"image/png\" | \"image/jpeg\" | \"image/webp\" | \"image/gif\" | \"application/pdf\";\n /** Bytes. */\n size: number;\n}\n\n/** What the messenger can send: pictures and PDFs, at most 10 MB each, 4 per message. */\nexport const CHAT_FILE_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\", \"application/pdf\"] as const;\nexport const CHAT_FILE_MAX_BYTES = 10 * 1024 * 1024;\nexport const CHAT_FILES_PER_MESSAGE = 4;\n\n/** A file to upload: a Blob or File on the web, the image picker's `{ uri, name, type }` in React Native. */\nexport type ChatUpload = Blob | { uri: string; name: string; type: string };\n\n/** The bug context a visitor message carries; the server fills browser and system from the user agent when left out. */\nexport interface ChatContext {\n browser?: string;\n os?: string;\n /** \"1440×900\". */\n viewport?: string;\n}\n\n/** One message of the messenger's chat. \"visitor\" is the person on the site; the rest come from the product's team. */\nexport interface ChatMessage {\n id: string;\n from: \"visitor\" | \"team\" | \"ai\" | \"auto\";\n body: string;\n at: string;\n /** A team reply's sender, by first name (servers from 2026-11-19 on): \"Lukas · Team\". */\n name?: string;\n /** Help articles an answer drew on (servers from SDK 0.9 on). */\n articles?: { id: string; title: string }[];\n /** Files sent with it (servers from SDK 0.15 on). */\n attachments?: ChatFile[];\n}\n\n/** A published help article in a list (the messenger's Help tab). */\nexport interface ArticleSummary {\n id: string;\n title: string;\n collection: string;\n excerpt: string;\n updatedAt: string;\n}\n\n/** A run of text inside an article block. Links are http(s), mailto or tel only. */\nexport interface ArticleSpan {\n text: string;\n href?: string;\n bold?: boolean;\n italic?: boolean;\n code?: boolean;\n}\n\n/** An article's content as blocks, written with textContent (never parsed as HTML). */\nexport type ArticleBlock =\n | { type: \"h2\" | \"h3\" | \"p\" | \"quote\"; spans: ArticleSpan[] }\n | { type: \"ul\" | \"ol\"; items: ArticleSpan[][] }\n | { type: \"code\"; text: string }\n | { type: \"hr\" }\n /**\n * A table (0.27.0): `head` is its first row when it has one (else empty), every row has the same number of cells.\n * Sent only to a widget that asks for it (`article(id, signal, \"table\")`); every other one gets the rows as a list.\n */\n | { type: \"table\"; head: ArticleSpan[][]; rows: ArticleSpan[][][] };\n\nexport interface Article {\n id: string;\n title: string;\n collection: string;\n updatedAt: string;\n blocks: ArticleBlock[];\n}\n\n/** Where the chat button sits: a corner, the middle of the top or bottom edge, or the middle of a side. */\nexport type MessengerPosition = \"top-left\" | \"top-center\" | \"top-right\" | \"middle-left\" | \"middle-right\" | \"bottom-left\" | \"bottom-center\" | \"bottom-right\";\n\n/** How round the messenger is. */\nexport type MessengerCorners = \"round\" | \"soft\" | \"square\";\n\n/** The radii per corner style, in px: the panel or sheet, message bubbles (and their tail), cards, fields and buttons. */\nexport const CORNERS: Record<MessengerCorners, { panel: number; bubble: number; tail: number; card: number; field: number }> = {\n round: { panel: 22, bubble: 18, tail: 6, card: 16, field: 20 },\n soft: { panel: 14, bubble: 12, tail: 4, card: 10, field: 10 },\n square: { panel: 6, bubble: 6, tail: 2, card: 4, field: 4 },\n};\n\n/** The messenger's look and texts as set in MRRocket › Support › Messenger (servers from SDK 0.9 on). */\nexport interface MessengerLook {\n accent: string;\n /** Up to two more colors blended into Home's background glow (MRRocket from 0.16; older servers leave it out). */\n glow?: string[];\n theme: \"light\" | \"dark\" | \"auto\";\n position: MessengerPosition;\n title: string;\n greeting: string;\n label: string;\n /** How soon the team usually answers (MRRocket from 0.10; older servers leave it out). */\n replyTime?: \"minutes\" | \"hours\" | \"day\";\n /** A round chat button in the app (React Native) too. */\n appLauncher?: boolean;\n help: boolean;\n /** The Updates tab with the published changelog (MRRocket from 0.22; older servers leave it out). */\n updates?: boolean;\n sound: boolean;\n preview: boolean;\n askEmail: boolean;\n /** How round panel, bubbles, cards and fields are (MRRocket from 0.15; older servers leave it out: round). */\n corners?: MessengerCorners;\n /** The site's own font (the default) or the system's (web only; from 0.15). */\n font?: \"site\" | \"system\";\n /** Home's top: plain like the rest, or in the accent color (from 0.15; older servers leave it out: plain). */\n header?: \"plain\" | \"color\";\n /** \"Powered by MRRocket\" at the bottom; the server sends false only on plans that may hide it (from 0.15). */\n branding?: boolean;\n /** The logo at the top left of Home: the one uploaded in MRRocket, else the product's favicon; without it the title's first letter. */\n logo?: string;\n /** The product's favicon, the round mark in the chat's head (from 0.17; without it the title's first letter). */\n icon?: string;\n /** The AI agent's name on its answers (from 0.17; empty or left out: \"AI agent\"). */\n agentName?: string;\n /** The AI agent's picture beside its answers (from 0.17). */\n agentPhoto?: string;\n}\n\n/** The link behind \"Powered by MRRocket\". */\nexport const BRAND_URL = \"https://mrrocket.dev/?utm_source=messenger&utm_medium=powered-by\";\n\n/** The line under \"Send us a message\" and in the chat's head. */\nexport const replyLine = (time: MessengerLook[\"replyTime\"]) =>\n time === \"minutes\" ? t(\"We usually reply in a few minutes\") : time === \"day\" ? t(\"We usually reply within a day\") : t(\"We usually reply in a few hours\");\n\n/** Black or white, whichever reads better on the accent (a light custom color gets dark text). */\nexport const inkOn = (hex: string) => {\n const m = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);\n if (!m) return \"#ffffff\";\n const [r, g, b] = [m[1], m[2], m[3]].map((x) => {\n const c = parseInt(x, 16) / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * r + 0.7152 * g + 0.0722 * b > 0.45 ? \"#111214\" : \"#ffffff\";\n};\n\n/** One of the visitor's conversations in their list (0.19). */\nexport interface ChatSummary {\n id: string;\n status: \"open\" | \"solved\";\n /** The visitor's first words. */\n subject: string;\n /** The newest message, its body cut to a preview. */\n last: ChatMessage | null;\n /** Up to when the visitor read it, on any device (servers from 0.24.0). */\n seenAt?: string;\n}\n\n/** One chat (the one asked for, else the visitor's newest, open or closed) and its messages. */\nexport interface ChatThread {\n /** `typing`: the team's AI agent is writing an answer in it right now (server 2026-11-27; older servers leave it out). */\n conversation: { id: string; status: \"open\" | \"solved\"; seenAt?: string; typing?: boolean } | null;\n messages: ChatMessage[];\n /** All the visitor's conversations, the latest activity first (0.19). */\n conversations?: ChatSummary[];\n /** The visitor gave an email already: the messenger stops asking. */\n hasEmail: boolean;\n}\n\n/**\n * For the count and the preview of unread answers, after a read: an answer the team took back and a conversation it\n * archived leave them. Of a conversation that is not on screen the list brings only the newest message, so an answer\n * newer than that one is gone.\n */\nexport const stillThere = (t: ChatThread, chats: ChatSummary[]) => (m: { id: string; at: string; chat: string }) => {\n if (m.chat === t.conversation?.id) return t.messages.some((x) => x.id === m.id);\n const last = chats.find((c) => c.id === m.chat)?.last;\n return !!last && m.at <= last.at;\n};\n\nexport class ApiError extends Error {\n status: number;\n constructor(message: string, status: number) {\n super(message);\n this.status = status;\n }\n}\n\ninterface Conn {\n host: string;\n apiKey: string;\n distinctId: string;\n user?: { id?: string; [key: string]: unknown };\n /**\n * The identity hash of `distinctId` (0.16.0, see identity.ts), sent with every request that names the visitor: a\n * JSON field next to `distinctId`, a query parameter, a form field. Leave it out for any other id.\n */\n userHash?: string;\n}\n\n// Not URLSearchParams: React Native's lacks `set` in older versions, and the apps use this client too.\n// `lang` goes along so the answer's words can be in the visitor's language; \"\" leaves it out.\nconst qs = (params: Record<string, string | undefined>, lang = currentLocale()) =>\n Object.entries({ ...params, lang })\n .filter((e): e is [string, string] => !!e[1])\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n\n/** A POST's address: its body names the visitor, the query only the language of the words in its answer. */\nconst withLang = (url: string) => {\n const q = qs({});\n return q ? `${url}?${q}` : url;\n};\n\nconst call = async <T>(url: string, init: RequestInit | undefined, signal?: AbortSignal): Promise<T> => {\n let res: Response;\n try {\n res = await fetch(url, {\n ...init,\n signal,\n // A form (a file upload) sets its own multipart type with the boundary.\n headers: typeof init?.body === \"string\" ? { \"content-type\": \"application/json\" } : undefined,\n });\n } catch (e) {\n if ((e as Error).name === \"AbortError\") throw e;\n throw new ApiError(t(\"Could not reach the server. Check your connection and try again.\"), 0);\n }\n if (!res.ok) {\n // A missing or wrong identity hash: the console says once how to sign the user id.\n warnUnsigned(res.status);\n let detail = \"\";\n try {\n detail = ((await res.json()) as { error?: string }).error ?? \"\";\n } catch {\n // Not JSON; the status is enough.\n }\n throw new ApiError(detail || (res.status === 429 ? t(\"Too many requests. Try again in a minute.\") : t(\"Something went wrong. Please try again.\")), res.status);\n }\n return (await res.json()) as T;\n};\n\n/** The small fetch client behind the widgets. Every read takes an AbortSignal so unmounting cancels it. */\nexport const createApi = (c: Conn) => {\n const base = `${c.host}/api/sdk`;\n const who = { key: c.apiKey, distinctId: c.distinctId, user: c.user, userHash: c.userHash };\n // Every query that names the visitor names its hash too.\n const me = { key: c.apiKey, distinctId: c.distinctId, userHash: c.userHash };\n const post = <T>(path: string, body: Record<string, unknown>, signal?: AbortSignal) =>\n call<T>(withLang(`${base}${path}`), { method: \"POST\", body: JSON.stringify({ ...who, ...body }) }, signal);\n return {\n list: (o: { board?: string; sort?: \"top\" | \"new\"; q?: string }, signal?: AbortSignal) =>\n call<FeedbackList>(`${base}/feedback?${qs({ ...me, board: o.board, sort: o.sort, q: o.q })}`, undefined, signal),\n post: (id: string, signal?: AbortSignal) =>\n call<FeedbackPost>(`${base}/feedback/${encodeURIComponent(id)}?${qs(me)}`, undefined, signal),\n roadmap: (signal?: AbortSignal) => call<FeedbackRoadmap>(`${base}/feedback/roadmap?${qs(me)}`, undefined, signal),\n changelog: (signal?: AbortSignal) => call<{ entries: ChangelogEntry[] }>(`${base}/feedback/changelog?${qs({ key: c.apiKey })}`, undefined, signal),\n submit: (p: { title: string; body?: string; board: string }) => post<FeedbackPost>(\"/feedback\", p),\n vote: (id: string) => post<{ voted: boolean; votes: number }>(`/feedback/${encodeURIComponent(id)}/vote`, {}),\n comments: (id: string, signal?: AbortSignal) =>\n call<{ comments: FeedbackComment[] }>(`${base}/feedback/${encodeURIComponent(id)}/comments?${qs({ key: c.apiKey })}`, undefined, signal),\n comment: (id: string, body: string) => post<FeedbackComment>(`/feedback/${encodeURIComponent(id)}/comments`, { body }),\n survey: (url: string, signal?: AbortSignal) =>\n call<{ survey: SurveyDefinition | null }>(`${base}/surveys?${qs({ ...me, url })}`, undefined, signal),\n seen: (id: string) => post<unknown>(`/surveys/${encodeURIComponent(id)}/seen`, { user: undefined }),\n respond: (id: string, r: { answers: Record<string, SurveyAnswer>; completed: boolean; seconds: number }) =>\n post<unknown>(`/surveys/${encodeURIComponent(id)}/respond`, r),\n /**\n * One chat by id, else the visitor's newest; `conversations` lists them all. `aiLabel`: the messenger says \"AI agent\"\n * beside an answer's name, so the answer comes without its AI notice line (from 0.22.0).\n */\n chat: (signal?: AbortSignal, conversation?: string) => call<ChatThread>(`${base}/messages?${qs({ ...me, conversation, aiLabel: \"1\" })}`, undefined, signal),\n /**\n * A message; `attachments` are upload ids from `uploadChatFile` (then the body may be empty). `conversation` is\n * the chat it answers, or \"new\" to start one; without it, the running chat or else a new one.\n */\n sendChat: (m: { body: string; conversation?: string; email?: string; url?: string; attachments?: string[]; context?: ChatContext }) => post<ChatThread>(\"/messages\", { ...m, aiLabel: true }),\n /** The visitor read a chat up to `at` (the newest message they saw): MRRocket counts it read on every device and shows \"Seen\" to the team (0.24.0). */\n seenChat: (conversation: string, at: string) => post<{ seenAt: string | null }>(\"/messages/seen\", { conversation, at, user: undefined }),\n /** Uploads one picked file for the next message (pictures and PDFs, at most 10 MB); answers its upload id. */\n uploadChatFile: (file: ChatUpload, signal?: AbortSignal) => {\n const form = new FormData();\n form.append(\"key\", c.apiKey);\n form.append(\"distinctId\", c.distinctId);\n if (c.userHash) form.append(\"userHash\", c.userHash);\n if (\"uri\" in file) form.append(\"file\", file as unknown as Blob);\n else form.append(\"file\", file, (file as Blob & { name?: string }).name || \"file\");\n return call<ChatFile>(withLang(`${base}/messages/attachments`), { method: \"POST\", body: form }, signal);\n },\n /** Where a sent file of this visitor's chat is read (an image's src, a PDF's link). */\n attachmentUrl: (id: string) => `${base}/messages/attachments/${encodeURIComponent(id)}?${qs(me, \"\")}`,\n articles: (q?: string, signal?: AbortSignal) => call<{ articles: ArticleSummary[] }>(`${base}/articles?${qs({ key: c.apiKey, q })}`, undefined, signal),\n /**\n * One article as blocks. `blocks` names the newer kinds of block this widget draws (\"table\", 0.27.0): MRRocket\n * sends those only when asked, so a widget that draws none (older versions, the apps) keeps getting lines of text.\n */\n article: (id: string, signal?: AbortSignal, blocks?: string) =>\n call<Article>(`${base}/articles/${encodeURIComponent(id)}?${qs({ ...me, blocks })}`, undefined, signal),\n messengerLook: (signal?: AbortSignal) => call<MessengerLook>(`${base}/messenger?${qs({ key: c.apiKey })}`, undefined, signal),\n rateArticle: (id: string, helpful: boolean) => post<{ counted: boolean }>(`/articles/${encodeURIComponent(id)}/rate`, { helpful }),\n };\n};\n\nexport type Api = ReturnType<typeof createApi>;\n"],"mappings":";AAIA,SAAS,oBAAoB;AAC7B,SAAS,eAAe,SAAS;AAK1B,IAAM,eAA2C;AAAA,EACpD,IAAI,SAAS;AACT,WAAO,EAAE,cAAc;AAAA,EAC3B;AAAA,EACA,IAAI,UAAU;AACV,WAAO,EAAE,SAAS;AAAA,EACtB;AAAA,EACA,IAAI,WAAW;AACX,WAAO,EAAE,aAAa;AAAA,EAC1B;AAAA,EACA,IAAI,UAAU;AACV,WAAO,EAAE,SAAS;AAAA,EACtB;AACJ;AAgGO,IAAM,kBAAkB,CAAC,aAAa,cAAc,cAAc,aAAa,iBAAiB;AAChG,IAAM,sBAAsB,KAAK,OAAO;AACxC,IAAM,yBAAyB;AAwE/B,IAAM,UAAkH;AAAA,EAC3H,OAAO,EAAE,OAAO,IAAI,QAAQ,IAAI,MAAM,GAAG,MAAM,IAAI,OAAO,GAAG;AAAA,EAC7D,MAAM,EAAE,OAAO,IAAI,QAAQ,IAAI,MAAM,GAAG,MAAM,IAAI,OAAO,GAAG;AAAA,EAC5D,QAAQ,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,EAAE;AAC9D;AAyCO,IAAM,YAAY;AAGlB,I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A,IAC5H,aAAa,CAAC,IAAY,YAAqB,KAA2B,aAAa,mBAAmB,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;AAAA,EACrI;AACJ;","names":["t"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){'use strict';var
|
|
1
|
+
(function(){'use strict';var Ba=Object.defineProperty;var Ka=(r,n,i)=>n in r?Ba(r,n,{enumerable:true,configurable:true,writable:true,value:i}):r[n]=i;var Xr=(r,n,i)=>Ka(r,n+"",i);var Wa="401: sign the user id on your server with userHash(id) from @mrrocket/sdk/next/server and pass identify(id, props, { hash }).",Zr=(r,n=i=>console.warn(i))=>{let i=globalThis;r!==401||i.__mrrocketUnsigned||(i.__mrrocketUnsigned=true,n(`[MRRocket] ${Wa}`));};var Yt=globalThis,ea,we=(ea=Yt.__mrrocketI18n)!=null?ea:Yt.__mrrocketI18n={version:0,onWords:new Set,onLocale:new Set};var c=r=>{var n;return ((n=we.words)==null?void 0:n[r])||r},$=(r,n)=>c(r).replace(/\{(\w+)\}/g,(i,w)=>w in n?String(n[w]):i);var ke=()=>{var r,n;return (n=(r=we.locale)!=null?r:we.device)!=null?n:typeof navigator!="undefined"&&navigator.language||void 0};var Vt=()=>we.lang,ta=()=>we.version,ra=r=>(we.onWords.add(r),()=>{we.onWords.delete(r);});var Gt=["image/png","image/jpeg","image/webp","image/gif","application/pdf"],na=10*1024*1024,Jt=4;var oa="https://mrrocket.dev/?utm_source=messenger&utm_medium=powered-by",ia=r=>r==="minutes"?c("We usually reply in a few minutes"):r==="day"?c("We usually reply within a day"):c("We usually reply in a few hours"),sa=r=>{let n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(r);if(!n)return "#ffffff";let[i,w,h]=[n[1],n[2],n[3]].map(l=>{let m=parseInt(l,16)/255;return m<=.03928?m/12.92:((m+.055)/1.055)**2.4});return .2126*i+.7152*w+.0722*h>.45?"#111214":"#ffffff"},ca=(r,n)=>i=>{var h,l;if(i.chat===((h=r.conversation)==null?void 0:h.id))return r.messages.some(m=>m.id===i.id);let w=(l=n.find(m=>m.id===i.chat))==null?void 0:l.last;return !!w&&i.at<=w.at},wt=class extends Error{constructor(i,w){super(i);Xr(this,"status");this.status=w;}},K=(r,n=ke())=>Object.entries({...r,lang:n}).filter(i=>!!i[1]).map(([i,w])=>`${encodeURIComponent(i)}=${encodeURIComponent(w)}`).join("&"),aa=r=>{let n=K({});return n?`${r}?${n}`:r},B=async(r,n,i)=>{var h;let w;try{w=await fetch(r,{...n,signal:i,headers:typeof(n==null?void 0:n.body)=="string"?{"content-type":"application/json"}:void 0});}catch(l){throw l.name==="AbortError"?l:new wt(c("Could not reach the server. Check your connection and try again."),0)}if(!w.ok){Zr(w.status);let l="";try{l=(h=(await w.json()).error)!=null?h:"";}catch(m){}throw new wt(l||(w.status===429?c("Too many requests. Try again in a minute."):c("Something went wrong. Please try again.")),w.status)}return await w.json()},Qt=r=>{let n=`${r.host}/api/sdk`,i={key:r.apiKey,distinctId:r.distinctId,user:r.user,userHash:r.userHash},w={key:r.apiKey,distinctId:r.distinctId,userHash:r.userHash},h=(l,m,z)=>B(aa(`${n}${l}`),{method:"POST",body:JSON.stringify({...i,...m})},z);return {list:(l,m)=>B(`${n}/feedback?${K({...w,board:l.board,sort:l.sort,q:l.q})}`,void 0,m),post:(l,m)=>B(`${n}/feedback/${encodeURIComponent(l)}?${K(w)}`,void 0,m),roadmap:l=>B(`${n}/feedback/roadmap?${K(w)}`,void 0,l),changelog:l=>B(`${n}/feedback/changelog?${K({key:r.apiKey})}`,void 0,l),submit:l=>h("/feedback",l),vote:l=>h(`/feedback/${encodeURIComponent(l)}/vote`,{}),comments:(l,m)=>B(`${n}/feedback/${encodeURIComponent(l)}/comments?${K({key:r.apiKey})}`,void 0,m),comment:(l,m)=>h(`/feedback/${encodeURIComponent(l)}/comments`,{body:m}),survey:(l,m)=>B(`${n}/surveys?${K({...w,url:l})}`,void 0,m),seen:l=>h(`/surveys/${encodeURIComponent(l)}/seen`,{user:void 0}),respond:(l,m)=>h(`/surveys/${encodeURIComponent(l)}/respond`,m),chat:(l,m)=>B(`${n}/messages?${K({...w,conversation:m,aiLabel:"1"})}`,void 0,l),sendChat:l=>h("/messages",{...l,aiLabel:true}),seenChat:(l,m)=>h("/messages/seen",{conversation:l,at:m,user:void 0}),uploadChatFile:(l,m)=>{let z=new FormData;return z.append("key",r.apiKey),z.append("distinctId",r.distinctId),r.userHash&&z.append("userHash",r.userHash),"uri"in l?z.append("file",l):z.append("file",l,l.name||"file"),B(aa(`${n}/messages/attachments`),{method:"POST",body:z},m)},attachmentUrl:l=>`${n}/messages/attachments/${encodeURIComponent(l)}?${K(w,"")}`,articles:(l,m)=>B(`${n}/articles?${K({key:r.apiKey,q:l})}`,void 0,m),article:(l,m,z)=>B(`${n}/articles/${encodeURIComponent(l)}?${K({...w,blocks:z})}`,void 0,m),messengerLook:l=>B(`${n}/messenger?${K({key:r.apiKey})}`,void 0,l),rateArticle:(l,m)=>h(`/articles/${encodeURIComponent(l)}/rate`,{helpful:m})}};var la="ckw-styles",Ya=`
|
|
2
2
|
.ckw-root{--ckw-accent:#3f76ff;--ckw-accent-ink:#fff;--ckw-bg:#fff;--ckw-bg2:#f7f7f8;--ckw-bg3:#eeeff1;--ckw-fg:#1c1d20;--ckw-fg2:#5d6068;--ckw-fg3:#8b8e96;--ckw-line:#e4e5e8;--ckw-danger:#d92d20;--ckw-shadow:0 8px 30px rgba(16,18,24,.16);--ckw-card:#fff;--ckw-col:#f5f6f7;--ckw-lift:0 1px 2px rgba(16,18,24,.06),0 0 0 1px rgba(16,18,24,.07);--ckw-raise:0 0 0 1px rgba(16,18,24,.05),0 1px 2px rgba(16,18,24,.05),0 6px 18px rgba(16,18,24,.06);--ckw-float:0 0 0 1px rgba(16,18,24,.06),0 18px 50px rgba(16,18,24,.2);--ckw-soft:0 2px 8px rgba(16,18,24,.05),0 18px 48px rgba(16,18,24,.15);
|
|
3
3
|
font-size:14px;line-height:1.45;font-family:inherit;color:var(--ckw-fg);box-sizing:border-box;-webkit-font-smoothing:antialiased}
|
|
4
4
|
.ckw-root[data-theme=dark]{--ckw-bg:#111214;--ckw-bg2:#1a1b1f;--ckw-bg3:#26272c;--ckw-fg:#f1f2f4;--ckw-fg2:#a9acb3;--ckw-fg3:#7a7d86;--ckw-line:#2a2b31;--ckw-shadow:0 8px 30px rgba(0,0,0,.5);--ckw-card:#1b1c20;--ckw-col:#16171a;--ckw-lift:0 0 0 1px rgba(255,255,255,.07);--ckw-raise:0 0 0 1px rgba(255,255,255,.07);--ckw-float:0 0 0 1px rgba(255,255,255,.09),0 18px 50px rgba(0,0,0,.55);--ckw-soft:0 0 0 1px rgba(255,255,255,.07),0 18px 50px rgba(0,0,0,.55)}
|
|
@@ -407,6 +407,9 @@ button.ckw-msgr-card:hover .ckw-msgr-go{transform:translateX(2px)}
|
|
|
407
407
|
.ckw-bubble{padding:10px 14px;border-radius:var(--ckw-r-bubble) var(--ckw-r-bubble) var(--ckw-r-bubble) var(--ckw-r-tail);background:var(--ckw-bg3);white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:1.45;text-wrap:pretty}
|
|
408
408
|
.ckw-msg[data-from=me] .ckw-bubble{background:var(--ckw-accent);color:var(--ckw-accent-ink);border-radius:var(--ckw-r-bubble) var(--ckw-r-bubble) var(--ckw-r-tail) var(--ckw-r-bubble)}
|
|
409
409
|
.ckw-msg[aria-busy=true] .ckw-bubble{opacity:.7}
|
|
410
|
+
.ckw-typing{display:flex;gap:4px;align-items:center;min-height:20px}.ckw-typing>span{width:6px;height:6px;border-radius:50%;background:currentColor;opacity:.35;animation:ckw-typing 1.2s infinite ease-in-out}.ckw-typing>span:nth-child(2){animation-delay:.15s}.ckw-typing>span:nth-child(3){animation-delay:.3s}
|
|
411
|
+
@keyframes ckw-typing{0%,60%,100%{opacity:.35;transform:none}30%{opacity:.9;transform:translateY(-2px)}}
|
|
412
|
+
@media (prefers-reduced-motion:reduce){.ckw-typing>span{animation:none;opacity:.6}}
|
|
410
413
|
.ckw-msg-meta{font-size:11px;color:var(--ckw-fg3);font-variant-numeric:tabular-nums;padding:0 6px}
|
|
411
414
|
.ckw-msgr-sugg{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px;margin-top:auto;padding-top:12px}
|
|
412
415
|
.ckw-msgr-sugg-b{max-width:100%;padding:9px 14px;border:0;border-radius:var(--ckw-r-card);background:var(--ckw-bg2);font-size:13.5px;text-align:left;color:var(--ckw-fg);transition:background-color .12s linear,color .12s linear,transform .2s cubic-bezier(.32,.72,0,1)}
|
|
@@ -635,5 +638,5 @@ button.ckw-msgr-card:hover .ckw-msgr-go{transform:translateX(2px)}
|
|
|
635
638
|
.ckw-sv-foot{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-top:12px}
|
|
636
639
|
.ckw-thanks{text-align:center;padding:14px 0;display:flex;flex-direction:column;align-items:center;gap:8px}
|
|
637
640
|
.ckw-tick{width:32px;height:32px;border-radius:50%;background:var(--ckw-accent);color:var(--ckw-accent-ink);display:flex;align-items:center;justify-content:center}
|
|
638
|
-
`,sa=()=>{if(typeof document=="undefined"||document.getElementById(ia))return;let r=document.createElement("style");r.id=ia,r.textContent=Ba,document.head.appendChild(r);};var Ka=20,Wa=4e3,Va=5e3,Ya=8e3,Vt=3e4,Ga=6e4,Ja=10*6e4,Yt=1500,Qa=/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/,Xa="ckw_msgr_seen",wa="ckw_msgr_seen_chats",Za=()=>{var r,n;try{return {old:(r=window.localStorage.getItem(Xa))!=null?r:"",chats:JSON.parse((n=window.localStorage.getItem(wa))!=null?n:"{}")}}catch(i){return {old:"",chats:{}}}},ka="ckw_msgr_preview_gone",en=()=>{var r;try{return (r=window.localStorage.getItem(ka))!=null?r:""}catch(n){return ""}},tn=r=>{try{window.localStorage.setItem(ka,r);}catch(n){}},rn=r=>{try{window.localStorage.setItem(wa,JSON.stringify(r));}catch(n){}},dt=r=>{let n=new Date(r).getTime();if(Number.isNaN(n))return "";let i=Math.max(0,Date.now()-n)/1e3;return i<60?c("just now"):i<3600?j("{n}m ago",{n:Math.floor(i/60)}):i<86400?j("{n}h ago",{n:Math.floor(i/3600)}):i<86400*30?j("{n}d ago",{n:Math.floor(i/86400)}):new Date(r).toLocaleDateString(we(),{month:"short",day:"numeric",year:"numeric"})},a=(r,n={},...i)=>{let w=document.createElement(r);for(let[h,l]of Object.entries(n))w.setAttribute(h,l);for(let h of i)h!==null&&h!==false&&h!==void 0&&w.append(h);return w},Be="http://www.w3.org/2000/svg",E=(r,n=16)=>{let i=document.createElementNS(Be,"svg");for(let[h,l]of Object.entries({class:"ckw-icon",width:String(n),height:String(n),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.75","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"}))i.setAttribute(h,l);let w=document.createElementNS(Be,"path");return w.setAttribute("d",r),i.appendChild(w),i},C={cross:"M18 6 6 18M6 6l12 12",chat:"M7.9 20A9 9 0 1 0 4 16.1L2 22z",up:"M12 19V5M5 12l7-7 7 7",home:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",back:"m15 18-6-6 6-6",next:"m9 18 6-6-6-6",search:"M19 11a8 8 0 1 1-16 0 8 8 0 0 1 16 0zM21 21l-4.3-4.3",doc:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7zM14 2v4a2 2 0 0 0 2 2h4M10 9H8M16 13H8M16 17H8",dots:"M13 12a1 1 0 1 1-2 0 1 1 0 0 1 2 0zM13 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0zM13 19a1 1 0 1 1-2 0 1 1 0 0 1 2 0z",expand:"M15 3h6v6M21 3l-7 7M3 21l7-7M9 21H3v-6",collapse:"m14 10 7-7M20 10h-6V4M3 21l7-7M4 14h6v6",minus:"M5 12h14",down:"m6 9 6 6 6-6",help:"M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20zM9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3M12 17h.01",updates:"m3 11 18-5v12L3 14zM11.6 16.8a3 3 0 1 1-5.8-1.6",clip:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48",image:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zM9 11a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM21 15l-3.09-3.09a2 2 0 0 0-2.82 0L6 21",screen:"M20 3H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zM8 21h8M12 17v4"},pt=r=>{var n,i;return r.body||(((n=r.attachments)==null?void 0:n.length)===1?j("Sent {name}",{name:r.attachments[0].name}):(i=r.attachments)!=null&&i.length?j("Sent {n} files",{n:r.attachments.length}):"")},an=()=>{var r;return typeof navigator!="undefined"&&typeof((r=navigator.mediaDevices)==null?void 0:r.getDisplayMedia)=="function"},ca="M7.9 20A9 9 0 1 0 4 16.1L2 22z",nn=(r,n)=>{let i=document.createElementNS(Be,"svg");for(let[h,l]of Object.entries({class:"ckw-icon",width:String(n),height:String(n),viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor","stroke-width":"1.5","stroke-linejoin":"round","aria-hidden":"true"}))i.setAttribute(h,l);let w=document.createElementNS(Be,"path");return w.setAttribute("d",r),i.appendChild(w),i},la=(r,n,i,w=2)=>{let h=nn(r,i),l=document.createElementNS(Be,"path");for(let[k,z]of Object.entries({d:n,class:"ckw-cut",fill:"none","stroke-width":String(w),"stroke-linecap":"round","stroke-linejoin":"round"}))l.setAttribute(k,z);return h.appendChild(l),h},da="M8 12h.01M12 12h.01M16 12h.01",on="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",sn="M9.5 15.5c1.4 1 3.6 1 5 0",cn="M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z",ln="M9.4 9.2a2.7 2.7 0 0 1 5.2 1c0 1.8-2.6 2.5-2.6 2.5M12 16.8h.01",dn="m3 11 18-5v12L3 14zM5.8 15.2a3 3 0 0 0 5.8 1.6z",Ee=(()=>{let r=null,n=()=>{var w;let i=(w=window.AudioContext)!=null?w:window.webkitAudioContext;return i?(r!=null||(r=new i),r):null};return {unlock:()=>{try{let i=n();(i==null?void 0:i.state)==="suspended"&&i.resume();}catch(i){}},play:()=>{try{let i=n();if(!i||i.state!=="running")return;let w=i.currentTime;[880,1318.5].forEach((h,l)=>{let k=i.createOscillator(),z=i.createGain(),B=w+l*.11;k.type="sine",k.frequency.value=h,z.gain.setValueAtTime(1e-4,B),z.gain.exponentialRampToValueAtTime(.12,B+.012),z.gain.exponentialRampToValueAtTime(1e-4,B+.32),k.connect(z),z.connect(i.destination),k.start(B),k.stop(B+.34);});}catch(i){}}}})(),De=r=>r.map(n=>{let i=n.href?a("a",{href:n.href,target:"_blank",rel:"noopener noreferrer"},n.text):a("span",{},n.text);return n.code&&(i=a("code",{},i)),n.italic&&(i=a("em",{},i)),n.bold&&(i=a("strong",{},i)),i}),pn="table",gn=r=>{var n;switch(r.type){case "table":{let i=(w,h)=>a("tr",{},...w.map(l=>a(h,{},...De(l))));return a("div",{class:"ckw-msgr-doc-table",tabindex:"0"},a("table",{},r.head.length?a("thead",{},i(r.head,"th")):null,a("tbody",{},...r.rows.map(w=>i(w,"td")))))}case "h2":case "h3":return a(r.type,{},...De(r.spans));case "quote":return a("blockquote",{},...De(r.spans));case "ul":case "ol":return a(r.type,{},...r.items.map(i=>a("li",{},...De(i))));case "code":return a("pre",{},a("code",{},r.text));case "hr":return a("hr");default:return a("p",{},...De((n=r.spans)!=null?n:[]))}},pa=r=>r.map(n=>n.text).join("").replace(/\s+/g," ").trim().toLowerCase(),wn=2500,ma="ckw_msgr_look:",kn=r=>{try{let n=window.localStorage.getItem(ma+r);return n?JSON.parse(n):null}catch(n){return null}},mn=(r,n)=>{try{window.localStorage.setItem(ma+r,JSON.stringify(n));}catch(i){}},un="ckw_msgr_chats:",hn="ckw_msgr_product:",ga=20,Gt=r=>{var n;try{return JSON.parse((n=window.localStorage.getItem(r))!=null?n:"null")}catch(i){return null}},gt=(r,n)=>{try{n?window.localStorage.setItem(r,JSON.stringify(n)):window.localStorage.removeItem(r);}catch(i){}},ua=r=>{let n=null,i="",w=false,h=[],l=b=>n?b(n):h.push(b),k=new AbortController,z=!r.client&&!!r.apiKey,B=null,V=b=>{var me,u,J;if(w)return;B=b;let P=`${Xr()}:${JSON.stringify(b!=null?b:{})}`;if(n&&P===i)return;if(n!=null&&n.isOpen()){n.onClose(()=>V(b));return}n==null||n.destroy(),i=P;let S=Object.fromEntries(Object.entries(r).filter(([,M])=>M!==void 0));n=bn({...b!=null?b:{},...S,accent:(me=r.accent)!=null?me:b==null?void 0:b.accent,theme:(u=r.theme)!=null?u:b==null?void 0:b.theme,branding:(J=b==null?void 0:b.branding)!=null?J:true});for(let M of h.splice(0))M(n);},ne=z?kn(r.apiKey):null;ne&&V(ne);let ee=ne?void 0:setTimeout(()=>V(null),wn),ke=()=>{var b,P;return ((P=r.client)!=null?P:Wt({host:r.host,apiKey:r.apiKey,distinctId:r.distinctId(),user:r.user(),userHash:(b=r.userHash)==null?void 0:b.call(r)})).messengerLook(k.signal).then(S=>{z&&S&&mn(r.apiKey,S),V(S);}).catch(()=>{V(B);}).finally(()=>clearTimeout(ee))},Le=we();ke();let wt=Zr(()=>{we()!==Le?(Le=we(),ke()):n&&V(B);});return {open:b=>l(P=>P.open(b)),close:()=>n==null?void 0:n.close(),toggle:()=>l(b=>b.toggle()),refresh:()=>n==null?void 0:n.refresh(),destroy:()=>{w=true,wt(),k.abort(),clearTimeout(ee),n==null||n.destroy();}}},fn=["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"],bn=r=>{var jr,Pr,Ir,_r,Or,Rr,Nr,qr,Fr,Ur,Dr,Br,Kr,Wr,Vr;sa();let n=(jr=fn.find(e=>e===r.position))!=null?jr:"bottom-right",i=r.title||c("Support"),w=r.greeting||c("Hi! How can we help?"),h=(Pr=r.askEmail)!=null?Pr:true,l=(Ir=r.label)!=null?Ir:"",k=aa(r.replyTime),z=((_r=i.trim()[0])!=null?_r:"?").toUpperCase(),B={visitor:c("You"),team:c("Team"),ai:(Or=r.agentName)!=null&&Or.trim()?`${r.agentName.trim()} \xB7 ${c("AI agent")}`:c("AI agent"),auto:c("Team")},V=e=>{var t;return e.from==="team"&&((t=e.name)!=null&&t.trim())?`${e.name.trim()} \xB7 ${c("Team")}`:B[e.from]},ne=(Rr=r.launcher)!=null?Rr:true,ee=(Nr=r.help)!=null?Nr:true,ke=(qr=r.updates)!=null?qr:true,Le=(Fr=r.sound)!=null?Fr:true,wt=(Ur=r.preview)!=null?Ur:true,b=()=>{var e,t;return (t=r.client)!=null?t:Wt({host:r.host,apiKey:r.apiKey,distinctId:r.distinctId(),user:r.user(),userHash:(e=r.userHash)==null?void 0:e.call(r)})},P=a("div",{class:"ckw-root","data-theme":(Dr=r.theme)!=null?Dr:"auto","data-corners":r.corners==="soft"||r.corners==="square"?r.corners:"round","data-font":r.font==="system"?"system":"site","data-header":r.header==="color"?"color":"plain",...Dt()?{lang:Dt()}:{}});r.container&&P.setAttribute("data-contained",""),r.accent&&(P.style.setProperty("--ckw-accent",r.accent),P.style.setProperty("--ckw-accent-ink",na(r.accent))),(Br=r.glow)==null||Br.slice(0,2).forEach((e,t)=>/^#[0-9a-f]{6}$/i.test(e)&&P.style.setProperty(`--ckw-glow${t+2}`,e)),((Kr=r.container)!=null?Kr:document.body).appendChild(P);let S=false,me=null,u="home",J=null,M=[],Jt=false,I=null,Q=null,Qt=0,oe=false,Te=false,q="",Xt=e=>e.status===401?c("The chat is not available right now. Please try again later."):e.message,te=[],ha=0,kt=false,mt=new Map,ie=Za(),ue=new Map,A=[],Ke=false,We,Ve=false,T=null,O=null,Y="",ut=new Set,$e=null,se=[],he=0,re=null,He=false,fe=null,K=null,je=false,Pe=!r.client&&!!r.apiKey,Ie=un+r.apiKey,Zt=hn+r.apiKey,Ye=r.distinctId(),er=(Wr=r.user())==null?void 0:Wr.id,tr=()=>{let e=Pe?Gt(Ie):null;M=(e==null?void 0:e.who)===Ye&&Array.isArray(e.chats)?e.chats:[];};if(tr(),Pe){let e=Gt(Zt);(Vr=e==null?void 0:e.articles)!=null&&Vr.length&&(se=e.articles,O=e.articles,$e=true),He=!!(e!=null&&e.updates);}let fa=e=>{var t;!Pe||r.distinctId()!==e||(M.length?gt(Ie,{who:e,chats:M.slice(0,ga)}):((t=Gt(Ie))==null?void 0:t.who)===e&>(Ie,null));},rr=()=>{Pe&>(Zt,se.length||He?{articles:se.slice(0,ga),updates:He}:null);},ar=e=>e.from==="team"||e.from==="ai",ht=()=>S&&u==="messages"&&document.visibilityState!=="hidden",nr=()=>{var e,t;return oe||Q!==null?null:(t=I!=null?I:(e=J==null?void 0:J.conversation)==null?void 0:e.id)!=null?t:null},or=e=>A.filter(t=>t.chat===e).length,ir=(e,t,o,s,d)=>{var p;let f=mt.get(e),g=m=>t.filter(v=>v.at>m);if(f===void 0){let m=ie.chats[e],v=d&&(!m||d>m)?d:m,x=s?[]:v?g(v):t.slice(t.findIndex(L=>L.id===ie.old)+1);A=[...A,...x.map(L=>({...L,chat:e}))],Te&&x.length&&(Le&&Ee.play(),Ke=false);}else {let m=g(f);m.length&&(Le&&Ee.play(),(!ht()||nr()!==e)&&(A=[...A,...m.map(v=>({...v,chat:e}))],Ke=false));}mt.set(e,(p=o!=null?o:f)!=null?p:"");},sr=e=>{var d,f;let t=e.conversation,o=e.messages.at(-1);M=(d=e.conversations)!=null?d:t&&o?[{id:t.id,status:t.status,subject:pt(e.messages[0]),last:o}]:[],Jt=e.hasEmail,M.forEach((g,p)=>{var m;g.id!==(t==null?void 0:t.id)&&ir(g.id,g.last&&ar(g.last)?[g.last]:[],(m=g.last)==null?void 0:m.at,g.status==="solved"&&p>0,g.seenAt);}),t&&ir(t.id,e.messages.filter(ar),o==null?void 0:o.at,t.status==="solved"&&((f=M[0])==null?void 0:f.id)!==t.id,t.seenAt);let s=new Map(M.flatMap(g=>g.seenAt?[[g.id,g.seenAt]]:[]));t!=null&&t.seenAt&&s.set(t.id,t.seenAt);for(let[g,p]of s)(!ue.has(g)||p>ue.get(g))&&ue.set(g,p);A=A.filter(oa(e,M)).filter(g=>!(s.get(g.chat)&&g.at<=s.get(g.chat))),(I===null||(t==null?void 0:t.id)===I)&&(J=e),ht()&&ft();},ft=()=>{var d,f;let e=nr();if(!e)return;A=A.filter(g=>g.chat!==e);let t=mt.get(e);if(!t)return;let o=ue.get(e);if((!o||o<t)&&(ue.set(e,t),(f=(d=b()).seenChat)==null||f.call(d,e,t).catch(()=>ue.delete(e))),ie.chats[e]===t)return;let s=Object.fromEntries(Object.entries(ie.chats).filter(([g])=>M.some(p=>p.id===g)));ie={...ie,chats:{...s,[e]:t}},rn(ie.chats);},be=(e,t,o=false)=>{(e!==I||t!==Q)&&(T==null||T.abort(),T=null,J=null,Nt="",Fe=-1),I=e,Q=t,oe=o;},ce=()=>be(null,null,M.length>1),bt=()=>be(null,++Qt),cr=e=>a("span",{class:`ckw-msgr-av${" ckw-msgr-av-sm"}`,"aria-hidden":"true"},z),Ge=e=>{if(!r.icon)return cr();let t=a("span",{class:`ckw-msgr-av ckw-msgr-av-img${" ckw-msgr-av-sm"}`,"aria-hidden":"true"}),o=a("img",{src:r.icon,alt:""});return o.addEventListener("error",()=>t.replaceWith(cr())),t.append(o),t},Je=a("span",{class:"ckw-msgr-logo","aria-hidden":"true"});if(r.logo){let e=a("img",{src:r.logo,alt:""});e.addEventListener("error",()=>Je.replaceChildren(Ge())),Je.append(e);}else Je.append(Ge());let ba=()=>r.agentPhoto?a("img",{class:"ckw-msg-face",src:r.agentPhoto,alt:""}):null,xa=a("div",{class:"ckw-msgr-sky","aria-hidden":"true"}),xe=new Map,Qe=(e,t=P)=>{clearTimeout(xe.get(e)),xe.delete(e),e.removeAttribute("data-out"),e.isConnected||t.appendChild(e);},Xe=(e,t=180)=>{!e.isConnected||xe.has(e)||(e.setAttribute("data-out",""),xe.set(e,setTimeout(()=>{xe.delete(e),e.removeAttribute("data-out"),e.remove();},t)));},xt=(e,t)=>{e.classList.remove(t),e.offsetWidth,e.classList.add(t);},X=a("button",{type:"button",class:`ckw-fab ckw-msgr-fab${l?"":" ckw-msgr-round"}`,"data-pos":n,"aria-haspopup":"dialog"}),va=a("span",{class:"ckw-msgr-fab-ic","aria-hidden":"true"},a("span",{class:"ckw-msgr-fab-i","data-i":"chat"},la(ca,da,l?20:27,2.6)),a("span",{class:"ckw-msgr-fab-i","data-i":"x"},E(C.down,l?18:24))),_e=a("span",{class:"ckw-msgr-count","aria-hidden":"true"});X.append(va),l&&X.append(a("span",{},l));let vt=a("div",{class:"ckw-msgr-preview","data-pos":n,role:"status"}),ve=()=>{if(X.toggleAttribute("data-open",S),A.length&&!S){let e=String(Math.min(A.length,9));_e.textContent!==e&&(_e.textContent=e),_e.isConnected||X.append(_e);}else _e.remove();X.setAttribute("aria-expanded",String(S)),X.setAttribute("aria-label",S?c("Close chat"):A.length===1?c("Open chat, 1 new reply"):A.length?j("Open chat, {n} new replies",{n:A.length}):c("Open chat")),dr();},yt=en(),lr=()=>{Ke=true;let e=A.reduce((t,o)=>o.at>t?o.at:t,"");e&&e>yt&&(yt=e,tn(e));},ya=()=>wt&&!S&&!Ke&&A.some(e=>e.at>yt)&&ne,dr=()=>{let e=A.at(-1);if(!ya()||!e)return Xe(vt);let t=a("button",{type:"button",class:"ckw-msgr-preview-x","aria-label":c("Dismiss")},E(C.cross,14));t.addEventListener("click",s=>{s.stopPropagation(),lr(),dr();});let o=a("button",{type:"button",class:"ckw-msgr-preview-card"},a("span",{class:"ckw-msgr-preview-main"},a("span",{class:"ckw-msgr-preview-who"},`${V(e)}${A.length>1?` \xB7 ${j("{n} new",{n:A.length})}`:""}`),a("span",{class:"ckw-msgr-preview-text"},pt(e))));o.addEventListener("click",()=>{be(e.chat,null),Ue("messages");}),vt.replaceChildren(o,t),Qe(vt);};X.addEventListener("click",()=>{if(Ee.unlock(),S)return Ae();let e=A.at(-1);e&&be(e.chat,null),Ue(e?"messages":"home");}),ne&&P.appendChild(X);let $=a("div",{class:"ckw-pop ckw-msgr","data-pos":n,role:"dialog","aria-label":i}),Ct=a("div",{class:"ckw-msgr-bar"}),y=a("div",{class:"ckw-pop-body ckw-msgr-body"});$.addEventListener("click",()=>Ee.unlock());let le=a("span",{class:"ckw-msgr-lead"}),de=a("span",{class:"ckw-msgr-mid"}),Oe=a("nav",{class:"ckw-msgr-tabs","aria-label":c("Messenger")}),Ze=(e,t,o,s,d)=>{let f=a("button",{type:"button",class:"ckw-msgr-tab"},a("span",{class:"ckw-msgr-tab-ic"},E(o,22),la(s,d,22)),a("span",{},t));return f.addEventListener("click",()=>{K=null,e==="messages"&&ce(),_(e);}),f},pr=Ze("home",c("Home"),C.home,on,sn),St=Ze("messages",c("Messages"),C.chat,ca,da),gr=Ze("help",c("Help"),C.help,cn,ln),wr=Ze("updates",c("Updates"),C.updates,dn,""),et=a("span",{class:"ckw-msgr-count ckw-msgr-count-tab","aria-hidden":"true"}),Re=a("button",{type:"button",class:"ckw-msgr-ib","aria-label":c("More"),"aria-haspopup":"menu","aria-expanded":"false"},E(C.dots,18)),kr=a("button",{type:"button",class:"ckw-msgr-ib ckw-msgr-x","aria-label":c("Close messenger")},E(C.cross));kr.addEventListener("click",()=>Ae()),Ct.append(le,de,a("span",{class:"ckw-msgr-trail"},Re,kr));let Z=a("div",{class:"ckw-msgr-menu",role:"menu"}),zt=()=>Z.isConnected&&!Z.hasAttribute("data-out"),Ne=()=>{Re.setAttribute("aria-expanded","false"),Xe(Z,120);},mr=(e,t,o)=>{let s=a("button",{type:"button",class:"ckw-msgr-menu-i",role:"menuitem"},E(e,15),a("span",{},t));return s.addEventListener("click",d=>{d.stopPropagation(),Ne(),o();}),s};Re.addEventListener("click",e=>{var t;if(e.stopPropagation(),zt())return Ne();Z.replaceChildren(a("span",{class:"ckw-msgr-menu-h"},c("Quick actions")),mr(C.minus,c("Minimize chat"),()=>Ae()),mr(je?C.collapse:C.expand,je?c("Collapse view"):c("Expand view"),()=>{je=!je,$.toggleAttribute("data-wide",je);})),Re.setAttribute("aria-expanded","true"),Qe(Z,$),(t=Z.querySelector("button"))==null||t.focus();}),$.addEventListener("click",()=>zt()&&Ne());let ur=()=>{let e=(o,s)=>{let d=a("button",{type:"button",class:"ckw-msgr-ib","aria-label":s},E(C.back,18));return d.addEventListener("click",o),d};typeof u!="string"?le.replaceChildren(e(()=>_("help"),c("Back to help"))):u==="help"&&K&&!Y.trim()?le.replaceChildren(e(()=>{K=null,_("help");},c("All collections"))):u==="messages"&&!oe&&M.length>1?le.replaceChildren(e(()=>{ce(),_("messages");},c("All conversations"))):u==="messages"?le.replaceChildren(e(()=>_("home"),c("Back to home"))):u==="home"?le.replaceChildren(Je):le.replaceChildren(),u==="messages"&&oe?de.replaceChildren(a("b",{},c("Messages"))):u==="messages"?de.replaceChildren(Ge(),a("span",{class:"ckw-msgr-mid-t"},a("b",{},i),a("span",{class:"ckw-msgr-online"},k))):u==="help"?de.replaceChildren(a("b",{},!Y.trim()&&K||c("Help"))):u==="updates"?de.replaceChildren(a("b",{},c("Updates"))):typeof u!="string"?de.replaceChildren(a("b",{},Ea(u.article)||c("Help"))):de.replaceChildren();let t=[pr,St,...ee&&$e?[gr]:[],...ke&&(re?re.length:He)?[wr]:[]];(Oe.childNodes.length!==t.length||t.some((o,s)=>Oe.childNodes[s]!==o))&&Oe.replaceChildren(...t),Oe.toggleAttribute("data-four",t.length>3),pr.setAttribute("aria-current",u==="home"?"page":"false"),St.setAttribute("aria-current",u==="messages"?"page":"false"),gr.setAttribute("aria-current",u!=="home"&&u!=="messages"&&u!=="updates"?"page":"false"),wr.setAttribute("aria-current",u==="updates"?"page":"false"),A.length&&u!=="messages"?(et.textContent=String(Math.min(A.length,9)),et.isConnected||St.firstChild.appendChild(et)):et.remove();},pe=a("form",{class:"ckw-msgr-compose"}),tt=a("p",{class:"ckw-msgr-error",role:"alert"}),G=a("input",{class:"ckw-input ckw-msgr-email",type:"email",inputmode:"email",autocomplete:"email",placeholder:c("Email for our reply (optional)"),"aria-label":c("Your email (optional)"),maxlength:"200","data-1p-ignore":"","data-lpignore":"true","data-bwignore":"","data-form-type":"other"}),ye=a("div",{class:"ckw-msgr-box"}),R=a("textarea",{class:"ckw-textarea ckw-msgr-input",rows:"1",placeholder:c("Write your message\u2026"),"aria-label":c("Message"),maxlength:"4000"}),Mt=a("button",{type:"submit",class:"ckw-msgr-send","aria-label":c("Send")},E(C.up)),At=an(),qe=a("button",{type:"button",class:"ckw-msgr-clip","aria-label":At?c("Attach a file or a screenshot"):c("Attach a file"),...At?{"aria-haspopup":"menu","aria-expanded":"false"}:{}},E(C.clip,18));ye.append(R,a("div",{class:"ckw-msgr-tools"},qe,a("span",{class:"ckw-msgr-sp"}),Mt)),ye.addEventListener("click",e=>e.target===ye&&R.focus()),pe.append(ye);let Ce=a("input",{type:"file",accept:Bt.join(","),multiple:"",hidden:"",tabindex:"-1","aria-hidden":"true"});pe.append(Ce);let rt=a("div",{class:"ckw-msgr-files",role:"list","aria-label":c("Files to send")}),F=[],Se=new Map,Et=e=>{var t;return (t=Se.get(e))!=null?t:b().attachmentUrl(e)},hr=e=>{e.ctrl.abort(),[...Se.values()].includes(e.local)||URL.revokeObjectURL(e.local);},fr=e=>{F=F.filter(t=>t!==e),hr(e);},at=e=>{q="";for(let t of e){let o=t.name||"screenshot.png";if(F.length>=Kt){q=j("Up to {n} files per message.",{n:Kt});break}if(!Bt.includes(t.type)){q=c("Only pictures (PNG, JPEG, WebP, GIF) and PDFs can be sent.");continue}if(t.size>ta){q=j("{name} is larger than 10 MB.",{name:o});continue}let s={key:`local-${Date.now().toString(36)}${Math.random().toString(36).slice(2,7)}`,name:o,type:t.type,size:t.size,local:URL.createObjectURL(t),up:Promise.resolve(),ctrl:new AbortController};s.up=b().uploadChatFile(t,s.ctrl.signal).then(d=>{s.id=d.id,N();},d=>{d.name!=="AbortError"&&(fr(s),q=`${s.name}: ${d.message}`,N());}),F.push(s);}S&&(u!=="messages"||oe)?(bt(),_("messages")):N(),R.focus();},br="",Ca=()=>{let e=F.map(t=>`${t.key}:${t.id?1:0}`).join(",");e!==br&&(br=e,rt.replaceChildren(...F.map(t=>{let o=a("button",{type:"button",class:"ckw-msgr-file-x","aria-label":j("Remove {name}",{name:t.name})},E(C.cross,12));o.addEventListener("click",()=>{fr(t),N(),R.focus();});let s=t.type.startsWith("image/")?a("img",{src:t.local,alt:""}):a("span",{class:"ckw-msgr-file-doc"},E(C.doc,18),a("span",{},t.name));return a("div",{class:"ckw-msgr-file",role:"listitem",title:t.name,"aria-label":t.id?t.name:j("{name}, uploading",{name:t.name}),...t.id?{}:{"aria-busy":"true"}},s,o)}))),F.length?rt.isConnected||pe.insertBefore(rt,ye):rt.remove();},Sa=async()=>{var s;let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include"});}catch(d){d.name!=="NotAllowedError"&&d.name!=="AbortError"&&(q=c("The screenshot did not work here. Attach a picture instead."),N());return}P.style.visibility="hidden";let t=null;try{let d=document.createElement("video");d.muted=!0,d.playsInline=!0,d.srcObject=e,await d.play(),await new Promise(m=>setTimeout(m,300));let f=d;await new Promise(m=>f.requestVideoFrameCallback?f.requestVideoFrameCallback(()=>m()):requestAnimationFrame(()=>m()));let g=document.createElement("canvas");g.width=d.videoWidth,g.height=d.videoHeight,(s=g.getContext("2d"))==null||s.drawImage(d,0,0);let p=(m,v)=>new Promise(x=>g.toBlob(x,m,v));t=await p("image/png"),t&&t.size>4.5*1024*1024&&(t=await p("image/jpeg",.9));}catch(d){t=null;}finally{for(let d of e.getTracks())d.stop();P.style.visibility="";}if(!t||!t.size)return q=c("The screenshot did not work here. Attach a picture instead."),N();let o=new Date().toISOString().slice(0,16).replace(/[:T]/g,"-");at([Object.assign(t,{name:`screenshot-${o}.${t.type==="image/png"?"png":"jpg"}`})]);},ze=a("div",{class:"ckw-msgr-menu ckw-msgr-amenu",role:"menu"}),Lt=()=>ze.isConnected&&!ze.hasAttribute("data-out"),nt=()=>{qe.setAttribute("aria-expanded","false"),Xe(ze,120);},xr=(e,t,o)=>{let s=a("button",{type:"button",class:"ckw-msgr-menu-i",role:"menuitem"},E(e,15),a("span",{},t));return s.addEventListener("click",d=>{d.stopPropagation(),nt(),o();}),s};qe.addEventListener("click",e=>{var t;if(e.stopPropagation(),Ee.unlock(),!At)return Ce.click();if(Lt())return nt();ze.replaceChildren(xr(C.image,c("Photo or file"),()=>Ce.click()),xr(C.screen,c("Screenshot of this page"),()=>{Sa();})),qe.setAttribute("aria-expanded","true"),Qe(ze,pe),(t=ze.querySelector("button"))==null||t.focus();}),Ce.addEventListener("change",()=>{var e;at([...(e=Ce.files)!=null?e:[]]),Ce.value="";});let za=a("a",{class:"ckw-msgr-powered",href:ra,target:"_blank",rel:"noopener"},c("Powered by {brand}").split("{brand}")[0],a("b",{},"MRRocket"),c("Powered by {brand}").split("{brand}")[1]),vr=a("ol",{class:"ckw-msgs","aria-live":"polite","aria-label":c("Messages")}),yr=()=>{var e;return h&&!((e=r.user())!=null&&e.email)&&!Jt},Tt=()=>!G.value.trim()||Qa.test(G.value.trim()),$t=()=>(!!R.value.trim()||F.length>0)&&Tt(),_=e=>{let t=JSON.stringify(e)!==JSON.stringify(u);u=e,ct=-1,N(),t&&xt(y,"ckw-msgr-enter"),e==="messages"?(ft(),ve(),R.focus()):e==="help"&&K===null&&jt.focus(),ae(0);},Ma=(e,t)=>{let o=a("img",{src:e,alt:t,loading:"lazy"});return o.addEventListener("load",()=>{y.scrollHeight-y.scrollTop-y.clientHeight<o.clientHeight+120&&(y.scrollTop=y.scrollHeight);}),o},Cr=(e,t=false)=>{var d,f,g;let o=t&&Date.now()-Date.parse(e.at)>=Yt,s=a("li",{class:"ckw-msg","data-from":e.from==="visitor"?"me":"them"},e.body||!((d=e.attachments)!=null&&d.length)?a("div",{class:"ckw-bubble"},e.body):null);t&&s.setAttribute("aria-busy","true"),(f=e.attachments)!=null&&f.length&&s.append(a("div",{class:"ckw-msg-files"},...e.attachments.map(p=>p.type.startsWith("image/")?a("a",{class:"ckw-msg-img",href:Et(p.id),target:"_blank",rel:"noopener",title:p.name},Ma(Et(p.id),p.name)):a("a",{class:"ckw-msgr-cite",href:Et(p.id),target:"_blank",rel:"noopener"},E(C.doc,14),a("span",{},p.name)))));for(let p of (g=e.articles)!=null?g:[]){let m=a("button",{type:"button",class:"ckw-msgr-cite"},E(C.doc,14),a("span",{},p.title));m.addEventListener("click",()=>_({article:p.id})),s.append(m);}return s.append(a("span",{class:"ckw-msg-meta"},e.from==="ai"?ba():null,`${e.from!=="visitor"?`${V(e)} \xB7 `:""}${o?c("Sending\u2026"):dt(e.at)}`)),s},Aa=e=>{let t=a("button",{type:"button",class:"ckw-msgr-art"},a("span",{class:"ckw-msgr-art-t"},e.title),E(C.next,14));return t.addEventListener("click",()=>_({article:e.id})),t},Sr=(e,t,o,s)=>{let d=a("button",{type:"button",class:"ckw-msgr-card ckw-msgr-hrow"},a("span",{class:"ckw-msgr-card-main"},a("b",{},e),t?a("span",{class:"ckw-msgr-hrow-sub"},t):null,o?a("span",{class:"ckw-msgr-card-meta"},o):null),E(C.next,16));return d.addEventListener("click",s),d},Ea=e=>{var t;return (W==null?void 0:W.id)===e&&W.collection||((t=[...O!=null?O:[],...se].find(o=>o.id===e))==null?void 0:t.collection)||""},Ht=((e=c("Search for help"))=>{let t=a("label",{class:"ckw-msgr-search"}),o=a("input",{class:"ckw-msgr-search-in",type:"search",placeholder:e,"aria-label":c("Search for help"),maxlength:"200"});o.value=Y;let s;return o.addEventListener("input",()=>{Y=o.value,clearTimeout(s),s=setTimeout(()=>{if(u!=="help")return _("help");It(true);},250);}),o.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),u!=="help"&&_("help"));}),t.append(E(C.search,16),o),t})(c("Search our help center\u2026")),jt=Ht.querySelector("input"),Pt=false,ot=()=>{bt(),_("messages");},It=async(e=false)=>{if(!ee||Pt&&!e)return;Pt=true;let t=Y.trim();try{let o=await b().articles(t||void 0);if(t!==Y.trim())return;O=o.articles,t||(se=o.articles,$e=o.articles.length>0,rr());}catch(o){O=O!=null?O:[];}finally{Pt=false;}N();},La=async()=>{try{re=(await b().changelog()).entries.slice(0,Ka),He=re.length>0,rr();}catch(e){re=[];}fe=null,N();},_t=a("form",{class:"ckw-msgr-askq"}),Me=a("input",{class:"ckw-msgr-askq-in",placeholder:c("Ask a question"),"aria-label":c("Ask a question"),maxlength:"4000",autocomplete:"off"}),Ot=a("button",{type:"submit",class:"ckw-msgr-send","aria-label":c("Send"),disabled:""},E(C.up));_t.append(Me,Ot),Me.addEventListener("input",()=>Ot.disabled=!Me.value.trim()),_t.addEventListener("submit",e=>{if(e.preventDefault(),!Me.value.trim())return ce(),_("messages");R.value=Me.value,Me.value="",Ot.disabled=true,bt(),_("messages"),$t()&&Ft();});let it=(e,t=false)=>a("div",{class:"ckw-msgr-shapes","aria-hidden":"true"},...Array.from({length:e},()=>a("div",{class:t?"ckw-msgr-card ckw-msgr-recent":"ckw-msgr-shape"},a("span",{class:"ckw-msgr-recent-row"},t?a("span",{class:"ckw-msgr-av ckw-msgr-av-sm ckw-msgr-sk"}):null,a("span",{class:"ckw-msgr-card-main"},a("span",{class:"ckw-msgr-sk"}),a("span",{class:"ckw-msgr-sk"})))))),zr=e=>(e.isConnected&&e.setAttribute("data-still",""),e),Ta=it(1,true),$a=it(3),st=null,Mr=e=>{let t=e.last,o=or(e.id),s=e.status==="solved"?` \xB7 ${c("Closed")}`:"",d=a("button",{type:"button",class:"ckw-msgr-card ckw-msgr-recent","aria-label":`${j("Conversation: {subject}",{subject:e.subject})}${s}${o?`, ${j("{n} new",{n:o})}`:""}`},a("span",{class:"ckw-msgr-recent-row"},Ge(),a("span",{class:"ckw-msgr-card-main"},a("span",{class:"ckw-msgr-card-sub ckw-msgr-recent-text"},e.subject),t&&pt(t)!==e.subject?a("span",{class:"ckw-msgr-card-sub"},pt(t)):null,t?a("span",{class:"ckw-msgr-card-meta"},`${V(t)} \xB7 ${dt(t.at)}${s}`):null),o?a("span",{class:"ckw-msgr-badge"},String(o)):E(C.next,14)));return d.addEventListener("click",()=>{be(e.id,null),_("messages");}),d},Rt=a("div",{class:"ckw-msgr-chats"}),Ar=a("button",{type:"button",class:"ckw-btn ckw-btn-primary ckw-msgr-new"},E(C.chat),c("New conversation"));Ar.addEventListener("click",ot);let Er="",Ha=()=>{let e=`${M.map(t=>{var o;return `${t.id}:${t.status}:${(o=t.last)==null?void 0:o.id}:${or(t.id)}`}).join()}|${Math.floor(Date.now()/6e4)}`;e!==Er&&(Er=e,Rt.replaceChildren(...M.map(Mr))),y.childNodes[0]!==Rt&&y.replaceChildren(Rt,Ar);},ja=()=>{var v,x,L;let e=(x=(v=r.user())==null?void 0:v.name)==null?void 0:x.trim().split(/\s+/)[0],t=(r.greeting?w.replace(/^(hi|hello|hey|hallo|moin|servus|bonjour|salut|hola|ciao|salve|hoi|ol[áa]|cze[śs][ćc]|hej|こんにちは)( there)?\s*[!,.!、。]*\s*/i,"").trim():c("How can we help?"))||c("How can we help you today?"),s=[a("h2",{class:"ckw-msgr-hero ckw-msgr-hello"},a("span",{},`${e?j("Hi, {name}",{name:e}):c("Hi there")} `,a("span",{class:"ckw-msgr-wave","aria-hidden":"true"},"\u{1F44B}")),a("span",{class:"ckw-msgr-hello-sub"},t)),_t],d=new Set,f=(H,Yr)=>(d.add(Yr),st&&!st.has(Yr)&&H.setAttribute("data-arrive",""),H),g=M.filter(H=>H.status!=="solved"),p=(g.length?g:M).slice(0,2);if(s.push(...p.map(H=>f(Mr(H),H.id))),!p.length&&!Te&&he<3&&((L=r.user())!=null&&L.id)&&s.push(zr(Ta)),M.length>p.length){let H=a("button",{type:"button",class:"ckw-msgr-all"},j("All conversations ({n})",{n:M.length}),E(C.next,14));H.addEventListener("click",()=>{ce(),_("messages");}),s.push(H);}let m=ee?se.slice(0,3):[];m.length&&s.push(f(a("div",{class:"ckw-msgr-card ckw-msgr-card-col"},...m.map(Aa)),"help")),st=d,y.replaceChildren(...s);},Pa=()=>{var f,g;jt.value!==Y&&(jt.value=Y);let e=Y.trim(),t=O!=null?O:[],o=new Map;for(let p of t)o.set(p.collection,[...(f=o.get(p.collection))!=null?f:[],p]);let s=!e&&K!==null?(g=o.get(K))!=null?g:[]:null,d=[];if(O===null)d.push(zr($a));else if(t.length)e||s?d.push(...e?[a("p",{class:"ckw-msgr-help-h"},c("Search results"))]:[],a("div",{class:"ckw-msgr-hlist"},...(s!=null?s:t).map(p=>Sr(p.title,p.excerpt.startsWith(p.title)?p.excerpt.slice(p.title.length).trim():p.excerpt,e?p.collection:"",()=>_({article:p.id}))))):d.push(a("div",{class:"ckw-msgr-hlist"},...[...o].map(([p,m])=>Sr(p,m.slice(0,3).map(v=>v.title).join(", "),m.length===1?c("1 article"):j("{n} articles",{n:m.length}),()=>{K=p,_("help"),xt(y,"ckw-msgr-enter");}))));else {let p=a("button",{type:"button",class:"ckw-btn ckw-btn-primary"},c("Send us a message"));p.addEventListener("click",ot),d.push(a("div",{class:"ckw-msgr-empty"},a("p",{},e?j("Nothing found for \u201C{q}\u201D.",{q:e}):c("No help articles yet.")),p));}if(y.firstChild!==Ht)y.replaceChildren(Ht,...d);else {for(;y.childNodes.length>1;)y.lastChild.remove();y.append(...d);}},Ia=()=>{fe!=null||(fe=re?re.length?a("div",{class:"ckw-msgr-updates"},...re.map(e=>a("article",{class:"ckw-msgr-update"},a("p",{class:"ckw-msgr-doc-c"},dt(e.publishedAt)),a("h2",{class:"ckw-msgr-update-t"},e.title),e.body?a("p",{class:"ckw-msgr-update-b"},e.body):null))):a("div",{class:"ckw-msgr-empty"},a("p",{},c("No updates yet."))):it(3)),(y.firstChild!==fe||y.childNodes.length!==1)&&y.replaceChildren(fe);},W=null,_a=e=>{if((W==null?void 0:W.id)===e)return y.replaceChildren(W.node);let t=a("article",{class:"ckw-msgr-doc"},it(4)),o={id:e,node:t};W=o,y.replaceChildren(t),b().article(e,void 0,pn).then(s=>{o.collection=s.collection,W===o&&ur();let d=a("div",{class:"ckw-msgr-rate"}),f=()=>{if(ut.has(e))return d.replaceChildren(a("span",{},c("Thanks for letting us know.")));let v=a("button",{type:"button",class:"ckw-btn"},c("Yes")),x=a("button",{type:"button",class:"ckw-btn"},c("No")),L=H=>{ut=new Set(ut).add(e),f(),b().rateArticle(e,H).catch(()=>{}),H||ot();};v.addEventListener("click",()=>L(true)),x.addEventListener("click",()=>L(false)),d.replaceChildren(a("span",{},c("Did this answer your question?")),a("span",{class:"ckw-msgr-rate-b"},v,x));};f();let g=a("button",{type:"button",class:"ckw-btn ckw-msgr-ask"},E(C.chat),c("Still need help? Send us a message"));g.addEventListener("click",ot);let p=s.blocks[0],m=p&&(p.type==="h2"||p.type==="h3")&&pa(p.spans)===pa([{text:s.title}])?s.blocks.slice(1):s.blocks;t.replaceChildren(a("h2",{class:"ckw-msgr-doc-t"},s.title),a("p",{class:"ckw-msgr-doc-c"},j("Updated {when}",{when:dt(s.updatedAt)})),a("div",{class:"ckw-msgr-doc-b"},...m.map(gn)),d,g);}).catch(s=>{W=null,t.replaceChildren(a("p",{class:"ckw-msgr-error"},s.message));});},ct=-1,Nt="",Fe=-1,qt=a("div",{class:"ckw-msgr-sugg"}),Oa=()=>te.filter(e=>e.draft===Q&&e.chat===I),Ra=()=>{var f,g;let e=Q===null?J:null,t=(f=e==null?void 0:e.messages)!=null?f:[],o=Oa(),s=[];{let p=o.map(x=>x.message),m=`${t.map(x=>x.id).join(",")}|${p.map(x=>`${x.id}:${Date.now()-Date.parse(x.at)>=Yt}`).join(",")}|${Math.floor(Date.now()/6e4)}`;if(m!==Nt){Nt=m;let L=[...t.length||p.length||I?[]:[a("li",{class:"ckw-msg","data-from":"them"},a("div",{class:"ckw-bubble"},w))],...t.map(H=>Cr(H)),...p.map(H=>Cr(H,true))];Fe>=0&&L.slice(Fe).forEach(H=>H.setAttribute("data-new","")),Fe=L.length,vr.replaceChildren(...L);}s.push(vr);let v=!t.some(x=>x.from==="visitor")&&!o.length&&!I?(O!=null?O:[]).slice(0,3):[];v.length&&(qt.childNodes.length!==v.length&&qt.replaceChildren(...v.map(x=>{let L=a("button",{type:"button",class:"ckw-msgr-sugg-b"},x.title);return L.addEventListener("click",()=>_({article:x.id})),L})),s.push(qt));}((g=e==null?void 0:e.conversation)==null?void 0:g.status)==="solved"&&!o.length&&s.push(a("p",{class:"ckw-fine ckw-msgr-note"},c("This conversation is closed. Write to start a new one."))),(y.childNodes.length!==s.length||s.some((p,m)=>y.childNodes[m]!==p))&&y.replaceChildren(...s);let d=t.length+o.length;d!==ct&&(ct=d,y.scrollTop=y.scrollHeight),tt.textContent=q,q&&!tt.isConnected?pe.prepend(tt):q||tt.remove(),yr()?(Tt()?G.removeAttribute("aria-invalid"):G.setAttribute("aria-invalid","true"),G.isConnected||ye.insertBefore(G,R)):G.remove(),Ca(),Mt.disabled=!$t();},N=()=>{if(!S)return;$.dataset.view=typeof u=="string"?u:"article",K!==null&&$e!==null&&!se.some(t=>t.collection===K)&&(K=null),ur(),u==="home"?ja():u==="messages"?(oe?Ha:Ra)():u==="help"?Pa():u==="updates"?Ia():_a(u.article);let e=u==="home"?[xa,Ct,y]:[Ct,y];e.push(u==="messages"&&!oe?pe:Oe),r.branding!==false&&e.push(za),Z.isConnected&&e.push(Z),($.childNodes.length!==e.length||e.some((t,o)=>$.childNodes[o]!==t))&&$.replaceChildren(...e);},Lr=async()=>{if(T)return;let e=T=new AbortController,t=r.distinctId(),o=false,s=setTimeout(()=>{o=true,e.abort();},Math.min(Va*2**he,Vt)),d;try{sr(await b().chat(e.signal,I!=null?I:void 0)),q="",Ve=!1,he=0,fa(t);}catch(f){if(f.name==="AbortError"&&!o)return;let g=f.status;Ve=g===401||g===403,g===404&&I?ce():S&&u==="messages"&&!o&&(q=Xt(f)),(o||g===void 0||g>=500)&&(he+=1,d=o?0:Math.min(1e3*2**(he-1),Vt));}finally{clearTimeout(s),T===e&&(T=null);}!Te&&d===void 0&&(Fe=-1,u==="messages"&&I===null&&Q===null&&!R.value.trim()&&!te.length&&!F.length&&ce(),Te=true),N(),ve(),ae(S&&document.visibilityState!=="hidden"?d:void 0);},Na=()=>{var t,o;let e=r.distinctId();e===Ye&&!Ve||(e!==Ye&&(er&&!((t=r.user())!=null&&t.id)&&Pe&>(Ie,null),Ye=e,T==null||T.abort(),T=null,A=[],Te=false,he=0,tr()),er=(o=r.user())==null?void 0:o.id,N(),ve(),ae(0));};function ae(e){clearTimeout(We);let t=M.filter(g=>g.status!=="solved"),o=t.length>0,s=t.some(g=>g.last&&Date.now()-new Date(g.last.at).getTime()<Ja),d=e===void 0&&!S&&!o,f=e!=null?e:document.visibilityState==="hidden"?0:ht()?Wa:o&&s?Ya:d?Ga:Vt;(f||e===0)&&(We=setTimeout(()=>{var g;return d&&(Ve||!((g=r.user())!=null&&g.id||M.length))?ae():void Lr()},f));}let Tr=()=>{document.visibilityState==="visible"?ae(0):clearTimeout(We);};document.addEventListener("visibilitychange",Tr);let qa=async()=>{var e,t;if(!kt){for(kt=true;te.length;){let o=te[0],{message:s,files:d,email:f}=o;await Promise.all(d.map(p=>p.up));let g=d.filter(p=>p.id).map(p=>p.id);try{if(!s.body&&!g.length)throw new Error(q||c("The file could not be sent."));let p=await b().sendChat({body:s.body,...o.draft!==null?{conversation:"new"}:o.chat?{conversation:o.chat}:{},email:f,url:window.location.href.slice(0,500),...g.length?{attachments:g}:{},context:{viewport:`${window.innerWidth}\xD7${window.innerHeight}`}});T==null||T.abort(),T=null;let m=(t=(e=p.conversation)==null?void 0:e.id)!=null?t:null;if(m){let v=te.slice(1).filter(x=>x.draft===o.draft&&x.chat===o.chat);o.draft===Q&&o.chat===I&&(Q=null,I=m);for(let x of v)x.draft=null,x.chat=m;}sr(p),te.shift();for(let v of d)Se.delete(v.key),URL.revokeObjectURL(v.local);}catch(p){let m=te.splice(0),v=p.status===404;be(v?null:m[0].chat,v?++Qt:m[0].draft),R.value=[...m.map(x=>x.message.body),R.value.trim()].filter(Boolean).join(`
|
|
639
|
-
`),
|
|
641
|
+
`,da=()=>{if(typeof document=="undefined"||document.getElementById(la))return;let r=document.createElement("style");r.id=la,r.textContent=Ya,document.head.appendChild(r);};var Va=20,Ga=4e3,Ja=1500,Qa=5e3,Xa=8e3,Xt=3e4,Za=6e4,en=10*6e4,Zt=1500,tn=/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/,rn="ckw_msgr_seen",ua="ckw_msgr_seen_chats",an=()=>{var r,n;try{return {old:(r=window.localStorage.getItem(rn))!=null?r:"",chats:JSON.parse((n=window.localStorage.getItem(ua))!=null?n:"{}")}}catch(i){return {old:"",chats:{}}}},ha="ckw_msgr_preview_gone",nn=()=>{var r;try{return (r=window.localStorage.getItem(ha))!=null?r:""}catch(n){return ""}},on=r=>{try{window.localStorage.setItem(ha,r);}catch(n){}},sn=r=>{try{window.localStorage.setItem(ua,JSON.stringify(r));}catch(n){}},kt=r=>{let n=new Date(r).getTime();if(Number.isNaN(n))return "";let i=Math.max(0,Date.now()-n)/1e3;return i<60?c("just now"):i<3600?$("{n}m ago",{n:Math.floor(i/60)}):i<86400?$("{n}h ago",{n:Math.floor(i/3600)}):i<86400*30?$("{n}d ago",{n:Math.floor(i/86400)}):new Date(r).toLocaleDateString(ke(),{month:"short",day:"numeric",year:"numeric"})},a=(r,n={},...i)=>{let w=document.createElement(r);for(let[h,l]of Object.entries(n))w.setAttribute(h,l);for(let h of i)h!==null&&h!==false&&h!==void 0&&w.append(h);return w},We="http://www.w3.org/2000/svg",E=(r,n=16)=>{let i=document.createElementNS(We,"svg");for(let[h,l]of Object.entries({class:"ckw-icon",width:String(n),height:String(n),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.75","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"}))i.setAttribute(h,l);let w=document.createElementNS(We,"path");return w.setAttribute("d",r),i.appendChild(w),i},y={cross:"M18 6 6 18M6 6l12 12",chat:"M7.9 20A9 9 0 1 0 4 16.1L2 22z",up:"M12 19V5M5 12l7-7 7 7",home:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",back:"m15 18-6-6 6-6",next:"m9 18 6-6-6-6",search:"M19 11a8 8 0 1 1-16 0 8 8 0 0 1 16 0zM21 21l-4.3-4.3",doc:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7zM14 2v4a2 2 0 0 0 2 2h4M10 9H8M16 13H8M16 17H8",dots:"M13 12a1 1 0 1 1-2 0 1 1 0 0 1 2 0zM13 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0zM13 19a1 1 0 1 1-2 0 1 1 0 0 1 2 0z",expand:"M15 3h6v6M21 3l-7 7M3 21l7-7M9 21H3v-6",collapse:"m14 10 7-7M20 10h-6V4M3 21l7-7M4 14h6v6",minus:"M5 12h14",down:"m6 9 6 6 6-6",help:"M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20zM9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3M12 17h.01",updates:"m3 11 18-5v12L3 14zM11.6 16.8a3 3 0 1 1-5.8-1.6",clip:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48",image:"M19 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zM9 11a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM21 15l-3.09-3.09a2 2 0 0 0-2.82 0L6 21",screen:"M20 3H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2zM8 21h8M12 17v4"},mt=r=>{var n,i;return r.body||(((n=r.attachments)==null?void 0:n.length)===1?$("Sent {name}",{name:r.attachments[0].name}):(i=r.attachments)!=null&&i.length?$("Sent {n} files",{n:r.attachments.length}):"")},cn=()=>{var r;return typeof navigator!="undefined"&&typeof((r=navigator.mediaDevices)==null?void 0:r.getDisplayMedia)=="function"},pa="M7.9 20A9 9 0 1 0 4 16.1L2 22z",ln=(r,n)=>{let i=document.createElementNS(We,"svg");for(let[h,l]of Object.entries({class:"ckw-icon",width:String(n),height:String(n),viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor","stroke-width":"1.5","stroke-linejoin":"round","aria-hidden":"true"}))i.setAttribute(h,l);let w=document.createElementNS(We,"path");return w.setAttribute("d",r),i.appendChild(w),i},ga=(r,n,i,w=2)=>{let h=ln(r,i),l=document.createElementNS(We,"path");for(let[m,z]of Object.entries({d:n,class:"ckw-cut",fill:"none","stroke-width":String(w),"stroke-linecap":"round","stroke-linejoin":"round"}))l.setAttribute(m,z);return h.appendChild(l),h},wa="M8 12h.01M12 12h.01M16 12h.01",dn="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",pn="M9.5 15.5c1.4 1 3.6 1 5 0",gn="M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20z",wn="M9.4 9.2a2.7 2.7 0 0 1 5.2 1c0 1.8-2.6 2.5-2.6 2.5M12 16.8h.01",kn="m3 11 18-5v12L3 14zM5.8 15.2a3 3 0 0 0 5.8 1.6z",Le=(()=>{let r=null,n=()=>{var w;let i=(w=window.AudioContext)!=null?w:window.webkitAudioContext;return i?(r!=null||(r=new i),r):null};return {unlock:()=>{try{let i=n();(i==null?void 0:i.state)==="suspended"&&i.resume();}catch(i){}},play:()=>{try{let i=n();if(!i||i.state!=="running")return;let w=i.currentTime;[880,1318.5].forEach((h,l)=>{let m=i.createOscillator(),z=i.createGain(),W=w+l*.11;m.type="sine",m.frequency.value=h,z.gain.setValueAtTime(1e-4,W),z.gain.exponentialRampToValueAtTime(.12,W+.012),z.gain.exponentialRampToValueAtTime(1e-4,W+.32),m.connect(z),z.connect(i.destination),m.start(W),m.stop(W+.34);});}catch(i){}}}})(),Ke=r=>r.map(n=>{let i=n.href?a("a",{href:n.href,target:"_blank",rel:"noopener noreferrer"},n.text):a("span",{},n.text);return n.code&&(i=a("code",{},i)),n.italic&&(i=a("em",{},i)),n.bold&&(i=a("strong",{},i)),i}),mn="table",un=r=>{var n;switch(r.type){case "table":{let i=(w,h)=>a("tr",{},...w.map(l=>a(h,{},...Ke(l))));return a("div",{class:"ckw-msgr-doc-table",tabindex:"0"},a("table",{},r.head.length?a("thead",{},i(r.head,"th")):null,a("tbody",{},...r.rows.map(w=>i(w,"td")))))}case "h2":case "h3":return a(r.type,{},...Ke(r.spans));case "quote":return a("blockquote",{},...Ke(r.spans));case "ul":case "ol":return a(r.type,{},...r.items.map(i=>a("li",{},...Ke(i))));case "code":return a("pre",{},a("code",{},r.text));case "hr":return a("hr");default:return a("p",{},...Ke((n=r.spans)!=null?n:[]))}},ka=r=>r.map(n=>n.text).join("").replace(/\s+/g," ").trim().toLowerCase(),hn=2500,fa="ckw_msgr_look:",fn=r=>{try{let n=window.localStorage.getItem(fa+r);return n?JSON.parse(n):null}catch(n){return null}},bn=(r,n)=>{try{window.localStorage.setItem(fa+r,JSON.stringify(n));}catch(i){}},xn="ckw_msgr_chats:",vn="ckw_msgr_product:",ma=20,er=r=>{var n;try{return JSON.parse((n=window.localStorage.getItem(r))!=null?n:"null")}catch(i){return null}},ut=(r,n)=>{try{n?window.localStorage.setItem(r,JSON.stringify(n)):window.localStorage.removeItem(r);}catch(i){}},ba=r=>{let n=null,i="",w=false,h=[],l=b=>n?b(n):h.push(b),m=new AbortController,z=!r.client&&!!r.apiKey,W=null,G=b=>{var ue,u,D;if(w)return;W=b;let H=`${ta()}:${JSON.stringify(b!=null?b:{})}`;if(n&&H===i)return;if(n!=null&&n.isOpen()){n.onClose(()=>G(b));return}n==null||n.destroy(),i=H;let C=Object.fromEntries(Object.entries(r).filter(([,M])=>M!==void 0));n=Sn({...b!=null?b:{},...C,accent:(ue=r.accent)!=null?ue:b==null?void 0:b.accent,theme:(u=r.theme)!=null?u:b==null?void 0:b.theme,branding:(D=b==null?void 0:b.branding)!=null?D:true});for(let M of h.splice(0))M(n);},oe=z?fn(r.apiKey):null;oe&&G(oe);let te=oe?void 0:setTimeout(()=>G(null),hn),me=()=>{var b,H;return ((H=r.client)!=null?H:Qt({host:r.host,apiKey:r.apiKey,distinctId:r.distinctId(),user:r.user(),userHash:(b=r.userHash)==null?void 0:b.call(r)})).messengerLook(m.signal).then(C=>{z&&C&&bn(r.apiKey,C),G(C);}).catch(()=>{G(W);}).finally(()=>clearTimeout(te))},Te=ke();me();let ht=ra(()=>{ke()!==Te?(Te=ke(),me()):n&&G(W);});return {open:b=>l(H=>H.open(b)),close:()=>n==null?void 0:n.close(),toggle:()=>l(b=>b.toggle()),refresh:()=>n==null?void 0:n.refresh(),destroy:()=>{w=true,ht(),m.abort(),clearTimeout(te),n==null||n.destroy();}}},yn=["top-left","top-center","top-right","middle-left","middle-right","bottom-left","bottom-center","bottom-right"],Sn=r=>{var Or,Rr,Nr,qr,Fr,Ur,Dr,Br,Kr,Wr,Yr,Vr,Gr,Jr,Qr;da();let n=(Or=yn.find(e=>e===r.position))!=null?Or:"bottom-right",i=r.title||c("Support"),w=r.greeting||c("Hi! How can we help?"),h=(Rr=r.askEmail)!=null?Rr:true,l=(Nr=r.label)!=null?Nr:"",m=ia(r.replyTime),z=((qr=i.trim()[0])!=null?qr:"?").toUpperCase(),W={visitor:c("You"),team:c("Team"),ai:(Fr=r.agentName)!=null&&Fr.trim()?`${r.agentName.trim()} \xB7 ${c("AI agent")}`:c("AI agent"),auto:c("Team")},G=e=>{var t;return e.from==="team"&&((t=e.name)!=null&&t.trim())?`${e.name.trim()} \xB7 ${c("Team")}`:W[e.from]},oe=(Ur=r.launcher)!=null?Ur:true,te=(Dr=r.help)!=null?Dr:true,me=(Br=r.updates)!=null?Br:true,Te=(Kr=r.sound)!=null?Kr:true,ht=(Wr=r.preview)!=null?Wr:true,b=()=>{var e,t;return (t=r.client)!=null?t:Qt({host:r.host,apiKey:r.apiKey,distinctId:r.distinctId(),user:r.user(),userHash:(e=r.userHash)==null?void 0:e.call(r)})},H=a("div",{class:"ckw-root","data-theme":(Yr=r.theme)!=null?Yr:"auto","data-corners":r.corners==="soft"||r.corners==="square"?r.corners:"round","data-font":r.font==="system"?"system":"site","data-header":r.header==="color"?"color":"plain",...Vt()?{lang:Vt()}:{}});r.container&&H.setAttribute("data-contained",""),r.accent&&(H.style.setProperty("--ckw-accent",r.accent),H.style.setProperty("--ckw-accent-ink",sa(r.accent))),(Vr=r.glow)==null||Vr.slice(0,2).forEach((e,t)=>/^#[0-9a-f]{6}$/i.test(e)&&H.style.setProperty(`--ckw-glow${t+2}`,e)),((Gr=r.container)!=null?Gr:document.body).appendChild(H);let C=false,ue=null,u="home",D=null,M=[],tr=false,P=null,X=null,rr=0,ie=false,$e=false,F="",ar=e=>e.status===401?c("The chat is not available right now. Please try again later."):e.message,re=[],xa=0,ft=false,bt=new Map,se=an(),he=new Map,A=[],Ye=false,Ve,Ge=false,L=null,I=null,J="",xt=new Set,He=null,ce=[],fe=0,ae=null,Pe=false,be=null,Y=null,je=false,Ie=!r.client&&!!r.apiKey,_e=xn+r.apiKey,nr=vn+r.apiKey,Je=r.distinctId(),or=(Jr=r.user())==null?void 0:Jr.id,ir=()=>{let e=Ie?er(_e):null;M=(e==null?void 0:e.who)===Je&&Array.isArray(e.chats)?e.chats:[];};if(ir(),Ie){let e=er(nr);(Qr=e==null?void 0:e.articles)!=null&&Qr.length&&(ce=e.articles,I=e.articles,He=true),Pe=!!(e!=null&&e.updates);}let va=e=>{var t;!Ie||r.distinctId()!==e||(M.length?ut(_e,{who:e,chats:M.slice(0,ma)}):((t=er(_e))==null?void 0:t.who)===e&&ut(_e,null));},sr=()=>{Ie&&ut(nr,ce.length||Pe?{articles:ce.slice(0,ma),updates:Pe}:null);},cr=e=>e.from==="team"||e.from==="ai",Qe=()=>C&&u==="messages"&&document.visibilityState!=="hidden",lr=()=>{var e,t;return ie||X!==null?null:(t=P!=null?P:(e=D==null?void 0:D.conversation)==null?void 0:e.id)!=null?t:null},dr=e=>A.filter(t=>t.chat===e).length,pr=(e,t,o,s,d)=>{var p;let f=bt.get(e),g=k=>t.filter(x=>x.at>k);if(f===void 0){let k=se.chats[e],x=d&&(!k||d>k)?d:k,S=s?[]:x?g(x):t.slice(t.findIndex(N=>N.id===se.old)+1);A=[...A,...S.map(N=>({...N,chat:e}))],$e&&S.length&&(Te&&Le.play(),Ye=false);}else {let k=g(f);k.length&&(Te&&Le.play(),(!Qe()||lr()!==e)&&(A=[...A,...k.map(x=>({...x,chat:e}))],Ye=false));}bt.set(e,(p=o!=null?o:f)!=null?p:"");},gr=e=>{var d,f;let t=e.conversation,o=e.messages.at(-1);M=(d=e.conversations)!=null?d:t&&o?[{id:t.id,status:t.status,subject:mt(e.messages[0]),last:o}]:[],tr=e.hasEmail,M.forEach((g,p)=>{var k;g.id!==(t==null?void 0:t.id)&&pr(g.id,g.last&&cr(g.last)?[g.last]:[],(k=g.last)==null?void 0:k.at,g.status==="solved"&&p>0,g.seenAt);}),t&&pr(t.id,e.messages.filter(cr),o==null?void 0:o.at,t.status==="solved"&&((f=M[0])==null?void 0:f.id)!==t.id,t.seenAt);let s=new Map(M.flatMap(g=>g.seenAt?[[g.id,g.seenAt]]:[]));t!=null&&t.seenAt&&s.set(t.id,t.seenAt);for(let[g,p]of s)(!he.has(g)||p>he.get(g))&&he.set(g,p);A=A.filter(ca(e,M)).filter(g=>!(s.get(g.chat)&&g.at<=s.get(g.chat))),(P===null||(t==null?void 0:t.id)===P)&&(D=e),Qe()&&vt();},vt=()=>{var d,f;let e=lr();if(!e)return;A=A.filter(g=>g.chat!==e);let t=bt.get(e);if(!t)return;let o=he.get(e);if((!o||o<t)&&(he.set(e,t),(f=(d=b()).seenChat)==null||f.call(d,e,t).catch(()=>he.delete(e))),se.chats[e]===t)return;let s=Object.fromEntries(Object.entries(se.chats).filter(([g])=>M.some(p=>p.id===g)));se={...se,chats:{...s,[e]:t}},sn(se.chats);},xe=(e,t,o=false)=>{(e!==P||t!==X)&&(L==null||L.abort(),L=null,D=null,Dt="",Ue=-1),P=e,X=t,ie=o;},le=()=>xe(null,null,M.length>1),yt=()=>xe(null,++rr),wr=e=>a("span",{class:`ckw-msgr-av${" ckw-msgr-av-sm"}`,"aria-hidden":"true"},z),Xe=e=>{if(!r.icon)return wr();let t=a("span",{class:`ckw-msgr-av ckw-msgr-av-img${" ckw-msgr-av-sm"}`,"aria-hidden":"true"}),o=a("img",{src:r.icon,alt:""});return o.addEventListener("error",()=>t.replaceWith(wr())),t.append(o),t},Ze=a("span",{class:"ckw-msgr-logo","aria-hidden":"true"});if(r.logo){let e=a("img",{src:r.logo,alt:""});e.addEventListener("error",()=>Ze.replaceChildren(Xe())),Ze.append(e);}else Ze.append(Xe());let ya=()=>r.agentPhoto?a("img",{class:"ckw-msg-face",src:r.agentPhoto,alt:""}):null,Sa=a("div",{class:"ckw-msgr-sky","aria-hidden":"true"}),ve=new Map,et=(e,t=H)=>{clearTimeout(ve.get(e)),ve.delete(e),e.removeAttribute("data-out"),e.isConnected||t.appendChild(e);},tt=(e,t=180)=>{!e.isConnected||ve.has(e)||(e.setAttribute("data-out",""),ve.set(e,setTimeout(()=>{ve.delete(e),e.removeAttribute("data-out"),e.remove();},t)));},St=(e,t)=>{e.classList.remove(t),e.offsetWidth,e.classList.add(t);},Z=a("button",{type:"button",class:`ckw-fab ckw-msgr-fab${l?"":" ckw-msgr-round"}`,"data-pos":n,"aria-haspopup":"dialog"}),Ca=a("span",{class:"ckw-msgr-fab-ic","aria-hidden":"true"},a("span",{class:"ckw-msgr-fab-i","data-i":"chat"},ga(pa,wa,l?20:27,2.6)),a("span",{class:"ckw-msgr-fab-i","data-i":"x"},E(y.down,l?18:24))),Oe=a("span",{class:"ckw-msgr-count","aria-hidden":"true"});Z.append(Ca),l&&Z.append(a("span",{},l));let Ct=a("div",{class:"ckw-msgr-preview","data-pos":n,role:"status"}),ye=()=>{if(Z.toggleAttribute("data-open",C),A.length&&!C){let e=String(Math.min(A.length,9));Oe.textContent!==e&&(Oe.textContent=e),Oe.isConnected||Z.append(Oe);}else Oe.remove();Z.setAttribute("aria-expanded",String(C)),Z.setAttribute("aria-label",C?c("Close chat"):A.length===1?c("Open chat, 1 new reply"):A.length?$("Open chat, {n} new replies",{n:A.length}):c("Open chat")),mr();},zt=nn(),kr=()=>{Ye=true;let e=A.reduce((t,o)=>o.at>t?o.at:t,"");e&&e>zt&&(zt=e,on(e));},za=()=>ht&&!C&&!Ye&&A.some(e=>e.at>zt)&&oe,mr=()=>{let e=A.at(-1);if(!za()||!e)return tt(Ct);let t=a("button",{type:"button",class:"ckw-msgr-preview-x","aria-label":c("Dismiss")},E(y.cross,14));t.addEventListener("click",s=>{s.stopPropagation(),kr(),mr();});let o=a("button",{type:"button",class:"ckw-msgr-preview-card"},a("span",{class:"ckw-msgr-preview-main"},a("span",{class:"ckw-msgr-preview-who"},`${G(e)}${A.length>1?` \xB7 ${$("{n} new",{n:A.length})}`:""}`),a("span",{class:"ckw-msgr-preview-text"},mt(e))));o.addEventListener("click",()=>{xe(e.chat,null),De("messages");}),Ct.replaceChildren(o,t),et(Ct);};Z.addEventListener("click",()=>{if(Le.unlock(),C)return Ee();let e=A.at(-1);e&&xe(e.chat,null),De(e?"messages":"home");}),oe&&H.appendChild(Z);let T=a("div",{class:"ckw-pop ckw-msgr","data-pos":n,role:"dialog","aria-label":i}),Mt=a("div",{class:"ckw-msgr-bar"}),v=a("div",{class:"ckw-pop-body ckw-msgr-body"});T.addEventListener("click",()=>Le.unlock());let de=a("span",{class:"ckw-msgr-lead"}),pe=a("span",{class:"ckw-msgr-mid"}),Re=a("nav",{class:"ckw-msgr-tabs","aria-label":c("Messenger")}),rt=(e,t,o,s,d)=>{let f=a("button",{type:"button",class:"ckw-msgr-tab"},a("span",{class:"ckw-msgr-tab-ic"},E(o,22),ga(s,d,22)),a("span",{},t));return f.addEventListener("click",()=>{Y=null,e==="messages"&&le(),j(e);}),f},ur=rt("home",c("Home"),y.home,dn,pn),At=rt("messages",c("Messages"),y.chat,pa,wa),hr=rt("help",c("Help"),y.help,gn,wn),fr=rt("updates",c("Updates"),y.updates,kn,""),at=a("span",{class:"ckw-msgr-count ckw-msgr-count-tab","aria-hidden":"true"}),Ne=a("button",{type:"button",class:"ckw-msgr-ib","aria-label":c("More"),"aria-haspopup":"menu","aria-expanded":"false"},E(y.dots,18)),br=a("button",{type:"button",class:"ckw-msgr-ib ckw-msgr-x","aria-label":c("Close messenger")},E(y.cross));br.addEventListener("click",()=>Ee()),Mt.append(de,pe,a("span",{class:"ckw-msgr-trail"},Ne,br));let ee=a("div",{class:"ckw-msgr-menu",role:"menu"}),Et=()=>ee.isConnected&&!ee.hasAttribute("data-out"),qe=()=>{Ne.setAttribute("aria-expanded","false"),tt(ee,120);},xr=(e,t,o)=>{let s=a("button",{type:"button",class:"ckw-msgr-menu-i",role:"menuitem"},E(e,15),a("span",{},t));return s.addEventListener("click",d=>{d.stopPropagation(),qe(),o();}),s};Ne.addEventListener("click",e=>{var t;if(e.stopPropagation(),Et())return qe();ee.replaceChildren(a("span",{class:"ckw-msgr-menu-h"},c("Quick actions")),xr(y.minus,c("Minimize chat"),()=>Ee()),xr(je?y.collapse:y.expand,je?c("Collapse view"):c("Expand view"),()=>{je=!je,T.toggleAttribute("data-wide",je);})),Ne.setAttribute("aria-expanded","true"),et(ee,T),(t=ee.querySelector("button"))==null||t.focus();}),T.addEventListener("click",()=>Et()&&qe());let vr=()=>{let e=(o,s)=>{let d=a("button",{type:"button",class:"ckw-msgr-ib","aria-label":s},E(y.back,18));return d.addEventListener("click",o),d};typeof u!="string"?de.replaceChildren(e(()=>j("help"),c("Back to help"))):u==="help"&&Y&&!J.trim()?de.replaceChildren(e(()=>{Y=null,j("help");},c("All collections"))):u==="messages"&&!ie&&M.length>1?de.replaceChildren(e(()=>{le(),j("messages");},c("All conversations"))):u==="messages"?de.replaceChildren(e(()=>j("home"),c("Back to home"))):u==="home"?de.replaceChildren(Ze):de.replaceChildren(),u==="messages"&&ie?pe.replaceChildren(a("b",{},c("Messages"))):u==="messages"?pe.replaceChildren(Xe(),a("span",{class:"ckw-msgr-mid-t"},a("b",{},i),a("span",{class:"ckw-msgr-online"},m))):u==="help"?pe.replaceChildren(a("b",{},!J.trim()&&Y||c("Help"))):u==="updates"?pe.replaceChildren(a("b",{},c("Updates"))):typeof u!="string"?pe.replaceChildren(a("b",{},$a(u.article)||c("Help"))):pe.replaceChildren();let t=[ur,At,...te&&He?[hr]:[],...me&&(ae?ae.length:Pe)?[fr]:[]];(Re.childNodes.length!==t.length||t.some((o,s)=>Re.childNodes[s]!==o))&&Re.replaceChildren(...t),Re.toggleAttribute("data-four",t.length>3),ur.setAttribute("aria-current",u==="home"?"page":"false"),At.setAttribute("aria-current",u==="messages"?"page":"false"),hr.setAttribute("aria-current",u!=="home"&&u!=="messages"&&u!=="updates"?"page":"false"),fr.setAttribute("aria-current",u==="updates"?"page":"false"),A.length&&u!=="messages"?(at.textContent=String(Math.min(A.length,9)),at.isConnected||At.firstChild.appendChild(at)):at.remove();},ge=a("form",{class:"ckw-msgr-compose"}),nt=a("p",{class:"ckw-msgr-error",role:"alert"}),Q=a("input",{class:"ckw-input ckw-msgr-email",type:"email",inputmode:"email",autocomplete:"email",placeholder:c("Email for our reply (optional)"),"aria-label":c("Your email (optional)"),maxlength:"200","data-1p-ignore":"","data-lpignore":"true","data-bwignore":"","data-form-type":"other"}),Se=a("div",{class:"ckw-msgr-box"}),_=a("textarea",{class:"ckw-textarea ckw-msgr-input",rows:"1",placeholder:c("Write your message\u2026"),"aria-label":c("Message"),maxlength:"4000"}),Lt=a("button",{type:"submit",class:"ckw-msgr-send","aria-label":c("Send")},E(y.up)),Tt=cn(),Fe=a("button",{type:"button",class:"ckw-msgr-clip","aria-label":Tt?c("Attach a file or a screenshot"):c("Attach a file"),...Tt?{"aria-haspopup":"menu","aria-expanded":"false"}:{}},E(y.clip,18));Se.append(_,a("div",{class:"ckw-msgr-tools"},Fe,a("span",{class:"ckw-msgr-sp"}),Lt)),Se.addEventListener("click",e=>e.target===Se&&_.focus()),ge.append(Se);let Ce=a("input",{type:"file",accept:Gt.join(","),multiple:"",hidden:"",tabindex:"-1","aria-hidden":"true"});ge.append(Ce);let ot=a("div",{class:"ckw-msgr-files",role:"list","aria-label":c("Files to send")}),U=[],ze=new Map,$t=e=>{var t;return (t=ze.get(e))!=null?t:b().attachmentUrl(e)},yr=e=>{e.ctrl.abort(),[...ze.values()].includes(e.local)||URL.revokeObjectURL(e.local);},Sr=e=>{U=U.filter(t=>t!==e),yr(e);},it=e=>{F="";for(let t of e){let o=t.name||"screenshot.png";if(U.length>=Jt){F=$("Up to {n} files per message.",{n:Jt});break}if(!Gt.includes(t.type)){F=c("Only pictures (PNG, JPEG, WebP, GIF) and PDFs can be sent.");continue}if(t.size>na){F=$("{name} is larger than 10 MB.",{name:o});continue}let s={key:`local-${Date.now().toString(36)}${Math.random().toString(36).slice(2,7)}`,name:o,type:t.type,size:t.size,local:URL.createObjectURL(t),up:Promise.resolve(),ctrl:new AbortController};s.up=b().uploadChatFile(t,s.ctrl.signal).then(d=>{s.id=d.id,R();},d=>{d.name!=="AbortError"&&(Sr(s),F=`${s.name}: ${d.message}`,R());}),U.push(s);}C&&(u!=="messages"||ie)?(yt(),j("messages")):R(),_.focus();},Cr="",Ma=()=>{let e=U.map(t=>`${t.key}:${t.id?1:0}`).join(",");e!==Cr&&(Cr=e,ot.replaceChildren(...U.map(t=>{let o=a("button",{type:"button",class:"ckw-msgr-file-x","aria-label":$("Remove {name}",{name:t.name})},E(y.cross,12));o.addEventListener("click",()=>{Sr(t),R(),_.focus();});let s=t.type.startsWith("image/")?a("img",{src:t.local,alt:""}):a("span",{class:"ckw-msgr-file-doc"},E(y.doc,18),a("span",{},t.name));return a("div",{class:"ckw-msgr-file",role:"listitem",title:t.name,"aria-label":t.id?t.name:$("{name}, uploading",{name:t.name}),...t.id?{}:{"aria-busy":"true"}},s,o)}))),U.length?ot.isConnected||ge.insertBefore(ot,Se):ot.remove();},Aa=async()=>{var s;let e;try{e=await navigator.mediaDevices.getDisplayMedia({video:{displaySurface:"browser"},audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include"});}catch(d){d.name!=="NotAllowedError"&&d.name!=="AbortError"&&(F=c("The screenshot did not work here. Attach a picture instead."),R());return}H.style.visibility="hidden";let t=null;try{let d=document.createElement("video");d.muted=!0,d.playsInline=!0,d.srcObject=e,await d.play(),await new Promise(k=>setTimeout(k,300));let f=d;await new Promise(k=>f.requestVideoFrameCallback?f.requestVideoFrameCallback(()=>k()):requestAnimationFrame(()=>k()));let g=document.createElement("canvas");g.width=d.videoWidth,g.height=d.videoHeight,(s=g.getContext("2d"))==null||s.drawImage(d,0,0);let p=(k,x)=>new Promise(S=>g.toBlob(S,k,x));t=await p("image/png"),t&&t.size>4.5*1024*1024&&(t=await p("image/jpeg",.9));}catch(d){t=null;}finally{for(let d of e.getTracks())d.stop();H.style.visibility="";}if(!t||!t.size)return F=c("The screenshot did not work here. Attach a picture instead."),R();let o=new Date().toISOString().slice(0,16).replace(/[:T]/g,"-");it([Object.assign(t,{name:`screenshot-${o}.${t.type==="image/png"?"png":"jpg"}`})]);},Me=a("div",{class:"ckw-msgr-menu ckw-msgr-amenu",role:"menu"}),Ht=()=>Me.isConnected&&!Me.hasAttribute("data-out"),st=()=>{Fe.setAttribute("aria-expanded","false"),tt(Me,120);},zr=(e,t,o)=>{let s=a("button",{type:"button",class:"ckw-msgr-menu-i",role:"menuitem"},E(e,15),a("span",{},t));return s.addEventListener("click",d=>{d.stopPropagation(),st(),o();}),s};Fe.addEventListener("click",e=>{var t;if(e.stopPropagation(),Le.unlock(),!Tt)return Ce.click();if(Ht())return st();Me.replaceChildren(zr(y.image,c("Photo or file"),()=>Ce.click()),zr(y.screen,c("Screenshot of this page"),()=>{Aa();})),Fe.setAttribute("aria-expanded","true"),et(Me,ge),(t=Me.querySelector("button"))==null||t.focus();}),Ce.addEventListener("change",()=>{var e;it([...(e=Ce.files)!=null?e:[]]),Ce.value="";});let Ea=a("a",{class:"ckw-msgr-powered",href:oa,target:"_blank",rel:"noopener"},c("Powered by {brand}").split("{brand}")[0],a("b",{},"MRRocket"),c("Powered by {brand}").split("{brand}")[1]),Pt=a("ol",{class:"ckw-msgs","aria-live":"polite","aria-label":c("Messages")}),Mr=()=>{var e;return h&&!((e=r.user())!=null&&e.email)&&!tr},jt=()=>!Q.value.trim()||tn.test(Q.value.trim()),It=()=>(!!_.value.trim()||U.length>0)&&jt(),j=e=>{let t=JSON.stringify(e)!==JSON.stringify(u);u=e,pt=-1,R(),t&&St(v,"ckw-msgr-enter"),e==="messages"?(vt(),ye(),_.focus()):e==="help"&&Y===null&&Ot.focus(),ne(0);},La=(e,t)=>{let o=a("img",{src:e,alt:t,loading:"lazy"});return o.addEventListener("load",()=>{v.scrollHeight-v.scrollTop-v.clientHeight<o.clientHeight+120&&(v.scrollTop=v.scrollHeight);}),o},Ar=(e,t=false)=>{var d,f,g;let o=t&&Date.now()-Date.parse(e.at)>=Zt,s=a("li",{class:"ckw-msg","data-from":e.from==="visitor"?"me":"them"},e.body||!((d=e.attachments)!=null&&d.length)?a("div",{class:"ckw-bubble"},e.body):null);t&&s.setAttribute("aria-busy","true"),(f=e.attachments)!=null&&f.length&&s.append(a("div",{class:"ckw-msg-files"},...e.attachments.map(p=>p.type.startsWith("image/")?a("a",{class:"ckw-msg-img",href:$t(p.id),target:"_blank",rel:"noopener",title:p.name},La($t(p.id),p.name)):a("a",{class:"ckw-msgr-cite",href:$t(p.id),target:"_blank",rel:"noopener"},E(y.doc,14),a("span",{},p.name)))));for(let p of (g=e.articles)!=null?g:[]){let k=a("button",{type:"button",class:"ckw-msgr-cite"},E(y.doc,14),a("span",{},p.title));k.addEventListener("click",()=>j({article:p.id})),s.append(k);}return s.append(a("span",{class:"ckw-msg-meta"},e.from==="ai"?ya():null,`${e.from!=="visitor"?`${G(e)} \xB7 `:""}${o?c("Sending\u2026"):kt(e.at)}`)),s},Ta=e=>{let t=a("button",{type:"button",class:"ckw-msgr-art"},a("span",{class:"ckw-msgr-art-t"},e.title),E(y.next,14));return t.addEventListener("click",()=>j({article:e.id})),t},Er=(e,t,o,s)=>{let d=a("button",{type:"button",class:"ckw-msgr-card ckw-msgr-hrow"},a("span",{class:"ckw-msgr-card-main"},a("b",{},e),t?a("span",{class:"ckw-msgr-hrow-sub"},t):null,o?a("span",{class:"ckw-msgr-card-meta"},o):null),E(y.next,16));return d.addEventListener("click",s),d},$a=e=>{var t;return (V==null?void 0:V.id)===e&&V.collection||((t=[...I!=null?I:[],...ce].find(o=>o.id===e))==null?void 0:t.collection)||""},_t=((e=c("Search for help"))=>{let t=a("label",{class:"ckw-msgr-search"}),o=a("input",{class:"ckw-msgr-search-in",type:"search",placeholder:e,"aria-label":c("Search for help"),maxlength:"200"});o.value=J;let s;return o.addEventListener("input",()=>{J=o.value,clearTimeout(s),s=setTimeout(()=>{if(u!=="help")return j("help");Nt(true);},250);}),o.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),u!=="help"&&j("help"));}),t.append(E(y.search,16),o),t})(c("Search our help center\u2026")),Ot=_t.querySelector("input"),Rt=false,ct=()=>{yt(),j("messages");},Nt=async(e=false)=>{if(!te||Rt&&!e)return;Rt=true;let t=J.trim();try{let o=await b().articles(t||void 0);if(t!==J.trim())return;I=o.articles,t||(ce=o.articles,He=o.articles.length>0,sr());}catch(o){I=I!=null?I:[];}finally{Rt=false;}R();},Ha=async()=>{try{ae=(await b().changelog()).entries.slice(0,Va),Pe=ae.length>0,sr();}catch(e){ae=[];}be=null,R();},qt=a("form",{class:"ckw-msgr-askq"}),Ae=a("input",{class:"ckw-msgr-askq-in",placeholder:c("Ask a question"),"aria-label":c("Ask a question"),maxlength:"4000",autocomplete:"off"}),Ft=a("button",{type:"submit",class:"ckw-msgr-send","aria-label":c("Send"),disabled:""},E(y.up));qt.append(Ae,Ft),Ae.addEventListener("input",()=>Ft.disabled=!Ae.value.trim()),qt.addEventListener("submit",e=>{if(e.preventDefault(),!Ae.value.trim())return le(),j("messages");_.value=Ae.value,Ae.value="",Ft.disabled=true,yt(),j("messages"),It()&&Kt();});let lt=(e,t=false)=>a("div",{class:"ckw-msgr-shapes","aria-hidden":"true"},...Array.from({length:e},()=>a("div",{class:t?"ckw-msgr-card ckw-msgr-recent":"ckw-msgr-shape"},a("span",{class:"ckw-msgr-recent-row"},t?a("span",{class:"ckw-msgr-av ckw-msgr-av-sm ckw-msgr-sk"}):null,a("span",{class:"ckw-msgr-card-main"},a("span",{class:"ckw-msgr-sk"}),a("span",{class:"ckw-msgr-sk"})))))),Lr=e=>(e.isConnected&&e.setAttribute("data-still",""),e),Pa=lt(1,true),ja=lt(3),dt=null,Tr=e=>{let t=e.last,o=dr(e.id),s=e.status==="solved"?` \xB7 ${c("Closed")}`:"",d=a("button",{type:"button",class:"ckw-msgr-card ckw-msgr-recent","aria-label":`${$("Conversation: {subject}",{subject:e.subject})}${s}${o?`, ${$("{n} new",{n:o})}`:""}`},a("span",{class:"ckw-msgr-recent-row"},Xe(),a("span",{class:"ckw-msgr-card-main"},a("span",{class:"ckw-msgr-card-sub ckw-msgr-recent-text"},e.subject),t&&mt(t)!==e.subject?a("span",{class:"ckw-msgr-card-sub"},mt(t)):null,t?a("span",{class:"ckw-msgr-card-meta"},`${G(t)} \xB7 ${kt(t.at)}${s}`):null),o?a("span",{class:"ckw-msgr-badge"},String(o)):E(y.next,14)));return d.addEventListener("click",()=>{xe(e.id,null),j("messages");}),d},Ut=a("div",{class:"ckw-msgr-chats"}),$r=a("button",{type:"button",class:"ckw-btn ckw-btn-primary ckw-msgr-new"},E(y.chat),c("New conversation"));$r.addEventListener("click",ct);let Hr="",Ia=()=>{let e=`${M.map(t=>{var o;return `${t.id}:${t.status}:${(o=t.last)==null?void 0:o.id}:${dr(t.id)}`}).join()}|${Math.floor(Date.now()/6e4)}`;e!==Hr&&(Hr=e,Ut.replaceChildren(...M.map(Tr))),v.childNodes[0]!==Ut&&v.replaceChildren(Ut,$r);},_a=()=>{var x,S,N;let e=(S=(x=r.user())==null?void 0:x.name)==null?void 0:S.trim().split(/\s+/)[0],t=(r.greeting?w.replace(/^(hi|hello|hey|hallo|moin|servus|bonjour|salut|hola|ciao|salve|hoi|ol[áa]|cze[śs][ćc]|hej|こんにちは)( there)?\s*[!,.!、。]*\s*/i,"").trim():c("How can we help?"))||c("How can we help you today?"),s=[a("h2",{class:"ckw-msgr-hero ckw-msgr-hello"},a("span",{},`${e?$("Hi, {name}",{name:e}):c("Hi there")} `,a("span",{class:"ckw-msgr-wave","aria-hidden":"true"},"\u{1F44B}")),a("span",{class:"ckw-msgr-hello-sub"},t)),qt],d=new Set,f=(O,q)=>(d.add(q),dt&&!dt.has(q)&&O.setAttribute("data-arrive",""),O),g=M.filter(O=>O.status!=="solved"),p=(g.length?g:M).slice(0,2);if(s.push(...p.map(O=>f(Tr(O),O.id))),!p.length&&!$e&&fe<3&&((N=r.user())!=null&&N.id)&&s.push(Lr(Pa)),M.length>p.length){let O=a("button",{type:"button",class:"ckw-msgr-all"},$("All conversations ({n})",{n:M.length}),E(y.next,14));O.addEventListener("click",()=>{le(),j("messages");}),s.push(O);}let k=te?ce.slice(0,3):[];k.length&&s.push(f(a("div",{class:"ckw-msgr-card ckw-msgr-card-col"},...k.map(Ta)),"help")),dt=d,v.replaceChildren(...s);},Oa=()=>{var f,g;Ot.value!==J&&(Ot.value=J);let e=J.trim(),t=I!=null?I:[],o=new Map;for(let p of t)o.set(p.collection,[...(f=o.get(p.collection))!=null?f:[],p]);let s=!e&&Y!==null?(g=o.get(Y))!=null?g:[]:null,d=[];if(I===null)d.push(Lr(ja));else if(t.length)e||s?d.push(...e?[a("p",{class:"ckw-msgr-help-h"},c("Search results"))]:[],a("div",{class:"ckw-msgr-hlist"},...(s!=null?s:t).map(p=>Er(p.title,p.excerpt.startsWith(p.title)?p.excerpt.slice(p.title.length).trim():p.excerpt,e?p.collection:"",()=>j({article:p.id}))))):d.push(a("div",{class:"ckw-msgr-hlist"},...[...o].map(([p,k])=>Er(p,k.slice(0,3).map(x=>x.title).join(", "),k.length===1?c("1 article"):$("{n} articles",{n:k.length}),()=>{Y=p,j("help"),St(v,"ckw-msgr-enter");}))));else {let p=a("button",{type:"button",class:"ckw-btn ckw-btn-primary"},c("Send us a message"));p.addEventListener("click",ct),d.push(a("div",{class:"ckw-msgr-empty"},a("p",{},e?$("Nothing found for \u201C{q}\u201D.",{q:e}):c("No help articles yet.")),p));}if(v.firstChild!==_t)v.replaceChildren(_t,...d);else {for(;v.childNodes.length>1;)v.lastChild.remove();v.append(...d);}},Ra=()=>{be!=null||(be=ae?ae.length?a("div",{class:"ckw-msgr-updates"},...ae.map(e=>a("article",{class:"ckw-msgr-update"},a("p",{class:"ckw-msgr-doc-c"},kt(e.publishedAt)),a("h2",{class:"ckw-msgr-update-t"},e.title),e.body?a("p",{class:"ckw-msgr-update-b"},e.body):null))):a("div",{class:"ckw-msgr-empty"},a("p",{},c("No updates yet."))):lt(3)),(v.firstChild!==be||v.childNodes.length!==1)&&v.replaceChildren(be);},V=null,Na=e=>{if((V==null?void 0:V.id)===e)return v.replaceChildren(V.node);let t=a("article",{class:"ckw-msgr-doc"},lt(4)),o={id:e,node:t};V=o,v.replaceChildren(t),b().article(e,void 0,mn).then(s=>{o.collection=s.collection,V===o&&vr();let d=a("div",{class:"ckw-msgr-rate"}),f=()=>{if(xt.has(e))return d.replaceChildren(a("span",{},c("Thanks for letting us know.")));let x=a("button",{type:"button",class:"ckw-btn"},c("Yes")),S=a("button",{type:"button",class:"ckw-btn"},c("No")),N=O=>{xt=new Set(xt).add(e),f(),b().rateArticle(e,O).catch(()=>{}),O||ct();};x.addEventListener("click",()=>N(true)),S.addEventListener("click",()=>N(false)),d.replaceChildren(a("span",{},c("Did this answer your question?")),a("span",{class:"ckw-msgr-rate-b"},x,S));};f();let g=a("button",{type:"button",class:"ckw-btn ckw-msgr-ask"},E(y.chat),c("Still need help? Send us a message"));g.addEventListener("click",ct);let p=s.blocks[0],k=p&&(p.type==="h2"||p.type==="h3")&&ka(p.spans)===ka([{text:s.title}])?s.blocks.slice(1):s.blocks;t.replaceChildren(a("h2",{class:"ckw-msgr-doc-t"},s.title),a("p",{class:"ckw-msgr-doc-c"},$("Updated {when}",{when:kt(s.updatedAt)})),a("div",{class:"ckw-msgr-doc-b"},...k.map(un)),d,g);}).catch(s=>{V=null,t.replaceChildren(a("p",{class:"ckw-msgr-error"},s.message));});},pt=-1,Dt="",Ue=-1,Bt=a("div",{class:"ckw-msgr-sugg"}),qa=()=>re.filter(e=>e.draft===X&&e.chat===P),Fa=()=>{var f,g,p,k;let e=X===null?D:null,t=(f=e==null?void 0:e.messages)!=null?f:[],o=qa(),s=[];{let x=o.map(q=>q.message),S=!!((g=e==null?void 0:e.conversation)!=null&&g.typing)&&!x.length&&((p=t[t.length-1])==null?void 0:p.from)==="visitor",N=`${S}|${t.map(q=>q.id).join(",")}|${x.map(q=>`${q.id}:${Date.now()-Date.parse(q.at)>=Zt}`).join(",")}|${Math.floor(Date.now()/6e4)}`;if(N!==Dt){Dt=N;let q=t.length||x.length||P?[]:[a("li",{class:"ckw-msg","data-from":"them"},a("div",{class:"ckw-bubble"},w))],gt=S?[a("li",{class:"ckw-msg","data-from":"them"},a("div",{class:"ckw-bubble ckw-typing",role:"status","aria-label":c("Typing\u2026")},a("span"),a("span"),a("span")))]:[],Wt=[...q,...t.map(Be=>Ar(Be)),...x.map(Be=>Ar(Be,true)),...gt];Ue>=0&&Wt.slice(Ue).forEach(Be=>Be.setAttribute("data-new","")),Ue=Wt.length,Pt.replaceChildren(...Wt);}s.push(Pt);let O=!t.some(q=>q.from==="visitor")&&!o.length&&!P?(I!=null?I:[]).slice(0,3):[];O.length&&(Bt.childNodes.length!==O.length&&Bt.replaceChildren(...O.map(q=>{let gt=a("button",{type:"button",class:"ckw-msgr-sugg-b"},q.title);return gt.addEventListener("click",()=>j({article:q.id})),gt})),s.push(Bt));}((k=e==null?void 0:e.conversation)==null?void 0:k.status)==="solved"&&!o.length&&s.push(a("p",{class:"ckw-fine ckw-msgr-note"},c("This conversation is closed. Write to start a new one."))),(v.childNodes.length!==s.length||s.some((x,S)=>v.childNodes[S]!==x))&&v.replaceChildren(...s);let d=t.length+o.length+(Pt.querySelector(".ckw-typing")?1:0);d!==pt&&(pt=d,v.scrollTop=v.scrollHeight),nt.textContent=F,F&&!nt.isConnected?ge.prepend(nt):F||nt.remove(),Mr()?(jt()?Q.removeAttribute("aria-invalid"):Q.setAttribute("aria-invalid","true"),Q.isConnected||Se.insertBefore(Q,_)):Q.remove(),Ma(),Lt.disabled=!It();},R=()=>{if(!C)return;T.dataset.view=typeof u=="string"?u:"article",Y!==null&&He!==null&&!ce.some(t=>t.collection===Y)&&(Y=null),vr(),u==="home"?_a():u==="messages"?(ie?Ia:Fa)():u==="help"?Oa():u==="updates"?Ra():Na(u.article);let e=u==="home"?[Sa,Mt,v]:[Mt,v];e.push(u==="messages"&&!ie?ge:Re),r.branding!==false&&e.push(Ea),ee.isConnected&&e.push(ee),(T.childNodes.length!==e.length||e.some((t,o)=>T.childNodes[o]!==t))&&T.replaceChildren(...e);},Pr=async()=>{if(L)return;let e=L=new AbortController,t=r.distinctId(),o=false,s=setTimeout(()=>{o=true,e.abort();},Math.min(Qa*2**fe,Xt)),d;try{gr(await b().chat(e.signal,P!=null?P:void 0)),F="",Ge=!1,fe=0,va(t);}catch(f){if(f.name==="AbortError"&&!o)return;let g=f.status;Ge=g===401||g===403,g===404&&P?le():C&&u==="messages"&&!o&&(F=ar(f)),(o||g===void 0||g>=500)&&(fe+=1,d=o?0:Math.min(1e3*2**(fe-1),Xt));}finally{clearTimeout(s),L===e&&(L=null);}!$e&&d===void 0&&(Ue=-1,u==="messages"&&P===null&&X===null&&!_.value.trim()&&!re.length&&!U.length&&le(),$e=true),R(),ye(),ne(C&&document.visibilityState!=="hidden"?d:void 0);},Ua=()=>{var t,o;let e=r.distinctId();e===Je&&!Ge||(e!==Je&&(or&&!((t=r.user())!=null&&t.id)&&Ie&&ut(_e,null),Je=e,L==null||L.abort(),L=null,A=[],$e=false,fe=0,ir()),or=(o=r.user())==null?void 0:o.id,R(),ye(),ne(0));};function ne(e){var p;clearTimeout(Ve);let t=M.filter(k=>k.status!=="solved"),o=t.length>0,s=t.some(k=>k.last&&Date.now()-new Date(k.last.at).getTime()<en),d=e===void 0&&!C&&!o,f=Qe()&&!!((p=D==null?void 0:D.conversation)!=null&&p.typing),g=e!=null?e:document.visibilityState==="hidden"?0:f?Ja:Qe()?Ga:o&&s?Xa:d?Za:Xt;(g||e===0)&&(Ve=setTimeout(()=>{var k;return d&&(Ge||!((k=r.user())!=null&&k.id||M.length))?ne():void Pr()},g));}let jr=()=>{document.visibilityState==="visible"?ne(0):clearTimeout(Ve);};document.addEventListener("visibilitychange",jr);let Da=async()=>{var e,t;if(!ft){for(ft=true;re.length;){let o=re[0],{message:s,files:d,email:f}=o;await Promise.all(d.map(p=>p.up));let g=d.filter(p=>p.id).map(p=>p.id);try{if(!s.body&&!g.length)throw new Error(F||c("The file could not be sent."));let p=await b().sendChat({body:s.body,...o.draft!==null?{conversation:"new"}:o.chat?{conversation:o.chat}:{},email:f,url:window.location.href.slice(0,500),...g.length?{attachments:g}:{},context:{viewport:`${window.innerWidth}\xD7${window.innerHeight}`}});L==null||L.abort(),L=null;let k=(t=(e=p.conversation)==null?void 0:e.id)!=null?t:null;if(k){let x=re.slice(1).filter(S=>S.draft===o.draft&&S.chat===o.chat);o.draft===X&&o.chat===P&&(X=null,P=k);for(let S of x)S.draft=null,S.chat=k;}gr(p),re.shift();for(let x of d)ze.delete(x.key),URL.revokeObjectURL(x.local);}catch(p){let k=re.splice(0),x=p.status===404;xe(x?null:k[0].chat,x?++rr:k[0].draft),_.value=[...k.map(S=>S.message.body),_.value.trim()].filter(Boolean).join(`
|
|
642
|
+
`),U=[...k.flatMap(S=>S.files.filter(N=>N.id)),...U];for(let S of k)for(let N of S.files)ze.delete(N.key);F=x?c("This conversation is no longer available. Your message is still here to send as a new one."):ar(p);}R();}ft=false,ne();}},Kt=()=>{let e=_.value.trim(),t=U;if(!(!e&&!t.length||!jt())){Le.unlock();for(let o of t)ze.set(o.key,o.local);re.push({message:{id:`pending-${++xa}`,from:"visitor",body:e,at:new Date().toISOString(),...t.length?{attachments:t.map(o=>({id:o.key,name:o.name,type:o.type,size:o.size}))}:{}},files:t,email:Mr()&&Q.value.trim()?Q.value.trim():void 0,chat:P,draft:X}),_.value="",U=[],F="",R(),setTimeout(R,Zt+50),Da();}};ge.addEventListener("submit",e=>{e.preventDefault(),Kt();}),_.addEventListener("keydown",e=>{e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),Kt());}),_.addEventListener("input",()=>Lt.disabled=!It()),_.addEventListener("paste",e=>{var o,s;let t=[...(s=(o=e.clipboardData)==null?void 0:o.files)!=null?s:[]];t.length&&(e.preventDefault(),it(t));});let Ir=e=>!!e.dataTransfer&&[...e.dataTransfer.types].includes("Files");T.addEventListener("dragover",e=>{Ir(e)&&(e.preventDefault(),T.setAttribute("data-drop",""));}),T.addEventListener("dragleave",e=>{(!e.relatedTarget||!T.contains(e.relatedTarget))&&T.removeAttribute("data-drop");}),T.addEventListener("drop",e=>{var t,o;Ir(e)&&(e.preventDefault(),T.removeAttribute("data-drop"),it([...(o=(t=e.dataTransfer)==null?void 0:t.files)!=null?o:[]]));}),Q.addEventListener("input",()=>R());function De(e="home",t=false){let o=C;C=true,u=e==="help"&&!te||e==="updates"&&!me?"home":e,pt=-1,kr(),dt=null,T.toggleAttribute("data-still",t),et(T),o&&St(v,"ckw-msgr-enter"),(I===null||He===null||u==="help"&&J)&&Nt(),R(),ye(),u==="messages"&&(vt(),_.focus()),ne(0);}function Ee(){if(!C)return;C=false,ee.isConnected&&qe(),tt(T,200),ye(),ne(),oe&&Z.focus();let e=ue;ue=null,e&&setTimeout(e,220);}T.addEventListener("click",()=>Ht()&&st());let _r=e=>{e.key!=="Escape"||!C||(Ht()?(st(),Fe.focus()):Et()?(qe(),Ne.focus()):Ee());};return document.addEventListener("keydown",_r),Pr(),te&&Nt(),me&&Ha(),ye(),r.opened&&De(r.opened,true),{open:e=>{e==="messages"&&le(),De(e!=null?e:"home");},close:Ee,toggle:()=>C?Ee():De(),refresh:Ua,isOpen:()=>C,onClose:e=>{ue=e;},destroy:()=>{clearTimeout(Ve);for(let e of ve.values())clearTimeout(e);L==null||L.abort();for(let e of U)yr(e);for(let e of ze.values())URL.revokeObjectURL(e);document.removeEventListener("keydown",_r),document.removeEventListener("visibilitychange",jr),H.remove();}}};window.__mrrocketMessenger={mountMessenger:ba};})();
|