AI Guide
Use this page first if you are an AI agent scanning the WebComponent docs.
Read First
Package Boundary
@beforesemicolon/web-componentexportsWebComponent,HTMLComponentElement,css, and the WebComponent-specific types.- It also re-exports
@beforesemicolon/markup, so examples can importhtml,repeat,when,state, and other Markup APIs from@beforesemicolon/web-component. - The browser bundle exposes
window.BFS.WebComponent,window.BFS.css, andwindow.BFS.MARKUP.
Runtime Facts
static observedAttributesdefines public attributes and creates camelCase reactive props underthis.props.- Default prop values are class fields with the camelCase prop name.
initialStatedefines local state getters underthis.state.this.setState()only works after the component is mounted.this.dispatch(name, detail)creates aCustomEventwithdetail. Add native custom event options manually only if the runtime API changes to support them.render()may return a MarkupHtmlTemplate, a string, a DOMNode, or nothing.stylesheetaccepts a CSS string, aCSSStyleSheet, or a reactivecssresult.config.shadowdefaults totrue.- When
config.shadow = false,:hostselectors are rewritten to the custom element tag.
Common Tasks
- Public input: add the kebab-case name to
static observedAttributesand readthis.props.camelName. - Internal UI state: add a key to
initialStateand update it withthis.setState(). - DOM element access: add
ref="name"and usethis.refs.name?.[0]after render. - Component output: call
this.dispatch('event-name', { value }). - Mount side effects: use
onMount()and return cleanup. - Prop reactions: use
onUpdate(name, newValue, oldValue). - Scoped CSS: assign
stylesheet. - Reactive CSS: assign
stylesheet = css\...``. - Native forms: set
static formAssociated = trueand usethis.internals.
Avoid
- Do not call
this.setState()in the constructor or during class field initialization. - Do not mutate arrays or objects inside state in place; return a new value from
setState. - Do not document native lifecycle callbacks as extension points; use
onMount,onUpdate,onDestroy, andonAdoption. - Do not assume
dispatch()bubbles or crosses shadow boundaries unless the source code supports options for that. - Do not use long one-line custom element examples when several attributes are present.