import type { Subscription } from "@akala/core"; import type { Composer } from "../template.js"; import { DataContext } from "./context.js"; import { AttributeComposer } from "./shared.js"; export class IfComposer> extends AttributeComposer implements Composer { getContext(item: HTMLElement, options?: T) { return DataContext.find(item); } constructor() { super('if'); this.allowSubProperties = false; } optionName = 'controller'; applyInternal(item: HTMLElement, options: T, event: TKey, value: unknown): Subscription | void { const beacon = item['replacedWith'] || document.createTextNode(''); if (!value) { if (!item['replacedWith']) { item.replaceWith(beacon); item['replacedWith'] = beacon } } else if (beacon.parentElement) beacon.replaceWith(item); } }