var Vr=Object.defineProperty;var ce=(t,e)=>{for(var r in e)Vr(t,r,{get:e[r],enumerable:!0})};function ft(t){let e=atob(t),r=e.length,n=new Uint8Array(r);for(let o=0;o(...n)=>{let o=this.prefix?[this.prefix,...n]:n;this.originalConsole[r](...o),this.captureLog(r,n)};console.log=e("log"),console.info=e("info"),console.warn=e("warn"),console.error=e("error"),console.debug=e("debug")}captureLog(e,r){let n={level:e,timestamp:Date.now(),message:r.map(o=>{if(typeof o=="string")return o;try{return JSON.stringify(o)}catch{return String(o)}}).join(" ")};this.logBuffer.push(n),this.logBuffer.length>this.maxCaptureSize&&this.logBuffer.shift()}async postToServer(e,r){if(this.logBuffer.length>0){let o=[...this.logBuffer];this.logBuffer=[];try{if(!(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o.map(a=>({...a,source:r})))})).ok)throw new Error("Failed to post logs to server")}catch(i){console.warn("Could not post logs to server",i.message),this.logBuffer.unshift(...o)}}}},pt;function mt(t=""){return pt=new Ie(t),pt}var le=t=>{throw new Error("Not initialized yet")},Ke=typeof window>"u"&&typeof globalThis.WebSocketPair>"u";typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var Ye=new Map,Ue=0;Ke&&(globalThis.syscall=async(t,...e)=>await new Promise((r,n)=>{Ue++,Ye.set(Ue,{resolve:r,reject:n}),le({type:"sys",id:Ue,name:t,args:e})}));function ht(t,e,r){Ke&&(le=r,self.addEventListener("message",n=>{(async()=>{let o=n.data;switch(o.type){case"inv":{let i=t[o.name];if(!i)throw new Error(`Function not loaded: ${o.name}`);try{let a=await Promise.resolve(i(...o.args||[]));le({type:"invr",id:o.id,result:a})}catch(a){console.error("An exception was thrown as a result of invoking function",o.name,"error:",a.message),le({type:"invr",id:o.id,error:a.message})}}break;case"sysr":{let i=o.id,a=Ye.get(i);if(!a)throw Error("Invalid request id");Ye.delete(i),o.error?a.reject(new Error(o.error)):a.resolve(o.result)}break}})().catch(console.error)}),le({type:"manifest",manifest:e}),mt(`[${e.name} plug]`))}async function Wr(t,e){if(typeof t!="string"){let r=new Uint8Array(await t.arrayBuffer()),n=r.length>0?Ne(r):void 0;e={method:t.method,headers:Object.fromEntries(t.headers.entries()),base64Body:n},t=t.url}return syscall("sandboxFetch.fetch",t,e)}globalThis.nativeFetch=globalThis.fetch;function Hr(){globalThis.fetch=async function(t,e){let r=e&&e.body?Ne(new Uint8Array(await new Response(e.body).arrayBuffer())):void 0,n=await Wr(t,e&&{method:e.method,headers:e.headers,base64Body:r});return new Response(n.base64Body?ft(n.base64Body):null,{status:n.status,headers:n.headers})}}Ke&&Hr();var H={};ce(H,{alert:()=>Rn,configureVimMode:()=>qn,confirm:()=>Mn,copyToClipboard:()=>Bn,deleteLine:()=>jn,dispatch:()=>Cn,downloadFile:()=>hn,filterBox:()=>bn,flashNotification:()=>vn,fold:()=>Ln,foldAll:()=>Un,getCurrentEditor:()=>Jr,getCurrentPage:()=>$r,getCurrentPageMeta:()=>qr,getCurrentPath:()=>Gr,getCursor:()=>en,getRecentlyOpenedPages:()=>Zr,getSelection:()=>tn,getText:()=>Qr,getUiOption:()=>Pn,goHistory:()=>mn,hidePanel:()=>Tn,insertAtCursor:()=>Dn,insertAtPos:()=>Sn,invokeCommand:()=>nn,isMobile:()=>Zn,moveCursor:()=>xn,moveCursorToLine:()=>kn,moveLineDown:()=>Hn,moveLineUp:()=>Wn,navigate:()=>an,newWindow:()=>pn,openCommandPalette:()=>un,openPageNavigator:()=>sn,openSearchPanel:()=>Fn,openUrl:()=>fn,prompt:()=>On,rebuildEditorState:()=>dn,redo:()=>zn,reloadConfigAndCommands:()=>yn,reloadPage:()=>cn,reloadUI:()=>ln,replaceRange:()=>An,save:()=>on,sendMessage:()=>Gn,setSelection:()=>rn,setText:()=>Xr,setUiOption:()=>_n,showPanel:()=>En,showProgress:()=>wn,toggleComment:()=>Vn,toggleFold:()=>In,undo:()=>Kn,unfold:()=>Nn,unfoldAll:()=>Yn,uploadFile:()=>gn,vimEx:()=>$n});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function y(t,...e){return globalThis.syscall(t,...e)}function $r(){return y("editor.getCurrentPage")}function qr(){return y("editor.getCurrentPageMeta")}function Gr(){return y("editor.getCurrentPath")}function Zr(){return y("editor.getRecentlyOpenedPages")}function Jr(){return y("editor.getCurrentEditor")}function Qr(){return y("editor.getText")}function Xr(t,e=!1){return y("editor.setText",t,e)}function en(){return y("editor.getCursor")}function tn(){return y("editor.getSelection")}function rn(t,e){return y("editor.setSelection",t,e)}function nn(t,e){return y("editor.invokeCommand",t,e)}function on(){return y("editor.save")}function an(t,e=!1,r=!1){return y("editor.navigate",t,e,r)}function sn(t="page"){return y("editor.openPageNavigator",t)}function un(){return y("editor.openCommandPalette")}function cn(){return y("editor.reloadPage")}function ln(){return y("editor.reloadUI")}function dn(){return y("editor.rebuildEditorState")}function yn(){return y("editor.reloadConfigAndCommands")}function fn(t,e=!1){return y("editor.openUrl",t,e)}function pn(){return y("editor.newWindow")}function mn(t){return y("editor.goHistory",t)}function hn(t,e){return y("editor.downloadFile",t,e)}function gn(t,e){return y("editor.uploadFile",t,e)}function vn(t,e="info"){return y("editor.flashNotification",t,e)}function bn(t,e,r="",n=""){return y("editor.filterBox",t,e,r,n)}function En(t,e,r,n=""){return y("editor.showPanel",t,e,r,n)}function Tn(t){return y("editor.hidePanel",t)}function wn(t,e){return y("editor.showProgress",t,e)}function Sn(t,e){return y("editor.insertAtPos",t,e)}function An(t,e,r){return y("editor.replaceRange",t,e,r)}function xn(t,e=!1){return y("editor.moveCursor",t,e)}function kn(t,e=1,r=!1){return y("editor.moveCursorToLine",t,e,r)}function Dn(t,e=!1,r=!1){return y("editor.insertAtCursor",t,e,r)}function Cn(t){return y("editor.dispatch",t)}function On(t,e=""){return y("editor.prompt",t,e)}function Mn(t){return y("editor.confirm",t)}function Rn(t){return y("editor.alert",t)}function Pn(t){return y("editor.getUiOption",t)}function _n(t,e){return y("editor.setUiOption",t,e)}function Ln(){return y("editor.fold")}function Nn(){return y("editor.unfold")}function In(){return y("editor.toggleFold")}function Un(){return y("editor.foldAll")}function Yn(){return y("editor.unfoldAll")}function Kn(){return y("editor.undo")}function zn(){return y("editor.redo")}function Fn(){return y("editor.openSearchPanel")}function Bn(t){return y("editor.copyToClipboard",t)}function jn(){return y("editor.deleteLine")}function Vn(){return y("editor.toggleComment")}function Wn(){return y("editor.moveLineUp")}function Hn(){return y("editor.moveLineDown")}function $n(t){return y("editor.vimEx",t)}function qn(){return y("editor.configureVimMode")}function Gn(t,e){return y("editor.sendMessage",t,e)}function Zn(){return y("editor.isMobile")}var de={};ce(de,{del:()=>ro,get:()=>to,set:()=>eo});function eo(t,e){return y("clientStore.set",t,e)}function to(t){return y("clientStore.get",t)}function ro(t){return y("clientStore.delete",t)}var $s=new Uint8Array(16);var ye={};ce(ye,{batchDel:()=>ho,batchDeletePrefix:()=>bo,batchGet:()=>po,batchSet:()=>yo,del:()=>mo,get:()=>fo,listFunctions:()=>To,query:()=>go,queryDelete:()=>Eo,queryLua:()=>vo,set:()=>lo});function lo(t,e){return y("datastore.set",t,e)}function yo(t){return y("datastore.batchSet",t)}function fo(t){return y("datastore.get",t)}function po(t){return y("datastore.batchGet",t)}function mo(t){return y("datastore.delete",t)}function ho(t){return y("datastore.batchDelete",t)}function go(t){return y("datastore.query",t)}function vo(t,e,r){return y("datastore.queryLua",t,e,r)}function bo(t){return y("datastore.batchDeletePrefix",t)}function Eo(t,e){return y("datastore.queryDelete",t,e)}function To(){return y("datastore.listFunctions")}var Te={};ce(Te,{define:()=>Co,get:()=>Ao,has:()=>Do,insert:()=>ko,set:()=>xo});function Ao(t,e){return y("config.get",t,e)}function xo(t,e){return y("config.set",t,e)}function ko(t,e){return y("config.insert",t,e)}function Do(t){return y("config.has",t)}function Co(t,e){return y("config.define",t,e)}var we={};ce(we,{ensureFullIndex:()=>Po,getObjectByRef:()=>Ro,indexObjects:()=>Oo,queryLuaObjects:()=>Mo});function Oo(t,e){return y("index.indexObjects",t,e)}function Mo(t,e,r,n){return y("index.queryLuaObjects",t,e,r,n)}function Ro(t,e,r){return y("index.getObjectByRef",t,e,r)}function Po(){return y("index.ensureFullIndex")}var V=t=>Object.fromEntries(Object.entries(t).map(([e,r])=>[r,e])),C=t=>Object.keys(t),At={action:"ACTION",description:"DESCRIPTION",duration:"DURATION",repeat:"REPEAT",summary:"SUMMARY",trigger:"TRIGGER",attachments:"ATTACH",attendees:"ATTENDEE"},xt=V(At),uu=C(xt),cu=C(At),kt={method:"METHOD",prodId:"PRODID",version:"VERSION",name:"X-WR-CALNAME"},Dt=V(kt),lu=C(Dt),du=C(kt),Ct={alarms:"ALARM",categories:"CATEGORIES",created:"CREATED",description:"DESCRIPTION",lastModified:"LAST-MODIFIED",location:"LOCATION",exceptionDates:"EXDATE",recurrenceRule:"RRULE",stamp:"DTSTAMP",start:"DTSTART",summary:"SUMMARY",uid:"UID",timeTransparent:"TRANSP",url:"URL",end:"DTEND",duration:"DURATION",geo:"GEO",class:"CLASS",organizer:"ORGANIZER",priority:"PRIORITY",sequence:"SEQUENCE",status:"STATUS",attach:"ATTACH",recurrenceId:"RECURRENCE-ID",attendees:"ATTENDEE",comment:"COMMENT"},Ot=V(Ct),yu=C(Ot),fu=C(Ct),Mt={id:"TZID",lastModified:"LAST-MODIFIED",url:"TZURL"},Rt=V(Mt),pu=C(Rt),mu=C(Mt),Pt={comment:"COMMENT",name:"TZNAME",offsetFrom:"TZOFFSETFROM",offsetTo:"TZOFFSETTO",recurrenceDate:"RDATE",recurrenceRule:"RRULE",start:"DTSTART"},_t=V(Pt),hu=C(_t),gu=C(Pt),Lt={byDay:"BYDAY",byHour:"BYHOUR",byMinute:"BYMINUTE",byMonth:"BYMONTH",byMonthday:"BYMONTHDAY",bySecond:"BYSECOND",bySetPos:"BYSETPOS",byWeekNo:"BYWEEKNO",byYearday:"BYYEARDAY",count:"COUNT",frequency:"FREQ",interval:"INTERVAL",until:"UNTIL",workweekStart:"WKST"},Nt=V(Lt),vu=C(Nt),bu=C(Lt),It={categories:"CATEGORIES",created:"CREATED",description:"DESCRIPTION",lastModified:"LAST-MODIFIED",location:"LOCATION",exceptionDates:"EXDATE",recurrenceRule:"RRULE",stamp:"DTSTAMP",start:"DTSTART",summary:"SUMMARY",uid:"UID",url:"URL",duration:"DURATION",geo:"GEO",class:"CLASS",organizer:"ORGANIZER",priority:"PRIORITY",sequence:"SEQUENCE",status:"STATUS",attach:"ATTACH",recurrenceId:"RECURRENCE-ID",attendees:"ATTENDEE",comment:"COMMENT",completed:"COMPLETED",due:"DUE",percentComplete:"PERCENT-COMPLETE"},Ut=V(It),Eu=C(Ut),Tu=C(It),Yt={categories:"CATEGORIES",created:"CREATED",description:"DESCRIPTION",lastModified:"LAST-MODIFIED",exceptionDates:"EXDATE",recurrenceRule:"RRULE",stamp:"DTSTAMP",start:"DTSTART",summary:"SUMMARY",uid:"UID",url:"URL",geo:"GEO",class:"CLASS",organizer:"ORGANIZER",sequence:"SEQUENCE",status:"STATUS",attach:"ATTACH",recurrenceId:"RECURRENCE-ID",attendees:"ATTENDEE",comment:"COMMENT"},Kt=V(Yt),wu=C(Kt),Su=C(Yt),zt={stamp:"DTSTAMP",start:"DTSTART",uid:"UID",url:"URL",organizer:"ORGANIZER",attendees:"ATTENDEE",comment:"COMMENT",end:"DTEND",freeBusy:"FREEBUSY"},Ft=V(zt),Au=C(Ft),xu=C(zt),Bt="BEGIN",jt="END",_o="VCALENDAR",Vt="VTIMEZONE",Lo="STANDARD",No="DAYLIGHT",Wt="VEVENT",Ht="VALARM",$t="VTODO",qt="VJOURNAL",Gt="VFREEBUSY";var gt=t=>new RegExp(`${Bt}:${t}([\\s\\S]*?)${jt}:${t}`,"g"),Io=t=>new RegExp(`${Bt}:${t}|${jt}:${t}`,"g");var Fe=/\r\n|\r|\n/;var vt=` `,Uo=":",te=",",Yo='"',Be=";";var bt="=";var Ko=Math.pow(10,8)*24*60*60*1e3,ku=-Ko,zo=6048e5;var Zt=6e4,Jt=36e5,Fo=3600,Qt=Fo*24,Du=Qt*7,Bo=Qt*365.2425,jo=Bo/12,Cu=jo*3,Et=Symbol.for("constructDateFrom");function Y(t,e){return typeof t=="function"?t(e):t&&typeof t=="object"&&Et in t?t[Et](e):t instanceof Date?new t.constructor(e):new Date(e)}function E(t,e){return Y(e||t,t)}function Ve(t,e,r){let n=E(t,r?.in);return isNaN(e)?Y(r?.in||t,NaN):(e&&n.setDate(n.getDate()+e),n)}function Xt(t,e,r){let n=E(t,r?.in);if(isNaN(e))return Y(r?.in||t,NaN);if(!e)return n;let o=n.getDate(),i=Y(r?.in||t,n.getTime());i.setMonth(n.getMonth()+e+1,0);let a=i.getDate();return o>=a?i:(n.setFullYear(i.getFullYear(),i.getMonth(),o),n)}function ke(t,e,r){return Y(r?.in||t,+E(t)+e)}function Vo(t,e,r){return ke(t,e*Jt,r)}var Wo={};function De(){return Wo}function Ae(t,e){var r,n,o,i;let a=De(),s=e?.weekStartsOn??((n=(r=e?.locale)==null?void 0:r.options)==null?void 0:n.weekStartsOn)??a.weekStartsOn??((i=(o=a.locale)==null?void 0:o.options)==null?void 0:i.weekStartsOn)??0,u=E(t,e?.in),c=u.getDay(),l=(ctypeof n=="object"));return e.map(r)}function $o(t,e){let r=E(t,e?.in);return r.setHours(0,0,0,0),r}function er(t,e,r){let n=E(t,r?.in);return n.setTime(n.getTime()+e*Zt),n}function qo(t,e,r){return ke(t,e*1e3,r)}function We(t,e,r){return Ve(t,e*7,r)}function tr(t,e,r){return Xt(t,e*12,r)}function He(t,e){let r=+E(t)-+E(e);return r<0?-1:r>0?1:r}function Tt(t,e){let r=E(t,e?.in),n=r.getMonth();return r.setFullYear(r.getFullYear(),n+1,0),r.setHours(23,59,59,999),r}function Go(t,e){let[r,n]=Ho(t,e.start,e.end);return{start:r,end:n}}function Zo(t,e){let{start:r,end:n}=Go(e?.in,t),o=+r>+n,i=o?+r:+n,a=o?n:r;a.setHours(0,0,0,0);let s=e?.step??1;if(!s)return[];s<0&&(s=-s,o=!o);let u=[];for(;+a<=i;)u.push(Y(r,a)),a.setDate(a.getDate()+s),a.setHours(0,0,0,0);return o?u.reverse():u}function wt(t,e){let r=E(t,e?.in);return r.setDate(1),r.setHours(0,0,0,0),r}function Jo(t,e){let r=E(t,e?.in),n=r.getFullYear();return r.setFullYear(n+1,0,0),r.setHours(23,59,59,999),r}function Qo(t,e){let r=E(t,e?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function Xo(t,e){var r,n,o,i;let a=E(t,e?.in),s=a.getFullYear(),u=De(),c=e?.firstWeekContainsDate??((n=(r=e?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??u.firstWeekContainsDate??((i=(o=u.locale)==null?void 0:o.options)==null?void 0:i.firstWeekContainsDate)??1,l=Y(e?.in||t,0);l.setFullYear(s+1,0,c),l.setHours(0,0,0,0);let p=Ae(l,e),d=Y(e?.in||t,0);d.setFullYear(s,0,c),d.setHours(0,0,0,0);let f=Ae(d,e);return+a>=+p?s+1:+a>=+f?s:s-1}function ei(t,e){var r,n,o,i;let a=De(),s=e?.firstWeekContainsDate??((n=(r=e?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??a.firstWeekContainsDate??((i=(o=a.locale)==null?void 0:o.options)==null?void 0:i.firstWeekContainsDate)??1,u=Xo(t,e),c=Y(e?.in||t,0);return c.setFullYear(u,0,s),c.setHours(0,0,0,0),Ae(c,e)}function ti(t,e){let r=E(t,e?.in),n=+Ae(r,e)-+ei(r,e);return Math.round(n/zo)+1}function Se(t,e){return E(t,e?.in).getDay()}function rr(t,e){let r=E(t,e?.in),n=r.getFullYear(),o=r.getMonth(),i=Y(r,0);return i.setFullYear(n,o+1,0),i.setHours(0,0,0,0),i.getDate()}function ri(t,e){return E(t,e?.in).getHours()}function ni(t,e){return E(t,e?.in).getMinutes()}function nr(t,e){return E(t,e?.in).getMonth()}function oi(t){return E(t).getSeconds()}function ii(t,e){return E(t,e?.in).getFullYear()}function ai(t,e){return+E(t)==+E(e)}function si(t,e,r){let n=E(t,r?.in),o=ti(n,r)-e;return n.setDate(n.getDate()-o*7),E(n,r?.in)}function xe(t,e,r){var n,o,i,a;let s=De(),u=r?.weekStartsOn??((o=(n=r?.locale)==null?void 0:n.options)==null?void 0:o.weekStartsOn)??s.weekStartsOn??((a=(i=s.locale)==null?void 0:i.options)==null?void 0:a.weekStartsOn)??0,c=E(t,r?.in),l=c.getDay(),p=(e%7+7)%7,d=7-u,f=e<0||e>6?e-(l+d)%7:(p+d)%7-(l+d)%7;return Ve(c,f,r)}function or(t,e,r){let n=+E(t,r?.in),[o,i]=[+E(e.start,r?.in),+E(e.end,r?.in)].sort((a,s)=>a-s);return n>=o&&n<=i}function ui(t){let e=t/Jt;return Math.trunc(e)}function ci(t){let e=t/Zt;return Math.trunc(e)}function li(t,e,r){let n=E(t,r?.in),o=n.getFullYear(),i=n.getDate(),a=Y(r?.in||t,0);a.setFullYear(o,e,15),a.setHours(0,0,0,0);let s=rr(a);return n.setMonth(e,Math.min(i,s)),n}function di(t,e,r){let n=E(t,r?.in);return n.setDate(e),n}function yi(t,e,r){let n=E(t,r?.in);return n.setMonth(0),n.setDate(e),n}function fi(t,e,r){let n=E(t,r?.in);return n.setHours(e),n}function pi(t,e,r){let n=E(t,r?.in);return n.setMinutes(e),n}function mi(t,e,r){let n=E(t,r?.in);return n.setSeconds(e),n}function hi(t,e,r){return ke(t,-e,r)}function gi(t,e,r){return We(t,-e,r)}var vi=[Lo,No];var bi=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"];var ir=["SU","MO","TU","WE","TH","FR","SA"];var X=(t,e)=>e===void 0?!1:t>=e,Ei=(t,{start:e,end:r},n)=>{if(X(n.length,t.count))return;let o=t.frequency,i=t.interval||1;if(!o)return;let a=e;if(o==="SECONDLY"){for(;a{let o=r.map(({day:i,occurrence:a})=>({occurrence:a,day:ir.indexOf(i)}));return t.frequency==="YEARLY"?t.byYearday||t.byMonthday?e.map(i=>i.filter(a=>o.find(({day:s})=>s===Se(a)))):t.byWeekNo?e.map(i=>i.flatMap(a=>o.map(({day:s})=>xe(a,s,{weekStartsOn:n})))):t.byMonth?e.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>ze($(wt(a)),$(Tt(a)),s,n,u)))):e.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>ze($(Qo(a)),$(Jo(a)),s,n,u)))):t.frequency==="MONTHLY"?t.byMonthday?e.map(i=>i.filter(a=>o.find(({day:s})=>s===Se(a)))):e.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>ze($(wt(a)),$(Tt(a)),s,n,u)))):t.frequency==="WEEKLY"?e.map(i=>i.flatMap(a=>o.map(({day:s})=>xe(a,s,{weekStartsOn:n})))):e.map(i=>i.filter(a=>o.find(({day:s})=>s===Se(a))))},ze=(t,e,r,n,o)=>{if(o!==void 0){if(!(o<0)){let s=xe(t,r,{weekStartsOn:n}),u=t>s;return We(s,(o||1)-1+(u?1:0))}let i=xe(e,r,{weekStartsOn:n}),a=e$(i)).filter(i=>or(i,{start:t,end:e})).filter(i=>r===Se(i))},$=t=>er(t,-t.getTimezoneOffset()),wi=(t,e,r)=>t.frequency==="YEARLY"||t.frequency==="MONTHLY"||t.frequency==="WEEKLY"||t.frequency==="DAILY"?e.map(n=>n.flatMap(o=>r.map(i=>fi(o,i)))):e.map(n=>n.filter(o=>r.includes(ri(o)))),Si=(t,e,r)=>t.frequency==="YEARLY"||t.frequency==="MONTHLY"||t.frequency==="WEEKLY"||t.frequency==="DAILY"||t.frequency==="HOURLY"?e.map(n=>n.flatMap(o=>r.map(i=>pi(o,i)))):e.map(n=>n.filter(o=>r.includes(ni(o)))),Ai=(t,e,r)=>t.frequency==="YEARLY"?e.map(n=>n.flatMap(o=>r.map(i=>li(o,i)))):e.map(n=>n.filter(o=>r.includes(nr(o)))),xi=(t,e,r)=>t.frequency==="YEARLY"||t.frequency==="MONTHLY"?e.map(n=>n.flatMap(o=>{let i=rr(o);return r.map(a=>a>i?void 0:di(o,a)).filter(a=>!!a)})):t.frequency==="WEEKLY"?e:e.map(n=>n.filter(o=>r.includes(nr(o)))),ki=(t,e,r)=>t.frequency==="YEARLY"||t.frequency==="MONTHLY"||t.frequency==="WEEKLY"||t.frequency==="DAILY"||t.frequency==="HOURLY"||t.frequency==="MINUTELY"?e.map(n=>n.flatMap(o=>r.map(i=>mi(o,i)))):e.map(n=>n.filter(o=>r.includes(oi(o)))),Di=(t,e,r)=>!t.byYearday&&!t.byWeekNo&&!t.byMonthday&&!t.byMonth&&!t.byDay&&!t.byHour&&!t.byMinute&&!t.bySecond?e:e.map(n=>n.sort(He).filter((o,i)=>r.some(a=>a>0?i===0?!1:i%a===0:i===0?n.length-1+a===0:i%(n.length-1+a)===0))),Ci=(t,e,r,n)=>t.frequency==="YEARLY"?e.map(o=>o.flatMap(i=>r.map(a=>si(i,a,{weekStartsOn:n})))):e,Oi=(t,e,r)=>t.frequency==="YEARLY"?e.map(n=>n.flatMap(o=>r.map(i=>yi(o,i)))):t.frequency==="MONTHLY"||t.frequency==="WEEKLY"||t.frequency==="DAILY"?e:e.map(n=>n.filter(o=>r.includes(ii(o)))),Mi=(t,e,r)=>{let n=r;return t.byMonth&&(n=Ai(t,n,t.byMonth)),t.byWeekNo&&(n=Ci(t,n,t.byWeekNo,e.weekStartsOn)),t.byYearday&&(n=Oi(t,n,t.byYearday)),t.byMonthday&&(n=xi(t,n,t.byMonthday)),t.byDay&&(n=Ti(t,n,t.byDay,e.weekStartsOn)),t.byHour&&(n=wi(t,n,t.byHour)),t.byMinute&&(n=Si(t,n,t.byMinute)),t.bySecond&&(n=ki(t,n,t.bySecond)),t.bySetPos&&(n=Di(t,n,t.bySetPos)),n.map(o=>o.sort(He).filter(i=>!(e.exceptions.length>0&&e.exceptions.some(a=>ai(a,i))||!or(i,{start:e.start,end:e.end}))))},Ri=2,Pi=(t,e)=>{var r;let n=e.start,o=((r=t.until)==null?void 0:r.date)||e?.end||tr(n,Ri),i=e.exceptions||[],a=(t.workweekStart?ir.indexOf(t.workweekStart):1)%7,s=[[n]];Ei(t,{start:n,end:o},s);let u=Mi(t,{start:n,end:o,exceptions:i,weekStartsOn:a},s);return t.count?u.flat().splice(0,t.count):u.flat()},_i=(t,e)=>e.flatMap(r=>!r.recurrenceRule||r.recurrenceRule.until&&r.recurrenceRule.until.date({...r,start:n}))),je=t=>{let e=t[0]==="+"?1:-1,r=Number(t.slice(1,3)),n=t.length>3?Number(t.slice(3,5)):0,o=t.length>5?Number(t.slice(5,7)):0;return((r*60+n)*60+o)*1e3*e},Li=(t,e)=>{let r="en-US",n=new Date(e.toLocaleString(r,{timeZone:"UTC"}));try{return new Date(e.toLocaleString(r,{timeZone:t})).getTime()-n.getTime()}catch{return e.getTime()-n.getTime()}},Ni=(t,e,r)=>{let n=r?.find(i=>i.id===e);if(n){let i=_i(t,n.props).sort((u,c)=>He(u.start,c.start));for(let u=0;u5?c.substring(0,5):c;return{offset:l,milliseconds:je(l)}}let a=i[i.length-1].offsetTo,s=a.length>5?a.substring(0,5):a;return{offset:s,milliseconds:je(s)}}let o=Li(e,t);if(!Number.isNaN(o)){let i=o<0,a=Math.abs(ui(o)),s=Math.abs(ci(o))-a*60,u=a.toString().length===1?`0${a}`:a.toString(),c=s.toString().length===1?`0${s}`:s.toString();return{offset:`${i?"-":"+"}${u}${c}`,milliseconds:o}}};var x=(t,e)=>{if(t===void 0)return e;let r=t["~standard"].validate(e);if(r instanceof Promise)throw new TypeError("Schema validation must be synchronous");if(r.issues)throw new Error(JSON.stringify(r.issues,null,2));return r.value},Ii=(t,e)=>{var r,n,o,i;let a=((r=e.options)==null?void 0:r.VALUE)==="BINARY"?{type:"binary",encoding:((n=e.options)==null?void 0:n.ENCODING)||"BASE64",binary:e.value,value:(o=e.options)==null?void 0:o.VALUE}:{type:"uri",url:e.value,formatType:(i=e.options)==null?void 0:i.FMTTYPE};return x(t,a)},ee=t=>t.replace(/mailto:/gi,""),me=(t,e)=>{var r,n,o,i,a,s,u,c,l,p,d;return x(t,{email:ee(e.value),delegatedFrom:(r=e.options)!=null&&r["DELEGATED-FROM"]?ee((n=e.options)==null?void 0:n["DELEGATED-FROM"]):void 0,dir:(o=e.options)==null?void 0:o.DIR,member:(i=e.options)!=null&&i.MEMBER?ee(e.options.MEMBER):void 0,name:(a=e.options)==null?void 0:a.CN,partstat:(s=e.options)==null?void 0:s.PARTSTAT,role:(u=e.options)==null?void 0:u.ROLE,sentBy:(c=e.options)!=null&&c["SENT-BY"]?ee(e.options["SENT-BY"]):void 0,rsvp:(l=e.options)!=null&&l.RSVP?((p=e.options)==null?void 0:p.RSVP)==="TRUE"?!0:((d=e.options)==null?void 0:d.RSVP)==="FALSE"?!1:void 0:void 0})},he=(t,e)=>{let r=e.value,n={};r[0]==="-"&&(n.before=!0,r=r.slice(1)),r=r.slice(1);let o=r.split("T"),i=o[0];if(i.includes("D")){let[s,u]=i.split("D");n.days=Number(s),i=u}if(i.includes("W")){let[s,u]=i.split("W");n.weeks=Number(s),i=u}let a=o[1];if(a){if(a.includes("H")){let[s,u]=a.split("H");n.hours=Number(s),a=u}if(a.includes("M")){let[s,u]=a.split("M");n.minutes=Number(s),a=u}if(a.includes("S")){let[s,u]=a.split("S");n.seconds=Number(s),a=u}}return x(t,n)},Ui=(t,e)=>{let r=Number.parseInt(e.value.slice(0,4),10),n=Number.parseInt(e.value.slice(4,6),10)-1,o=Number.parseInt(e.value.slice(6,8),10),i=new Date(Date.UTC(r,n,o));return x(t,i)},fe=(t,e)=>{let r=Number.parseInt(e.value.slice(0,4),10),n=Number.parseInt(e.value.slice(4,6),10)-1,o=Number.parseInt(e.value.slice(6,8),10),i=Number.parseInt(e.value.slice(9,11),10),a=Number.parseInt(e.value.slice(11,13),10),s=Number.parseInt(e.value.slice(13,15),10),u=new Date(Date.UTC(r,n,o,i,a,s));return x(t,u)},Yi=(t,e,r)=>{let n=je(r),o=fe(void 0,e),i=hi(o,n);return x(t,i)},Ki=(t,e)=>{var r,n,o,i,a,s;if(((r=t.options)==null?void 0:r.VALUE)==="DATE")return{date:Ui(void 0,t),type:(n=t.options)==null?void 0:n.VALUE};let u=((o=t.options)==null?void 0:o.VALUE)||"DATE-TIME",c=fe(void 0,t);if(!((i=t.options)!=null&&i.TZID))return{date:c,type:u};let l=Ni(c,t.options.TZID,e?.timezones);return l?{date:ke(c,-l.milliseconds),type:u,local:(a=t.options)!=null&&a.TZID?{date:c,timezone:(s=t.options)==null?void 0:s.TZID,tzoffset:l.offset}:void 0}:{date:c,type:u}},k=(t,e,r)=>x(t,Ki(e,r)),zi=(t,e,r)=>{var n,o,i,a;let s=((n=e.options)==null?void 0:n.VALUE)==="DATE-TIME"||((o=e.options)==null?void 0:o.VALUE)==="DATE"?{type:"absolute",value:k(void 0,e,r),options:{related:(i=e.options)==null?void 0:i.RELATED}}:{type:"relative",value:he(void 0,e),options:{related:(a=e.options)==null?void 0:a.RELATED}};return x(t,s)},Fi=t=>t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t,ar=t=>t.map(e=>{let[r,...n]=e.split(bt),o=n.join(bt);return{property:r,value:Fi(o)}},{}),Bi=t=>t.reduce((e,r)=>(e[r.property]=r.value,e),{}),ji=t=>Bi(ar(t)),Vi=t=>{let e=!1,r;for(let i=0;i{let{property:e,value:r}=Vi(t);if(e.includes(Be)){let[n,...o]=e.split(Be),i=ji(o);return{property:n,line:{options:i,value:r}}}return{property:e,line:{value:r}}},St=t=>/^[ \t]/.test(t),Hi=t=>/^[A-Z]+(?:-[A-Z]+)*[:;]/.test(t),$i=t=>{let e=[],r=t.split(Fe);for(;r[0]==="";)r.shift();let n=r.length;for(;n>0&&r[n-1]==="";)n-=1,r.pop();for(let o=0;oo!=="")},qi=(t,e,r)=>{if(!e)return t;let n={};return Object.entries(e).forEach(([o,i])=>{let a=Object.entries(r||{}).find(([c,l])=>l.name===o);if(!a){n[Gi(o)]=i.value;return}let s=a[1].convert(i),u=a[1].schema;if(!u){n[a[0]]=s;return}n[a[0]]=x(u,s)}),t.nonStandard=n,t},Gi=t=>{let e=t.startsWith("X-")?t.slice(2):t,r="",n=!1;for(let o of e)o==="-"?n=!0:(r+=n?o.toUpperCase():o.toLowerCase(),n=!1);return r},Zi=t=>t.startsWith("X-"),q=(t,e,r)=>{let n=e.replace(Io(r?.icsComponent),""),o=[...new Set(Object.values(r.childComponents||{}).flatMap(({icsComponent:p})=>p))],i=$i(o.reduce((p,d)=>p.replace(gt(d),""),n)),a=r.defaultValues||{},s={};i.forEach(p=>{var d,f;let{property:g,line:b}=Wi(p);Zi(g)&&(s[g]=b);let h=r.objectKeyMap[g];if(!h)return;let S=(d=r.convertArrayValues)==null?void 0:d[h];if(S){let N=S({line:b});if(!N)return;(a[h]===void 0||a[h]===null||!Array.isArray(a[h]))&&(a[h]=[]),Array.isArray(N)?a[h].push(...N):a[h].push(N);return}let L=(f=r.convertValues)==null?void 0:f[h];if(L){let N=L({line:b});if(!N)return;a[h]=N;return}a[h]=b.value});let u=r.childComponents,c=u?Object.keys(u||{}):[];u&&c.length>0&&c.forEach(p=>{let d=u?.[p];if(!d)return;let f=Array.isArray(d.icsComponent)?d.icsComponent:[d.icsComponent],g=[],b=[];f.forEach(h=>{b.push(...n.matchAll(gt(h)))}),b.map(h=>h[0]).forEach(h=>{let S=d.convert(h,{data:a});S&&g.push(S)}),g.length!==0&&(a[p]=g)});let l=x(t,a);return r!=null&&r.nonStandard?qi(l,s,r?.nonStandard):l},Ce=(t,e)=>{var r,n,o;return x(t,{name:(r=e.options)==null?void 0:r.CN,dir:(n=e.options)==null?void 0:n.DIR,sentBy:(o=e.options)!=null&&o["SENT-BY"]?ee(e.options["SENT-BY"]):void 0,email:ee(e.value)})},$e=(t,e,r)=>{var n;return x(t,{value:k(void 0,e,r),range:(n=e.options)==null?void 0:n.RANGE})},Ji=t=>{if(t.length===2)return{day:t};let e=t.slice(0,-2);return{day:t.replace(e,""),occurrence:Number(e)}},Qi=(t,e)=>x(t,Ji(e.value)),Xi=(t,e)=>x(t,e.value),ea=["until"],ta=t=>ea.includes(t),ra=["bySecond","byMinute","byHour","byMonthday","byYearday","byWeekNo","bySetPos"],na=t=>ra.includes(t),oa=["byDay"],ia=t=>oa.includes(t),aa=["count","interval"],sa=t=>aa.includes(t),Oe=(t,e,r)=>{let n={};return ar(e.value.split(Be)).forEach(o=>{let{property:i,value:a}=o,s=Nt[i];if(s){if(ta(s)){n[s]=k(void 0,{value:a,options:{VALUE:a.includes("T")?"DATE-TIME":"DATE"}},{timezones:r?.timezones});return}if(na(s)){n[s]=a.split(te).map(u=>Number(u));return}if(s==="byMonth"){n[s]=a.split(te).map(u=>Number(u)-1);return}if(ia(s)){n[s]=a.split(te).map(u=>Qi(void 0,{value:u}));return}if(sa(s)){n[s]=Number(a);return}if(s==="frequency"){if(!a||!bi.includes(a))return;n[s]=a;return}if(s==="workweekStart"){n[s]=Xi(void 0,{value:a});return}}}),x(t,n)},qe=(t,e)=>x(t,e.value),ua=(t,e)=>x(t,e.value),Ge=(t,e,r)=>x(t,e.value.split(",").map(n=>k(void 0,{value:n,options:e.options},r))),ca=(t,e)=>x(t,e.value),la=(t,e)=>x(t,e.value),da=(t,e)=>x(t,e.value),pe=(t,e)=>x(t,Number.parseInt(e.value,10)),ya=t=>t.replace(/\\(([,;\\])|([nN]))/g,(e,r,n)=>n||` `),U=(t,e)=>x(t,ya(e.value)),fa=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:Ht,objectKeyMap:xt,convertValues:{trigger:({line:o})=>zi(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>he(void 0,o),repeat:({line:o})=>pe(void 0,o)},convertArrayValues:{attachments:({line:o})=>Ii(void 0,o),attendees:({line:o})=>me(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},pa=(...t)=>{let[e,r,n]=t,o,i=q(e,r,{icsComponent:Wt,objectKeyMap:Ot,convertValues:{stamp:({line:a})=>k(void 0,a,{timezones:n?.timezones}),start:({line:a})=>k(void 0,a,{timezones:n?.timezones}),end:({line:a})=>k(void 0,a,{timezones:n?.timezones}),created:({line:a})=>k(void 0,a,{timezones:n?.timezones}),lastModified:({line:a})=>k(void 0,a,{timezones:n?.timezones}),categories:({line:a})=>a.value.split(te),description:({line:a})=>{var s;return(s=a.options)!=null&&s.ALTREP&&(o=a.options.ALTREP),U(void 0,a)},location:({line:a})=>U(void 0,a),comment:({line:a})=>U(void 0,a),summary:({line:a})=>U(void 0,a),recurrenceRule:({line:a})=>Oe(void 0,a,{timezones:n?.timezones}),duration:({line:a})=>he(void 0,a),organizer:({line:a})=>Ce(void 0,a),sequence:({line:a})=>pe(void 0,a),class:({line:a})=>qe(void 0,a),recurrenceId:({line:a})=>$e(void 0,a,{timezones:n?.timezones}),status:({line:a})=>ca(void 0,a),timeTransparent:({line:a})=>ua(void 0,a)},convertArrayValues:{attendees:({line:a})=>me(void 0,a),exceptionDates:({line:a})=>Ge(void 0,a,{timezones:n?.timezones})},childComponents:{alarms:{icsComponent:Ht,convert:a=>fa(void 0,a,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},timezones:n?.timezones,nonStandard:n?.nonStandard});return o&&(i.descriptionAltRep=o),i},ma=(...t)=>{let[e,r,n]=t,o=r.split("BEGIN:")[1].split(Fe)[0],i=vi.includes(o)?o:"STANDARD",a=r.split("TZOFFSETTO:")[1].split(Fe)[0];return q(e,r,{icsComponent:i,objectKeyMap:_t,defaultValues:{type:i},convertValues:{start:({line:s})=>Yi(void 0,s,a),recurrenceRule:({line:s})=>Oe(void 0,s,{timezones:n?.timezones}),recurrenceDate:({line:s})=>k(void 0,s,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},ha=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:Vt,objectKeyMap:Rt,convertValues:{lastModified:({line:o})=>fe(void 0,o)},childComponents:{props:{icsComponent:["DAYLIGHT","STANDARD"],convert:o=>ma(void 0,o,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},nonStandard:n?.nonStandard,timezones:n?.timezones})},ga=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:$t,objectKeyMap:Ut,convertValues:{stamp:({line:o})=>k(void 0,o,{timezones:n?.timezones}),start:({line:o})=>k(void 0,o,{timezones:n?.timezones}),due:({line:o})=>k(void 0,o,{timezones:n?.timezones}),created:({line:o})=>k(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>k(void 0,o,{timezones:n?.timezones}),completed:({line:o})=>k(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(te),description:({line:o})=>U(void 0,o),location:({line:o})=>U(void 0,o),comment:({line:o})=>U(void 0,o),summary:({line:o})=>U(void 0,o),recurrenceRule:({line:o})=>Oe(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>he(void 0,o),organizer:({line:o})=>Ce(void 0,o),sequence:({line:o})=>pe(void 0,o),percentComplete:({line:o})=>pe(void 0,o),class:({line:o})=>qe(void 0,o),recurrenceId:({line:o})=>$e(void 0,o,{timezones:n?.timezones}),status:({line:o})=>la(void 0,o)},convertArrayValues:{attendees:({line:o})=>me(void 0,o),exceptionDates:({line:o})=>Ge(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},va=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:qt,objectKeyMap:Kt,convertValues:{stamp:({line:o})=>k(void 0,o,{timezones:n?.timezones}),start:({line:o})=>k(void 0,o,{timezones:n?.timezones}),created:({line:o})=>k(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>k(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(te),description:({line:o})=>U(void 0,o),comment:({line:o})=>U(void 0,o),summary:({line:o})=>U(void 0,o),recurrenceRule:({line:o})=>Oe(void 0,o,{timezones:n?.timezones}),organizer:({line:o})=>Ce(void 0,o),sequence:({line:o})=>pe(void 0,o),class:({line:o})=>qe(void 0,o),recurrenceId:({line:o})=>$e(void 0,o,{timezones:n?.timezones}),status:({line:o})=>da(void 0,o)},convertArrayValues:{attendees:({line:o})=>me(void 0,o),exceptionDates:({line:o})=>Ge(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},ba=(t,e)=>{var r;return x(t,{type:(r=e.options)==null?void 0:r.FBTYPE,values:e.value.split(",").map(n=>{let[o,i]=n.split("/"),a=fe(void 0,{value:o});if(i.startsWith("PT")){let u=he(void 0,{value:i});return{start:a,duration:u}}let s=fe(void 0,{value:i});return{start:a,end:s}})})},Ea=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:Gt,objectKeyMap:Ft,convertValues:{stamp:({line:o})=>k(void 0,o,{timezones:n?.timezones}),start:({line:o})=>k(void 0,o,{timezones:n?.timezones}),end:({line:o})=>k(void 0,o,{timezones:n?.timezones}),comment:({line:o})=>U(void 0,o),organizer:({line:o})=>Ce(void 0,o)},convertArrayValues:{attendees:({line:o})=>me(void 0,o),freeBusy:({line:o})=>ba(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},sr=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:_o,objectKeyMap:Dt,convertValues:{version:({line:o})=>o.value},childComponents:{timezones:{icsComponent:Vt,convert:o=>ha(void 0,o,{nonStandard:n?.nonStandard})},events:{icsComponent:Wt,convert:(o,{data:i})=>pa(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},todos:{icsComponent:$t,convert:(o,{data:i})=>ga(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},journals:{icsComponent:qt,convert:(o,{data:i})=>va(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},freeBusy:{icsComponent:Gt,convert:(o,{data:i})=>Ea(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})}},nonStandard:n?.nonStandard})};var Ze=function(t,e){return Ze=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(r[o]=n[o])},Ze(t,e)};function re(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");Ze(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var M=function(){return M=Object.assign||function(t){for(var e,r=1,n=arguments.length;r0?"+":"")+String(this.n)+e),e},t.prototype.getJsWeekday=function(){return this.weekday===6?0:this.weekday+1},t}(),D=function(t){return t!=null},F=function(t){return typeof t=="number"},ur=function(t){return typeof t=="string"&&Xe.includes(t)},I=Array.isArray,j=function(t,e){e===void 0&&(e=t),arguments.length===1&&(e=t,t=0);for(var r=[],n=t;n>0,n.length>e?String(n):(e=e-n.length,e>r.length&&(r+=T(r,e/r.length)),r.slice(0,e)+String(n))}var wa=function(t,e,r){var n=t.split(e);return r?n.slice(0,r).concat([n.slice(r).join(e)]):n},K=function(t,e){var r=t%e;return r*e<0?r+e:r},Je=function(t,e){return{div:Math.floor(t/e),mod:K(t,e)}},B=function(t){return!D(t)||t.length===0},O=function(t){return!B(t)},A=function(t,e){return O(t)&&t.indexOf(e)!==-1},Q=function(t,e,r,n,o,i){return n===void 0&&(n=0),o===void 0&&(o=0),i===void 0&&(i=0),new Date(Date.UTC(t,e-1,r,n,o,i))},Sa=[31,28,31,30,31,30,31,31,30,31,30,31],xr=1e3*60*60*24,kr=9999,Dr=Q(1970,1,1),Aa=[6,0,1,2,3,4,5],ve=function(t){return t%4===0&&t%100!==0||t%400===0},Cr=function(t){return t instanceof Date},ge=function(t){return Cr(t)&&!isNaN(t.getTime())},xa=function(t,e){var r=t.getTime(),n=e.getTime(),o=r-n;return Math.round(o/xr)},et=function(t){return xa(t,Dr)},Or=function(t){return new Date(Dr.getTime()+t*xr)},ka=function(t){var e=t.getUTCMonth();return e===1&&ve(t.getUTCFullYear())?29:Sa[e]},ae=function(t){return Aa[t.getUTCDay()]},cr=function(t,e){var r=Q(t,e+1,1);return[ae(r),ka(r)]},Mr=function(t,e){return e=e||t,new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))},tt=function(t){var e=new Date(t.getTime());return e},lr=function(t){for(var e=[],r=0;rthis.maxDate;if(this.method==="between"){if(r)return!0;if(n)return!1}else if(this.method==="before"){if(n)return!1}else if(this.method==="after")return r?!0:(this.add(e),!1);return this.add(e)},t.prototype.add=function(e){return this._result.push(e),!0},t.prototype.getValue=function(){var e=this._result;switch(this.method){case"all":case"between":return e;case"before":case"after":default:return e.length?e[e.length-1]:null}},t.prototype.clone=function(){return new t(this.method,this.args)},t}(),ie=Ca,Oa=function(t){re(e,t);function e(r,n,o){var i=t.call(this,r,n)||this;return i.iterator=o,i}return e.prototype.add=function(r){return this.iterator(r,this._result.length)?(this._result.push(r),!0):!1},e}(ie),yr=Oa,Ma={dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],tokens:{SKIP:/^[ \r\n\t]+|^\.$/,number:/^[1-9][0-9]*/,numberAsText:/^(one|two|three)/i,every:/^every/i,"day(s)":/^days?/i,"weekday(s)":/^weekdays?/i,"week(s)":/^weeks?/i,"hour(s)":/^hours?/i,"minute(s)":/^minutes?/i,"month(s)":/^months?/i,"year(s)":/^years?/i,on:/^(on|in)/i,at:/^(at)/i,the:/^the/i,first:/^first/i,second:/^second/i,third:/^third/i,nth:/^([1-9][0-9]*)(\.|th|nd|rd|st)/i,last:/^last/i,for:/^for/i,"time(s)":/^times?/i,until:/^(un)?til/i,monday:/^mo(n(day)?)?/i,tuesday:/^tu(e(s(day)?)?)?/i,wednesday:/^we(d(n(esday)?)?)?/i,thursday:/^th(u(r(sday)?)?)?/i,friday:/^fr(i(day)?)?/i,saturday:/^sa(t(urday)?)?/i,sunday:/^su(n(day)?)?/i,january:/^jan(uary)?/i,february:/^feb(ruary)?/i,march:/^mar(ch)?/i,april:/^apr(il)?/i,may:/^may/i,june:/^june?/i,july:/^july?/i,august:/^aug(ust)?/i,september:/^sep(t(ember)?)?/i,october:/^oct(ober)?/i,november:/^nov(ember)?/i,december:/^dec(ember)?/i,comma:/^(,\s*|(and|or)\s*)+/i}},Me=Ma,fr=function(t,e){return t.indexOf(e)!==-1},Ra=function(t){return t.toString()},Pa=function(t,e,r){return"".concat(e," ").concat(r,", ").concat(t)},_a=function(){function t(e,r,n,o){if(r===void 0&&(r=Ra),n===void 0&&(n=Me),o===void 0&&(o=Pa),this.text=[],this.language=n||Me,this.gettext=r,this.dateFormatter=o,this.rrule=e,this.options=e.options,this.origOptions=e.origOptions,this.origOptions.bymonthday){var i=[].concat(this.options.bymonthday),a=[].concat(this.options.bynmonthday);i.sort(function(l,p){return l-p}),a.sort(function(l,p){return p-l}),this.bymonthday=i.concat(a),this.bymonthday.length||(this.bymonthday=null)}if(D(this.origOptions.byweekday)){var s=I(this.origOptions.byweekday)?this.origOptions.byweekday:[this.origOptions.byweekday],u=String(s);this.byweekday={allWeeks:s.filter(function(l){return!l.n}),someWeeks:s.filter(function(l){return!!l.n}),isWeekdays:u.indexOf("MO")!==-1&&u.indexOf("TU")!==-1&&u.indexOf("WE")!==-1&&u.indexOf("TH")!==-1&&u.indexOf("FR")!==-1&&u.indexOf("SA")===-1&&u.indexOf("SU")===-1,isEveryDay:u.indexOf("MO")!==-1&&u.indexOf("TU")!==-1&&u.indexOf("WE")!==-1&&u.indexOf("TH")!==-1&&u.indexOf("FR")!==-1&&u.indexOf("SA")!==-1&&u.indexOf("SU")!==-1};var c=function(l,p){return l.weekday-p.weekday};this.byweekday.allWeeks.sort(c),this.byweekday.someWeeks.sort(c),this.byweekday.allWeeks.length||(this.byweekday.allWeeks=null),this.byweekday.someWeeks.length||(this.byweekday.someWeeks=null)}else this.byweekday=null}return t.isFullyConvertible=function(e){var r=!0;if(!(e.options.freq in t.IMPLEMENTED)||e.origOptions.until&&e.origOptions.count)return!1;for(var n in e.origOptions){if(fr(["dtstart","tzid","wkst","freq"],n))return!0;if(!fr(t.IMPLEMENTED[e.options.freq],n))return!1}return r},t.prototype.isFullyConvertible=function(){return t.isFullyConvertible(this.rrule)},t.prototype.toString=function(){var e=this.gettext;if(!(this.options.freq in t.IMPLEMENTED))return e("RRule error: Unable to fully convert this rrule to text");if(this.text=[e("every")],this[v.FREQUENCIES[this.options.freq]](),this.options.until){this.add(e("until"));var r=this.options.until;this.add(this.dateFormatter(r.getUTCFullYear(),this.language.monthNames[r.getUTCMonth()],r.getUTCDate()))}else this.options.count&&this.add(e("for")).add(this.options.count.toString()).add(this.plural(this.options.count)?e("times"):e("time"));return this.isFullyConvertible()||this.add(e("(~ approximate)")),this.text.join("")},t.prototype.HOURLY=function(){var e=this.gettext;this.options.interval!==1&&this.add(this.options.interval.toString()),this.add(this.plural(this.options.interval)?e("hours"):e("hour"))},t.prototype.MINUTELY=function(){var e=this.gettext;this.options.interval!==1&&this.add(this.options.interval.toString()),this.add(this.plural(this.options.interval)?e("minutes"):e("minute"))},t.prototype.DAILY=function(){var e=this.gettext;this.options.interval!==1&&this.add(this.options.interval.toString()),this.byweekday&&this.byweekday.isWeekdays?this.add(this.plural(this.options.interval)?e("weekdays"):e("weekday")):this.add(this.plural(this.options.interval)?e("days"):e("day")),this.origOptions.bymonth&&(this.add(e("in")),this._bymonth()),this.bymonthday?this._bymonthday():this.byweekday?this._byweekday():this.origOptions.byhour&&this._byhour()},t.prototype.WEEKLY=function(){var e=this.gettext;this.options.interval!==1&&this.add(this.options.interval.toString()).add(this.plural(this.options.interval)?e("weeks"):e("week")),this.byweekday&&this.byweekday.isWeekdays?this.options.interval===1?this.add(this.plural(this.options.interval)?e("weekdays"):e("weekday")):this.add(e("on")).add(e("weekdays")):this.byweekday&&this.byweekday.isEveryDay?this.add(this.plural(this.options.interval)?e("days"):e("day")):(this.options.interval===1&&this.add(e("week")),this.origOptions.bymonth&&(this.add(e("in")),this._bymonth()),this.bymonthday?this._bymonthday():this.byweekday&&this._byweekday(),this.origOptions.byhour&&this._byhour())},t.prototype.MONTHLY=function(){var e=this.gettext;this.origOptions.bymonth?(this.options.interval!==1&&(this.add(this.options.interval.toString()).add(e("months")),this.plural(this.options.interval)&&this.add(e("in"))),this._bymonth()):(this.options.interval!==1&&this.add(this.options.interval.toString()),this.add(this.plural(this.options.interval)?e("months"):e("month"))),this.bymonthday?this._bymonthday():this.byweekday&&this.byweekday.isWeekdays?this.add(e("on")).add(e("weekdays")):this.byweekday&&this._byweekday()},t.prototype.YEARLY=function(){var e=this.gettext;this.origOptions.bymonth?(this.options.interval!==1&&(this.add(this.options.interval.toString()),this.add(e("years"))),this._bymonth()):(this.options.interval!==1&&this.add(this.options.interval.toString()),this.add(this.plural(this.options.interval)?e("years"):e("year"))),this.bymonthday?this._bymonthday():this.byweekday&&this._byweekday(),this.options.byyearday&&this.add(e("on the")).add(this.list(this.options.byyearday,this.nth,e("and"))).add(e("day")),this.options.byweekno&&this.add(e("in")).add(this.plural(this.options.byweekno.length)?e("weeks"):e("week")).add(this.list(this.options.byweekno,void 0,e("and")))},t.prototype._bymonthday=function(){var e=this.gettext;this.byweekday&&this.byweekday.allWeeks?this.add(e("on")).add(this.list(this.byweekday.allWeeks,this.weekdaytext,e("or"))).add(e("the")).add(this.list(this.bymonthday,this.nth,e("or"))):this.add(e("on the")).add(this.list(this.bymonthday,this.nth,e("and")))},t.prototype._byweekday=function(){var e=this.gettext;this.byweekday.allWeeks&&!this.byweekday.isWeekdays&&this.add(e("on")).add(this.list(this.byweekday.allWeeks,this.weekdaytext)),this.byweekday.someWeeks&&(this.byweekday.allWeeks&&this.add(e("and")),this.add(e("on the")).add(this.list(this.byweekday.someWeeks,this.weekdaytext,e("and"))))},t.prototype._byhour=function(){var e=this.gettext;this.add(e("at")).add(this.list(this.origOptions.byhour,void 0,e("and")))},t.prototype._bymonth=function(){this.add(this.list(this.options.bymonth,this.monthtext,this.gettext("and")))},t.prototype.nth=function(e){e=parseInt(e.toString(),10);var r,n=this.gettext;if(e===-1)return n("last");var o=Math.abs(e);switch(o){case 1:case 21:case 31:r=o+n("st");break;case 2:case 22:r=o+n("nd");break;case 3:case 23:r=o+n("rd");break;default:r=o+n("th")}return e<0?r+" "+n("last"):r},t.prototype.monthtext=function(e){return this.language.monthNames[e-1]},t.prototype.weekdaytext=function(e){var r=F(e)?(e+1)%7:e.getJsWeekday();return(e.n?this.nth(e.n)+" ":"")+this.language.dayNames[r]},t.prototype.plural=function(e){return e%100!==1},t.prototype.add=function(e){return this.text.push(" "),this.text.push(e),this},t.prototype.list=function(e,r,n,o){var i=this;o===void 0&&(o=","),I(e)||(e=[e]);var a=function(u,c,l){for(var p="",d=0;de[0].length)&&(e=i,r=o)}if(e!=null&&(this.text=this.text.substr(e[0].length),this.text===""&&(this.done=!0)),e==null){this.done=!0,this.symbol=null,this.value=null;return}}while(r==="SKIP");return this.symbol=r,this.value=e,!0},t.prototype.accept=function(e){if(this.symbol===e){if(this.value){var r=this.value;return this.nextSymbol(),r}return this.nextSymbol(),!0}return!1},t.prototype.acceptNumber=function(){return this.accept("number")},t.prototype.expect=function(e){if(this.accept(e))return!0;throw new Error("expected "+e+" but found "+this.symbol)},t}();function Rr(t,e){e===void 0&&(e=Me);var r={},n=new La(e.tokens);if(!n.start(t))return null;return o(),r;function o(){n.expect("every");var d=n.acceptNumber();if(d&&(r.interval=parseInt(d[0],10)),n.isDone())throw new Error("Unexpected end");switch(n.symbol){case"day(s)":r.freq=v.DAILY,n.nextSymbol()&&(a(),p());break;case"weekday(s)":r.freq=v.WEEKLY,r.byweekday=[v.MO,v.TU,v.WE,v.TH,v.FR],n.nextSymbol(),a(),p();break;case"week(s)":r.freq=v.WEEKLY,n.nextSymbol()&&(i(),a(),p());break;case"hour(s)":r.freq=v.HOURLY,n.nextSymbol()&&(i(),p());break;case"minute(s)":r.freq=v.MINUTELY,n.nextSymbol()&&(i(),p());break;case"month(s)":r.freq=v.MONTHLY,n.nextSymbol()&&(i(),p());break;case"year(s)":r.freq=v.YEARLY,n.nextSymbol()&&(i(),p());break;case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":r.freq=v.WEEKLY;var f=n.symbol.substr(0,2).toUpperCase();if(r.byweekday=[v[f]],!n.nextSymbol())return;for(;n.accept("comma");){if(n.isDone())throw new Error("Unexpected end");var g=u();if(!g)throw new Error("Unexpected symbol "+n.symbol+", expected weekday");r.byweekday.push(v[g]),n.nextSymbol()}a(),l(),p();break;case"january":case"february":case"march":case"april":case"may":case"june":case"july":case"august":case"september":case"october":case"november":case"december":if(r.freq=v.YEARLY,r.bymonth=[s()],!n.nextSymbol())return;for(;n.accept("comma");){if(n.isDone())throw new Error("Unexpected end");var b=s();if(!b)throw new Error("Unexpected symbol "+n.symbol+", expected month");r.bymonth.push(b),n.nextSymbol()}i(),p();break;default:throw new Error("Unknown symbol")}}function i(){var d=n.accept("on"),f=n.accept("the");if(d||f)do{var g=c(),b=u(),h=s();if(g)b?(n.nextSymbol(),r.byweekday||(r.byweekday=[]),r.byweekday.push(v[b].nth(g))):(r.bymonthday||(r.bymonthday=[]),r.bymonthday.push(g),n.accept("day(s)"));else if(b)n.nextSymbol(),r.byweekday||(r.byweekday=[]),r.byweekday.push(v[b]);else if(n.symbol==="weekday(s)")n.nextSymbol(),r.byweekday||(r.byweekday=[v.MO,v.TU,v.WE,v.TH,v.FR]);else if(n.symbol==="week(s)"){n.nextSymbol();var S=n.acceptNumber();if(!S)throw new Error("Unexpected symbol "+n.symbol+", expected week number");for(r.byweekno=[parseInt(S[0],10)];n.accept("comma");){if(S=n.acceptNumber(),!S)throw new Error("Unexpected symbol "+n.symbol+"; expected monthday");r.byweekno.push(parseInt(S[0],10))}}else if(h)n.nextSymbol(),r.bymonth||(r.bymonth=[]),r.bymonth.push(h);else return}while(n.accept("comma")||n.accept("the")||n.accept("on"))}function a(){var d=n.accept("at");if(d)do{var f=n.acceptNumber();if(!f)throw new Error("Unexpected symbol "+n.symbol+", expected hour");for(r.byhour=[parseInt(f[0],10)];n.accept("comma");){if(f=n.acceptNumber(),!f)throw new Error("Unexpected symbol "+n.symbol+"; expected hour");r.byhour.push(parseInt(f[0],10))}}while(n.accept("comma")||n.accept("at"))}function s(){switch(n.symbol){case"january":return 1;case"february":return 2;case"march":return 3;case"april":return 4;case"may":return 5;case"june":return 6;case"july":return 7;case"august":return 8;case"september":return 9;case"october":return 10;case"november":return 11;case"december":return 12;default:return!1}}function u(){switch(n.symbol){case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":return n.symbol.substr(0,2).toUpperCase();default:return!1}}function c(){switch(n.symbol){case"last":return n.nextSymbol(),-1;case"first":return n.nextSymbol(),1;case"second":return n.nextSymbol(),n.accept("last")?-2:2;case"third":return n.nextSymbol(),n.accept("last")?-3:3;case"nth":var d=parseInt(n.value[1],10);if(d<-366||d>366)throw new Error("Nth out of range: "+d);return n.nextSymbol(),n.accept("last")?-d:d;default:return!1}}function l(){n.accept("on"),n.accept("the");var d=c();if(d)for(r.bymonthday=[d],n.nextSymbol();n.accept("comma");){if(d=c(),!d)throw new Error("Unexpected symbol "+n.symbol+"; expected monthday");r.bymonthday.push(d),n.nextSymbol()}}function p(){if(n.symbol==="until"){var d=Date.parse(n.text);if(!d)throw new Error("Cannot parse until date:"+n.text);r.until=new Date(d)}else n.accept("for")&&(r.count=parseInt(n.value[0],10),n.expect("number"))}}var w;(function(t){t[t.YEARLY=0]="YEARLY",t[t.MONTHLY=1]="MONTHLY",t[t.WEEKLY=2]="WEEKLY",t[t.DAILY=3]="DAILY",t[t.HOURLY=4]="HOURLY",t[t.MINUTELY=5]="MINUTELY",t[t.SECONDLY=6]="SECONDLY"})(w||(w={}));function at(t){return t12){var n=Math.floor(this.month/12),o=K(this.month,12);this.month=o,this.year+=n,this.month===0&&(this.month=12,--this.year)}},e.prototype.addWeekly=function(r,n){n>this.getWeekday()?this.day+=-(this.getWeekday()+1+(6-n))+r*7:this.day+=-(this.getWeekday()-n)+r*7,this.fixDay()},e.prototype.addDaily=function(r){this.day+=r,this.fixDay()},e.prototype.addHours=function(r,n,o){for(n&&(this.hour+=Math.floor((23-this.hour)/r)*r);;){this.hour+=r;var i=Je(this.hour,24),a=i.div,s=i.mod;if(a&&(this.hour=s,this.addDaily(a)),B(o)||A(o,this.hour))break}},e.prototype.addMinutes=function(r,n,o,i){for(n&&(this.minute+=Math.floor((1439-(this.hour*60+this.minute))/r)*r);;){this.minute+=r;var a=Je(this.minute,60),s=a.div,u=a.mod;if(s&&(this.minute=u,this.addHours(s,!1,o)),(B(o)||A(o,this.hour))&&(B(i)||A(i,this.minute)))break}},e.prototype.addSeconds=function(r,n,o,i,a){for(n&&(this.second+=Math.floor((86399-(this.hour*3600+this.minute*60+this.second))/r)*r);;){this.second+=r;var s=Je(this.second,60),u=s.div,c=s.mod;if(u&&(this.second=c,this.addMinutes(u,!1,o,i)),(B(o)||A(o,this.hour))&&(B(i)||A(i,this.minute))&&(B(a)||A(a,this.second)))break}},e.prototype.fixDay=function(){if(!(this.day<=28)){var r=cr(this.year,this.month-1)[1];if(!(this.day<=r))for(;this.day>r;){if(this.day-=r,++this.month,this.month===13&&(this.month=1,++this.year,this.year>kr))return;r=cr(this.year,this.month-1)[1]}}},e.prototype.add=function(r,n){var o=r.freq,i=r.interval,a=r.wkst,s=r.byhour,u=r.byminute,c=r.bysecond;switch(o){case w.YEARLY:return this.addYears(i);case w.MONTHLY:return this.addMonths(i);case w.WEEKLY:return this.addWeekly(i,a);case w.DAILY:return this.addDaily(i);case w.HOURLY:return this.addHours(i,n,s);case w.MINUTELY:return this.addMinutes(i,n,s,u);case w.SECONDLY:return this.addSeconds(i,n,s,u,c)}},e}(Re);function Pr(t){for(var e=[],r=Object.keys(t),n=0,o=r;n=-366&&n<=366))throw new Error("bysetpos must be between 1 and 366, or between -366 and -1")}}if(!(e.byweekno||O(e.byweekno)||O(e.byyearday)||e.bymonthday||O(e.bymonthday)||D(e.byweekday)||D(e.byeaster)))switch(e.freq){case v.YEARLY:e.bymonth||(e.bymonth=e.dtstart.getUTCMonth()+1),e.bymonthday=e.dtstart.getUTCDate();break;case v.MONTHLY:e.bymonthday=e.dtstart.getUTCDate();break;case v.WEEKLY:e.byweekday=[ae(e.dtstart)];break}if(D(e.bymonth)&&!I(e.bymonth)&&(e.bymonth=[e.bymonth]),D(e.byyearday)&&!I(e.byyearday)&&F(e.byyearday)&&(e.byyearday=[e.byyearday]),!D(e.bymonthday))e.bymonthday=[],e.bynmonthday=[];else if(I(e.bymonthday)){for(var o=[],i=[],r=0;r0?o.push(n):n<0&&i.push(n)}e.bymonthday=o,e.bynmonthday=i}else e.bymonthday<0?(e.bynmonthday=[e.bymonthday],e.bymonthday=[]):(e.bynmonthday=[],e.bymonthday=[e.bymonthday]);if(D(e.byweekno)&&!I(e.byweekno)&&(e.byweekno=[e.byweekno]),!D(e.byweekday))e.bynweekday=null;else if(F(e.byweekday))e.byweekday=[e.byweekday],e.bynweekday=null;else if(ur(e.byweekday))e.byweekday=[_.fromStr(e.byweekday).weekday],e.bynweekday=null;else if(e.byweekday instanceof _)!e.byweekday.n||e.freq>v.MONTHLY?(e.byweekday=[e.byweekday.weekday],e.bynweekday=null):(e.bynweekday=[[e.byweekday.weekday,e.byweekday.n]],e.byweekday=null);else{for(var a=[],s=[],r=0;rv.MONTHLY?a.push(u.weekday):s.push([u.weekday,u.n])}e.byweekday=O(a)?a:null,e.bynweekday=O(s)?s:null}return D(e.byhour)?F(e.byhour)&&(e.byhour=[e.byhour]):e.byhour=e.freq=4?(l=0,c=s.yearlen+K(a-e.wkst,7)):c=n-l;for(var p=Math.floor(c/7),d=K(c,7),f=Math.floor(p+d/4),g=0;g0&&b<=f){var h=void 0;b>1?(h=l+(b-1)*7,l!==u&&(h-=7-u)):h=l;for(var S=0;S<7&&(s.wnomask[h]=1,h++,s.wdaymask[h]!==e.wkst);S++);}}if(A(e.byweekno,1)){var h=l+f*7;if(l!==u&&(h-=7-u),h=4?(ue=0,J=Le+K(N-e.wkst,7)):J=n-l,L=Math.floor(52+K(J,7)/4)}if(A(e.byweekno,L))for(var h=0;hi)return oe(t);if(L>=r){var N=gr(L,e);if(!t.accept(N)||s&&(--s,!s))return oe(t)}}else for(var S=f;Si)return oe(t);if(L>=r){var N=gr(L,e);if(!t.accept(N)||s&&(--s,!s))return oe(t)}}}if(e.interval===0||(u.add(e,b),u.year>kr))return oe(t);at(n)||(l=c.gettimeset(n)(u.hour,u.minute,u.second,0)),c.rebuild(u.year,u.month)}}function ys(t,e,r){var n=r.bymonth,o=r.byweekno,i=r.byweekday,a=r.byeaster,s=r.bymonthday,u=r.bynmonthday,c=r.byyearday;return O(n)&&!A(n,t.mmask[e])||O(o)&&!t.wnomask[e]||O(i)&&!A(i,t.wdaymask[e])||O(t.nwdaymask)&&!t.nwdaymask[e]||a!==null&&!A(t.eastermask,e)||(O(s)||O(u))&&!A(s,t.mdaymask[e])&&!A(u,t.nmdaymask[e])||O(c)&&(e=t.yearlen&&!A(c,e+1-t.yearlen)&&!A(c,-t.nextyearlen+e-t.yearlen))}function gr(t,e){return new _e(t,e.tzid).rezonedDate()}function oe(t){return t.getValue()}function fs(t,e,r,n,o){for(var i=!1,a=e;a=v.HOURLY&&O(o)&&!A(o,e.hour)||n>=v.MINUTELY&&O(i)&&!A(i,e.minute)||n>=v.SECONDLY&&O(a)&&!A(a,e.second)?[]:t.gettimeset(n)(e.hour,e.minute,e.second,e.millisecond)}var z={MO:new _(0),TU:new _(1),WE:new _(2),TH:new _(3),FR:new _(4),SA:new _(5),SU:new _(6)},st={freq:w.YEARLY,dtstart:null,interval:1,wkst:z.MO,count:null,until:null,tzid:null,bysetpos:null,bymonth:null,bymonthday:null,bynmonthday:null,byyearday:null,byweekno:null,byweekday:null,bynweekday:null,byhour:null,byminute:null,bysecond:null,byeaster:null},ms=Object.keys(st),v=function(){function t(e,r){e===void 0&&(e={}),r===void 0&&(r=!1),this._cache=r?null:new Ha,this.origOptions=Pr(e);var n=Ka(e).parsedOptions;this.options=n}return t.parseText=function(e,r){return Rr(e,r)},t.fromText=function(e,r){return Na(e,r)},t.fromString=function(e){return new t(t.parseString(e)||void 0)},t.prototype._iter=function(e){return _r(e,this.options)},t.prototype._cacheGet=function(e,r){return this._cache?this._cache._cacheGet(e,r):!1},t.prototype._cacheAdd=function(e,r,n){if(this._cache)return this._cache._cacheAdd(e,r,n)},t.prototype.all=function(e){if(e)return this._iter(new yr("all",{},e));var r=this._cacheGet("all");return r===!1&&(r=this._iter(new ie("all",{})),this._cacheAdd("all",r)),r},t.prototype.between=function(e,r,n,o){if(n===void 0&&(n=!1),!ge(e)||!ge(r))throw new Error("Invalid date passed in to RRule.between");var i={before:r,after:e,inc:n};if(o)return this._iter(new yr("between",i,o));var a=this._cacheGet("between",i);return a===!1&&(a=this._iter(new ie("between",i)),this._cacheAdd("between",a,i)),a},t.prototype.before=function(e,r){if(r===void 0&&(r=!1),!ge(e))throw new Error("Invalid date passed in to RRule.before");var n={dt:e,inc:r},o=this._cacheGet("before",n);return o===!1&&(o=this._iter(new ie("before",n)),this._cacheAdd("before",o,n)),o},t.prototype.after=function(e,r){if(r===void 0&&(r=!1),!ge(e))throw new Error("Invalid date passed in to RRule.after");var n={dt:e,inc:r},o=this._cacheGet("after",n);return o===!1&&(o=this._iter(new ie("after",n)),this._cacheAdd("after",o,n)),o},t.prototype.count=function(){return this.all().length},t.prototype.toString=function(){return nt(this.origOptions)},t.prototype.toText=function(e,r,n){return Ia(this,e,r,n)},t.prototype.isFullyConvertibleToText=function(){return Ua(this)},t.prototype.clone=function(){return new t(this.origOptions)},t.FREQUENCIES=["YEARLY","MONTHLY","WEEKLY","DAILY","HOURLY","MINUTELY","SECONDLY"],t.YEARLY=w.YEARLY,t.MONTHLY=w.MONTHLY,t.WEEKLY=w.WEEKLY,t.DAILY=w.DAILY,t.HOURLY=w.HOURLY,t.MINUTELY=w.MINUTELY,t.SECONDLY=w.SECONDLY,t.MO=z.MO,t.TU=z.TU,t.WE=z.WE,t.TH=z.TH,t.FR=z.FR,t.SA=z.SA,t.SU=z.SU,t.parseString=rt,t.optionsToString=nt,t}();function hs(t,e,r,n,o,i){var a={},s=t.accept;function u(d,f){r.forEach(function(g){g.between(d,f,!0).forEach(function(b){a[Number(b)]=!0})})}o.forEach(function(d){var f=new _e(d,i).rezonedDate();a[Number(f)]=!0}),t.accept=function(d){var f=Number(d);return isNaN(f)?s.call(this,d):!a[f]&&(u(new Date(f-1),new Date(f+1)),!a[f])?(a[f]=!0,s.call(this,d)):!0},t.method==="between"&&(u(t.args.after,t.args.before),t.accept=function(d){var f=Number(d);return a[f]?!0:(a[f]=!0,s.call(this,d))});for(var c=0;c1||o.length||i.length||a.length){var l=new ut(c);return l.dtstart(s),l.tzid(u||void 0),n.forEach(function(d){l.rrule(new v(Qe(d,s,u),c))}),o.forEach(function(d){l.rdate(d)}),i.forEach(function(d){l.exrule(new v(Qe(d,s,u),c))}),a.forEach(function(d){l.exdate(d)}),e.compatible&&e.dtstart&&l.rdate(s),l}var p=n[0]||{};return new v(Qe(p,p.dtstart||e.dtstart||s,p.tzid||e.tzid||u),c)}function br(t,e){return e===void 0&&(e={}),vs(t,bs(e))}function Qe(t,e,r){return M(M({},t),{dtstart:e,tzid:r})}function bs(t){var e=[],r=Object.keys(t),n=Object.keys(vr);if(r.forEach(function(o){A(n,o)||e.push(o)}),e.length)throw new Error("Invalid options: "+e.join(", "));return M(M({},vr),t)}function Es(t){if(t.indexOf(":")===-1)return{name:"RRULE",value:t};var e=wa(t,":",1),r=e[0],n=e[1];return{name:r,value:n}}function Ts(t){var e=Es(t),r=e.name,n=e.value,o=r.split(";");if(!o)throw new Error("empty property name");return{name:o[0].toUpperCase(),parms:o.slice(1),value:n}}function ws(t,e){if(e===void 0&&(e=!1),t=t&&t.trim(),!t)throw new Error("Invalid empty string");if(!e)return t.split(/\s/);for(var r=t.split(` `),n=0;n0&&o[0]===" "?(r[n-1]+=o.slice(1),r.splice(n,1)):n+=1:r.splice(n,1)}return r}function Ss(t){t.forEach(function(e){if(!/(VALUE=DATE(-TIME)?)|(TZID=)/.test(e))throw new Error("unsupported RDATE/EXDATE parm: "+e)})}function Er(t,e){return Ss(e),t.split(",").map(function(r){return it(r)})}function Tr(t){var e=this;return function(r){if(r!==void 0&&(e["_".concat(t)]=r),e["_".concat(t)]!==void 0)return e["_".concat(t)];for(var n=0;nl.format(p).replace(", ","T"),a=i(n,e),s=i(o,e),u=new Date(a+"Z").getTime();return new Date(s+"Z").getTime()-u}var Nr="0.4.4",Ir="icalendar:lastSync";console.log(`[iCalendar] Plug script executing at top level (Version ${Nr})`);var xs={frequency:"FREQ",until:"UNTIL",count:"COUNT",interval:"INTERVAL",bysecond:"BYSECOND",byminute:"BYMINUTE",byhour:"BYHOUR",byday:"BYDAY",bymonthday:"BYMONTHDAY",byyearday:"BYYEARDAY",byweekno:"BYWEEKNO",bymonth:"BYMONTH",bysetpos:"BYSETPOS",wkst:"WKST",workweekstart:"WKST",freq:"FREQ"};function lt(t){if(Array.isArray(t))return t.map(e=>lt(e)).join(",");if(t instanceof Date)return t.toISOString().replace(/[-:]/g,"").split(".")[0]+"Z";if(typeof t=="object"&&t!==null){let e=t.date||t.day||t.value;if(e!==void 0)return lt(e)}return String(t)}async function ks(t){let r=new TextEncoder().encode(t),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")}function Ee(t,e="America/Los_Angeles"){try{let r=t.toLocaleString("en-US",{timeZone:e,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1});console.log(`[iCalendar] Converting ${t.toISOString()} to ${e}: ${r}`);let n=r.match(/(\d{2})\/(\d{2})\/(\d{4}),\s*(\d{2}):(\d{2}):(\d{2})/);if(n){let[o,i,a,s,u,c,l]=n;return`${s}-${i}-${a}T${u}:${c}:${l}`}throw new Error("Failed to parse toLocaleString result")}catch(r){console.error(`[iCalendar] Error converting to timezone ${e}:`,r);let n=o=>String(o).padStart(2,"0");return t.getUTCFullYear()+"-"+n(t.getUTCMonth()+1)+"-"+n(t.getUTCDate())+"T"+n(t.getUTCHours())+":"+n(t.getUTCMinutes())+":"+n(t.getUTCSeconds())}}function dt(t){if(t==null)return t;if(t instanceof Date)return t.toISOString();if(typeof t=="object"&&"date"in t&&t.date instanceof Date)return t.date.toISOString();if(typeof t=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(t))try{return new Date(t).toISOString()}catch{return t}if(Array.isArray(t))return t.map(e=>dt(e));if(typeof t=="object"){let e={};for(let r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=dt(t[r]));return e}return t}async function Ds(){try{let t=await Te.get("icalendar",{sources:[]});console.log("[iCalendar] Raw config retrieved:",JSON.stringify(t));let e=t.sources||[],r=t.syncWindowDays||365,n=t.displayTimezone||"America/Los_Angeles";if(e&&typeof e=="object"&&!Array.isArray(e)){let o=[];for(let i in e)e[i]&&typeof e[i].url=="string"&&o.push(e[i]);e=o}return{sources:e,syncWindowDays:r,displayTimezone:n}}catch(t){return console.error("[iCalendar] Error in getSources:",t),{sources:[],syncWindowDays:365,displayTimezone:"America/Los_Angeles"}}}async function Ur(t){let e=t.start;if(!e)return null;let r=null;if(e.local?.date){let s=e.local.date;r=s instanceof Date?s.toISOString():String(s)}else if(e.date){let s=e.date;r=s instanceof Date?s.toISOString():String(s)}if(!r)return null;r=r.replace(/Z$/,"");let n=e.local?.timezone||e.timezone||"UTC",o=ct(n);if(!o){console.warn(`[iCalendar] Unknown timezone: "${n}" - falling back to UTC for event "${t.summary}"`);let s=new Date(r+(r.includes("T")?"":"T00:00:00")+"Z");return isNaN(s.getTime())?null:s}let i=new Date(r+(r.includes("T")?"":"T00:00:00")+"Z");if(isNaN(i.getTime()))return null;let a=Lr(o,i);return new Date(i.getTime()-a)}async function Cs(t){if(!t.end)return null;let e={...t,start:t.end};return await Ur(e)}function Os(t,e=365,r="America/Los_Angeles",n=new Date){let o=t.rrule||t.recurrenceRule;if(!o)return[t];try{let i=new ut,a="";if(typeof o=="string")a=o.replace(/^RRULE:/i,"");else if(typeof o=="object"&&o!==null)a=Object.entries(o).map(([f,g])=>`${xs[f.toLowerCase()]||f.toUpperCase()}=${lt(g)}`).join(";");else return console.warn(`[iCalendar] Invalid rrule type (${typeof o}) for event "${t.summary||"Untitled"}". Treating as non-recurring.`),[t];let s=new Date(t.start);if(isNaN(s.getTime()))return console.error(`[iCalendar] Invalid start date for recurrence: ${t.start}`),[t];let u=v.parseString(a);u.dtstart=s,i.rrule(new v(u));for(let f of t.exdate||[])i.exdate(new Date(f));let c=new Date(n.getTime()+e*864e5),l=i.between(s,c,!0),p=t.end?new Date(t.end).getTime()-s.getTime():0;return l.map(f=>{let g=p>0?new Date(f.getTime()+p):null;return{...t,start:f.toISOString(),startLocal:Ee(f,r),end:g?g.toISOString():void 0,endLocal:g?Ee(g,r):void 0,recurrent:!0,rrule:void 0}})}catch(i){return console.error(`[iCalendar] Error expanding recurrence for ${t.summary}:`,i),[t]}}async function Ms(t,e=365,r="America/Los_Angeles"){try{let n=await fetch(t.url);if(!n.ok)return console.error(`[iCalendar] Fetch failed for ${t.name}: ${n.status} ${n.statusText}`),[];let o=await n.text(),i=sr(void 0,o);if(!i||!i.events)return[];let a=[];for(let s of i.events){if(s.status?.toUpperCase()==="CANCELLED")continue;let u=await Ur(s);if(!u)continue;let c=await Cs(s),l=s.start?.local?.timezone||s.start?.timezone||"UTC",p={...s,name:s.summary||"Untitled Event",start:u.toISOString(),startLocal:Ee(u,r),end:c?c.toISOString():void 0,endLocal:c?Ee(c,r):void 0,tag:"ical-event",sourceName:t.name,timezone:l};l!=="UTC"&&l!=="None"&&!ct(l)&&(p.description=`(Warning: Unknown timezone "${l}") ${p.description||""}`);let d=Os(p,e,r);for(let f of d){let g=`${f.start}${f.uid||""}${f.summary||""}`;f.ref=await ks(g);let b={start:f.start,startLocal:f.startLocal,end:f.end,endLocal:f.endLocal},h=dt(f);h.start=b.start,h.startLocal=b.startLocal,h.end=b.end,h.endLocal=b.endLocal,a.push(h)}}return a}catch(n){return console.error(`[iCalendar] Error fetching/parsing ${t.name}:`,n.message||n,n.stack||""),[]}}async function yt(){try{let{sources:t,syncWindowDays:e,displayTimezone:r}=await Ds();if(t.length===0)return;console.log(`[iCalendar] Using display timezone: ${r}`);let n=new Date("2026-02-21T14:00:00.000Z"),o=Ee(n,r);console.log(`[iCalendar] Timezone test: ${n.toISOString()} \u2192 ${o} (should be 06:00 PST)`),await H.flashNotification("Syncing calendars...","info");let i=[];for(let a of t){let s=await Ms(a,e,r);i.push(...s)}await we.indexObjects("$icalendar",i),await H.flashNotification(`Synced ${i.length} events`,"info")}catch(t){console.error("[iCalendar] syncCalendars failed:",t)}}async function Yr(){await de.del(Ir),await yt()}async function Kr(){if(!await H.confirm("Clear all calendar events?"))return;let t=await ye.query({prefix:["ridx","$icalendar"]}),e=[];for(let{key:r}of t)e.push(r),e.push(["idx",...r.slice(2),"$icalendar"]);e.length>0&&await ye.batchDel(e),await de.del(Ir),await H.flashNotification("Calendar index cleared","info")}async function zr(){await H.flashNotification(`iCalendar Plug ${Nr}`,"info")}var Fr={syncCalendars:yt,forceSync:Yr,clearCache:Kr,showVersion:zr},Br={name:"icalendar",version:"0.4.4",author:"sstent",index:"icalendar.ts",requiredPermissions:["fetch"],permissions:["fetch","http"],functions:{syncCalendars:{path:"icalendar.ts:syncCalendars",command:{name:"iCalendar: Sync",priority:-1},events:["editor:init"]},forceSync:{path:"icalendar.ts:forceSync",command:{name:"iCalendar: Force Sync",priority:-1}},clearCache:{path:"icalendar.ts:clearCache",command:{name:"iCalendar: Clear All Events",priority:-1}},showVersion:{path:"icalendar.ts:showVersion",command:{name:"iCalendar: Version",priority:-2}}},assets:{}},ac={manifest:Br,functionMapping:Fr};ht(Fr,Br,self.postMessage);export{ac as plug}; //# sourceMappingURL=icalendar.plug.js.map