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,QAAQ,oBAAoB,GACtE,CACA,mBAAA,GACI,OAAO,OAAO,QAAQ,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,CAAC,EAAG,KAAK,SAAU,CAAE,mBAAoB,KAAK,qBAAwB,KAAK,YAAc,CAAE,WAAY,KAAK,cAAgB,QAAO,CAAC,GAAQ,EAAK,MAC7M,QAAc,IAAV,GAAwC,iBAAV,GAAsB,CAAC,SAAU,cAAc,SAAS,GACtF,OAAO,EAGX,OAAO,GADa,EAAM,OAAS,IAAM,KACZ,EAAM,IAAM,mBAAmB,EAAM,GACnE,GACP,EAEJ,OAAO,QAAU","file":"/npm/@wert-io/widget-initializer@7.0.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@wert-io/widget-initializer@7.0.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nconst package_json_1 = require(\"./package.json\");\nconst externalStaticOrigin = 'https://javascript.wert.io';\nclass WertWidget {\n    constructor(options) {\n        this.options = options;\n        this.iframe = document.createElement('iframe');\n        this.widgetWindow = null;\n        this.widget_layout_mode = 'Modal';\n        this.await_data = false;\n        this.onMessage = (event) => {\n            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;\n            const thisWidgetEvent = event.source === this.widgetWindow;\n            const isDataObject = typeof event.data === 'object';\n            if (!thisWidgetEvent || !isDataObject)\n                return;\n            switch (event.data.type) {\n                case 'loaded':\n                    this.sendEvent('allow-redirect', {\n                        redirectAllowed: false\n                    });\n                    this.sendEvent('extra', this.options.extra);\n                    this.sendEvent('parent-hostname', { hostname: window.location.hostname });\n                    (_b = (_a = this.options.listeners) === null || _a === void 0 ? void 0 : _a[event.data.type]) === null || _b === void 0 ? void 0 : _b.call(_a);\n                    break;\n                case \"payment-status\":\n                    (_d = (_c = this.options.listeners) === null || _c === void 0 ? void 0 : _c[event.data.type]) === null || _d === void 0 ? void 0 : _d.call(_c, event.data.data);\n                    break;\n                case \"position\":\n                    (_f = (_e = this.options.listeners) === null || _e === void 0 ? void 0 : _e[event.data.type]) === null || _f === void 0 ? void 0 : _f.call(_e, event.data.data);\n                    break;\n                case \"rate-update\":\n                    (_h = (_g = this.options.listeners) === null || _g === void 0 ? void 0 : _g[event.data.type]) === null || _h === void 0 ? void 0 : _h.call(_g, event.data.data);\n                    break;\n                case 'close':\n                    this.close();\n                    break;\n                case \"error\":\n                    (_k = (_j = this.options.listeners) === null || _j === void 0 ? void 0 : _j[event.data.type]) === null || _k === void 0 ? void 0 : _k.call(_j, event.data.data);\n                    break;\n                case \"3ds-start\":\n                    this.iframe.style.background = \"#fff\";\n                    break;\n                case \"3ds-end\":\n                    this.iframe.style.background = \"transparent\";\n                    break;\n            }\n        };\n        this.validateOptions(options);\n        if (!this.options.origin) {\n            this.options.origin = 'https://widget.wert.io';\n        }\n        if (this.options.extra) {\n            this.await_data = true;\n        }\n    }\n    open() {\n        this.iframe.style.border = 'none';\n        this.iframe.style.width = '100%';\n        this.iframe.style.height = '100%';\n        this.iframe.style.bottom = '0';\n        this.iframe.style.right = '0';\n        this.iframe.style.position = 'fixed';\n        this.iframe.style.zIndex = '10000';\n        document.body.style.overflow = 'hidden';\n        this.iframe.setAttribute('src', this.getEmbedUrl());\n        this.iframe.setAttribute('allow', 'camera *; microphone *; payment');\n        this.iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-popups allow-same-origin');\n        this.iframe.setAttribute('data-version', package_json_1.version);\n        document.body.appendChild(this.iframe);\n        this.widgetWindow = this.iframe.contentWindow;\n        this.listenWidget();\n    }\n    addEventListeners(listeners) {\n        this.options.listeners = Object.assign(Object.assign({}, this.options.listeners), listeners);\n    }\n    removeEventListeners(types) {\n        var _a, _b;\n        if (typeof types === 'undefined') {\n            delete this.options.listeners;\n        }\n        else if (typeof types === 'string') {\n            (_a = this.options.listeners) === null || _a === void 0 ? true : delete _a[types];\n        }\n        else {\n            for (const type of types) {\n                (_b = this.options.listeners) === null || _b === void 0 ? true : delete _b[type];\n            }\n        }\n    }\n    updateTheme(data) {\n        if (!data || !Object.keys(data).length)\n            return;\n        this.sendEvent('theme', data);\n    }\n    close() {\n        var _a, _b;\n        document.body.removeChild(this.iframe);\n        document.body.style.overflow = '';\n        this.unListenWidget();\n        (_b = (_a = this.options.listeners) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a);\n    }\n    validateOptions(options) {\n        var _a, _b, _c, _d;\n        const maxNameLength = 40;\n        const maxCategoryLength = 40;\n        if (!options.partner_id) {\n            throw Error(\"Please provide a partner_id in order for the widget to work correctly\");\n        }\n        // This is required for showing error during old integration usages\n        if (options.container_id) {\n            console.error('container_id is no longer supported');\n        }\n        if (((_b = (_a = options.extra) === null || _a === void 0 ? void 0 : _a.item_info) === null || _b === void 0 ? void 0 : _b.name) && options.extra.item_info.name.length > maxNameLength) {\n            console.error(`Max length of the extra.item_info.name value is ${maxNameLength} characters`);\n        }\n        if (((_d = (_c = options.extra) === null || _c === void 0 ? void 0 : _c.item_info) === null || _d === void 0 ? void 0 : _d.category) && options.extra.item_info.category.length > maxCategoryLength) {\n            console.error(`Max length of the extra.item_info.category value is ${maxCategoryLength} characters`);\n        }\n    }\n    listenWidget() {\n        window.addEventListener('message', this.onMessage);\n        const checkLiveliness = () => {\n            const alive = this.widgetWindow && !this.widgetWindow.closed;\n            if (alive)\n                return;\n            this.unListenWidget();\n        };\n        this.checkIntervalId = window.setInterval(checkLiveliness, 200);\n    }\n    unListenWidget() {\n        if (!this.checkIntervalId)\n            return;\n        clearInterval(this.checkIntervalId);\n        this.checkIntervalId = undefined;\n        window.removeEventListener('message', this.onMessage);\n    }\n    sendEvent(type, data) {\n        var _a;\n        if (!data)\n            return;\n        (_a = this.widgetWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ data, type }, this.options.origin);\n    }\n    getEmbedUrl() {\n        const parametersString = this.getParametersString();\n        return `${this.options.origin}/${this.options.partner_id}/widget${parametersString}`;\n    }\n    getParametersString() {\n        return Object.entries(Object.assign(Object.assign(Object.assign({}, this.options), { widget_layout_mode: this.widget_layout_mode }), (this.await_data && { await_data: this.await_data }))).reduce((accum, [key, value]) => {\n            if (value === undefined || typeof value === 'object' || ['origin', 'partner_id'].includes(key)) {\n                return accum;\n            }\n            const startSymbol = accum.length ? '&' : '?';\n            return accum + startSymbol + key + '=' + encodeURIComponent(value);\n        }, '');\n    }\n}\nmodule.exports = WertWidget;\n"]}