pinafore/static/inline-script.js.map

1 line
6.1 KiB
Plaintext

{"version":3,"file":"inline-script.js","sources":["src/routes/_utils/themeEngine.js","inline-script.js","src/routes/_utils/testStorage.js"],"sourcesContent":["let meta = process.browser && document.getElementById('theThemeColor')\nlet offlineStyle = process.browser && document.getElementById('theOfflineStyle')\n\nfunction getExistingThemeLink () {\n return document.head.querySelector('link[rel=stylesheet][href^=\"/theme-\"]')\n}\n\nfunction resetExistingTheme () {\n let existingLink = getExistingThemeLink()\n if (existingLink) {\n document.head.removeChild(existingLink)\n }\n}\n\nfunction loadCSS (href) {\n let existingLink = getExistingThemeLink()\n\n let link = document.createElement('link')\n link.rel = 'stylesheet'\n link.href = href\n\n link.addEventListener('load', function onload () {\n link.removeEventListener('load', onload)\n if (existingLink) { // remove after load to avoid flash of default theme\n document.head.removeChild(existingLink)\n }\n })\n\n // inserting before the offline <style> ensures that the offline style wins when offline\n document.head.insertBefore(link, offlineStyle)\n}\n\nexport function switchToTheme (themeName) {\n let themeColor = window.__themeColors[themeName]\n meta.content = themeColor || window.__themeColors['default']\n if (themeName !== 'default') {\n loadCSS(`/theme-${themeName}.css`)\n } else {\n resetExistingTheme()\n }\n}\n","// For perf reasons, this script is run inline to quickly set certain styles.\n// To allow CSP to work correctly, we also calculate a sha256 hash during\n// the build process and write it to inline-script-checksum.json.\n\nimport { testHasLocalStorageOnce } from './src/routes/_utils/testStorage'\nimport { switchToTheme } from './src/routes/_utils/themeEngine'\n\nwindow.__themeColors = process.env.THEME_COLORS\n\nconst hasLocalStorage = testHasLocalStorageOnce()\n\nif (hasLocalStorage && localStorage.store_currentInstance && localStorage.store_instanceThemes) {\n let safeParse = (str) => str === 'undefined' ? undefined : JSON.parse(str)\n let theme = safeParse(localStorage.store_instanceThemes)[safeParse(localStorage.store_currentInstance)]\n if (theme && theme !== 'default') {\n switchToTheme(theme)\n }\n}\n\nif (!hasLocalStorage || !localStorage.store_currentInstance) {\n // if not logged in, show all these 'hidden-from-ssr' elements\n let style = document.createElement('style')\n style.textContent = '.hidden-from-ssr { opacity: 1 !important; }'\n document.head.appendChild(style)\n}\n\nif (hasLocalStorage && localStorage.store_disableCustomScrollbars === 'true') {\n // if user has disabled custom scrollbars, remove this style\n let theScrollbarStyle = document.getElementById('theScrollbarStyle')\n theScrollbarStyle.setAttribute('media', 'only x') // disables the style\n}\n\n// hack to make the scrollbars rounded only on macOS\nif (/mac/i.test(navigator.platform)) {\n document.documentElement.style.setProperty('--scrollbar-border-radius', '50px')\n}\n\n// TODO: remove this hack when Safari works with cross-origin window.open()\n// in a PWA: https://github.com/nolanlawson/pinafore/issues/45\nif (/iP(?:hone|ad|od)/.test(navigator.userAgent)) {\n document.head.removeChild(document.getElementById('theManifest'))\n}\n","// LocalStorage and IDB may be disabled in private mode, when \"blocking cookies\" in Safari,\n// or other cases\n\nimport { thunk } from './thunk'\n\nconst testKey = '__test__'\n\nexport const testHasLocalStorageOnce = () => {\n try {\n localStorage.setItem(testKey, testKey)\n if (!localStorage.length || localStorage.getItem(testKey) !== testKey) {\n return false\n }\n localStorage.removeItem(testKey)\n } catch (e) {\n return false\n }\n return true\n}\n\nexport const testHasLocalStorage = thunk(testHasLocalStorageOnce)\n\nexport const testHasIndexedDB = thunk(async () => {\n if (typeof indexedDB === 'undefined') {\n return false\n }\n\n try {\n let idbFailed = await new Promise(resolve => {\n let db = indexedDB.open(testKey)\n db.onerror = () => resolve(true)\n db.onsuccess = () => {\n indexedDB.deleteDatabase(testKey)\n resolve(false)\n }\n })\n if (idbFailed) {\n return false\n }\n } catch (e) {\n return false\n }\n return true\n})\n"],"names":["meta","document","getElementById","offlineStyle","getExistingThemeLink","head","querySelector","window","__themeColors","hasLocalStorage","localStorage","setItem","length","getItem","removeItem","e","testHasLocalStorageOnce","store_currentInstance","store_instanceThemes","safeParse","str","undefined","JSON","parse","theme","themeName","themeColor","content","href","existingLink","link","createElement","rel","addEventListener","onload","removeEventListener","removeChild","insertBefore","loadCSS","resetExistingTheme","switchToTheme","style","textContent","appendChild","store_disableCustomScrollbars","setAttribute","test","navigator","platform","documentElement","setProperty","userAgent"],"mappings":"yBAAA,IAAIA,EAAOC,SAA4BC,eAAe,iBAClDC,EAAeF,SAA4BC,eAAe,mBAE9D,SAASE,IACP,OAAOH,SAASI,KAAKC,cAAc,yCCGrCC,OAAOC,cAAgB,0PAEvB,MAAMC,ECFiC,MACrC,IAEE,GADAC,aAAaC,QAJD,WAAA,aAKPD,aAAaE,QALN,aAKgBF,aAAaG,QAL7B,YAMV,OAAO,EAETH,aAAaI,WARD,YASZ,MAAOC,GACP,OAAO,EAET,OAAO,GDReC,GAExB,GAAIP,GAAmBC,aAAaO,uBAAyBP,aAAaQ,qBAAsB,CAC9F,IAAIC,EAAaC,GAAgB,cAARA,OAAsBC,EAAYC,KAAKC,MAAMH,GAClEI,EAAQL,EAAUT,aAAaQ,sBAAsBC,EAAUT,aAAaO,wBAC5EO,GAAmB,YAAVA,GDkBR,SAAwBC,GAC7B,IAAIC,EAAanB,OAAOC,cAAciB,GACtCzB,EAAK2B,QAAUD,GAAcnB,OAAOC,cAAuB,QACzC,YAAdiB,EArBN,SAAkBG,GAChB,IAAIC,EAAezB,IAEf0B,EAAO7B,SAAS8B,cAAc,QAClCD,EAAKE,IAAM,aACXF,EAAKF,KAAOA,EAEZE,EAAKG,iBAAiB,OAAQ,SAASC,IACrCJ,EAAKK,oBAAoB,OAAQD,GAC7BL,GACF5B,SAASI,KAAK+B,YAAYP,KAK9B5B,SAASI,KAAKgC,aAAaP,EAAM3B,GAO/BmC,WAAkBb,SA7BtB,WACE,IAAII,EAAezB,IACfyB,GACF5B,SAASI,KAAK+B,YAAYP,GA4B1BU,GCvBAC,CAAchB,GAIlB,IAAKf,IAAoBC,aAAaO,sBAAuB,CAE3D,IAAIwB,EAAQxC,SAAS8B,cAAc,SACnCU,EAAMC,YAAc,8CACpBzC,SAASI,KAAKsC,YAAYF,GAG5B,GAAIhC,GAAkE,SAA/CC,aAAakC,8BAA0C,CAEpD3C,SAASC,eAAe,qBAC9B2C,aAAa,QAAS,UAItC,OAAOC,KAAKC,UAAUC,WACxB/C,SAASgD,gBAAgBR,MAAMS,YAAY,4BAA6B,QAKtE,mBAAmBJ,KAAKC,UAAUI,YACpClD,SAASI,KAAK+B,YAAYnC,SAASC,eAAe"}