plossy 0.5.0 → 0.5.2

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/plossy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Plossy v0.5.0 | MIT License
2
+ * Plossy v0.5.2 | MIT License
3
3
  *
4
4
  * Includes icons from Lucide (https://lucide.dev), some of them derived from Feather.
5
5
  * Full third-party notices (also shipped as LICENSE-LUCIDE):
@@ -378,7 +378,7 @@
378
378
  }
379
379
  return out;
380
380
  }
381
- var Component = class {
381
+ var _Component = class _Component {
382
382
  constructor(el, options = {}) {
383
383
  const name = this.constructor.componentName;
384
384
  this.el = el;
@@ -392,7 +392,11 @@
392
392
  forget(this);
393
393
  if (state.destroyed) return;
394
394
  state.destroyed = true;
395
- destroy.call(this);
395
+ try {
396
+ destroy.call(this);
397
+ } finally {
398
+ _Component.prototype.destroy.call(this);
399
+ }
396
400
  }
397
401
  });
398
402
  mount(this);
@@ -454,9 +458,10 @@
454
458
  }
455
459
  };
456
460
  /** Domyślne opcje — nadpisywane w klasach potomnych. */
457
- __publicField(Component, "defaults", {});
461
+ __publicField(_Component, "defaults", {});
458
462
  /** Nazwa opcji, do której trafia „goła" wartość atrybutu (np. data-pl-toggle="#cel"). */
459
- __publicField(Component, "primary", null);
463
+ __publicField(_Component, "primary", null);
464
+ var Component = _Component;
460
465
  function mount(instance) {
461
466
  const C = instance.constructor;
462
467
  const el = instance.el;
@@ -473,7 +478,27 @@
473
478
  if (!map) store.set(el, map = /* @__PURE__ */ new Map());
474
479
  if (!map.has(C.componentName)) liveCount++;
475
480
  map.set(C.componentName, instance);
476
- instance.init();
481
+ const { signal } = instance._life;
482
+ let result;
483
+ try {
484
+ result = instance.init();
485
+ } catch (error) {
486
+ rollback(instance);
487
+ throw error;
488
+ }
489
+ if (result && typeof result.then === "function") {
490
+ result.then(null, (error) => {
491
+ console.error(`[Plossy] ${C.componentName}:`, error);
492
+ if (!signal.aborted) rollback(instance);
493
+ });
494
+ }
495
+ }
496
+ function rollback(instance) {
497
+ try {
498
+ instance.destroy();
499
+ } catch (error) {
500
+ console.error(`[Plossy] ${instance.constructor.componentName}:`, error);
501
+ }
477
502
  }
478
503
  function getInstance(el, name) {
479
504
  return store.get(el)?.get(name) || null;
@@ -843,8 +868,9 @@
843
868
  item.classList.add("pl-open");
844
869
  title.setAttribute("aria-expanded", "true");
845
870
  this.emit("show", { item });
871
+ const { signal } = this;
846
872
  await toggleHeight(content, true, { duration: this.options.duration });
847
- this.emit("shown", { item });
873
+ if (!signal.aborted) this.emit("shown", { item });
848
874
  }
849
875
  async hide(item, force = false) {
850
876
  item = this.resolve(item);
@@ -856,8 +882,9 @@
856
882
  item.classList.remove("pl-open");
857
883
  title.setAttribute("aria-expanded", "false");
858
884
  this.emit("hide", { item });
885
+ const { signal } = this;
859
886
  await toggleHeight(content, false, { duration: this.options.duration });
860
- this.emit("hidden", { item });
887
+ if (!signal.aborted) this.emit("hidden", { item });
861
888
  }
862
889
  };
863
890
  __publicField(Accordion, "defaults", {
@@ -893,7 +920,13 @@
893
920
  this.on(this.el, "focusin", () => this.stop());
894
921
  this.on(this.el, "focusout", () => this.start());
895
922
  }
896
- this.onDestroy(() => this.stop());
923
+ this.onDestroy(() => {
924
+ this.stop();
925
+ this.animation?.cancel();
926
+ this.animation = null;
927
+ this.el.classList.remove("pl-alert-leave");
928
+ this.el.style.overflow = "";
929
+ });
897
930
  }
