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AAW,OAC7BN,EAAQO,KAAKC,MAAOF,EAAW,MAAY,MAC3CL,EAAUM,KAAKC,MAAOF,EAAW,KAAW,KAC5CJ,EAAUK,KAAKC,MAAOF,EAAW,IAAS,KAEhDR,EAASC,EAAMC,EAAOC,EAASC,GAE3BI,EAAW,IACblB,cAAcb,EAAGY,wBACjBN,EAAUsB,UAAY7B,EACtBK,EAAY/B,MAAM6D,QAAU,OAC5B5B,EAAUjC,MAAM6D,QAAU,GAE9B,EAEIjC,GACFD,EAAGY,uBAAyBuB,YAAYN,EAAW,KACnDvB,EAAUjC,MAAM6D,QAAU,OAC1B9B,EAAY/B,MAAM6D,QAAU,GAC5BL,KAEAN,EAAS,EAAG,EAAG,EAAG,EAEtB,EAWM,eAAgB,CAAC,YAAa,WAC9Ba,OAAQ,CAAC,CACPlE,MAAO,QACPmE,KAAM,YACNC,YAAY,EACZhD,KAAMtB,EAAQS,eACd,CACAP,MAAO,WACPmE,KAAM,UACNC,YAAY,IAGdC,WAAY,0DACyBxD,EAAG,8CACtBA,EAAG,2EACuBA,EAAG,uDAC3BA,EAAG,oBAAWf,EAAQU,UAAS,gEAEjCK,EAAG,4EACwBA,EAAG,uDAC5BA,EAAG,oBAAWf,EAAQW,WAAU,gEAElCI,EAAG,8EAC0BA,EAAG,uDAC9BA,EAAG,oBAAWf,EAAQY,aAAY,gEAEpCG,EAAG,8EAC0BA,EAAG,uDAC9BA,EAAG,oBAAWf,EAAQa,aAAY,gHAGTE,EAAG,gCAEhDyD,QAASnE,GAAS,uBACbU,EAAG,0EAIHA,EAAG,4IAMHA,EAAG,6EAIHA,EAAG,+EAIHA,EAAG,uEAGFf,EAAuB,iBAC1BI,KAIX,E","sources":["webpack://grapesjs-component-countdown/webpack/universalModuleDefinition","webpack://grapesjs-component-countdown/webpack/bootstrap","webpack://grapesjs-component-countdown/webpack/runtime/define property getters","webpack://grapesjs-component-countdown/webpack/runtime/hasOwnProperty shorthand","webpack://grapesjs-component-countdown/webpack/runtime/make namespace object","webpack://grapesjs-component-countdown/./src/index.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[\"grapesjs-component-countdown\"] = factory();\n\telse\n\t\troot[\"grapesjs-component-countdown\"] = factory();\n})(typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : this), () => {\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))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type { Plugin, BlockProperties, ComponentDefinition } from 'grapesjs';\n\nexport type PluginOptions = {\n /**\n * The ID used to create the block and component\n * @default 'countdown'\n */\n id?: string;\n\n /**\n * The label used for the block and the component.\n * @default 'Countdown'\n */\n label?: string,\n\n /**\n * Object to extend the default block. Pass a falsy value to avoid adding the block.\n * @example\n * { label: 'Countdown', category: 'Extra', ... }\n */\n block?: Partial;\n\n /**\n * Object to extend the default component properties.\n * @example\n * { name: 'Countdown', droppable: false, ... }\n */\n props?: ComponentDefinition;\n\n /**\n * Custom CSS styles for the component. This will replace the default one.\n * @default ''\n */\n style?: string,\n\n /**\n * Additional CSS styles for the component. These will be appended to the default one.\n * @default ''\n */\n styleAdditional?: string,\n\n /**\n * Default start time.\n * @default ''\n * @example '2018-01-25 00:00'\n */\n startTime?: string,\n\n /**\n * Text to show when the countdown is ended.\n * @default 'EXPIRED'\n */\n endText?: string,\n\n /**\n * Date input type, eg. `date`, `datetime-local`\n * @default 'date'\n */\n dateInputType?: string,\n\n /**\n * Days label text used in component.\n * @default 'days'\n */\n labelDays?: string,\n\n /**\n * Hours label text used in component.\n * @default 'hours'\n */\n labelHours?: string,\n\n /**\n * Minutes label text used in component.\n * @default 'minutes'\n */\n labelMinutes?: string,\n\n /**\n * Seconds label text used in component.\n * @default 'seconds'\n */\n labelSeconds?: string,\n\n /**\n * Countdown component class prefix.\n * @default 'countdown'\n */\n classPrefix?: string,\n};\n\ntype TElement = HTMLElement & { __gjsCountdownInterval: NodeJS.Timer };\n\ndeclare global {\n interface Window { __gjsCountdownIntervals: TElement[]; }\n}\n\nconst plugin: Plugin = (editor, opts = {}) => {\n const options: PluginOptions = {\n id: 'countdown',\n label: 'Countdown',\n block: {},\n props: {},\n style: '',\n styleAdditional: '',\n startTime: '',\n endText: 'EXPIRED',\n dateInputType: 'date',\n labelDays: 'days',\n labelHours: 'hours',\n labelMinutes: 'minutes',\n labelSeconds: 'seconds',\n classPrefix: 'countdown',\n ...opts,\n };\n\n const { block, props, style } = options;\n const id = options.id!;\n const label = options.label!;\n const pfx = options.classPrefix!;\n\n // Create block\n if (block) {\n editor.Blocks.add(id, {\n media: `\n \n `,\n label,\n category: 'Extra',\n select: true,\n content: { type: id },\n ...block\n });\n };\n\n const coundownScript = function(props: Record) {\n const startfrom: string = props.startfrom;\n const endTxt: string = props.endText;\n // @ts-ignore\n const el: TElement = this;\n const countDownDate = new Date(startfrom).getTime();\n const countdownEl = el.querySelector('[data-js=countdown]') as HTMLElement;\n const endTextEl = el.querySelector('[data-js=countdown-endtext]') as HTMLElement;\n const dayEl = el.querySelector('[data-js=countdown-day]')!;\n const hourEl = el.querySelector('[data-js=countdown-hour]')!;\n const minuteEl = el.querySelector('[data-js=countdown-minute]')!;\n const secondEl = el.querySelector('[data-js=countdown-second]')!;\n const oldInterval = el.__gjsCountdownInterval;\n oldInterval && clearInterval(oldInterval);\n\n const connected: TElement[] = window.__gjsCountdownIntervals || [];\n const toClean: TElement[] = [];\n connected.forEach((item: TElement) => {\n if (!item.isConnected) {\n clearInterval(item.__gjsCountdownInterval);\n toClean.push(item);\n }\n });\n connected.indexOf(el) < 0 && connected.push(el);\n window.__gjsCountdownIntervals = connected.filter(item => toClean.indexOf(item) < 0);\n\n const setTimer = function (days: number, hours: number, minutes: number, seconds: number) {\n dayEl.innerHTML = `${days < 10 ? '0' + days : days}`;\n hourEl.innerHTML = `${hours < 10 ? '0' + hours : hours}`;\n minuteEl.innerHTML = `${minutes < 10 ? '0' + minutes : minutes}`;\n secondEl.innerHTML = `${seconds < 10 ? '0' + seconds : seconds}`;\n }\n\n const moveTimer = function() {\n const now = new Date().getTime();\n const distance = countDownDate - now;\n const days = Math.floor(distance / 86400000);\n const hours = Math.floor((distance % 86400000) / 3600000);\n const minutes = Math.floor((distance % 3600000) / 60000);\n const seconds = Math.floor((distance % 60000) / 1000);\n\n setTimer(days, hours, minutes, seconds);\n\n if (distance < 0) {\n clearInterval(el.__gjsCountdownInterval);\n endTextEl.innerHTML = endTxt;\n countdownEl.style.display = 'none';\n endTextEl.style.display = '';\n }\n };\n\n if (countDownDate) {\n el.__gjsCountdownInterval = setInterval(moveTimer, 1000);\n endTextEl.style.display = 'none';\n countdownEl.style.display = '';\n moveTimer();\n } else {\n setTimer(0, 0, 0, 0);\n }\n };\n\n // Create component\n editor.Components.addType(id, {\n model: {\n defaults: {\n startfrom: options.startTime,\n classes: [pfx],\n endText: options.endText,\n droppable: false,\n script: coundownScript,\n 'script-props': ['startfrom', 'endText'],\n traits: [{\n label: 'Start',\n name: 'startfrom',\n changeProp: true,\n type: options.dateInputType,\n },{\n label: 'End text',\n name: 'endText',\n changeProp: true,\n }],\n // @ts-ignore\n components: `\n \n
\n
\n
${options.labelDays}
\n
\n
\n
\n
${options.labelHours}
\n
\n
\n
\n
${options.labelMinutes}
\n
\n
\n
\n
${options.labelSeconds}
\n
\n
\n \n `,\n styles: (style || `\n .${pfx} {\n text-align: center;\n }\n\n .${pfx}-block {\n display: inline-block;\n margin: 0 10px;\n padding: 10px;\n }\n\n .${pfx}-digit {\n font-size: 5rem;\n }\n\n .${pfx}-endtext {\n font-size: 5rem;\n }\n\n .${pfx}-cont {\n display: inline-block;\n }\n `) + (options.styleAdditional),\n ...props,\n },\n },\n });\n};\n\nexport default plugin;"],"names":["root","factory","exports","module","define","amd","globalThis","window","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","editor","opts","options","id","label","block","props","style","styleAdditional","startTime","endText","dateInputType","labelDays","labelHours","labelMinutes","labelSeconds","classPrefix","pfx","Blocks","add","media","category","select","content","type","Components","addType","model","defaults","startfrom","classes","droppable","script","endTxt","el","countDownDate","Date","getTime","countdownEl","querySelector","endTextEl","dayEl","hourEl","minuteEl","secondEl","oldInterval","__gjsCountdownInterval","clearInterval","connected","__gjsCountdownIntervals","toClean","forEach","item","isConnected","push","indexOf","filter","setTimer","days","hours","minutes","seconds","innerHTML","moveTimer","now","distance","Math","floor","display","setInterval","traits","name","changeProp","components","styles"],"sourceRoot":""}