@oslokommune/punkt-elements 14.0.2 → 14.0.4
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-BtShW7ER.cjs +90 -0
- package/dist/{calendar-Bz27nuTP.js → calendar-yxjSI4wd.js} +766 -682
- package/dist/datepicker-D0q75U1Z.js +1463 -0
- package/dist/datepicker-DDV382Uu.cjs +271 -0
- package/dist/index.d.ts +118 -83
- 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 +2 -2
- package/dist/pkt-index.cjs +1 -1
- package/dist/pkt-index.js +3 -3
- package/package.json +4 -4
- package/src/components/calendar/calendar.ts +372 -414
- package/src/components/calendar/helpers/calendar-grid.ts +93 -0
- package/src/components/calendar/helpers/date-validation.ts +86 -0
- package/src/components/calendar/helpers/index.ts +49 -0
- package/src/components/calendar/helpers/keyboard-navigation.ts +54 -0
- package/src/components/calendar/helpers/selection-manager.ts +184 -0
- package/src/components/datepicker/datepicker-base.ts +151 -0
- package/src/components/datepicker/datepicker-multiple.ts +7 -114
- package/src/components/datepicker/datepicker-range.ts +21 -141
- package/src/components/datepicker/datepicker-single.ts +7 -115
- package/src/components/datepicker/datepicker-types.ts +56 -0
- package/src/components/datepicker/datepicker-utils.test.ts +730 -0
- package/src/components/datepicker/datepicker-utils.ts +338 -9
- package/src/components/datepicker/datepicker.ts +25 -1
- package/dist/calendar-Dz1Cnzx5.cjs +0 -115
- package/dist/datepicker-CnCOXI2x.cjs +0 -289
- package/dist/datepicker-DsqM01iU.js +0 -1355
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ og skriver commits ca etter [Conventional Commits](https://conventionalcommits.o
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [14.0.3](https://github.com/oslokommune/punkt/compare/14.0.2...14.0.3) (2026-02-03)
|
|
9
|
+
|
|
10
|
+
### ⚠ BREAKING CHANGES
|
|
11
|
+
Ingen
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
Ingen
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
Ingen
|
|
18
|
+
|
|
19
|
+
### Chores
|
|
20
|
+
Ingen
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
|
|
8
25
|
## [14.0.0](https://github.com/oslokommune/punkt/compare/13.22.0...14.0.0) (2026-02-02)
|
|
9
26
|
|
|
10
27
|
### ⚠ BREAKING CHANGES
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";const tt=require("./class-map-C_erArZz.cjs"),u=require("./element-CJ_QKaki.cjs"),q=require("./state-DSjcvzDN.cjs");require("./icon-BGuizDwk.cjs");const ht=6048e5,Tt=864e5,et=Symbol.for("constructDateFrom");function k(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&et in e?e[et](t):e instanceof Date?new e.constructor(t):new Date(t)}function b(e,t){return k(t||e,e)}function nt(e,t,n){const r=b(e,n==null?void 0:n.in);return isNaN(t)?k(e,NaN):(t&&r.setDate(r.getDate()+t),r)}let xt={};function B(){return xt}function H(e,t){var o,c,d,f;const n=B(),r=(t==null?void 0:t.weekStartsOn)??((c=(o=t==null?void 0:t.locale)==null?void 0:o.options)==null?void 0:c.weekStartsOn)??n.weekStartsOn??((f=(d=n.locale)==null?void 0:d.options)==null?void 0:f.weekStartsOn)??0,a=b(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 U(e,t){return H(e,{...t,weekStartsOn:1})}function dt(e,t){const n=b(e,t==null?void 0:t.in),r=n.getFullYear(),a=k(n,0);a.setFullYear(r+1,0,4),a.setHours(0,0,0,0);const s=U(a),i=k(n,0);i.setFullYear(r,0,4),i.setHours(0,0,0,0);const o=U(i);return n.getTime()>=s.getTime()?r+1:n.getTime()>=o.getTime()?r:r-1}function rt(e){const t=b(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 ft(e,...t){const n=k.bind(null,t.find(r=>typeof r=="object"));return t.map(n)}function G(e,t){const n=b(e,t==null?void 0:t.in);return n.setHours(0,0,0,0),n}function Ot(e,t,n){const[r,a]=ft(n==null?void 0:n.in,e,t),s=G(r),i=G(a),o=+s-rt(s),c=+i-rt(i);return Math.round((o-c)/Tt)}function Pt(e,t){const n=dt(e,t),r=k(e,0);return r.setFullYear(n,0,4),r.setHours(0,0,0,0),U(r)}function Ct(e){return e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]"}function Nt(e){return!(!Ct(e)&&typeof e!="number"||isNaN(+b(e)))}function $t(e,t){const n=b(e,t==null?void 0:t.in);return n.setHours(23,59,59,999),n}function Et(e,t){const[n,r]=ft(e,t.start,t.end);return{start:n,end:r}}function mt(e,t){const{start:n,end:r}=Et(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 o=1;const c=[];for(;+i<=s;)c.push(k(n,i)),i.setDate(i.getDate()+o),i.setHours(0,0,0,0);return a?c.reverse():c}function Wt(e,t){const n=b(e,t==null?void 0:t.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}const _t={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"}},Yt=(e,t,n)=>{let r;const a=_t[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 Q(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const It={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},Ft={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},At={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},Ht={date:Q({formats:It,defaultWidth:"full"}),time:Q({formats:Ft,defaultWidth:"full"}),dateTime:Q({formats:At,defaultWidth:"full"})},Rt={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},qt=(e,t,n,r)=>Rt[e];function Y(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,o=n!=null&&n.width?String(n.width):i;a=e.formattingValues[o]||e.formattingValues[i]}else{const i=e.defaultWidth,o=n!=null&&n.width?String(n.width):e.defaultWidth;a=e.values[o]||e.values[i]}const s=e.argumentCallback?e.argumentCallback(t):t;return a[s]}}const Lt={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},Ut={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},Bt={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"]},zt={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"]},jt={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"}},Qt={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"}},Xt=(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"},Gt={ordinalNumber:Xt,era:Y({values:Lt,defaultWidth:"wide"}),quarter:Y({values:Ut,defaultWidth:"wide",argumentCallback:e=>e-1}),month:Y({values:Bt,defaultWidth:"wide"}),day:Y({values:zt,defaultWidth:"wide"}),dayPeriod:Y({values:jt,defaultWidth:"wide",formattingValues:Qt,defaultFormattingWidth:"wide"})};function I(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],o=r&&e.parsePatterns[r]||e.parsePatterns[e.defaultParseWidth],c=Array.isArray(o)?Kt(o,y=>y.test(i)):Vt(o,y=>y.test(i));let d;d=e.valueCallback?e.valueCallback(c):c,d=n.valueCallback?n.valueCallback(d):d;const f=t.slice(i.length);return{value:d,rest:f}}}function Vt(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n}function Kt(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n}function Jt(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 o=t.slice(a.length);return{value:i,rest:o}}}const Zt=/^(\d+)(th|st|nd|rd)?/i,te=/\d+/i,ee={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},ne={any:[/^b/i,/^(a|c)/i]},re={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},ae={any:[/1/i,/2/i,/3/i,/4/i]},se={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},ie={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]},oe={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},ce={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]},ue={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},le={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}},he={ordinalNumber:Jt({matchPattern:Zt,parsePattern:te,valueCallback:e=>parseInt(e,10)}),era:I({matchPatterns:ee,defaultMatchWidth:"wide",parsePatterns:ne,defaultParseWidth:"any"}),quarter:I({matchPatterns:re,defaultMatchWidth:"wide",parsePatterns:ae,defaultParseWidth:"any",valueCallback:e=>e+1}),month:I({matchPatterns:se,defaultMatchWidth:"wide",parsePatterns:ie,defaultParseWidth:"any"}),day:I({matchPatterns:oe,defaultMatchWidth:"wide",parsePatterns:ce,defaultParseWidth:"any"}),dayPeriod:I({matchPatterns:ue,defaultMatchWidth:"any",parsePatterns:le,defaultParseWidth:"any"})},de={code:"en-US",formatDistance:Yt,formatLong:Ht,formatRelative:qt,localize:Gt,match:he,options:{weekStartsOn:0,firstWeekContainsDate:1}};function fe(e,t){const n=b(e,t==null?void 0:t.in);return Ot(n,Wt(n))+1}function me(e,t){const n=b(e,t==null?void 0:t.in),r=+U(n)-+Pt(n);return Math.round(r/ht)+1}function gt(e,t){var f,y,w,S;const n=b(e,t==null?void 0:t.in),r=n.getFullYear(),a=B(),s=(t==null?void 0:t.firstWeekContainsDate)??((y=(f=t==null?void 0:t.locale)==null?void 0:f.options)==null?void 0:y.firstWeekContainsDate)??a.firstWeekContainsDate??((S=(w=a.locale)==null?void 0:w.options)==null?void 0:S.firstWeekContainsDate)??1,i=k((t==null?void 0:t.in)||e,0);i.setFullYear(r+1,0,s),i.setHours(0,0,0,0);const o=H(i,t),c=k((t==null?void 0:t.in)||e,0);c.setFullYear(r,0,s),c.setHours(0,0,0,0);const d=H(c,t);return+n>=+o?r+1:+n>=+d?r:r-1}function ge(e,t){var o,c,d,f;const n=B(),r=(t==null?void 0:t.firstWeekContainsDate)??((c=(o=t==null?void 0:t.locale)==null?void 0:o.options)==null?void 0:c.firstWeekContainsDate)??n.firstWeekContainsDate??((f=(d=n.locale)==null?void 0:d.options)==null?void 0:f.firstWeekContainsDate)??1,a=gt(e,t),s=k((t==null?void 0:t.in)||e,0);return s.setFullYear(a,0,r),s.setHours(0,0,0,0),H(s,t)}function yt(e,t){const n=b(e,t==null?void 0:t.in),r=+H(n,t)-+ge(n,t);return Math.round(r/ht)+1}function l(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 l(t==="yy"?r%100:r,t.length)},M(e,t){const n=e.getMonth();return t==="M"?String(n+1):l(n+1,2)},d(e,t){return l(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 l(e.getHours()%12||12,t.length)},H(e,t){return l(e.getHours(),t.length)},m(e,t){return l(e.getMinutes(),t.length)},s(e,t){return l(e.getSeconds(),t.length)},S(e,t){const n=t.length,r=e.getMilliseconds(),a=Math.trunc(r*Math.pow(10,n-3));return l(a,t.length)}},$={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},at={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=gt(e,r),s=a>0?a:1-a;if(t==="YY"){const i=s%100;return l(i,2)}return t==="Yo"?n.ordinalNumber(s,{unit:"year"}):l(s,t.length)},R:function(e,t){const n=dt(e);return l(n,t.length)},u:function(e,t){const n=e.getFullYear();return l(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 l(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 l(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 l(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=yt(e,r);return t==="wo"?n.ordinalNumber(a,{unit:"week"}):l(a,t.length)},I:function(e,t,n){const r=me(e);return t==="Io"?n.ordinalNumber(r,{unit:"week"}):l(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=fe(e);return t==="Do"?n.ordinalNumber(r,{unit:"dayOfYear"}):l(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 l(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 l(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 l(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=$.noon:r===0?a=$.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=$.evening:r>=12?a=$.afternoon:r>=4?a=$.morning:a=$.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"}):l(r,t.length)},k:function(e,t,n){let r=e.getHours();return r===0&&(r=24),t==="ko"?n.ordinalNumber(r,{unit:"hour"}):l(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 it(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 it(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"+st(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"+st(r,":");case"zzzz":default:return"GMT"+O(r,":")}},t:function(e,t,n){const r=Math.trunc(+e/1e3);return l(r,t.length)},T:function(e,t,n){return l(+e,t.length)}};function st(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+l(s,2)}function it(e,t){return e%60===0?(e>0?"-":"+")+l(Math.abs(e)/60,2):O(e,t)}function O(e,t=""){const n=e>0?"-":"+",r=Math.abs(e),a=l(Math.trunc(r/60),2),s=l(r%60,2);return n+a+t+s}const ot=(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"})}},wt=(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"})}},ye=(e,t)=>{const n=e.match(/(P+)(p+)?/)||[],r=n[1],a=n[2];if(!a)return ot(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}}",ot(r,t)).replace("{{time}}",wt(a,t))},we={p:wt,P:ye},pe=/^D+$/,be=/^Y+$/,De=["D","DD","YY","YYYY"];function ke(e){return pe.test(e)}function Se(e){return be.test(e)}function ve(e,t,n){const r=Me(e,t,n);if(console.warn(r),De.includes(e))throw new RangeError(r)}function Me(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 Te=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,xe=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Oe=/^'([^]*?)'?$/,Pe=/''/g,Ce=/[a-zA-Z]/;function Ne(e,t,n){var f,y,w,S;const r=B(),a=r.locale??de,s=r.firstWeekContainsDate??((y=(f=r.locale)==null?void 0:f.options)==null?void 0:y.firstWeekContainsDate)??1,i=r.weekStartsOn??((S=(w=r.locale)==null?void 0:w.options)==null?void 0:S.weekStartsOn)??0,o=b(e,n==null?void 0:n.in);if(!Nt(o))throw new RangeError("Invalid time value");let c=t.match(xe).map(p=>{const g=p[0];if(g==="p"||g==="P"){const _=we[g];return _(p,a.formatLong)}return p}).join("").match(Te).map(p=>{if(p==="''")return{isToken:!1,value:"'"};const g=p[0];if(g==="'")return{isToken:!1,value:$e(p)};if(at[g])return{isToken:!0,value:p};if(g.match(Ce))throw new RangeError("Format string contains an unescaped latin alphabet character `"+g+"`");return{isToken:!1,value:p}});a.localize.preprocessor&&(c=a.localize.preprocessor(o,c));const d={firstWeekContainsDate:s,weekStartsOn:i,locale:a};return c.map(p=>{if(!p.isToken)return p.value;const g=p.value;(Se(g)||ke(g))&&ve(g,t,String(e));const _=at[g[0]];return _(o,g,a.localize,d)}).join("")}function $e(e){const t=e.match(Oe);return t?t[1].replace(Pe,"'"):e}function Ee(e,t){const n=b(e,t==null?void 0:t.in).getDay();return n===0?7:n}function We(e,t,n="long"){return new Intl.DateTimeFormat("en-US",{hour:"numeric",timeZone:e,timeZoneName:n}).format(t).split(/\s/g).slice(2).join(" ")}const X={},A={};function P(e,t){try{const r=(X[e]||(X[e]=new Intl.DateTimeFormat("en-US",{timeZone:e,timeZoneName:"longOffset"}).format))(t).split("GMT")[1];return r in A?A[r]:ct(r,r.split(":"))}catch{if(e in A)return A[e];const n=e==null?void 0:e.match(_e);return n?ct(e,n.slice(1)):NaN}}const _e=/([+-]\d\d):?(\d\d)?/;function ct(e,t){const n=+(t[0]||0),r=+(t[1]||0),a=+(t[2]||0)/60;return A[e]=n*60+r>0?n*60+r+a:n*60-r-a}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(P(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)),pt(this),V(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(){const t=-P(this.timeZone,this);return t>0?Math.floor(t):Math.ceil(t)}setTime(t){return Date.prototype.setTime.apply(this,arguments),V(this),+this}[Symbol.for("constructDateFrom")](t){return new D(+new Date(t),this.timeZone)}}const ut=/^(get|set)(?!UTC)/;Object.getOwnPropertyNames(Date.prototype).forEach(e=>{if(!ut.test(e))return;const t=e.replace(ut,"$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),Ye(this),+this},D.prototype[t]=function(){return Date.prototype[t].apply(this,arguments),V(this),+this}))});function V(e){e.internal.setTime(+e),e.internal.setUTCSeconds(e.internal.getUTCSeconds()-Math.round(-P(e.timeZone,e)*60))}function Ye(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()),pt(e)}function pt(e){const t=P(e.timeZone,e),n=t>0?Math.floor(t):Math.ceil(t),r=new Date(+e);r.setUTCHours(r.getUTCHours()-1);const a=-new Date(+e).getTimezoneOffset(),s=-new Date(+r).getTimezoneOffset(),i=a-s,o=Date.prototype.getHours.apply(e)!==e.internal.getUTCHours();i&&o&&e.internal.setUTCMinutes(e.internal.getUTCMinutes()+i);const c=a-n;c&&Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+c);const d=new Date(+e);d.setUTCSeconds(0);const f=a>0?d.getSeconds():(d.getSeconds()-60)%60,y=Math.round(-(P(e.timeZone,e)*60))%60;(y||f)&&(e.internal.setUTCSeconds(e.internal.getUTCSeconds()+y),Date.prototype.setUTCSeconds.call(e,Date.prototype.getUTCSeconds.call(e)+y+f));const w=P(e.timeZone,e),S=w>0?Math.floor(w):Math.ceil(w),g=-new Date(+e).getTimezoneOffset()-S,_=S!==n,Z=g-c;if(_&&Z){Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+Z);const z=P(e.timeZone,e),Mt=z>0?Math.floor(z):Math.ceil(z),j=S-Mt;j&&(e.internal.setUTCMinutes(e.internal.getUTCMinutes()+j),Date.prototype.setUTCMinutes.call(e,Date.prototype.getUTCMinutes.call(e)+j))}}class M extends D{static tz(t,...n){return n.length?new M(...n,t):new M(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} (${We(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 M(+this,t)}[Symbol.for("constructDateFrom")](t){return new M(+new Date(t),this.timeZone)}}window.pktTz=window.pktTz===void 0?"Europe/Oslo":window.pktTz;const Ie=(e=window.pktTz)=>{const t=new M(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 m=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}`},W=e=>{if(!e)return null;const t=T(e);return isNaN(t.getTime())?null:t},Fe=(e,t)=>{const n=N(e);return isNaN(n.getTime())?"":Ne(n,t)},N=(e="",t)=>{const n=typeof e=="string"?T(e):e;return!n||isNaN(n.getTime())?new Date:t?t==="end"?$t(n):G(n):n},C=(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},F=e=>{let t;return typeof e=="number"?t=new M(e,window.pktTz):t=new M(e,window.pktTz),t.setHours(12,0,0,0),t},Ae=e=>!e||isNaN(e.getTime())?"":new Intl.DateTimeFormat("no",{dateStyle:"full",timeZone:window.pktTz}).format(e),He=(e,t,n)=>{if(!e||isNaN(e.getTime()))return!1;const r=t?N(t):null,a=n?N(n):null;return!(r&&e<r||a&&e>a)},Re=(e,t)=>{if(!e||isNaN(e.getTime())||!Array.isArray(t))return!1;const n=m(e);return t.includes(n)},qe=(e,t)=>{if(!e||isNaN(e.getTime())||!Array.isArray(t))return!1;const n=e.getDay().toString();return t.includes(n)},bt=(e,t,n,r,a)=>!(!e||isNaN(e.getTime())||!He(e,t,n)||r&&Re(e,r)||a&&qe(e,a)),Le=(e,t,n,r,a)=>e.filter(s=>{const i=W(s);return i&&bt(i,t,n,r,a)}),Ue=e=>e.slice().sort((t,n)=>{const r=W(t),a=W(n);return!r||!a?0:r.getTime()-a.getTime()}),Be=(e,t)=>{const n=W(e),r=W(t);return!n||!r?!1:n<=r},Dt=e=>e?Array.isArray(e)?e.filter(Boolean):String(e).split(",").map(t=>t.trim()).filter(Boolean):[],ze=e=>e.join(","),kt=e=>Dt(e),je=e=>e?T(e):null,Qe=e=>{if(typeof e=="string")return e.split(",").map(t=>T(t));if(Array.isArray(e))return e.map(t=>T(t))},L={csvToArray:kt,stringToDate:je,stringsToDate:Qe},Xe={earliest:{default:null},latest:{default:null},weeknumbers:{default:!1},withcontrols:{default:!1},multiple:{default:!1},maxMultiple:{default:4},range:{default:!1}},x={props:Xe};function St(e,t){const n=t.excludedates.map(r=>typeof r=="string"?r:m(r));return!bt(e,t.earliest,t.latest,n,t.excludeweekdays)}function Ge(e,t,n,r){return!!(St(e,n)||!t&&r.multiple&&r.maxMultiple>0&&r.selectedCount>=r.maxMultiple)}function Ve(e,t,n){const r=C(e,t,0);return!(n&&N(n)>r)}function Ke(e,t,n){const r=C(t===11?e+1:e,t===11?0:t+1,1);return!(n&&N(n)<r)}const R=7,Je=6;function Ze(e,t){const n=C(e,t,1),r=C(e,t+1,0),a=(n.getDay()+Je)%R,s=r.getDate(),i=Math.ceil((s+a)/R),c=C(e,t,0).getDate(),d=yt(n);return{firstDayOfMonth:n,lastDayOfMonth:r,startingDay:a,numDays:s,numRows:i,numDaysPrevMonth:c,initialWeek:d}}function tn(e,t,n,r){const{startingDay:a,numDays:s}=r;return e===0&&t<a?"prev-month":n>s?"next-month":"current-month"}function en(e,t,n,r){const{startingDay:a,numDaysPrevMonth:s,numDays:i}=r;return e==="prev-month"?s-(a-t-1):e==="next-month"?n-i:n}function E(e){return typeof e=="string"&&(e=e.split(",")),e.length===1&&e[0]===""?[]:e.map(t=>T(t))}function lt(e,t){const n=mt({start:e,end:t}),r={};if(Array.isArray(n)&&n.length)for(let a=0;a<n.length;a++){const s=n[a],i=s>e&&s<t;r[m(s)]=i}return r}function vt(e,t,n,r){if(t.length!==1)return!0;const a=mt({start:t[0],end:e});if(!Array.isArray(a)||!a.length)return!0;for(let s=0;s<a.length;s++){for(const i of n)if(i>t[0]&&i<e)return!1;if(r.includes(Ee(a[s]).toString()))return!1}return!0}function K(e,t){const n=m(e);return t.includes(n)?t:[...t,n]}function J(e,t){const n=m(e),r=t.indexOf(n);if(r===-1)return t;if(t.length===1)return[];const a=[...t];return a.splice(r,1),a}function nn(e,t,n){const r=m(e);return t.includes(r)?J(e,t):n>0&&t.length>=n?t:K(e,t)}function rn(e,t,n){const r=m(e),a=E(t);if(t.includes(r))return t.indexOf(r)===0?[]:J(e,t);if(t.length>1)return[r];if(t.length===1){if(!vt(e,a,n.excludedates,n.excludeweekdays))return[r];if(a[0]>e)return[r]}return K(e,t)}const an={ArrowLeft:-1,ArrowRight:1,ArrowUp:-R,ArrowDown:R};function sn(e){var n;const t=e.nodeName;return t==="INPUT"||t==="SELECT"||t==="BUTTON"&&!((n=e.dataset)!=null&&n.date)}function on(e,t,n){let r=nt(e,t);if(!r)return null;let a=n(`button[data-date="${m(r)}"]`);for(;a instanceof HTMLButtonElement&&a.dataset.disabled;)if(r=nt(r,t),a=n(`button[data-date="${m(r)}"]`),!a)return null;return r}function cn(e){return an[e]??null}var un=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,h=(e,t,n,r)=>{for(var a=r>1?void 0:r?ln(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&&un(t,n,a),a};exports.PktCalendar=class extends u.PktElement{constructor(){super(...arguments),this.selected=[],this.multiple=x.props.multiple.default,this.maxMultiple=x.props.maxMultiple.default,this.range=x.props.range.default,this.earliest=x.props.earliest.default,this.latest=x.props.latest.default,this.excludedates=[],this.excludeweekdays=[],this.weeknumbers=x.props.weeknumbers.default,this.withcontrols=x.props.withcontrols.default,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.inRange={},this.rangeHovered=null,this.year=0,this.month=0,this.week=0,this.currentmonthtouched=!1,this.focusedDate=null,this.selectableDates=[],this.tabIndexSet=0}firstUpdated(t){this.addEventListener("keydown",this.handleKeydown)}disconnectedCallback(){this.removeEventListener("keydown",this.handleKeydown),super.disconnectedCallback()}updated(t){super.updated(t),t.has("selected")&&this.convertSelected()}convertSelected(){typeof this.selected=="string"&&(this.selected=this.selected.split(",")),this.selected.length===1&&this.selected[0]===""&&(this.selected=[]),this._selected=E(this.selected),this.range&&this.selected.length===2&&(this.inRange=lt(this._selected[0],this._selected[1])),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())?F(new Date):t}else this.currentmonth===null&&(this.currentmonth=F(new Date));(!this.currentmonth||isNaN(this.currentmonth.getTime()))&&(this.currentmonth=F(new Date)),this.year=this.currentmonth.getFullYear(),this.month=this.currentmonth.getMonth()}handleKeydown(t){const n=cn(t.key);n!==null&&this.handleArrowKey(t,n)}handleArrowKey(t,n){const r=t.target;if(sn(r))return;if(t.preventDefault(),!this.focusedDate){this.focusOnCurrentDate();return}const a=this.focusedDate?N(this.focusedDate):C(this.year,this.month,1),s=on(a,n,this.querySelector.bind(this));if(s){const i=this.querySelector(`button[data-date="${m(s)}"]`);i instanceof HTMLButtonElement&&!i.dataset.disabled&&(this.focusedDate=m(s),i.focus())}}render(){return u.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
|
+
${this.renderMonthNavButton("prev")}
|
|
9
|
+
${this.renderMonthNav()}
|
|
10
|
+
${this.renderMonthNavButton("next")}
|
|
11
|
+
</nav>
|
|
12
|
+
<table
|
|
13
|
+
class="pkt-cal-days pkt-txt-12-medium pkt-calendar__body"
|
|
14
|
+
role="grid"
|
|
15
|
+
?aria-multiselectable=${this.range||this.multiple}
|
|
16
|
+
>
|
|
17
|
+
<thead>
|
|
18
|
+
${this.renderDayNames()}
|
|
19
|
+
</thead>
|
|
20
|
+
<tbody>
|
|
21
|
+
${this.renderCalendarBody()}
|
|
22
|
+
</tbody>
|
|
23
|
+
</table>
|
|
24
|
+
</div>
|
|
25
|
+
`}renderMonthNavButton(t){const n=t==="prev",r=n?this.isPrevMonthAllowed():this.isNextMonthAllowed(),a=n?this.prevMonthString:this.nextMonthString,s=n?"chevron-thin-left":"chevron-thin-right",i=n?"pkt-calendar__prev-month":"pkt-calendar__next-month",o=n?()=>this.prevMonth():()=>this.nextMonth();return u.x`<div>
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
aria-label="${a}"
|
|
29
|
+
@click=${()=>r&&o()}
|
|
30
|
+
@keydown=${c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),r&&o())}}
|
|
31
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--icon-only ${i} ${r?"":"pkt-hide"}"
|
|
32
|
+
.data-disabled=${r?u.E:"disabled"}
|
|
33
|
+
?aria-disabled=${!r}
|
|
34
|
+
tabindex=${r?"0":"-1"}
|
|
35
|
+
>
|
|
36
|
+
<pkt-icon class="pkt-btn__icon" name="${s}"></pkt-icon>
|
|
37
|
+
<span class="pkt-btn__text">${a}</span>
|
|
38
|
+
</button>
|
|
39
|
+
</div>`}renderDayNames(){const t=[];this.weeknumbers&&t.push(u.x`<th><div class="pkt-calendar__week-number">${this.weekString}</div></th>`);for(let n=0;n<this.dayStrings.length;n++)t.push(u.x`<th>
|
|
40
|
+
<div class="pkt-calendar__day-name" aria-label="${this.dayStringsLong[n]}">
|
|
41
|
+
${this.dayStrings[n]}
|
|
42
|
+
</div>
|
|
43
|
+
</th>`);return u.x`<tr class="pkt-cal-week-row">${t}</tr>`}renderMonthNav(){return this.withcontrols?u.x`<div class="pkt-cal-month-picker">
|
|
44
|
+
<label for="${this.id}-monthnav" class="pkt-hide">${this.strings.dates.month}</label>
|
|
45
|
+
<select
|
|
46
|
+
aria-label="${this.strings.dates.month}"
|
|
47
|
+
class="pkt-input pkt-input-compact"
|
|
48
|
+
id="${this.id}-monthnav"
|
|
49
|
+
@change=${t=>{t.stopImmediatePropagation();const n=t.target;this.changeMonth(this.year,parseInt(n.value))}}
|
|
50
|
+
>
|
|
51
|
+
${this.monthStrings.map((t,n)=>u.x`<option value=${n} ?selected=${this.month===n}>${t}</option>`)}
|
|
52
|
+
</select>
|
|
53
|
+
<label for="${this.id}-yearnav" class="pkt-hide">${this.strings.dates.year}</label>
|
|
54
|
+
<input
|
|
55
|
+
aria-label="${this.strings.dates.year}"
|
|
56
|
+
class="pkt-input pkt-cal-input-year pkt-input-compact"
|
|
57
|
+
id="${this.id}-yearnav"
|
|
58
|
+
type="number"
|
|
59
|
+
size="4"
|
|
60
|
+
placeholder="0000"
|
|
61
|
+
@change=${t=>{t.stopImmediatePropagation();const n=t.target;this.changeMonth(parseInt(n.value),this.month)}}
|
|
62
|
+
.value=${this.year}
|
|
63
|
+
/>
|
|
64
|
+
</div>`:u.x`<div class="pkt-txt-16-medium pkt-calendar__month-title" aria-live="polite">
|
|
65
|
+
${this.monthStrings[this.month]} ${this.year}
|
|
66
|
+
</div>`}getDayViewData(t,n){const r=C(this.year,this.month,t),a=m(r),s=a===m(n),i=this.selected.includes(a),o=this.isDayDisabled(r,i),c=this.calculateTabIndex(a,o,t);return{currentDate:r,currentDateISO:a,isToday:s,isSelected:i,isDisabled:o,ariaLabel:Ae(r),tabindex:c}}getDateConstraints(){return{earliest:this.earliest,latest:this.latest,excludedates:this.excludedates,excludeweekdays:this.excludeweekdays}}isDayDisabled(t,n){return Ge(t,n,this.getDateConstraints(),{multiple:this.multiple,maxMultiple:this.maxMultiple,selectedCount:this.selected.length})}calculateTabIndex(t,n,r){return this.focusedDate?this.focusedDate===t&&!n?"0":"-1":!n&&this.tabIndexSet===0?(this.tabIndexSet=r,"0"):this.tabIndexSet===r?"0":"-1"}getDayCellClasses(t){const{currentDateISO:n,isToday:r,isSelected:a}=t,s=this.range&&(this.selected.length===2||this.rangeHovered!==null)&&n===this.selected[0],i=this.range&&this.selected.length===2&&n===this.selected[1];return{"pkt-cal-today":r,"pkt-cal-selected":a,"pkt-cal-in-range":this.inRange[n],"pkt-cal-excluded":this.isExcluded(t.currentDate),"pkt-cal-in-range-first":s,"pkt-cal-in-range-last":i,"pkt-cal-range-hover":this.rangeHovered!==null&&n===m(this.rangeHovered)}}getDayButtonClasses(t){const{currentDateISO:n,isToday:r,isSelected:a,isDisabled:s}=t,i=this.range&&(this.selected.length===2||this.rangeHovered!==null)&&n===this.selected[0],o=this.range&&this.selected.length===2&&n===this.selected[1];return{"pkt-calendar__date":!0,"pkt-calendar__date--today":r,"pkt-calendar__date--selected":a,"pkt-calendar__date--disabled":s,"pkt-calendar__date--in-range":this.inRange[n],"pkt-calendar__date--in-range-hover":this.rangeHovered!==null&&n===m(this.rangeHovered),"pkt-calendar__date--range-start":i,"pkt-calendar__date--range-end":o}}handleDayFocus(t,n){this.range&&!this.isExcluded(t)&&this.handleRangeHover(t),this.focusedDate=n}renderDayView(t,n){const r=this.getDayViewData(t,n),{currentDate:a,currentDateISO:s,isSelected:i,isDisabled:o,ariaLabel:c,tabindex:d}=r;this.selectableDates.push({currentDateISO:s,isDisabled:o,tabindex:d});const f=this.getDayCellClasses(r),y=this.getDayButtonClasses(r);return u.x`<td class=${tt.e(f)}>
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
aria-pressed=${i?"true":"false"}
|
|
70
|
+
?disabled=${o}
|
|
71
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only ${tt.e(y)}"
|
|
72
|
+
@mouseover=${()=>this.range&&!this.isExcluded(a)&&this.handleRangeHover(a)}
|
|
73
|
+
@focus=${()=>this.handleDayFocus(a,s)}
|
|
74
|
+
aria-label="${c}"
|
|
75
|
+
tabindex=${d}
|
|
76
|
+
data-disabled=${o?"disabled":u.E}
|
|
77
|
+
data-date=${s}
|
|
78
|
+
@keydown=${w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),this.handleDateSelect(a))}}
|
|
79
|
+
@click=${w=>{o||(w.preventDefault(),this.handleDateSelect(a))}}
|
|
80
|
+
>
|
|
81
|
+
<span class="pkt-btn__text pkt-txt-14-light">${t}</span>
|
|
82
|
+
</button>
|
|
83
|
+
</td>`}renderEmptyDayCell(t){return u.x`<td class="pkt-cal-other">
|
|
84
|
+
<div
|
|
85
|
+
class="pkt-btn pkt-btn--tertiary pkt-btn--small pkt-btn--label-only"
|
|
86
|
+
data-disabled="disabled"
|
|
87
|
+
>
|
|
88
|
+
<span class="pkt-btn__text pkt-txt-14-light">${t}</span>
|
|
89
|
+
</div>
|
|
90
|
+
</td>`}renderWeekRow(t){return u.x`<tr class="pkt-cal-week-row" role="row">${t}</tr>`}renderCalendarBody(){const t=Ie(),n=Ze(this.year,this.month);let r=1;this.week=n.initialWeek;const a=[];for(let s=0;s<n.numRows;s++){const i=[];this.weeknumbers&&i.push(u.x`<td class="pkt-cal-week">${this.week}</td>`),this.week++;for(let o=0;o<R;o++){const c=tn(s,o,r,n);if(c==="current-month")i.push(this.renderDayView(r,t)),r++;else{const d=en(c,o,r,n);i.push(this.renderEmptyDayCell(d)),c==="next-month"&&r++}}a.push(this.renderWeekRow(i))}return a}isExcluded(t){return St(t,this.getDateConstraints())}isPrevMonthAllowed(){return Ve(this.year,this.month,this.earliest)}prevMonth(){const t=this.month===0?11:this.month-1,n=this.month===0?this.year-1:this.year;this.changeMonth(n,t)}isNextMonthAllowed(){return Ke(this.year,this.month,this.latest)}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=F(new Date(this.year,this.month,1)),this.tabIndexSet=0,this.focusedDate=null,this.selectableDates=[]}emptySelected(){this.selected=[],this._selected=[],this.inRange={}}normalizeSelected(){return typeof this.selected=="string"?this.selected.split(","):this.selected}addToSelected(t){this.selected=K(t,this.normalizeSelected()),this._selected=E(this.selected),this.range&&this.selected.length===2&&(this.convertSelected(),this.close())}removeFromSelected(t){this.selected=J(t,this.normalizeSelected()),this._selected=E(this.selected)}toggleSelected(t){this.selected=nn(t,this.normalizeSelected(),this.maxMultiple),this._selected=E(this.selected)}isRangeAllowed(t){return vt(t,this._selected,this.excludedates,this.excludeweekdays)}handleRangeSelect(t){return this.selected=rn(t,this.normalizeSelected(),{excludedates:this.excludedates,excludeweekdays:this.excludeweekdays}),this._selected=E(this.selected),this.selected.length===2?this.convertSelected():this.selected.length===1&&(this.inRange={}),Promise.resolve()}handleRangeHover(t){if(!this.range||this._selected.length!==1||!this.isRangeAllowed(t)||this._selected[0]>=t){this.rangeHovered=null;return}this.rangeHovered=t,this.inRange=lt(this._selected[0],t)}handleDateSelect(t){return t&&(this.range?this.handleRangeSelect(t):this.multiple?this.toggleSelected(t):(this.selected.includes(m(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=m(F(new Date)),n=this.querySelector(`button[data-date="${t}"]`);if(n instanceof HTMLButtonElement){this.focusedDate=t,n.focus();return}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}))}};h([u.n({converter:L.csvToArray})],exports.PktCalendar.prototype,"selected",2);h([u.n({type:Boolean})],exports.PktCalendar.prototype,"multiple",2);h([u.n({type:Number})],exports.PktCalendar.prototype,"maxMultiple",2);h([u.n({type:Boolean})],exports.PktCalendar.prototype,"range",2);h([u.n({type:String})],exports.PktCalendar.prototype,"earliest",2);h([u.n({type:String})],exports.PktCalendar.prototype,"latest",2);h([u.n({converter:L.stringsToDate})],exports.PktCalendar.prototype,"excludedates",2);h([u.n({converter:L.csvToArray})],exports.PktCalendar.prototype,"excludeweekdays",2);h([u.n({type:Boolean})],exports.PktCalendar.prototype,"weeknumbers",2);h([u.n({type:Boolean})],exports.PktCalendar.prototype,"withcontrols",2);h([u.n({converter:L.stringToDate})],exports.PktCalendar.prototype,"currentmonth",2);h([u.n({type:Array})],exports.PktCalendar.prototype,"dayStrings",2);h([u.n({type:Array})],exports.PktCalendar.prototype,"dayStringsLong",2);h([u.n({type:Array})],exports.PktCalendar.prototype,"monthStrings",2);h([u.n({type:String})],exports.PktCalendar.prototype,"weekString",2);h([u.n({type:String})],exports.PktCalendar.prototype,"prevMonthString",2);h([u.n({type:String})],exports.PktCalendar.prototype,"nextMonthString",2);h([u.n({type:Array})],exports.PktCalendar.prototype,"_selected",2);h([q.r()],exports.PktCalendar.prototype,"inRange",2);h([u.n({type:Date})],exports.PktCalendar.prototype,"rangeHovered",2);h([u.n({type:Number})],exports.PktCalendar.prototype,"year",2);h([u.n({type:Number})],exports.PktCalendar.prototype,"month",2);h([u.n({type:Number})],exports.PktCalendar.prototype,"week",2);h([q.r()],exports.PktCalendar.prototype,"currentmonthtouched",2);h([q.r()],exports.PktCalendar.prototype,"focusedDate",2);h([q.r()],exports.PktCalendar.prototype,"selectableDates",2);h([q.r()],exports.PktCalendar.prototype,"tabIndexSet",2);exports.PktCalendar=h([u.t("pkt-calendar")],exports.PktCalendar);exports.arrayToCsv=ze;exports.converters=L;exports.csvToArray=kt;exports.filterSelectableDates=Le;exports.formatISODate=m;exports.fromISOToDate=W;exports.fromISOtoLocal=Fe;exports.isValidDateRange=Be;exports.newDate=N;exports.parseISODateString=T;exports.sortDateStrings=Ue;exports.valueToArray=Dt;
|