jb-calendar
Version:
jalali calendar interface web component
2 lines • 38.5 kB
JavaScript
import{getDate as e,getDay as t,getDaysInMonth as a,getMonth as r,getYear as n,isEqual as s}from"date-fns";import{getDate as i,getDay as o,getDaysInMonth as l,getMonth as c,getYear as h,isAfter as d,isBefore as p,newDate as m}from"date-fns-jalali";import{enToFaDigits as y}from"jb-core";function u(e,t,a,r){if("a"===a&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===a?r:"a"===a?r.call(e):r?r.value:t.get(e)}function v(e,t,a,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?n.call(e,a):n?n.value=a:t.set(e,a),a}var b=class{get value(){return`oklch(${this.lightness} ${this.chroma} ${this.hue})`}constructor(e,t){this.variableName=t,this.lightness=e.lightness,this.chroma=e.chroma,this.hue=e.hue}};function w(e){return new b({lightness:6*(3+1.3*e)*.01,chroma:.001*(14+.09*e),hue:258.36},`--jb-neutral-${e}`)}function g(e){return new b({lightness:e.lightness+.07,chroma:e.chroma+.07,hue:e.hue},`${e.variableName}-hover`)}function f(e){return new b({lightness:e.lightness-.1,chroma:e.chroma-.05,hue:e.hue},`${e.variableName}-pressed`)}function x(e){const t=Math.min(e.lightness+.12*(1-e.lightness),.985),a=e.chroma*(1-.15*(t-e.lightness));return new b({lightness:t,chroma:Number(a.toFixed(3)),hue:e.hue},`${e.variableName}-l`)}function j(e){const t=Math.max(e.lightness-.12*e.lightness,.02),a=e.chroma*(1-.15*(t-e.lightness));return new b({lightness:t,chroma:a,hue:e.hue},`${e.variableName}-d`)}function S(e){const t=Math.min(e.lightness+.65*(1-e.lightness),.93),a=.55*e.chroma*(1-.08*(t-e.lightness)),r=e.hue>=70&&e.hue<=162?5:-3,n=e.hue+r;return new b({lightness:t,chroma:Number(a.toFixed(3)),hue:n},`${e.variableName}-subtle`)}function W(e){const t=Math.max(e.lightness-.35,.22),a=Math.min(1.6*e.chroma,.28);return new b({lightness:Number(t.toFixed(3)),chroma:Number(a.toFixed(3)),hue:e.hue},`${e.variableName}-contrast`)}const L=new b({lightness:.6,chroma:.26,hue:256},"--jb-primary"),D=new b({lightness:.6,chroma:.26,hue:286},"--jb-secondary"),M=new b({lightness:.75,chroma:.18,hue:70},"--jb-yellow"),T=new b({lightness:.68,chroma:.1484,hue:162.1},"--jb-green"),k=new b({lightness:.6,chroma:.22,hue:23.21},"--jb-red"),Y={single:{black:new b({lightness:.14,chroma:0,hue:0},"--jb-black"),white:new b({lightness:1,chroma:0,hue:0},"--jb-white"),highlight:new b({lightness:.93,chroma:.2302,hue:125.18},"--jb-highlight")},neutral:[w(0),w(1),w(2),w(3),w(4),w(5),w(6),w(7),w(8),w(9),w(10)],primary:{main:L,hover:g(L),pressed:f(L),light:x(L),dark:j(L),subtle:S(L),contrast:W(L)},secondary:{main:D,hover:g(D),pressed:f(D),light:x(D),dark:j(D),subtle:S(D),contrast:W(D)},yellow:{main:M,hover:g(M),pressed:f(M),light:x(M),dark:j(M),subtle:S(M),contrast:W(M)},green:{main:T,hover:g(T),pressed:f(T),light:x(T),dark:j(T),subtle:S(T),contrast:W(T)},red:{main:k,hover:g(k),pressed:f(k),light:x(k),dark:j(k),subtle:S(k),contrast:W(k)}};function C(e){try{const{value:t,...a}=e;window.CSS.registerProperty({...a}),function(e,t){try{t&&(document.documentElement.style.getPropertyValue(e)||document.documentElement.style.setProperty(e,t))}catch(e){}}(e.name,t)}catch(e){}}function E(){var e;C({name:"--jb-radius",inherits:!0,syntax:"<length-percentage>",value:"1rem",initialValue:"16px"}),C({name:"--jb-radius-xs",inherits:!0,value:"0.5rem",initialValue:"8px",syntax:"<length-percentage>"}),C({name:"--jb-radius-sm",inherits:!0,value:"0.75rem",initialValue:"12px",syntax:"<length-percentage>"}),C({name:"--jb-radius-lg",inherits:!0,value:"1.25rem",initialValue:"20px",syntax:"<length-percentage>"}),C({name:"--jb-radius-xl",inherits:!0,value:"1.5rem",initialValue:"24px",syntax:"<length-percentage>"}),function(e){C({name:e.primary.main.variableName,syntax:"<color>",inherits:!0,initialValue:e.primary.main.value}),C({name:e.secondary.main.variableName,syntax:"<color>",inherits:!0,initialValue:e.secondary.main.value}),C({name:"--jb-neutral",syntax:"<color>",inherits:!0,initialValue:e.neutral[0].value}),C({name:e.single.black.variableName,syntax:"<color>",inherits:!0,initialValue:e.single.black.value}),C({name:e.single.white.variableName,syntax:"<color>",inherits:!0,initialValue:e.single.white.value}),C({name:e.single.highlight.variableName,syntax:"<color>",inherits:!0,initialValue:e.single.highlight.value}),C({name:e.yellow.main.variableName,syntax:"<color>",inherits:!0,initialValue:e.yellow.main.value}),C({name:e.green.main.variableName,syntax:"<color>",inherits:!0,initialValue:e.green.main.value}),C({name:e.red.main.variableName,syntax:"<color>",inherits:!0,initialValue:e.red.main.value}),C({name:"--jb-neutral",syntax:"<color>",inherits:!0,initialValue:e.neutral[0].value});for(let t=1;t<=10;t++)C({name:e.neutral[t].variableName,syntax:"<color>",inherits:!0,initialValue:e.neutral[t].value})}(Y),C({name:"--jb-text-primary",syntax:"<color>",inherits:!0,initialValue:(e=Y).single.black.value}),C({name:"--jb-text-secondary",syntax:"<color>",inherits:!0,initialValue:e.neutral[7].value}),C({name:"--jb-text-contrast",syntax:"<color>",inherits:!0,initialValue:e.single.white.value})}var X,R,N,B,P,H,A,V,$,q,O,z,I,F,J,_,G,Z;const K=["فروردین","اردیبهشت","خرداد","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند"],Q=["January","February","March","April","May","June","July","August","September","October","November","December"],U="JALALI";var ee,te;(te=ee||(ee={})).day="DAY",te.month="MONTH",te.year="YEAR";const ae=new Date;null==HTMLElement&&console.error("you cant render web component on a server side");var re=class extends HTMLElement{setMonthList(e,t){if(Array.isArray(t)&&12==t.length){switch(e){case"JALALI":v(this,A,t.map((e=>e)),"f");break;case"GREGORIAN":v(this,V,t,"f")}u(this,X,"m",I).call(this),u(this,X,"m",O).call(this,this.data.selectedMonth)}else console.error("Invalid Month List",t)}get defaultCalendarData(){return u(this,H,"f")}set defaultCalendarData(e){v(this,H,e,"f")}get value(){return u(this,N,"f")}set value(e){const{year:t,month:a,day:r}=e;if(t&&a&&r){u(this,N,"f").year=t,u(this,N,"f").month=a,u(this,N,"f").day=r,this.data.selectedYear=t,this.data.selectedMonth=a;const e=this.shadowRoot.querySelector(".--selected");if(null!==e&&e.classList.remove("--selected"),this.data.selectedYear==t&&this.data.selectedMonth==a){const e=this.shadowRoot.querySelector(`.day-wrapper[day-number="${r}"]`);e&&e.classList.add("--selected")}}else console.error("Invalid value. please make sure you have year,month and day")}get activeSection(){return u(this,B,"f")||ee.day}set activeSection(e){if(e!=u(this,B,"f")){if(u(this,B,"f")){const e=u(this,B,"f").toLocaleLowerCase();this.elements.selectionSections[e].classList.remove("--show")}"DAY"==e&&(this.elements.selectionSections.day.classList.add("--show"),this.elements.navigatorTitle.month.classList.add("--show"),this.elements.navigatorTitle.year.classList.add("--show"),this.elements.navigatorTitle.yearRange.classList.remove("--show")),"MONTH"==e&&(this.elements.selectionSections.month.classList.add("--show"),this.elements.navigatorTitle.month.classList.remove("--show"),this.elements.navigatorTitle.year.classList.add("--show"),this.elements.navigatorTitle.yearRange.classList.remove("--show")),"YEAR"==e&&(this.elements.selectionSections.year.classList.add("--show"),this.elements.navigatorTitle.month.classList.remove("--show"),this.elements.navigatorTitle.year.classList.remove("--show"),this.elements.navigatorTitle.yearRange.classList.add("--show")),v(this,B,e,"f")}}get inputType(){return u(this,P,"f")}set inputType(e){v(this,P,e,"f"),this.onInputTypeChange()}get showPersianNumber(){return u(this,$,"f")}set showPersianNumber(e){"boolean"==typeof e?(v(this,$,e,"f"),this.setCalendarData()):console.error("showPersianNumber must be boolean")}get cssDirection(){return getComputedStyle(this).direction}get direction(){return u(this,q,"f")?u(this,q,"f"):this.cssDirection}set direction(e){!e||"ltr"!=e&&"rtl"!=e||v(this,q,e,"f"),this.setupStyleBaseOnCssDirection()}constructor(){super(),X.add(this),R.set(this,{daysWrapper:{startX:null,startY:null},yearsWrapper:{startX:null}}),N.set(this,{year:null,month:null,day:null}),B.set(this,null),P.set(this,U),H.set(this,{jalali:{year:h(ae),month:c(ae)+1},gregorian:{year:n(ae),month:r(ae)+1}}),A.set(this,K),V.set(this,Q),this.dateRestrictions=new Proxy({min:null,max:null},this.createDateRestrictionHandler()),this.data=new Proxy({selectedYear:0,selectedMonth:0,yearSelectionRange:[0,0]},this.createDataHandler()),$.set(this,!1),q.set(this,null),this.initWebComponent(),this.initProps(),this.initCalendar()}connectedCallback(){this.callOnLoadEvent(),this.setupStyleBaseOnCssDirection(),this.initCalendarLayout()}initCalendarLayout(){u(this,X,"m",I).call(this),this.fillDayOfWeek(),this.setCalendarData()}setupStyleBaseOnCssDirection(e=this.direction){"ltr"==e?(this.elements.navigatorTitle.nextButton.classList.add("--css-ltr"),this.elements.navigatorTitle.prevButton.classList.add("--css-ltr"),this.elements.monthDayWrapper.next.classList.add("--css-ltr"),this.elements.monthDayWrapper.prev.classList.add("--css-ltr"),this.elements.yearsWrapper.next.classList.add("--css-ltr"),this.elements.yearsWrapper.prev.classList.add("--css-ltr")):"rtl"==e&&(this.elements.navigatorTitle.nextButton.classList.remove("--css-ltr"),this.elements.navigatorTitle.prevButton.classList.remove("--css-ltr"),this.elements.monthDayWrapper.next.classList.remove("--css-ltr"),this.elements.monthDayWrapper.prev.classList.remove("--css-ltr"),this.elements.yearsWrapper.next.classList.remove("--css-ltr"),this.elements.yearsWrapper.prev.classList.remove("--css-ltr"))}fillDayOfWeek(){const e=this.inputType==U?["ش","ی","د","س","چ","پ","ج"]:["Su","Mo","Tu","We","Th","Fr","Sa"];this.elements.dayOfWeekWrapper.innerHTML="";for(let t=0;t<=6;t++){const a=document.createElement("div");a.classList.add("week-day"),a.innerHTML=e[t],this.elements.dayOfWeekWrapper.appendChild(a)}}setCalendarData(){this.inputType==U?(this.data.selectedYear=this.value.year||this.data.selectedYear||u(this,H,"f").jalali.year,this.data.selectedMonth=this.value.month||this.data.selectedMonth||u(this,H,"f").jalali.month,this.data.yearSelectionRange=[this.data.selectedYear-4,this.data.selectedYear+7],this.shadowRoot.querySelector(".swipe-up-text").innerHTML="نمایش سالها"):(this.data.selectedYear=this.value.year||this.data.selectedYear||u(this,H,"f").gregorian.year,this.data.selectedMonth=this.value.month||this.data.selectedMonth||u(this,H,"f").gregorian.month,this.data.yearSelectionRange=[this.data.selectedYear-4,this.data.selectedYear+7],this.shadowRoot.querySelector(".swipe-up-text").innerHTML="show years")}callOnLoadEvent(){const e=new CustomEvent("load",{bubbles:!0,composed:!0});this.dispatchEvent(e)}callOnInitEvent(){const e=new CustomEvent("init",{bubbles:!0,composed:!0});this.dispatchEvent(e)}initWebComponent(){const e=this.attachShadow({mode:"open"});E();const t=document.createElement("template");t.innerHTML='<style>:host{--arrow-button-border-radius: var(--jb-calendar-arrow-button-border-radius, var(--jb-radius-sm));--day-button-border-radius: var(--jb-calendar-day-button-border-radius, var(--jb-radius-sm));--month-button-border-radius: var(--jb-calendar-month-button-border-radius, var(--jb-radius-sm));--year-button-border-radius: var(--jb-calendar-year-button-border-radius, var(--jb-radius-sm));--color: var(--jb-calendar-color,var(--jb-text-primary));--arrow-button-bgcolor: var(--jb-calendar-arrow-button-bgcolor, var(--jb-neutral-10));--arrow-fill-color: var(--jb-calendar-arrow-fill-color, var(--jb-neutral-6));--day-text-color-disabled: var(--jb-calendar-day-text-color-disabled, var(--jb-neutral-8));--day-text-color-today: var(--jb-calendar-day-text-color-today, var(--jb-green));--day-bgcolor-selected: var(--jb-calendar-day-bgcolor-selected, var(--jb-neutral));--day-color-selected: var(--jb-calendar-day-color-selected, var(--jb-text-contrast));--day-bgcolor-selected-hover: var(--jb-calendar-day-bgcolor-selected-hover, var(--jb-neutral-2));--day-color-selected-hover: var(--jb-calendar-day-color-selected-hover, var(--jb-text-contrast));--day-bgcolor-hover: var(--jb-calendar-day-bgcolor-hover,var(--jb-neutral-10));--day-color-hover: var(--jb-calendar-day-color-hover, var(--jb-text-primary));--day-text-color: var(--jb-calendar-day-text-color, var(--jb-neutral-4));--status-point-bgcolor-today: var(--jb-calendar-status-point-bgcolor-today, var(--jb-green));--status-point-border-color: var(--jb-calendar-status-point-border-color, var(--jb-white));--month-bgcolor-hover: var(--jb-calendar-month-bgcolor-hover, var(--jb-neutral-10));--month-color-hover: var(--jb-calendar-month-color-hover, var(--jb-text-primary));--year-bgcolor-hover: var(--jb-calendar-year-bgcolor-hover, var(--jb-neutral-10));--year-color-hover: var(--jb-calendar-year-color-hover, var(--jb-text-primary));--swipe-up-icon-color: var(--jb-calendar-arrow-fill-color, var(--arrow-fill-color))}.jb-calendar-web-component{width:272px;height:auto;color:var(--color);font-size:16px}.jb-calendar-web-component .navigator-section{height:32px;width:100%;margin-bottom:24px;display:flex;align-items:center;justify-content:space-between;cursor:pointer}.jb-calendar-web-component .navigator-section .arrow-btn{background-color:var(--arrow-button-bgcolor);width:32px;height:32px;border-radius:var(--arrow-button-border-radius);cursor:pointer;display:flex;justify-content:center;align-items:center;user-select:none}.jb-calendar-web-component .navigator-section .arrow-btn.--css-ltr svg{transform:scaleX(-1)}.jb-calendar-web-component .navigator-section .arrow-btn svg{fill:var(--arrow-fill-color)}.jb-calendar-web-component .navigator-section .navigator-title{user-select:none}.jb-calendar-web-component .navigator-section .navigator-title .month{display:none}.jb-calendar-web-component .navigator-section .navigator-title .month.--show{display:inline}.jb-calendar-web-component .navigator-section .navigator-title .month.--show:hover{font-weight:600}.jb-calendar-web-component .navigator-section .navigator-title .year{display:none}.jb-calendar-web-component .navigator-section .navigator-title .year.--show{display:inline}.jb-calendar-web-component .navigator-section .navigator-title .year.--show:hover{font-weight:600}.jb-calendar-web-component .navigator-section .navigator-title .year-range{display:none}.jb-calendar-web-component .navigator-section .navigator-title .year-range.--show{display:inline}.jb-calendar-web-component .calendar-section{height:auto;width:100%;position:relative}.jb-calendar-web-component .calendar-section .day-selection-section{display:none}.jb-calendar-web-component .calendar-section .day-selection-section.--show{display:block}.jb-calendar-web-component .calendar-section .day-selection-section .week-day-wrapper{display:grid;grid-template-columns:1fr 1fr 1fr 1fr 1fr 1fr 1fr;grid-template-rows:1fr;gap:4px;height:32px;width:100%;margin-bottom:16px}.jb-calendar-web-component .calendar-section .day-selection-section .week-day-wrapper .week-day{height:32px;text-align:center;font-weight:800;font-variation-settings:"wght" 800;font-size:1em;user-select:none}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container{position:relative;width:100%;height:auto;overflow-x:hidden}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper{display:grid;grid-template-columns:1fr 1fr 1fr 1fr 1fr 1fr 1fr;grid-auto-rows:1fr;gap:4px 4px;height:auto;width:100%;user-select:none}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper.current-month-day-wrapper{position:static}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper.prev-month-day-wrapper{position:absolute;top:0;left:100%;width:100%;height:100%;overflow:hidden}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper.prev-month-day-wrapper.--css-ltr{left:-100%}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper.next-month-day-wrapper{position:absolute;top:0;left:-100%;width:100%;height:100%;overflow:hidden}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper.next-month-day-wrapper.--css-ltr{left:100%}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper{position:relative;height:37px;width:32px;user-select:none;cursor:pointer}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper.--disable{cursor:not-allowed}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper.--disable .day-number-wrapper{color:var(--day-text-color-disabled)}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper.--today .day-number-wrapper{color:var(--day-text-color-today)}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper.--today .status-point{display:block}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper.--selected .day-number-wrapper{color:var(--day-color-selected);background-color:var(--day-bgcolor-selected)}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper.--selected:hover .day-number-wrapper{color:var(--day-color-selected-hover);background-color:var(--day-bgcolor-selected-hover)}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper:hover .day-number-wrapper{background-color:var(--day-bgcolor-hover);color:var(--day-color-hover)}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper .day-number-wrapper{width:32px;height:32px;border-radius:var(--day-button-border-radius);color:var(--day-text-color);display:flex;align-items:center;justify-content:center}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper .day-number-wrapper .day-number{display:flex;align-items:center;justify-content:center}.jb-calendar-web-component .calendar-section .day-selection-section .month-day-container .month-day-wrapper .day-wrapper .status-point{position:absolute;width:10px;height:10px;background-color:var(--status-point-bgcolor-today);border-radius:6px;bottom:0px;left:calc(50% - 5px);display:none;z-index:1;border:1px solid var(--status-point-border-color);box-sizing:border-box}.jb-calendar-web-component .calendar-section .month-selection-section{display:none;grid-template-columns:1fr 1fr 1fr;grid-template-rows:1fr 1fr 1fr 1fr;gap:12px 8px}.jb-calendar-web-component .calendar-section .month-selection-section.--show{display:grid}.jb-calendar-web-component .calendar-section .month-selection-section .month-wrapper{width:100%;height:32px;cursor:pointer;border-radius:var(--month-button-border-radius);user-select:none}.jb-calendar-web-component .calendar-section .month-selection-section .month-wrapper:hover{background-color:var(--month-bgcolor-hover)}.jb-calendar-web-component .calendar-section .month-selection-section .month-wrapper .month-name{width:100%;height:100%;display:flex;justify-content:center;align-items:center}.jb-calendar-web-component .calendar-section .month-selection-section .month-wrapper .month-name:hover{color:var(--month-color-hover)}.jb-calendar-web-component .calendar-section .year-selection-section{display:none;width:100%;height:100%;position:relative;overflow-x:hidden}.jb-calendar-web-component .calendar-section .year-selection-section.--show{display:block}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper{display:grid;width:100%;height:100%;grid-template-columns:1fr 1fr 1fr;grid-template-rows:1fr 1fr 1fr 1fr;gap:12px 8px;user-select:none}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper.prev-years-wrapper{position:absolute;top:0;left:100%;width:100%;height:100%;overflow:hidden}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper.prev-years-wrapper.--css-ltr{left:-100%}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper.current-years-wrapper{position:static}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper.next-years-wrapper{position:absolute;top:0;left:-100%;width:100%;height:100%;overflow:hidden}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper.next-years-wrapper.--css-ltr{left:100%}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper .year-wrapper{width:100%;height:32px;cursor:pointer;border-radius:var(--year-button-border-radius);user-select:none}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper .year-wrapper:hover{background-color:var(--year-bgcolor-hover)}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper .year-wrapper .year-number{width:100%;height:100%;display:flex;justify-content:center;align-items:center}.jb-calendar-web-component .calendar-section .year-selection-section .years-wrapper .year-wrapper .year-number:hover{color:var(--year-color-hover)}.jb-calendar-web-component .calendar-section .swipe-up-symbol{display:none;position:absolute;bottom:0px;opacity:0;transition:all .1s 0s ease;width:100%;justify-content:center;align-items:center;flex-direction:column}.jb-calendar-web-component .calendar-section .swipe-up-symbol.--show{display:flex}.jb-calendar-web-component .calendar-section .swipe-up-symbol .swipe-up-text{font-size:.8rem}.jb-calendar-web-component .calendar-section .swipe-up-symbol .swipe-up-icon{fill:var(--swipe-up-icon-color)}</style>\n<div class="jb-calendar-web-component">\r\n <section class="navigator-section">\r\n <div class="prev-btn arrow-btn" title="قبل">\r\n <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fit="" preserveAspectRatio="xMidYMid meet">\r\n <path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path>\r\n </svg>\r\n </div>\r\n <div class="navigator-title">\r\n <span class="month"></span>\r\n <span class="year"></span>\r\n <span class="year-range"></span>\r\n </div>\r\n <div class="next-btn arrow-btn" title="بعد">\r\n <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fit="" preserveAspectRatio="xMidYMid meet">\r\n <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"></path>\r\n </svg>\r\n </div>\r\n\r\n </section>\r\n <section class="calendar-section">\r\n <div class="day-selection-section">\r\n <div class="week-day-wrapper">\r\n </div>\r\n <div class="month-day-container">\r\n <div class="prev-month-day-wrapper month-day-wrapper"></div>\r\n <div class="current-month-day-wrapper month-day-wrapper"></div>\r\n <div class="next-month-day-wrapper month-day-wrapper"></div>\r\n </div>\r\n </div>\r\n <div class="month-selection-section">\r\n\r\n </div>\r\n <div class="year-selection-section">\r\n <div class="prev-years-wrapper years-wrapper"></div>\r\n <div class="current-years-wrapper years-wrapper"></div>\r\n <div class="next-years-wrapper years-wrapper"></div>\r\n </div>\r\n <div class="swipe-up-symbol">\r\n <svg class="swipe-up-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\r\n <g clip-path="url(#clip0_403_3281)">\r\n <path d="M23.7101 16.2899L15.5401 8.11994C15.0756 7.65431 14.5239 7.28488 13.9164 7.03281C13.309 6.78075 12.6578 6.651 12.0001 6.651C11.3424 6.651 10.6912 6.78075 10.0838 7.03281C9.47631 7.28488 8.92455 7.65431 8.46009 8.11994L0.290094 16.2899C0.10179 16.4782 -0.0039978 16.7336 -0.0039978 16.9999C-0.0039978 17.2662 0.10179 17.5216 0.290094 17.7099C0.478398 17.8982 0.733792 18.004 1.00009 18.004C1.2664 18.004 1.52179 17.8982 1.71009 17.7099L9.88009 9.53994C10.4426 8.97814 11.2051 8.66258 12.0001 8.66258C12.7951 8.66258 13.5576 8.97814 14.1201 9.53994L22.2901 17.7099C22.3831 17.8037 22.4937 17.8781 22.6155 17.9288C22.7374 17.9796 22.8681 18.0057 23.0001 18.0057C23.1321 18.0057 23.2628 17.9796 23.3847 17.9288C23.5065 17.8781 23.6171 17.8037 23.7101 17.7099C23.8038 17.617 23.8782 17.5064 23.929 17.3845C23.9798 17.2627 24.0059 17.132 24.0059 16.9999C24.0059 16.8679 23.9798 16.7372 23.929 16.6154C23.8782 16.4935 23.8038 16.3829 23.7101 16.2899Z"/>\r\n </g>\r\n <defs>\r\n <clipPath id="clip0_403_3281">\r\n <rect width="24" height="24" fill="white"/>\r\n </clipPath>\r\n </defs>\r\n </svg>\r\n <div class="swipe-up-text">\r\n نمایش سالها\r\n </div>\r\n </div>\r\n </section>\r\n</div>',e.appendChild(t.content.cloneNode(!0)),this.elements={selectionSections:{day:e.querySelector(".day-selection-section"),month:e.querySelector(".month-selection-section"),year:e.querySelector(".year-selection-section")},monthDayWrapper:{current:e.querySelector(".current-month-day-wrapper"),prev:e.querySelector(".prev-month-day-wrapper"),next:e.querySelector(".next-month-day-wrapper")},yearsWrapper:{current:e.querySelector(".current-years-wrapper"),prev:e.querySelector(".prev-years-wrapper"),next:e.querySelector(".next-years-wrapper")},dayOfWeekWrapper:e.querySelector(".week-day-wrapper"),navigatorTitle:{month:e.querySelector(".navigator-title .month"),year:e.querySelector(".navigator-title .year"),yearRange:e.querySelector(".navigator-title .year-range"),nextButton:e.querySelector(".next-btn"),prevButton:e.querySelector(".prev-btn"),wrapper:e.querySelector(".navigator-title")},swipeupSymbol:e.querySelector(".swipe-up-symbol")},this.registerEventHandlers(),window.matchMedia}registerEventHandlers(){this.elements.navigatorTitle.nextButton.addEventListener("click",this.onNextButtonClicked.bind(this)),this.elements.navigatorTitle.prevButton.addEventListener("click",this.onPrevButtonClicked.bind(this)),this.elements.navigatorTitle.year.addEventListener("click",this.onNavigatorTitleYearClicked.bind(this)),this.elements.navigatorTitle.month.addEventListener("click",this.onNavigatorTitleMonthClicked.bind(this)),this.elements.selectionSections.day.addEventListener("touchstart",this.onDayWrapperTouchStart.bind(this)),this.elements.selectionSections.day.addEventListener("touchmove",this.onDayWrapperTouchMove.bind(this)),this.elements.selectionSections.day.addEventListener("touchend",this.onDayWrapperTouchEnd.bind(this)),this.elements.selectionSections.year.addEventListener("touchstart",this.onYearWrapperTouchStart.bind(this)),this.elements.selectionSections.year.addEventListener("touchmove",this.onYearWrapperTouchMove.bind(this)),this.elements.selectionSections.year.addEventListener("touchend",this.onYearWrapperTouchEnd.bind(this))}onDayWrapperTouchStart(e){u(this,R,"f").daysWrapper.startX=e.touches[0].clientX,u(this,R,"f").daysWrapper.startY=e.touches[0].clientY}onDayWrapperTouchMove(e){if(null!==u(this,R,"f").daysWrapper.startX&&null!==u(this,R,"f").daysWrapper.startY){e.preventDefault();const t=e.touches[0].clientX-u(this,R,"f").daysWrapper.startX,a=e.touches[0].clientY-u(this,R,"f").daysWrapper.startY;if(Math.abs(t)>Math.abs(a))this.elements.swipeupSymbol.classList.remove("--show"),this.elements.swipeupSymbol.style.transform="translateY(0px)",this.elements.swipeupSymbol.style.opacity="0",this.elements.monthDayWrapper.current.style.transform=`translateX(${t}px)`,this.elements.monthDayWrapper.prev.style.transform=`translateX(${t}px)`,this.elements.monthDayWrapper.next.style.transform=`translateX(${t}px)`;else if(this.elements.monthDayWrapper.current.style.transform="translateX(0px)",this.elements.monthDayWrapper.prev.style.transform="translateX(0px)",this.elements.monthDayWrapper.next.style.transform="translateX(0px)",this.elements.monthDayWrapper.current.style.transform=`translateY(${a}px)`,a<0){this.elements.swipeupSymbol.classList.add("--show");const e=Math.abs(a)/70;Math.abs(a)>32?this.elements.swipeupSymbol.style.transform="translateY(0px)":this.elements.swipeupSymbol.style.transform=`translateY(${a+32}px)`,this.elements.swipeupSymbol.style.opacity=`${e}`}}}onDayWrapperTouchEnd(e){if(null!==u(this,R,"f").daysWrapper.startX){const t=e.changedTouches[0].clientX-u(this,R,"f").daysWrapper.startX;if(u(this,R,"f").daysWrapper.startX=null,Math.abs(t)>100){let e=t>0?"next":"prev";"ltr"==this.direction&&(e=t>0?"prev":"next"),"prev"==e?(this.elements.monthDayWrapper.current.style.transform="translateX(0px)",this.elements.monthDayWrapper.prev.style.transform="translateX(0px)",this.elements.monthDayWrapper.next.style.transform="translateX(0px)",this.onPrevButtonClicked()):(this.elements.monthDayWrapper.current.style.transform="translateX(0px)",this.elements.monthDayWrapper.prev.style.transform="translateX(0px)",this.elements.monthDayWrapper.next.style.transform="translateX(0px)",this.onNextButtonClicked())}else this.moveBackToPos(this.elements.monthDayWrapper.current),this.moveBackToPos(this.elements.monthDayWrapper.prev),this.moveBackToPos(this.elements.monthDayWrapper.next)}if(null!==u(this,R,"f").daysWrapper.startY){const t=e.changedTouches[0].clientY-u(this,R,"f").daysWrapper.startY;u(this,R,"f").daysWrapper.startY=null,this.elements.swipeupSymbol.classList.remove("--show"),this.elements.swipeupSymbol.style.transform="translateY(0px)",this.elements.swipeupSymbol.style.opacity="0",Math.abs(t)>70&&(this.activeSection=t>0?ee.month:ee.year)}}onYearWrapperTouchStart(e){u(this,R,"f").yearsWrapper.startX=e.touches[0].clientX}onYearWrapperTouchMove(e){null!==u(this,R,"f").yearsWrapper.startX&&(this.elements.yearsWrapper.current.style.transform=`translateX(${e.touches[0].clientX-u(this,R,"f").yearsWrapper.startX}px)`,this.elements.yearsWrapper.prev.style.transform=`translateX(${e.touches[0].clientX-u(this,R,"f").yearsWrapper.startX}px)`,this.elements.yearsWrapper.next.style.transform=`translateX(${e.touches[0].clientX-u(this,R,"f").yearsWrapper.startX}px)`)}onYearWrapperTouchEnd(e){if(null!==u(this,R,"f").yearsWrapper.startX){const t=e.changedTouches[0].clientX-u(this,R,"f").yearsWrapper.startX;u(this,R,"f").yearsWrapper.startX=null;let a=t>0?"next":"prev";"ltr"==this.direction&&(a=t>0?"prev":"next"),Math.abs(t)>100?"prev"==a?(this.elements.yearsWrapper.current.style.transform="translateX(0px)",this.elements.yearsWrapper.prev.style.transform="translateX(0px)",this.elements.yearsWrapper.next.style.transform="translateX(0px)",this.onPrevButtonClicked()):(this.elements.yearsWrapper.current.style.transform="translateX(0px)",this.elements.yearsWrapper.prev.style.transform="translateX(0px)",this.elements.yearsWrapper.next.style.transform="translateX(0px)",this.onNextButtonClicked()):(this.moveBackToPos(this.elements.yearsWrapper.current),this.moveBackToPos(this.elements.yearsWrapper.prev),this.moveBackToPos(this.elements.yearsWrapper.next))}}moveBackToPos(e){e&&(e.style.transition="transform 0.3s 0s ease",setTimeout((()=>{e.style.transition=""}),300),e.style.transform="")}createDataHandler(){const e=(e,t)=>{this.elements.navigatorTitle.year.innerHTML=this.localizeString(e.toString())},t=(e,t)=>{u(this,X,"m",O).call(this,e),this.fillMonthDays()},a=e=>{this.elements.navigatorTitle.yearRange.innerHTML=this.localizeString(`${e[0]} - ${e[1]}`),this.fillYearList()};return{set:(r,n,s)=>("selectedYear"==n&&(e(s,r.selectedYear),r[n]=s),"selectedMonth"==n&&(r[n]=s,t(s,r.selectedMonth)),"yearSelectionRange"==n&&Array.isArray(s)&&(r[n]=s,a(s)),!0)}}createDateRestrictionHandler(){return{set:(e,t,a)=>{switch(e[t]=a,t){case"min":case"max":"DAY"==this.activeSection&&this.fillMonthDays()}return!0}}}initProps(){this.callOnInitEvent()}selectToday(){const e=new Date;this.inputType==U?this.select(h(e),c(e)+1,o(e)):this.select(n(e),r(e)+1,t(e))}select(e,t,a){this.value={year:e,month:t,day:a}}initCalendar(){u(this,B,"f")||(this.activeSection=ee.day)}fillYearList(){this.fillYearListDom(this.data.yearSelectionRange[0],this.data.yearSelectionRange[1],"current"),this.fillYearListDom(this.data.yearSelectionRange[0]-12,this.data.yearSelectionRange[1]-12,"prev"),this.fillYearListDom(this.data.yearSelectionRange[0]+12,this.data.yearSelectionRange[1]+12,"next")}fillYearListDom(e,t,a){this.elements.yearsWrapper[a].innerHTML="";for(let r=e;r<=t;r++){const e=this.createYearDom(r);this.elements.yearsWrapper[a].appendChild(e)}}createYearDom(e){const t=document.createElement("div");t.classList.add("year-wrapper");const a=document.createElement("div");return a.classList.add("year-number"),a.innerHTML=this.localizeString(e.toString()),t.appendChild(a),t.addEventListener("click",(()=>{this.data.selectedYear=e,this.activeSection=ee.month})),t}fillMonthDaysDom(e,t,a){const r=u(this,X,"m",J).call(this,e,t,1),n=u(this,X,"m",_).call(this,r);this.elements.monthDayWrapper[a].innerHTML="";for(let e=1;e<n;e++){const e=this.createEmptyDayDom();this.elements.monthDayWrapper[a].appendChild(e)}const s=u(this,X,"m",G).call(this,r);for(let e=1;e<=s;e++){const t=u(this,X,"m",J).call(this,this.data.selectedYear,this.data.selectedMonth,e),r=u(this,X,"m",Z).call(this,e,this.data.selectedMonth,this.data.selectedYear),n=this.value.year==this.data.selectedYear&&this.value.month==this.data.selectedMonth&&this.value.day==e,s=!this.checkIsDayDisable(t).isAllValid,i=this.createDayDom(e,this.data.selectedYear,this.data.selectedMonth,r,n,s);this.elements.monthDayWrapper[a].appendChild(i)}}fillMonthDays(){const e=this.data.selectedMonth,t=this.data.selectedYear;let a,r,n,s;e>1?(a=e-1,r=this.data.selectedYear):(r=this.data.selectedYear-1,a=12),this.fillMonthDaysDom(r,a,"prev"),this.fillMonthDaysDom(t,e,"current"),e<12?(n=e+1,s=this.data.selectedYear):(s=this.data.selectedYear+1,n=1),this.fillMonthDaysDom(s,n,"next")}checkIsDayDisable(e){const t={min:!0,max:!0,get isAllValid(){return this.min&&this.max}};return this.dateRestrictions.min&&(t.min=d(e,this.dateRestrictions.min)||s(e,this.dateRestrictions.min)),this.dateRestrictions.max&&(t.max=p(e,this.dateRestrictions.max)||s(e,this.dateRestrictions.max)),t}createEmptyDayDom(){const e=document.createElement("div");return e.classList.add("empty-day"),e}createDayDom(e,t,a,r,n,s){const i=document.createElement("div");i.classList.add("day-wrapper"),i.setAttribute("day-number",e.toString()),r&&i.classList.add("--today"),n&&i.classList.add("--selected");const o=document.createElement("div");o.classList.add("day-number-wrapper");const l=document.createElement("div");l.classList.add("day-number"),l.innerHTML=this.localizeString(e.toString());const c=document.createElement("div");return c.classList.add("status-point"),o.appendChild(l),i.appendChild(c),i.appendChild(o),s?i.classList.add("--disable"):i.addEventListener("click",(()=>{this.onDayClicked(t,a,e)})),i}onDayClicked(e,t,a){this.select(e,t,a);const r=new CustomEvent("select");this.dispatchEvent(r)}onNextButtonClicked(){if("DAY"==this.activeSection){const e=this.data.selectedMonth;e<12?this.data.selectedMonth=e+1:(this.data.selectedYear=this.data.selectedYear+1,this.data.selectedMonth=1)}if("MONTH"==this.activeSection&&(this.data.selectedYear=this.data.selectedYear+1),"YEAR"==this.activeSection){const e=this.data.yearSelectionRange[0]+12,t=this.data.yearSelectionRange[1]+12;this.data.yearSelectionRange=[e,t]}}onPrevButtonClicked(){if("DAY"==this.activeSection){const e=this.data.selectedMonth;e>1?this.data.selectedMonth=e-1:(this.data.selectedYear=this.data.selectedYear-1,this.data.selectedMonth=12)}if("MONTH"==this.activeSection&&(this.data.selectedYear=this.data.selectedYear-1),"YEAR"==this.activeSection){const e=this.data.yearSelectionRange[0]-12,t=this.data.yearSelectionRange[1]-12;e>0&&(this.data.yearSelectionRange=[e,t])}}onNavigatorTitleYearClicked(){this.activeSection!=ee.day&&this.activeSection!=ee.month||(this.activeSection=ee.year)}onNavigatorTitleMonthClicked(){this.activeSection==ee.day&&(this.activeSection=ee.month)}onInputTypeChange(){this.setCalendarData(),this.fillDayOfWeek(),u(this,X,"m",I).call(this)}localizeString(e){return this.showPersianNumber?y(e):e}};R=new WeakMap,N=new WeakMap,B=new WeakMap,P=new WeakMap,H=new WeakMap,A=new WeakMap,V=new WeakMap,$=new WeakMap,q=new WeakMap,X=new WeakSet,O=function(e){const t=this.inputType==U?u(this,A,"f")[e-1]:u(this,V,"f")[e-1];this.elements.navigatorTitle.month.innerHTML=t},z=function(e){return[2,3,4,5,6,7,1][e]},I=function(){this.elements.selectionSections.month.innerHTML="";for(let e=1;e<13;e++){const t=u(this,X,"m",F).call(this,e);this.elements.selectionSections.month.appendChild(t)}},F=function(e){const t=document.createElement("div");t.classList.add("month-wrapper");const a=document.createElement("div");a.classList.add("month-name");const r=this.inputType==U?u(this,A,"f")[e-1]:u(this,V,"f")[e-1];return a.innerHTML=r,t.appendChild(a),t.addEventListener("click",(()=>{this.data.selectedMonth=e,this.activeSection=ee.day})),t},J=function(e,t,a){return this.inputType==U?m(e,t-1,a):new Date(e,t-1,a)},_=function(e){return this.inputType==U?u(this,X,"m",z).call(this,o(e)):t(e)},G=function(e){return this.inputType==U?l(e):a(e)},Z=function(t,a,s){const o=new Date;return this.inputType==U?h(o)==s&&c(o)==a-1&&i(o)==t:n(o)==s&&r(o)==a-1&&e(o)==t};!customElements.get("jb-calendar")&&window.customElements.define("jb-calendar",re);export{ee as JBCalendarSections,re as JBCalendarWebComponent};
//# sourceMappingURL=jb-calendar.js.map