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.
- package/README.md +1 -1
- package/dist/booking.es.js +421 -318
- package/dist/booking.es.js.map +1 -1
- package/dist/booking.umd.js +12 -12
- package/dist/booking.umd.js.map +1 -1
- package/dist/calkit.d.ts +453 -0
- package/dist/calkit.es.js +1101 -898
- package/dist/calkit.es.js.map +1 -1
- package/dist/calkit.umd.js +34 -34
- package/dist/calkit.umd.js.map +1 -1
- package/dist/datepicker.es.js +333 -241
- package/dist/datepicker.es.js.map +1 -1
- package/dist/datepicker.umd.js +12 -12
- package/dist/datepicker.umd.js.map +1 -1
- package/dist/scheduler.es.js +705 -638
- package/dist/scheduler.es.js.map +1 -1
- package/dist/scheduler.umd.js +20 -20
- package/dist/scheduler.umd.js.map +1 -1
- package/dist/timepicker.es.js +146 -116
- package/dist/timepicker.es.js.map +1 -1
- package/dist/timepicker.umd.js +6 -6
- package/dist/timepicker.umd.js.map +1 -1
- package/llms.txt +1 -1
- package/package.json +4 -2
package/dist/booking.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(P,F){typeof exports=="object"&&typeof module<"u"?F(exports):typeof define=="function"&&define.amd?define(["exports"],F):(P=typeof globalThis<"u"?globalThis:P||self,F(P.CalBooking={}))})(this,(function(P){"use strict";class F extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._initialized=!1}static get styles(){return[]}connectedCallback(){this._initialized||(this._adoptStyles(),this._initialized=!0),this.render()}_adoptStyles(){const e=this.constructor.styles;if(e.length)if("adoptedStyleSheets"in this.shadowRoot)this.shadowRoot.adoptedStyleSheets=e.map(a=>{if(a instanceof CSSStyleSheet)return a;const t=new CSSStyleSheet;return t.replaceSync(a),t});else for(const a of e){const t=document.createElement("style");t.textContent=a instanceof CSSStyleSheet?"":a,this.shadowRoot.prepend(t)}}render(){}clear(){}emit(e,a={}){this.dispatchEvent(new CustomEvent(e,{detail:a,bubbles:!0,composed:!0}))}showStatus(e,a,t={}){if(!this._store)return;const{autoDismiss:n,dismissible:r=!0}=t;clearTimeout(this._statusTimer),this._store.set({statusType:e,statusMessage:a,statusDismissible:r}),this.emit("cal:status",{type:e,message:a}),n&&n>0&&(this._statusTimer=setTimeout(()=>this.clearStatus(),n))}clearStatus(){this._store&&(clearTimeout(this._statusTimer),this._store.set({statusType:null,statusMessage:null,statusDismissible:!0}),this.emit("cal:status",{type:null,message:null}))}$(e){return this.shadowRoot.querySelector(e)}$$(e){return this.shadowRoot.querySelectorAll(e)}}function ge(s){let e={...s};const a=new Set;return{get(t){return e[t]},set(t){const n=e;e={...e,...t};let r=!1;for(const i of Object.keys(t))if(n[i]!==e[i]){r=!0;break}if(r)for(const i of a)i(e,n)},getState(){return e},subscribe(t){return a.add(t),()=>a.delete(t)}}}const Q=["January","February","March","April","May","June","July","August","September","October","November","December"],he=["Su","Mo","Tu","We","Th","Fr","Sa"];function be(s){if(!s)return Q;try{const e=new Intl.DateTimeFormat(s,{month:"long"});return Array.from({length:12},(a,t)=>{const n=e.format(new Date(2024,t,1));return n.charAt(0).toUpperCase()+n.slice(1)})}catch{return Q}}function Z(s){if(!s)return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];try{const e=new Intl.DateTimeFormat(s,{month:"short"});return Array.from({length:12},(a,t)=>{const n=e.format(new Date(2024,t,1));return n.charAt(0).toUpperCase()+n.slice(1)})}catch{return["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}}function me(s=0,e){if(e)try{const t=new Intl.DateTimeFormat(e,{weekday:"short"}),n=[];for(let r=0;r<7;r++){const i=new Date(2024,0,7+(s+r)%7),o=t.format(i);n.push(o.charAt(0).toUpperCase()+o.slice(1))}return n}catch{}const a=[];for(let t=0;t<7;t++)a.push(he[(s+t)%7]);return a}function ee(s,e){return new Date(s,e+1,0).getDate()}function fe(s,e){return new Date(s,e,1).getDay()}function E(s){if(typeof s=="string")return s;const e=s instanceof Date?s:new Date(s.year,s.month,s.day),a=e.getFullYear(),t=String(e.getMonth()+1).padStart(2,"0"),n=String(e.getDate()).padStart(2,"0");return`${a}-${t}-${n}`}function L(s){if(!s)return null;if(s instanceof Date)return s;if(typeof s=="string"){const[e,a,t]=s.split("-").map(Number);return!e||!a||!t?null:new Date(e,a-1,t)}return null}function $(s,e){if(!s||!e)return!1;const a=L(s),t=L(e);return!a||!t?!1:a.getFullYear()===t.getFullYear()&&a.getMonth()===t.getMonth()&&a.getDate()===t.getDate()}function pe(s,e,a){if(!s||!e||!a)return!1;const t=L(s),n=L(e),r=L(a);if(!t||!n||!r)return!1;const i=t.getTime(),o=Math.min(n.getTime(),r.getTime()),l=Math.max(n.getTime(),r.getTime());return i>=o&&i<=l}function te(){return E(new Date)}function O(s,e,a){const t=new Date(s,e+a,1);return{year:t.getFullYear(),month:t.getMonth()}}function ve(s,e,a=0){const t=ee(s,e),r=(fe(s,e)-a+7)%7,i=[],o=te(),l=O(s,e,-1),g=ee(l.year,l.month);for(let c=r-1;c>=0;c--){const u=g-c,m=E({year:l.year,month:l.month,day:u});i.push({year:l.year,month:l.month,day:u,dateString:m,isCurrentMonth:!1,isToday:m===o})}for(let c=1;c<=t;c++){const u=E({year:s,month:e,day:c});i.push({year:s,month:e,day:c,dateString:u,isCurrentMonth:!0,isToday:u===o})}const h=O(s,e,1);let d=1;for(;i.length<42;){const c=E({year:h.year,month:h.month,day:d});i.push({year:h.year,month:h.month,day:d,dateString:c,isCurrentMonth:!1,isToday:c===o}),d++}return i}function j(s){if(!s||typeof s!="string")return null;const e=s.trim().toUpperCase(),a=e.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/);if(a){let n=parseInt(a[1],10);const r=parseInt(a[2],10),i=a[3];return i==="AM"&&n===12&&(n=0),i==="PM"&&n!==12&&(n+=12),{hours:n,minutes:r}}const t=e.match(/^(\d{1,2}):(\d{2})$/);return t?{hours:parseInt(t[1],10),minutes:parseInt(t[2],10)}:null}function q(s,e,a="24h"){const t=String(e).padStart(2,"0");if(a==="12h"){const n=s>=12?"PM":"AM";return`${s%12||12}:${t} ${n}`}return`${String(s).padStart(2,"0")}:${t}`}function M(s){const e=j(s);return e?e.hours*60+e.minutes:0}function W(s){const e=Math.floor(s/60)%24,a=s%60;return`${String(e).padStart(2,"0")}:${String(a).padStart(2,"0")}`}function ye(s,e,a){const t=[],n=M(s);let r=M(e);r<=n&&(r+=1440);for(let i=n;i<=r;i+=a)t.push(W(i%1440));return t}function ke(s,e,a,t="24h"){const n=[],r=M(s);let i=M(e);i<=r&&(i+=1440);for(let o=r;o<=i;o+=a){const l=W(o%1440),g=o+a,h=W(Math.min(g,i+a)%1440),d=j(l),c=j(h),u=d?q(d.hours,d.minutes,t):l,m=c?q(c.hours,c.minutes,t):h;n.push({time:l,displayText:`${u}–${m}`})}return n}function ae(s,e,a){const t=M(s),n=M(e),r=M(a);return r>=n?t>=n&&t<=r:t>=n||t<=r}const _e=`
|
|
2
2
|
:host {
|
|
3
3
|
/* Light theme (default) */
|
|
4
4
|
--cal-bg: 0 0% 100%;
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
--cal-status-success-border: 152 40% 28%;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
`,
|
|
169
|
+
`,we=`
|
|
170
170
|
:host {
|
|
171
171
|
display: inline-block;
|
|
172
172
|
font-family: inherit;
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
[hidden] {
|
|
208
208
|
display: none !important;
|
|
209
209
|
}
|
|
210
|
-
`,
|
|
210
|
+
`,xe=`
|
|
211
211
|
@keyframes cal-fade-in {
|
|
212
212
|
from { opacity: 0; }
|
|
213
213
|
to { opacity: 1; }
|
|
@@ -271,7 +271,7 @@
|
|
|
271
271
|
.cal-skeleton--rect {
|
|
272
272
|
border-radius: var(--cal-radius-sm);
|
|
273
273
|
}
|
|
274
|
-
`,
|
|
274
|
+
`,ne='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10 12L6 8l4-4"/></svg>',se='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 4l4 4-4 4"/></svg>';function re({year:s,month:e,onPrev:a,onNext:t,onTitleClick:n,locale:r}){const i=document.createElement("div");i.classList.add("cal-nav");const o=document.createElement("button");o.classList.add("cal-nav__btn","cal-nav__btn--prev"),o.innerHTML=ne,o.setAttribute("aria-label","Previous month"),o.addEventListener("click",a);const l=be(r),g=n?"button":"div",h=document.createElement(g);h.classList.add("cal-nav__title"),n&&(h.classList.add("cal-nav__title--interactive"),h.setAttribute("aria-label",`Select month and year, currently ${l[e]} ${s}`),h.addEventListener("click",n)),h.setAttribute("aria-live","polite"),h.textContent=`${l[e]} ${s}`;const d=document.createElement("button");return d.classList.add("cal-nav__btn","cal-nav__btn--next"),d.innerHTML=se,d.setAttribute("aria-label","Next month"),d.addEventListener("click",t),i.appendChild(o),i.appendChild(h),i.appendChild(d),i}const Se=`
|
|
275
275
|
.cal-nav {
|
|
276
276
|
display: flex;
|
|
277
277
|
align-items: center;
|
|
@@ -312,7 +312,7 @@
|
|
|
312
312
|
.cal-nav__title--interactive:hover {
|
|
313
313
|
background: hsl(var(--cal-hover));
|
|
314
314
|
}
|
|
315
|
-
|
|
315
|
+
`;function Le({pickerYear:s,viewMonth:e,viewYear:a,onMonthSelect:t,onYearPrev:n,onYearNext:r,onClose:i,locale:o}){const l=document.createElement("div");l.classList.add("cal-myp","cal-animate-fade");const g=document.createElement("div");g.classList.add("cal-myp__year-nav");const h=document.createElement("button");h.classList.add("cal-nav__btn"),h.innerHTML=ne,h.setAttribute("aria-label","Previous year"),h.addEventListener("click",n);const d=document.createElement("div");d.classList.add("cal-myp__year-label"),d.textContent=s;const c=document.createElement("button");c.classList.add("cal-nav__btn"),c.innerHTML=se,c.setAttribute("aria-label","Next year"),c.addEventListener("click",r),g.appendChild(h),g.appendChild(d),g.appendChild(c),l.appendChild(g);const u=document.createElement("div");u.classList.add("cal-myp__grid");const m=Z(o),f=new Date,C=f.getMonth(),Y=f.getFullYear();for(let w=0;w<12;w++){const v=document.createElement("button");v.classList.add("cal-myp__cell"),v.textContent=m[w],w===e&&s===a&&v.classList.add("cal-myp__cell--active"),w===C&&s===Y&&v.classList.add("cal-myp__cell--today"),v.addEventListener("click",()=>t(w,s)),u.appendChild(v)}return l.appendChild(u),l.addEventListener("keydown",w=>{w.key==="Escape"&&(w.stopPropagation(),i())}),l}const De=`
|
|
316
316
|
.cal-myp {
|
|
317
317
|
width: calc(7 * var(--cal-cell-size));
|
|
318
318
|
}
|
|
@@ -370,7 +370,7 @@
|
|
|
370
370
|
border: 1px solid hsl(var(--cal-border));
|
|
371
371
|
font-weight: 600;
|
|
372
372
|
}
|
|
373
|
-
`;function
|
|
373
|
+
`;function Ee({trigger:s,content:e,onClose:a}){const t=document.createElement("div");t.classList.add("cal-popover"),t.setAttribute("role","dialog"),t.setAttribute("aria-modal","false"),t.style.display="none",t.appendChild(e);let n=!1;function r(){t.classList.remove("cal-popover--above");const d=s.getBoundingClientRect(),c=t.offsetHeight,u=window.innerHeight-d.bottom,m=d.top;u<c+8&&m>u?(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")}function i(){n||(n=!0,t.style.display="",t.classList.add("cal-animate-slide-up"),requestAnimationFrame(()=>r()),document.addEventListener("click",l,!0),document.addEventListener("keydown",g,!0))}function o(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up"),document.removeEventListener("click",l,!0),document.removeEventListener("keydown",g,!0),a==null||a())}function l(d){var u;const c=(u=s.getRootNode())==null?void 0:u.host;c&&!c.contains(d.target)&&d.target!==c&&o()}function g(d){d.key==="Escape"&&(d.stopPropagation(),o())}function h(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up")),document.removeEventListener("click",l,!0),document.removeEventListener("keydown",g,!0)}return{panel:t,open:i,close:o,destroy:h,get isOpen(){return n}}}const Me=`
|
|
374
374
|
.cal-popover-wrapper {
|
|
375
375
|
position: relative;
|
|
376
376
|
display: inline-block;
|
|
@@ -415,7 +415,7 @@
|
|
|
415
415
|
display: flex;
|
|
416
416
|
color: hsl(var(--cal-fg-muted));
|
|
417
417
|
}
|
|
418
|
-
`,
|
|
418
|
+
`,ie={blue:{bg:"var(--cal-booking-blue-bg)",fg:"var(--cal-booking-blue-fg)",hover:"var(--cal-booking-blue-hover)"},green:{bg:"var(--cal-booking-green-bg)",fg:"var(--cal-booking-green-fg)",hover:"var(--cal-booking-green-hover)"},red:{bg:"var(--cal-booking-red-bg)",fg:"var(--cal-booking-red-fg)",hover:"var(--cal-booking-red-hover)"},orange:{bg:"var(--cal-booking-orange-bg)",fg:"var(--cal-booking-orange-fg)",hover:"var(--cal-booking-orange-hover)"},gray:{bg:"var(--cal-booking-gray-bg)",fg:"var(--cal-booking-gray-fg)",hover:"var(--cal-booking-gray-hover)"}},z="blue";function I(s,e){return e&&e[s]?e[s]:ie[s]||ie[z]}function Ce(s){if(!Array.isArray(s)||!s.length)return null;const e={};for(const a of s)!a.name||!a.bg||!a.fg||(e[a.name]={bg:a.bg,fg:a.fg,hover:a.hover||a.bg});return Object.keys(e).length?e:null}function Te(s,e=[],a={},t=null,n=null){const r=e.find(f=>f.end===s),i=e.find(f=>f.start===s),o=e.find(f=>f.start<s&&f.end>s);let l="available",g=null,h=!1,d=null,c=null,u=null;r&&i?(l="half-day",h=!0,d=I(r.color||z,n),c=I(i.color||z,n)):o?(l="booked",u=I(o.color||z,n)):i&&!r?(l="checkin-only",c=I(i.color||z,n)):r&&!i&&(l="checkout-only",d=I(r.color||z,n));const m=a[s];if(m&&(m.status&&(l=m.status),m.label!==void 0&&(g=m.label)),t){const f=t(s);f&&(f.status&&(l=f.status),f.label!==void 0&&(g=f.label))}return{status:l,label:g,checkoutBooking:r,checkinBooking:i,halfDay:h,colorOut:d,colorIn:c,colorFull:u}}function oe(s,e,a=[]){if(!s||!e)return!0;const t=s<e?s:e,n=s<e?e:s;for(const r of a)if(t<r.end&&n>r.start)return!1;return!0}function Ae(s,e,a=[]){return!s||!e?!1:!oe(s,e,a)}function Pe(s){const{year:e,month:a,firstDay:t=0,selectedDates:n=[],rangeStart:r,rangeEnd:i,hoverDate:o,minDate:l,maxDate:g,disabledDates:h=[],mode:d="single",focusedDate:c,onSelect:u,onHover:m,bookings:f=null,dayData:C=null,labelFormula:Y=null,showLabelsOnHover:w=!1,locale:v,customColors:T=null}=s,k=f!==null,B=document.createElement("div");B.setAttribute("role","grid"),B.classList.add("cal-grid");const H=document.createElement("div");H.setAttribute("role","row"),H.classList.add("cal-weekdays");for(const x of me(t,v)){const A=document.createElement("div");A.setAttribute("role","columnheader"),A.setAttribute("aria-label",x),A.classList.add("cal-weekday"),A.textContent=x,H.appendChild(A)}B.appendChild(H);const Ue=ve(e,a,t),V=d==="range"&&r&&!i&&o||k&&r&&!i&&o?o:i,Ke=k?Ae(r,o,f):!1;let R;return Ue.forEach((x,A)=>{A%7===0&&(R=document.createElement("div"),R.setAttribute("role","row"),R.classList.add("cal-row"),B.appendChild(R));const b=document.createElement("button");b.setAttribute("role","gridcell"),b.setAttribute("part","day"),b.classList.add("cal-day");const p=x.dateString;b.dataset.date=p;const Xe=new Date(x.year,x.month,x.day);b.setAttribute("aria-label",Xe.toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"})),x.isCurrentMonth||b.classList.add("cal-day--outside"),x.isToday&&b.classList.add("cal-day--today");let _=null,N=!1;if(k){_=Te(p,f,C||{},Y,T);const{status:y,label:S,halfDay:G,colorOut:J,colorIn:U,colorFull:K}=_;if(y==="booked"&&(b.classList.add("cal-day--booked"),K&&(b.style.setProperty("--booking-bg",`hsl(${K.bg})`),b.style.setProperty("--booking-fg",`hsl(${K.fg})`),b.style.setProperty("--booking-hover",`hsl(${K.hover})`)),N=!0),y==="blocked"&&(b.classList.add("cal-day--blocked"),N=!0),G&&(b.classList.add("cal-day--half-day"),J&&b.style.setProperty("--half-day-color-out",`hsl(${J.bg})`),U&&b.style.setProperty("--half-day-color-in",`hsl(${U.bg})`),N=!0),y==="checkout-only"&&(b.classList.add("cal-day--checkout-only"),J&&b.style.setProperty("--half-day-color-out",`hsl(${J.bg})`)),y==="checkin-only"&&(b.classList.add("cal-day--checkin-only"),U&&b.style.setProperty("--half-day-color-in",`hsl(${U.bg})`)),w){let D=null;if(G&&_.checkoutBooking&&_.checkinBooking)D=`${_.checkoutBooking.label||""} / ${_.checkinBooking.label||""}`;else if(y==="booked"){const X=f.find(ue=>ue.start<=p&&ue.end>p);X&&(D=X.label)}else y==="checkout-only"&&_.checkoutBooking?D=_.checkoutBooking.label:y==="checkin-only"&&_.checkinBooking&&(D=_.checkinBooking.label);D&&b.setAttribute("data-booking-label",D)}if(Ke&&r&&!i&&o){const D=r<o?r:o,X=r<o?o:r;p>=D&&p<=X&&b.classList.add("cal-day--invalid-range")}}if(k?r&&i&&($(p,r)||$(p,i))?(b.classList.add("cal-day--selected"),b.setAttribute("aria-selected","true")):b.setAttribute("aria-selected","false"):n.some(S=>$(S,p))?(b.classList.add("cal-day--selected"),b.setAttribute("aria-selected","true")):b.setAttribute("aria-selected","false"),(d==="range"||k)&&r&&V){const y=$(p,r),S=$(p,V),G=pe(p,r,V);y&&b.classList.add("cal-day--range-start"),S&&b.classList.add("cal-day--range-end"),G&&!y&&!S&&b.classList.add("cal-day--in-range")}const de=$e(p,l,g,h)||N;if(de&&(b.classList.add("cal-day--disabled"),b.disabled=!0,b.setAttribute("aria-disabled","true")),c&&$(p,c)?b.setAttribute("tabindex","0"):b.setAttribute("tabindex","-1"),k&&_&&_.label!=null){b.classList.add("cal-day--with-label");const y=document.createElement("span");y.classList.add("cal-day__number"),y.textContent=x.day,b.appendChild(y);const S=document.createElement("span");S.classList.add("cal-day__label"),S.textContent=_.label,b.appendChild(S)}else b.textContent=x.day;de?k&&b.addEventListener("mouseenter",()=>m==null?void 0:m(p)):(b.addEventListener("click",()=>u==null?void 0:u(p)),b.addEventListener("mouseenter",()=>m==null?void 0:m(p))),R.appendChild(b)}),B.addEventListener("mouseleave",()=>m==null?void 0:m(null)),B}function $e(s,e,a,t){return!!(t.includes(s)||e&&s<e||a&&s>a)}const ze=`
|
|
419
419
|
.cal-grid {
|
|
420
420
|
display: flex;
|
|
421
421
|
flex-direction: column;
|
|
@@ -673,7 +673,7 @@
|
|
|
673
673
|
pointer-events: none;
|
|
674
674
|
z-index: 10;
|
|
675
675
|
}
|
|
676
|
-
`;function
|
|
676
|
+
`;function Ye(s){const{slots:e=[],mode:a="single",format:t="24h",selected:n,hoverTime:r,rangeStart:i,unavailableTimes:o=[],onSelect:l,onHover:g,durationLabels:h=!1}=s,d=document.createElement("div");d.classList.add("cal-time-grid"),h&&d.classList.add("cal-time-grid--duration"),d.setAttribute("role","listbox"),a==="multi"&&d.setAttribute("aria-multiselectable","true");for(const c of e){const u=document.createElement("button");u.classList.add("cal-time-slot"),u.setAttribute("role","option"),u.dataset.time=c.time;const m=j(c.time),f=c.displayText?c.displayText:m?q(m.hours,m.minutes,t):c.time,C=document.createElement("span");if(C.classList.add("cal-time-slot__time"),C.textContent=f,u.appendChild(C),c.label){const v=document.createElement("span");v.classList.add("cal-time-slot__label"),v.textContent=c.label,u.appendChild(v)}const Y=c.available===!1||o.includes(c.time);if(Y&&(u.classList.add("cal-time-slot--unavailable"),u.disabled=!0,u.setAttribute("aria-disabled","true")),Be(c.time,n,a)?(u.classList.add("cal-time-slot--selected"),u.setAttribute("aria-selected","true")):u.setAttribute("aria-selected","false"),a==="range"&&i&&!Fe(n)&&r){const v=ae(c.time,i,r),T=c.time===i,k=c.time===r;v&&!T&&!k&&u.classList.add("cal-time-slot--in-range"),T&&u.classList.add("cal-time-slot--range-start"),k&&u.classList.add("cal-time-slot--range-end")}else if(a==="range"&&n&&typeof n=="object"&&n.start&&n.end){const v=ae(c.time,n.start,n.end),T=c.time===n.start,k=c.time===n.end;T&&u.classList.add("cal-time-slot--range-start","cal-time-slot--selected"),k&&u.classList.add("cal-time-slot--range-end","cal-time-slot--selected"),v&&!T&&!k&&u.classList.add("cal-time-slot--in-range")}Y||(u.addEventListener("click",()=>l==null?void 0:l(c.time)),u.addEventListener("mouseenter",()=>g==null?void 0:g(c.time))),d.appendChild(u)}return d.addEventListener("mouseleave",()=>g==null?void 0:g(null)),d}function Be(s,e,a){return e?a==="single"?e===s:a==="multi"?Array.isArray(e)&&e.includes(s):a==="range"&&typeof e=="object"&&e.start&&e.end?e.start===s||e.end===s:!1:!1}function Fe(s){return s&&typeof s=="object"&&s.start&&s.end}const Oe=`
|
|
677
677
|
.cal-time-grid {
|
|
678
678
|
display: grid;
|
|
679
679
|
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
|
|
@@ -755,7 +755,7 @@
|
|
|
755
755
|
.cal-time-grid--duration .cal-time-slot {
|
|
756
756
|
font-size: 12px;
|
|
757
757
|
}
|
|
758
|
-
`;function
|
|
758
|
+
`;function Ie({columns:s=3,rows:e=4,durationLabels:a=!1}={}){const t=document.createElement("div");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");const n=s*e;for(let r=0;r<n;r++){const i=document.createElement("div");i.classList.add("cal-skeleton"),t.appendChild(i)}return t}function Re({rows:s=5}={}){const e=document.createElement("div");e.setAttribute("role","status"),e.setAttribute("aria-label","Loading..."),e.classList.add("cal-skeleton-calendar-grid");for(let t=0;t<7;t++){const n=document.createElement("div");n.classList.add("cal-skeleton","cal-skeleton-calendar-grid__header"),e.appendChild(n)}const a=7*s;for(let t=0;t<a;t++){const n=document.createElement("div");n.classList.add("cal-skeleton","cal-skeleton-calendar-grid__day"),e.appendChild(n)}return e}const je=`
|
|
759
759
|
.cal-skeleton-time-grid {
|
|
760
760
|
display: grid;
|
|
761
761
|
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
|
|
@@ -788,7 +788,7 @@
|
|
|
788
788
|
aspect-ratio: 1;
|
|
789
789
|
border-radius: var(--cal-radius-sm) !important;
|
|
790
790
|
}
|
|
791
|
-
`,
|
|
791
|
+
`,le={error:'<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 4v3M7 9.5v.01"/></svg>',warning:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M7 1.5L1 12.5h12L7 1.5zM7 6v2.5M7 10.5v.01"/></svg>',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>',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>'};function He({type:s="info",message:e,dismissible:a=!0,onDismiss:t}){const n=document.createElement("div");n.classList.add("cal-status",`cal-status--${s}`,"cal-animate-slide-up"),n.setAttribute("role",s==="error"?"alert":"status"),n.setAttribute("aria-live",s==="error"?"assertive":"polite");const r=document.createElement("span");r.classList.add("cal-status__icon"),r.innerHTML=le[s]||le.info,n.appendChild(r);const i=document.createElement("span");if(i.classList.add("cal-status__text"),i.textContent=e,n.appendChild(i),a){const o=document.createElement("button");o.classList.add("cal-status__close"),o.setAttribute("aria-label","Dismiss"),o.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>',o.addEventListener("click",()=>t==null?void 0:t()),n.appendChild(o)}return n}const Ne=`
|
|
792
792
|
.cal-status {
|
|
793
793
|
display: flex;
|
|
794
794
|
align-items: center;
|
|
@@ -850,7 +850,7 @@
|
|
|
850
850
|
color: hsl(var(--cal-status-success-fg));
|
|
851
851
|
border: 1px solid hsl(var(--cal-status-success-border));
|
|
852
852
|
}
|
|
853
|
-
`,
|
|
853
|
+
`,Ge='<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="12" height="11" rx="2"/><path d="M5 1v3M11 1v3M2 7h12"/></svg>',Je=`
|
|
854
854
|
.cal-picker {
|
|
855
855
|
background: hsl(var(--cal-bg));
|
|
856
856
|
border-radius: var(--cal-radius);
|
|
@@ -884,5 +884,5 @@
|
|
|
884
884
|
color: hsl(var(--cal-fg));
|
|
885
885
|
margin-bottom: 8px;
|
|
886
886
|
}
|
|
887
|
-
`;class ie extends ${static get styles(){return[pe,ve,ye,Te,Pe,ke,we,Le,Oe,Re,je]}static get observedAttributes(){return["theme","display","min-date","max-date","first-day","placeholder","dual","show-labels-on-hover","time-slots","time-start","time-end","time-interval","time-format","duration-labels","loading"]}constructor(){super();const e=new Date;this._store=ce({viewYear:e.getFullYear(),viewMonth:e.getMonth(),rangeStart:null,rangeEnd:null,hoverDate:null,isOpen:!1,focusedDate:V(),navDirection:null,pickingMonth:!1,pickerYear:e.getFullYear(),startTime:null,endTime:null,timeSelectPhase:null,statusType:null,statusMessage:null,statusDismissible:!0}),this._bookings=[],this._dayData={},this._labelFormula=null,this._timeSlots=null,this._popover=null,this._unsubscribe=null,this._rendering=!1}get display(){return this.getAttribute("display")||"inline"}get placeholder(){return this.getAttribute("placeholder")||"Select dates"}get firstDay(){return parseInt(this.getAttribute("first-day")||"0",10)}get minDate(){return this.getAttribute("min-date")||null}get maxDate(){return this.getAttribute("max-date")||null}get showLabelsOnHover(){return this.hasAttribute("show-labels-on-hover")}get timeSlotsEnabled(){return this.hasAttribute("time-slots")}get timeStartTime(){return this.getAttribute("time-start")||"09:00"}get timeEndTime(){return this.getAttribute("time-end")||"17:00"}get timeInterval(){return parseInt(this.getAttribute("time-interval")||"60",10)}get timeFormat(){return this.getAttribute("time-format")||"24h"}get durationLabels(){return this.hasAttribute("duration-labels")}get loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get bookings(){return this._bookings}set bookings(e){this._bookings=Array.isArray(e)?e:[],this._initialized&&this.render()}get dayData(){return this._dayData}set dayData(e){this._dayData=e&&typeof e=="object"?e:{},this._initialized&&this.render()}get labelFormula(){return this._labelFormula}set labelFormula(e){this._labelFormula=typeof e=="function"?e:null,this._initialized&&this.render()}get timeSlots(){return this._timeSlots}set timeSlots(e){this._timeSlots=Array.isArray(e)?e:null,this._initialized&&this.render()}get value(){const e=this._store.getState();if(!e.rangeStart||!e.rangeEnd)return null;const a={start:e.rangeStart,end:e.rangeEnd};return this.timeSlotsEnabled&&(e.startTime&&(a.startTime=e.startTime),e.endTime&&(a.endTime=e.endTime)),a}set value(e){if(e&&typeof e=="object"&&e.start&&e.end){const a=typeof e.start=="string"?e.start:C(e.start),t=typeof e.end=="string"?e.end:C(e.end),n={rangeStart:a,rangeEnd:t};e.startTime&&(n.startTime=e.startTime),e.endTime&&(n.endTime=e.endTime),this._store.set(n),this._navigateToDate(a)}else this._store.set({rangeStart:null,rangeEnd:null,startTime:null,endTime:null,timeSelectPhase:null})}_navigateToDate(e){const a=E(e);a&&this._store.set({viewYear:a.getFullYear(),viewMonth:a.getMonth()})}connectedCallback(){super.connectedCallback(),this._unsubscribe=this._store.subscribe((a,t)=>{if(this._rendering)return;a.hoverDate!==t.hoverDate&&a.viewYear===t.viewYear&&a.viewMonth===t.viewMonth&&a.rangeStart===t.rangeStart&&a.rangeEnd===t.rangeEnd&&a.isOpen===t.isOpen&&a.navDirection===t.navDirection&&a.pickingMonth===t.pickingMonth&&a.pickerYear===t.pickerYear&&a.timeSelectPhase===t.timeSelectPhase?this._updateGridHighlight(a):this.render()});const e=this.getAttribute("bookings");if(e&&!this._bookings.length)try{this._bookings=JSON.parse(e)}catch{}}disconnectedCallback(){var e,a;(e=this._unsubscribe)==null||e.call(this),(a=this._popover)==null||a.destroy(),clearTimeout(this._statusTimer)}attributeChangedCallback(e,a,t){a!==t&&this._initialized&&this.render()}_handleSelect(e){const a=this._store.getState();if(!a.rangeStart||a.rangeEnd)this._store.set({rangeStart:e,rangeEnd:null,hoverDate:null,focusedDate:e,startTime:null,endTime:null,timeSelectPhase:null});else{let t=a.rangeStart,n=e;if(t>n&&([t,n]=[n,t]),!ne(t,n,this._bookings)){this.emit("cal:selection-invalid",{start:t,end:n}),this._store.set({rangeStart:null,rangeEnd:null,hoverDate:null,startTime:null,endTime:null,timeSelectPhase:null}),this.showStatus("error","Selection overlaps an existing booking",{autoDismiss:4e3});return}this.timeSlotsEnabled?this._store.set({rangeStart:t,rangeEnd:n,hoverDate:null,focusedDate:n,timeSelectPhase:"start"}):(this._store.set({rangeStart:t,rangeEnd:n,hoverDate:null,focusedDate:n}),this.emit("cal:change",{value:{start:t,end:n}}),this.display==="popover"&&this.close())}}_handleTimeSelect(e){const a=this._store.getState();if(a.timeSelectPhase==="start")this._store.set({startTime:e,timeSelectPhase:"end"});else if(a.timeSelectPhase==="end"){this._store.set({endTime:e,timeSelectPhase:null});const t={start:a.rangeStart,end:a.rangeEnd,startTime:a.startTime,endTime:e};this.emit("cal:change",{value:t}),this.display==="popover"&&this.close()}}_handleHover(e){this._store.set({hoverDate:e})}_updateGridHighlight(e){const a=this.$$(".cal-day"),{rangeStart:t,hoverDate:n}=e,i=t&&!e.rangeEnd&&n?n:e.rangeEnd;let o=!1;if(t&&!e.rangeEnd&&n){const r=t<n?t:n,l=t<n?n:t;for(const u of this._bookings)if(r<u.end&&l>u.start){o=!0;break}}for(const r of a){const l=r.dataset.date;if(!l)continue;const u=l===t&&!!i,m=l===i&&!!i;let g=!1;if(t&&i){const d=t<i?t:i,b=t<i?i:t;g=l>=d&&l<=b&&!u&&!m}const c=o&&t&&!e.rangeEnd&&n&&(()=>{const d=t<n?t:n,b=t<n?n:t;return l>=d&&l<=b})();r.classList.toggle("cal-day--range-start",u),r.classList.toggle("cal-day--range-end",m),r.classList.toggle("cal-day--in-range",g),r.classList.toggle("cal-day--invalid-range",!!c)}}_prevMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=B(e,a,-1);this._store.set({viewYear:t,viewMonth:n,navDirection:"prev"}),this.emit("cal:month-change",{year:t,month:n})}_nextMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=B(e,a,1);this._store.set({viewYear:t,viewMonth:n,navDirection:"next"}),this.emit("cal:month-change",{year:t,month:n})}_toggleMonthPicker(){const e=this._store.getState();this._store.set({pickingMonth:!e.pickingMonth,pickerYear:e.viewYear})}_selectMonthFromPicker(e,a){this._store.set({viewYear:a,viewMonth:e,pickingMonth:!1}),this.emit("cal:month-change",{year:a,month:e})}_handleKeydown(e){if(e.key==="Escape"&&this._store.get("pickingMonth")){e.stopPropagation(),this._store.set({pickingMonth:!1});return}const a=this._store.getState(),t=E(a.focusedDate);if(!t)return;let n=null;switch(e.key){case"ArrowLeft":n=new Date(t),n.setDate(t.getDate()-1);break;case"ArrowRight":n=new Date(t),n.setDate(t.getDate()+1);break;case"ArrowUp":n=new Date(t),n.setDate(t.getDate()-7);break;case"ArrowDown":n=new Date(t),n.setDate(t.getDate()+7);break;case"Enter":case" ":e.preventDefault(),this._handleSelect(a.focusedDate);return;case"Escape":this.display==="popover"&&this.close();return;default:return}if(n){e.preventDefault();const i=C(n);n.getMonth()!==a.viewMonth||n.getFullYear()!==a.viewYear?this._store.set({viewYear:n.getFullYear(),viewMonth:n.getMonth(),focusedDate:i,navDirection:n>t?"next":"prev"}):this._store.set({focusedDate:i}),requestAnimationFrame(()=>{const o=this.$(`[data-date="${i}"]`);o==null||o.focus()})}}open(){this._popover&&(this._popover.open(),this._store.set({isOpen:!0}),this.emit("cal:open"))}close(){this._popover&&(this._popover.close(),this._store.set({isOpen:!1}),this.emit("cal:close"))}goToMonth(e,a){this._store.set({viewYear:a,viewMonth:e})}_getTimeSlotArray(){return this._timeSlots?this._timeSlots:this.durationLabels?fe(this.timeStartTime,this.timeEndTime,this.timeInterval,this.timeFormat).map(a=>({...a,available:!0})):me(this.timeStartTime,this.timeEndTime,this.timeInterval).map(a=>({time:a,available:!0}))}_renderCalendarContent(){const e=this._store.getState(),a=document.createElement("div");if(a.classList.add("cal-picker"),e.statusType&&e.statusMessage&&a.appendChild(Fe({type:e.statusType,message:e.statusMessage,dismissible:e.statusDismissible,onDismiss:()=>this.clearStatus()})),this.loading){const o=document.createElement("div");o.classList.add("cal-months");const r=document.createElement("div");if(r.classList.add("cal-month"),r.appendChild(Be()),o.appendChild(r),a.appendChild(o),this.timeSlotsEnabled){const l=document.createElement("div");l.classList.add("cal-booking-time-section"),l.appendChild($e({durationLabels:this.durationLabels})),a.appendChild(l)}return a.addEventListener("keydown",l=>this._handleKeydown(l)),a}const t=document.createElement("div");t.classList.add("cal-months");const n=this.hasAttribute("dual"),i=n?2:1;for(let o=0;o<i;o++){const{year:r,month:l}=o===0?{year:e.viewYear,month:e.viewMonth}:B(e.viewYear,e.viewMonth,1),u=document.createElement("div");if(u.classList.add("cal-month"),o===0&&u.appendChild(te({year:r,month:l,onPrev:e.pickingMonth?()=>{}:()=>this._prevMonth(),onNext:e.pickingMonth?()=>{}:()=>{n||this._nextMonth()},onTitleClick:()=>this._toggleMonthPicker()})),o===1&&u.appendChild(te({year:r,month:l,onPrev:()=>{},onNext:()=>this._nextMonth()})),e.pickingMonth&&o===0){const m=xe({pickerYear:e.pickerYear,viewMonth:e.viewMonth,viewYear:e.viewYear,onMonthSelect:(g,c)=>this._selectMonthFromPicker(g,c),onYearPrev:()=>this._store.set({pickerYear:e.pickerYear-1}),onYearNext:()=>this._store.set({pickerYear:e.pickerYear+1}),onClose:()=>this._store.set({pickingMonth:!1})});u.appendChild(m)}else{const m=e.navDirection==="next"?"cal-animate-slide-left":e.navDirection==="prev"?"cal-animate-slide-right":"",g=Me({year:r,month:l,firstDay:this.firstDay,rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,hoverDate:e.hoverDate,minDate:this.minDate,maxDate:this.maxDate,focusedDate:e.focusedDate,mode:"range",onSelect:c=>this._handleSelect(c),onHover:c=>this._handleHover(c),bookings:this._bookings,dayData:this._dayData,labelFormula:this._labelFormula,showLabelsOnHover:this.showLabelsOnHover});m&&g.classList.add(m),u.appendChild(g)}t.appendChild(u)}if(a.appendChild(t),this.timeSlotsEnabled&&e.timeSelectPhase&&!e.pickingMonth){const o=document.createElement("div");o.classList.add("cal-booking-time-section");const r=document.createElement("div");r.classList.add("cal-booking-time-header"),r.textContent=e.timeSelectPhase==="start"?"Select check-in time":"Select check-out time",o.appendChild(r);const l=this._getTimeSlotArray(),u=Ae({slots:l,mode:"single",format:this.timeFormat,selected:e.timeSelectPhase==="end"?e.startTime:null,onSelect:m=>this._handleTimeSelect(m),onHover:()=>{},durationLabels:this.durationLabels});o.appendChild(u),a.appendChild(o)}return a.addEventListener("keydown",o=>this._handleKeydown(o)),a}_formatTriggerText(){const e=this._store.getState();if(e.rangeStart&&e.rangeEnd){let a=`${this._formatShortDate(e.rangeStart)} – ${this._formatShortDate(e.rangeEnd)}`;return e.startTime&&e.endTime&&(a+=` (${e.startTime} – ${e.endTime})`),a}return null}_formatShortDate(e){const a=E(e);return a?`${K[a.getMonth()].slice(0,3)} ${a.getDate()}, ${a.getFullYear()}`:e}render(){var t;if(this._rendering)return;this._rendering=!0;const e=this.shadowRoot,a=[...e.childNodes];for(const n of a)n.nodeName!=="STYLE"&&!(n instanceof CSSStyleSheet)&&e.removeChild(n);if((t=this._popover)==null||t.destroy(),this._popover=null,this.display==="popover"){const n=document.createElement("div");n.classList.add("cal-popover-wrapper");const i=document.createElement("button");i.classList.add("cal-trigger");const o=document.createElement("span");o.classList.add("cal-trigger__icon"),o.innerHTML=Ie,i.appendChild(o);const r=this._formatTriggerText(),l=document.createElement("span");r?l.textContent=r:(l.textContent=this.placeholder,l.classList.add("cal-trigger--placeholder")),i.appendChild(l),n.appendChild(i);const u=this._renderCalendarContent(),m=Se({trigger:i,content:u,onClose:()=>{this._store.set({isOpen:!1}),this.emit("cal:close")}});n.appendChild(m.panel),e.appendChild(n),i.addEventListener("click",g=>{g.stopPropagation(),m.isOpen?this.close():this.open()}),this._popover=m,this._store.get("isOpen")&&m.open()}else e.appendChild(this._renderCalendarContent());this._store.set({navDirection:null}),this._rendering=!1}}customElements.get("cal-booking")||customElements.define("cal-booking",ie),Y.CalBooking=ie,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})}));
|
|
887
|
+
`;class ce extends F{static get styles(){return[_e,we,xe,ze,Oe,Se,De,Me,je,Ne,Je]}static get observedAttributes(){return["theme","display","min-date","max-date","first-day","locale","placeholder","dual","show-labels-on-hover","time-slots","time-start","time-end","time-interval","time-format","duration-labels","loading"]}constructor(){super();const e=new Date;this._store=ge({viewYear:e.getFullYear(),viewMonth:e.getMonth(),rangeStart:null,rangeEnd:null,hoverDate:null,isOpen:!1,focusedDate:te(),navDirection:null,pickingMonth:!1,pickerYear:e.getFullYear(),startTime:null,endTime:null,timeSelectPhase:null,statusType:null,statusMessage:null,statusDismissible:!0}),this._bookings=[],this._dayData={},this._labelFormula=null,this._colors=null,this._customColorMap=null,this._timeSlots=null,this._popover=null,this._unsubscribe=null,this._rendering=!1}get display(){return this.getAttribute("display")||"inline"}get placeholder(){return this.getAttribute("placeholder")||"Select dates"}get firstDay(){return parseInt(this.getAttribute("first-day")||"0",10)}get minDate(){return this.getAttribute("min-date")||null}get maxDate(){return this.getAttribute("max-date")||null}get locale(){return this.getAttribute("locale")||void 0}get showLabelsOnHover(){return this.hasAttribute("show-labels-on-hover")}get timeSlotsEnabled(){return this.hasAttribute("time-slots")}get timeStartTime(){return this.getAttribute("time-start")||"09:00"}get timeEndTime(){return this.getAttribute("time-end")||"17:00"}get timeInterval(){return parseInt(this.getAttribute("time-interval")||"60",10)}get timeFormat(){return this.getAttribute("time-format")||"24h"}get durationLabels(){return this.hasAttribute("duration-labels")}get loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get bookings(){return this._bookings}set bookings(e){this._bookings=Array.isArray(e)?e:[],this._initialized&&this.render()}get dayData(){return this._dayData}set dayData(e){this._dayData=e&&typeof e=="object"?e:{},this._initialized&&this.render()}get labelFormula(){return this._labelFormula}set labelFormula(e){this._labelFormula=typeof e=="function"?e:null,this._initialized&&this.render()}get timeSlots(){return this._timeSlots}set timeSlots(e){this._timeSlots=Array.isArray(e)?e:null,this._initialized&&this.render()}get colors(){return this._colors}set colors(e){if(this._colors=Array.isArray(e)?e:null,this._customColorMap=Ce(this._colors),this._customColorMap)for(const[a,t]of Object.entries(this._customColorMap))this.style.setProperty(`--cal-booking-${a}-bg`,t.bg),this.style.setProperty(`--cal-booking-${a}-fg`,t.fg),this.style.setProperty(`--cal-booking-${a}-hover`,t.hover);this._initialized&&this.render()}get value(){const e=this._store.getState();if(!e.rangeStart||!e.rangeEnd)return null;const a={start:e.rangeStart,end:e.rangeEnd};return this.timeSlotsEnabled&&(e.startTime&&(a.startTime=e.startTime),e.endTime&&(a.endTime=e.endTime)),a}set value(e){if(e&&typeof e=="object"&&e.start&&e.end){const a=typeof e.start=="string"?e.start:E(e.start),t=typeof e.end=="string"?e.end:E(e.end),n={rangeStart:a,rangeEnd:t};e.startTime&&(n.startTime=e.startTime),e.endTime&&(n.endTime=e.endTime),this._store.set(n),this._navigateToDate(a)}else this._store.set({rangeStart:null,rangeEnd:null,startTime:null,endTime:null,timeSelectPhase:null})}_navigateToDate(e){const a=L(e);a&&this._store.set({viewYear:a.getFullYear(),viewMonth:a.getMonth()})}connectedCallback(){super.connectedCallback(),this._unsubscribe=this._store.subscribe((a,t)=>{if(this._rendering)return;a.hoverDate!==t.hoverDate&&a.viewYear===t.viewYear&&a.viewMonth===t.viewMonth&&a.rangeStart===t.rangeStart&&a.rangeEnd===t.rangeEnd&&a.isOpen===t.isOpen&&a.navDirection===t.navDirection&&a.pickingMonth===t.pickingMonth&&a.pickerYear===t.pickerYear&&a.timeSelectPhase===t.timeSelectPhase?this._updateGridHighlight(a):this.render()});const e=this.getAttribute("bookings");if(e&&!this._bookings.length)try{this._bookings=JSON.parse(e)}catch{}}disconnectedCallback(){var e,a;(e=this._unsubscribe)==null||e.call(this),(a=this._popover)==null||a.destroy(),clearTimeout(this._statusTimer)}attributeChangedCallback(e,a,t){a!==t&&this._initialized&&this.render()}_handleSelect(e){const a=this._store.getState();if(!a.rangeStart||a.rangeEnd)this._store.set({rangeStart:e,rangeEnd:null,hoverDate:null,focusedDate:e,startTime:null,endTime:null,timeSelectPhase:null});else{let t=a.rangeStart,n=e;if(t>n&&([t,n]=[n,t]),!oe(t,n,this._bookings)){this.emit("cal:selection-invalid",{start:t,end:n}),this._store.set({rangeStart:null,rangeEnd:null,hoverDate:null,startTime:null,endTime:null,timeSelectPhase:null}),this.showStatus("error","Selection overlaps an existing booking",{autoDismiss:4e3});return}this.timeSlotsEnabled?this._store.set({rangeStart:t,rangeEnd:n,hoverDate:null,focusedDate:n,timeSelectPhase:"start"}):(this._store.set({rangeStart:t,rangeEnd:n,hoverDate:null,focusedDate:n}),this.emit("cal:change",{value:{start:t,end:n}}),this.display==="popover"&&this.close())}}_handleTimeSelect(e){const a=this._store.getState();if(a.timeSelectPhase==="start")this._store.set({startTime:e,timeSelectPhase:"end"});else if(a.timeSelectPhase==="end"){this._store.set({endTime:e,timeSelectPhase:null});const t={start:a.rangeStart,end:a.rangeEnd,startTime:a.startTime,endTime:e};this.emit("cal:change",{value:t}),this.display==="popover"&&this.close()}}_handleHover(e){this._store.set({hoverDate:e})}_updateGridHighlight(e){const a=this.$$(".cal-day"),{rangeStart:t,hoverDate:n}=e,r=t&&!e.rangeEnd&&n?n:e.rangeEnd;let i=!1;if(t&&!e.rangeEnd&&n){const o=t<n?t:n,l=t<n?n:t;for(const g of this._bookings)if(o<g.end&&l>g.start){i=!0;break}}for(const o of a){const l=o.dataset.date;if(!l)continue;const g=l===t&&!!r,h=l===r&&!!r;let d=!1;if(t&&r){const u=t<r?t:r,m=t<r?r:t;d=l>=u&&l<=m&&!g&&!h}const c=i&&t&&!e.rangeEnd&&n&&(()=>{const u=t<n?t:n,m=t<n?n:t;return l>=u&&l<=m})();o.classList.toggle("cal-day--range-start",g),o.classList.toggle("cal-day--range-end",h),o.classList.toggle("cal-day--in-range",d),o.classList.toggle("cal-day--invalid-range",!!c)}}_prevMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=O(e,a,-1);this._store.set({viewYear:t,viewMonth:n,navDirection:"prev"}),this.emit("cal:month-change",{year:t,month:n})}_nextMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=O(e,a,1);this._store.set({viewYear:t,viewMonth:n,navDirection:"next"}),this.emit("cal:month-change",{year:t,month:n})}_toggleMonthPicker(){const e=this._store.getState();this._store.set({pickingMonth:!e.pickingMonth,pickerYear:e.viewYear})}_selectMonthFromPicker(e,a){this._store.set({viewYear:a,viewMonth:e,pickingMonth:!1}),this.emit("cal:month-change",{year:a,month:e})}_handleKeydown(e){if(e.key==="Escape"&&this._store.get("pickingMonth")){e.stopPropagation(),this._store.set({pickingMonth:!1});return}const a=this._store.getState(),t=L(a.focusedDate);if(!t)return;let n=null;switch(e.key){case"ArrowLeft":n=new Date(t),n.setDate(t.getDate()-1);break;case"ArrowRight":n=new Date(t),n.setDate(t.getDate()+1);break;case"ArrowUp":n=new Date(t),n.setDate(t.getDate()-7);break;case"ArrowDown":n=new Date(t),n.setDate(t.getDate()+7);break;case"Enter":case" ":e.preventDefault(),this._handleSelect(a.focusedDate);return;case"Escape":this.display==="popover"&&this.close();return;default:return}if(n){e.preventDefault();const r=E(n);n.getMonth()!==a.viewMonth||n.getFullYear()!==a.viewYear?this._store.set({viewYear:n.getFullYear(),viewMonth:n.getMonth(),focusedDate:r,navDirection:n>t?"next":"prev"}):this._store.set({focusedDate:r}),requestAnimationFrame(()=>{const i=this.$(`[data-date="${r}"]`);i==null||i.focus()})}}open(){this._popover&&(this._popover.open(),this._store.set({isOpen:!0}),this.emit("cal:open"))}close(){this._popover&&(this._popover.close(),this._store.set({isOpen:!1}),this.emit("cal:close"))}goToMonth(e,a){this._store.set({viewYear:a,viewMonth:e})}clear(){this._store.set({rangeStart:null,rangeEnd:null,hoverDate:null,startTime:null,endTime:null,timeSelectPhase:null}),this.emit("cal:change",{value:null})}_getTimeSlotArray(){return this._timeSlots?this._timeSlots:this.durationLabels?ke(this.timeStartTime,this.timeEndTime,this.timeInterval,this.timeFormat).map(a=>({...a,available:!0})):ye(this.timeStartTime,this.timeEndTime,this.timeInterval).map(a=>({time:a,available:!0}))}_renderCalendarContent(){const e=this._store.getState(),a=document.createElement("div");if(a.classList.add("cal-picker"),e.statusType&&e.statusMessage&&a.appendChild(He({type:e.statusType,message:e.statusMessage,dismissible:e.statusDismissible,onDismiss:()=>this.clearStatus()})),this.loading){const i=document.createElement("div");i.classList.add("cal-months");const o=document.createElement("div");if(o.classList.add("cal-month"),o.appendChild(Re()),i.appendChild(o),a.appendChild(i),this.timeSlotsEnabled){const l=document.createElement("div");l.classList.add("cal-booking-time-section"),l.appendChild(Ie({durationLabels:this.durationLabels})),a.appendChild(l)}return a.addEventListener("keydown",l=>this._handleKeydown(l)),a}const t=document.createElement("div");t.classList.add("cal-months");const n=this.hasAttribute("dual"),r=n?2:1;for(let i=0;i<r;i++){const{year:o,month:l}=i===0?{year:e.viewYear,month:e.viewMonth}:O(e.viewYear,e.viewMonth,1),g=document.createElement("div");if(g.classList.add("cal-month"),i===0&&g.appendChild(re({year:o,month:l,onPrev:e.pickingMonth?()=>{}:()=>this._prevMonth(),onNext:e.pickingMonth?()=>{}:()=>{n||this._nextMonth()},onTitleClick:()=>this._toggleMonthPicker(),locale:this.locale})),i===1&&g.appendChild(re({year:o,month:l,onPrev:()=>{},onNext:()=>this._nextMonth(),locale:this.locale})),e.pickingMonth&&i===0){const h=Le({pickerYear:e.pickerYear,viewMonth:e.viewMonth,viewYear:e.viewYear,onMonthSelect:(d,c)=>this._selectMonthFromPicker(d,c),onYearPrev:()=>this._store.set({pickerYear:e.pickerYear-1}),onYearNext:()=>this._store.set({pickerYear:e.pickerYear+1}),onClose:()=>this._store.set({pickingMonth:!1}),locale:this.locale});g.appendChild(h)}else{const h=e.navDirection==="next"?"cal-animate-slide-left":e.navDirection==="prev"?"cal-animate-slide-right":"",d=Pe({year:o,month:l,firstDay:this.firstDay,rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,hoverDate:e.hoverDate,minDate:this.minDate,maxDate:this.maxDate,focusedDate:e.focusedDate,mode:"range",onSelect:c=>this._handleSelect(c),onHover:c=>this._handleHover(c),bookings:this._bookings,dayData:this._dayData,labelFormula:this._labelFormula,showLabelsOnHover:this.showLabelsOnHover,locale:this.locale,customColors:this._customColorMap});h&&d.classList.add(h),g.appendChild(d)}t.appendChild(g)}if(a.appendChild(t),this.timeSlotsEnabled&&e.timeSelectPhase&&!e.pickingMonth){const i=document.createElement("div");i.classList.add("cal-booking-time-section");const o=document.createElement("div");o.classList.add("cal-booking-time-header"),o.textContent=e.timeSelectPhase==="start"?"Select check-in time":"Select check-out time",i.appendChild(o);const l=this._getTimeSlotArray(),g=Ye({slots:l,mode:"single",format:this.timeFormat,selected:e.timeSelectPhase==="end"?e.startTime:null,onSelect:h=>this._handleTimeSelect(h),onHover:()=>{},durationLabels:this.durationLabels});i.appendChild(g),a.appendChild(i)}return a.addEventListener("keydown",i=>this._handleKeydown(i)),a}_formatTriggerText(){const e=this._store.getState();if(e.rangeStart&&e.rangeEnd){let a=`${this._formatShortDate(e.rangeStart)} – ${this._formatShortDate(e.rangeEnd)}`;return e.startTime&&e.endTime&&(a+=` (${e.startTime} – ${e.endTime})`),a}return null}_formatShortDate(e){const a=L(e);if(!a)return e;if(this.locale)try{return new Intl.DateTimeFormat(this.locale,{month:"short",day:"numeric",year:"numeric"}).format(a)}catch{}return`${Z(this.locale)[a.getMonth()]} ${a.getDate()}, ${a.getFullYear()}`}render(){var t;if(this._rendering)return;this._rendering=!0;const e=this.shadowRoot,a=[...e.childNodes];for(const n of a)n.nodeName!=="STYLE"&&!(n instanceof CSSStyleSheet)&&e.removeChild(n);if((t=this._popover)==null||t.destroy(),this._popover=null,this.display==="popover"){const n=document.createElement("div");n.classList.add("cal-popover-wrapper");const r=document.createElement("button");r.classList.add("cal-trigger");const i=document.createElement("span");i.classList.add("cal-trigger__icon"),i.innerHTML=Ge,r.appendChild(i);const o=this._formatTriggerText(),l=document.createElement("span");o?l.textContent=o:(l.textContent=this.placeholder,l.classList.add("cal-trigger--placeholder")),r.appendChild(l),n.appendChild(r);const g=this._renderCalendarContent(),h=Ee({trigger:r,content:g,onClose:()=>{this._store.set({isOpen:!1}),this.emit("cal:close")}});n.appendChild(h.panel),e.appendChild(n),r.addEventListener("click",d=>{d.stopPropagation(),h.isOpen?this.close():this.open()}),this._popover=h,this._store.get("isOpen")&&h.open()}else e.appendChild(this._renderCalendarContent());this._store.set({navDirection:null}),this._rendering=!1}}customElements.get("cal-booking")||customElements.define("cal-booking",ce),P.CalBooking=ce,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}));
|
|
888
888
|
//# sourceMappingURL=booking.umd.js.map
|