@jasonshimmy/custom-elements-runtime 0.0.9-beta.4 → 0.0.9

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.
@@ -1,4 +1,4 @@
1
- function j(e) {
1
+ function N(e) {
2
2
  let t = new Proxy(e, {
3
3
  set: (i, a, c) => (i[a] = c, s(), !0)
4
4
  });
@@ -161,7 +161,7 @@ function Z(e, t = {}) {
161
161
  const r = e.state, n = G(r), o = e.template(r, n);
162
162
  let s = "";
163
163
  t.includeStyles && e.style && (s = `<style>${typeof e.style == "function" ? e.style(r) : e.style}</style>`);
164
- const i = t.sanitizeAttributes ? t.sanitizeAttributes(e.attrs || {}) : e.attrs || {}, a = Object.entries(i).map(([u, d]) => `${N(u)}="${N(d)}"`).join(" "), l = `${a ? `<${e.tag} ${a}>` : `<${e.tag}>`}${s}${o}</${e.tag}>`;
164
+ const i = t.sanitizeAttributes ? t.sanitizeAttributes(e.attrs || {}) : e.attrs || {}, a = Object.entries(i).map(([u, d]) => `${D(u)}="${D(d)}"`).join(" "), l = `${a ? `<${e.tag} ${a}>` : `<${e.tag}>`}${s}${o}</${e.tag}>`;
165
165
  return t.prettyPrint ? V(l) : l;
166
166
  } catch (r) {
167
167
  return console.error(`[SSR] Error rendering ${e.tag}:`, r), `<${e.tag}><div style="color: red;">SSR Error: ${X(String(r))}</div></${e.tag}>`;
@@ -225,27 +225,27 @@ function lt(e) {
225
225
  }
226
226
  <\/script>`.trim();
227
227
  }
228
- const X = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), N = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), V = (e) => e.replace(/></g, `>
228
+ const X = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), D = (e) => e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), V = (e) => e.replace(/></g, `>
229
229
  <`).split(`
230
230
  `).map((t) => {
231
231
  const r = (t.match(/^<[^\/]/g) || []).length - (t.match(/<\//g) || []).length;
232
232
  return " ".repeat(Math.max(0, r)) + t.trim();
233
233
  }).join(`
234
234
  `);
235
- function D(e) {
235
+ function I(e) {
236
236
  return String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
237
237
  }
238
238
  function L(e, t) {
239
239
  if (typeof e != "string" || !t) return String(e);
240
240
  for (const r in t) {
241
241
  if (typeof t[r] == "string" && e === t[r])
242
- return D(e);
242
+ return I(e);
243
243
  if (Array.isArray(t[r])) {
244
244
  for (const n of t[r])
245
245
  if (n && typeof n == "object") {
246
246
  for (const o in n)
247
247
  if (typeof n[o] == "string" && e === n[o])
248
- return D(e);
248
+ return I(e);
249
249
  }
250
250
  }
251
251
  }
@@ -352,7 +352,7 @@ function J(e, t, r) {
352
352
  };
353
353
  e.addEventListener("input", i), e.addEventListener("change", i), e.addEventListener("keydown", i), e.addEventListener("blur", i);
354
354
  }
355
- const x = (() => {
355
+ const j = (() => {
356
356
  try {
357
357
  if (typeof process < "u" && process.env)
358
358
  return process.env.NODE_ENV === "development";
@@ -361,7 +361,7 @@ const x = (() => {
361
361
  return typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" : !1;
362
362
  })();
363
363
  function ht(e, t = {}) {
364
- const { development: r = x, cache: n = !0, optimize: o = !0 } = t, s = F(e);
364
+ const { development: r = j, cache: n = !0, optimize: o = !0 } = t, s = K(e);
365
365
  if (n && S.has(s)) {
366
366
  if (r) {
367
367
  const i = v.get(s) || {
@@ -421,7 +421,7 @@ function Q(e, t) {
421
421
  const s = new DOMParser().parseFromString(`<div>${e}</div>`, "text/html").body.firstElementChild;
422
422
  return r(s) || [0];
423
423
  } catch (r) {
424
- return x && console.warn("[Template Compiler] Error finding DOM path for placeholder:", t, r), [0];
424
+ return j && console.warn("[Template Compiler] Error finding DOM path for placeholder:", t, r), [0];
425
425
  }
426
426
  }
427
427
  function tt(e, t) {
@@ -437,7 +437,7 @@ class et {
437
437
  }
438
438
  compile() {
439
439
  this.parseTemplate();
440
- const t = this.createStaticFragment(), r = F(this.template), n = (o, s) => {
440
+ const t = this.createStaticFragment(), r = K(this.template), n = (o, s) => {
441
441
  let i = "";
442
442
  for (let a = 0; a < this.statics.length; a++)
443
443
  if (i += this.statics[a], a < this.dynamics.length) {
@@ -544,7 +544,7 @@ function R(e, t) {
544
544
  return null;
545
545
  }
546
546
  }
547
- function I(e, t, r) {
547
+ function P(e, t, r) {
548
548
  let n;
549
549
  return e.fragment && !e.hasDynamics ? n = e.fragment.cloneNode(!0) : n = nt(e, t, r), n;
550
550
  }
@@ -555,7 +555,7 @@ function rt(e, t, r, n, o) {
555
555
  const i = s.getValue(r, n);
556
556
  if (o !== void 0 && s.getValue(o, n) === i)
557
557
  continue;
558
- W(t, s, i);
558
+ F(t, s, i);
559
559
  } catch (i) {
560
560
  console.warn("[Template Compiler] Error applying update:", i);
561
561
  }
@@ -577,11 +577,11 @@ function nt(e, t, r) {
577
577
  i.appendChild(s.body.firstChild);
578
578
  for (const a of e.dynamics) {
579
579
  const c = a.getValue(t, r), l = R(i, a.path);
580
- W(l, a, c);
580
+ F(l, a, c);
581
581
  }
582
582
  return i;
583
583
  }
584
- function W(e, t, r) {
584
+ function F(e, t, r) {
585
585
  try {
586
586
  if (t.type === "text") {
587
587
  const o = document.createTreeWalker(
@@ -630,11 +630,11 @@ function W(e, t, r) {
630
630
  throw new Error(`Unknown update type: ${t.type}`);
631
631
  }
632
632
  } catch (n) {
633
- (typeof globalThis < "u" ? globalThis.isDevelopment : x) && console.warn("[Template Compiler] Error applying update:", t, n);
633
+ (typeof globalThis < "u" ? globalThis.isDevelopment : j) && console.warn("[Template Compiler] Error applying update:", t, n);
634
634
  }
635
635
  }
636
636
  const S = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map();
637
- function F(e) {
637
+ function K(e) {
638
638
  let t = 0;
639
639
  for (let r = 0; r < e.length; r++) {
640
640
  const n = e.charCodeAt(r);
@@ -642,10 +642,10 @@ function F(e) {
642
642
  }
643
643
  return `tpl_${Math.abs(t).toString(36)}`;
644
644
  }
645
- function P(e, t, r, n, o) {
645
+ function q(e, t, r, n, o) {
646
646
  return n && o ? `${t}.${e}[${r}]:${n}:${o}` : n ? `${t}.${e}[${r}]:${n}` : `${t}.${e}[${r}]`;
647
647
  }
648
- function q(e, t, r) {
648
+ function z(e, t, r) {
649
649
  if (!(!e || !(e instanceof Element)) && e.contains(r) && r.parentNode === e)
650
650
  try {
651
651
  e.replaceChild(t, r);
@@ -693,7 +693,7 @@ function $(e, t = "", r = 0) {
693
693
  if (!e)
694
694
  return { type: "#unknown", key: void 0, props: {}, children: [], dom: void 0 };
695
695
  if (e.nodeType === Node.TEXT_NODE)
696
- return !e.nodeValue || /^\s*$/.test(e.nodeValue) ? { type: "#whitespace", key: void 0, props: {}, children: [], dom: void 0 } : { type: "#text", key: P("#text", t, r), props: { nodeValue: e.nodeValue }, children: [], dom: e };
696
+ return !e.nodeValue || /^\s*$/.test(e.nodeValue) ? { type: "#whitespace", key: void 0, props: {}, children: [], dom: void 0 } : { type: "#text", key: q("#text", t, r), props: { nodeValue: e.nodeValue }, children: [], dom: e };
697
697
  if (e.nodeType === Node.ELEMENT_NODE) {
698
698
  const n = e, o = {};
699
699
  Array.from(n.attributes).forEach((l) => {
@@ -706,7 +706,7 @@ function $(e, t = "", r = 0) {
706
706
  i = `${s}:${l}:${u}`, o["data-uid"] = i, n.setAttribute("data-uid", i);
707
707
  let d = n.getAttribute("value"), f = n.getAttribute("checked");
708
708
  d && (o.value = d), f && (o.checked = f);
709
- } else s === "input" || s === "textarea" || s === "select" || n.hasAttribute("contenteditable") ? (i = `${s}:${t}:${r}`, o["data-uid"] = i, n.setAttribute("data-uid", i)) : (i = P(s, t, r), s === "li" && (o["data-uid"] = i, n.setAttribute("data-uid", i)));
709
+ } else s === "input" || s === "textarea" || s === "select" || n.hasAttribute("contenteditable") ? (i = `${s}:${t}:${r}`, o["data-uid"] = i, n.setAttribute("data-uid", i)) : (i = q(s, t, r), s === "li" && (o["data-uid"] = i, n.setAttribute("data-uid", i)));
710
710
  const a = Array.from(n.childNodes).map((l, u) => $(l, i, u));
711
711
  return {
712
712
  type: s,
@@ -727,7 +727,7 @@ function M(e, t, r) {
727
727
  if (t.type !== r.type || t.key !== r.key) {
728
728
  const c = g(r);
729
729
  if (c instanceof Node && t.dom instanceof Node && e.contains(t.dom)) {
730
- if (q(e, c, t.dom), i && r.props && e.firstChild instanceof HTMLInputElement) {
730
+ if (z(e, c, t.dom), i && r.props && e.firstChild instanceof HTMLInputElement) {
731
731
  const l = e.firstChild;
732
732
  l.type === "radio" || l.type, l.value = r.props.value, l.setAttribute("value", r.props.value), "checked" in r.props && (l.checked = r.props.checked === !0 || r.props.checked === "true");
733
733
  }
@@ -785,7 +785,7 @@ function M(e, t, r) {
785
785
  a.nodeValue !== r.props.nodeValue && (a.nodeValue = r.props.nodeValue), r.dom = a;
786
786
  else {
787
787
  const c = document.createTextNode(r.props.nodeValue ?? "");
788
- a && e.contains(a) && a.parentNode === e ? q(e, c, a) : e.appendChild(c), r.dom = c;
788
+ a && e.contains(a) && a.parentNode === e ? z(e, c, a) : e.appendChild(c), r.dom = c;
789
789
  }
790
790
  return;
791
791
  }
@@ -869,7 +869,7 @@ function at(e) {
869
869
  return { path: f, query: h };
870
870
  }, o = n();
871
871
  const u = b(t, o.path);
872
- s = j({
872
+ s = N({
873
873
  path: o.path,
874
874
  params: u.params,
875
875
  query: o.query
@@ -884,7 +884,7 @@ function at(e) {
884
884
  } else {
885
885
  n = () => ({ path: "/", query: {} }), o = n();
886
886
  const u = b(t, o.path);
887
- s = j({
887
+ s = N({
888
888
  path: o.path,
889
889
  params: u.params,
890
890
  query: o.query
@@ -965,8 +965,8 @@ function _(e, t = /* @__PURE__ */ new WeakSet()) {
965
965
  function O(e) {
966
966
  return !!e && typeof e.then == "function";
967
967
  }
968
- let K;
969
- typeof HTMLElement < "u" && (K = class extends HTMLElement {
968
+ let x;
969
+ typeof HTMLElement < "u" ? x = class extends HTMLElement {
970
970
  /**
971
971
  * Syncs whitelisted state properties to attributes after render.
972
972
  * Only keys listed in config.reflect are reflected.
@@ -1376,13 +1376,13 @@ typeof HTMLElement < "u" && (K = class extends HTMLElement {
1376
1376
  } else {
1377
1377
  const r = !this.shadowRoot.firstElementChild, n = this.lastCompiledTemplate?.id === e.id;
1378
1378
  if (r) {
1379
- const o = I(e, this.stateObj, this.api);
1379
+ const o = P(e, this.stateObj, this.api);
1380
1380
  this.shadowRoot.appendChild(o);
1381
1381
  } else if (n && this.shadowRoot.firstElementChild) {
1382
1382
  const o = this.lastState;
1383
1383
  rt(e, this.shadowRoot.firstElementChild, this.stateObj, this.api, o || void 0);
1384
1384
  } else {
1385
- const o = I(e, this.stateObj, this.api);
1385
+ const o = P(e, this.stateObj, this.api);
1386
1386
  let s = this.shadowRoot.querySelector("style");
1387
1387
  s || (s = document.createElement("style"), this.shadowRoot.insertBefore(s, this.shadowRoot.firstChild)), this.config.style ? s.textContent = typeof this.config.style == "function" ? this.config.style(this.stateObj) : this.config.style : s.textContent = "";
1388
1388
  let i = this.shadowRoot.querySelector("[data-root]");
@@ -1490,8 +1490,12 @@ typeof HTMLElement < "u" && (K = class extends HTMLElement {
1490
1490
  </div>
1491
1491
  `;
1492
1492
  }
1493
- });
1494
- function z(e, t) {
1493
+ } : x = class {
1494
+ // No-op for SSR, just a stub
1495
+ constructor() {
1496
+ }
1497
+ };
1498
+ function W(e, t) {
1495
1499
  if (t = _(t), t.debug && console.log(`[runtime] Debugging component: ${e}`, t), !e || !t.template) {
1496
1500
  t && typeof t.onError == "function" && t.onError(new Error("Component requires tag and template"), t.state ?? {}, {
1497
1501
  state: t.state ?? {},
@@ -1536,7 +1540,7 @@ function z(e, t) {
1536
1540
  const i = t.state ?? {}, a = Object.keys(i).filter(
1537
1541
  (u) => ["string", "number", "boolean"].includes(typeof i[u])
1538
1542
  );
1539
- class c extends K {
1543
+ class c extends x {
1540
1544
  static get observedAttributes() {
1541
1545
  return a;
1542
1546
  }
@@ -1549,7 +1553,7 @@ function z(e, t) {
1549
1553
  }
1550
1554
  function yt(e) {
1551
1555
  const t = at(e);
1552
- return z("router-view", {
1556
+ return W("router-view", {
1553
1557
  template: async () => {
1554
1558
  if (!t) return "<div>Router not initialized.</div>";
1555
1559
  const r = t.getCurrent(), { path: n } = r, o = t.matchRoute(n);
@@ -1560,7 +1564,7 @@ function yt(e) {
1560
1564
  n.render();
1561
1565
  });
1562
1566
  }
1563
- }), z("router-link", {
1567
+ }), W("router-link", {
1564
1568
  state: {
1565
1569
  to: "",
1566
1570
  tag: "a",
@@ -1639,17 +1643,17 @@ function yt(e) {
1639
1643
  }), t;
1640
1644
  }
1641
1645
  export {
1642
- j as Store,
1646
+ N as Store,
1643
1647
  dt as classes,
1644
1648
  ut as compile,
1645
1649
  ht as compileTemplate,
1646
- z as component,
1650
+ W as component,
1647
1651
  $ as createVNodeFromElement,
1648
1652
  Y as css,
1649
1653
  _ as deepSanitizeObject,
1650
1654
  w as eventBus,
1651
1655
  lt as generateHydrationScript,
1652
- P as getVNodeKey,
1656
+ q as getVNodeKey,
1653
1657
  T as html,
1654
1658
  yt as initRouter,
1655
1659
  O as isPromise,
@@ -1657,12 +1661,12 @@ export {
1657
1661
  g as mountVNode,
1658
1662
  st as parseVNodeFromHTML,
1659
1663
  M as patchVNode,
1660
- I as renderCompiledTemplate,
1664
+ P as renderCompiledTemplate,
1661
1665
  ct as renderComponentsToString,
1662
1666
  Z as renderToString,
1663
1667
  ot as resolveRouteComponent,
1664
1668
  A as runtimePlugins,
1665
- q as safeReplaceChild,
1669
+ z as safeReplaceChild,
1666
1670
  ft as styles,
1667
1671
  rt as updateCompiledTemplate,
1668
1672
  J as useDataModel,