{"version":3,"file":"chunk-Container.mjs","names":[],"sources":["../../src/components/Container/Container.tsx"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { ark } from '@ark-ui/react/factory';\nimport React, { type CSSProperties, type PropsWithChildren, createContext, useContext, useEffect, useRef } from 'react';\n\nimport { log } from '@dxos/log';\nimport { useComposedRefs } from '@dxos/react-hooks';\n\nimport { recipes } from '../../recipes.ts';\nimport { type Size } from '../../sizes.ts';\nimport { composableProps, slottable } from '../../util/slots.ts';\n\nexport type Level = 'sunken' | 'chrome' | 'base' | 'raised' | 'overlay' | 'popup' | '+1';\n\n/** Custom properties, which React's `CSSProperties` does not declare. */\nexport type CSSVariables = Record<`--${string}`, string>;\n\nexport type Gutter = 'rail' | 'inset' | 'sm' | 'md' | 'lg' | 'none' | 'inherit';\n\n/** Space between the container's rows; the current `ColumnGap` steps (0.25, 0.5, 0.75rem). */\nexport type ContainerGap = 'none' | 'sm' | 'md' | 'lg' | 'xl';\n\n/** Tracks a child spans in its parent Container: a count, or `full` for every track of the content area. */\nexport type Span = number | 'full';\n\n/**\n * The attributes that place an element across `span` tracks of its parent Container; the count travels as a custom\n * property because CSS cannot yet read a numeric attribute in every engine.\n */\nexport const spanAttributes = (span: Span | undefined) => {\n  const style: CSSProperties & CSSVariables = typeof span === 'number' ? { '--dx-span': String(span) } : {};\n  return { 'data-span': span === undefined ? undefined : String(span), style };\n};\n\n//\n// Default gutter\n//\n\n/**\n * The gutter a Container takes when it names none. `Panel.Body` provides its panel's (`sm` by default), and every grid\n * part clears it for its subtree, so only the first Container under a Body becomes a template root on it and nested\n * Containers stay subgrids.\n */\nconst DefaultGutterContext = createContext<Gutter | undefined>(undefined);\n\n/** The gutter an unnamed Container here would take, or `undefined` where it would inherit. */\nexport const useDefaultGutter = () => useContext(DefaultGutterContext);\n\n/** True under a Container, whose content and gutter lines a subgrid (`gutter='inherit'`) can join. */\nconst InGridContext = createContext(false);\n\n/** Whether this subtree sits inside a Container, so a nested scroll viewport can inherit its gutters. */\nexport const useInGrid = () => useContext(InGridContext);\n\n/** Provides the gutter an unnamed Container under it takes (`undefined` restores `inherit`). */\nexport const DefaultGutterProvider = ({ gutter, children }: PropsWithChildren<{ gutter: Gutter | undefined }>) => (\n  <DefaultGutterContext.Provider value={gutter}>{children}</DefaultGutterContext.Provider>\n);\n\n//\n// Container\n//\n\nexport type ContainerProps = {\n  size?: Size;\n  /**\n   * `inherit` makes the container a subgrid of its parent's tracks; any other value starts a fresh template. Unset, it\n   * is the enclosing `Panel.Body`'s gutter for the first Container under the Body, and `inherit` everywhere else.\n   */\n  gutter?: Gutter;\n  /** Inner template for the content track; interior line names only, since edge names collide with `content-*`. */\n  columns?: string;\n  /** `stack` places each child across the content track; `row` flows children through its inner tracks. */\n  layout?: 'stack' | 'row';\n  /** Placement of the container itself within a parent Container. */\n  place?: 'content' | 'full';\n  /** A rung of ui-theme's surface ladder, or `+1` for one rung above the enclosing level. */\n  level?: Level;\n  /** Row gap only: columns are shared through subgrid, so a column gap would shift the parent's tracks. */\n  gap?: ContainerGap;\n  /**\n   * Block alignment of a `row`'s cells: `center` (default) centres controls in a one-block row; `start` tops cells of\n   * differing heights (e.g. two forms side by side), which centring would offset against the tallest; `stretch` makes\n   * every cell of a row as tall as its tallest (a grid of cards).\n   */\n  align?: 'center' | 'start' | 'stretch';\n  /** Tracks the container spans in a parent Container (e.g. a cell across two columns of a `row`). */\n  span?: Span;\n  /** `document` caps a template root at the reading width and centres it (the current `dx-document`). */\n  width?: 'document';\n  /** A `row` that keeps its columns in a narrow pane rather than stacking its cells (e.g. an X/Y pair). */\n  fixed?: boolean;\n  /** Pads the block axis by the gutter too, so content scrolled in a template root starts and ends a gutter inside. */\n  padBlock?: boolean;\n};\n\n/**\n * The attributes that make any element a Container (`.dx-container` plus its `data-*` and `--dx-columns`), for a part that\n * must keep its own element and scope (a listbox row is Ark's item) rather than render a Container under `asChild`,\n * where the Container's `data-scope`/`data-part` would win (finding 10).\n */\nexport const containerAttributes = ({\n  size,\n  gutter = 'inherit',\n  columns,\n  layout = 'stack',\n  place,\n  level,\n  gap,\n  align,\n  span,\n  width,\n  fixed,\n  padBlock,\n}: ContainerProps) => {\n  const { style: spanStyle, ...spanAttrs } = spanAttributes(span);\n  const style: CSSProperties & CSSVariables = columns ? { ...spanStyle, '--dx-columns': columns } : spanStyle;\n  return {\n    ...spanAttrs,\n    'data-size': size,\n    'data-gutter': gutter,\n    'data-layout': layout,\n    'data-place': place,\n    'data-surface': level,\n    'data-gap': gap,\n    'data-align': align === 'center' ? undefined : align,\n    'data-width': width,\n    'data-fixed': fixed ? '' : undefined,\n    'data-pad-block': padBlock ? '' : undefined,\n    'data-columns': columns ? '' : undefined,\n    style,\n  };\n};\n\n/** Grid part (decision 5): every prop is a `data-*` attribute resolved by `theme/container.css`. */\nexport const Container = slottable<HTMLDivElement, ContainerProps>(\n  (\n    {\n      children,\n      asChild,\n      size,\n      gutter: gutterProp,\n      columns,\n      layout = 'stack',\n      place,\n      level,\n      gap,\n      align,\n      span,\n      width,\n      fixed,\n      padBlock,\n      ...props\n    },\n    forwardedRef,\n  ) => {\n    const defaultGutter = useDefaultGutter();\n    const gutter = gutterProp ?? defaultGutter ?? 'inherit';\n    const localRef = useRef<HTMLDivElement>(null);\n    const ref = useComposedRefs(forwardedRef, localRef);\n    const { className, style, ...rest } = composableProps(props, { classNames: recipes.container() });\n\n    // Subgrid only reaches the parent's tracks from a direct child; own `columns` start a fresh template, so any parent will do.\n    useEffect(() => {\n      if (process.env.NODE_ENV === 'production' || gutter !== 'inherit' || columns) {\n        return;\n      }\n      const parent = localRef.current?.parentElement;\n      if (parent && !parent.matches('.dx-container, .dx-scroll-root')) {\n        log.warn('inheriting Container is not a direct child of a Container', { parent: parent.className });\n      }\n    }, [gutter, columns]);\n\n    const { style: columnsStyle, ...attributes } = containerAttributes({\n      size,\n      gutter,\n      columns,\n      layout,\n      place,\n      level,\n      gap,\n      align,\n      span,\n      width,\n      fixed,\n      padBlock,\n    });\n    return (\n      <DefaultGutterProvider gutter={undefined}>\n        <InGridContext.Provider value>\n          <ark.div\n            asChild={asChild}\n            {...rest}\n            data-scope='container'\n            data-part='root'\n            {...attributes}\n            style={{ ...columnsStyle, ...style }}\n            className={className}\n            ref={ref}\n          >\n            {children}\n          </ark.div>\n        </InGridContext.Provider>\n      </DefaultGutterProvider>\n    );\n  },\n);\n\nContainer.displayName = 'Container';\n"],"mappings":";;;;;;;;;;;;;AA+BA,IAAa,kBAAkB,SAA2B;CAExD,OAAO;EAAE,aAAa,SAAS,KAAA,IAAY,KAAA,IAAY,OAAO,IAAI;EAAG,OADzB,OAAO,SAAS,WAAW,EAAE,aAAa,OAAO,IAAI,EAAE,IAAI,CAAC;CAC7B;AAC7E;;;;;;AAWA,IAAM,uBAAuB,cAAkC,KAAA,CAAS;;AAGxE,IAAa,yBAAyB,WAAW,oBAAoB;;AAGrE,IAAM,gBAAgB,cAAc,KAAK;;AAGzC,IAAa,kBAAkB,WAAW,aAAa;;AAGvD,IAAa,yBAAyB,EAAE,QAAQ,eAC9C,oBAAC,qBAAqB,UAAtB;CAA+B,OAAO;CAAS;AAAwC,CAAA;;;;;;AA6CzF,IAAa,uBAAuB,EAClC,MACA,SAAS,WACT,SACA,SAAS,SACT,OACA,OACA,KACA,OACA,MACA,OACA,OACA,eACoB;CACpB,MAAM,EAAE,OAAO,WAAW,GAAG,cAAc,eAAe,IAAI;CAC9D,MAAM,QAAsC,UAAU;EAAE,GAAG;EAAW,gBAAgB;CAAQ,IAAI;CAClG,OAAO;EACL,GAAG;EACH,aAAa;EACb,eAAe;EACf,eAAe;EACf,cAAc;EACd,gBAAgB;EAChB,YAAY;EACZ,cAAc,UAAU,WAAW,KAAA,IAAY;EAC/C,cAAc;EACd,cAAc,QAAQ,KAAK,KAAA;EAC3B,kBAAkB,WAAW,KAAK,KAAA;EAClC,gBAAgB,UAAU,KAAK,KAAA;EAC/B;CACF;AACF;;AAGA,IAAa,YAAY,WAErB,EACE,UACA,SACA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