{"version":3,"file":"css.cjs","names":[],"sources":["../src/css/load-css-file.ts","../src/css/to-rem.ts"],"sourcesContent":["import type { Maybe } from 'yummies/types';\n\n/**\n * Injects a stylesheet by appending a `<link rel=\"stylesheet\">` to `document.head`.\n * Resolves when the sheet fires `load`; rejects on `error` (e.g. 404 or network failure).\n *\n * **Id replacement:** if `attrubutes.id` is set, any existing element with that `id` is removed\n * first, so repeated calls with the same `id` replace the previous link (useful for theme or\n * font URLs that change).\n *\n * If `rel` is omitted in `attrubutes`, it defaults to `stylesheet`. Other attributes (`crossorigin`,\n * `media`, `data-*`, etc.) are set via `setAttribute` from the record entries.\n *\n * @param url - Stylesheet URL (`href`).\n * @param attrubutes - Optional HTML attributes for the `<link>` element (see `id` / `rel` behavior above).\n * @returns Promise that resolves to `undefined` on load, or rejects on load error.\n *\n * @example\n * ```ts\n * await loadCssFile('https://example.com/fonts.css', {\n *   id: 'app-fonts',\n *   crossOrigin: 'anonymous',\n * });\n * ```\n *\n * @example\n * ```ts\n * // Swap theme stylesheet without duplicate link tags\n * await loadCssFile('/themes/dark.css', { id: 'theme' });\n * await loadCssFile('/themes/light.css', { id: 'theme' });\n * ```\n */\nexport const loadCssFile = (url: string, attrubutes?: Record<string, any>) =>\n  new Promise((resolve, reject) => {\n    let link: Maybe<HTMLLinkElement>;\n\n    if (attrubutes?.id) {\n      link = document.getElementById(attrubutes.id) as HTMLLinkElement | null;\n\n      if (link) {\n        link.remove();\n      }\n    }\n\n    link = document.createElement('link');\n\n    const handleLoad = () => {\n      resolve(undefined);\n      link!.removeEventListener('load', handleLoad);\n      link!.removeEventListener('error', handleError);\n    };\n\n    const handleError = () => {\n      reject(undefined);\n      link!.removeEventListener('load', handleLoad);\n      link!.removeEventListener('error', handleError);\n    };\n\n    link.addEventListener('load', handleLoad);\n    link.addEventListener('error', handleError);\n\n    link.setAttribute('href', url);\n\n    if (!attrubutes?.rel) {\n      link.setAttribute('rel', 'stylesheet');\n    }\n\n    Object.entries(attrubutes || {}).forEach(([key, value]) => {\n      link.setAttribute(key, value);\n    });\n\n    document.head.appendChild(link);\n  });\n","/**\n * Converts a length in **pixels** to a CSS **`rem`** string (`\"<number>rem\"`).\n *\n * Use when authoring component styles in JS/TS where design tokens are in px but the stylesheet\n * should scale with root font size (accessibility, user zoom). `remValue` is the assumed\n * `1rem` size in px (browser default is typically `16`).\n *\n * Also you can override default rem value using `toRem.defaultRemValue = 24`\n *\n * @param px - Pixel value to convert (not rounded; stringification keeps full float).\n * @param remValue - How many pixels one `rem` equals. Defaults to `16`.\n * @returns A string like `\"1.5rem\"` suitable for `style` or CSS-in-JS.\n *\n * @example\n * ```ts\n * const width = toRem(24); // '1.5rem' with default 16px root\n * ```\n *\n * @example\n * ```ts\n * // Custom root / design system where 1rem === 10px\n * const gap = toRem(20, 10); // '2rem'\n * ```\n */\nexport const toRem = (px: number, remValue?: number): string =>\n  `${px / (remValue ?? toRem.defaultRemValue)}rem`;\n\ntoRem.defaultRemValue = 16;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,IAAa,eAAe,KAAa,eACvC,IAAI,SAAS,SAAS,WAAW;CAC/B,IAAI;CAEJ,IAAI,YAAY,IAAI;EAClB,OAAO,SAAS,eAAe,WAAW,EAAE;EAE5C,IAAI,MACF,KAAK,OAAO;CAEhB;CAEA,OAAO,SAAS,cAAc,MAAM;CAEpC,MAAM,mBAAmB;EACvB,QAAQ,KAAA,CAAS;EACjB,KAAM,oBAAoB,QAAQ,UAAU;EAC5C,KAAM,oBAAoB,SAAS,WAAW;CAChD;CAEA,MAAM,oBAAoB;EACxB,OAAO,KAAA,CAAS;EAChB,KAAM,oBAAoB,QAAQ,UAAU;EAC5C,KAAM,oBAAoB,SAAS,WAAW;CAChD;CAEA,KAAK,iBAAiB,QAAQ,UAAU;CACxC,KAAK,iBAAiB,SAAS,WAAW;CAE1C,KAAK,aAAa,QAAQ,GAAG;CAE7B,IAAI,CAAC,YAAY,KACf,KAAK,aAAa,OAAO,YAAY;CAGvC,OAAO,QAAQ,cAAc,CAAC,CAAC,EAAE,SAAS,CAAC,KAAK,WAAW;EACzD,KAAK,aAAa,KAAK,KAAK;CAC9B,CAAC;CAED,SAAS,KAAK,YAAY,IAAI;AAChC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AChDH,IAAa,SAAS,IAAY,aAChC,GAAG,MAAM,YAAY,MAAM,iBAAiB;AAE9C,MAAM,kBAAkB"}