UNPKG

@volvo-cars/css

Version:
1 lines 2.24 kB
{"version":3,"sources":["../src/links.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"],"mappings":"yFAMO,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,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","base","defaultBase","filter","linkProps","imports_default","createFilter","name","filename","props","media","getMediaQuery","html","link","attrs","key","value"]}