898
931
  start() {
899
932
  this.stop();
@@ -907,12 +940,12 @@
907
940
  }
908
941
  /** Zamyka alert: zanik + zwinięcie wysokości, potem usunięcie z DOM. */
909
942
  async close() {
910
- if (this.closing || this.el.hidden) return;
943
+ if (this.signal.aborted || this.closing || this.el.hidden) return;
911
944
  if (!this.emit("beforehide", {}, true)) return;
912
945
  this.closing = true;
913
946
  this.stop();
914
947
  this.emit("hide");
915
- const { el } = this;
948
+ const { el, signal } = this;
916
949
  const duration = prefersReducedMotion() ? 0 : this.options.duration;
917
950
  if (duration && typeof el.animate === "function") {
918
951
  const cs = getComputedStyle(el);
@@ -941,10 +974,13 @@
941
974
  opacity: 0,
942
975
  transform: "scale(0.97)"
943
976
  };
977
+ this.animation = el.animate([from, faded, to], { duration, easing: "cubic-bezier(0.33, 0.5, 0.2, 1)" });
944
978
  try {
945
- await el.animate([from, faded, to], { duration, easing: "cubic-bezier(0.33, 0.5, 0.2, 1)" }).finished;
979
+ await this.animation.finished;
946
980
  } catch {
947
981
  }
982
+ if (signal.aborted) return;
983
+ this.animation = null;
948
984
  }
949
985
  el.hidden = true;
950
986
  el.classList.remove("pl-alert-leave");
@@ -1521,8 +1557,9 @@
1521
1557
  item.classList.add("pl-open");
1522
1558
  link.setAttribute("aria-expanded", "true");
1523
1559
  this.emit("show", { item });
1560
+ const { signal } = this;
1524
1561
  await toggleHeight(sub, true, { duration: this.options.duration });
1525
- this.emit("shown", { item });
1562
+ if (!signal.aborted) this.emit("shown", { item });
1526
1563
  }
1527
1564
  async hide(item, force = false) {
1528
1565
  item = this.resolve(item);
@@ -1533,8 +1570,9 @@
1533
1570
  item.classList.remove("pl-open");
1534
1571
  link.setAttribute("aria-expanded", "false");
1535
1572
  this.emit("hide", { item });
1573
+ const { signal } = this;
1536
1574
  await toggleHeight(sub, false, { duration: this.options.duration });
1537
- this.emit("hidden", { item });
1575
+ if (!signal.aborted) this.emit("hidden", { item });
1538
1576
  }
1539
1577
  };
1540
1578
  __publicField(Nav, "defaults", {
@@ -2136,7 +2174,7 @@
2136
2174
  default:
2137
2175
  }
2138
2176
  });
2139
- this.on(this.input.form, "reset", () => setTimeout(() => this.clear()));
2177
+ this.on(this.input.form, "reset", () => setTimeout(() => !this.signal.aborted && this.clear()));
2140
2178
  this.onDestroy(() => {
2141
2179
  this.generated.forEach((node) => node.remove());
2142
2180
  if (this.ownInput) this.input.remove();
@@ -2346,7 +2384,7 @@
2346
2384
  }
2347
2385
  }
2348
2386
  this.on(this.input, "input", () => this.update());
2349
- this.on(this.input?.form, "reset", () => setTimeout(() => this.update()));
2387
+ this.on(this.input?.form, "reset", () => setTimeout(() => !this.signal.aborted && this.update()));
2350
2388
  this.onDestroy(() => this.created.forEach((node) => node.remove()));
2351
2389
  this.update(true);
2352
2390
  }
@@ -4088,7 +4126,7 @@
4088
4126
  });
4089
4127
  this.on(input, "change", () => this.emit("change", this.detail()));
4090
4128
  });
