nuclo 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -8
- package/dist/core/elementFactory.d.ts.map +1 -1
- package/dist/internal/applyModifiers.d.ts +4 -16
- package/dist/internal/applyModifiers.d.ts.map +1 -1
- package/dist/list/runtime.d.ts.map +1 -1
- package/dist/nuclo.cjs +1 -1
- package/dist/nuclo.cjs.map +1 -1
- package/dist/nuclo.mjs +1 -1
- package/dist/nuclo.mjs.map +1 -1
- package/dist/nuclo.umd.js +1 -1
- package/dist/nuclo.umd.js.map +1 -1
- package/dist/polyfill/Element.d.ts +9 -3
- package/dist/polyfill/Element.d.ts.map +1 -1
- package/dist/polyfill/nuclo.polyfill.cjs +1 -1
- package/dist/polyfill/nuclo.polyfill.cjs.map +1 -1
- package/dist/polyfill/nuclo.polyfill.mjs +1 -1
- package/dist/polyfill/nuclo.polyfill.mjs.map +1 -1
- package/dist/ssr/nuclo.ssr.cjs +1 -1
- package/dist/ssr/nuclo.ssr.cjs.map +1 -1
- package/dist/ssr/nuclo.ssr.mjs +1 -1
- package/dist/ssr/nuclo.ssr.mjs.map +1 -1
- package/dist/ssr/renderToString.d.ts.map +1 -1
- package/dist/style/engine.d.ts.map +1 -1
- package/dist/utility/dom.d.ts.map +1 -1
- package/dist/utility/domTypeHelpers.d.ts +0 -8
- package/dist/utility/domTypeHelpers.d.ts.map +1 -1
- package/dist/utility/on.d.ts +0 -7
- package/dist/utility/on.d.ts.map +1 -1
- package/package.json +8 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuclo.polyfill.mjs","names":["document","document"],"sources":["../../src/utility/environment.ts","../../src/polyfill/Node.ts","../../src/polyfill/Element.ts","../../src/polyfill/Text.ts","../../src/polyfill/Document.ts","../../src/polyfill/Event.ts","../../src/polyfill/index.ts"],"sourcesContent":["/**\n * Simplified environment detection - minimal overhead for smaller bundle size\n */\n\n// Basic environment detection - no complex caching or edge cases\nexport const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';\n","/**\n * Base Node class for instanceof checks in Node.js polyfill\n */\nexport class NucloNode {\n nodeType: number = 1; // ELEMENT_NODE\n nodeName: string = '';\n nodeValue: string | null = null;\n parentNode: unknown = null;\n _childNodes: Node[] | null = null;\n textContent: string = '';\n\n get childNodes(): NodeListOf<ChildNode> {\n const nodes = this._childNodes ?? [];\n return {\n ...nodes,\n length: nodes.length,\n item: (index: number) => (nodes[index] as ChildNode) || null,\n [Symbol.iterator]: function* () {\n for (const node of nodes) {\n yield node as ChildNode;\n }\n },\n forEach: (callback: (value: ChildNode, key: number, parent: NodeListOf<ChildNode>) => void) => {\n for (let i = 0; i < nodes.length; i++) {\n callback(nodes[i] as ChildNode, i, this.childNodes);\n }\n },\n entries: function* () {\n for (let i = 0; i < nodes.length; i++) {\n yield [i, nodes[i] as ChildNode] as [number, ChildNode];\n }\n },\n keys: function* () {\n for (let i = 0; i < nodes.length; i++) {\n yield i;\n }\n },\n values: function* () {\n for (const node of nodes) {\n yield node as ChildNode;\n }\n }\n } as unknown as NodeListOf<ChildNode>;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NucloNode } from './Node';\nimport { isBrowser } from '../utility/environment';\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(): string {\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): void {\n (this as Record<string, unknown>)[name] = value;\n }\n\n getPropertyValue(name: string): 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 add(...tokens: string[]): void {\n const classes = this._el.className ? this._el.className.split(' ').filter(Boolean) : [];\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[]): void {\n if (!this._el.className) return;\n this._el.className = this._el.className.split(' ').filter(c => c && !tokens.includes(c)).join(' ');\n }\n contains(token: string): boolean {\n return !!this._el.className && this._el.className.split(' ').includes(token);\n }\n toggle(token: string, force?: boolean): boolean {\n const has = this.contains(token);\n if (force === undefined) { if (has) { this.remove(token); return false; } this.add(token); return true; }\n if (force) { this.add(token); return true; }\n this.remove(token); return false;\n }\n replace(oldToken: string, newToken: string): boolean {\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._el.className.split(' ').filter(Boolean)[index]) ?? null; }\n get length(): number { return this._el.className ? this._el.className.split(' ').filter(Boolean).length : 0; }\n get value(): string { return this._el.className; }\n set value(v: string) { this._el.className = v; }\n toString(): string { return this._el.className; }\n supports(_token: string): boolean { return false; }\n forEach(cb: (value: string, key: number, parent: DOMTokenList) => void): void {\n const classes = this._el.className.split(' ').filter(Boolean);\n for (let i = 0; i < classes.length; i++) cb(classes[i], i, this as unknown as DOMTokenList);\n }\n [Symbol.iterator](): Iterator<string> {\n const classes = this._el.className.split(' ').filter(Boolean);\n let i = 0;\n return { next(): IteratorResult<string> { return i < classes.length ? { value: classes[i++], done: false } : { value: '', done: true }; } };\n }\n entries(): Iterator<[number, string]> {\n const classes = this._el.className.split(' ').filter(Boolean);\n let i = 0;\n return { next(): IteratorResult<[number, string]> { return i < classes.length ? { value: [i, classes[i++]], done: false } : { value: [0, ''], done: true }; } };\n }\n keys(): Iterator<number> {\n const len = this.length; let i = 0;\n return { next(): IteratorResult<number> { return i < len ? { value: i++, done: false } : { value: 0, done: true }; } };\n }\n values(): Iterator<string> { return this[Symbol.iterator](); }\n}\n\ninterface TextNode {\n nodeType: 3;\n textContent: string;\n}\n\ninterface CommentNode {\n nodeType: 8;\n data: string;\n}\n\nfunction isElementNode(node: unknown): node is NucloElement {\n return typeof node === 'object' && node !== null && 'tagName' in node;\n}\n\nfunction isTextNode(node: unknown): node is TextNode {\n return typeof node === 'object' && node !== null && 'nodeType' in node && (node as { nodeType: number }).nodeType === 3;\n}\n\nfunction isCommentNode(node: unknown): node is CommentNode {\n return typeof node === 'object' && node !== null && 'nodeType' in node && (node as { nodeType: number }).nodeType === 8;\n}\n\nexport class NucloElement extends NucloNode {\n tagName: string;\n children: unknown[];\n attributes: Map<string, string>;\n className: string = '';\n classList: DOMTokenList;\n textContent: string = '';\n private _innerHTML: string = '';\n parentNode: unknown = null;\n rawMods?: unknown[];\n mods?: unknown[];\n style: CSSStyleDeclaration;\n id: string = '';\n namespaceURI?: string;\n sheet?: CSSStyleSheet | null;\n private _listeners: Map<string, Set<EventListener>> | null;\n\n get innerHTML(): string {\n return this.serializeChildren();\n }\n\n set innerHTML(value: string) {\n this._innerHTML = value;\n }\n \n private serializeChildren(): string {\n let html = '';\n for (const child of this.children) {\n if (isElementNode(child)) {\n html += this.serializeElement(child);\n } else if (isTextNode(child)) {\n html += child.textContent || '';\n } else if (isCommentNode(child)) {\n html += `<!--${child.data || ''}-->`;\n }\n }\n return html;\n }\n \n private serializeElement(element: NucloElement): string {\n const tag = element.tagName.toLowerCase();\n let html = `<${tag}`;\n \n // Add attributes\n if (element.id) {\n html += ` id=\"${element.id}\"`;\n }\n if (element.className) {\n html += ` class=\"${element.className}\"`;\n }\n if (element.attributes) {\n for (const [name, value] of element.attributes) {\n if (name !== 'id' && name !== 'class') {\n html += ` ${name}=\"${value}\"`;\n }\n }\n }\n \n html += '>';\n \n // Add children\n if (element.children && element.children.length > 0) {\n for (const child of element.children) {\n if (isElementNode(child)) {\n html += this.serializeElement(child);\n } else if (isTextNode(child)) {\n html += child.textContent || '';\n } else if (isCommentNode(child)) {\n html += `<!--${child.data || ''}-->`;\n }\n }\n }\n \n html += `</${tag}>`;\n return html;\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 this.attributes = new Map<string, string>();\n\n if (!isBrowser) {\n // ── SSR path: minimal allocations, no Proxy, no event listeners ──\n this._listeners = null;\n\n // Prototype-based style — zero Object.defineProperty calls per element\n this.style = new SSRStyle() as unknown as CSSStyleDeclaration;\n\n // Prototype-based classList — zero closures per element\n this.classList = new SSRClassList(this) as unknown as DOMTokenList;\n // sheet stays undefined — not needed in SSR\n } else {\n // ── Browser path: full-featured Proxy style + DOMTokenList ──\n this._listeners = new Map();\n\n const styleProps: Record<string, string> = {};\n this.style = new Proxy({} as CSSStyleDeclaration, {\n get: (_target, prop: string) => {\n if (prop === 'setProperty') return (name: string, value: string) => { styleProps[name] = value; };\n if (prop === 'getPropertyValue') return (name: string) => styleProps[name] || '';\n if (prop === 'cssText') return Object.entries(styleProps).map(([k, v]) => `${k}: ${v}`).join('; ');\n return styleProps[prop];\n },\n set: (_target, prop: string, value: string) => { styleProps[prop] = value; return true; },\n });\n\n // CSSStyleSheet mock for style elements (browser only)\n if (this.tagName === 'style') {\n const cssRules: CSSRule[] = [];\n this.sheet = {\n cssRules: cssRules as unknown as CSSRuleList,\n insertRule: (rule: string, index?: number) => {\n const idx = index ?? cssRules.length;\n let mockRule: CSSRule;\n if (rule.trim().startsWith('@')) {\n const innerRules: CSSRule[] = [];\n const conditionText = rule.replace(/^@\\w+\\s+/, '').replace(/\\s*\\{[\\s\\S]*\\}$/, '').trim();\n mockRule = {\n cssText: rule, conditionText,\n media: { mediaText: conditionText } as MediaList,\n cssRules: innerRules as unknown as CSSRuleList,\n insertRule: (innerRule: string, innerIndex?: number) => {\n const innerIdx = innerIndex ?? innerRules.length;\n innerRules.splice(innerIdx, 0, { cssText: innerRule, selectorText: innerRule.split('{')[0].trim(), style: {} as CSSStyleDeclaration, type: 1 } as unknown as CSSRule);\n return innerIdx;\n },\n deleteRule: (i: number) => { innerRules.splice(i, 1); },\n type: 4,\n } as unknown as CSSRule;\n } else {\n mockRule = { cssText: rule, selectorText: rule.split('{')[0].trim(), style: {} as CSSStyleDeclaration, type: 1 } as unknown as CSSRule;\n }\n cssRules.splice(idx, 0, mockRule);\n return idx;\n },\n deleteRule: (index: number) => { cssRules.splice(index, 1); },\n } as unknown as CSSStyleSheet;\n }\n\n this.classList = createClassList(this);\n }\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 const kids = ((child as any).childNodes as Node[]).slice();\n for (let i = 0; i < kids.length; i++) this.appendChild(kids[i]);\n (child as any).childNodes = [];\n if ((child as any).children) (child as any).children = [];\n return child;\n }\n this.children.push(child);\n if (isBrowser && (this as any)['_childNodes']) {\n (this as any)['_childNodes'].push(child);\n }\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): void {\n this.attributes.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): void {\n this.attributes.delete(name);\n if (name === 'class') {\n this.className = '';\n }\n }\n \n hasAttribute(name: string): boolean {\n return this.attributes.has(name);\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[]).slice();\n for (let i = 0; i < kids.length; i++) this.insertBefore(kids[i], referenceNode);\n (newNode as any).childNodes = [];\n if ((newNode as any).children) (newNode as any).children = [];\n return newNode;\n }\n const index = this.children.indexOf(referenceNode);\n if (index !== -1) {\n this.children.splice(index, 0, newNode);\n if (isBrowser && (this as any)['_childNodes']) {\n const childNodesIndex = (this as any)['_childNodes'].indexOf(referenceNode);\n if (childNodesIndex !== -1) {\n (this as any)['_childNodes'].splice(childNodesIndex, 0, newNode);\n }\n }\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 (isBrowser && (this as any)['_childNodes']) {\n const cnIndex = (this as any)['_childNodes'].indexOf(child);\n if (cnIndex !== -1) {\n (this as any)['_childNodes'].splice(cnIndex, 1);\n }\n }\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 (isBrowser && (this as any)['_childNodes']) {\n const cnIndex = (this as any)['_childNodes'].indexOf(oldChild);\n if (cnIndex !== -1) {\n (this as any)['_childNodes'][cnIndex] = newChild;\n }\n }\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 addEventListener(type: string, listener: EventListener): void {\n if (!this._listeners) return;\n if (!this._listeners.has(type)) {\n this._listeners.set(type, new Set());\n }\n this._listeners.get(type)!.add(listener);\n }\n\n removeEventListener(type: string, listener: EventListener): void {\n const listeners = this._listeners?.get(type);\n if (listeners) {\n listeners.delete(listener);\n }\n }\n\n dispatchEvent(event: Event): boolean {\n const listeners = this._listeners?.get(event.type);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(event);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error in event listener:', error);\n }\n }\n }\n if (event.bubbles && this.parentNode && typeof this.parentNode === 'object' && 'dispatchEvent' in this.parentNode && typeof this.parentNode.dispatchEvent === 'function') {\n this.parentNode.dispatchEvent(event);\n }\n return true;\n }\n \n querySelector(selector: string): Element | null {\n // Simple implementation - supports basic selectors\n // #id, .class, tagName\n if (selector.startsWith('#')) {\n const id = selector.slice(1);\n return this.querySelectorById(id);\n } else if (selector.startsWith('.')) {\n const className = selector.slice(1);\n return this.querySelectorByClass(className);\n } else {\n // Tag name selector\n return this.querySelectorByTag(selector);\n }\n }\n \n private querySelectorById(id: string): Element | null {\n // Check self\n if (this.id === id) {\n return this as unknown as Element;\n }\n // Check children recursively\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.id === id) {\n return child as unknown as Element;\n }\n const found = child.querySelector(`#${id}`);\n if (found) return found;\n }\n }\n return null;\n }\n \n private querySelectorByClass(className: string): Element | null {\n // Check self\n if (this.classList.contains(className)) {\n return this as unknown as Element;\n }\n // Check children recursively\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.classList?.contains(className)) {\n return child as unknown as Element;\n }\n const found = child.querySelector(`.${className}`);\n if (found) return found;\n }\n }\n return null;\n }\n \n private querySelectorByTag(tagName: string): Element | null {\n const lowerTag = tagName.toLowerCase();\n // Check self\n if (this.tagName.toLowerCase() === lowerTag) {\n return this as unknown as Element;\n }\n // Check children recursively\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.tagName.toLowerCase() === lowerTag) {\n return child as unknown as Element;\n }\n const found = child.querySelector(tagName);\n if (found) return found;\n }\n }\n return null;\n }\n \n querySelectorAll(selector: string): NodeListOf<Element> {\n const results: Element[] = [];\n \n if (selector.startsWith('#')) {\n const found = this.querySelector(selector);\n if (found) results.push(found);\n } else if (selector.startsWith('.')) {\n const className = selector.slice(1);\n this.querySelectorAllByClass(className, results);\n } else {\n const tagName = selector.toLowerCase();\n this.querySelectorAllByTag(tagName, results);\n }\n \n return results as unknown as NodeListOf<Element>;\n }\n \n private querySelectorAllByClass(className: string, results: Element[]): void {\n if (this.classList.contains(className)) {\n results.push(this as unknown as Element);\n }\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.classList?.contains(className)) {\n results.push(child as unknown as Element);\n }\n child.querySelectorAllByClass(className, results);\n }\n }\n }\n \n private querySelectorAllByTag(tagName: string, results: Element[]): void {\n if (this.tagName.toLowerCase() === tagName) {\n results.push(this as unknown as Element);\n }\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.tagName.toLowerCase() === tagName) {\n results.push(child as unknown as Element);\n }\n child.querySelectorAllByTag(tagName, results);\n }\n }\n }\n}\n\nfunction createClassList(owner: NucloElement): DOMTokenList {\n const getClasses = () => owner.className.split(' ').filter((c) => c);\n const setClasses = (classes: string[]) => {\n owner.className = classes.join(' ');\n };\n\n const classList = {\n add: (...tokens: string[]) => {\n const classes = getClasses();\n for (const token of tokens) {\n if (token && !classes.includes(token)) {\n classes.push(token);\n }\n }\n setClasses(classes);\n },\n remove: (...tokens: string[]) => {\n if (tokens.length === 0) return;\n setClasses(getClasses().filter((c) => !tokens.includes(c)));\n },\n toggle: (token: string, force?: boolean) => {\n const hasClass = classList.contains(token);\n if (force === undefined) {\n if (hasClass) {\n classList.remove(token);\n return false;\n }\n classList.add(token);\n return true;\n }\n if (force) {\n classList.add(token);\n return true;\n }\n classList.remove(token);\n return false;\n },\n contains: (token: string) => getClasses().includes(token),\n replace: (oldToken: string, newToken: string) => {\n const classes = getClasses();\n const index = classes.indexOf(oldToken);\n if (index === -1) return false;\n classes[index] = newToken;\n setClasses(classes);\n return true;\n },\n item: (index: number) => getClasses()[index] || null,\n get length() {\n return getClasses().length;\n },\n toString: () => owner.className,\n [Symbol.iterator]: function* () {\n yield* getClasses();\n },\n forEach: (callback: (value: string, key: number, parent: DOMTokenList) => void) => {\n const classes = getClasses();\n for (let i = 0; i < classes.length; i++) {\n callback(classes[i], i, classList as unknown as DOMTokenList);\n }\n },\n entries: function* () {\n const classes = getClasses();\n for (let i = 0; i < classes.length; i++) {\n yield [i, classes[i]] as [number, string];\n }\n },\n keys: function* () {\n const classes = getClasses();\n for (let i = 0; i < classes.length; i++) {\n yield i;\n }\n },\n values: function* () {\n yield* getClasses();\n },\n get value() {\n return owner.className;\n },\n set value(value: string) {\n owner.className = value;\n },\n supports: (_token: string) => false\n };\n\n return classList as unknown as DOMTokenList;\n}\n","export 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(): string {\n return this.data;\n }\n \n set nodeValue(value: string) {\n this.data = value;\n this.textContent = value;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NucloElement } from './Element';\nimport { NucloText } from './Text';\n\n/**\n * Lightweight DocumentFragment for SSR — prototype methods instead of per-instance closures.\n */\nclass SSRDocumentFragment {\n nodeType: number = 11;\n nodeName: string = '#document-fragment';\n childNodes: Node[] = [];\n children: Element[] = [];\n textContent: string = '';\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 private _listeners: Map<string, Map<EventListener, { listener: EventListener; options?: boolean | AddEventListenerOptions }>>;\n \n constructor() {\n this.head = new NucloElement('head') as unknown as ExpandedElement;\n this.body = new NucloElement('body') as unknown as ExpandedElement;\n this._listeners = new Map();\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 createComment(data: string): Comment {\n const comment = {\n nodeType: 8,\n nodeName: '#comment',\n data,\n textContent: data,\n nodeValue: data,\n parentNode: null,\n nextSibling: null,\n previousSibling: null\n };\n return comment as unknown as Comment;\n }\n \n createDocumentFragment(): DocumentFragment {\n return new SSRDocumentFragment() as unknown as DocumentFragment;\n }\n \n querySelector(selector: string): Element | null {\n // Simple implementation - only supports ID selector for #nuclo-styles\n if (selector.startsWith('#')) {\n const id = selector.slice(1);\n if (id === 'nuclo-styles' && this.head.children) {\n for (const child of this.head.children) {\n if ((child as any).id === id) {\n return child as unknown as Element;\n }\n }\n }\n }\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): void {\n if (!this._listeners.has(type)) {\n this._listeners.set(type, new Map());\n }\n const listenersMap = this._listeners.get(type)!;\n listenersMap.set(listener, { listener, options });\n }\n \n removeEventListener(type: string, listener: EventListener, _options?: boolean | AddEventListenerOptions): void {\n const listeners = this._listeners.get(type);\n if (listeners) {\n listeners.delete(listener);\n // Clean up empty maps to prevent memory leaks\n if (listeners.size === 0) {\n this._listeners.delete(type);\n }\n }\n }\n \n dispatchEvent(event: Event): boolean {\n const listeners = this._listeners.get(event.type);\n if (listeners) {\n // Create a copy to avoid issues if listeners are modified during dispatch\n const listenersCopy = Array.from(listeners.values());\n for (let i = 0; i < listenersCopy.length; i++) {\n const { listener } = listenersCopy[i];\n try {\n listener(event);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error in event listener:', error);\n }\n }\n }\n return true;\n }\n \n contains(_node: Node): boolean {\n return false;\n }\n}\n\nexport const document = globalThis.document || new NucloDocument();","/* eslint-disable @typescript-eslint/no-explicit-any */\nexport class NucloEvent implements Event {\n type: string;\n bubbles: boolean;\n cancelable: boolean;\n composed: boolean;\n currentTarget: EventTarget | null = null;\n defaultPrevented: boolean = false;\n eventPhase: number = 0;\n isTrusted: boolean = false;\n target: EventTarget | null = null;\n timeStamp: number;\n readonly AT_TARGET = 2;\n readonly BUBBLING_PHASE = 3;\n readonly CAPTURING_PHASE = 1;\n readonly NONE = 0;\n returnValue: boolean = true;\n srcElement: EventTarget | null = null;\n cancelBubble: boolean = false;\n \n constructor(type: string, eventInitDict?: EventInit) {\n this.type = type;\n this.bubbles = eventInitDict?.bubbles || false;\n this.cancelable = eventInitDict?.cancelable || false;\n this.composed = eventInitDict?.composed || false;\n this.timeStamp = Date.now();\n }\n \n composedPath(): EventTarget[] {\n return [];\n }\n \n initEvent(_type: string, _bubbles?: boolean, _cancelable?: boolean): void {\n // Legacy method - no-op\n }\n \n preventDefault(): void {\n if (this.cancelable) {\n this.defaultPrevented = true;\n }\n }\n \n stopImmediatePropagation(): void {\n this.cancelBubble = true;\n }\n \n stopPropagation(): void {\n this.cancelBubble = true;\n }\n}\n\nexport class NucloCustomEvent<T = any> extends NucloEvent implements CustomEvent<T> {\n detail: T;\n \n constructor(type: string, eventInitDict?: CustomEventInit<T>) {\n super(type, eventInitDict);\n this.detail = eventInitDict?.detail as T;\n }\n \n initCustomEvent(_type: string, _bubbles?: boolean, _cancelable?: boolean, _detail?: T): void {\n // Legacy method - no-op\n }\n}\n\n// Export polyfills if browser globals don't exist\nexport const Event = globalThis.Event || NucloEvent;\nexport const CustomEvent = globalThis.CustomEvent || NucloCustomEvent;\n","/**\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) scenarios.\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 { NucloEvent, NucloCustomEvent, Event, CustomEvent } from './Event';\nexport { NucloNode } from './Node';\n\n// Import for local use\nimport { NucloElement } from './Element';\nimport { NucloNode } from './Node';\nimport { document } from './Document';\nimport { Event, CustomEvent } from './Event';\n\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' && typeof globalThis !== 'undefined') {\n interface GlobalWithPolyfills {\n document?: typeof document;\n Event?: typeof Event;\n CustomEvent?: typeof CustomEvent;\n Node?: typeof NucloNode;\n Element?: typeof NucloElement;\n HTMLElement?: typeof NucloElement;\n }\n\n const g = globalThis as unknown as GlobalWithPolyfills;\n\n if (!g.document) g.document = document;\n if (!g.Event) g.Event = Event;\n if (!g.CustomEvent) g.CustomEvent = CustomEvent;\n if (!g.Node) g.Node = NucloNode;\n if (!g.Element) g.Element = NucloElement;\n if (!g.HTMLElement) g.HTMLElement = NucloElement;\n}\n"],"mappings":"AAKA,MAAa,EAAY,OAAO,OAAW,KAAe,OAAO,SAAa,ICF9E,IAAa,EAAb,KAAuB,CACrB,SAAmB,EACnB,SAAmB,GACnB,UAA2B,KAC3B,WAAsB,KACtB,YAA6B,KAC7B,YAAsB,GAEtB,IAAI,YAAoC,CACtC,IAAM,EAAQ,KAAK,aAAe,CAAC,EACnC,MAAO,CACL,GAAG,EACH,OAAQ,EAAM,OACd,KAAO,GAAmB,EAAM,IAAwB,KACxD,CAAC,OAAO,UAAW,WAAa,CAC9B,IAAK,IAAM,KAAQ,EACjB,MAAM,CAEV,EACA,QAAU,GAAqF,CAC7F,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,EAAS,EAAM,GAAiB,EAAG,KAAK,UAAU,CAEtD,EACA,QAAS,WAAa,CACpB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,KAAM,CAAC,EAAG,EAAM,EAAe,CAEnC,EACA,KAAM,WAAa,CACjB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAChC,MAAM,CAEV,EACA,OAAQ,WAAa,CACnB,IAAK,IAAM,KAAQ,EACjB,MAAM,CAEV,CACF,CACF,CACF,ECpCM,EAAN,KAAe,CAGb,IAAI,SAAkB,CACpB,IAAM,EAAU,OAAO,QAAQ,IAAI,EAEnC,OADI,EAAQ,SAAW,EAAU,GAC1B,EAAQ,KAAK,CAAC,EAAG,KAAO,GAAG,EAAE,IAAI,GAAG,CAAC,CAAC,KAAK,IAAI,CACxD,CAEA,YAAY,EAAc,EAAqB,C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AAU,EAC5B,AAAoB,EAAE,cAAc,CACtC"}
|
|
1
|
+
{"version":3,"file":"nuclo.polyfill.mjs","names":["document","document"],"sources":["../../src/utility/environment.ts","../../src/polyfill/Node.ts","../../src/polyfill/Element.ts","../../src/polyfill/Text.ts","../../src/polyfill/Document.ts","../../src/polyfill/Event.ts","../../src/polyfill/index.ts"],"sourcesContent":["/**\n * Simplified environment detection - minimal overhead for smaller bundle size\n */\n\n// Basic environment detection - no complex caching or edge cases\nexport const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';\n","/**\n * Base Node class for instanceof checks in Node.js polyfill\n */\nexport class NucloNode {\n nodeType: number = 1; // ELEMENT_NODE\n nodeName: string = '';\n nodeValue: string | null = null;\n parentNode: unknown = null;\n _childNodes: Node[] | null = null;\n textContent: string = '';\n\n get childNodes(): NodeListOf<ChildNode> {\n const nodes = this._childNodes ?? [];\n return {\n ...nodes,\n length: nodes.length,\n item: (index: number) => (nodes[index] as ChildNode) || null,\n [Symbol.iterator]: function* () {\n for (const node of nodes) {\n yield node as ChildNode;\n }\n },\n forEach: (callback: (value: ChildNode, key: number, parent: NodeListOf<ChildNode>) => void) => {\n for (let i = 0; i < nodes.length; i++) {\n callback(nodes[i] as ChildNode, i, this.childNodes);\n }\n },\n entries: function* () {\n for (let i = 0; i < nodes.length; i++) {\n yield [i, nodes[i] as ChildNode] as [number, ChildNode];\n }\n },\n keys: function* () {\n for (let i = 0; i < nodes.length; i++) {\n yield i;\n }\n },\n values: function* () {\n for (const node of nodes) {\n yield node as ChildNode;\n }\n }\n } as unknown as NodeListOf<ChildNode>;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NucloNode } from './Node';\nimport { isBrowser } from '../utility/environment';\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(): string {\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): void {\n (this as Record<string, unknown>)[name] = value;\n }\n\n getPropertyValue(name: string): 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 add(...tokens: string[]): void {\n const classes = this._el.className ? this._el.className.split(' ').filter(Boolean) : [];\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[]): void {\n if (!this._el.className) return;\n this._el.className = this._el.className.split(' ').filter(c => c && !tokens.includes(c)).join(' ');\n }\n contains(token: string): boolean {\n return !!this._el.className && this._el.className.split(' ').includes(token);\n }\n toggle(token: string, force?: boolean): boolean {\n const has = this.contains(token);\n if (force === undefined) { if (has) { this.remove(token); return false; } this.add(token); return true; }\n if (force) { this.add(token); return true; }\n this.remove(token); return false;\n }\n replace(oldToken: string, newToken: string): boolean {\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._el.className.split(' ').filter(Boolean)[index]) ?? null; }\n get length(): number { return this._el.className ? this._el.className.split(' ').filter(Boolean).length : 0; }\n get value(): string { return this._el.className; }\n set value(v: string) { this._el.className = v; }\n toString(): string { return this._el.className; }\n supports(_token: string): boolean { return false; }\n forEach(cb: (value: string, key: number, parent: DOMTokenList) => void): void {\n const classes = this._el.className.split(' ').filter(Boolean);\n for (let i = 0; i < classes.length; i++) cb(classes[i], i, this as unknown as DOMTokenList);\n }\n [Symbol.iterator](): Iterator<string> {\n const classes = this._el.className.split(' ').filter(Boolean);\n let i = 0;\n return { next(): IteratorResult<string> { return i < classes.length ? { value: classes[i++], done: false } : { value: '', done: true }; } };\n }\n entries(): Iterator<[number, string]> {\n const classes = this._el.className.split(' ').filter(Boolean);\n let i = 0;\n return { next(): IteratorResult<[number, string]> { return i < classes.length ? { value: [i, classes[i++]], done: false } : { value: [0, ''], done: true }; } };\n }\n keys(): Iterator<number> {\n const len = this.length; let i = 0;\n return { next(): IteratorResult<number> { return i < len ? { value: i++, done: false } : { value: 0, done: true }; } };\n }\n values(): Iterator<string> { return this[Symbol.iterator](); }\n}\n\ninterface TextNode {\n nodeType: 3;\n textContent: string;\n}\n\ninterface CommentNode {\n nodeType: 8;\n data: string;\n}\n\nfunction isElementNode(node: unknown): node is NucloElement {\n return typeof node === 'object' && node !== null && 'tagName' in node;\n}\n\nfunction isTextNode(node: unknown): node is TextNode {\n return typeof node === 'object' && node !== null && 'nodeType' in node && (node as { nodeType: number }).nodeType === 3;\n}\n\nfunction isCommentNode(node: unknown): node is CommentNode {\n return typeof node === 'object' && node !== null && 'nodeType' in node && (node as { nodeType: number }).nodeType === 8;\n}\n\nexport class NucloElement extends NucloNode {\n tagName: string;\n children: unknown[];\n className: string = '';\n textContent: string = '';\n private _innerHTML: string = '';\n parentNode: unknown = null;\n rawMods?: unknown[];\n mods?: unknown[];\n id: string = '';\n namespaceURI?: string;\n sheet?: CSSStyleSheet | null;\n private _listeners: Map<string, Set<EventListener>> | null;\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 was pure allocation churn. The browser\n // path assigns these in the constructor, so its getter never lazy-allocates.\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 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 get innerHTML(): string {\n return this.serializeChildren();\n }\n\n set innerHTML(value: string) {\n this._innerHTML = value;\n }\n \n private serializeChildren(): string {\n let html = '';\n for (const child of this.children) {\n if (isElementNode(child)) {\n html += this.serializeElement(child);\n } else if (isTextNode(child)) {\n html += child.textContent || '';\n } else if (isCommentNode(child)) {\n html += `<!--${child.data || ''}-->`;\n }\n }\n return html;\n }\n \n private serializeElement(element: NucloElement): string {\n const tag = element.tagName.toLowerCase();\n let html = `<${tag}`;\n \n // Add attributes\n if (element.id) {\n html += ` id=\"${element.id}\"`;\n }\n if (element.className) {\n html += ` class=\"${element.className}\"`;\n }\n if (element._attributes) {\n for (const [name, value] of element._attributes) {\n if (name !== 'id' && name !== 'class') {\n html += ` ${name}=\"${value}\"`;\n }\n }\n }\n \n html += '>';\n \n // Add children\n if (element.children && element.children.length > 0) {\n for (const child of element.children) {\n if (isElementNode(child)) {\n html += this.serializeElement(child);\n } else if (isTextNode(child)) {\n html += child.textContent || '';\n } else if (isCommentNode(child)) {\n html += `<!--${child.data || ''}-->`;\n }\n }\n }\n \n html += `</${tag}>`;\n return html;\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 if (!isBrowser) {\n // ── SSR path: minimal allocations, no Proxy, no event listeners ──\n // style and classList stay unallocated until first access (see getters).\n this._listeners = null;\n } else {\n // ── Browser path: full-featured Proxy style + DOMTokenList ──\n this._listeners = new Map();\n\n const styleProps: Record<string, string> = {};\n this.style = new Proxy({} as CSSStyleDeclaration, {\n get: (_target, prop: string) => {\n if (prop === 'setProperty') return (name: string, value: string) => { styleProps[name] = value; };\n if (prop === 'getPropertyValue') return (name: string) => styleProps[name] || '';\n if (prop === 'cssText') return Object.entries(styleProps).map(([k, v]) => `${k}: ${v}`).join('; ');\n return styleProps[prop];\n },\n set: (_target, prop: string, value: string) => { styleProps[prop] = value; return true; },\n });\n\n // CSSStyleSheet mock for style elements (browser only)\n if (this.tagName === 'style') {\n const cssRules: CSSRule[] = [];\n this.sheet = {\n cssRules: cssRules as unknown as CSSRuleList,\n insertRule: (rule: string, index?: number) => {\n const idx = index ?? cssRules.length;\n let mockRule: CSSRule;\n if (rule.trim().startsWith('@')) {\n const innerRules: CSSRule[] = [];\n const conditionText = rule.replace(/^@\\w+\\s+/, '').replace(/\\s*\\{[\\s\\S]*\\}$/, '').trim();\n mockRule = {\n cssText: rule, conditionText,\n media: { mediaText: conditionText } as MediaList,\n cssRules: innerRules as unknown as CSSRuleList,\n insertRule: (innerRule: string, innerIndex?: number) => {\n const innerIdx = innerIndex ?? innerRules.length;\n innerRules.splice(innerIdx, 0, { cssText: innerRule, selectorText: innerRule.split('{')[0].trim(), style: {} as CSSStyleDeclaration, type: 1 } as unknown as CSSRule);\n return innerIdx;\n },\n deleteRule: (i: number) => { innerRules.splice(i, 1); },\n type: 4,\n } as unknown as CSSRule;\n } else {\n mockRule = { cssText: rule, selectorText: rule.split('{')[0].trim(), style: {} as CSSStyleDeclaration, type: 1 } as unknown as CSSRule;\n }\n cssRules.splice(idx, 0, mockRule);\n return idx;\n },\n deleteRule: (index: number) => { cssRules.splice(index, 1); },\n } as unknown as CSSStyleSheet;\n }\n\n this.classList = createClassList(this);\n }\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 const kids = ((child as any).childNodes as Node[]).slice();\n for (let i = 0; i < kids.length; i++) this.appendChild(kids[i]);\n (child as any).childNodes = [];\n if ((child as any).children) (child as any).children = [];\n return child;\n }\n this.children.push(child);\n if (isBrowser && (this as any)['_childNodes']) {\n (this as any)['_childNodes'].push(child);\n }\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): void {\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): void {\n this._attributes?.delete(name);\n if (name === 'class') {\n this.className = '';\n }\n }\n\n hasAttribute(name: string): boolean {\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[]).slice();\n for (let i = 0; i < kids.length; i++) this.insertBefore(kids[i], referenceNode);\n (newNode as any).childNodes = [];\n if ((newNode as any).children) (newNode as any).children = [];\n return newNode;\n }\n const index = this.children.indexOf(referenceNode);\n if (index !== -1) {\n this.children.splice(index, 0, newNode);\n if (isBrowser && (this as any)['_childNodes']) {\n const childNodesIndex = (this as any)['_childNodes'].indexOf(referenceNode);\n if (childNodesIndex !== -1) {\n (this as any)['_childNodes'].splice(childNodesIndex, 0, newNode);\n }\n }\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 (isBrowser && (this as any)['_childNodes']) {\n const cnIndex = (this as any)['_childNodes'].indexOf(child);\n if (cnIndex !== -1) {\n (this as any)['_childNodes'].splice(cnIndex, 1);\n }\n }\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 (isBrowser && (this as any)['_childNodes']) {\n const cnIndex = (this as any)['_childNodes'].indexOf(oldChild);\n if (cnIndex !== -1) {\n (this as any)['_childNodes'][cnIndex] = newChild;\n }\n }\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 addEventListener(type: string, listener: EventListener): void {\n if (!this._listeners) return;\n if (!this._listeners.has(type)) {\n this._listeners.set(type, new Set());\n }\n this._listeners.get(type)!.add(listener);\n }\n\n removeEventListener(type: string, listener: EventListener): void {\n const listeners = this._listeners?.get(type);\n if (listeners) {\n listeners.delete(listener);\n }\n }\n\n dispatchEvent(event: Event): boolean {\n const listeners = this._listeners?.get(event.type);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(event);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error in event listener:', error);\n }\n }\n }\n if (event.bubbles && this.parentNode && typeof this.parentNode === 'object' && 'dispatchEvent' in this.parentNode && typeof this.parentNode.dispatchEvent === 'function') {\n this.parentNode.dispatchEvent(event);\n }\n return true;\n }\n \n querySelector(selector: string): Element | null {\n // Simple implementation - supports basic selectors\n // #id, .class, tagName\n if (selector.startsWith('#')) {\n const id = selector.slice(1);\n return this.querySelectorById(id);\n } else if (selector.startsWith('.')) {\n const className = selector.slice(1);\n return this.querySelectorByClass(className);\n } else {\n // Tag name selector\n return this.querySelectorByTag(selector);\n }\n }\n \n private querySelectorById(id: string): Element | null {\n // Check self\n if (this.id === id) {\n return this as unknown as Element;\n }\n // Check children recursively\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.id === id) {\n return child as unknown as Element;\n }\n const found = child.querySelector(`#${id}`);\n if (found) return found;\n }\n }\n return null;\n }\n \n private querySelectorByClass(className: string): Element | null {\n // Check self\n if (this.classList.contains(className)) {\n return this as unknown as Element;\n }\n // Check children recursively\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.classList?.contains(className)) {\n return child as unknown as Element;\n }\n const found = child.querySelector(`.${className}`);\n if (found) return found;\n }\n }\n return null;\n }\n \n private querySelectorByTag(tagName: string): Element | null {\n const lowerTag = tagName.toLowerCase();\n // Check self\n if (this.tagName.toLowerCase() === lowerTag) {\n return this as unknown as Element;\n }\n // Check children recursively\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.tagName.toLowerCase() === lowerTag) {\n return child as unknown as Element;\n }\n const found = child.querySelector(tagName);\n if (found) return found;\n }\n }\n return null;\n }\n \n querySelectorAll(selector: string): NodeListOf<Element> {\n const results: Element[] = [];\n \n if (selector.startsWith('#')) {\n const found = this.querySelector(selector);\n if (found) results.push(found);\n } else if (selector.startsWith('.')) {\n const className = selector.slice(1);\n this.querySelectorAllByClass(className, results);\n } else {\n const tagName = selector.toLowerCase();\n this.querySelectorAllByTag(tagName, results);\n }\n \n return results as unknown as NodeListOf<Element>;\n }\n \n private querySelectorAllByClass(className: string, results: Element[]): void {\n if (this.classList.contains(className)) {\n results.push(this as unknown as Element);\n }\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.classList?.contains(className)) {\n results.push(child as unknown as Element);\n }\n child.querySelectorAllByClass(className, results);\n }\n }\n }\n \n private querySelectorAllByTag(tagName: string, results: Element[]): void {\n if (this.tagName.toLowerCase() === tagName) {\n results.push(this as unknown as Element);\n }\n for (const child of this.children) {\n if (isElementNode(child)) {\n if (child.tagName.toLowerCase() === tagName) {\n results.push(child as unknown as Element);\n }\n child.querySelectorAllByTag(tagName, results);\n }\n }\n }\n}\n\nfunction createClassList(owner: NucloElement): DOMTokenList {\n const getClasses = () => owner.className.split(' ').filter((c) => c);\n const setClasses = (classes: string[]) => {\n owner.className = classes.join(' ');\n };\n\n const classList = {\n add: (...tokens: string[]) => {\n const classes = getClasses();\n for (const token of tokens) {\n if (token && !classes.includes(token)) {\n classes.push(token);\n }\n }\n setClasses(classes);\n },\n remove: (...tokens: string[]) => {\n if (tokens.length === 0) return;\n setClasses(getClasses().filter((c) => !tokens.includes(c)));\n },\n toggle: (token: string, force?: boolean) => {\n const hasClass = classList.contains(token);\n if (force === undefined) {\n if (hasClass) {\n classList.remove(token);\n return false;\n }\n classList.add(token);\n return true;\n }\n if (force) {\n classList.add(token);\n return true;\n }\n classList.remove(token);\n return false;\n },\n contains: (token: string) => getClasses().includes(token),\n replace: (oldToken: string, newToken: string) => {\n const classes = getClasses();\n const index = classes.indexOf(oldToken);\n if (index === -1) return false;\n classes[index] = newToken;\n setClasses(classes);\n return true;\n },\n item: (index: number) => getClasses()[index] || null,\n get length() {\n return getClasses().length;\n },\n toString: () => owner.className,\n [Symbol.iterator]: function* () {\n yield* getClasses();\n },\n forEach: (callback: (value: string, key: number, parent: DOMTokenList) => void) => {\n const classes = getClasses();\n for (let i = 0; i < classes.length; i++) {\n callback(classes[i], i, classList as unknown as DOMTokenList);\n }\n },\n entries: function* () {\n const classes = getClasses();\n for (let i = 0; i < classes.length; i++) {\n yield [i, classes[i]] as [number, string];\n }\n },\n keys: function* () {\n const classes = getClasses();\n for (let i = 0; i < classes.length; i++) {\n yield i;\n }\n },\n values: function* () {\n yield* getClasses();\n },\n get value() {\n return owner.className;\n },\n set value(value: string) {\n owner.className = value;\n },\n supports: (_token: string) => false\n };\n\n return classList as unknown as DOMTokenList;\n}\n","export 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(): string {\n return this.data;\n }\n \n set nodeValue(value: string) {\n this.data = value;\n this.textContent = value;\n }\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NucloElement } from './Element';\nimport { NucloText } from './Text';\n\n/**\n * Lightweight DocumentFragment for SSR — prototype methods instead of per-instance closures.\n */\nclass SSRDocumentFragment {\n nodeType: number = 11;\n nodeName: string = '#document-fragment';\n childNodes: Node[] = [];\n children: Element[] = [];\n textContent: string = '';\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 private _listeners: Map<string, Map<EventListener, { listener: EventListener; options?: boolean | AddEventListenerOptions }>>;\n \n constructor() {\n this.head = new NucloElement('head') as unknown as ExpandedElement;\n this.body = new NucloElement('body') as unknown as ExpandedElement;\n this._listeners = new Map();\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 createComment(data: string): Comment {\n const comment = {\n nodeType: 8,\n nodeName: '#comment',\n data,\n textContent: data,\n nodeValue: data,\n parentNode: null,\n nextSibling: null,\n previousSibling: null\n };\n return comment as unknown as Comment;\n }\n \n createDocumentFragment(): DocumentFragment {\n return new SSRDocumentFragment() as unknown as DocumentFragment;\n }\n \n querySelector(selector: string): Element | null {\n // Simple implementation - only supports ID selector for #nuclo-styles\n if (selector.startsWith('#')) {\n const id = selector.slice(1);\n if (id === 'nuclo-styles' && this.head.children) {\n for (const child of this.head.children) {\n if ((child as any).id === id) {\n return child as unknown as Element;\n }\n }\n }\n }\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): void {\n if (!this._listeners.has(type)) {\n this._listeners.set(type, new Map());\n }\n const listenersMap = this._listeners.get(type)!;\n listenersMap.set(listener, { listener, options });\n }\n \n removeEventListener(type: string, listener: EventListener, _options?: boolean | AddEventListenerOptions): void {\n const listeners = this._listeners.get(type);\n if (listeners) {\n listeners.delete(listener);\n // Clean up empty maps to prevent memory leaks\n if (listeners.size === 0) {\n this._listeners.delete(type);\n }\n }\n }\n \n dispatchEvent(event: Event): boolean {\n const listeners = this._listeners.get(event.type);\n if (listeners) {\n // Create a copy to avoid issues if listeners are modified during dispatch\n const listenersCopy = Array.from(listeners.values());\n for (let i = 0; i < listenersCopy.length; i++) {\n const { listener } = listenersCopy[i];\n try {\n listener(event);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error in event listener:', error);\n }\n }\n }\n return true;\n }\n \n contains(_node: Node): boolean {\n return false;\n }\n}\n\nexport const document = globalThis.document || new NucloDocument();","/* eslint-disable @typescript-eslint/no-explicit-any */\nexport class NucloEvent implements Event {\n type: string;\n bubbles: boolean;\n cancelable: boolean;\n composed: boolean;\n currentTarget: EventTarget | null = null;\n defaultPrevented: boolean = false;\n eventPhase: number = 0;\n isTrusted: boolean = false;\n target: EventTarget | null = null;\n timeStamp: number;\n readonly AT_TARGET = 2;\n readonly BUBBLING_PHASE = 3;\n readonly CAPTURING_PHASE = 1;\n readonly NONE = 0;\n returnValue: boolean = true;\n srcElement: EventTarget | null = null;\n cancelBubble: boolean = false;\n \n constructor(type: string, eventInitDict?: EventInit) {\n this.type = type;\n this.bubbles = eventInitDict?.bubbles || false;\n this.cancelable = eventInitDict?.cancelable || false;\n this.composed = eventInitDict?.composed || false;\n this.timeStamp = Date.now();\n }\n \n composedPath(): EventTarget[] {\n return [];\n }\n \n initEvent(_type: string, _bubbles?: boolean, _cancelable?: boolean): void {\n // Legacy method - no-op\n }\n \n preventDefault(): void {\n if (this.cancelable) {\n this.defaultPrevented = true;\n }\n }\n \n stopImmediatePropagation(): void {\n this.cancelBubble = true;\n }\n \n stopPropagation(): void {\n this.cancelBubble = true;\n }\n}\n\nexport class NucloCustomEvent<T = any> extends NucloEvent implements CustomEvent<T> {\n detail: T;\n \n constructor(type: string, eventInitDict?: CustomEventInit<T>) {\n super(type, eventInitDict);\n this.detail = eventInitDict?.detail as T;\n }\n \n initCustomEvent(_type: string, _bubbles?: boolean, _cancelable?: boolean, _detail?: T): void {\n // Legacy method - no-op\n }\n}\n\n// Export polyfills if browser globals don't exist\nexport const Event = globalThis.Event || NucloEvent;\nexport const CustomEvent = globalThis.CustomEvent || NucloCustomEvent;\n","/**\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) scenarios.\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 { NucloEvent, NucloCustomEvent, Event, CustomEvent } from './Event';\nexport { NucloNode } from './Node';\n\n// Import for local use\nimport { NucloElement } from './Element';\nimport { NucloNode } from './Node';\nimport { document } from './Document';\nimport { Event, CustomEvent } from './Event';\n\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' && typeof globalThis !== 'undefined') {\n interface GlobalWithPolyfills {\n document?: typeof document;\n Event?: typeof Event;\n CustomEvent?: typeof CustomEvent;\n Node?: typeof NucloNode;\n Element?: typeof NucloElement;\n HTMLElement?: typeof NucloElement;\n }\n\n const g = globalThis as unknown as GlobalWithPolyfills;\n\n if (!g.document) g.document = document;\n if (!g.Event) g.Event = Event;\n if (!g.CustomEvent) g.CustomEvent = CustomEvent;\n if (!g.Node) g.Node = NucloNode;\n if (!g.Element) g.Element = NucloElement;\n if (!g.HTMLElement) g.HTMLElement = NucloElement;\n}\n"],"mappings":"AAKA,MAAa,EAAY,OAAO,OAAW,KAAe,OAAO,SAAa,ICF9E,IAAa,EAAb,KAAuB,CACrB,SAAmB,EACnB,SAAmB,GACnB,UAA2B,KAC3B,WAAsB,KACtB,YAA6B,KAC7B,YAAsB,GAEtB,IAAI,YAAoC,CACtC,IAAM,EAAQ,KAAK,aAAe,CAA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AyC,CACvC,KACA,QACA,WACA,SACA,cAAoC,KACpC,iBAA4B,GAC5B,WAAqB,EACrB,UAAqB,GACrB,OAA6B,KAC7B,UACA,UAAqB,EACrB,eAA0B,EAC1B,gBAA2B,EAC3B,KAAgB,EAChB,YAAuB,GACvB,WAAiC,KACjC,aAAwB,GAExB,YAAY,EAAc,EAA2B,CACnD,KAAK,KAAO,EACZ,KAAK,QAAU,GAAe,SAAW,GACzC,KAAK,WAAa,GAAe,YAAc,GAC/C,KAAK,SAAW,GAAe,UAAY,GAC3C,KAAK,UAAY,KAAK,IAAI,CAC5B,CAEA,cAA8B,CAC5B,MAAO,CAAC,CACV,CAEA,UAAU,EAAe,EAAoB,EAA6B,CAE1E,CAEA,gBAAuB,CACjB,KAAK,aACP,KAAK,iBAAmB,GAE5B,CAEA,0BAAiC,CAC/B,KAAK,aAAe,EACtB,CAEA,iBAAwB,CACtB,KAAK,aAAe,EACtB,CACF,EAEa,EAAb,cAA+C,CAAqC,CAClF,OAEA,YAAY,EAAc,EAAoC,CAC5D,MAAM,EAAM,CAAa,EACzB,KAAK,OAAS,GAAe,MAC/B,CAEA,gBAAgB,EAAe,EAAoB,EAAuB,EAAmB,CAE7F,CACF,EAGA,MAAa,EAAQ,WAAW,OAAS,EAC5B,EAAc,WAAW,aAAe,ECxCxC,EAAO,EACP,EAAU,EACV,EAAc,EAG3B,GAAI,OAAO,OAAW,KAAe,OAAO,WAAe,IAAa,CAUtE,IAAM,EAAI,WAEV,AAAiB,EAAE,WAAWC,EAC9B,AAAc,EAAE,QAAQ,EACxB,AAAoB,EAAE,cAAc,EACpC,AAAa,EAAE,OAAO,EACtB,AAAgB,EAAE,UAAU,EAC5B,AAAoB,EAAE,cAAc,CACtC"}
|
package/dist/ssr/nuclo.ssr.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let t=0;for(;t<e.length;t++){let n=e.charCodeAt(t);if(n>=65&&n<=90)break}if(t===e.length)return e;let n=e.slice(0,t);for(let r=t;r<e.length;r++){let t=e.charCodeAt(r);t>=65&&t<=90?(r>0&&(n+=`-`),n+=String.fromCharCode(t+32)):n+=e[r]}return n}const t=/[&<>"']/,n=/[&<>]/;function r(e){let n=t.exec(e);if(!n)return e;let r=``,i=0;for(let t=n.index;t<e.length;t++){let n;switch(e.charCodeAt(t)){case 38:n=`&`;break;case 60:n=`<`;break;case 62:n=`>`;break;case 34:n=`"`;break;case 39:n=`'`;break;default:continue}r+=e.slice(i,t)+n,i=t+1}return r+e.slice(i)}function i(e){let t=n.exec(e);if(!t)return e;let r=``,i=0;for(let n=t.index;n<e.length;n++){let t;switch(e.charCodeAt(n)){case 38:t=`&`;break;case 60:t=`<`;break;case 62:t=`>`;break;default:continue}r+=e.slice(i,n)+t,i=n+1}return r+e.slice(i)}const a=new Set,o=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{a.delete(e)}),typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{o.delete(e)});const s=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{s.delete(e)});function c(e){return globalThis.document?document.createElement(e):null}const l=new Set(`viewBox.preserveAspectRatio.markerWidth.markerHeight.gradientTransform.patternTransform.clipPathUnits.gradientUnits.patternUnits.pathLength.refX.refY.stdDeviation.baseFrequency.numOctaves.kernelMatrix.tableValues.targetX.targetY.specularExponent.specularConstant.diffuseConstant.surfaceScale.xChannelSelector.yChannelSelector.edgeMode.stitchTiles.spreadMethod.patternContentUnits.markerUnits.startOffset.textLength.lengthAdjust`.split(`.`)),u=new Set([`allowfullscreen`,`async`,`autofocus`,`autoplay`,`checked`,`controls`,`default`,`defer`,`disabled`,`formnovalidate`,`hidden`,`ismap`,`loop`,`multiple`,`muted`,`nomodule`,`novalidate`,`open`,`readonly`,`required`,`reversed`,`selected`]);function d(t,n){if(n==null||n===!1)return``;if(n===!0)return` ${t}`;if(u.has(t)){if(n===`false`)return``;if(n===`true`||n===``||n===t)return` ${t}`}if(t===`style`&&typeof n==`object`){let t=``;for(let r in n){let i=n[r];i==null||i===``||(t+=(t?` `:``)+e(r)+`: `+String(i)+`;`)}return t?` style="${r(t)}"`:``}return` ${t}="${r(String(n))}"`}function f(t){let n=``;if(
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){let t=0;for(;t<e.length;t++){let n=e.charCodeAt(t);if(n>=65&&n<=90)break}if(t===e.length)return e;let n=e.slice(0,t);for(let r=t;r<e.length;r++){let t=e.charCodeAt(r);t>=65&&t<=90?(r>0&&(n+=`-`),n+=String.fromCharCode(t+32)):n+=e[r]}return n}const t=/[&<>"']/,n=/[&<>]/;function r(e){let n=t.exec(e);if(!n)return e;let r=``,i=0;for(let t=n.index;t<e.length;t++){let n;switch(e.charCodeAt(t)){case 38:n=`&`;break;case 60:n=`<`;break;case 62:n=`>`;break;case 34:n=`"`;break;case 39:n=`'`;break;default:continue}r+=e.slice(i,t)+n,i=t+1}return r+e.slice(i)}function i(e){let t=n.exec(e);if(!t)return e;let r=``,i=0;for(let n=t.index;n<e.length;n++){let t;switch(e.charCodeAt(n)){case 38:t=`&`;break;case 60:t=`<`;break;case 62:t=`>`;break;default:continue}r+=e.slice(i,n)+t,i=n+1}return r+e.slice(i)}const a=new Set,o=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{a.delete(e)}),typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{o.delete(e)});const s=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{s.delete(e)});function c(e){return globalThis.document?document.createElement(e):null}const l=new Set(`viewBox.preserveAspectRatio.markerWidth.markerHeight.gradientTransform.patternTransform.clipPathUnits.gradientUnits.patternUnits.pathLength.refX.refY.stdDeviation.baseFrequency.numOctaves.kernelMatrix.tableValues.targetX.targetY.specularExponent.specularConstant.diffuseConstant.surfaceScale.xChannelSelector.yChannelSelector.edgeMode.stitchTiles.spreadMethod.patternContentUnits.markerUnits.startOffset.textLength.lengthAdjust`.split(`.`)),u=new Set([`allowfullscreen`,`async`,`autofocus`,`autoplay`,`checked`,`controls`,`default`,`defer`,`disabled`,`formnovalidate`,`hidden`,`ismap`,`loop`,`multiple`,`muted`,`nomodule`,`novalidate`,`open`,`readonly`,`required`,`reversed`,`selected`]);function d(t,n){if(n==null||n===!1)return``;if(n===!0)return` ${t}`;if(u.has(t)){if(n===`false`)return``;if(n===`true`||n===``||n===t)return` ${t}`}if(t===`style`&&typeof n==`object`){let t=``;for(let r in n){let i=n[r];i==null||i===``||(t+=(t?` `:``)+e(r)+`: `+String(i)+`;`)}return t?` style="${r(t)}"`:``}return` ${t}="${r(String(n))}"`}function f(t){let n=``;if(Array.isArray(t.children)){let i=t,a=i._attributes;i.id&&!a?.has(`id`)&&(n+=d(`id`,i.id)),i.className&&!a?.has(`class`)&&(n+=d(`class`,i.className));let o=i._style;if(!a?.has(`style`)&&o){let t=o.cssText||``;if(t){let i=t.split(`;`).map(e=>e.trim()).filter(Boolean).map(t=>{let n=t.indexOf(`:`);if(n===-1)return t;let r=t.slice(0,n).trim(),i=t.slice(n+1).trim();return i?`${e(r)}: ${i};`:``}).filter(Boolean).join(` `);i&&(n+=` style="${r(i)}"`)}}if(a)for(let[t,r]of a){let i=l.has(t)?t:e(t);n+=d(i,r)}return n}if(t.attributes&&t.attributes.length)for(let e=0;e<t.attributes.length;e++){let r=t.attributes[e];r&&r.name&&(n+=d(r.name,r.value))}return n}const p=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),m=new Set([`script`,`style`]);function h(e,t){return t.replace(RegExp(`</(`+e+`)`,`gi`),`<\\/$1`)}function g(e){if(`tagName`in e&&`children`in e){let t=e.children;if(Array.isArray(t))return t}if(`childNodes`in e){let t=e.childNodes;if(t&&(Array.isArray(t)||t.length!==void 0))return t}return[]}function _(e){if(e.nodeType===3)return i(e.textContent||``);if(e.nodeType===8)return`<!--${e.textContent||``}-->`;if(e.nodeType===1){let t=e,n=t.tagName.toLowerCase(),r=f(t);if(p.has(n))return`<${n}${r} />`;if(m.has(n)){let i=``,a=g(t);if(a&&a.length>0)for(let e=0;e<a.length;e++){let t=a[e];t&&t.nodeType===3&&(i+=t.textContent||``)}else{let t=e.textContent;typeof t==`string`&&(i=t)}return`<${n}${r}>${h(n,i)}</${n}>`}let a=``,o=g(t);if(o&&o.length>0)for(let e=0;e<o.length;e++){let t=o[e];t&&(a+=_(t))}else{let t=e.textContent;typeof t==`string`&&t&&(a=i(t))}return`<${n}${r}>${a}</${n}>`}if(e.nodeType===11){let t=``,n=g(e);if(n&&n.length>0)for(let e=0;e<n.length;e++){let r=n[e];r&&(t+=_(r))}return t}return``}function v(e){if(!e)return``;if(typeof e==`function`)try{let t=c(`div`);if(!t)throw Error(`Document is not available. Make sure polyfills are loaded.`);let n=e(t,0);return n&&typeof n==`object`&&`nodeType`in n?_(n):``}catch(e){return console.error(`Error rendering component to string:`,e),``}return`nodeType`in e?_(e):``}function y(e){return e.map(e=>v(e))}function b(e,t=`div`,n={}){let r=v(e);return`<${t}${Object.entries(n).map(([e,t])=>d(e,t)).join(``)}>${r}</${t}>`}function x(e){}const S=[],C=new Map;let w=null;function T(){if(w!==null)return w;let e=S.join(``);for(let[t,n]of C)n.length>0&&(e+=t+`{`+n.join(``)+`}`);return w=e,e}exports.getCssText=T,exports.renderManyToString=y,exports.renderToString=v,exports.renderToStringWithContainer=b,exports.setSSRCollector=x;
|
|
2
2
|
//# sourceMappingURL=nuclo.ssr.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuclo.ssr.cjs","names":[],"sources":["../../src/utility/stringUtils.ts","../../src/core/reactiveCleanup.ts","../../src/utility/conditionalInfo.ts","../../src/utility/dom.ts","../../src/ssr/renderToString.ts","../../src/style/engine.ts"],"sourcesContent":["/**\n * String utility functions\n */\n\n/**\n * Converts camelCase to kebab-case (optimized for performance)\n * Uses direct character code manipulation for maximum speed\n * @example camelToKebab('backgroundColor') => 'background-color'\n */\nexport function camelToKebab(str: string): string {\n // Fast path: attribute/property names are usually already lowercase.\n let firstUpper = 0;\n for (; firstUpper < str.length; firstUpper++) {\n const code = str.charCodeAt(firstUpper);\n if (code >= 65 && code <= 90) break;\n }\n if (firstUpper === str.length) return str;\n\n let result = str.slice(0, firstUpper);\n for (let i = firstUpper; i < str.length; i++) {\n const code = str.charCodeAt(i);\n // A-Z is 65-90, a-z is 97-122 (difference of 32)\n if (code >= 65 && code <= 90) {\n if (i > 0) result += '-';\n result += String.fromCharCode(code + 32);\n } else {\n result += str[i];\n }\n }\n return result;\n}\n\nconst ATTR_ESCAPE_RE = /[&<>\"']/;\nconst TEXT_ESCAPE_RE = /[&<>]/;\n\n/**\n * Escapes HTML special characters in attribute values (includes \" and ')\n */\nexport function escapeHtml(text: string): string {\n // Fast path: most strings contain no special characters at all.\n const first = ATTR_ESCAPE_RE.exec(text);\n if (!first) return text;\n\n let result = '';\n let last = 0;\n for (let i = first.index; i < text.length; i++) {\n let escaped: string;\n switch (text.charCodeAt(i)) {\n case 38: escaped = '&'; break; // &\n case 60: escaped = '<'; break; // <\n case 62: escaped = '>'; break; // >\n case 34: escaped = '"'; break; // \"\n case 39: escaped = '''; break; // '\n default: continue;\n }\n result += text.slice(last, i) + escaped;\n last = i + 1;\n }\n return result + text.slice(last);\n}\n\n/**\n * Escapes HTML special characters in text node content.\n * Only &, < and > need escaping — quotes are safe inside text nodes.\n */\nexport function escapeText(text: string): string {\n const first = TEXT_ESCAPE_RE.exec(text);\n if (!first) return text;\n\n let result = '';\n let last = 0;\n for (let i = first.index; i < text.length; i++) {\n let escaped: string;\n switch (text.charCodeAt(i)) {\n case 38: escaped = '&'; break; // &\n case 60: escaped = '<'; break; // <\n case 62: escaped = '>'; break; // >\n default: continue;\n }\n result += text.slice(last, i) + escaped;\n last = i + 1;\n }\n return result + text.slice(last);\n}\n","/**\n * Shared types and registries for reactive nodes.\n * Single source of truth — imported by reactiveText.ts and reactiveAttributes.ts.\n *\n * Registry structure: the iteration sets only hold WeakRefs; the actual info\n * records live in WeakMaps keyed by the node. Info records may strongly\n * reference the node (e.g. attribute applyValue closures capture the\n * element), so storing them in a strongly-held map would pin the node in\n * memory forever. With WeakMap storage the whole record is collectible as\n * soon as the node is unreachable, and the FinalizationRegistry prunes the\n * leftover WeakRef from the iteration set. The notify passes also prune\n * dead/disconnected entries as they iterate.\n */\n\nexport type TextResolver = () => Primitive;\n\nexport interface ReactiveTextNodeInfo {\n resolver: TextResolver;\n lastValue: string;\n}\n\nexport type AttributeResolver = () => unknown;\n\nexport interface AttributeResolverRecord {\n resolver: AttributeResolver;\n applyValue: (value: unknown) => void;\n lastValue: unknown;\n}\n\nexport interface ReactiveElementInfo {\n attributeResolvers: Map<string, AttributeResolverRecord>;\n}\n\n/**\n * Iteration set of weak references to reactive text nodes.\n */\nexport const reactiveTextNodes = new Set<WeakRef<Text>>();\n\n/**\n * WeakMap for O(1) lookups of reactive text node info by node reference.\n */\nexport const reactiveTextNodesByNode = new WeakMap<Text, { ref: WeakRef<Text>; info: ReactiveTextNodeInfo }>();\n\n/**\n * Iteration set of weak references to reactive elements.\n */\nexport const reactiveElements = new Set<WeakRef<Element>>();\n\n/**\n * WeakMap for O(1) lookups of reactive element info by element reference.\n */\nexport const reactiveElementsByNode = new WeakMap<Element, { ref: WeakRef<Element>; info: ReactiveElementInfo }>();\n\nconst textNodeFinalizer = typeof FinalizationRegistry !== \"undefined\"\n ? new FinalizationRegistry<WeakRef<Text>>((ref) => { reactiveTextNodes.delete(ref); })\n : null;\n\nconst elementFinalizer = typeof FinalizationRegistry !== \"undefined\"\n ? new FinalizationRegistry<WeakRef<Element>>((ref) => { reactiveElements.delete(ref); })\n : null;\n\n/**\n * Registers a reactive text node in both lookup structures.\n */\nexport function registerReactiveTextNode(node: Text, info: ReactiveTextNodeInfo): void {\n const existing = reactiveTextNodesByNode.get(node);\n if (existing) {\n // Re-registration (e.g. repeated hydration): replace the info in place.\n existing.info.resolver = info.resolver;\n existing.info.lastValue = info.lastValue;\n return;\n }\n const ref = new WeakRef(node);\n reactiveTextNodes.add(ref);\n reactiveTextNodesByNode.set(node, { ref, info });\n textNodeFinalizer?.register(node, ref);\n}\n\n/**\n * Registers a reactive element in both lookup structures.\n */\nexport function registerReactiveElement(element: Element, info: ReactiveElementInfo): void {\n const ref = new WeakRef(element);\n reactiveElements.add(ref);\n reactiveElementsByNode.set(element, { ref, info });\n elementFinalizer?.register(element, ref);\n}\n\n/**\n * Removes a reactive text node's WeakRef entry from the iteration set.\n */\nexport function removeReactiveTextNodeRef(ref: WeakRef<Text>): void {\n reactiveTextNodes.delete(ref);\n}\n\n/**\n * Removes a reactive element's WeakRef entry from the iteration set.\n */\nexport function removeReactiveElementRef(ref: WeakRef<Element>): void {\n reactiveElements.delete(ref);\n}\n\n/**\n * Manually removes reactive text node info for a specific text node.\n * This should be called when a text node is removed from the DOM to prevent memory leaks.\n */\nexport function cleanupReactiveTextNode(node: Text): void {\n const entry = reactiveTextNodesByNode.get(node);\n if (entry) {\n reactiveTextNodes.delete(entry.ref);\n reactiveTextNodesByNode.delete(node);\n }\n}\n\n/**\n * Manually removes reactive element info for a specific element.\n * This should be called when an element is removed from the DOM to prevent memory leaks.\n */\nexport function cleanupReactiveElement(element: Element): void {\n const entry = reactiveElementsByNode.get(element);\n if (entry) {\n reactiveElements.delete(entry.ref);\n reactiveElementsByNode.delete(element);\n }\n}\n","export interface ConditionalInfo<TTagName extends ElementTagName = ElementTagName> {\n\tcondition: () => boolean;\n\ttagName: TTagName;\n\tmodifiers: Array<NodeMod<TTagName> | NodeModFn<TTagName>>;\n\tisSvg: boolean;\n}\n\n// WeakMap replaces the _conditionalInfo expando property — zero `any`, no DOM pollution, auto-GC.\nconst conditionalInfoMap = new WeakMap<Node, ConditionalInfo<ElementTagName>>();\n\n/**\n * Registry of all nodes that have conditional info attached.\n * Uses WeakRef to prevent memory leaks — allows garbage collection of removed nodes.\n * This enables O(nConditionals) updates instead of a full DOM tree walk.\n */\nconst activeConditionalNodes = new Set<WeakRef<Node>>();\n\n/**\n * Reverse lookup for O(1) unregister — maps node to its WeakRef in the active set.\n */\nconst refByNode = new WeakMap<Node, WeakRef<Node>>();\n\n/**\n * Prunes dead WeakRefs from the active set as soon as their node is\n * collected, instead of waiting for the next getActiveConditionalNodes() pass.\n */\nconst conditionalNodeFinalizer = typeof FinalizationRegistry !== \"undefined\"\n\t? new FinalizationRegistry<WeakRef<Node>>((ref) => { activeConditionalNodes.delete(ref); })\n\t: null;\n\n/**\n * Attach conditional info to a node and register it.\n */\nexport function storeConditionalInfo<TTagName extends ElementTagName>(\n\tnode: Node,\n\tinfo: ConditionalInfo<TTagName>\n): void {\n\tconditionalInfoMap.set(node, info as ConditionalInfo<ElementTagName>);\n\tconst ref = new WeakRef(node);\n\tactiveConditionalNodes.add(ref);\n\trefByNode.set(node, ref);\n\tconditionalNodeFinalizer?.register(node, ref);\n}\n\n/**\n * Explicit unregister helper (optional use on teardown if needed).\n * O(1) via reverse lookup WeakMap.\n */\nexport function unregisterConditionalNode(node: Node): void {\n\tconditionalInfoMap.delete(node);\n\tconst ref = refByNode.get(node);\n\tif (ref) {\n\t\tactiveConditionalNodes.delete(ref);\n\t\trefByNode.delete(node);\n\t}\n}\n\n/**\n * Returns an array of currently tracked conditional nodes that are still alive.\n * Automatically cleans up garbage-collected nodes.\n */\nexport function getActiveConditionalNodes(): Node[] {\n\tconst nodes: Node[] = [];\n\tconst toDelete: WeakRef<Node>[] = [];\n\n\tfor (const ref of activeConditionalNodes) {\n\t\tconst node = ref.deref();\n\t\tif (node === undefined) {\n\t\t\ttoDelete.push(ref);\n\t\t} else {\n\t\t\tnodes.push(node);\n\t\t}\n\t}\n\n\tfor (const ref of toDelete) {\n\t\tactiveConditionalNodes.delete(ref);\n\t}\n\n\treturn nodes;\n}\n\nexport function getConditionalInfo(node: Node): ConditionalInfo<ElementTagName> | null {\n\treturn conditionalInfoMap.get(node) ?? null;\n}\n","import { logError } from \"./errorHandler\";\nimport { removeAllListeners } from \"./on\";\nimport { cleanupReactiveTextNode, cleanupReactiveElement } from \"../core/reactiveCleanup\";\nimport { unregisterConditionalNode } from \"./conditionalInfo\";\n\nexport const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\n/**\n * Creates an HTML element.\n * Wrapper for document.createElement with type safety.\n */\nexport function createElement<K extends keyof HTMLElementTagNameMap>(\n tagName: K\n): HTMLElementTagNameMap[K] | null;\nexport function createElement(tagName: string): ExpandedElement | null;\nexport function createElement(tagName: string): ExpandedElement | null {\n return globalThis.document ? document.createElement(tagName) as ExpandedElement : null;\n}\n\n/**\n * Creates an element in the given namespace (typically for SVG elements).\n * Wrapper for document.createElementNS with type safety.\n */\nexport function createElementNS(\n namespace: string,\n tagName: string\n): ExpandedElement | null {\n return globalThis.document ? document.createElementNS(namespace, tagName) as ExpandedElement : null;\n}\n\n/**\n * Creates a text node with the given content.\n * Wrapper for document.createTextNode.\n */\nexport function createTextNode(text: string): Text | null {\n return globalThis.document ? document.createTextNode(text) : null;\n}\n\n/**\n * Creates a document fragment.\n * Wrapper for document.createDocumentFragment.\n */\nexport function createDocumentFragment(): DocumentFragment | null {\n return globalThis.document ? document.createDocumentFragment() : null;\n}\n\nfunction safeAppendChild(parent: Element | Node, child: Node): boolean {\n try {\n parent.appendChild(child);\n return true;\n } catch (error) {\n logError('Failed to append child node', error);\n return false;\n }\n}\n\n/**\n * Recursively removes all event listeners and reactive subscriptions from a node and its descendants\n * to prevent memory leaks when elements are removed from the DOM.\n */\nfunction cleanupNodeTree(node: Node): void {\n // Clean up the node itself based on its type\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = node as HTMLElement;\n // Remove all event listeners\n removeAllListeners(element);\n // Remove reactive attribute resolvers\n cleanupReactiveElement(element);\n // Remove conditional info\n unregisterConditionalNode(element);\n } else if (node.nodeType === Node.TEXT_NODE) {\n // Remove reactive text node info\n cleanupReactiveTextNode(node as Text);\n } else if (node.nodeType === Node.COMMENT_NODE) {\n // Remove conditional info from comment nodes (used by when/list)\n unregisterConditionalNode(node);\n }\n \n // Recursively clean up all child nodes\n if (node.childNodes && node.childNodes.length > 0) {\n for (let i = 0; i < node.childNodes.length; i++) {\n cleanupNodeTree(node.childNodes[i]);\n }\n }\n}\n\nexport function safeRemoveChild(child: Node): boolean {\n if (!child?.parentNode) return false;\n try {\n // Clean up all event listeners before removing the element\n cleanupNodeTree(child);\n child.parentNode.removeChild(child);\n return true;\n } catch (error) {\n logError('Failed to remove child node', error);\n return false;\n }\n}\n\nfunction safeInsertBefore(parent: Node, newNode: Node, referenceNode: Node | null): boolean {\n try {\n parent.insertBefore(newNode, referenceNode);\n return true;\n } catch (error) {\n logError('Failed to insert node before reference', error);\n return false;\n }\n}\n\nexport function createComment(text: string): Comment | null {\n return globalThis.document ? globalThis.document.createComment(text) : null;\n}\n\nexport function createConditionalComment(tagName: string, suffix = \"hidden\"): Comment | null {\n return globalThis.document ? globalThis.document.createComment(`conditional-${tagName}-${suffix}`) : null;\n}\n\nexport function createMarkerPair(prefix: string, id: number | string): { start: Comment; end: Comment } {\n const endComment = createComment(`${prefix}-end`);\n if (!endComment) throw new Error(\"Failed to create comment: document not available\");\n const startComment = createComment(`${prefix}-start-${id}`);\n if (!startComment) throw new Error(\"Failed to create comment: document not available\");\n return { start: startComment, end: endComment };\n}\n\nexport function clearBetweenMarkers(startMarker: Comment, endMarker: Comment): void {\n let current = startMarker.nextSibling;\n while (current && current !== endMarker) {\n const next = current.nextSibling;\n safeRemoveChild(current);\n current = next;\n }\n}\n\nexport function insertNodesBefore(nodes: Node[], referenceNode: Node): void {\n const parent = referenceNode.parentNode;\n if (parent) {\n for (let i = 0; i < nodes.length; i++) {\n safeInsertBefore(parent, nodes[i], referenceNode);\n }\n }\n}\n\nexport function appendChildren(\n parent: Element | Node,\n ...children: Array<Element | Node | string | null | undefined>\n): Element | Node {\n if (!parent) return parent;\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (child != null) {\n let nodeToAppend: Node;\n\n if (typeof child === \"string\") {\n const textNode = createTextNode(child);\n if (textNode) {\n nodeToAppend = textNode;\n } else {\n continue;\n }\n } else {\n nodeToAppend = child as Node;\n }\n\n safeAppendChild(parent, nodeToAppend);\n }\n }\n\n return parent;\n}\n\nexport function isNodeConnected(node: Node | null | undefined): boolean {\n if (!node) return false;\n return node.isConnected === true;\n}\n\n/**\n * Safely replaces an old node with a new node in the DOM.\n * Returns true on success, false on failure (and logs the error).\n */\nexport function replaceNodeSafely(oldNode: Node, newNode: Node): boolean {\n if (!oldNode?.parentNode) return false;\n try {\n oldNode.parentNode.replaceChild(newNode, oldNode);\n return true;\n } catch (error) {\n logError(\"Error replacing conditional node\", error);\n return false;\n }\n}\n","/**\n * Server-Side Rendering (SSR) utilities for Nuclo\n * Renders Nuclo components to HTML strings in Node.js environment\n */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { escapeHtml, escapeText, camelToKebab } from '../utility/stringUtils';\nimport { createElement } from '../utility/dom';\n\ntype RenderableInput =\n | NodeModFn<ElementTagName>\n | Element\n | Node\n | null\n | undefined;\n\n/**\n * SVG attributes that are natively camelCase and must NOT be converted to kebab-case.\n * Most SVG attributes are already kebab-case (stroke-width, fill-rule, etc.), but a\n * handful are defined as camelCase in the SVG spec and must be preserved.\n */\nconst SVG_PRESERVE_CASE_ATTRS = new Set([\n 'viewBox', 'preserveAspectRatio', 'markerWidth', 'markerHeight',\n 'gradientTransform', 'patternTransform', 'clipPathUnits', 'gradientUnits',\n 'patternUnits', 'pathLength', 'refX', 'refY', 'stdDeviation',\n 'baseFrequency', 'numOctaves', 'kernelMatrix', 'tableValues',\n 'targetX', 'targetY', 'specularExponent', 'specularConstant',\n 'diffuseConstant', 'surfaceScale', 'xChannelSelector', 'yChannelSelector',\n 'edgeMode', 'stitchTiles', 'spreadMethod', 'patternContentUnits',\n 'markerUnits', 'startOffset', 'textLength', 'lengthAdjust',\n]);\n\n/**\n * HTML boolean attributes — presence means true, absence means false.\n * When the stored value is the string \"true\" or \"false\" (from setAttribute),\n * we must re-apply boolean semantics instead of outputting the raw string.\n */\nconst HTML_BOOLEAN_ATTRIBUTES = new Set([\n 'allowfullscreen', 'async', 'autofocus', 'autoplay', 'checked', 'controls',\n 'default', 'defer', 'disabled', 'formnovalidate', 'hidden', 'ismap', 'loop',\n 'multiple', 'muted', 'nomodule', 'novalidate', 'open', 'readonly', 'required',\n 'reversed', 'selected',\n]);\n\n/**\n * Serializes a DOM attribute value\n */\nfunction serializeAttribute(name: string, value: unknown): string {\n if (value === null || value === undefined || value === false) {\n return '';\n }\n\n if (value === true) {\n return ` ${name}`;\n }\n\n // Boolean attributes stored as strings via setAttribute() need special handling\n if (HTML_BOOLEAN_ATTRIBUTES.has(name)) {\n if (value === 'false') return '';\n if (value === 'true' || value === '' || value === name) return ` ${name}`;\n }\n\n if (name === 'style' && typeof value === 'object') {\n let styleStr = '';\n for (const key in value as Record<string, unknown>) {\n const val = (value as Record<string, unknown>)[key];\n if (val == null || val === '') continue;\n styleStr += (styleStr ? ' ' : '') + camelToKebab(key) + ': ' + String(val) + ';';\n }\n return styleStr ? ` style=\"${escapeHtml(styleStr)}\"` : '';\n }\n\n return ` ${name}=\"${escapeHtml(String(value))}\"`;\n}\n\n/**\n * Serializes DOM element attributes to HTML string\n */\nfunction serializeAttributes(element: Element): string {\n let result = '';\n\n // Handle polyfill elements with Map-based attributes\n if ('attributes' in element && element.attributes instanceof Map) {\n const el = element as any;\n\n // id — may live on the property rather than in the Map\n if (el.id && !element.attributes.has('id')) {\n result += serializeAttribute('id', el.id);\n }\n\n // class — kept on .className, mirrored to Map only when setAttribute is used\n if (el.className && !element.attributes.has('class')) {\n result += serializeAttribute('class', el.className);\n }\n\n // style — lives on the Proxy, not in the attributes Map.\n // cssText returns camelCase keys (\"backgroundColor: red\"), so convert them.\n if (!element.attributes.has('style') && el.style) {\n const rawCssText: string = el.style.cssText || '';\n if (rawCssText) {\n const kebabStyle = rawCssText\n .split(';')\n .map((decl: string) => decl.trim())\n .filter(Boolean)\n .map((decl: string) => {\n const colonIdx = decl.indexOf(':');\n if (colonIdx === -1) return decl;\n const key = decl.slice(0, colonIdx).trim();\n const val = decl.slice(colonIdx + 1).trim();\n // Skip declarations with empty values (e.g. reactive styles that resolved to undefined)\n if (!val) return '';\n return `${camelToKebab(key)}: ${val};`;\n })\n .filter(Boolean)\n .join(' ');\n if (kebabStyle) {\n result += ` style=\"${escapeHtml(kebabStyle)}\"`;\n }\n }\n }\n\n // All remaining attributes from the Map\n // Convert camelCase ARIA/HTML attribute names (e.g. ariaLabel → aria-label) that the\n // polyfill stores as-is because NucloElement lacks the browser property mappings.\n // SVG attributes that are natively camelCase (e.g. viewBox, preserveAspectRatio) must\n // NOT be converted — they are stored via setAttribute() as-is.\n for (const [name, value] of element.attributes) {\n const htmlName = SVG_PRESERVE_CASE_ATTRS.has(name) ? name : camelToKebab(name);\n result += serializeAttribute(htmlName, value);\n }\n return result;\n }\n\n // Handle browser elements with NamedNodeMap attributes\n if (element.attributes && element.attributes.length) {\n for (let i = 0; i < element.attributes.length; i++) {\n const attr = element.attributes[i];\n if (attr && attr.name) {\n result += serializeAttribute(attr.name, attr.value);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Self-closing HTML tags that don't have closing tags\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n]);\n\n/**\n * Raw-text elements — browsers never decode entities inside them, so their\n * text content must be emitted verbatim (escaping would corrupt inline JS/CSS,\n * e.g. `a < b` becoming `a < b` inside a script). A closing-tag sequence\n * in the content would terminate the element early, so it is neutralized.\n */\nconst RAW_TEXT_ELEMENTS = new Set(['script', 'style']);\n\nfunction escapeRawText(tagName: string, text: string): string {\n // \"</script\" (any case) inside a script would close it — break the sequence\n // the same way JSON serializers do (\"<\\/script\").\n return text.replace(new RegExp('</(' + tagName + ')', 'gi'), '<\\\\/$1');\n}\n\n/**\n * Get child nodes from a node (handles both browser and polyfill elements).\n *\n * NucloElement stores ALL children (elements, text, comments) in a plain Array\n * called `children` — it is the authoritative list. DocumentFragments in the\n * polyfill also have a `children` array, but it only holds Element children;\n * their full set of nodes lives in `childNodes`. We therefore only prefer\n * `children` when the node is an actual element (has `tagName`).\n */\nfunction getChildNodes(node: Node): ArrayLike<Node> {\n // NucloElement: tagName exists and children is a plain Array containing every node type\n if ('tagName' in node && 'children' in node) {\n const children = (node as any).children;\n if (Array.isArray(children)) {\n return children as ArrayLike<Node>;\n }\n }\n // DocumentFragments and browser elements: use childNodes\n if ('childNodes' in node) {\n const childNodes = (node as any).childNodes;\n if (childNodes && (Array.isArray(childNodes) || childNodes.length !== undefined)) {\n return childNodes;\n }\n }\n return [] as ArrayLike<Node>;\n}\n\n/**\n * Serializes a DOM node to HTML string\n */\nfunction serializeNode(node: Node): string {\n // Text node — only & < > need escaping; quotes are safe in text content\n if (node.nodeType === 3) { // Node.TEXT_NODE\n return escapeText(node.textContent || '');\n }\n\n // Comment node\n if (node.nodeType === 8) { // Node.COMMENT_NODE\n return `<!--${node.textContent || ''}-->`;\n }\n\n // Element node\n if (node.nodeType === 1) { // Node.ELEMENT_NODE\n const element = node as Element;\n const tagName = element.tagName.toLowerCase();\n const attributes = serializeAttributes(element);\n\n // Self-closing tags\n if (VOID_ELEMENTS.has(tagName)) {\n return `<${tagName}${attributes} />`;\n }\n\n // Raw-text elements: emit text verbatim (no entity escaping, no Nuclo\n // text markers — `<!--` would act as a line comment inside a script).\n if (RAW_TEXT_ELEMENTS.has(tagName)) {\n let rawContent = '';\n const rawChildren = getChildNodes(element);\n if (rawChildren && rawChildren.length > 0) {\n for (let i = 0; i < rawChildren.length; i++) {\n const child = rawChildren[i];\n if (child && child.nodeType === 3) {\n rawContent += child.textContent || '';\n }\n }\n } else {\n const tc = (node as { textContent?: unknown }).textContent;\n if (typeof tc === 'string') rawContent = tc;\n }\n return `<${tagName}${attributes}>${escapeRawText(tagName, rawContent)}</${tagName}>`;\n }\n\n // Regular elements with children\n let childrenHtml = '';\n const childNodes = getChildNodes(element);\n if (childNodes && childNodes.length > 0) {\n for (let i = 0; i < childNodes.length; i++) {\n const child = childNodes[i];\n if (child) {\n childrenHtml += serializeNode(child);\n }\n }\n } else {\n // Fallback: textContent set directly on the element (e.g. el.textContent = \"...\")\n const tc = (node as any).textContent;\n if (typeof tc === 'string' && tc) {\n childrenHtml = escapeText(tc);\n }\n }\n\n return `<${tagName}${attributes}>${childrenHtml}</${tagName}>`;\n }\n\n // Document fragment\n if (node.nodeType === 11) { // Node.DOCUMENT_FRAGMENT_NODE\n let result = '';\n const childNodes = getChildNodes(node);\n if (childNodes && childNodes.length > 0) {\n for (let i = 0; i < childNodes.length; i++) {\n const child = childNodes[i];\n if (child) {\n result += serializeNode(child);\n }\n }\n }\n return result;\n }\n\n return '';\n}\n\n/**\n * Renders a Nuclo component to an HTML string for server-side rendering\n *\n * @param input - A Nuclo component function, DOM element, or node\n * @returns HTML string representation of the component\n *\n * @example\n * ```ts\n * import { renderToString } from 'nuclo/ssr';\n * import { div } from 'nuclo';\n *\n * const html = renderToString(\n * div(\"Hello, World!\")\n * );\n * // Returns: '<div>Hello, World!</div>'\n * ```\n */\nexport function renderToString(input: RenderableInput): string {\n if (!input) return '';\n\n if (typeof input === 'function') {\n try {\n const container = createElement('div');\n if (!container) throw new Error('Document is not available. Make sure polyfills are loaded.');\n const element = input(container as ExpandedElement<ElementTagName>, 0);\n return element && typeof element === 'object' && 'nodeType' in element ? serializeNode(element as Node) : '';\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error rendering component to string:', error);\n return '';\n }\n }\n\n if ('nodeType' in input) {\n return serializeNode(input as Node);\n }\n\n return '';\n}\n\n/**\n * Renders multiple Nuclo components to HTML strings\n *\n * @param inputs - Array of Nuclo components\n * @returns Array of HTML strings\n */\nexport function renderManyToString(inputs: RenderableInput[]): string[] {\n return inputs.map(input => renderToString(input));\n}\n\n/**\n * Renders a Nuclo component and wraps it in a container element\n *\n * @param input - A Nuclo component\n * @param containerTag - The tag name for the container (default: 'div')\n * @param containerAttrs - Attributes for the container element\n * @returns HTML string with container wrapper\n */\nexport function renderToStringWithContainer(\n input: RenderableInput,\n containerTag: string = 'div',\n containerAttrs: Record<string, string> = {}\n): string {\n const content = renderToString(input);\n const attrs = Object.entries(containerAttrs)\n .map(([key, value]) => serializeAttribute(key, value))\n .join('');\n\n return `<${containerTag}${attrs}>${content}</${containerTag}>`;\n}\n","/**\n * Shared atomic-CSS engine state.\n *\n * One stylesheet, one rule registry, shared by every `createCss` instance so\n * identical declarations dedupe globally and cascade order stays deterministic:\n * base rules first (insertion order), then one grouping rule per at-rule query\n * in registration order (theme `screens` order).\n *\n * Browser: rules are injected through CSSOM with O(1) appends — no rescans.\n * SSR: rules accumulate in the registry; `getCssText()` serializes them.\n */\n\n// SSR collector — optional hook that receives every newly minted rule string\n// (wrapped in its at-rule, if any). Installed once at server startup.\ntype SSRCollector = (rule: string) => void;\nlet ssrCollector: SSRCollector | null = null;\n\nexport function setSSRCollector(fn: SSRCollector | null): void {\n\tssrCollector = fn;\n}\n\n// Registry — the source of truth for all generated CSS.\n// atomCache: declaration key -> class name (dedup)\n// atomOwner: class name -> conflict key (query|suffix|property), used by cx()\nconst atomCache = new Map<string, string>();\nconst atomOwner = new Map<string, string>();\nconst rawKeys = new Set<string>();\nconst baseRules: string[] = [];\nconst queryRules = new Map<string, string[]>();\n\n// Browser CSSOM state. Base rules occupy [0, baseRuleCount); grouping rules\n// (one per query, created in registration order) live after them. CSSRule\n// references stay live when indices shift, so insertion never rescans.\nlet sheet: CSSStyleSheet | null = null;\nlet sheetDocument: Document | null = null;\nlet baseRuleCount = 0;\nconst groupRules = new Map<string, CSSGroupingRule>();\n\n/** Pre-register at-rule queries so their cascade order follows theme order. */\nexport function registerQueries(queries: Iterable<string>): void {\n\tfor (const query of queries) {\n\t\tif (!queryRules.has(query)) queryRules.set(query, []);\n\t}\n}\n\nfunction createGroup(s: CSSStyleSheet, query: string): CSSGroupingRule | null {\n\ttry {\n\t\tconst idx = s.cssRules.length;\n\t\ts.insertRule(query + \"{}\", idx);\n\t\tconst group = s.cssRules[idx] as CSSGroupingRule;\n\t\tgroupRules.set(query, group);\n\t\treturn group;\n\t} catch {\n\t\treturn null; // unsupported at-rule in this environment\n\t}\n}\n\nfunction insertBase(s: CSSStyleSheet, rule: string): void {\n\ttry {\n\t\ts.insertRule(rule, baseRuleCount);\n\t\tbaseRuleCount++;\n\t} catch {\n\t\t// Invalid value/selector: drop the declaration, like browsers do for bad CSS.\n\t}\n}\n\n/**\n * Returns the live stylesheet, (re)binding when the document changes — e.g.\n * fresh jsdom documents between tests. Rebinding replays the whole registry,\n * which replaces v1's per-call classExistsInDOM() DOM scans with a single\n * replay per document.\n */\nfunction ensureSheet(): CSSStyleSheet | null {\n\tif (typeof document === \"undefined\") return null;\n\t// The nuclo SSR polyfill provides a document without getElementById — in\n\t// that context rules accumulate in the registry for getCssText() only.\n\tif (typeof document.getElementById !== \"function\") return null;\n\tif (sheet && sheetDocument === document && sheet.ownerNode && (sheet.ownerNode as Element).isConnected) {\n\t\treturn sheet;\n\t}\n\tlet el = document.getElementById(\"nuclo-styles\") as HTMLStyleElement | null;\n\tif (!el) {\n\t\tel = document.createElement(\"style\");\n\t\tel.id = \"nuclo-styles\";\n\t\tdocument.head.appendChild(el);\n\t}\n\tsheet = el.sheet;\n\tsheetDocument = document;\n\tgroupRules.clear();\n\tbaseRuleCount = 0;\n\tif (!sheet) return null;\n\tfor (const rule of baseRules) insertBase(sheet, rule);\n\tfor (const [query, rules] of queryRules) {\n\t\tconst group = createGroup(sheet, query);\n\t\tif (group) {\n\t\t\tfor (const rule of rules) {\n\t\t\t\ttry {\n\t\t\t\t\tgroup.insertRule(rule, group.cssRules.length);\n\t\t\t\t} catch { /* drop invalid rule */ }\n\t\t\t}\n\t\t}\n\t}\n\treturn sheet;\n}\n\nfunction record(rule: string, query: string | undefined): void {\n\tif (query === undefined) {\n\t\tbaseRules.push(rule);\n\t} else {\n\t\tlet bucket = queryRules.get(query);\n\t\tif (!bucket) {\n\t\t\tbucket = [];\n\t\t\tqueryRules.set(query, bucket);\n\t\t}\n\t\tbucket.push(rule);\n\t}\n\tssrCollector?.(query === undefined ? rule : query + \"{\" + rule + \"}\");\n\n\tconst s = ensureSheet();\n\tif (!s) return;\n\tif (query === undefined) {\n\t\tinsertBase(s, rule);\n\t} else {\n\t\tconst group = groupRules.get(query) ?? createGroup(s, query);\n\t\tif (group) {\n\t\t\ttry {\n\t\t\t\tgroup.insertRule(rule, group.cssRules.length);\n\t\t\t} catch { /* drop invalid rule */ }\n\t\t}\n\t}\n}\n\n/**\n * Order-independent 53-bit content hash (two interleaved FNV-1a style passes).\n * Class names must match between server and client for SSR hydration, so a\n * counter is not an option; 53 bits keeps collision odds negligible (~1e-5 at\n * 10k unique declarations).\n */\nexport function hash(input: string): string {\n\tlet a = 0x811c9dc5;\n\tlet b = 0x7ee3623b;\n\tfor (let i = 0; i < input.length; i++) {\n\t\tconst c = input.charCodeAt(i);\n\t\ta = Math.imul(a ^ c, 0x01000193);\n\t\tb = Math.imul(b ^ c, 0x85ebca6b);\n\t}\n\treturn (a >>> 0).toString(36) + ((b >>> 9) % 1296).toString(36);\n}\n\n/** One class per (query, selector-suffix, declaration) — the atomic core. */\nexport function atom(query: string | undefined, suffix: string, property: string, value: string): string {\n\tconst declKey = (query ?? \"\") + \"|\" + suffix + \"|\" + property + \":\" + value;\n\tlet className = atomCache.get(declKey);\n\tif (className !== undefined) {\n\t\t// Touch the sheet so a swapped document (tests) gets the replayed rules.\n\t\tensureSheet();\n\t\treturn className;\n\t}\n\tclassName = \"n\" + hash(declKey);\n\tatomCache.set(declKey, className);\n\tatomOwner.set(className, (query ?? \"\") + \"|\" + suffix + \"|\" + property);\n\trecord(\".\" + className + suffix + \"{\" + property + \":\" + value + \"}\", query);\n\treturn className;\n}\n\n/** Conflict key for a generated class — lets cx() resolve overrides exactly. */\nexport function conflictKeyOf(className: string): string | undefined {\n\treturn atomOwner.get(className);\n}\n\n/** Register a non-atomic rule (keyframes, global styles) once per dedupe key. */\nexport function addRawRule(dedupeKey: string, rule: string): void {\n\tif (rawKeys.has(dedupeKey)) {\n\t\tensureSheet();\n\t\treturn;\n\t}\n\trawKeys.add(dedupeKey);\n\trecord(rule, undefined);\n}\n\n/** All generated CSS — base rules first, then at-rule groups in registration order. */\nexport function getCssText(): string {\n\tlet out = baseRules.join(\"\");\n\tfor (const [query, rules] of queryRules) {\n\t\tif (rules.length > 0) out += query + \"{\" + rules.join(\"\") + \"}\";\n\t}\n\treturn out;\n}\n\n/** Clear all engine state (test helper). Removes the injected style element. */\nexport function resetStyles(): void {\n\tatomCache.clear();\n\tatomOwner.clear();\n\trawKeys.clear();\n\tbaseRules.length = 0;\n\tqueryRules.clear();\n\tgroupRules.clear();\n\tbaseRuleCount = 0;\n\tsheet = null;\n\tsheetDocument = null;\n\tif (typeof document !== \"undefined\") {\n\t\tdocument.getElementById(\"nuclo-styles\")?.remove();\n\t}\n}\n"],"mappings":"mEASA,SAAgB,EAAa,EAAqB,CAEhD,IAAI,EAAa,EACjB,KAAO,EAAa,EAAI,OAAQ,IAAc,CAC5C,IAAM,EAAO,EAAI,WAAW,CAAU,EACtC,GAAI,GAAQ,IAAM,GAAQ,GAAI,KAChC,CACA,GAAI,IAAe,EAAI,OAAQ,OAAO,EAEtC,IAAI,EAAS,EAAI,MAAM,EAAG,CAAU,EACpC,IAAK,IAAI,EAAI,EAAY,EAAI,EAAI,OAAQ,IAAK,CAC5C,IAAM,EAAO,EAAI,WAAW,CAAC,EAEzB,GAAQ,IAAM,GAAQ,IACpB,EAAI,IAAG,GAAU,KACrB,GAAU,OAAO,aAAa,EAAO,EAAE,GAEvC,GAAU,EAAI,EAElB,CACA,OAAO,CACT,CAEA,MAAM,EAAiB,UACjB,EAAiB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vB,SAAgB,GAAqB,CACpC,IAAI,EAAM,EAAU,KAAK,EAAE,EAC3B,IAAK,GAAM,CAAC,EAAO,KAAU,EACxB,EAAM,OAAS,IAAG,GAAO,EAAQ,IAAM,EAAM,KAAK,EAAE,EAAI,KAE7D,OAAO,CACR"}
|
|
1
|
+
{"version":3,"file":"nuclo.ssr.cjs","names":[],"sources":["../../src/utility/stringUtils.ts","../../src/core/reactiveCleanup.ts","../../src/utility/conditionalInfo.ts","../../src/utility/dom.ts","../../src/ssr/renderToString.ts","../../src/style/engine.ts"],"sourcesContent":["/**\n * String utility functions\n */\n\n/**\n * Converts camelCase to kebab-case (optimized for performance)\n * Uses direct character code manipulation for maximum speed\n * @example camelToKebab('backgroundColor') => 'background-color'\n */\nexport function camelToKebab(str: string): string {\n // Fast path: attribute/property names are usually already lowercase.\n let firstUpper = 0;\n for (; firstUpper < str.length; firstUpper++) {\n const code = str.charCodeAt(firstUpper);\n if (code >= 65 && code <= 90) break;\n }\n if (firstUpper === str.length) return str;\n\n let result = str.slice(0, firstUpper);\n for (let i = firstUpper; i < str.length; i++) {\n const code = str.charCodeAt(i);\n // A-Z is 65-90, a-z is 97-122 (difference of 32)\n if (code >= 65 && code <= 90) {\n if (i > 0) result += '-';\n result += String.fromCharCode(code + 32);\n } else {\n result += str[i];\n }\n }\n return result;\n}\n\nconst ATTR_ESCAPE_RE = /[&<>\"']/;\nconst TEXT_ESCAPE_RE = /[&<>]/;\n\n/**\n * Escapes HTML special characters in attribute values (includes \" and ')\n */\nexport function escapeHtml(text: string): string {\n // Fast path: most strings contain no special characters at all.\n const first = ATTR_ESCAPE_RE.exec(text);\n if (!first) return text;\n\n let result = '';\n let last = 0;\n for (let i = first.index; i < text.length; i++) {\n let escaped: string;\n switch (text.charCodeAt(i)) {\n case 38: escaped = '&'; break; // &\n case 60: escaped = '<'; break; // <\n case 62: escaped = '>'; break; // >\n case 34: escaped = '"'; break; // \"\n case 39: escaped = '''; break; // '\n default: continue;\n }\n result += text.slice(last, i) + escaped;\n last = i + 1;\n }\n return result + text.slice(last);\n}\n\n/**\n * Escapes HTML special characters in text node content.\n * Only &, < and > need escaping — quotes are safe inside text nodes.\n */\nexport function escapeText(text: string): string {\n const first = TEXT_ESCAPE_RE.exec(text);\n if (!first) return text;\n\n let result = '';\n let last = 0;\n for (let i = first.index; i < text.length; i++) {\n let escaped: string;\n switch (text.charCodeAt(i)) {\n case 38: escaped = '&'; break; // &\n case 60: escaped = '<'; break; // <\n case 62: escaped = '>'; break; // >\n default: continue;\n }\n result += text.slice(last, i) + escaped;\n last = i + 1;\n }\n return result + text.slice(last);\n}\n","/**\n * Shared types and registries for reactive nodes.\n * Single source of truth — imported by reactiveText.ts and reactiveAttributes.ts.\n *\n * Registry structure: the iteration sets only hold WeakRefs; the actual info\n * records live in WeakMaps keyed by the node. Info records may strongly\n * reference the node (e.g. attribute applyValue closures capture the\n * element), so storing them in a strongly-held map would pin the node in\n * memory forever. With WeakMap storage the whole record is collectible as\n * soon as the node is unreachable, and the FinalizationRegistry prunes the\n * leftover WeakRef from the iteration set. The notify passes also prune\n * dead/disconnected entries as they iterate.\n */\n\nexport type TextResolver = () => Primitive;\n\nexport interface ReactiveTextNodeInfo {\n resolver: TextResolver;\n lastValue: string;\n}\n\nexport type AttributeResolver = () => unknown;\n\nexport interface AttributeResolverRecord {\n resolver: AttributeResolver;\n applyValue: (value: unknown) => void;\n lastValue: unknown;\n}\n\nexport interface ReactiveElementInfo {\n attributeResolvers: Map<string, AttributeResolverRecord>;\n}\n\n/**\n * Iteration set of weak references to reactive text nodes.\n */\nexport const reactiveTextNodes = new Set<WeakRef<Text>>();\n\n/**\n * WeakMap for O(1) lookups of reactive text node info by node reference.\n */\nexport const reactiveTextNodesByNode = new WeakMap<Text, { ref: WeakRef<Text>; info: ReactiveTextNodeInfo }>();\n\n/**\n * Iteration set of weak references to reactive elements.\n */\nexport const reactiveElements = new Set<WeakRef<Element>>();\n\n/**\n * WeakMap for O(1) lookups of reactive element info by element reference.\n */\nexport const reactiveElementsByNode = new WeakMap<Element, { ref: WeakRef<Element>; info: ReactiveElementInfo }>();\n\nconst textNodeFinalizer = typeof FinalizationRegistry !== \"undefined\"\n ? new FinalizationRegistry<WeakRef<Text>>((ref) => { reactiveTextNodes.delete(ref); })\n : null;\n\nconst elementFinalizer = typeof FinalizationRegistry !== \"undefined\"\n ? new FinalizationRegistry<WeakRef<Element>>((ref) => { reactiveElements.delete(ref); })\n : null;\n\n/**\n * Registers a reactive text node in both lookup structures.\n */\nexport function registerReactiveTextNode(node: Text, info: ReactiveTextNodeInfo): void {\n const existing = reactiveTextNodesByNode.get(node);\n if (existing) {\n // Re-registration (e.g. repeated hydration): replace the info in place.\n existing.info.resolver = info.resolver;\n existing.info.lastValue = info.lastValue;\n return;\n }\n const ref = new WeakRef(node);\n reactiveTextNodes.add(ref);\n reactiveTextNodesByNode.set(node, { ref, info });\n textNodeFinalizer?.register(node, ref);\n}\n\n/**\n * Registers a reactive element in both lookup structures.\n */\nexport function registerReactiveElement(element: Element, info: ReactiveElementInfo): void {\n const ref = new WeakRef(element);\n reactiveElements.add(ref);\n reactiveElementsByNode.set(element, { ref, info });\n elementFinalizer?.register(element, ref);\n}\n\n/**\n * Removes a reactive text node's WeakRef entry from the iteration set.\n */\nexport function removeReactiveTextNodeRef(ref: WeakRef<Text>): void {\n reactiveTextNodes.delete(ref);\n}\n\n/**\n * Removes a reactive element's WeakRef entry from the iteration set.\n */\nexport function removeReactiveElementRef(ref: WeakRef<Element>): void {\n reactiveElements.delete(ref);\n}\n\n/**\n * Manually removes reactive text node info for a specific text node.\n * This should be called when a text node is removed from the DOM to prevent memory leaks.\n */\nexport function cleanupReactiveTextNode(node: Text): void {\n const entry = reactiveTextNodesByNode.get(node);\n if (entry) {\n reactiveTextNodes.delete(entry.ref);\n reactiveTextNodesByNode.delete(node);\n }\n}\n\n/**\n * Manually removes reactive element info for a specific element.\n * This should be called when an element is removed from the DOM to prevent memory leaks.\n */\nexport function cleanupReactiveElement(element: Element): void {\n const entry = reactiveElementsByNode.get(element);\n if (entry) {\n reactiveElements.delete(entry.ref);\n reactiveElementsByNode.delete(element);\n }\n}\n","export interface ConditionalInfo<TTagName extends ElementTagName = ElementTagName> {\n\tcondition: () => boolean;\n\ttagName: TTagName;\n\tmodifiers: Array<NodeMod<TTagName> | NodeModFn<TTagName>>;\n\tisSvg: boolean;\n}\n\n// WeakMap replaces the _conditionalInfo expando property — zero `any`, no DOM pollution, auto-GC.\nconst conditionalInfoMap = new WeakMap<Node, ConditionalInfo<ElementTagName>>();\n\n/**\n * Registry of all nodes that have conditional info attached.\n * Uses WeakRef to prevent memory leaks — allows garbage collection of removed nodes.\n * This enables O(nConditionals) updates instead of a full DOM tree walk.\n */\nconst activeConditionalNodes = new Set<WeakRef<Node>>();\n\n/**\n * Reverse lookup for O(1) unregister — maps node to its WeakRef in the active set.\n */\nconst refByNode = new WeakMap<Node, WeakRef<Node>>();\n\n/**\n * Prunes dead WeakRefs from the active set as soon as their node is\n * collected, instead of waiting for the next getActiveConditionalNodes() pass.\n */\nconst conditionalNodeFinalizer = typeof FinalizationRegistry !== \"undefined\"\n\t? new FinalizationRegistry<WeakRef<Node>>((ref) => { activeConditionalNodes.delete(ref); })\n\t: null;\n\n/**\n * Attach conditional info to a node and register it.\n */\nexport function storeConditionalInfo<TTagName extends ElementTagName>(\n\tnode: Node,\n\tinfo: ConditionalInfo<TTagName>\n): void {\n\tconditionalInfoMap.set(node, info as ConditionalInfo<ElementTagName>);\n\tconst ref = new WeakRef(node);\n\tactiveConditionalNodes.add(ref);\n\trefByNode.set(node, ref);\n\tconditionalNodeFinalizer?.register(node, ref);\n}\n\n/**\n * Explicit unregister helper (optional use on teardown if needed).\n * O(1) via reverse lookup WeakMap.\n */\nexport function unregisterConditionalNode(node: Node): void {\n\tconditionalInfoMap.delete(node);\n\tconst ref = refByNode.get(node);\n\tif (ref) {\n\t\tactiveConditionalNodes.delete(ref);\n\t\trefByNode.delete(node);\n\t}\n}\n\n/**\n * Returns an array of currently tracked conditional nodes that are still alive.\n * Automatically cleans up garbage-collected nodes.\n */\nexport function getActiveConditionalNodes(): Node[] {\n\tconst nodes: Node[] = [];\n\tconst toDelete: WeakRef<Node>[] = [];\n\n\tfor (const ref of activeConditionalNodes) {\n\t\tconst node = ref.deref();\n\t\tif (node === undefined) {\n\t\t\ttoDelete.push(ref);\n\t\t} else {\n\t\t\tnodes.push(node);\n\t\t}\n\t}\n\n\tfor (const ref of toDelete) {\n\t\tactiveConditionalNodes.delete(ref);\n\t}\n\n\treturn nodes;\n}\n\nexport function getConditionalInfo(node: Node): ConditionalInfo<ElementTagName> | null {\n\treturn conditionalInfoMap.get(node) ?? null;\n}\n","import { logError } from \"./errorHandler\";\nimport { removeAllListeners } from \"./on\";\nimport { cleanupReactiveTextNode, cleanupReactiveElement } from \"../core/reactiveCleanup\";\nimport { unregisterConditionalNode } from \"./conditionalInfo\";\n\nexport const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\n/**\n * Creates an HTML element.\n * Wrapper for document.createElement with type safety.\n */\nexport function createElement<K extends keyof HTMLElementTagNameMap>(\n tagName: K\n): HTMLElementTagNameMap[K] | null;\nexport function createElement(tagName: string): ExpandedElement | null;\nexport function createElement(tagName: string): ExpandedElement | null {\n return globalThis.document ? document.createElement(tagName) as ExpandedElement : null;\n}\n\n/**\n * Creates an element in the given namespace (typically for SVG elements).\n * Wrapper for document.createElementNS with type safety.\n */\nexport function createElementNS(\n namespace: string,\n tagName: string\n): ExpandedElement | null {\n return globalThis.document ? document.createElementNS(namespace, tagName) as ExpandedElement : null;\n}\n\n/**\n * Creates a text node with the given content.\n * Wrapper for document.createTextNode.\n */\nexport function createTextNode(text: string): Text | null {\n return globalThis.document ? document.createTextNode(text) : null;\n}\n\n/**\n * Creates a document fragment.\n * Wrapper for document.createDocumentFragment.\n */\nexport function createDocumentFragment(): DocumentFragment | null {\n return globalThis.document ? document.createDocumentFragment() : null;\n}\n\nfunction safeAppendChild(parent: Element | Node, child: Node): boolean {\n try {\n parent.appendChild(child);\n return true;\n } catch (error) {\n logError('Failed to append child node', error);\n return false;\n }\n}\n\n/**\n * Recursively removes all event listeners and reactive subscriptions from a node and its descendants\n * to prevent memory leaks when elements are removed from the DOM.\n */\nfunction cleanupNodeTree(node: Node): void {\n // Clean up the node itself based on its type\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = node as HTMLElement;\n // Remove all event listeners\n removeAllListeners(element);\n // Remove reactive attribute resolvers\n cleanupReactiveElement(element);\n // Remove conditional info\n unregisterConditionalNode(element);\n } else if (node.nodeType === Node.TEXT_NODE) {\n // Remove reactive text node info\n cleanupReactiveTextNode(node as Text);\n } else if (node.nodeType === Node.COMMENT_NODE) {\n // Remove conditional info from comment nodes (used by when/list)\n unregisterConditionalNode(node);\n }\n \n // Recursively clean up all child nodes\n if (node.childNodes && node.childNodes.length > 0) {\n for (let i = 0; i < node.childNodes.length; i++) {\n cleanupNodeTree(node.childNodes[i]);\n }\n }\n}\n\nexport function safeRemoveChild(child: Node): boolean {\n if (!child?.parentNode) return false;\n try {\n // Clean up all event listeners before removing the element\n cleanupNodeTree(child);\n child.parentNode.removeChild(child);\n return true;\n } catch (error) {\n logError('Failed to remove child node', error);\n return false;\n }\n}\n\nfunction safeInsertBefore(parent: Node, newNode: Node, referenceNode: Node | null): boolean {\n try {\n parent.insertBefore(newNode, referenceNode);\n return true;\n } catch (error) {\n logError('Failed to insert node before reference', error);\n return false;\n }\n}\n\nexport function createComment(text: string): Comment | null {\n return globalThis.document ? globalThis.document.createComment(text) : null;\n}\n\nexport function createConditionalComment(tagName: string, suffix = \"hidden\"): Comment | null {\n return globalThis.document ? globalThis.document.createComment(`conditional-${tagName}-${suffix}`) : null;\n}\n\nexport function createMarkerPair(prefix: string, id: number | string): { start: Comment; end: Comment } {\n const endComment = createComment(`${prefix}-end`);\n if (!endComment) throw new Error(\"Failed to create comment: document not available\");\n const startComment = createComment(`${prefix}-start-${id}`);\n if (!startComment) throw new Error(\"Failed to create comment: document not available\");\n return { start: startComment, end: endComment };\n}\n\nexport function clearBetweenMarkers(startMarker: Comment, endMarker: Comment): void {\n let current = startMarker.nextSibling;\n while (current && current !== endMarker) {\n const next = current.nextSibling;\n safeRemoveChild(current);\n current = next;\n }\n}\n\nexport function insertNodesBefore(nodes: Node[], referenceNode: Node): void {\n const parent = referenceNode.parentNode;\n if (parent) {\n for (let i = 0; i < nodes.length; i++) {\n safeInsertBefore(parent, nodes[i], referenceNode);\n }\n }\n}\n\nexport function appendChildren(\n parent: Element | Node,\n ...children: Array<Element | Node | string | null | undefined>\n): Element | Node {\n if (!parent) return parent;\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i];\n if (child != null) {\n let nodeToAppend: Node;\n\n if (typeof child === \"string\") {\n const textNode = createTextNode(child);\n if (textNode) {\n nodeToAppend = textNode;\n } else {\n continue;\n }\n } else {\n nodeToAppend = child as Node;\n }\n\n safeAppendChild(parent, nodeToAppend);\n }\n }\n\n return parent;\n}\n\nexport function isNodeConnected(node: Node | null | undefined): boolean {\n return node?.isConnected === true;\n}\n\n/**\n * Safely replaces an old node with a new node in the DOM.\n * Returns true on success, false on failure (and logs the error).\n */\nexport function replaceNodeSafely(oldNode: Node, newNode: Node): boolean {\n if (!oldNode?.parentNode) return false;\n try {\n oldNode.parentNode.replaceChild(newNode, oldNode);\n return true;\n } catch (error) {\n logError(\"Error replacing conditional node\", error);\n return false;\n }\n}\n","/**\n * Server-Side Rendering (SSR) utilities for Nuclo\n * Renders Nuclo components to HTML strings in Node.js environment\n */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { escapeHtml, escapeText, camelToKebab } from '../utility/stringUtils';\nimport { createElement } from '../utility/dom';\n\ntype RenderableInput =\n | NodeModFn<ElementTagName>\n | Element\n | Node\n | null\n | undefined;\n\n/**\n * SVG attributes that are natively camelCase and must NOT be converted to kebab-case.\n * Most SVG attributes are already kebab-case (stroke-width, fill-rule, etc.), but a\n * handful are defined as camelCase in the SVG spec and must be preserved.\n */\nconst SVG_PRESERVE_CASE_ATTRS = new Set([\n 'viewBox', 'preserveAspectRatio', 'markerWidth', 'markerHeight',\n 'gradientTransform', 'patternTransform', 'clipPathUnits', 'gradientUnits',\n 'patternUnits', 'pathLength', 'refX', 'refY', 'stdDeviation',\n 'baseFrequency', 'numOctaves', 'kernelMatrix', 'tableValues',\n 'targetX', 'targetY', 'specularExponent', 'specularConstant',\n 'diffuseConstant', 'surfaceScale', 'xChannelSelector', 'yChannelSelector',\n 'edgeMode', 'stitchTiles', 'spreadMethod', 'patternContentUnits',\n 'markerUnits', 'startOffset', 'textLength', 'lengthAdjust',\n]);\n\n/**\n * HTML boolean attributes — presence means true, absence means false.\n * When the stored value is the string \"true\" or \"false\" (from setAttribute),\n * we must re-apply boolean semantics instead of outputting the raw string.\n */\nconst HTML_BOOLEAN_ATTRIBUTES = new Set([\n 'allowfullscreen', 'async', 'autofocus', 'autoplay', 'checked', 'controls',\n 'default', 'defer', 'disabled', 'formnovalidate', 'hidden', 'ismap', 'loop',\n 'multiple', 'muted', 'nomodule', 'novalidate', 'open', 'readonly', 'required',\n 'reversed', 'selected',\n]);\n\n/**\n * Serializes a DOM attribute value\n */\nfunction serializeAttribute(name: string, value: unknown): string {\n if (value === null || value === undefined || value === false) {\n return '';\n }\n\n if (value === true) {\n return ` ${name}`;\n }\n\n // Boolean attributes stored as strings via setAttribute() need special handling\n if (HTML_BOOLEAN_ATTRIBUTES.has(name)) {\n if (value === 'false') return '';\n if (value === 'true' || value === '' || value === name) return ` ${name}`;\n }\n\n if (name === 'style' && typeof value === 'object') {\n let styleStr = '';\n for (const key in value as Record<string, unknown>) {\n const val = (value as Record<string, unknown>)[key];\n if (val == null || val === '') continue;\n styleStr += (styleStr ? ' ' : '') + camelToKebab(key) + ': ' + String(val) + ';';\n }\n return styleStr ? ` style=\"${escapeHtml(styleStr)}\"` : '';\n }\n\n return ` ${name}=\"${escapeHtml(String(value))}\"`;\n}\n\n/**\n * Serializes DOM element attributes to HTML string\n */\nfunction serializeAttributes(element: Element): string {\n let result = '';\n\n // Handle polyfill elements. NucloElement keeps every child in a plain Array\n // (`children`), which a real DOM element never does (HTMLCollection) — this is\n // the same allocation-free discriminator getChildNodes() uses. Reading\n // `el.attributes` directly would lazily allocate an empty Map for every\n // element being serialized, so the backing `_attributes` field is read instead.\n if (Array.isArray((element as any).children)) {\n const el = element as any;\n const attrs = el._attributes as Map<string, string> | undefined;\n\n // id — may live on the property rather than in the Map\n if (el.id && !attrs?.has('id')) {\n result += serializeAttribute('id', el.id);\n }\n\n // class — kept on .className, mirrored to Map only when setAttribute is used\n if (el.className && !attrs?.has('class')) {\n result += serializeAttribute('class', el.className);\n }\n\n // style — lives on the backing _style object, not in the attributes Map.\n // Read the field directly (never `el.style`) so elements that never set a\n // style are not forced to lazily allocate an empty SSRStyle just to serialize.\n // cssText returns camelCase keys (\"backgroundColor: red\"), so convert them.\n const styleObj = el._style;\n if (!attrs?.has('style') && styleObj) {\n const rawCssText: string = styleObj.cssText || '';\n if (rawCssText) {\n const kebabStyle = rawCssText\n .split(';')\n .map((decl: string) => decl.trim())\n .filter(Boolean)\n .map((decl: string) => {\n const colonIdx = decl.indexOf(':');\n if (colonIdx === -1) return decl;\n const key = decl.slice(0, colonIdx).trim();\n const val = decl.slice(colonIdx + 1).trim();\n // Skip declarations with empty values (e.g. reactive styles that resolved to undefined)\n if (!val) return '';\n return `${camelToKebab(key)}: ${val};`;\n })\n .filter(Boolean)\n .join(' ');\n if (kebabStyle) {\n result += ` style=\"${escapeHtml(kebabStyle)}\"`;\n }\n }\n }\n\n // All remaining attributes from the Map\n // Convert camelCase ARIA/HTML attribute names (e.g. ariaLabel → aria-label) that the\n // polyfill stores as-is because NucloElement lacks the browser property mappings.\n // SVG attributes that are natively camelCase (e.g. viewBox, preserveAspectRatio) must\n // NOT be converted — they are stored via setAttribute() as-is.\n if (attrs) {\n for (const [name, value] of attrs) {\n const htmlName = SVG_PRESERVE_CASE_ATTRS.has(name) ? name : camelToKebab(name);\n result += serializeAttribute(htmlName, value);\n }\n }\n return result;\n }\n\n // Handle browser elements with NamedNodeMap attributes\n if (element.attributes && element.attributes.length) {\n for (let i = 0; i < element.attributes.length; i++) {\n const attr = element.attributes[i];\n if (attr && attr.name) {\n result += serializeAttribute(attr.name, attr.value);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Self-closing HTML tags that don't have closing tags\n */\nconst VOID_ELEMENTS = new Set([\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\n]);\n\n/**\n * Raw-text elements — browsers never decode entities inside them, so their\n * text content must be emitted verbatim (escaping would corrupt inline JS/CSS,\n * e.g. `a < b` becoming `a < b` inside a script). A closing-tag sequence\n * in the content would terminate the element early, so it is neutralized.\n */\nconst RAW_TEXT_ELEMENTS = new Set(['script', 'style']);\n\nfunction escapeRawText(tagName: string, text: string): string {\n // \"</script\" (any case) inside a script would close it — break the sequence\n // the same way JSON serializers do (\"<\\/script\").\n return text.replace(new RegExp('</(' + tagName + ')', 'gi'), '<\\\\/$1');\n}\n\n/**\n * Get child nodes from a node (handles both browser and polyfill elements).\n *\n * NucloElement stores ALL children (elements, text, comments) in a plain Array\n * called `children` — it is the authoritative list. DocumentFragments in the\n * polyfill also have a `children` array, but it only holds Element children;\n * their full set of nodes lives in `childNodes`. We therefore only prefer\n * `children` when the node is an actual element (has `tagName`).\n */\nfunction getChildNodes(node: Node): ArrayLike<Node> {\n // NucloElement: tagName exists and children is a plain Array containing every node type\n if ('tagName' in node && 'children' in node) {\n const children = (node as any).children;\n if (Array.isArray(children)) {\n return children as ArrayLike<Node>;\n }\n }\n // DocumentFragments and browser elements: use childNodes\n if ('childNodes' in node) {\n const childNodes = (node as any).childNodes;\n if (childNodes && (Array.isArray(childNodes) || childNodes.length !== undefined)) {\n return childNodes;\n }\n }\n return [] as ArrayLike<Node>;\n}\n\n/**\n * Serializes a DOM node to HTML string\n */\nfunction serializeNode(node: Node): string {\n // Text node — only & < > need escaping; quotes are safe in text content\n if (node.nodeType === 3) { // Node.TEXT_NODE\n return escapeText(node.textContent || '');\n }\n\n // Comment node\n if (node.nodeType === 8) { // Node.COMMENT_NODE\n return `<!--${node.textContent || ''}-->`;\n }\n\n // Element node\n if (node.nodeType === 1) { // Node.ELEMENT_NODE\n const element = node as Element;\n const tagName = element.tagName.toLowerCase();\n const attributes = serializeAttributes(element);\n\n // Self-closing tags\n if (VOID_ELEMENTS.has(tagName)) {\n return `<${tagName}${attributes} />`;\n }\n\n // Raw-text elements: emit text verbatim (no entity escaping, no Nuclo\n // text markers — `<!--` would act as a line comment inside a script).\n if (RAW_TEXT_ELEMENTS.has(tagName)) {\n let rawContent = '';\n const rawChildren = getChildNodes(element);\n if (rawChildren && rawChildren.length > 0) {\n for (let i = 0; i < rawChildren.length; i++) {\n const child = rawChildren[i];\n if (child && child.nodeType === 3) {\n rawContent += child.textContent || '';\n }\n }\n } else {\n const tc = (node as { textContent?: unknown }).textContent;\n if (typeof tc === 'string') rawContent = tc;\n }\n return `<${tagName}${attributes}>${escapeRawText(tagName, rawContent)}</${tagName}>`;\n }\n\n // Regular elements with children\n let childrenHtml = '';\n const childNodes = getChildNodes(element);\n if (childNodes && childNodes.length > 0) {\n for (let i = 0; i < childNodes.length; i++) {\n const child = childNodes[i];\n if (child) {\n childrenHtml += serializeNode(child);\n }\n }\n } else {\n // Fallback: textContent set directly on the element (e.g. el.textContent = \"...\")\n const tc = (node as any).textContent;\n if (typeof tc === 'string' && tc) {\n childrenHtml = escapeText(tc);\n }\n }\n\n return `<${tagName}${attributes}>${childrenHtml}</${tagName}>`;\n }\n\n // Document fragment\n if (node.nodeType === 11) { // Node.DOCUMENT_FRAGMENT_NODE\n let result = '';\n const childNodes = getChildNodes(node);\n if (childNodes && childNodes.length > 0) {\n for (let i = 0; i < childNodes.length; i++) {\n const child = childNodes[i];\n if (child) {\n result += serializeNode(child);\n }\n }\n }\n return result;\n }\n\n return '';\n}\n\n/**\n * Renders a Nuclo component to an HTML string for server-side rendering\n *\n * @param input - A Nuclo component function, DOM element, or node\n * @returns HTML string representation of the component\n *\n * @example\n * ```ts\n * import { renderToString } from 'nuclo/ssr';\n * import { div } from 'nuclo';\n *\n * const html = renderToString(\n * div(\"Hello, World!\")\n * );\n * // Returns: '<div>Hello, World!</div>'\n * ```\n */\nexport function renderToString(input: RenderableInput): string {\n if (!input) return '';\n\n if (typeof input === 'function') {\n try {\n const container = createElement('div');\n if (!container) throw new Error('Document is not available. Make sure polyfills are loaded.');\n const element = input(container as ExpandedElement<ElementTagName>, 0);\n return element && typeof element === 'object' && 'nodeType' in element ? serializeNode(element as Node) : '';\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error rendering component to string:', error);\n return '';\n }\n }\n\n if ('nodeType' in input) {\n return serializeNode(input as Node);\n }\n\n return '';\n}\n\n/**\n * Renders multiple Nuclo components to HTML strings\n *\n * @param inputs - Array of Nuclo components\n * @returns Array of HTML strings\n */\nexport function renderManyToString(inputs: RenderableInput[]): string[] {\n return inputs.map(input => renderToString(input));\n}\n\n/**\n * Renders a Nuclo component and wraps it in a container element\n *\n * @param input - A Nuclo component\n * @param containerTag - The tag name for the container (default: 'div')\n * @param containerAttrs - Attributes for the container element\n * @returns HTML string with container wrapper\n */\nexport function renderToStringWithContainer(\n input: RenderableInput,\n containerTag: string = 'div',\n containerAttrs: Record<string, string> = {}\n): string {\n const content = renderToString(input);\n const attrs = Object.entries(containerAttrs)\n .map(([key, value]) => serializeAttribute(key, value))\n .join('');\n\n return `<${containerTag}${attrs}>${content}</${containerTag}>`;\n}\n","/**\n * Shared atomic-CSS engine state.\n *\n * One stylesheet, one rule registry, shared by every `createCss` instance so\n * identical declarations dedupe globally and cascade order stays deterministic:\n * base rules first (insertion order), then one grouping rule per at-rule query\n * in registration order (theme `screens` order).\n *\n * Browser: rules are injected through CSSOM with O(1) appends — no rescans.\n * SSR: rules accumulate in the registry; `getCssText()` serializes them.\n */\n\n// SSR collector — optional hook that receives every newly minted rule string\n// (wrapped in its at-rule, if any). Installed once at server startup.\ntype SSRCollector = (rule: string) => void;\nlet ssrCollector: SSRCollector | null = null;\n\nexport function setSSRCollector(fn: SSRCollector | null): void {\n\tssrCollector = fn;\n}\n\n// Registry — the source of truth for all generated CSS.\n// atomCache: declaration key -> class name (dedup)\n// atomOwner: class name -> conflict key (query|suffix|property), used by cx()\nconst atomCache = new Map<string, string>();\nconst atomOwner = new Map<string, string>();\nconst rawKeys = new Set<string>();\nconst baseRules: string[] = [];\nconst queryRules = new Map<string, string[]>();\n\n// Memoized getCssText() output. SSR calls getCssText() once per request, but the\n// rule set is stable after warmup — so the serialized sheet is recomputed only\n// when a new rule is actually recorded. Invalidated in record() and resetStyles().\nlet cssTextCache: string | null = null;\n\n// Browser CSSOM state. Base rules occupy [0, baseRuleCount); grouping rules\n// (one per query, created in registration order) live after them. CSSRule\n// references stay live when indices shift, so insertion never rescans.\nlet sheet: CSSStyleSheet | null = null;\nlet sheetDocument: Document | null = null;\nlet baseRuleCount = 0;\nconst groupRules = new Map<string, CSSGroupingRule>();\n\n/** Pre-register at-rule queries so their cascade order follows theme order. */\nexport function registerQueries(queries: Iterable<string>): void {\n\tfor (const query of queries) {\n\t\tif (!queryRules.has(query)) queryRules.set(query, []);\n\t}\n}\n\nfunction createGroup(s: CSSStyleSheet, query: string): CSSGroupingRule | null {\n\ttry {\n\t\tconst idx = s.cssRules.length;\n\t\ts.insertRule(query + \"{}\", idx);\n\t\tconst group = s.cssRules[idx] as CSSGroupingRule;\n\t\tgroupRules.set(query, group);\n\t\treturn group;\n\t} catch {\n\t\treturn null; // unsupported at-rule in this environment\n\t}\n}\n\nfunction insertBase(s: CSSStyleSheet, rule: string): void {\n\ttry {\n\t\ts.insertRule(rule, baseRuleCount);\n\t\tbaseRuleCount++;\n\t} catch {\n\t\t// Invalid value/selector: drop the declaration, like browsers do for bad CSS.\n\t}\n}\n\n/**\n * Returns the live stylesheet, (re)binding when the document changes — e.g.\n * fresh jsdom documents between tests. Rebinding replays the whole registry,\n * which replaces v1's per-call classExistsInDOM() DOM scans with a single\n * replay per document.\n */\nfunction ensureSheet(): CSSStyleSheet | null {\n\tif (typeof document === \"undefined\") return null;\n\t// The nuclo SSR polyfill provides a document without getElementById — in\n\t// that context rules accumulate in the registry for getCssText() only.\n\tif (typeof document.getElementById !== \"function\") return null;\n\tif (sheet && sheetDocument === document && sheet.ownerNode && (sheet.ownerNode as Element).isConnected) {\n\t\treturn sheet;\n\t}\n\tlet el = document.getElementById(\"nuclo-styles\") as HTMLStyleElement | null;\n\tif (!el) {\n\t\tel = document.createElement(\"style\");\n\t\tel.id = \"nuclo-styles\";\n\t\tdocument.head.appendChild(el);\n\t}\n\tsheet = el.sheet;\n\tsheetDocument = document;\n\tgroupRules.clear();\n\tbaseRuleCount = 0;\n\tif (!sheet) return null;\n\tfor (const rule of baseRules) insertBase(sheet, rule);\n\tfor (const [query, rules] of queryRules) {\n\t\tconst group = createGroup(sheet, query);\n\t\tif (group) {\n\t\t\tfor (const rule of rules) {\n\t\t\t\ttry {\n\t\t\t\t\tgroup.insertRule(rule, group.cssRules.length);\n\t\t\t\t} catch { /* drop invalid rule */ }\n\t\t\t}\n\t\t}\n\t}\n\treturn sheet;\n}\n\nfunction record(rule: string, query: string | undefined): void {\n\tif (query === undefined) {\n\t\tbaseRules.push(rule);\n\t} else {\n\t\tlet bucket = queryRules.get(query);\n\t\tif (!bucket) {\n\t\t\tbucket = [];\n\t\t\tqueryRules.set(query, bucket);\n\t\t}\n\t\tbucket.push(rule);\n\t}\n\tcssTextCache = null; // a new rule changes the serialized sheet\n\tssrCollector?.(query === undefined ? rule : query + \"{\" + rule + \"}\");\n\n\tconst s = ensureSheet();\n\tif (!s) return;\n\tif (query === undefined) {\n\t\tinsertBase(s, rule);\n\t} else {\n\t\tconst group = groupRules.get(query) ?? createGroup(s, query);\n\t\tif (group) {\n\t\t\ttry {\n\t\t\t\tgroup.insertRule(rule, group.cssRules.length);\n\t\t\t} catch { /* drop invalid rule */ }\n\t\t}\n\t}\n}\n\n/**\n * Order-independent 53-bit content hash (two interleaved FNV-1a style passes).\n * Class names must match between server and client for SSR hydration, so a\n * counter is not an option; 53 bits keeps collision odds negligible (~1e-5 at\n * 10k unique declarations).\n */\nexport function hash(input: string): string {\n\tlet a = 0x811c9dc5;\n\tlet b = 0x7ee3623b;\n\tfor (let i = 0; i < input.length; i++) {\n\t\tconst c = input.charCodeAt(i);\n\t\ta = Math.imul(a ^ c, 0x01000193);\n\t\tb = Math.imul(b ^ c, 0x85ebca6b);\n\t}\n\treturn (a >>> 0).toString(36) + ((b >>> 9) % 1296).toString(36);\n}\n\n/** One class per (query, selector-suffix, declaration) — the atomic core. */\nexport function atom(query: string | undefined, suffix: string, property: string, value: string): string {\n\tconst declKey = (query ?? \"\") + \"|\" + suffix + \"|\" + property + \":\" + value;\n\tlet className = atomCache.get(declKey);\n\tif (className !== undefined) {\n\t\t// Touch the sheet so a swapped document (tests) gets the replayed rules.\n\t\tensureSheet();\n\t\treturn className;\n\t}\n\tclassName = \"n\" + hash(declKey);\n\tatomCache.set(declKey, className);\n\tatomOwner.set(className, (query ?? \"\") + \"|\" + suffix + \"|\" + property);\n\trecord(\".\" + className + suffix + \"{\" + property + \":\" + value + \"}\", query);\n\treturn className;\n}\n\n/** Conflict key for a generated class — lets cx() resolve overrides exactly. */\nexport function conflictKeyOf(className: string): string | undefined {\n\treturn atomOwner.get(className);\n}\n\n/** Register a non-atomic rule (keyframes, global styles) once per dedupe key. */\nexport function addRawRule(dedupeKey: string, rule: string): void {\n\tif (rawKeys.has(dedupeKey)) {\n\t\tensureSheet();\n\t\treturn;\n\t}\n\trawKeys.add(dedupeKey);\n\trecord(rule, undefined);\n}\n\n/** All generated CSS — base rules first, then at-rule groups in registration order. */\nexport function getCssText(): string {\n\tif (cssTextCache !== null) return cssTextCache;\n\tlet out = baseRules.join(\"\");\n\tfor (const [query, rules] of queryRules) {\n\t\tif (rules.length > 0) out += query + \"{\" + rules.join(\"\") + \"}\";\n\t}\n\tcssTextCache = out;\n\treturn out;\n}\n\n/** Clear all engine state (test helper). Removes the injected style element. */\nexport function resetStyles(): void {\n\tatomCache.clear();\n\tatomOwner.clear();\n\trawKeys.clear();\n\tbaseRules.length = 0;\n\tqueryRules.clear();\n\tgroupRules.clear();\n\tcssTextCache = null;\n\tbaseRuleCount = 0;\n\tsheet = null;\n\tsheetDocument = null;\n\tif (typeof document !== \"undefined\") {\n\t\tdocument.getElementById(\"nuclo-styles\")?.remove();\n\t}\n}\n"],"mappings":"mEASA,SAAgB,EAAa,EAAqB,CAEhD,IAAI,EAAa,EACjB,KAAO,EAAa,EAAI,OAAQ,IAAc,CAC5C,IAAM,EAAO,EAAI,WAAW,CAAU,EACtC,GAAI,GAAQ,IAAM,GAAQ,GAAI,KAChC,CACA,GAAI,IAAe,EAAI,OAAQ,OAAO,EAEtC,IAAI,EAAS,EAAI,MAAM,EAAG,CAAU,EACpC,IAAK,IAAI,EAAI,EAAY,EAAI,EAAI,OAAQ,IAAK,CAC5C,IAAM,EAAO,EAAI,WAAW,CAAC,EAEzB,GAAQ,IAAM,GAAQ,IACpB,EAAI,IAAG,GAAU,KACrB,GAAU,OAAO,aAAa,EAAO,EAAE,GAEvC,GAAU,EAAI,EAElB,CACA,OAAO,CACT,CAEA,MAAM,EAAiB,UACjB,EAAiB,QAKvB,SAAgB,EAAW,EAAsB,CAE/C,IAAM,EAAQ,EAAe,KAAK,CAAI,EACtC,GAAI,CAAC,EAAO,OAAO,EAEnB,IAAI,EAAS,GACT,EAAO,EACX,IAAK,IAAI,EAAI,EAAM,MAAO,EAAI,EAAK,OAAQ,IAAK,CAC9C,IAAI,EACJ,OAAQ,EAAK,WAAW,CAAC,EAAzB,CACE,IAAK,IAAI,EAAU,QAAS,MAC5B,IAAK,IAAI,EAAU,OAAQ,MAC3B,IAAK,IAAI,EAAU,OAAQ,MAC3B,IAAK,IAAI,EAAU,SAAU,MAC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if(n>=65&&n<=90)break}if(t===e.length)return e;let n=e.slice(0,t);for(let r=t;r<e.length;r++){let t=e.charCodeAt(r);t>=65&&t<=90?(r>0&&(n+=`-`),n+=String.fromCharCode(t+32)):n+=e[r]}return n}const t=/[&<>"']/,n=/[&<>]/;function r(e){let n=t.exec(e);if(!n)return e;let r=``,i=0;for(let t=n.index;t<e.length;t++){let n;switch(e.charCodeAt(t)){case 38:n=`&`;break;case 60:n=`<`;break;case 62:n=`>`;break;case 34:n=`"`;break;case 39:n=`'`;break;default:continue}r+=e.slice(i,t)+n,i=t+1}return r+e.slice(i)}function i(e){let t=n.exec(e);if(!t)return e;let r=``,i=0;for(let n=t.index;n<e.length;n++){let t;switch(e.charCodeAt(n)){case 38:t=`&`;break;case 60:t=`<`;break;case 62:t=`>`;break;default:continue}r+=e.slice(i,n)+t,i=n+1}return r+e.slice(i)}const a=new Set,o=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{a.delete(e)}),typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{o.delete(e)});const s=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{s.delete(e)});function c(e){return globalThis.document?document.createElement(e):null}const l=new Set(`viewBox.preserveAspectRatio.markerWidth.markerHeight.gradientTransform.patternTransform.clipPathUnits.gradientUnits.patternUnits.pathLength.refX.refY.stdDeviation.baseFrequency.numOctaves.kernelMatrix.tableValues.targetX.targetY.specularExponent.specularConstant.diffuseConstant.surfaceScale.xChannelSelector.yChannelSelector.edgeMode.stitchTiles.spreadMethod.patternContentUnits.markerUnits.startOffset.textLength.lengthAdjust`.split(`.`)),u=new Set([`allowfullscreen`,`async`,`autofocus`,`autoplay`,`checked`,`controls`,`default`,`defer`,`disabled`,`formnovalidate`,`hidden`,`ismap`,`loop`,`multiple`,`muted`,`nomodule`,`novalidate`,`open`,`readonly`,`required`,`reversed`,`selected`]);function d(t,n){if(n==null||n===!1)return``;if(n===!0)return` ${t}`;if(u.has(t)){if(n===`false`)return``;if(n===`true`||n===``||n===t)return` ${t}`}if(t===`style`&&typeof n==`object`){let t=``;for(let r in n){let i=n[r];i==null||i===``||(t+=(t?` `:``)+e(r)+`: `+String(i)+`;`)}return t?` style="${r(t)}"`:``}return` ${t}="${r(String(n))}"`}function f(t){let n=``;if(
|
|
1
|
+
function e(e){let t=0;for(;t<e.length;t++){let n=e.charCodeAt(t);if(n>=65&&n<=90)break}if(t===e.length)return e;let n=e.slice(0,t);for(let r=t;r<e.length;r++){let t=e.charCodeAt(r);t>=65&&t<=90?(r>0&&(n+=`-`),n+=String.fromCharCode(t+32)):n+=e[r]}return n}const t=/[&<>"']/,n=/[&<>]/;function r(e){let n=t.exec(e);if(!n)return e;let r=``,i=0;for(let t=n.index;t<e.length;t++){let n;switch(e.charCodeAt(t)){case 38:n=`&`;break;case 60:n=`<`;break;case 62:n=`>`;break;case 34:n=`"`;break;case 39:n=`'`;break;default:continue}r+=e.slice(i,t)+n,i=t+1}return r+e.slice(i)}function i(e){let t=n.exec(e);if(!t)return e;let r=``,i=0;for(let n=t.index;n<e.length;n++){let t;switch(e.charCodeAt(n)){case 38:t=`&`;break;case 60:t=`<`;break;case 62:t=`>`;break;default:continue}r+=e.slice(i,n)+t,i=n+1}return r+e.slice(i)}const a=new Set,o=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{a.delete(e)}),typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{o.delete(e)});const s=new Set;typeof FinalizationRegistry<`u`&&new FinalizationRegistry(e=>{s.delete(e)});function c(e){return globalThis.document?document.createElement(e):null}const l=new Set(`viewBox.preserveAspectRatio.markerWidth.markerHeight.gradientTransform.patternTransform.clipPathUnits.gradientUnits.patternUnits.pathLength.refX.refY.stdDeviation.baseFrequency.numOctaves.kernelMatrix.tableValues.targetX.targetY.specularExponent.specularConstant.diffuseConstant.surfaceScale.xChannelSelector.yChannelSelector.edgeMode.stitchTiles.spreadMethod.patternContentUnits.markerUnits.startOffset.textLength.lengthAdjust`.split(`.`)),u=new Set([`allowfullscreen`,`async`,`autofocus`,`autoplay`,`checked`,`controls`,`default`,`defer`,`disabled`,`formnovalidate`,`hidden`,`ismap`,`loop`,`multiple`,`muted`,`nomodule`,`novalidate`,`open`,`readonly`,`required`,`reversed`,`selected`]);function d(t,n){if(n==null||n===!1)return``;if(n===!0)return` ${t}`;if(u.has(t)){if(n===`false`)return``;if(n===`true`||n===``||n===t)return` ${t}`}if(t===`style`&&typeof n==`object`){let t=``;for(let r in n){let i=n[r];i==null||i===``||(t+=(t?` `:``)+e(r)+`: `+String(i)+`;`)}return t?` style="${r(t)}"`:``}return` ${t}="${r(String(n))}"`}function f(t){let n=``;if(Array.isArray(t.children)){let i=t,a=i._attributes;i.id&&!a?.has(`id`)&&(n+=d(`id`,i.id)),i.className&&!a?.has(`class`)&&(n+=d(`class`,i.className));let o=i._style;if(!a?.has(`style`)&&o){let t=o.cssText||``;if(t){let i=t.split(`;`).map(e=>e.trim()).filter(Boolean).map(t=>{let n=t.indexOf(`:`);if(n===-1)return t;let r=t.slice(0,n).trim(),i=t.slice(n+1).trim();return i?`${e(r)}: ${i};`:``}).filter(Boolean).join(` `);i&&(n+=` style="${r(i)}"`)}}if(a)for(let[t,r]of a){let i=l.has(t)?t:e(t);n+=d(i,r)}return n}if(t.attributes&&t.attributes.length)for(let e=0;e<t.attributes.length;e++){let r=t.attributes[e];r&&r.name&&(n+=d(r.name,r.value))}return n}const p=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`]),m=new Set([`script`,`style`]);function h(e,t){return t.replace(RegExp(`</(`+e+`)`,`gi`),`<\\/$1`)}function g(e){if(`tagName`in e&&`children`in e){let t=e.children;if(Array.isArray(t))return t}if(`childNodes`in e){let t=e.childNodes;if(t&&(Array.isArray(t)||t.length!==void 0))return t}return[]}function _(e){if(e.nodeType===3)return i(e.textContent||``);if(e.nodeType===8)return`<!--${e.textContent||``}-->`;if(e.nodeType===1){let t=e,n=t.tagName.toLowerCase(),r=f(t);if(p.has(n))return`<${n}${r} />`;if(m.has(n)){let i=``,a=g(t);if(a&&a.length>0)for(let e=0;e<a.length;e++){let t=a[e];t&&t.nodeType===3&&(i+=t.textContent||``)}else{let t=e.textContent;typeof t==`string`&&(i=t)}return`<${n}${r}>${h(n,i)}</${n}>`}let a=``,o=g(t);if(o&&o.length>0)for(let e=0;e<o.length;e++){let t=o[e];t&&(a+=_(t))}else{let t=e.textContent;typeof t==`string`&&t&&(a=i(t))}return`<${n}${r}>${a}</${n}>`}if(e.nodeType===11){let t=``,n=g(e);if(n&&n.length>0)for(let e=0;e<n.length;e++){let r=n[e];r&&(t+=_(r))}return t}return``}function v(e){if(!e)return``;if(typeof e==`function`)try{let t=c(`div`);if(!t)throw Error(`Document is not available. Make sure polyfills are loaded.`);let n=e(t,0);return n&&typeof n==`object`&&`nodeType`in n?_(n):``}catch(e){return console.error(`Error rendering component to string:`,e),``}return`nodeType`in e?_(e):``}function y(e){return e.map(e=>v(e))}function b(e,t=`div`,n={}){let r=v(e);return`<${t}${Object.entries(n).map(([e,t])=>d(e,t)).join(``)}>${r}</${t}>`}function x(e){}const S=[],C=new Map;let w=null;function T(){if(w!==null)return w;let e=S.join(``);for(let[t,n]of C)n.length>0&&(e+=t+`{`+n.join(``)+`}`);return w=e,e}export{T as getCssText,y as renderManyToString,v as renderToString,b as renderToStringWithContainer,x as setSSRCollector};
|
|
2
2
|
//# sourceMappingURL=nuclo.ssr.mjs.map
|