import type * as dom from './dom.d.ts' import type { FragmentProps, Handle, PortalProps, RenderFn } from './component.ts' export type ElementFunction = ((...args: never[]) => unknown) & { readonly name?: string } export type Key = string | number | bigint /** * Any valid element type accepted by JSX or {@link import('./create-element.ts').createElement}. * - `string` for host elements (e.g., 'div') * - `Function` for user components */ export type ElementType = string | Function /** * Generic bag of props passed to elements/components. * Consumers should define specific prop types on their components; this is the * renderer's normalized shape used throughout reconciler/SSR code. */ export type ElementProps = Record /** * A virtual element produced by JSX or {@link import('./create-element.ts').createElement} * describing UI. Carries an internal symbol brand that distinguishes it from plain data. */ export interface RemixElement { /** Host tag or component function for the element. */ type: ElementType /** Normalized props for the element. */ props: ElementProps /** Optional reconciliation key. */ key?: any /** Internal brand used to distinguish Remix elements at runtime. */ [REMIX_ELEMENT]: true /** Serialization tag for Remix elements. */ $rmx: true } /** * Any single value Remix can render. Booleans render as empty text. */ export type Renderable = RemixElement | string | number | bigint | boolean | null | undefined /** * Anything that Remix can render, including nested arrays of renderable values. * This mirrors how JSX spreads children into arrays (e.g. when using `map`) * and how our reconciler flattens children at runtime. * * Particularly useful for `props.children`. * * ```tsx * function MyComponent(handle: Handle<{ children: RemixNode }>) {} * ``` */ export type RemixNode = Renderable | RemixNode[] type PreviousMixDepth = [0, 0, 1, 2, 3, 4] type FalsyMixValue = false | 0 | 0n | '' | null | undefined type NullableMixValue = mix | FalsyMixValue type MixLeaf = mix extends ReadonlyArray ? MixLeaf : mix type NormalizeMixLeaf = Exclude, FalsyMixValue> type NestedMixValue = depth extends 0 ? NullableMixValue | ReadonlyArray> : NullableMixValue | ReadonlyArray> type NormalizeMixProp = props extends { mix?: infer mix } ? Omit & { mix?: Array> } : props type ExpandMixProp = props extends { mix?: infer mix } ? Omit & { mix?: NestedMixValue> } : props type MixinElementType = (( handle: { update(): Promise }, setup: unknown, ) => (props: any) => RemixElement) & { __rmxMixinElementType: string } /** * Get the props for a specific element type. * * @example * interface MyButtonProps extends Props<"button"> { * size: "sm" | "md" | "lg" * } */ export type Props = NormalizeMixProp< JSX.IntrinsicElements[T] > /** * Creates a Remix virtual element. * * @param type Host tag or component function. * @param props Element props. * @param key Optional reconciliation key. * @returns A Remix virtual element. */ export function jsx(type: ElementType, props: ElementProps, key?: any): RemixElement { return { [REMIX_ELEMENT]: true, $rmx: true, key, props: normalizeElementProps(props), type, } } export { jsx as jsxDEV, jsx as jsxs } // Shared across module instances, and enumerable so element spreads retain their identity. const REMIX_ELEMENT = Symbol.for('remix.element') export const MIXIN_RUNTIME = Symbol.for('remix.mixinRuntime') export const DIRECT_EVENT = Symbol.for('remix.directEvent') export let defaultMixinDriver: unknown export let activeSchedulerUpdateParents: ParentNode[] | undefined export type ComponentStalenessCheck = (type: Function) => boolean export let componentStalenessCheck: ComponentStalenessCheck | null = null export const roots = new Set<{ reconcile(): void }>() export function setComponentStalenessCheck(check: ComponentStalenessCheck): void { componentStalenessCheck = check } export function setDefaultMixinDriver(driver: unknown): void { defaultMixinDriver = driver } export function setActiveSchedulerUpdateParents(parents: ParentNode[] | undefined): void { activeSchedulerUpdateParents = parents } export function isMixinDescriptor( value: unknown, ): value is { type: (...args: any[]) => unknown; args: readonly unknown[] } { if (!value || typeof value !== 'object' || isRemixElement(value)) return false let descriptor = value as { type?: unknown; args?: unknown } return typeof descriptor.type === 'function' && Array.isArray(descriptor.args) } export function isRemixElement(node: unknown): node is RemixElement { return ( typeof node === 'object' && node !== null && (node as Partial)[REMIX_ELEMENT] === true && (typeof (node as RemixElement).type === 'string' || typeof (node as RemixElement).type === 'function') && typeof (node as RemixElement).props === 'object' && (node as RemixElement).props !== null ) } function normalizeElementProps(props: ElementProps | null | undefined): ElementProps { if (!props) return {} let mix = props.mix if (mix === undefined) { if (!('mix' in props)) return props } else if (Array.isArray(mix) && mix.length > 0) { let allFlat = true for (let i = 0; i < mix.length; i++) { let item = mix[i] if (!item || Array.isArray(item)) { allFlat = false break } } if (allFlat) return props } let { mix: _mix, ...rest } = props let normalized = Array.isArray(mix) ? mix.flat(Infinity).filter(Boolean) : mix ? [mix] : [] if (normalized.length) rest.mix = normalized return rest } export type EmptyChild = boolean | null | undefined export type PrimitiveChild = string | number | bigint export function isEmptyChild(value: unknown): value is EmptyChild { return value == null || typeof value === 'boolean' } export function isPrimitiveChild(value: unknown): value is PrimitiveChild { let type = typeof value return type === 'string' || type === 'number' || type === 'bigint' } export function normalizeChildren(children: readonly RemixNode[]): RemixNode[] { return children.some(Array.isArray) ? ((children as unknown[]).flat(Infinity) as RemixNode[]) : (children as RemixNode[]) } export function isRemixNode(value: unknown): value is RemixNode { return ( isEmptyChild(value) || isPrimitiveChild(value) || isRemixElement(value) || (Array.isArray(value) && value.every(isRemixNode)) ) } /** * Use this when framework code is incorrect, indicating an internal bug rather * than application code error. * * @param assertion The value to check for truthiness * @param message Optional message to include in the error */ export function invariant(assertion: any, message?: string): asserts assertion { let prefix = 'Framework invariant' if (assertion) return throw new Error(message ? `${prefix}: ${message}` : prefix) } class UnsafeHTMLValue { #value: string constructor(value: string) { this.#value = value } static read(value: unknown): string | undefined { return value instanceof UnsafeHTMLValue ? value.#value : undefined } } /** * An opaque value that Remix may insert into an element without HTML escaping. * * Create values with {@link unsafeHTML}. Remix does not sanitize or otherwise modify the HTML. */ export type UnsafeHTML = UnsafeHTMLValue /** * Explicitly allows a string to be inserted into an element as raw HTML. * * This function does not sanitize or otherwise modify the HTML. Only pass trusted content or * content that your application has already sanitized. * * @param value The raw HTML string to allow. * @returns An opaque value accepted by raw-HTML props such as `innerHTML` and iframe * `srcDoc`/`srcdoc`. */ export function unsafeHTML(value: string): UnsafeHTML { let result = new UnsafeHTMLValue(value) Object.freeze(result) return result } interface NormalizedUnsafeHTMLProps extends Record { innerHTML?: string srcDoc?: string srcdoc?: string } /** * Validates and unwraps every host prop that can cause the browser to parse raw HTML. * * @param props The authored host props to normalize. * @returns Host props with opaque raw-HTML values replaced by their strings. * @internal */ const UNSAFE_HTML_PROPS = ['innerHTML', 'srcDoc', 'srcdoc'] as const export function normalizeUnsafeHTMLProps( props: Record, ): NormalizedUnsafeHTMLProps { invariant( props.outerHTML === undefined, 'Invalid outerHTML prop: outerHTML is not supported on host elements', ) if (props.innerHTML === undefined && props.srcDoc === undefined && props.srcdoc === undefined) { return props } let normalized: NormalizedUnsafeHTMLProps = { ...props } for (let name of UNSAFE_HTML_PROPS) { let value = props[name] if (value === undefined) continue let html = UnsafeHTMLValue.read(value) invariant( html !== undefined, `Invalid ${name} prop: expected a value created with unsafeHTML()`, ) normalized[name] = html } return normalized } type TypedEventListener = { [key in keyof eventMap]: (event: eventMap[key]) => void } /** * An `EventTarget` subclass with typed event maps. */ export class TypedEventTarget extends EventTarget {} /** * Interface surface for {@link TypedEventTarget} with typed listener overloads. */ export interface TypedEventTarget { /** * Adds a listener for a typed event name from the event map. * * @param type Event name to listen for. * @param listener Listener to invoke when the event fires. * @param options Listener registration options. */ addEventListener>( type: type, listener: TypedEventListener[type], options?: AddEventListenerOptions, ): void /** * Adds a listener using the standard untyped `EventTarget` signature. * * @param type Event name to listen for. * @param listener Listener to invoke when the event fires. * @param options Listener registration options. */ addEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions, ): void /** * Removes a listener for a typed event name from the event map. * * @param type Event name to stop listening for. * @param listener Previously registered listener. * @param options Listener removal options. */ removeEventListener>( type: type, listener: TypedEventListener[type], options?: EventListenerOptions, ): void /** * Removes a listener using the standard untyped `EventTarget` signature. * * @param type Event name to stop listening for. * @param listener Previously registered listener. * @param options Listener removal options. */ removeEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: EventListenerOptions, ): void } // Marks the built-in `Frame` and `Portal` components. The symbol properties hold their client node // renderers, so the reconciler and server renderer can recognize and render them without importing // the frame or portal runtime. export const FRAME_NODE = Symbol('FrameNode') export const PORTAL_NODE = Symbol('PortalNode') /** * Built-in component used to group children without adding a host element. * * @param handle Component handle for the fragment instance. * @returns A placeholder render function handled by the reconciler. */ export function Fragment(handle: Handle): RenderFn { void handle return () => null // reconciler renders } // The server and the client entry decoder share this identity before the portal renderer loads. export function Portal(handle: Handle): RenderFn { void handle return () => null } declare global { namespace JSX { export interface IntrinsicAttributes { key?: any } type Element = RemixElement type ElementType = // host elements | keyof IntrinsicElements // Factory component | ((handle: Handle) => RenderFn) // Mixin element used internally by mixin render callbacks | MixinElementType type ElementChildrenAttribute = { children: any } export interface ElementAttributesProperty { props: any } type LibraryManagedAttributes = component extends MixinElementType ? ExpandMixProp>[0]> : component extends () => RenderFn ? ExpandMixProp> : props extends { props: infer P } ? ExpandMixProp

