@jasonshimmy/custom-elements-runtime 0.0.9 → 0.0.10

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.
@@ -138,8 +138,8 @@ class y extends EventTarget {
138
138
  this.eventCounters.clear();
139
139
  }
140
140
  }
141
- const w = y.getInstance(), B = typeof window > "u" || typeof document > "u";
142
- function G(e) {
141
+ const w = y.getInstance(), G = typeof window > "u" || typeof document > "u";
142
+ function Z(e) {
143
143
  return {
144
144
  state: e,
145
145
  emit: () => {
@@ -155,19 +155,19 @@ function G(e) {
155
155
  }
156
156
  };
157
157
  }
158
- function Z(e, t = {}) {
159
- B || console.warn("[SSR] renderToString should only be used on the server");
158
+ function V(e, t = {}) {
159
+ G || console.warn("[SSR] renderToString should only be used on the server");
160
160
  try {
161
- const r = e.state, n = G(r), o = e.template(r, n);
161
+ const r = e.state, n = Z(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
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
- return t.prettyPrint ? V(l) : l;
165
+ return t.prettyPrint ? Y(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}>`;
168
168
  }
169
169
  }
170
- function ct(e, t = {}) {
170
+ function lt(e, t = {}) {
171
171
  const r = {
172
172
  components: /* @__PURE__ */ new Map(),
173
173
  styles: /* @__PURE__ */ new Set()
@@ -177,7 +177,7 @@ function ct(e, t = {}) {
177
177
  const c = typeof i.style == "function" ? i.style(i.state) : i.style;
178
178
  r.styles.add(c);
179
179
  }
180
- const a = Z(i, { ...t, includeStyles: !1 });
180
+ const a = V(i, { ...t, includeStyles: !1 });
181
181
  n.push(a);
182
182
  });
183
183
  const o = Array.from(r.styles).join(`
@@ -185,7 +185,7 @@ function ct(e, t = {}) {
185
185
  return { html: n.join(`
186
186
  `), styles: o, context: r };
187
187
  }
188
- function lt(e) {
188
+ function ut(e) {
189
189
  const t = Array.from(e.components.entries()).map(([r, n]) => ({
190
190
  tag: r,
191
191
  state: n.state
@@ -225,13 +225,16 @@ 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;"), D = (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;"), Y = (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 F(e) {
236
+ return typeof e != "string" ? String(e) : /expression\s*\(|url\s*\(\s*['"]?javascript:/i.test(e) ? "" : e.replace(/[\u0000-\u001F\u007F-\u009F]/g, "").replace(/<|>|"|'|`|;/g, "");
237
+ }
235
238
  function I(e) {
236
239
  return String(e).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
237
240
  }
@@ -284,7 +287,7 @@ function T(e, ...t) {
284
287
  }) : s;
285
288
  };
286
289
  }
287
- function ut(e, ...t) {
290
+ function dt(e, ...t) {
288
291
  const r = "compiled-" + Math.random().toString(36).slice(2);
289
292
  function n(s, i, a) {
290
293
  return Array.isArray(s) ? s.map((c) => n(c, i, a)).join("") : typeof s == "function" ? n(s(i, a), i, a) : s == null ? "" : String(s);
@@ -301,19 +304,22 @@ function ut(e, ...t) {
301
304
  };
302
305
  return o.id = r, o;
303
306
  }
304
- function Y(e, ...t) {
307
+ function J(e, ...t) {
305
308
  let r = "";
306
309
  for (let n = 0; n < e.length; n++)
307
- r += e[n], n < t.length && (r += t[n] ?? "");
310
+ r += e[n], n < t.length && (r += F(t[n]));
308
311
  return r;
309
312
  }
310
- function dt(e) {
313
+ function ft(e) {
311
314
  return Object.keys(e).filter((t) => e[t]).join(" ");
312
315
  }
313
- function ft(e) {
314
- return Object.entries(e).map(([t, r]) => `${t}: ${r}`).join("; ");
316
+ function ht(e) {
317
+ return Object.entries(e).map(([t, r]) => {
318
+ const n = t.replace(/[^a-zA-Z0-9\-]/g, ""), o = typeof r == "string" ? F(r) : r;
319
+ return `${n}: ${o}`;
320
+ }).join("; ");
315
321
  }
316
- function J(e, t, r) {
322
+ function Q(e, t, r) {
317
323
  const [n, ...o] = r.split("|").map((a) => a.trim());
318
324
  if (!n || n === "__proto__" || n === "constructor" || n === "prototype") return;
319
325
  function s(a, c, l) {
@@ -360,8 +366,8 @@ const j = (() => {
360
366
  }
361
367
  return typeof window < "u" ? window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" : !1;
362
368
  })();
363
- function ht(e, t = {}) {
364
- const { development: r = j, cache: n = !0, optimize: o = !0 } = t, s = K(e);
369
+ function pt(e, t = {}) {
370
+ const { development: r = j, cache: n = !0, optimize: o = !0 } = t, s = U(e);
365
371
  if (n && S.has(s)) {
366
372
  if (r) {
367
373
  const i = v.get(s) || {
@@ -386,7 +392,7 @@ function ht(e, t = {}) {
386
392
  i.cacheMisses++, v.set(s, i);
387
393
  }
388
394
  try {
389
- const i = tt(e, { development: r, optimize: o });
395
+ const i = et(e, { development: r, optimize: o });
390
396
  return n && S.set(s, i), i;
391
397
  } catch (i) {
392
398
  return r && (console.error("[Template Compiler] Error compiling template:", i), console.error("[Template Compiler] Template:", e)), {
@@ -399,7 +405,7 @@ function ht(e, t = {}) {
399
405
  };
400
406
  }
401
407
  }
402
- function Q(e, t) {
408
+ function tt(e, t) {
403
409
  if (typeof document > "u")
404
410
  return [0];
405
411
  try {
@@ -424,10 +430,10 @@ function Q(e, t) {
424
430
  return j && console.warn("[Template Compiler] Error finding DOM path for placeholder:", t, r), [0];
425
431
  }
426
432
  }
427
- function tt(e, t) {
428
- return new et(e, t).compile();
433
+ function et(e, t) {
434
+ return new rt(e, t).compile();
429
435
  }
430
- class et {
436
+ class rt {
431
437
  template;
432
438
  options;
433
439
  dynamics = [];
@@ -437,7 +443,7 @@ class et {
437
443
  }
438
444
  compile() {
439
445
  this.parseTemplate();
440
- const t = this.createStaticFragment(), r = K(this.template), n = (o, s) => {
446
+ const t = this.createStaticFragment(), r = U(this.template), n = (o, s) => {
441
447
  let i = "";
442
448
  for (let a = 0; a < this.statics.length; a++)
443
449
  if (i += this.statics[a], a < this.dynamics.length) {
@@ -488,7 +494,7 @@ class et {
488
494
  let s = "text", i;
489
495
  n ? n === "class" ? (s = "class", i = "class") : n === "style" ? (s = "style", i = o || "style") : n === "value" ? (s = "property", i = "value") : (s = "attribute", i = n) : t.includes("class.") ? (s = "class", i = t.split(".")[1]) : t.includes("style.") ? (s = "style", i = t.split(".")[1]) : t.includes("@") ? (s = "event", i = t.split("@")[1]) : t === "class" ? (s = "class", i = "class") : t === "style" ? (s = "style", i = "style") : t === "value" ? (s = "property", i = "value") : t === "title" && (s = "attribute", i = "title");
490
496
  const a = `__DYNAMIC_${r}__`, c = this.statics.join(a);
491
- let l = Q(c, a);
497
+ let l = tt(c, a);
492
498
  this.statics.length === 2 && s !== "text" ? l = [0] : this.statics.length === 2 && l.length === 0 && (l = [0]), this.dynamics.push({
493
499
  path: l,
494
500
  type: s,
@@ -546,21 +552,21 @@ function R(e, t) {
546
552
  }
547
553
  function P(e, t, r) {
548
554
  let n;
549
- return e.fragment && !e.hasDynamics ? n = e.fragment.cloneNode(!0) : n = nt(e, t, r), n;
555
+ return e.fragment && !e.hasDynamics ? n = e.fragment.cloneNode(!0) : n = st(e, t, r), n;
550
556
  }
551
- function rt(e, t, r, n, o) {
557
+ function nt(e, t, r, n, o) {
552
558
  if (e.hasDynamics)
553
559
  for (const s of e.dynamics)
554
560
  try {
555
561
  const i = s.getValue(r, n);
556
562
  if (o !== void 0 && s.getValue(o, n) === i)
557
563
  continue;
558
- F(t, s, i);
564
+ K(t, s, i);
559
565
  } catch (i) {
560
566
  console.warn("[Template Compiler] Error applying update:", i);
561
567
  }
562
568
  }
563
- function nt(e, t, r) {
569
+ function st(e, t, r) {
564
570
  let n = "";
565
571
  for (let a = 0; a < e.statics.length; a++)
566
572
  if (n += e.statics[a], a < e.dynamics.length) {
@@ -577,11 +583,11 @@ function nt(e, t, r) {
577
583
  i.appendChild(s.body.firstChild);
578
584
  for (const a of e.dynamics) {
579
585
  const c = a.getValue(t, r), l = R(i, a.path);
580
- F(l, a, c);
586
+ K(l, a, c);
581
587
  }
582
588
  return i;
583
589
  }
584
- function F(e, t, r) {
590
+ function K(e, t, r) {
585
591
  try {
586
592
  if (t.type === "text") {
587
593
  const o = document.createTreeWalker(
@@ -634,7 +640,7 @@ function F(e, t, r) {
634
640
  }
635
641
  }
636
642
  const S = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map();
637
- function K(e) {
643
+ function U(e) {
638
644
  let t = 0;
639
645
  for (let r = 0; r < e.length; r++) {
640
646
  const n = e.charCodeAt(r);
@@ -677,7 +683,7 @@ function g(e) {
677
683
  }
678
684
  return t;
679
685
  }
680
- function st(e) {
686
+ function it(e) {
681
687
  const t = document.createElement("template");
682
688
  t.innerHTML = e.trim();
683
689
  const r = Array.from(t.content.childNodes);
@@ -835,7 +841,7 @@ function M(e, t, r) {
835
841
  });
836
842
  }
837
843
  }
838
- const it = (e) => e ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(e)) : {}, b = (e, t) => {
844
+ const ot = (e) => e ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new URLSearchParams(e)) : {}, b = (e, t) => {
839
845
  for (const r of e) {
840
846
  const n = [], o = r.path.replace(/:[^/]+/g, (a) => (n.push(a.slice(1)), "([^/]+)")), s = new RegExp(`^${o}$`), i = t.match(s);
841
847
  if (i) {
@@ -847,7 +853,7 @@ const it = (e) => e ? typeof URLSearchParams > "u" ? {} : Object.fromEntries(new
847
853
  }
848
854
  return { route: null, params: {} };
849
855
  }, k = {};
850
- async function ot(e) {
856
+ async function at(e) {
851
857
  if (e.component) return e.component;
852
858
  if (e.load) {
853
859
  if (k[e.path]) return k[e.path];
@@ -860,12 +866,12 @@ async function ot(e) {
860
866
  }
861
867
  throw new Error(`No component or loader defined for route: ${e.path}`);
862
868
  }
863
- function at(e) {
869
+ function ct(e) {
864
870
  const { routes: t, base: r = "" } = e;
865
871
  let n, o, s, i, a, c, l;
866
872
  if (typeof window < "u" && typeof document < "u") {
867
873
  n = () => {
868
- const d = new URL(window.location.href), f = d.pathname.replace(r, "") || "/", h = it(d.search);
874
+ const d = new URL(window.location.href), f = d.pathname.replace(r, "") || "/", h = ot(d.search);
869
875
  return { path: f, query: h };
870
876
  }, o = n();
871
877
  const u = b(t, o.path);
@@ -902,13 +908,13 @@ function at(e) {
902
908
  subscribe: s.subscribe,
903
909
  matchRoute: (u) => b(t, u),
904
910
  getCurrent: () => s.getState(),
905
- resolveRouteComponent: ot
911
+ resolveRouteComponent: at
906
912
  };
907
913
  }
908
- function pt(e, t) {
914
+ function mt(e, t) {
909
915
  return b(e, t);
910
916
  }
911
- function H(e, t) {
917
+ function x(e, t) {
912
918
  const r = [], n = t ? Object.keys(t) : [], o = { ...e };
913
919
  let s = null;
914
920
  function i(u) {
@@ -936,7 +942,7 @@ function H(e, t) {
936
942
  if (t && n.includes(h))
937
943
  return !1;
938
944
  const C = f[h], E = Reflect.set(f, h, m, p);
939
- return C !== m && r.forEach((U) => U(s)), E;
945
+ return C !== m && r.forEach((B) => B(s)), E;
940
946
  },
941
947
  deleteProperty(f, h) {
942
948
  if (t && n.includes(h))
@@ -950,7 +956,7 @@ function H(e, t) {
950
956
  return s = l(o), s;
951
957
  }
952
958
  const A = [];
953
- function mt(e) {
959
+ function yt(e) {
954
960
  A.push(e);
955
961
  }
956
962
  function _(e, t = /* @__PURE__ */ new WeakSet()) {
@@ -965,8 +971,8 @@ function _(e, t = /* @__PURE__ */ new WeakSet()) {
965
971
  function O(e) {
966
972
  return !!e && typeof e.then == "function";
967
973
  }
968
- let x;
969
- typeof HTMLElement < "u" ? x = class extends HTMLElement {
974
+ let H;
975
+ typeof HTMLElement < "u" ? H = class extends HTMLElement {
970
976
  /**
971
977
  * Syncs whitelisted state properties to attributes after render.
972
978
  * Only keys listed in config.reflect are reflected.
@@ -1122,7 +1128,7 @@ typeof HTMLElement < "u" ? x = class extends HTMLElement {
1122
1128
  const e = this.shadowRoot;
1123
1129
  e && (e.querySelectorAll("[data-model]").forEach((t) => {
1124
1130
  const r = t.getAttribute("data-model");
1125
- r && (t._dataModelBound || (J(t, this.stateObj, r), t._dataModelBound = !0));
1131
+ r && (t._dataModelBound || (Q(t, this.stateObj, r), t._dataModelBound = !0));
1126
1132
  }), e.querySelectorAll("[data-model]").forEach((t) => {
1127
1133
  const [r] = t.getAttribute("data-model")?.split("|").map((n) => n.trim()) ?? [];
1128
1134
  if (!(!r || !(r in this.stateObj)))
@@ -1157,7 +1163,7 @@ typeof HTMLElement < "u" ? x = class extends HTMLElement {
1157
1163
  if (!r.state || typeof r.state != "object")
1158
1164
  throw new Error("Invalid component config: state must be an object");
1159
1165
  this.config = r;
1160
- const n = r.computed ? H(r.state, r.computed) : H(r.state);
1166
+ const n = r.computed ? x(r.state, r.computed) : x(r.state);
1161
1167
  if (this.stateObj = n, typeof this.stateObj.subscribe == "function" && this.unsubscribes.push(this.stateObj.subscribe(() => {
1162
1168
  this.scheduleRender();
1163
1169
  })), this.api = {
@@ -1331,7 +1337,7 @@ typeof HTMLElement < "u" ? x = class extends HTMLElement {
1331
1337
  }, n = function(c) {
1332
1338
  c.children.forEach(n);
1333
1339
  };
1334
- const o = r(e), s = st(o);
1340
+ const o = r(e), s = it(o);
1335
1341
  n(s);
1336
1342
  const i = this.shadowRoot;
1337
1343
  if (!i)
@@ -1380,7 +1386,7 @@ typeof HTMLElement < "u" ? x = class extends HTMLElement {
1380
1386
  this.shadowRoot.appendChild(o);
1381
1387
  } else if (n && this.shadowRoot.firstElementChild) {
1382
1388
  const o = this.lastState;
1383
- rt(e, this.shadowRoot.firstElementChild, this.stateObj, this.api, o || void 0);
1389
+ nt(e, this.shadowRoot.firstElementChild, this.stateObj, this.api, o || void 0);
1384
1390
  } else {
1385
1391
  const o = P(e, this.stateObj, this.api);
1386
1392
  let s = this.shadowRoot.querySelector("style");
@@ -1490,7 +1496,7 @@ typeof HTMLElement < "u" ? x = class extends HTMLElement {
1490
1496
  </div>
1491
1497
  `;
1492
1498
  }
1493
- } : x = class {
1499
+ } : H = class {
1494
1500
  // No-op for SSR, just a stub
1495
1501
  constructor() {
1496
1502
  }
@@ -1535,12 +1541,12 @@ function W(e, t) {
1535
1541
  t.debug && console.warn(`[runtime] Component "${e}" already registered`);
1536
1542
  return;
1537
1543
  }
1538
- const s = H(t.state ?? {}, t.computed);
1544
+ const s = x(t.state ?? {}, t.computed);
1539
1545
  t.state = s, t._subscribe = s.subscribe;
1540
1546
  const i = t.state ?? {}, a = Object.keys(i).filter(
1541
1547
  (u) => ["string", "number", "boolean"].includes(typeof i[u])
1542
1548
  );
1543
- class c extends x {
1549
+ class c extends H {
1544
1550
  static get observedAttributes() {
1545
1551
  return a;
1546
1552
  }
@@ -1551,8 +1557,8 @@ function W(e, t) {
1551
1557
  const l = c;
1552
1558
  typeof customElements < "u" && !customElements.get(e) && (window.__componentRegistry = window.__componentRegistry || {}, window.__componentRegistry[e] = t, customElements.define(e, l));
1553
1559
  }
1554
- function yt(e) {
1555
- const t = at(e);
1560
+ function gt(e) {
1561
+ const t = ct(e);
1556
1562
  return W("router-view", {
1557
1563
  template: async () => {
1558
1564
  if (!t) return "<div>Router not initialized.</div>";
@@ -1575,7 +1581,7 @@ function yt(e) {
1575
1581
  ariaCurrentValue: "page",
1576
1582
  disabled: !1,
1577
1583
  external: !1,
1578
- style: Y`
1584
+ style: J`
1579
1585
  [aria-disabled="true"] {
1580
1586
  pointer-events: none;
1581
1587
  opacity: 0.5;
@@ -1644,33 +1650,33 @@ function yt(e) {
1644
1650
  }
1645
1651
  export {
1646
1652
  N as Store,
1647
- dt as classes,
1648
- ut as compile,
1649
- ht as compileTemplate,
1653
+ ft as classes,
1654
+ dt as compile,
1655
+ pt as compileTemplate,
1650
1656
  W as component,
1651
1657
  $ as createVNodeFromElement,
1652
- Y as css,
1658
+ J as css,
1653
1659
  _ as deepSanitizeObject,
1654
1660
  w as eventBus,
1655
- lt as generateHydrationScript,
1661
+ ut as generateHydrationScript,
1656
1662
  q as getVNodeKey,
1657
1663
  T as html,
1658
- yt as initRouter,
1664
+ gt as initRouter,
1659
1665
  O as isPromise,
1660
- pt as matchRouteSSR,
1666
+ mt as matchRouteSSR,
1661
1667
  g as mountVNode,
1662
- st as parseVNodeFromHTML,
1668
+ it as parseVNodeFromHTML,
1663
1669
  M as patchVNode,
1664
1670
  P as renderCompiledTemplate,
1665
- ct as renderComponentsToString,
1666
- Z as renderToString,
1667
- ot as resolveRouteComponent,
1671
+ lt as renderComponentsToString,
1672
+ V as renderToString,
1673
+ at as resolveRouteComponent,
1668
1674
  A as runtimePlugins,
1669
1675
  z as safeReplaceChild,
1670
- ft as styles,
1671
- rt as updateCompiledTemplate,
1672
- J as useDataModel,
1673
- at as useRouter,
1674
- mt as useRuntimePlugin
1676
+ ht as styles,
1677
+ nt as updateCompiledTemplate,
1678
+ Q as useDataModel,
1679
+ ct as useRouter,
1680
+ yt as useRuntimePlugin
1675
1681
  };
1676
1682
  //# sourceMappingURL=custom-elements-runtime.es.js.map