{"version":3,"file":"chunk-Icon.mjs","names":[],"sources":["../../src/hooks/useIconHref.ts","../../src/components/Icon/Icon.tsx"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback, useSyncExternalStore } from 'react';\n\nimport { useIconRegistry } from '../providers/ThemeProvider/icon-registry.ts';\n\n/**\n * Resolves an icon name to a same-document `<use href>`.\n *\n * Returns `undefined` while the icon is not yet present in the in-DOM sprite — kicking off\n * a runtime fetch as a side effect. Once the registry has the symbol (either because the\n * static sprite finished ingesting or because the resolver injected it), the component\n * re-renders via `useSyncExternalStore` and we return `#name`.\n */\nexport const useIconHref = (icon?: string) => {\n  const registry = useIconRegistry();\n\n  const subscribe = useCallback((listener: () => void) => registry.subscribe(listener), [registry]);\n  const getSnapshot = useCallback(() => (icon ? registry.hasIcon(icon) : false), [icon, registry]);\n  const getServerSnapshot = useCallback(() => false, []);\n\n  const hasIcon = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n\n  if (!icon) {\n    return undefined;\n  }\n\n  if (!hasIcon) {\n    registry.requestIcon(icon);\n    return undefined;\n  }\n\n  return `#${icon}`;\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport React, { type SVGProps, forwardRef, useMemo } from 'react';\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ChromaticPalette, type MessageValence, type NeutralPalette, type ThemedClassName } from '@dxos/ui-types';\n\nimport { useIconHref } from '../../hooks/useIconHref.ts';\nimport { recipes } from '../../recipes.ts';\nimport { type Size } from '../../sizes.ts';\n\nexport type IconHue = NeutralPalette | ChromaticPalette | MessageValence;\n\nexport type IconValence = MessageValence;\n\n/** Text emphasis below the default, as Typography's `tone`. */\nexport type IconTone = 'muted' | 'subtle';\n\nexport type IconProps = ThemedClassName<Omit<SVGProps<SVGSVGElement>, 'ref'>> & {\n  icon: string;\n  /** Names the icon for assistive tech; without it the icon is decorative and hidden. */\n  label?: string;\n  /** Colours the glyph with a Tag hue's foreground (`--color-<hue>-fg`). */\n  hue?: IconHue;\n  /** Colours the glyph with a valence's semantic text colour (`--color-<valence>-text`); takes precedence over `hue`. */\n  valence?: IconValence;\n  /** A lower-emphasis colour (`--color-fg-muted` or `--color-fg-subtle`); `hue` and `valence` take precedence. */\n  tone?: IconTone;\n  /**\n   * Rotates continuously, as a busy indicator; still under `prefers-reduced-motion`. Spinners share one phase (the\n   * animation starts at the wall clock's second), so several in a list turn together.\n   */\n  spin?: boolean;\n  /** The icon at this size's scale instead of its scope's (one icon in a denser or roomier control). */\n  size?: Size;\n};\n\nexport const Icon = forwardRef<SVGSVGElement, IconProps>(\n  ({ icon, label, hue, valence, tone, spin, size, classNames, style, ...props }, forwardedRef) => {\n    const href = useIconHref(icon);\n    // A negative delay of the wall clock's offset into the 1s turn puts every spinner at the same angle.\n    const spinDelay = useMemo(() => (spin ? `${-(Date.now() % 1_000)}ms` : undefined), [spin]);\n    return (\n      <svg\n        {...props}\n        style={spinDelay ? { ...style, animationDelay: spinDelay } : style}\n        {...(label ? { 'role': 'img', 'aria-label': label } : { 'aria-hidden': true })}\n        data-scope='icon'\n        data-part='root'\n        data-icon={icon}\n        data-hue={hue}\n        data-valence={valence}\n        data-tone={tone}\n        data-spin={spin ? '' : undefined}\n        data-icon-size={size}\n        className={mx(recipes.icon(), classNames)}\n        ref={forwardedRef}\n      >\n        <use href={href} />\n      </svg>\n    );\n  },\n);\n\nIcon.displayName = 'Icon';\n\nexport * from '../../hooks/useIconHref.ts';\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,IAAa,eAAe,SAAkB;CAC5C,MAAM,WAAW,gBAAgB;CAEjC,MAAM,YAAY,aAAa,aAAyB,SAAS,UAAU,QAAQ,GAAG,CAAC,QAAQ,CAAC;CAChG,MAAM,cAAc,kBAAmB,OAAO,SAAS,QAAQ,IAAI,IAAI,OAAQ,CAAC,MAAM,QAAQ,CAAC;CAC/F,MAAM,oBAAoB,kBAAkB,OAAO,CAAC,CAAC;CAErD,MAAM,UAAU,qBAAqB,WAAW,aAAa,iBAAiB;CAE9E,IAAI,CAAC,MACH;CAGF,IAAI,CAAC,SAAS;EACZ,SAAS,YAAY,IAAI;EACzB;CACF;CAEA,OAAO,IAAI;AACb;;;;;;;ACMA,IAAa,OAAO,YACjB,EAAE,MAAM,OAAO,KAAK,SAAS,MAAM,MAAM,MAAM,YAAY,OAAO,GAAG,SAAS,iBAAiB;CAC9F,MAAM,OAAO,YAAY,IAAI;CAE7B,MAAM,YAAY,cAAe,OAAO,GAAG,EAAE,KAAK,IAAI,IAAI,KAAO,MAAM,KAAA,GAAY,CAAC,IAAI,CAAC;CACzF,OACE,oBAAC,OAAD;EACE,GAAI;EACJ,OAAO,YAAY;GAAE,GAAG;GAAO,gBAAgB;EAAU,IAAI;EAC7D,GAAK,QAAQ;GAAE,QAAQ;GAAO,cAAc;EAAM,IAAI,EAAE,eAAe,KAAK;EAC5E,cAAW;EACX,aAAU;EACV,aAAW;EACX,YAAU;EACV,gBAAc;EACd,aAAW;EACX,aAAW,OAAO,KAAK,KAAA;EACvB,kBAAgB;EAChB,WAAW,GAAG,QAAQ,KAAK,GAAG,UAAU;EACxC,KAAK;EAEL,UAAA,oBAAC,OAAD,EAAW,KAAO,CAAA;CACf,CAAA;AAET,CACF;AAEA,KAAK,cAAc"}