@koppajs/koppajs-core 3.0.3 → 3.0.5

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/dist/index.es.js CHANGED
@@ -6,9 +6,8 @@ const B = {
6
6
  DEBUG: "🔍"
7
7
  };
8
8
  class Pe {
9
- constructor() {
10
- this.level = 3, this.isDevelopment = !1;
11
- }
9
+ level = 3;
10
+ isDevelopment = !1;
12
11
  /**
13
12
  * Initialize logger with environment detection.
14
13
  * @param options - Logger configuration options
@@ -113,8 +112,8 @@ class Pe {
113
112
  ) && console.warn(this.formatMessage(B.WARN, t, n));
114
113
  }
115
114
  }
116
- const T = new Pe();
117
- T.init();
115
+ const _ = new Pe();
116
+ _.init();
118
117
  const ce = /* @__PURE__ */ Symbol("isBounded"), pe = /* @__PURE__ */ Symbol("isProxy"), Ie = [
119
118
  "created",
120
119
  "beforeMount",
@@ -137,7 +136,7 @@ function Le(e, t) {
137
136
  try {
138
137
  e[n] = K(o, t);
139
138
  } catch (r) {
140
- T.errorWithContext(
139
+ _.errorWithContext(
141
140
  `Failed to bind method "${n}"`,
142
141
  { methodName: n },
143
142
  r
@@ -313,7 +312,7 @@ function H(e, t = {}) {
313
312
  }
314
313
  return a(...o.map((i) => t[i]));
315
314
  } catch (o) {
316
- T.debug(`Expression evaluation failed: ${n}`, o);
315
+ _.debug(`Expression evaluation failed: ${n}`, o);
317
316
  return;
318
317
  }
319
318
  }
@@ -344,7 +343,7 @@ function Xe(e, t) {
344
343
  const i = t ? new Function("context", "__deps", a) : new Function("context", a);
345
344
  return ((c) => t ? i(c, t) : i(c));
346
345
  } catch (i) {
347
- throw T.errorWithContext("Failed to compile dynamic code", { functionBody: a }, i), i;
346
+ throw _.errorWithContext("Failed to compile dynamic code", { functionBody: a }, i), i;
348
347
  }
349
348
  }
350
349
  function ye() {
@@ -361,7 +360,7 @@ async function R(e, t, n) {
361
360
  try {
362
361
  await r(n);
363
362
  } catch (a) {
364
- T.errorWithContext(`Hook "${t}" callback failed`, { hook: t }, a);
363
+ _.errorWithContext(`Hook "${t}" callback failed`, { hook: t }, a);
365
364
  }
366
365
  }
367
366
  const G = {
@@ -507,7 +506,7 @@ function ot(e, t, n, o) {
507
506
  const r = [];
508
507
  return t.forEach(([a, i, s]) => {
509
508
  if (typeof a != "string" || typeof s != "function") {
510
- T.error("Provided handler is not a function", s);
509
+ _.error("Provided handler is not a function", s);
511
510
  return;
512
511
  }
513
512
  let c = [];
@@ -576,7 +575,7 @@ function st(e, t, n, o, r) {
576
575
  const a = [];
577
576
  return n.forEach(([i, s, c]) => {
578
577
  if (typeof i != "string" || typeof c != "function") {
579
- T.error("Provided handler is not a function", c);
578
+ _.error("Provided handler is not a function", c);
580
579
  return;
581
580
  }
582
581
  let l = [];
@@ -651,14 +650,14 @@ function lt() {
651
650
  });
652
651
  }), J.observe(document.body, { childList: !0, subtree: !0 }));
653
652
  }
654
- const Te = /* @__PURE__ */ new WeakMap(), _e = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap();
653
+ const _e = /* @__PURE__ */ new WeakMap(), Te = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap();
655
654
  let ft = 0;
656
655
  const V = () => `slot-${++ft}`, W = (e) => typeof e == "object" && e !== null, Q = (e) => typeof e == "symbol" ? e.toString() : String(e), ut = (e) => {
657
- const t = Te.get(e);
656
+ const t = _e.get(e);
658
657
  return t && W(t) ? t : void 0;
659
658
  };
660
659
  function Se(e) {
661
- const t = _e.get(e);
660
+ const t = Te.get(e);
662
661
  return t || e;
663
662
  }
664
663
  const D = (e) => W(e) ? Reflect.get(e, pe) === !0 : !1;
@@ -759,11 +758,11 @@ function pt(e) {
759
758
  break;
760
759
  }
761
760
  case "splice": {
762
- const u = b[0] ?? 0, d = b[1] !== void 0 ? b[1] : f.length - u, g = b.slice(2), _ = Array.from(
761
+ const u = b[0] ?? 0, d = b[1] !== void 0 ? b[1] : f.length - u, g = b.slice(2), T = Array.from(
763
762
  { length: g.length },
764
763
  () => V()
765
764
  );
766
- w.splice(u, d, ..._);
765
+ w.splice(u, d, ...T);
767
766
  break;
768
767
  }
769
768
  case "reverse": {
@@ -822,21 +821,21 @@ function pt(e) {
822
821
  }
823
822
  };
824
823
  }
825
- const _ = Reflect.get(u, d, g), M = Array.isArray(u) && typeof d == "string" && /^\d+$/.test(d);
826
- if (W(_) && !D(_) && !M && (Array.isArray(_) || !Array.isArray(u))) {
824
+ const T = Reflect.get(u, d, g), M = Array.isArray(u) && typeof d == "string" && /^\d+$/.test(d);
825
+ if (W(T) && !D(T) && !M && (Array.isArray(T) || !Array.isArray(u))) {
827
826
  const L = Q(d), O = s(u, L);
828
- return v(_, O);
827
+ return v(T, O);
829
828
  }
830
- return _;
829
+ return T;
831
830
  },
832
- set: (u, d, g, _) => {
833
- const M = Reflect.get(u, d, _);
831
+ set: (u, d, g, T) => {
832
+ const M = Reflect.get(u, d, T);
834
833
  if (M === g) return !0;
835
834
  const L = Q(d), O = s(u, L);
836
835
  if (Array.isArray(u) && typeof d == "string" && /^\d+$/.test(d)) {
837
836
  const k = parseInt(d, 10);
838
837
  if (k >= 0 && k < u.length) {
839
- const h = Reflect.set(u, d, g, _);
838
+ const h = Reflect.set(u, d, g, T);
840
839
  return l(O), h;
841
840
  }
842
841
  }
@@ -851,25 +850,25 @@ function pt(e) {
851
850
  g
852
851
  )) {
853
852
  let h = g;
854
- W(h) && !D(h) && (h = v(h, O)), Reflect.set(u, d, h, _), l(O);
853
+ W(h) && !D(h) && (h = v(h, O)), Reflect.set(u, d, h, T), l(O);
855
854
  }
856
855
  return !0;
857
856
  }
858
- const I = Reflect.set(u, d, g, _);
857
+ const I = Reflect.set(u, d, g, T);
859
858
  if (W(g) && !D(g)) {
860
859
  const k = v(g, O);
861
- Reflect.set(u, d, k, _), Array.isArray(g) && X(g);
860
+ Reflect.set(u, d, k, T), Array.isArray(g) && X(g);
862
861
  }
863
862
  return l(O), I;
864
863
  },
865
864
  deleteProperty: (u, d) => {
866
865
  if (d === "changedPaths")
867
866
  return Reflect.deleteProperty(u, d);
868
- const g = Q(d), _ = s(u, g), M = Reflect.get(u, d), L = Reflect.deleteProperty(u, d);
869
- return L && M !== void 0 && l(_), L;
867
+ const g = Q(d), T = s(u, g), M = Reflect.get(u, d), L = Reflect.deleteProperty(u, d);
868
+ return L && M !== void 0 && l(T), L;
870
869
  }
871
870
  });
872
- return Te.set(f, w), _e.set(w, f), w;
871
+ return _e.set(f, w), Te.set(w, f), w;
873
872
  };
874
873
  return {
875
874
  state: v(e),
@@ -936,8 +935,8 @@ function pt(e) {
936
935
  for (const d of w) {
937
936
  const g = y.get(d);
938
937
  if (g)
939
- for (const _ of u)
940
- g.add(_);
938
+ for (const T of u)
939
+ g.add(T);
941
940
  else
942
941
  y.set(d, new Set(u));
943
942
  }
@@ -1019,7 +1018,7 @@ async function vt(e, t, n) {
1019
1018
  return;
1020
1019
  }
1021
1020
  if (typeof l != "object") {
1022
- T.error("State source is not iterable", { collectionExp: s, raw: l });
1021
+ _.error("State source is not iterable", { collectionExp: s, raw: l });
1023
1022
  return;
1024
1023
  }
1025
1024
  const m = Array.isArray(l), p = m ? l.map((f, y) => [String(y), f]) : Object.entries(l), N = p.length, x = document.createDocumentFragment(), S = m ? dt(l) : void 0, v = { ...t };
@@ -1131,7 +1130,7 @@ async function Oe(e, t, n) {
1131
1130
  } else p != null && p !== !1 && (p === !0 ? s.setAttribute(l, "") : s.setAttribute(l, String(p)));
1132
1131
  s.removeAttribute(c.name);
1133
1132
  } catch (p) {
1134
- T.errorWithContext(
1133
+ _.errorWithContext(
1135
1134
  `Error evaluating dynamic attribute "${c.name}"`,
1136
1135
  { attributeName: c.name, expression: m },
1137
1136
  p
@@ -1144,7 +1143,7 @@ async function Oe(e, t, n) {
1144
1143
  let l = xe(c.value, t);
1145
1144
  c.name === "class" && (l = l.replace(/\s+/g, " ").trim()), l !== c.value && s.setAttribute(c.name, l);
1146
1145
  } catch (l) {
1147
- T.errorWithContext(
1146
+ _.errorWithContext(
1148
1147
  `Error replacing attribute "${c.name}"`,
1149
1148
  { attributeName: c.name },
1150
1149
  l
@@ -1170,7 +1169,7 @@ async function Oe(e, t, n) {
1170
1169
  }
1171
1170
  await Nt(a, n);
1172
1171
  } catch (o) {
1173
- throw T.errorWithContext("Error processing template", {}, o), o;
1172
+ throw _.errorWithContext("Error processing template", {}, o), o;
1174
1173
  }
1175
1174
  }
1176
1175
  function Ct(e, t = {}) {
@@ -1179,7 +1178,7 @@ function Ct(e, t = {}) {
1179
1178
  if (e.some((s) => s == null || typeof s != "object"))
1180
1179
  throw new Error("composeBySource: all layers must be objects");
1181
1180
  const { defaultWriteIndex: n = e.length - 1, includePrototype: o = !1 } = t, r = n >= 0 && n < e.length && Number.isInteger(n) ? n : e.length - 1;
1182
- n !== r && T.warnWithContext(
1181
+ n !== r && _.warnWithContext(
1183
1182
  `Invalid defaultWriteIndex ${n}, using ${r}`,
1184
1183
  { defaultWriteIndex: n, validWriteIndex: r, layersLength: e.length }
1185
1184
  );
@@ -1258,7 +1257,7 @@ function te({
1258
1257
  object: i === "object" && r !== null && !Array.isArray(r),
1259
1258
  function: i === "function"
1260
1259
  };
1261
- return (a === "unknown" ? !0 : s[a] ?? !1) ? o.regex && typeof r == "string" && !new RegExp(o.regex).test(r) ? (T.error(`Prop "${e}" does not match regex "${o.regex}".`), !1) : !0 : (T.error(
1260
+ return (a === "unknown" ? !0 : s[a] ?? !1) ? o.regex && typeof r == "string" && !new RegExp(o.regex).test(r) ? (_.error(`Prop "${e}" does not match regex "${o.regex}".`), !1) : !0 : (_.error(
1262
1261
  `Prop "${e}" should be of type "${a}", but got "${i}".`,
1263
1262
  r
1264
1263
  ), !1);
@@ -1282,7 +1281,7 @@ function de({
1282
1281
  try {
1283
1282
  De(t.state, s, c);
1284
1283
  } catch (l) {
1285
- T.errorWithContext(
1284
+ _.errorWithContext(
1286
1285
  `Failed to set bound prop "${i}" → "${s}"`,
1287
1286
  { propName: i, parentPath: s },
1288
1287
  l
@@ -1309,15 +1308,29 @@ function de({
1309
1308
  (!r || te({ propName: c, propValue: p, props: n })) && (o[c] = p);
1310
1309
  }
1311
1310
  for (const [i, s] of Object.entries(n))
1312
- i in o || (s.default !== void 0 ? o[i] = s.default : s.required && T.error(`Required prop "${i}" is missing.`));
1311
+ i in o || (s.default !== void 0 ? o[i] = s.default : s.required && _.error(`Required prop "${i}" is missing.`));
1313
1312
  }
1314
- function Tt(e, t) {
1313
+ function _t(e, t) {
1315
1314
  customElements.define(
1316
1315
  e,
1317
1316
  class extends HTMLElement {
1317
+ template;
1318
+ /**
1319
+ * Public instance property for type compatibility with HTMLElementWithInstance.
1320
+ */
1321
+ instance;
1322
+ // Cleanup state for deterministic teardown
1323
+ _isDisconnected = !1;
1324
+ _isMounted = !1;
1325
+ // Track if component has been mounted (persists across connectedCallback calls)
1326
+ _model;
1327
+ _observerFn;
1328
+ _renderAborted = !1;
1329
+ _pendingRender = null;
1330
+ _eventCleanup = null;
1318
1331
  // Cleanup for setupEvents listeners (including window)
1319
1332
  constructor() {
1320
- super(), this._isDisconnected = !1, this._isMounted = !1, this._renderAborted = !1, this._pendingRender = null, this._eventCleanup = null, this.template = document.createElement("template"), this.template.innerHTML = t.template;
1333
+ super(), this.template = document.createElement("template"), this.template.innerHTML = t.template;
1321
1334
  }
1322
1335
  async connectedCallback() {
1323
1336
  const n = this;
@@ -1358,7 +1371,7 @@ function Tt(e, t) {
1358
1371
  const P = (h) => {
1359
1372
  const E = G.plugins[h];
1360
1373
  if (!E || typeof E.setup != "function") {
1361
- T.warnWithContext(
1374
+ _.warnWithContext(
1362
1375
  `Plugin "${h}" not found or has no setup method`,
1363
1376
  { pluginName: h }
1364
1377
  );
@@ -1368,7 +1381,7 @@ function Tt(e, t) {
1368
1381
  const A = r && v ? v : S;
1369
1382
  return E.setup.call(A);
1370
1383
  } catch (A) {
1371
- T.errorWithContext(
1384
+ _.errorWithContext(
1372
1385
  `Plugin "${h}" setup failed`,
1373
1386
  { pluginName: h },
1374
1387
  A
@@ -1410,14 +1423,14 @@ function Tt(e, t) {
1410
1423
  ...f
1411
1424
  }, d = c(u), g = pt(d.state ?? {});
1412
1425
  S = g.state;
1413
- const _ = d.methods || {}, M = d.props || {}, L = d.events || [];
1426
+ const T = d.methods || {}, M = d.props || {}, L = d.events || [];
1414
1427
  let O = d.watchList || [];
1415
- r && (v = Ct([_, S])), de({
1428
+ r && (v = Ct([T, S])), de({
1416
1429
  ele: n,
1417
1430
  parent: a,
1418
1431
  props: M,
1419
1432
  state: S
1420
- }), r && v && Le(_, v);
1433
+ }), r && v && Le(T, v);
1421
1434
  for (const h of Ie) {
1422
1435
  const E = d[h];
1423
1436
  if (typeof E == "function") {
@@ -1450,8 +1463,8 @@ function Tt(e, t) {
1450
1463
  this._pendingRender = I;
1451
1464
  return;
1452
1465
  }
1453
- r && v ? (rt(v, E), this._eventCleanup && this._eventCleanup(), this._eventCleanup = ot(v, L, E, l)) : (it(_, E), this._eventCleanup && this._eventCleanup(), this._eventCleanup = st(
1454
- _,
1466
+ r && v ? (rt(v, E), this._eventCleanup && this._eventCleanup(), this._eventCleanup = ot(v, L, E, l)) : (it(T, E), this._eventCleanup && this._eventCleanup(), this._eventCleanup = st(
1467
+ T,
1455
1468
  S,
1456
1469
  L,
1457
1470
  E,
@@ -1479,14 +1492,14 @@ function Tt(e, t) {
1479
1492
  }
1480
1493
  et(n, E, !this._isMounted, t.structAttr), this._isMounted && (await R("global", "updated", C), await R(N, "updated", C)), delete C.changedPaths, p = h, n.instance && (n.instance._lastRenderedStateVersion = p);
1481
1494
  } catch (E) {
1482
- T.errorWithContext("Error during render", { componentName: e }, E);
1495
+ _.errorWithContext("Error during render", { componentName: e }, E);
1483
1496
  } finally {
1484
1497
  const E = r && v ? v : S;
1485
1498
  if (delete E.changedPaths, m = !1, n.instance && (n.instance.isRendering = !1), this._pendingRender && !this._isDisconnected) {
1486
1499
  const A = this._pendingRender;
1487
1500
  this._pendingRender = null, requestAnimationFrame(() => {
1488
1501
  this._isDisconnected || A().catch((C) => {
1489
- T.errorWithContext(
1502
+ _.errorWithContext(
1490
1503
  "Error during pending render",
1491
1504
  { componentName: e },
1492
1505
  C
@@ -1503,7 +1516,7 @@ function Tt(e, t) {
1503
1516
  state: S,
1504
1517
  userContext: r ? v : void 0,
1505
1518
  props: M,
1506
- methods: _,
1519
+ methods: T,
1507
1520
  events: L,
1508
1521
  watchList: O,
1509
1522
  $refs: l,
@@ -1525,7 +1538,7 @@ function Tt(e, t) {
1525
1538
  }
1526
1539
  requestAnimationFrame(() => {
1527
1540
  this._isDisconnected || I().catch((E) => {
1528
- T.errorWithContext(
1541
+ _.errorWithContext(
1529
1542
  "Error during render (observer)",
1530
1543
  { componentName: e },
1531
1544
  E
@@ -1549,17 +1562,17 @@ function Tt(e, t) {
1549
1562
  );
1550
1563
  }
1551
1564
  let ie = !1, he = !1, se = [];
1552
- function _t() {
1565
+ function Tt() {
1553
1566
  he || (he = !0, !(typeof document > "u" || typeof HTMLElement > "u") && (ct(), Ye(), lt()));
1554
1567
  }
1555
1568
  function $e(...e) {
1556
1569
  const t = e[0], n = e[1];
1557
1570
  if (Ge(t)) {
1558
1571
  if (!n) {
1559
- T.error("ComponentSource requires a component name when calling take()");
1572
+ _.error("ComponentSource requires a component name when calling take()");
1560
1573
  return;
1561
1574
  }
1562
- Tt(n, t);
1575
+ _t(n, t);
1563
1576
  return;
1564
1577
  }
1565
1578
  if (Z(t) || Ke(t)) {
@@ -1572,7 +1585,7 @@ function $e(...e) {
1572
1585
  try {
1573
1586
  t.install(o), Z(t) ? G.plugins[t.name] = t : G.modules[t.name] = t;
1574
1587
  } catch (r) {
1575
- T.errorWithContext(
1588
+ _.errorWithContext(
1576
1589
  "Failed to install extension",
1577
1590
  { name: t.name, type: Z(t) ? "plugin" : "module" },
1578
1591
  r
@@ -1580,14 +1593,14 @@ function $e(...e) {
1580
1593
  }
1581
1594
  return;
1582
1595
  }
1583
- T.error("Unknown extension type", t);
1596
+ _.error("Unknown extension type", t);
1584
1597
  }
1585
1598
  function St() {
1586
- ie || (ie = !0, se.forEach((e) => $e(...e)), se = [], T.info("Core initialized"));
1599
+ ie || (ie = !0, se.forEach((e) => $e(...e)), se = [], _.info("Core initialized"));
1587
1600
  }
1588
1601
  const ke = Object.assign(
1589
1602
  () => {
1590
- _t(), St();
1603
+ Tt(), St();
1591
1604
  },
1592
1605
  {
1593
1606
  take: (...t) => {
@@ -1598,5 +1611,5 @@ const ke = Object.assign(
1598
1611
  export {
1599
1612
  ke as Core,
1600
1613
  Re as LogLevel,
1601
- T as logger
1614
+ _ as logger
1602
1615
  };