4091
- this.on(this.inputs[0].form, "reset", () => requestAnimationFrame(() => this.update()));
4129
+ this.on(this.inputs[0].form, "reset", () => requestAnimationFrame(() => !this.signal.aborted && this.update()));
4092
4130
  if (this.dual) {
4093
4131
  this.constrain(1);
4094
4132
  this.on(el, "pointerdown", (event) => this.jump(event));
@@ -4309,7 +4347,7 @@
4309
4347
  if (this.options.minRows) el.rows = this.options.minRows;
4310
4348
  this.update = this.update.bind(this);
4311
4349
  this.on(el, "input", this.update);
4312
- this.on(el.form, "reset", () => requestAnimationFrame(this.update));
4350
+ this.on(el.form, "reset", () => requestAnimationFrame(() => !this.signal.aborted && this.update()));
4313
4351
  this.on(window, "resize", this.update, { passive: true });
4314
4352
  if (typeof ResizeObserver === "function") {
4315
4353
  let width = el.offsetWidth;
@@ -4443,7 +4481,7 @@
4443
4481
  }
4444
4482
  this.update = this.update.bind(this);
4445
4483
  this.on(el, "input", this.update);
4446
- this.on(el.form, "reset", () => requestAnimationFrame(this.update));
4484
+ this.on(el.form, "reset", () => requestAnimationFrame(() => !this.signal.aborted && this.update()));
4447
4485
  this.update();
4448
4486
  }
4449
4487
  update() {
@@ -4764,7 +4802,7 @@
4764
4802
  const onFocusOut = () => {
4765
4803
  setTimeout(() => {
4766
4804
  const active2 = document.activeElement;
4767
- if (!this.isOpen || !active2 || active2 === document.body) return;
4805
+ if (this.signal.aborted || !this.isOpen || !active2 || active2 === document.body) return;
4768
4806
  if (el.contains(active2) || this.toggleEl?.contains(active2)) return;
4769
4807
  this.hide();
4770
4808
  });
@@ -5093,11 +5131,12 @@
5093
5131
  const mine = ++token;
5094
5132
  tip.classList.add("pl-leave");
5095
5133
  tip.classList.remove("pl-open");
5134
+ const { signal } = this;
5096
5135
  await animationsDone(tip);
5097
5136
  if (mine !== token) return;
5098
5137
  tip.classList.remove("pl-leave");
5099
5138
  hideLayer(tip);
5100
- this.emit("hidden");
5139
+ if (!signal.aborted) this.emit("hidden");
5101
5140
  }
5102
5141
  };
5103
5142
  __publicField(Tooltip, "defaults", {
@@ -5203,9 +5242,10 @@
5203
5242
  });
5204
5243
  }
5205
5244
  onFocusOut() {
5245
+ const { signal } = this;
5206
5246
  setTimeout(() => {
5207
5247
  const active2 = document.activeElement;
5208
- if (!this.isOpen || this.el.contains(active2) || this.pop?.contains(active2)) return;
5248
+ if (signal.aborted || !this.isOpen || this.el.contains(active2) || this.pop?.contains(active2)) return;
5209
5249
  this.hide();
5210
5250
  });
5211
5251
  }
@@ -5502,12 +5542,13 @@
5502
5542
  const el = this.el;
5503
5543
  if (this.state === "closing") await this.closing;
5504
5544
  if (this.state !== "closed" || typeof el.showModal !== "function") return;
5545
+ if (!alive(this)) scan(el);
5546
+ if (!alive(this)) return;
5547
+ if (!el.isConnected) document.body.append(el);
5505
5548
  if (!this.emit("beforeshow", {}, true)) return;
5506
5549
  if (!this.options.stack) {
5507
5550
  [...opened].filter((other) => other !== this && !other.el.contains(el)).forEach((other) => other.hide());
5508
5551
  }
5509
- if (!el.isConnected) document.body.append(el);
5510
- if (getInstance(el, this.constructor.componentName) !== this) scan(el);
5511
5552
  this.opener = opener instanceof Element ? opener : document.activeElement;
5512
5553
  el.classList.remove("pl-closing");
5513
5554
  if (el.open) el.close();
@@ -5532,6 +5573,7 @@
5532
5573
  if (this.state === "open") this.emit("shown");
5533
5574
  }
