chispa 0.5.0 → 0.6.1
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/dist/html-compiler/cli.js +9 -9
- package/dist/html-compiler/cli.js.map +1 -1
- package/dist/html-compiler/vite-plugin.js +9 -9
- package/dist/html-compiler/vite-plugin.js.map +1 -1
- package/dist/index.d.ts +17 -7
- package/dist/index.js +152 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -63,11 +63,11 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
63
63
|
let attrValue = attr.value;
|
|
64
64
|
if (attrName === "data-cb") return;
|
|
65
65
|
if (attrName === "class") return;
|
|
66
|
-
|
|
66
|
+
const valueLiteral = JSON.stringify(attrValue);
|
|
67
67
|
if (attrName === "style") {
|
|
68
|
-
attrsHtml += ` '${attrName}':
|
|
68
|
+
attrsHtml += ` '${attrName}': ${valueLiteral}, `;
|
|
69
69
|
} else {
|
|
70
|
-
attrsHtml += ` '${attrName}':
|
|
70
|
+
attrsHtml += ` '${attrName}': ${valueLiteral}, `;
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
attrsHtml += "}";
|
|
@@ -113,7 +113,7 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
113
113
|
htmlNodeCode += `setAttributes(node, ${attrs});
|
|
114
114
|
`;
|
|
115
115
|
if (isComponent) {
|
|
116
|
-
htmlNodeCode += `setProps(node,
|
|
116
|
+
htmlNodeCode += `setProps(node, props);
|
|
117
117
|
`;
|
|
118
118
|
}
|
|
119
119
|
let subTs = "";
|
|
@@ -205,9 +205,9 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
205
205
|
} else {
|
|
206
206
|
const tagname = this.componentsTags[cbid];
|
|
207
207
|
if (this.isSvg[cbid]) {
|
|
208
|
-
return `type ${typename} =
|
|
208
|
+
return `type ${typename} = ChispaNodeBuilderPropsReactive<SVGElementTagNameMap['${tagname}'], ${itemsType}>;`;
|
|
209
209
|
} else {
|
|
210
|
-
return `type ${typename} =
|
|
210
|
+
return `type ${typename} = ChispaNodeBuilderPropsReactive<HTMLElementTagNameMap['${tagname.toLowerCase()}'], ${itemsType}>;`;
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -221,8 +221,8 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
221
221
|
`;
|
|
222
222
|
}
|
|
223
223
|
const jsOutput = `
|
|
224
|
-
import { appendChild, getItem,
|
|
225
|
-
import type { ChispaContentReactive,
|
|
224
|
+
import { appendChild, getItem, setAttributes, setProps } from 'chispa';
|
|
225
|
+
import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';
|
|
226
226
|
|
|
227
227
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
228
228
|
|
|
@@ -233,7 +233,7 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
233
233
|
export default template;
|
|
234
234
|
`;
|
|
235
235
|
const dtsOutput = `
|
|
236
|
-
import type { ChispaContentReactive,
|
|
236
|
+
import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';
|
|
237
237
|
|
|
238
238
|
${typedefs}
|
|
239
239
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/html-compiler/generator.ts","../../src/html-compiler/html-compiler.ts","../../src/html-compiler/cli.ts"],"sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { HtmlCompiler } from './html-compiler';\n\nexport async function generateTypes(filePath: string, content: string, rootDir: string) {\n\ttry {\n\t\tconst compiler = new HtmlCompiler(content);\n\t\tconst { dts } = await compiler.compile();\n\n\t\tconst outDir = path.join(rootDir, '.chispa/types');\n\t\tconst relativePath = path.relative(rootDir, filePath);\n\t\tconst targetPath = path.join(outDir, relativePath + '.d.ts');\n\t\tconst targetDir = path.dirname(targetPath);\n\n\t\tif (!fs.existsSync(targetDir)) {\n\t\t\tfs.mkdirSync(targetDir, { recursive: true });\n\t\t}\n\t\tfs.writeFileSync(targetPath, dts);\n\t} catch (e) {\n\t\tconsole.error(`[chispa] Error generating types for ${filePath}`, e);\n\t}\n}\n\nexport async function findAndCompileHtmlFiles(dir: string, rootDir: string) {\n\tif (!fs.existsSync(dir)) return;\n\tconst files = fs.readdirSync(dir);\n\tfor (const file of files) {\n\t\tconst fullPath = path.join(dir, file);\n\t\tif (fullPath === path.join(rootDir, 'index.html')) continue;\n\t\tif (fs.statSync(fullPath).isDirectory()) {\n\t\t\tif (file !== 'node_modules' && file !== '.git' && file !== 'dist' && file !== '.chispa') {\n\t\t\t\tawait findAndCompileHtmlFiles(fullPath, rootDir);\n\t\t\t}\n\t\t} else if (file.endsWith('.html')) {\n\t\t\tconsole.log('Generating types for', fullPath);\n\t\t\tconst content = fs.readFileSync(fullPath, 'utf-8');\n\t\t\tawait generateTypes(fullPath, content, rootDir);\n\t\t}\n\t}\n}\n","import { JSDOM } from 'jsdom';\nimport { format } from 'prettier';\n\nconst VOID_ELEMENTS = ['area', 'base', 'br', 'hr', 'img', 'input', 'link', 'meta', 'param', 'keygen', 'source'];\n\nconst SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\nexport class HtmlCompiler {\n\tprivate components: Record<string, string> = {};\n\tprivate stack: string[] = ['fragment'];\n\tprivate componentsItems: Record<string, string[]> = {};\n\tprivate componentsTags: Record<string, string> = {};\n\tprivate isSvg: Record<string, boolean> = {};\n\tprivate inSvgContext = 0;\n\tprivate htmlDocument: Document;\n\n\tconstructor(htmlContent: string) {\n\t\tconst dom = new JSDOM(htmlContent);\n\t\tthis.htmlDocument = dom.window.document;\n\t}\n\n\tprivate static camelize(str: string): string {\n\t\tif (str.startsWith('--')) {\n\t\t\treturn str;\n\t\t}\n\t\tconst arr = str.split('-');\n\t\tlet camelized = '';\n\t\tarr.forEach((v, i) => {\n\t\t\tcamelized += i === 0 ? v : v.charAt(0).toUpperCase() + v.slice(1);\n\t\t});\n\t\treturn camelized;\n\t}\n\n\tprivate static parseStyle(cssCode: string): string {\n\t\tlet out = '{';\n\t\tconst styles = cssCode.split(';');\n\t\tstyles.forEach((line) => {\n\t\t\tconst parts = line.split(':');\n\t\t\tif (parts.length !== 2) return;\n\t\t\tconst prop = HtmlCompiler.camelize(parts[0].trim());\n\t\t\tout += ` ${prop}: '${parts[1].trim()}',`;\n\t\t});\n\t\tout += '}';\n\t\treturn out;\n\t}\n\n\tprivate makeClassAttr(classAttr: string | null, isComponent: boolean): string {\n\t\tconst tplClasses = (classAttr || '').split(' ');\n\t\tlet finalClass = '';\n\n\t\ttplClasses.forEach((tplClass) => {\n\t\t\tif (!tplClass.startsWith('-tpl--')) {\n\t\t\t\tfinalClass += tplClass + ' ';\n\t\t\t}\n\t\t});\n\n\t\tfinalClass = finalClass.trim();\n\n\t\treturn ` 'class': \"${finalClass}\", `;\n\t}\n\n\tprivate getHtmlNodeAttrs(domNode: Element, isComponent: boolean): string {\n\t\tlet attrsHtml = '{';\n\t\tattrsHtml += this.makeClassAttr(domNode.getAttribute('class'), isComponent);\n\n\t\tArray.from(domNode.attributes).forEach((attr) => {\n\t\t\tconst attrName = attr.name;\n\t\t\tlet attrValue = attr.value;\n\n\t\t\tif (attrName === 'data-cb') return;\n\t\t\tif (attrName === 'class') return;\n\n\t\t\tattrValue = attrValue.replace(/\\n/g, ' ').replace(/\"/g, '\\\\\"');\n\n\t\t\t// Simplified logic compared to PHP which had cbt.prefixize... calls\n\t\t\t// Assuming we just output the value for now as I don't see cbt implementation here\n\t\t\t// The PHP code imported CoreBuilderTools but here we might not have it.\n\t\t\t// The user's example output imports from 'chispa'.\n\t\t\t// I will stick to simple string values for now unless I see cbt in chispa.\n\n\t\t\tif (attrName === 'style') {\n\t\t\t\t// PHP called cbt.prefixizeStyle, but also had parse_style static method.\n\t\t\t\t// Wait, the PHP code used cbt.prefixizeStyle inside get_html_node_attrs.\n\t\t\t\t// But parse_style was defined but not used in the snippet I read?\n\t\t\t\t// Ah, I should check if I should use parseStyle or just output string.\n\t\t\t\t// The PHP code: $attrs_html .= \" '$attr_name': cbt.prefixizeStyle('$attr_value'), \";\n\t\t\t\t// If cbt is a runtime helper, I should output the call.\n\t\t\t\t// But wait, the generated code imports CoreBuilderTools.\n\t\t\t\t// Does 'chispa' export CoreBuilderTools?\n\t\t\t\t// src/index.ts does NOT export CoreBuilderTools.\n\t\t\t\t// It exports appendChild, getItem, etc.\n\t\t\t\t// Maybe I should just output the string for now.\n\t\t\t\tattrsHtml += ` '${attrName}': \"${attrValue}\", `;\n\t\t\t} else {\n\t\t\t\tattrsHtml += ` '${attrName}': \"${attrValue}\", `;\n\t\t\t}\n\t\t});\n\n\t\tattrsHtml += '}';\n\t\treturn attrsHtml;\n\t}\n\n\tprivate buildTsForNode(domNode: Node, isComponent = false): string {\n\t\tlet htmlNodeCode = '';\n\n\t\tif (domNode.nodeType === 1) {\n\t\t\t// Element\n\t\t\tconst element = domNode as Element;\n\t\t\tlet tagName = element.tagName;\n\n\t\t\tif (tagName === 'svg') {\n\t\t\t\tthis.inSvgContext++;\n\t\t\t}\n\n\t\t\tlet cbid = element.getAttribute('data-cb');\n\n\t\t\tif (cbid) {\n\t\t\t\tconst currComp = this.stack[0];\n\t\t\t\telement.removeAttribute('data-cb');\n\t\t\t\tcbid = HtmlCompiler.camelize(cbid);\n\n\t\t\t\tif (!this.componentsItems[currComp]) {\n\t\t\t\t\tthis.componentsItems[currComp] = [];\n\t\t\t\t}\n\n\t\t\t\tthis.componentsItems[currComp].push(cbid);\n\t\t\t\tthis.stack.unshift(cbid);\n\t\t\t\tthis.components[cbid] = this.buildTsForNode(element, true);\n\t\t\t\tthis.componentsTags[cbid] = element.tagName;\n\t\t\t\tthis.isSvg[cbid] = this.inSvgContext > 0;\n\t\t\t\tthis.stack.shift();\n\n\t\t\t\tif (currComp === 'fragment') {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props, '${cbid}')`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props.nodes, '${cbid}')`;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst attrs = this.getHtmlNodeAttrs(element, isComponent);\n\n\t\t\t\tif (!this.inSvgContext) {\n\t\t\t\t\ttagName = tagName.toLowerCase();\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElement('${tagName}');\\n`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElementNS('${SVG_NAMESPACE}', '${tagName}');\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `setAttributes(node, ${attrs});\\n`;\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `setProps(node, getValidProps(props));\\n`;\n\t\t\t\t}\n\n\t\t\t\tlet subTs = '';\n\t\t\t\telement.childNodes.forEach((child) => {\n\t\t\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\t\t\tif (chCode) {\n\t\t\t\t\t\tsubTs += `appendChild(node, ${chCode});\\n`;\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tif (!VOID_ELEMENTS.includes(tagName.toLowerCase())) {\n\t\t\t\t\tif (isComponent) {\n\t\t\t\t\t\thtmlNodeCode += `\n if (props.inner === null) {\n node.innerHTML = '';\n } else if (props.inner !== undefined) {\n node.innerHTML = '';\n appendChild(node, props.inner);\n } else {\n ${subTs}\n }\n `;\n\t\t\t\t\t} else {\n\t\t\t\t\t\thtmlNodeCode += subTs;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `if (typeof props._ref === 'function') props._ref(node);\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `return node;})()`;\n\n\t\t\t\tif (tagName === 'svg') {\n\t\t\t\t\tthis.inSvgContext--;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (domNode.nodeType === 3) {\n\t\t\t// Text\n\t\t\tconst textNode = domNode as Text;\n\t\t\tconst parent = textNode.parentNode as Element;\n\t\t\tconst parentTag = parent ? parent.tagName.toLowerCase() : '';\n\n\t\t\tconst mustOmit = ['table', 'thead', 'tbody', 'tfoot', 'tr'].includes(parentTag);\n\n\t\t\tif (!mustOmit && textNode.textContent) {\n\t\t\t\tif (textNode.textContent.trim() === '') {\n\t\t\t\t\tif (textNode.textContent.length > 0) {\n\t\t\t\t\t\thtmlNodeCode += `document.createTextNode(' ')`;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode = `document.createTextNode(${JSON.stringify(textNode.textContent)})`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn htmlNodeCode.trim();\n\t}\n\n\tprivate static getPropsTypename(cbid: string): string {\n\t\treturn 'Cb' + cbid.charAt(0).toUpperCase() + cbid.slice(1) + 'Props';\n\t}\n\n\tprivate wrapFnComponent(cbid: string, jsx: string): string {\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\treturn `(props: ${typename}) => { \\n return(${jsx}); \\n }`;\n\t}\n\n\tprivate createAllComponents() {\n\t\tconst body = this.htmlDocument.querySelector('body');\n\t\tif (!body) throw new Error('Not valid HTML');\n\n\t\tlet rendererJsx = '(() => { const fragment = document.createDocumentFragment();\\n';\n\n\t\tbody.childNodes.forEach((child) => {\n\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\tif (chCode) {\n\t\t\t\trendererJsx += `appendChild(fragment, ${chCode});\\n`;\n\t\t\t}\n\t\t});\n\n\t\trendererJsx += 'return fragment;\\n';\n\t\trendererJsx += '})()';\n\n\t\tthis.components['fragment'] = rendererJsx;\n\t}\n\n\tprivate getTypedef(cbid: string): string {\n\t\tconst items = this.componentsItems[cbid] || [];\n\t\tlet itemsType = '{\\n';\n\t\titems.forEach((itemCbid) => {\n\t\t\tconst itemTypename = HtmlCompiler.getPropsTypename(itemCbid);\n\t\t\titemsType += `${itemCbid}?: ${itemTypename} | ChispaContentReactive;\\n`;\n\t\t});\n\t\titemsType += '}\\n';\n\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\n\t\tif (cbid === 'fragment') {\n\t\t\treturn `interface ${typename} ${itemsType}`;\n\t\t} else {\n\t\t\tconst tagname = this.componentsTags[cbid];\n\t\t\tif (this.isSvg[cbid]) {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderProps<SVGElementTagNameMap['${tagname}'], ${itemsType}>;`;\n\t\t\t} else {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderProps<HTMLElementTagNameMap['${tagname.toLowerCase()}'], ${itemsType}>;`;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async compile(): Promise<{ ts: string; dts: string }> {\n\t\tthis.createAllComponents();\n\n\t\tlet componentsClasses = '';\n\t\tlet typedefs = '';\n\n\t\tfor (const [cbid, compJsx] of Object.entries(this.components)) {\n\t\t\ttypedefs += this.getTypedef(cbid) + '\\n';\n\t\t\tcomponentsClasses += `${cbid}: ${this.wrapFnComponent(cbid, compJsx)},\\n`;\n\t\t}\n\n\t\tconst jsOutput = `\n import { appendChild, getItem, getValidProps, setAttributes, setProps } from 'chispa';\n import type { ChispaContentReactive, ChispaNodeBuilderProps } from 'chispa';\n\t\t\t\n const SVG_NS = 'http://www.w3.org/2000/svg';\n \n const template = {\n ${componentsClasses}\n };\n \n export default template;\n `;\n\n\t\tconst dtsOutput = `\n import type { ChispaContentReactive, ChispaNodeBuilderProps } from 'chispa';\n \n ${typedefs}\n \n declare const template: {\n ${Object.keys(this.components)\n\t\t\t\t\t.map((cbid) => {\n\t\t\t\t\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\t\t\t\t\treturn `${cbid}: (props: ${typename}) => Node | DocumentFragment;`;\n\t\t\t\t\t})\n\t\t\t\t\t.join('\\n')}\n };\n \n export default template;\n `;\n\n\t\tconst prettierOptions = {\n\t\t\tparser: 'typescript',\n\t\t\tsemi: true,\n\t\t\tsingleQuote: true,\n\t\t\tuseTabs: true,\n\t\t\tprintWidth: 120,\n\t\t};\n\n\t\treturn {\n\t\t\tts: await format(jsOutput, prettierOptions),\n\t\t\tdts: await format(dtsOutput, prettierOptions),\n\t\t};\n\t}\n}\n","#!/usr/bin/env node\nimport { findAndCompileHtmlFiles } from './generator';\n\nconst args = process.argv.slice(2);\n\nif (args.includes('--compile-html')) {\n\tconst rootDir = process.cwd();\n\tconsole.log('Scanning for HTML files...');\n\tawait findAndCompileHtmlFiles(rootDir, rootDir);\n\tconsole.log('HTML compilation completed.');\n} else {\n\tconsole.log('Usage: chispa-cli --compile-html');\n}\n"],"mappings":";;;AAAA,YAAY,QAAQ;AACpB,YAAY,UAAU;;;ACDtB,SAAS,aAAa;AACtB,SAAS,cAAc;AAEvB,IAAM,gBAAgB,CAAC,QAAQ,QAAQ,MAAM,MAAM,OAAO,SAAS,QAAQ,QAAQ,SAAS,UAAU,QAAQ;AAE9G,IAAM,gBAAgB;AAEf,IAAM,eAAN,MAAM,cAAa;AAAA,EACjB,aAAqC,CAAC;AAAA,EACtC,QAAkB,CAAC,UAAU;AAAA,EAC7B,kBAA4C,CAAC;AAAA,EAC7C,iBAAyC,CAAC;AAAA,EAC1C,QAAiC,CAAC;AAAA,EAClC,eAAe;AAAA,EACf;AAAA,EAER,YAAY,aAAqB;AAChC,UAAM,MAAM,IAAI,MAAM,WAAW;AACjC,SAAK,eAAe,IAAI,OAAO;AAAA,EAChC;AAAA,EAEA,OAAe,SAAS,KAAqB;AAC5C,QAAI,IAAI,WAAW,IAAI,GAAG;AACzB,aAAO;AAAA,IACR;AACA,UAAM,MAAM,IAAI,MAAM,GAAG;AACzB,QAAI,YAAY;AAChB,QAAI,QAAQ,CAAC,GAAG,MAAM;AACrB,mBAAa,MAAM,IAAI,IAAI,EAAE,OAAO,CAAC,EAAE,YAAY,IAAI,EAAE,MAAM,CAAC;AAAA,IACjE,CAAC;AACD,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,WAAW,SAAyB;AAClD,QAAI,MAAM;AACV,UAAM,SAAS,QAAQ,MAAM,GAAG;AAChC,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AS,OAAO,GAAG;AAClC,cAAQ,IAAI,wBAAwB,QAAQ;AAC5C,YAAM,UAAa,gBAAa,UAAU,OAAO;AACjD,YAAM,cAAc,UAAU,SAAS,OAAO;AAAA,IAC/C;AAAA,EACD;AACD;;;AEpCA,IAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,IAAI,KAAK,SAAS,gBAAgB,GAAG;AACpC,QAAM,UAAU,QAAQ,IAAI;AAC5B,UAAQ,IAAI,4BAA4B;AACxC,QAAM,wBAAwB,SAAS,OAAO;AAC9C,UAAQ,IAAI,6BAA6B;AAC1C,OAAO;AACN,UAAQ,IAAI,kCAAkC;AAC/C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/html-compiler/generator.ts","../../src/html-compiler/html-compiler.ts","../../src/html-compiler/cli.ts"],"sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { HtmlCompiler } from './html-compiler';\n\nexport async function generateTypes(filePath: string, content: string, rootDir: string) {\n\ttry {\n\t\tconst compiler = new HtmlCompiler(content);\n\t\tconst { dts } = await compiler.compile();\n\n\t\tconst outDir = path.join(rootDir, '.chispa/types');\n\t\tconst relativePath = path.relative(rootDir, filePath);\n\t\tconst targetPath = path.join(outDir, relativePath + '.d.ts');\n\t\tconst targetDir = path.dirname(targetPath);\n\n\t\tif (!fs.existsSync(targetDir)) {\n\t\t\tfs.mkdirSync(targetDir, { recursive: true });\n\t\t}\n\t\tfs.writeFileSync(targetPath, dts);\n\t} catch (e) {\n\t\tconsole.error(`[chispa] Error generating types for ${filePath}`, e);\n\t}\n}\n\nexport async function findAndCompileHtmlFiles(dir: string, rootDir: string) {\n\tif (!fs.existsSync(dir)) return;\n\tconst files = fs.readdirSync(dir);\n\tfor (const file of files) {\n\t\tconst fullPath = path.join(dir, file);\n\t\tif (fullPath === path.join(rootDir, 'index.html')) continue;\n\t\tif (fs.statSync(fullPath).isDirectory()) {\n\t\t\tif (file !== 'node_modules' && file !== '.git' && file !== 'dist' && file !== '.chispa') {\n\t\t\t\tawait findAndCompileHtmlFiles(fullPath, rootDir);\n\t\t\t}\n\t\t} else if (file.endsWith('.html')) {\n\t\t\tconsole.log('Generating types for', fullPath);\n\t\t\tconst content = fs.readFileSync(fullPath, 'utf-8');\n\t\t\tawait generateTypes(fullPath, content, rootDir);\n\t\t}\n\t}\n}\n","import { JSDOM } from 'jsdom';\nimport { format } from 'prettier';\n\nconst VOID_ELEMENTS = ['area', 'base', 'br', 'hr', 'img', 'input', 'link', 'meta', 'param', 'keygen', 'source'];\n\nconst SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\nexport class HtmlCompiler {\n\tprivate components: Record<string, string> = {};\n\tprivate stack: string[] = ['fragment'];\n\tprivate componentsItems: Record<string, string[]> = {};\n\tprivate componentsTags: Record<string, string> = {};\n\tprivate isSvg: Record<string, boolean> = {};\n\tprivate inSvgContext = 0;\n\tprivate htmlDocument: Document;\n\n\tconstructor(htmlContent: string) {\n\t\tconst dom = new JSDOM(htmlContent);\n\t\tthis.htmlDocument = dom.window.document;\n\t}\n\n\tprivate static camelize(str: string): string {\n\t\tif (str.startsWith('--')) {\n\t\t\treturn str;\n\t\t}\n\t\tconst arr = str.split('-');\n\t\tlet camelized = '';\n\t\tarr.forEach((v, i) => {\n\t\t\tcamelized += i === 0 ? v : v.charAt(0).toUpperCase() + v.slice(1);\n\t\t});\n\t\treturn camelized;\n\t}\n\n\tprivate static parseStyle(cssCode: string): string {\n\t\tlet out = '{';\n\t\tconst styles = cssCode.split(';');\n\t\tstyles.forEach((line) => {\n\t\t\tconst parts = line.split(':');\n\t\t\tif (parts.length !== 2) return;\n\t\t\tconst prop = HtmlCompiler.camelize(parts[0].trim());\n\t\t\tout += ` ${prop}: '${parts[1].trim()}',`;\n\t\t});\n\t\tout += '}';\n\t\treturn out;\n\t}\n\n\tprivate makeClassAttr(classAttr: string | null, isComponent: boolean): string {\n\t\tconst tplClasses = (classAttr || '').split(' ');\n\t\tlet finalClass = '';\n\n\t\ttplClasses.forEach((tplClass) => {\n\t\t\tif (!tplClass.startsWith('-tpl--')) {\n\t\t\t\tfinalClass += tplClass + ' ';\n\t\t\t}\n\t\t});\n\n\t\tfinalClass = finalClass.trim();\n\n\t\treturn ` 'class': \"${finalClass}\", `;\n\t}\n\n\tprivate getHtmlNodeAttrs(domNode: Element, isComponent: boolean): string {\n\t\tlet attrsHtml = '{';\n\t\tattrsHtml += this.makeClassAttr(domNode.getAttribute('class'), isComponent);\n\n\t\tArray.from(domNode.attributes).forEach((attr) => {\n\t\t\tconst attrName = attr.name;\n\t\t\tlet attrValue = attr.value;\n\n\t\t\tif (attrName === 'data-cb') return;\n\t\t\tif (attrName === 'class') return;\n\n\t\t\t// Use JSON.stringify to properly escape newlines, quotes and other characters\n\t\t\tconst valueLiteral = JSON.stringify(attrValue);\n\n\t\t\t// Simplified logic compared to PHP which had cbt.prefixize... calls\n\t\t\t// Assuming we just output the value for now as I don't see cbt implementation here\n\t\t\t// The PHP code imported CoreBuilderTools but here we might not have it.\n\t\t\t// The user's example output imports from 'chispa'.\n\t\t\t// I will stick to simple string values for now unless I see cbt in chispa.\n\n\t\t\tif (attrName === 'style') {\n\t\t\t\t// PHP called cbt.prefixizeStyle, but also had parse_style static method.\n\t\t\t\t// Wait, the PHP code used cbt.prefixizeStyle inside get_html_node_attrs.\n\t\t\t\t// But parse_style was defined but not used in the snippet I read?\n\t\t\t\t// Ah, I should check if I should use parseStyle or just output string.\n\t\t\t\t// The PHP code: $attrs_html .= \" '$attr_name': cbt.prefixizeStyle('$attr_value'), \";\n\t\t\t\t// If cbt is a runtime helper, I should output the call.\n\t\t\t\t// But wait, the generated code imports CoreBuilderTools.\n\t\t\t\t// Does 'chispa' export CoreBuilderTools?\n\t\t\t\t// src/index.ts does NOT export CoreBuilderTools.\n\t\t\t\t// It exports appendChild, getItem, etc.\n\t\t\t\t// Maybe I should just output the string for now.\n\t\t\t\tattrsHtml += ` '${attrName}': ${valueLiteral}, `;\n\t\t\t} else {\n\t\t\t\tattrsHtml += ` '${attrName}': ${valueLiteral}, `;\n\t\t\t}\n\t\t});\n\n\t\tattrsHtml += '}';\n\t\treturn attrsHtml;\n\t}\n\n\tprivate buildTsForNode(domNode: Node, isComponent = false): string {\n\t\tlet htmlNodeCode = '';\n\n\t\tif (domNode.nodeType === 1) {\n\t\t\t// Element\n\t\t\tconst element = domNode as Element;\n\t\t\tlet tagName = element.tagName;\n\n\t\t\tif (tagName === 'svg') {\n\t\t\t\tthis.inSvgContext++;\n\t\t\t}\n\n\t\t\tlet cbid = element.getAttribute('data-cb');\n\n\t\t\tif (cbid) {\n\t\t\t\tconst currComp = this.stack[0];\n\t\t\t\telement.removeAttribute('data-cb');\n\t\t\t\tcbid = HtmlCompiler.camelize(cbid);\n\n\t\t\t\tif (!this.componentsItems[currComp]) {\n\t\t\t\t\tthis.componentsItems[currComp] = [];\n\t\t\t\t}\n\n\t\t\t\tthis.componentsItems[currComp].push(cbid);\n\t\t\t\tthis.stack.unshift(cbid);\n\t\t\t\tthis.components[cbid] = this.buildTsForNode(element, true);\n\t\t\t\tthis.componentsTags[cbid] = element.tagName;\n\t\t\t\tthis.isSvg[cbid] = this.inSvgContext > 0;\n\t\t\t\tthis.stack.shift();\n\n\t\t\t\tif (currComp === 'fragment') {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props, '${cbid}')`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props.nodes, '${cbid}')`;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst attrs = this.getHtmlNodeAttrs(element, isComponent);\n\n\t\t\t\tif (!this.inSvgContext) {\n\t\t\t\t\ttagName = tagName.toLowerCase();\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElement('${tagName}');\\n`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElementNS('${SVG_NAMESPACE}', '${tagName}');\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `setAttributes(node, ${attrs});\\n`;\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `setProps(node, props);\\n`;\n\t\t\t\t}\n\n\t\t\t\tlet subTs = '';\n\t\t\t\telement.childNodes.forEach((child) => {\n\t\t\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\t\t\tif (chCode) {\n\t\t\t\t\t\tsubTs += `appendChild(node, ${chCode});\\n`;\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tif (!VOID_ELEMENTS.includes(tagName.toLowerCase())) {\n\t\t\t\t\tif (isComponent) {\n\t\t\t\t\t\thtmlNodeCode += `\n if (props.inner === null) {\n node.innerHTML = '';\n } else if (props.inner !== undefined) {\n node.innerHTML = '';\n appendChild(node, props.inner);\n } else {\n ${subTs}\n }\n `;\n\t\t\t\t\t} else {\n\t\t\t\t\t\thtmlNodeCode += subTs;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `if (typeof props._ref === 'function') props._ref(node);\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `return node;})()`;\n\n\t\t\t\tif (tagName === 'svg') {\n\t\t\t\t\tthis.inSvgContext--;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (domNode.nodeType === 3) {\n\t\t\t// Text\n\t\t\tconst textNode = domNode as Text;\n\t\t\tconst parent = textNode.parentNode as Element;\n\t\t\tconst parentTag = parent ? parent.tagName.toLowerCase() : '';\n\n\t\t\tconst mustOmit = ['table', 'thead', 'tbody', 'tfoot', 'tr'].includes(parentTag);\n\n\t\t\tif (!mustOmit && textNode.textContent) {\n\t\t\t\tif (textNode.textContent.trim() === '') {\n\t\t\t\t\tif (textNode.textContent.length > 0) {\n\t\t\t\t\t\thtmlNodeCode += `document.createTextNode(' ')`;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode = `document.createTextNode(${JSON.stringify(textNode.textContent)})`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn htmlNodeCode.trim();\n\t}\n\n\tprivate static getPropsTypename(cbid: string): string {\n\t\treturn 'Cb' + cbid.charAt(0).toUpperCase() + cbid.slice(1) + 'Props';\n\t}\n\n\tprivate wrapFnComponent(cbid: string, jsx: string): string {\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\treturn `(props: ${typename}) => { \\n return(${jsx}); \\n }`;\n\t}\n\n\tprivate createAllComponents() {\n\t\tconst body = this.htmlDocument.querySelector('body');\n\t\tif (!body) throw new Error('Not valid HTML');\n\n\t\tlet rendererJsx = '(() => { const fragment = document.createDocumentFragment();\\n';\n\n\t\tbody.childNodes.forEach((child) => {\n\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\tif (chCode) {\n\t\t\t\trendererJsx += `appendChild(fragment, ${chCode});\\n`;\n\t\t\t}\n\t\t});\n\n\t\trendererJsx += 'return fragment;\\n';\n\t\trendererJsx += '})()';\n\n\t\tthis.components['fragment'] = rendererJsx;\n\t}\n\n\tprivate getTypedef(cbid: string): string {\n\t\tconst items = this.componentsItems[cbid] || [];\n\t\tlet itemsType = '{\\n';\n\t\titems.forEach((itemCbid) => {\n\t\t\tconst itemTypename = HtmlCompiler.getPropsTypename(itemCbid);\n\t\t\titemsType += `${itemCbid}?: ${itemTypename} | ChispaContentReactive;\\n`;\n\t\t});\n\t\titemsType += '}\\n';\n\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\n\t\tif (cbid === 'fragment') {\n\t\t\treturn `interface ${typename} ${itemsType}`;\n\t\t} else {\n\t\t\tconst tagname = this.componentsTags[cbid];\n\t\t\tif (this.isSvg[cbid]) {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderPropsReactive<SVGElementTagNameMap['${tagname}'], ${itemsType}>;`;\n\t\t\t} else {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderPropsReactive<HTMLElementTagNameMap['${tagname.toLowerCase()}'], ${itemsType}>;`;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async compile(): Promise<{ ts: string; dts: string }> {\n\t\tthis.createAllComponents();\n\n\t\tlet componentsClasses = '';\n\t\tlet typedefs = '';\n\n\t\tfor (const [cbid, compJsx] of Object.entries(this.components)) {\n\t\t\ttypedefs += this.getTypedef(cbid) + '\\n';\n\t\t\tcomponentsClasses += `${cbid}: ${this.wrapFnComponent(cbid, compJsx)},\\n`;\n\t\t}\n\n\t\tconst jsOutput = `\n import { appendChild, getItem, setAttributes, setProps } from 'chispa';\n import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';\n\t\t\t\n const SVG_NS = 'http://www.w3.org/2000/svg';\n \n const template = {\n ${componentsClasses}\n };\n \n export default template;\n `;\n\n\t\tconst dtsOutput = `\n import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';\n \n ${typedefs}\n \n declare const template: {\n ${Object.keys(this.components)\n\t\t\t\t\t.map((cbid) => {\n\t\t\t\t\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\t\t\t\t\treturn `${cbid}: (props: ${typename}) => Node | DocumentFragment;`;\n\t\t\t\t\t})\n\t\t\t\t\t.join('\\n')}\n };\n \n export default template;\n `;\n\n\t\tconst prettierOptions = {\n\t\t\tparser: 'typescript',\n\t\t\tsemi: true,\n\t\t\tsingleQuote: true,\n\t\t\tuseTabs: true,\n\t\t\tprintWidth: 120,\n\t\t};\n\n\t\treturn {\n\t\t\tts: await format(jsOutput, prettierOptions),\n\t\t\tdts: await format(dtsOutput, prettierOptions),\n\t\t};\n\t}\n}\n","#!/usr/bin/env node\nimport { findAndCompileHtmlFiles } from './generator';\n\nconst args = process.argv.slice(2);\n\nif (args.includes('--compile-html')) {\n\tconst rootDir = process.cwd();\n\tconsole.log('Scanning for HTML files...');\n\tawait findAndCompileHtmlFiles(rootDir, rootDir);\n\tconsole.log('HTML compilation completed.');\n} else {\n\tconsole.log('Usage: chispa-cli --compile-html');\n}\n"],"mappings":";;;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AAC1C,OAAO;AACN,UAAQ,IAAI,kCAAkC;AAC/C;","names":[]}
|
|
@@ -57,11 +57,11 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
57
57
|
let attrValue = attr.value;
|
|
58
58
|
if (attrName === "data-cb") return;
|
|
59
59
|
if (attrName === "class") return;
|
|
60
|
-
|
|
60
|
+
const valueLiteral = JSON.stringify(attrValue);
|
|
61
61
|
if (attrName === "style") {
|
|
62
|
-
attrsHtml += ` '${attrName}':
|
|
62
|
+
attrsHtml += ` '${attrName}': ${valueLiteral}, `;
|
|
63
63
|
} else {
|
|
64
|
-
attrsHtml += ` '${attrName}':
|
|
64
|
+
attrsHtml += ` '${attrName}': ${valueLiteral}, `;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
attrsHtml += "}";
|
|
@@ -107,7 +107,7 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
107
107
|
htmlNodeCode += `setAttributes(node, ${attrs});
|
|
108
108
|
`;
|
|
109
109
|
if (isComponent) {
|
|
110
|
-
htmlNodeCode += `setProps(node,
|
|
110
|
+
htmlNodeCode += `setProps(node, props);
|
|
111
111
|
`;
|
|
112
112
|
}
|
|
113
113
|
let subTs = "";
|
|
@@ -199,9 +199,9 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
199
199
|
} else {
|
|
200
200
|
const tagname = this.componentsTags[cbid];
|
|
201
201
|
if (this.isSvg[cbid]) {
|
|
202
|
-
return `type ${typename} =
|
|
202
|
+
return `type ${typename} = ChispaNodeBuilderPropsReactive<SVGElementTagNameMap['${tagname}'], ${itemsType}>;`;
|
|
203
203
|
} else {
|
|
204
|
-
return `type ${typename} =
|
|
204
|
+
return `type ${typename} = ChispaNodeBuilderPropsReactive<HTMLElementTagNameMap['${tagname.toLowerCase()}'], ${itemsType}>;`;
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
}
|
|
@@ -215,8 +215,8 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
215
215
|
`;
|
|
216
216
|
}
|
|
217
217
|
const jsOutput = `
|
|
218
|
-
import { appendChild, getItem,
|
|
219
|
-
import type { ChispaContentReactive,
|
|
218
|
+
import { appendChild, getItem, setAttributes, setProps } from 'chispa';
|
|
219
|
+
import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';
|
|
220
220
|
|
|
221
221
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
222
222
|
|
|
@@ -227,7 +227,7 @@ var HtmlCompiler = class _HtmlCompiler {
|
|
|
227
227
|
export default template;
|
|
228
228
|
`;
|
|
229
229
|
const dtsOutput = `
|
|
230
|
-
import type { ChispaContentReactive,
|
|
230
|
+
import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';
|
|
231
231
|
|
|
232
232
|
${typedefs}
|
|
233
233
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/html-compiler/html-compiler.ts","../../src/html-compiler/generator.ts","../../src/html-compiler/vite-plugin.ts"],"sourcesContent":["import { JSDOM } from 'jsdom';\nimport { format } from 'prettier';\n\nconst VOID_ELEMENTS = ['area', 'base', 'br', 'hr', 'img', 'input', 'link', 'meta', 'param', 'keygen', 'source'];\n\nconst SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\nexport class HtmlCompiler {\n\tprivate components: Record<string, string> = {};\n\tprivate stack: string[] = ['fragment'];\n\tprivate componentsItems: Record<string, string[]> = {};\n\tprivate componentsTags: Record<string, string> = {};\n\tprivate isSvg: Record<string, boolean> = {};\n\tprivate inSvgContext = 0;\n\tprivate htmlDocument: Document;\n\n\tconstructor(htmlContent: string) {\n\t\tconst dom = new JSDOM(htmlContent);\n\t\tthis.htmlDocument = dom.window.document;\n\t}\n\n\tprivate static camelize(str: string): string {\n\t\tif (str.startsWith('--')) {\n\t\t\treturn str;\n\t\t}\n\t\tconst arr = str.split('-');\n\t\tlet camelized = '';\n\t\tarr.forEach((v, i) => {\n\t\t\tcamelized += i === 0 ? v : v.charAt(0).toUpperCase() + v.slice(1);\n\t\t});\n\t\treturn camelized;\n\t}\n\n\tprivate static parseStyle(cssCode: string): string {\n\t\tlet out = '{';\n\t\tconst styles = cssCode.split(';');\n\t\tstyles.forEach((line) => {\n\t\t\tconst parts = line.split(':');\n\t\t\tif (parts.length !== 2) return;\n\t\t\tconst prop = HtmlCompiler.camelize(parts[0].trim());\n\t\t\tout += ` ${prop}: '${parts[1].trim()}',`;\n\t\t});\n\t\tout += '}';\n\t\treturn out;\n\t}\n\n\tprivate makeClassAttr(classAttr: string | null, isComponent: boolean): string {\n\t\tconst tplClasses = (classAttr || '').split(' ');\n\t\tlet finalClass = '';\n\n\t\ttplClasses.forEach((tplClass) => {\n\t\t\tif (!tplClass.startsWith('-tpl--')) {\n\t\t\t\tfinalClass += tplClass + ' ';\n\t\t\t}\n\t\t});\n\n\t\tfinalClass = finalClass.trim();\n\n\t\treturn ` 'class': \"${finalClass}\", `;\n\t}\n\n\tprivate getHtmlNodeAttrs(domNode: Element, isComponent: boolean): string {\n\t\tlet attrsHtml = '{';\n\t\tattrsHtml += this.makeClassAttr(domNode.getAttribute('class'), isComponent);\n\n\t\tArray.from(domNode.attributes).forEach((attr) => {\n\t\t\tconst attrName = attr.name;\n\t\t\tlet attrValue = attr.value;\n\n\t\t\tif (attrName === 'data-cb') return;\n\t\t\tif (attrName === 'class') return;\n\n\t\t\tattrValue = attrValue.replace(/\\n/g, ' ').replace(/\"/g, '\\\\\"');\n\n\t\t\t// Simplified logic compared to PHP which had cbt.prefixize... calls\n\t\t\t// Assuming we just output the value for now as I don't see cbt implementation here\n\t\t\t// The PHP code imported CoreBuilderTools but here we might not have it.\n\t\t\t// The user's example output imports from 'chispa'.\n\t\t\t// I will stick to simple string values for now unless I see cbt in chispa.\n\n\t\t\tif (attrName === 'style') {\n\t\t\t\t// PHP called cbt.prefixizeStyle, but also had parse_style static method.\n\t\t\t\t// Wait, the PHP code used cbt.prefixizeStyle inside get_html_node_attrs.\n\t\t\t\t// But parse_style was defined but not used in the snippet I read?\n\t\t\t\t// Ah, I should check if I should use parseStyle or just output string.\n\t\t\t\t// The PHP code: $attrs_html .= \" '$attr_name': cbt.prefixizeStyle('$attr_value'), \";\n\t\t\t\t// If cbt is a runtime helper, I should output the call.\n\t\t\t\t// But wait, the generated code imports CoreBuilderTools.\n\t\t\t\t// Does 'chispa' export CoreBuilderTools?\n\t\t\t\t// src/index.ts does NOT export CoreBuilderTools.\n\t\t\t\t// It exports appendChild, getItem, etc.\n\t\t\t\t// Maybe I should just output the string for now.\n\t\t\t\tattrsHtml += ` '${attrName}': \"${attrValue}\", `;\n\t\t\t} else {\n\t\t\t\tattrsHtml += ` '${attrName}': \"${attrValue}\", `;\n\t\t\t}\n\t\t});\n\n\t\tattrsHtml += '}';\n\t\treturn attrsHtml;\n\t}\n\n\tprivate buildTsForNode(domNode: Node, isComponent = false): string {\n\t\tlet htmlNodeCode = '';\n\n\t\tif (domNode.nodeType === 1) {\n\t\t\t// Element\n\t\t\tconst element = domNode as Element;\n\t\t\tlet tagName = element.tagName;\n\n\t\t\tif (tagName === 'svg') {\n\t\t\t\tthis.inSvgContext++;\n\t\t\t}\n\n\t\t\tlet cbid = element.getAttribute('data-cb');\n\n\t\t\tif (cbid) {\n\t\t\t\tconst currComp = this.stack[0];\n\t\t\t\telement.removeAttribute('data-cb');\n\t\t\t\tcbid = HtmlCompiler.camelize(cbid);\n\n\t\t\t\tif (!this.componentsItems[currComp]) {\n\t\t\t\t\tthis.componentsItems[currComp] = [];\n\t\t\t\t}\n\n\t\t\t\tthis.componentsItems[currComp].push(cbid);\n\t\t\t\tthis.stack.unshift(cbid);\n\t\t\t\tthis.components[cbid] = this.buildTsForNode(element, true);\n\t\t\t\tthis.componentsTags[cbid] = element.tagName;\n\t\t\t\tthis.isSvg[cbid] = this.inSvgContext > 0;\n\t\t\t\tthis.stack.shift();\n\n\t\t\t\tif (currComp === 'fragment') {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props, '${cbid}')`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props.nodes, '${cbid}')`;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst attrs = this.getHtmlNodeAttrs(element, isComponent);\n\n\t\t\t\tif (!this.inSvgContext) {\n\t\t\t\t\ttagName = tagName.toLowerCase();\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElement('${tagName}');\\n`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElementNS('${SVG_NAMESPACE}', '${tagName}');\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `setAttributes(node, ${attrs});\\n`;\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `setProps(node, getValidProps(props));\\n`;\n\t\t\t\t}\n\n\t\t\t\tlet subTs = '';\n\t\t\t\telement.childNodes.forEach((child) => {\n\t\t\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\t\t\tif (chCode) {\n\t\t\t\t\t\tsubTs += `appendChild(node, ${chCode});\\n`;\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tif (!VOID_ELEMENTS.includes(tagName.toLowerCase())) {\n\t\t\t\t\tif (isComponent) {\n\t\t\t\t\t\thtmlNodeCode += `\n if (props.inner === null) {\n node.innerHTML = '';\n } else if (props.inner !== undefined) {\n node.innerHTML = '';\n appendChild(node, props.inner);\n } else {\n ${subTs}\n }\n `;\n\t\t\t\t\t} else {\n\t\t\t\t\t\thtmlNodeCode += subTs;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `if (typeof props._ref === 'function') props._ref(node);\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `return node;})()`;\n\n\t\t\t\tif (tagName === 'svg') {\n\t\t\t\t\tthis.inSvgContext--;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (domNode.nodeType === 3) {\n\t\t\t// Text\n\t\t\tconst textNode = domNode as Text;\n\t\t\tconst parent = textNode.parentNode as Element;\n\t\t\tconst parentTag = parent ? parent.tagName.toLowerCase() : '';\n\n\t\t\tconst mustOmit = ['table', 'thead', 'tbody', 'tfoot', 'tr'].includes(parentTag);\n\n\t\t\tif (!mustOmit && textNode.textContent) {\n\t\t\t\tif (textNode.textContent.trim() === '') {\n\t\t\t\t\tif (textNode.textContent.length > 0) {\n\t\t\t\t\t\thtmlNodeCode += `document.createTextNode(' ')`;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode = `document.createTextNode(${JSON.stringify(textNode.textContent)})`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn htmlNodeCode.trim();\n\t}\n\n\tprivate static getPropsTypename(cbid: string): string {\n\t\treturn 'Cb' + cbid.charAt(0).toUpperCase() + cbid.slice(1) + 'Props';\n\t}\n\n\tprivate wrapFnComponent(cbid: string, jsx: string): string {\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\treturn `(props: ${typename}) => { \\n return(${jsx}); \\n }`;\n\t}\n\n\tprivate createAllComponents() {\n\t\tconst body = this.htmlDocument.querySelector('body');\n\t\tif (!body) throw new Error('Not valid HTML');\n\n\t\tlet rendererJsx = '(() => { const fragment = document.createDocumentFragment();\\n';\n\n\t\tbody.childNodes.forEach((child) => {\n\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\tif (chCode) {\n\t\t\t\trendererJsx += `appendChild(fragment, ${chCode});\\n`;\n\t\t\t}\n\t\t});\n\n\t\trendererJsx += 'return fragment;\\n';\n\t\trendererJsx += '})()';\n\n\t\tthis.components['fragment'] = rendererJsx;\n\t}\n\n\tprivate getTypedef(cbid: string): string {\n\t\tconst items = this.componentsItems[cbid] || [];\n\t\tlet itemsType = '{\\n';\n\t\titems.forEach((itemCbid) => {\n\t\t\tconst itemTypename = HtmlCompiler.getPropsTypename(itemCbid);\n\t\t\titemsType += `${itemCbid}?: ${itemTypename} | ChispaContentReactive;\\n`;\n\t\t});\n\t\titemsType += '}\\n';\n\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\n\t\tif (cbid === 'fragment') {\n\t\t\treturn `interface ${typename} ${itemsType}`;\n\t\t} else {\n\t\t\tconst tagname = this.componentsTags[cbid];\n\t\t\tif (this.isSvg[cbid]) {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderProps<SVGElementTagNameMap['${tagname}'], ${itemsType}>;`;\n\t\t\t} else {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderProps<HTMLElementTagNameMap['${tagname.toLowerCase()}'], ${itemsType}>;`;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async compile(): Promise<{ ts: string; dts: string }> {\n\t\tthis.createAllComponents();\n\n\t\tlet componentsClasses = '';\n\t\tlet typedefs = '';\n\n\t\tfor (const [cbid, compJsx] of Object.entries(this.components)) {\n\t\t\ttypedefs += this.getTypedef(cbid) + '\\n';\n\t\t\tcomponentsClasses += `${cbid}: ${this.wrapFnComponent(cbid, compJsx)},\\n`;\n\t\t}\n\n\t\tconst jsOutput = `\n import { appendChild, getItem, getValidProps, setAttributes, setProps } from 'chispa';\n import type { ChispaContentReactive, ChispaNodeBuilderProps } from 'chispa';\n\t\t\t\n const SVG_NS = 'http://www.w3.org/2000/svg';\n \n const template = {\n ${componentsClasses}\n };\n \n export default template;\n `;\n\n\t\tconst dtsOutput = `\n import type { ChispaContentReactive, ChispaNodeBuilderProps } from 'chispa';\n \n ${typedefs}\n \n declare const template: {\n ${Object.keys(this.components)\n\t\t\t\t\t.map((cbid) => {\n\t\t\t\t\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\t\t\t\t\treturn `${cbid}: (props: ${typename}) => Node | DocumentFragment;`;\n\t\t\t\t\t})\n\t\t\t\t\t.join('\\n')}\n };\n \n export default template;\n `;\n\n\t\tconst prettierOptions = {\n\t\t\tparser: 'typescript',\n\t\t\tsemi: true,\n\t\t\tsingleQuote: true,\n\t\t\tuseTabs: true,\n\t\t\tprintWidth: 120,\n\t\t};\n\n\t\treturn {\n\t\t\tts: await format(jsOutput, prettierOptions),\n\t\t\tdts: await format(dtsOutput, prettierOptions),\n\t\t};\n\t}\n}\n","import * as fs from 'fs';\nimport * as path from 'path';\nimport { HtmlCompiler } from './html-compiler';\n\nexport async function generateTypes(filePath: string, content: string, rootDir: string) {\n\ttry {\n\t\tconst compiler = new HtmlCompiler(content);\n\t\tconst { dts } = await compiler.compile();\n\n\t\tconst outDir = path.join(rootDir, '.chispa/types');\n\t\tconst relativePath = path.relative(rootDir, filePath);\n\t\tconst targetPath = path.join(outDir, relativePath + '.d.ts');\n\t\tconst targetDir = path.dirname(targetPath);\n\n\t\tif (!fs.existsSync(targetDir)) {\n\t\t\tfs.mkdirSync(targetDir, { recursive: true });\n\t\t}\n\t\tfs.writeFileSync(targetPath, dts);\n\t} catch (e) {\n\t\tconsole.error(`[chispa] Error generating types for ${filePath}`, e);\n\t}\n}\n\nexport async function findAndCompileHtmlFiles(dir: string, rootDir: string) {\n\tif (!fs.existsSync(dir)) return;\n\tconst files = fs.readdirSync(dir);\n\tfor (const file of files) {\n\t\tconst fullPath = path.join(dir, file);\n\t\tif (fullPath === path.join(rootDir, 'index.html')) continue;\n\t\tif (fs.statSync(fullPath).isDirectory()) {\n\t\t\tif (file !== 'node_modules' && file !== '.git' && file !== 'dist' && file !== '.chispa') {\n\t\t\t\tawait findAndCompileHtmlFiles(fullPath, rootDir);\n\t\t\t}\n\t\t} else if (file.endsWith('.html')) {\n\t\t\tconsole.log('Generating types for', fullPath);\n\t\t\tconst content = fs.readFileSync(fullPath, 'utf-8');\n\t\t\tawait generateTypes(fullPath, content, rootDir);\n\t\t}\n\t}\n}\n","import { HtmlCompiler } from './html-compiler';\nimport { generateTypes, findAndCompileHtmlFiles } from './generator';\nimport { type Plugin, transformWithEsbuild } from 'vite';\nimport * as fs from 'fs';\n\n/**\n * Convierte una ruta real de archivo en el ID de módulo virtual que usa Vite/Rollup.\n * Añade el prefijo `\\0` para marcar el módulo como virtual y el sufijo\n * `.chispa.ts` para que sea tratado como módulo TypeScript.\n */\nconst toVirtualId = (id: string) => '\\0' + id + '.chispa.ts';\n\n/**\n * Convierte un ID de módulo virtual de vuelta a la ruta real del archivo.\n * Elimina el prefijo `\\0` (si existe) y el sufijo `.chispa.ts`.\n */\nconst fromVirtualId = (id: string) => id.replace(/^\\0/, '').replace('.chispa.ts', '');\n\nexport function chispaHtmlPlugin(): Plugin {\n\tlet rootDir = process.cwd();\n\n\treturn {\n\t\tname: 'chispa-html',\n\t\tenforce: 'pre',\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync buildStart() {\n\t\t\tawait findAndCompileHtmlFiles(rootDir, rootDir);\n\t\t},\n\t\tasync handleHotUpdate(ctx) {\n\t\t\tif (ctx.file.endsWith('.html')) {\n\t\t\t\tconst content = await ctx.read();\n\t\t\t\tawait generateTypes(ctx.file, content, rootDir);\n\n\t\t\t\t// Buscamos el módulo virtual asociado al archivo HTML modificado.\n\t\t\t\tconst module = ctx.server.moduleGraph.getModuleById(toVirtualId(ctx.file));\n\t\t\t\tif (module) {\n\t\t\t\t\treturn [module];\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tasync resolveId(source, importer, options) {\n\t\t\tif (source.endsWith('.html.chispa.ts')) {\n\t\t\t\treturn source;\n\t\t\t}\n\t\t\tif (source.endsWith('.html') && importer) {\n\t\t\t\tconst resolution = await this.resolve(source, importer, { skipSelf: true, ...options });\n\t\t\t\tif (resolution && !resolution.external) {\n\t\t\t\t\treturn toVirtualId(resolution.id);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t\tasync load(id) {\n\t\t\tif (id.endsWith('.html.chispa.ts')) {\n\t\t\t\tconst realId = fromVirtualId(id);\n\t\t\t\ttry {\n\t\t\t\t\tconst content = fs.readFileSync(realId, 'utf-8');\n\t\t\t\t\tif (content.includes('<!DOCTYPE html>') || content.includes('<html')) {\n\t\t\t\t\t\treturn 'export default {};';\n\t\t\t\t\t}\n\n\t\t\t\t\tconst compiler = new HtmlCompiler(content);\n\t\t\t\t\tconst { ts } = await compiler.compile();\n\t\t\t\t\tgenerateTypes(realId, content, rootDir);\n\n\t\t\t\t\tconst result = await transformWithEsbuild(ts, realId, {\n\t\t\t\t\t\tloader: 'ts',\n\t\t\t\t\t});\n\t\t\t\t\treturn result.code;\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(`[chispa] Error loading ${id}:`, e);\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,cAAc;AAEvB,IAAM,gBAAgB,CAAC,QAAQ,QAAQ,MAAM,MAAM,OAAO,SAAS,QAAQ,QAAQ,SAAS,UAAU,QAAQ;AAE9G,IAAM,gBAAgB;AAEf,IAAM,eAAN,MAAM,cAAa;AAAA,EACjB,aAAqC,CAAC;AAAA,EACtC,QAAkB,CAAC,UAAU;AAAA,EAC7B,kBAA4C,CAAC;AAAA,EAC7C,iBAAyC,CAAC;AAAA,EAC1C,QAAiC,CAAC;AAAA,EAClC,eAAe;AAAA,EACf;AAAA,EAER,YAAY,aAAqB;AAChC,UAAM,MAAM,IAAI,MAAM,WAAW;AACjC,SAAK,eAAe,IAAI,OAAO;AAAA,EAChC;AAAA,EAEA,OAAe,SAAS,KAAqB;AAC5C,QAAI,IAAI,WAAW,IAAI,GAAG;AACzB,aAAO;AAAA,IACR;AACA,UAAM,MAAM,IAAI,MAAM,GAAG;AACzB,QAAI,YAAY;AAChB,QAAI,QAAQ,CAAC,GAAG,MAAM;AACrB,mBAAa,MAAM,IAAI,IAAI,EAAE,OAAO,CAAC,EAAE,YAAY,IAAI,EAAE,MAAM,CAAC;AAAA,IACjE,CAAC;AACD,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,WAAW,SAAyB;AAClD,QAAI,MAAM;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AAAA,QACjC;AAAA,MACD;AACA,aAAO;AAAA,IACR;AAAA,IACA,MAAM,KAAK,IAAI;AACd,UAAI,GAAG,SAAS,iBAAiB,GAAG;AACnC,cAAM,SAAS,cAAc,EAAE;AAC/B,YAAI;AACH,gBAAM,UAAa,iBAAa,QAAQ,OAAO;AAC/C,cAAI,QAAQ,SAAS,iBAAiB,KAAK,QAAQ,SAAS,OAAO,GAAG;AACrE,mBAAO;AAAA,UACR;AAEA,gBAAM,WAAW,IAAI,aAAa,OAAO;AACzC,gBAAM,EAAE,GAAG,IAAI,MAAM,SAAS,QAAQ;AACtC,wBAAc,QAAQ,SAAS,OAAO;AAEtC,gBAAM,SAAS,MAAM,qBAAqB,IAAI,QAAQ;AAAA,YACrD,QAAQ;AAAA,UACT,CAAC;AACD,iBAAO,OAAO;AAAA,QACf,SAAS,GAAG;AACX,kBAAQ,MAAM,0BAA0B,EAAE,KAAK,CAAC;AAChD,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;","names":["fs"]}
|
|
1
|
+
{"version":3,"sources":["../../src/html-compiler/html-compiler.ts","../../src/html-compiler/generator.ts","../../src/html-compiler/vite-plugin.ts"],"sourcesContent":["import { JSDOM } from 'jsdom';\nimport { format } from 'prettier';\n\nconst VOID_ELEMENTS = ['area', 'base', 'br', 'hr', 'img', 'input', 'link', 'meta', 'param', 'keygen', 'source'];\n\nconst SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\nexport class HtmlCompiler {\n\tprivate components: Record<string, string> = {};\n\tprivate stack: string[] = ['fragment'];\n\tprivate componentsItems: Record<string, string[]> = {};\n\tprivate componentsTags: Record<string, string> = {};\n\tprivate isSvg: Record<string, boolean> = {};\n\tprivate inSvgContext = 0;\n\tprivate htmlDocument: Document;\n\n\tconstructor(htmlContent: string) {\n\t\tconst dom = new JSDOM(htmlContent);\n\t\tthis.htmlDocument = dom.window.document;\n\t}\n\n\tprivate static camelize(str: string): string {\n\t\tif (str.startsWith('--')) {\n\t\t\treturn str;\n\t\t}\n\t\tconst arr = str.split('-');\n\t\tlet camelized = '';\n\t\tarr.forEach((v, i) => {\n\t\t\tcamelized += i === 0 ? v : v.charAt(0).toUpperCase() + v.slice(1);\n\t\t});\n\t\treturn camelized;\n\t}\n\n\tprivate static parseStyle(cssCode: string): string {\n\t\tlet out = '{';\n\t\tconst styles = cssCode.split(';');\n\t\tstyles.forEach((line) => {\n\t\t\tconst parts = line.split(':');\n\t\t\tif (parts.length !== 2) return;\n\t\t\tconst prop = HtmlCompiler.camelize(parts[0].trim());\n\t\t\tout += ` ${prop}: '${parts[1].trim()}',`;\n\t\t});\n\t\tout += '}';\n\t\treturn out;\n\t}\n\n\tprivate makeClassAttr(classAttr: string | null, isComponent: boolean): string {\n\t\tconst tplClasses = (classAttr || '').split(' ');\n\t\tlet finalClass = '';\n\n\t\ttplClasses.forEach((tplClass) => {\n\t\t\tif (!tplClass.startsWith('-tpl--')) {\n\t\t\t\tfinalClass += tplClass + ' ';\n\t\t\t}\n\t\t});\n\n\t\tfinalClass = finalClass.trim();\n\n\t\treturn ` 'class': \"${finalClass}\", `;\n\t}\n\n\tprivate getHtmlNodeAttrs(domNode: Element, isComponent: boolean): string {\n\t\tlet attrsHtml = '{';\n\t\tattrsHtml += this.makeClassAttr(domNode.getAttribute('class'), isComponent);\n\n\t\tArray.from(domNode.attributes).forEach((attr) => {\n\t\t\tconst attrName = attr.name;\n\t\t\tlet attrValue = attr.value;\n\n\t\t\tif (attrName === 'data-cb') return;\n\t\t\tif (attrName === 'class') return;\n\n\t\t\t// Use JSON.stringify to properly escape newlines, quotes and other characters\n\t\t\tconst valueLiteral = JSON.stringify(attrValue);\n\n\t\t\t// Simplified logic compared to PHP which had cbt.prefixize... calls\n\t\t\t// Assuming we just output the value for now as I don't see cbt implementation here\n\t\t\t// The PHP code imported CoreBuilderTools but here we might not have it.\n\t\t\t// The user's example output imports from 'chispa'.\n\t\t\t// I will stick to simple string values for now unless I see cbt in chispa.\n\n\t\t\tif (attrName === 'style') {\n\t\t\t\t// PHP called cbt.prefixizeStyle, but also had parse_style static method.\n\t\t\t\t// Wait, the PHP code used cbt.prefixizeStyle inside get_html_node_attrs.\n\t\t\t\t// But parse_style was defined but not used in the snippet I read?\n\t\t\t\t// Ah, I should check if I should use parseStyle or just output string.\n\t\t\t\t// The PHP code: $attrs_html .= \" '$attr_name': cbt.prefixizeStyle('$attr_value'), \";\n\t\t\t\t// If cbt is a runtime helper, I should output the call.\n\t\t\t\t// But wait, the generated code imports CoreBuilderTools.\n\t\t\t\t// Does 'chispa' export CoreBuilderTools?\n\t\t\t\t// src/index.ts does NOT export CoreBuilderTools.\n\t\t\t\t// It exports appendChild, getItem, etc.\n\t\t\t\t// Maybe I should just output the string for now.\n\t\t\t\tattrsHtml += ` '${attrName}': ${valueLiteral}, `;\n\t\t\t} else {\n\t\t\t\tattrsHtml += ` '${attrName}': ${valueLiteral}, `;\n\t\t\t}\n\t\t});\n\n\t\tattrsHtml += '}';\n\t\treturn attrsHtml;\n\t}\n\n\tprivate buildTsForNode(domNode: Node, isComponent = false): string {\n\t\tlet htmlNodeCode = '';\n\n\t\tif (domNode.nodeType === 1) {\n\t\t\t// Element\n\t\t\tconst element = domNode as Element;\n\t\t\tlet tagName = element.tagName;\n\n\t\t\tif (tagName === 'svg') {\n\t\t\t\tthis.inSvgContext++;\n\t\t\t}\n\n\t\t\tlet cbid = element.getAttribute('data-cb');\n\n\t\t\tif (cbid) {\n\t\t\t\tconst currComp = this.stack[0];\n\t\t\t\telement.removeAttribute('data-cb');\n\t\t\t\tcbid = HtmlCompiler.camelize(cbid);\n\n\t\t\t\tif (!this.componentsItems[currComp]) {\n\t\t\t\t\tthis.componentsItems[currComp] = [];\n\t\t\t\t}\n\n\t\t\t\tthis.componentsItems[currComp].push(cbid);\n\t\t\t\tthis.stack.unshift(cbid);\n\t\t\t\tthis.components[cbid] = this.buildTsForNode(element, true);\n\t\t\t\tthis.componentsTags[cbid] = element.tagName;\n\t\t\t\tthis.isSvg[cbid] = this.inSvgContext > 0;\n\t\t\t\tthis.stack.shift();\n\n\t\t\t\tif (currComp === 'fragment') {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props, '${cbid}')`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `getItem(template, props.nodes, '${cbid}')`;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst attrs = this.getHtmlNodeAttrs(element, isComponent);\n\n\t\t\t\tif (!this.inSvgContext) {\n\t\t\t\t\ttagName = tagName.toLowerCase();\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElement('${tagName}');\\n`;\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode += `(() => { const node = document.createElementNS('${SVG_NAMESPACE}', '${tagName}');\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `setAttributes(node, ${attrs});\\n`;\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `setProps(node, props);\\n`;\n\t\t\t\t}\n\n\t\t\t\tlet subTs = '';\n\t\t\t\telement.childNodes.forEach((child) => {\n\t\t\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\t\t\tif (chCode) {\n\t\t\t\t\t\tsubTs += `appendChild(node, ${chCode});\\n`;\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tif (!VOID_ELEMENTS.includes(tagName.toLowerCase())) {\n\t\t\t\t\tif (isComponent) {\n\t\t\t\t\t\thtmlNodeCode += `\n if (props.inner === null) {\n node.innerHTML = '';\n } else if (props.inner !== undefined) {\n node.innerHTML = '';\n appendChild(node, props.inner);\n } else {\n ${subTs}\n }\n `;\n\t\t\t\t\t} else {\n\t\t\t\t\t\thtmlNodeCode += subTs;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (isComponent) {\n\t\t\t\t\thtmlNodeCode += `if (typeof props._ref === 'function') props._ref(node);\\n`;\n\t\t\t\t}\n\n\t\t\t\thtmlNodeCode += `return node;})()`;\n\n\t\t\t\tif (tagName === 'svg') {\n\t\t\t\t\tthis.inSvgContext--;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (domNode.nodeType === 3) {\n\t\t\t// Text\n\t\t\tconst textNode = domNode as Text;\n\t\t\tconst parent = textNode.parentNode as Element;\n\t\t\tconst parentTag = parent ? parent.tagName.toLowerCase() : '';\n\n\t\t\tconst mustOmit = ['table', 'thead', 'tbody', 'tfoot', 'tr'].includes(parentTag);\n\n\t\t\tif (!mustOmit && textNode.textContent) {\n\t\t\t\tif (textNode.textContent.trim() === '') {\n\t\t\t\t\tif (textNode.textContent.length > 0) {\n\t\t\t\t\t\thtmlNodeCode += `document.createTextNode(' ')`;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\thtmlNodeCode = `document.createTextNode(${JSON.stringify(textNode.textContent)})`;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn htmlNodeCode.trim();\n\t}\n\n\tprivate static getPropsTypename(cbid: string): string {\n\t\treturn 'Cb' + cbid.charAt(0).toUpperCase() + cbid.slice(1) + 'Props';\n\t}\n\n\tprivate wrapFnComponent(cbid: string, jsx: string): string {\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\treturn `(props: ${typename}) => { \\n return(${jsx}); \\n }`;\n\t}\n\n\tprivate createAllComponents() {\n\t\tconst body = this.htmlDocument.querySelector('body');\n\t\tif (!body) throw new Error('Not valid HTML');\n\n\t\tlet rendererJsx = '(() => { const fragment = document.createDocumentFragment();\\n';\n\n\t\tbody.childNodes.forEach((child) => {\n\t\t\tconst chCode = this.buildTsForNode(child);\n\t\t\tif (chCode) {\n\t\t\t\trendererJsx += `appendChild(fragment, ${chCode});\\n`;\n\t\t\t}\n\t\t});\n\n\t\trendererJsx += 'return fragment;\\n';\n\t\trendererJsx += '})()';\n\n\t\tthis.components['fragment'] = rendererJsx;\n\t}\n\n\tprivate getTypedef(cbid: string): string {\n\t\tconst items = this.componentsItems[cbid] || [];\n\t\tlet itemsType = '{\\n';\n\t\titems.forEach((itemCbid) => {\n\t\t\tconst itemTypename = HtmlCompiler.getPropsTypename(itemCbid);\n\t\t\titemsType += `${itemCbid}?: ${itemTypename} | ChispaContentReactive;\\n`;\n\t\t});\n\t\titemsType += '}\\n';\n\n\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\n\t\tif (cbid === 'fragment') {\n\t\t\treturn `interface ${typename} ${itemsType}`;\n\t\t} else {\n\t\t\tconst tagname = this.componentsTags[cbid];\n\t\t\tif (this.isSvg[cbid]) {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderPropsReactive<SVGElementTagNameMap['${tagname}'], ${itemsType}>;`;\n\t\t\t} else {\n\t\t\t\treturn `type ${typename} = ChispaNodeBuilderPropsReactive<HTMLElementTagNameMap['${tagname.toLowerCase()}'], ${itemsType}>;`;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async compile(): Promise<{ ts: string; dts: string }> {\n\t\tthis.createAllComponents();\n\n\t\tlet componentsClasses = '';\n\t\tlet typedefs = '';\n\n\t\tfor (const [cbid, compJsx] of Object.entries(this.components)) {\n\t\t\ttypedefs += this.getTypedef(cbid) + '\\n';\n\t\t\tcomponentsClasses += `${cbid}: ${this.wrapFnComponent(cbid, compJsx)},\\n`;\n\t\t}\n\n\t\tconst jsOutput = `\n import { appendChild, getItem, setAttributes, setProps } from 'chispa';\n import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';\n\t\t\t\n const SVG_NS = 'http://www.w3.org/2000/svg';\n \n const template = {\n ${componentsClasses}\n };\n \n export default template;\n `;\n\n\t\tconst dtsOutput = `\n import type { ChispaContentReactive, ChispaNodeBuilderPropsReactive } from 'chispa';\n \n ${typedefs}\n \n declare const template: {\n ${Object.keys(this.components)\n\t\t\t\t\t.map((cbid) => {\n\t\t\t\t\t\tconst typename = HtmlCompiler.getPropsTypename(cbid);\n\t\t\t\t\t\treturn `${cbid}: (props: ${typename}) => Node | DocumentFragment;`;\n\t\t\t\t\t})\n\t\t\t\t\t.join('\\n')}\n };\n \n export default template;\n `;\n\n\t\tconst prettierOptions = {\n\t\t\tparser: 'typescript',\n\t\t\tsemi: true,\n\t\t\tsingleQuote: true,\n\t\t\tuseTabs: true,\n\t\t\tprintWidth: 120,\n\t\t};\n\n\t\treturn {\n\t\t\tts: await format(jsOutput, prettierOptions),\n\t\t\tdts: await format(dtsOutput, prettierOptions),\n\t\t};\n\t}\n}\n","import * as fs from 'fs';\nimport * as path from 'path';\nimport { HtmlCompiler } from './html-compiler';\n\nexport async function generateTypes(filePath: string, content: string, rootDir: string) {\n\ttry {\n\t\tconst compiler = new HtmlCompiler(content);\n\t\tconst { dts } = await compiler.compile();\n\n\t\tconst outDir = path.join(rootDir, '.chispa/types');\n\t\tconst relativePath = path.relative(rootDir, filePath);\n\t\tconst targetPath = path.join(outDir, relativePath + '.d.ts');\n\t\tconst targetDir = path.dirname(targetPath);\n\n\t\tif (!fs.existsSync(targetDir)) {\n\t\t\tfs.mkdirSync(targetDir, { recursive: true });\n\t\t}\n\t\tfs.writeFileSync(targetPath, dts);\n\t} catch (e) {\n\t\tconsole.error(`[chispa] Error generating types for ${filePath}`, e);\n\t}\n}\n\nexport async function findAndCompileHtmlFiles(dir: string, rootDir: string) {\n\tif (!fs.existsSync(dir)) return;\n\tconst files = fs.readdirSync(dir);\n\tfor (const file of files) {\n\t\tconst fullPath = path.join(dir, file);\n\t\tif (fullPath === path.join(rootDir, 'index.html')) continue;\n\t\tif (fs.statSync(fullPath).isDirectory()) {\n\t\t\tif (file !== 'node_modules' && file !== '.git' && file !== 'dist' && file !== '.chispa') {\n\t\t\t\tawait findAndCompileHtmlFiles(fullPath, rootDir);\n\t\t\t}\n\t\t} else if (file.endsWith('.html')) {\n\t\t\tconsole.log('Generating types for', fullPath);\n\t\t\tconst content = fs.readFileSync(fullPath, 'utf-8');\n\t\t\tawait generateTypes(fullPath, content, rootDir);\n\t\t}\n\t}\n}\n","import { HtmlCompiler } from './html-compiler';\nimport { generateTypes, findAndCompileHtmlFiles } from './generator';\nimport { type Plugin, transformWithEsbuild } from 'vite';\nimport * as fs from 'fs';\n\n/**\n * Convierte una ruta real de archivo en el ID de módulo virtual que usa Vite/Rollup.\n * Añade el prefijo `\\0` para marcar el módulo como virtual y el sufijo\n * `.chispa.ts` para que sea tratado como módulo TypeScript.\n */\nconst toVirtualId = (id: string) => '\\0' + id + '.chispa.ts';\n\n/**\n * Convierte un ID de módulo virtual de vuelta a la ruta real del archivo.\n * Elimina el prefijo `\\0` (si existe) y el sufijo `.chispa.ts`.\n */\nconst fromVirtualId = (id: string) => id.replace(/^\\0/, '').replace('.chispa.ts', '');\n\nexport function chispaHtmlPlugin(): Plugin {\n\tlet rootDir = process.cwd();\n\n\treturn {\n\t\tname: 'chispa-html',\n\t\tenforce: 'pre',\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync buildStart() {\n\t\t\tawait findAndCompileHtmlFiles(rootDir, rootDir);\n\t\t},\n\t\tasync handleHotUpdate(ctx) {\n\t\t\tif (ctx.file.endsWith('.html')) {\n\t\t\t\tconst content = await ctx.read();\n\t\t\t\tawait generateTypes(ctx.file, content, rootDir);\n\n\t\t\t\t// Buscamos el módulo virtual asociado al archivo HTML modificado.\n\t\t\t\tconst module = ctx.server.moduleGraph.getModuleById(toVirtualId(ctx.file));\n\t\t\t\tif (module) {\n\t\t\t\t\treturn [module];\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tasync resolveId(source, importer, options) {\n\t\t\tif (source.endsWith('.html.chispa.ts')) {\n\t\t\t\treturn source;\n\t\t\t}\n\t\t\tif (source.endsWith('.html') && importer) {\n\t\t\t\tconst resolution = await this.resolve(source, importer, { skipSelf: true, ...options });\n\t\t\t\tif (resolution && !resolution.external) {\n\t\t\t\t\treturn toVirtualId(resolution.id);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn null;\n\t\t},\n\t\tasync load(id) {\n\t\t\tif (id.endsWith('.html.chispa.ts')) {\n\t\t\t\tconst realId = fromVirtualId(id);\n\t\t\t\ttry {\n\t\t\t\t\tconst content = fs.readFileSync(realId, 'utf-8');\n\t\t\t\t\tif (content.includes('<!DOCTYPE html>') || content.includes('<html')) {\n\t\t\t\t\t\treturn 'export default {};';\n\t\t\t\t\t}\n\n\t\t\t\t\tconst compiler = new HtmlCompiler(content);\n\t\t\t\t\tconst { ts } = await compiler.compile();\n\t\t\t\t\tgenerateTypes(realId, content, rootDir);\n\n\t\t\t\t\tconst result = await transformWithEsbuild(ts, realId, {\n\t\t\t\t\t\tloader: 'ts',\n\t\t\t\t\t});\n\t\t\t\t\treturn result.code;\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error(`[chispa] Error loading ${id}:`, e);\n\t\t\t\t\tthrow e;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,cAAc;AAEvB,IAAM,gBAAgB,CAAC,QAAQ,QAAQ,MAAM,MAAM,OAAO,SAAS,QAAQ,QAAQ,SAAS,UAAU,QAAQ;AAE9G,IAAM,gBAAgB;AAEf,IAAM,eAAN,MAAM,cAAa;AAAA,EACjB,aAAqC,CAAC;AAAA,EACtC,QAAkB,CAAC,UAAU;AAAA,EAC7B,kBAA4C,CAAC;AAAA,EAC7C,iBAAyC,CAAC;AAAA,EAC1C,QAAiC,CAAC;AAAA,EAClC,eAAe;AAAA,EACf;AAAA,EAER,YAAY,aAAqB;AAChC,UAAM,MAAM,IAAI,MAAM,WAAW;AACjC,SAAK,eAAe,IAAI,OAAO;AAAA,EAChC;AAAA,EAEA,OAAe,SAAS,KAAqB;AAC5C,QAAI,IAAI,WAAW,IAAI,GAAG;AACzB,aAAO;AAAA,IACR;AACA,UAAM,MAAM,IAAI,MAAM,GAAG;AACzB,QAAI,YAAY;AAChB,QAAI,QAAQ,CAAC,GAAG,MAAM;AACrB,mBAAa,MAAM,IAAI,IAAI,EAAE,O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AAU,EAAE,UAAU,MAAM,GAAG,QAAQ,CAAC;AACtF,YAAI,cAAc,CAAC,WAAW,UAAU;AACvC,iBAAO,YAAY,WAAW,EAAE;AAAA,QACjC;AAAA,MACD;AACA,aAAO;AAAA,IACR;AAAA,IACA,MAAM,KAAK,IAAI;AACd,UAAI,GAAG,SAAS,iBAAiB,GAAG;AACnC,cAAM,SAAS,cAAc,EAAE;AAC/B,YAAI;AACH,gBAAM,UAAa,iBAAa,QAAQ,OAAO;AAC/C,cAAI,QAAQ,SAAS,iBAAiB,KAAK,QAAQ,SAAS,OAAO,GAAG;AACrE,mBAAO;AAAA,UACR;AAEA,gBAAM,WAAW,IAAI,aAAa,OAAO;AACzC,gBAAM,EAAE,GAAG,IAAI,MAAM,SAAS,QAAQ;AACtC,wBAAc,QAAQ,SAAS,OAAO;AAEtC,gBAAM,SAAS,MAAM,qBAAqB,IAAI,QAAQ;AAAA,YACrD,QAAQ;AAAA,UACT,CAAC;AACD,iBAAO,OAAO;AAAA,QACf,SAAS,GAAG;AACX,kBAAQ,MAAM,0BAA0B,EAAE,KAAK,CAAC;AAChD,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;","names":["fs"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,22 +10,25 @@ type AllowSignals<T> = {
|
|
|
10
10
|
[K in keyof T]: T[K] | Signal<T[K]>;
|
|
11
11
|
};
|
|
12
12
|
type ChispaNodeBuilderBaseProps<T> = AllowSignals<Omit<Partial<T>, 'style' | 'dataset'>>;
|
|
13
|
-
interface
|
|
13
|
+
interface INodeBuilderSpecialProps {
|
|
14
14
|
addClass?: ChispaReactive<string>;
|
|
15
15
|
classes?: ChispaClasses;
|
|
16
|
-
nodes?: TNodes;
|
|
17
|
-
inner?: ChispaContentReactive;
|
|
18
16
|
style?: ChispaCSSPropertiesStrings;
|
|
19
17
|
dataset?: Record<string, ChispaReactive<string>>;
|
|
18
|
+
}
|
|
19
|
+
interface INodeBuilderAdditionalProps<T, TNodes> {
|
|
20
|
+
nodes?: TNodes;
|
|
21
|
+
inner?: ChispaContentReactive;
|
|
20
22
|
_ref?: (node: T) => void | {
|
|
21
23
|
current: T | null;
|
|
22
24
|
};
|
|
23
25
|
}
|
|
24
|
-
type ChispaNodeBuilderProps<T, TNodes> = ChispaNodeBuilderBaseProps<T> & INodeBuilderAdditionalProps<T, TNodes
|
|
25
|
-
|
|
26
|
+
type ChispaNodeBuilderProps<T, TNodes> = ChispaNodeBuilderBaseProps<T> & INodeBuilderAdditionalProps<T, TNodes> & INodeBuilderSpecialProps;
|
|
27
|
+
type ChispaNodeBuilderPropsReactive<T, TNodes> = ChispaReactive<ChispaNodeBuilderProps<T, TNodes>>;
|
|
28
|
+
declare function getValidProps<T>(props: ChispaNodeBuilderProps<T, any>): ChispaNodeBuilderProps<T, any>;
|
|
26
29
|
declare function getItem<T>(template: T, items: any, itemName: keyof T): any;
|
|
27
30
|
declare function setAttributes(node: Element, attributes: Record<string, string>): void;
|
|
28
|
-
declare function setProps<T extends Element>(node: T, props:
|
|
31
|
+
declare function setProps<T extends Element>(node: T, props: ChispaNodeBuilderPropsReactive<T, any>): void;
|
|
29
32
|
declare function appendChild(node: Element | DocumentFragment, child: ChispaContentReactive): void;
|
|
30
33
|
|
|
31
34
|
type Dict = Record<string, any>;
|
|
@@ -106,6 +109,7 @@ declare class AppContext {
|
|
|
106
109
|
setCurrentReactivityContext(context: Reactivity): void;
|
|
107
110
|
restorePreviousReactivityContext(): void;
|
|
108
111
|
getCurrentRenderContext(): Reactivity | null;
|
|
112
|
+
maxScheduleIterations: number;
|
|
109
113
|
scheduleRefresh(): void;
|
|
110
114
|
addReactivity(executor: () => void): Reactivity;
|
|
111
115
|
createRoot(component: () => Component, mountPoint: HTMLElement): void;
|
|
@@ -152,6 +156,7 @@ declare function isSignal(value: any): value is Signal<any>;
|
|
|
152
156
|
declare function isWriteableSignal<T>(value: Signal<T>): value is WritableSignal<T>;
|
|
153
157
|
declare function signal<T>(initialValue: T): WritableSignal<T>;
|
|
154
158
|
declare function computed<T>(fn: () => T): Signal<T>;
|
|
159
|
+
declare function effect(fn: () => void): void;
|
|
155
160
|
|
|
156
161
|
interface ControlledInputOptions {
|
|
157
162
|
/**
|
|
@@ -165,7 +170,12 @@ interface ControlledInputOptions {
|
|
|
165
170
|
*/
|
|
166
171
|
validate?: (value: string) => boolean;
|
|
167
172
|
}
|
|
173
|
+
interface SelectOption {
|
|
174
|
+
value: string;
|
|
175
|
+
label: string;
|
|
176
|
+
}
|
|
168
177
|
declare function bindControlledInput(element: HTMLInputElement | HTMLTextAreaElement, signal: WritableSignal<string>, options?: ControlledInputOptions): () => void;
|
|
178
|
+
declare function bindControlledSelect(element: HTMLSelectElement, signal: WritableSignal<string>, optionsSignal?: Signal<SelectOption[]>): () => void;
|
|
169
179
|
|
|
170
180
|
interface Route {
|
|
171
181
|
path: string;
|
|
@@ -183,4 +193,4 @@ interface LinkProps extends ChispaNodeBuilderProps<HTMLAnchorElement, {}> {
|
|
|
183
193
|
}
|
|
184
194
|
declare const Link: (props: LinkProps) => Component<LinkProps>;
|
|
185
195
|
|
|
186
|
-
export { type ChispaContent, type ChispaContentReactive, type ChispaNodeBuilderProps, Link, type LinkProps, type Route, Router, Signal, WritableSignal, appendChild, bindControlledInput, component, componentList, computed, getItem, getValidProps, globalContext, isSignal, isWriteableSignal, navigate, onUnmount, pathMatches, setAttributes, setProps, signal };
|
|
196
|
+
export { type ChispaContent, type ChispaContentReactive, type ChispaNodeBuilderProps, type ChispaNodeBuilderPropsReactive, type ChispaReactive, Link, type LinkProps, type Route, Router, type SelectOption, Signal, WritableSignal, appendChild, bindControlledInput, bindControlledSelect, component, componentList, computed, effect, getItem, getValidProps, globalContext, isSignal, isWriteableSignal, navigate, onUnmount, pathMatches, setAttributes, setProps, signal };
|
package/dist/index.js
CHANGED
|
@@ -30,13 +30,26 @@ var AppContext = class {
|
|
|
30
30
|
}
|
|
31
31
|
return this.reactivityContextStack[this.reactivityContextStack.length - 1];
|
|
32
32
|
}
|
|
33
|
+
// Maximum number of iterations to process during a scheduled refresh. Prevents
|
|
34
|
+
// unbounded loops in case of uncontrolled reactivity cascades. Use the
|
|
35
|
+
// `globalContext.maxScheduleIterations` field to override in tests or
|
|
36
|
+
// special cases.
|
|
37
|
+
maxScheduleIterations = 100;
|
|
33
38
|
scheduleRefresh() {
|
|
34
39
|
if (this.refreshTimeout) {
|
|
35
40
|
clearTimeout(this.refreshTimeout);
|
|
36
41
|
}
|
|
37
42
|
this.refreshTimeout = setTimeout(() => {
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
let iteration = 0;
|
|
44
|
+
while (this.dirtyReactivities.size > 0 && iteration < this.maxScheduleIterations) {
|
|
45
|
+
iteration++;
|
|
46
|
+
const dirtyContexts = Array.from(this.dirtyReactivities);
|
|
47
|
+
dirtyContexts.forEach((ctx) => ctx.process());
|
|
48
|
+
}
|
|
49
|
+
if (this.dirtyReactivities.size > 0) {
|
|
50
|
+
console.warn(`[AppContext.scheduleRefresh] possible uncontrolled reactivity cascade: processed ${iteration} iterations \u2014 aborting.`);
|
|
51
|
+
this.dirtyReactivities.clear();
|
|
52
|
+
}
|
|
40
53
|
}, 0);
|
|
41
54
|
}
|
|
42
55
|
addReactivity(executor) {
|
|
@@ -206,6 +219,9 @@ function computed(fn) {
|
|
|
206
219
|
globalContext.restorePreviousReactivityContext();
|
|
207
220
|
return sig;
|
|
208
221
|
}
|
|
222
|
+
function effect(fn) {
|
|
223
|
+
globalContext.addReactivity(fn);
|
|
224
|
+
}
|
|
209
225
|
|
|
210
226
|
// src/components.ts
|
|
211
227
|
var Component = class {
|
|
@@ -462,100 +478,114 @@ function setAttributes(node, attributes) {
|
|
|
462
478
|
}
|
|
463
479
|
}
|
|
464
480
|
function setProps(node, props) {
|
|
481
|
+
let _props = props;
|
|
482
|
+
if (typeof _props === "function") {
|
|
483
|
+
_props = computed(_props);
|
|
484
|
+
}
|
|
485
|
+
if (isSignal(_props)) {
|
|
486
|
+
globalContext.addReactivity(() => {
|
|
487
|
+
setProps(node, _props.get());
|
|
488
|
+
});
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
props = getValidProps(_props);
|
|
465
492
|
if (node instanceof HTMLElement) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
node.style[styleKey] = styleValue;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
delete props.style;
|
|
493
|
+
setSpecialProps(node, props);
|
|
494
|
+
}
|
|
495
|
+
for (const prop in props) {
|
|
496
|
+
const propValue = props[prop];
|
|
497
|
+
if (isSignal(propValue)) {
|
|
498
|
+
globalContext.addReactivity(() => {
|
|
499
|
+
node[prop] = propValue.get();
|
|
500
|
+
});
|
|
501
|
+
} else if (propValue === void 0) {
|
|
502
|
+
continue;
|
|
503
|
+
} else {
|
|
504
|
+
node[prop] = propValue;
|
|
482
505
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
function setSpecialProps(node, props) {
|
|
509
|
+
if (props.style !== void 0) {
|
|
510
|
+
const style = props.style;
|
|
511
|
+
for (const styleKey in style) {
|
|
512
|
+
let styleValue = style[styleKey];
|
|
513
|
+
if (typeof styleValue === "function") {
|
|
514
|
+
styleValue = computed(styleValue);
|
|
488
515
|
}
|
|
489
|
-
if (isSignal(
|
|
516
|
+
if (isSignal(styleValue)) {
|
|
490
517
|
globalContext.addReactivity(() => {
|
|
491
|
-
|
|
492
|
-
if (cls !== prevClass) {
|
|
493
|
-
if (prevClass) {
|
|
494
|
-
node.classList.remove(prevClass);
|
|
495
|
-
}
|
|
496
|
-
node.classList.add(cls);
|
|
497
|
-
}
|
|
498
|
-
prevClass = cls;
|
|
518
|
+
node.style[styleKey] = styleValue.get();
|
|
499
519
|
});
|
|
500
520
|
} else {
|
|
501
|
-
node.
|
|
521
|
+
node.style[styleKey] = styleValue;
|
|
502
522
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
523
|
+
}
|
|
524
|
+
delete props.style;
|
|
525
|
+
}
|
|
526
|
+
if (props.addClass !== void 0) {
|
|
527
|
+
let addClass = props.addClass;
|
|
528
|
+
let prevClass = null;
|
|
529
|
+
if (typeof addClass === "function") {
|
|
530
|
+
addClass = computed(addClass);
|
|
531
|
+
}
|
|
532
|
+
if (isSignal(addClass)) {
|
|
533
|
+
globalContext.addReactivity(() => {
|
|
534
|
+
const cls = addClass.get();
|
|
535
|
+
if (cls !== prevClass) {
|
|
536
|
+
if (prevClass) {
|
|
537
|
+
node.classList.remove(prevClass);
|
|
538
|
+
}
|
|
539
|
+
node.classList.add(cls);
|
|
511
540
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
541
|
+
prevClass = cls;
|
|
542
|
+
});
|
|
543
|
+
} else {
|
|
544
|
+
node.classList.add(addClass);
|
|
545
|
+
}
|
|
546
|
+
delete props.addClass;
|
|
547
|
+
}
|
|
548
|
+
if (props.classes !== void 0) {
|
|
549
|
+
const classes = props.classes;
|
|
550
|
+
for (const className in classes) {
|
|
551
|
+
let apply = classes[className];
|
|
552
|
+
if (typeof apply === "function") {
|
|
553
|
+
apply = computed(apply);
|
|
554
|
+
}
|
|
555
|
+
if (isSignal(apply)) {
|
|
556
|
+
globalContext.addReactivity(() => {
|
|
557
|
+
if (apply.get()) {
|
|
522
558
|
node.classList.add(className);
|
|
523
559
|
} else {
|
|
524
560
|
node.classList.remove(className);
|
|
525
561
|
}
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
if (props.dataset !== void 0) {
|
|
531
|
-
const dataset = props.dataset;
|
|
532
|
-
for (const datasetKey in dataset) {
|
|
533
|
-
let ds = dataset[datasetKey];
|
|
534
|
-
if (typeof ds === "function") {
|
|
535
|
-
ds = computed(ds);
|
|
536
|
-
}
|
|
537
|
-
if (isSignal(ds)) {
|
|
538
|
-
globalContext.addReactivity(() => {
|
|
539
|
-
node.dataset[datasetKey] = ds.get();
|
|
540
|
-
});
|
|
562
|
+
});
|
|
563
|
+
} else {
|
|
564
|
+
if (classes[className]) {
|
|
565
|
+
node.classList.add(className);
|
|
541
566
|
} else {
|
|
542
|
-
node.
|
|
567
|
+
node.classList.remove(className);
|
|
543
568
|
}
|
|
544
569
|
}
|
|
545
|
-
delete props.dataset;
|
|
546
570
|
}
|
|
571
|
+
delete props.classes;
|
|
547
572
|
}
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
573
|
+
if (props.dataset !== void 0) {
|
|
574
|
+
const dataset = props.dataset;
|
|
575
|
+
for (const datasetKey in dataset) {
|
|
576
|
+
let ds = dataset[datasetKey];
|
|
577
|
+
if (typeof ds === "function") {
|
|
578
|
+
ds = computed(ds);
|
|
579
|
+
}
|
|
580
|
+
if (isSignal(ds)) {
|
|
581
|
+
globalContext.addReactivity(() => {
|
|
582
|
+
node.dataset[datasetKey] = ds.get();
|
|
583
|
+
});
|
|
584
|
+
} else {
|
|
585
|
+
node.dataset[datasetKey] = ds;
|
|
586
|
+
}
|
|
558
587
|
}
|
|
588
|
+
delete props.dataset;
|
|
559
589
|
}
|
|
560
590
|
}
|
|
561
591
|
function appendChild(node, child) {
|
|
@@ -671,6 +701,48 @@ function bindControlledInput(element, signal2, options = {}) {
|
|
|
671
701
|
element.removeEventListener("input", handleInput);
|
|
672
702
|
};
|
|
673
703
|
}
|
|
704
|
+
function bindControlledSelect(element, signal2, optionsSignal) {
|
|
705
|
+
const updateOptions = (options) => {
|
|
706
|
+
element.innerHTML = "";
|
|
707
|
+
options.forEach((option) => {
|
|
708
|
+
const optElement = document.createElement("option");
|
|
709
|
+
optElement.value = option.value;
|
|
710
|
+
optElement.textContent = option.label;
|
|
711
|
+
element.appendChild(optElement);
|
|
712
|
+
});
|
|
713
|
+
element.value = signal2.get();
|
|
714
|
+
};
|
|
715
|
+
if (optionsSignal) {
|
|
716
|
+
updateOptions(optionsSignal.get());
|
|
717
|
+
}
|
|
718
|
+
element.value = signal2.initialValue;
|
|
719
|
+
const handleChange = (e) => {
|
|
720
|
+
const target = e.target;
|
|
721
|
+
let newValue = target.value;
|
|
722
|
+
const originalValue = signal2.get();
|
|
723
|
+
if (newValue !== originalValue) {
|
|
724
|
+
signal2.set(newValue);
|
|
725
|
+
}
|
|
726
|
+
if (target.value !== newValue) {
|
|
727
|
+
target.value = newValue;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
element.addEventListener("change", handleChange);
|
|
731
|
+
globalContext.addReactivity(() => {
|
|
732
|
+
const newValue = signal2.get();
|
|
733
|
+
if (element.value !== newValue) {
|
|
734
|
+
element.value = newValue;
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
if (optionsSignal) {
|
|
738
|
+
globalContext.addReactivity(() => {
|
|
739
|
+
updateOptions(optionsSignal.get());
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
return () => {
|
|
743
|
+
element.removeEventListener("change", handleChange);
|
|
744
|
+
};
|
|
745
|
+
}
|
|
674
746
|
|
|
675
747
|
// src/router.ts
|
|
676
748
|
var currentPath = signal(typeof window !== "undefined" ? window.location.pathname : "/");
|
|
@@ -750,9 +822,11 @@ export {
|
|
|
750
822
|
Router,
|
|
751
823
|
appendChild,
|
|
752
824
|
bindControlledInput,
|
|
825
|
+
bindControlledSelect,
|
|
753
826
|
component,
|
|
754
827
|
componentList,
|
|
755
828
|
computed,
|
|
829
|
+
effect,
|
|
756
830
|
getItem,
|
|
757
831
|
getValidProps,
|
|
758
832
|
globalContext,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context.ts","../src/signals.ts","../src/components.ts","../src/builder.ts","../src/controlled-input.ts","../src/router.ts"],"sourcesContent":["import { Component, ComponentList } from './components';\nimport { Signal } from './signals';\n\ntype ExecutionKind = 'createComponent' | 'computed' | 'addReactivity';\n\nexport interface IDisposable {\n\tdispose: () => void;\n}\n\nclass AppContext {\n\tprivate reactivityContextStack: Reactivity[] = [];\n\n\tprivate refreshTimeout: any = 0;\n\n\t//private contexts = new Set<RenderContext>();\n\n\tprivate dirtyReactivities = new Set<Reactivity>();\n\n\tprivate executionStack: ExecutionKind[] = [];\n\n\tprivate componentStack: (Component | ComponentList)[] = [];\n\n\tpushComponentStack(cmp: Component | ComponentList) {\n\t\tthis.componentStack.push(cmp);\n\t}\n\n\tpopComponentStack() {\n\t\tthis.componentStack.pop();\n\t}\n\n\tgetCurrentComponent() {\n\t\tif (this.componentStack.length === 0) {\n\t\t\t//console.warn('No current component');\n\t\t\treturn null;\n\t\t}\n\t\treturn this.componentStack[this.componentStack.length - 1];\n\t}\n\n\tsetCurrentReactivityContext(context: Reactivity) {\n\t\tthis.reactivityContextStack.push(context);\n\t\t//this.contexts.add(context);\n\t}\n\n\trestorePreviousReactivityContext() {\n\t\tthis.reactivityContextStack.pop();\n\t}\n\n\tgetCurrentRenderContext() {\n\t\tif (this.reactivityContextStack.length === 0) {\n\t\t\t//console.warn('No current render context');\n\t\t\treturn null;\n\t\t}\n\t\treturn this.reactivityContextStack[this.reactivityContextStack.length - 1];\n\t}\n\n\tscheduleRefresh() {\n\t\tif (this.refreshTimeout) {\n\t\t\tclearTimeout(this.refreshTimeout);\n\t\t}\n\t\tthis.refreshTimeout = setTimeout(() => {\n\t\t\tconst dirtyContexts = Array.from(this.dirtyReactivities);\n\t\t\tdirtyContexts.forEach((ctx) => ctx.process());\n\t\t}, 0);\n\t}\n\n\taddReactivity(executor: () => void) {\n\t\tconst ctx = new Reactivity(executor);\n\t\tglobalContext.pushExecutionStack('addReactivity');\n\t\tctx.exec();\n\t\tglobalContext.popExecutionStack();\n\t\treturn ctx;\n\t}\n\n\tcreateRoot(component: () => Component, mountPoint: HTMLElement) {\n\t\tthis.dirtyReactivities.clear();\n\t\tmountPoint.innerHTML = '';\n\t\tconst cmp = component();\n\t\tcmp.mount(mountPoint, null);\n\t}\n\n\tcanReadSignal() {\n\t\tconst length = this.executionStack.length;\n\t\tif (length === 0) return true;\n\t\tconst current = this.executionStack[length - 1];\n\t\treturn current !== 'createComponent';\n\t}\n\n\tpushExecutionStack(type: ExecutionKind) {\n\t\tthis.executionStack.push(type);\n\t}\n\n\tpopExecutionStack() {\n\t\tthis.executionStack.pop();\n\t}\n\n\taddDirtyContext(ctx: Reactivity) {\n\t\tthis.dirtyReactivities.add(ctx);\n\t}\n\n\tremoveDirtyContext(ctx: Reactivity) {\n\t\tthis.dirtyReactivities.delete(ctx);\n\t}\n}\n\nexport class Reactivity implements IDisposable {\n\tprivate dirty: boolean = false;\n\n\tprivate signals = new Set<Signal<any>>();\n\n\tconstructor(private readonly action: () => void) {\n\t\tconst currentComponent = globalContext.getCurrentComponent();\n\t\tif (currentComponent) {\n\t\t\tcurrentComponent.addDisposable(this);\n\t\t} else {\n\t\t\tconsole.warn('Creating a Reactivity outside of a component');\n\t\t}\n\t}\n\n\tmarkDirty() {\n\t\t// Mark the context as dirty (needing re-render)\n\t\t//console.log('marking context as dirty');\n\t\tthis.dirty = true;\n\t\tglobalContext.addDirtyContext(this);\n\t\tglobalContext.scheduleRefresh();\n\t}\n\n\taddSignal(signal: Signal<any>) {\n\t\tthis.signals.add(signal);\n\t}\n\n\tremoveSignal(signal: Signal<any>) {\n\t\tthis.signals.delete(signal);\n\t}\n\n\tprocess() {\n\t\tif (!this.dirty) return;\n\t\tthis.exec();\n\t\t//console.log('re-render cycle completed');\n\t\tthis.dirty = false;\n\t\tglobalContext.removeDirtyContext(this);\n\t}\n\n\texec() {\n\t\tthis.signals.forEach((s) => s.removeContext(this));\n\t\tthis.signals.clear();\n\t\tglobalContext.setCurrentReactivityContext(this);\n\t\tthis.action();\n\t\tglobalContext.restorePreviousReactivityContext();\n\t}\n\n\tdispose() {\n\t\tthis.signals.forEach((s) => s.removeContext(this));\n\t\tthis.signals.clear();\n\t\tthis.dirty = false;\n\t\tglobalContext.removeDirtyContext(this);\n\t}\n}\n\nexport const globalContext = new AppContext();\n","import { globalContext, Reactivity } from './context';\n\ntype WithSignals<T> = { [K in keyof T]: Signal<T[K]> };\n\nabstract class Signal<T> {\n\tprotected abstract value: T;\n\n\tprotected contexts: Set<Reactivity> = new Set();\n\n\tconstructor() {}\n\n\tget() {\n\t\tif (!globalContext.canReadSignal()) {\n\t\t\tthrow new Error('Cannot read a signal value during component creation. Did you mean to use a computed signal instead?');\n\t\t}\n\t\t//context.current.register(this);\n\t\tconst ctx = globalContext.getCurrentRenderContext();\n\t\tif (ctx) {\n\t\t\tthis.contexts.add(ctx);\n\t\t\tctx.addSignal(this);\n\t\t}\n\t\treturn this.value;\n\t}\n\n\tpublic readonly computed = new Proxy(\n\t\t{},\n\t\t{\n\t\t\tget: (_, prop) => {\n\t\t\t\treturn computed(() => this.get()[prop as keyof T]);\n\t\t\t},\n\t\t}\n\t) as WithSignals<T>;\n\n\tremoveContext(ctx: Reactivity) {\n\t\tthis.contexts.delete(ctx);\n\t}\n\n\tdispose() {\n\t\tconsole.log('disposing signal', this);\n\t\tthis.contexts.forEach((ctx) => {\n\t\t\tctx.removeSignal(this);\n\t\t});\n\t\tthis.contexts.clear();\n\t}\n}\n\nclass WritableSignal<T> extends Signal<T> {\n\tprotected override value: T;\n\n\tpublic readonly initialValue: T;\n\n\tconstructor(initialValue: T) {\n\t\tsuper();\n\t\tthis.initialValue = initialValue;\n\t\tthis.value = initialValue;\n\t}\n\n\tset(newValue: T) {\n\t\tthis.value = newValue;\n\t\tthis.contexts.forEach((ctx) => ctx.markDirty());\n\t}\n\n\tupdate(updater: (value: T) => T) {\n\t\tthis.value = updater(this.value);\n\t\tthis.contexts.forEach((ctx) => ctx.markDirty());\n\t}\n}\n\nclass ComputedSignal<T> extends Signal<T> {\n\tprotected override value: T;\n\n\tprivate computeFn: () => T;\n\n\tconstructor(computeFn: () => T) {\n\t\tsuper();\n\t\tglobalContext.pushExecutionStack('computed');\n\t\tthis.value = computeFn();\n\t\tglobalContext.popExecutionStack();\n\t\tthis.computeFn = computeFn;\n\t}\n\n\trecompute() {\n\t\tconst newValue = this.computeFn();\n\t\tif (newValue !== this.value) {\n\t\t\tthis.value = newValue;\n\t\t\tthis.contexts.forEach((ctx) => ctx.markDirty());\n\t\t}\n\t}\n}\n\nexport function isSignal(value: any): value is Signal<any> {\n\treturn value instanceof Signal;\n}\n\nexport function isWriteableSignal<T>(value: Signal<T>): value is WritableSignal<T> {\n\treturn value instanceof WritableSignal;\n}\n\nexport function signal<T>(initialValue: T) {\n\tconst sig = new WritableSignal(initialValue);\n\n\t// // Creamos una función que se usará como callable\n\t// const fn = (() => sig.get()) as any;\n\n\t// // Copiamos todas las propiedades y métodos de la instancia a la función\n\t// Object.setPrototypeOf(fn, sig.constructor.prototype);\n\n\t// // Copiamos las propiedades de instancia\n\t// Object.assign(fn, this);\n\n\t// // Retornamos la función como si fuera la instancia\n\t// return fn as WritableSignal<T> & (() => T);\n\n\treturn sig;\n}\n\nexport function computed<T>(fn: () => T) {\n\tlet sig: ComputedSignal<T>;\n\tconst ctx = new Reactivity(() => {\n\t\tsig.recompute();\n\t});\n\tglobalContext.setCurrentReactivityContext(ctx);\n\tsig = new ComputedSignal(fn);\n\tglobalContext.restorePreviousReactivityContext();\n\n\treturn sig as Signal<T>;\n}\n\nexport function effect(fn: () => void) {\n\tglobalContext.addReactivity(fn);\n}\n\nexport type { Signal, WritableSignal };\n","import { ChispaContent } from './builder';\nimport { globalContext, IDisposable } from './context';\nimport { computed, Signal, WritableSignal } from './signals';\n\nexport type Dict = Record<string, any>;\nexport type ComponentFactory<TProps extends Dict> = (props: TProps) => ChispaContent;\n\nexport class Component<TProps extends Dict = any> {\n\tpublic nodes: Node[] | null = null;\n\n\tprivate container: Node | null = null;\n\n\tprivate anchor: Node | null = null;\n\n\tprivate disposables: IDisposable[] = [];\n\n\tpublic silent = true;\n\n\tconstructor(\n\t\tprivate readonly factoryFn: ComponentFactory<TProps>,\n\t\tpublic readonly key: any = null,\n\t\tpublic readonly props: TProps | null = null\n\t) {}\n\n\tmount(container: Node, anchor: Node | null = null) {\n\t\tif (!this.silent) console.log('Mounting Component', this);\n\n\t\tthis.container = container;\n\t\tthis.anchor = anchor;\n\n\t\t// If mounting within another component, register for automatic unmounting\n\t\tconst parentComponent = globalContext.getCurrentComponent();\n\t\tif (parentComponent && parentComponent !== this) {\n\t\t\tparentComponent.addDisposable({\n\t\t\t\tdispose: () => this.unmount(),\n\t\t\t});\n\t\t}\n\n\t\tglobalContext.pushExecutionStack('createComponent');\n\t\tglobalContext.pushComponentStack(this);\n\t\tconst node = this.factoryFn ? (this.factoryFn as any)(this.props) : null;\n\t\tglobalContext.popComponentStack();\n\t\tglobalContext.popExecutionStack();\n\t\t// if node is fragment, convert to array of nodes\n\t\tif (node) {\n\t\t\tif (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n\t\t\t\tthis.nodes = Array.from(node.childNodes);\n\t\t\t} else {\n\t\t\t\tthis.nodes = [node];\n\t\t\t}\n\t\t} else {\n\t\t\tthis.nodes = null;\n\t\t}\n\t\tthis.insertNodes();\n\t}\n\n\treanchor(anchor: Node | null) {\n\t\tthis.anchor = anchor;\n\n\t\t//console.log('reanchoring', this.nodes, ' before anchor', this.anchor);\n\t\tthis.insertNodes();\n\t}\n\n\tprivate insertNodes() {\n\t\tif (!this.container || !this.nodes) return;\n\t\t// Insertar en la nueva posición\n\t\tfor (const node of this.nodes) {\n\t\t\tif (this.anchor) {\n\t\t\t\tthis.container.insertBefore(node, this.anchor);\n\t\t\t} else {\n\t\t\t\tthis.container.appendChild(node);\n\t\t\t}\n\t\t}\n\t}\n\n\taddDisposable(disposable: IDisposable) {\n\t\tthis.disposables.push(disposable);\n\t}\n\n\tunmount() {\n\t\tif (!this.silent) console.log('Unmounting Component', this);\n\n\t\tif (this.nodes) {\n\t\t\tthis.nodes.forEach((node) => {\n\t\t\t\tif (node && node.parentNode) {\n\t\t\t\t\tnode.parentNode.removeChild(node);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tthis.disposables.forEach((d) => {\n\t\t\td.dispose();\n\t\t});\n\t\tthis.disposables = [];\n\t\tthis.nodes = null;\n\t\tthis.container = null;\n\t\tthis.anchor = null;\n\t}\n}\n\n// Definimos overloads para component\nexport function component(factory: ComponentFactory<any>): (props?: any) => Component;\nexport function component<TProps extends Dict>(factory: ComponentFactory<TProps>): (props: TProps) => Component<TProps>;\n\nexport function component<TProps extends Dict = any>(factory: ComponentFactory<TProps>) {\n\treturn (props?: TProps) => {\n\t\treturn new Component(factory, null, props);\n\t};\n}\n\nexport function onUnmount(unmountFn: () => void) {\n\tconst currentComponent = globalContext.getCurrentComponent();\n\tif (currentComponent) {\n\t\tcurrentComponent.addDisposable({\n\t\t\tdispose: unmountFn,\n\t\t});\n\t} else {\n\t\tthrow new Error('onUnmount must be called within a component context');\n\t}\n}\n\ntype ItemFactoryFn<T, TProps = any> = (item: Signal<T>, index: Signal<number>, list: Signal<T[]>, props?: TProps) => ChispaContent;\ntype KeyFn<T> = (item: T, index: number) => any;\n\nexport class ComponentList<TItem = any, TProps extends Dict = any> {\n\tprivate readonly components: Map<string, Component<TProps>>;\n\tprivate container: Node | null = null; // Contenedor donde se montan los nodos\n\tprivate anchor: Node | null = null; // Nodes must be inserted before this node\n\tprivate currentKeys: any[] = [];\n\tpublic disposables: any[] = [];\n\n\tconstructor(\n\t\tprivate readonly itemFactoryFn: ItemFactoryFn<TItem, TProps>,\n\t\tprivate readonly keyFn: KeyFn<TItem>,\n\t\tprivate readonly itemsSignal: Signal<TItem[]>,\n\t\tprivate readonly props: TProps | null = null\n\t) {\n\t\tthis.components = new Map();\n\t}\n\n\t/**\n\t * Obtiene todos los componentes\n\t */\n\tprivate getAllComponents(): Component[] {\n\t\treturn Array.from(this.components.values());\n\t}\n\n\t/**\n\t * Limpia todos los componentes\n\t */\n\tprivate clear(): void {\n\t\tArray.from(this.components.values()).forEach((component) => {\n\t\t\tthis.removeComponent(component);\n\t\t});\n\t}\n\n\t/**\n\t * Elimina un componente completo\n\t */\n\tprivate removeComponent(component: Component) {\n\t\tcomponent.unmount();\n\t\tif (component.key) {\n\t\t\tthis.components.delete(component.key);\n\t\t}\n\t}\n\n\t/**\n\t * Crea un nuevo componente\n\t */\n\tprivate createNewComponent(key: any): Component {\n\t\tconst factory = (props?: TProps) => {\n\t\t\tconst item = computed(() => this.itemsSignal.get().find((v, index) => this.keyFn(v, index) === key)!);\n\t\t\tconst index = computed(() => this.itemsSignal.get().findIndex((v, index) => this.keyFn(v, index) === key));\n\t\t\treturn this.itemFactoryFn ? this.itemFactoryFn(item, index, this.itemsSignal, props) : null;\n\t\t};\n\n\t\tconst component = new Component(factory, key, this.props);\n\t\tthis.components.set(key, component);\n\n\t\treturn component;\n\t}\n\n\tprivate getTargetAnchor(items: TItem[], index: number): Node | null {\n\t\tconst nextItem = index + 1 < items.length ? items[index + 1] : null;\n\t\tconst nextComp = nextItem ? this.components.get(this.keyFn(nextItem, index + 1)) : null;\n\t\tif (nextComp && nextComp.nodes) {\n\t\t\treturn nextComp.nodes[0];\n\t\t} else {\n\t\t\t// Es el último componente, debería insertarse antes del anchor original\n\t\t\treturn this.anchor;\n\t\t}\n\t}\n\n\t/**\n\t * Función principal que sincroniza los componentes DOM con un array de keys\n\t */\n\tprivate synchronizeComponents(): void {\n\t\tconst existingComponents = this.getAllComponents();\n\n\t\t// Identificar qué componentes eliminar (los que no están en keys)\n\t\tconst items = this.itemsSignal.get();\n\t\tconst keys = items.map((item, index) => this.keyFn(item, index));\n\t\tconst componentsToRemove = existingComponents.filter((component) => component.key && !keys.includes(component.key));\n\t\tcomponentsToRemove.forEach((component) => this.removeComponent(component));\n\n\t\tthis.currentKeys = this.currentKeys.filter((key) => keys.includes(key));\n\t\t//console.log('Current keys:', this.currentKeys, 'Target keys:', keys);\n\n\t\tif (!this.container) {\n\t\t\tconsole.warn('Container is null in synchronizeComponents');\n\t\t\treturn;\n\t\t}\n\t\t// Procesar cada key en el orden deseado\n\t\tconst container = this.container;\n\n\t\titems.forEach((item, index) => {\n\t\t\tconst targetKey = this.keyFn(item, index);\n\t\t\tconst currentKey = this.currentKeys[index];\n\t\t\tif (targetKey === currentKey) {\n\t\t\t\t// La key no ha cambiado de posición, no hacer nada\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst existingComponent = this.components.get(targetKey);\n\n\t\t\tif (existingComponent) {\n\t\t\t\tconst prevComp = this.components.get(currentKey);\n\t\t\t\tif (!prevComp || !prevComp.nodes) {\n\t\t\t\t\tconsole.warn('Previous component or its nodes not found for key', currentKey);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\texistingComponent.reanchor(prevComp.nodes[0]);\n\t\t\t\t// Reordenar el array de keys actuales\n\t\t\t\tthis.currentKeys = this.currentKeys.filter((k) => k !== targetKey);\n\t\t\t\tthis.currentKeys.splice(index, 0, targetKey);\n\t\t\t} else {\n\t\t\t\t// El componente no existe, crearlo\n\t\t\t\tconst targetAnchor = this.getTargetAnchor(items, index);\n\t\t\t\tconst newComponent = this.createNewComponent(targetKey);\n\t\t\t\tnewComponent.mount(container, targetAnchor);\n\t\t\t\tthis.currentKeys.splice(index, 0, targetKey);\n\t\t\t}\n\t\t});\n\t}\n\n\tmount(container: Node, anchor: Node | null = null) {\n\t\t//console.log('Mounting ComponentList');\n\t\tthis.container = container;\n\t\tthis.anchor = anchor;\n\n\t\t// If mounting within another component, register for automatic unmounting\n\t\tconst parentComponent = globalContext.getCurrentComponent();\n\t\tif (parentComponent && parentComponent !== this) {\n\t\t\tparentComponent.addDisposable({\n\t\t\t\tdispose: () => this.unmount(),\n\t\t\t});\n\t\t}\n\n\t\tglobalContext.pushComponentStack(this);\n\t\tglobalContext.addReactivity(() => {\n\t\t\tthis.synchronizeComponents();\n\t\t});\n\t\tglobalContext.popComponentStack();\n\t}\n\n\taddDisposable(disposable: IDisposable) {\n\t\tthis.disposables.push(disposable);\n\t}\n\n\tunmount() {\n\t\t//console.log('Unmounting ComponentList');\n\t\tthis.clear();\n\t\tthis.container = null!;\n\t\tthis.anchor = null!;\n\t\tthis.disposables.forEach((d) => {\n\t\t\td.dispose();\n\t\t});\n\t}\n}\n\n// Definimos overloads para componentList\nexport function componentList<TItem>(\n\titemFactoryFn: ItemFactoryFn<TItem, any>,\n\tkeyFn: KeyFn<TItem>\n): (listSignal: Signal<TItem[]>, props?: any) => ComponentList<TItem>;\nexport function componentList<TItem, TProps extends Dict>(\n\titemFactoryFn: ItemFactoryFn<TItem, TProps>,\n\tkeyFn: KeyFn<TItem>\n): (listSignal: Signal<TItem[]>, props: TProps) => ComponentList<TItem, TProps>;\n\nexport function componentList<TItem, TProps extends Dict = any>(itemFactoryFn: ItemFactoryFn<TItem, TProps>, keyFn: KeyFn<TItem>) {\n\treturn (listSignal: Signal<TItem[]>, props?: TProps) => {\n\t\tconst list = new ComponentList(itemFactoryFn, keyFn, listSignal, props);\n\t\treturn list;\n\t};\n}\n","import { Component, ComponentList } from './components';\nimport { globalContext } from './context';\nimport { computed, isSignal, type Signal } from './signals';\n\nexport type ChispaReactive<T> = T | Signal<T> | (() => T);\nexport type ChispaNode = string | number | Node | null;\nexport type ChispaContent = ChispaNode | ChispaNode[] | Component | Component[] | ComponentList;\nexport type ChispaContentReactive = ChispaReactive<ChispaContent>;\nexport type ChispaClasses = Record<string, ChispaReactive<boolean>>;\nexport type ChispaCSSPropertiesStrings = {\n\t[K in keyof CSSStyleDeclaration]?: ChispaReactive<string>;\n};\n\ntype AllowSignals<T> = { [K in keyof T]: T[K] | Signal<T[K]> };\n\ntype ChispaNodeBuilderBaseProps<T> = AllowSignals<Omit<Partial<T>, 'style' | 'dataset'>>;\ninterface INodeBuilderAdditionalProps<T, TNodes> {\n\taddClass?: ChispaReactive<string>;\n\tclasses?: ChispaClasses;\n\tnodes?: TNodes;\n\tinner?: ChispaContentReactive;\n\tstyle?: ChispaCSSPropertiesStrings;\n\tdataset?: Record<string, ChispaReactive<string>>;\n\t_ref?: (node: T) => void | { current: T | null };\n}\nexport type ChispaNodeBuilderProps<T, TNodes> = ChispaNodeBuilderBaseProps<T> & INodeBuilderAdditionalProps<T, TNodes>;\n\nconst forbiddenProps = ['nodes', 'inner', '_ref'];\n\nexport function getValidProps(props: any) {\n\tconst finalProps: any = {};\n\n\tfor (const propName in props) {\n\t\tif (forbiddenProps.indexOf(propName) === -1) {\n\t\t\tfinalProps[propName] = props[propName];\n\t\t}\n\t}\n\n\tif (props._ref !== undefined) {\n\t\t//finalProps.ref = props._ref;\n\t}\n\n\treturn finalProps;\n}\n\nexport function getItem<T>(template: T, items: any, itemName: keyof T) {\n\tif (!items || !items[itemName]) {\n\t\treturn null;\n\t}\n\n\tconst item = items[itemName];\n\n\tif (item.constructor && item.constructor.name === 'Object' && !(item instanceof Element)) {\n\t\tconst Comp = template[itemName] as (props: any) => Element;\n\t\tconst itemProps = item;\n\n\t\treturn Comp(itemProps);\n\t} else {\n\t\treturn item;\n\t}\n}\n\nexport function setAttributes(node: Element, attributes: Record<string, string>) {\n\tfor (const attr in attributes) {\n\t\tconst attrValue = attributes[attr].trim();\n\t\tif (!attrValue) continue;\n\t\t//console.log('setting attr', attr, attrValue )\n\t\tnode.setAttribute(attr, attrValue);\n\t}\n}\n\nexport function setProps<T extends Element>(node: T, props: ChispaNodeBuilderProps<T, any>) {\n\tif (node instanceof HTMLElement) {\n\t\tif (props.style !== undefined) {\n\t\t\tconst style = props.style;\n\t\t\tfor (const styleKey in style) {\n\t\t\t\tlet styleValue = style[styleKey]!;\n\t\t\t\tif (typeof styleValue === 'function') {\n\t\t\t\t\tstyleValue = computed(styleValue);\n\t\t\t\t}\n\t\t\t\tif (isSignal(styleValue)) {\n\t\t\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t\t\tnode.style[styleKey] = styleValue.get();\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tnode.style[styleKey] = styleValue;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdelete props.style;\n\t\t}\n\n\t\tif (props.addClass !== undefined) {\n\t\t\tlet addClass = props.addClass;\n\t\t\tlet prevClass: string | null = null;\n\n\t\t\tif (typeof addClass === 'function') {\n\t\t\t\taddClass = computed(addClass);\n\t\t\t}\n\n\t\t\tif (isSignal(addClass)) {\n\t\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t\tconst cls = addClass.get();\n\t\t\t\t\tif (cls !== prevClass) {\n\t\t\t\t\t\tif (prevClass) {\n\t\t\t\t\t\t\tnode.classList.remove(prevClass);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnode.classList.add(cls);\n\t\t\t\t\t}\n\t\t\t\t\tprevClass = cls;\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tnode.classList.add(addClass);\n\t\t\t}\n\t\t\tdelete props.addClass;\n\t\t}\n\n\t\tif (props.classes !== undefined) {\n\t\t\tconst classes = props.classes;\n\t\t\tfor (const className in classes) {\n\t\t\t\tlet apply = classes[className];\n\t\t\t\tif (typeof apply === 'function') {\n\t\t\t\t\tapply = computed(apply);\n\t\t\t\t}\n\t\t\t\tif (isSignal(apply)) {\n\t\t\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t\t\tif (apply.get()) {\n\t\t\t\t\t\t\tnode.classList.add(className);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tnode.classList.remove(className);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tif (classes[className]) {\n\t\t\t\t\t\tnode.classList.add(className);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.classList.remove(className);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdelete props.classes;\n\t\t}\n\n\t\tif (props.dataset !== undefined) {\n\t\t\tconst dataset = props.dataset;\n\t\t\tfor (const datasetKey in dataset) {\n\t\t\t\tlet ds = dataset[datasetKey];\n\t\t\t\tif (typeof ds === 'function') {\n\t\t\t\t\tds = computed(ds);\n\t\t\t\t}\n\t\t\t\tif (isSignal(ds)) {\n\t\t\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t\t\tnode.dataset[datasetKey] = ds.get();\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tnode.dataset[datasetKey] = ds;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdelete props.dataset;\n\t\t}\n\t}\n\n\tfor (const prop in props) {\n\t\tconst propValue = (props as any)[prop];\n\t\t//console.log('setting prop', prop, propValue )\n\t\tif (isSignal(propValue)) {\n\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t(node as any)[prop] = propValue.get();\n\t\t\t});\n\t\t} else if (propValue === undefined) {\n\t\t\tcontinue;\n\t\t} else {\n\t\t\t(node as any)[prop] = propValue;\n\t\t}\n\t}\n}\n\nexport function appendChild(node: Element | DocumentFragment, child: ChispaContentReactive) {\n\tif (child === null) return;\n\tif (typeof child === 'function') {\n\t\tprocessSignalChild(node, computed(child));\n\t\treturn;\n\t}\n\tif (isSignal(child)) {\n\t\tprocessSignalChild(node, child);\n\t\treturn;\n\t}\n\tif (child instanceof Component || child instanceof ComponentList) {\n\t\tchild.mount(node, null);\n\t\treturn;\n\t}\n\tif (Array.isArray(child)) {\n\t\tchild.forEach((ch) => {\n\t\t\tappendChild(node, ch);\n\t\t});\n\t\treturn;\n\t}\n\tnode.appendChild(child instanceof Node ? child : document.createTextNode(child.toString()));\n}\n\nfunction isStaticArrayOfComponents(arr: ChispaContent): arr is Component[] {\n\tif (!Array.isArray(arr)) return false;\n\tfor (const item of arr) {\n\t\tif (!(item instanceof Component)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction processSignalChild(node: Element | DocumentFragment, child: Signal<ChispaContent>) {\n\tconst anchor = document.createTextNode('');\n\tnode.appendChild(anchor);\n\tlet prevValue: Component | ComponentList | null = null;\n\n\tglobalContext.addReactivity(() => {\n\t\t//console.log('Signal child changed', child);\n\t\tconst ch = child.get();\n\t\tif (prevValue) {\n\t\t\tprevValue.unmount();\n\t\t}\n\t\tif (ch === null) {\n\t\t\tprevValue = null;\n\t\t\treturn;\n\t\t}\n\n\t\tlet component: Component | ComponentList;\n\t\tif (isStaticArrayOfComponents(ch)) {\n\t\t\tthrow new Error('Static array of components not supported in signal children. Use ComponentList instead.');\n\t\t} else if (ch instanceof Component || ch instanceof ComponentList) {\n\t\t\tch.mount(node, anchor);\n\t\t\tcomponent = ch;\n\t\t} else {\n\t\t\tconst wrCmp = new Component(() => toNode(ch));\n\t\t\t//wrCmp.silent = true;\n\t\t\twrCmp.mount(node, anchor);\n\t\t\tcomponent = wrCmp;\n\t\t}\n\t\tprevValue = component;\n\t});\n}\n\nfunction toNode(n: ChispaNode | ChispaNode[]): Node | null {\n\tif (Array.isArray(n)) {\n\t\tconst frag = document.createDocumentFragment();\n\t\tconst nodes = n.map((c) => toNode(c)).filter((n) => n !== null);\n\t\tfrag.append(...nodes);\n\t\treturn frag;\n\t} else if (n instanceof Node) {\n\t\treturn n;\n\t} else if (typeof n === 'string' || typeof n === 'number') {\n\t\treturn document.createTextNode(n.toString());\n\t} else {\n\t\treturn null;\n\t\t//throw new Error('Invalid node type');\n\t}\n}\n","import { globalContext } from './context';\nimport { WritableSignal } from './signals';\n\nexport interface ControlledInputOptions {\n\t/**\n\t * Optional function to transform the value before setting it to the signal.\n\t * Useful for enforcing uppercase, removing invalid characters, etc.\n\t */\n\ttransform?: (value: string) => string;\n\n\t/**\n\t * Optional function to validate the value.\n\t * If it returns false, the change is rejected and the previous value is restored.\n\t */\n\tvalidate?: (value: string) => boolean;\n}\n\nexport function bindControlledInput(element: HTMLInputElement | HTMLTextAreaElement, signal: WritableSignal<string>, options: ControlledInputOptions = {}) {\n\tconst { transform, validate } = options;\n\n\t// Initialize value\n\telement.value = signal.initialValue;\n\n\t// Handle input events\n\tconst handleInput = (e: Event) => {\n\t\tconst target = e.target as HTMLInputElement;\n\t\tlet newValue = target.value;\n\t\tconst originalValue = signal.get();\n\n\t\t// Save cursor position\n\t\tconst selectionStart = target.selectionStart;\n\t\tconst selectionEnd = target.selectionEnd;\n\n\t\t// Apply transformation if provided\n\t\tif (transform) {\n\t\t\tnewValue = transform(newValue);\n\t\t}\n\n\t\t// Apply validation if provided\n\t\tif (validate && !validate(newValue)) {\n\t\t\t// If invalid, revert to original value\n\t\t\tnewValue = originalValue;\n\t\t}\n\n\t\t// Update signal\n\t\tif (newValue !== originalValue) {\n\t\t\tsignal.set(newValue);\n\t\t}\n\n\t\t// Force update DOM if it doesn't match the new value (e.g. transformed or rejected)\n\t\tif (target.value !== newValue) {\n\t\t\tconst lengthDiff = target.value.length - newValue.length;\n\t\t\ttarget.value = newValue;\n\n\t\t\t// Restore cursor\n\t\t\tif (selectionStart !== null && selectionEnd !== null) {\n\t\t\t\t// Restore to the saved position.\n\t\t\t\t// Adjust for length difference to keep cursor relative to the content\n\t\t\t\tconst newStart = Math.max(0, selectionStart - lengthDiff);\n\t\t\t\tconst newEnd = Math.max(0, selectionEnd - lengthDiff);\n\t\t\t\ttarget.setSelectionRange(newStart, newEnd);\n\t\t\t}\n\t\t}\n\t};\n\n\telement.addEventListener('input', handleInput);\n\n\t// Subscribe to signal changes to update the input if it changes externally\n\tglobalContext.addReactivity(() => {\n\t\tconst newValue = signal.get();\n\t\t// Only update if the value is actually different to avoid cursor jumping\n\t\tif (element.value !== newValue) {\n\t\t\telement.value = newValue;\n\t\t}\n\t});\n\n\t// Return a cleanup function\n\treturn () => {\n\t\telement.removeEventListener('input', handleInput);\n\t};\n}\n","import { signal, computed, Signal } from './signals';\nimport { component, Component, Dict } from './components';\nimport { appendChild, ChispaNodeBuilderProps, setProps } from './builder';\n\nexport interface Route {\n\tpath: string;\n\tcomponent: (props?: any) => Component<any>;\n}\n\nconst currentPath = signal(typeof window !== 'undefined' ? window.location.pathname : '/');\n\nif (typeof window !== 'undefined') {\n\twindow.addEventListener('popstate', () => {\n\t\tcurrentPath.set(window.location.pathname);\n\t});\n}\n\nexport function navigate(to: string, replace = false) {\n\tif (typeof window === 'undefined') {\n\t\tcurrentPath.set(to);\n\t\treturn;\n\t}\n\tif (replace) {\n\t\twindow.history.replaceState({}, '', to);\n\t} else {\n\t\twindow.history.pushState({}, '', to);\n\t}\n\tcurrentPath.set(to);\n}\n\nexport function pathMatches(path: string): Signal<boolean> {\n\treturn computed(() => {\n\t\tconst current = currentPath.get();\n\t\treturn match(path, current) !== null;\n\t});\n}\n\nfunction match(routePath: string, currentPath: string): Dict | null {\n\tif (routePath === '*') return {};\n\tconst routeParts = routePath.split('/').filter(Boolean);\n\tconst currentParts = currentPath.split('/').filter(Boolean);\n\tif (routeParts.length !== currentParts.length) return null;\n\tconst params: Dict = {};\n\tfor (let i = 0; i < routeParts.length; i++) {\n\t\tif (routeParts[i].startsWith(':')) {\n\t\t\tparams[routeParts[i].substring(1)] = currentParts[i];\n\t\t} else if (routeParts[i] !== currentParts[i]) {\n\t\t\treturn null;\n\t\t}\n\t}\n\treturn params;\n}\n\nexport const Router = component<{ routes: Route[] }>((props) => {\n\tconst container = document.createElement('div');\n\tcontainer.style.display = 'contents';\n\tconst activeRoute = computed(() => {\n\t\tconst path = currentPath.get();\n\t\tfor (const route of props.routes) {\n\t\t\tconst params = match(route.path, path);\n\t\t\tif (params) {\n\t\t\t\treturn route.component(params);\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t});\n\tappendChild(container, activeRoute);\n\treturn container;\n});\n\nexport interface LinkProps extends ChispaNodeBuilderProps<HTMLAnchorElement, {}> {\n\tto: string;\n}\n\nexport const Link = component<LinkProps>((props) => {\n\tconst { to, inner, ...rest } = props;\n\tconst a = document.createElement('a');\n\ta.href = to;\n\n\ta.addEventListener('click', (e) => {\n\t\tif (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.defaultPrevented || e.button !== 0) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\t\tnavigate(to);\n\t});\n\n\tif (inner) {\n\t\tappendChild(a, inner);\n\t}\n\n\tsetProps(a, rest);\n\n\treturn a;\n});\n"],"mappings":";AASA,IAAM,aAAN,MAAiB;AAAA,EACR,yBAAuC,CAAC;AAAA,EAExC,iBAAsB;AAAA;AAAA,EAItB,oBAAoB,oBAAI,IAAgB;AAAA,EAExC,iBAAkC,CAAC;AAAA,EAEnC,iBAAgD,CAAC;AAAA,EAEzD,mBAAmB,KAAgC;AAClD,SAAK,eAAe,KAAK,GAAG;AAAA,EAC7B;AAAA,EAEA,oBAAoB;AACnB,SAAK,eAAe,IAAI;AAAA,EACzB;AAAA,EAEA,sBAAsB;AACrB,QAAI,KAAK,eAAe,WAAW,GAAG;AAErC,aAAO;AAAA,IACR;AACA,WAAO,KAAK,eAAe,KAAK,eAAe,SAAS,CAAC;AAAA,EAC1D;AAAA,EAEA,4BAA4B,SAAqB;AAChD,SAAK,uBAAuB,KAAK,OAAO;AAAA,EAEzC;AAAA,EAEA,mCAAmC;AAClC,SAAK,uBAAuB,IAAI;AAAA,EACjC;AAAA,EAEA,0BAA0B;AACzB,QAAI,KAAK,uBAAuB,WAAW,GAAG;AAE7C,aAAO;AAAA,IACR;AACA,WAAO,KAAK,uBAAuB,KAAK,uBAAuB,SAAS,CAAC;AAAA,EAC1E;AAAA,EAEA,kBAAkB;AACjB,QAAI,KAAK,gBAAgB;AACxB,mBAAa,KAAK,cAAc;AAAA,IACjC;AACA,SAAK,iBAAiB,WAAW,MAAM;AACtC,YAAM,gBAAgB,MAAM,KAAK,KAAK,iBAAiB;AACvD,oBAAc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,CAAC,CAAC,IAAI,aAAa,CAAC;AAAA,IACpD,WAAW,WAAW,CAAC,MAAM,aAAa,CAAC,GAAG;AAC7C,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;AAEO,IAAM,SAAS,UAA+B,CAAC,UAAU;AAC/D,QAAM,YAAY,SAAS,cAAc,KAAK;AAC9C,YAAU,MAAM,UAAU;AAC1B,QAAM,cAAc,SAAS,MAAM;AAClC,UAAM,OAAO,YAAY,IAAI;AAC7B,eAAW,SAAS,MAAM,QAAQ;AACjC,YAAM,SAAS,MAAM,MAAM,MAAM,IAAI;AACrC,UAAI,QAAQ;AACX,eAAO,MAAM,UAAU,MAAM;AAAA,MAC9B;AAAA,IACD;AACA,WAAO;AAAA,EACR,CAAC;AACD,cAAY,WAAW,WAAW;AAClC,SAAO;AACR,CAAC;AAMM,IAAM,OAAO,UAAqB,CAAC,UAAU;AACnD,QAAM,EAAE,IAAI,OAAO,GAAG,KAAK,IAAI;AAC/B,QAAM,IAAI,SAAS,cAAc,GAAG;AACpC,IAAE,OAAO;AAET,IAAE,iBAAiB,SAAS,CAAC,MAAM;AAClC,QAAI,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,WAAW,GAAG;AAC7F;AAAA,IACD;AACA,MAAE,eAAe;AACjB,aAAS,EAAE;AAAA,EACZ,CAAC;AAED,MAAI,OAAO;AACV,gBAAY,GAAG,KAAK;AAAA,EACrB;AAEA,WAAS,GAAG,IAAI;AAEhB,SAAO;AACR,CAAC;","names":["component","signal","component","index","component","n","signal","currentPath"]}
|
|
1
|
+
{"version":3,"sources":["../src/context.ts","../src/signals.ts","../src/components.ts","../src/builder.ts","../src/controlled-input.ts","../src/router.ts"],"sourcesContent":["import { Component, ComponentList } from './components';\nimport { Signal } from './signals';\n\ntype ExecutionKind = 'createComponent' | 'computed' | 'addReactivity';\n\nexport interface IDisposable {\n\tdispose: () => void;\n}\n\nclass AppContext {\n\tprivate reactivityContextStack: Reactivity[] = [];\n\n\tprivate refreshTimeout: any = 0;\n\n\t//private contexts = new Set<RenderContext>();\n\n\tprivate dirtyReactivities = new Set<Reactivity>();\n\n\tprivate executionStack: ExecutionKind[] = [];\n\n\tprivate componentStack: (Component | ComponentList)[] = [];\n\n\tpushComponentStack(cmp: Component | ComponentList) {\n\t\tthis.componentStack.push(cmp);\n\t}\n\n\tpopComponentStack() {\n\t\tthis.componentStack.pop();\n\t}\n\n\tgetCurrentComponent() {\n\t\tif (this.componentStack.length === 0) {\n\t\t\t//console.warn('No current component');\n\t\t\treturn null;\n\t\t}\n\t\treturn this.componentStack[this.componentStack.length - 1];\n\t}\n\n\tsetCurrentReactivityContext(context: Reactivity) {\n\t\tthis.reactivityContextStack.push(context);\n\t\t//this.contexts.add(context);\n\t}\n\n\trestorePreviousReactivityContext() {\n\t\tthis.reactivityContextStack.pop();\n\t}\n\n\tgetCurrentRenderContext() {\n\t\tif (this.reactivityContextStack.length === 0) {\n\t\t\t//console.warn('No current render context');\n\t\t\treturn null;\n\t\t}\n\t\treturn this.reactivityContextStack[this.reactivityContextStack.length - 1];\n\t}\n\n\t// Maximum number of iterations to process during a scheduled refresh. Prevents\n\t// unbounded loops in case of uncontrolled reactivity cascades. Use the\n\t// `globalContext.maxScheduleIterations` field to override in tests or\n\t// special cases.\n\tpublic maxScheduleIterations = 100;\n\n\tscheduleRefresh() {\n\t\tif (this.refreshTimeout) {\n\t\t\tclearTimeout(this.refreshTimeout);\n\t\t}\n\t\tthis.refreshTimeout = setTimeout(() => {\n\t\t\tlet iteration = 0;\n\t\t\t// Process dirty contexts until none remain, or until the iteration limit\n\t\t\t// is reached (this avoids infinite loops when reactivities keep\n\t\t\t// re-adding themselves or each other).\n\t\t\twhile (this.dirtyReactivities.size > 0 && iteration < this.maxScheduleIterations) {\n\t\t\t\titeration++;\n\t\t\t\tconst dirtyContexts = Array.from(this.dirtyReactivities);\n\t\t\t\tdirtyContexts.forEach((ctx) => ctx.process());\n\t\t\t}\n\n\t\t\tif (this.dirtyReactivities.size > 0) {\n\t\t\t\t// Warn once if we stopped early due to the iteration limit. We also\n\t\t\t\t// clear the set to avoid repeated warnings and to avoid leaving the\n\t\t\t\t// system in a permanently spinning state.\n\t\t\t\tconsole.warn(`[AppContext.scheduleRefresh] possible uncontrolled reactivity cascade: processed ${iteration} iterations — aborting.`);\n\t\t\t\tthis.dirtyReactivities.clear();\n\t\t\t}\n\t\t}, 0);\n\t}\n\n\taddReactivity(executor: () => void) {\n\t\tconst ctx = new Reactivity(executor);\n\t\tglobalContext.pushExecutionStack('addReactivity');\n\t\tctx.exec();\n\t\tglobalContext.popExecutionStack();\n\t\treturn ctx;\n\t}\n\n\tcreateRoot(component: () => Component, mountPoint: HTMLElement) {\n\t\tthis.dirtyReactivities.clear();\n\t\tmountPoint.innerHTML = '';\n\t\tconst cmp = component();\n\t\tcmp.mount(mountPoint, null);\n\t}\n\n\tcanReadSignal() {\n\t\tconst length = this.executionStack.length;\n\t\tif (length === 0) return true;\n\t\tconst current = this.executionStack[length - 1];\n\t\treturn current !== 'createComponent';\n\t}\n\n\tpushExecutionStack(type: ExecutionKind) {\n\t\tthis.executionStack.push(type);\n\t}\n\n\tpopExecutionStack() {\n\t\tthis.executionStack.pop();\n\t}\n\n\taddDirtyContext(ctx: Reactivity) {\n\t\tthis.dirtyReactivities.add(ctx);\n\t}\n\n\tremoveDirtyContext(ctx: Reactivity) {\n\t\tthis.dirtyReactivities.delete(ctx);\n\t}\n}\n\nexport class Reactivity implements IDisposable {\n\tprivate dirty: boolean = false;\n\n\tprivate signals = new Set<Signal<any>>();\n\n\tconstructor(private readonly action: () => void) {\n\t\tconst currentComponent = globalContext.getCurrentComponent();\n\t\tif (currentComponent) {\n\t\t\tcurrentComponent.addDisposable(this);\n\t\t} else {\n\t\t\tconsole.warn('Creating a Reactivity outside of a component');\n\t\t}\n\t}\n\n\tmarkDirty() {\n\t\tthis.dirty = true;\n\t\tglobalContext.addDirtyContext(this);\n\t\tglobalContext.scheduleRefresh();\n\t}\n\n\taddSignal(signal: Signal<any>) {\n\t\tthis.signals.add(signal);\n\t}\n\n\tremoveSignal(signal: Signal<any>) {\n\t\tthis.signals.delete(signal);\n\t}\n\n\tprocess() {\n\t\tif (!this.dirty) return;\n\t\tthis.exec();\n\t\t//console.log('re-render cycle completed');\n\t\tthis.dirty = false;\n\t\tglobalContext.removeDirtyContext(this);\n\t}\n\n\texec() {\n\t\tthis.signals.forEach((s) => s.removeContext(this));\n\t\tthis.signals.clear();\n\t\tglobalContext.setCurrentReactivityContext(this);\n\t\tthis.action();\n\t\tglobalContext.restorePreviousReactivityContext();\n\t}\n\n\tdispose() {\n\t\tthis.signals.forEach((s) => s.removeContext(this));\n\t\tthis.signals.clear();\n\t\tthis.dirty = false;\n\t\tglobalContext.removeDirtyContext(this);\n\t}\n}\n\nexport const globalContext = new AppContext();\n","import { globalContext, Reactivity } from './context';\n\ntype WithSignals<T> = { [K in keyof T]: Signal<T[K]> };\n\nabstract class Signal<T> {\n\tprotected abstract value: T;\n\n\tprotected contexts: Set<Reactivity> = new Set();\n\n\tconstructor() {}\n\n\tget() {\n\t\tif (!globalContext.canReadSignal()) {\n\t\t\tthrow new Error('Cannot read a signal value during component creation. Did you mean to use a computed signal instead?');\n\t\t}\n\t\t//context.current.register(this);\n\t\tconst ctx = globalContext.getCurrentRenderContext();\n\t\tif (ctx) {\n\t\t\tthis.contexts.add(ctx);\n\t\t\tctx.addSignal(this);\n\t\t}\n\t\treturn this.value;\n\t}\n\n\tpublic readonly computed = new Proxy(\n\t\t{},\n\t\t{\n\t\t\tget: (_, prop) => {\n\t\t\t\treturn computed(() => this.get()[prop as keyof T]);\n\t\t\t},\n\t\t}\n\t) as WithSignals<T>;\n\n\tremoveContext(ctx: Reactivity) {\n\t\tthis.contexts.delete(ctx);\n\t}\n\n\tdispose() {\n\t\tconsole.log('disposing signal', this);\n\t\tthis.contexts.forEach((ctx) => {\n\t\t\tctx.removeSignal(this);\n\t\t});\n\t\tthis.contexts.clear();\n\t}\n}\n\nclass WritableSignal<T> extends Signal<T> {\n\tprotected override value: T;\n\n\tpublic readonly initialValue: T;\n\n\tconstructor(initialValue: T) {\n\t\tsuper();\n\t\tthis.initialValue = initialValue;\n\t\tthis.value = initialValue;\n\t}\n\n\tset(newValue: T) {\n\t\tthis.value = newValue;\n\t\tthis.contexts.forEach((ctx) => ctx.markDirty());\n\t}\n\n\tupdate(updater: (value: T) => T) {\n\t\tthis.value = updater(this.value);\n\t\tthis.contexts.forEach((ctx) => ctx.markDirty());\n\t}\n}\n\nclass ComputedSignal<T> extends Signal<T> {\n\tprotected override value: T;\n\n\tprivate computeFn: () => T;\n\n\tconstructor(computeFn: () => T) {\n\t\tsuper();\n\t\tglobalContext.pushExecutionStack('computed');\n\t\tthis.value = computeFn();\n\t\tglobalContext.popExecutionStack();\n\t\tthis.computeFn = computeFn;\n\t}\n\n\trecompute() {\n\t\tconst newValue = this.computeFn();\n\t\tif (newValue !== this.value) {\n\t\t\tthis.value = newValue;\n\t\t\tthis.contexts.forEach((ctx) => ctx.markDirty());\n\t\t}\n\t}\n}\n\nexport function isSignal(value: any): value is Signal<any> {\n\treturn value instanceof Signal;\n}\n\nexport function isWriteableSignal<T>(value: Signal<T>): value is WritableSignal<T> {\n\treturn value instanceof WritableSignal;\n}\n\nexport function signal<T>(initialValue: T) {\n\tconst sig = new WritableSignal(initialValue);\n\n\t// // Creamos una función que se usará como callable\n\t// const fn = (() => sig.get()) as any;\n\n\t// // Copiamos todas las propiedades y métodos de la instancia a la función\n\t// Object.setPrototypeOf(fn, sig.constructor.prototype);\n\n\t// // Copiamos las propiedades de instancia\n\t// Object.assign(fn, this);\n\n\t// // Retornamos la función como si fuera la instancia\n\t// return fn as WritableSignal<T> & (() => T);\n\n\treturn sig;\n}\n\nexport function computed<T>(fn: () => T) {\n\tlet sig: ComputedSignal<T>;\n\tconst ctx = new Reactivity(() => {\n\t\tsig.recompute();\n\t});\n\tglobalContext.setCurrentReactivityContext(ctx);\n\tsig = new ComputedSignal(fn);\n\tglobalContext.restorePreviousReactivityContext();\n\n\treturn sig as Signal<T>;\n}\n\nexport function effect(fn: () => void) {\n\tglobalContext.addReactivity(fn);\n}\n\nexport type { Signal, WritableSignal };\n","import { ChispaContent } from './builder';\nimport { globalContext, IDisposable } from './context';\nimport { computed, Signal, WritableSignal } from './signals';\n\nexport type Dict = Record<string, any>;\nexport type ComponentFactory<TProps extends Dict> = (props: TProps) => ChispaContent;\n\nexport class Component<TProps extends Dict = any> {\n\tpublic nodes: Node[] | null = null;\n\n\tprivate container: Node | null = null;\n\n\tprivate anchor: Node | null = null;\n\n\tprivate disposables: IDisposable[] = [];\n\n\tpublic silent = true;\n\n\tconstructor(\n\t\tprivate readonly factoryFn: ComponentFactory<TProps>,\n\t\tpublic readonly key: any = null,\n\t\tpublic readonly props: TProps | null = null\n\t) {}\n\n\tmount(container: Node, anchor: Node | null = null) {\n\t\tif (!this.silent) console.log('Mounting Component', this);\n\n\t\tthis.container = container;\n\t\tthis.anchor = anchor;\n\n\t\t// If mounting within another component, register for automatic unmounting\n\t\tconst parentComponent = globalContext.getCurrentComponent();\n\t\tif (parentComponent && parentComponent !== this) {\n\t\t\tparentComponent.addDisposable({\n\t\t\t\tdispose: () => this.unmount(),\n\t\t\t});\n\t\t}\n\n\t\tglobalContext.pushExecutionStack('createComponent');\n\t\tglobalContext.pushComponentStack(this);\n\t\tconst node = this.factoryFn ? (this.factoryFn as any)(this.props) : null;\n\t\tglobalContext.popComponentStack();\n\t\tglobalContext.popExecutionStack();\n\t\t// if node is fragment, convert to array of nodes\n\t\tif (node) {\n\t\t\tif (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {\n\t\t\t\tthis.nodes = Array.from(node.childNodes);\n\t\t\t} else {\n\t\t\t\tthis.nodes = [node];\n\t\t\t}\n\t\t} else {\n\t\t\tthis.nodes = null;\n\t\t}\n\t\tthis.insertNodes();\n\t}\n\n\treanchor(anchor: Node | null) {\n\t\tthis.anchor = anchor;\n\n\t\t//console.log('reanchoring', this.nodes, ' before anchor', this.anchor);\n\t\tthis.insertNodes();\n\t}\n\n\tprivate insertNodes() {\n\t\tif (!this.container || !this.nodes) return;\n\t\t// Insertar en la nueva posición\n\t\tfor (const node of this.nodes) {\n\t\t\tif (this.anchor) {\n\t\t\t\tthis.container.insertBefore(node, this.anchor);\n\t\t\t} else {\n\t\t\t\tthis.container.appendChild(node);\n\t\t\t}\n\t\t}\n\t}\n\n\taddDisposable(disposable: IDisposable) {\n\t\tthis.disposables.push(disposable);\n\t}\n\n\tunmount() {\n\t\tif (!this.silent) console.log('Unmounting Component', this);\n\n\t\tif (this.nodes) {\n\t\t\tthis.nodes.forEach((node) => {\n\t\t\t\tif (node && node.parentNode) {\n\t\t\t\t\tnode.parentNode.removeChild(node);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tthis.disposables.forEach((d) => {\n\t\t\td.dispose();\n\t\t});\n\t\tthis.disposables = [];\n\t\tthis.nodes = null;\n\t\tthis.container = null;\n\t\tthis.anchor = null;\n\t}\n}\n\n// Definimos overloads para component\nexport function component(factory: ComponentFactory<any>): (props?: any) => Component;\nexport function component<TProps extends Dict>(factory: ComponentFactory<TProps>): (props: TProps) => Component<TProps>;\n\nexport function component<TProps extends Dict = any>(factory: ComponentFactory<TProps>) {\n\treturn (props?: TProps) => {\n\t\treturn new Component(factory, null, props);\n\t};\n}\n\nexport function onUnmount(unmountFn: () => void) {\n\tconst currentComponent = globalContext.getCurrentComponent();\n\tif (currentComponent) {\n\t\tcurrentComponent.addDisposable({\n\t\t\tdispose: unmountFn,\n\t\t});\n\t} else {\n\t\tthrow new Error('onUnmount must be called within a component context');\n\t}\n}\n\ntype ItemFactoryFn<T, TProps = any> = (item: Signal<T>, index: Signal<number>, list: Signal<T[]>, props?: TProps) => ChispaContent;\ntype KeyFn<T> = (item: T, index: number) => any;\n\nexport class ComponentList<TItem = any, TProps extends Dict = any> {\n\tprivate readonly components: Map<string, Component<TProps>>;\n\tprivate container: Node | null = null; // Contenedor donde se montan los nodos\n\tprivate anchor: Node | null = null; // Nodes must be inserted before this node\n\tprivate currentKeys: any[] = [];\n\tpublic disposables: any[] = [];\n\n\tconstructor(\n\t\tprivate readonly itemFactoryFn: ItemFactoryFn<TItem, TProps>,\n\t\tprivate readonly keyFn: KeyFn<TItem>,\n\t\tprivate readonly itemsSignal: Signal<TItem[]>,\n\t\tprivate readonly props: TProps | null = null\n\t) {\n\t\tthis.components = new Map();\n\t}\n\n\t/**\n\t * Obtiene todos los componentes\n\t */\n\tprivate getAllComponents(): Component[] {\n\t\treturn Array.from(this.components.values());\n\t}\n\n\t/**\n\t * Limpia todos los componentes\n\t */\n\tprivate clear(): void {\n\t\tArray.from(this.components.values()).forEach((component) => {\n\t\t\tthis.removeComponent(component);\n\t\t});\n\t}\n\n\t/**\n\t * Elimina un componente completo\n\t */\n\tprivate removeComponent(component: Component) {\n\t\tcomponent.unmount();\n\t\tif (component.key) {\n\t\t\tthis.components.delete(component.key);\n\t\t}\n\t}\n\n\t/**\n\t * Crea un nuevo componente\n\t */\n\tprivate createNewComponent(key: any): Component {\n\t\tconst factory = (props?: TProps) => {\n\t\t\tconst item = computed(() => this.itemsSignal.get().find((v, index) => this.keyFn(v, index) === key)!);\n\t\t\tconst index = computed(() => this.itemsSignal.get().findIndex((v, index) => this.keyFn(v, index) === key));\n\t\t\treturn this.itemFactoryFn ? this.itemFactoryFn(item, index, this.itemsSignal, props) : null;\n\t\t};\n\n\t\tconst component = new Component(factory, key, this.props);\n\t\tthis.components.set(key, component);\n\n\t\treturn component;\n\t}\n\n\tprivate getTargetAnchor(items: TItem[], index: number): Node | null {\n\t\tconst nextItem = index + 1 < items.length ? items[index + 1] : null;\n\t\tconst nextComp = nextItem ? this.components.get(this.keyFn(nextItem, index + 1)) : null;\n\t\tif (nextComp && nextComp.nodes) {\n\t\t\treturn nextComp.nodes[0];\n\t\t} else {\n\t\t\t// Es el último componente, debería insertarse antes del anchor original\n\t\t\treturn this.anchor;\n\t\t}\n\t}\n\n\t/**\n\t * Función principal que sincroniza los componentes DOM con un array de keys\n\t */\n\tprivate synchronizeComponents(): void {\n\t\tconst existingComponents = this.getAllComponents();\n\n\t\t// Identificar qué componentes eliminar (los que no están en keys)\n\t\tconst items = this.itemsSignal.get();\n\t\tconst keys = items.map((item, index) => this.keyFn(item, index));\n\t\tconst componentsToRemove = existingComponents.filter((component) => component.key && !keys.includes(component.key));\n\t\tcomponentsToRemove.forEach((component) => this.removeComponent(component));\n\n\t\tthis.currentKeys = this.currentKeys.filter((key) => keys.includes(key));\n\t\t//console.log('Current keys:', this.currentKeys, 'Target keys:', keys);\n\n\t\tif (!this.container) {\n\t\t\tconsole.warn('Container is null in synchronizeComponents');\n\t\t\treturn;\n\t\t}\n\t\t// Procesar cada key en el orden deseado\n\t\tconst container = this.container;\n\n\t\titems.forEach((item, index) => {\n\t\t\tconst targetKey = this.keyFn(item, index);\n\t\t\tconst currentKey = this.currentKeys[index];\n\t\t\tif (targetKey === currentKey) {\n\t\t\t\t// La key no ha cambiado de posición, no hacer nada\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst existingComponent = this.components.get(targetKey);\n\n\t\t\tif (existingComponent) {\n\t\t\t\tconst prevComp = this.components.get(currentKey);\n\t\t\t\tif (!prevComp || !prevComp.nodes) {\n\t\t\t\t\tconsole.warn('Previous component or its nodes not found for key', currentKey);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\texistingComponent.reanchor(prevComp.nodes[0]);\n\t\t\t\t// Reordenar el array de keys actuales\n\t\t\t\tthis.currentKeys = this.currentKeys.filter((k) => k !== targetKey);\n\t\t\t\tthis.currentKeys.splice(index, 0, targetKey);\n\t\t\t} else {\n\t\t\t\t// El componente no existe, crearlo\n\t\t\t\tconst targetAnchor = this.getTargetAnchor(items, index);\n\t\t\t\tconst newComponent = this.createNewComponent(targetKey);\n\t\t\t\tnewComponent.mount(container, targetAnchor);\n\t\t\t\tthis.currentKeys.splice(index, 0, targetKey);\n\t\t\t}\n\t\t});\n\t}\n\n\tmount(container: Node, anchor: Node | null = null) {\n\t\t//console.log('Mounting ComponentList');\n\t\tthis.container = container;\n\t\tthis.anchor = anchor;\n\n\t\t// If mounting within another component, register for automatic unmounting\n\t\tconst parentComponent = globalContext.getCurrentComponent();\n\t\tif (parentComponent && parentComponent !== this) {\n\t\t\tparentComponent.addDisposable({\n\t\t\t\tdispose: () => this.unmount(),\n\t\t\t});\n\t\t}\n\n\t\tglobalContext.pushComponentStack(this);\n\t\tglobalContext.addReactivity(() => {\n\t\t\tthis.synchronizeComponents();\n\t\t});\n\t\tglobalContext.popComponentStack();\n\t}\n\n\taddDisposable(disposable: IDisposable) {\n\t\tthis.disposables.push(disposable);\n\t}\n\n\tunmount() {\n\t\t//console.log('Unmounting ComponentList');\n\t\tthis.clear();\n\t\tthis.container = null!;\n\t\tthis.anchor = null!;\n\t\tthis.disposables.forEach((d) => {\n\t\t\td.dispose();\n\t\t});\n\t}\n}\n\n// Definimos overloads para componentList\nexport function componentList<TItem>(\n\titemFactoryFn: ItemFactoryFn<TItem, any>,\n\tkeyFn: KeyFn<TItem>\n): (listSignal: Signal<TItem[]>, props?: any) => ComponentList<TItem>;\nexport function componentList<TItem, TProps extends Dict>(\n\titemFactoryFn: ItemFactoryFn<TItem, TProps>,\n\tkeyFn: KeyFn<TItem>\n): (listSignal: Signal<TItem[]>, props: TProps) => ComponentList<TItem, TProps>;\n\nexport function componentList<TItem, TProps extends Dict = any>(itemFactoryFn: ItemFactoryFn<TItem, TProps>, keyFn: KeyFn<TItem>) {\n\treturn (listSignal: Signal<TItem[]>, props?: TProps) => {\n\t\tconst list = new ComponentList(itemFactoryFn, keyFn, listSignal, props);\n\t\treturn list;\n\t};\n}\n","import { Component, ComponentList } from './components';\nimport { globalContext } from './context';\nimport { computed, isSignal, type Signal } from './signals';\n\nexport type ChispaReactive<T> = T | Signal<T> | (() => T);\nexport type ChispaNode = string | number | Node | null;\nexport type ChispaContent = ChispaNode | ChispaNode[] | Component | Component[] | ComponentList;\nexport type ChispaContentReactive = ChispaReactive<ChispaContent>;\nexport type ChispaClasses = Record<string, ChispaReactive<boolean>>;\nexport type ChispaCSSPropertiesStrings = {\n\t[K in keyof CSSStyleDeclaration]?: ChispaReactive<string>;\n};\n\ntype AllowSignals<T> = { [K in keyof T]: T[K] | Signal<T[K]> };\n\ntype ChispaNodeBuilderBaseProps<T> = AllowSignals<Omit<Partial<T>, 'style' | 'dataset'>>;\ninterface INodeBuilderSpecialProps {\n\taddClass?: ChispaReactive<string>;\n\tclasses?: ChispaClasses;\n\tstyle?: ChispaCSSPropertiesStrings;\n\tdataset?: Record<string, ChispaReactive<string>>;\n}\ninterface INodeBuilderAdditionalProps<T, TNodes> {\n\tnodes?: TNodes;\n\tinner?: ChispaContentReactive;\n\t_ref?: (node: T) => void | { current: T | null };\n}\nexport type ChispaNodeBuilderProps<T, TNodes> = ChispaNodeBuilderBaseProps<T> & INodeBuilderAdditionalProps<T, TNodes> & INodeBuilderSpecialProps;\nexport type ChispaNodeBuilderPropsReactive<T, TNodes> = ChispaReactive<ChispaNodeBuilderProps<T, TNodes>>;\n\nconst forbiddenProps = ['nodes', 'inner', '_ref'];\n\nexport function getValidProps<T>(props: ChispaNodeBuilderProps<T, any>) {\n\tconst finalProps: any = {};\n\n\tfor (const propName in props) {\n\t\tif (forbiddenProps.indexOf(propName) === -1) {\n\t\t\tfinalProps[propName] = props[propName as keyof typeof props];\n\t\t}\n\t}\n\n\tif (props._ref !== undefined) {\n\t\t//finalProps.ref = props._ref;\n\t}\n\n\treturn finalProps as ChispaNodeBuilderProps<T, any>;\n}\n\nexport function getItem<T>(template: T, items: any, itemName: keyof T) {\n\tif (!items || !items[itemName]) {\n\t\treturn null;\n\t}\n\n\tconst item = items[itemName];\n\n\tif (item.constructor && item.constructor.name === 'Object' && !(item instanceof Element)) {\n\t\tconst Comp = template[itemName] as (props: any) => Element;\n\t\tconst itemProps = item;\n\n\t\treturn Comp(itemProps);\n\t} else {\n\t\treturn item;\n\t}\n}\n\nexport function setAttributes(node: Element, attributes: Record<string, string>) {\n\tfor (const attr in attributes) {\n\t\tconst attrValue = attributes[attr].trim();\n\t\tif (!attrValue) continue;\n\t\t//console.log('setting attr', attr, attrValue )\n\t\tnode.setAttribute(attr, attrValue);\n\t}\n}\n\nexport function setProps<T extends Element>(node: T, props: ChispaNodeBuilderPropsReactive<T, any>) {\n\tlet _props = props;\n\tif (typeof _props === 'function') {\n\t\t_props = computed(_props);\n\t}\n\tif (isSignal(_props)) {\n\t\tglobalContext.addReactivity(() => {\n\t\t\tsetProps(node, _props.get());\n\t\t});\n\t\treturn;\n\t}\n\n\tprops = getValidProps(_props);\n\n\tif (node instanceof HTMLElement) {\n\t\tsetSpecialProps(node, props);\n\t}\n\n\tfor (const prop in props) {\n\t\tconst propValue = (props as any)[prop];\n\t\t//console.log('setting prop', prop, propValue )\n\t\tif (isSignal(propValue)) {\n\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t(node as any)[prop] = propValue.get();\n\t\t\t});\n\t\t} else if (propValue === undefined) {\n\t\t\tcontinue;\n\t\t} else {\n\t\t\t(node as any)[prop] = propValue;\n\t\t}\n\t}\n}\n\nfunction setSpecialProps<T extends HTMLElement>(node: T, props: INodeBuilderSpecialProps) {\n\tif (props.style !== undefined) {\n\t\tconst style = props.style;\n\t\tfor (const styleKey in style) {\n\t\t\tlet styleValue = style[styleKey]!;\n\t\t\tif (typeof styleValue === 'function') {\n\t\t\t\tstyleValue = computed(styleValue);\n\t\t\t}\n\t\t\tif (isSignal(styleValue)) {\n\t\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t\tnode.style[styleKey] = styleValue.get();\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tnode.style[styleKey] = styleValue;\n\t\t\t}\n\t\t}\n\t\tdelete props.style;\n\t}\n\n\tif (props.addClass !== undefined) {\n\t\tlet addClass = props.addClass;\n\t\tlet prevClass: string | null = null;\n\n\t\tif (typeof addClass === 'function') {\n\t\t\taddClass = computed(addClass);\n\t\t}\n\n\t\tif (isSignal(addClass)) {\n\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\tconst cls = addClass.get();\n\t\t\t\tif (cls !== prevClass) {\n\t\t\t\t\tif (prevClass) {\n\t\t\t\t\t\tnode.classList.remove(prevClass);\n\t\t\t\t\t}\n\t\t\t\t\tnode.classList.add(cls);\n\t\t\t\t}\n\t\t\t\tprevClass = cls;\n\t\t\t});\n\t\t} else {\n\t\t\tnode.classList.add(addClass);\n\t\t}\n\t\tdelete props.addClass;\n\t}\n\n\tif (props.classes !== undefined) {\n\t\tconst classes = props.classes;\n\t\tfor (const className in classes) {\n\t\t\tlet apply = classes[className];\n\t\t\tif (typeof apply === 'function') {\n\t\t\t\tapply = computed(apply);\n\t\t\t}\n\t\t\tif (isSignal(apply)) {\n\t\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t\tif (apply.get()) {\n\t\t\t\t\t\tnode.classList.add(className);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.classList.remove(className);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tif (classes[className]) {\n\t\t\t\t\tnode.classList.add(className);\n\t\t\t\t} else {\n\t\t\t\t\tnode.classList.remove(className);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdelete props.classes;\n\t}\n\n\tif (props.dataset !== undefined) {\n\t\tconst dataset = props.dataset;\n\t\tfor (const datasetKey in dataset) {\n\t\t\tlet ds = dataset[datasetKey];\n\t\t\tif (typeof ds === 'function') {\n\t\t\t\tds = computed(ds);\n\t\t\t}\n\t\t\tif (isSignal(ds)) {\n\t\t\t\tglobalContext.addReactivity(() => {\n\t\t\t\t\tnode.dataset[datasetKey] = ds.get();\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tnode.dataset[datasetKey] = ds;\n\t\t\t}\n\t\t}\n\t\tdelete props.dataset;\n\t}\n}\n\nexport function appendChild(node: Element | DocumentFragment, child: ChispaContentReactive) {\n\tif (child === null) return;\n\tif (typeof child === 'function') {\n\t\tprocessSignalChild(node, computed(child));\n\t\treturn;\n\t}\n\tif (isSignal(child)) {\n\t\tprocessSignalChild(node, child);\n\t\treturn;\n\t}\n\tif (child instanceof Component || child instanceof ComponentList) {\n\t\tchild.mount(node, null);\n\t\treturn;\n\t}\n\tif (Array.isArray(child)) {\n\t\tchild.forEach((ch) => {\n\t\t\tappendChild(node, ch);\n\t\t});\n\t\treturn;\n\t}\n\tnode.appendChild(child instanceof Node ? child : document.createTextNode(child.toString()));\n}\n\nfunction isStaticArrayOfComponents(arr: ChispaContent): arr is Component[] {\n\tif (!Array.isArray(arr)) return false;\n\tfor (const item of arr) {\n\t\tif (!(item instanceof Component)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction processSignalChild(node: Element | DocumentFragment, child: Signal<ChispaContent>) {\n\tconst anchor = document.createTextNode('');\n\tnode.appendChild(anchor);\n\tlet prevValue: Component | ComponentList | null = null;\n\n\tglobalContext.addReactivity(() => {\n\t\t//console.log('Signal child changed', child);\n\t\tconst ch = child.get();\n\t\tif (prevValue) {\n\t\t\tprevValue.unmount();\n\t\t}\n\t\tif (ch === null) {\n\t\t\tprevValue = null;\n\t\t\treturn;\n\t\t}\n\n\t\tlet component: Component | ComponentList;\n\t\tif (isStaticArrayOfComponents(ch)) {\n\t\t\tthrow new Error('Static array of components not supported in signal children. Use ComponentList instead.');\n\t\t} else if (ch instanceof Component || ch instanceof ComponentList) {\n\t\t\tch.mount(node, anchor);\n\t\t\tcomponent = ch;\n\t\t} else {\n\t\t\tconst wrCmp = new Component(() => toNode(ch));\n\t\t\t//wrCmp.silent = true;\n\t\t\twrCmp.mount(node, anchor);\n\t\t\tcomponent = wrCmp;\n\t\t}\n\t\tprevValue = component;\n\t});\n}\n\nfunction toNode(n: ChispaNode | ChispaNode[]): Node | null {\n\tif (Array.isArray(n)) {\n\t\tconst frag = document.createDocumentFragment();\n\t\tconst nodes = n.map((c) => toNode(c)).filter((n) => n !== null);\n\t\tfrag.append(...nodes);\n\t\treturn frag;\n\t} else if (n instanceof Node) {\n\t\treturn n;\n\t} else if (typeof n === 'string' || typeof n === 'number') {\n\t\treturn document.createTextNode(n.toString());\n\t} else {\n\t\treturn null;\n\t\t//throw new Error('Invalid node type');\n\t}\n}\n","import { globalContext } from './context';\nimport { Signal, WritableSignal } from './signals';\n\nexport interface ControlledInputOptions {\n\t/**\n\t * Optional function to transform the value before setting it to the signal.\n\t * Useful for enforcing uppercase, removing invalid characters, etc.\n\t */\n\ttransform?: (value: string) => string;\n\n\t/**\n\t * Optional function to validate the value.\n\t * If it returns false, the change is rejected and the previous value is restored.\n\t */\n\tvalidate?: (value: string) => boolean;\n}\n\nexport interface SelectOption {\n\tvalue: string;\n\tlabel: string;\n}\n\nexport function bindControlledInput(element: HTMLInputElement | HTMLTextAreaElement, signal: WritableSignal<string>, options: ControlledInputOptions = {}) {\n\tconst { transform, validate } = options;\n\n\t// Initialize value\n\telement.value = signal.initialValue;\n\n\t// Handle input events\n\tconst handleInput = (e: Event) => {\n\t\tconst target = e.target as HTMLInputElement;\n\t\tlet newValue = target.value;\n\t\tconst originalValue = signal.get();\n\n\t\t// Save cursor position\n\t\tconst selectionStart = target.selectionStart;\n\t\tconst selectionEnd = target.selectionEnd;\n\n\t\t// Apply transformation if provided\n\t\tif (transform) {\n\t\t\tnewValue = transform(newValue);\n\t\t}\n\n\t\t// Apply validation if provided\n\t\tif (validate && !validate(newValue)) {\n\t\t\t// If invalid, revert to original value\n\t\t\tnewValue = originalValue;\n\t\t}\n\n\t\t// Update signal\n\t\tif (newValue !== originalValue) {\n\t\t\tsignal.set(newValue);\n\t\t}\n\n\t\t// Force update DOM if it doesn't match the new value (e.g. transformed or rejected)\n\t\tif (target.value !== newValue) {\n\t\t\tconst lengthDiff = target.value.length - newValue.length;\n\t\t\ttarget.value = newValue;\n\n\t\t\t// Restore cursor\n\t\t\tif (selectionStart !== null && selectionEnd !== null) {\n\t\t\t\t// Restore to the saved position.\n\t\t\t\t// Adjust for length difference to keep cursor relative to the content\n\t\t\t\tconst newStart = Math.max(0, selectionStart - lengthDiff);\n\t\t\t\tconst newEnd = Math.max(0, selectionEnd - lengthDiff);\n\t\t\t\ttarget.setSelectionRange(newStart, newEnd);\n\t\t\t}\n\t\t}\n\t};\n\n\telement.addEventListener('input', handleInput);\n\n\t// Subscribe to signal changes to update the input if it changes externally\n\tglobalContext.addReactivity(() => {\n\t\tconst newValue = signal.get();\n\t\t// Only update if the value is actually different to avoid cursor jumping\n\t\tif (element.value !== newValue) {\n\t\t\telement.value = newValue;\n\t\t}\n\t});\n\n\t// Return a cleanup function\n\treturn () => {\n\t\telement.removeEventListener('input', handleInput);\n\t};\n}\n\nexport function bindControlledSelect(element: HTMLSelectElement, signal: WritableSignal<string>, optionsSignal?: Signal<SelectOption[]>) {\n\t// Function to update options\n\tconst updateOptions = (options: SelectOption[]) => {\n\t\t// Clear existing options\n\t\telement.innerHTML = '';\n\t\t// Add new options\n\t\toptions.forEach((option) => {\n\t\t\tconst optElement = document.createElement('option');\n\t\t\toptElement.value = option.value;\n\t\t\toptElement.textContent = option.label;\n\t\t\telement.appendChild(optElement);\n\t\t});\n\t\t// Ensure the current value is set\n\t\telement.value = signal.get();\n\t};\n\n\t// Initialize options if provided\n\tif (optionsSignal) {\n\t\tupdateOptions(optionsSignal.get());\n\t}\n\n\t// Initialize value\n\telement.value = signal.initialValue;\n\n\t// Handle change events\n\tconst handleChange = (e: Event) => {\n\t\tconst target = e.target as HTMLSelectElement;\n\t\tlet newValue = target.value;\n\t\tconst originalValue = signal.get();\n\n\t\t// Update signal\n\t\tif (newValue !== originalValue) {\n\t\t\tsignal.set(newValue);\n\t\t}\n\n\t\t// Force update DOM if it doesn't match the new value (e.g. transformed or rejected)\n\t\tif (target.value !== newValue) {\n\t\t\ttarget.value = newValue;\n\t\t}\n\t};\n\n\telement.addEventListener('change', handleChange);\n\n\t// Subscribe to signal changes to update the select if it changes externally\n\tglobalContext.addReactivity(() => {\n\t\tconst newValue = signal.get();\n\t\t// Only update if the value is actually different\n\t\tif (element.value !== newValue) {\n\t\t\telement.value = newValue;\n\t\t}\n\t});\n\n\t// Subscribe to options signal changes if provided\n\tif (optionsSignal) {\n\t\tglobalContext.addReactivity(() => {\n\t\t\tupdateOptions(optionsSignal.get());\n\t\t});\n\t}\n\n\t// Return a cleanup function\n\treturn () => {\n\t\telement.removeEventListener('change', handleChange);\n\t};\n}\n","import { signal, computed, Signal } from './signals';\nimport { component, Component, Dict } from './components';\nimport { appendChild, ChispaNodeBuilderProps, setProps } from './builder';\n\nexport interface Route {\n\tpath: string;\n\tcomponent: (props?: any) => Component<any>;\n}\n\nconst currentPath = signal(typeof window !== 'undefined' ? window.location.pathname : '/');\n\nif (typeof window !== 'undefined') {\n\twindow.addEventListener('popstate', () => {\n\t\tcurrentPath.set(window.location.pathname);\n\t});\n}\n\nexport function navigate(to: string, replace = false) {\n\tif (typeof window === 'undefined') {\n\t\tcurrentPath.set(to);\n\t\treturn;\n\t}\n\tif (replace) {\n\t\twindow.history.replaceState({}, '', to);\n\t} else {\n\t\twindow.history.pushState({}, '', to);\n\t}\n\tcurrentPath.set(to);\n}\n\nexport function pathMatches(path: string): Signal<boolean> {\n\treturn computed(() => {\n\t\tconst current = currentPath.get();\n\t\treturn match(path, current) !== null;\n\t});\n}\n\nfunction match(routePath: string, currentPath: string): Dict | null {\n\tif (routePath === '*') return {};\n\tconst routeParts = routePath.split('/').filter(Boolean);\n\tconst currentParts = currentPath.split('/').filter(Boolean);\n\tif (routeParts.length !== currentParts.length) return null;\n\tconst params: Dict = {};\n\tfor (let i = 0; i < routeParts.length; i++) {\n\t\tif (routeParts[i].startsWith(':')) {\n\t\t\tparams[routeParts[i].substring(1)] = currentParts[i];\n\t\t} else if (routeParts[i] !== currentParts[i]) {\n\t\t\treturn null;\n\t\t}\n\t}\n\treturn params;\n}\n\nexport const Router = component<{ routes: Route[] }>((props) => {\n\tconst container = document.createElement('div');\n\tcontainer.style.display = 'contents';\n\tconst activeRoute = computed(() => {\n\t\tconst path = currentPath.get();\n\t\tfor (const route of props.routes) {\n\t\t\tconst params = match(route.path, path);\n\t\t\tif (params) {\n\t\t\t\treturn route.component(params);\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t});\n\tappendChild(container, activeRoute);\n\treturn container;\n});\n\nexport interface LinkProps extends ChispaNodeBuilderProps<HTMLAnchorElement, {}> {\n\tto: string;\n}\n\nexport const Link = component<LinkProps>((props) => {\n\tconst { to, inner, ...rest } = props;\n\tconst a = document.createElement('a');\n\ta.href = to;\n\n\ta.addEventListener('click', (e) => {\n\t\tif (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.defaultPrevented || e.button !== 0) {\n\t\t\treturn;\n\t\t}\n\t\te.preventDefault();\n\t\tnavigate(to);\n\t});\n\n\tif (inner) {\n\t\tappendChild(a, inner);\n\t}\n\n\tsetProps(a, rest);\n\n\treturn a;\n});\n"],"mappings":";AASA,IAAM,aAAN,MAAiB;AAAA,EACR,yBAAuC,CAAC;AAAA,EAExC,iBAAsB;AAAA;AAAA,EAItB,oBAAoB,oBAAI,IAAgB;AAAA,EAExC,iBAAkC,CAAC;AAAA,EAEnC,iBAAgD,CAAC;AAAA,EAEzD,mBAAmB,KAAgC;AAClD,SAAK,eAAe,KAAK,GAAG;AAAA,EAC7B;AAAA,EAEA,oBAAoB;AACnB,SAAK,eAAe,IAAI;AAAA,EACzB;AAAA,EAEA,sBAAsB;AACrB,QAAI,KAAK,eAAe,WAAW,GAAG;AAErC,aAAO;AAAA,IACR;AACA,WAAO,KAAK,eAAe,KAAK,eAAe,SAAS,CAAC;AAAA,EAC1D;AAAA,EAEA,4BAA4B,SAAqB;AAChD,SAAK,uBAAuB,KAAK,OAAO;AAAA,EAEzC;AAAA,EAEA,mCAAmC;AAClC,SAAK,uBAAuB,IAAI;AAAA,EACjC;AAAA,EAEA,0BAA0B;A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