{"version":3,"file":"define.cjs","names":[],"sources":["../src/define.ts"],"sourcesContent":["import { createComponentClass } from './_component-class';\nimport type { ComponentDefinition } from './component-types';\nimport { ORE_ERRORS, OreApiError } from './errors';\nimport { type PropDef, prop } from './props';\n\nexport type { HostBindFn } from './host-bind';\nexport type { PropDef };\nexport { prop };\n\n/**\n * Define and register a web component.\n *\n * The `setup` function runs for each connection and returns an `HTMLResult`.\n * Disconnecting disposes its state; reconnecting rebuilds it. All reactive\n * behaviour within a connection is expressed through directives inside the\n * template — not by re-evaluating setup itself.\n *\n * Everything besides `props` — lifecycle hooks, host bindings, context, slots,\n * emit — is a free function imported from `@vielzeug/ore` and called directly\n * from inside `setup()` (or from a composable it calls):\n *\n * ```ts\n * import { define, html, prop, onMounted, useEmit, useSlots } from '@vielzeug/ore';\n *\n * define<{ count?: number }>('my-counter', {\n *   props: { count: prop.number(0) },\n *   setup(props) {\n *     const emit = useEmit<{ increment: number }>();\n *     const slots = useSlots<'header' | 'footer'>();\n *\n *     onMounted(() => console.log('mounted'));\n *\n *     return html`<button @click=${() => emit('increment', props.count.value + 1)}>${props.count}</button>`;\n *   },\n * });\n * ```\n */\nexport function define<Props extends Record<string, unknown> = Record<never, never>>(\n  tag: string,\n  definition: ComponentDefinition<Props>,\n): void {\n  if (!tag) throw new OreApiError(ORE_ERRORS.defineRequiresTag);\n\n  if (customElements.get(tag)) throw new OreApiError(ORE_ERRORS.defineDuplicate(tag));\n\n  const ComponentClass = createComponentClass(tag, definition);\n\n  // Registration is intentionally the sole global side effect of define().\n  Object.defineProperty(ComponentClass, 'name', { value: tag });\n  customElements.define(tag, ComponentClass);\n}\n"],"mappings":"6FAqCA,SAAgB,EACd,EACA,EACM,CACN,GAAI,CAAC,EAAK,MAAM,IAAI,EAAA,YAAY,EAAA,WAAW,iBAAiB,EAE5D,GAAI,eAAe,IAAI,CAAG,EAAG,MAAM,IAAI,EAAA,YAAY,EAAA,WAAW,gBAAgB,CAAG,CAAC,EAElF,IAAM,EAAiB,EAAA,qBAAqB,EAAK,CAAU,EAG3D,OAAO,eAAe,EAAgB,OAAQ,CAAE,MAAO,CAAI,CAAC,EAC5D,eAAe,OAAO,EAAK,CAAc,CAC3C"}