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AI3C,KAAKL,OACiB,QAAzBgD,EAAA3C,KAAKL,OAAOiD,qBAAa,IAAAD,GAAzBA,EAA2BtC,YAAYC,KAAKC,UAAUP,KAAKJ,QAAS,KACpEI,KAAKiC,qBAEN,MAED,IAAK,QACAjC,KAAKL,SACR4B,SAASH,KAAKe,YAAYnC,KAAKL,QAE/BQ,OAAO0C,oBAAoB,UAAW7C,KAAKqC,cAAcC,KAAKtC,OAAO,GAErEA,KAAKF,eAAiB,KACtBE,KAAKJ,OAAS,KACdI,KAAKL,OAAS,MAOlB,EACAmD,kBAAmB,WAElB,OAAO9C,KAAKE,YAAYoC,KAAKtC,KAC9B,G,oBJ7KD","sources":["webpack://webpack-react-ts/webpack/universalModuleDefinition","webpack://webpack-react-ts/webpack/bootstrap","webpack://webpack-react-ts/webpack/runtime/define property getters","webpack://webpack-react-ts/webpack/runtime/hasOwnProperty shorthand","webpack://webpack-react-ts/./src/widget.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"CobuyrWidget\"] = factory();\n\telse\n\t\troot[\"CobuyrWidget\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","const defaultStyles: any = {\n\tborder: 'none',\n\t'z-index': 2147483647,\n\theight: '100vh',\n\twidth: '100vw',\n\tdisplay: 'block !important',\n\tvisibility: 'visible',\n\tbackground: 'none transparent',\n\topacity: 1,\n\tleft: 0,\n\tright: 0,\n\ttop: 0,\n\tbottom: 0,\n\t'pointer-events': 'auto',\n\t'touch-action': 'auto',\n\tposition: 'fixed',\n};\n\ninterface IConfig {\n\tbuttonStyle: {\n\t\tbackgroundColor: string;\n\t};\n\ttags: string[];\n\tsource: string;\n\treadonly order: {\n\t\tname: string;\n\t\tdescription: string;\n\t\tprice: number;\n\t\tquantity: number;\n\t};\n}\n\ninterface IWidget {\n\twindow?: any;\n\tconfig: IConfig | null;\n\tiframe: HTMLIFrameElement | null;\n\tloadingSpinner: HTMLDivElement | null;\n\tshowLoadingSpinner: () => void; // New function to show the loading spinner\n\thideLoadingSpinner: () => void;\n\tcreateLoadingDiv: () => void;\n\texposeCloseWidget: () => void;\n\tstyleElement: null | HTMLStyleElement;\n\tinit: (config: IConfig) => void;\n\tsetupListeners: () => void;\n\tcreateIframe: () => void;\n\thandleMessage: (event: MessageEvent) => void;\n\tcloseWidget: () => void;\n}\n\nconst CobuyrWidget: IWidget = {\n\tiframe: null,\n\tconfig: null,\n\tstyleElement: null,\n\tloadingSpinner: null,\n\tinit: function (config: IConfig) {\n\t\tthis.config = config;\n\t\tthis.createIframe();\n\t},\n\tcloseWidget: function () {\n\t\twindow.parent.postMessage(JSON.stringify({ action: 'close' }), '*');\n\t},\n\tcreateLoadingDiv: function () {\n\t\tif (this.loadingSpinner) {\n\t\t\t// Check if the iframe has a content document\n\t\t\tconst contentDocument = this.loadingSpinner.ownerDocument;\n\t\t\tif (contentDocument) {\n\t\t\t\t// Create a div with an id for styling\n\t\t\t\tconst loadingDiv = contentDocument.createElement('div');\n\t\t\t\tloadingDiv.id = 'loadingDiv';\n\t\t\t\tloadingDiv.style.position = 'absolute';\n\t\t\t\tloadingDiv.style.top = '50%';\n\t\t\t\tloadingDiv.style.left = '50%';\n\t\t\t\tloadingDiv.style.transform = 'translate(-50%, -50%)';\n\n\t\t\t\t// Add the spinner HTML and style directly within the iframe content\n\t\t\t\tloadingDiv.innerHTML = `
`;\n\n\t\t\t\t// Append the loading div to the body of the iframe\n\t\t\t\tcontentDocument.body?.appendChild(loadingDiv);\n\n\t\t\t\t// Include the spinner CSS within the iframe content\n\t\t\t\tconst styleElement = contentDocument.createElement('style');\n\t\t\t\tstyleElement.innerHTML = `\n \t\t@keyframes spin {\n \t\t 0% { transform: rotate(0deg); }\n \t\t 100% { transform: rotate(360deg); }\n \t\t}\n\n .spinner {\n border: 4px solid rgba(0, 0, 0, 0.1);\n border-left: 4px solid #3498db;\n border-radius: 50%;\n width: 40px;\n height: 40px;\n animation: spin 1s linear infinite;\n }\n `;\n\n\t\t\t\t// Append the style element to the head of the iframe document\n\t\t\t\tcontentDocument.head?.appendChild(styleElement);\n\t\t\t\tthis.styleElement = styleElement;\n\t\t\t}\n\t\t}\n\t},\n\tcreateIframe: function () {\n\t\tthis.loadingSpinner = document.createElement('div');\n\n\t\tvar container: HTMLDivElement = document.createElement('div');\n\t\tcontainer.setAttribute('id', 'connect-widget-div');\n\n\t\tdocument.body.appendChild(this.loadingSpinner);\n\t\tthis.showLoadingSpinner();\n\t\tthis.createLoadingDiv();\n\n\t\tthis.iframe = document.createElement('iframe');\n\t\tthis.iframe.id = 'cobuyriFrame';\n\n\t\tlet styles = '';\n\n\t\tfor (let key in defaultStyles) {\n\t\t\tstyles += key + ': ' + defaultStyles[key] + ';';\n\t\t}\n\t\tthis.iframe.setAttribute('style', styles);\n\n\t\tthis.iframe.src = `${process.env.REACT_APP_COBUYR_WIDGET}`;\n\n\t\tthis.iframe.allow = 'clipboard-write *';\n\n\t\tthis.iframe.referrerPolicy = 'no-referrer';\n\n\t\tdocument.body.appendChild(this.iframe);\n\n\t\tthis.setupListeners();\n\t},\n\tshowLoadingSpinner: function () {\n\t\tif (this.loadingSpinner) {\n\t\t\tthis.loadingSpinner.style.display = 'block';\n\t\t}\n\t},\n\thideLoadingSpinner: function () {\n\t\tif (this.styleElement && this.styleElement.parentNode) {\n\t\t\tthis.styleElement.parentNode.removeChild(this.styleElement);\n\t\t}\n\t\tif (this.loadingSpinner) {\n\t\t\tthis.loadingSpinner = null;\n\t\t}\n\t},\n\tsetupListeners: function () {\n\t\twindow.addEventListener('message', this.handleMessage.bind(this));\n\t},\n\thandleMessage: function (e) {\n\t\te.preventDefault();\n\n\t\tif (!e.data || typeof e.data !== 'string') return;\n\n\t\tlet data = JSON.parse(e.data);\n\t\tswitch (data.action) {\n\t\t\tcase 'init': {\n\t\t\t\tif (this.iframe) {\n\t\t\t\t\tthis.iframe.contentWindow?.postMessage(JSON.stringify(this.config), '*');\n\t\t\t\t\tthis.hideLoadingSpinner();\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'close': {\n\t\t\t\tif (this.iframe) {\n\t\t\t\t\tdocument.body.removeChild(this.iframe);\n\n\t\t\t\t\twindow.removeEventListener('message', this.handleMessage.bind(this), false);\n\n\t\t\t\t\tthis.loadingSpinner = null;\n\t\t\t\t\tthis.config = null;\n\t\t\t\t\tthis.iframe = null;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t},\n\texposeCloseWidget: function () {\n\t\t// Expose a function that allows calling closeWidget externally\n\t\treturn this.closeWidget.bind(this);\n\t},\n};\n\nexport default CobuyrWidget;\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","defaultStyles","border","height","width","display","visibility","background","opacity","left","right","top","bottom","position","iframe","config","styleElement","loadingSpinner","init","this","createIframe","closeWidget","window","parent","postMessage","JSON","stringify","action","createLoadingDiv","contentDocument","ownerDocument","_contentDocument$body","_contentDocument$head","loadingDiv","createElement","id","style","transform","innerHTML","body","appendChild","head","document","setAttribute","showLoadingSpinner","styles","src","concat","process","allow","referrerPolicy","setupListeners","hideLoadingSpinner","parentNode","removeChild","addEventListener","handleMessage","bind","e","preventDefault","data","parse","_this$iframe$contentW","contentWindow","removeEventListener","exposeCloseWidget"],"sourceRoot":""}