: component extends (handle: Handle) => RenderFn ? // Handles typed without a props member still use signature inference. ExpandMixProp

: ExpandMixProp export interface IntrinsicSVGElements { svg: dom.SVGProps animate: dom.SVGProps circle: dom.SVGProps animateMotion: dom.SVGProps animateTransform: dom.SVGProps clipPath: dom.SVGProps defs: dom.SVGProps desc: dom.SVGProps ellipse: dom.SVGProps feBlend: dom.SVGProps feColorMatrix: dom.SVGProps feComponentTransfer: dom.SVGProps feComposite: dom.SVGProps feConvolveMatrix: dom.SVGProps feDiffuseLighting: dom.SVGProps feDisplacementMap: dom.SVGProps feDistantLight: dom.SVGProps feDropShadow: dom.SVGProps feFlood: dom.SVGProps feFuncA: dom.SVGProps feFuncB: dom.SVGProps feFuncG: dom.SVGProps feFuncR: dom.SVGProps feGaussianBlur: dom.SVGProps feImage: dom.SVGProps feMerge: dom.SVGProps feMergeNode: dom.SVGProps feMorphology: dom.SVGProps feOffset: dom.SVGProps fePointLight: dom.SVGProps feSpecularLighting: dom.SVGProps feSpotLight: dom.SVGProps feTile: dom.SVGProps feTurbulence: dom.SVGProps filter: dom.SVGProps foreignObject: dom.SVGProps g: dom.SVGProps image: dom.SVGProps line: dom.SVGProps linearGradient: dom.SVGProps marker: dom.SVGProps mask: dom.SVGProps metadata: dom.SVGProps mpath: dom.SVGProps path: dom.SVGProps pattern: dom.SVGProps polygon: dom.SVGProps polyline: dom.SVGProps radialGradient: dom.SVGProps rect: dom.SVGProps set: dom.SVGProps stop: dom.SVGProps switch: dom.SVGProps symbol: dom.SVGProps text: dom.SVGProps textPath: dom.SVGProps tspan: dom.SVGProps use: dom.SVGProps view: dom.SVGProps } export interface IntrinsicMathMLElements { annotation: dom.AnnotationMathMLProps 'annotation-xml': dom.AnnotationXmlMathMLProps /** @deprecated See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/maction */ maction: dom.MActionMathMLProps math: dom.MathMathMLProps /** This feature is non-standard. See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/menclose */ menclose: dom.MEncloseMathMLProps merror: dom.MErrorMathMLProps /** @deprecated See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfenced */ mfenced: dom.MFencedMathMLProps mfrac: dom.MFracMathMLProps mi: dom.MiMathMLProps mmultiscripts: dom.MmultiScriptsMathMLProps mn: dom.MNMathMLProps mo: dom.MOMathMLProps mover: dom.MOverMathMLProps mpadded: dom.MPaddedMathMLProps mphantom: dom.MPhantomMathMLProps mprescripts: dom.MPrescriptsMathMLProps mroot: dom.MRootMathMLProps mrow: dom.MRowMathMLProps ms: dom.MSMathMLProps mspace: dom.MSpaceMathMLProps msqrt: dom.MSqrtMathMLProps mstyle: dom.MStyleMathMLProps msub: dom.MSubMathMLProps msubsup: dom.MSubsupMathMLProps msup: dom.MSupMathMLProps mtable: dom.MTableMathMLProps mtd: dom.MTdMathMLProps mtext: dom.MTextMathMLProps mtr: dom.MTrMathMLProps munder: dom.MUnderMathMLProps munderover: dom.MUnderMathMLProps semantics: dom.SemanticsMathMLProps } export interface IntrinsicHTMLElements { a: dom.AccessibleAnchorHTMLProps abbr: dom.HTMLProps address: dom.HTMLProps area: dom.AccessibleAreaHTMLProps article: dom.ArticleHTMLProps aside: dom.AsideHTMLProps audio: dom.AudioHTMLProps b: dom.HTMLProps base: dom.BaseHTMLProps bdi: dom.HTMLProps bdo: dom.HTMLProps big: dom.HTMLProps blockquote: dom.BlockquoteHTMLProps body: dom.HTMLProps br: dom.BrHTMLProps button: dom.ButtonHTMLProps canvas: dom.CanvasHTMLProps caption: dom.CaptionHTMLProps cite: dom.HTMLProps code: dom.HTMLProps col: dom.ColHTMLProps colgroup: dom.ColgroupHTMLProps data: dom.DataHTMLProps datalist: dom.DataListHTMLProps dd: dom.DdHTMLProps del: dom.DelHTMLProps details: dom.DetailsHTMLProps dfn: dom.HTMLProps dialog: dom.DialogHTMLProps div: dom.HTMLProps dl: dom.DlHTMLProps dt: dom.DtHTMLProps em: dom.HTMLProps embed: dom.EmbedHTMLProps fieldset: dom.FieldsetHTMLProps figcaption: dom.FigcaptionHTMLProps figure: dom.HTMLProps footer: dom.FooterHTMLProps form: dom.FormHTMLProps h1: dom.HeadingHTMLProps h2: dom.HeadingHTMLProps h3: dom.HeadingHTMLProps h4: dom.HeadingHTMLProps h5: dom.HeadingHTMLProps h6: dom.HeadingHTMLProps head: dom.HeadHTMLProps header: dom.HeaderHTMLProps hgroup: dom.HTMLProps hr: dom.HrHTMLProps html: dom.HtmlHTMLProps i: dom.HTMLProps iframe: dom.IframeHTMLProps img: dom.AccessibleImgHTMLProps input: dom.AccessibleInputHTMLProps ins: dom.InsHTMLProps kbd: dom.HTMLProps keygen: dom.KeygenHTMLProps label: dom.LabelHTMLProps legend: dom.LegendHTMLProps li: dom.LiHTMLProps link: dom.LinkHTMLProps main: dom.MainHTMLProps map: dom.MapHTMLProps mark: dom.HTMLProps marquee: dom.MarqueeHTMLProps menu: dom.MenuHTMLProps menuitem: dom.HTMLProps meta: dom.MetaHTMLProps meter: dom.MeterHTMLProps nav: dom.NavHTMLProps noscript: dom.NoScriptHTMLProps object: dom.ObjectHTMLProps ol: dom.OlHTMLProps optgroup: dom.OptgroupHTMLProps option: dom.OptionHTMLProps output: dom.OutputHTMLProps p: dom.HTMLProps param: dom.ParamHTMLProps picture: dom.PictureHTMLProps pre: dom.HTMLProps progress: dom.ProgressHTMLProps q: dom.QuoteHTMLProps rp: dom.HTMLProps rt: dom.HTMLProps ruby: dom.HTMLProps s: dom.HTMLProps samp: dom.HTMLProps script: dom.ScriptHTMLProps search: dom.SearchHTMLProps section: dom.HTMLProps select: dom.AccessibleSelectHTMLProps slot: dom.SlotHTMLProps small: dom.HTMLProps source: dom.SourceHTMLProps span: dom.HTMLProps strong: dom.HTMLProps style: dom.StyleHTMLProps sub: dom.HTMLProps summary: dom.HTMLProps sup: dom.HTMLProps table: dom.TableHTMLProps tbody: dom.HTMLProps td: dom.TdHTMLProps template: dom.TemplateHTMLProps textarea: dom.TextareaHTMLProps tfoot: dom.HTMLProps th: dom.ThHTMLProps thead: dom.HTMLProps time: dom.TimeHTMLProps title: dom.TitleHTMLProps tr: dom.HTMLProps track: dom.TrackHTMLProps u: dom.UlHTMLProps ul: dom.HTMLProps var: dom.HTMLProps video: dom.VideoHTMLProps wbr: dom.WbrHTMLProps } export interface IntrinsicElements extends IntrinsicSVGElements, IntrinsicMathMLElements, IntrinsicHTMLElements {} } }