{"version":3,"file":"allianz-ng-aquila-surface.mjs","names":[],"sources":["../../../projects/ng-aquila/src/surface/surface-types.ts","../../../projects/ng-aquila/src/surface/inject-surface.ts","../../../projects/ng-aquila/src/surface/surface.ts"],"sourcesContent":["import { InjectionToken, Signal } from '@angular/core';\n\n/**\n * The surface a component is sitting on.\n *\n * - `default` - the neutral page or card surface.\n * - `attention` - the inverse, brand-colored surface.\n * - `emphasis` - the emphasis tint.\n * - `accent-attention` - one of the accent hues, see `NxSurfaceAccentColor`.\n *\n * A surface says what the background is, not what a component should do about\n * it - each component decides that for itself.\n */\nexport type NxSurfaceType = 'default' | 'attention' | 'emphasis' | 'accent-attention';\n\n/**\n * The value accepted by `[nxSurface]` - an {@link NxSurfaceType}, or `inherit` to keep\n * the enclosing surface instead of declaring a new one.\n */\nexport type NxSurfaceInputValue = NxSurfaceType | 'inherit';\n\n/** Accent hue. Only meaningful when the surface is `accent-attention`. */\nexport type NxSurfaceAccentColor =\n  'yellow' | 'orange' | 'red' | 'purple' | 'aqua' | 'blue' | 'teal' | 'green' | 'gray';\n\n/** The hue an `accent-attention` surface falls back to when it names none. */\nexport const NX_DEFAULT_SURFACE_ACCENT_COLOR: NxSurfaceAccentColor = 'blue';\n\n/** A surface together with its accent hue, which only the accent arm carries. */\nexport type NxResolvedSurface =\n  | { readonly surface: 'default' | 'attention' | 'emphasis' }\n  | { readonly surface: 'accent-attention'; readonly accentColor: NxSurfaceAccentColor };\n\n/** The value carried by {@link NX_SURFACE}. */\nexport interface NxSurfaceContext {\n  readonly resolved: Signal<NxResolvedSurface>;\n}\n\n/**\n * Context token published by containers that paint a non-default background.\n *\n * A container that paints its own background - an overlay panel, a card - must\n * stop the context at its boundary with\n * `providers: [{ provide: NX_SURFACE, useValue: undefined }]`, otherwise its\n * content would adapt to a surface it is no longer sitting on.\n */\nexport const NX_SURFACE = new InjectionToken<NxSurfaceContext | undefined>('NX_SURFACE');\n","import { computed, inject, Signal } from '@angular/core';\n\nimport { NX_SURFACE, NxResolvedSurface } from './surface-types';\n\n/** Stable identity, so the common case does not hand out a new object per read. */\nconst DEFAULT_SURFACE: NxResolvedSurface = { surface: 'default' };\n\n/**\n * The surface this component sits on, or `'default'` when no container published\n * one.\n *\n * Must be called in an injection context.\n */\nexport function injectSurface(): Signal<NxResolvedSurface> {\n  const context = inject(NX_SURFACE, { optional: true });\n\n  return computed(() => context?.resolved() ?? DEFAULT_SURFACE);\n}\n","import { booleanAttribute, computed, Directive, inject, input } from '@angular/core';\n\nimport {\n  NX_DEFAULT_SURFACE_ACCENT_COLOR,\n  NX_SURFACE,\n  NxResolvedSurface,\n  NxSurfaceAccentColor,\n  NxSurfaceContext,\n  NxSurfaceInputValue,\n  NxSurfaceType,\n} from './surface-types';\n\n/**\n * Declares the surface for everything inside the host element, and paints its\n * background to match. Adopting ng-aquila components adapt automatically; other\n * components and plain CSS can key off the `data-nx-surface` attribute.\n */\n@Directive({\n  selector: '[nxSurface]',\n  standalone: true,\n  exportAs: 'nxSurface',\n  providers: [{ provide: NX_SURFACE, useExisting: NxSurface }],\n  host: {\n    '[attr.data-nx-surface]': '_surface()',\n    '[attr.data-nx-accent-color]': '_accentColor()',\n    '[style.background-color]': '_backgroundColor()',\n  },\n})\nexport class NxSurface implements NxSurfaceContext {\n  /** `skipSelf`, because this directive provides the token on its own element. */\n  private readonly _parent = inject(NX_SURFACE, { optional: true, skipSelf: true });\n\n  /**\n   * The surface painted on this element. Use `inherit` to keep the enclosing\n   * surface, and `default` to reset it. Default: `'default'`.\n   */\n  readonly surfaceInput = input<NxSurfaceInputValue>('default', { alias: 'nxSurface' });\n\n  /** The accent hue. Only takes effect with an `accent-attention` surface. */\n  readonly accentColorInput = input<NxSurfaceAccentColor | undefined>(undefined, {\n    alias: 'nxSurfaceAccentColor',\n  });\n\n  /**\n   * Whether to paint the surface's background on the host. Turn off when the host\n   * already paints this same surface itself - descendants keep reacting either\n   * way. To stop them reacting, reset the surface instead, see {@link NX_SURFACE}.\n   * Default: `true`.\n   */\n  readonly background = input(true, {\n    transform: booleanAttribute,\n    alias: 'nxSurfaceBackground',\n  });\n\n  readonly resolved = computed<NxResolvedSurface>(() => {\n    const declared = this.surfaceInput();\n    const parent = this._parent?.resolved();\n    const surface = declared === 'inherit' ? (parent?.surface ?? 'default') : declared;\n\n    if (surface !== 'accent-attention') {\n      return { surface };\n    }\n\n    // Only an enclosing accent surface has a hue to pass down.\n    const inherited = parent?.surface === 'accent-attention' ? parent.accentColor : undefined;\n\n    return {\n      surface,\n      accentColor: this.accentColorInput() ?? inherited ?? NX_DEFAULT_SURFACE_ACCENT_COLOR,\n    };\n  });\n\n  protected readonly _surface = computed<NxSurfaceType>(() => this.resolved().surface);\n\n  protected readonly _accentColor = computed<NxSurfaceAccentColor | null>(() => {\n    const resolved = this.resolved();\n    return resolved.surface === 'accent-attention' ? resolved.accentColor : null;\n  });\n\n  readonly _backgroundColor = computed<string | null>(() => {\n    if (!this.background()) {\n      return null;\n    }\n    const resolved = this.resolved();\n    switch (resolved.surface) {\n      case 'default':\n        return 'var(--nx-surface-default-background-color)';\n      case 'attention':\n        return 'var(--nx-surface-attention-background-color)';\n      case 'emphasis':\n        return 'var(--nx-surface-emphasis-background-color)';\n      case 'accent-attention':\n        return `var(--color-attention-${resolved.accentColor})`;\n    }\n  });\n}\n"],"mappings":";;AA0BA,MAAa,kCAAwD;AAoBrE,MAAa,aAAa,IAAI,eAA6C,YAAY;ACzCvF,MAAM,kBAAqC,EAAE,SAAS,UAAS;AAQ/D,SAAgB,gBAAa;CAC3B,MAAM,UAAU,OAAO,YAAY,EAAE,UAAU,KAAI,CAAE;CAErD,OAAO,eAAe,SAAS,SAAQ,KAAM,eAAe;AAC9D;ACWA,IAAa,YAAb,MAAa,UAAS;CAXtB,cAAA;EAamB,KAAA,UAAU,OAAO,YAAY;GAAE,UAAU;GAAM,UAAU;EAAI,CAAE;EAMvE,KAAA,eAAe,MAA2B,WAAS;GAAA,GAAA,YAAA,EAAA,WAAA,eAAA,+BAA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