{"version":3,"file":"nuclo.polyfill.mjs","names":["NO_CHILDREN","siblingOf","kids","node","i","offset","NucloNode","NucloComment","data","marker","SSRStyle","entries","k","v","name","value","SSRClassList","el","tokens","classes","t","c","token","on","force","oldToken","newToken","index","cb","NucloElement","tagName","child","referenceNode","newNode","oldChild","newChild","NucloText","SSRDocumentFragment","refNode","elementIndex","NucloDocument","element","namespace","document","Event","CustomEvent","Node","Element","HTMLElement","g"],"sources":["../../src/polyfill/Node.ts","../../src/polyfill/Element.ts","../../src/polyfill/Text.ts","../../src/polyfill/Document.ts","../../src/polyfill/index.ts"],"sourcesContent":["/** The child list of a node that can have none (text, comments). */\nexport const NO_CHILDREN: never[] = [];\n\n/**\n * A node's neighbour in its parent's child array.\n *\n * Computed on each read rather than kept as pointers: appendChild is the\n * hottest path in renderToString() and would pay for pointer upkeep on every\n * node, while a sibling walk on a server is rare and short — a region\n * replacing its `empty` content, or a latest region taking a second view.\n */\nexport function siblingOf(node: object, offset: 1 | -1): Node | null {\n  const parent = (node as { parentNode: { childNodes?: ArrayLike<Node> } | null }).parentNode;\n  const kids = parent?.childNodes;\n  if (!kids) return null;\n  const i = Array.prototype.indexOf.call(kids, node);\n  return i === -1 ? null : (kids[i + offset] ?? null);\n}\n\n/**\n * Base Node class for instanceof checks in Node.js polyfill\n */\nexport class NucloNode {\n  nodeType = 1; // ELEMENT_NODE\n  nodeName = '';\n  nodeValue: string | null = null;\n  parentNode: unknown = null;\n  textContent = '';\n\n  get childNodes(): NodeListOf<ChildNode> {\n    return NO_CHILDREN as unknown as NodeListOf<ChildNode>;\n  }\n\n  get nextSibling(): Node | null {\n    return siblingOf(this, 1);\n  }\n\n  get previousSibling(): Node | null {\n    return siblingOf(this, -1);\n  }\n}\n\n/** A comment: nuclo's own markers (`marker` set) and the app's. */\nexport class NucloComment extends NucloNode {\n  data: string;\n  marker: boolean;\n\n  constructor(data: string, marker: boolean) {\n    super();\n    this.nodeType = 8; // COMMENT_NODE\n    this.nodeName = '#comment';\n    this.data = data;\n    this.textContent = data;\n    this.nodeValue = data;\n    this.marker = marker;\n  }\n}\n","import { NucloNode } from './Node';\n\n/**\n * Lightweight style object for SSR — prototype methods instead of Object.defineProperty per element.\n * Stores CSS properties as own properties and provides cssText/setProperty/getPropertyValue via prototype.\n */\nclass SSRStyle {\n  [key: string]: unknown;\n\n  get cssText() {\n    const entries = Object.entries(this);\n    if (entries.length === 0) return '';\n    return entries.map(([k, v]) => `${k}: ${v}`).join('; ');\n  }\n\n  setProperty(name: string, value: string) {\n    (this as Record<string, unknown>)[name] = value;\n  }\n\n  getPropertyValue(name: string) {\n    return ((this as Record<string, unknown>)[name] as string) || '';\n  }\n}\n\n// Lightweight classList for SSR — prototype methods instead of per-element closures\nclass SSRClassList {\n  private _el: NucloElement;\n  constructor(el: NucloElement) { this._el = el; }\n\n  private tokens(): string[] { return this._el.className.split(' ').filter(Boolean); }\n\n  add(...tokens: string[]) {\n    const classes = this.tokens();\n    for (const t of tokens) if (t && !classes.includes(t)) classes.push(t);\n    this._el.className = classes.join(' ');\n  }\n  remove(...tokens: string[]) {\n    this._el.className = this.tokens().filter(c => !tokens.includes(c)).join(' ');\n  }\n  contains(token: string) { return this.tokens().includes(token); }\n  toggle(token: string, force?: boolean) {\n    const on = force ?? !this.contains(token);\n    if (on) this.add(token); else this.remove(token);\n    return on;\n  }\n  replace(oldToken: string, newToken: string) {\n    if (!this.contains(oldToken)) return false;\n    this.remove(oldToken); this.add(newToken); return true;\n  }\n  item(index: number): string | null { return this.tokens()[index] ?? null; }\n  get length() { return this.tokens().length; }\n  get value() { return this._el.className; }\n  set value(v: string) { this._el.className = v; }\n  toString() { return this._el.className; }\n  supports(_token: string) { return false; }\n  forEach(cb: (value: string, key: number, parent: DOMTokenList) => void) {\n    this.tokens().forEach((token, i) => cb(token, i, this as unknown as DOMTokenList));\n  }\n  [Symbol.iterator](): IterableIterator<string> { return this.tokens().values(); }\n  entries(): IterableIterator<[number, string]> { return this.tokens().entries(); }\n  keys(): IterableIterator<number> { return this.tokens().keys(); }\n  values(): IterableIterator<string> { return this.tokens().values(); }\n}\n\nexport class NucloElement extends NucloNode {\n  tagName: string;\n  children: unknown[];\n  className = '';\n  textContent = '';\n  parentNode: unknown = null;\n  id = '';\n  namespaceURI?: string;\n\n  // style/classList are allocated lazily: the vast majority of SSR elements\n  // never touch either (className is stored on the .className string, and the\n  // serializer reads the backing field directly), so eagerly constructing an\n  // SSRStyle + SSRClassList per element would be pure allocation churn.\n  private _style?: CSSStyleDeclaration;\n  private _classList?: DOMTokenList;\n\n  // attributes is allocated lazily too — most elements carry their identity on\n  // .className/.id (separate string fields) and never call setAttribute. Reads\n  // short-circuit on the undefined backing map without allocating; the\n  // serializer reads _attributes directly. The public getter still lazily\n  // materializes a Map for any external `el.attributes` consumer.\n  private _attributes?: Map<string, string>;\n\n  get attributes(): Map<string, string> {\n    return (this._attributes ??= new Map<string, string>());\n  }\n  set attributes(value: Map<string, string>) {\n    this._attributes = value;\n  }\n\n  // `{ innerText }` behaves like `{ textContent }` on the server: plain text\n  // the serializer escapes. (Prototype accessor — no per-element field.)\n  get innerText() {\n    return this.textContent;\n  }\n  set innerText(value: string) {\n    this.textContent = value;\n  }\n\n  get style(): CSSStyleDeclaration {\n    return (this._style ??= new SSRStyle() as unknown as CSSStyleDeclaration);\n  }\n  set style(value: CSSStyleDeclaration) {\n    this._style = value;\n  }\n\n  get classList(): DOMTokenList {\n    return (this._classList ??= new SSRClassList(this) as unknown as DOMTokenList);\n  }\n  set classList(value: DOMTokenList) {\n    this._classList = value;\n  }\n\n  constructor(tagName: string) {\n    super();\n    this.tagName = tagName.toLowerCase();\n    this.nodeType = 1; // ELEMENT_NODE\n    this.nodeName = tagName.toUpperCase();\n    this.children = [];\n  }\n\n  /** Every node, elements, text and comments alike (children holds them all). */\n  get childNodes(): NodeListOf<ChildNode> {\n    return this.children as unknown as NodeListOf<ChildNode>;\n  }\n\n  appendChild<T extends Node>(child: T): T {\n    // Spec behaviour: appending a DocumentFragment moves its children into this\n    // node and leaves the fragment empty. The list runtime relies on this to\n    // batch row insertions.\n    if ((child as any)?.nodeType === 11) {\n      // Detach the fragment's backing array before iterating (instead of\n      // slicing it) — the fragment is emptied either way, and reassigning\n      // first means the loop never has to allocate a copy just to guard\n      // against the array it's about to discard.\n      const kids = (child as any).childNodes as Node[];\n      (child as any).childNodes = [];\n      if ((child as any).children) (child as any).children = [];\n      for (let i = 0; i < kids.length; i++) this.appendChild(kids[i]);\n      return child;\n    }\n    this.children.push(child);\n    if (typeof child === 'object' && child !== null && 'parentNode' in child) {\n      (child as { parentNode: unknown }).parentNode = this;\n    }\n    return child;\n  }\n  \n  setAttribute(name: string, value: string) {\n    (this._attributes ??= new Map<string, string>()).set(name, value);\n    if (name === 'class') {\n      this.className = value;\n    } else if (name === 'id') {\n      this.id = value;\n    }\n  }\n\n  getAttribute(name: string): string | null {\n    return this._attributes?.get(name) ?? null;\n  }\n\n  removeAttribute(name: string) {\n    this._attributes?.delete(name);\n    if (name === 'class') {\n      this.className = '';\n    }\n  }\n\n  hasAttribute(name: string) {\n    return this._attributes?.has(name) ?? false;\n  }\n  \n  insertBefore<T extends Node>(newNode: T, referenceNode: Node | null): T {\n    if (referenceNode === null) {\n      return this.appendChild(newNode);\n    }\n    // Spec behaviour: inserting a DocumentFragment moves its children (in order)\n    // before the reference node and empties the fragment.\n    if ((newNode as any)?.nodeType === 11) {\n      const kids = (newNode as any).childNodes as Node[];\n      (newNode as any).childNodes = [];\n      if ((newNode as any).children) (newNode as any).children = [];\n      for (let i = 0; i < kids.length; i++) this.insertBefore(kids[i], referenceNode);\n      return newNode;\n    }\n    const index = this.children.indexOf(referenceNode);\n    if (index !== -1) {\n      this.children.splice(index, 0, newNode);\n      if (typeof newNode === 'object' && newNode !== null && 'parentNode' in newNode) {\n        (newNode as { parentNode: unknown }).parentNode = this;\n      }\n    }\n    return newNode;\n  }\n  \n  removeChild<T extends Node>(child: T): T {\n    const index = this.children.indexOf(child);\n    if (index !== -1) {\n      this.children.splice(index, 1);\n      if (typeof child === 'object' && child !== null && 'parentNode' in child) {\n        (child as { parentNode: unknown }).parentNode = null;\n      }\n    }\n    return child;\n  }\n\n  replaceChild<T extends Node>(newChild: Node, oldChild: T): T {\n    const index = this.children.indexOf(oldChild);\n    if (index !== -1) {\n      this.children[index] = newChild;\n      if (typeof newChild === 'object' && newChild !== null && 'parentNode' in newChild) {\n        (newChild as { parentNode: unknown }).parentNode = this;\n      }\n      if (typeof oldChild === 'object' && oldChild !== null && 'parentNode' in oldChild) {\n        (oldChild as { parentNode: unknown }).parentNode = null;\n      }\n    }\n    return oldChild;\n  }\n  \n  // SSR never dispatches events: listeners are accepted and dropped, and\n  // queries find nothing (serialize with renderToString instead).\n  addEventListener(_type: string, _listener: EventListener) {}\n  removeEventListener(_type: string, _listener: EventListener) {}\n  dispatchEvent(_event: Event) {\n    return true;\n  }\n  querySelector(_selector: string): Element | null {\n    return null;\n  }\n  querySelectorAll(_selector: string): NodeListOf<Element> {\n    return [] as unknown as NodeListOf<Element>;\n  }\n}\n","import { NO_CHILDREN, siblingOf } from './Node';\n\nexport class NucloText {\n  nodeType = 3; // Node.TEXT_NODE\n  nodeName = '#text';\n  data: string;\n  textContent: string;\n  parentNode: unknown = null;\n  \n  constructor(data: string) {\n    this.data = data;\n    this.textContent = data;\n  }\n  \n  get nodeValue() {\n    return this.data;\n  }\n  \n  set nodeValue(value: string) {\n    this.data = value;\n    this.textContent = value;\n  }\n\n  get childNodes(): NodeListOf<ChildNode> {\n    return NO_CHILDREN as unknown as NodeListOf<ChildNode>;\n  }\n\n  get nextSibling(): Node | null {\n    return siblingOf(this, 1);\n  }\n\n  get previousSibling(): Node | null {\n    return siblingOf(this, -1);\n  }\n}\n","import { NucloElement } from './Element';\nimport { NucloText } from './Text';\nimport { NucloComment } from './Node';\n\n/**\n * Lightweight DocumentFragment for SSR — prototype methods instead of per-instance closures.\n */\nclass SSRDocumentFragment {\n  nodeType = 11;\n  nodeName = '#document-fragment';\n  childNodes: Node[] = [];\n  children: Element[] = [];\n  textContent = '';\n\n  get firstChild(): Node | null {\n    return this.childNodes.length > 0 ? this.childNodes[0] : null;\n  }\n\n  get lastChild(): Node | null {\n    return this.childNodes.length > 0 ? this.childNodes[this.childNodes.length - 1] : null;\n  }\n\n  appendChild<T extends Node>(child: T): T {\n    this.childNodes.push(child);\n    if ((child as any).nodeType === 1) {\n      this.children.push(child as unknown as Element);\n    }\n    (child as any).parentNode = this;\n    return child;\n  }\n\n  insertBefore<T extends Node>(newNode: T, refNode: Node | null): T {\n    if (!refNode) return this.appendChild(newNode);\n    const index = this.childNodes.indexOf(refNode);\n    if (index !== -1) {\n      this.childNodes.splice(index, 0, newNode);\n      if ((newNode as any).nodeType === 1) {\n        const elementIndex = this.children.indexOf(refNode as Element);\n        if (elementIndex !== -1) {\n          this.children.splice(elementIndex, 0, newNode as unknown as Element);\n        }\n      }\n    }\n    (newNode as any).parentNode = this;\n    return newNode;\n  }\n\n  removeChild<T extends Node>(child: T): T {\n    const index = this.childNodes.indexOf(child);\n    if (index !== -1) this.childNodes.splice(index, 1);\n    if ((child as any).nodeType === 1) {\n      const elementIndex = this.children.indexOf(child as unknown as Element);\n      if (elementIndex !== -1) this.children.splice(elementIndex, 1);\n    }\n    (child as any).parentNode = null;\n    return child;\n  }\n\n  replaceChild<T extends Node>(newChild: T, oldChild: Node): T {\n    const index = this.childNodes.indexOf(oldChild);\n    if (index !== -1) {\n      this.childNodes[index] = newChild;\n      if ((oldChild as any).nodeType === 1 && (newChild as any).nodeType === 1) {\n        const elementIndex = this.children.indexOf(oldChild as Element);\n        if (elementIndex !== -1) {\n          this.children[elementIndex] = newChild as unknown as Element;\n        }\n      }\n    }\n    (newChild as any).parentNode = this;\n    (oldChild as any).parentNode = null;\n    return newChild;\n  }\n\n  querySelector(): null { return null; }\n  querySelectorAll(): NodeListOf<Element> { return [] as unknown as NodeListOf<Element>; }\n}\n\nexport class NucloDocument {\n  head: ExpandedElement;\n  body: ExpandedElement;\n\n  constructor() {\n    this.head = new NucloElement('head') as unknown as ExpandedElement;\n    this.body = new NucloElement('body') as unknown as ExpandedElement;\n  }\n  \n  createElement(tagName: string, _options?: unknown): ExpandedElement {\n    return new NucloElement(tagName) as unknown as ExpandedElement;\n  }\n  \n  createElementNS(namespace: string, tagName: string, _options?: unknown): ExpandedElement {\n    const element = new NucloElement(tagName) as unknown as ExpandedElement;\n    (element as any).namespaceURI = namespace;\n    return element;\n  }\n  \n  createTextNode(data: string): Text {\n    return new NucloText(data) as unknown as Text;\n  }\n  \n  /**\n   * `marker` is passed by nuclo's own text/list/when markers (see\n   * createMarker() in shared/dom.ts): renderToString() emits those verbatim\n   * and only inspects comments the app created itself.\n   */\n  createComment(data: string, marker?: boolean): Comment {\n    return new NucloComment(data, marker === true) as unknown as Comment;\n  }\n  \n  createDocumentFragment(): DocumentFragment {\n    return new SSRDocumentFragment() as unknown as DocumentFragment;\n  }\n  \n  // SSR never dispatches events: listeners are accepted and dropped, and\n  // queries find nothing.\n  querySelector(_selector: string): Element | null {\n    return null;\n  }\n\n  querySelectorAll(_selector: string): NodeListOf<Element> {\n    return [] as unknown as NodeListOf<Element>;\n  }\n\n  addEventListener(_type: string, _listener: EventListener, _options?: boolean | AddEventListenerOptions) {}\n\n  removeEventListener(_type: string, _listener: EventListener, _options?: boolean | AddEventListenerOptions) {}\n\n  dispatchEvent(_event: Event) {\n    return true;\n  }\n\n  contains(_node: Node) {\n    return false;\n  }\n}\n\nexport const document = globalThis.document || new NucloDocument();","/**\n * Polyfills for Node.js environments\n *\n * This module provides minimal browser API polyfills to allow Nuclo to run in Node.js\n * for server-side rendering (SSR).\n *\n * To use in Node.js:\n * ```typescript\n * import 'nuclo/polyfill';\n * // or\n * import { document, Event, CustomEvent } from 'nuclo/polyfill';\n * ```\n */\n\nexport { NucloDocument, document } from './Document';\nexport { NucloElement } from './Element';\nexport { NucloText } from './Text';\nexport { NucloNode } from './Node';\n\nimport { NucloElement } from './Element';\nimport { NucloNode } from './Node';\nimport { document } from './Document';\n\n// Event and CustomEvent are built into every supported runtime (Node >= 19,\n// Bun, Deno); re-exported for the documented named imports.\nexport const Event = globalThis.Event;\nexport const CustomEvent = globalThis.CustomEvent;\nexport const Node = NucloNode;\nexport const Element = NucloElement;\nexport const HTMLElement = NucloElement;\n\n// Auto-apply polyfills to globalThis if in Node environment (synchronous — no top-level await)\nif (typeof window === 'undefined') {\n  const g = globalThis as unknown as {\n    document?: typeof document;\n    Node?: typeof NucloNode;\n    Element?: typeof NucloElement;\n    HTMLElement?: typeof NucloElement;\n  };\n  g.document ??= document;\n  g.Node ??= NucloNode;\n  g.Element ??= NucloElement;\n  g.HTMLElement ??= NucloElement;\n}\n"],"mappings":"AACA,MAAaA,EAAuB,CAAC,EAUrC,SAAgBC,EAAU,EAAc,EAA6B,CAEnE,IAAMC,EADUC,EAAiE,YAC5D,WACrB,GAAI,CAACD,EAAM,OAAO,KAClB,IAAME,EAAI,MAAM,UAAU,QAAQ,KAAKF,EAAMC,CAAI,EACjD,OAAOC,IAAM,GAAK,KAAQF,EAAKE,EAAIC,IAAW,IAChD,CAKA,IAAaC,EAAb,KAAuB,CACrB,SAAW,EACX,SAAW,GACX,UAA2B,KAC3B,WAAsB,KACtB,YAAc,GAEd,IAAI,YAAoC,CACtC,OAAON,CACT,CAEA,IAAI,aAA2B,CAC7B,OAAOC,EAAU,KAAM,CAAC,CAC1B,CAEA,IAAI,iBAA+B,CACjC,OAAOA,EAAU,KAAM,EAAE,CAC3B,CACF,EAGaM,EAAb,cAAkCD,CAAU,CAC1C,KACA,OAEA,YAAY,EAAc,EAAiB,CACzC,MAAM,EACN,KAAK,SAAW,EAChB,KAAK,SAAW,WAChB,KAAK,KAAOE,EACZ,KAAK,YAAcA,EACnB,KAAK,UAAYA,EACjB,KAAK,OAASC,CAChB,CACF,EClDMC,EAAN,KAAe,CAGb,IAAI,SAAU,CACZ,IAAMC,EAAU,OAAO,QAAQ,IAAI,EAEnC,OADIA,EAAQ,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