{"version":3,"sources":["../src/index.tsx"],"names":["useContext","Box","useDeepCompareMemo","merge","defaults"],"mappings":";;;;;;;;;;;;AAiEO,SAAS,WAAA,CAAY,EAAE,QAAA,EAAU,GAAG,QAAO,EAAqB;AACrE,EAAA,IAAI,GAAA,GAAM,EAAE,GAAGA,gBAAA,CAA4CC,OAAG,CAAA,EAAE;AAEhE,EAAA,MAAM,OAAA,GAAUC,iCAAA;AAAA,IACd,SAAS,gBAAA,GAAmB;AAC1B,MAAA,MAAM,EAAE,IAAA,EAAM,GAAG,OAAA,EAAQ,GAAI,MAAA;AAE7B,MAAA,GAAA,CAAI,GAAA,GAAMC,iBAAA,CAAM,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA;AAEhC,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,MAAM,EAAE,QAAA,EAAU,MAAA,EAAO,GAAIC,YAAA,CAAS,IAAI,CAAA,CAAE,GAAA;AAC5C,QAAA,GAAA,CAAI,MAAMD,iBAAA,CAAM,GAAA,CAAI,KAAK,EAAE,QAAA,EAAU,QAAQ,CAAA;AAAA,MAC/C;AAEA,MAAA,OAAO,GAAA;AAAA,IACT,CAAA;AAAA,IACA,CAAC,KAAK,MAAM;AAAA,GACd;AAEA,EAAA,4DAAQF,OAAA,CAAI,QAAA,EAAJ,EAAa,KAAA,EAAO,WAAU,QAAS,CAAA;AACjD","file":"index.cjs","sourcesContent":["import { Box, defaults, type BoxContext, type EnvContext } from '@bento/box';\nimport React, { useContext, type ReactElement } from 'react';\nimport { useDeepCompareMemo } from 'use-deep-compare';\nimport { merge } from 'ts-deepmerge';\n\nexport interface EnvironmentProps {\n  /**\n   * The root node (Document, ShadowRoot, or Node) to use for the environment context.\n   * This will automatically update the `window` and `document` props.\n   */\n  root?: Document | ShadowRoot | Node;\n\n  /**\n   * The child components that will have access to the configured context.\n   */\n  children: ReactElement;\n\n  /**\n   * Object that contains components that should be replaced.\n   */\n  components?: Record<string, React.ComponentType<any> | { props: Record<string, any> }>;\n\n  /**\n   * Get the window object for the rendering context.\n   */\n  window?: () => Window & typeof globalThis;\n\n  /**\n   * Get the document object for the rendering context.\n   */\n  document?: () => Document;\n\n  /**\n   * External sprite URL.\n   */\n  sprite?: string;\n\n  //\n  // Catch all, to allow users specify custom configuration that can be shared\n  // between Bento component that does need strong typing.\n  //\n  [key: string]: any;\n}\n\n/**\n * The `Environment` component is responsible for configuring and providing\n * a context to its children. It merges the provided configuration into the\n * existing context and ensures that the environment (`env`) is properly set up.\n *\n * @param props - The props for the `Environment` component.\n *\n * @returns A `Box.Provider` component that wraps the children with the configured context.\n *\n * @remarks\n * - If a value in the configuration is an array, it will be concatenated with the existing array in the context.\n * - If a value in the configuration is an object, it will be deeply merged with the existing object in the context.\n * - Primitive values in the configuration will overwrite the existing values in the context.\n *\n * @example\n * ```tsx\n * <Environment someKey=\"value\" anotherKey={{ nested: true }}>\n *   <ChildComponent />\n * </Environment>\n * ```\n */\nexport function Environment({ children, ...config }: EnvironmentProps) {\n  let ctx = { ...useContext<BoxContext<Record<string, any>>>(Box) };\n\n  const context = useDeepCompareMemo(\n    function configureContext() {\n      const { root, ...options } = config;\n\n      ctx.env = merge(ctx.env, options) as EnvContext<Record<string, any>>;\n\n      if (root) {\n        const { document, window } = defaults(root).env;\n        ctx.env = merge(ctx.env, { document, window }) as EnvContext<Record<string, any>>;\n      }\n\n      return ctx;\n    },\n    [ctx, config]\n  );\n\n  return <Box.Provider value={context}>{children}</Box.Provider>;\n}\n"]}