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/datepicker.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(A,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(A=typeof globalThis<"u"?globalThis:A||self,B(A.CalDatepicker={}))})(this,(function(A){"use strict";class B 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 le(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 o of Object.keys(t))if(n[o]!==e[o]){r=!0;break}if(r)for(const o of a)o(e,n)},getState(){return e},subscribe(t){return a.add(t),()=>a.delete(t)}}}const X=["January","February","March","April","May","June","July","August","September","October","November","December"],ie=["Su","Mo","Tu","We","Th","Fr","Sa"];function ce(s){if(!s)return X;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 X}}function q(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 de(s=0,e){if(e)try{const t=new Intl.DateTimeFormat(e,{weekday:"short"}),n=[];for(let r=0;r<7;r++){const o=new Date(2024,0,7+(s+r)%7),l=t.format(o);n.push(l.charAt(0).toUpperCase()+l.slice(1))}return n}catch{}const a=[];for(let t=0;t<7;t++)a.push(ie[(s+t)%7]);return a}function Q(s,e){return new Date(s,e+1,0).getDate()}function ge(s,e){return new Date(s,e,1).getDay()}function m(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 D(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 E(s,e){if(!s||!e)return!1;const a=D(s),t=D(e);return!a||!t?!1:a.getFullYear()===t.getFullYear()&&a.getMonth()===t.getMonth()&&a.getDate()===t.getDate()}function ue(s,e,a){if(!s||!e||!a)return!1;const t=D(s),n=D(e),r=D(a);if(!t||!n||!r)return!1;const o=t.getTime(),l=Math.min(n.getTime(),r.getTime()),i=Math.max(n.getTime(),r.getTime());return o>=l&&o<=i}function J(){return m(new Date)}function z(s,e,a){const t=new Date(s,e+a,1);return{year:t.getFullYear(),month:t.getMonth()}}function he(s,e,a=0){const t=Q(s,e),r=(ge(s,e)-a+7)%7,o=[],l=J(),i=z(s,e,-1),h=Q(i.year,i.month);for(let u=r-1;u>=0;u--){const p=h-u,b=m({year:i.year,month:i.month,day:p});o.push({year:i.year,month:i.month,day:p,dateString:b,isCurrentMonth:!1,isToday:b===l})}for(let u=1;u<=t;u++){const p=m({year:s,month:e,day:u});o.push({year:s,month:e,day:u,dateString:p,isCurrentMonth:!0,isToday:p===l})}const d=z(s,e,1);let g=1;for(;o.length<42;){const u=m({year:d.year,month:d.month,day:g});o.push({year:d.year,month:d.month,day:g,dateString:u,isCurrentMonth:!1,isToday:u===l}),g++}return o}const pe=`
|
|
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
|
+
`,be=`
|
|
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
|
+
`,fe=`
|
|
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
|
+
`,Z={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)"}},T="blue";function P(s,e){return e&&e[s]?e[s]:Z[s]||Z[T]}function ve(s,e=[],a={},t=null,n=null){const r=e.find(f=>f.end===s),o=e.find(f=>f.start===s),l=e.find(f=>f.start<s&&f.end>s);let i="available",h=null,d=!1,g=null,u=null,p=null;r&&o?(i="half-day",d=!0,g=P(r.color||T,n),u=P(o.color||T,n)):l?(i="booked",p=P(l.color||T,n)):o&&!r?(i="checkin-only",u=P(o.color||T,n)):r&&!o&&(i="checkout-only",g=P(r.color||T,n));const b=a[s];if(b&&(b.status&&(i=b.status),b.label!==void 0&&(h=b.label)),t){const f=t(s);f&&(f.status&&(i=f.status),f.label!==void 0&&(h=f.label))}return{status:i,label:h,checkoutBooking:r,checkinBooking:o,halfDay:d,colorOut:g,colorIn:u,colorFull:p}}function ye(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 me(s,e,a=[]){return!s||!e?!1:!ye(s,e,a)}function ke(s){const{year:e,month:a,firstDay:t=0,selectedDates:n=[],rangeStart:r,rangeEnd:o,hoverDate:l,minDate:i,maxDate:h,disabledDates:d=[],mode:g="single",focusedDate:u,onSelect:p,onHover:b,bookings:f=null,dayData:G=null,labelFormula:U=null,showLabelsOnHover:_=!1,locale:L,customColors:$e=null}=s,M=f!==null,Y=document.createElement("div");Y.setAttribute("role","grid"),Y.classList.add("cal-grid");const F=document.createElement("div");F.setAttribute("role","row"),F.classList.add("cal-weekdays");for(const w of de(t,L)){const C=document.createElement("div");C.setAttribute("role","columnheader"),C.setAttribute("aria-label",w),C.classList.add("cal-weekday"),C.textContent=w,F.appendChild(C)}Y.appendChild(F);const Fe=he(e,a,t),W=g==="range"&&r&&!o&&l||M&&r&&!o&&l?l:o,Re=M?me(r,l,f):!1;let O;return Fe.forEach((w,C)=>{C%7===0&&(O=document.createElement("div"),O.setAttribute("role","row"),O.classList.add("cal-row"),Y.appendChild(O));const c=document.createElement("button");c.setAttribute("role","gridcell"),c.setAttribute("part","day"),c.classList.add("cal-day");const v=w.dateString;c.dataset.date=v;const Ne=new Date(w.year,w.month,w.day);c.setAttribute("aria-label",Ne.toLocaleDateString("en-US",{weekday:"long",year:"numeric",month:"long",day:"numeric"})),w.isCurrentMonth||c.classList.add("cal-day--outside"),w.isToday&&c.classList.add("cal-day--today");let k=null,R=!1;if(M){k=ve(v,f,G||{},U,$e);const{status:y,label:x,halfDay:N,colorOut:I,colorIn:H,colorFull:j}=k;if(y==="booked"&&(c.classList.add("cal-day--booked"),j&&(c.style.setProperty("--booking-bg",`hsl(${j.bg})`),c.style.setProperty("--booking-fg",`hsl(${j.fg})`),c.style.setProperty("--booking-hover",`hsl(${j.hover})`)),R=!0),y==="blocked"&&(c.classList.add("cal-day--blocked"),R=!0),N&&(c.classList.add("cal-day--half-day"),I&&c.style.setProperty("--half-day-color-out",`hsl(${I.bg})`),H&&c.style.setProperty("--half-day-color-in",`hsl(${H.bg})`),R=!0),y==="checkout-only"&&(c.classList.add("cal-day--checkout-only"),I&&c.style.setProperty("--half-day-color-out",`hsl(${I.bg})`)),y==="checkin-only"&&(c.classList.add("cal-day--checkin-only"),H&&c.style.setProperty("--half-day-color-in",`hsl(${H.bg})`)),_){let S=null;if(N&&k.checkoutBooking&&k.checkinBooking)S=`${k.checkoutBooking.label||""} / ${k.checkinBooking.label||""}`;else if(y==="booked"){const K=f.find(oe=>oe.start<=v&&oe.end>v);K&&(S=K.label)}else y==="checkout-only"&&k.checkoutBooking?S=k.checkoutBooking.label:y==="checkin-only"&&k.checkinBooking&&(S=k.checkinBooking.label);S&&c.setAttribute("data-booking-label",S)}if(Re&&r&&!o&&l){const S=r<l?r:l,K=r<l?l:r;v>=S&&v<=K&&c.classList.add("cal-day--invalid-range")}}if(M?r&&o&&(E(v,r)||E(v,o))?(c.classList.add("cal-day--selected"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"):n.some(x=>E(x,v))?(c.classList.add("cal-day--selected"),c.setAttribute("aria-selected","true")):c.setAttribute("aria-selected","false"),(g==="range"||M)&&r&&W){const y=E(v,r),x=E(v,W),N=ue(v,r,W);y&&c.classList.add("cal-day--range-start"),x&&c.classList.add("cal-day--range-end"),N&&!y&&!x&&c.classList.add("cal-day--in-range")}const re=_e(v,i,h,d)||R;if(re&&(c.classList.add("cal-day--disabled"),c.disabled=!0,c.setAttribute("aria-disabled","true")),u&&E(v,u)?c.setAttribute("tabindex","0"):c.setAttribute("tabindex","-1"),M&&k&&k.label!=null){c.classList.add("cal-day--with-label");const y=document.createElement("span");y.classList.add("cal-day__number"),y.textContent=w.day,c.appendChild(y);const x=document.createElement("span");x.classList.add("cal-day__label"),x.textContent=k.label,c.appendChild(x)}else c.textContent=w.day;re?M&&c.addEventListener("mouseenter",()=>b==null?void 0:b(v)):(c.addEventListener("click",()=>p==null?void 0:p(v)),c.addEventListener("mouseenter",()=>b==null?void 0:b(v))),O.appendChild(c)}),Y.addEventListener("mouseleave",()=>b==null?void 0:b(null)),Y}function _e(s,e,a,t){return!!(t.includes(s)||e&&s<e||a&&s>a)}const we=`
|
|
275
275
|
.cal-grid {
|
|
276
276
|
display: flex;
|
|
277
277
|
flex-direction: column;
|
|
@@ -529,7 +529,7 @@
|
|
|
529
529
|
pointer-events: none;
|
|
530
530
|
z-index: 10;
|
|
531
531
|
}
|
|
532
|
-
`,
|
|
532
|
+
`,V='<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>',ee='<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 te({year:s,month:e,onPrev:a,onNext:t,onTitleClick:n,locale:r}){const o=document.createElement("div");o.classList.add("cal-nav");const l=document.createElement("button");l.classList.add("cal-nav__btn","cal-nav__btn--prev"),l.innerHTML=V,l.setAttribute("aria-label","Previous month"),l.addEventListener("click",a);const i=ce(r),h=n?"button":"div",d=document.createElement(h);d.classList.add("cal-nav__title"),n&&(d.classList.add("cal-nav__title--interactive"),d.setAttribute("aria-label",`Select month and year, currently ${i[e]} ${s}`),d.addEventListener("click",n)),d.setAttribute("aria-live","polite"),d.textContent=`${i[e]} ${s}`;const g=document.createElement("button");return g.classList.add("cal-nav__btn","cal-nav__btn--next"),g.innerHTML=ee,g.setAttribute("aria-label","Next month"),g.addEventListener("click",t),o.appendChild(l),o.appendChild(d),o.appendChild(g),o}const xe=`
|
|
533
533
|
.cal-nav {
|
|
534
534
|
display: flex;
|
|
535
535
|
align-items: center;
|
|
@@ -570,7 +570,7 @@
|
|
|
570
570
|
.cal-nav__title--interactive:hover {
|
|
571
571
|
background: hsl(var(--cal-hover));
|
|
572
572
|
}
|
|
573
|
-
|
|
573
|
+
`;function De({pickerYear:s,viewMonth:e,viewYear:a,onMonthSelect:t,onYearPrev:n,onYearNext:r,onClose:o,locale:l}){const i=document.createElement("div");i.classList.add("cal-myp","cal-animate-fade");const h=document.createElement("div");h.classList.add("cal-myp__year-nav");const d=document.createElement("button");d.classList.add("cal-nav__btn"),d.innerHTML=V,d.setAttribute("aria-label","Previous year"),d.addEventListener("click",n);const g=document.createElement("div");g.classList.add("cal-myp__year-label"),g.textContent=s;const u=document.createElement("button");u.classList.add("cal-nav__btn"),u.innerHTML=ee,u.setAttribute("aria-label","Next year"),u.addEventListener("click",r),h.appendChild(d),h.appendChild(g),h.appendChild(u),i.appendChild(h);const p=document.createElement("div");p.classList.add("cal-myp__grid");const b=q(l),f=new Date,G=f.getMonth(),U=f.getFullYear();for(let _=0;_<12;_++){const L=document.createElement("button");L.classList.add("cal-myp__cell"),L.textContent=b[_],_===e&&s===a&&L.classList.add("cal-myp__cell--active"),_===G&&s===U&&L.classList.add("cal-myp__cell--today"),L.addEventListener("click",()=>t(_,s)),p.appendChild(L)}return i.appendChild(p),i.addEventListener("keydown",_=>{_.key==="Escape"&&(_.stopPropagation(),o())}),i}const Le=`
|
|
574
574
|
.cal-myp {
|
|
575
575
|
width: calc(7 * var(--cal-cell-size));
|
|
576
576
|
}
|
|
@@ -628,7 +628,7 @@
|
|
|
628
628
|
border: 1px solid hsl(var(--cal-border));
|
|
629
629
|
font-weight: 600;
|
|
630
630
|
}
|
|
631
|
-
|
|
631
|
+
`,ae={today:"Today","this-week":"This Week","next-7":"Next 7 Days","next-30":"Next 30 Days"};function $(s,e){if(!e)return ae[s]||s;try{if(s==="today"){const n=new Intl.RelativeTimeFormat(e,{numeric:"auto"}).formatToParts(0,"day").map(r=>r.value).join("");return n.charAt(0).toUpperCase()+n.slice(1)}}catch{}return ae[s]||s}function Se(s){return[{key:"today",label:$("today",s),resolve(){const e=J();return{start:e,end:e}}},{key:"this-week",label:$("this-week",s),resolve(){const e=new Date,a=e.getDay(),t=new Date(e);t.setDate(e.getDate()-a);const n=new Date(t);return n.setDate(t.getDate()+6),{start:m(t),end:m(n)}}},{key:"next-7",label:$("next-7",s),resolve(){const e=new Date,a=new Date;return a.setDate(e.getDate()+6),{start:m(e),end:m(a)}}},{key:"next-30",label:$("next-30",s),resolve(){const e=new Date,a=new Date;return a.setDate(e.getDate()+29),{start:m(e),end:m(a)}}}]}function Ee({presetKeys:s,onSelect:e,locale:a}){const t=document.createElement("div");t.classList.add("cal-presets");const n=Se(a),r=s.map(o=>n.find(l=>l.key===o)).filter(Boolean);for(const o of r){const l=document.createElement("button");l.classList.add("cal-preset"),l.textContent=o.label,l.addEventListener("click",()=>{e==null||e(o.resolve())}),t.appendChild(l)}return t}const Me=`
|
|
632
632
|
.cal-presets {
|
|
633
633
|
display: flex;
|
|
634
634
|
flex-wrap: wrap;
|
|
@@ -654,7 +654,7 @@
|
|
|
654
654
|
.cal-preset:hover {
|
|
655
655
|
background: hsl(var(--cal-hover));
|
|
656
656
|
}
|
|
657
|
-
`;function
|
|
657
|
+
`;function Ce({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 g=s.getBoundingClientRect(),u=t.offsetHeight,p=window.innerHeight-g.bottom,b=g.top;p<u+8&&b>p?(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 o(){n||(n=!0,t.style.display="",t.classList.add("cal-animate-slide-up"),requestAnimationFrame(()=>r()),document.addEventListener("click",i,!0),document.addEventListener("keydown",h,!0))}function l(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up"),document.removeEventListener("click",i,!0),document.removeEventListener("keydown",h,!0),a==null||a())}function i(g){var p;const u=(p=s.getRootNode())==null?void 0:p.host;u&&!u.contains(g.target)&&g.target!==u&&l()}function h(g){g.key==="Escape"&&(g.stopPropagation(),l())}function d(){n&&(n=!1,t.style.display="none",t.classList.remove("cal-animate-slide-up")),document.removeEventListener("click",i,!0),document.removeEventListener("keydown",h,!0)}return{panel:t,open:o,close:l,destroy:d,get isOpen(){return n}}}const Ae=`
|
|
658
658
|
.cal-popover-wrapper {
|
|
659
659
|
position: relative;
|
|
660
660
|
display: inline-block;
|
|
@@ -699,7 +699,7 @@
|
|
|
699
699
|
display: flex;
|
|
700
700
|
color: hsl(var(--cal-fg-muted));
|
|
701
701
|
}
|
|
702
|
-
`;function
|
|
702
|
+
`;function Te({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 Ye=`
|
|
703
703
|
.cal-skeleton-time-grid {
|
|
704
704
|
display: grid;
|
|
705
705
|
grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
|
|
@@ -732,7 +732,7 @@
|
|
|
732
732
|
aspect-ratio: 1;
|
|
733
733
|
border-radius: var(--cal-radius-sm) !important;
|
|
734
734
|
}
|
|
735
|
-
`,
|
|
735
|
+
`,ne={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 Be({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=ne[s]||ne.info,n.appendChild(r);const o=document.createElement("span");if(o.classList.add("cal-status__text"),o.textContent=e,n.appendChild(o),a){const l=document.createElement("button");l.classList.add("cal-status__close"),l.setAttribute("aria-label","Dismiss"),l.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>',l.addEventListener("click",()=>t==null?void 0:t()),n.appendChild(l)}return n}const ze=`
|
|
736
736
|
.cal-status {
|
|
737
737
|
display: flex;
|
|
738
738
|
align-items: center;
|
|
@@ -794,7 +794,7 @@
|
|
|
794
794
|
color: hsl(var(--cal-status-success-fg));
|
|
795
795
|
border: 1px solid hsl(var(--cal-status-success-border));
|
|
796
796
|
}
|
|
797
|
-
`,
|
|
797
|
+
`,Pe='<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>',Oe=`
|
|
798
798
|
.cal-picker {
|
|
799
799
|
background: hsl(var(--cal-bg));
|
|
800
800
|
border-radius: var(--cal-radius);
|
|
@@ -814,5 +814,5 @@
|
|
|
814
814
|
.cal-month {
|
|
815
815
|
flex: 0 0 auto;
|
|
816
816
|
}
|
|
817
|
-
`;class V extends B{static get styles(){return[ie,ce,de,fe,ve,ke,we,Le,Ee,Ce,Te]}static get observedAttributes(){return["mode","display","theme","value","min-date","max-date","disabled-dates","first-day","locale","presets","placeholder","loading"]}constructor(){super();const e=new Date;this._store=ae({viewYear:e.getFullYear(),viewMonth:e.getMonth(),selectedDates:[],rangeStart:null,rangeEnd:null,hoverDate:null,isOpen:!1,focusedDate:G(),navDirection:null,pickingMonth:!1,pickerYear:e.getFullYear(),statusType:null,statusMessage:null,statusDismissible:!0}),this._popover=null,this._unsubscribe=null,this._rendering=!1}get mode(){return this.getAttribute("mode")||"single"}get display(){return this.getAttribute("display")||"inline"}get placeholder(){return this.getAttribute("placeholder")||"Select date"}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 loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get disabledDates(){const e=this.getAttribute("disabled-dates");return e?e.split(",").map(a=>a.trim()):[]}get presetKeys(){const e=this.getAttribute("presets");return e?e.split(",").map(a=>a.trim()):[]}get value(){const e=this._store.getState();return this.mode==="range"?e.rangeStart&&e.rangeEnd?{start:e.rangeStart,end:e.rangeEnd}:null:this.mode==="multi"?[...e.selectedDates]:e.selectedDates[0]||null}set value(e){if(this.mode==="range"&&e&&typeof e=="object"){const a=typeof e.start=="string"?e.start:y(e.start),t=typeof e.end=="string"?e.end:y(e.end);this._store.set({rangeStart:a,rangeEnd:t,selectedDates:[a,t]}),this._navigateToDate(a)}else this.mode==="multi"&&Array.isArray(e)?(this._store.set({selectedDates:e}),e.length&&this._navigateToDate(e[0])):typeof e=="string"?(this._store.set({selectedDates:[e],rangeStart:null,rangeEnd:null}),this._navigateToDate(e)):this._store.set({selectedDates:[],rangeStart:null,rangeEnd:null})}_navigateToDate(e){const a=w(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.selectedDates===t.selectedDates&&a.rangeStart===t.rangeStart&&a.rangeEnd===t.rangeEnd&&a.isOpen===t.isOpen&&a.navDirection===t.navDirection&&a.pickingMonth===t.pickingMonth&&a.pickerYear===t.pickerYear?this._updateGridHighlight(a):this.render()});const e=this.getAttribute("value");if(e)if(this.mode==="range"&&e.includes("/")){const[a,t]=e.split("/");this.value={start:a,end:t}}else this.mode==="multi"&&e.includes(",")?this.value=e.split(",").map(a=>a.trim()):this.value=e}disconnectedCallback(){var e,a;(e=this._unsubscribe)==null||e.call(this),(a=this._popover)==null||a.destroy(),clearTimeout(this._statusTimer)}attributeChangedCallback(e,a,t){if(a!==t){if(e==="value"&&this._initialized)if(this.mode==="range"&&t&&t.includes("/")){const[n,r]=t.split("/");this.value={start:n,end:r}}else this.mode==="multi"&&t&&t.includes(",")?this.value=t.split(",").map(n=>n.trim()):this.value=t;this._initialized&&this.render()}}_handleSelect(e){const a=this._store.getState();if(this.mode==="single")this._store.set({selectedDates:[e],focusedDate:e}),this.emit("cal:change",{value:e}),this.display==="popover"&&this.close();else if(this.mode==="range")if(!a.rangeStart||a.rangeEnd)this._store.set({rangeStart:e,rangeEnd:null,selectedDates:[e],focusedDate:e});else{let t=a.rangeStart,n=e;t>n&&([t,n]=[n,t]),this._store.set({rangeStart:t,rangeEnd:n,selectedDates:[t,n],hoverDate:null,focusedDate:n}),this.emit("cal:change",{value:{start:t,end:n}}),this.display==="popover"&&this.close()}else if(this.mode==="multi"){const t=[...a.selectedDates],n=t.findIndex(r=>S(r,e));n>=0?t.splice(n,1):t.push(e),t.sort(),this._store.set({selectedDates:t,focusedDate:e}),this.emit("cal:change",{value:t})}}_handleHover(e){this.mode==="range"&&this._store.set({hoverDate:e})}_handlePresetSelect({start:e,end:a}){this._store.set({rangeStart:e,rangeEnd:a,selectedDates:[e,a],hoverDate:null}),this._navigateToDate(e),this.emit("cal:change",{value:{start:e,end:a}}),this.display==="popover"&&this.close()}_prevMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=z(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}=z(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=w(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=y(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 o=this.$(`[data-date="${r}"]`);o==null||o.focus()})}}_updateGridHighlight(e){const a=this.$$(".cal-day"),{rangeStart:t,hoverDate:n}=e,r=t&&!e.rangeEnd&&n?n:e.rangeEnd;for(const o of a){const l=o.dataset.date;if(!l||o.classList.contains("cal-day--disabled"))continue;const i=l===t,g=l===r;let h=!1;if(t&&r){const u=t<r?t:r,d=t<r?r:t;h=l>=u&&l<=d&&!i&&!g}o.classList.toggle("cal-day--range-start",i&&!!r),o.classList.toggle("cal-day--range-end",g&&!!r),o.classList.toggle("cal-day--in-range",h)}}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})}_renderCalendarContent(){const e=this._store.getState(),a=document.createElement("div");if(a.classList.add("cal-picker"),e.statusType&&e.statusMessage&&a.appendChild(Me({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 l=document.createElement("div");return l.classList.add("cal-month"),l.appendChild(Se()),o.appendChild(l),a.appendChild(o),a.addEventListener("keydown",i=>this._handleKeydown(i)),a}const t=document.createElement("div");t.classList.add("cal-months");const n=this.mode==="range"&&this.hasAttribute("dual"),r=n?2:1;for(let o=0;o<r;o++){const{year:l,month:i}=o===0?{year:e.viewYear,month:e.viewMonth}:z(e.viewYear,e.viewMonth,1),g=document.createElement("div");if(g.classList.add("cal-month"),o===0&&g.appendChild(Q({year:l,month:i,onPrev:e.pickingMonth?()=>{}:()=>this._prevMonth(),onNext:e.pickingMonth?()=>{}:()=>{n||this._nextMonth()},onTitleClick:()=>this._toggleMonthPicker()})),o===1&&g.appendChild(Q({year:l,month:i,onPrev:()=>{},onNext:()=>this._nextMonth()})),e.pickingMonth&&o===0){const h=me({pickerYear:e.pickerYear,viewMonth:e.viewMonth,viewYear:e.viewYear,onMonthSelect:(u,d)=>this._selectMonthFromPicker(u,d),onYearPrev:()=>this._store.set({pickerYear:e.pickerYear-1}),onYearNext:()=>this._store.set({pickerYear:e.pickerYear+1}),onClose:()=>this._store.set({pickingMonth:!1})});g.appendChild(h)}else{const h=e.navDirection==="next"?"cal-animate-slide-left":e.navDirection==="prev"?"cal-animate-slide-right":"",u=pe({year:l,month:i,firstDay:this.firstDay,selectedDates:e.selectedDates,rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,hoverDate:e.hoverDate,minDate:this.minDate,maxDate:this.maxDate,disabledDates:this.disabledDates,mode:this.mode,focusedDate:e.focusedDate,onSelect:d=>this._handleSelect(d),onHover:d=>this._handleHover(d)});h&&u.classList.add(h),g.appendChild(u)}t.appendChild(g)}return a.appendChild(t),this.mode==="range"&&this.presetKeys.length&&a.appendChild(xe({presetKeys:this.presetKeys,onSelect:o=>this._handlePresetSelect(o)})),a.addEventListener("keydown",o=>this._handleKeydown(o)),a}_formatTriggerText(){const e=this._store.getState();return this.mode==="range"&&e.rangeStart&&e.rangeEnd?`${this._formatShortDate(e.rangeStart)} – ${this._formatShortDate(e.rangeEnd)}`:e.selectedDates.length?this.mode==="multi"?`${e.selectedDates.length} dates selected`:this._formatShortDate(e.selectedDates[0]):null}_formatShortDate(e){const a=w(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 r=document.createElement("button");r.classList.add("cal-trigger");const o=document.createElement("span");o.classList.add("cal-trigger__icon"),o.innerHTML=Ae,r.appendChild(o);const l=this._formatTriggerText(),i=document.createElement("span");l?i.textContent=l:(i.textContent=this.placeholder,i.classList.add("cal-trigger--placeholder")),r.appendChild(i),n.appendChild(r);const g=this._renderCalendarContent(),h=De({trigger:r,content:g,onClose:()=>{this._store.set({isOpen:!1}),this.emit("cal:close")}});n.appendChild(h.panel),e.appendChild(n),r.addEventListener("click",u=>{u.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-datepicker")||customElements.define("cal-datepicker",V),C.CalDatepicker=V,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
817
|
+
`;class se extends B{static get styles(){return[pe,be,fe,we,xe,Le,Me,Ae,Ye,ze,Oe]}static get observedAttributes(){return["mode","display","theme","value","min-date","max-date","disabled-dates","first-day","locale","presets","placeholder","loading"]}constructor(){super();const e=new Date;this._store=le({viewYear:e.getFullYear(),viewMonth:e.getMonth(),selectedDates:[],rangeStart:null,rangeEnd:null,hoverDate:null,isOpen:!1,focusedDate:J(),navDirection:null,pickingMonth:!1,pickerYear:e.getFullYear(),statusType:null,statusMessage:null,statusDismissible:!0}),this._popover=null,this._unsubscribe=null,this._rendering=!1}get mode(){return this.getAttribute("mode")||"single"}get display(){return this.getAttribute("display")||"inline"}get placeholder(){return this.getAttribute("placeholder")||"Select date"}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 loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get disabledDates(){const e=this.getAttribute("disabled-dates");return e?e.split(",").map(a=>a.trim()):[]}get presetKeys(){const e=this.getAttribute("presets");return e?e.split(",").map(a=>a.trim()):[]}get value(){const e=this._store.getState();return this.mode==="range"?e.rangeStart&&e.rangeEnd?{start:e.rangeStart,end:e.rangeEnd}:null:this.mode==="multi"?[...e.selectedDates]:e.selectedDates[0]||null}set value(e){if(this.mode==="range"&&e&&typeof e=="object"){const a=typeof e.start=="string"?e.start:m(e.start),t=typeof e.end=="string"?e.end:m(e.end);this._store.set({rangeStart:a,rangeEnd:t,selectedDates:[a,t]}),this._navigateToDate(a)}else this.mode==="multi"&&Array.isArray(e)?(this._store.set({selectedDates:e}),e.length&&this._navigateToDate(e[0])):typeof e=="string"?(this._store.set({selectedDates:[e],rangeStart:null,rangeEnd:null}),this._navigateToDate(e)):this._store.set({selectedDates:[],rangeStart:null,rangeEnd:null})}_navigateToDate(e){const a=D(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.selectedDates===t.selectedDates&&a.rangeStart===t.rangeStart&&a.rangeEnd===t.rangeEnd&&a.isOpen===t.isOpen&&a.navDirection===t.navDirection&&a.pickingMonth===t.pickingMonth&&a.pickerYear===t.pickerYear?this._updateGridHighlight(a):this.render()});const e=this.getAttribute("value");if(e)if(this.mode==="range"&&e.includes("/")){const[a,t]=e.split("/");this.value={start:a,end:t}}else this.mode==="multi"&&e.includes(",")?this.value=e.split(",").map(a=>a.trim()):this.value=e}disconnectedCallback(){var e,a;(e=this._unsubscribe)==null||e.call(this),(a=this._popover)==null||a.destroy(),clearTimeout(this._statusTimer)}attributeChangedCallback(e,a,t){if(a!==t){if(e==="value"&&this._initialized)if(this.mode==="range"&&t&&t.includes("/")){const[n,r]=t.split("/");this.value={start:n,end:r}}else this.mode==="multi"&&t&&t.includes(",")?this.value=t.split(",").map(n=>n.trim()):this.value=t;this._initialized&&this.render()}}_handleSelect(e){const a=this._store.getState();if(this.mode==="single")this._store.set({selectedDates:[e],focusedDate:e}),this.emit("cal:change",{value:e}),this.display==="popover"&&this.close();else if(this.mode==="range")if(!a.rangeStart||a.rangeEnd)this._store.set({rangeStart:e,rangeEnd:null,selectedDates:[e],focusedDate:e});else{let t=a.rangeStart,n=e;t>n&&([t,n]=[n,t]),this._store.set({rangeStart:t,rangeEnd:n,selectedDates:[t,n],hoverDate:null,focusedDate:n}),this.emit("cal:change",{value:{start:t,end:n}}),this.display==="popover"&&this.close()}else if(this.mode==="multi"){const t=[...a.selectedDates],n=t.findIndex(r=>E(r,e));n>=0?t.splice(n,1):t.push(e),t.sort(),this._store.set({selectedDates:t,focusedDate:e}),this.emit("cal:change",{value:t})}}_handleHover(e){this.mode==="range"&&this._store.set({hoverDate:e})}_handlePresetSelect({start:e,end:a}){this._store.set({rangeStart:e,rangeEnd:a,selectedDates:[e,a],hoverDate:null}),this._navigateToDate(e),this.emit("cal:change",{value:{start:e,end:a}}),this.display==="popover"&&this.close()}_prevMonth(){const{viewYear:e,viewMonth:a}=this._store.getState(),{year:t,month:n}=z(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}=z(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=D(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=m(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 o=this.$(`[data-date="${r}"]`);o==null||o.focus()})}}_updateGridHighlight(e){const a=this.$$(".cal-day"),{rangeStart:t,hoverDate:n}=e,r=t&&!e.rangeEnd&&n?n:e.rangeEnd;for(const o of a){const l=o.dataset.date;if(!l||o.classList.contains("cal-day--disabled"))continue;const i=l===t,h=l===r;let d=!1;if(t&&r){const g=t<r?t:r,u=t<r?r:t;d=l>=g&&l<=u&&!i&&!h}o.classList.toggle("cal-day--range-start",i&&!!r),o.classList.toggle("cal-day--range-end",h&&!!r),o.classList.toggle("cal-day--in-range",d)}}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({selectedDates:[],rangeStart:null,rangeEnd:null,hoverDate:null}),this.emit("cal:change",{value:null})}_renderCalendarContent(){const e=this._store.getState(),a=document.createElement("div");if(a.classList.add("cal-picker"),e.statusType&&e.statusMessage&&a.appendChild(Be({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 l=document.createElement("div");return l.classList.add("cal-month"),l.appendChild(Te()),o.appendChild(l),a.appendChild(o),a.addEventListener("keydown",i=>this._handleKeydown(i)),a}const t=document.createElement("div");t.classList.add("cal-months");const n=this.mode==="range"&&this.hasAttribute("dual"),r=n?2:1;for(let o=0;o<r;o++){const{year:l,month:i}=o===0?{year:e.viewYear,month:e.viewMonth}:z(e.viewYear,e.viewMonth,1),h=document.createElement("div");if(h.classList.add("cal-month"),o===0&&h.appendChild(te({year:l,month:i,onPrev:e.pickingMonth?()=>{}:()=>this._prevMonth(),onNext:e.pickingMonth?()=>{}:()=>{n||this._nextMonth()},onTitleClick:()=>this._toggleMonthPicker(),locale:this.locale})),o===1&&h.appendChild(te({year:l,month:i,onPrev:()=>{},onNext:()=>this._nextMonth(),locale:this.locale})),e.pickingMonth&&o===0){const d=De({pickerYear:e.pickerYear,viewMonth:e.viewMonth,viewYear:e.viewYear,onMonthSelect:(g,u)=>this._selectMonthFromPicker(g,u),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});h.appendChild(d)}else{const d=e.navDirection==="next"?"cal-animate-slide-left":e.navDirection==="prev"?"cal-animate-slide-right":"",g=ke({year:l,month:i,firstDay:this.firstDay,selectedDates:e.selectedDates,rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,hoverDate:e.hoverDate,minDate:this.minDate,maxDate:this.maxDate,disabledDates:this.disabledDates,mode:this.mode,focusedDate:e.focusedDate,onSelect:u=>this._handleSelect(u),onHover:u=>this._handleHover(u),locale:this.locale});d&&g.classList.add(d),h.appendChild(g)}t.appendChild(h)}return a.appendChild(t),this.mode==="range"&&this.presetKeys.length&&a.appendChild(Ee({presetKeys:this.presetKeys,onSelect:o=>this._handlePresetSelect(o),locale:this.locale})),a.addEventListener("keydown",o=>this._handleKeydown(o)),a}_formatTriggerText(){const e=this._store.getState();return this.mode==="range"&&e.rangeStart&&e.rangeEnd?`${this._formatShortDate(e.rangeStart)} – ${this._formatShortDate(e.rangeEnd)}`:e.selectedDates.length?this.mode==="multi"?`${e.selectedDates.length} dates selected`:this._formatShortDate(e.selectedDates[0]):null}_formatShortDate(e){const a=D(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`${q(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 o=document.createElement("span");o.classList.add("cal-trigger__icon"),o.innerHTML=Pe,r.appendChild(o);const l=this._formatTriggerText(),i=document.createElement("span");l?i.textContent=l:(i.textContent=this.placeholder,i.classList.add("cal-trigger--placeholder")),r.appendChild(i),n.appendChild(r);const h=this._renderCalendarContent(),d=Ce({trigger:r,content:h,onClose:()=>{this._store.set({isOpen:!1}),this.emit("cal:close")}});n.appendChild(d.panel),e.appendChild(n),r.addEventListener("click",g=>{g.stopPropagation(),d.isOpen?this.close():this.open()}),this._popover=d,this._store.get("isOpen")&&d.open()}else e.appendChild(this._renderCalendarContent());this._store.set({navDirection:null}),this._rendering=!1}}customElements.get("cal-datepicker")||customElements.define("cal-datepicker",se),A.CalDatepicker=se,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})}));
|
|
818
818
|
//# sourceMappingURL=datepicker.umd.js.map
|