From 02582cc490fc0d753dd153211cc172eb28fbee5d Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 5 Oct 2026 15:33:46 +0200 Subject: first sketch of wasm environment --- src/z/z.js | 101 ------------------------------------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 src/z/z.js (limited to 'src/z/z.js') diff --git a/src/z/z.js b/src/z/z.js deleted file mode 100644 index e279f42..0000000 --- a/src/z/z.js +++ /dev/null @@ -1,101 +0,0 @@ -class ZComponent extends HTMLElement { - static observedAttributes = [ 'type' ]; - - constructor() { - super(); - this.attachShadow({ mode: 'open' }); - this.onconnected = () => {}; - this.ondisconnected = () => {}; - } - - build() { - const type = this.getAttribute('type'); - - if (type == null) { - throw `component without any type given.`; - } - - const template = document.getElementById(`@${type}`); - - if (template == null) { - throw `component '${type}' does not exist.`; - } - - const node = document.importNode(template.content, true); - this.shadowRoot.appendChild(node); - - Zenv.constructors[`component__${type}`](new Zenv(this)); - } - - attributeChangedCallback(name, previous, current) { - if (name == 'type') { - this.shadowRoot.innerHTML = ''; - this.build() - } - } - - connectedCallback() { - this.onconnected(); - } - - disconnectedCallback() { - this.ondisconnected(); - } -} - -class Zenv { - static constructors = {}; - - constructor(doc) { - this.document = doc; - } - - component(type, slots) { - const element = document.createElement('z-component'); - element.setAttribute('type', type); - - for (const name in slots) { - const slot = slots[name]; - slot.setAttribute('slot', name); - element.appendChild(slot); - } - - return element; - } - - populate_attributes(obj, attrs) { - for (const attr in attrs) { - if (typeof(obj[attr]) == 'object' && typeof(attrs[attr]) == 'object') { - this.populate_attributes(obj[attr], attrs[attr]); - } else { - obj[attr] = attrs[attr]; - } - } - } - - native(name, options) { - const element = document.createElement(name); - this.populate_attributes(element, options); - return element; - } - - by_id(id) { - return this.document.shadowRoot.getElementById(id); - } - - by_selector(query) { - return this.document.shadowRoot.querySelector(query); - } - - by_selector_all(query) { - return this.document.shadowRoot.querySelectorAll(query); - } - - get body() { - return this.document.shadowRoot; - } -} - -Z = new Zenv(document.body); - -customElements.define("z-component", ZComponent); -- cgit v1.2.3-70-g09d2