{"version":3,"file":"index.es.min.js","sources":["../../../packages/components/src/video/constants.mjs","../../../packages/helpers/src/getScript.js","../../../packages/helpers/src/deferred.js","../../../packages/helpers/src/dataLayer.js","../../../packages/helpers/src/playerYoutube.js","../../../packages/helpers/src/htmlElement.js","../../../packages/helpers/src/playerYouku.js","../../../packages/helpers/src/props.helpers.js","../../../packages/components/src/video/components/youtube-overlay.js","../../../packages/helpers/src/assets/js/eventDispatch.js","../../../packages/components/src/constants.mjs","../../../packages/helpers/src/viewport.helpers.ts","../../../packages/helpers/src/utils.ts","../../../packages/components/src/video/video.js"],"sourcesContent":["export const VIDEO_SERVICE_YOUTUBE = 'youtube'\nexport const VIDEO_SERVICE_YOUKU = 'youku'\nexport const VIDEO_SERVICE_LOCAL = 'local'\n","export default function getScript(source, asyncLoad = true, defer = false) {\n return new Promise((resolve, reject) => {\n if (document.querySelector(`script[src=\"${source}\"]`)) {\n return resolve() // Script already loaded\n }\n\n const script = document.createElement('script')\n const prior = document.getElementsByTagName('script')[0]\n script.async = asyncLoad\n script.defer = defer\n script.addEventListener('load', () => resolve())\n script.addEventListener('error', () => reject(new Error('Loading script')))\n script.src = source\n prior.parentNode.insertBefore(script, prior)\n })\n}\n","export default class Deferred {\n constructor() {\n this.promise = new Promise((resolve, reject) => {\n this.reject = reject\n this.resolve = resolve\n })\n }\n}\n","export const getDataLayer = () => {\n return window[window?.padlNamespace]?.dataLayer\n}\n\nexport const getMarketCode = () => {\n const dataLayer = getDataLayer()\n if (!dataLayer) {\n return 'ch'\n }\n\n return dataLayer.app.app.market.toLocaleLowerCase()\n}\n\nexport const getLangCode = () => {\n const dataLayer = getDataLayer()\n if (!dataLayer) {\n return 'en'\n }\n\n return getDataLayer().page.page.pageInfo.language.toLocaleLowerCase()\n}\n\nexport const getSegmentCode = () => {\n const dataLayer = getDataLayer()\n if (!dataLayer) {\n return 'B2C'\n }\n\n return getDataLayer().page.page.pageInfo.segmentBusiness\n}\n\nexport const isLoggedIn = () => {\n const dataLayer = getDataLayer()\n if (!dataLayer || !dataLayer.user) {\n return false\n }\n\n return dataLayer.user.isLoggedIn\n}\n\nexport const interpolateMarketLang = (string, market, lang) => {\n return string.replace('{market}', market).replace('{lang}', lang)\n}\n","import getScript from './getScript'\nimport Deferred from './deferred'\nimport { getMarketCode } from './dataLayer'\n\nfunction initYouTubeIframeAPI() {\n const deferred = new Deferred()\n\n if (window.YT?.Player || getMarketCode() === 'cn') {\n deferred.resolve()\n }\n\n // YouTube API will call this function automatically when player API is ready\n // https://developers.google.com/youtube/iframe_api_reference\n window.onYouTubeIframeAPIReady = function () {\n deferred.resolve()\n }\n\n getScript('https://www.youtube.com/iframe_api', false).then(() => {\n window.YT?.ready(() => deferred.resolve())\n })\n\n return deferred.promise\n}\n\nclass PlayerYoutube {\n constructor() {\n this.iframeApi = initYouTubeIframeAPI()\n }\n\n attach(iframeContainer, videoId, isBackgroundVideoPlaying, isAutoPlay = 1, moreParams = {}) {\n let params = {}\n\n if (isBackgroundVideoPlaying) {\n params = { playlist: videoId, controls: 0, loop: 1 }\n }\n\n return new Promise(resolve => {\n this.iframeApi.then(() => {\n const player = new window.YT.Player(iframeContainer, {\n videoId,\n host: 'https://www.youtube-nocookie.com',\n playerVars: {\n // disablekb: 1,\n // showinfo: 0,\n // modestbranding: 1,\n enablejsapi: 1,\n rel: 0,\n fs: 0,\n autoplay: isAutoPlay,\n ...params,\n ...moreParams\n },\n events: {\n onReady: () => {\n if (isBackgroundVideoPlaying) {\n player.mute()\n }\n resolve(player)\n },\n onStateChange: () => ({}),\n onError: () => ({})\n }\n })\n })\n })\n }\n}\n\nexport default PlayerYoutube\n","/**\n * Return real width for a DOM Node\n * @param {HTMLElement} el\n * @returns {number}\n */\nexport const outerWidth = el => {\n const style = getComputedStyle(el)\n const width = style.getPropertyValue('width') || 0\n const marginLeft = style.getPropertyValue('margin-left') || 0\n const marginRight = style.getPropertyValue('margin-right') || 0\n\n return parseInt(width) + parseInt(marginLeft) + parseInt(marginRight)\n}\n\n/**\n * Return real height for a DOM Node\n * @param {DOM Node} el\n * @returns {number}\n */\nexport const outerHeight = el => {\n const style = getComputedStyle(el)\n const height = style.getPropertyValue('height') || 0\n const marginTop = style.getPropertyValue('margin-top') || 0\n const marginBottom = style.getPropertyValue('margin-bottom') || 0\n\n return parseInt(height) + parseInt(marginTop) + parseInt(marginBottom)\n}\n\nexport const appendSchema = content => {\n const el = window.document.createElement('script')\n el.setAttribute('type', 'application/ld+json')\n el.innerHTML = JSON.stringify(content)\n window.document.head.appendChild(el)\n}\n","import getScript from './getScript'\nimport { outerWidth, outerHeight } from './htmlElement'\n\nclass PlayerYouku {\n constructor() {\n this.iframeApi = new Promise(resolve => {\n getScript('https://player.youku.com/jsapi').then(() => resolve())\n })\n }\n\n attach(iframeContainerId, videoId, isBackgroundVideoPlaying, isAutoPlay = 1, moreParams = {}) {\n let params = {}\n if (isBackgroundVideoPlaying) {\n const container = document.getElementById(iframeContainerId)\n\n params = {\n playlist: videoId,\n controls: 0,\n loop: 1,\n autoplay: 1,\n width: outerWidth(container),\n height: outerHeight(container)\n }\n }\n return new Promise(resolve => {\n this.iframeApi.then(() => {\n const player = new window.YKU.Player(iframeContainerId, {\n styleid: '0',\n client_id: 'a3660779c8b57c32',\n vid: videoId,\n newPlayer: true,\n autoplay: isAutoPlay,\n show_related: false,\n width: 640,\n height: 360,\n ...params,\n ...moreParams,\n events: {\n onPlayerReady: () => resolve(player),\n onPlayStart: () => ({}),\n onPlay: () => ({}),\n onPlayEnd: () => ({}),\n onPause: () => ({}),\n onWaiting: () => ({}),\n onFullScreen: () => ({}),\n onPlayError: () => ({})\n }\n })\n })\n })\n }\n}\n\nexport default PlayerYouku\n","const getData = attributes => attributes.find(attribute => attribute.nodeName === 'data')\n\nconst createProps = attributes => {\n const data = getData([...attributes])\n const props = [...attributes]\n .filter(attribute => attribute.nodeName !== 'data')\n .reduce((all, attr) => {\n return { ...all, [attr.nodeName]: attr.nodeValue }\n }, {})\n\n if (isNil(data)) {\n return props\n }\n\n try {\n return { ...props, ...JSON.parse(data.nodeValue) }\n } catch (error) {\n console.log('ERROR: No data', error, data?.nodeValue)\n }\n}\n\nconst isNil = obj => obj === undefined || obj === null\n\nexport const parseBool = value => (!value || value === 'false' ? false : true)\n\nexport default createProps\n","import createProps from '@kissui/helpers/src/props.helpers'\n\nclass YoutubeOverlay extends HTMLElement {\n connectedCallback() {\n const { video_id = '' } = createProps(this.attributes)\n\n if (video_id) {\n this.render(video_id)\n }\n }\n\n render(videoId) {\n this.setAttribute('role', 'button')\n this.style.backgroundImage = `url(https://img.youtube.com/vi/${videoId}/sddefault.jpg)`\n this.innerHTML = `\n