{"version":3,"file":"component.cjs","sourceRoot":"","sources":["../../src/jsx/component.ts"],"names":[],"mappings":";;;AAmFA;;;;;GAKG;AACH,SAAS,oBAAoB,CAA2B,KAAY;IAClE,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CACxD,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CAGjC,IAAU;IACV,OAAO,CAAC,KAAmC,EAAE,EAAE;QAC7C,MAAM,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QACtC,OAAO;YACL,IAAI;YACJ,KAAK,EAAE,oBAAoB,CAAC,IAAa,CAAC;YAC1C,GAAG;SACJ,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAZD,kDAYC","sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * A key, which can be a string or a number.\n */\nexport type Key = string | number;\n\n/**\n * A JSON object.\n */\nexport type JsonObject = Record<string, Json>;\n\n/**\n * A generic JSX element.\n *\n * @property type - The type of the element.\n * @property props - The props of the element.\n * @property key - The key of the element.\n */\nexport type GenericSnapElement = {\n  type: string;\n  props: JsonObject;\n  key: Key | null;\n};\n\n/**\n * A JSX element.\n *\n * @property type - The type of the element.\n * @property props - The props of the element.\n * @property key - The key of the element.\n */\nexport type SnapElement<\n  Props extends JsonObject = Record<string, never>,\n  Type extends string = string,\n> = {\n  type: Type;\n  props: Props;\n  key: Key | null;\n};\n\n/**\n * A type that can be a single value or an infinitely nestable array of values.\n *\n * @template Type - The type that can be an array.\n * @example\n * type NestableString = Nestable<string>;\n * const nestableString: NestableString = 'hello';\n * const nestableStringArray: NestableString = ['hello', 'world', ['foo', ['bar']]];\n */\nexport type Nestable<Type> = Type | Nestable<Type>[];\n\n/**\n * A type that can be a single value or an array of values, a boolean, or null.\n *\n * @template Type - The type that can be an array.\n */\nexport type SnapsChildren<Type> = Nestable<Type | boolean | null>;\n\n/**\n * A type type that can be a generic JSX element, a boolean, or null.\n */\nexport type GenericSnapChildren = GenericSnapElement | boolean | null;\n\n/**\n * A JSX node, which can be an element, a string, null, or an array of nodes.\n */\nexport type SnapNode = SnapsChildren<GenericSnapElement | string>;\n\n/**\n * A JSX string element, which can be a string or an array of strings, or\n * booleans (for conditional rendering).\n */\nexport type StringElement = SnapsChildren<string>;\n\n/**\n * A JSX component.\n */\nexport type SnapComponent<\n  Props extends JsonObject = Record<string, never>,\n  Type extends string = string,\n> = (props: Props & { key?: Key | null }) => SnapElement<Props, Type>;\n\n/**\n * Remove undefined props from an object.\n *\n * @param props - The object to remove undefined props from.\n * @returns The object without undefined props.\n */\nfunction removeUndefinedProps<Props extends JsonObject>(props: Props): Props {\n  return Object.fromEntries(\n    Object.entries(props).filter(([, value]) => value !== undefined),\n  ) as Props;\n}\n\n/**\n * Create a Snap component from a type. This is a helper function that creates a\n * Snap component function.\n *\n * @param type - The type of the component.\n * @returns A function that creates a Snap element.\n * @see SnapComponent\n */\nexport function createSnapComponent<\n  Props extends JsonObject = Record<string, never>,\n  Type extends string = string,\n>(type: Type): SnapComponent<Props, Type> {\n  return (props: Props & { key?: Key | null }) => {\n    const { key = null, ...rest } = props;\n    return {\n      type,\n      props: removeUndefinedProps(rest as Props),\n      key,\n    };\n  };\n}\n"]}