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