// JQHTML v2 Template Integration // Connects compiled templates to Component class /// import { process_instructions, html, register_template } from './runtime.js'; // Mixin to add template support to any component export function with_template(ComponentClass, template_name) { const original_on_render = ComponentClass.prototype.on_render; ComponentClass.prototype.on_render = async function () { // Get compiled template from registry const global_obj = typeof window !== 'undefined' ? window : global; const template_map = global_obj.jqhtml_components; if (!template_map || !template_map.has(template_name)) { throw new Error(`Template not found: ${template_name}`); } const template_info = template_map.get(template_name); const render_fn = template_info.render; // Call render function with component context const [instructions] = render_fn.call(this, this.constructor, this.data, this.args, {}); // Process instructions into DOM const rendered = process_instructions(instructions, this); // Clear and append to component element this.$.empty().append(rendered); // Call original on_render if it exists if (original_on_render) { await original_on_render.call(this); } }; return ComponentClass; } // Register templates from compiled module export function register_compiled_templates(template_map) { // Store on global object for now (MVP approach) const global_obj = typeof window !== 'undefined' ? window : global; global_obj.jqhtml_components = template_map; // Also register each template for (const [name, info] of template_map) { register_template(name, info.render); } } // Make html function available globally for templates if (typeof window !== 'undefined') { window.html = html; } else if (typeof global !== 'undefined') { global.html = html; } //# sourceMappingURL=integration.js.map