{"version":3,"sources":["webpack://remark42/./app/common/constants.config.ts","webpack://remark42/./app/embed.ts"],"names":["BASE_URL","window","remark_config","host","removeDomNode","node","parentNode","removeChild","createFrame","query","height","margin","__colors__","iframe","document","createElement","src","name","JSON","stringify","setAttribute","init","REMARK42","createInstance","dispatchEvent","Event","config","root","getElementById","Error","site_id","initDataAnimationTimeout","titleObserver","url","location","origin","pathname","split","Object","keys","filter","key","map","encodeURIComponent","join","firstElementChild","appendChild","addEventListener","receiveMessages","postHashToIframe","postClickOutsideToIframe","titleElement","querySelector","MutationObserver","mutations","postTitleToIframe","target","textContent","observe","subtree","characterData","childList","remarkRootId","userInfo","back","closeEl","style","user","this","animationStop","innerHTML","id","onclick","close","queryUserInfo","picture","isDefaultPicture","body","onKeyDown","setTimeout","focus","onAnimationClose","removeAttribute","removeEventListener","delay","events","prefix","el","forEach","event","e","keyCode","t","clearTimeout","remove","data","parse","remarkIframeHeight","scrollTo","pageXOffset","getBoundingClientRect","top","pageYOffset","prototype","hasOwnProperty","call","isUserInfoShown","inited","title","hash","newURL","indexOf","preventDefault","contentWindow","postMessage","contains","clickOutside","changeTheme","theme","destroy","disconnect","readyState"],"mappings":"mBAAO,MAAMA,EAAWC,OAAOC,cAAcC,MAAQ,mBCSrD,SAASC,EAAcC,GACjBA,GAAQA,EAAKC,YACfD,EAAKC,WAAWC,YAAYF,GAIhC,SAASG,GAAY,KACnBL,EADmB,MAEnBM,EAFmB,OAGnBC,EAHmB,OAInBC,EAAS,OAJU,WAKnBC,EAAa,KAQb,MAAMC,EAASC,SAASC,cAAc,UAqBtC,OAnBAF,EAAOG,IAAM,GAAGb,qBAAwBM,IACxCI,EAAOI,KAAOC,KAAKC,UAAU,CAAEP,eAC/BC,EAAOO,aAAa,QAAS,QAC7BP,EAAOO,aAAa,cAAe,KACnCP,EAAOO,aAAa,oBAAqB,QACzCP,EAAOO,aAAa,YAAa,MACjCP,EAAOO,aAAa,WAAY,KAChCP,EAAOO,aAAa,QAAS,uBAC7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EAAKY,SACP1D,IACAM,EAAkBzC,SAAS8F,QAE7B,MAAOlB,KAGX,SAASzC,EAAiByC,GACxB,MAAMmB,EAAOnB,EAAI,IAAIA,EAAEoB,OAAOzE,MAAM,KAAK,KAAOpC,OAAOiC,SAAS2E,KAEN,IAAtDA,EAAKE,QAAQ,yBACXrB,GAAGA,EAAEsB,iBAETnG,EAAOoG,cAAeC,YAAYhG,KAAKC,UAAU,CAAE0F,SAAS,MAIhE,SAAStD,EAAkBqD,GACrB/F,EAAOoG,eACTpG,EAAOoG,cAAcC,YAAYhG,KAAKC,UAAU,CAAEyF,UAAU,KAIhE,SAAS1D,EAAyBwC,GAC5B7E,EAAOoG,gBAAkBpG,EAAOsG,SAASzB,EAAElC,SAC7C3C,EAAOoG,cAAcC,YAAYhG,KAAKC,UAAU,CAAEiG,cAAc,IAAS,KAI7E,SAASC,EAAYC,GACfzG,EAAOoG,eACTpG,EAAOoG,cAAcC,YAAYhG,KAAKC,UAAU,CAAEmG,UAAU,KAIhE,SAASC,IACHxF,GACF8D,aAAa9D,GAGf9B,OAAOkF,oBAAoB,UAAWnC,GACtC/C,OAAOkF,oBAAoB,aAAclC,GACzCnC,SAASqE,oBAAoB,QAASjC,GAElClB,IACFA,EAAcwF,aAGdxF,EAAgB,MAGlBnB,EAAOiF,SAWT,OAPA7F,OAAOqB,SAAS+F,YAAcA,EAC9BpH,OAAOqB,SAASiG,QAAU,KACxBA,WACOtH,OAAOqB,SAAS+F,mBAChBpH,OAAOqB,SAASiG,SAGlB,CACLF,cACAE,WA3VwB,YAAxBzG,SAAS2G,WACX3G,SAASiC,iBAAiB,mBAAoB1B,GAE9CA,K","file":"embed.mjs","sourcesContent":["export const BASE_URL = window.remark_config.host || process.env.REMARK_URL!;\nexport const NODE_ID = process.env.REMARK_NODE!;\nexport const API_BASE = '/api/v1';\nexport const COMMENT_NODE_CLASSNAME_PREFIX = 'remark42__comment-';\nexport const COUNTER_NODE_CLASSNAME = 'remark42__counter';\n","import type { UserInfo, Theme } from 'common/types';\nimport { BASE_URL, NODE_ID, COMMENT_NODE_CLASSNAME_PREFIX } from 'common/constants.config';\n\nif (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', init);\n} else {\n init();\n}\n\nfunction removeDomNode(node: HTMLElement | null) {\n if (node && node.parentNode) {\n node.parentNode.removeChild(node);\n }\n}\n\nfunction createFrame({\n host,\n query,\n height,\n margin = '-6px',\n __colors__ = {},\n}: {\n host: string;\n query: string;\n height?: string;\n margin?: string;\n __colors__?: Record;\n}) {\n const iframe = document.createElement('iframe');\n\n iframe.src = `${host}/web/iframe.html?${query}`;\n iframe.name = JSON.stringify({ __colors__ });\n iframe.setAttribute('width', '100%');\n iframe.setAttribute('frameborder', '0');\n iframe.setAttribute('allowtransparency', 'true');\n iframe.setAttribute('scrolling', 'no');\n iframe.setAttribute('tabindex', '0');\n iframe.setAttribute('title', 'Comments | Remark42');\n iframe.setAttribute('horizontalscrolling', 'no');\n iframe.setAttribute('verticalscrolling', 'no');\n iframe.setAttribute(\n 'style',\n `width: 1px !important; min-width: 100% !important; border: none !important; overflow: hidden !important; margin: ${margin};`\n );\n\n if (height) {\n iframe.setAttribute('height', height);\n }\n\n return iframe;\n}\n\nfunction init() {\n window.REMARK42 = window.REMARK42 || {};\n window.REMARK42.createInstance = createInstance;\n\n createInstance(window.remark_config);\n\n window.dispatchEvent(new Event('REMARK42::ready'));\n}\n\nfunction createInstance(config: typeof window.remark_config) {\n const root = document.getElementById(NODE_ID);\n\n if (!root) {\n throw new Error(\"Remark42: Can't find root node.\");\n }\n if (!window.remark_config) {\n throw new Error('Remark42: Config object is undefined.');\n }\n if (!window.remark_config.site_id) {\n throw new Error('Remark42: Site ID is undefined.');\n }\n\n let initDataAnimationTimeout: number | null = null;\n let titleObserver: MutationObserver | null = null;\n\n config.url = (config.url || `${window.location.origin}${window.location.pathname}`).split('#')[0];\n\n const query = Object.keys(config)\n .filter((key) => key !== '__colors__')\n .map(\n (key) =>\n `${encodeURIComponent(key)}=${encodeURIComponent(\n config[key as keyof Omit] as string | number | boolean\n )}`\n )\n .join('&');\n\n const iframe =\n (root.firstElementChild as HTMLIFrameElement) ||\n createFrame({ host: BASE_URL, query, __colors__: config.__colors__ });\n\n root.appendChild(iframe);\n\n window.addEventListener('message', receiveMessages);\n window.addEventListener('hashchange', postHashToIframe);\n document.addEventListener('click', postClickOutsideToIframe);\n\n const titleElement = document.querySelector('title');\n if (titleElement) {\n titleObserver = new MutationObserver((mutations) => postTitleToIframe(mutations[0].target.textContent!));\n titleObserver.observe(titleElement, {\n subtree: true,\n characterData: true,\n childList: true,\n });\n }\n\n const remarkRootId = 'remark-km423lmfdslkm34';\n const userInfo: {\n node: HTMLElement | null;\n back: HTMLElement | null;\n closeEl: HTMLElement | null;\n iframe: HTMLIFrameElement | null;\n style: HTMLStyleElement | null;\n init: (user: UserInfo) => void;\n close: () => void;\n delay: number | null;\n events: string[];\n onAnimationClose: () => void;\n onKeyDown: (e: KeyboardEvent) => void;\n animationStop: () => void;\n remove: () => void;\n } = {\n node: null,\n back: null,\n closeEl: null,\n iframe: null,\n style: null,\n init(user) {\n this.animationStop();\n if (!this.style) {\n this.style = document.createElement('style');\n this.style.setAttribute('rel', 'stylesheet');\n this.style.setAttribute('type', 'text/css');\n this.style.innerHTML = `\n #${remarkRootId}-node {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n width: 400px;\n transition: transform 0.4s ease-out;\n max-width: 100%;\n transform: translate(400px, 0);\n }\n #${remarkRootId}-node[data-animation] {\n transform: translate(0, 0);\n }\n #${remarkRootId}-back {\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(0,0,0,0.7);\n opacity: 0;\n transition: opacity 0.4s ease-out;\n }\n #${remarkRootId}-back[data-animation] {\n opacity: 1;\n }\n #${remarkRootId}-close {\n top: 0px;\n right: 400px;\n position: absolute;\n text-align: center;\n font-size: 25px;\n cursor: pointer;\n color: white;\n border-color: transparent;\n border-width: 0;\n padding: 0;\n margin-right: 4px;\n background-color: transparent;\n }\n @media all and (max-width: 430px) {\n #${remarkRootId}-close {\n right: 0px;\n font-size: 20px;\n color: black;\n }\n }\n `;\n }\n if (!this.node) {\n this.node = document.createElement('div');\n this.node.id = `${remarkRootId}-node`;\n }\n if (!this.back) {\n this.back = document.createElement('div');\n this.back.id = `${remarkRootId}-back`;\n this.back.onclick = () => this.close();\n }\n if (!this.closeEl) {\n this.closeEl = document.createElement('button');\n this.closeEl.id = `${remarkRootId}-close`;\n this.closeEl.innerHTML = '✖';\n this.closeEl.onclick = () => this.close();\n }\n const queryUserInfo = `${query}&page=user-info&&id=${user.id}&name=${user.name}&picture=${\n user.picture || ''\n }&isDefaultPicture=${user.isDefaultPicture || 0}`;\n const iframe = createFrame({ host: BASE_URL, query: queryUserInfo, height: '100%', margin: '0' });\n this.node.appendChild(iframe);\n this.iframe = iframe;\n this.node.appendChild(this.closeEl);\n document.body.appendChild(this.style);\n document.body.appendChild(this.back);\n document.body.appendChild(this.node);\n document.addEventListener('keydown', this.onKeyDown);\n initDataAnimationTimeout = window.setTimeout(() => {\n this.back!.setAttribute('data-animation', '');\n this.node!.setAttribute('data-animation', '');\n iframe.focus();\n }, 400);\n },\n close() {\n if (this.node) {\n if (this.iframe) {\n this.node.removeChild(this.iframe);\n }\n this.onAnimationClose();\n this.node.removeAttribute('data-animation');\n }\n if (this.back) {\n this.back.removeAttribute('data-animation');\n }\n document.removeEventListener('keydown', this.onKeyDown);\n },\n delay: null,\n events: ['', 'webkit', 'moz', 'MS', 'o'].map((prefix) => (prefix ? `${prefix}TransitionEnd` : 'transitionend')),\n onAnimationClose() {\n const el = this.node!;\n if (!this.node) {\n return;\n }\n this.delay = window.setTimeout(this.animationStop, 1000);\n this.events.forEach((event) => el.addEventListener(event, this.animationStop, false));\n },\n onKeyDown(e) {\n // ESCAPE key pressed\n if (e.keyCode === 27) {\n userInfo.close();\n }\n },\n animationStop() {\n const t = userInfo;\n if (!t.node) {\n return;\n }\n if (t.delay) {\n clearTimeout(t.delay);\n t.delay = null;\n }\n t.events.forEach((event) => t.node!.removeEventListener(event, t.animationStop, false));\n return t.remove();\n },\n remove() {\n const t = userInfo;\n removeDomNode(t.node);\n removeDomNode(t.back);\n removeDomNode(t.style);\n },\n };\n\n function receiveMessages(event: { data?: string }): void {\n try {\n const data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;\n if (data.remarkIframeHeight) {\n iframe.style.height = `${data.remarkIframeHeight}px`;\n }\n\n if (data.scrollTo) {\n window.scrollTo(window.pageXOffset, data.scrollTo + iframe.getBoundingClientRect().top + window.pageYOffset);\n }\n\n if (Object.prototype.hasOwnProperty.call(data, 'isUserInfoShown')) {\n if (data.isUserInfoShown) {\n userInfo.init(data.user || {});\n } else {\n userInfo.close();\n }\n }\n\n if (data.inited) {\n postHashToIframe();\n postTitleToIframe(document.title);\n }\n } catch (e) {}\n }\n\n function postHashToIframe(e?: Event & { newURL: string }) {\n const hash = e ? `#${e.newURL.split('#')[1]}` : window.location.hash;\n\n if (hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) {\n if (e) e.preventDefault();\n\n iframe.contentWindow!.postMessage(JSON.stringify({ hash }), '*');\n }\n }\n\n function postTitleToIframe(title: string) {\n if (iframe.contentWindow) {\n iframe.contentWindow.postMessage(JSON.stringify({ title }), '*');\n }\n }\n\n function postClickOutsideToIframe(e: MouseEvent) {\n if (iframe.contentWindow && !iframe.contains(e.target as Node)) {\n iframe.contentWindow.postMessage(JSON.stringify({ clickOutside: true }), '*');\n }\n }\n\n function changeTheme(theme: Theme) {\n if (iframe.contentWindow) {\n iframe.contentWindow.postMessage(JSON.stringify({ theme }), '*');\n }\n }\n\n function destroy() {\n if (initDataAnimationTimeout) {\n clearTimeout(initDataAnimationTimeout);\n }\n\n window.removeEventListener('message', receiveMessages);\n window.removeEventListener('hashchange', postHashToIframe);\n document.removeEventListener('click', postClickOutsideToIframe);\n\n if (titleObserver) {\n titleObserver.disconnect();\n // Allow browser to drop observer and iframe captured in callback\n // to prevent attempts to send messages to detached frame\n titleObserver = null;\n }\n\n iframe.remove();\n }\n\n // TODO: These do not appear in Chrome DevTools\n window.REMARK42.changeTheme = changeTheme;\n window.REMARK42.destroy = () => {\n destroy();\n delete window.REMARK42.changeTheme;\n delete window.REMARK42.destroy;\n };\n\n return {\n changeTheme,\n destroy,\n };\n}\n"],"sourceRoot":""}