@volvo-cars/css
Version:
Volvo Cars shared CSS
1 lines • 3.34 kB
Source Map (JSON)
{"version":3,"sources":["../src/links.server.ts"],"sourcesContent":["// @ts-ignore\nimport fontFaceCss from './font-face.base64css';\nimport cssImports from './imports.json' assert { type: 'json' };\nimport { defaultBase } from './links/constants';\nimport { createFilter } from './links/create-filter';\nimport { getMediaQuery } from './links/get-media-query';\nimport type { LinkProps, LinksFunction } from './links/types';\n\nexport const links: LinksFunction = ({ base = defaultBase, filter } = {}) => {\n if (base && typeof base !== 'string') {\n base = base.href;\n }\n if (typeof base === 'string' && base !== '' && !base.endsWith('/')) {\n base += '/';\n }\n const linkProps = Object.entries(cssImports)\n .filter(createFilter(filter))\n .flatMap(([name, filename]) => {\n const props: LinkProps = {\n href: base + filename,\n rel: 'stylesheet',\n crossOrigin: 'anonymous',\n };\n const media = getMediaQuery(name);\n if (media) {\n props.media = media;\n }\n\n const preloadProps = {\n ...props,\n rel: 'preload',\n as: 'style',\n };\n\n props['data-volvo-css-name'] = name;\n\n // Return @font-face rules as base64 encoded inline CSS to start downloading fonts earlier,\n // improving LCP.\n if (name === 'font-face.css' && filter?.preload !== false) {\n return {\n ...props,\n href: `data:text/css;base64,${fontFaceCss}`,\n };\n }\n if (filter?.preload === false) {\n return props;\n } else {\n return [preloadProps, props] as const;\n }\n })\n .sort((a, b) =>\n a.rel === 'preload' && b.rel === 'preload'\n ? 0\n : a.rel === 'preload'\n ? -1\n : 1\n ) as LinkProps[];\n\n linkProps.toString = function toString() {\n let html = '';\n for (const link of this) {\n const attrs = Object.entries(link)\n .map(([key, value]) => `${key}=\"${value}\"`)\n .join(' ');\n html += `<link ${attrs} />\\n`;\n }\n return html;\n };\n\n return linkProps;\n};\n\nexport type { LinksFunction, LinkProps };\n"],"mappings":"srIAQO,IAAMA,EAAuB,CAAC,CAAE,KAAAC,EAAOC,EAAa,OAAAC,CAAO,EAAI,CAAC,IAAM,CACvEF,GAAQ,OAAOA,GAAS,WAC1BA,EAAOA,EAAK,MAEV,OAAOA,GAAS,UAAYA,IAAS,IAAM,CAACA,EAAK,SAAS,GAAG,IAC/DA,GAAQ,KAEV,IAAMG,EAAY,OAAO,QAAQC,CAAU,EACxC,OAAOC,EAAaH,CAAM,CAAC,EAC3B,QAAQ,CAAC,CAACI,EAAMC,CAAQ,IAAM,CAC7B,IAAMC,EAAmB,CACvB,KAAMR,EAAOO,EACb,IAAK,aACL,YAAa,WACf,EACME,EAAQC,EAAcJ,CAAI,EAC5BG,IACFD,EAAM,MAAQC,GAGhB,IAAME,EAAe,CACnB,GAAGH,EACH,IAAK,UACL,GAAI,OACN,EAMA,OAJAA,EAAM,qBAAqB,EAAIF,EAI3BA,IAAS,iBAAmBJ,GAAQ,UAAY,GAC3C,CACL,GAAGM,EACH,KAAM,wBAAwBI,CAAW,EAC3C,EAEEV,GAAQ,UAAY,GACfM,EAEA,CAACG,EAAcH,CAAK,CAE/B,CAAC,EACA,KAAK,CAACK,EAAGC,IACRD,EAAE,MAAQ,WAAaC,EAAE,MAAQ,UAC7B,EACAD,EAAE,MAAQ,UACV,GACA,CACN,EAEF,OAAAV,EAAU,SAAW,UAAoB,CACvC,IAAIY,EAAO,GACX,QAAWC,KAAQ,KAAM,CACvB,IAAMC,EAAQ,OAAO,QAAQD,CAAI,EAC9B,IAAI,CAAC,CAACE,EAAKC,CAAK,IAAM,GAAGD,CAAG,KAAKC,CAAK,GAAG,EACzC,KAAK,GAAG,EACXJ,GAAQ,SAASE,CAAK;AAAA,CACxB,CACA,OAAOF,CACT,EAEOZ,CACT","names":["links","base","defaultBase","filter","linkProps","imports_default","createFilter","name","filename","props","media","getMediaQuery","preloadProps","font_face_default","a","b","html","link","attrs","key","value"]}