UNPKG

8.58 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../../client/dev/dev-build-watcher.js"],"names":["initializeBuildWatcher","toggleCallback","shadowHost","document","createElement","id","style","position","bottom","right","width","height","zIndex","body","appendChild","shadowRoot","prefix","attachShadow","mode","container","createContainer","css","createCss","isVisible","isBuilding","timeoutId","event","data","handleMessage","obj","action","JSON","parse","clearTimeout","updateContainer","setTimeout","classList","add","remove","innerHTML","textContent"],"mappings":"4EAAA,wDAEe,QAASA,CAAAA,sBAAT,CAAgCC,cAAhC,CAAgD,CAC7D,KAAMC,CAAAA,UAAU,CAAGC,QAAQ,CAACC,aAAT,CAAuB,KAAvB,CAAnB,CACAF,UAAU,CAACG,EAAX,CAAgB,sBAAhB,CACA;AACAH,UAAU,CAACI,KAAX,CAAiBC,QAAjB,CAA4B,OAA5B,CACAL,UAAU,CAACI,KAAX,CAAiBE,MAAjB,CAA0B,MAA1B,CACAN,UAAU,CAACI,KAAX,CAAiBG,KAAjB,CAAyB,MAAzB,CACAP,UAAU,CAACI,KAAX,CAAiBI,KAAjB,CAAyB,CAAzB,CACAR,UAAU,CAACI,KAAX,CAAiBK,MAAjB,CAA0B,CAA1B,CACAT,UAAU,CAACI,KAAX,CAAiBM,MAAjB,CAA0B,KAA1B,CACAT,QAAQ,CAACU,IAAT,CAAcC,WAAd,CAA0BZ,UAA1B,EAEA,GAAIa,CAAAA,UAAJ,CACA,GAAIC,CAAAA,MAAM,CAAG,EAAb,CAEA,GAAId,UAAU,CAACe,YAAf,CAA6B,CAC3BF,UAAU,CAAGb,UAAU,CAACe,YAAX,CAAwB,CAAEC,IAAI,CAAE,MAAR,CAAxB,CAAb,CACD,CAFD,IAEO,CACL;AACA;AACA;AACAH,UAAU,CAAGb,UAAb,CACAc,MAAM,CAAG,uBAAT,CACD,CAED;AACA,KAAMG,CAAAA,SAAS,CAAGC,eAAe,CAACJ,MAAD,CAAjC,CACAD,UAAU,CAACD,WAAX,CAAuBK,SAAvB,EAEA;AACA,K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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GArEE,CAuEA,MAAOK,CAAAA,GAAP,CACD","sourcesContent":["import { addMessageListener } from './error-overlay/eventsource'\n\nexport default function initializeBuildWatcher(toggleCallback) {\n const shadowHost = document.createElement('div')\n shadowHost.id = '__next-build-watcher'\n // Make sure container is fixed and on a high zIndex so it shows\n shadowHost.style.position = 'fixed'\n shadowHost.style.bottom = '10px'\n shadowHost.style.right = '20px'\n shadowHost.style.width = 0\n shadowHost.style.height = 0\n shadowHost.style.zIndex = 99999\n document.body.appendChild(shadowHost)\n\n let shadowRoot\n let prefix = ''\n\n if (shadowHost.attachShadow) {\n shadowRoot = shadowHost.attachShadow({ mode: 'open' })\n } else {\n // If attachShadow is undefined then the browser does not support\n // the Shadow DOM, we need to prefix all the names so there\n // will be no conflicts\n shadowRoot = shadowHost\n prefix = '__next-build-watcher-'\n }\n\n // Container\n const container = createContainer(prefix)\n shadowRoot.appendChild(container)\n\n // CSS\n const css = createCss(prefix)\n shadowRoot.appendChild(css)\n\n // State\n let isVisible = false\n let isBuilding = false\n let timeoutId = null\n\n // Handle events\n\n addMessageListener((event) => {\n // This is the heartbeat event\n if (event.data === '\\uD83D\\uDC93') {\n return\n }\n\n try {\n handleMessage(event)\n } catch {}\n })\n\n function handleMessage(event) {\n const obj =\n typeof event === 'string' ? { action: event } : JSON.parse(event.data)\n\n // eslint-disable-next-line default-case\n switch (obj.action) {\n case 'building':\n timeoutId && clearTimeout(timeoutId)\n isVisible = true\n isBuilding = true\n updateContainer()\n break\n case 'built':\n case 'sync':\n isBuilding = false\n // Wait for the fade out transition to complete\n timeoutId = setTimeout(() => {\n isVisible = false\n updateContainer()\n }, 100)\n updateContainer()\n break\n }\n }\n\n toggleCallback(handleMessage)\n\n function updateContainer() {\n if (isBuilding) {\n container.classList.add(`${prefix}building`)\n } else {\n container.classList.remove(`${prefix}building`)\n }\n\n if (isVisible) {\n container.classList.add(`${prefix}visible`)\n } else {\n container.classList.remove(`${prefix}visible`)\n }\n }\n}\n\nfunction createContainer(prefix) {\n const container = document.createElement('div')\n container.id = `${prefix}container`\n container.innerHTML = `\n <div id=\"${prefix}icon-wrapper\">\n <svg viewBox=\"0 0 226 200\">\n <defs>\n <linearGradient\n x1=\"114.720775%\"\n y1=\"181.283245%\"\n x2=\"39.5399306%\"\n y2=\"100%\"\n id=\"${prefix}linear-gradient\"\n >\n <stop stop-color=\"#000000\" offset=\"0%\" />\n <stop stop-color=\"#FFFFFF\" offset=\"100%\" />\n </linearGradient>\n </defs>\n <g id=\"${prefix}icon-group\" fill=\"none\" stroke=\"url(#${prefix}linear-gradient)\" stroke-width=\"18\">\n <path d=\"M113,5.08219117 L4.28393801,197.5 L221.716062,197.5 L113,5.08219117 Z\" />\n </g>\n </svg>\n </div>\n `\n\n return container\n}\n\nfunction createCss(prefix) {\n const css = document.createElement('style')\n css.textContent = `\n #${prefix}container {\n position: absolute;\n bottom: 10px;\n right: 30px;\n\n border-radius: 3px;\n background: #000;\n color: #fff;\n font: initial;\n cursor: initial;\n letter-spacing: initial;\n text-shadow: initial;\n text-transform: initial;\n visibility: initial;\n\n padding: 7px 10px 8px 10px;\n align-items: center;\n box-shadow: 0 11px 40px 0 rgba(0, 0, 0, 0.25), 0 2px 10px 0 rgba(0, 0, 0, 0.12);\n\n display: none;\n opacity: 0;\n transition: opacity 0.1s ease, bottom 0.1s ease;\n animation: ${prefix}fade-in 0.1s ease-in-out;\n }\n\n #${prefix}container.${prefix}visible {\n display: flex;\n }\n\n #${prefix}container.${prefix}building {\n bottom: 20px;\n opacity: 1;\n }\n\n #${prefix}icon-wrapper {\n width: 16px;\n height: 16px;\n }\n\n #${prefix}icon-wrapper > svg {\n width: 100%;\n height: 100%;\n }\n\n #${prefix}icon-group {\n animation: ${prefix}strokedash 1s ease-in-out both infinite;\n }\n\n @keyframes ${prefix}fade-in {\n from {\n bottom: 10px;\n opacity: 0;\n }\n to {\n bottom: 20px;\n opacity: 1;\n }\n }\n\n @keyframes ${prefix}strokedash {\n 0% {\n stroke-dasharray: 0 226;\n }\n 80%,\n 100% {\n stroke-dasharray: 659 226;\n }\n }\n `\n\n return css\n}\n"]}
\No newline at end of file