UNPKG

22.3 kBJavaScriptView Raw
1function t(t){return t?(t.nodeName||"").toLowerCase():null}function n(e,r){if(void 0===r&&(r=[]),function(n){var e=t(n);return"body"===e||"html"===e}(e))return r;if(function(t){return t instanceof window.Node}(e)){var i=getComputedStyle(e),a=i.overflow,o=i.overflowX,u=i.overflowY;/auto|scroll|overlay|hidden/.test(a+u+o)&&r.push(e)}return n("html"===t(c=e)?c:c.parentNode||document.ownerDocument||document.documentElement,r);var c}function e(n){return"input"===t(n)}function r(n){return t(n)?function t(n){if(e(n))return n;var r,i=n.childNodes;if(!i)return null;for(var a=0,o=i;a<o.length;a++){var u=o[a],c=e(u)?u:t(u);c&&(r=c)}return r||null}(n):(console.error("Invalid argument provided. They must be a Input element"),null)}function i(t,n){return d(n)?n.some((function(n){return i(t,n)})):t.indexOf(n)>-1}var a=Object.prototype.toString,o=function(t,n){return i(a.call(t),n)};function u(t){return o(t,"Number")&&!Number.isNaN(t)}function c(t){return o(t,"Object")}function s(t){return o(t,"Function")}function l(t){return o(t,"String")}function f(t){return o(t,"Boolean")}function d(t){return Array.isArray(t)}function h(t,n){return Array.from({length:n}).map((function(n,e){return t(e)}))}function y(t){return void 0===t&&(t=new Date),t.getFullYear()}function v(t){return void 0===t&&(t=new Date),t.getMonth()+1}function p(t){return void 0===t&&(t=new Date),t.getDate()}function m(t){return t.split("/").map((function(t){return Number(t)}))}function g(t,n){return new Date(t,n,0).getDate()}function b(t){return h((function(n){return t+n-1-Number(t.toString().slice(-1))}),12)}function k(t,n){var e=new Date(t+"/"+n+"/01").getDay();return 0===e&&(e=7),e}function x(t,n,e){return void 0===n&&(n=1),void 0===e&&(e=1),d(t)?t.reverse().join("/")+"/"+n:n+"/"+t+"/"+e}function w(t,n){return!(!t||!n)&&Date.parse(t)>Date.parse(n)}function C(t,n,e){return void 0===e&&(e=2),!(!t||!n)&&(t=t.split("/").slice(0,e).join("/"))===(n=n.split("/").slice(0,e).join("/"))}function E(t,n){var e=[t,n];return w(t,n)?e:e.reverse()}function S(t,n){var e;c(t)&&(t=(e=[t.month,t.year])[0],n=e[1]);var r=--t;return 0===r&&(r=12,--n),[r,n]}function D(t,n){var e;c(t)&&(t=(e=[t.month,t.year])[0],n=e[1]);var r=++t;return 13===r&&(r=1,++n),[r,n]}function j(t,n){var e=t.options.disabledDate;return e&&e(new Date(n))?"disabled":""}var K=function(){return h((function(){return{status:"",date:""}}),12)};function N(t,n){return{date:null,year:n,month:t,_date:h((function(){return{text:"",status:"",date:""}}),42),_month:K(),_year:K()}}var _=0,O=function(){function t(t,n){this.id=_++,this.subs=[],this.state=n,this.child=t}return t.prototype.addSub=function(t){this.subs.push(t)},t.prototype.depend=function(){t.target&&t.target.addDep(this)},t.prototype.notify=function(){this.subs.forEach((function(t){t.update()}))},t}();function A(t){return function n(e){return Object.keys(e).forEach((function(r){var i=e[r];d(i)?i.forEach((function(t){return n(t)})):c(i)?n(i):function(n,e,r){var i=new O(n,t);Object.defineProperty(n,e,{enumerable:!0,configurable:!0,get:function(){return O.target&&i.depend(),r},set:function(t){t!==r&&(r=t,i.notify())}})}(e,r,i)})),e}(t)}function M(t){return Object.assign({reference:null,popover:null,onChange:null},function(){var t=new Date,n=[y(t),v(t)],e=n[0],r=n[1],i=D(r,e),a=i[0],o=i[1];return{range:{start:null,end:null,status:"complete"},start:N(r,e),end:N(a,o),today:x(r,e,p(t)),date:null}}(),function(t){return{options:t,visible:!1,page:"date"}}(t))}O.target=null;var T=function(){var t=0,n={};return{createState:function(e){var r=function(t){return A(M(t))}(e);return r.type=e.type,r._type=r.type.split("-").shift(),r.id=++t,n[t]=r,r},getState:function(){return n[t]},removeState:function(t){delete n[t]}}}(),L=T.createState,z=T.getState,Y=T.removeState,$={placement:["top","left","bottom","right"],type:["date","date-range","month","month-range","year","year-range"],unlinkPanels:f,format:l,zIndex:u,disabled:f,disabledDate:s,offset:u,insertTo:["body","parent"],binding:f,themeColor:l,rangeBgColor:l};function B(t,n){var e=$[t];return d(e)?i(e,n):e(n)}var I="better-datepicker";function P(t,n){for(var e in void 0===n&&(n=Object.create(null)),t){var r=n[e];B(e,r)&&(t[e]=r)}return t}function F(t){return i(t,I)?t:I+"-"+t}function R(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return t.filter((function(t){return t})).map((function(t){return d(t)?R.apply(void 0,t):F(t)})).join(" ")}var J,X,W=[],H=!1;function q(){H=!1;var t=W.slice(0);W.length=0;for(var n=0;n<t.length;n++)try{t[n]()}catch(t){console.error("nextTick callback error")}}if("undefined"!=typeof Promise&&("function"==typeof(X=Promise)&&i(X.toString(),"native code"))){var G=Promise.resolve();J=function(){G.then(q)}}else J=function(){setTimeout(q,0)};var Q=[],U={},V=!1,Z=0;function tt(){var t,n;for(Z=0;Z<Q.length;Z++)(t=Q[Z]).getter(),n=t.id,U[n]=null;V=!1,U={},Q.length=Z=0}function nt(t){var n,e=t.id;U[e]||(U[e]=!0,Q.push(t),V||(V=!0,n=function(){return tt()},W.push(n),H||(H=!0,J())))}var et=0,rt=function(){function t(t,n,e){var r;this.watcher=t,this.state=n,this.child=e,this.id=++et,r=this,O.target=r,this.getter()}return t.prototype.getter=function(){var t=this,n=this.watcher.key.map((function(n){return t.child[n]})).concat(this.child);O.target=null,this.watcher.cb.apply(this.state,n)},t.prototype.update=function(){nt(this)},t.prototype.addDep=function(t){t.addSub(this)},t}();function it(t,n){var e=Object.assign({},t);new rt(e,n,function(t,n){return function t(e,r){if(d(r))return n.key=r,e;if("child"in r)return n.key=r.name,r.child;var i=r,a=i.name,o=i.idx,c=i.childKey;return a&&(e=e[a]),u(o)&&d(e)&&(e=e[o]),c&&(e=t(e,c)),e}(t,n.key)}(n,e))}function at(t){var n=z();d(t)?t.forEach((function(t){return it(t,n)})):it(t,n)}function ot(t,n){var e;return void 0===n&&(n="click"),[function(r,i){e=ut(t,r,n,i)},function(){t.removeEventListener(n,e)}]}function ut(t,n,e,r,i){function a(t){if(!(c(i)&&i.date&&r&&j(r,i.date)))return n.call(r,t)}return void 0===e&&(e="click"),t.addEventListener(e,a),a}function ct(t,n,e){if(void 0===e&&(e="class"),!n)return t.removeAttribute(e);t.setAttribute(e,n)}function st(t,n,e){var r=e.options.themeColor;function i(n,r){d(n)?n.forEach((function(n){return ut(t,n.handler,n.name,e,r)})):ut(t,n,"click",e,r)}return{event:function(){"listener"in n?i(n.listener,n.arg):i(n),r&&function(t,n){function e(e){t.style.color="mouseenter"===e.type?n:""}ut(t,e,"mouseenter"),ut(t,e,"mouseleave")}(t,r)},children:function(){n.forEach((function(n){return t.appendChild(ft(n,e))}))},class:function(){return ht.call(e,t,n,"cls")},style:function(){return ct(t,(e=n,Object.keys(e).reduce((function(t,n){return t.concat(n+":"+e[n])}),[]).join(";")),"style");var e},name:function(){return null},text:function(){l(n)?t.innerText=n:ht(t,n)},hidden:function(){return function(t,n){if(!n)return;t.style.display="none"}(t,n)},$style:function(){Object.keys(n).forEach((function(e){ht(t,n[e],"style",e)}))}}}var lt={month:["M721.9968 979.0208l47.0528-47.104-419.94752-419.98848 419.94752-419.90144-47.05792-47.04768-419.93216 419.89632h-0.00512l-47.104 47.09888 47.04768 47.04256z"],year:["M176 513.7l392.73-395.44a32 32 0 0 0-45.41-45.1L108 491.3a32 32 0 0 0 0.16 45.25L523.48 949a32 32 0 1 0 45.1-45.41z","M525.23 513.7L918 118.26a32 32 0 1 0-45.41-45.1L457.27 491.3a32 32 0 0 0 0.16 45.25L872.7 949a32 32 0 0 0 45.1-45.41z"]};function ft(t,n){if(s(t))return t(n);var e,r="svg"===t.name?function(t){var n="http://www.w3.org/2000/svg",e=document.createElementNS(n,"svg");return e.setAttribute("viewBox","0 0 1024 1024"),lt[t].forEach((function(t){var r=document.createElementNS(n,"path");r.setAttribute("d",t),e.appendChild(r)})),e}(t.text):(void 0===(e=t.name)&&(e="div"),document.createElement(e));return Object.keys(t).forEach((function(e){st(r,t[e],n)[e]()})),r}function dt(t){return t?"inline-block":"none"}function ht(t,n,e,r){var a=this;if(void 0===e&&(e="text"),d(n))return ct(t,R(n));var o=n.key,u=n.cb,c={cls:function(e){var r=R(e,n.static);ct(t,r),function(t,n,e){var r=n.options,a=r.themeColor,o=r.rangeBgColor,u=t.children[0];if(u){var c=u.style;o&&(c.backgroundColor=i(e,"inRange")?o:""),a&&(c.backgroundColor=i(e,["selected","range-start","range-end"])?a:o?c.backgroundColor:"",c.color=i(e,"today")?a:"")}}(t,a,r)},text:function(n){return t.innerText=n},style:function(n){return t.style[r]=n}};at({key:o,cb:function(){var t=u.apply(this,arguments);c[e](t)}})}var yt={"text-align":"center",padding:"5px 20px",width:"320px"},vt={complete:{plt:"start",status:"selecting"},selecting:{plt:"end",status:"complete"}};function pt(t){return[{name:"click",handler:function(){var n=this.range,e=vt[n.status];n[e.plt]=t.date,n.status=e.status}},{name:"mouseenter",handler:function(){var n=this.range;"selecting"===n.status&&(n.end=t.date)}}]}function mt(t){var n="year"===this.page?10:1;this[t].year+=n}function gt(){var t="year"===this.page?10:1;this.start.year-=t}function bt(t){var n,e=this[t];n=D(e),e.month=n[0],e.year=n[1]}function kt(){var t,n=this.start;t=S(n),n.month=t[0],n.year=t[1]}function xt(t){var n=t.date;n&&(this.start.year=m(n)[0]),this.page="month"}function wt(t){var n=t.date;this.start.year=m(n)[0],this.start.date=n,this.visible=!1}function Ct(t){var n=t.date;this.start.month=m(n),this.start.date=n,this.visible=!1}function Et(t){this.start.month=m(t.date)[1],this.page="date"}function St(){this.page="year"}function Dt(t){return dt("date"===t)}function jt(t,n){return d(n)||(n=[n]),function(){return t.apply(this,n.concat(Array.from(arguments)))}}var Kt=["Su","Mo","Tu","We","Th","Fr","Sa"],Nt=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],_t="start",Ot={display:{key:["page"],cb:Dt}},At=function(t){var n=b(t)[1];return n+" - "+(n+9)};function Mt(t){return ft({name:"span",text:{date:{key:{name:_t,childKey:["month","year"]},cb:function(t,n){return Nt[t-1]+" "+n}},month:{key:{name:_t,childKey:["year"]},cb:function(t){return t}},year:{key:{name:_t,childKey:["year","_date"]},cb:function(t){return At(t)}}}[t._type]},t)}function Tt(t){return ft({name:"svg",text:"year",style:{position:"absolute",left:"30px",width:"14px",height:"14px"},event:gt},t)}function Lt(t){return ft({name:"svg",text:"month",style:{position:"absolute",left:"50px",width:"14px",height:"14px"},event:kt,$style:Ot},t)}function zt(t){return ft({name:"svg",text:"year",style:{position:"absolute",right:"30px",transform:"rotate(180deg)",width:"14px",height:"14px"},event:jt(mt,_t)},t)}function Yt(t){return ft({name:"svg",text:"month",style:{position:"absolute",right:"50px",transform:"rotate(180deg)",width:"14px",height:"14px"},event:jt(bt,_t),$style:Ot},t)}var $t={start:[Tt,Lt,Mt],main:[Tt,Lt,function(t){return ft({name:"span",text:{key:{name:"start",childKey:["year","_date"]},cb:function(t){return At(t)}},$style:{display:{key:["page"],cb:function(t){return dt("year"===t)}}},event:St},t)},function(t){return ft({name:"span",text:{key:{name:_t,childKey:["month"]},cb:function(t){return Nt[t-1]}},class:["pointerCursor"],event:xt,$style:Ot},t)},function(t){return ft({name:"span",text:{key:{name:_t,childKey:["year","_date"]},cb:function(t){return t}},event:St,class:["pointerCursor"],$style:{display:{key:["page"],cb:function(t){return dt("year"!==t)}}}},t)},zt,Yt],end:[Mt,zt,Yt]};function Bt(t,n){return _t=n||"start",ft({class:["header"],children:$t[n||"main"],style:{width:"298px","text-align":"center"}},t)}function It(t){return Bt(t,"start")}function Pt(t){return Bt(t,"end")}function Ft(t){return{date:function(){this.start.date=t.date,this.visible=!1},"date-range":pt(t)}}var Rt="start",Jt={height:"40px",width:"40px",padding:"3px 0"};function Xt(t,n){return void 0===n&&(n="status"),{key:{name:[n],child:t},cb:function(t){return t}}}function Wt(t){function n(n){return h((function(e){var r=7*n+e,i=t[Rt]._date[r];return{name:"td",children:[{text:Xt(i,"text")}],style:Jt,class:Xt(i),event:{listener:Ft(i)[t.type],arg:i}}}),7)}return ft({children:h((function(t){return{name:"tr",children:n(t)}}),6),name:"tbody"},t)}function Ht(t){return ft({name:"thead",children:Kt.map((function(t){return{text:t,name:"th",style:Jt}}))},t)}function qt(t,n){return void 0===n&&(n="start"),Rt=n,ft({name:"table",children:[Ht,Wt],class:["day"],style:yt,$style:{display:{key:["page"],cb:Dt}}},t)}function Gt(t){return qt(t,"end")}var Qt="start",Ut={month:{listener:function(t,n){return function(t){return{date:jt(Et,t),"month-range":pt(t),month:jt(Ct,t)}}(t)[n.type]},children:function(t){return[{text:Nt[t]}]}},year:{listener:function(t,n){return function(t){return{date:jt(xt,t),"year-range":pt(t),year:jt(wt,t)}}(t)[n.type]},children:function(t){return[{text:{key:{name:Qt,childKey:["year"]},cb:function(n){return String(b(n)[t])}}}]}}};function Vt(t){void 0===t&&(t="month");var n=Ut[t],e=n.children,r=n.listener;return function(n,i){function a(i){return h((function(a){var o=4*i+a,u=n[Qt]["_"+t][o];return{name:"td",event:{listener:r(u,n),arg:u},children:e(o),class:{key:{name:["status"],child:u},cb:function(t){return t}}}}),4)}return void 0===i&&(i="start"),Qt=i,ft({name:"table",children:[function(t){return ft({children:h((function(t){return{name:"tr",children:a(t)}}),3),name:"tbody"},t)}],class:[t],style:yt,$style:{display:{key:["page"],cb:function(n){return dt(n===t)}}}},n)}}var Zt=Vt();function tn(t){return Zt(t,"end")}var nn=Vt("year");function en(t){return nn(t,"end")}function rn(t){void 0===t&&(t="month");var n={date:{start:[It,qt],end:[Pt,Gt]},month:{start:[It,Zt],end:[Pt,tn]},year:{start:[It,nn],end:[Pt,en]}};return[{style:{width:"646px"},children:[{style:{display:"inline-block","border-right":"1px solid #e4e4e4"},children:n[t].start},{style:{display:"inline-block"},children:n[t].end}]}]}var an={date:[Bt,qt,Zt,nn],"date-range":rn("date"),month:[Bt,Zt,nn],"month-range":rn(),year:[Bt,nn],"year-range":rn("year")};function on(t){void 0===t&&(t=document.styleSheets[0]);var n=t?t.rules:null;if(n&&n.length>0){var e=n[0],r=e.name,a=e.type;i(["show","hidden"],r)&&7===a&&t.deleteRule(0)}}function un(t){var n=ft({class:["wrapper"],children:an[t.type],hidden:!0},t);return function(t){t.style.display="none",t.addEventListener("animationend",(function(n){t.style.display="hidden"===n.animationName?"none":"inline-block",on()}))}(n),n}var cn={true:{animation:"show .3s",rule:function(t){return"@keyframes show { 0% {display: block;opacity: 0;transform:scaleY(.8) "+t+";} 100% {display: block;opacity: 1;transform: scaleY(1) "+t+";} }"}},false:{animation:"hidden .3s",rule:function(t){return"@keyframes hidden { 0% {opacity: 1;transform: "+t+" scaleY(1);} 100% {opacity: 0;visibility: hidden;transform: "+t+" scaleY(.8);} }"}}};function sn(){if(this.visible){var t,n,e,r,i,a,o=this.popover,u=this.reference,c=this.options,s=c.offset,l=c.placement,f=u.getBoundingClientRect();(function(t){if(!t)return!1;for(var n=document.body.childNodes,e=!1,r=n.length;r>=0;r--)if(n[r]===t){e=!0;break}return e})(o)?(a=function(t,n){var e=t.top,r=t.left,i=t.height,a=t.width,o=e+window.scrollY-n,u=e+i+window.scrollY+n,c=r+window.scrollX,s=r+a+window.scrollX;return{top:{top:o,left:c},left:{top:o,left:c},bottom:{top:u,left:s-a},right:{top:o,left:s}}}(f,s),Array.from(["left","top"]).forEach((function(t){return o.style[t]=a[l][t]+"px"})),o.style.transform=function(t){return{top:"translate(0,calc(-100% - "+(t+="px")+"))",left:"translate(calc(-100% - "+t+"),0)",bottom:"translate(0,"+t+")",right:"translate("+t+",0)"}}(s)[l]):(n=u.offsetWidth,e=u.offsetHeight,i={bottom:{top:e+s+"px",left:0},top:{top:"calc(-100% - "+s+"px)",left:0},left:{top:0,right:(r=n+s+"px")+s},right:{top:0,left:r+s}}[l],Object.keys(i).forEach((function(t){return o.style[t]=i[t]})),(t=u.parentNode)&&t.style&&(t.style.position="relative"))}}var ln={key:["options","popover"],cb:function(t,n){var e;if(null!==n){var r,i,a=this.options.insertTo;r=n,void 0===(i="body"===a||null===(e=this.reference)||void 0===e?void 0:e.parentNode)&&(i=document.body),d(r)?r.forEach((function(t){return i.appendChild(t)})):i.appendChild(r)}}},fn={key:["visible"],cb:function(t){var n=this.popover;if(n){var e=document.styleSheets[0],r=this.options.zIndex;on(e),t&&(n.style.display="inline-block",sn.call(this)),function(t,n){!function(t,n,e){void 0===e&&(e="class");var r=t.getAttribute(e)||"";c(n)&&(n=Object.keys(n).reduce((function(t,e){return t+e+":"+n[e]+";"}),"")),r+=" "+n,t.setAttribute(e,r)}(t,{position:"absolute","z-index":n},"style")}(n,r);var i=cn[t],a=i.animation,o=i.rule;n.style.animation=a,e?e.insertRule(o(n.style.transform),0):n.style.display=t?"inline-block":"none"}}};var dn=/d{1,2}|M{1,2}|yy(?:yy)?|"[^"]*"|'[^']*'/g,hn={d:function(t){return p(t)},dd:function(t){return yn(p(t))},M:function(t){return v(t)},MM:function(t){return yn(v(t))},yy:function(t){return String(y(t)).substr(2)},yyyy:function(t){return y(t)}};function yn(t,n){for(t=String(t),n=n||2;t.length<n;)t="0"+t;return t}function vn(t){var n=i(t.options.type,"range"),e=[t.start.date,t.end.date],r=e[0];return n?[r,e[1]]:r}function pn(t,n){var e=t.range,r=E(e.start,e.end),i=r[0],a=r[1],o=n===a,u=n===i,c="range-start",s="range-end";return w(i,n)&&w(n,a)?"inRange":u&&o?R(c,s):o?c:u?s:""}var mn={key:{name:"start",childKey:["date"]},cb:function(t){var n;if(t){var e=this.start;n=m(t),e.year=n[0],e.month=n[1],this.date=vn(this)}}},gn={key:{name:"end",childKey:["date"]},cb:function(t){t&&(this.date=vn(this))}},bn={key:{name:"range",childKey:["status"]},cb:function(t){"selecting"===t?this.range.end=null:function(t){var n;t.visible=!1;var e=t.range,r=e.start,i=e.end;n=E(r,i),t.end.date=n[0],t.start.date=n[1]}(this)}},kn={key:["date"],cb:function(){var t=vn(this);this.onChange&&this.onChange(t),this.options.binding&&this.reference&&(this.reference.value=function(t,n){function e(t){return n.replace(dn,(function(n){return hn[n](new Date(t))}))}return d(t)?t.map((function(t){return e(t)})).join(" - "):e(t)}(t,this.options.format))}},xn={key:{name:"start",childKey:["year","month"]},cb:function(t,n,e){e._month.forEach((function(t,e){t.status=n===e+1?"selected":""})),e._year.forEach((function(n,e){var r=m(n.date)[0];n.status=0===e?"pre":11===e?"next":t===r?"selected":""}))}};function wn(t){return void 0===t&&(t="month"),{key:{name:"range",childKey:["start","end"]},cb:function(){var n=this;["start","end"].forEach((function(e){n[e]["_"+t].filter((function(t){return n=t.status,d(e=["pre","next"])?e.every((function(t){return!i(n,t)})):!i(n,e);var n,e})).forEach((function(e,r){return e.status=Sn(n,e.date,r,t)}))}))}}}function Cn(t,n){return C(t.start.date,n)?"selected":""}function En(t,n,e){return 0===e?"pre":11===e?"next":C(t.start.date,n,1)?"selected":""}function Sn(t,n,e,r,i){return void 0===r&&(r="month"),void 0===i&&(i=""),R({year:{year:En,date:En,"year-range":pn},month:{month:Cn,date:Cn,"month-range":pn},date:{date:function(){return t.start.date===n?"selected":""},"date-range":function(){return pn(t,n)}}}[r][t.type](t,n,e),j(t,n),i,Date.parse(t.today)===Date.parse(n)?"today":"")}function Dn(t,n,e){var r=this;e._month.forEach((function(n,e){n.date=x(e+1,t),n.status=Sn(r,n.date,e)}))}function jn(t,n,e){var r=this,i=b(t);e._year.forEach((function(t,n){t.date=x(1,i[n]);var e=0===n?"pre":11===n?"next":"";t.status=Sn(r,t.date,n,"year",e)}))}function Kn(t,n,e,r){var i=this,a=S(t,n),o=a[0],u=g(a[1],o),c=[k(n,t),g(n,t)],s=c[0],l=c[1];r._date.forEach((function(e,r){var a,o=r+1,c=o-s,f=r<s?"pre":s+l<=r?"next":"";a={pre:function(){var e=u+c;return[String(e),x(S(t,n),e)]},next:function(){var e=c-l;return[String(e),x(D(t,n),e)]},other:function(){var e=x(t,n,c);return[String(c),e]}}[f||"other"](),e.text=a[0],e.date=a[1],e.status=Sn(i,e.date,o,"date",f)}))}var Nn=["month","year","date"];function _n(t){void 0===t&&(t="start");var n={start:"end",end:"start"};return{key:{name:t,childKey:Nn},cb:function(e,r){var i,a=this[n[t]];i=("start"===t?D:S)(e,r),a.month=i[0],a.year=i[1]}}}var On={key:{name:"start",childKey:["month","year","date"]},cb:Kn},An=function(t){return{name:t,childKey:["year","date"]}};function Mn(t,n){return void 0===t&&(t=!0),void 0===n&&(n="start"),{key:An(n),cb:t?Dn:jn}}function Tn(t,n){void 0===t&&(t="start"),void 0===n&&(n=!1);var e=n?10:1;return{key:{name:t,childKey:["year"]},cb:function(n){"start"===t?this.end.year=n+e:this.start.year=n-e}}}var Ln={"date-range":[On,{key:{name:"end",childKey:["month","year","date"]},cb:Kn},_n(),_n("end"),wn("date")],date:[On,Mn(!1),Mn(),xn],month:[Mn()],"month-range":[Mn(),Tn(),Tn("end"),Mn(!0,"end"),wn()],year:[Mn(!1)],"year-range":[Mn(!1),Mn(!1,"end"),Tn("start",!0),Tn("end",!0),wn("year")]},zn=[mn,kn],Yn=[bn,gn];var $n={key:["options"],cb:function(){this.page=this._type}},Bn={key:["visible"],cb:function(){var t=this.range,n=this.start,e=this.end;t.status="complete",n.date&&n.date?(t.start=n.date,t.end=e.date):t.start=t.end=null}};function In(){at([$n,Bn])}function Pn(t){at([ln,fn]),function(t){var n=t.type,e=zn;i(n,"range")&&(e=e.concat(Yn)),at(Ln[n].concat(e))}(t),In()}function Fn(t,n){var e=t.visible,r=t.reference,i=t.popover;!e||(null==r?void 0:r.contains(n.target))||(null==i?void 0:i.contains(n.target))||(t.visible=!1)}function Rn(){var e,i,a,o,u,c,l;function f(){e&&(e.visible=!0)}function d(){var t,r;t=ot(i),o=t[0],u=t[1],r=ot(document.body),c=r[0],l=r[1],o(f),c(jt(Fn,e)),e&&function(t,e){var r=n(t),i=sn.bind(e);r.forEach((function(t){return ut(t,i,"scroll")})),ut(window,i,"resize")}(i,e)}function h(){return e?e.date:null}function y(t){e&&(s(t)?e.onChange=t:console.error("Invalid argument provided. They must be a Function"))}function v(t){a=P(a,t),p(),m()}function p(){if(!e)return null;!function(t){var n=t.popover;if(n){var e=n.parentNode;e&&e.removeChild&&e.removeChild(n)}}(e),l(),u(),Y(e.id),e=null}function m(){i&&(e=L(a),Pn(a),d(),e.reference=i,e.popover=un(e))}function g(){if(!e)return null;e.reference&&(e.reference.value=""),e.range.start=e.range.end=e.start.date=e.end.date=null}function b(){if(!e)return null;e.visible=!0}function k(){if(!e)return null;e.visible=!1}return function(n,e){var o=r(n);if(function(n){return"input"===t(n)}(o))return i=o,a=P({placement:"bottom",type:"date",zIndex:2e3,unlinkPanels:!1,format:"yyyy/MM/dd",offset:12,insertTo:"body",binding:!0,disabled:!1,disabledDate:null,themeColor:"",rangeBgColor:""},e),m(),{options:e,getCurrentDate:h,onChange:y,update:v,destroyed:p,clear:g,open:b,close:k}}}function Jn(t,n){return Rn()(t,n)}export{Jn as createDatePicker};
2//# sourceMappingURL=betterDatePicker.es5.js.map