{"version":3,"file":"index.esm.js","sources":["../src/component/component.ts","../src/views/rental.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nexport default class Component extends HTMLElement {\n $state: any;\n\n constructor() {\n super();\n this.setup();\n }\n connectedCallback() {\n this.innerHTML = `\n \n `;\n this.innerHTML += this.template();\n this.setEvent();\n }\n setup() {\n /**/\n }\n template() {\n return '';\n }\n\n setEvent() {\n /**/\n }\n setState(newState: any) {\n this.$state = { ...this.$state, ...newState };\n this.connectedCallback();\n }\n}\n","import Component from '../component/component';\n\nconst urlFormatter = (returnUrl: string, queryString: string) => {\n if (returnUrl.includes('?')) {\n return `${returnUrl}&${queryString}`;\n }\n return `${returnUrl}?${queryString}`;\n};\n\nexport class Rental extends Component {\n public signKey = '';\n public partnerKey = '';\n public partnerGoodsNo = '';\n public partnerOptionCode = '';\n public partnerOptionValue = '';\n public returnUrl = '';\n public closeUrl = '';\n public imageUrl = '';\n public iframeURL = '';\n public orderNo = '';\n public onlyConsult?: boolean = false;\n private baseUrl = '';\n private brodCd = '';\n\n constructor(\n signKey: string,\n partnerKey: string,\n partnerGoodsNo: string,\n imageUrl: string,\n partnerOptionCode?: string,\n partnerOptionValue?: string,\n closeUrl?: string,\n returnUrl?: string,\n orderNo?: string,\n onlyConsult?: boolean,\n brodCd?: string,\n ) {\n super();\n this.signKey = signKey || '';\n this.partnerKey = partnerKey || '';\n this.partnerGoodsNo = partnerGoodsNo || '';\n this.partnerOptionCode = partnerOptionCode || '';\n this.partnerOptionValue = partnerOptionValue || '';\n this.closeUrl = closeUrl || '';\n this.returnUrl = returnUrl || '';\n this.imageUrl = imageUrl || '';\n this.orderNo = orderNo || '';\n this.baseUrl =\n process.env.VITE_RENTAL_JS || 'https://js.rentalnow.co.kr';\n this.onlyConsult = onlyConsult;\n this.brodCd = brodCd || '';\n if (this.partnerKey !== '') {\n this.iframeURL = `${this.baseUrl}/?signKey=${this.signKey}&partnerKey=${this.partnerKey}&partnerGoodsNo=${this.partnerGoodsNo}&partnerOptionCode=${this.partnerOptionCode}&partnerOptionValue=${this.partnerOptionValue}&closeUrl=${this.closeUrl}&returnUrl=${this.returnUrl}&imageUrl=${this.imageUrl}&orderNo=${this.orderNo}&onlyConsult=${this.onlyConsult}&brodCd=${this.brodCd}`;\n document\n .getElementById('rental_iframe')!\n .setAttribute('src', this.iframeURL);\n\n if (this.isMobile()) {\n document\n .getElementById('rental_iframe')!\n .setAttribute('width', '100%');\n document\n .getElementById('rental_iframe')!\n .setAttribute('height', '100%');\n document.getElementById('rental_iframe')!.style.marginTop = '0';\n }\n }\n }\n\n setup() {\n this.$state = { result: '' }; // user-agent 초기값 세팅\n }\n\n setEvent() {\n super.setEvent();\n if (this.iframeURL.length > 0) {\n const { mode } = this.$state;\n const _this: any = this;\n let elements = document.getElementsByTagName('html');\n\n // const btn_close = document.getElementById('rental_content')!;\n // btn_close.onclick = function () {\n // _this.hide();\n // _this.setState({});\n // for (let i = 0; i < len; i++) {\n // elements.item(i)!.style.overflow = 'auto';\n // }\n // };\n\n let len = elements.length;\n\n for (let i = 0; i < len; i++) {\n elements.item(i)!.style.overflow = 'hidden';\n }\n\n if (this.isMobile()) {\n this.mobile();\n } else {\n this.pc();\n }\n window.addEventListener('message', function (e) {\n if ('rental_close' == e.data) {\n // _this.callbackFunction();\n _this.hide();\n _this.setState({ result: e });\n parent.document.location.reload();\n for (let i = 0; i < len; i++) {\n elements.item(i)!.style.overflow = 'auto';\n }\n window.parent.postMessage(\n 'rental_close://?sucess=111',\n '*',\n );\n\n return;\n }\n\n const messageData = JSON.parse(e.data) as {\n message: string;\n data: any;\n };\n\n if (messageData.message === 'rental_done') {\n _this.hide();\n _this.setState({ result: e });\n parent.document.location.href = urlFormatter(\n _this.returnUrl,\n `cntrNo=${messageData.data.cntrNo}&totalPrice=${messageData.data.totalPrice}`,\n );\n for (let i = 0; i < len; i++) {\n elements.item(i)!.style.overflow = 'auto';\n }\n window.parent.postMessage(\n 'rental_close://?sucess=111',\n '*',\n );\n }\n });\n }\n }\n\n isMobile() {\n const UserAgent = navigator.userAgent;\n\n if (\n UserAgent.match(\n /iPhone|iPod|Android|Windows CE|BlackBerry|Symbian|Windows Phone|webOS|Opera Mini|Opera Mobi|POLARIS|IEMobile|lgtelecom|nokia|SonyEricsson/i,\n ) != null ||\n UserAgent.match(/LG|SAMSUNG|Samsung/) != null\n ) {\n return true;\n } else {\n return false;\n }\n }\n\n compelete(callback: any) {\n const { result } = this.$state;\n callback(result);\n }\n\n show() {\n document.getElementById('rental_background')!.style.display = 'block';\n this.setEvent();\n }\n\n // set callback(args: () => any) {\n // if (typeof args === 'function') {\n // this.callbackFunction = args;\n // }\n // }\n\n hide() {\n document.getElementById('rental_background')!.style.display = 'none';\n }\n\n pc() {\n return '';\n }\n\n mobile() {\n document.getElementById('rental_iframe')!.setAttribute('width', '100%');\n document\n .getElementById('rental_iframe')!\n .setAttribute('height', '100%');\n }\n\n template() {\n return ` \n
\n
\n