UNPKG

@volvo-cars/css

Version:
1 lines 4.3 kB
{"version":3,"sources":["../src/links.ts","../src/imports.json","../src/links/constants.ts","../src/links/create-filter.ts","../src/media-queries.ts","../src/links/get-media-query.ts"],"sourcesContent":["import 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 .map(([name, filename]) => {\n const props = {\n rel: 'stylesheet',\n href: base + filename,\n 'data-volvo-css-name': name,\n crossOrigin: 'anonymous',\n } as LinkProps;\n const media = getMediaQuery(name);\n if (media) {\n props.media = media;\n }\n return props;\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 return linkProps;\n};\n\nexport type { LinksFunction, LinkProps };\n","{\n \"font-face.css\": \"css/v1/font-face.05a7ed4c.css\",\n \"tokens.css\": \"css/v1/tokens.a3299985.css\",\n \"styles.css\": \"css/v1/styles.831ef042.css\",\n \"styles_md.css\": \"css/v1/styles_md.ff85772e.css\",\n \"styles_xl.css\": \"css/v1/styles_xl.477cb2f4.css\",\n \"styles_hover.css\": \"css/v1/styles_hover.3fbd1ade.css\"\n}","export const defaultBase = 'https://www.volvocars.com/static/shared/pkg/';\n","export interface LinksFilter {\n preload?: boolean;\n fonts?: boolean;\n tokens?: boolean;\n}\n\nexport function createFilter({\n fonts = true,\n tokens = true,\n}: LinksFilter = {}) {\n return ([name]: [string, string]) => {\n if (name === 'font-face.css') return fonts;\n if (name.endsWith('tokens.css')) return tokens;\n return true;\n };\n}\n","const queries = {\n hover: '(hover: hover)',\n md: '(min-width: 30rem)',\n lg: '(min-width: 64rem)',\n xl: '(min-width: 100rem)',\n} as const;\n\nexport default queries;\n","import mediaQueries from '../media-queries';\n\nexport function getMediaQuery(name: string) {\n let suffix = name.split('_').pop()?.replace('.css', '');\n return mediaQueries[suffix as keyof typeof mediaQueries];\n}\n"],"mappings":"4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,WAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAA,CACE,gBAAiB,gCACjB,aAAc,6BACd,aAAc,6BACd,gBAAiB,gCACjB,gBAAiB,gCACjB,mBAAoB,kCACtB,ECPO,IAAMC,EAAc,+CCMpB,SAASC,EAAa,CAC3B,MAAAC,EAAQ,GACR,OAAAC,EAAS,EACX,EAAiB,CAAC,EAAG,CACnB,MAAO,CAAC,CAACC,CAAI,IACPA,IAAS,gBAAwBF,EACjCE,EAAK,SAAS,YAAY,EAAUD,EACjC,EAEX,CCfA,IAAME,EAAU,CACd,MAAO,iBACP,GAAI,qBACJ,GAAI,qBACJ,GAAI,qBACN,EAEOC,EAAQD,ECLR,SAASE,EAAcC,EAAc,CAC1C,IAAIC,EAASD,EAAK,MAAM,GAAG,EAAE,IAAI,GAAG,QAAQ,OAAQ,EAAE,EACtD,OAAOE,EAAaD,CAAmC,CACzD,CLCO,IAAME,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,IAAI,CAAC,CAACI,EAAMC,CAAQ,IAAM,CACzB,IAAMC,EAAQ,CACZ,IAAK,aACL,KAAMR,EAAOO,EACb,sBAAuBD,EACvB,YAAa,WACf,EACMG,EAAQC,EAAcJ,CAAI,EAChC,OAAIG,IACFD,EAAM,MAAQC,GAETD,CACT,CAAC,EACH,OAAAL,EAAU,SAAW,UAAoB,CACvC,IAAIQ,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,EACOR,CACT","names":["links_exports","__export","links","__toCommonJS","imports_default","defaultBase","createFilter","fonts","tokens","name","queries","media_queries_default","getMediaQuery","name","suffix","media_queries_default","links","base","defaultBase","filter","linkProps","imports_default","createFilter","name","filename","props","media","getMediaQuery","html","link","attrs","key","value"]}