5534
5575
  hide() {
5576
+ if (!alive(this)) return Promise.resolve();
5535
5577
  if (this.state === "closing") return this.closing;
5536
5578
  if (this.state !== "open") return Promise.resolve();
5537
5579
  if (!this.emit("beforehide", {}, true)) return Promise.resolve();
@@ -5574,6 +5616,7 @@
5574
5616
  __publicField(Overlay, "panel", ".pl-modal-dialog");
5575
5617
  /** Selektor tytułu (aria-labelledby). */
5576
5618
  __publicField(Overlay, "title", ".pl-modal-title");
5619
+ var alive = (instance) => !instance.signal.aborted && getInstance(instance.el, instance.constructor.componentName) === instance;
5577
5620
  function delegateOpen(name) {
5578
5621
  if (typeof document === "undefined") return;
5579
5622
  const attr = `data-pl-${name}-open`;
@@ -6742,6 +6785,7 @@
6742
6785
  }
6743
6786
  const detail = { component: this, toggle: this.el };
6744
6787
  if (!fire(target, show ? "beforeshow" : "beforehide", detail, true)) return;
6788
+ const { signal } = this;
6745
6789
  const { cls, animation, duration } = this.options;
6746
6790
  if (cls) {
6747
6791
  this.classes.forEach((name) => target.classList.toggle(name, show));
@@ -6765,14 +6809,14 @@
6765
6809
  const names = leave?.length ? leave : [...enter, "pl-animation-reverse"];
6766
6810
  target.classList.add(...names);
6767
6811
  await animationsDone(target);
6768
- target.hidden = true;
6812
+ if (!signal.aborted) target.hidden = true;
6769
6813
  target.classList.remove(...names);
6770
6814
  }
6771
6815
  } else {
6772
6816
  target.hidden = !show;
6773
6817
  fire(target, show ? "show" : "hide", detail);
6774
6818
  }
6775
- fire(target, show ? "shown" : "hidden", detail);
6819
+ if (!signal.aborted) fire(target, show ? "shown" : "hidden", detail);
6776
6820
  }
6777
6821
  /** Ustawia ARIA od razu, zanim skończy się animacja. */
6778
6822
  syncState(active2) {
@@ -6845,12 +6889,14 @@
6845
6889
  this.onDestroy(() => observer.disconnect());
6846
6890
  }
6847
6891
  this.on(window, "resize", this.updateIndicator, { passive: true });
