@oslokommune/punkt-elements 13.6.6 → 13.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/{calendar-ChphTIhk.js → calendar-CodWwTHM.js} +503 -471
- package/dist/calendar-DH-fCGyW.cjs +115 -0
- package/dist/datepicker-BEMo4X9s.js +770 -0
- package/dist/datepicker-n49TAIAt.cjs +169 -0
- package/dist/index.d.ts +7 -1
- package/dist/pkt-calendar.cjs +1 -1
- package/dist/pkt-calendar.js +1 -1
- package/dist/pkt-datepicker.cjs +1 -1
- package/dist/pkt-datepicker.js +1 -1
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +3 -3
- package/package.json +2 -2
- package/src/components/calendar/calendar.ts +26 -28
- package/src/components/datepicker/date-tags.ts +2 -1
- package/src/components/datepicker/datepicker-utils.ts +475 -0
- package/src/components/datepicker/datepicker.selection.test.ts +62 -1
- package/src/components/datepicker/datepicker.ts +157 -271
- package/dist/calendar-CL9O0tLP.cjs +0 -115
- package/dist/datepicker-CV73pLqD.cjs +0 -169
- package/dist/datepicker-Ca552mbJ.js +0 -531
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";const G=require("./class-map-CG3vIaNm.cjs"),c=require("./element-D62wHiNU.cjs"),H=require("./state-BkE_Rxl7.cjs");require("./icon-__Hjt2XZ.cjs");const at=6048e5,ft=864e5,X=Symbol.for("constructDateFrom");function S(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&X in e?e[X](t):e instanceof Date?new e.constructor(t):new Date(t)}function k(e,t){return S(t||e,e)}function U(e,t,n){const r=k(e,n==null?void 0:n.in);return isNaN(t)?S(e,NaN):(t&&r.setDate(r.getDate()+t),r)}let mt={};function R(){return mt}function F(e,t){var l,o,h,f;const n=R(),r=(t==null?void 0:t.weekStartsOn)??((o=(l=t==null?void 0:t.locale)==null?void 0:l.options)==null?void 0:o.weekStartsOn)??n.weekStartsOn??((f=(h=n.locale)==null?void 0:h.options)==null?void 0:f.weekStartsOn)??0,a=k(e,t==null?void 0:t.in),s=a.getDay(),i=(s<r?7:0)+s-r;return a.setDate(a.getDate()-i),a.setHours(0,0,0,0),a}function q(e,t){return F(e,{...t,weekStartsOn:1})}function st(e,t){const n=k(e,t==null?void 0:t.in),r=n.getFullYear(),a=S(n,0);a.setFullYear(r+1,0,4),a.setHours(0,0,0,0);const s=q(a),i=S(n,0);i.setFullYear(r,0,4),i.setHours(0,0,0,0);const l=q(i);return n.getTime()>=s.getTime()?r+1:n.getTime()>=l.getTime()?r:r-1}function V(e){const t=k(e),n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return n.setUTCFullYear(t.getFullYear()),+e-+n}function it(e,...t){const n=S.bind(null,t.find(r=>typeof r=="object"));return t.map(n)}function J(e,t){const n=k(e,t==null?void 0:t.in);return n.setHours(0,0,0,0),n}function gt(e,t,n){const[r,a]=it(n==null?void 0:n.in,e,t),s=J(r),i=J(a),l=+s-V(s),o=+i-V(i);return Math.round((l-o)/ft)}function yt(e,t){const n=st(e,t),r=S(e,0);return r.setFullYear(n,0,4),r.setHours(0,0,0,0),q(r)}function pt(e){return e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]"}function wt(e){return!(!pt(e)&&typeof e!="number"||isNaN(+k(e)))}function bt(e,t){const[n,r]=it(e,t.start,t.end);return{start:n,end:r}}function B(e,t){const{start:n,end:r}=bt(t==null?void 0:t.in,e);let a=+n>+r;const s=a?+n:+r,i=a?r:n;i.setHours(0,0,0,0);let l=1;const o=[];for(;+i<=s;)o.push(S(n,i)),i.setDate(i.getDate()+l),i.setHours(0,0,0,0);return a?o.reverse():o}function kt(e,t){const n=k(e,t==null?void 0:t.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}const Dt={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},St=(e,t,n)=>{let r;const a=Dt[e];return typeof a=="string"?r=a:t===1?r=a.one:r=a.other.replace("{{count}}",t.toString()),n!=null&&n.addSuffix?n.comparison&&n.comparison>0?"in "+r:r+" ago":r};function z(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const vt={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},Mt={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},xt={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},Tt={date:z({formats:vt,defaultWidth:"full"}),time:z({formats:Mt,defaultWidth:"full"}),dateTime:z({formats:xt,defaultWidth:"full"})},Pt={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},Ot=(e,t,n,r)=>Pt[e];function _(e){return(t,n)=>{const r=n!=null&&n.context?String(n.context):"standalone";let a;if(r==="formatting"&&e.formattingValues){const i=e.defaultFormattingWidth||e.defaultWidth,l=n!=null&&n.width?String(n.width):i;a=e.formattingValues[l]||e.formattingValues[i]}else{const i=e.defaultWidth,l=n!=null&&n.width?String(n.width):e.defaultWidth;a=e.values[l]||e.values[i]}const s=e.argumentCallback?e.argumentCallback(t):t;return a[s]}}const Ct={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},Nt={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},$t={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},_t={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},Et={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},Wt={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},Yt=(e,t)=>{const n=Number(e),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},At={ordinalNumber:Yt,era:_({values:Ct,defaultWidth:"wide"}),quarter:_({values:Nt,defaultWidth:"wide",argumentCallback:e=>e-1}),month:_({values:$t,defaultWidth:"wide"}),day:_({values:_t,defaultWidth:"wide"}),dayPeriod:_({values:Et,defaultWidth:"wide",formattingValues:Wt,defaultFormattingWidth:"wide"})};function E(e){return(t,n={})=>{const r=n.width,a=r&&e.matchPatterns[r]||e.matchPatterns[e.defaultMatchWidth],s=t.match(a);if(!s)return null;const i=s[0],l=r&&e.parsePatterns[r]||e.parsePatterns[e.defaultParseWidth],o=Array.isArray(l)?Ht(l,m=>m.test(i)):Ft(l,m=>m.test(i));let h;h=e.valueCallback?e.valueCallback(o):o,h=n.valueCallback?n.valueCallback(h):h;const f=t.slice(i.length);return{value:h,rest:f}}}function Ft(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n}function Ht(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n}function It(e){return(t,n={})=>{const r=t.match(e.matchPattern);if(!r)return null;const a=r[0],s=t.match(e.parsePattern);if(!s)return null;let i=e.valueCallback?e.valueCallback(s[0]):s[0];i=n.valueCallback?n.valueCallback(i):i;const l=t.slice(a.length);return{value:i,rest:l}}}const qt=/^(\d+)(th|st|nd|rd)?/i,Rt=/\d+/i,Lt={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},Ut={any:[/^b/i,/^(a|c)/i]},Bt={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},zt={any:[/1/i,/2/i,/3/i,/4/i]},jt={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},Qt={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},Gt={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},Xt={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},Vt={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},Jt={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},Kt={ordinalNumber:It({matchPattern:qt,parsePattern:Rt,valueCallback:e=>parseInt(e,10)}),era:E({matchPatterns:Lt,defaultMatchWidth:"wide",parsePatterns:Ut,defaultParseWidth:"any"}),quarter:E({matchPatterns:Bt,defaultMatchWidth:"wide",parsePatterns:zt,defaultParseWidth:"any",valueCallback:e=>e+1}),month:E({matchPatterns:jt,defaultMatchWidth:"wide",parsePatterns:Qt,defaultParseWidth:"any"}),day:E({matchPatterns:Gt,defaultMatchWidth:"wide",parsePatterns:Xt,defaultParseWidth:"any"}),dayPeriod:E({matchPatterns:Vt,defaultMatchWidth:"any",parsePatterns:Jt,defaultParseWidth:"any"})},Zt={code:"en-US",formatDistance:St,formatLong:Tt,formatRelative:Ot,localize:At,match:Kt,options:{weekStartsOn:0,firstWeekContainsDate:1}};function te(e,t){const n=k(e,t==null?void 0:t.in);return gt(n,kt(n))+1}function ee(e,t){const n=k(e,t==null?void 0:t.in),r=+q(n)-+yt(n);return Math.round(r/at)+1}function ot(e,t){var f,m,w,g;const n=k(e,t==null?void 0:t.in),r=n.getFullYear(),a=R(),s=(t==null?void 0:t.firstWeekContainsDate)??((m=(f=t==null?void 0:t.locale)==null?void 0:f.options)==null?void 0:m.firstWeekContainsDate)??a.firstWeekContainsDate??((g=(w=a.locale)==null?void 0:w.options)==null?void 0:g.firstWeekContainsDate)??1,i=S((t==null?void 0:t.in)||e,0);i.setFullYear(r+1,0,s),i.setHours(0,0,0,0);const l=F(i,t),o=S((t==null?void 0:t.in)||e,0);o.setFullYear(r,0,s),o.setHours(0,0,0,0);const h=F(o,t);return+n>=+l?r+1:+n>=+h?r:r-1}function ne(e,t){var l,o,h,f;const n=R(),r=(t==null?void 0:t.firstWeekContainsDate)??((o=(l=t==null?void 0:t.locale)==null?void 0:l.options)==null?void 0:o.firstWeekContainsDate)??n.firstWeekContainsDate??((f=(h=n.locale)==null?void 0:h.options)==null?void 0:f.firstWeekContainsDate)??1,a=ot(e,t),s=S((t==null?void 0:t.in)||e,0);return s.setFullYear(a,0,r),s.setHours(0,0,0,0),F(s,t)}function ct(e,t){const n=k(e,t==null?void 0:t.in),r=+F(n,t)-+ne(n,t);return Math.round(r/at)+1}function u(e,t){const n=e<0?"-":"",r=Math.abs(e).toString().padStart(t,"0");return n+r}const v={y(e,t){const n=e.getFullYear(),r=n>0?n:1-n;return u(t==="yy"?r%100:r,t.length)},M(e,t){const n=e.getMonth();return t==="M"?String(n+1):u(n+1,2)},d(e,t){return u(e.getDate(),t.length)},a(e,t){const n=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h(e,t){return u(e.getHours()%12||12,t.length)},H(e,t){return u(e.getHours(),t.length)},m(e,t){return u(e.getMinutes(),t.length)},s(e,t){return u(e.getSeconds(),t.length)},S(e,t){const n=t.length,r=e.getMilliseconds(),a=Math.trunc(r*Math.pow(10,n-3));return u(a,t.length)}},N={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},K={G:function(e,t,n){const r=e.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return n.era(r,{width:"abbreviated"});case"GGGGG":return n.era(r,{width:"narrow"});case"GGGG":default:return n.era(r,{width:"wide"})}},y:function(e,t,n){if(t==="yo"){const r=e.getFullYear(),a=r>0?r:1-r;return n.ordinalNumber(a,{unit:"year"})}return v.y(e,t)},Y:function(e,t,n,r){const a=ot(e,r),s=a>0?a:1-a;if(t==="YY"){const i=s%100;return u(i,2)}return t==="Yo"?n.ordinalNumber(s,{unit:"year"}):u(s,t.length)},R:function(e,t){const n=st(e);return u(n,t.length)},u:function(e,t){const n=e.getFullYear();return u(n,t.length)},Q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"Q":return String(r);case"QQ":return u(r,2);case"Qo":return n.ordinalNumber(r,{unit:"quarter"});case"QQQ":return n.quarter(r,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(r,{width:"narrow",context:"formatting"});case"QQQQ":default:return n.quarter(r,{width:"wide",context:"formatting"})}},q:function(e,t,n){const r=Math.ceil((e.getMonth()+1)/3);switch(t){case"q":return String(r);case"qq":return u(r,2);case"qo":return n.ordinalNumber(r,{unit:"quarter"});case"qqq":return n.quarter(r,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(r,{width:"narrow",context:"standalone"});case"qqqq":default:return n.quarter(r,{width:"wide",context:"standalone"})}},M:function(e,t,n){const r=e.getMonth();switch(t){case"M":case"MM":return v.M(e,t);case"Mo":return n.ordinalNumber(r+1,{unit:"month"});case"MMM":return n.month(r,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(r,{width:"narrow",context:"formatting"});case"MMMM":default:return n.month(r,{width:"wide",context:"formatting"})}},L:function(e,t,n){const r=e.getMonth();switch(t){case"L":return String(r+1);case"LL":return u(r+1,2);case"Lo":return n.ordinalNumber(r+1,{unit:"month"});case"LLL":return n.month(r,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(r,{width:"narrow",context:"standalone"});case"LLLL":default:return n.month(r,{width:"wide",context:"standalone"})}},w:function(e,t,n,r){const a=ct(e,r);return t==="wo"?n.ordinalNumber(a,{unit:"week"}):u(a,t.length)},I:function(e,t,n){const r=ee(e);return t==="Io"?n.ordinalNumber(r,{unit:"week"}):u(r,t.length)},d:function(e,t,n){return t==="do"?n.ordinalNumber(e.getDate(),{unit:"date"}):v.d(e,t)},D:function(e,t,n){const r=te(e);return t==="Do"?n.ordinalNumber(r,{unit:"dayOfYear"}):u(r,t.length)},E:function(e,t,n){const r=e.getDay();switch(t){case"E":case"EE":case"EEE":return n.day(r,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(r,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(r,{width:"short",context:"formatting"});case"EEEE":default:return n.day(r,{width:"wide",context:"formatting"})}},e:function(e,t,n,r){const a=e.getDay(),s=(a-r.weekStartsOn+8)%7||7;switch(t){case"e":return String(s);case"ee":return u(s,2);case"eo":return n.ordinalNumber(s,{unit:"day"});case"eee":return n.day(a,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(a,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(a,{width:"short",context:"formatting"});case"eeee":default:return n.day(a,{width:"wide",context:"formatting"})}},c:function(e,t,n,r){const a=e.getDay(),s=(a-r.weekStartsOn+8)%7||7;switch(t){case"c":return String(s);case"cc":return u(s,t.length);case"co":return n.ordinalNumber(s,{unit:"day"});case"ccc":return n.day(a,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(a,{width:"narrow",context:"standalone"});case"cccccc":return n.day(a,{width:"short",context:"standalone"});case"cccc":default:return n.day(a,{width:"wide",context:"standalone"})}},i:function(e,t,n){const r=e.getDay(),a=r===0?7:r;switch(t){case"i":return String(a);case"ii":return u(a,t.length);case"io":return n.ordinalNumber(a,{unit:"day"});case"iii":return n.day(r,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(r,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(r,{width:"short",context:"formatting"});case"iiii":default:return n.day(r,{width:"wide",context:"formatting"})}},a:function(e,t,n){const a=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(a,{width:"narrow",context:"formatting"});case"aaaa":default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},b:function(e,t,n){const r=e.getHours();let a;switch(r===12?a=N.noon:r===0?a=N.midnight:a=r/12>=1?"pm":"am",t){case"b":case"bb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(a,{width:"narrow",context:"formatting"});case"bbbb":default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},B:function(e,t,n){const r=e.getHours();let a;switch(r>=17?a=N.evening:r>=12?a=N.afternoon:r>=4?a=N.morning:a=N.night,t){case"B":case"BB":case"BBB":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(a,{width:"narrow",context:"formatting"});case"BBBB":default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},h:function(e,t,n){if(t==="ho"){let r=e.getHours()%12;return r===0&&(r=12),n.ordinalNumber(r,{unit:"hour"})}return v.h(e,t)},H:function(e,t,n){return t==="Ho"?n.ordinalNumber(e.getHours(),{unit:"hour"}):v.H(e,t)},K:function(e,t,n){const r=e.getHours()%12;return t==="Ko"?n.ordinalNumber(r,{unit:"hour"}):u(r,t.length)},k:function(e,t,n){let r=e.getHours();return r===0&&(r=24),t==="ko"?n.ordinalNumber(r,{unit:"hour"}):u(r,t.length)},m:function(e,t,n){return t==="mo"?n.ordinalNumber(e.getMinutes(),{unit:"minute"}):v.m(e,t)},s:function(e,t,n){return t==="so"?n.ordinalNumber(e.getSeconds(),{unit:"second"}):v.s(e,t)},S:function(e,t){return v.S(e,t)},X:function(e,t,n){const r=e.getTimezoneOffset();if(r===0)return"Z";switch(t){case"X":return tt(r);case"XXXX":case"XX":return O(r);case"XXXXX":case"XXX":default:return O(r,":")}},x:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"x":return tt(r);case"xxxx":case"xx":return O(r);case"xxxxx":case"xxx":default:return O(r,":")}},O:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+Z(r,":");case"OOOO":default:return"GMT"+O(r,":")}},z:function(e,t,n){const r=e.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+Z(r,":");case"zzzz":default:return"GMT"+O(r,":")}},t:function(e,t,n){const r=Math.trunc(+e/1e3);return u(r,t.length)},T:function(e,t,n){return u(+e,t.length)}};function Z(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),a=Math.trunc(r/60),s=r%60;return s===0?n+String(a):n+String(a)+t+u(s,2)}function tt(e,t){return e%60===0?(e>0?"-":"+")+u(Math.abs(e)/60,2):O(e,t)}function O(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),a=u(Math.trunc(r/60),2),s=u(r%60,2);return n+a+t+s}const et=(e,t)=>{switch(e){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});case"PPPP":default:return t.date({width:"full"})}},lt=(e,t)=>{switch(e){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});case"pppp":default:return t.time({width:"full"})}},re=(e,t)=>{const n=e.match(/(P+)(p+)?/)||[],r=n[1],a=n[2];if(!a)return et(e,t);let s;switch(r){case"P":s=t.dateTime({width:"short"});break;case"PP":s=t.dateTime({width:"medium"});break;case"PPP":s=t.dateTime({width:"long"});break;case"PPPP":default:s=t.dateTime({width:"full"});break}return s.replace("{{date}}",et(r,t)).replace("{{time}}",lt(a,t))},ae={p:lt,P:re},se=/^D+$/,ie=/^Y+$/,oe=["D","DD","YY","YYYY"];function ce(e){return se.test(e)}function le(e){return ie.test(e)}function ue(e,t,n){const r=he(e,t,n);if(console.warn(r),oe.includes(e))throw new RangeError(r)}function he(e,t,n){const r=e[0]==="Y"?"years":"days of the month";return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${r} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}const de=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,fe=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,me=/^'([^]*?)'?$/,ge=/''/g,ye=/[a-zA-Z]/;function pe(e,t,n){var f,m,w,g;const r=R(),a=r.locale??Zt,s=r.firstWeekContainsDate??((m=(f=r.locale)==null?void 0:f.options)==null?void 0:m.firstWeekContainsDate)??1,i=r.weekStartsOn??((g=(w=r.locale)==null?void 0:w.options)==null?void 0:g.weekStartsOn)??0,l=k(e,n==null?void 0:n.in);if(!wt(l))throw new RangeError("Invalid time value");let o=t.match(fe).map(p=>{const b=p[0];if(b==="p"||b==="P"){const L=ae[b];return L(p,a.formatLong)}return p}).join("").match(de).map(p=>{if(p==="''")return{isToken:!1,value:"'"};const b=p[0];if(b==="'")return{isToken:!1,value:we(p)};if(K[b])return{isToken:!0,value:p};if(b.match(ye))throw new RangeError("Format string contains an unescaped latin alphabet character `"+b+"`");return{isToken:!1,value:p}});a.localize.preprocessor&&(o=a.localize.preprocessor(l,o));const h={firstWeekContainsDate:s,weekStartsOn:i,locale:a};return o.map(p=>{if(!p.isToken)return p.value;const b=p.value;(le(b)||ce(b))&&ue(b,t,String(e));const L=K[b[0]];return L(l,b,a.localize,h)}).join("")}function we(e){const t=e.match(me);return t?t[1].replace(ge,"'"):e}function be(e,t){const n=k(e,t==null?void 0:t.in).getDay();return n===0?7:n}const j={},Y={};function A(e,t){try{const r=(j[e]||(j[e]=new Intl.DateTimeFormat("en-GB",{timeZone:e,hour:"numeric",timeZoneName:"longOffset"}).format))(t).split("GMT")[1]||"";return r in Y?Y[r]:nt(r,r.split(":"))}catch{if(e in Y)return Y[e];const n=e==null?void 0:e.match(ke);return n?nt(e,n.slice(1)):NaN}}const ke=/([+-]\d\d):?(\d\d)?/;function nt(e,t){const n=+t[0],r=+(t[1]||0);return Y[e]=n>0?n*60+r:n*60-r}class D extends Date{constructor(...t){super(),t.length>1&&typeof t[t.length-1]=="string"&&(this.timeZone=t.pop()),this.internal=new Date,isNaN(A(this.timeZone,this))?this.setTime(NaN):t.length?typeof t[0]=="number"&&(t.length===1||t.length===2&&typeof t[1]!="number")?this.setTime(t[0]):typeof t[0]=="string"?this.setTime(+new Date(t[0])):t[0]instanceof Date?this.setTime(+t[0]):(this.setTime(+new Date(...t)),ut(this),Q(this)):this.setTime(Date.now())}static tz(t,...n){return n.length?new D(...n,t):new D(Date.now(),t)}withTimeZone(t){return new D(+this,t)}getTimezoneOffset(){return-A(this.timeZone,this)}setTime(t){return Date.prototype.setTime.apply(this,arguments),Q(this),+this}[Symbol.for("constructDateFrom")](t){return new D(+new Date(t),this.timeZone)}}const rt=/^(get|set)(?!UTC)/;Object.getOwnPropertyNames(Date.prototype).forEach(e=>{if(!rt.test(e))return;const t=e.replace(rt,"$1UTC");D.prototype[t]&&(e.startsWith("get")?D.prototype[e]=function(){return this.internal[t]()}:(D.prototype[e]=function(){return Date.prototype[t].apply(this.internal,arguments),De(this),+this},D.prototype[t]=function(){return Date.prototype[t].apply(this,arguments),Q(this),+this}))});function Q(e){e.internal.setTime(+e),e.internal.setUTCMinutes(e.internal.getUTCMinutes()-e.getTimezoneOffset())}function De(e){Date.prototype.setFullYear.call(e,e.internal.getUTCFullYear(),e.internal.getUTCMonth(),e.internal.getUTCDate()),Date.prototype.setHours.call(e,e.internal.getUTCHours(),e.internal.getUTCMinutes(),e.internal.getUTCSeconds(),e.internal.getUTCMilliseconds()),ut(e)}function ut(e){const t=A(e.timeZone,e),n=new Date(+e);n.setUTCHours(n.getUTCHours()-1);const r=-new Date(+e).getTimezoneOffset(),a=-new Date(+n).getTimezoneOffset(),s=r-a,i=Date.prototype.getHours.apply(e)!==e.internal.getUTCHours();s&&i&&e.internal.setUTCMinutes(e.internal.getUTCMinutes()+s);const l=r-t;l&&Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+l);const o=A(e.timeZone,e),f=-new Date(+e).getTimezoneOffset()-o,m=o!==t,w=f-l;if(m&&w){Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+w);const g=A(e.timeZone,e),p=o-g;p&&(e.internal.setUTCMinutes(e.internal.getUTCMinutes()+p),Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+p))}}class x extends D{static tz(t,...n){return n.length?new x(...n,t):new x(Date.now(),t)}toISOString(){const[t,n,r]=this.tzComponents(),a=`${t}${n}:${r}`;return this.internal.toISOString().slice(0,-1)+a}toString(){return`${this.toDateString()} ${this.toTimeString()}`}toDateString(){const[t,n,r,a]=this.internal.toUTCString().split(" ");return`${t==null?void 0:t.slice(0,-1)} ${r} ${n} ${a}`}toTimeString(){const t=this.internal.toUTCString().split(" ")[4],[n,r,a]=this.tzComponents();return`${t} GMT${n}${r}${a} (${Se(this.timeZone,this)})`}toLocaleString(t,n){return Date.prototype.toLocaleString.call(this,t,{...n,timeZone:(n==null?void 0:n.timeZone)||this.timeZone})}toLocaleDateString(t,n){return Date.prototype.toLocaleDateString.call(this,t,{...n,timeZone:(n==null?void 0:n.timeZone)||this.timeZone})}toLocaleTimeString(t,n){return Date.prototype.toLocaleTimeString.call(this,t,{...n,timeZone:(n==null?void 0:n.timeZone)||this.timeZone})}tzComponents(){const t=this.getTimezoneOffset(),n=t>0?"-":"+",r=String(Math.floor(Math.abs(t)/60)).padStart(2,"0"),a=String(Math.abs(t)%60).padStart(2,"0");return[n,r,a]}withTimeZone(t){return new x(+this,t)}[Symbol.for("constructDateFrom")](t){return new x(+new Date(t),this.timeZone)}}function Se(e,t){return new Intl.DateTimeFormat("en-GB",{timeZone:e,timeZoneName:"long"}).format(t).slice(12)}window.pktTz=window.pktTz===void 0?"Europe/Oslo":window.pktTz;const ve=(e=window.pktTz)=>{const t=new x(new Date().toISOString(),e);return t.setHours(0,0,0,0),isNaN(t.getTime())?new Date:new Date(t.getFullYear(),t.getMonth(),t.getDate())};function T(e){if(!e||e==="")return new Date;if(/^\d{4}-\d{2}-\d{2}$/.test(e)){const[t,n,r]=e.split("-").map(Number);return new Date(t,n-1,r)}if(/^\d{4}-\d{2}$/.test(e)){const[t,n]=e.split("-").map(Number);return new Date(t,n-1,1)}return/^\d{4}$/.test(e)?new Date(Number(e),0,1):new Date(e)}const y=e=>{if(!e||isNaN(e.getTime()))return"";const t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return`${t}-${n}-${r}`},$=e=>{if(!e)return null;const t=T(e);return isNaN(t.getTime())?null:t},Me=(e,t)=>{const n=C(e);return isNaN(n.getTime())?"":pe(n,t)},C=(e="",t)=>{const n=typeof e=="string"?T(e):e;return!n||isNaN(n.getTime())?new Date:n},M=(e,t,n=1)=>{if(typeof e!="number"||typeof t!="number"||typeof n!="number"||isNaN(e)||isNaN(t)||isNaN(n))return new Date;const r=new Date(e,t,n);return isNaN(r.getTime())?new Date:r},W=e=>{let t;return typeof e=="number"?t=new x(e,window.pktTz):t=new x(e,window.pktTz),t.setHours(12,0,0,0),t},xe=e=>!e||isNaN(e.getTime())?"":new Intl.DateTimeFormat("no",{dateStyle:"full",timeZone:window.pktTz}).format(e),Te=(e,t,n)=>{if(!e||isNaN(e.getTime()))return!1;const r=t?C(t):null,a=n?C(n):null;return!(r&&e<r||a&&e>a)},Pe=(e,t)=>{if(!e||isNaN(e.getTime())||!Array.isArray(t))return!1;const n=y(e);return t.includes(n)},Oe=(e,t)=>{if(!e||isNaN(e.getTime())||!Array.isArray(t))return!1;const n=e.getDay().toString();return t.includes(n)},ht=(e,t,n,r,a)=>!(!e||isNaN(e.getTime())||!Te(e,t,n)||r&&Pe(e,r)||a&&Oe(e,a)),Ce=(e,t,n,r,a)=>e.filter(s=>{const i=$(s);return i&&ht(i,t,n,r,a)}),Ne=e=>e.slice().sort((t,n)=>{const r=$(t),a=$(n);return!r||!a?0:r.getTime()-a.getTime()}),$e=(e,t)=>{const n=$(e),r=$(t);return!n||!r?!1:n<=r},dt=e=>{if(Array.isArray(e))return e;if(typeof e=="string")return e.split(",")},_e=e=>e?T(e):null,Ee=e=>{if(typeof e=="string")return e.split(",").map(t=>T(t));if(Array.isArray(e))return e.map(t=>T(t))},I={csvToArray:dt,stringToDate:_e,stringsToDate:Ee},We={earliest:{default:null},latest:{default:null},weeknumbers:{default:!1},withcontrols:{default:!1},multiple:{default:!1},maxMultiple:{default:4},range:{default:!1}},P={props:We};var Ye=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,d=(e,t,n,r)=>{for(var a=r>1?void 0:r?Ae(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(a=(r?i(t,n,a):i(a))||a);return r&&a&&Ye(t,n,a),a};exports.PktCalendar=class extends c.PktElement{constructor(){super(...arguments),this.multiple=P.props.multiple.default,this.maxMultiple=P.props.maxMultiple.default,this.range=P.props.range.default,this.weeknumbers=P.props.weeknumbers.default,this.withcontrols=P.props.withcontrols.default,this.selected=[],this.earliest=P.props.earliest.default,this.latest=P.props.latest.default,this.excludedates=[],this.excludeweekdays=[],this.currentmonth=null,this.dayStrings=this.strings.dates.daysShort,this.dayStringsLong=this.strings.dates.days,this.monthStrings=this.strings.dates.months,this.weekString=this.strings.dates.week,this.prevMonthString=this.strings.dates.prevMonth,this.nextMonthString=this.strings.dates.nextMonth,this._selected=[],this.year=0,this.month=0,this.week=0,this.rangeHovered=null,this.inRange={},this.focusedDate=null,this.selectableDates=[],this.currentmonthtouched=!1,this.tabIndexSet=0}connectedCallback(){super.connectedCallback()}disconnectedCallback(){this.removeEventListener("keydown",this.handleKeydown),super.disconnectedCallback()}attributeChangedCallback(t,n,r){t==="selected"&&r&&this.convertSelected(),super.attributeChangedCallback(t,n,r)}updated(t){super.updated(t),t.has("selected")&&this.convertSelected()}firstUpdated(t){this.addEventListener("keydown",this.handleKeydown)}convertSelected(){if(typeof this.selected=="string"&&(this.selected=this.selected.split(",")),this.selected.length===1&&this.selected[0]===""&&(this.selected=[]),this._selected=this.selected.map(t=>T(t)),this.range&&this.selected.length===2){const t=B({start:this._selected[0],end:this._selected[1]});if(this.inRange={},Array.isArray(t)&&t.length){const n={};for(let r=0;r<t.length;r++){const a=t[r],s=a>this._selected[0]&&a<this._selected[1];n[y(a)]=s}this.inRange=n}}this.setCurrentMonth()}setCurrentMonth(){if(this.currentmonth===null&&!this.currentmonthtouched&&(this.currentmonthtouched=!0),this.selected.length&&this.selected[0]!==""){const t=T(this.selected[this.selected.length-1]);this.currentmonth=isNaN(t.getTime())?W(new Date):t}else this.currentmonth===null&&(this.currentmonth=W(new Date));(!this.currentmonth||isNaN(this.currentmonth.getTime()))&&(this.currentmonth=W(new Date)),this.year=this.currentmonth.getFullYear(),this.month=this.currentmonth.getMonth()}handleKeydown(t){switch(t.key){case"ArrowLeft":this.handleArrowKey(t,-1);break;case"ArrowRight":this.handleArrowKey(t,1);break;case"ArrowUp":this.handleArrowKey(t,-7);break;case"ArrowDown":this.handleArrowKey(t,7);break}}handleArrowKey(t,n){var s,i,l,o,h;if(((s=t.target)==null?void 0:s.nodeName)==="INPUT"||((i=t.target)==null?void 0:i.nodeName)==="SELECT"||((l=t.target)==null?void 0:l.nodeName)==="BUTTON"&&!((h=(o=t.target)==null?void 0:o.dataset)!=null&&h.date))return;t.preventDefault(),this.focusedDate||this.focusOnCurrentDate();const r=this.focusedDate?C(this.focusedDate):M(this.year,this.month,1);let a=U(r,n);if(a){let f=this.querySelector(`button[data-date="${y(a)}"]`);if(f instanceof HTMLButtonElement){if(f.dataset.disabled){a=U(a,n);let m=this.querySelector(`button[data-date="${y(a)}"]`);for(;m&&m instanceof HTMLButtonElement&&m.dataset.disabled;)a=U(a,n),m=this.querySelector(`button[data-date="${y(a)}"]`);f=m}f instanceof HTMLButtonElement&&!f.dataset.disabled&&(this.focusedDate=y(a),f.focus())}}}render(){return c.x`
|
|
2
|
+
<div
|
|
3
|
+
class="pkt-calendar ${this.weeknumbers?"pkt-cal-weeknumbers":""}"
|
|
4
|
+
@focusout=${this.closeEvent}
|
|
5
|
+
@keydown=${t=>{t.key==="Escape"&&(t.preventDefault(),this.close())}}
|
|
6
|
+
>
|
|
7
|
+
<nav class="pkt-cal-month-nav">
|
|
8
|
+
<div>
|
|
9
|
+
<button
|
|
10
|
+
type="button"
|
|
11
|
+
aria-label="${this.prevMonthString}"
|
|
12
|
+
@click=${()=>this.isPrevMonthAllowed()&&this.prevMonth()}
|
|
13
|
+
@keydown=${t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),this.isPrevMonthAllowed()&&this.prevMonth())}}
|
|
14
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only pkt-calendar__prev-month ${this.isPrevMonthAllowed()?"":"pkt-hide"}"
|
|
15
|
+
.data-disabled=${this.isPrevMonthAllowed()?c.E:"disabled"}
|
|
16
|
+
?aria-disabled=${!this.isPrevMonthAllowed()}
|
|
17
|
+
tabindex=${this.isPrevMonthAllowed()?"0":"-1"}
|
|
18
|
+
>
|
|
19
|
+
<pkt-icon class="pkt-btn__icon" name="chevron-thin-left"></pkt-icon>
|
|
20
|
+
<span class="pkt-btn__text">${this.prevMonthString}</span>
|
|
21
|
+
</button>
|
|
22
|
+
</div>
|
|
23
|
+
${this.renderMonthNav()}
|
|
24
|
+
<div>
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
aria-label="${this.nextMonthString}"
|
|
28
|
+
@click=${()=>this.isNextMonthAllowed()&&this.nextMonth()}
|
|
29
|
+
@keydown=${t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),this.isNextMonthAllowed()&&this.nextMonth())}}
|
|
30
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only pkt-calendar__next-month ${this.isNextMonthAllowed()?"":"pkt-hide"}"
|
|
31
|
+
.data-disabled=${this.isNextMonthAllowed()?c.E:"disabled"}
|
|
32
|
+
?aria-disabled=${!this.isNextMonthAllowed()}
|
|
33
|
+
tabindex=${this.isNextMonthAllowed()?"0":"-1"}
|
|
34
|
+
>
|
|
35
|
+
<pkt-icon class="pkt-btn__icon" name="chevron-thin-right"></pkt-icon>
|
|
36
|
+
<span class="pkt-btn__text">${this.nextMonthString}</span>
|
|
37
|
+
</button>
|
|
38
|
+
</div>
|
|
39
|
+
</nav>
|
|
40
|
+
<table
|
|
41
|
+
class="pkt-cal-days pkt-txt-12-medium pkt-calendar__body"
|
|
42
|
+
role="grid"
|
|
43
|
+
?aria-multiselectable=${this.range||this.multiple}
|
|
44
|
+
>
|
|
45
|
+
<thead>
|
|
46
|
+
${this.renderDayNames()}
|
|
47
|
+
</thead>
|
|
48
|
+
<tbody>
|
|
49
|
+
${this.renderCalendarBody()}
|
|
50
|
+
</tbody>
|
|
51
|
+
</table>
|
|
52
|
+
</div>
|
|
53
|
+
`}renderDayNames(){const t=[];this.weeknumbers&&t.push(c.x`<th><div class="pkt-calendar__week-number">${this.weekString}</div></th>`);for(let n=0;n<this.dayStrings.length;n++)t.push(c.x`<th>
|
|
54
|
+
<div class="pkt-calendar__day-name" aria-label="${this.dayStringsLong[n]}">
|
|
55
|
+
${this.dayStrings[n]}
|
|
56
|
+
</div>
|
|
57
|
+
</th>`);return c.x`<tr class="pkt-cal-week-row">
|
|
58
|
+
${t}
|
|
59
|
+
</tr>`}renderMonthNav(){let t=[];return this.withcontrols?t.push(c.x`<div class="pkt-cal-month-picker">
|
|
60
|
+
<label for="${this.id}-monthnav" class="pkt-hide">${this.strings.dates.month}</label>
|
|
61
|
+
<select
|
|
62
|
+
aria-label="${this.strings.dates.month}"
|
|
63
|
+
class="pkt-input pkt-input-compact"
|
|
64
|
+
id="${this.id}-monthnav"
|
|
65
|
+
@change=${n=>{n.stopImmediatePropagation(),this.changeMonth(this.year,n.target.value)}}
|
|
66
|
+
>
|
|
67
|
+
${this.monthStrings.map((n,r)=>c.x`<option value=${r} ?selected=${this.month===r}>${n}</option>`)}
|
|
68
|
+
</select>
|
|
69
|
+
<label for="${this.id}-yearnav" class="pkt-hide">${this.strings.dates.year}</label>
|
|
70
|
+
<input
|
|
71
|
+
aria-label="${this.strings.dates.year}"
|
|
72
|
+
class="pkt-input pkt-cal-input-year pkt-input-compact"
|
|
73
|
+
id="${this.id}-yearnav"
|
|
74
|
+
type="number"
|
|
75
|
+
size="4"
|
|
76
|
+
placeholder="0000"
|
|
77
|
+
@change=${n=>{n.stopImmediatePropagation(),this.changeMonth(n.target.value,this.month)}}
|
|
78
|
+
.value=${this.year}
|
|
79
|
+
/>
|
|
80
|
+
</div> `):t.push(c.x`<div class="pkt-txt-16-medium pkt-calendar__month-title" aria-live="polite">
|
|
81
|
+
${this.monthStrings[this.month]} ${this.year}
|
|
82
|
+
</div>`),t}renderDayView(t,n){var w;const r=M(this.year,this.month,t),a=y(r),s=a===y(n),i=this.selected.includes(a),l=xe(r),o=this.isExcluded(r)||!i&&this.multiple&&this.maxMultiple>0&&this.selected.length>=this.maxMultiple,h=this.focusedDate?this.focusedDate===a&&!o?"0":"-1":!o&&this.tabIndexSet===0||this.tabIndexSet===t?"0":"-1";h==="0"&&(this.tabIndexSet=t),this.selectableDates.push({currentDateISO:a,isDisabled:o,tabindex:h});const f={"pkt-cal-today":s,"pkt-cal-selected":i,"pkt-cal-in-range":this.inRange[a],"pkt-cal-excluded":this.isExcluded(r),"pkt-cal-in-range-first":this.range&&(this.selected.length===2||this.rangeHovered!==null)&&a===this.selected[0],"pkt-cal-in-range-last":this.range&&this.selected.length===2&&a===this.selected[1],"pkt-cal-range-hover":this.rangeHovered!==null&&a===y(this.rangeHovered)},m={"pkt-calendar__date":!0,"pkt-calendar__date--today":s,"pkt-calendar__date--selected":i,"pkt-calendar__date--disabled":o,"pkt-calendar__date--in-range":this.inRange[a],"pkt-calendar__date--in-range-hover":this.rangeHovered!==null&&a===y(this.rangeHovered),"pkt-calendar__date--range-start":this.range&&(this.selected.length===2||this.rangeHovered!==null)&&a===this.selected[0],"pkt-calendar__date--range-end":this.range&&this.selected.length===2&&a===this.selected[1]};return c.x`<td class=${G.e(f)}>
|
|
83
|
+
<button
|
|
84
|
+
type="button"
|
|
85
|
+
aria-pressed=${i?"true":"false"}
|
|
86
|
+
?disabled=${o}
|
|
87
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only ${G.e(m)}"
|
|
88
|
+
@mouseover=${()=>this.range&&!this.isExcluded(r)&&this.handleRangeHover(r)}
|
|
89
|
+
@focus=${()=>{this.range&&!this.isExcluded(r)&&this.handleRangeHover(r),this.focusedDate=a}}
|
|
90
|
+
aria-label="${l}"
|
|
91
|
+
tabindex=${(w=this.selectableDates.find(g=>g.currentDateISO===a))==null?void 0:w.tabindex}
|
|
92
|
+
data-disabled=${o?"disabled":c.E}
|
|
93
|
+
data-date=${a}
|
|
94
|
+
@keydown=${g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),this.handleDateSelect(r))}}
|
|
95
|
+
@click=${g=>{o||(g.preventDefault(),this.handleDateSelect(r))}}
|
|
96
|
+
>
|
|
97
|
+
<span class="pkt-btn__text pkt-txt-14-light">${t}</span>
|
|
98
|
+
</button>
|
|
99
|
+
</td>`}renderCalendarBody(){const t=ve(),n=M(this.year,this.month,1),r=M(this.year,this.month+1,0),a=(n.getDay()+6)%7,s=r.getDate(),i=Math.ceil((s+a)/7),o=M(this.year,this.month,0).getDate();let h=1;this.week=ct(M(this.year,this.month,1));const f=[];for(let m=0;m<i;m++){const w=[];this.weeknumbers&&w.push(c.x`<td class="pkt-cal-week">${this.week}</td>`),this.week++;for(let g=1;g<8;g++)if(m===0&&g<a+1){const p=o-(a-g);w.push(c.x`<td class="pkt-cal-other">
|
|
100
|
+
<div
|
|
101
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
102
|
+
data-disabled="disabled"
|
|
103
|
+
>
|
|
104
|
+
<span class="pkt-btn__text pkt-txt-14-light">${p}</span>
|
|
105
|
+
</div>
|
|
106
|
+
</td>`)}else h>s?(w.push(c.x`<td class="pkt-cal-other">
|
|
107
|
+
<div
|
|
108
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
109
|
+
data-disabled="disabled"
|
|
110
|
+
>
|
|
111
|
+
<span class="pkt-btn__text pkt-txt-14-light">${h-s}</span>
|
|
112
|
+
</div>
|
|
113
|
+
</td>`),h++):(w.push(this.renderDayView(h,t)),h++);f.push(c.x`<tr class="pkt-cal-week-row" role="row">
|
|
114
|
+
${w}
|
|
115
|
+
</tr>`)}return f}isExcluded(t){const n=this.excludedates.map(r=>typeof r=="string"?r:y(r));return!ht(t,this.earliest,this.latest,n,this.excludeweekdays)}isPrevMonthAllowed(){const t=M(this.year,this.month,0);return!(this.earliest&&C(this.earliest)>t)}prevMonth(){const t=this.month===0?11:this.month-1,n=this.month===0?this.year-1:this.year;this.changeMonth(n,t)}isNextMonthAllowed(){const t=M(this.month===11?this.year+1:this.year,this.month===11?0:this.month+1,1);return!(this.latest&&C(this.latest)<t)}nextMonth(){const t=this.month===11?0:this.month+1,n=this.month===11?this.year+1:this.year;this.changeMonth(n,t)}changeMonth(t,n){this.year=typeof t=="string"?parseInt(t):t,this.month=typeof n=="string"?parseInt(n):n,this.currentmonth=W(new Date(this.year,this.month,1)),this.tabIndexSet=0,this.focusedDate=null,this.selectableDates=[]}isRangeAllowed(t){let n=!0;if(this._selected.length===1){const r=B({start:this._selected[0],end:t});if(Array.isArray(r)&&r.length)for(let a=0;a<r.length;a++)this.excludedates.forEach(s=>{s>this._selected[0]&&s<t&&(n=!1)}),this.excludeweekdays.includes(be(r[a]).toString())&&(n=!1)}return n}emptySelected(){this.selected=[],this._selected=[],this.inRange={}}addToSelected(t){this.selected.includes(y(t))||(this.selected=[...this.selected,y(t)],this._selected=[...this._selected,t],this.range&&this.selected.length===2&&(this.convertSelected(),this.close()))}removeFromSelected(t){if(this.selected.length===1)this.emptySelected();else{const n=this.selected.indexOf(y(t)),r=[...this.selected],a=[...this._selected];r.splice(n,1),a.splice(n,1),this.selected=r,this._selected=a}}toggleSelected(t){const n=y(t);this.selected.includes(n)?this.removeFromSelected(t):this.maxMultiple&&this.selected.length>=this.maxMultiple||this.addToSelected(t)}handleRangeSelect(t){const n=y(t);return this.selected.includes(n)?this.selected.indexOf(n)===0?this.emptySelected():this.removeFromSelected(t):this.selected.length>1?(this.emptySelected(),this.addToSelected(t)):(this.selected.length===1&&!this.isRangeAllowed(t)&&this.emptySelected(),this.selected.length===1&&this._selected[0]>t&&this.emptySelected(),this.addToSelected(t)),Promise.resolve()}handleRangeHover(t){if(this.range&&this._selected.length===1&&this.isRangeAllowed(t)&&this._selected[0]<t){this.rangeHovered=t,this.inRange={};const n=B({start:this._selected[0],end:t});if(Array.isArray(n)&&n.length)for(let r=0;r<n.length;r++){const a=n[r],s=a>this._selected[0]&&a<t;this.inRange[y(a)]=s}}else this.rangeHovered=null}handleDateSelect(t){if(t)return this.range?this.handleRangeSelect(t):this.multiple?this.toggleSelected(t):(this.selected.includes(y(t))?this.emptySelected():(this.emptySelected(),this.addToSelected(t)),this.close()),this.dispatchEvent(new CustomEvent("date-selected",{detail:this.selected,bubbles:!0,composed:!0})),Promise.resolve()}focusOnCurrentDate(){const t=y(W(new Date)),n=this.querySelector(`button[data-date="${t}"]`);if(n instanceof HTMLButtonElement)this.focusedDate=t,n.focus();else{const r=this.selectableDates.find(a=>!a.isDisabled);if(r){const a=this.querySelector(`button[data-date="${r.currentDateISO}"]`);a instanceof HTMLButtonElement&&(this.focusedDate=r.currentDateISO,a.focus())}}}closeEvent(t){!this.contains(t.relatedTarget)&&!t.target.classList.contains("pkt-hide")&&this.close()}close(){this.dispatchEvent(new CustomEvent("close",{detail:!0,bubbles:!0,composed:!0}))}};d([c.n({type:Boolean})],exports.PktCalendar.prototype,"multiple",2);d([c.n({type:Number})],exports.PktCalendar.prototype,"maxMultiple",2);d([c.n({type:Boolean})],exports.PktCalendar.prototype,"range",2);d([c.n({type:Boolean})],exports.PktCalendar.prototype,"weeknumbers",2);d([c.n({type:Boolean})],exports.PktCalendar.prototype,"withcontrols",2);d([c.n({converter:I.csvToArray})],exports.PktCalendar.prototype,"selected",2);d([c.n({type:String})],exports.PktCalendar.prototype,"earliest",2);d([c.n({type:String})],exports.PktCalendar.prototype,"latest",2);d([c.n({converter:I.stringsToDate})],exports.PktCalendar.prototype,"excludedates",2);d([c.n({converter:I.csvToArray})],exports.PktCalendar.prototype,"excludeweekdays",2);d([c.n({converter:I.stringToDate})],exports.PktCalendar.prototype,"currentmonth",2);d([c.n({type:Array})],exports.PktCalendar.prototype,"dayStrings",2);d([c.n({type:Array})],exports.PktCalendar.prototype,"dayStringsLong",2);d([c.n({type:Array})],exports.PktCalendar.prototype,"monthStrings",2);d([c.n({type:String})],exports.PktCalendar.prototype,"weekString",2);d([c.n({type:String})],exports.PktCalendar.prototype,"prevMonthString",2);d([c.n({type:String})],exports.PktCalendar.prototype,"nextMonthString",2);d([c.n({type:Array})],exports.PktCalendar.prototype,"_selected",2);d([c.n({type:Number})],exports.PktCalendar.prototype,"year",2);d([c.n({type:Number})],exports.PktCalendar.prototype,"month",2);d([c.n({type:Number})],exports.PktCalendar.prototype,"week",2);d([c.n({type:Date})],exports.PktCalendar.prototype,"rangeHovered",2);d([H.r()],exports.PktCalendar.prototype,"inRange",2);d([H.r()],exports.PktCalendar.prototype,"focusedDate",2);d([H.r()],exports.PktCalendar.prototype,"selectableDates",2);d([H.r()],exports.PktCalendar.prototype,"currentmonthtouched",2);d([H.r()],exports.PktCalendar.prototype,"tabIndexSet",2);exports.PktCalendar=d([c.t("pkt-calendar")],exports.PktCalendar);exports.converters=I;exports.csvToArray=dt;exports.filterSelectableDates=Ce;exports.formatISODate=y;exports.fromISOToDate=$;exports.fromISOtoLocal=Me;exports.isValidDateRange=$e;exports.newDate=C;exports.parseISODateString=T;exports.sortDateStrings=Ne;
|