{"version":3,"file":"widget_boot-CG7cuUAT.js","sources":["../../../app/frontend/javascript/widget/icons.js","../../../app/frontend/javascript/widget/template.js","../../../app/frontend/javascript/widget/index.js","../../../app/frontend/entrypoints/widget_boot.js"],"sourcesContent":["const iconBackgroundColor = '#5796C7'\nconst iconContentColor = '#ffffff'\n\nexport const hideIcon =\n `\n \n \n `\n\nexport const openIcon =\n `\n \n \n \n `\n","const html = (strings, ...keys) => {\n return (values) => {\n // Replace placeholders with values from the passed object\n const result = strings.map((str, i) => {\n const key = keys[i]\n return str + (values[key] || '')\n }).join('')\n return result\n }\n}\n\nexport const widgetTemplate = html`\n \n
\n ${'icon'}\n
\n
\n
\n
\n

Loading...

\n
\n \n
\n
\n \n \n \n
\n `\n","import styles from '~js/widget/styles.css?inline'\nimport { openIcon, hideIcon } from '~js/widget/icons'\nimport { widgetTemplate } from './template'\n\nexport default class Widget extends HTMLElement {\n static defaultConfiguration = {}\n\n bootstrap = false\n open = false\n\n rootUrl = null\n primaryColor = null\n\n configuration = {}\n\n set configuration(configuration) {\n this.configuration = Object.assign({}, Widget.defaultConfiguration, configuration)\n }\n\n get frameWindow() { return this.frameTarget.contentWindow }\n get frameTarget() { return this.shadowRoot.getElementById('upthread-widget-frame') }\n get actionTarget() { return this.shadowRoot.getElementById('upthread-widget-action') }\n get closeTarget() { return this.shadowRoot.getElementById('upthread-widget-close') }\n get loaderTarget() { return this.shadowRoot.getElementById('upthread-widget-loader') }\n get containerTarget() { return this.shadowRoot.getElementById('upthread-widget-container') }\n get authToken() { return (this.configuration.authToken || localStorage.getItem(`${this.widgetToken}-upthread-auth-token`)) }\n get widgetToken() { return this.configuration.token }\n get widgetMethods() { return ['startWorkflow', 'openWidget'] }\n get rootURL() { return this.enrichURL(this.rootUrl) }\n\n constructor() {\n super()\n this.css = new CSSStyleSheet()\n this.css.replaceSync(styles)\n this.attachShadow({ mode: 'open', delegatesFocus: true })\n this.shadowRoot.adoptedStyleSheets = [this.css]\n }\n\n async connectedCallback() {\n const response = await this.fetchConfiguration()\n\n this.rootUrl = response.root_url\n this.primaryColor = response.primary_color\n\n this.css.insertRule(`:host { --primary-color: ${this.primaryColor} }`)\n this.shadowRoot.innerHTML = widgetTemplate({ icon: openIcon })\n\n if (this.authToken) {\n this.bootstrapFrame()\n }\n\n window.addEventListener('message', this.handleMessage.bind(this), false)\n document.addEventListener('click', this.handleExternalEvent.bind(this))\n this.actionTarget.addEventListener('click', this.handleButtonClick.bind(this))\n this.closeTarget.addEventListener('click', this.handleCloseClick.bind(this))\n }\n\n async fetchConfiguration() {\n const params = new URLSearchParams({\n time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone\n })\n const response = await fetch(`${window.location.protocol}//${import.meta.env.VITE_UPTHREAD_HOST}/widget.json?${params}`, {\n headers: {\n Accept: 'application/json',\n Authorization: `Bearer ${this.authToken}`,\n 'X-Widget-Token': this.widgetToken,\n }\n })\n\n return await response.json()\n }\n\n enrichURL(url) {\n const enrichedUrl = new URL(url)\n enrichedUrl.searchParams.append('widget_token', this.widgetToken)\n enrichedUrl.searchParams.append('auth_token', this.authToken)\n return enrichedUrl\n }\n\n bootstrapFrame(urlAsString) {\n this.frameTarget.src = urlAsString || this.rootURL.toString()\n }\n\n handleMessage(event) {\n const { message, payload } = event.data\n\n if (message === 'onFrameLoaded') {\n this.onFrameLoaded(payload)\n } else if (message === 'notification') {\n this.shadowRoot.querySelector('.badge').style.display = 'block'\n } else if (message === 'localStore') {\n localStorage.setItem(payload.key, payload.value)\n }\n }\n\n handleExternalEvent(event) {\n const target = event.target.closest('a')\n\n if (!target) { return }\n\n const href = target.getAttribute('href')\n\n if (href.includes('#upthread#')) {\n event.preventDefault()\n\n const [method, params] = href.split('#').filter(str => str !== 'upthread' && str !== '')\n\n const rootUrl = this.rootURL\n\n if (this.widgetMethods.includes(method)) {\n if (method === 'startWorkflow') {\n\n if (params.length > 0) {\n const paramPairs = params.split('&')\n\n const urlParams = new URLSearchParams(rootUrl.search)\n\n paramPairs.forEach(param => {\n const [key, value] = param.split('=')\n if (key && value) {\n urlParams.append(key, value)\n }\n })\n\n rootUrl.search = urlParams.toString()\n }\n }\n\n this.openWidget(rootUrl.toString())\n }\n } else {\n if (!target.dataset.turboAction) {\n target.dataset.turboAction = 'advance'\n }\n }\n }\n\n handleButtonClick(event) {\n event.preventDefault()\n this.toggleWidget()\n }\n\n handleCloseClick(event) {\n event.preventDefault()\n this.hideWidget()\n }\n\n onFrameLoaded() {\n this.showFrame()\n this.hideLoader()\n this.bootstrap = true\n }\n\n showFrame() {\n this.frameTarget.style.display = 'block'\n }\n\n hideLoader() {\n this.loaderTarget.style.display = 'none'\n }\n\n showContainer() {\n this.containerTarget.style.display = 'block'\n }\n\n hideContainer() {\n this.containerTarget.style.display = 'none'\n }\n\n openWidget(UrlAsString) {\n if (this.bootstrap == false) {\n this.bootstrapFrame(UrlAsString)\n } else {\n this.visit(UrlAsString)\n }\n\n this.open = true\n this.showContainer()\n this.actionTarget.innerHTML = hideIcon\n document.querySelector('html').classList.add('upthread-widget-open')\n this.closeTarget.classList.add('active')\n }\n\n visit(url) {\n this.frameWindow.postMessage({ message: 'visit', payload: { url: url } }, '*')\n }\n\n hideWidget() {\n this.open = false\n this.hideContainer()\n this.actionTarget.innerHTML = openIcon\n document.querySelector('html').classList.remove('upthread-widget-open')\n this.closeTarget.classList.remove('active')\n }\n\n toggleWidget() {\n if (this.open) { this.hideWidget() } else { this.openWidget() }\n }\n}\n\ncustomElements.define('upthread-widget', Widget)\n","import '~js/widget'\n\n(() => {\n const globalAction = () => {\n const initAction = window[window['upthread']]\n if (!initAction) { return }\n const queue = initAction.q\n const globalStyle = `\n \n `\n document.head.insertAdjacentHTML('beforeend', globalStyle)\n if (queue) {\n if (queue[0] && queue[0][0] === 'init') {\n let configuration = queue[0][1]\n let widget = document.createElement('upthread-widget')\n widget.configuration = configuration\n document.body.appendChild(widget)\n }\n }\n }\n globalAction()\n})()\n"],"names":["iconBackgroundColor","iconContentColor","hideIcon","openIcon","html","strings","keys","values","str","i","key","widgetTemplate","_Widget","__publicField","styles","configuration","response","params","url","enrichedUrl","urlAsString","event","message","payload","target","href","method","rootUrl","paramPairs","urlParams","param","value","UrlAsString","Widget","initAction","queue","widget"],"mappings":"+0DAAMA,EAAsB,UACtBC,EAAmB,UAEZC,EACX;AAAA,2CACyCF,CAAmB;AAAA,kBAC5CC,CAAgB;AAAA,UAGrBE,EACX;AAAA,2CACyCH,CAAmB;AAAA,kBAC5CC,CAAgB;AAAA,kBAChBA,CAAgB;AAAA,UCb5BG,EAAO,CAACC,KAAYC,IAChBC,GAESF,EAAQ,IAAI,CAACG,EAAKC,IAAM,CACrC,MAAMC,EAAMJ,EAAKG,CAAC,EAClB,OAAOD,GAAOD,EAAOG,CAAG,GAAK,GACnC,CAAK,EAAE,KAAK,EAAE,EAKDC,EAAiBP;AAAA;AAAA;AAAA,MAGxB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,ICVSQ,EAArB,MAAqBA,UAAe,WAAY,CA0B9C,aAAc,CACN,MAAA,EAxBRC,EAAA,iBAAY,IACZA,EAAA,YAAO,IAEPA,EAAA,eAAU,MACVA,EAAA,oBAAe,MAEfA,EAAA,qBAAgB,CAAC,GAmBV,KAAA,IAAM,IAAI,cACV,KAAA,IAAI,YAAYC,CAAM,EAC3B,KAAK,aAAa,CAAE,KAAM,OAAQ,eAAgB,GAAM,EACxD,KAAK,WAAW,mBAAqB,CAAC,KAAK,GAAG,CAAA,CApBhD,IAAI,cAAcC,EAAe,CAC/B,KAAK,cAAgB,OAAO,OAAO,CAAA,EAAIH,EAAO,qBAAsBG,CAAa,CAAA,CAGnF,IAAI,aAAc,CAAE,OAAO,KAAK,YAAY,aAAA,CAC5C,IAAI,aAAc,CAAS,OAAA,KAAK,WAAW,eAAe,uBAAuB,CAAA,CACjF,IAAI,cAAe,CAAS,OAAA,KAAK,WAAW,eAAe,wBAAwB,C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