6848
- document.fonts?.ready.then(() => this.setIndicator()).catch(() => {
6892
+ const { signal } = this;
6893
+ document.fonts?.ready.then(() => !signal.aborted && this.setIndicator()).catch(() => {
6849
6894
  });
6850
6895
  this.activate(start2, false);
6851
6896
  requestAnimationFrame(() => {
6897
+ if (signal.aborted) return;
6852
6898
  this.setIndicator();
6853
- requestAnimationFrame(() => el.classList.add("pl-switcher-ready"));
6899
+ requestAnimationFrame(() => !signal.aborted && el.classList.add("pl-switcher-ready"));
6854
6900
  });
6855
6901
  }
6856
6902
  // ── Struktura ───────────────────────────────────────────────────────────
@@ -7211,7 +7257,9 @@
7211
7257
  const top = !el && (target === "#" || target === "#top");
7212
7258
  if (!el && !top) return false;
7213
7259
  if (!this.emit("beforescroll", { target: el }, true)) return false;
7260
+ const { signal } = this;
7214
7261
  const done = await scrollTo(el || 0, { offset: el ? offset : 0, duration, easing });
7262
+ if (signal.aborted) return done;
7215
7263
  if (hash && typeof target === "string" && target.length > 1 && target !== location.hash) {
7216
7264
  history.pushState(null, "", target);
7217
7265
  }
@@ -7361,7 +7409,9 @@
7361
7409
  event.preventDefault();
7362
7410
  this.locked = true;
7363
7411
  this.setActive(link);
7412
+ const { signal } = this;
7364
7413
  const done = await scrollTo(target, { offset: this.options.offset, duration: this.options.duration });
7414
+ if (signal.aborted) return;
7365
7415
  this.locked = false;
7366
7416
  if (done) {
7367
7417
  if (link.hash !== location.hash) history.replaceState(null, "", link.hash);
@@ -7482,7 +7532,8 @@
7482
7532
  this.on(window, "resize", remeasure, { passive: true });
7483
7533
  this.on(window, "load", remeasure);
7484
7534
  this.on(this.media, "change", remeasure);
7485
- document.fonts?.ready.then(remeasure).catch(() => {
7535
+ const { signal } = this;
7536
+ document.fonts?.ready.then(() => !signal.aborted && remeasure()).catch(() => {
7486
7537
  });
7487
7538
  if (typeof ResizeObserver === "function") {
7488
7539
  const observer = new ResizeObserver(() => {
@@ -7654,9 +7705,10 @@
7654
7705
  /** Odklejenie z animacją wyjścia. */
7655
7706
  async leave() {
7656
7707
  const token2 = this.leaving = Math.random() + 1;
7708
+ const { signal } = this;
7657
7709
  this.setState(false);
7658
7710
  await this.animate(true);
7659
- if (this.leaving !== token2) return;
7711
+ if (signal.aborted || this.leaving !== token2) return;
7660
7712
  this.leaving = 0;
7661
7713
  this.unfix();
7662
7714
  this.refresh();
@@ -9433,8 +9485,9 @@
9433
9485
  this.finishAnimations();
9434
9486
  const animation = animate && !prefersReducedMotion() && this.options.duration > 0 ? this.options.animation : false;
9435
9487
  const jobs = this.targets.map((target) => this.filterTarget(target, animation));
9488
+ const { signal } = this;
9436
9489
  return Promise.all(jobs).then(() => {
9437
- if (this.state !== state) return;
9490
+ if (signal.aborted || this.state !== state) return;
9438
9491
  const items = this.visible;
9439
9492
  for (const empty of $$(".pl-filter-empty", this.el)) empty.hidden = items.length > 0;
9440
9493
  this.emit("afterfilter", { state, items });
@@ -9557,6 +9610,7 @@
9557
9610
  const half = duration / 2;
9558
9611
  const step = delayed ? Math.min(45, duration / 4) : 0;
9559
9612
  const state = this.state;
9613
+ const { signal } = this;
9560
9614
  const out = children.filter((el) => !el.hidden).map(
9561
9615
  (el, i) => el.animate([{ opacity: 1 }, { opacity: 0, transform: delayed ? "translateY(-6px)" : "none" }], {
9562
9616
  duration: half,
@@ -9566,7 +9620,7 @@
9566
9620
  })
9567
9621
  );
9568
9622
  await this.track(out);
9569
- if (this.state !== state) return;
9623
+ if (signal.aborted || this.state !== state) return;
9570
9624
  mutate();
9571
9625
  const into = [...target.children].filter((el) => !el.hidden).map(
9572
9626
  (el, i) => el.animate([{ opacity: 0, transform: delayed ? "translateY(8px)" : "none" }, { opacity: 1, transform: "none" }], {
@@ -9894,7 +9948,8 @@
9894
9948
  this.onDestroy(() => mutations.disconnect());
9895
9949
  this.on(window, "resize", this.update, { passive: true });
9896
9950
  this.on(window, "load", this.update);
9897
- document.fonts?.ready.then(this.update).catch(() => {
9951
+ const { signal } = this;
9952
+ document.fonts?.ready.then(() => !signal.aborted && this.update()).catch(() => {
9898
9953
  });
9899
9954
  this.onDestroy(() => this.targets.forEach((target) => target.style.minHeight = ""));
9900
9955
  this.match();
@@ -9962,7 +10017,8 @@
9962
10017
  this.update = rafThrottle(() => this.resize());
9963
10018
  this.on(window, "resize", this.update, { passive: true });
9964
10019
  this.on(window, "load", this.update);
9965
- document.fonts?.ready.then(this.update).catch(() => {
10020
+ const { signal } = this;
10021
+ document.fonts?.ready.then(() => !signal.aborted && this.update()).catch(() => {
9966
10022
  });
9967
10023
  if (typeof ResizeObserver === "function" && this.options.expand) {
9968
10024
  const observer = new ResizeObserver(this.update);
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Plossy v0.5.0 | MIT License
2
+ * Plossy v0.5.2 | MIT License
3
3
  *
4
4
  * Includes icons from Lucide (https://lucide.dev), some of them derived from Feather.
5
5
  * Full third-party notices (also shipped as LICENSE-LUCIDE):