calkit 0.1.0 → 0.2.0

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.
@@ -13,31 +13,34 @@ class C extends HTMLElement {
13
13
  const e = this.constructor.styles;
14
14
  if (e.length)
15
15
  if ("adoptedStyleSheets" in this.shadowRoot)
16
- this.shadowRoot.adoptedStyleSheets = e.map((s) => {
17
- if (s instanceof CSSStyleSheet) return s;
16
+ this.shadowRoot.adoptedStyleSheets = e.map((a) => {
17
+ if (a instanceof CSSStyleSheet) return a;
18
18
  const t = new CSSStyleSheet();
19
- return t.replaceSync(s), t;
19
+ return t.replaceSync(a), t;
20
20
  });
21
21
  else
22
- for (const s of e) {
22
+ for (const a of e) {
23
23
  const t = document.createElement("style");
24
- t.textContent = s instanceof CSSStyleSheet ? "" : s, this.shadowRoot.prepend(t);
24
+ t.textContent = a instanceof CSSStyleSheet ? "" : a, this.shadowRoot.prepend(t);
25
25
  }
26
26
  }
27
27
  /** Subclasses override to update Shadow DOM. */
28
28
  render() {
29
29
  }
30
+ /** Reset selection state. Subclasses should override with specific logic. */
31
+ clear() {
32
+ }
30
33
  /** Dispatch a composed, bubbling custom event. */
31
- emit(e, s = {}) {
34
+ emit(e, a = {}) {
32
35
  this.dispatchEvent(
33
- new CustomEvent(e, { detail: s, bubbles: !0, composed: !0 })
36
+ new CustomEvent(e, { detail: a, bubbles: !0, composed: !0 })
34
37
  );
35
38
  }
36
39
  /** Show an inline status banner. */
37
- showStatus(e, s, t = {}) {
40
+ showStatus(e, a, t = {}) {
38
41
  if (!this._store) return;
39
- const { autoDismiss: a, dismissible: i = !0 } = t;
40
- clearTimeout(this._statusTimer), this._store.set({ statusType: e, statusMessage: s, statusDismissible: i }), this.emit("cal:status", { type: e, message: s }), a && a > 0 && (this._statusTimer = setTimeout(() => this.clearStatus(), a));
42
+ const { autoDismiss: s, dismissible: i = !0 } = t;
43
+ clearTimeout(this._statusTimer), this._store.set({ statusType: e, statusMessage: a, statusDismissible: i }), this.emit("cal:status", { type: e, message: a }), s && s > 0 && (this._statusTimer = setTimeout(() => this.clearStatus(), s));
41
44
  }
42
45
  /** Clear the status banner. */
43
46
  clearStatus() {
@@ -53,75 +56,79 @@ class C extends HTMLElement {
53
56
  }
54
57
  function A(r) {
55
58
  let e = { ...r };
56
- const s = /* @__PURE__ */ new Set();
59
+ const a = /* @__PURE__ */ new Set();
57
60
  return {
58
61
  get(t) {
59
62
  return e[t];
60
63
  },
61
64
  set(t) {
62
- const a = e;
65
+ const s = e;
63
66
  e = { ...e, ...t };
64
67
  let i = !1;
65
68
  for (const l of Object.keys(t))
66
- if (a[l] !== e[l]) {
69
+ if (s[l] !== e[l]) {
67
70
  i = !0;
68
71
  break;
69
72
  }
70
73
  if (i)
71
- for (const l of s) l(e, a);
74
+ for (const l of a) l(e, s);
72
75
  },
73
76
  getState() {
74
77
  return e;
75
78
  },
76
79
  subscribe(t) {
77
- return s.add(t), () => s.delete(t);
80
+ return a.add(t), () => a.delete(t);
78
81
  }
79
82
  };
80
83
  }
81
84
  function k(r) {
82
85
  if (!r || typeof r != "string") return null;
83
- const e = r.trim().toUpperCase(), s = e.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/);
84
- if (s) {
85
- let a = parseInt(s[1], 10);
86
- const i = parseInt(s[2], 10), l = s[3];
87
- return l === "AM" && a === 12 && (a = 0), l === "PM" && a !== 12 && (a += 12), { hours: a, minutes: i };
86
+ const e = r.trim().toUpperCase(), a = e.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/);
87
+ if (a) {
88
+ let s = parseInt(a[1], 10);
89
+ const i = parseInt(a[2], 10), l = a[3];
90
+ return l === "AM" && s === 12 && (s = 0), l === "PM" && s !== 12 && (s += 12), { hours: s, minutes: i };
88
91
  }
89
92
  const t = e.match(/^(\d{1,2}):(\d{2})$/);
90
93
  return t ? { hours: parseInt(t[1], 10), minutes: parseInt(t[2], 10) } : null;
91
94
  }
92
- function x(r, e, s = "24h") {
95
+ function x(r, e, a = "24h") {
93
96
  const t = String(e).padStart(2, "0");
94
- if (s === "12h") {
95
- const a = r >= 12 ? "PM" : "AM";
96
- return `${r % 12 || 12}:${t} ${a}`;
97
+ if (a === "12h") {
98
+ const s = r >= 12 ? "PM" : "AM";
99
+ return `${r % 12 || 12}:${t} ${s}`;
97
100
  }
98
101
  return `${String(r).padStart(2, "0")}:${t}`;
99
102
  }
100
- function g(r) {
103
+ function u(r) {
101
104
  const e = k(r);
102
105
  return e ? e.hours * 60 + e.minutes : 0;
103
106
  }
104
107
  function _(r) {
105
- const e = Math.floor(r / 60) % 24, s = r % 60;
106
- return `${String(e).padStart(2, "0")}:${String(s).padStart(2, "0")}`;
108
+ const e = Math.floor(r / 60) % 24, a = r % 60;
109
+ return `${String(e).padStart(2, "0")}:${String(a).padStart(2, "0")}`;
107
110
  }
108
- function E(r, e, s) {
109
- const t = [], a = g(r), i = g(e);
110
- for (let l = a; l <= i; l += s)
111
- t.push(_(l));
111
+ function E(r, e, a) {
112
+ const t = [], s = u(r);
113
+ let i = u(e);
114
+ i <= s && (i += 1440);
115
+ for (let l = s; l <= i; l += a)
116
+ t.push(_(l % 1440));
112
117
  return t;
113
118
  }
114
- function M(r, e, s, t = "24h") {
115
- const a = [], i = g(r), l = g(e);
116
- for (let c = i; c <= l; c += s) {
117
- const u = _(c), h = c + s, m = _(Math.min(h, l + s)), d = k(u), n = k(m), o = d ? x(d.hours, d.minutes, t) : u, p = n ? x(n.hours, n.minutes, t) : m;
118
- a.push({ time: u, displayText: `${o}–${p}` });
119
- }
120
- return a;
119
+ function M(r, e, a, t = "24h") {
120
+ const s = [], i = u(r);
121
+ let l = u(e);
122
+ l <= i && (l += 1440);
123
+ for (let c = i; c <= l; c += a) {
124
+ const g = _(c % 1440), h = c + a, m = _(Math.min(h, l + a) % 1440), d = k(g), n = k(m), o = d ? x(d.hours, d.minutes, t) : g, p = n ? x(n.hours, n.minutes, t) : m;
125
+ s.push({ time: g, displayText: `${o}–${p}` });
126
+ }
127
+ return s;
121
128
  }
122
- function T(r, e, s) {
123
- const t = g(r), a = g(e), i = g(s), l = Math.min(a, i), c = Math.max(a, i);
124
- return t >= l && t <= c;
129
+ function T(r, e, a) {
130
+ const t = u(r), s = u(e), i = u(a);
131
+ return i >= s ? t >= s && t <= i : t >= s || t <= i;
125
132
  }
126
133
  const z = `
127
134
  :host {
@@ -397,22 +404,22 @@ const z = `
397
404
  border-radius: var(--cal-radius-sm);
398
405
  }
399
406
  `;
400
- function O({ trigger: r, content: e, onClose: s }) {
407
+ function O({ trigger: r, content: e, onClose: a }) {
401
408
  const t = document.createElement("div");
402
409
  t.classList.add("cal-popover"), t.setAttribute("role", "dialog"), t.setAttribute("aria-modal", "false"), t.style.display = "none", t.appendChild(e);
403
- let a = !1;
410
+ let s = !1;
404
411
  function i() {
405
412
  t.classList.remove("cal-popover--above");
406
413
  const d = r.getBoundingClientRect(), n = t.offsetHeight, o = window.innerHeight - d.bottom, p = d.top;
407
414
  o < n + 8 && p > o ? (t.classList.add("cal-popover--above"), t.style.top = "auto", t.style.bottom = "100%", t.style.marginBottom = "4px", t.style.marginTop = "0") : (t.style.top = "100%", t.style.bottom = "auto", t.style.marginTop = "4px", t.style.marginBottom = "0");
408
415
  }
409
416
  function l() {
410
- a || (a = !0, t.style.display = "", t.classList.add("cal-animate-slide-up"), requestAnimationFrame(() => i()), document.addEventListener("click", u, !0), document.addEventListener("keydown", h, !0));
417
+ s || (s = !0, t.style.display = "", t.classList.add("cal-animate-slide-up"), requestAnimationFrame(() => i()), document.addEventListener("click", g, !0), document.addEventListener("keydown", h, !0));
411
418
  }
412
419
  function c() {
413
- a && (a = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up"), document.removeEventListener("click", u, !0), document.removeEventListener("keydown", h, !0), s == null || s());
420
+ s && (s = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up"), document.removeEventListener("click", g, !0), document.removeEventListener("keydown", h, !0), a == null || a());
414
421
  }
415
- function u(d) {
422
+ function g(d) {
416
423
  var o;
417
424
  const n = (o = r.getRootNode()) == null ? void 0 : o.host;
418
425
  n && !n.contains(d.target) && d.target !== n && c();
@@ -421,10 +428,10 @@ function O({ trigger: r, content: e, onClose: s }) {
421
428
  d.key === "Escape" && (d.stopPropagation(), c());
422
429
  }
423
430
  function m() {
424
- a && (a = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up")), document.removeEventListener("click", u, !0), document.removeEventListener("keydown", h, !0);
431
+ s && (s = !1, t.style.display = "none", t.classList.remove("cal-animate-slide-up")), document.removeEventListener("click", g, !0), document.removeEventListener("keydown", h, !0);
425
432
  }
426
433
  return { panel: t, open: l, close: c, destroy: m, get isOpen() {
427
- return a;
434
+ return s;
428
435
  } };
429
436
  }
430
437
  const R = `
@@ -476,17 +483,17 @@ const R = `
476
483
  function j(r) {
477
484
  const {
478
485
  slots: e = [],
479
- mode: s = "single",
486
+ mode: a = "single",
480
487
  format: t = "24h",
481
- selected: a,
488
+ selected: s,
482
489
  hoverTime: i,
483
490
  rangeStart: l,
484
491
  unavailableTimes: c = [],
485
- onSelect: u,
492
+ onSelect: g,
486
493
  onHover: h,
487
494
  durationLabels: m = !1
488
495
  } = r, d = document.createElement("div");
489
- d.classList.add("cal-time-grid"), m && d.classList.add("cal-time-grid--duration"), d.setAttribute("role", "listbox"), s === "multi" && d.setAttribute("aria-multiselectable", "true");
496
+ d.classList.add("cal-time-grid"), m && d.classList.add("cal-time-grid--duration"), d.setAttribute("role", "listbox"), a === "multi" && d.setAttribute("aria-multiselectable", "true");
490
497
  for (const n of e) {
491
498
  const o = document.createElement("button");
492
499
  o.classList.add("cal-time-slot"), o.setAttribute("role", "option"), o.dataset.time = n.time;
@@ -496,19 +503,19 @@ function j(r) {
496
503
  b.classList.add("cal-time-slot__label"), b.textContent = n.label, o.appendChild(b);
497
504
  }
498
505
  const S = n.available === !1 || c.includes(n.time);
499
- if (S && (o.classList.add("cal-time-slot--unavailable"), o.disabled = !0, o.setAttribute("aria-disabled", "true")), H(n.time, a, s) ? (o.classList.add("cal-time-slot--selected"), o.setAttribute("aria-selected", "true")) : o.setAttribute("aria-selected", "false"), s === "range" && l && !I(a) && i) {
506
+ if (S && (o.classList.add("cal-time-slot--unavailable"), o.disabled = !0, o.setAttribute("aria-disabled", "true")), H(n.time, s, a) ? (o.classList.add("cal-time-slot--selected"), o.setAttribute("aria-selected", "true")) : o.setAttribute("aria-selected", "false"), a === "range" && l && !I(s) && i) {
500
507
  const b = T(n.time, l, i), f = n.time === l, v = n.time === i;
501
508
  b && !f && !v && o.classList.add("cal-time-slot--in-range"), f && o.classList.add("cal-time-slot--range-start"), v && o.classList.add("cal-time-slot--range-end");
502
- } else if (s === "range" && a && typeof a == "object" && a.start && a.end) {
503
- const b = T(n.time, a.start, a.end), f = n.time === a.start, v = n.time === a.end;
509
+ } else if (a === "range" && s && typeof s == "object" && s.start && s.end) {
510
+ const b = T(n.time, s.start, s.end), f = n.time === s.start, v = n.time === s.end;
504
511
  f && o.classList.add("cal-time-slot--range-start", "cal-time-slot--selected"), v && o.classList.add("cal-time-slot--range-end", "cal-time-slot--selected"), b && !f && !v && o.classList.add("cal-time-slot--in-range");
505
512
  }
506
- S || (o.addEventListener("click", () => u == null ? void 0 : u(n.time)), o.addEventListener("mouseenter", () => h == null ? void 0 : h(n.time))), d.appendChild(o);
513
+ S || (o.addEventListener("click", () => g == null ? void 0 : g(n.time)), o.addEventListener("mouseenter", () => h == null ? void 0 : h(n.time))), d.appendChild(o);
507
514
  }
508
515
  return d.addEventListener("mouseleave", () => h == null ? void 0 : h(null)), d;
509
516
  }
510
- function H(r, e, s) {
511
- return e ? s === "single" ? e === r : s === "multi" ? Array.isArray(e) && e.includes(r) : s === "range" && typeof e == "object" && e.start && e.end ? e.start === r || e.end === r : !1 : !1;
517
+ function H(r, e, a) {
518
+ return e ? a === "single" ? e === r : a === "multi" ? Array.isArray(e) && e.includes(r) : a === "range" && typeof e == "object" && e.start && e.end ? e.start === r || e.end === r : !1 : !1;
512
519
  }
513
520
  function I(r) {
514
521
  return r && typeof r == "object" && r.start && r.end;
@@ -596,11 +603,11 @@ const P = `
596
603
  font-size: 12px;
597
604
  }
598
605
  `;
599
- function D({ columns: r = 3, rows: e = 4, durationLabels: s = !1 } = {}) {
606
+ function D({ columns: r = 3, rows: e = 4, durationLabels: a = !1 } = {}) {
600
607
  const t = document.createElement("div");
601
- t.setAttribute("role", "status"), t.setAttribute("aria-label", "Loading..."), t.classList.add("cal-skeleton-time-grid"), s && t.classList.add("cal-skeleton-time-grid--duration");
602
- const a = r * e;
603
- for (let i = 0; i < a; i++) {
608
+ t.setAttribute("role", "status"), t.setAttribute("aria-label", "Loading..."), t.classList.add("cal-skeleton-time-grid"), a && t.classList.add("cal-skeleton-time-grid--duration");
609
+ const s = r * e;
610
+ for (let i = 0; i < s; i++) {
604
611
  const l = document.createElement("div");
605
612
  l.classList.add("cal-skeleton"), t.appendChild(l);
606
613
  }
@@ -645,17 +652,17 @@ const X = `
645
652
  info: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M7 6.5V10M7 4.5v.01"/></svg>',
646
653
  success: '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><circle cx="7" cy="7" r="6"/><path d="M4.5 7l2 2L9.5 5"/></svg>'
647
654
  };
648
- function q({ type: r = "info", message: e, dismissible: s = !0, onDismiss: t }) {
649
- const a = document.createElement("div");
650
- a.classList.add("cal-status", `cal-status--${r}`, "cal-animate-slide-up"), a.setAttribute("role", r === "error" ? "alert" : "status"), a.setAttribute("aria-live", r === "error" ? "assertive" : "polite");
655
+ function q({ type: r = "info", message: e, dismissible: a = !0, onDismiss: t }) {
656
+ const s = document.createElement("div");
657
+ s.classList.add("cal-status", `cal-status--${r}`, "cal-animate-slide-up"), s.setAttribute("role", r === "error" ? "alert" : "status"), s.setAttribute("aria-live", r === "error" ? "assertive" : "polite");
651
658
  const i = document.createElement("span");
652
- i.classList.add("cal-status__icon"), i.innerHTML = w[r] || w.info, a.appendChild(i);
659
+ i.classList.add("cal-status__icon"), i.innerHTML = w[r] || w.info, s.appendChild(i);
653
660
  const l = document.createElement("span");
654
- if (l.classList.add("cal-status__text"), l.textContent = e, a.appendChild(l), s) {
661
+ if (l.classList.add("cal-status__text"), l.textContent = e, s.appendChild(l), a) {
655
662
  const c = document.createElement("button");
656
- c.classList.add("cal-status__close"), c.setAttribute("aria-label", "Dismiss"), c.innerHTML = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M3 3l6 6M9 3l-6 6"/></svg>', c.addEventListener("click", () => t == null ? void 0 : t()), a.appendChild(c);
663
+ c.classList.add("cal-status__close"), c.setAttribute("aria-label", "Dismiss"), c.innerHTML = '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M3 3l6 6M9 3l-6 6"/></svg>', c.addEventListener("click", () => t == null ? void 0 : t()), s.appendChild(c);
657
664
  }
658
- return a;
665
+ return s;
659
666
  }
660
667
  const G = `
661
668
  .cal-status {
@@ -745,7 +752,7 @@ class U extends C {
745
752
  return [z, $, B, P, R, X, G, Y];
746
753
  }
747
754
  static get observedAttributes() {
748
- return ["mode", "display", "theme", "start-time", "end-time", "interval", "format", "placeholder", "value", "duration-labels", "loading"];
755
+ return ["mode", "display", "theme", "start-time", "end-time", "interval", "format", "placeholder", "value", "duration-labels", "loading", "locale", "min-time"];
749
756
  }
750
757
  constructor() {
751
758
  super(), this._store = A({
@@ -791,6 +798,12 @@ class U extends C {
791
798
  set loading(e) {
792
799
  e ? this.setAttribute("loading", "") : this.removeAttribute("loading");
793
800
  }
801
+ get locale() {
802
+ return this.getAttribute("locale") || void 0;
803
+ }
804
+ get minTime() {
805
+ return this.getAttribute("min-time") || null;
806
+ }
794
807
  // -- Properties --
795
808
  get slots() {
796
809
  return this._slots;
@@ -808,44 +821,54 @@ class U extends C {
808
821
  return this._store.getState().selected;
809
822
  }
810
823
  set value(e) {
811
- this.mode === "single" && typeof e == "string" ? this._store.set({ selected: e, rangeStart: null }) : this.mode === "multi" && Array.isArray(e) ? this._store.set({ selected: [...e].sort((s, t) => g(s) - g(t)), rangeStart: null }) : this.mode === "range" && e && typeof e == "object" ? this._store.set({ selected: { start: e.start, end: e.end }, rangeStart: null }) : this._store.set({ selected: null, rangeStart: null });
824
+ this.mode === "single" && typeof e == "string" ? this._store.set({ selected: e, rangeStart: null }) : this.mode === "multi" && Array.isArray(e) ? this._store.set({ selected: [...e].sort((a, t) => u(a) - u(t)), rangeStart: null }) : this.mode === "range" && e && typeof e == "object" ? this._store.set({ selected: { start: e.start, end: e.end }, rangeStart: null }) : this._store.set({ selected: null, rangeStart: null });
812
825
  }
813
826
  _getEffectiveSlots() {
814
- return this._slots ? this._slots : this.durationLabels ? M(this.startTime, this.endTime, this.interval, this.format).map((t) => ({
815
- ...t,
816
- available: !this._unavailableTimes.includes(t.time)
817
- })) : E(this.startTime, this.endTime, this.interval).map((s) => ({
827
+ let e;
828
+ this._slots ? e = this._slots : this.durationLabels ? e = M(this.startTime, this.endTime, this.interval, this.format).map((s) => ({
829
+ ...s,
830
+ available: !this._unavailableTimes.includes(s.time)
831
+ })) : e = E(this.startTime, this.endTime, this.interval).map((s) => ({
818
832
  time: s,
819
833
  available: !this._unavailableTimes.includes(s)
820
834
  }));
835
+ const a = this.minTime;
836
+ if (a) {
837
+ const t = u(a);
838
+ e = e.map((s) => {
839
+ const i = typeof s == "string" ? s : s.time;
840
+ return u(i) < t ? typeof s == "string" ? { time: s, available: !1 } : { ...s, available: !1 } : s;
841
+ });
842
+ }
843
+ return e;
821
844
  }
822
845
  connectedCallback() {
823
- super.connectedCallback(), this._unsubscribe = this._store.subscribe((s, t) => {
846
+ super.connectedCallback(), this._unsubscribe = this._store.subscribe((a, t) => {
824
847
  if (this._rendering) return;
825
- s.hoverTime !== t.hoverTime && s.selected === t.selected && s.rangeStart === t.rangeStart && s.isOpen === t.isOpen ? this._updateSlotHighlight(s) : this.render();
848
+ a.hoverTime !== t.hoverTime && a.selected === t.selected && a.rangeStart === t.rangeStart && a.isOpen === t.isOpen ? this._updateSlotHighlight(a) : this.render();
826
849
  });
827
850
  const e = this.getAttribute("value");
828
851
  if (e)
829
852
  if (this.mode === "multi" && e.includes(","))
830
- this.value = e.split(",").map((s) => s.trim());
853
+ this.value = e.split(",").map((a) => a.trim());
831
854
  else if (this.mode === "range" && e.includes("/")) {
832
- const [s, t] = e.split("/");
833
- this.value = { start: s.trim(), end: t.trim() };
855
+ const [a, t] = e.split("/");
856
+ this.value = { start: a.trim(), end: t.trim() };
834
857
  } else
835
858
  this.value = e;
836
859
  }
837
860
  disconnectedCallback() {
838
- var e, s;
839
- (e = this._unsubscribe) == null || e.call(this), (s = this._popover) == null || s.destroy(), clearTimeout(this._statusTimer);
861
+ var e, a;
862
+ (e = this._unsubscribe) == null || e.call(this), (a = this._popover) == null || a.destroy(), clearTimeout(this._statusTimer);
840
863
  }
841
- attributeChangedCallback(e, s, t) {
842
- if (s !== t) {
864
+ attributeChangedCallback(e, a, t) {
865
+ if (a !== t) {
843
866
  if (e === "value" && this._initialized)
844
867
  if (this.mode === "multi" && t && t.includes(","))
845
- this.value = t.split(",").map((a) => a.trim());
868
+ this.value = t.split(",").map((s) => s.trim());
846
869
  else if (this.mode === "range" && t && t.includes("/")) {
847
- const [a, i] = t.split("/");
848
- this.value = { start: a.trim(), end: i.trim() };
870
+ const [s, i] = t.split("/");
871
+ this.value = { start: s.trim(), end: i.trim() };
849
872
  } else
850
873
  this.value = t;
851
874
  this._initialized && this.render();
@@ -853,19 +876,19 @@ class U extends C {
853
876
  }
854
877
  // -- Selection --
855
878
  _handleSelect(e) {
856
- const s = this._store.getState();
879
+ const a = this._store.getState();
857
880
  if (this.mode === "single")
858
881
  this._store.set({ selected: e }), this.emit("cal:time-change", { value: e }), this.display === "popover" && this.close();
859
882
  else if (this.mode === "multi") {
860
- const t = Array.isArray(s.selected) ? [...s.selected] : [], a = t.indexOf(e);
861
- a >= 0 ? t.splice(a, 1) : t.push(e), t.sort((i, l) => g(i) - g(l)), this._store.set({ selected: t }), this.emit("cal:time-change", { value: t });
883
+ const t = Array.isArray(a.selected) ? [...a.selected] : [], s = t.indexOf(e);
884
+ s >= 0 ? t.splice(s, 1) : t.push(e), t.sort((i, l) => u(i) - u(l)), this._store.set({ selected: t }), this.emit("cal:time-change", { value: t });
862
885
  } else if (this.mode === "range")
863
- if (!s.rangeStart || s.selected && typeof s.selected == "object" && s.selected.start && s.selected.end)
886
+ if (!a.rangeStart || a.selected && typeof a.selected == "object" && a.selected.start && a.selected.end)
864
887
  this._store.set({ rangeStart: e, selected: null, hoverTime: null });
865
888
  else {
866
- let t = s.rangeStart, a = e;
867
- g(t) > g(a) && ([t, a] = [a, t]);
868
- const i = { start: t, end: a };
889
+ let t = a.rangeStart, s = e;
890
+ u(t) > u(s) && ([t, s] = [s, t]);
891
+ const i = { start: t, end: s };
869
892
  this._store.set({ selected: i, rangeStart: null, hoverTime: null }), this.emit("cal:time-change", { value: i }), this.display === "popover" && this.close();
870
893
  }
871
894
  }
@@ -874,12 +897,12 @@ class U extends C {
874
897
  }
875
898
  // -- Lightweight hover highlight --
876
899
  _updateSlotHighlight(e) {
877
- const s = this.$$(".cal-time-slot"), { rangeStart: t, hoverTime: a, selected: i } = e, l = i && typeof i == "object" && i.start && i.end;
878
- for (const c of s) {
879
- const u = c.dataset.time;
880
- if (!(!u || c.disabled))
881
- if (t && !l && a) {
882
- const h = g(t) < g(a) ? t : a, m = g(t) < g(a) ? a : t, d = g(u), n = d > g(h) && d < g(m), o = u === t, p = u === a;
900
+ const a = this.$$(".cal-time-slot"), { rangeStart: t, hoverTime: s, selected: i } = e, l = i && typeof i == "object" && i.start && i.end;
901
+ for (const c of a) {
902
+ const g = c.dataset.time;
903
+ if (!(!g || c.disabled))
904
+ if (t && !l && s) {
905
+ const h = u(t) < u(s) ? t : s, m = u(t) < u(s) ? s : t, d = u(g), n = d > u(h) && d < u(m), o = g === t, p = g === s;
883
906
  c.classList.toggle("cal-time-slot--range-start", o), c.classList.toggle("cal-time-slot--range-end", p), c.classList.toggle("cal-time-slot--in-range", n);
884
907
  } else t || c.classList.remove("cal-time-slot--range-start", "cal-time-slot--range-end", "cal-time-slot--in-range");
885
908
  }
@@ -891,21 +914,28 @@ class U extends C {
891
914
  close() {
892
915
  this._popover && (this._popover.close(), this._store.set({ isOpen: !1 }), this.emit("cal:close"));
893
916
  }
917
+ clear() {
918
+ this._store.set({
919
+ selected: null,
920
+ rangeStart: null,
921
+ hoverTime: null
922
+ }), this.emit("cal:time-change", { value: null });
923
+ }
894
924
  // -- Render --
895
925
  _renderTimepickerContent() {
896
- const e = this._store.getState(), s = document.createElement("div");
897
- s.classList.add("cal-timepicker"), e.statusType && e.statusMessage && s.appendChild(q({
926
+ const e = this._store.getState(), a = document.createElement("div");
927
+ a.classList.add("cal-timepicker"), e.statusType && e.statusMessage && a.appendChild(q({
898
928
  type: e.statusType,
899
929
  message: e.statusMessage,
900
930
  dismissible: e.statusDismissible,
901
931
  onDismiss: () => this.clearStatus()
902
932
  }));
903
933
  const t = document.createElement("div");
904
- if (t.classList.add("cal-timepicker__header"), t.textContent = "Select Time", s.appendChild(t), this.loading)
905
- s.appendChild(D({ durationLabels: this.durationLabels }));
934
+ if (t.classList.add("cal-timepicker__header"), t.textContent = "Select Time", a.appendChild(t), this.loading)
935
+ a.appendChild(D({ durationLabels: this.durationLabels }));
906
936
  else {
907
- const a = this._getEffectiveSlots(), i = j({
908
- slots: a,
937
+ const s = this._getEffectiveSlots(), i = j({
938
+ slots: s,
909
939
  mode: this.mode,
910
940
  format: this.format,
911
941
  selected: e.selected,
@@ -916,9 +946,9 @@ class U extends C {
916
946
  onHover: (l) => this._handleHover(l),
917
947
  durationLabels: this.durationLabels
918
948
  });
919
- s.appendChild(i);
949
+ a.appendChild(i);
920
950
  }
921
- return s;
951
+ return a;
922
952
  }
923
953
  _formatTriggerText() {
924
954
  const e = this._store.getState();
@@ -928,18 +958,18 @@ class U extends C {
928
958
  var t;
929
959
  if (this._rendering) return;
930
960
  this._rendering = !0;
931
- const e = this.shadowRoot, s = [...e.childNodes];
932
- for (const a of s)
933
- a.nodeName !== "STYLE" && !(a instanceof CSSStyleSheet) && e.removeChild(a);
961
+ const e = this.shadowRoot, a = [...e.childNodes];
962
+ for (const s of a)
963
+ s.nodeName !== "STYLE" && !(s instanceof CSSStyleSheet) && e.removeChild(s);
934
964
  if ((t = this._popover) == null || t.destroy(), this._popover = null, this.display === "popover") {
935
- const a = document.createElement("div");
936
- a.classList.add("cal-popover-wrapper");
965
+ const s = document.createElement("div");
966
+ s.classList.add("cal-popover-wrapper");
937
967
  const i = document.createElement("button");
938
968
  i.classList.add("cal-trigger");
939
969
  const l = document.createElement("span");
940
970
  l.classList.add("cal-trigger__icon"), l.innerHTML = N, i.appendChild(l);
941
- const c = this._formatTriggerText(), u = document.createElement("span");
942
- c ? u.textContent = c : (u.textContent = this.placeholder, u.classList.add("cal-trigger--placeholder")), i.appendChild(u), a.appendChild(i);
971
+ const c = this._formatTriggerText(), g = document.createElement("span");
972
+ c ? g.textContent = c : (g.textContent = this.placeholder, g.classList.add("cal-trigger--placeholder")), i.appendChild(g), s.appendChild(i);
943
973
  const h = this._renderTimepickerContent(), m = O({
944
974
  trigger: i,
945
975
  content: h,
@@ -947,7 +977,7 @@ class U extends C {
947
977
  this._store.set({ isOpen: !1 }), this.emit("cal:close");
948
978
  }
949
979
  });
950
- a.appendChild(m.panel), e.appendChild(a), i.addEventListener("click", (d) => {
980
+ s.appendChild(m.panel), e.appendChild(s), i.addEventListener("click", (d) => {
951
981
  d.stopPropagation(), m.isOpen ? this.close() : this.open();
952
982
  }), this._popover = m, this._store.get("isOpen") && m.open();
953
983
  } else