{"version":3,"file":"withSx-CumpXk8y.cjs","sources":["../src/utils/cx.ts","../src/utils/NoncedStyle.tsx","../src/components/Layout/sx.ts","../src/utils/withSx.tsx"],"sourcesContent":["export type CxInput = string | false | null | undefined;\n\nexport function cx(...args: CxInput[]): string {\n  return args.filter(Boolean).join(' ');\n}\n","'use client';\n\nimport { useCspNonce } from '../components/CspNonce/CspNonceProvider';\n\n/**\n * A `<style>` element carrying the CSP nonce from the nearest\n * `CspNonceProvider` (none → no nonce attribute, exactly as before). Every\n * scoped stylesheet the library emits renders through this so it passes a\n * nonce-based `style-src-elem` policy.\n */\nexport function NoncedStyle({ css }: { css: string }) {\n  const nonce = useCspNonce();\n  // `css` is library-generated, never raw user input: resolveSx strips\n  // characters that could break out of the <style> context, and CannyLoader's\n  // sheet only interpolates useId() values scrubbed to [a-zA-Z0-9_-].\n  // suppressHydrationWarning: browsers hide a parsed element's nonce attribute (it reads back as \"\"),\n  // so React 18 would report a nonce mismatch on every server-rendered sheet. The sheet was already\n  // applied with the real nonce; only the attribute comparison differs.\n  return <style nonce={nonce} suppressHydrationWarning dangerouslySetInnerHTML={{ __html: css }} />;\n}\n","'use client';\nimport type { CSSProperties } from 'react';\n\n/** Responsive breakpoint keys. `base` has no media query (applies at all widths). */\nexport type Breakpoint = 'base' | 'sm' | 'md' | 'lg' | 'xl';\n\n/** Mobile-first min-width breakpoints (px). Mirrors the common sm/md/lg/xl scale. */\nexport const BREAKPOINTS: Record<Exclude<Breakpoint, 'base'>, number> = {\n  sm: 640,\n  md: 768,\n  lg: 1024,\n  xl: 1280,\n};\n\nconst BP_ORDER: Breakpoint[] = ['base', 'sm', 'md', 'lg', 'xl'];\n\ntype CSSValue = string | number | undefined;\ntype Responsive<T> = T | Partial<Record<Breakpoint, T>>;\n\n/**\n * MUI-like style object: any CSS property, each value either a scalar or a\n * responsive map keyed by breakpoint, e.g.\n * `sx={{ padding: 8, gridTemplateColumns: { base: '1fr', lg: '3fr 1fr' } }}`.\n */\nexport type SxProp = {\n  [K in keyof CSSProperties]?: Responsive<CSSProperties[K]>;\n};\n\n/** React's unitless CSS properties — numeric values here are NOT suffixed with px. */\nconst UNITLESS = new Set([\n  'animationIterationCount', 'aspectRatio', 'columnCount', 'flex', 'flexGrow',\n  'flexShrink', 'fontWeight', 'gridArea', 'gridColumn', 'gridColumnEnd',\n  'gridColumnStart', 'gridRow', 'gridRowEnd', 'gridRowStart', 'lineHeight',\n  'opacity', 'order', 'orphans', 'widows', 'zIndex', 'zoom', 'scale',\n]);\n\nconst isResponsive = (v: unknown): v is Partial<Record<Breakpoint, CSSValue>> =>\n  v !== null && typeof v === 'object' && !Array.isArray(v);\n\nconst kebab = (prop: string): string =>\n  prop.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).replace(/^ms-/, '-ms-');\n\n// Strip characters that could break out of the CSS/<style> context (e.g. a\n// literal `</style>`). `<`/`>` are never valid in the CSS values we support, so\n// removing them defends against injection if an sx value ever carries untrusted\n// data, without pulling in a sanitizer dependency.\nconst sanitize = (s: string): string => s.replace(/[<>]/g, '');\n\nconst cssValue = (prop: string, value: CSSValue): string => {\n  if (typeof value === 'number' && value !== 0 && !UNITLESS.has(prop)) return `${value}px`;\n  return sanitize(String(value));\n};\n\nconst declBlock = (decls: Record<string, CSSValue>): string =>\n  Object.entries(decls)\n    .filter(([, v]) => v !== undefined)\n    .map(([k, v]) => `${kebab(k)}:${cssValue(k, v)};`)\n    .join('');\n\n// djb2 → base36. Deterministic so server and client generate the same class (no\n// hydration mismatch) without any runtime registry.\nconst hash = (str: string): string => {\n  let h = 5381;\n  for (let i = 0; i < str.length; i++) h = ((h << 5) + h + str.charCodeAt(i)) | 0;\n  return (h >>> 0).toString(36);\n};\n\nexport interface SxResult {\n  /** Inline style for all-scalar sx. */\n  style?: CSSProperties;\n  /** Generated class for responsive sx. */\n  className?: string;\n  /** CSS text (base rules + min-width @media blocks) to inject in a <style>. */\n  css?: string;\n}\n\n/**\n * Resolve an `sx` object into what a component needs to render:\n * - All-scalar sx → merged into inline `style` (no <style> element needed).\n * - Any responsive value → a deterministic hashed class plus a `css` string of\n *   base rules and min-width @media blocks. The hash is content-derived, so SSR\n *   and client output match exactly.\n */\nexport function resolveSx(sx: SxProp): SxResult {\n  const scalar: Record<string, CSSValue> = {};\n  const byBp: Record<Breakpoint, Record<string, CSSValue>> = {\n    base: {}, sm: {}, md: {}, lg: {}, xl: {},\n  };\n  let responsive = false;\n\n  for (const [prop, val] of Object.entries(sx)) {\n    if (isResponsive(val)) {\n      responsive = true;\n      for (const bp of BP_ORDER) {\n        const v = (val as Record<string, CSSValue>)[bp];\n        if (v !== undefined) byBp[bp][prop] = v;\n      }\n    } else {\n      scalar[prop] = val as CSSValue;\n    }\n  }\n\n  if (!responsive) {\n    return { style: scalar as CSSProperties };\n  }\n\n  // Scalars apply at every width → fold into the base block.\n  Object.assign(byBp.base, scalar);\n\n  // Serialize deterministically for a stable hash/class.\n  const keyParts: string[] = [];\n  for (const bp of BP_ORDER) {\n    const block = declBlock(byBp[bp]);\n    if (block) keyParts.push(`${bp}{${block}}`);\n  }\n  const cls = `cny-sx-${hash(keyParts.join(''))}`;\n\n  let css = '';\n  for (const bp of BP_ORDER) {\n    const block = declBlock(byBp[bp]);\n    if (!block) continue;\n    css += bp === 'base'\n      ? `.${cls}{${block}}`\n      : `@media (min-width:${BREAKPOINTS[bp as Exclude<Breakpoint, 'base'>]}px){.${cls}{${block}}}`;\n  }\n\n  return { className: cls, css };\n}\n","import { Children, cloneElement } from 'react';\nimport type { CSSProperties, ReactElement, ReactNode } from 'react';\nimport { cx } from './cx';\nimport { NoncedStyle } from './NoncedStyle';\nimport { resolveSx } from '../components/Layout/sx';\nimport type { SxProp } from '../components/Layout/sx';\n\nexport interface WithSxResult {\n  /** Merged class names (base classes + generated responsive-sx class). */\n  className: string;\n  /** Inline style (scalar sx + any explicit style; explicit style wins). */\n  style: CSSProperties | undefined;\n  /** Scoped <style> element for responsive sx, or null. Render inside the root. */\n  styleTag: ReactElement | null;\n}\n\n/**\n * Resolve an `sx` prop for a component that isn't built on `Box`.\n *\n * Standardizes the same behavior `Box` has: scalar sx → inline style; responsive\n * sx → a content-hashed class + a scoped `<style>` (SSR-safe). Pass the base\n * class names last; the generated sx class is appended so it wins the cascade.\n *\n * @example\n * const { className, style, styleTag } = withSx(sx, style, 'card', color);\n * return <div className={className} style={style}>{styleTag}{children}</div>;\n */\nexport function withSx(\n  sx: SxProp | undefined,\n  style: CSSProperties | undefined,\n  ...classNames: (string | false | null | undefined)[]\n): WithSxResult {\n  const r = sx ? resolveSx(sx) : undefined;\n  return {\n    className: cx(...classNames, r?.className),\n    style:\n      r?.style || style\n        ? { ...(r?.style as CSSProperties), ...(style as CSSProperties) }\n        : undefined,\n    styleTag: r?.css ? <NoncedStyle css={r.css} /> : null,\n  };\n}\n\n/**\n * Children for a primitive that may render `asChild`, with `withSx`'s styleTag placed\n * inside the rendered element. With no styleTag the children pass through untouched,\n * so a Slot still receives its single child; with `asChild` the tag goes inside that\n * child, ahead of the child's own children.\n */\nexport function withStyleTag(\n  children: ReactNode,\n  styleTag: ReactElement | null,\n  asChild?: boolean,\n): ReactNode {\n  if (!styleTag) return children;\n  if (!asChild) return <>{styleTag}{children}</>;\n  const child = Children.only(children) as ReactElement<{ children?: ReactNode }>;\n  return cloneElement(child, undefined, <>{styleTag}{child.props.children}</>);\n}\n"],"names":["cx","args","NoncedStyle","css","nonce","useCspNonce","jsx","BREAKPOINTS","BP_ORDER","UNITLESS","isResponsive","v","kebab","prop","m","sanitize","s","cssValue","value","declBlock","decls","k","hash","str","h","i","resolveSx","sx","scalar","byBp","responsive","val","bp","keyParts","block","cls","withSx","style","classNames","r","withStyleTag","children","styleTag","asChild","jsxs","Fragment","child","Children","cloneElement"],"mappings":"+HAEO,SAASA,KAAMC,EAAyB,CAC7C,OAAOA,EAAK,OAAO,OAAO,EAAE,KAAK,GAAG,CACtC,CCMO,SAASC,EAAY,CAAE,IAAAC,GAAwB,CACpD,MAAMC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