enigmatic 0.32.0 → 0.33.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "enigmatic",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "unpkg": "./public/client.js",
5
5
  "scripts": {
6
6
  "start": "bun --hot ./bun-server.js",
package/public/client.js CHANGED
@@ -3,7 +3,11 @@ const D = document, W = window, Enc = encodeURIComponent;
3
3
  // 1. Unified Render Logic (Handles both State & Custom Elements)
4
4
  const ren = async (el, v) => {
5
5
  const f = W.custom?.[el.tagName.toLowerCase()];
6
- if (f) try { el.innerHTML = await (f.render || f)(v) } catch(e) { console.error(e) }
6
+ if (f) {
7
+ const dataAttr = el.getAttribute('data');
8
+ const val = v !== undefined ? v : (dataAttr ? W.state[dataAttr] : undefined);
9
+ try { el.innerHTML = await (f.render || f)(val) } catch(e) { console.error(e) }
10
+ }
7
11
  };
8
12
 
9
13
  // 2. Proxies setup
@@ -51,12 +55,26 @@ Object.assign(W, {
51
55
  a.click();
52
56
  URL.revokeObjectURL(a.href);
53
57
  },
54
- initCustomElements: () => Object.keys(W.custom).forEach(t => W.$$(t).forEach(el => ren(el)))
58
+ initCustomElements: () => Object.keys(W.custom || {}).forEach(t => W.$$(t).forEach(el => ren(el)))
55
59
  });
56
60
 
57
61
  // 4. Initialization & Observers
58
62
  const boot = () => {
59
63
  W.initCustomElements();
60
- new MutationObserver(W.initCustomElements).observe(D.body, { childList: true, subtree: true });
64
+ new MutationObserver((mutations) => {
65
+ mutations.forEach(m => {
66
+ m.addedNodes.forEach(node => {
67
+ if (node.nodeType === 1) { // Element node
68
+ const tag = node.tagName?.toLowerCase();
69
+ if (tag && W.custom?.[tag]) ren(node);
70
+ // Also check children
71
+ node.querySelectorAll && Array.from(node.querySelectorAll('*')).forEach(child => {
72
+ const childTag = child.tagName?.toLowerCase();
73
+ if (childTag && W.custom?.[childTag]) ren(child);
74
+ });
75
+ }
76
+ });
77
+ });
78
+ }).observe(D.body, { childList: true, subtree: true });
61
79
  };
62
80
  D.readyState === 'loading' ? D.addEventListener('DOMContentLoaded', boot) : boot();
@@ -1,8 +1,9 @@
1
- <script src='https://unpkg.com/enigmatic@0.32.0/public/client.js'></script>
1
+ <script src='client.js'></script>
2
2
 
3
3
  <script>
4
4
  window.api_url = 'http://localhost:3000';
5
5
  custom.hw = (data) => `Hello ${data}`;
6
+ state.message = "World";
6
7
  </script>
7
8
 
8
- <hw></hw>
9
+ <hw data="message"></hw>