MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / injectTailwindBrowserScript

Function injectTailwindBrowserScript

packages/cli/src/commands/init.ts:276–300  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

274}
275
276export function injectTailwindBrowserScript(html: string): string {
277 if (html.includes(TAILWIND_BROWSER_SRC)) return html;
278
279 const script = [
280 `<script>`,
281 `window.__tailwindReady=new Promise(function(resolve){`,
282 `var loaded=document.readyState==="complete";`,
283 `var resolved=false;`,
284 `var observer;`,
285 `function readTailwindCss(){var styles=document.querySelectorAll("style");for(var i=styles.length-1;i>=0;i--){var text=styles[i].textContent||"";if(text.indexOf("tailwindcss v")!==-1)return text;}return "";}`,
286 `function finish(){if(resolved||!loaded||!readTailwindCss())return;resolved=true;if(observer)observer.disconnect();resolve(true);}`,
287 `observer=new MutationObserver(finish);`,
288 `observer.observe(document.documentElement,{childList:true,subtree:true,characterData:true});`,
289 `if(loaded){finish();}else{window.addEventListener("load",function(){loaded=true;finish();},{once:true});}`,
290 `});`,
291 `</script>`,
292 `<script src="${TAILWIND_BROWSER_SRC}" integrity="${TAILWIND_BROWSER_INTEGRITY}" crossorigin="anonymous"></script>`,
293 ].join("\n");
294
295 if (/<\/head>/i.test(html)) {
296 return html.replace(/<\/head>/i, (closingHead) => `\n${script}\n${closingHead}`);
297 }
298
299 return `${script}\n${html}`;
300}
301
302function writeTailwindSupport(destDir: string): void {
303 for (const file of listHtmlFiles(destDir)) {

Callers 2

init.test.tsFile · 0.85
writeTailwindSupportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected