@lekoala/date-picker 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,16 @@
1
- /*** @lekoala/date-picker v0.5.2 - https://github.com/lekoala/date-picker ***/
2
- (()=>{var{defineProperty:wt,getOwnPropertyNames:ge,getOwnPropertyDescriptor:ye}=Object,ve=Object.prototype.hasOwnProperty;function be(t){return this[t]}var De=(t)=>{var e=(Pt??=new WeakMap).get(t),s;if(e)return e;if(e=wt({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function"){for(var i of ge(t))if(!ve.call(e,i))wt(e,i,{get:be.bind(t,i),enumerable:!(s=ye(t,i))||s.enumerable})}return Pt.set(t,e),e},Pt;var we=(t)=>t;function Ee(t,e){this[t]=we.bind(null,e)}var xe=(t,e)=>{for(var s in e)wt(t,s,{get:e[s],enumerable:!0,configurable:!0,set:Ee.bind(e,s)})};var as={};xe(as,{defineDatePicker:()=>ue});var tt=new WeakMap;var Ce=/^(\d{4})-(\d{2})-(\d{2})$/,Ae=/^(\d{4})-(\d{2})$/;function ke(t){return t%4===0&&(t%100!==0||t%400===0)}function st(t,e){if(e===2)return ke(t)?29:28;return[4,6,9,11].includes(e)?30:31}function L(t){let e=Ce.exec(String(t||""));if(!e)return null;let s=Number(e[1]),i=Number(e[2]),n=Number(e[3]);if(s<1||s>9999||i<1||i>12)return null;if(n<1||n>st(s,i))return null;return{year:s,month:i,day:n}}function c(t){return L(t)!==null}function f(t){let e=String(t||""),s=Ae.exec(e);if(s){let n=Number(s[2]);if(n>=1&&n<=12)return`${s[1]}-${String(n).padStart(2,"0")}`}let i=L(e);if(!i)throw TypeError(`Invalid civil date/month: ${t}`);return`${String(i.year).padStart(4,"0")}-${String(i.month).padStart(2,"0")}`}function G(t,e,s){let i=`${String(t).padStart(4,"0")}-${String(e).padStart(2,"0")}-${String(s).padStart(2,"0")}`;if(!c(i))throw TypeError(`Invalid civil date: ${i}`);return i}function B(t){let e=new Date(0);return e.setUTCHours(12,0,0,0),e.setUTCFullYear(t.year,t.month-1,t.day),e}function Se(t){return G(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate())}function N(t){let e=L(t);if(!e)throw TypeError(`Invalid civil date: ${t}`);return B(e)}function _(t,e){if(!c(t)||!c(e))throw TypeError("compareDates() expects YYYY-MM-DD values");return t===e?0:t<e?-1:1}function F(t,e){let s=L(t);if(!s||!Number.isInteger(e))throw TypeError("addDays() expects a date and integer amount");let i=B(s);return i.setUTCDate(i.getUTCDate()+e),Se(i)}function ht(t,e){let s=L(t);if(!s||!Number.isInteger(e))throw TypeError("addMonths() expects a date and integer amount");let i=s.year*12+(s.month-1)+e,n=Math.floor(i/12),a=(i%12+12)%12+1,o=Math.min(s.day,st(n,a));return G(n,a,o)}function Vt(t,e){let s=L(t);if(!s||!Number.isInteger(e))throw TypeError("addYears() expects a date and integer amount");let i=s.year+e,n=Math.min(s.day,st(i,s.month));return G(i,s.month,n)}function et(t,e){let s=`${f(t)}-01`;return f(ht(s,e))}function Te(t){return`${f(t)}-01`}function Et(t){let e=L(`${f(t)}-01`);if(!e)throw TypeError(`Invalid month: ${t}`);return G(e.year,e.month,st(e.year,e.month))}function Me(t){let e=L(t);if(!e)throw TypeError(`Invalid civil date: ${t}`);return B(e).getUTCDay()}function W(t){if(t===7)return 0;if(!Number.isInteger(t)||t<0||t>6)throw RangeError("firstDay must be 0..6 (Sunday=0, 7 accepted as Sunday alias)");return t}function ft(t,e=1){let s=(Me(t)-W(e)+7)%7;return F(t,-s)}function xt(t,e=1){return F(ft(t,e),6)}function Bt(t,e={}){let s=e.firstDay??1,i=ft(Te(t),s),n=xt(Et(t),s),r=[],a=i;for(;;){let o=[];for(let l=0;l<7;l++)o.push(F(a,l));if(r.push(o),_(o[6],n)>=0){if(!e.fixedWeeks||r.length>=6||_(o[6],F("9999-12-31",-7))>0)break}a=F(a,7)}return r}function Ht(t,e,s){let i=B({year:1,month:1,day:1});return Math.round((B({year:t,month:e,day:s}).getTime()-i.getTime())/86400000)}function it(t,e=1){let s=W(e),i=Ht(9999,12,31),n=f(t);for(;;){let r=L(`${n}-01`);if(!r)throw TypeError(`Invalid civil date/month: ${t}`);let a=Ht(r.year,r.month,1),o=(B(r).getUTCDay()-s+7)%7;if(a-o<0){n=et(n,1);continue}let l=st(r.year,r.month),d={year:r.year,month:r.month,day:l},u=a+l-1,v=(B(d).getUTCDay()-s+7)%7;if(u-v+6>i){n=et(n,-1);continue}return n}}function Nt(t,e="",s=""){if(!c(t))throw TypeError(`Invalid civil date: ${t}`);if(e&&_(t,e)<0)return e;if(s&&_(t,s)>0)return s;return t}function O(){let t=new Date;return G(t.getFullYear(),t.getMonth()+1,t.getDate())}function Ut(t){let e=L(t);if(!e)throw TypeError(`Invalid civil date: ${t}`);let s=B(e),i=s.getUTCDay()||7;s.setUTCDate(s.getUTCDate()+4-i);let n=new Date(0);return n.setUTCHours(12,0,0,0),n.setUTCFullYear(s.getUTCFullYear(),0,1),Math.ceil(((s.getTime()-n.getTime())/86400000+1)/7)}class Ct{constructor(t={}){let e=O();this.firstDay=W(t.firstDay??1),this.value=t.value&&c(t.value)?t.value:"",this.focused=t.focused&&c(t.focused)?t.focused:this.value||e,this.display=t.display?f(t.display):f(this.focused)}setValue(t){if(t&&!c(t))throw TypeError(`Invalid value: ${t}`);return this.value=t||"",this.value}setDisplay(t){let e=f(t),s=Number(this.focused.slice(8,10))||1,i=ht(`${e}-01`,0),n=F(i,Math.max(0,s-1));return this.focused=f(n)===e?n:F(`${et(e,1)}-01`,-1),this.display=e,this.display}setFocused(t,e={}){if(!c(t))throw TypeError(`Invalid focused date: ${t}`);if(this.focused=t,e.follow!==!1)this.display=f(t);return this.focused}moveFocusDays(t){return this.setFocused(F(this.focused,t))}moveFocusMonths(t){return this.setFocused(ht(this.focused,t))}moveFocusYears(t){return this.setFocused(Vt(this.focused,t))}focusWeekStart(){return this.setFocused(ft(this.focused,this.firstDay))}focusWeekEnd(){return this.setFocused(xt(this.focused,this.firstDay))}navigateMonth(t){let e=et(this.display,t);return this.setDisplay(e),this.display}}function $e(t){if(typeof t!=="string")return"";return[...new Set(t.split(/\s+/).filter((e)=>e&&!e.startsWith("dp-")&&![...e].some((s)=>s.charCodeAt(0)<32||s.charCodeAt(0)===127)))].join(" ")}function St(t,e){return t.month===e.month&&t.year===e.year&&t.nav===e.nav}var At={month:"",year:"",nav:""};function nt(){return{...At}}function rt(t){if(t==null)return null;let e={};for(let s of["month","year","nav"])if(Object.hasOwn(t,s))e[s]=$e(t[s]);return e}function Gt(t){return t==null||["month","year","nav"].some((e)=>!Object.hasOwn(t,e))}function at(t){return{...nt(),...rt(t)}}function pt(t){let e=at(t);if(St(At,e))return;At=e;for(let s of kt)s()}var kt=new Set;function Yt(t){return kt.add(t),()=>{kt.delete(t)}}function mt(t){if(t==null)return{start:"",end:""};if(typeof t!=="object")throw TypeError("highlightedRange expects { start, end }");let{start:e="",end:s=""}=t;if(e&&!c(e))throw TypeError(`Invalid range start: ${e}`);if(s&&!c(s))throw TypeError(`Invalid range end: ${s}`);if(!e&&s)throw TypeError("highlightedRange cannot define an end without a start");if(e&&s&&_(s,e)<0)throw TypeError("highlightedRange must be ordered; start must be on or before end");return{start:e,end:s}}function _t(t,e){if(!e||!c(t))return"";let{start:s,end:i}=e;if(!s||!c(s))return"";if(s===t)return i?i===t?"single":"start":"start";if(i&&i===t)return"end";if(i&&_(t,s)>=0&&_(t,i)<=0)return"in";return""}class Tt{constructor(){this.activeEndpoint="",this.start="",this.end=""}get range(){return{start:this.start,end:this.end}}get complete(){return Boolean(this.start&&this.end&&_(this.end,this.start)>=0)}focus(t){this.activeEndpoint=t}_refuse(t){return{status:"refused",endpoint:t,changedEndpoints:[],range:this.range,activeEndpoint:this.activeEndpoint}}project(t,e=()=>!0){if(!c(t))throw TypeError(`Invalid range activation: ${t}`);let{start:s,end:i}=this;if(this.complete&&(_(t,s)<0||_(t,i)>0)){let r=_(t,s)<0?"start":"end";if(!e(r))return this._refuse(r);return{status:"complete",endpoint:r,changedEndpoints:[r],range:r==="start"?{start:t,end:i}:{start:s,end:t},activeEndpoint:r}}if(this.activeEndpoint==="end"){if(s&&!i&&_(t,s)<0){if(!e("start"))return this._refuse("start");if(!e("end"))return this._refuse("end");return{status:"complete",endpoint:"end",changedEndpoints:["start","end"],range:{start:t,end:s},activeEndpoint:"end"}}if(s&&_(t,s)<0)return this._refuse("end");if(!e("end"))return this._refuse("end");return{status:s?"complete":"pending",endpoint:"end",changedEndpoints:["end"],range:{start:s,end:t},activeEndpoint:"end"}}if(i&&!s&&_(t,i)>0){if(!e("start"))return this._refuse("start");if(!e("end"))return this._refuse("end");return{status:"complete",endpoint:"start",changedEndpoints:["start","end"],range:{start:i,end:t},activeEndpoint:"start"}}if(!e("start"))return this._refuse("start");let n=e("end");return{status:"pending",endpoint:"start",changedEndpoints:["start"],range:{start:t,end:i},activeEndpoint:n?"end":this.activeEndpoint,...n?{}:{close:!0}}}projectEndpoint(t,e,s=()=>!0){if(!c(t))throw TypeError(`Invalid range activation: ${t}`);if(!this.complete||!s(e))return this._refuse(e);let{start:i,end:n}=this,r=e==="start"?i:n,a=e==="start"?Le(t,n):Fe(t,i);return{status:"complete",endpoint:e,changedEndpoints:a===r?[]:[e],range:e==="start"?{start:a,end:n}:{start:i,end:a},activeEndpoint:e}}previewRange(t,e="",s=()=>!0){if(!c(t))return null;if(!e&&Boolean(this.start)===Boolean(this.end))return null;let i=e?this.projectEndpoint(t,e,s):this.project(t,s);if(i.status==="refused")return null;let{start:n,end:r}=i.range;if(!n||r&&_(r,n)<0)return null;return{start:n,end:r}}_apply(t){if(t.status==="refused")return t;return this.start=t.range.start,this.end=t.range.end,this.activeEndpoint=t.activeEndpoint,t}activate(t,e=()=>!0){return this._apply(this.project(t,e))}moveEndpoint(t,e,s=()=>!0){return this._apply(this.projectEndpoint(t,e,s))}}function Fe(t,e){if(!t)return e;if(!e)return t;return _(t,e)>=0?t:e}function Le(t,e){if(!t)return e;if(!e)return t;return _(t,e)<=0?t:e}var Wt=/[\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/g,Ie=new Map,Re=new Map;function zt(t,e,s){let i=t.get(e);if(i!==void 0)return i;let n=s(),r=t.keys().next().value;if(t.size>=64&&r!==void 0)t.delete(r);return t.set(e,n),n}function z(t,e){let s=JSON.stringify([t,e]);return zt(Ie,s,()=>new Intl.DateTimeFormat(t,e))}function P(t=""){if(t)return t;if(typeof document<"u"&&document.documentElement.lang)return document.documentElement.lang;if(typeof navigator<"u"&&navigator.language)return navigator.language;return"en-US"}function Oe(t){return zt(Re,t,()=>{let e=new Intl.NumberFormat(t,{useGrouping:!1}),s=new Map;for(let i=0;i<=9;i++)s.set(e.format(i),String(i));return s})}function jt(t,e,s={}){let i=String(t||"").replace(Wt,"");if(s.trim!==!1)i=i.trim();for(let[n,r]of Oe(e))i=i.split(n).join(r);return i}function ot(t,e=""){let s=P(e);return z(s,{calendar:"gregory",weekday:"long",year:"numeric",month:"long",day:"numeric",timeZone:"UTC"}).format(N(t))}function Kt(t,e=""){let s=P(e);return z(s,{calendar:"gregory",year:"numeric",month:"long",timeZone:"UTC"}).format(N(`${t.slice(0,7)}-15`))}function qt(t=""){let e=P(t);try{let s=z(e,{calendar:"gregory",year:"numeric",month:"long",timeZone:"UTC"}).formatToParts(N("2026-09-15")),i=-1,n=-1;if(s.forEach((r,a)=>{let o=r.type;if(o==="month"){if(i<0)i=a}else if(o==="year"||o==="relatedYear"||o==="yearName"){if(n<0)n=a}}),i>=0&&n>=0)return n<i?["year","month"]:["month","year"]}catch{}return["month","year"]}function Xt(t="",e="long"){let s=P(t),i=z(s,{calendar:"gregory",month:e,timeZone:"UTC"});return Array.from({length:12},(n,r)=>i.format(N(`2026-${String(r+1).padStart(2,"0")}-15`)))}function Mt(t="",e=1,s="short"){let i=P(t),n=z(i,{calendar:"gregory",weekday:s,timeZone:"UTC"}),r=W(e),a=N("2026-01-04");return Array.from({length:7},(o,l)=>{let d=new Date(a);return d.setUTCDate(a.getUTCDate()+(r+l)%7),n.format(d)})}function Pe(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function lt(t=""){let e=P(t),s=z(e,{calendar:"gregory",year:"numeric",month:"2-digit",day:"2-digit",timeZone:"UTC"}),i=N("2006-11-22"),n=s.formatToParts(i).filter((d)=>d.type!=="literal"||d.value),r=n.filter((d)=>["day","month","year"].includes(d.type)).map((d)=>d.type),a=n.map((d)=>{if(d.type==="day")return"DD";if(d.type==="month")return"MM";if(d.type==="year")return"YYYY";return d.value.replace(Wt,"")}).join(""),o=n.map((d)=>{if(d.type==="day"||d.type==="month")return"(\\d{1,2})";if(d.type==="year")return"(\\d{4})";let u=jt(d.value,e,{trim:!1});return Pe(u).replace(/\s+/g,"\\s*")}).join(""),l=new RegExp(`^\\s*${o}\\s*$`);return{locale:e,placeholder:a,format(d){if(!c(d))return"";return s.format(N(d))},parse(d){let u=jt(d,e);if(c(u))return u;let v=l.exec(u);if(!v)return"";let w={};if(r.forEach((E,S)=>{w[E]=Number(v[S+1])}),!w.year||!w.month||!w.day)return"";try{return G(w.year,w.month,w.day)}catch{return""}}}}var He={chooseDate:"Choose date",changeDate:"Change date",previousMonth:"Previous month",nextMonth:"Next month",month:"Month",year:"Year",calendar:"Choose a date",unavailable:"Unavailable",invalidDate:"Enter a valid date",unavailableDate:"This date is unavailable",formatHint:"Format",week:"Week",rangeStart:"Range start",rangeInRange:"Inside range",rangeEnd:"Range end",rangeSingle:"Range of one day",rangeOrderStart:"Start must be on or before end",rangeOrderEnd:"End must be on or after start"},$t={...He};function U(){return{...$t}}function gt(t){$t={...$t,...t};for(let e of Ft)e()}var Ft=new Set;function yt(t){return Ft.add(t),()=>{Ft.delete(t)}}function Zt(t){let e=t&&typeof t==="object"&&!Array.isArray(t)&&"dates"in t?t.dates:t,s=new Map;if(Array.isArray(e)){for(let i of e){if(!i||typeof i!=="object"||!("date"in i))continue;let{date:n,...r}=i;s.set(String(n),r)}return s}if(e&&typeof e==="object")for(let[i,n]of Object.entries(e))s.set(i,n&&typeof n==="object"?n:{});return s}function K(t,e){for(let s of e){if(!Object.hasOwn(t,s))continue;let i=Reflect.get(t,s);Reflect.deleteProperty(t,s),Reflect.set(t,s,i)}}var Ve=0;function k(t){return String(t).replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}function Be(t){let e=Number(t);if(e===7)return 0;return Number.isInteger(e)&&e>=0&&e<=6?e:1}function Ne(t){return Number(t.slice(0,4))}function vt(t,e){let[s,i]=t.split("-").map(Number),n=s*12+(i-1)+e,r=Math.floor(n/12),a=(n%12+12)%12+1;if(r<1||r>9999)return null;return`${String(r).padStart(4,"0")}-${String(a).padStart(2,"0")}`}function Jt(t){return{"data-range-start":t==="start"||t==="single","data-range-end":t==="end"||t==="single","data-in-range":t==="in"}}function Ue(t){return Object.entries(Jt(t)).filter(([,e])=>e).map(([e])=>` ${e}="true"`).join("")}function Ge(t){if(t==="single")return"rangeSingle";if(t==="start")return"rangeStart";if(t==="end")return"rangeEnd";if(t==="in")return"rangeInRange";return""}class dt extends HTMLElement{static observedAttributes=["value","display","min","max","first-day","locale","fixed-weeks","show-week-numbers","selection","month-format"];static setDefaultControlClasses(t){pt(t)}static getDefaultControlClasses(){return nt()}static setDefaultMessages(t){gt(t)}static getDefaultMessages(){return U()}constructor(){super();this._id=`date-calendar-${++Ve}`,this._model=new Ct,this._connected=!1,this._rendering=!1,this._source=null,this._hostIntent=null,this._sourceStates=new Map,this._loadedRanges=new Set,this._loadController=null,this._loadingKey="",this._loadingPromise=null,this._dateState=null,this._renderDay=null,this._isDateDisabled=null,this._highlightedRange={start:"",end:""},this._paintedRange={start:"",end:""},this._paintedPreview=!1,this._renderedStates=new Map,this._messages=null,this._controlClasses=null,this._stopDefaultMessages=null,this._stopDefaultControlClasses=null,this._onClick=this._onClick.bind(this),this._onChange=this._onChange.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onFocusIn=this._onFocusIn.bind(this)}connectedCallback(){if(this._connected)return;K(this,["locale","min","max","firstDay","selection","monthFormat","fixedWeeks","showWeekNumbers","controlClasses","messages","source","dateState","renderDay","isDateDisabled","highlightedRange","value","display"]),this._syncModel(),K(this,["focusedDate"]),this._stopDefaultControlClasses=Yt(()=>{if(Gt(this._controlClasses))this.render()}),this._stopDefaultMessages=yt(()=>{if(this._messages===null)this.render()}),this._connected=!0,this.addEventListener("click",this._onClick),this.addEventListener("change",this._onChange),this.addEventListener("keydown",this._onKeyDown),this.addEventListener("focusin",this._onFocusIn),this.render()}disconnectedCallback(){this._stopDefaultControlClasses?.(),this._stopDefaultControlClasses=null,this._stopDefaultMessages?.(),this._stopDefaultMessages=null,this._connected=!1,this._loadController?.abort(),this._loadController=null,this._loadingKey="",this._loadingPromise=null,this.removeEventListener("click",this._onClick),this.removeEventListener("change",this._onChange),this.removeEventListener("keydown",this._onKeyDown),this.removeEventListener("focusin",this._onFocusIn)}attributeChangedCallback(){if(!this._connected||this._rendering)return;this._syncModel(),this.render()}get locale(){return P(this.getAttribute("locale")||"")}set locale(t){if(t)this.setAttribute("locale",t);else this.removeAttribute("locale")}get value(){return this._model.value}set value(t){let e=t||"";if(e&&!c(e))throw TypeError(`Invalid calendar value: ${e}`);if(e===this._model.value)return;if(this._model.setValue(e),this._reflect("value",e),this._connected)this.render()}get display(){return this._model.display}set display(t){this._setDisplay(t,{emit:!1})}get focusedDate(){return this._model.focused}set focusedDate(t){let e=t||"";if(e===this._model.focused)return;this.focusDate(e,{moveFocus:!1})}get min(){let t=this.getAttribute("min")||"";return c(t)?t:""}set min(t){if(t)this.setAttribute("min",t);else this.removeAttribute("min")}get max(){let t=this.getAttribute("max")||"";return c(t)?t:""}set max(t){if(t)this.setAttribute("max",t);else this.removeAttribute("max")}get firstDay(){return Be(this.getAttribute("first-day")||"1")}set firstDay(t){this.setAttribute("first-day",String(t))}get selection(){return this.getAttribute("selection")==="none"?"none":"single"}set selection(t){this.setAttribute("selection",t==="none"?"none":"single")}get monthFormat(){return this.getAttribute("month-format")==="short"?"short":"long"}set monthFormat(t){if(t==="short")this.setAttribute("month-format","short");else this.removeAttribute("month-format")}get highlightedRange(){return{...this._highlightedRange}}set highlightedRange(t){let e=mt(t),s=this.hasAttribute("data-range-preview");if(e.start===this._paintedRange.start&&e.end===this._paintedRange.end&&s===this._paintedPreview)return;if(this._highlightedRange=e,this._connected)this._updateRangeDom()}get fixedWeeks(){return this.hasAttribute("fixed-weeks")}set fixedWeeks(t){this.toggleAttribute("fixed-weeks",Boolean(t))}get showWeekNumbers(){return this.hasAttribute("show-week-numbers")}set showWeekNumbers(t){this.toggleAttribute("show-week-numbers",Boolean(t))}get controlClasses(){return at(this._controlClasses)}set controlClasses(t){let e=this.controlClasses;if(this._controlClasses=rt(t),St(e,this.controlClasses))return;if(this._connected)this.render()}get messages(){return this._messages??U()}set messages(t){if(this._messages=t==null?null:{...U(),...t},this._connected)this.render()}get source(){return this._source}set source(t){this._source=t||null,this.refreshSource()}get dateState(){return this._dateState}set dateState(t){if(this._dateState=typeof t==="function"?t:null,this._connected)this.render()}get renderDay(){return this._renderDay}set renderDay(t){if(this._renderDay=typeof t==="function"?t:null,this._connected)this.render()}get isDateDisabled(){return this._isDateDisabled}set isDateDisabled(t){if(this._isDateDisabled=typeof t==="function"?t:null,this._connected)this.render()}_syncModel(){let t=this.firstDay;this._model.firstDay=t;let e=this.getAttribute("value")||"";if(!e||c(e))this._model.value=e;let s=this.getAttribute("display")||"";if(s)try{this._model.setDisplay(it(s,t))}catch{}else if(this._model.value)this._model.display=f(this._model.value),this._model.focused=this._model.value;if(this._model.focused=this._clamp(this._model.focused),!this.getAttribute("display"))this._model.display=f(this._model.focused)}_reflect(t,e){if(this._rendering=!0,e){if(this.getAttribute(t)!==e)this.setAttribute(t,e)}else if(this.hasAttribute(t))this.removeAttribute(t);this._rendering=!1}_clamp(t){let e=Nt(t,this.min,this.max),s=f(e),i=it(s,this.firstDay);if(i===s)return e;let n=Number(e.slice(8,10))||1,r=F(`${i}-01`,n-1),a=Et(i);return _(r,a)>0?a:r}_weeks(t=this.display){return Bt(it(t,this.firstDay),{firstDay:this.firstDay,fixedWeeks:this.fixedWeeks})}_focusTargetKey(t){if(t.matches(".dp-month-select, .dp-year-input")&&t.id)return`#${CSS.escape(t.id)}`;if(t.matches(".dp-nav[data-calendar-action]"))return`.dp-nav[data-calendar-action="${CSS.escape(t.dataset.calendarAction||"")}"]`;if(t.matches(".dp-day[data-date]")){let e=t.getAttribute("data-date")||"";if(c(e))return`.dp-day[data-date="${e}"]`}return""}_range(t=this.display){let e=this._weeks(t),s=e[0],i=e[e.length-1];if(!s||!i)throw Error("Calendar month produced no weeks");return{start:s[0],end:i[6]}}getDateState(t){let e=this._sourceStates.get(t)||{},s=this._dateState?.(t,{...e})||{},i={...e,...s},n=this.min&&_(t,this.min)<0||this.max&&_(t,this.max)>0,a=i.enabled===!0?!1:Boolean(this._isDateDisabled?.(t)),o=Boolean(n)||Boolean(i.disabled)||a;return{...i,disabled:o}}async refreshSource(){if(this._loadController?.abort(),this._loadController=null,this._loadingKey="",this._loadingPromise=null,this._loadedRanges.clear(),this._sourceStates.clear(),this._connected)this.render(),await this._loadDisplay(this.display)}async ensureDate(t){if(!c(t)||!this._source)return!0;return await this._loadDisplay(f(t),!1)==="loaded"}async _loadDisplay(t,e=!0){if(!this._source)return"loaded";let s=this._range(t),i=`${s.start}/${s.end}`;if(this._loadedRanges.has(i))return"loaded";if(i===this._loadingKey&&this._loadingPromise)return this._loadingPromise;this._loadController?.abort();let n=new AbortController;this._loadController=n,this._loadingKey=i;let r=this._source,a=(async()=>{this.toggleAttribute("data-loading",!0),this.dispatchEvent(new CustomEvent("dateloadstart",{detail:s,bubbles:!0}));try{let o=typeof r==="function"?r:r?.load?.bind(r);if(!o)throw TypeError("Date source must be a function or expose load(range, { signal })");let l=await o(s,{signal:n.signal});if(n.signal.aborted)return"cancelled";for(let[d,u]of Zt(l))this._sourceStates.set(d,u);if(this._loadedRanges.add(i),this.dispatchEvent(new CustomEvent("dateloadend",{detail:s,bubbles:!0})),e&&this._connected&&f(this.display)===f(t))this.render(!1);return"loaded"}catch(o){if(n.signal.aborted)return"cancelled";return this.dispatchEvent(new CustomEvent("dateloaderror",{detail:{...s,error:o},bubbles:!0})),"failed"}finally{if(this._loadController===n)this._loadController=null,this.removeAttribute("data-loading");if(this._loadingKey===i)this._loadingKey="",this._loadingPromise=null}})();return this._loadingPromise=a,a}_setDisplay(t,e={}){let s=this._model.display;if(this._model.setDisplay(it(t,this.firstDay)),this._model.focused=this._clamp(this._model.focused),this._model.display=f(this._model.focused),this._reflect("display",this._model.display),this._connected)this.render();if(e.emit!==!1&&s!==this._model.display)this._emitDisplayChange();return this._model.display}_emitDisplayChange(){let t=this._range();this.dispatchEvent(new CustomEvent("displaychange",{detail:{display:this.display,...t},bubbles:!0}))}previousMonth(){return this._setDisplay(vt(this.display,-1)??this.display)}nextMonth(){return this._setDisplay(vt(this.display,1)??this.display)}focusDate(t,e={}){if(!c(t))throw TypeError(`Invalid date: ${t}`);let s=this._clamp(t),i=this.display,n=this._model.focused,r=e.moveFocus!==!1;if(this._model.setFocused(s),this._reflect("display",this._model.display),i!==this.display){if(this._connected)this.render();this._emitDisplayChange()}else if(this._connected&&n!==this._model.focused)this._moveFocusDom(n,this._model.focused,r);if(r)queueMicrotask(()=>this.focusGrid())}_moveFocusDom(t,e,s=!0){let i=t?this.querySelector(`.dp-day[data-date="${CSS.escape(t)}"]`):null,n=this.querySelector(`.dp-day[data-date="${CSS.escape(e)}"]`);if(i instanceof HTMLElement)i.tabIndex=-1;if(n instanceof HTMLElement){if(n.tabIndex=0,s)n.focus()}else if(s)this.focusGrid()}_syncRovingDom(t){for(let s of this.querySelectorAll('.dp-day[tabindex="0"]'))if(s instanceof HTMLElement&&s.dataset.date!==t)s.tabIndex=-1;let e=this.querySelector(`.dp-day[data-date="${CSS.escape(t)}"]`);if(e instanceof HTMLElement)e.tabIndex=0}_moveSelectionDom(t,e){if(t){let s=this.querySelector(`.dp-day[data-date="${CSS.escape(t)}"]`);if(s instanceof HTMLElement)s.removeAttribute("data-selected"),s.removeAttribute("aria-selected")}if(e){let s=this.querySelector(`.dp-day[data-date="${CSS.escape(e)}"]`);if(s instanceof HTMLElement)return s.setAttribute("data-selected","true"),s.setAttribute("aria-selected","true"),!0}return!1}_dayLabel(t,e,s){let i=this.hasAttribute("data-range-preview")?"":Ge(s),n=typeof e.description==="string"?e.description:"";return[ot(t,this.locale),n,i?this.messages[i]:"",e.disabled?this.messages.unavailable:""].filter(Boolean).join(". ")}_updateRangeDom(){let t=this._paintedRange,e=this._paintedPreview;this._paintedRange={...this._highlightedRange},this._paintedPreview=this.hasAttribute("data-range-preview");for(let s of this.querySelectorAll(".dp-day[data-date]")){if(!(s instanceof HTMLTableCellElement))continue;let i=s.dataset.date||"",n=_t(i,this._highlightedRange);if(n===_t(i,t)&&e===this._paintedPreview)continue;for(let[r,a]of Object.entries(Jt(n)))if(a)s.setAttribute(r,"true");else s.removeAttribute(r);if(!e||!this._paintedPreview){let r=this._renderedStates.get(i)||{},a=this._dayLabel(i,r,n);if(s.getAttribute("aria-label")!==a)s.setAttribute("aria-label",a)}}}focusGrid(){let t=this.querySelector(`.dp-day[data-date="${CSS.escape(this.focusedDate)}"]`);if(t instanceof HTMLElement)t.focus()}async activateDate(t){let e=this._hostIntent?.date===t?this._hostIntent.intent:void 0;this._hostIntent=null;let s=(a)=>{if(e!==void 0)tt.set(a,e);return a},i=await this.ensureDate(t),n=this.getDateState(t);if(!i||n.disabled)return this.dispatchEvent(s(new CustomEvent("dateinvalid",{detail:{date:t,state:n},bubbles:!0}))),!1;if(!this.dispatchEvent(s(new CustomEvent("dateactivate",{detail:{date:t,state:n},bubbles:!0,cancelable:!0}))))return!1;if(this.selection==="single"){let a=this._model.value;if(this._model.setValue(t),this._reflect("value",t),this.dispatchEvent(new CustomEvent("datechange",{detail:{value:t},bubbles:!0})),this.dispatchEvent(new Event("change",{bubbles:!0})),this._connected)if(f(t)===this.display)this._moveSelectionDom(a,t);else this.render()}else if(this._connected){if(f(t)!==this.display)this.render()}return!0}_onClick(t){let e=t.target;if(!(e instanceof Element))return;let s=e.closest("[data-calendar-action]");if(s instanceof HTMLButtonElement){let a=s.dataset.calendarAction;if(a==="previous")this.previousMonth();if(a==="next")this.nextMonth();return}let i=e.closest(".dp-day[data-date]");if(!(i instanceof HTMLTableCellElement))return;let n=i.dataset.date||"";if(!c(n))return;let r=this.display;if(this._model.setFocused(this._clamp(n)),this._reflect("display",this._model.display),r!==this.display)this._emitDisplayChange();else this._syncRovingDom(this._model.focused);this.activateDate(n)}_onChange(t){let e=t.target;if(e instanceof HTMLSelectElement&&e.matches(".dp-month-select")){this._setDisplay(`${this.display.slice(0,4)}-${e.value}`);return}if(e instanceof HTMLInputElement&&e.matches(".dp-year-input")){let s=Number(e.value);if(!Number.isInteger(s)||s<1||s>9999){if(this._connected)this.render(!1);return}this._setDisplay(`${String(s).padStart(4,"0")}-${this.display.slice(5,7)}`)}}_onFocusIn(t){let e=t.target;if(!(e instanceof HTMLTableCellElement)||!e.matches(".dp-day[data-date]"))return;let s=e.dataset.date||"";if(!c(s))return;this._model.focused=s,this._syncRovingDom(s),this.dispatchEvent(new CustomEvent("datefocus",{detail:{date:s,state:this.getDateState(s)},bubbles:!0}))}_onKeyDown(t){let e=t.target;if(!(e instanceof HTMLTableCellElement)||!e.matches(".dp-day[data-date]"))return;let s=e.dataset.date||this.focusedDate;if(t.key==="Enter"||t.key===" "){t.preventDefault(),this.activateDate(s);return}let i=this._model.focused,n=this._model.display;if(this._model.firstDay=this.firstDay,this._model.setFocused(s,{follow:!1}),t.key==="ArrowLeft")this._model.moveFocusDays(-1);else if(t.key==="ArrowRight")this._model.moveFocusDays(1);else if(t.key==="ArrowUp")this._model.moveFocusDays(-7);else if(t.key==="ArrowDown")this._model.moveFocusDays(7);else if(t.key==="Home")this._model.focusWeekStart();else if(t.key==="End")this._model.focusWeekEnd();else if(t.key==="PageUp")t.shiftKey?this._model.moveFocusYears(-1):this._model.moveFocusMonths(-1);else if(t.key==="PageDown")t.shiftKey?this._model.moveFocusYears(1):this._model.moveFocusMonths(1);else return;let r=this._model.focused;if(this._model.focused=i,this._model.display=n,!r)return;t.preventDefault(),this.focusDate(this._clamp(r))}render(t=!0){if(!this._connected)return;let e=this.locale,s=this.display,i=Ne(s),n=Number(s.slice(5,7)),r=Xt(e,this.monthFormat),a=Mt(e,this.firstDay,"short"),o=Mt(e,this.firstDay,"long"),l=this._weeks(),d=O(),u=`${this._id}-heading`,v=`${this._id}-grid`,w=this.min?f(this.min):"",E=this.max?f(this.max):"",S=vt(s,-1),T=vt(s,1),M=Boolean(w&&S!==null&&S<w),y=Boolean(E&&T!==null&&T>E),b=` min="${this.min?Number(this.min.slice(0,4)):1}"`,x=` max="${this.max?Number(this.max.slice(0,4)):9999}"`,A=this.showWeekNumbers&&this.firstDay===1,C=A?`<th scope="col" class="dp-week-heading" abbr="${k(this.messages.week)}">#</th>`:"",V=r.map((h,m)=>{let D=m+1,p=`${String(i).padStart(4,"0")}-${String(D).padStart(2,"0")}`,Q=w&&p<w||E&&p>E;return`<option value="${String(D).padStart(2,"0")}"${D===n?" selected":""}${Q?" disabled":""}>${k(h)}</option>`}).join(""),I=a.map((h,m)=>`<th scope="col" abbr="${k(o[m])}">${k(h.replace(".",""))}</th>`).join("");this._renderedStates.clear();let Y=l.map((h)=>{let m=A?`<th scope="row" class="dp-week-number">${Ut(h[0])}</th>`:"",D=h.map((p)=>{let Q=this.getDateState(p);this._renderedStates.set(p,Q);let he=f(p)!==s,fe=this.value===p,pe=this.focusedDate===p,me=p===d,Ot=_t(p,this._highlightedRange),_e=this._dayLabel(p,Q,Ot);return`<td class="dp-day" data-date="${p}"${he?' data-outside-month="true"':""}${me?' data-today="true" aria-current="date"':""}${fe?' data-selected="true" aria-selected="true"':""}${Ue(Ot)}${Q.disabled?' data-disabled="true" aria-disabled="true"':""} tabindex="${pe?"0":"-1"}" aria-label="${k(_e)}"><span class="dp-day-number" aria-hidden="true">${Number(p.slice(8,10))}</span><span class="dp-day-extra" aria-hidden="true"></span></td>`}).join("");return`<tr>${m}${D}</tr>`}).join(""),q=document.activeElement,X=q instanceof HTMLElement&&this.contains(q)?this._focusTargetKey(q):"",R=qt(e)[0]==="year";this.toggleAttribute("data-year-first",R);let Z=this.controlClasses,j=k(Z.month||"dp-skin"),Dt=k(Z.year||"dp-skin"),ut=k(Z.nav||"dp-skin"),J=`<label class="dp-visually-hidden" for="${this._id}-month">${k(this.messages.month)}</label>
3
- <select id="${this._id}-month" class="dp-month-select ${j}" aria-label="${k(this.messages.month)}">${V}</select>`,g=`<label class="dp-visually-hidden" for="${this._id}-year">${k(this.messages.year)}</label>
4
- <input id="${this._id}-year" class="dp-year-input ${Dt}" type="number" inputmode="numeric" value="${i}"${b}${x} aria-label="${k(this.messages.year)}">`;if(this._rendering=!0,this.innerHTML=`
1
+ /*** @lekoala/date-picker v0.5.3 - https://github.com/lekoala/date-picker ***/
2
+ (()=>{var{defineProperty:wt,getOwnPropertyNames:ge,getOwnPropertyDescriptor:ye}=Object,ve=Object.prototype.hasOwnProperty;function be(t){return this[t]}var De=(t)=>{var e=(Pt??=new WeakMap).get(t),s;if(e)return e;if(e=wt({},"__esModule",{value:!0}),t&&typeof t==="object"||typeof t==="function"){for(var i of ge(t))if(!ve.call(e,i))wt(e,i,{get:be.bind(t,i),enumerable:!(s=ye(t,i))||s.enumerable})}return Pt.set(t,e),e},Pt;var we=(t)=>t;function Ee(t,e){this[t]=we.bind(null,e)}var Ce=(t,e)=>{for(var s in e)wt(t,s,{get:e[s],enumerable:!0,configurable:!0,set:Ee.bind(e,s)})};var as={};Ce(as,{defineDatePicker:()=>ue});var tt=new WeakMap;var xe=/^(\d{4})-(\d{2})-(\d{2})$/,Ae=/^(\d{4})-(\d{2})$/;function Se(t){return t%4===0&&(t%100!==0||t%400===0)}function st(t,e){if(e===2)return Se(t)?29:28;return[4,6,9,11].includes(e)?30:31}function F(t){let e=xe.exec(String(t||""));if(!e)return null;let s=Number(e[1]),i=Number(e[2]),n=Number(e[3]);if(s<1||s>9999||i<1||i>12)return null;if(n<1||n>st(s,i))return null;return{year:s,month:i,day:n}}function c(t){return F(t)!==null}function p(t){let e=String(t||""),s=Ae.exec(e);if(s){let n=Number(s[1]),r=Number(s[2]);if(n>=1&&n<=9999&&r>=1&&r<=12)return`${s[1]}-${String(r).padStart(2,"0")}`}let i=F(e);if(!i)throw TypeError(`Invalid civil date/month: ${t}`);return`${String(i.year).padStart(4,"0")}-${String(i.month).padStart(2,"0")}`}function G(t,e,s){let i=`${String(t).padStart(4,"0")}-${String(e).padStart(2,"0")}-${String(s).padStart(2,"0")}`;if(!c(i))throw TypeError(`Invalid civil date: ${i}`);return i}function N(t){let e=new Date(0);return e.setUTCHours(12,0,0,0),e.setUTCFullYear(t.year,t.month-1,t.day),e}function ke(t){return G(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate())}function V(t){let e=F(t);if(!e)throw TypeError(`Invalid civil date: ${t}`);return N(e)}function _(t,e){if(!c(t)||!c(e))throw TypeError("compareDates() expects YYYY-MM-DD values");return t===e?0:t<e?-1:1}function I(t,e){let s=F(t);if(!s||!Number.isInteger(e))throw TypeError("addDays() expects a date and integer amount");let i=N(s);return i.setUTCDate(i.getUTCDate()+e),ke(i)}function ht(t,e){let s=F(t);if(!s||!Number.isInteger(e))throw TypeError("addMonths() expects a date and integer amount");let i=s.year*12+(s.month-1)+e,n=Math.floor(i/12),a=(i%12+12)%12+1,o=Math.min(s.day,st(n,a));return G(n,a,o)}function Bt(t,e){let s=F(t);if(!s||!Number.isInteger(e))throw TypeError("addYears() expects a date and integer amount");let i=s.year+e,n=Math.min(s.day,st(i,s.month));return G(i,s.month,n)}function et(t,e){let s=`${p(t)}-01`;return p(ht(s,e))}function Me(t){return`${p(t)}-01`}function Et(t){let e=F(`${p(t)}-01`);if(!e)throw TypeError(`Invalid month: ${t}`);return G(e.year,e.month,st(e.year,e.month))}function Te(t){let e=F(t);if(!e)throw TypeError(`Invalid civil date: ${t}`);return N(e).getUTCDay()}function W(t){if(t===7)return 0;if(!Number.isInteger(t)||t<0||t>6)throw RangeError("firstDay must be 0..6 (Sunday=0, 7 accepted as Sunday alias)");return t}function ft(t,e=1){let s=(Te(t)-W(e)+7)%7;return I(t,-s)}function Ct(t,e=1){return I(ft(t,e),6)}function Nt(t,e={}){let s=e.firstDay??1,i=ft(Me(t),s),n=Ct(Et(t),s),r=[],a=i;for(;;){let o=[];for(let l=0;l<7;l++)o.push(I(a,l));if(r.push(o),_(o[6],n)>=0){if(!e.fixedWeeks||r.length>=6||_(o[6],I("9999-12-31",-7))>0)break}a=I(a,7)}return r}function Ht(t,e,s){let i=N({year:1,month:1,day:1});return Math.round((N({year:t,month:e,day:s}).getTime()-i.getTime())/86400000)}function it(t,e=1){let s=W(e),i=Ht(9999,12,31),n=p(t);for(;;){let r=F(`${n}-01`);if(!r)throw TypeError(`Invalid civil date/month: ${t}`);let a=Ht(r.year,r.month,1),o=(N(r).getUTCDay()-s+7)%7;if(a-o<0){n=et(n,1);continue}let l=st(r.year,r.month),d={year:r.year,month:r.month,day:l},h=a+l-1,v=(N(d).getUTCDay()-s+7)%7;if(h-v+6>i){n=et(n,-1);continue}return n}}function Vt(t,e="",s=""){if(!c(t))throw TypeError(`Invalid civil date: ${t}`);if(e&&_(t,e)<0)return e;if(s&&_(t,s)>0)return s;return t}function O(){let t=new Date;return G(t.getFullYear(),t.getMonth()+1,t.getDate())}function Ut(t){let e=F(t);if(!e)throw TypeError(`Invalid civil date: ${t}`);let s=N(e),i=s.getUTCDay()||7;s.setUTCDate(s.getUTCDate()+4-i);let n=new Date(0);return n.setUTCHours(12,0,0,0),n.setUTCFullYear(s.getUTCFullYear(),0,1),Math.ceil(((s.getTime()-n.getTime())/86400000+1)/7)}class xt{constructor(t={}){let e=O();this.firstDay=W(t.firstDay??1),this.value=t.value&&c(t.value)?t.value:"",this.focused=t.focused&&c(t.focused)?t.focused:this.value||e,this.display=t.display?p(t.display):p(this.focused)}setValue(t){if(t&&!c(t))throw TypeError(`Invalid value: ${t}`);return this.value=t||"",this.value}setDisplay(t){let e=p(t),s=Number(this.focused.slice(8,10))||1,i=ht(`${e}-01`,0),n=I(i,Math.max(0,s-1));return this.focused=p(n)===e?n:I(`${et(e,1)}-01`,-1),this.display=e,this.display}setFocused(t,e={}){if(!c(t))throw TypeError(`Invalid focused date: ${t}`);if(this.focused=t,e.follow!==!1)this.display=p(t);return this.focused}moveFocusDays(t){return this.setFocused(I(this.focused,t))}moveFocusMonths(t){return this.setFocused(ht(this.focused,t))}moveFocusYears(t){return this.setFocused(Bt(this.focused,t))}focusWeekStart(){return this.setFocused(ft(this.focused,this.firstDay))}focusWeekEnd(){return this.setFocused(Ct(this.focused,this.firstDay))}navigateMonth(t){let e=et(this.display,t);return this.setDisplay(e),this.display}}function Ie(t){if(typeof t!=="string")return"";return[...new Set(t.split(/\s+/).filter((e)=>e&&!e.startsWith("dp-")&&![...e].some((s)=>s.charCodeAt(0)<32||s.charCodeAt(0)===127)))].join(" ")}function kt(t,e){return t.month===e.month&&t.year===e.year&&t.nav===e.nav}var At={month:"",year:"",nav:""};function nt(){return{...At}}function rt(t){if(t==null)return null;let e={};for(let s of["month","year","nav"])if(Object.hasOwn(t,s))e[s]=Ie(t[s]);return e}function Gt(t){return t==null||["month","year","nav"].some((e)=>!Object.hasOwn(t,e))}function at(t){return{...nt(),...rt(t)}}function pt(t){let e=at(t);if(kt(At,e))return;At=e;for(let s of St)s()}var St=new Set;function Yt(t){return St.add(t),()=>{St.delete(t)}}function mt(t){if(t==null)return{start:"",end:""};if(typeof t!=="object")throw TypeError("highlightedRange expects { start, end }");let{start:e="",end:s=""}=t;if(e&&!c(e))throw TypeError(`Invalid range start: ${e}`);if(s&&!c(s))throw TypeError(`Invalid range end: ${s}`);if(!e&&s)throw TypeError("highlightedRange cannot define an end without a start");if(e&&s&&_(s,e)<0)throw TypeError("highlightedRange must be ordered; start must be on or before end");return{start:e,end:s}}function _t(t,e){if(!e||!c(t))return"";let{start:s,end:i}=e;if(!s||!c(s))return"";if(s===t)return i?i===t?"single":"start":"start";if(i&&i===t)return"end";if(i&&_(t,s)>=0&&_(t,i)<=0)return"in";return""}class Mt{constructor(){this.activeEndpoint="",this.start="",this.end=""}get range(){return{start:this.start,end:this.end}}get complete(){return Boolean(this.start&&this.end&&_(this.end,this.start)>=0)}focus(t){this.activeEndpoint=t}_refuse(t){return{status:"refused",endpoint:t,changedEndpoints:[],range:this.range,activeEndpoint:this.activeEndpoint}}project(t,e=()=>!0){if(!c(t))throw TypeError(`Invalid range activation: ${t}`);let{start:s,end:i}=this;if(this.complete&&(_(t,s)<0||_(t,i)>0)){let r=_(t,s)<0?"start":"end";if(!e(r))return this._refuse(r);return{status:"complete",endpoint:r,changedEndpoints:[r],range:r==="start"?{start:t,end:i}:{start:s,end:t},activeEndpoint:r}}if(this.activeEndpoint==="end"){if(s&&!i&&_(t,s)<0){if(!e("start"))return this._refuse("start");if(!e("end"))return this._refuse("end");return{status:"complete",endpoint:"end",changedEndpoints:["start","end"],range:{start:t,end:s},activeEndpoint:"end"}}if(s&&_(t,s)<0)return this._refuse("end");if(!e("end"))return this._refuse("end");return{status:s?"complete":"pending",endpoint:"end",changedEndpoints:["end"],range:{start:s,end:t},activeEndpoint:"end"}}if(i&&!s&&_(t,i)>0){if(!e("start"))return this._refuse("start");if(!e("end"))return this._refuse("end");return{status:"complete",endpoint:"start",changedEndpoints:["start","end"],range:{start:i,end:t},activeEndpoint:"start"}}if(!e("start"))return this._refuse("start");let n=e("end");return{status:"pending",endpoint:"start",changedEndpoints:["start"],range:{start:t,end:i},activeEndpoint:n?"end":this.activeEndpoint,...n?{}:{close:!0}}}projectEndpoint(t,e,s=()=>!0){if(!c(t))throw TypeError(`Invalid range activation: ${t}`);if(!this.complete||!s(e))return this._refuse(e);let{start:i,end:n}=this,r=e==="start"?i:n,a=e==="start"?Fe(t,n):$e(t,i);return{status:"complete",endpoint:e,changedEndpoints:a===r?[]:[e],range:e==="start"?{start:a,end:n}:{start:i,end:a},activeEndpoint:e}}previewRange(t,e="",s=()=>!0){if(!c(t))return null;if(!e&&Boolean(this.start)===Boolean(this.end))return null;let i=e?this.projectEndpoint(t,e,s):this.project(t,s);if(i.status==="refused")return null;let{start:n,end:r}=i.range;if(!n||r&&_(r,n)<0)return null;return{start:n,end:r}}_apply(t){if(t.status==="refused")return t;return this.start=t.range.start,this.end=t.range.end,this.activeEndpoint=t.activeEndpoint,t}activate(t,e=()=>!0){return this._apply(this.project(t,e))}moveEndpoint(t,e,s=()=>!0){return this._apply(this.projectEndpoint(t,e,s))}}function $e(t,e){if(!t)return e;if(!e)return t;return _(t,e)>=0?t:e}function Fe(t,e){if(!t)return e;if(!e)return t;return _(t,e)<=0?t:e}var Wt=/[\u200e\u200f\u061c\u202a-\u202e\u2066-\u2069]/g,Le=new Map,Re=new Map;function zt(t,e,s){let i=t.get(e);if(i!==void 0)return i;let n=s(),r=t.keys().next().value;if(t.size>=64&&r!==void 0)t.delete(r);return t.set(e,n),n}function z(t,e){let s=JSON.stringify([t,e]);return zt(Le,s,()=>new Intl.DateTimeFormat(t,e))}function P(t=""){if(t)return t;if(typeof document<"u"&&document.documentElement.lang)return document.documentElement.lang;if(typeof navigator<"u"&&navigator.language)return navigator.language;return"en-US"}function Oe(t){return zt(Re,t,()=>{let e=new Intl.NumberFormat(t,{useGrouping:!1}),s=new Map;for(let i=0;i<=9;i++)s.set(e.format(i),String(i));return s})}function jt(t,e,s={}){let i=String(t||"").replace(Wt,"");if(s.trim!==!1)i=i.trim();for(let[n,r]of Oe(e))i=i.split(n).join(r);return i}function ot(t,e=""){let s=P(e);return z(s,{calendar:"gregory",weekday:"long",year:"numeric",month:"long",day:"numeric",timeZone:"UTC"}).format(V(t))}function qt(t,e=""){let s=P(e);return z(s,{calendar:"gregory",year:"numeric",month:"long",timeZone:"UTC"}).format(V(`${t.slice(0,7)}-15`))}function Kt(t=""){let e=P(t);try{let s=z(e,{calendar:"gregory",year:"numeric",month:"long",timeZone:"UTC"}).formatToParts(V("2026-09-15")),i=-1,n=-1;if(s.forEach((r,a)=>{let o=r.type;if(o==="month"){if(i<0)i=a}else if(o==="year"||o==="relatedYear"||o==="yearName"){if(n<0)n=a}}),i>=0&&n>=0)return n<i?["year","month"]:["month","year"]}catch{}return["month","year"]}function Xt(t="",e="long"){let s=P(t),i=z(s,{calendar:"gregory",month:e,timeZone:"UTC"});return Array.from({length:12},(n,r)=>i.format(V(`2026-${String(r+1).padStart(2,"0")}-15`)))}function Tt(t="",e=1,s="short"){let i=P(t),n=z(i,{calendar:"gregory",weekday:s,timeZone:"UTC"}),r=W(e),a=V("2026-01-04");return Array.from({length:7},(o,l)=>{let d=new Date(a);return d.setUTCDate(a.getUTCDate()+(r+l)%7),n.format(d)})}function Pe(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function lt(t=""){let e=P(t),s=z(e,{calendar:"gregory",year:"numeric",month:"2-digit",day:"2-digit",timeZone:"UTC"}),i=V("2006-11-22"),n=s.formatToParts(i).filter((d)=>d.type!=="literal"||d.value),r=n.filter((d)=>["day","month","year"].includes(d.type)).map((d)=>d.type),a=n.map((d)=>{if(d.type==="day")return"DD";if(d.type==="month")return"MM";if(d.type==="year")return"YYYY";return d.value.replace(Wt,"")}).join(""),o=n.map((d)=>{if(d.type==="day"||d.type==="month")return"(\\d{1,2})";if(d.type==="year")return"(\\d{4})";let h=jt(d.value,e,{trim:!1});return Pe(h).replace(/\s+/g,"\\s*")}).join(""),l=new RegExp(`^\\s*${o}\\s*$`);return{locale:e,placeholder:a,format(d){if(!c(d))return"";return s.format(V(d))},parse(d){let h=jt(d,e);if(c(h))return h;let v=l.exec(h);if(!v)return"";let w={};if(r.forEach((E,k)=>{w[E]=Number(v[k+1])}),!w.year||!w.month||!w.day)return"";try{return G(w.year,w.month,w.day)}catch{return""}}}}var He={chooseDate:"Choose date",changeDate:"Change date",previousMonth:"Previous month",nextMonth:"Next month",month:"Month",year:"Year",calendar:"Choose a date",unavailable:"Unavailable",invalidDate:"Enter a valid date",unavailableDate:"This date is unavailable",formatHint:"Format",week:"Week",rangeStart:"Range start",rangeInRange:"Inside range",rangeEnd:"Range end",rangeSingle:"Range of one day",rangeOrderStart:"Start must be on or before end",rangeOrderEnd:"End must be on or after start"},It={...He};function U(){return{...It}}function gt(t){It={...It,...t};for(let e of $t)e()}var $t=new Set;function yt(t){return $t.add(t),()=>{$t.delete(t)}}function Zt(t){let e=t&&typeof t==="object"&&!Array.isArray(t)&&"dates"in t?t.dates:t,s=new Map;if(Array.isArray(e)){for(let i of e){if(!i||typeof i!=="object"||!("date"in i))continue;let{date:n,...r}=i;s.set(String(n),r)}return s}if(e&&typeof e==="object")for(let[i,n]of Object.entries(e))s.set(i,n&&typeof n==="object"?n:{});return s}function q(t,e){for(let s of e){if(!Object.hasOwn(t,s))continue;let i=Reflect.get(t,s);Reflect.deleteProperty(t,s),Reflect.set(t,s,i)}}var Be=0;function S(t){return String(t).replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}function Ne(t){let e=Number(t);if(e===7)return 0;return Number.isInteger(e)&&e>=0&&e<=6?e:1}function Ve(t){return Number(t.slice(0,4))}function vt(t,e){let[s,i]=t.split("-").map(Number),n=s*12+(i-1)+e,r=Math.floor(n/12),a=(n%12+12)%12+1;if(r<1||r>9999)return null;return`${String(r).padStart(4,"0")}-${String(a).padStart(2,"0")}`}function Jt(t){return{"data-range-start":t==="start"||t==="single","data-range-end":t==="end"||t==="single","data-in-range":t==="in"}}function Ue(t){return Object.entries(Jt(t)).filter(([,e])=>e).map(([e])=>` ${e}="true"`).join("")}function Ge(t){if(t==="single")return"rangeSingle";if(t==="start")return"rangeStart";if(t==="end")return"rangeEnd";if(t==="in")return"rangeInRange";return""}class dt extends HTMLElement{static observedAttributes=["value","display","min","max","first-day","locale","fixed-weeks","show-week-numbers","selection","month-format"];static setDefaultControlClasses(t){pt(t)}static getDefaultControlClasses(){return nt()}static setDefaultMessages(t){gt(t)}static getDefaultMessages(){return U()}constructor(){super();this._id=`date-calendar-${++Be}`,this._model=new xt,this._connected=!1,this._lifecycleId=0,this._rendering=!1,this._heading=null,this._renderRoot=null,this._source=null,this._hostIntent=null,this._sourceStates=new Map,this._loadedRanges=new Set,this._loadController=null,this._loadingKey="",this._loadingPromise=null,this._dateState=null,this._renderDay=null,this._isDateDisabled=null,this._highlightedRange={start:"",end:""},this._paintedRange={start:"",end:""},this._paintedPreview=!1,this._renderedStates=new Map,this._messages=null,this._controlClasses=null,this._stopDefaultMessages=null,this._stopDefaultControlClasses=null,this._onClick=this._onClick.bind(this),this._onChange=this._onChange.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onFocusIn=this._onFocusIn.bind(this)}connectedCallback(){if(this._connected)return;this._lifecycleId++,q(this,["locale","min","max","firstDay","selection","monthFormat","fixedWeeks","showWeekNumbers","controlClasses","messages","source","dateState","renderDay","isDateDisabled","highlightedRange","value","display"]),this._syncModel(),q(this,["focusedDate"]),this._stopDefaultControlClasses=Yt(()=>{if(Gt(this._controlClasses))this.render()}),this._stopDefaultMessages=yt(()=>{if(this._messages===null)this.render()}),this._connected=!0,this.addEventListener("click",this._onClick),this.addEventListener("change",this._onChange),this.addEventListener("keydown",this._onKeyDown),this.addEventListener("focusin",this._onFocusIn),this.render()}disconnectedCallback(){this._stopDefaultControlClasses?.(),this._stopDefaultControlClasses=null,this._stopDefaultMessages?.(),this._stopDefaultMessages=null,this._connected=!1,this._lifecycleId++,this._loadController?.abort(),this._loadController=null,this._loadingKey="",this._loadingPromise=null,this.removeEventListener("click",this._onClick),this.removeEventListener("change",this._onChange),this.removeEventListener("keydown",this._onKeyDown),this.removeEventListener("focusin",this._onFocusIn)}attributeChangedCallback(t,e,s){if(this._rendering)return;if(t==="value"&&s&&!c(s)){this._reflect("value",this._model.value);return}if((t==="min"||t==="max")&&s&&!c(s)){if(this._reflect(t,""),this._connected)this._syncModel(),this.render();return}if(t==="display"&&s)try{if(p(s)!==s)throw TypeError("Non-canonical month")}catch{this._reflect("display",this._model.display);return}if(!this._connected)return;this._syncModel(),this.render()}_queueFocus(t){let e=this._lifecycleId;queueMicrotask(()=>{if(!this._connected||e!==this._lifecycleId)return;t()})}get locale(){return P(this.getAttribute("locale")||"")}set locale(t){if(t)this.setAttribute("locale",t);else this.removeAttribute("locale")}get value(){return this._model.value}set value(t){let e=t||"";if(e&&!c(e))throw TypeError(`Invalid calendar value: ${e}`);if(e===this._model.value)return;if(this._model.setValue(e),this._reflect("value",e),this._connected)this.render()}get display(){return this._model.display}set display(t){this._setDisplay(t,{emit:!1})}get focusedDate(){return this._model.focused}set focusedDate(t){let e=t||"";if(e===this._model.focused)return;this.focusDate(e,{moveFocus:!1})}get min(){let t=this.getAttribute("min")||"";return c(t)?t:""}set min(t){if(t)this.setAttribute("min",t);else this.removeAttribute("min")}get max(){let t=this.getAttribute("max")||"";return c(t)?t:""}set max(t){if(t)this.setAttribute("max",t);else this.removeAttribute("max")}get firstDay(){return Ne(this.getAttribute("first-day")||"1")}set firstDay(t){this.setAttribute("first-day",String(t))}get selection(){return this.getAttribute("selection")==="none"?"none":"single"}set selection(t){this.setAttribute("selection",t==="none"?"none":"single")}get monthFormat(){return this.getAttribute("month-format")==="short"?"short":"long"}set monthFormat(t){if(t==="short")this.setAttribute("month-format","short");else this.removeAttribute("month-format")}get highlightedRange(){return{...this._highlightedRange}}set highlightedRange(t){let e=mt(t),s=this.hasAttribute("data-range-preview");if(e.start===this._paintedRange.start&&e.end===this._paintedRange.end&&s===this._paintedPreview)return;if(this._highlightedRange=e,this._connected)this._updateRangeDom()}get fixedWeeks(){return this.hasAttribute("fixed-weeks")}set fixedWeeks(t){this.toggleAttribute("fixed-weeks",Boolean(t))}get showWeekNumbers(){return this.hasAttribute("show-week-numbers")}set showWeekNumbers(t){this.toggleAttribute("show-week-numbers",Boolean(t))}get controlClasses(){return at(this._controlClasses)}set controlClasses(t){let e=this.controlClasses;if(this._controlClasses=rt(t),kt(e,this.controlClasses))return;if(this._connected)this.render()}get messages(){return this._messages??U()}set messages(t){if(this._messages=t==null?null:{...U(),...t},this._connected)this.render()}get source(){return this._source}set source(t){this._source=t||null,this.refreshSource()}get dateState(){return this._dateState}set dateState(t){if(this._dateState=typeof t==="function"?t:null,this._connected)this.render()}get renderDay(){return this._renderDay}set renderDay(t){if(this._renderDay=typeof t==="function"?t:null,this._connected)this.render()}get isDateDisabled(){return this._isDateDisabled}set isDateDisabled(t){if(this._isDateDisabled=typeof t==="function"?t:null,this._connected)this.render()}_syncModel(){let t=this.firstDay;this._model.firstDay=t;let e=this.getAttribute("value")||"";if(!e||c(e))this._model.value=e;let s=this.getAttribute("display")||"";if(s)try{this._model.setDisplay(it(s,t))}catch{}else if(this._model.value)this._model.display=p(this._model.value),this._model.focused=this._model.value;if(this._model.focused=this._clamp(this._model.focused),!this.getAttribute("display"))this._model.display=p(this._model.focused)}_reflect(t,e){if(this._rendering=!0,e){if(this.getAttribute(t)!==e)this.setAttribute(t,e)}else if(this.hasAttribute(t))this.removeAttribute(t);this._rendering=!1}_clamp(t){let e=Vt(t,this.min,this.max),s=p(e),i=it(s,this.firstDay);if(i===s)return e;let n=Number(e.slice(8,10))||1,r=I(`${i}-01`,n-1),a=Et(i);return _(r,a)>0?a:r}_weeks(t=this.display){return Nt(it(t,this.firstDay),{firstDay:this.firstDay,fixedWeeks:this.fixedWeeks})}_focusTargetKey(t){if(t.matches(".dp-month-select, .dp-year-input")&&t.id)return`#${CSS.escape(t.id)}`;if(t.matches(".dp-nav[data-calendar-action]"))return`.dp-nav[data-calendar-action="${CSS.escape(t.dataset.calendarAction||"")}"]`;if(t.matches(".dp-day[data-date]")){let e=t.getAttribute("data-date")||"";if(c(e))return`.dp-day[data-date="${e}"]`}return""}_range(t=this.display){let e=this._weeks(t),s=e[0],i=e[e.length-1];if(!s||!i)throw Error("Calendar month produced no weeks");return{start:s[0],end:i[6]}}getDateState(t){let e=this._sourceStates.get(t)||{},s=this._dateState?.(t,{...e})||{},i={...e,...s},n=this.min&&_(t,this.min)<0||this.max&&_(t,this.max)>0,a=i.enabled===!0?!1:Boolean(this._isDateDisabled?.(t)),o=Boolean(n)||Boolean(i.disabled)||a;return{...i,disabled:o}}async refreshSource(){if(this._loadController?.abort(),this._loadController=null,this._loadingKey="",this._loadingPromise=null,this._loadedRanges.clear(),this._sourceStates.clear(),this._connected)this.render(),await this._loadDisplay(this.display)}async ensureDate(t){if(!c(t)||!this._source)return!0;return await this._loadDisplay(p(t),!1)==="loaded"}async _loadDisplay(t,e=!0){if(!this._source)return"loaded";let s=this._range(t),i=`${s.start}/${s.end}`;if(this._loadedRanges.has(i))return"loaded";if(i===this._loadingKey&&this._loadingPromise)return this._loadingPromise;this._loadController?.abort();let n=new AbortController;this._loadController=n,this._loadingKey=i;let r=this._source,a=(async()=>{this.toggleAttribute("data-loading",!0),this.dispatchEvent(new CustomEvent("dateloadstart",{detail:s,bubbles:!0}));try{let o=typeof r==="function"?r:r?.load?.bind(r);if(!o)throw TypeError("Date source must be a function or expose load(range, { signal })");let l=await o(s,{signal:n.signal});if(n.signal.aborted)return"cancelled";for(let[d,h]of Zt(l))this._sourceStates.set(d,h);if(this._loadedRanges.add(i),this.dispatchEvent(new CustomEvent("dateloadend",{detail:s,bubbles:!0})),e&&this._connected&&p(this.display)===p(t))this.render(!1);return"loaded"}catch(o){if(n.signal.aborted)return"cancelled";return this.dispatchEvent(new CustomEvent("dateloaderror",{detail:{...s,error:o},bubbles:!0})),"failed"}finally{if(this._loadController===n)this._loadController=null,this.removeAttribute("data-loading");if(this._loadingKey===i)this._loadingKey="",this._loadingPromise=null}})();return this._loadingPromise=a,a}_setDisplay(t,e={}){let s=this._model.display;if(this._model.setDisplay(it(t,this.firstDay)),this._model.focused=this._clamp(this._model.focused),this._model.display=p(this._model.focused),this._reflect("display",this._model.display),this._connected)this.render();if(e.emit!==!1&&s!==this._model.display)this._emitDisplayChange();return this._model.display}_emitDisplayChange(){let t=this._range();this.dispatchEvent(new CustomEvent("displaychange",{detail:{display:this.display,...t},bubbles:!0}))}previousMonth(){return this._setDisplay(vt(this.display,-1)??this.display)}nextMonth(){return this._setDisplay(vt(this.display,1)??this.display)}focusDate(t,e={}){if(!c(t))throw TypeError(`Invalid date: ${t}`);let s=this._clamp(t),i=this.display,n=this._model.focused,r=e.moveFocus!==!1;if(this._model.setFocused(s),this._reflect("display",this._model.display),i!==this.display){if(this._connected)this.render();this._emitDisplayChange()}else if(this._connected&&n!==this._model.focused)this._moveFocusDom(n,this._model.focused,r);if(r)this._queueFocus(()=>this.focusGrid())}_moveFocusDom(t,e,s=!0){let i=t?this.querySelector(`.dp-day[data-date="${CSS.escape(t)}"]`):null,n=this.querySelector(`.dp-day[data-date="${CSS.escape(e)}"]`);if(i instanceof HTMLElement)i.tabIndex=-1;if(n instanceof HTMLElement){if(n.tabIndex=0,s)n.focus()}else if(s)this.focusGrid()}_syncRovingDom(t){for(let s of this.querySelectorAll('.dp-day[tabindex="0"]'))if(s instanceof HTMLElement&&s.dataset.date!==t)s.tabIndex=-1;let e=this.querySelector(`.dp-day[data-date="${CSS.escape(t)}"]`);if(e instanceof HTMLElement)e.tabIndex=0}_moveSelectionDom(t,e){if(t){let s=this.querySelector(`.dp-day[data-date="${CSS.escape(t)}"]`);if(s instanceof HTMLElement)s.removeAttribute("data-selected"),s.removeAttribute("aria-selected")}if(e){let s=this.querySelector(`.dp-day[data-date="${CSS.escape(e)}"]`);if(s instanceof HTMLElement)return s.setAttribute("data-selected","true"),s.setAttribute("aria-selected","true"),!0}return!1}_dayLabel(t,e,s){let i=this.hasAttribute("data-range-preview")?"":Ge(s),n=typeof e.description==="string"?e.description:"";return[ot(t,this.locale),n,i?this.messages[i]:"",e.disabled?this.messages.unavailable:""].filter(Boolean).join(". ")}_updateRangeDom(){let t=this._paintedRange,e=this._paintedPreview;this._paintedRange={...this._highlightedRange},this._paintedPreview=this.hasAttribute("data-range-preview");for(let s of this.querySelectorAll(".dp-day[data-date]")){if(!(s instanceof HTMLTableCellElement))continue;let i=s.dataset.date||"",n=_t(i,this._highlightedRange);if(n===_t(i,t)&&e===this._paintedPreview)continue;for(let[r,a]of Object.entries(Jt(n)))if(a)s.setAttribute(r,"true");else s.removeAttribute(r);if(!e||!this._paintedPreview){let r=this._renderedStates.get(i)||{},a=this._dayLabel(i,r,n);if(s.getAttribute("aria-label")!==a)s.setAttribute("aria-label",a)}}}focusGrid(){let t=this.querySelector(`.dp-day[data-date="${CSS.escape(this.focusedDate)}"]`);if(t instanceof HTMLElement)t.focus()}async activateDate(t){if(!this._connected)return!1;let e=this._lifecycleId,s=this._hostIntent?.date===t?this._hostIntent.intent:void 0;this._hostIntent=null;let i=(o)=>{if(s!==void 0)tt.set(o,s);return o},n=await this.ensureDate(t);if(!this._connected||e!==this._lifecycleId)return!1;let r=this.getDateState(t);if(!n||r.disabled)return this.dispatchEvent(i(new CustomEvent("dateinvalid",{detail:{date:t,state:r},bubbles:!0}))),!1;if(!this.dispatchEvent(i(new CustomEvent("dateactivate",{detail:{date:t,state:r},bubbles:!0,cancelable:!0}))))return!1;if(this.selection==="single"){let o=this._model.value;if(this._model.setValue(t),this._reflect("value",t),this.dispatchEvent(new CustomEvent("datechange",{detail:{value:t},bubbles:!0})),this.dispatchEvent(new Event("change",{bubbles:!0})),this._connected)if(p(t)===this.display)this._moveSelectionDom(o,t);else this.render()}else if(this._connected){if(p(t)!==this.display)this.render()}return!0}_onClick(t){let e=t.target;if(!(e instanceof Element))return;let s=e.closest("[data-calendar-action]");if(s instanceof HTMLButtonElement){let a=s.dataset.calendarAction;if(a==="previous")this.previousMonth();if(a==="next")this.nextMonth();return}let i=e.closest(".dp-day[data-date]");if(!(i instanceof HTMLTableCellElement))return;let n=i.dataset.date||"";if(!c(n))return;let r=this.display;if(this._model.setFocused(this._clamp(n)),this._reflect("display",this._model.display),r!==this.display)this._emitDisplayChange();else this._syncRovingDom(this._model.focused);this.activateDate(n)}_onChange(t){let e=t.target;if(e instanceof HTMLSelectElement&&e.matches(".dp-month-select")){this._setDisplay(`${this.display.slice(0,4)}-${e.value}`);return}if(e instanceof HTMLInputElement&&e.matches(".dp-year-input")){let s=Number(e.value);if(!Number.isInteger(s)||s<1||s>9999){if(this._connected)this.render(!1);return}this._setDisplay(`${String(s).padStart(4,"0")}-${this.display.slice(5,7)}`)}}_onFocusIn(t){let e=t.target;if(!(e instanceof HTMLTableCellElement)||!e.matches(".dp-day[data-date]"))return;let s=e.dataset.date||"";if(!c(s))return;this._model.focused=s,this._syncRovingDom(s),this.dispatchEvent(new CustomEvent("datefocus",{detail:{date:s,state:this.getDateState(s)},bubbles:!0}))}_onKeyDown(t){let e=t.target;if(!(e instanceof HTMLTableCellElement)||!e.matches(".dp-day[data-date]"))return;let s=e.dataset.date||this.focusedDate;if(t.key==="Enter"||t.key===" "){t.preventDefault(),this.activateDate(s);return}let i=this._model.focused,n=this._model.display;if(this._model.firstDay=this.firstDay,this._model.setFocused(s,{follow:!1}),t.key==="ArrowLeft")this._model.moveFocusDays(-1);else if(t.key==="ArrowRight")this._model.moveFocusDays(1);else if(t.key==="ArrowUp")this._model.moveFocusDays(-7);else if(t.key==="ArrowDown")this._model.moveFocusDays(7);else if(t.key==="Home")this._model.focusWeekStart();else if(t.key==="End")this._model.focusWeekEnd();else if(t.key==="PageUp")t.shiftKey?this._model.moveFocusYears(-1):this._model.moveFocusMonths(-1);else if(t.key==="PageDown")t.shiftKey?this._model.moveFocusYears(1):this._model.moveFocusMonths(1);else return;let r=this._model.focused;if(this._model.focused=i,this._model.display=n,!r)return;t.preventDefault(),this.focusDate(this._clamp(r))}render(t=!0){if(!this._connected)return;let e=this.locale,s=this.display,i=Ve(s),n=Number(s.slice(5,7)),r=Xt(e,this.monthFormat),a=Tt(e,this.firstDay,"short"),o=Tt(e,this.firstDay,"long"),l=this._weeks(),d=O(),h=`${this._id}-heading`,v=`${this._id}-grid`,w=this.min?p(this.min):"",E=this.max?p(this.max):"",k=vt(s,-1),M=vt(s,1),T=Boolean(w&&k!==null&&k<w),y=Boolean(E&&M!==null&&M>E),b=` min="${this.min?Number(this.min.slice(0,4)):1}"`,C=` max="${this.max?Number(this.max.slice(0,4)):9999}"`,A=this.showWeekNumbers&&this.firstDay===1,x=A?`<th scope="col" class="dp-week-heading" abbr="${S(this.messages.week)}">#</th>`:"",B=r.map((u,f)=>{let D=f+1,m=`${String(i).padStart(4,"0")}-${String(D).padStart(2,"0")}`,Q=w&&m<w||E&&m>E;return`<option value="${String(D).padStart(2,"0")}"${D===n?" selected":""}${Q?" disabled":""}>${S(u)}</option>`}).join(""),L=a.map((u,f)=>`<th scope="col" abbr="${S(o[f])}">${S(u.replace(".",""))}</th>`).join("");this._renderedStates.clear();let Y=l.map((u)=>{let f=A?`<th scope="row" class="dp-week-number">${Ut(u[0])}</th>`:"",D=u.map((m)=>{let Q=this.getDateState(m);this._renderedStates.set(m,Q);let he=p(m)!==s,fe=this.value===m,pe=this.focusedDate===m,me=m===d,Ot=_t(m,this._highlightedRange),_e=this._dayLabel(m,Q,Ot);return`<td class="dp-day" data-date="${m}"${he?' data-outside-month="true"':""}${me?' data-today="true" aria-current="date"':""}${fe?' data-selected="true" aria-selected="true"':""}${Ue(Ot)}${Q.disabled?' data-disabled="true" aria-disabled="true"':""} tabindex="${pe?"0":"-1"}" aria-label="${S(_e)}"><span class="dp-day-number" aria-hidden="true">${Number(m.slice(8,10))}</span><span class="dp-day-extra" aria-hidden="true"></span></td>`}).join("");return`<tr>${f}${D}</tr>`}).join(""),K=document.activeElement,X=K instanceof HTMLElement&&this.contains(K)?this._focusTargetKey(K):"",R=Kt(e)[0]==="year";this.toggleAttribute("data-year-first",R);let Z=this.controlClasses,j=S(Z.month||"dp-skin"),Dt=S(Z.year||"dp-skin"),ut=S(Z.nav||"dp-skin"),J=`<label class="dp-visually-hidden" for="${this._id}-month">${S(this.messages.month)}</label>
3
+ <select id="${this._id}-month" class="dp-month-select ${j}" aria-label="${S(this.messages.month)}">${B}</select>`,g=`<label class="dp-visually-hidden" for="${this._id}-year">${S(this.messages.year)}</label>
4
+ <input id="${this._id}-year" class="dp-year-input ${Dt}" type="number" inputmode="numeric" value="${i}"${b}${C} aria-label="${S(this.messages.year)}">`;if(!this._heading?.isConnected||!this._renderRoot?.isConnected){this.replaceChildren();let u=document.createElement("h2");u.id=h,u.className="dp-calendar-heading dp-visually-hidden",u.setAttribute("aria-live","polite");let f=document.createElement("div");f.className="dp-calendar-render",this.append(u,f),this._heading=u,this._renderRoot=f}if(this._rendering=!0,this._renderRoot.innerHTML=`
5
5
  <div class="dp-calendar-shell">
6
6
  <div class="dp-calendar-header">
7
7
  ${R?g:J}
8
8
  ${R?J:g}
9
- <button type="button" class="dp-nav dp-prev ${ut}" data-calendar-action="previous" aria-label="${k(this.messages.previousMonth)}"${M?" disabled":""}><svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m4 10 4-4 4 4"/></svg></button>
10
- <button type="button" class="dp-nav dp-next ${ut}" data-calendar-action="next" aria-label="${k(this.messages.nextMonth)}"${y?" disabled":""}><svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m4 6 4 4 4-4"/></svg></button>
9
+ <button type="button" class="dp-nav dp-prev ${ut}" data-calendar-action="previous" aria-label="${S(this.messages.previousMonth)}"${T?" disabled":""}><svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m4 10 4-4 4 4"/></svg></button>
10
+ <button type="button" class="dp-nav dp-next ${ut}" data-calendar-action="next" aria-label="${S(this.messages.nextMonth)}"${y?" disabled":""}><svg aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="m4 6 4 4 4-4"/></svg></button>
11
11
  </div>
12
- <h2 id="${u}" class="dp-calendar-heading dp-visually-hidden" aria-live="polite">${k(Kt(`${s}-15`,e))}</h2>
13
- <table id="${v}" class="dp-grid" role="grid" aria-labelledby="${u}">
14
- <thead><tr>${C}${I}</tr></thead>
12
+ <table id="${v}" class="dp-grid" role="grid" aria-labelledby="${h}">
13
+ <thead><tr>${x}${L}</tr></thead>
15
14
  <tbody>${Y}</tbody>
16
15
  </table>
17
- </div>`,this._rendering=!1,this._paintedRange={...this._highlightedRange},this._paintedPreview=this.hasAttribute("data-range-preview"),X)queueMicrotask(()=>{let h=X;if(h.startsWith(".dp-day[data-date="))h=`.dp-day[data-date="${CSS.escape(this._model.focused)}"]`;let m=this.querySelector(h);if(m instanceof HTMLElement)m.focus()});if(this._renderDay)for(let h of this.querySelectorAll(".dp-day[data-date]")){if(!(h instanceof HTMLTableCellElement))continue;let m=h.dataset.date||"",D=h.querySelector(".dp-day-extra");if(!(D instanceof HTMLElement))continue;let p=this._renderDay(m,this._renderedStates.get(m)||{});if(p instanceof Node)D.append(p);else if(p!==void 0&&p!==null)D.textContent=String(p)}if(t)this._loadDisplay(s)}}function bt(t){return t==="top"||t==="bottom"?"x":"y"}var ne={top:"bottom",bottom:"top",left:"right",right:"left"},Ye=new Set(Object.keys(ne).flatMap((t)=>[t,`${t}-start`,`${t}-end`])),je=new Set(["viewport","document"]);function We(t){if(!Ye.has(t))throw TypeError(`Unknown placement: ${t}`);let[e,s=null]=t.split("-");return{side:e,align:s,crossAxis:bt(e)}}function ze(t,e,s,i,n,r){let a=bt(s),o=t.x+t.width/2-e.width/2,l=t.y+t.height/2-e.height/2,d=t[a==="x"?"width":"height"]/2-e[a==="x"?"width":"height"]/2,u;switch(s){case"top":u={x:o,y:t.y-e.height-r};break;case"bottom":u={x:o,y:t.y+t.height+r};break;case"right":u={x:t.x+t.width+r,y:l};break;case"left":u={x:t.x-e.width-r,y:l};break;default:u={x:t.x,y:t.y}}if(i==="start"||i==="end"){let v=(n&&a==="x"?-1:1)*(i==="end"?1:-1);u[a]+=d*v}return u}function Ke(t,e,s,i){return Math.max(s-t,0)+Math.max(t+e-i,0)}function qe(t){let e=t.ownerDocument?.defaultView;if(e&&t instanceof e.Element)return e.getComputedStyle(t).direction==="rtl";return"dir"in t&&t.dir==="rtl"}var Xe=25;function Ze(t){let e=t.defaultView;if(!e)return null;let s=t.documentElement,i=e.visualViewport,n=i?.offsetLeft||0,r=i?.offsetTop||0,a=i?.width||s.clientWidth||e.innerWidth,o=i?.height||s.clientHeight||e.innerHeight,l=t.compatMode==="BackCompat"?a-s.clientWidth:s.clientWidth-s.getBoundingClientRect().width;if(l>0&&l<=Xe){let d=e.getComputedStyle?.(s).scrollbarGutter;if(d&&d!=="auto")a-=l}return{x:n,y:r,width:a,height:o,right:n+a,bottom:r+o}}function Je(t,e){return e.scope?e.scope.getBoundingClientRect():Ze(t.ownerDocument)}function Qt(t,e,s,i,n){let r=s+n,a=i-e-n,o=a>=r,l=o?r:s,d=o?a:i-e;return Math.max(l,Math.min(t,d))}function te(t,e,s){if(!s)return 50;let i=(t-e)/s*100;return Math.round(Math.min(100,Math.max(0,i))*1000)/1000}function Qe(t,e){for(let s=0;s<t.length;s++){let i=t[s];if(i.right>=e.x&&i.left<=e.right&&i.bottom>=e.y&&i.top<=e.bottom)return!1}return!0}function ts(t,e,s,i,n){if(e==="top")return Math.max(0,t.top-s.y-i-n);if(e==="bottom")return Math.max(0,s.bottom-t.bottom-i-n);return Math.max(0,s.height-n*2)}function es(t){if(t.hidden)return!1;if(typeof t.checkVisibility==="function")return t.checkVisibility();return t.getClientRects().length>0}function re(t){let{offsetWidth:e,offsetHeight:s}=t;if(e&&s)return{width:e,height:s};let i=t.getBoundingClientRect();return{width:e||i.width,height:s||i.height}}var ee=new WeakMap,se={scroll:0,resize:1,"element-resize":2};function ss(t){let e=t.defaultView;if(!e)throw TypeError("floating must belong to a document with a browsing context");let s=new Set,i=new Map,n=e.ResizeObserver,r=!1,a=!1,o=e.visualViewport;function l(y,b){let x=i.get(y);if(x===void 0||se[b]>se[x])i.set(y,b)}function d(){if(r)return;r=!0,e.requestAnimationFrame(()=>{let y=[...i];i.clear(),r=!1;for(let[b,x]of y){if(!s.has(b)||!b.floating.isConnected)continue;try{b.callback({type:x})}catch(A){u(A)}}})}function u(y){if(typeof e.reportError==="function")e.reportError(y);else e.setTimeout(()=>{throw y})}function v(y){for(let b of s)l(b,y);d()}function w(y){if(!n)return null;let b=new Set,x=new n((V)=>{let I=!1;for(let Y of V)if(b.has(Y.target))I=!0;else b.add(Y.target);if(!I)return;l(y,"element-resize"),d()}),{reference:A,floating:C}=y;if(A)x.observe(A);if(C!==A)x.observe(C);return x}let E=()=>v("scroll"),S=()=>v("resize");function T(){if(a)return;t.addEventListener("scroll",E,{passive:!0,capture:!0}),e.addEventListener("resize",S,{passive:!0}),o?.addEventListener("scroll",E,{passive:!0}),o?.addEventListener("resize",S,{passive:!0}),a=!0}function M(){if(!a)return;t.removeEventListener("scroll",E,{capture:!0}),e.removeEventListener("resize",S),o?.removeEventListener("scroll",E),o?.removeEventListener("resize",S),a=!1}return{add(y,b,x){let A={reference:y,floating:b,callback:x};s.add(A),T();let C=w(A),V=!1;return()=>{if(V)return;if(V=!0,s.delete(A),i.delete(A),C?.disconnect(),s.size===0)M()}}}}function is(t){let e=t.ownerDocument,s=ee.get(e);if(!s)s=ss(e),ee.set(e,s);return s}function ae(t,e,s){if(!e?.ownerDocument)throw TypeError("autoUpdate() expects a floating HTMLElement");if(t&&t.ownerDocument!==e.ownerDocument)throw TypeError("reference and floating must belong to the same document");if(typeof s!=="function")throw TypeError("callback must be a function");return is(e).add(t,e,s)}function ie(t,e,s){let i=s.placement===void 0?"bottom-start":s.placement,{side:n,align:r,crossAxis:a}=We(i),o=s.coordinateSpace===void 0?"viewport":s.coordinateSpace;if(!je.has(o))throw TypeError(`Unknown coordinateSpace: ${o}`);if(!es(e))return null;let l=s.distance||0,d=s.flip!==!1,u=s.shift!==!1,v=s.shiftPadding??4,w=r?qe(t):!1,E=t.getClientRects();if(!E.length)return null;let S=(g)=>g==="bottom"?E[E.length-1]:E[0],T=Je(t,s);if(!T||Qe(E,T))return null;let M=re(e),y={x:{size:M.width,start:T.x,end:T.right},y:{size:M.height,start:T.y,end:T.bottom}},b=(g,h)=>ze(S(g),M,g,h,w,l),x=(g,h)=>{let{size:m,start:D,end:p}=y[h];return Ke(g,m,D+v,p-v)},A=(g,h)=>{let{size:m,start:D,end:p}=y[h];return x(u?Qt(g,m,D,p,v):g,h)},C=b(n,r),V=(g,h)=>{let m=bt(g),D=m==="x"?"y":"x",p=x(h[D],D);return{main:p,total:p+A(h[m],m)}};if(d){let g=V(n,C),h=(m)=>{let D=b(m,r),p=V(m,D);if(p.total<g.total)n=m,C=D,g=p};if(g.main>0)h(ne[n]);if(a==="y"&&g.main>0)h("top"),h("bottom");a=bt(n)}if(a==="x"&&u&&r){let g=x(C.x,"x");if(g>0){let h=r==="end"?"start":"end",m=b(n,h);if(x(m.x,"x")<g)r=h,C=m}}if(u){let{size:g,start:h,end:m}=y[a];C[a]=Qt(C[a],g,h,m,v)}let I=S(n),Y=te(I.x+I.width/2,C.x,M.width),q=te(I.y+I.height/2,C.y,M.height),X=`${ts(I,n,T,l,v)}px`,{style:R}=e,Z=R.getPropertyValue("--available-height")!==X,j=o==="document"?t.ownerDocument.defaultView:null,Dt=j?j.scrollX:0,ut=j?j.scrollY:0;R.left=`${C.x+Dt}px`,R.top=`${C.y+ut}px`,R.setProperty("--arrow-x",`${Y}%`),R.setProperty("--arrow-y",`${q}%`),R.setProperty("--available-height",X);let J=r?`${n}-${r}`:n;return e.dataset.placement=J,{width:M.width,height:M.height,roomChanged:Z,placement:J}}function oe(t,e,s={}){let i=ie(t,e,s);if(!i)return!1;if(i.roomChanged){let n=re(e);if(n.width!==i.width||n.height!==i.height)ie(t,e,{...s,placement:i.placement,flip:!1})}return!0}function H(t){return!t.matches(":disabled")&&!t.readOnly}class ct{constructor(t,e={}){this.input=t,this.messages=e.messages||{},this.adapter=lt(e.locale||""),this.hidden=null,this.canonical="",this._dirty=!1,this._commitId=0,this._originalName=t.getAttribute("name")||"",this._attributeObserver=null,this.onAttributesChanged=null,this.confirm=null,this._generatedDefault=null}setLocale(t){let e=this._generatedDefault,s=e?this.adapter.format(e):null;if(this.adapter=lt(t||""),e&&this.input.defaultValue===s)this.input.defaultValue=this.adapter.format(e)}adoptDefault(){let t=this.input;if(t.getAttribute("value")!=null||t.defaultValue!=="")return;t.defaultValue=t.value,this._generatedDefault=this.canonical&&t.value?this.canonical:null}setMessages(t){this.messages=t||{}}format(t){return this.adapter.format(t)}parse(t){return this.adapter.parse(t)}get placeholder(){return this.adapter.placeholder}get isDisabled(){return this.input.matches(":disabled")}get isReadOnly(){return this.input.readOnly}setupFormValue(){let t=this.input;this._originalName=t.getAttribute("name")||"",this._attributeObserver=new MutationObserver(()=>this.onAttributesChanged?.()),this._attributeObserver.observe(t,{attributes:!0,attributeFilter:["disabled","readonly","name","form"]}),this.syncInputState()}syncInputState(){let t=this.input,e=t.getAttribute("name")||"";if(e){if(!this.hidden){let s=document.createElement("input");s.type="hidden",s.value=this.canonical,t.insertAdjacentElement("afterend",s),this.hidden=s}if(this.hidden)this.hidden.name=e;t.removeAttribute("name")}if(this.hidden){if(t.hasAttribute("form"))this.hidden.setAttribute("form",t.getAttribute("form")||"");else this.hidden.removeAttribute("form");this.hidden.disabled=t.disabled}}dirty(){this._commitId++}get isDirty(){return this._dirty}handleInput(){let t=this.input,e=t.value.trim(),s=this.canonical?this.adapter.format(this.canonical):"";if(this.dirty(),e===s){if(this._dirty=!1,this.hidden)this.hidden.value=this.canonical;t.setCustomValidity("");return}if(this._dirty=!0,this.hidden)this.hidden.value="";if(!e){t.setCustomValidity("");return}t.setCustomValidity(this.messages.invalidDate)}async commit(t={}){let e=this.input,s=++this._commitId,i=e.value.trim();if(!i){if(s!==this._commitId)return{status:"stale"};return e.setCustomValidity(""),{status:"clear",value:""}}let n=this.adapter.parse(i);if(!n){if(s!==this._commitId)return{status:"stale"};if(this.hidden)this.hidden.value="";return e.setCustomValidity(this.messages.invalidDate),{status:"invalid"}}if(this.confirm){let r=await this.confirm(n,t);if(s!==this._commitId)return{status:"stale"};if(!r?.ok){if(this.hidden)this.hidden.value="";return e.setCustomValidity(r?.message||this.messages.unavailableDate),{status:"invalid"}}}return{status:"ok",value:n}}setCanonical(t,e={}){let s=t||"";if(s&&!c(s))throw TypeError(`Invalid date-picker value: ${s}`);if(this.dirty(),this.canonical=s,this._dirty=!1,this.hidden)this.hidden.value=s;if(e.format!==!1)this.input.value=s?this.adapter.format(s):"";this.input.setCustomValidity("")}restoreDefault(){let t=String(this.input.defaultValue??"").trim(),e=c(t)?t:this.adapter.parse(t);return e&&c(e)?e:""}teardown(){this._attributeObserver?.disconnect(),this._attributeObserver=null;let t=this.hidden?.getAttribute("name")||this._originalName;if(t)this.input.setAttribute("name",t);this.hidden?.remove(),this.hidden=null}}var ns=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?$/;function Lt(t){let e=ns.exec(String(t||""));if(!e)return null;let s=Number(e[1]),i=Number(e[2]),n=e[3]===void 0?0:Number(e[3]),r=e[4]===void 0?0:Number(e[4].padEnd(3,"0"));if(s>23||i>59||n>59||r>999)return null;return{hour:s,minute:i,second:n,millisecond:r}}function It(t){return Lt(t)!==null}function le(t){return((t.hour*60+t.minute)*60+t.second)*1000+t.millisecond}function de(t,e){let s=Lt(t),i=Lt(e);if(!s||!i)throw TypeError("compareTimes() expects HH:MM values");let n=le(s)-le(i);return n===0?0:n<0?-1:1}var rs=0,ce=4;class Rt extends HTMLElement{static observedAttributes=["value","locale","min","max","open-on-focus","month-format"];static setDefaultControlClasses(t){pt(t)}static getDefaultControlClasses(){return nt()}static setDefaultMessages(t){gt(t)}static getDefaultMessages(){return U()}constructor(){super();this._id=`date-picker-${++rs}`,this._connected=!1,this._reflecting=!1,this._value="",this._input=null,this._field=null,this._fields=null,this._range=null,this._orderTags=new Set,this._timeFields=[null,null],this._timeOrderOwned=new Set,this._lastFocusEndpoint="",this._activationId=0,this._previewDate="",this._drag=null,this._suppressGridClick=!1,this._buttons=[],this._returnFocus=null,this._panel=null,this._calendar=null,this._originalDescribedBy="",this._rangeOriginalDescribedBy=["",""],this._formatHint=null,this._generatedPlaceholder=!1,this._controller=null,this._stopTracking=null,this._open=!1,this._suppressFocusOpen=!1,this._messages=null,this._controlClasses=null,this._stopDefaultMessages=null,this._source=null,this._dateState=null,this._renderDay=null,this._isDateDisabled=null,this._coordinateSpace="viewport"}_rangeMode(){return this.hasAttribute("range")&&Boolean(this._range)}connectedCallback(){if(this._connected)return;if(K(this,["locale","min","max","monthFormat","openOnFocus","coordinateSpace","controlClasses","messages","source","dateState","renderDay","isDateDisabled"]),this.hasAttribute("range"))this._connectRange();else this._connectSingle();if(this._connected)K(this,["value","range"]),this._stopDefaultMessages=yt(()=>{if(this._messages===null)this._refreshMessages()}),this.validate()}_connectSingle(){let t=this.querySelector(":scope > input:not([type=hidden]):not([type=time]):not([data-time-start]):not([data-time-end])");if(!(t instanceof HTMLInputElement)){console.warn("<date-picker> expects a direct child text input");return}this._connected=!0,this._input=t,this._discoverTimeFields(),this._field=new ct(t,{messages:this.messages,locale:this.locale}),this._field.onAttributesChanged=()=>this._syncInputState(),this._field.confirm=(i,n)=>this._confirmDate(i,n),this._setupFormValue(),this._build(),this._syncInputState(),this._bind(),this._syncCalendarOptions();let e=this._adapter(),s=this.getAttribute("value")||(c(t.value)?t.value:e.parse(t.value));if(s&&c(s))this._setValue(s,{emit:!1,format:!0});else if(!t.value)this._setValue("",{emit:!1,format:!1});else t.setCustomValidity(this.messages.invalidDate);if(this._field.hidden)this._field.hidden.defaultValue=this._value;this._field.adoptDefault()}_discoverTimeFields(){this._timeFields=[null,null];let t=["data-time-start","data-time-end"];for(let[e,s]of t.entries()){let i=this.querySelectorAll(`:scope > input[${s}]`);if(i.length>1)console.warn(`<date-picker> expects at most one direct child input[${s}]; ignoring extras`);let n=i[0];if(n==null)continue;if(!(n instanceof HTMLInputElement)||n.type!=="time"){console.warn(`<date-picker> input[${s}] must be an <input type="time">; ignoring it`);continue}this._timeFields[e]=n}if(this.querySelector(":scope > input[type=time]:not([data-time-start]):not([data-time-end])"))console.warn("<date-picker> time inputs need [data-time-start] or [data-time-end]; ignoring it")}_connectRange(){if(this.querySelector(":scope > input[data-time-start], :scope > input[data-time-end]"))console.warn("<date-picker range> time companions are not supported yet; leaving them native");let t=this.querySelector(":scope > input[data-range-start]"),e=this.querySelector(":scope > input[data-range-end]");if(!(t instanceof HTMLInputElement)||!(e instanceof HTMLInputElement)){console.warn("<date-picker range> expects direct child inputs marked [data-range-start] and [data-range-end]");return}this._connected=!0,this._input=null,this._fields=[new ct(t,{messages:this.messages,locale:this.locale}),new ct(e,{messages:this.messages,locale:this.locale})],this._range=new Tt,this._rangeOriginalDescribedBy=[t.getAttribute("aria-describedby")||"",e.getAttribute("aria-describedby")||""];for(let o of this._fields)o.onAttributesChanged=()=>this._syncRangeFields(),o.confirm=(l,d)=>this._confirmDate(l,d),o.setupFormValue();this._build(),this._setRangeAria(),this._syncRangeFields(),this._bindRange(),this._syncCalendarOptions();let s=this._adapter(),i=c(t.value)?t.value:s.parse(t.value),n=c(e.value)?e.value:s.parse(e.value),r=t.value,a=e.value;this._setRange(i||"",n||"",{emit:!1});for(let[o,l,d]of[[t,r,i],[e,a,n]]){if(!l.trim()||c(d))continue;o.value=l,o.setCustomValidity(this.messages.invalidDate)}if(this._fields[0].hidden)this._fields[0].hidden.defaultValue=this._range.start;if(this._fields[1].hidden)this._fields[1].hidden.defaultValue=this._range.end;for(let o of this._fields)o.adoptDefault()}disconnectedCallback(){if(this._stopDefaultMessages?.(),this._stopDefaultMessages=null,this._connected=!1,this.hide(!1),this._controller?.abort(),this._controller=null,this._clearTimeOrderValidity(),this._timeFields=[null,null],this._rangeMode()){for(let t of this._fields||[])this._teardownField(t);this._fields=null,this._range=null}else this._teardownField(this._field);this._field=null;for(let{button:t}of this._buttons)t.remove();this._buttons=[],this._returnFocus=null,this._panel?.remove(),this._formatHint?.remove(),this._panel=null,this._calendar=null,this._formatHint=null}_teardownField(t){if(!t)return;let e=t.input,s=this._fields?.includes(t)?this._rangeOriginalDescribedBy[this._fields?.indexOf(t)??0]||"":this._originalDescribedBy;if(t.teardown(),s)e.setAttribute("aria-describedby",s);else e.removeAttribute("aria-describedby");e.removeAttribute("role"),e.removeAttribute("aria-haspopup"),e.removeAttribute("aria-expanded"),e.removeAttribute("aria-controls")}attributeChangedCallback(t,e,s){if(!this._connected||this._reflecting||e===s)return;if(t==="value"){if(this._rangeMode())return;if(!s||c(s))this._supersedeActivations(),this._setValue(s||"",{emit:!1,format:!0,reflect:!1});return}if(t==="locale")this._refreshLocale();if(t==="open-on-focus")return;this._syncCalendarOptions(),this.validate()}get input(){return this._rangeMode()?void 0:this._input}get calendar(){return this._calendar}get value(){return this._rangeMode()?void 0:this._value}set value(t){if(this._rangeMode())throw TypeError("value is not available in range mode; use range");if(t&&!c(t))throw TypeError(`Invalid date-picker value: ${t}`);this._supersedeActivations(),this._setValue(t||"",{emit:!1,format:!0})}get range(){return this._rangeMode()&&this._range?{...this._range.range}:void 0}set range(t){if(!this._rangeMode())throw TypeError("range is only available on <date-picker range>");let{start:e,end:s}=mt(t);this._supersedeActivations(),this._setRange(e,s)}get locale(){return P(this.getAttribute("locale")||"")}set locale(t){if(t)this.setAttribute("locale",t);else this.removeAttribute("locale")}get monthFormat(){return this.getAttribute("month-format")==="short"?"short":"long"}set monthFormat(t){if(t==="short")this.setAttribute("month-format","short");else this.removeAttribute("month-format")}get min(){let t=this.getAttribute("min")||"";return c(t)?t:""}set min(t){if(t)this.setAttribute("min",t);else this.removeAttribute("min")}get max(){let t=this.getAttribute("max")||"";return c(t)?t:""}set max(t){if(t)this.setAttribute("max",t);else this.removeAttribute("max")}get openOnFocus(){return this.getAttribute("open-on-focus")!=="false"}set openOnFocus(t){if(t===!1)this.setAttribute("open-on-focus","false");else this.removeAttribute("open-on-focus")}get open(){return this._open}get controlClasses(){return at(this._controlClasses)}set controlClasses(t){if(this._controlClasses=rt(t),this._calendar)this._calendar.controlClasses=this._controlClasses}get messages(){return this._messages??U()}set messages(t){if(this._messages=t==null?null:{...U(),...t},this._calendar)this._calendar.messages=this._messages;this._refreshMessages()}_refreshMessages(){let t=this.messages;for(let s of this._fields||[])s.setMessages(t);this._field?.setMessages(t),this._panel?.setAttribute("aria-label",t.calendar);let e=this._field??this._fields?.[0];if(this._formatHint&&e)this._formatHint.textContent=`${t.formatHint}: ${e.placeholder}`;if(this._refreshButtonLabel(),this._connected)this.validate()}get source(){return this._source}set source(t){if(this._source=t||null,this._calendar)this._calendar.source=this._source;if(this._connected)this.validate()}get dateState(){return this._dateState}set dateState(t){if(this._dateState=typeof t==="function"?t:null,this._calendar)this._calendar.dateState=this._dateState;if(this._connected)this.validate()}get renderDay(){return this._renderDay}set renderDay(t){if(this._renderDay=typeof t==="function"?t:null,this._calendar)this._calendar.renderDay=this._renderDay}get isDateDisabled(){return this._isDateDisabled}set isDateDisabled(t){if(this._isDateDisabled=typeof t==="function"?t:null,this._calendar)this._calendar.isDateDisabled=this._isDateDisabled;if(this._connected)this.validate()}get coordinateSpace(){return this._coordinateSpace}set coordinateSpace(t){this._coordinateSpace=t==="document"?"document":"viewport"}_adapter(){return this._field?.adapter??this._fields?.[0]?.adapter??lt(this.locale)}_setupFormValue(){this._field?.setupFormValue()}_syncInputState(){let t=this._input;if(!t)return;this._field?.syncInputState();let e=this._buttons[0]?.button;if(e)e.disabled=t.disabled||t.readOnly;if(this._open&&!H(t))this.hide(!1)}_syncRangeFields(){if(!this._fields)return;for(let s of this._fields)s.syncInputState();for(let{button:s,endpoint:i}of this._buttons){let n=i==="end"?1:0,r=this._fields[n];s.disabled=Boolean(r?.input.disabled||r?.input.readOnly)}this._syncDragAffordance();let t=this._range?.activeEndpoint==="end"?1:0,e=this._fields[t]?.input;if(this._open&&e&&!H(e))this.hide(!1)}_setRangeAria(){if(!this._fields||!this._panel||!this._formatHint)return;for(let t of this._fields){let e=t.input,s=[this._rangeOriginalDescribedBy[this._fields.indexOf(t)],this._formatHint.id].filter(Boolean).join(" ");e.setAttribute("aria-describedby",s),e.setAttribute("role","combobox"),e.setAttribute("aria-haspopup","dialog"),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-controls",this._panel.id)}}_createTrigger(t){let e=document.createElement("button");if(e.type="button",e.className="dp-picker-button",e.setAttribute("aria-haspopup","dialog"),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-controls",`${this._id}-panel`),t)e.dataset.endpoint=t;return e.innerHTML='<span aria-hidden="true"><svg viewBox="0 0 16 16" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><rect x="1.75" y="3" width="12.5" height="11" rx="1.75"/><path d="M1.75 6.75h12.5"/><path d="M5.25 1.75v2.5M10.75 1.75v2.5"/></svg></span>',e}_build(){let t=this._rangeMode(),e=[];if(t)for(let[o,l]of(this._fields||[]).entries())e.push([l.input,o===1?"end":"start"]);else if(this._input)e.push([this._input,""]);if(!e.length)return;let s=`${this._id}-panel`,i=`${this._id}-format`;this._buttons=e.map(([o,l])=>{let d=this._createTrigger(l);return o.insertAdjacentElement("afterend",d),{button:d,endpoint:l}});let n=document.createElement("div");n.id=s,n.className="dp-picker-panel",n.setAttribute("popover","manual"),n.setAttribute("role","dialog"),n.setAttribute("aria-label",this.messages.calendar);let r=new dt;r.selection="none",r.fixedWeeks=!0,n.append(r);let a=document.createElement("span");if(a.id=i,a.className="dp-visually-hidden",this.append(n,a),this._panel=n,this._calendar=r,this._formatHint=a,!t&&this._input){this._originalDescribedBy=this._input.getAttribute("aria-describedby")||"";let o=[this._originalDescribedBy,i].filter(Boolean).join(" ");this._input.setAttribute("aria-describedby",o),this._input.setAttribute("role","combobox"),this._input.setAttribute("aria-haspopup","dialog"),this._input.setAttribute("aria-expanded","false"),this._input.setAttribute("aria-controls",s)}this._refreshLocale(),this._refreshButtonLabel()}_bindPopup(t,e,s){this.ownerDocument.addEventListener("pointerdown",(i)=>{if(!this._open||i.composedPath().includes(this))return;this.hide(!1)},{capture:!0,signal:t}),this.ownerDocument.addEventListener("reset",(i)=>{if(!(i.target instanceof HTMLFormElement)||!e||i.target!==e.form)return;this.hide(!1),queueMicrotask(()=>{if(!i.defaultPrevented)s()})},{capture:!0,signal:t}),this.addEventListener("keydown",(i)=>this._onEscape(i),{signal:t})}_bind(){let t=this._input,e=this._buttons[0]?.button,s=this._calendar;if(!t||!e||!s)return;let i=new AbortController;this._controller=i;let{signal:n}=i;t.addEventListener("input",()=>{this._field?.handleInput()},{signal:n}),t.addEventListener("change",()=>void this._commitText(!1),{signal:n}),t.addEventListener("blur",()=>void this._commitText(!1),{signal:n}),t.addEventListener("focus",(r)=>{if(!this.openOnFocus||this._suppressFocusOpen)return;let a=r.relatedTarget;if(a instanceof Node&&this.contains(a))return;if(!this._open)this.show({moveFocus:!1})},{signal:n}),t.addEventListener("keydown",(r)=>{this._onFieldKeyDown("",r)},{signal:n});for(let[r,a]of this._timeFields.entries()){if(!a)continue;let o=r===1?"end":"start";a.addEventListener("input",()=>this._revalidateTimeOrder(o),{signal:n}),a.addEventListener("change",()=>this._revalidateTimeOrder(o),{signal:n})}e.addEventListener("click",(r)=>{if(this._open){if(r.detail===0){setTimeout(()=>this._calendar?.focusGrid(),0);return}this.hide(!1);return}this.show({returnFocus:e})},{signal:n}),e.addEventListener("keydown",(r)=>this._onTriggerKeyDown("",r),{signal:n}),s.addEventListener("click",(r)=>this._captureGridIntent(r),{capture:!0,signal:n}),s.addEventListener("keydown",(r)=>this._captureGridIntent(r),{capture:!0,signal:n}),s.addEventListener("dateactivate",(r)=>{let a=r,o=a.detail?.date;if(!c(o))return;let l=tt.get(a);queueMicrotask(()=>{if(a.defaultPrevented||!this._connected)return;if(l&&l.id!==this._activationId)return;if(!this._input||!H(this._input))return;this._field?.dirty(),this._setValue(o,{emit:!0,format:!0}),this.hide(!1),this._restoreFocus()})},{signal:n}),s.addEventListener("dateloadend",()=>void this.validate(),{signal:n}),this._bindPopup(n,this._input,()=>this._restoreDefault())}_bindRange(){let t=this._calendar;if(!this._fields||!this._buttons.length||!t)return;let e=new AbortController;this._controller=e;let{signal:s}=e;for(let[i,n]of this._fields.entries()){let r=i===1?"end":"start";n.input.addEventListener("input",()=>{if(n.handleInput(),this._orderTags.delete(i),!n.isDirty)this._revalidateRange(r)},{signal:s}),n.input.addEventListener("change",()=>void this._commitFieldText(r),{signal:s}),n.input.addEventListener("blur",()=>void this._commitFieldText(r),{signal:s}),n.input.addEventListener("focus",(a)=>this._onFieldFocus(r,a),{signal:s}),n.input.addEventListener("keydown",(a)=>this._onFieldKeyDown(r,a),{signal:s})}for(let i of this._buttons){let n=i.endpoint;if(n==="")continue;i.button.addEventListener("click",(r)=>this._onRangeTriggerClick(n,r),{signal:s}),i.button.addEventListener("keydown",(r)=>this._onTriggerKeyDown(n,r),{signal:s})}t.addEventListener("click",(i)=>{if(this._suppressGridClick){this._suppressGridClick=!1,i.preventDefault(),i.stopImmediatePropagation();return}this._captureGridIntent(i)},{capture:!0,signal:s}),t.addEventListener("keydown",(i)=>this._captureGridIntent(i),{capture:!0,signal:s}),t.addEventListener("dateactivate",(i)=>{let n=i,r=n.detail?.date;if(!c(r))return;queueMicrotask(()=>{if(n.defaultPrevented||!this._connected||!this._range)return;let a=tt.get(n);if(a===void 0||a.id!==this._activationId)return;let o=(d)=>this._boundEditable(d),l=a.endpoint?this._range.moveEndpoint(r,a.endpoint,o):this._range.activate(r,o);if(l.status==="refused"){this._calendar?.dispatchEvent(new CustomEvent("dateinvalid",{detail:{date:r,state:this._calendar.getDateState(r)},bubbles:!0}));return}if(this._applyRangeTransition(l),a.endpoint)return;if(l.close||l.status==="complete")this.hide(!1),this._focusField(l.endpoint)})},{signal:s}),t.addEventListener("datefocus",(i)=>this._onGridDateFocus(i),{signal:s}),t.addEventListener("pointerover",(i)=>this._onGridPointerOver(i),{signal:s}),t.addEventListener("pointerleave",()=>this._onGridPointerLeave(),{signal:s}),t.addEventListener("pointerdown",(i)=>this._onGridPointerDown(i),{signal:s}),t.addEventListener("pointermove",(i)=>this._onGridPointerMove(i),{signal:s}),t.addEventListener("pointerup",(i)=>this._onGridPointerUp(i),{signal:s}),t.addEventListener("pointercancel",(i)=>this._onGridPointerCancel(i),{signal:s}),t.addEventListener("lostpointercapture",(i)=>this._onGridPointerCancel(i),{signal:s}),t.addEventListener("dateloadend",()=>void this.validate(),{signal:s}),this._bindPopup(s,this._fields?.[0]?.input,()=>this._restoreRangeDefault())}_activateRangeEndpoint(t){let e=this._calendar;if(!this._range||!e)return;this._range.focus(t),this._activationId++,this._lastFocusEndpoint=t;let s=this._boundCanonical(t)||O();e.display=f(s),e.focusedDate=s,this._clearPreview()}_onRangeTriggerClick(t,e){if(!this._open){this.show({endpoint:t});return}if(e.detail===0){this._activateRangeEndpoint(t),setTimeout(()=>this._calendar?.focusGrid(),0);return}if(t!==this._range?.activeEndpoint){this._activateRangeEndpoint(t);return}this.hide(!1)}_onTriggerKeyDown(t,e){if(e.key!=="ArrowDown")return;if(e.preventDefault(),this._open){if(this._rangeMode()&&t)this._activateRangeEndpoint(t);setTimeout(()=>this._calendar?.focusGrid(),0);return}if(this._rangeMode())this.show({endpoint:t||void 0});else this.show({returnFocus:this._buttons[0]?.button})}_onFieldKeyDown(t,e){if(e.key==="ArrowDown"){if(e.preventDefault(),this._rangeMode()&&t)this._lastFocusEndpoint=t,this._range?.focus(t);if(this._open)setTimeout(()=>this._calendar?.focusGrid(),0);else this.show()}else if(e.key==="Escape"&&this._open)e.preventDefault(),this.hide(!1)}_onFieldFocus(t,e){if(!this._rangeMode()||!t)return;let s=t!==this._range?.activeEndpoint;if(this._lastFocusEndpoint=t,this._range?.focus(t),s)this._activationId++;if(!this.openOnFocus||this._suppressFocusOpen)return;let i=e.relatedTarget;if(i instanceof Node&&this.contains(i))return;if(!this._open)this.show({moveFocus:!1})}_captureGridIntent(t){if(this._rangeMode()?!this._range:!this._field)return;if(t.type==="keydown"){let i=t.key;if(i!=="Enter"&&i!==" ")return}if(t.type==="click"&&this._suppressGridClick)return;if(!(t.target instanceof Element))return;let s=t.target.closest(".dp-day[data-date]")?.getAttribute("data-date")||"";if(!c(s))return;this._attachIntent(s,"")}_attachIntent(t,e){if(!this._calendar)return;this._calendar._hostIntent={date:t,intent:{id:++this._activationId,endpoint:e}}}_supersedeActivations(){this._activationId++}_boundEditable(t){let e=this._fields?.[t==="end"?1:0];return e!=null&&H(e.input)}_applyRangeTransition(t){let e=this._fields;if(!e||!this._range||t.status==="refused")return;let s=[];for(let i of t.changedEndpoints){let n=e[i==="end"?1:0],r=i==="end"?t.range.end:t.range.start;if(!n||n.canonical===r)continue;n.setCanonical(r,{format:!0}),s.push(n)}if(this._syncHighlight(),this._refreshRangeButtonLabel(),this._revalidateRange(t.endpoint),!s.length)return;this._emitRangeChange();for(let i of s)i.input.dispatchEvent(new Event("input",{bubbles:!0})),i.input.dispatchEvent(new Event("change",{bubbles:!0}))}_setPreview(t,e=""){let s=this._calendar;if(!s||!this._range||!this._open)return;let i=c(t)&&!s.getDateState(t).disabled?t:"",n=i?this._range.previewRange(i,e,(r)=>this._boundEditable(r)):null;if(!n){this._clearPreview();return}this._previewDate=i,s.toggleAttribute("data-range-preview",!0),s.highlightedRange=n}_clearPreview(){if(!this._previewDate)return;this._syncHighlight()}_onGridDateFocus(t){if(this._drag)return;let e=t.detail?.date;if(c(e))this._setPreview(e)}_onGridPointerOver(t){let e=t;if(this._drag||e.pointerType==="touch")return;this._setPreview(this._cellDate(e.target))}_onGridPointerLeave(){if(this._drag?.active===!1)this._drag=null;if(this._drag)return;this._clearPreview()}_cellDate(t){let s=(t instanceof Element?t.closest(".dp-day[data-date]"):null)?.getAttribute("data-date")||"";return c(s)?s:""}_dateAtPoint(t,e){let s=this.ownerDocument.elementFromPoint(t,e);if(!(s instanceof Element)||!this._calendar?.contains(s))return"";return this._cellDate(s)}_onGridPointerDown(t){let e=t;if(this._suppressGridClick=!1,this._drag?.active===!1)this._drag=null;if(!this._open||!this._range||this._drag)return;if(!e.isPrimary||e.button!==0)return;if(e.pointerType!=="mouse"&&e.pointerType!=="pen")return;if(!this._range.complete)return;let s=e.target instanceof Element?e.target.closest(".dp-day[data-date]"):null;if(!(s instanceof HTMLElement))return;let i=s.hasAttribute("data-range-start"),n=s.hasAttribute("data-range-end");if(i===n)return;let r=i?"start":"end",a=this._cellDate(s);if(!a||!this._boundEditable(r))return;this._drag={pointerId:e.pointerId,endpoint:r,x:e.clientX,y:e.clientY,date:a,active:!1}}_onGridPointerMove(t){let e=t,s=this._drag;if(!s||e.pointerId!==s.pointerId)return;if(!s.active){if(!(Math.abs(e.clientX-s.x)>ce||Math.abs(e.clientY-s.y)>ce))return;s.active=!0;try{this._calendar?.setPointerCapture(s.pointerId)}catch{}this._syncDragAffordance()}let i=this._dateAtPoint(e.clientX,e.clientY);if(!i||this._calendar?.getDateState(i).disabled)return;s.date=i,this._setPreview(i,s.endpoint)}_onGridPointerUp(t){let e=t,s=this._drag;if(!s||e.pointerId!==s.pointerId)return;if(this._drag=null,this._releaseDragCapture(s.pointerId),!s.active){this._syncDragAffordance();return}this._suppressGridClick=!0;let i=this._range?.projectEndpoint(s.date,s.endpoint,(r)=>this._boundEditable(r));if(!i||i.status==="refused"||!i.changedEndpoints.length){this._syncHighlight();return}let n=s.endpoint==="start"?i.range.start:i.range.end;this._attachIntent(n,s.endpoint),this._calendar?.activateDate(n)}_onGridPointerCancel(t){let e=t,s=this._drag;if(!s||e.pointerId!==s.pointerId)return;this._drag=null,this._releaseDragCapture(s.pointerId),this._syncHighlight()}_releaseDragCapture(t){let e=this._calendar;if(e?.hasPointerCapture(t))e.releasePointerCapture(t)}_syncDragAffordance(){let t=this._calendar;if(!t||!this._range)return;if(this._drag?.active){t.setAttribute("data-range-drag","active");return}let{start:e,end:s}=this._range;if(this._range.complete&&e!==s&&(this._boundEditable("start")||this._boundEditable("end")))t.setAttribute("data-range-drag","ready");else t.removeAttribute("data-range-drag")}_onEscape(t){if(t.key==="Escape"&&this._open)t.preventDefault(),t.stopPropagation(),this.hide(!0)}_syncCalendarOptions(){let t=this._calendar,e=this._panel;if(!t)return;if(t.locale=this.locale,t.min=this.min,t.max=this.max,t.monthFormat=this.monthFormat,t.controlClasses=this._controlClasses,t.messages=this._messages,t.source=this._source,t.dateState=this._dateState,t.renderDay=this._renderDay,t.isDateDisabled=this._isDateDisabled,!this._rangeMode()&&this._value)t.value=this._value;if(e)e.setAttribute("aria-label",this.messages.calendar)}_refreshLocale(){let t=this._formatHint;if(!t)return;if(this._rangeMode()&&this._fields){this._fields[0].setLocale(this.locale),this._fields[1].setLocale(this.locale),t.textContent=`${this.messages.formatHint}: ${this._fields[0].placeholder}`;for(let[s,i]of this._fields.entries()){if(!i.input.hasAttribute("placeholder")||this._generatedPlaceholder)i.input.placeholder=i.placeholder,this._generatedPlaceholder=!0;let n=s===1?this._range?.end||"":this._range?.start||"";if(n)i.input.value=i.format(n)}this._refreshButtonLabel();return}let e=this._field;if(!e)return;if(e.setLocale(this.locale),t.textContent=`${this.messages.formatHint}: ${e.placeholder}`,!e.input.hasAttribute("placeholder")||this._generatedPlaceholder)e.input.placeholder=e.placeholder,this._generatedPlaceholder=!0;if(this._value)e.input.value=e.format(this._value);this._refreshButtonLabel()}_refreshButtonLabel(){let t=this._buttons[0]?.button;if(!t)return;if(this._rangeMode()){this._refreshRangeButtonLabel();return}let e=this._value?this.messages.changeDate:this.messages.chooseDate,s=this._value?`, ${ot(this._value,this.locale)}`:"";t.setAttribute("aria-label",`${e}${s}`)}_refreshRangeButtonLabel(){if(!this._range)return;let{start:t,end:e}=this._range;for(let{button:s,endpoint:i}of this._buttons){let n=i==="end"?e:t,r=n?this.messages.changeDate:this.messages.chooseDate,a=n?`, ${ot(n,this.locale)}`:"",o=i==="end"?this.messages.rangeEnd:this.messages.rangeStart;s.setAttribute("aria-label",`${r}${a}, ${o}`)}}_reflectValue(t){if(this._reflecting=!0,t)this.setAttribute("value",t);else this.removeAttribute("value");this._reflecting=!1}_setValue(t,e={}){if(t&&!c(t))throw TypeError(`Invalid date-picker value: ${t}`);let s=this._value;if(this._value=t||"",e.reflect!==!1)this._reflectValue(this._value);if(this._field?.setCanonical(this._value,{format:e.format!==!1}),this._calendar){if(this._calendar.value=this._value,this._value&&e.moveDisplay!==!1)this._calendar.focusedDate=this._value}if(this._refreshButtonLabel(),s!==this._value){if(this.dispatchEvent(new CustomEvent("valuechange",{detail:{value:this._value},bubbles:!0})),e.emit&&this._field){let i=this._field.input;i.dispatchEvent(new Event("input",{bubbles:!0})),i.dispatchEvent(new Event("change",{bubbles:!0}))}}}async _confirmDate(t,e={}){let s=this._calendar;if(!s)return{ok:!0};if(e.moveDisplay!==!1){let r=f(t);if(s.display!==r)s.display=r}let i=await s.ensureDate(t),n=s.getDateState(t);if(!i||n.disabled)return{ok:!1,message:this.messages.unavailableDate};return{ok:!0}}async _commitText(t,e={}){let s=this._field;if(!s)return!1;if(!e.force&&!s.isDirty)return!1;let i=await s.commit(e);if(i.status==="stale"||i.status==="invalid")return!1;return this._setValue(i.value||"",{emit:t,format:i.status==="ok",moveDisplay:e.moveDisplay}),!0}async _commitFieldText(t){let e=this._fields;if(!e)return!1;let s=t==="end"?1:0,i=e[s];if(!i?.isDirty)return!1;let n=await i.commit();if(n.status==="stale")return!1;if(n.status==="invalid")return this._orderTags.delete(s),!1;return this._setBound(t,n.value||"",{emit:!1,user:!0,format:n.status==="ok"}),!0}_setBound(t,e,s={}){if(!this._range)return!1;let i=this._fields;if(!i)return!1;let r=i[t==="end"?1:0];if(!r)return!1;if(s.user===!0&&!H(r.input))return!1;let a=e||"",o=r.canonical;if(r.setCanonical(a,{format:s.format!==!1}),t==="end")this._range.end=a;else this._range.start=a;let l=o!==a;if(l){if(this._syncHighlight(),this._refreshRangeButtonLabel(),this._emitRangeChange(),s.emit)r.input.dispatchEvent(new Event("input",{bubbles:!0})),r.input.dispatchEvent(new Event("change",{bubbles:!0}))}return this._revalidateRange(t),l}_setRange(t,e,s={}){if(!this._range||!this._fields)return;if(this._range.start=t||"",this._range.end=e||"",this._fields[0].setCanonical(t||"",{format:s.format!==!1}),this._fields[1].setCanonical(e||"",{format:s.format!==!1}),this._syncHighlight(),this._refreshRangeButtonLabel(),this._revalidateRange("start"),this._revalidateRange("end"),s.emit!==!1)this._emitRangeChange()}_boundCanonical(t){return this._range?t==="end"?this._range.end:this._range.start:""}_emitRangeChange(){if(!this._range)return;this.dispatchEvent(new CustomEvent("rangechange",{detail:{...this._range.range},bubbles:!0}))}_displayRange(){let{start:t,end:e}=this._range?.range??{start:"",end:""};if(!t)return{start:"",end:""};if(e&&_(e,t)<0)return{start:t,end:""};return{start:t,end:e}}_syncHighlight(){if(!this._calendar||!this._range)return;this._previewDate="",this._calendar.removeAttribute("data-range-preview"),this._calendar.highlightedRange=this._displayRange(),this._syncDragAffordance()}_revalidateRange(t){if(!this._fields||!this._range)return;let{start:e,end:s}=this._range,i=Boolean(e&&s&&_(s,e)<0),n=["start","end"];for(let r of n){let a=r==="end"?1:0,o=this._fields[a].input,l=r==="end"?this.messages.rangeOrderEnd:this.messages.rangeOrderStart;if(i&&r===t)o.setCustomValidity(l),this._orderTags.add(a);else if(this._orderTags.has(a))o.setCustomValidity(""),this._orderTags.delete(a)}}_revalidateTimeOrder(t){let[e,s]=this._timeFields,i=["start","end"],n=[e,s],r=e&&!e.matches(":disabled")?e.value.trim():"",a=s&&!s.matches(":disabled")?s.value.trim():"",o=Boolean(e&&s&&r&&a)&&It(r)&&It(a)&&de(a,r)<0;for(let[l,d]of i.entries()){let u=n[l];if(!u)continue;let v=d==="end"?this.messages.rangeOrderEnd:this.messages.rangeOrderStart;if(o&&d===t)u.setCustomValidity(v),this._timeOrderOwned.add(u);else if(this._timeOrderOwned.has(u))u.setCustomValidity(""),this._timeOrderOwned.delete(u)}}_clearTimeOrderValidity(){for(let t of this._timeOrderOwned)t.setCustomValidity("");this._timeOrderOwned.clear()}_restoreDefault(){let t=this._field;if(!t)return;let e=t.restoreDefault();if(this._setValue(e,{emit:!1,format:!0}),this._calendar)if(this._value)this._calendar.display=f(this._value),this._calendar.focusedDate=this._value;else this._calendar.display=f(O()),this._calendar.focusedDate=O();this.validate()}_restoreRangeDefault(){if(!this._fields)return;let t=this._fields[0].restoreDefault(),e=this._fields[1].restoreDefault();if(this._setRange(t,e),this._calendar){let s=this._range?.start||O();this._calendar.display=f(s),this._calendar.focusedDate=s}this.validate()}_focusField(t){let e=t==="end"?1:0,s=this._fields?.[e]?.input;if(!s)return;this._suppressFocusOpen=!0,setTimeout(()=>{s.focus(),this._suppressFocusOpen=!1},0)}_restoreFocus(){let t=this._returnFocus;if(this._returnFocus=null,!(t instanceof HTMLElement)||!t.isConnected||t.matches(":disabled"))return;this._suppressFocusOpen=!0,setTimeout(()=>{t.focus(),this._suppressFocusOpen=!1},0)}_resolveRangeEndpoint(){if(!this._fields)return"";let t=this._lastFocusEndpoint||"start",e=t==="end"?1:0;if(H(this._fields[e].input))return t;let s=t==="end"?"start":"end",i=s==="end"?1:0;if(H(this._fields[i].input))return s;return""}async validate(){if(this._rangeMode()){let s=this._fields;if(!s)return!0;for(let[i,n]of s.entries()){let r=await n.commit({moveDisplay:!1});if(r.status==="invalid")this._orderTags.delete(i);if(r.status==="ok"||r.status==="clear"){let a=i===1?"end":"start";this._setBound(a,r.value||"",{format:r.status==="ok"})}}return this._revalidateRange("start"),this._revalidateRange("end"),s.every((i)=>i.input.checkValidity())}let t=this._field?.input;if(!t)return!0;await this._commitText(!1,{force:!0,moveDisplay:!1}),this._revalidateTimeOrder("start"),this._revalidateTimeOrder("end");let e=this._timeFields.every((s)=>s?.checkValidity()??!0);return t.checkValidity()&&e}show(t={}){let e=this._panel,s=this._calendar;if(!e||!s||!this._buttons.length||this._open)return;if(this._rangeMode()){let r=t.endpoint||this._resolveRangeEndpoint();if(!r)return;this._activateRangeEndpoint(r)}else{let r=this._input;if(!r||!H(r))return;let a=this._value||this._adapter().parse(r.value)||O();s.display=f(a),s.focusedDate=a,this._returnFocus=t.returnFocus instanceof HTMLElement?t.returnFocus:r}e.showPopover(),this._open=!0,this._setExpanded(!0);let i=this.coordinateSpace;e.style.position=i==="document"?"absolute":"fixed";let n=()=>oe(this,e,{placement:"bottom-start",distance:4,shiftPadding:8,coordinateSpace:i});if(n(),this._stopTracking=ae(this,e,n),t.moveFocus!==!1)queueMicrotask(()=>s.focusGrid());this.dispatchEvent(new Event("open",{bubbles:!0}))}_setExpanded(t){let e=t?"true":"false";this._input?.setAttribute("aria-expanded",e);for(let{button:s}of this._buttons)s.setAttribute("aria-expanded",e);for(let s of this._fields||[])s.input.setAttribute("aria-expanded",e)}hide(t=!1){if(!this._panel||!this._open)return;this._stopTracking?.(),this._stopTracking=null;try{this._panel.hidePopover()}catch{}if(this._open=!1,this._setExpanded(!1),this._supersedeActivations(),this._suppressGridClick=!1,this._drag)this._releaseDragCapture(this._drag.pointerId),this._drag=null;if(this._syncHighlight(),t)if(this._rangeMode()){let e=this._restoreFocusEndpoint();if(e)this._focusField(e)}else this._restoreFocus();this.dispatchEvent(new Event("close",{bubbles:!0}))}_restoreFocusEndpoint(){let t=this._range?.activeEndpoint||"";if(t){let e=t==="end"?1:0,s=this._fields?.[e];if(s&&H(s.input))return t}return this._resolveRangeEndpoint()}}function ue(){if(!customElements.get("date-calendar"))customElements.define("date-calendar",dt);if(!customElements.get("date-picker"))customElements.define("date-picker",Rt)}ue();})();
16
+ </div>`,this._heading.textContent=qt(`${s}-15`,e),this._rendering=!1,this._paintedRange={...this._highlightedRange},this._paintedPreview=this.hasAttribute("data-range-preview"),X)this._queueFocus(()=>{let u=X;if(u.startsWith(".dp-day[data-date="))u=`.dp-day[data-date="${CSS.escape(this._model.focused)}"]`;let f=this.querySelector(u);if(f instanceof HTMLElement)f.focus()});if(this._renderDay)for(let u of this.querySelectorAll(".dp-day[data-date]")){if(!(u instanceof HTMLTableCellElement))continue;let f=u.dataset.date||"",D=u.querySelector(".dp-day-extra");if(!(D instanceof HTMLElement))continue;let m=this._renderDay(f,this._renderedStates.get(f)||{});if(m instanceof Node)D.append(m);else if(m!==void 0&&m!==null)D.textContent=String(m)}if(t)this._loadDisplay(s)}}function bt(t){return t==="top"||t==="bottom"?"x":"y"}var ne={top:"bottom",bottom:"top",left:"right",right:"left"},Ye=new Set(Object.keys(ne).flatMap((t)=>[t,`${t}-start`,`${t}-end`])),je=new Set(["viewport","document"]);function We(t){if(!Ye.has(t))throw TypeError(`Unknown placement: ${t}`);let[e,s=null]=t.split("-");return{side:e,align:s,crossAxis:bt(e)}}function ze(t,e,s,i,n,r){let a=bt(s),o=t.x+t.width/2-e.width/2,l=t.y+t.height/2-e.height/2,d=t[a==="x"?"width":"height"]/2-e[a==="x"?"width":"height"]/2,h;switch(s){case"top":h={x:o,y:t.y-e.height-r};break;case"bottom":h={x:o,y:t.y+t.height+r};break;case"right":h={x:t.x+t.width+r,y:l};break;case"left":h={x:t.x-e.width-r,y:l};break;default:h={x:t.x,y:t.y}}if(i==="start"||i==="end"){let v=(n&&a==="x"?-1:1)*(i==="end"?1:-1);h[a]+=d*v}return h}function qe(t,e,s,i){return Math.max(s-t,0)+Math.max(t+e-i,0)}function Ke(t){let e=t.ownerDocument?.defaultView;if(e&&t instanceof e.Element)return e.getComputedStyle(t).direction==="rtl";return"dir"in t&&t.dir==="rtl"}var Xe=25;function Ze(t){let e=t.defaultView;if(!e)return null;let s=t.documentElement,i=e.visualViewport,n=i?.offsetLeft||0,r=i?.offsetTop||0,a=i?.width||s.clientWidth||e.innerWidth,o=i?.height||s.clientHeight||e.innerHeight,l=t.compatMode==="BackCompat"?a-s.clientWidth:s.clientWidth-s.getBoundingClientRect().width;if(l>0&&l<=Xe){let d=e.getComputedStyle?.(s).scrollbarGutter;if(d&&d!=="auto")a-=l}return{x:n,y:r,width:a,height:o,right:n+a,bottom:r+o}}function Je(t,e){return e.scope?e.scope.getBoundingClientRect():Ze(t.ownerDocument)}function Qt(t,e,s,i,n){let r=s+n,a=i-e-n,o=a>=r,l=o?r:s,d=o?a:i-e;return Math.max(l,Math.min(t,d))}function te(t,e,s){if(!s)return 50;let i=(t-e)/s*100;return Math.round(Math.min(100,Math.max(0,i))*1000)/1000}function Qe(t,e){for(let s=0;s<t.length;s++){let i=t[s];if(i.right>=e.x&&i.left<=e.right&&i.bottom>=e.y&&i.top<=e.bottom)return!1}return!0}function ts(t,e,s,i,n){if(e==="top")return Math.max(0,t.top-s.y-i-n);if(e==="bottom")return Math.max(0,s.bottom-t.bottom-i-n);return Math.max(0,s.height-n*2)}function es(t){if(t.hidden)return!1;if(typeof t.checkVisibility==="function")return t.checkVisibility();return t.getClientRects().length>0}function re(t){let{offsetWidth:e,offsetHeight:s}=t;if(e&&s)return{width:e,height:s};let i=t.getBoundingClientRect();return{width:e||i.width,height:s||i.height}}var ee=new WeakMap,se={scroll:0,resize:1,"element-resize":2};function ss(t){let e=t.defaultView;if(!e)throw TypeError("floating must belong to a document with a browsing context");let s=new Set,i=new Map,n=e.ResizeObserver,r=!1,a=!1,o=e.visualViewport;function l(y,b){let C=i.get(y);if(C===void 0||se[b]>se[C])i.set(y,b)}function d(){if(r)return;r=!0,e.requestAnimationFrame(()=>{let y=[...i];i.clear(),r=!1;for(let[b,C]of y){if(!s.has(b)||!b.floating.isConnected)continue;try{b.callback({type:C})}catch(A){h(A)}}})}function h(y){if(typeof e.reportError==="function")e.reportError(y);else e.setTimeout(()=>{throw y})}function v(y){for(let b of s)l(b,y);d()}function w(y){if(!n)return null;let b=new Set,C=new n((B)=>{let L=!1;for(let Y of B)if(b.has(Y.target))L=!0;else b.add(Y.target);if(!L)return;l(y,"element-resize"),d()}),{reference:A,floating:x}=y;if(A)C.observe(A);if(x!==A)C.observe(x);return C}let E=()=>v("scroll"),k=()=>v("resize");function M(){if(a)return;t.addEventListener("scroll",E,{passive:!0,capture:!0}),e.addEventListener("resize",k,{passive:!0}),o?.addEventListener("scroll",E,{passive:!0}),o?.addEventListener("resize",k,{passive:!0}),a=!0}function T(){if(!a)return;t.removeEventListener("scroll",E,{capture:!0}),e.removeEventListener("resize",k),o?.removeEventListener("scroll",E),o?.removeEventListener("resize",k),a=!1}return{add(y,b,C){let A={reference:y,floating:b,callback:C};s.add(A),M();let x=w(A),B=!1;return()=>{if(B)return;if(B=!0,s.delete(A),i.delete(A),x?.disconnect(),s.size===0)T()}}}}function is(t){let e=t.ownerDocument,s=ee.get(e);if(!s)s=ss(e),ee.set(e,s);return s}function ae(t,e,s){if(!e?.ownerDocument)throw TypeError("autoUpdate() expects a floating HTMLElement");if(t&&t.ownerDocument!==e.ownerDocument)throw TypeError("reference and floating must belong to the same document");if(typeof s!=="function")throw TypeError("callback must be a function");return is(e).add(t,e,s)}function ie(t,e,s){let i=s.placement===void 0?"bottom-start":s.placement,{side:n,align:r,crossAxis:a}=We(i),o=s.coordinateSpace===void 0?"viewport":s.coordinateSpace;if(!je.has(o))throw TypeError(`Unknown coordinateSpace: ${o}`);if(!es(e))return null;let l=s.distance||0,d=s.flip!==!1,h=s.shift!==!1,v=s.shiftPadding??4,w=r?Ke(t):!1,E=t.getClientRects();if(!E.length)return null;let k=(g)=>g==="bottom"?E[E.length-1]:E[0],M=Je(t,s);if(!M||Qe(E,M))return null;let T=re(e),y={x:{size:T.width,start:M.x,end:M.right},y:{size:T.height,start:M.y,end:M.bottom}},b=(g,u)=>ze(k(g),T,g,u,w,l),C=(g,u)=>{let{size:f,start:D,end:m}=y[u];return qe(g,f,D+v,m-v)},A=(g,u)=>{let{size:f,start:D,end:m}=y[u];return C(h?Qt(g,f,D,m,v):g,u)},x=b(n,r),B=(g,u)=>{let f=bt(g),D=f==="x"?"y":"x",m=C(u[D],D);return{main:m,total:m+A(u[f],f)}};if(d){let g=B(n,x),u=(f)=>{let D=b(f,r),m=B(f,D);if(m.total<g.total)n=f,x=D,g=m};if(g.main>0)u(ne[n]);if(a==="y"&&g.main>0)u("top"),u("bottom");a=bt(n)}if(a==="x"&&h&&r){let g=C(x.x,"x");if(g>0){let u=r==="end"?"start":"end",f=b(n,u);if(C(f.x,"x")<g)r=u,x=f}}if(h){let{size:g,start:u,end:f}=y[a];x[a]=Qt(x[a],g,u,f,v)}let L=k(n),Y=te(L.x+L.width/2,x.x,T.width),K=te(L.y+L.height/2,x.y,T.height),X=`${ts(L,n,M,l,v)}px`,{style:R}=e,Z=R.getPropertyValue("--available-height")!==X,j=o==="document"?t.ownerDocument.defaultView:null,Dt=j?j.scrollX:0,ut=j?j.scrollY:0;R.left=`${x.x+Dt}px`,R.top=`${x.y+ut}px`,R.setProperty("--arrow-x",`${Y}%`),R.setProperty("--arrow-y",`${K}%`),R.setProperty("--available-height",X);let J=r?`${n}-${r}`:n;return e.dataset.placement=J,{width:T.width,height:T.height,roomChanged:Z,placement:J}}function oe(t,e,s={}){let i=ie(t,e,s);if(!i)return!1;if(i.roomChanged){let n=re(e);if(n.width!==i.width||n.height!==i.height)ie(t,e,{...s,placement:i.placement,flip:!1})}return!0}function H(t){return!t.matches(":disabled")&&!t.readOnly}class ct{constructor(t,e={}){this.input=t,this.messages=e.messages||{},this.adapter=lt(e.locale||""),this.hidden=null,this.canonical="",this._dirty=!1,this._commitId=0,this._disposed=!1,this._originalName=t.getAttribute("name")||"",this._attributeObserver=null,this.onAttributesChanged=null,this.confirm=null,this._generatedDefault=null}setLocale(t){let e=this._generatedDefault,s=e?this.adapter.format(e):null;if(this.adapter=lt(t||""),e&&this.input.defaultValue===s)this.input.defaultValue=this.adapter.format(e)}adoptDefault(){let t=this.input;if(t.getAttribute("value")!=null||t.defaultValue!=="")return;t.defaultValue=t.value,this._generatedDefault=this.canonical&&t.value?this.canonical:null}setMessages(t){this.messages=t||{}}format(t){return this.adapter.format(t)}parse(t){return this.adapter.parse(t)}get placeholder(){return this.adapter.placeholder}get isDisabled(){return this.input.matches(":disabled")}get isReadOnly(){return this.input.readOnly}setupFormValue(){let t=this.input;this._originalName=t.getAttribute("name")||"",this._attributeObserver=new MutationObserver(()=>this.onAttributesChanged?.()),this._attributeObserver.observe(t,{attributes:!0,attributeFilter:["disabled","readonly","name","form"]}),this.syncInputState()}syncInputState(){let t=this.input,e=t.getAttribute("name")||"";if(e){if(!this.hidden){let s=document.createElement("input");s.type="hidden",s.value=this.canonical,t.insertAdjacentElement("afterend",s),this.hidden=s}if(this.hidden)this.hidden.name=e;t.removeAttribute("name")}if(this.hidden){if(t.hasAttribute("form"))this.hidden.setAttribute("form",t.getAttribute("form")||"");else this.hidden.removeAttribute("form");this.hidden.disabled=t.disabled}}dirty(){this._commitId++}get isDirty(){return this._dirty}handleInput(){let t=this.input,e=t.value.trim(),s=this.canonical?this.adapter.format(this.canonical):"";if(this.dirty(),e===s){if(this._dirty=!1,this.hidden)this.hidden.value=this.canonical;t.setCustomValidity("");return}if(this._dirty=!0,this.hidden)this.hidden.value="";if(!e){t.setCustomValidity("");return}t.setCustomValidity(this.messages.invalidDate)}async commit(t={}){let e=this.input,s=++this._commitId;if(this._disposed)return{status:"stale",commitId:s};let i=e.value.trim();if(!i){if(s!==this._commitId)return{status:"stale",commitId:s};return e.setCustomValidity(""),{status:"clear",value:"",commitId:s}}let n=this.adapter.parse(i);if(!n){if(s!==this._commitId)return{status:"stale",commitId:s};if(this.hidden)this.hidden.value="";return e.setCustomValidity(this.messages.invalidDate),{status:"invalid",commitId:s}}if(this.confirm){let r=await this.confirm(n,t);if(this._disposed||s!==this._commitId)return{status:"stale",commitId:s};if(!r?.ok){if(this.hidden)this.hidden.value="";return e.setCustomValidity(r?.message||this.messages.unavailableDate),{status:"invalid",commitId:s}}}return{status:"ok",value:n,commitId:s}}isCommitCurrent(t){return t===this._commitId}setCanonical(t,e={}){let s=t||"";if(s&&!c(s))throw TypeError(`Invalid date-picker value: ${s}`);if(this.dirty(),this.canonical=s,this._dirty=!1,this.hidden)this.hidden.value=s;if(e.format!==!1)this.input.value=s?this.adapter.format(s):"";this.input.setCustomValidity("")}restoreDefault(){let t=String(this.input.defaultValue??"").trim(),e=c(t)?t:this.adapter.parse(t);return e&&c(e)?e:""}teardown(){this.dirty(),this._disposed=!0,this._attributeObserver?.disconnect(),this._attributeObserver=null;let t=this.hidden?.getAttribute("name")||this._originalName;if(t)this.input.setAttribute("name",t);this.hidden?.remove(),this.hidden=null}}var ns=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?$/;function Ft(t){let e=ns.exec(String(t||""));if(!e)return null;let s=Number(e[1]),i=Number(e[2]),n=e[3]===void 0?0:Number(e[3]),r=e[4]===void 0?0:Number(e[4].padEnd(3,"0"));if(s>23||i>59||n>59||r>999)return null;return{hour:s,minute:i,second:n,millisecond:r}}function Lt(t){return Ft(t)!==null}function le(t){return((t.hour*60+t.minute)*60+t.second)*1000+t.millisecond}function de(t,e){let s=Ft(t),i=Ft(e);if(!s||!i)throw TypeError("compareTimes() expects HH:MM values");let n=le(s)-le(i);return n===0?0:n<0?-1:1}var rs=0,ce=4;class Rt extends HTMLElement{static observedAttributes=["value","locale","min","max","open-on-focus","month-format"];static setDefaultControlClasses(t){pt(t)}static getDefaultControlClasses(){return nt()}static setDefaultMessages(t){gt(t)}static getDefaultMessages(){return U()}constructor(){super();this._id=`date-picker-${++rs}`,this._connected=!1,this._reflecting=!1,this._value="",this._input=null,this._field=null,this._fields=null,this._range=null,this._orderTags=new Set,this._timeFields=[null,null],this._timeOrderOwned=new Set,this._lastFocusEndpoint="",this._activationId=0,this._previewDate="",this._drag=null,this._suppressGridClick=!1,this._buttons=[],this._returnFocus=null,this._panel=null,this._calendar=null,this._originalDescribedBy="",this._rangeOriginalDescribedBy=["",""],this._formatHint=null,this._generatedPlaceholders=new WeakSet,this._controller=null,this._stopTracking=null,this._open=!1,this._suppressFocusOpen=!1,this._messages=null,this._controlClasses=null,this._stopDefaultMessages=null,this._source=null,this._dateState=null,this._renderDay=null,this._isDateDisabled=null,this._coordinateSpace="viewport"}_rangeMode(){return this.hasAttribute("range")&&Boolean(this._range)}_ownsField(t){return this._connected&&(t===this._field||Boolean(this._fields?.includes(t)))}connectedCallback(){if(this._connected)return;if(q(this,["locale","min","max","monthFormat","openOnFocus","coordinateSpace","controlClasses","messages","source","dateState","renderDay","isDateDisabled"]),this.hasAttribute("range"))this._connectRange();else this._connectSingle();if(this._connected)q(this,["value","range"]),this._stopDefaultMessages=yt(()=>{if(this._messages===null)this._refreshMessages()}),this.validate()}_connectSingle(){let t=this.querySelector(":scope > input:not([type=hidden]):not([type=time]):not([data-time-start]):not([data-time-end])");if(!(t instanceof HTMLInputElement)){console.warn("<date-picker> expects a direct child text input");return}this._connected=!0,this._input=t,this._discoverTimeFields(),this._field=new ct(t,{messages:this.messages,locale:this.locale}),this._field.onAttributesChanged=()=>this._syncInputState(),this._field.confirm=(i,n)=>this._confirmDate(i,n),this._setupFormValue(),this._build(),this._syncInputState(),this._bind(),this._syncCalendarOptions();let e=this._adapter(),s=this.getAttribute("value")||(c(t.value)?t.value:e.parse(t.value));if(s&&c(s))this._setValue(s,{emit:!1,format:!0});else if(!t.value)this._setValue("",{emit:!1,format:!1});else t.setCustomValidity(this.messages.invalidDate);if(this._field.hidden)this._field.hidden.defaultValue=this._value;this._field.adoptDefault()}_discoverTimeFields(){this._timeFields=[null,null];let t=["data-time-start","data-time-end"];for(let[e,s]of t.entries()){let i=this.querySelectorAll(`:scope > input[${s}]`);if(i.length>1)console.warn(`<date-picker> expects at most one direct child input[${s}]; ignoring extras`);let n=i[0];if(n==null)continue;if(!(n instanceof HTMLInputElement)||n.type!=="time"){console.warn(`<date-picker> input[${s}] must be an <input type="time">; ignoring it`);continue}this._timeFields[e]=n}if(this.querySelector(":scope > input[type=time]:not([data-time-start]):not([data-time-end])"))console.warn("<date-picker> time inputs need [data-time-start] or [data-time-end]; ignoring it")}_connectRange(){if(this.querySelector(":scope > input[data-time-start], :scope > input[data-time-end]"))console.warn("<date-picker range> time companions are not supported yet; leaving them native");let t=this.querySelector(":scope > input[data-range-start]"),e=this.querySelector(":scope > input[data-range-end]");if(!(t instanceof HTMLInputElement)||!(e instanceof HTMLInputElement)){console.warn("<date-picker range> expects direct child inputs marked [data-range-start] and [data-range-end]");return}this._connected=!0,this._input=null,this._fields=[new ct(t,{messages:this.messages,locale:this.locale}),new ct(e,{messages:this.messages,locale:this.locale})],this._range=new Mt,this._rangeOriginalDescribedBy=[t.getAttribute("aria-describedby")||"",e.getAttribute("aria-describedby")||""];for(let o of this._fields)o.onAttributesChanged=()=>this._syncRangeFields(),o.confirm=(l,d)=>this._confirmDate(l,d),o.setupFormValue();this._build(),this._setRangeAria(),this._syncRangeFields(),this._bindRange(),this._syncCalendarOptions();let s=this._adapter(),i=c(t.value)?t.value:s.parse(t.value),n=c(e.value)?e.value:s.parse(e.value),r=t.value,a=e.value;this._setRange(i||"",n||"",{emit:!1});for(let[o,l,d]of[[t,r,i],[e,a,n]]){if(!l.trim()||c(d))continue;o.value=l,o.setCustomValidity(this.messages.invalidDate)}if(this._fields[0].hidden)this._fields[0].hidden.defaultValue=this._range.start;if(this._fields[1].hidden)this._fields[1].hidden.defaultValue=this._range.end;for(let o of this._fields)o.adoptDefault()}disconnectedCallback(){if(this._stopDefaultMessages?.(),this._stopDefaultMessages=null,this._connected=!1,this._suppressFocusOpen=!1,this.hide(!1),this._controller?.abort(),this._controller=null,this._clearTimeOrderValidity(),this._timeFields=[null,null],this._rangeMode()){for(let t of this._fields||[])this._teardownField(t);this._fields=null,this._range=null}else this._teardownField(this._field);this._field=null;for(let{button:t}of this._buttons)t.remove();this._buttons=[],this._returnFocus=null,this._panel?.remove(),this._formatHint?.remove(),this._panel=null,this._calendar=null,this._formatHint=null}_teardownField(t){if(!t)return;let e=t.input,s=this._fields?.includes(t)?this._rangeOriginalDescribedBy[this._fields?.indexOf(t)??0]||"":this._originalDescribedBy;if(t.teardown(),s)e.setAttribute("aria-describedby",s);else e.removeAttribute("aria-describedby");e.removeAttribute("role"),e.removeAttribute("aria-haspopup"),e.removeAttribute("aria-expanded"),e.removeAttribute("aria-controls")}attributeChangedCallback(t,e,s){if(this._reflecting||e===s)return;if(t==="value"&&s&&!c(s)){this._reflectValue(this._value);return}if((t==="min"||t==="max")&&s&&!c(s)){if(this.removeAttribute(t),this._connected)this._syncCalendarOptions(),this.validate();return}if(!this._connected)return;if(t==="value"){if(this._rangeMode())return;if(!s||c(s))this._supersedeActivations(),this._setValue(s||"",{emit:!1,format:!0,reflect:!1});return}if(t==="locale")this._refreshLocale();if(t==="open-on-focus")return;this._syncCalendarOptions(),this.validate()}get input(){return this._rangeMode()?void 0:this._input}get calendar(){return this._calendar}get value(){return this._rangeMode()?void 0:this._value}set value(t){if(this._rangeMode())throw TypeError("value is not available in range mode; use range");if(t&&!c(t))throw TypeError(`Invalid date-picker value: ${t}`);this._supersedeActivations(),this._setValue(t||"",{emit:!1,format:!0})}get range(){return this._rangeMode()&&this._range?{...this._range.range}:void 0}set range(t){if(!this._rangeMode())throw TypeError("range is only available on <date-picker range>");let{start:e,end:s}=mt(t);this._supersedeActivations(),this._setRange(e,s)}get locale(){return P(this.getAttribute("locale")||"")}set locale(t){if(t)this.setAttribute("locale",t);else this.removeAttribute("locale")}get monthFormat(){return this.getAttribute("month-format")==="short"?"short":"long"}set monthFormat(t){if(t==="short")this.setAttribute("month-format","short");else this.removeAttribute("month-format")}get min(){let t=this.getAttribute("min")||"";return c(t)?t:""}set min(t){if(t)this.setAttribute("min",t);else this.removeAttribute("min")}get max(){let t=this.getAttribute("max")||"";return c(t)?t:""}set max(t){if(t)this.setAttribute("max",t);else this.removeAttribute("max")}get openOnFocus(){return this.getAttribute("open-on-focus")!=="false"}set openOnFocus(t){if(t===!1)this.setAttribute("open-on-focus","false");else this.removeAttribute("open-on-focus")}get open(){return this._open}get controlClasses(){return at(this._controlClasses)}set controlClasses(t){if(this._controlClasses=rt(t),this._calendar)this._calendar.controlClasses=this._controlClasses}get messages(){return this._messages??U()}set messages(t){if(this._messages=t==null?null:{...U(),...t},this._calendar)this._calendar.messages=this._messages;this._refreshMessages()}_refreshMessages(){let t=this.messages;for(let s of this._fields||[])s.setMessages(t);this._field?.setMessages(t),this._panel?.setAttribute("aria-label",t.calendar);let e=this._field??this._fields?.[0];if(this._formatHint&&e)this._formatHint.textContent=`${t.formatHint}: ${e.placeholder}`;if(this._refreshButtonLabel(),this._connected)this.validate()}get source(){return this._source}set source(t){if(this._source=t||null,this._calendar)this._calendar.source=this._source;if(this._connected)this.validate()}get dateState(){return this._dateState}set dateState(t){if(this._dateState=typeof t==="function"?t:null,this._calendar)this._calendar.dateState=this._dateState;if(this._connected)this.validate()}get renderDay(){return this._renderDay}set renderDay(t){if(this._renderDay=typeof t==="function"?t:null,this._calendar)this._calendar.renderDay=this._renderDay}get isDateDisabled(){return this._isDateDisabled}set isDateDisabled(t){if(this._isDateDisabled=typeof t==="function"?t:null,this._calendar)this._calendar.isDateDisabled=this._isDateDisabled;if(this._connected)this.validate()}get coordinateSpace(){return this._coordinateSpace}set coordinateSpace(t){this._coordinateSpace=t==="document"?"document":"viewport"}_adapter(){return this._field?.adapter??this._fields?.[0]?.adapter??lt(this.locale)}_setupFormValue(){this._field?.setupFormValue()}_syncInputState(){let t=this._input;if(!t)return;this._field?.syncInputState();let e=this._buttons[0]?.button;if(e)e.disabled=t.disabled||t.readOnly;if(this._open&&!H(t))this.hide(!1)}_syncRangeFields(){if(!this._fields)return;for(let s of this._fields)s.syncInputState();for(let{button:s,endpoint:i}of this._buttons){let n=i==="end"?1:0,r=this._fields[n];s.disabled=Boolean(r?.input.disabled||r?.input.readOnly)}this._syncDragAffordance();let t=this._range?.activeEndpoint==="end"?1:0,e=this._fields[t]?.input;if(this._open&&e&&!H(e))this.hide(!1)}_setRangeAria(){if(!this._fields||!this._panel||!this._formatHint)return;for(let t of this._fields){let e=t.input,s=[this._rangeOriginalDescribedBy[this._fields.indexOf(t)],this._formatHint.id].filter(Boolean).join(" ");e.setAttribute("aria-describedby",s),e.setAttribute("role","combobox"),e.setAttribute("aria-haspopup","dialog"),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-controls",this._panel.id)}}_createTrigger(t){let e=document.createElement("button");if(e.type="button",e.className="dp-picker-button",e.setAttribute("aria-haspopup","dialog"),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-controls",`${this._id}-panel`),t)e.dataset.endpoint=t;return e.innerHTML='<span aria-hidden="true"><svg viewBox="0 0 16 16" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><rect x="1.75" y="3" width="12.5" height="11" rx="1.75"/><path d="M1.75 6.75h12.5"/><path d="M5.25 1.75v2.5M10.75 1.75v2.5"/></svg></span>',e}_build(){let t=this._rangeMode(),e=[];if(t)for(let[o,l]of(this._fields||[]).entries())e.push([l.input,o===1?"end":"start"]);else if(this._input)e.push([this._input,""]);if(!e.length)return;let s=`${this._id}-panel`,i=`${this._id}-format`;this._buttons=e.map(([o,l])=>{let d=this._createTrigger(l);return o.insertAdjacentElement("afterend",d),{button:d,endpoint:l}});let n=document.createElement("div");n.id=s,n.className="dp-picker-panel",n.setAttribute("popover","manual"),n.setAttribute("role","dialog"),n.setAttribute("aria-label",this.messages.calendar);let r=new dt;r.selection="none",r.fixedWeeks=!0,n.append(r);let a=document.createElement("span");if(a.id=i,a.className="dp-visually-hidden",this.append(n,a),this._panel=n,this._calendar=r,this._formatHint=a,!t&&this._input){this._originalDescribedBy=this._input.getAttribute("aria-describedby")||"";let o=[this._originalDescribedBy,i].filter(Boolean).join(" ");this._input.setAttribute("aria-describedby",o),this._input.setAttribute("role","combobox"),this._input.setAttribute("aria-haspopup","dialog"),this._input.setAttribute("aria-expanded","false"),this._input.setAttribute("aria-controls",s)}this._refreshLocale(),this._refreshButtonLabel()}_bindPopup(t,e,s){this.ownerDocument.addEventListener("pointerdown",(i)=>{if(!this._open||i.composedPath().includes(this))return;this.hide(!1)},{capture:!0,signal:t}),this.ownerDocument.addEventListener("reset",(i)=>{if(!(i.target instanceof HTMLFormElement)||!e||i.target!==e.form)return;this.hide(!1),queueMicrotask(()=>{if(!t.aborted&&!i.defaultPrevented)s()})},{capture:!0,signal:t}),this.addEventListener("keydown",(i)=>this._onEscape(i),{signal:t})}_bind(){let t=this._input,e=this._buttons[0]?.button,s=this._calendar;if(!t||!e||!s)return;let i=new AbortController;this._controller=i;let{signal:n}=i;t.addEventListener("input",()=>{this._field?.handleInput()},{signal:n}),t.addEventListener("change",()=>void this._commitText(!1),{signal:n}),t.addEventListener("blur",()=>void this._commitText(!1),{signal:n}),t.addEventListener("focus",(r)=>{if(!this.openOnFocus||this._suppressFocusOpen)return;let a=r.relatedTarget;if(a instanceof Node&&this.contains(a))return;if(!this._open)this.show({moveFocus:!1})},{signal:n}),t.addEventListener("keydown",(r)=>{this._onFieldKeyDown("",r)},{signal:n});for(let[r,a]of this._timeFields.entries()){if(!a)continue;let o=r===1?"end":"start";a.addEventListener("input",()=>this._revalidateTimeOrder(o),{signal:n}),a.addEventListener("change",()=>this._revalidateTimeOrder(o),{signal:n})}e.addEventListener("click",(r)=>{if(this._open){if(r.detail===0){this._defer(()=>this._calendar?.focusGrid());return}this.hide(!1);return}this.show({returnFocus:e})},{signal:n}),e.addEventListener("keydown",(r)=>this._onTriggerKeyDown("",r),{signal:n}),s.addEventListener("click",(r)=>this._captureGridIntent(r),{capture:!0,signal:n}),s.addEventListener("keydown",(r)=>this._captureGridIntent(r),{capture:!0,signal:n}),s.addEventListener("dateactivate",(r)=>{let a=r,o=a.detail?.date;if(!c(o))return;let l=tt.get(a);queueMicrotask(()=>{if(n.aborted||a.defaultPrevented||!this._connected)return;if(l&&l.id!==this._activationId)return;if(!this._input||!H(this._input))return;this._field?.dirty(),this._setValue(o,{emit:!0,format:!0}),this.hide(!1),this._restoreFocus()})},{signal:n}),s.addEventListener("dateloadend",()=>void this.validate(),{signal:n}),this._bindPopup(n,this._input,()=>this._restoreDefault())}_bindRange(){let t=this._calendar;if(!this._fields||!this._buttons.length||!t)return;let e=new AbortController;this._controller=e;let{signal:s}=e;for(let[i,n]of this._fields.entries()){let r=i===1?"end":"start";n.input.addEventListener("input",()=>{if(n.handleInput(),this._orderTags.delete(i),!n.isDirty)this._revalidateRange(r)},{signal:s}),n.input.addEventListener("change",()=>void this._commitFieldText(r),{signal:s}),n.input.addEventListener("blur",()=>void this._commitFieldText(r),{signal:s}),n.input.addEventListener("focus",(a)=>this._onFieldFocus(r,a),{signal:s}),n.input.addEventListener("keydown",(a)=>this._onFieldKeyDown(r,a),{signal:s})}for(let i of this._buttons){let n=i.endpoint;if(n==="")continue;i.button.addEventListener("click",(r)=>this._onRangeTriggerClick(n,r),{signal:s}),i.button.addEventListener("keydown",(r)=>this._onTriggerKeyDown(n,r),{signal:s})}t.addEventListener("click",(i)=>{if(this._suppressGridClick){this._suppressGridClick=!1,i.preventDefault(),i.stopImmediatePropagation();return}this._captureGridIntent(i)},{capture:!0,signal:s}),t.addEventListener("keydown",(i)=>this._captureGridIntent(i),{capture:!0,signal:s}),t.addEventListener("dateactivate",(i)=>{let n=i,r=n.detail?.date;if(!c(r))return;queueMicrotask(()=>{if(s.aborted||n.defaultPrevented||!this._connected||!this._range)return;let a=tt.get(n);if(a===void 0||a.id!==this._activationId)return;let o=(d)=>this._boundEditable(d),l=a.endpoint?this._range.moveEndpoint(r,a.endpoint,o):this._range.activate(r,o);if(l.status==="refused"){this._calendar?.dispatchEvent(new CustomEvent("dateinvalid",{detail:{date:r,state:this._calendar.getDateState(r)},bubbles:!0}));return}if(this._applyRangeTransition(l),a.endpoint)return;if(l.close||l.status==="complete")this.hide(!1),this._focusField(l.endpoint)})},{signal:s}),t.addEventListener("datefocus",(i)=>this._onGridDateFocus(i),{signal:s}),t.addEventListener("pointerover",(i)=>this._onGridPointerOver(i),{signal:s}),t.addEventListener("pointerleave",()=>this._onGridPointerLeave(),{signal:s}),t.addEventListener("pointerdown",(i)=>this._onGridPointerDown(i),{signal:s}),t.addEventListener("pointermove",(i)=>this._onGridPointerMove(i),{signal:s}),t.addEventListener("pointerup",(i)=>this._onGridPointerUp(i),{signal:s}),t.addEventListener("pointercancel",(i)=>this._onGridPointerCancel(i),{signal:s}),t.addEventListener("lostpointercapture",(i)=>this._onGridPointerCancel(i),{signal:s}),t.addEventListener("dateloadend",()=>void this.validate(),{signal:s}),this._bindPopup(s,this._fields?.[0]?.input,()=>this._restoreRangeDefault())}_activateRangeEndpoint(t){let e=this._calendar;if(!this._range||!e)return;this._range.focus(t),this._activationId++,this._lastFocusEndpoint=t;let s=this._boundCanonical(t)||O();e.display=p(s),e.focusedDate=s,this._clearPreview()}_onRangeTriggerClick(t,e){if(!this._open){this.show({endpoint:t});return}if(e.detail===0){this._activateRangeEndpoint(t),this._defer(()=>this._calendar?.focusGrid());return}if(t!==this._range?.activeEndpoint){this._activateRangeEndpoint(t);return}this.hide(!1)}_onTriggerKeyDown(t,e){if(e.key!=="ArrowDown")return;if(e.preventDefault(),this._open){if(this._rangeMode()&&t)this._activateRangeEndpoint(t);this._defer(()=>this._calendar?.focusGrid());return}if(this._rangeMode())this.show({endpoint:t||void 0});else this.show({returnFocus:this._buttons[0]?.button})}_onFieldKeyDown(t,e){if(e.key==="ArrowDown"){if(e.preventDefault(),this._rangeMode()&&t)this._lastFocusEndpoint=t,this._range?.focus(t);if(this._open)this._defer(()=>this._calendar?.focusGrid());else this.show()}else if(e.key==="Escape"&&this._open)e.preventDefault(),this.hide(!1)}_onFieldFocus(t,e){if(!this._rangeMode()||!t)return;let s=t!==this._range?.activeEndpoint;if(this._lastFocusEndpoint=t,this._range?.focus(t),s)this._activationId++;if(!this.openOnFocus||this._suppressFocusOpen)return;let i=e.relatedTarget;if(i instanceof Node&&this.contains(i))return;if(!this._open)this.show({moveFocus:!1})}_captureGridIntent(t){if(this._rangeMode()?!this._range:!this._field)return;if(t.type==="keydown"){let i=t.key;if(i!=="Enter"&&i!==" ")return}if(t.type==="click"&&this._suppressGridClick)return;if(!(t.target instanceof Element))return;let s=t.target.closest(".dp-day[data-date]")?.getAttribute("data-date")||"";if(!c(s))return;this._attachIntent(s,"")}_attachIntent(t,e){if(!this._calendar)return;this._calendar._hostIntent={date:t,intent:{id:++this._activationId,endpoint:e}}}_supersedeActivations(){this._activationId++}_boundEditable(t){let e=this._fields?.[t==="end"?1:0];return e!=null&&H(e.input)}_applyRangeTransition(t){let e=this._fields;if(!e||!this._range||t.status==="refused")return;let s=[];for(let i of t.changedEndpoints){let n=e[i==="end"?1:0],r=i==="end"?t.range.end:t.range.start;if(!n||n.canonical===r)continue;n.setCanonical(r,{format:!0}),s.push(n)}if(this._syncHighlight(),this._refreshRangeButtonLabel(),this._revalidateRange(t.endpoint),!s.length)return;this._emitRangeChange();for(let i of s)i.input.dispatchEvent(new Event("input",{bubbles:!0})),i.input.dispatchEvent(new Event("change",{bubbles:!0}))}_setPreview(t,e=""){let s=this._calendar;if(!s||!this._range||!this._open)return;let i=c(t)&&!s.getDateState(t).disabled?t:"",n=i?this._range.previewRange(i,e,(r)=>this._boundEditable(r)):null;if(!n){this._clearPreview();return}this._previewDate=i,s.toggleAttribute("data-range-preview",!0),s.highlightedRange=n}_clearPreview(){if(!this._previewDate)return;this._syncHighlight()}_onGridDateFocus(t){if(this._drag)return;let e=t.detail?.date;if(c(e))this._setPreview(e)}_onGridPointerOver(t){let e=t;if(this._drag||e.pointerType==="touch")return;this._setPreview(this._cellDate(e.target))}_onGridPointerLeave(){if(this._drag?.active===!1)this._drag=null;if(this._drag)return;this._clearPreview()}_cellDate(t){let s=(t instanceof Element?t.closest(".dp-day[data-date]"):null)?.getAttribute("data-date")||"";return c(s)?s:""}_dateAtPoint(t,e){let s=this.ownerDocument.elementFromPoint(t,e);if(!(s instanceof Element)||!this._calendar?.contains(s))return"";return this._cellDate(s)}_onGridPointerDown(t){let e=t;if(this._suppressGridClick=!1,this._drag?.active===!1)this._drag=null;if(!this._open||!this._range||this._drag)return;if(!e.isPrimary||e.button!==0)return;if(e.pointerType!=="mouse"&&e.pointerType!=="pen")return;if(!this._range.complete)return;let s=e.target instanceof Element?e.target.closest(".dp-day[data-date]"):null;if(!(s instanceof HTMLElement))return;let i=s.hasAttribute("data-range-start"),n=s.hasAttribute("data-range-end");if(i===n)return;let r=i?"start":"end",a=this._cellDate(s);if(!a||!this._boundEditable(r))return;this._drag={pointerId:e.pointerId,endpoint:r,x:e.clientX,y:e.clientY,date:a,active:!1}}_onGridPointerMove(t){let e=t,s=this._drag;if(!s||e.pointerId!==s.pointerId)return;if(!s.active){if(!(Math.abs(e.clientX-s.x)>ce||Math.abs(e.clientY-s.y)>ce))return;s.active=!0;try{this._calendar?.setPointerCapture(s.pointerId)}catch{}this._syncDragAffordance()}let i=this._dateAtPoint(e.clientX,e.clientY);if(!i||this._calendar?.getDateState(i).disabled)return;s.date=i,this._setPreview(i,s.endpoint)}_onGridPointerUp(t){let e=t,s=this._drag;if(!s||e.pointerId!==s.pointerId)return;if(this._drag=null,this._releaseDragCapture(s.pointerId),!s.active){this._syncDragAffordance();return}this._suppressGridClick=!0;let i=this._range?.projectEndpoint(s.date,s.endpoint,(r)=>this._boundEditable(r));if(!i||i.status==="refused"||!i.changedEndpoints.length){this._syncHighlight();return}let n=s.endpoint==="start"?i.range.start:i.range.end;this._attachIntent(n,s.endpoint),this._calendar?.activateDate(n)}_onGridPointerCancel(t){let e=t,s=this._drag;if(!s||e.pointerId!==s.pointerId)return;this._drag=null,this._releaseDragCapture(s.pointerId),this._syncHighlight()}_releaseDragCapture(t){let e=this._calendar;if(e?.hasPointerCapture(t))e.releasePointerCapture(t)}_syncDragAffordance(){let t=this._calendar;if(!t||!this._range)return;if(this._drag?.active){t.setAttribute("data-range-drag","active");return}let{start:e,end:s}=this._range;if(this._range.complete&&e!==s&&(this._boundEditable("start")||this._boundEditable("end")))t.setAttribute("data-range-drag","ready");else t.removeAttribute("data-range-drag")}_onEscape(t){if(t.key==="Escape"&&this._open)t.preventDefault(),t.stopPropagation(),this.hide(!0)}_syncCalendarOptions(){let t=this._calendar,e=this._panel;if(!t)return;if(t.locale=this.locale,t.min=this.min,t.max=this.max,t.monthFormat=this.monthFormat,t.controlClasses=this._controlClasses,t.messages=this._messages,t.source=this._source,t.dateState=this._dateState,t.renderDay=this._renderDay,t.isDateDisabled=this._isDateDisabled,!this._rangeMode()&&this._value)t.value=this._value;if(e)e.setAttribute("aria-label",this.messages.calendar)}_refreshLocale(){let t=this._formatHint;if(!t)return;if(this._rangeMode()&&this._fields){this._fields[0].setLocale(this.locale),this._fields[1].setLocale(this.locale),t.textContent=`${this.messages.formatHint}: ${this._fields[0].placeholder}`;for(let[s,i]of this._fields.entries()){if(!i.input.hasAttribute("placeholder")||this._generatedPlaceholders.has(i.input))i.input.placeholder=i.placeholder,this._generatedPlaceholders.add(i.input);let n=s===1?this._range?.end||"":this._range?.start||"";if(n)i.input.value=i.format(n)}this._refreshButtonLabel();return}let e=this._field;if(!e)return;if(e.setLocale(this.locale),t.textContent=`${this.messages.formatHint}: ${e.placeholder}`,!e.input.hasAttribute("placeholder")||this._generatedPlaceholders.has(e.input))e.input.placeholder=e.placeholder,this._generatedPlaceholders.add(e.input);if(this._value)e.input.value=e.format(this._value);this._refreshButtonLabel()}_refreshButtonLabel(){let t=this._buttons[0]?.button;if(!t)return;if(this._rangeMode()){this._refreshRangeButtonLabel();return}let e=this._value?this.messages.changeDate:this.messages.chooseDate,s=this._value?`, ${ot(this._value,this.locale)}`:"";t.setAttribute("aria-label",`${e}${s}`)}_refreshRangeButtonLabel(){if(!this._range)return;let{start:t,end:e}=this._range;for(let{button:s,endpoint:i}of this._buttons){let n=i==="end"?e:t,r=n?this.messages.changeDate:this.messages.chooseDate,a=n?`, ${ot(n,this.locale)}`:"",o=i==="end"?this.messages.rangeEnd:this.messages.rangeStart;s.setAttribute("aria-label",`${r}${a}, ${o}`)}}_reflectValue(t){if(this._reflecting=!0,t)this.setAttribute("value",t);else this.removeAttribute("value");this._reflecting=!1}_setValue(t,e={}){if(t&&!c(t))throw TypeError(`Invalid date-picker value: ${t}`);let s=this._value;if(this._value=t||"",e.reflect!==!1)this._reflectValue(this._value);if(this._field?.setCanonical(this._value,{format:e.format!==!1}),this._calendar){if(this._calendar.value=this._value,this._value&&e.moveDisplay!==!1)this._calendar.focusedDate=this._value}if(this._refreshButtonLabel(),s!==this._value){if(this.dispatchEvent(new CustomEvent("valuechange",{detail:{value:this._value},bubbles:!0})),e.emit&&this._field){let i=this._field.input;i.dispatchEvent(new Event("input",{bubbles:!0})),i.dispatchEvent(new Event("change",{bubbles:!0}))}}}async _confirmDate(t,e={}){let s=this._calendar;if(!s)return{ok:!0};if(e.moveDisplay!==!1){let r=p(t);if(s.display!==r)s.display=r}let i=await s.ensureDate(t),n=s.getDateState(t);if(!i||n.disabled)return{ok:!1,message:this.messages.unavailableDate};return{ok:!0}}async _commitText(t,e={}){let s=this._field;if(!s)return!1;if(!e.force&&!s.isDirty)return!1;let i=await s.commit(e);if(!this._ownsField(s)||!s.isCommitCurrent(i.commitId))return!1;if(i.status==="stale"||i.status==="invalid")return!1;return this._setValue(i.value||"",{emit:t,format:i.status==="ok",moveDisplay:e.moveDisplay}),!0}async _commitFieldText(t){let e=this._fields;if(!e)return!1;let s=t==="end"?1:0,i=e[s];if(!i?.isDirty)return!1;let n=await i.commit();if(!this._ownsField(i)||!i.isCommitCurrent(n.commitId))return!1;if(n.status==="stale")return!1;if(n.status==="invalid")return this._orderTags.delete(s),!1;return this._setBound(t,n.value||"",{emit:!1,user:!0,format:n.status==="ok"}),!0}_setBound(t,e,s={}){if(!this._range)return!1;let i=this._fields;if(!i)return!1;let r=i[t==="end"?1:0];if(!r)return!1;if(s.user===!0&&!H(r.input))return!1;let a=e||"",o=r.canonical;if(r.setCanonical(a,{format:s.format!==!1}),t==="end")this._range.end=a;else this._range.start=a;let l=o!==a;if(l){if(this._syncHighlight(),this._refreshRangeButtonLabel(),this._emitRangeChange(),s.emit)r.input.dispatchEvent(new Event("input",{bubbles:!0})),r.input.dispatchEvent(new Event("change",{bubbles:!0}))}return this._revalidateRange(t),l}_setRange(t,e,s={}){if(!this._range||!this._fields)return;if(this._range.start=t||"",this._range.end=e||"",this._fields[0].setCanonical(t||"",{format:s.format!==!1}),this._fields[1].setCanonical(e||"",{format:s.format!==!1}),this._syncHighlight(),this._refreshRangeButtonLabel(),this._revalidateRange("start"),this._revalidateRange("end"),s.emit!==!1)this._emitRangeChange()}_boundCanonical(t){return this._range?t==="end"?this._range.end:this._range.start:""}_emitRangeChange(){if(!this._range)return;this.dispatchEvent(new CustomEvent("rangechange",{detail:{...this._range.range},bubbles:!0}))}_displayRange(){let{start:t,end:e}=this._range?.range??{start:"",end:""};if(!t)return{start:"",end:""};if(e&&_(e,t)<0)return{start:t,end:""};return{start:t,end:e}}_syncHighlight(){if(!this._calendar||!this._range)return;this._previewDate="",this._calendar.removeAttribute("data-range-preview"),this._calendar.highlightedRange=this._displayRange(),this._syncDragAffordance()}_revalidateRange(t){if(!this._fields||!this._range)return;let{start:e,end:s}=this._range,i=Boolean(e&&s&&_(s,e)<0),n=["start","end"];for(let r of n){let a=r==="end"?1:0,o=this._fields[a].input,l=r==="end"?this.messages.rangeOrderEnd:this.messages.rangeOrderStart;if(i&&r===t)o.setCustomValidity(l),this._orderTags.add(a);else if(this._orderTags.has(a))o.setCustomValidity(""),this._orderTags.delete(a)}}_revalidateTimeOrder(t){let[e,s]=this._timeFields,i=["start","end"],n=[e,s],r=e&&!e.matches(":disabled")?e.value.trim():"",a=s&&!s.matches(":disabled")?s.value.trim():"",o=Boolean(e&&s&&r&&a)&&Lt(r)&&Lt(a)&&de(a,r)<0;for(let[l,d]of i.entries()){let h=n[l];if(!h)continue;let v=d==="end"?this.messages.rangeOrderEnd:this.messages.rangeOrderStart;if(o&&d===t)h.setCustomValidity(v),this._timeOrderOwned.add(h);else if(this._timeOrderOwned.has(h))h.setCustomValidity(""),this._timeOrderOwned.delete(h)}}_clearTimeOrderValidity(){for(let t of this._timeOrderOwned)t.setCustomValidity("");this._timeOrderOwned.clear()}_defer(t){let e=this._controller;setTimeout(()=>{if(!this._connected||!e||e.signal.aborted||this._controller!==e)return;t()},0)}_restoreDefault(){let t=this._field;if(!t)return;let e=t.restoreDefault();if(this._setValue(e,{emit:!1,format:!0}),this._calendar)if(this._value)this._calendar.display=p(this._value),this._calendar.focusedDate=this._value;else this._calendar.display=p(O()),this._calendar.focusedDate=O();this.validate()}_restoreRangeDefault(){if(!this._fields)return;let t=this._fields[0].restoreDefault(),e=this._fields[1].restoreDefault();if(this._setRange(t,e),this._calendar){let s=this._range?.start||O();this._calendar.display=p(s),this._calendar.focusedDate=s}this.validate()}_focusField(t){let e=t==="end"?1:0,s=this._fields?.[e]?.input;if(!s)return;this._suppressFocusOpen=!0,this._defer(()=>{s.focus(),this._suppressFocusOpen=!1})}_restoreFocus(){let t=this._returnFocus;if(this._returnFocus=null,!(t instanceof HTMLElement)||!t.isConnected||t.matches(":disabled"))return;this._suppressFocusOpen=!0,this._defer(()=>{t.focus(),this._suppressFocusOpen=!1})}_resolveRangeEndpoint(){if(!this._fields)return"";let t=this._lastFocusEndpoint||"start",e=t==="end"?1:0;if(H(this._fields[e].input))return t;let s=t==="end"?"start":"end",i=s==="end"?1:0;if(H(this._fields[i].input))return s;return""}async validate(){if(this._rangeMode()){let s=this._fields;if(!s)return!0;for(let[i,n]of s.entries()){let r=await n.commit({moveDisplay:!1});if(!this._ownsField(n)||!n.isCommitCurrent(r.commitId))continue;if(r.status==="invalid")this._orderTags.delete(i);if(r.status==="ok"||r.status==="clear"){let a=i===1?"end":"start";this._setBound(a,r.value||"",{format:r.status==="ok"})}}return this._revalidateRange("start"),this._revalidateRange("end"),s.every((i)=>i.input.checkValidity())}let t=this._field?.input;if(!t){let s=this.hasAttribute("range")?this.querySelectorAll(":scope > input[data-range-start], :scope > input[data-range-end]"):this._input?[this._input]:[],i=this.querySelectorAll(":scope > input[type=time][data-time-start], :scope > input[type=time][data-time-end]");return[...s,...i].every((n)=>n instanceof HTMLInputElement&&n.checkValidity())}await this._commitText(!1,{force:!0,moveDisplay:!1}),this._revalidateTimeOrder("start"),this._revalidateTimeOrder("end");let e=this._timeFields.every((s)=>s?.checkValidity()??!0);return t.checkValidity()&&e}show(t={}){let e=this._panel,s=this._calendar;if(!e||!s||!this._buttons.length||this._open)return;if(this._rangeMode()){let r=t.endpoint||this._resolveRangeEndpoint();if(!r)return;this._activateRangeEndpoint(r)}else{let r=this._input;if(!r||!H(r))return;let a=this._value||this._adapter().parse(r.value)||O();s.display=p(a),s.focusedDate=a,this._returnFocus=t.returnFocus instanceof HTMLElement?t.returnFocus:r}e.showPopover(),this._open=!0,this._setExpanded(!0);let i=this.coordinateSpace;e.style.position=i==="document"?"absolute":"fixed";let n=()=>oe(this,e,{placement:"bottom-start",distance:4,shiftPadding:8,coordinateSpace:i});if(n(),this._stopTracking=ae(this,e,n),t.moveFocus!==!1){let r=this._controller;queueMicrotask(()=>{if(!this._connected||!r||r.signal.aborted||this._controller!==r)return;s.focusGrid()})}this.dispatchEvent(new Event("open",{bubbles:!0}))}_setExpanded(t){let e=t?"true":"false";this._input?.setAttribute("aria-expanded",e);for(let{button:s}of this._buttons)s.setAttribute("aria-expanded",e);for(let s of this._fields||[])s.input.setAttribute("aria-expanded",e)}hide(t=!1){if(!this._panel||!this._open)return;this._stopTracking?.(),this._stopTracking=null;try{this._panel.hidePopover()}catch{}if(this._open=!1,this._setExpanded(!1),this._supersedeActivations(),this._suppressGridClick=!1,this._drag)this._releaseDragCapture(this._drag.pointerId),this._drag=null;if(this._syncHighlight(),t)if(this._rangeMode()){let e=this._restoreFocusEndpoint();if(e)this._focusField(e)}else this._restoreFocus();this.dispatchEvent(new Event("close",{bubbles:!0}))}_restoreFocusEndpoint(){let t=this._range?.activeEndpoint||"";if(t){let e=t==="end"?1:0,s=this._fields?.[e];if(s&&H(s.input))return t}return this._resolveRangeEndpoint()}}function ue(){if(!customElements.get("date-calendar"))customElements.define("date-calendar",dt);if(!customElements.get("date-picker"))customElements.define("date-picker",Rt)}ue();})();