diff --git a/icalendar.plug.js b/icalendar.plug.js index c8849e1..3916d30 100644 --- a/icalendar.plug.js +++ b/icalendar.plug.js @@ -1,4 +1,10 @@ -var vt=Object.defineProperty;var I=(e,t)=>{for(var r in t)vt(e,r,{get:t[r],enumerable:!0})};function ye(e){let t=atob(e),r=t.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=t("log"),console.info=t("info"),console.warn=t("warn"),console.error=t("error"),console.debug=t("debug")}captureLog(t,r){let n={level:t,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(t,r){if(this.logBuffer.length>0){let o=[...this.logBuffer];this.logBuffer=[];try{if(!(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o.map(i=>({...i,source:r})))})).ok)throw new Error("Failed to post logs to server")}catch(s){console.warn("Could not post logs to server",s.message),this.logBuffer.unshift(...o)}}}},ge;function ve(e=""){return ge=new Q(e),ge}var L=e=>{throw new Error("Not initialized yet")},te=typeof window>"u"&&typeof globalThis.WebSocketPair>"u";typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var ee=new Map,X=0;te&&(globalThis.syscall=async(e,...t)=>await new Promise((r,n)=>{X++,ee.set(X,{resolve:r,reject:n}),L({type:"sys",id:X,name:e,args:t})}));function Ee(e,t,r){te&&(L=r,self.addEventListener("message",n=>{(async()=>{let o=n.data;switch(o.type){case"inv":{let s=e[o.name];if(!s)throw new Error(`Function not loaded: ${o.name}`);try{let i=await Promise.resolve(s(...o.args||[]));L({type:"invr",id:o.id,result:i})}catch(i){console.error("An exception was thrown as a result of invoking function",o.name,"error:",i.message),L({type:"invr",id:o.id,error:i.message})}}break;case"sysr":{let s=o.id,i=ee.get(s);if(!i)throw Error("Invalid request id");ee.delete(s),o.error?i.reject(new Error(o.error)):i.resolve(o.result)}break}})().catch(console.error)}),L({type:"manifest",manifest:t}),ve(`[${t.name} plug]`))}async function Et(e,t){if(typeof e!="string"){let r=new Uint8Array(await e.arrayBuffer()),n=r.length>0?Z(r):void 0;t={method:e.method,headers:Object.fromEntries(e.headers.entries()),base64Body:n},e=e.url}return syscall("sandboxFetch.fetch",e,t)}globalThis.nativeFetch=globalThis.fetch;function Tt(){globalThis.fetch=async function(e,t){let r=t&&t.body?Z(new Uint8Array(await new Response(t.body).arrayBuffer())):void 0,n=await Et(e,t&&{method:t.method,headers:t.headers,base64Body:r});return new Response(n.base64Body?ye(n.base64Body):null,{status:n.status,headers:n.headers})}}te&&Tt();var x={};I(x,{alert:()=>nr,configureVimMode:()=>Sr,confirm:()=>rr,copyToClipboard:()=>fr,deleteLine:()=>yr,dispatch:()=>er,downloadFile:()=>Vt,filterBox:()=>Ht,flashNotification:()=>$t,fold:()=>sr,foldAll:()=>ur,getCurrentEditor:()=>Ct,getCurrentPage:()=>St,getCurrentPageMeta:()=>ht,getCurrentPath:()=>At,getCursor:()=>Dt,getRecentlyOpenedPages:()=>Pt,getSelection:()=>Mt,getText:()=>xt,getUiOption:()=>or,goHistory:()=>Bt,hidePanel:()=>jt,insertAtCursor:()=>Xt,insertAtPos:()=>Gt,invokeCommand:()=>Ot,isMobile:()=>Ar,moveCursor:()=>Zt,moveCursorToLine:()=>Qt,moveLineDown:()=>Er,moveLineUp:()=>vr,navigate:()=>wt,newWindow:()=>kt,openCommandPalette:()=>Lt,openPageNavigator:()=>It,openSearchPanel:()=>pr,openUrl:()=>Ft,prompt:()=>tr,rebuildEditorState:()=>Yt,redo:()=>mr,reloadConfigAndCommands:()=>Ut,reloadPage:()=>Kt,reloadUI:()=>zt,replaceRange:()=>Jt,save:()=>Nt,sendMessage:()=>hr,setSelection:()=>Rt,setText:()=>bt,setUiOption:()=>ir,showPanel:()=>qt,showProgress:()=>Wt,toggleComment:()=>gr,toggleFold:()=>lr,undo:()=>dr,unfold:()=>ar,unfoldAll:()=>cr,uploadFile:()=>_t,vimEx:()=>Tr});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function l(e,...t){return globalThis.syscall(e,...t)}function St(){return l("editor.getCurrentPage")}function ht(){return l("editor.getCurrentPageMeta")}function At(){return l("editor.getCurrentPath")}function Pt(){return l("editor.getRecentlyOpenedPages")}function Ct(){return l("editor.getCurrentEditor")}function xt(){return l("editor.getText")}function bt(e,t=!1){return l("editor.setText",e,t)}function Dt(){return l("editor.getCursor")}function Mt(){return l("editor.getSelection")}function Rt(e,t){return l("editor.setSelection",e,t)}function Ot(e,t){return l("editor.invokeCommand",e,t)}function Nt(){return l("editor.save")}function wt(e,t=!1,r=!1){return l("editor.navigate",e,t,r)}function It(e="page"){return l("editor.openPageNavigator",e)}function Lt(){return l("editor.openCommandPalette")}function Kt(){return l("editor.reloadPage")}function zt(){return l("editor.reloadUI")}function Yt(){return l("editor.rebuildEditorState")}function Ut(){return l("editor.reloadConfigAndCommands")}function Ft(e,t=!1){return l("editor.openUrl",e,t)}function kt(){return l("editor.newWindow")}function Bt(e){return l("editor.goHistory",e)}function Vt(e,t){return l("editor.downloadFile",e,t)}function _t(e,t){return l("editor.uploadFile",e,t)}function $t(e,t="info"){return l("editor.flashNotification",e,t)}function Ht(e,t,r="",n=""){return l("editor.filterBox",e,t,r,n)}function qt(e,t,r,n=""){return l("editor.showPanel",e,t,r,n)}function jt(e){return l("editor.hidePanel",e)}function Wt(e,t){return l("editor.showProgress",e,t)}function Gt(e,t){return l("editor.insertAtPos",e,t)}function Jt(e,t,r){return l("editor.replaceRange",e,t,r)}function Zt(e,t=!1){return l("editor.moveCursor",e,t)}function Qt(e,t=1,r=!1){return l("editor.moveCursorToLine",e,t,r)}function Xt(e,t=!1,r=!1){return l("editor.insertAtCursor",e,t,r)}function er(e){return l("editor.dispatch",e)}function tr(e,t=""){return l("editor.prompt",e,t)}function rr(e){return l("editor.confirm",e)}function nr(e){return l("editor.alert",e)}function or(e){return l("editor.getUiOption",e)}function ir(e,t){return l("editor.setUiOption",e,t)}function sr(){return l("editor.fold")}function ar(){return l("editor.unfold")}function lr(){return l("editor.toggleFold")}function ur(){return l("editor.foldAll")}function cr(){return l("editor.unfoldAll")}function dr(){return l("editor.undo")}function mr(){return l("editor.redo")}function pr(){return l("editor.openSearchPanel")}function fr(e){return l("editor.copyToClipboard",e)}function yr(){return l("editor.deleteLine")}function gr(){return l("editor.toggleComment")}function vr(){return l("editor.moveLineUp")}function Er(){return l("editor.moveLineDown")}function Tr(e){return l("editor.vimEx",e)}function Sr(){return l("editor.configureVimMode")}function hr(e,t){return l("editor.sendMessage",e,t)}function Ar(){return l("editor.isMobile")}var K={};I(K,{del:()=>Mr,get:()=>Dr,set:()=>br});function br(e,t){return l("clientStore.set",e,t)}function Dr(e){return l("clientStore.get",e)}function Mr(e){return l("clientStore.delete",e)}var fi=new Uint8Array(16);var z={};I(z,{batchDel:()=>Br,batchDeletePrefix:()=>$r,batchGet:()=>Fr,batchSet:()=>Yr,del:()=>kr,get:()=>Ur,listFunctions:()=>qr,query:()=>Vr,queryDelete:()=>Hr,queryLua:()=>_r,set:()=>zr});function zr(e,t){return l("datastore.set",e,t)}function Yr(e){return l("datastore.batchSet",e)}function Ur(e){return l("datastore.get",e)}function Fr(e){return l("datastore.batchGet",e)}function kr(e){return l("datastore.delete",e)}function Br(e){return l("datastore.batchDelete",e)}function Vr(e){return l("datastore.query",e)}function _r(e,t,r){return l("datastore.queryLua",e,t,r)}function $r(e){return l("datastore.batchDeletePrefix",e)}function Hr(e,t){return l("datastore.queryDelete",e,t)}function qr(){return l("datastore.listFunctions")}var B={};I(B,{define:()=>Xr,get:()=>Gr,has:()=>Qr,insert:()=>Zr,set:()=>Jr});function Gr(e,t){return l("config.get",e,t)}function Jr(e,t){return l("config.set",e,t)}function Zr(e,t){return l("config.insert",e,t)}function Qr(e){return l("config.has",e)}function Xr(e,t){return l("config.define",e,t)}var V={};I(V,{ensureFullIndex:()=>nn,getObjectByRef:()=>rn,indexObjects:()=>en,queryLuaObjects:()=>tn});function en(e,t){return l("index.indexObjects",e,t)}function tn(e,t,r,n){return l("index.queryLuaObjects",e,t,r,n)}function rn(e,t,r){return l("index.getObjectByRef",e,t,r)}function nn(){return l("index.ensureFullIndex")}var C=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[r,t])),v=e=>Object.keys(e),be={action:"ACTION",description:"DESCRIPTION",duration:"DURATION",repeat:"REPEAT",summary:"SUMMARY",trigger:"TRIGGER",attachments:"ATTACH",attendees:"ATTENDEE"},De=C(be),Ri=v(De),Oi=v(be),Me={method:"METHOD",prodId:"PRODID",version:"VERSION",name:"X-WR-CALNAME"},Re=C(Me),Ni=v(Re),wi=v(Me),Oe={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"},Ne=C(Oe),Ii=v(Ne),Li=v(Oe),we={id:"TZID",lastModified:"LAST-MODIFIED",url:"TZURL"},Ie=C(we),Ki=v(Ie),zi=v(we),Le={comment:"COMMENT",name:"TZNAME",offsetFrom:"TZOFFSETFROM",offsetTo:"TZOFFSETTO",recurrenceDate:"RDATE",recurrenceRule:"RRULE",start:"DTSTART"},Ke=C(Le),Yi=v(Ke),Ui=v(Le),ze={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"},Ye=C(ze),Fi=v(Ye),ki=v(ze),Ue={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"},Fe=C(Ue),Bi=v(Fe),Vi=v(Ue),ke={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"},Be=C(ke),_i=v(Be),$i=v(ke),Ve={stamp:"DTSTAMP",start:"DTSTART",uid:"UID",url:"URL",organizer:"ORGANIZER",attendees:"ATTENDEE",comment:"COMMENT",end:"DTEND",freeBusy:"FREEBUSY"},_e=C(Ve),Hi=v(_e),qi=v(Ve),$e="BEGIN",He="END",on="VCALENDAR",qe="VTIMEZONE",sn="STANDARD",an="DAYLIGHT",je="VEVENT",We="VALARM",Ge="VTODO",Je="VJOURNAL",Ze="VFREEBUSY";var Te=e=>new RegExp(`${$e}:${e}([\\s\\S]*?)${He}:${e}`,"g"),ln=e=>new RegExp(`${$e}:${e}|${He}:${e}`,"g");var ne=/\r\n|\r|\n/;var Se=` -`,un=":",N=",",cn='"',oe=";";var he="=";var dn=Math.pow(10,8)*24*60*60*1e3,ji=-dn,mn=6048e5;var Qe=6e4,Xe=36e5,pn=3600,et=pn*24,Wi=et*7,fn=et*365.2425,yn=fn/12,Gi=yn*3,Ae=Symbol.for("constructDateFrom");function S(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Ae in e?e[Ae](t):e instanceof Date?new e.constructor(t):new Date(t)}function d(e,t){return S(t||e,e)}function se(e,t,r){let n=d(e,r?.in);return isNaN(t)?S(r?.in||e,NaN):(t&&n.setDate(n.getDate()+t),n)}function tt(e,t,r){let n=d(e,r?.in);if(isNaN(t))return S(r?.in||e,NaN);if(!t)return n;let o=n.getDate(),s=S(r?.in||e,n.getTime());s.setMonth(n.getMonth()+t+1,0);let i=s.getDate();return o>=i?s:(n.setFullYear(s.getFullYear(),s.getMonth(),o),n)}function q(e,t,r){return S(r?.in||e,+d(e)+t)}function gn(e,t,r){return q(e,t*Xe,r)}var vn={};function j(){return vn}function $(e,t){var r,n,o,s;let i=j(),a=t?.weekStartsOn??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.weekStartsOn)??i.weekStartsOn??((s=(o=i.locale)==null?void 0:o.options)==null?void 0:s.weekStartsOn)??0,u=d(e,t?.in),c=u.getDay(),m=(ctypeof n=="object"));return t.map(r)}function Tn(e,t){let r=d(e,t?.in);return r.setHours(0,0,0,0),r}function rt(e,t,r){let n=d(e,r?.in);return n.setTime(n.getTime()+t*Qe),n}function Sn(e,t,r){return q(e,t*1e3,r)}function ae(e,t,r){return se(e,t*7,r)}function nt(e,t,r){return tt(e,t*12,r)}function le(e,t){let r=+d(e)-+d(t);return r<0?-1:r>0?1:r}function Pe(e,t){let r=d(e,t?.in),n=r.getMonth();return r.setFullYear(r.getFullYear(),n+1,0),r.setHours(23,59,59,999),r}function hn(e,t){let[r,n]=En(e,t.start,t.end);return{start:r,end:n}}function An(e,t){let{start:r,end:n}=hn(t?.in,e),o=+r>+n,s=o?+r:+n,i=o?n:r;i.setHours(0,0,0,0);let a=t?.step??1;if(!a)return[];a<0&&(a=-a,o=!o);let u=[];for(;+i<=s;)u.push(S(r,i)),i.setDate(i.getDate()+a),i.setHours(0,0,0,0);return o?u.reverse():u}function Ce(e,t){let r=d(e,t?.in);return r.setDate(1),r.setHours(0,0,0,0),r}function Pn(e,t){let r=d(e,t?.in),n=r.getFullYear();return r.setFullYear(n+1,0,0),r.setHours(23,59,59,999),r}function Cn(e,t){let r=d(e,t?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function xn(e,t){var r,n,o,s;let i=d(e,t?.in),a=i.getFullYear(),u=j(),c=t?.firstWeekContainsDate??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??u.firstWeekContainsDate??((s=(o=u.locale)==null?void 0:o.options)==null?void 0:s.firstWeekContainsDate)??1,m=S(t?.in||e,0);m.setFullYear(a+1,0,c),m.setHours(0,0,0,0);let E=$(m,t),f=S(t?.in||e,0);f.setFullYear(a,0,c),f.setHours(0,0,0,0);let h=$(f,t);return+i>=+E?a+1:+i>=+h?a:a-1}function bn(e,t){var r,n,o,s;let i=j(),a=t?.firstWeekContainsDate??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??i.firstWeekContainsDate??((s=(o=i.locale)==null?void 0:o.options)==null?void 0:s.firstWeekContainsDate)??1,u=xn(e,t),c=S(t?.in||e,0);return c.setFullYear(u,0,a),c.setHours(0,0,0,0),$(c,t)}function Dn(e,t){let r=d(e,t?.in),n=+$(r,t)-+bn(r,t);return Math.round(n/mn)+1}function _(e,t){return d(e,t?.in).getDay()}function ot(e,t){let r=d(e,t?.in),n=r.getFullYear(),o=r.getMonth(),s=S(r,0);return s.setFullYear(n,o+1,0),s.setHours(0,0,0,0),s.getDate()}function Mn(e,t){return d(e,t?.in).getHours()}function Rn(e,t){return d(e,t?.in).getMinutes()}function it(e,t){return d(e,t?.in).getMonth()}function On(e){return d(e).getSeconds()}function Nn(e,t){return d(e,t?.in).getFullYear()}function wn(e,t){return+d(e)==+d(t)}function In(e,t,r){let n=d(e,r?.in),o=Dn(n,r)-t;return n.setDate(n.getDate()-o*7),d(n,r?.in)}function H(e,t,r){var n,o,s,i;let a=j(),u=r?.weekStartsOn??((o=(n=r?.locale)==null?void 0:n.options)==null?void 0:o.weekStartsOn)??a.weekStartsOn??((i=(s=a.locale)==null?void 0:s.options)==null?void 0:i.weekStartsOn)??0,c=d(e,r?.in),m=c.getDay(),E=(t%7+7)%7,f=7-u,h=t<0||t>6?t-(m+f)%7:(E+f)%7-(m+f)%7;return se(c,h,r)}function st(e,t,r){let n=+d(e,r?.in),[o,s]=[+d(t.start,r?.in),+d(t.end,r?.in)].sort((i,a)=>i-a);return n>=o&&n<=s}function Ln(e){let t=e/Xe;return Math.trunc(t)}function Kn(e){let t=e/Qe;return Math.trunc(t)}function zn(e,t,r){let n=d(e,r?.in),o=n.getFullYear(),s=n.getDate(),i=S(r?.in||e,0);i.setFullYear(o,t,15),i.setHours(0,0,0,0);let a=ot(i);return n.setMonth(t,Math.min(s,a)),n}function Yn(e,t,r){let n=d(e,r?.in);return n.setDate(t),n}function Un(e,t,r){let n=d(e,r?.in);return n.setMonth(0),n.setDate(t),n}function Fn(e,t,r){let n=d(e,r?.in);return n.setHours(t),n}function kn(e,t,r){let n=d(e,r?.in);return n.setMinutes(t),n}function Bn(e,t,r){let n=d(e,r?.in);return n.setSeconds(t),n}function Vn(e,t,r){return q(e,-t,r)}function _n(e,t,r){return ae(e,-t,r)}var $n=[sn,an];var Hn=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"];var at=["SU","MO","TU","WE","TH","FR","SA"];var R=(e,t)=>t===void 0?!1:e>=t,qn=(e,{start:t,end:r},n)=>{if(R(n.length,e.count))return;let o=e.frequency,s=e.interval||1;if(!o)return;let i=t;if(o==="SECONDLY"){for(;i{let o=r.map(({day:s,occurrence:i})=>({occurrence:i,day:at.indexOf(s)}));return e.frequency==="YEARLY"?e.byYearday||e.byMonthday?t.map(s=>s.filter(i=>o.find(({day:a})=>a===_(i)))):e.byWeekNo?t.map(s=>s.flatMap(i=>o.map(({day:a})=>H(i,a,{weekStartsOn:n})))):e.byMonth?t.map(s=>s.flatMap(i=>o.flatMap(({day:a,occurrence:u})=>re(b(Ce(i)),b(Pe(i)),a,n,u)))):t.map(s=>s.flatMap(i=>o.flatMap(({day:a,occurrence:u})=>re(b(Cn(i)),b(Pn(i)),a,n,u)))):e.frequency==="MONTHLY"?e.byMonthday?t.map(s=>s.filter(i=>o.find(({day:a})=>a===_(i)))):t.map(s=>s.flatMap(i=>o.flatMap(({day:a,occurrence:u})=>re(b(Ce(i)),b(Pe(i)),a,n,u)))):e.frequency==="WEEKLY"?t.map(s=>s.flatMap(i=>o.map(({day:a})=>H(i,a,{weekStartsOn:n})))):t.map(s=>s.filter(i=>o.find(({day:a})=>a===_(i))))},re=(e,t,r,n,o)=>{if(o!==void 0){if(!(o<0)){let a=H(e,r,{weekStartsOn:n}),u=e>a;return ae(a,(o||1)-1+(u?1:0))}let s=H(t,r,{weekStartsOn:n}),i=tb(s)).filter(s=>st(s,{start:e,end:t})).filter(s=>r===_(s))},b=e=>rt(e,-e.getTimezoneOffset()),Wn=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t.map(n=>n.flatMap(o=>r.map(s=>Fn(o,s)))):t.map(n=>n.filter(o=>r.includes(Mn(o)))),Gn=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"||e.frequency==="HOURLY"?t.map(n=>n.flatMap(o=>r.map(s=>kn(o,s)))):t.map(n=>n.filter(o=>r.includes(Rn(o)))),Jn=(e,t,r)=>e.frequency==="YEARLY"?t.map(n=>n.flatMap(o=>r.map(s=>zn(o,s)))):t.map(n=>n.filter(o=>r.includes(it(o)))),Zn=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"?t.map(n=>n.flatMap(o=>{let s=ot(o);return r.map(i=>i>s?void 0:Yn(o,i)).filter(i=>!!i)})):e.frequency==="WEEKLY"?t:t.map(n=>n.filter(o=>r.includes(it(o)))),Qn=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"||e.frequency==="HOURLY"||e.frequency==="MINUTELY"?t.map(n=>n.flatMap(o=>r.map(s=>Bn(o,s)))):t.map(n=>n.filter(o=>r.includes(On(o)))),Xn=(e,t,r)=>!e.byYearday&&!e.byWeekNo&&!e.byMonthday&&!e.byMonth&&!e.byDay&&!e.byHour&&!e.byMinute&&!e.bySecond?t:t.map(n=>n.sort(le).filter((o,s)=>r.some(i=>i>0?s===0?!1:s%i===0:s===0?n.length-1+i===0:s%(n.length-1+i)===0))),eo=(e,t,r,n)=>e.frequency==="YEARLY"?t.map(o=>o.flatMap(s=>r.map(i=>In(s,i,{weekStartsOn:n})))):t,to=(e,t,r)=>e.frequency==="YEARLY"?t.map(n=>n.flatMap(o=>r.map(s=>Un(o,s)))):e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t:t.map(n=>n.filter(o=>r.includes(Nn(o)))),ro=(e,t,r)=>{let n=r;return e.byMonth&&(n=Jn(e,n,e.byMonth)),e.byWeekNo&&(n=eo(e,n,e.byWeekNo,t.weekStartsOn)),e.byYearday&&(n=to(e,n,e.byYearday)),e.byMonthday&&(n=Zn(e,n,e.byMonthday)),e.byDay&&(n=jn(e,n,e.byDay,t.weekStartsOn)),e.byHour&&(n=Wn(e,n,e.byHour)),e.byMinute&&(n=Gn(e,n,e.byMinute)),e.bySecond&&(n=Qn(e,n,e.bySecond)),e.bySetPos&&(n=Xn(e,n,e.bySetPos)),n.map(o=>o.sort(le).filter(s=>!(t.exceptions.length>0&&t.exceptions.some(i=>wn(i,s))||!st(s,{start:t.start,end:t.end}))))},no=2,oo=(e,t)=>{var r;let n=t.start,o=((r=e.until)==null?void 0:r.date)||t?.end||nt(n,no),s=t.exceptions||[],i=(e.workweekStart?at.indexOf(e.workweekStart):1)%7,a=[[n]];qn(e,{start:n,end:o},a);let u=ro(e,{start:n,end:o,exceptions:s,weekStartsOn:i},a);return e.count?u.flat().splice(0,e.count):u.flat()},io=(e,t)=>t.flatMap(r=>!r.recurrenceRule||r.recurrenceRule.until&&r.recurrenceRule.until.date({...r,start:n}))),ie=e=>{let t=e[0]==="+"?1:-1,r=Number(e.slice(1,3)),n=e.length>3?Number(e.slice(3,5)):0,o=e.length>5?Number(e.slice(5,7)):0;return((r*60+n)*60+o)*1e3*t},so=(e,t)=>{let r="en-US",n=new Date(t.toLocaleString(r,{timeZone:"UTC"}));try{return new Date(t.toLocaleString(r,{timeZone:e})).getTime()-n.getTime()}catch{return t.getTime()-n.getTime()}},ao=(e,t,r)=>{let n=r?.find(s=>s.id===t);if(n){let s=io(e,n.props).sort((u,c)=>le(u.start,c.start));for(let u=0;u5?c.substring(0,5):c;return{offset:m,milliseconds:ie(m)}}let i=s[s.length-1].offsetTo,a=i.length>5?i.substring(0,5):i;return{offset:a,milliseconds:ie(a)}}let o=so(t,e);if(!Number.isNaN(o)){let s=o<0,i=Math.abs(Ln(o)),a=Math.abs(Kn(o))-i*60,u=i.toString().length===1?`0${i}`:i.toString(),c=a.toString().length===1?`0${a}`:a.toString();return{offset:`${s?"-":"+"}${u}${c}`,milliseconds:o}}};var p=(e,t)=>{if(e===void 0)return t;let r=e["~standard"].validate(t);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},lo=(e,t)=>{var r,n,o,s;let i=((r=t.options)==null?void 0:r.VALUE)==="BINARY"?{type:"binary",encoding:((n=t.options)==null?void 0:n.ENCODING)||"BASE64",binary:t.value,value:(o=t.options)==null?void 0:o.VALUE}:{type:"uri",url:t.value,formatType:(s=t.options)==null?void 0:s.FMTTYPE};return p(e,i)},O=e=>e.replace(/mailto:/gi,""),F=(e,t)=>{var r,n,o,s,i,a,u,c,m,E,f;return p(e,{email:O(t.value),delegatedFrom:(r=t.options)!=null&&r["DELEGATED-FROM"]?O((n=t.options)==null?void 0:n["DELEGATED-FROM"]):void 0,dir:(o=t.options)==null?void 0:o.DIR,member:(s=t.options)!=null&&s.MEMBER?O(t.options.MEMBER):void 0,name:(i=t.options)==null?void 0:i.CN,partstat:(a=t.options)==null?void 0:a.PARTSTAT,role:(u=t.options)==null?void 0:u.ROLE,sentBy:(c=t.options)!=null&&c["SENT-BY"]?O(t.options["SENT-BY"]):void 0,rsvp:(m=t.options)!=null&&m.RSVP?((E=t.options)==null?void 0:E.RSVP)==="TRUE"?!0:((f=t.options)==null?void 0:f.RSVP)==="FALSE"?!1:void 0:void 0})},k=(e,t)=>{let r=t.value,n={};r[0]==="-"&&(n.before=!0,r=r.slice(1)),r=r.slice(1);let o=r.split("T"),s=o[0];if(s.includes("D")){let[a,u]=s.split("D");n.days=Number(a),s=u}if(s.includes("W")){let[a,u]=s.split("W");n.weeks=Number(a),s=u}let i=o[1];if(i){if(i.includes("H")){let[a,u]=i.split("H");n.hours=Number(a),i=u}if(i.includes("M")){let[a,u]=i.split("M");n.minutes=Number(a),i=u}if(i.includes("S")){let[a,u]=i.split("S");n.seconds=Number(a),i=u}}return p(e,n)},uo=(e,t)=>{let r=Number.parseInt(t.value.slice(0,4),10),n=Number.parseInt(t.value.slice(4,6),10)-1,o=Number.parseInt(t.value.slice(6,8),10),s=new Date(Date.UTC(r,n,o));return p(e,s)},Y=(e,t)=>{let r=Number.parseInt(t.value.slice(0,4),10),n=Number.parseInt(t.value.slice(4,6),10)-1,o=Number.parseInt(t.value.slice(6,8),10),s=Number.parseInt(t.value.slice(9,11),10),i=Number.parseInt(t.value.slice(11,13),10),a=Number.parseInt(t.value.slice(13,15),10),u=new Date(Date.UTC(r,n,o,s,i,a));return p(e,u)},co=(e,t,r)=>{let n=ie(r),o=Y(void 0,t),s=Vn(o,n);return p(e,s)},mo=(e,t)=>{var r,n,o,s,i,a;if(((r=e.options)==null?void 0:r.VALUE)==="DATE")return{date:uo(void 0,e),type:(n=e.options)==null?void 0:n.VALUE};let u=((o=e.options)==null?void 0:o.VALUE)||"DATE-TIME",c=Y(void 0,e);if(!((s=e.options)!=null&&s.TZID))return{date:c,type:u};let m=ao(c,e.options.TZID,t?.timezones);return m?{date:q(c,-m.milliseconds),type:u,local:(i=e.options)!=null&&i.TZID?{date:c,timezone:(a=e.options)==null?void 0:a.TZID,tzoffset:m.offset}:void 0}:{date:c,type:u}},y=(e,t,r)=>p(e,mo(t,r)),po=(e,t,r)=>{var n,o,s,i;let a=((n=t.options)==null?void 0:n.VALUE)==="DATE-TIME"||((o=t.options)==null?void 0:o.VALUE)==="DATE"?{type:"absolute",value:y(void 0,t,r),options:{related:(s=t.options)==null?void 0:s.RELATED}}:{type:"relative",value:k(void 0,t),options:{related:(i=t.options)==null?void 0:i.RELATED}};return p(e,a)},fo=e=>e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e,lt=e=>e.map(t=>{let[r,...n]=t.split(he),o=n.join(he);return{property:r,value:fo(o)}},{}),yo=e=>e.reduce((t,r)=>(t[r.property]=r.value,t),{}),go=e=>yo(lt(e)),vo=e=>{let t=!1,r;for(let s=0;s{let{property:t,value:r}=vo(e);if(t.includes(oe)){let[n,...o]=t.split(oe),s=go(o);return{property:n,line:{options:s,value:r}}}return{property:t,line:{value:r}}},xe=e=>/^[ \t]/.test(e),To=e=>/^[A-Z]+(?:-[A-Z]+)*[:;]/.test(e),So=e=>{let t=[],r=e.split(ne);for(;r[0]==="";)r.shift();let n=r.length;for(;n>0&&r[n-1]==="";)n-=1,r.pop();for(let o=0;oo!=="")},ho=(e,t,r)=>{if(!t)return e;let n={};return Object.entries(t).forEach(([o,s])=>{let i=Object.entries(r||{}).find(([c,m])=>m.name===o);if(!i){n[Ao(o)]=s.value;return}let a=i[1].convert(s),u=i[1].schema;if(!u){n[i[0]]=a;return}n[i[0]]=p(u,a)}),e.nonStandard=n,e},Ao=e=>{let t=e.startsWith("X-")?e.slice(2):e,r="",n=!1;for(let o of t)o==="-"?n=!0:(r+=n?o.toUpperCase():o.toLowerCase(),n=!1);return r},Po=e=>e.startsWith("X-"),D=(e,t,r)=>{let n=t.replace(ln(r?.icsComponent),""),o=[...new Set(Object.values(r.childComponents||{}).flatMap(({icsComponent:E})=>E))],s=So(o.reduce((E,f)=>E.replace(Te(f),""),n)),i=r.defaultValues||{},a={};s.forEach(E=>{var f,h;let{property:A,line:P}=Eo(E);Po(A)&&(a[A]=P);let g=r.objectKeyMap[A];if(!g)return;let w=(f=r.convertArrayValues)==null?void 0:f[g];if(w){let M=w({line:P});if(!M)return;(i[g]===void 0||i[g]===null||!Array.isArray(i[g]))&&(i[g]=[]),Array.isArray(M)?i[g].push(...M):i[g].push(M);return}let fe=(h=r.convertValues)==null?void 0:h[g];if(fe){let M=fe({line:P});if(!M)return;i[g]=M;return}i[g]=P.value});let u=r.childComponents,c=u?Object.keys(u||{}):[];u&&c.length>0&&c.forEach(E=>{let f=u?.[E];if(!f)return;let h=Array.isArray(f.icsComponent)?f.icsComponent:[f.icsComponent],A=[],P=[];h.forEach(g=>{P.push(...n.matchAll(Te(g)))}),P.map(g=>g[0]).forEach(g=>{let w=f.convert(g,{data:i});w&&A.push(w)}),A.length!==0&&(i[E]=A)});let m=p(e,i);return r!=null&&r.nonStandard?ho(m,a,r?.nonStandard):m},W=(e,t)=>{var r,n,o;return p(e,{name:(r=t.options)==null?void 0:r.CN,dir:(n=t.options)==null?void 0:n.DIR,sentBy:(o=t.options)!=null&&o["SENT-BY"]?O(t.options["SENT-BY"]):void 0,email:O(t.value)})},ue=(e,t,r)=>{var n;return p(e,{value:y(void 0,t,r),range:(n=t.options)==null?void 0:n.RANGE})},Co=e=>{if(e.length===2)return{day:e};let t=e.slice(0,-2);return{day:e.replace(t,""),occurrence:Number(t)}},xo=(e,t)=>p(e,Co(t.value)),bo=(e,t)=>p(e,t.value),Do=["until"],Mo=e=>Do.includes(e),Ro=["bySecond","byMinute","byHour","byMonthday","byYearday","byWeekNo","bySetPos"],Oo=e=>Ro.includes(e),No=["byDay"],wo=e=>No.includes(e),Io=["count","interval"],Lo=e=>Io.includes(e),G=(e,t,r)=>{let n={};return lt(t.value.split(oe)).forEach(o=>{let{property:s,value:i}=o,a=Ye[s];if(a){if(Mo(a)){n[a]=y(void 0,{value:i,options:{VALUE:i.includes("T")?"DATE-TIME":"DATE"}},{timezones:r?.timezones});return}if(Oo(a)){n[a]=i.split(N).map(u=>Number(u));return}if(a==="byMonth"){n[a]=i.split(N).map(u=>Number(u)-1);return}if(wo(a)){n[a]=i.split(N).map(u=>xo(void 0,{value:u}));return}if(Lo(a)){n[a]=Number(i);return}if(a==="frequency"){if(!i||!Hn.includes(i))return;n[a]=i;return}if(a==="workweekStart"){n[a]=bo(void 0,{value:i});return}}}),p(e,n)},ce=(e,t)=>p(e,t.value),Ko=(e,t)=>p(e,t.value),de=(e,t,r)=>p(e,t.value.split(",").map(n=>y(void 0,{value:n,options:t.options},r))),zo=(e,t)=>p(e,t.value),Yo=(e,t)=>p(e,t.value),Uo=(e,t)=>p(e,t.value),U=(e,t)=>p(e,Number.parseInt(t.value,10)),Fo=e=>e.replace(/\\(([,;\\])|([nN]))/g,(t,r,n)=>n||` -`),T=(e,t)=>p(e,Fo(t.value)),ko=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:We,objectKeyMap:De,convertValues:{trigger:({line:o})=>po(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>k(void 0,o),repeat:({line:o})=>U(void 0,o)},convertArrayValues:{attachments:({line:o})=>lo(void 0,o),attendees:({line:o})=>F(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},Bo=(...e)=>{let[t,r,n]=e,o,s=D(t,r,{icsComponent:je,objectKeyMap:Ne,convertValues:{stamp:({line:i})=>y(void 0,i,{timezones:n?.timezones}),start:({line:i})=>y(void 0,i,{timezones:n?.timezones}),end:({line:i})=>y(void 0,i,{timezones:n?.timezones}),created:({line:i})=>y(void 0,i,{timezones:n?.timezones}),lastModified:({line:i})=>y(void 0,i,{timezones:n?.timezones}),categories:({line:i})=>i.value.split(N),description:({line:i})=>{var a;return(a=i.options)!=null&&a.ALTREP&&(o=i.options.ALTREP),T(void 0,i)},location:({line:i})=>T(void 0,i),comment:({line:i})=>T(void 0,i),summary:({line:i})=>T(void 0,i),recurrenceRule:({line:i})=>G(void 0,i,{timezones:n?.timezones}),duration:({line:i})=>k(void 0,i),organizer:({line:i})=>W(void 0,i),sequence:({line:i})=>U(void 0,i),class:({line:i})=>ce(void 0,i),recurrenceId:({line:i})=>ue(void 0,i,{timezones:n?.timezones}),status:({line:i})=>zo(void 0,i),timeTransparent:({line:i})=>Ko(void 0,i)},convertArrayValues:{attendees:({line:i})=>F(void 0,i),exceptionDates:({line:i})=>de(void 0,i,{timezones:n?.timezones})},childComponents:{alarms:{icsComponent:We,convert:i=>ko(void 0,i,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},timezones:n?.timezones,nonStandard:n?.nonStandard});return o&&(s.descriptionAltRep=o),s},Vo=(...e)=>{let[t,r,n]=e,o=r.split("BEGIN:")[1].split(ne)[0],s=$n.includes(o)?o:"STANDARD",i=r.split("TZOFFSETTO:")[1].split(ne)[0];return D(t,r,{icsComponent:s,objectKeyMap:Ke,defaultValues:{type:s},convertValues:{start:({line:a})=>co(void 0,a,i),recurrenceRule:({line:a})=>G(void 0,a,{timezones:n?.timezones}),recurrenceDate:({line:a})=>y(void 0,a,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},_o=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:qe,objectKeyMap:Ie,convertValues:{lastModified:({line:o})=>Y(void 0,o)},childComponents:{props:{icsComponent:["DAYLIGHT","STANDARD"],convert:o=>Vo(void 0,o,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},nonStandard:n?.nonStandard,timezones:n?.timezones})},$o=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:Ge,objectKeyMap:Fe,convertValues:{stamp:({line:o})=>y(void 0,o,{timezones:n?.timezones}),start:({line:o})=>y(void 0,o,{timezones:n?.timezones}),due:({line:o})=>y(void 0,o,{timezones:n?.timezones}),created:({line:o})=>y(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>y(void 0,o,{timezones:n?.timezones}),completed:({line:o})=>y(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(N),description:({line:o})=>T(void 0,o),location:({line:o})=>T(void 0,o),comment:({line:o})=>T(void 0,o),summary:({line:o})=>T(void 0,o),recurrenceRule:({line:o})=>G(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>k(void 0,o),organizer:({line:o})=>W(void 0,o),sequence:({line:o})=>U(void 0,o),percentComplete:({line:o})=>U(void 0,o),class:({line:o})=>ce(void 0,o),recurrenceId:({line:o})=>ue(void 0,o,{timezones:n?.timezones}),status:({line:o})=>Yo(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),exceptionDates:({line:o})=>de(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},Ho=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:Je,objectKeyMap:Be,convertValues:{stamp:({line:o})=>y(void 0,o,{timezones:n?.timezones}),start:({line:o})=>y(void 0,o,{timezones:n?.timezones}),created:({line:o})=>y(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>y(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(N),description:({line:o})=>T(void 0,o),comment:({line:o})=>T(void 0,o),summary:({line:o})=>T(void 0,o),recurrenceRule:({line:o})=>G(void 0,o,{timezones:n?.timezones}),organizer:({line:o})=>W(void 0,o),sequence:({line:o})=>U(void 0,o),class:({line:o})=>ce(void 0,o),recurrenceId:({line:o})=>ue(void 0,o,{timezones:n?.timezones}),status:({line:o})=>Uo(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),exceptionDates:({line:o})=>de(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},qo=(e,t)=>{var r;return p(e,{type:(r=t.options)==null?void 0:r.FBTYPE,values:t.value.split(",").map(n=>{let[o,s]=n.split("/"),i=Y(void 0,{value:o});if(s.startsWith("PT")){let u=k(void 0,{value:s});return{start:i,duration:u}}let a=Y(void 0,{value:s});return{start:i,end:a}})})},jo=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:Ze,objectKeyMap:_e,convertValues:{stamp:({line:o})=>y(void 0,o,{timezones:n?.timezones}),start:({line:o})=>y(void 0,o,{timezones:n?.timezones}),end:({line:o})=>y(void 0,o,{timezones:n?.timezones}),comment:({line:o})=>T(void 0,o),organizer:({line:o})=>W(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),freeBusy:({line:o})=>qo(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},ut=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:on,objectKeyMap:Re,convertValues:{version:({line:o})=>o.value},childComponents:{timezones:{icsComponent:qe,convert:o=>_o(void 0,o,{nonStandard:n?.nonStandard})},events:{icsComponent:je,convert:(o,{data:s})=>Bo(void 0,o,{nonStandard:n?.nonStandard,timezones:s.timezones})},todos:{icsComponent:Ge,convert:(o,{data:s})=>$o(void 0,o,{nonStandard:n?.nonStandard,timezones:s.timezones})},journals:{icsComponent:Je,convert:(o,{data:s})=>Ho(void 0,o,{nonStandard:n?.nonStandard,timezones:s.timezones})},freeBusy:{icsComponent:Ze,convert:(o,{data:s})=>jo(void 0,o,{nonStandard:n?.nonStandard,timezones:s.timezones})}},nonStandard:n?.nonStandard})};var ct="0.3.25",dt="icalendar:lastSync";console.log(`[iCalendar] Plug script executing at top level (Version ${ct})`);var Wo={"GMT Standard Time":0,"W. Europe Standard Time":1,"Central Europe Standard Time":1,"Romance Standard Time":1,"Central European Standard Time":1,"Eastern Standard Time":-5,"Central Standard Time":-6,"Mountain Standard Time":-7,"Pacific Standard Time":-8,UTC:0,None:0};async function Go(e){let r=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(s=>s.toString(16).padStart(2,"0")).join("")}function J(e){let t=r=>String(r).padStart(2,"0");return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+"T"+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())}function me(e){if(e==null)return e;if(e instanceof Date)return J(e);if(typeof e=="object"&&"date"in e&&e.date instanceof Date)return J(e.date);if(typeof e=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(e))try{return J(new Date(e))}catch{return e}if(Array.isArray(e))return e.map(t=>me(t));if(typeof e=="object"){let t={};for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=me(e[r]));return t}return e}async function Jo(){try{let e=await B.get("icalendar",{sources:[]});console.log("[iCalendar] Raw config retrieved:",JSON.stringify(e));let t=e.sources||[],r=e.tzShift||0;if(t&&typeof t=="object"&&!Array.isArray(t)){t.tzShift!==void 0&&r===0&&(r=t.tzShift);let n=[];for(let o in t)t[o]&&typeof t[o].url=="string"&&n.push(t[o]);t=n}return{sources:t,tzShift:r}}catch(e){return console.error("[iCalendar] Error in getSources:",e),{sources:[],tzShift:0}}}async function Zo(e,t=0){console.log(`[iCalendar] Fetching from: ${e.url}`);try{let r=await fetch(e.url);if(!r.ok)return console.error(`[iCalendar] Fetch failed for ${e.name}: ${r.status} ${r.statusText}`),[];let n=await r.text(),o=ut(void 0,n);if(!o||!o.events)return[];let s=[];for(let i of o.events){let a=i.start;if(!a)continue;let u="";if(a.local&&a.local.date?u=typeof a.local.date=="string"?a.local.date:a.local.date instanceof Date?a.local.date.toISOString():String(a.local.date):a.date&&(u=typeof a.date=="string"?a.date:a.date instanceof Date?a.date.toISOString():String(a.date)),!u)continue;let c=new Date(u.replace("Z","")+"Z"),m=a.local?.timezone||a.timezone||"UTC",E=Wo[m]??0,f=c.getTime()-E*36e5,h=new Date(f+t*36e5),A=J(h),P=`${A}${i.uid||i.summary||""}`,g=await Go(P);s.push(me({...i,name:i.summary||"Untitled Event",start:A,ref:g,tag:"ical-event",sourceName:e.name}))}return s}catch(r){return console.error(`[iCalendar] Error fetching/parsing ${e.name}:`,r),[]}}async function pe(){try{let{sources:e,tzShift:t}=await Jo();if(e.length===0)return;await x.flashNotification("Syncing calendars...","info");let r=[];for(let n of e){let o=await Zo(n,t);r.push(...o)}await V.indexObjects("$icalendar",r),await x.flashNotification(`Synced ${r.length} events`,"info")}catch(e){console.error("[iCalendar] syncCalendars failed:",e)}}async function mt(){await K.del(dt),await pe()}async function pt(){if(!await x.confirm("Clear all calendar events?"))return;let e=await z.query({prefix:["ridx","$icalendar"]}),t=[];for(let{key:r}of e)t.push(r),t.push(["idx",...r.slice(2),"$icalendar"]);t.length>0&&await z.batchDel(t),await K.del(dt),await x.flashNotification("Calendar index cleared","info")}async function ft(){await x.flashNotification(`iCalendar Plug ${ct}`,"info")}var yt={syncCalendars:pe,forceSync:mt,clearCache:pt,showVersion:ft},gt={name:"icalendar",version:"0.3.25",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:{}},as={manifest:gt,functionMapping:yt};Ee(yt,gt,self.postMessage);export{as as plug}; +var Br=Object.defineProperty;var ce=(t,e)=>{for(var r in e)Br(t,r,{get:e[r],enumerable:!0})};function yt(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(i=>({...i,source:r})))})).ok)throw new Error("Failed to post logs to server")}catch(a){console.warn("Could not post logs to server",a.message),this.logBuffer.unshift(...o)}}}},ft;function pt(t=""){return ft=new Ie(t),ft}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 mt(t,e,r){Ke&&(le=r,self.addEventListener("message",n=>{(async()=>{let o=n.data;switch(o.type){case"inv":{let a=t[o.name];if(!a)throw new Error(`Function not loaded: ${o.name}`);try{let i=await Promise.resolve(a(...o.args||[]));le({type:"invr",id:o.id,result:i})}catch(i){console.error("An exception was thrown as a result of invoking function",o.name,"error:",i.message),le({type:"invr",id:o.id,error:i.message})}}break;case"sysr":{let a=o.id,i=Ye.get(a);if(!i)throw Error("Invalid request id");Ye.delete(a),o.error?i.reject(new Error(o.error)):i.resolve(o.result)}break}})().catch(console.error)}),le({type:"manifest",manifest:e}),pt(`[${e.name} plug]`))}async function jr(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 Vr(){globalThis.fetch=async function(t,e){let r=e&&e.body?Ne(new Uint8Array(await new Response(e.body).arrayBuffer())):void 0,n=await jr(t,e&&{method:e.method,headers:e.headers,base64Body:r});return new Response(n.base64Body?yt(n.base64Body):null,{status:n.status,headers:n.headers})}}Ke&&Vr();var H={};ce(H,{alert:()=>On,configureVimMode:()=>Hn,confirm:()=>Cn,copyToClipboard:()=>zn,deleteLine:()=>Fn,dispatch:()=>kn,downloadFile:()=>pn,filterBox:()=>gn,flashNotification:()=>hn,fold:()=>Rn,foldAll:()=>Nn,getCurrentEditor:()=>Gr,getCurrentPage:()=>Wr,getCurrentPageMeta:()=>Hr,getCurrentPath:()=>$r,getCursor:()=>Qr,getRecentlyOpenedPages:()=>qr,getSelection:()=>Xr,getText:()=>Zr,getUiOption:()=>Mn,goHistory:()=>fn,hidePanel:()=>bn,insertAtCursor:()=>xn,insertAtPos:()=>Tn,invokeCommand:()=>tn,isMobile:()=>qn,moveCursor:()=>Sn,moveCursorToLine:()=>An,moveLineDown:()=>Vn,moveLineUp:()=>jn,navigate:()=>nn,newWindow:()=>yn,openCommandPalette:()=>an,openPageNavigator:()=>on,openSearchPanel:()=>Kn,openUrl:()=>dn,prompt:()=>Dn,rebuildEditorState:()=>cn,redo:()=>Yn,reloadConfigAndCommands:()=>ln,reloadPage:()=>sn,reloadUI:()=>un,replaceRange:()=>wn,save:()=>rn,sendMessage:()=>$n,setSelection:()=>en,setText:()=>Jr,setUiOption:()=>Pn,showPanel:()=>vn,showProgress:()=>En,toggleComment:()=>Bn,toggleFold:()=>Ln,undo:()=>Un,unfold:()=>_n,unfoldAll:()=>In,uploadFile:()=>mn,vimEx:()=>Wn});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function y(t,...e){return globalThis.syscall(t,...e)}function Wr(){return y("editor.getCurrentPage")}function Hr(){return y("editor.getCurrentPageMeta")}function $r(){return y("editor.getCurrentPath")}function qr(){return y("editor.getRecentlyOpenedPages")}function Gr(){return y("editor.getCurrentEditor")}function Zr(){return y("editor.getText")}function Jr(t,e=!1){return y("editor.setText",t,e)}function Qr(){return y("editor.getCursor")}function Xr(){return y("editor.getSelection")}function en(t,e){return y("editor.setSelection",t,e)}function tn(t,e){return y("editor.invokeCommand",t,e)}function rn(){return y("editor.save")}function nn(t,e=!1,r=!1){return y("editor.navigate",t,e,r)}function on(t="page"){return y("editor.openPageNavigator",t)}function an(){return y("editor.openCommandPalette")}function sn(){return y("editor.reloadPage")}function un(){return y("editor.reloadUI")}function cn(){return y("editor.rebuildEditorState")}function ln(){return y("editor.reloadConfigAndCommands")}function dn(t,e=!1){return y("editor.openUrl",t,e)}function yn(){return y("editor.newWindow")}function fn(t){return y("editor.goHistory",t)}function pn(t,e){return y("editor.downloadFile",t,e)}function mn(t,e){return y("editor.uploadFile",t,e)}function hn(t,e="info"){return y("editor.flashNotification",t,e)}function gn(t,e,r="",n=""){return y("editor.filterBox",t,e,r,n)}function vn(t,e,r,n=""){return y("editor.showPanel",t,e,r,n)}function bn(t){return y("editor.hidePanel",t)}function En(t,e){return y("editor.showProgress",t,e)}function Tn(t,e){return y("editor.insertAtPos",t,e)}function wn(t,e,r){return y("editor.replaceRange",t,e,r)}function Sn(t,e=!1){return y("editor.moveCursor",t,e)}function An(t,e=1,r=!1){return y("editor.moveCursorToLine",t,e,r)}function xn(t,e=!1,r=!1){return y("editor.insertAtCursor",t,e,r)}function kn(t){return y("editor.dispatch",t)}function Dn(t,e=""){return y("editor.prompt",t,e)}function Cn(t){return y("editor.confirm",t)}function On(t){return y("editor.alert",t)}function Mn(t){return y("editor.getUiOption",t)}function Pn(t,e){return y("editor.setUiOption",t,e)}function Rn(){return y("editor.fold")}function _n(){return y("editor.unfold")}function Ln(){return y("editor.toggleFold")}function Nn(){return y("editor.foldAll")}function In(){return y("editor.unfoldAll")}function Un(){return y("editor.undo")}function Yn(){return y("editor.redo")}function Kn(){return y("editor.openSearchPanel")}function zn(t){return y("editor.copyToClipboard",t)}function Fn(){return y("editor.deleteLine")}function Bn(){return y("editor.toggleComment")}function jn(){return y("editor.moveLineUp")}function Vn(){return y("editor.moveLineDown")}function Wn(t){return y("editor.vimEx",t)}function Hn(){return y("editor.configureVimMode")}function $n(t,e){return y("editor.sendMessage",t,e)}function qn(){return y("editor.isMobile")}var de={};ce(de,{del:()=>eo,get:()=>Xn,set:()=>Qn});function Qn(t,e){return y("clientStore.set",t,e)}function Xn(t){return y("clientStore.get",t)}function eo(t){return y("clientStore.delete",t)}var Vs=new Uint8Array(16);var ye={};ce(ye,{batchDel:()=>po,batchDeletePrefix:()=>go,batchGet:()=>yo,batchSet:()=>co,del:()=>fo,get:()=>lo,listFunctions:()=>bo,query:()=>mo,queryDelete:()=>vo,queryLua:()=>ho,set:()=>uo});function uo(t,e){return y("datastore.set",t,e)}function co(t){return y("datastore.batchSet",t)}function lo(t){return y("datastore.get",t)}function yo(t){return y("datastore.batchGet",t)}function fo(t){return y("datastore.delete",t)}function po(t){return y("datastore.batchDelete",t)}function mo(t){return y("datastore.query",t)}function ho(t,e,r){return y("datastore.queryLua",t,e,r)}function go(t){return y("datastore.batchDeletePrefix",t)}function vo(t,e){return y("datastore.queryDelete",t,e)}function bo(){return y("datastore.listFunctions")}var Te={};ce(Te,{define:()=>ko,get:()=>wo,has:()=>xo,insert:()=>Ao,set:()=>So});function wo(t,e){return y("config.get",t,e)}function So(t,e){return y("config.set",t,e)}function Ao(t,e){return y("config.insert",t,e)}function xo(t){return y("config.has",t)}function ko(t,e){return y("config.define",t,e)}var we={};ce(we,{ensureFullIndex:()=>Mo,getObjectByRef:()=>Oo,indexObjects:()=>Do,queryLuaObjects:()=>Co});function Do(t,e){return y("index.indexObjects",t,e)}function Co(t,e,r,n){return y("index.queryLuaObjects",t,e,r,n)}function Oo(t,e,r){return y("index.getObjectByRef",t,e,r)}function Mo(){return y("index.ensureFullIndex")}var V=t=>Object.fromEntries(Object.entries(t).map(([e,r])=>[r,e])),C=t=>Object.keys(t),St={action:"ACTION",description:"DESCRIPTION",duration:"DURATION",repeat:"REPEAT",summary:"SUMMARY",trigger:"TRIGGER",attachments:"ATTACH",attendees:"ATTENDEE"},At=V(St),iu=C(At),au=C(St),xt={method:"METHOD",prodId:"PRODID",version:"VERSION",name:"X-WR-CALNAME"},kt=V(xt),su=C(kt),uu=C(xt),Dt={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"},Ct=V(Dt),cu=C(Ct),lu=C(Dt),Ot={id:"TZID",lastModified:"LAST-MODIFIED",url:"TZURL"},Mt=V(Ot),du=C(Mt),yu=C(Ot),Pt={comment:"COMMENT",name:"TZNAME",offsetFrom:"TZOFFSETFROM",offsetTo:"TZOFFSETTO",recurrenceDate:"RDATE",recurrenceRule:"RRULE",start:"DTSTART"},Rt=V(Pt),fu=C(Rt),pu=C(Pt),_t={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"},Lt=V(_t),mu=C(Lt),hu=C(_t),Nt={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"},It=V(Nt),gu=C(It),vu=C(Nt),Ut={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"},Yt=V(Ut),bu=C(Yt),Eu=C(Ut),Kt={stamp:"DTSTAMP",start:"DTSTART",uid:"UID",url:"URL",organizer:"ORGANIZER",attendees:"ATTENDEE",comment:"COMMENT",end:"DTEND",freeBusy:"FREEBUSY"},zt=V(Kt),Tu=C(zt),wu=C(Kt),Ft="BEGIN",Bt="END",Po="VCALENDAR",jt="VTIMEZONE",Ro="STANDARD",_o="DAYLIGHT",Vt="VEVENT",Wt="VALARM",Ht="VTODO",$t="VJOURNAL",qt="VFREEBUSY";var ht=t=>new RegExp(`${Ft}:${t}([\\s\\S]*?)${Bt}:${t}`,"g"),Lo=t=>new RegExp(`${Ft}:${t}|${Bt}:${t}`,"g");var Fe=/\r\n|\r|\n/;var gt=` +`,No=":",te=",",Io='"',Be=";";var vt="=";var Uo=Math.pow(10,8)*24*60*60*1e3,Su=-Uo,Yo=6048e5;var Gt=6e4,Zt=36e5,Ko=3600,Jt=Ko*24,Au=Jt*7,zo=Jt*365.2425,Fo=zo/12,xu=Fo*3,bt=Symbol.for("constructDateFrom");function Y(t,e){return typeof t=="function"?t(e):t&&typeof t=="object"&&bt in t?t[bt](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 Qt(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(),a=Y(r?.in||t,n.getTime());a.setMonth(n.getMonth()+e+1,0);let i=a.getDate();return o>=i?a:(n.setFullYear(a.getFullYear(),a.getMonth(),o),n)}function ke(t,e,r){return Y(r?.in||t,+E(t)+e)}function Bo(t,e,r){return ke(t,e*Zt,r)}var jo={};function De(){return jo}function Ae(t,e){var r,n,o,a;let i=De(),s=e?.weekStartsOn??((n=(r=e?.locale)==null?void 0:r.options)==null?void 0:n.weekStartsOn)??i.weekStartsOn??((a=(o=i.locale)==null?void 0:o.options)==null?void 0:a.weekStartsOn)??0,u=E(t,e?.in),c=u.getDay(),d=(ctypeof n=="object"));return e.map(r)}function Wo(t,e){let r=E(t,e?.in);return r.setHours(0,0,0,0),r}function Xt(t,e,r){let n=E(t,r?.in);return n.setTime(n.getTime()+e*Gt),n}function Ho(t,e,r){return ke(t,e*1e3,r)}function We(t,e,r){return Ve(t,e*7,r)}function er(t,e,r){return Qt(t,e*12,r)}function He(t,e){let r=+E(t)-+E(e);return r<0?-1:r>0?1:r}function Et(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 $o(t,e){let[r,n]=Vo(t,e.start,e.end);return{start:r,end:n}}function qo(t,e){let{start:r,end:n}=$o(e?.in,t),o=+r>+n,a=o?+r:+n,i=o?n:r;i.setHours(0,0,0,0);let s=e?.step??1;if(!s)return[];s<0&&(s=-s,o=!o);let u=[];for(;+i<=a;)u.push(Y(r,i)),i.setDate(i.getDate()+s),i.setHours(0,0,0,0);return o?u.reverse():u}function Tt(t,e){let r=E(t,e?.in);return r.setDate(1),r.setHours(0,0,0,0),r}function Go(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 Zo(t,e){let r=E(t,e?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function Jo(t,e){var r,n,o,a;let i=E(t,e?.in),s=i.getFullYear(),u=De(),c=e?.firstWeekContainsDate??((n=(r=e?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??u.firstWeekContainsDate??((a=(o=u.locale)==null?void 0:o.options)==null?void 0:a.firstWeekContainsDate)??1,d=Y(e?.in||t,0);d.setFullYear(s+1,0,c),d.setHours(0,0,0,0);let p=Ae(d,e),l=Y(e?.in||t,0);l.setFullYear(s,0,c),l.setHours(0,0,0,0);let m=Ae(l,e);return+i>=+p?s+1:+i>=+m?s:s-1}function Qo(t,e){var r,n,o,a;let i=De(),s=e?.firstWeekContainsDate??((n=(r=e?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??i.firstWeekContainsDate??((a=(o=i.locale)==null?void 0:o.options)==null?void 0:a.firstWeekContainsDate)??1,u=Jo(t,e),c=Y(e?.in||t,0);return c.setFullYear(u,0,s),c.setHours(0,0,0,0),Ae(c,e)}function Xo(t,e){let r=E(t,e?.in),n=+Ae(r,e)-+Qo(r,e);return Math.round(n/Yo)+1}function Se(t,e){return E(t,e?.in).getDay()}function tr(t,e){let r=E(t,e?.in),n=r.getFullYear(),o=r.getMonth(),a=Y(r,0);return a.setFullYear(n,o+1,0),a.setHours(0,0,0,0),a.getDate()}function ei(t,e){return E(t,e?.in).getHours()}function ti(t,e){return E(t,e?.in).getMinutes()}function rr(t,e){return E(t,e?.in).getMonth()}function ri(t){return E(t).getSeconds()}function ni(t,e){return E(t,e?.in).getFullYear()}function oi(t,e){return+E(t)==+E(e)}function ii(t,e,r){let n=E(t,r?.in),o=Xo(n,r)-e;return n.setDate(n.getDate()-o*7),E(n,r?.in)}function xe(t,e,r){var n,o,a,i;let s=De(),u=r?.weekStartsOn??((o=(n=r?.locale)==null?void 0:n.options)==null?void 0:o.weekStartsOn)??s.weekStartsOn??((i=(a=s.locale)==null?void 0:a.options)==null?void 0:i.weekStartsOn)??0,c=E(t,r?.in),d=c.getDay(),p=(e%7+7)%7,l=7-u,m=e<0||e>6?e-(d+l)%7:(p+l)%7-(d+l)%7;return Ve(c,m,r)}function nr(t,e,r){let n=+E(t,r?.in),[o,a]=[+E(e.start,r?.in),+E(e.end,r?.in)].sort((i,s)=>i-s);return n>=o&&n<=a}function ai(t){let e=t/Zt;return Math.trunc(e)}function si(t){let e=t/Gt;return Math.trunc(e)}function ui(t,e,r){let n=E(t,r?.in),o=n.getFullYear(),a=n.getDate(),i=Y(r?.in||t,0);i.setFullYear(o,e,15),i.setHours(0,0,0,0);let s=tr(i);return n.setMonth(e,Math.min(a,s)),n}function ci(t,e,r){let n=E(t,r?.in);return n.setDate(e),n}function li(t,e,r){let n=E(t,r?.in);return n.setMonth(0),n.setDate(e),n}function di(t,e,r){let n=E(t,r?.in);return n.setHours(e),n}function yi(t,e,r){let n=E(t,r?.in);return n.setMinutes(e),n}function fi(t,e,r){let n=E(t,r?.in);return n.setSeconds(e),n}function pi(t,e,r){return ke(t,-e,r)}function mi(t,e,r){return We(t,-e,r)}var hi=[Ro,_o];var gi=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"];var or=["SU","MO","TU","WE","TH","FR","SA"];var X=(t,e)=>e===void 0?!1:t>=e,vi=(t,{start:e,end:r},n)=>{if(X(n.length,t.count))return;let o=t.frequency,a=t.interval||1;if(!o)return;let i=e;if(o==="SECONDLY"){for(;i{let o=r.map(({day:a,occurrence:i})=>({occurrence:i,day:or.indexOf(a)}));return t.frequency==="YEARLY"?t.byYearday||t.byMonthday?e.map(a=>a.filter(i=>o.find(({day:s})=>s===Se(i)))):t.byWeekNo?e.map(a=>a.flatMap(i=>o.map(({day:s})=>xe(i,s,{weekStartsOn:n})))):t.byMonth?e.map(a=>a.flatMap(i=>o.flatMap(({day:s,occurrence:u})=>ze($(Tt(i)),$(Et(i)),s,n,u)))):e.map(a=>a.flatMap(i=>o.flatMap(({day:s,occurrence:u})=>ze($(Zo(i)),$(Go(i)),s,n,u)))):t.frequency==="MONTHLY"?t.byMonthday?e.map(a=>a.filter(i=>o.find(({day:s})=>s===Se(i)))):e.map(a=>a.flatMap(i=>o.flatMap(({day:s,occurrence:u})=>ze($(Tt(i)),$(Et(i)),s,n,u)))):t.frequency==="WEEKLY"?e.map(a=>a.flatMap(i=>o.map(({day:s})=>xe(i,s,{weekStartsOn:n})))):e.map(a=>a.filter(i=>o.find(({day:s})=>s===Se(i))))},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 a=xe(e,r,{weekStartsOn:n}),i=e$(a)).filter(a=>nr(a,{start:t,end:e})).filter(a=>r===Se(a))},$=t=>Xt(t,-t.getTimezoneOffset()),Ei=(t,e,r)=>t.frequency==="YEARLY"||t.frequency==="MONTHLY"||t.frequency==="WEEKLY"||t.frequency==="DAILY"?e.map(n=>n.flatMap(o=>r.map(a=>di(o,a)))):e.map(n=>n.filter(o=>r.includes(ei(o)))),Ti=(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(a=>yi(o,a)))):e.map(n=>n.filter(o=>r.includes(ti(o)))),wi=(t,e,r)=>t.frequency==="YEARLY"?e.map(n=>n.flatMap(o=>r.map(a=>ui(o,a)))):e.map(n=>n.filter(o=>r.includes(rr(o)))),Si=(t,e,r)=>t.frequency==="YEARLY"||t.frequency==="MONTHLY"?e.map(n=>n.flatMap(o=>{let a=tr(o);return r.map(i=>i>a?void 0:ci(o,i)).filter(i=>!!i)})):t.frequency==="WEEKLY"?e:e.map(n=>n.filter(o=>r.includes(rr(o)))),Ai=(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(a=>fi(o,a)))):e.map(n=>n.filter(o=>r.includes(ri(o)))),xi=(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,a)=>r.some(i=>i>0?a===0?!1:a%i===0:a===0?n.length-1+i===0:a%(n.length-1+i)===0))),ki=(t,e,r,n)=>t.frequency==="YEARLY"?e.map(o=>o.flatMap(a=>r.map(i=>ii(a,i,{weekStartsOn:n})))):e,Di=(t,e,r)=>t.frequency==="YEARLY"?e.map(n=>n.flatMap(o=>r.map(a=>li(o,a)))):t.frequency==="MONTHLY"||t.frequency==="WEEKLY"||t.frequency==="DAILY"?e:e.map(n=>n.filter(o=>r.includes(ni(o)))),Ci=(t,e,r)=>{let n=r;return t.byMonth&&(n=wi(t,n,t.byMonth)),t.byWeekNo&&(n=ki(t,n,t.byWeekNo,e.weekStartsOn)),t.byYearday&&(n=Di(t,n,t.byYearday)),t.byMonthday&&(n=Si(t,n,t.byMonthday)),t.byDay&&(n=bi(t,n,t.byDay,e.weekStartsOn)),t.byHour&&(n=Ei(t,n,t.byHour)),t.byMinute&&(n=Ti(t,n,t.byMinute)),t.bySecond&&(n=Ai(t,n,t.bySecond)),t.bySetPos&&(n=xi(t,n,t.bySetPos)),n.map(o=>o.sort(He).filter(a=>!(e.exceptions.length>0&&e.exceptions.some(i=>oi(i,a))||!nr(a,{start:e.start,end:e.end}))))},Oi=2,Mi=(t,e)=>{var r;let n=e.start,o=((r=t.until)==null?void 0:r.date)||e?.end||er(n,Oi),a=e.exceptions||[],i=(t.workweekStart?or.indexOf(t.workweekStart):1)%7,s=[[n]];vi(t,{start:n,end:o},s);let u=Ci(t,{start:n,end:o,exceptions:a,weekStartsOn:i},s);return t.count?u.flat().splice(0,t.count):u.flat()},Pi=(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},Ri=(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()}},_i=(t,e,r)=>{let n=r?.find(a=>a.id===e);if(n){let a=Pi(t,n.props).sort((u,c)=>He(u.start,c.start));for(let u=0;u5?c.substring(0,5):c;return{offset:d,milliseconds:je(d)}}let i=a[a.length-1].offsetTo,s=i.length>5?i.substring(0,5):i;return{offset:s,milliseconds:je(s)}}let o=Ri(e,t);if(!Number.isNaN(o)){let a=o<0,i=Math.abs(ai(o)),s=Math.abs(si(o))-i*60,u=i.toString().length===1?`0${i}`:i.toString(),c=s.toString().length===1?`0${s}`:s.toString();return{offset:`${a?"-":"+"}${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},Li=(t,e)=>{var r,n,o,a;let i=((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:(a=e.options)==null?void 0:a.FMTTYPE};return x(t,i)},ee=t=>t.replace(/mailto:/gi,""),me=(t,e)=>{var r,n,o,a,i,s,u,c,d,p,l;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:(a=e.options)!=null&&a.MEMBER?ee(e.options.MEMBER):void 0,name:(i=e.options)==null?void 0:i.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:(d=e.options)!=null&&d.RSVP?((p=e.options)==null?void 0:p.RSVP)==="TRUE"?!0:((l=e.options)==null?void 0:l.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"),a=o[0];if(a.includes("D")){let[s,u]=a.split("D");n.days=Number(s),a=u}if(a.includes("W")){let[s,u]=a.split("W");n.weeks=Number(s),a=u}let i=o[1];if(i){if(i.includes("H")){let[s,u]=i.split("H");n.hours=Number(s),i=u}if(i.includes("M")){let[s,u]=i.split("M");n.minutes=Number(s),i=u}if(i.includes("S")){let[s,u]=i.split("S");n.seconds=Number(s),i=u}}return x(t,n)},Ni=(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),a=new Date(Date.UTC(r,n,o));return x(t,a)},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),a=Number.parseInt(e.value.slice(9,11),10),i=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,a,i,s));return x(t,u)},Ii=(t,e,r)=>{let n=je(r),o=fe(void 0,e),a=pi(o,n);return x(t,a)},Ui=(t,e)=>{var r,n,o,a,i,s;if(((r=t.options)==null?void 0:r.VALUE)==="DATE")return{date:Ni(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(!((a=t.options)!=null&&a.TZID))return{date:c,type:u};let d=_i(c,t.options.TZID,e?.timezones);return d?{date:ke(c,-d.milliseconds),type:u,local:(i=t.options)!=null&&i.TZID?{date:c,timezone:(s=t.options)==null?void 0:s.TZID,tzoffset:d.offset}:void 0}:{date:c,type:u}},k=(t,e,r)=>x(t,Ui(e,r)),Yi=(t,e,r)=>{var n,o,a,i;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:(a=e.options)==null?void 0:a.RELATED}}:{type:"relative",value:he(void 0,e),options:{related:(i=e.options)==null?void 0:i.RELATED}};return x(t,s)},Ki=t=>t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t,ir=t=>t.map(e=>{let[r,...n]=e.split(vt),o=n.join(vt);return{property:r,value:Ki(o)}},{}),zi=t=>t.reduce((e,r)=>(e[r.property]=r.value,e),{}),Fi=t=>zi(ir(t)),Bi=t=>{let e=!1,r;for(let a=0;a{let{property:e,value:r}=Bi(t);if(e.includes(Be)){let[n,...o]=e.split(Be),a=Fi(o);return{property:n,line:{options:a,value:r}}}return{property:e,line:{value:r}}},wt=t=>/^[ \t]/.test(t),Vi=t=>/^[A-Z]+(?:-[A-Z]+)*[:;]/.test(t),Wi=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!=="")},Hi=(t,e,r)=>{if(!e)return t;let n={};return Object.entries(e).forEach(([o,a])=>{let i=Object.entries(r||{}).find(([c,d])=>d.name===o);if(!i){n[$i(o)]=a.value;return}let s=i[1].convert(a),u=i[1].schema;if(!u){n[i[0]]=s;return}n[i[0]]=x(u,s)}),t.nonStandard=n,t},$i=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},qi=t=>t.startsWith("X-"),q=(t,e,r)=>{let n=e.replace(Lo(r?.icsComponent),""),o=[...new Set(Object.values(r.childComponents||{}).flatMap(({icsComponent:p})=>p))],a=Wi(o.reduce((p,l)=>p.replace(ht(l),""),n)),i=r.defaultValues||{},s={};a.forEach(p=>{var l,m;let{property:v,line:b}=ji(p);qi(v)&&(s[v]=b);let h=r.objectKeyMap[v];if(!h)return;let S=(l=r.convertArrayValues)==null?void 0:l[h];if(S){let N=S({line:b});if(!N)return;(i[h]===void 0||i[h]===null||!Array.isArray(i[h]))&&(i[h]=[]),Array.isArray(N)?i[h].push(...N):i[h].push(N);return}let L=(m=r.convertValues)==null?void 0:m[h];if(L){let N=L({line:b});if(!N)return;i[h]=N;return}i[h]=b.value});let u=r.childComponents,c=u?Object.keys(u||{}):[];u&&c.length>0&&c.forEach(p=>{let l=u?.[p];if(!l)return;let m=Array.isArray(l.icsComponent)?l.icsComponent:[l.icsComponent],v=[],b=[];m.forEach(h=>{b.push(...n.matchAll(ht(h)))}),b.map(h=>h[0]).forEach(h=>{let S=l.convert(h,{data:i});S&&v.push(S)}),v.length!==0&&(i[p]=v)});let d=x(t,i);return r!=null&&r.nonStandard?Hi(d,s,r?.nonStandard):d},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})},Gi=t=>{if(t.length===2)return{day:t};let e=t.slice(0,-2);return{day:t.replace(e,""),occurrence:Number(e)}},Zi=(t,e)=>x(t,Gi(e.value)),Ji=(t,e)=>x(t,e.value),Qi=["until"],Xi=t=>Qi.includes(t),ea=["bySecond","byMinute","byHour","byMonthday","byYearday","byWeekNo","bySetPos"],ta=t=>ea.includes(t),ra=["byDay"],na=t=>ra.includes(t),oa=["count","interval"],ia=t=>oa.includes(t),Oe=(t,e,r)=>{let n={};return ir(e.value.split(Be)).forEach(o=>{let{property:a,value:i}=o,s=Lt[a];if(s){if(Xi(s)){n[s]=k(void 0,{value:i,options:{VALUE:i.includes("T")?"DATE-TIME":"DATE"}},{timezones:r?.timezones});return}if(ta(s)){n[s]=i.split(te).map(u=>Number(u));return}if(s==="byMonth"){n[s]=i.split(te).map(u=>Number(u)-1);return}if(na(s)){n[s]=i.split(te).map(u=>Zi(void 0,{value:u}));return}if(ia(s)){n[s]=Number(i);return}if(s==="frequency"){if(!i||!gi.includes(i))return;n[s]=i;return}if(s==="workweekStart"){n[s]=Ji(void 0,{value:i});return}}}),x(t,n)},qe=(t,e)=>x(t,e.value),aa=(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))),sa=(t,e)=>x(t,e.value),ua=(t,e)=>x(t,e.value),ca=(t,e)=>x(t,e.value),pe=(t,e)=>x(t,Number.parseInt(e.value,10)),la=t=>t.replace(/\\(([,;\\])|([nN]))/g,(e,r,n)=>n||` +`),U=(t,e)=>x(t,la(e.value)),da=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:Wt,objectKeyMap:At,convertValues:{trigger:({line:o})=>Yi(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>he(void 0,o),repeat:({line:o})=>pe(void 0,o)},convertArrayValues:{attachments:({line:o})=>Li(void 0,o),attendees:({line:o})=>me(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},ya=(...t)=>{let[e,r,n]=t,o,a=q(e,r,{icsComponent:Vt,objectKeyMap:Ct,convertValues:{stamp:({line:i})=>k(void 0,i,{timezones:n?.timezones}),start:({line:i})=>k(void 0,i,{timezones:n?.timezones}),end:({line:i})=>k(void 0,i,{timezones:n?.timezones}),created:({line:i})=>k(void 0,i,{timezones:n?.timezones}),lastModified:({line:i})=>k(void 0,i,{timezones:n?.timezones}),categories:({line:i})=>i.value.split(te),description:({line:i})=>{var s;return(s=i.options)!=null&&s.ALTREP&&(o=i.options.ALTREP),U(void 0,i)},location:({line:i})=>U(void 0,i),comment:({line:i})=>U(void 0,i),summary:({line:i})=>U(void 0,i),recurrenceRule:({line:i})=>Oe(void 0,i,{timezones:n?.timezones}),duration:({line:i})=>he(void 0,i),organizer:({line:i})=>Ce(void 0,i),sequence:({line:i})=>pe(void 0,i),class:({line:i})=>qe(void 0,i),recurrenceId:({line:i})=>$e(void 0,i,{timezones:n?.timezones}),status:({line:i})=>sa(void 0,i),timeTransparent:({line:i})=>aa(void 0,i)},convertArrayValues:{attendees:({line:i})=>me(void 0,i),exceptionDates:({line:i})=>Ge(void 0,i,{timezones:n?.timezones})},childComponents:{alarms:{icsComponent:Wt,convert:i=>da(void 0,i,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},timezones:n?.timezones,nonStandard:n?.nonStandard});return o&&(a.descriptionAltRep=o),a},fa=(...t)=>{let[e,r,n]=t,o=r.split("BEGIN:")[1].split(Fe)[0],a=hi.includes(o)?o:"STANDARD",i=r.split("TZOFFSETTO:")[1].split(Fe)[0];return q(e,r,{icsComponent:a,objectKeyMap:Rt,defaultValues:{type:a},convertValues:{start:({line:s})=>Ii(void 0,s,i),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})},pa=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:jt,objectKeyMap:Mt,convertValues:{lastModified:({line:o})=>fe(void 0,o)},childComponents:{props:{icsComponent:["DAYLIGHT","STANDARD"],convert:o=>fa(void 0,o,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},nonStandard:n?.nonStandard,timezones:n?.timezones})},ma=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:Ht,objectKeyMap:It,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})=>ua(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})},ha=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:$t,objectKeyMap:Yt,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})=>ca(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})},ga=(t,e)=>{var r;return x(t,{type:(r=e.options)==null?void 0:r.FBTYPE,values:e.value.split(",").map(n=>{let[o,a]=n.split("/"),i=fe(void 0,{value:o});if(a.startsWith("PT")){let u=he(void 0,{value:a});return{start:i,duration:u}}let s=fe(void 0,{value:a});return{start:i,end:s}})})},va=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:qt,objectKeyMap:zt,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})=>ga(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},ar=(...t)=>{let[e,r,n]=t;return q(e,r,{icsComponent:Po,objectKeyMap:kt,convertValues:{version:({line:o})=>o.value},childComponents:{timezones:{icsComponent:jt,convert:o=>pa(void 0,o,{nonStandard:n?.nonStandard})},events:{icsComponent:Vt,convert:(o,{data:a})=>ya(void 0,o,{nonStandard:n?.nonStandard,timezones:a.timezones})},todos:{icsComponent:Ht,convert:(o,{data:a})=>ma(void 0,o,{nonStandard:n?.nonStandard,timezones:a.timezones})},journals:{icsComponent:$t,convert:(o,{data:a})=>ha(void 0,o,{nonStandard:n?.nonStandard,timezones:a.timezones})},freeBusy:{icsComponent:qt,convert:(o,{data:a})=>va(void 0,o,{nonStandard:n?.nonStandard,timezones:a.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"},sr=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 Ea=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,a){return n===void 0&&(n=0),o===void 0&&(o=0),a===void 0&&(a=0),new Date(Date.UTC(t,e-1,r,n,o,a))},Ta=[31,28,31,30,31,30,31,31,30,31,30,31],Ar=1e3*60*60*24,xr=9999,kr=Q(1970,1,1),wa=[6,0,1,2,3,4,5],ve=function(t){return t%4===0&&t%100!==0||t%400===0},Dr=function(t){return t instanceof Date},ge=function(t){return Dr(t)&&!isNaN(t.getTime())},Sa=function(t,e){var r=t.getTime(),n=e.getTime(),o=r-n;return Math.round(o/Ar)},et=function(t){return Sa(t,kr)},Cr=function(t){return new Date(kr.getTime()+t*Ar)},Aa=function(t){var e=t.getUTCMonth();return e===1&&ve(t.getUTCFullYear())?29:Ta[e]},ae=function(t){return wa[t.getUTCDay()]},ur=function(t,e){var r=Q(t,e+1,1);return[ae(r),Aa(r)]},Or=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},cr=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=ka,Da=function(t){re(e,t);function e(r,n,o){var a=t.call(this,r,n)||this;return a.iterator=o,a}return e.prototype.add=function(r){return this.iterator(r,this._result.length)?(this._result.push(r),!0):!1},e}(ie),dr=Da,Ca={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=Ca,yr=function(t,e){return t.indexOf(e)!==-1},Oa=function(t){return t.toString()},Ma=function(t,e,r){return"".concat(e," ").concat(r,", ").concat(t)},Pa=function(){function t(e,r,n,o){if(r===void 0&&(r=Oa),n===void 0&&(n=Me),o===void 0&&(o=Ma),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 a=[].concat(this.options.bymonthday),i=[].concat(this.options.bynmonthday);a.sort(function(d,p){return d-p}),i.sort(function(d,p){return p-d}),this.bymonthday=a.concat(i),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(d){return!d.n}),someWeeks:s.filter(function(d){return!!d.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(d,p){return d.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(yr(["dtstart","tzid","wkst","freq"],n))return!0;if(!yr(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[g.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 a=this;o===void 0&&(o=","),I(e)||(e=[e]);var i=function(u,c,d){for(var p="",l=0;le[0].length)&&(e=a,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 Mr(t,e){e===void 0&&(e=Me);var r={},n=new Ra(e.tokens);if(!n.start(t))return null;return o(),r;function o(){n.expect("every");var l=n.acceptNumber();if(l&&(r.interval=parseInt(l[0],10)),n.isDone())throw new Error("Unexpected end");switch(n.symbol){case"day(s)":r.freq=g.DAILY,n.nextSymbol()&&(i(),p());break;case"weekday(s)":r.freq=g.WEEKLY,r.byweekday=[g.MO,g.TU,g.WE,g.TH,g.FR],n.nextSymbol(),i(),p();break;case"week(s)":r.freq=g.WEEKLY,n.nextSymbol()&&(a(),i(),p());break;case"hour(s)":r.freq=g.HOURLY,n.nextSymbol()&&(a(),p());break;case"minute(s)":r.freq=g.MINUTELY,n.nextSymbol()&&(a(),p());break;case"month(s)":r.freq=g.MONTHLY,n.nextSymbol()&&(a(),p());break;case"year(s)":r.freq=g.YEARLY,n.nextSymbol()&&(a(),p());break;case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":r.freq=g.WEEKLY;var m=n.symbol.substr(0,2).toUpperCase();if(r.byweekday=[g[m]],!n.nextSymbol())return;for(;n.accept("comma");){if(n.isDone())throw new Error("Unexpected end");var v=u();if(!v)throw new Error("Unexpected symbol "+n.symbol+", expected weekday");r.byweekday.push(g[v]),n.nextSymbol()}i(),d(),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=g.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()}a(),p();break;default:throw new Error("Unknown symbol")}}function a(){var l=n.accept("on"),m=n.accept("the");if(l||m)do{var v=c(),b=u(),h=s();if(v)b?(n.nextSymbol(),r.byweekday||(r.byweekday=[]),r.byweekday.push(g[b].nth(v))):(r.bymonthday||(r.bymonthday=[]),r.bymonthday.push(v),n.accept("day(s)"));else if(b)n.nextSymbol(),r.byweekday||(r.byweekday=[]),r.byweekday.push(g[b]);else if(n.symbol==="weekday(s)")n.nextSymbol(),r.byweekday||(r.byweekday=[g.MO,g.TU,g.WE,g.TH,g.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 i(){var l=n.accept("at");if(l)do{var m=n.acceptNumber();if(!m)throw new Error("Unexpected symbol "+n.symbol+", expected hour");for(r.byhour=[parseInt(m[0],10)];n.accept("comma");){if(m=n.acceptNumber(),!m)throw new Error("Unexpected symbol "+n.symbol+"; expected hour");r.byhour.push(parseInt(m[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 l=parseInt(n.value[1],10);if(l<-366||l>366)throw new Error("Nth out of range: "+l);return n.nextSymbol(),n.accept("last")?-l:l;default:return!1}}function d(){n.accept("on"),n.accept("the");var l=c();if(l)for(r.bymonthday=[l],n.nextSymbol();n.accept("comma");){if(l=c(),!l)throw new Error("Unexpected symbol "+n.symbol+"; expected monthday");r.bymonthday.push(l),n.nextSymbol()}}function p(){if(n.symbol==="until"){var l=Date.parse(n.text);if(!l)throw new Error("Cannot parse until date:"+n.text);r.until=new Date(l)}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 a=Je(this.hour,24),i=a.div,s=a.mod;if(i&&(this.hour=s,this.addDaily(i)),B(o)||A(o,this.hour))break}},e.prototype.addMinutes=function(r,n,o,a){for(n&&(this.minute+=Math.floor((1439-(this.hour*60+this.minute))/r)*r);;){this.minute+=r;var i=Je(this.minute,60),s=i.div,u=i.mod;if(s&&(this.minute=u,this.addHours(s,!1,o)),(B(o)||A(o,this.hour))&&(B(a)||A(a,this.minute)))break}},e.prototype.addSeconds=function(r,n,o,a,i){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,a)),(B(o)||A(o,this.hour))&&(B(a)||A(a,this.minute))&&(B(i)||A(i,this.second)))break}},e.prototype.fixDay=function(){if(!(this.day<=28)){var r=ur(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>xr))return;r=ur(this.year,this.month-1)[1]}}},e.prototype.add=function(r,n){var o=r.freq,a=r.interval,i=r.wkst,s=r.byhour,u=r.byminute,c=r.bysecond;switch(o){case w.YEARLY:return this.addYears(a);case w.MONTHLY:return this.addMonths(a);case w.WEEKLY:return this.addWeekly(a,i);case w.DAILY:return this.addDaily(a);case w.HOURLY:return this.addHours(a,n,s);case w.MINUTELY:return this.addMinutes(a,n,s,u);case w.SECONDLY:return this.addSeconds(a,n,s,u,c)}},e}(Pe);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 g.YEARLY:e.bymonth||(e.bymonth=e.dtstart.getUTCMonth()+1),e.bymonthday=e.dtstart.getUTCDate();break;case g.MONTHLY:e.bymonthday=e.dtstart.getUTCDate();break;case g.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=[],a=[],r=0;r0?o.push(n):n<0&&a.push(n)}e.bymonthday=o,e.bynmonthday=a}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(sr(e.byweekday))e.byweekday=[_.fromStr(e.byweekday).weekday],e.bynweekday=null;else if(e.byweekday instanceof _)!e.byweekday.n||e.freq>g.MONTHLY?(e.byweekday=[e.byweekday.weekday],e.bynweekday=null):(e.bynweekday=[[e.byweekday.weekday,e.byweekday.n]],e.byweekday=null);else{for(var i=[],s=[],r=0;rg.MONTHLY?i.push(u.weekday):s.push([u.weekday,u.n])}e.byweekday=O(i)?i:null,e.bynweekday=O(s)?s:null}return D(e.byhour)?F(e.byhour)&&(e.byhour=[e.byhour]):e.byhour=e.freq=4?(d=0,c=s.yearlen+K(i-e.wkst,7)):c=n-d;for(var p=Math.floor(c/7),l=K(c,7),m=Math.floor(p+l/4),v=0;v0&&b<=m){var h=void 0;b>1?(h=d+(b-1)*7,d!==u&&(h-=7-u)):h=d;for(var S=0;S<7&&(s.wnomask[h]=1,h++,s.wdaymask[h]!==e.wkst);S++);}}if(A(e.byweekno,1)){var h=d+m*7;if(d!==u&&(h-=7-u),h=4?(ue=0,J=Le+K(N-e.wkst,7)):J=n-d,L=Math.floor(52+K(J,7)/4)}if(A(e.byweekno,L))for(var h=0;ha)return oe(t);if(L>=r){var N=hr(L,e);if(!t.accept(N)||s&&(--s,!s))return oe(t)}}else for(var S=m;Sa)return oe(t);if(L>=r){var N=hr(L,e);if(!t.accept(N)||s&&(--s,!s))return oe(t)}}}if(e.interval===0||(u.add(e,b),u.year>xr))return oe(t);at(n)||(d=c.gettimeset(n)(u.hour,u.minute,u.second,0)),c.rebuild(u.year,u.month)}}function ls(t,e,r){var n=r.bymonth,o=r.byweekno,a=r.byweekday,i=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(a)&&!A(a,t.wdaymask[e])||O(t.nwdaymask)&&!t.nwdaymask[e]||i!==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 hr(t,e){return new _e(t,e.tzid).rezonedDate()}function oe(t){return t.getValue()}function ds(t,e,r,n,o){for(var a=!1,i=e;i=g.HOURLY&&O(o)&&!A(o,e.hour)||n>=g.MINUTELY&&O(a)&&!A(a,e.minute)||n>=g.SECONDLY&&O(i)&&!A(i,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},fs=Object.keys(st),g=function(){function t(e,r){e===void 0&&(e={}),r===void 0&&(r=!1),this._cache=r?null:new Va,this.origOptions=Pr(e);var n=Ua(e).parsedOptions;this.options=n}return t.parseText=function(e,r){return Mr(e,r)},t.fromText=function(e,r){return _a(e,r)},t.fromString=function(e){return new t(t.parseString(e)||void 0)},t.prototype._iter=function(e){return Rr(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 dr("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 a={before:r,after:e,inc:n};if(o)return this._iter(new dr("between",a,o));var i=this._cacheGet("between",a);return i===!1&&(i=this._iter(new ie("between",a)),this._cacheAdd("between",i,a)),i},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 La(this,e,r,n)},t.prototype.isFullyConvertibleToText=function(){return Na(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 ps(t,e,r,n,o,a){var i={},s=t.accept;function u(l,m){r.forEach(function(v){v.between(l,m,!0).forEach(function(b){i[Number(b)]=!0})})}o.forEach(function(l){var m=new _e(l,a).rezonedDate();i[Number(m)]=!0}),t.accept=function(l){var m=Number(l);return isNaN(m)?s.call(this,l):!i[m]&&(u(new Date(m-1),new Date(m+1)),!i[m])?(i[m]=!0,s.call(this,l)):!0},t.method==="between"&&(u(t.args.after,t.args.before),t.accept=function(l){var m=Number(l);return i[m]?!0:(i[m]=!0,s.call(this,l))});for(var c=0;c1||o.length||a.length||i.length){var d=new ut(c);return d.dtstart(s),d.tzid(u||void 0),n.forEach(function(l){d.rrule(new g(Qe(l,s,u),c))}),o.forEach(function(l){d.rdate(l)}),a.forEach(function(l){d.exrule(new g(Qe(l,s,u),c))}),i.forEach(function(l){d.exdate(l)}),e.compatible&&e.dtstart&&d.rdate(s),d}var p=n[0]||{};return new g(Qe(p,p.dtstart||e.dtstart||s,p.tzid||e.tzid||u),c)}function vr(t,e){return e===void 0&&(e={}),hs(t,gs(e))}function Qe(t,e,r){return M(M({},t),{dtstart:e,tzid:r})}function gs(t){var e=[],r=Object.keys(t),n=Object.keys(gr);if(r.forEach(function(o){A(n,o)||e.push(o)}),e.length)throw new Error("Invalid options: "+e.join(", "));return M(M({},gr),t)}function vs(t){if(t.indexOf(":")===-1)return{name:"RRULE",value:t};var e=Ea(t,":",1),r=e[0],n=e[1];return{name:r,value:n}}function bs(t){var e=vs(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 Es(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 Ts(t){t.forEach(function(e){if(!/(VALUE=DATE(-TIME)?)|(TZID=)/.test(e))throw new Error("unsupported RDATE/EXDATE parm: "+e)})}function br(t,e){return Ts(e),t.split(",").map(function(r){return it(r)})}function Er(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;nd.format(p).replace(", ","T"),i=a(n,e),s=a(o,e),u=new Date(i+"Z").getTime();return new Date(s+"Z").getTime()-u}var Lr="0.3.25",Nr="icalendar:lastSync";console.log(`[iCalendar] Plug script executing at top level (Version ${Lr})`);async function Ss(t){let r=new TextEncoder().encode(t),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(a=>a.toString(16).padStart(2,"0")).join("")}function Ee(t){let e=r=>String(r).padStart(2,"0");return t.getFullYear()+"-"+e(t.getMonth()+1)+"-"+e(t.getDate())+"T"+e(t.getHours())+":"+e(t.getMinutes())+":"+e(t.getSeconds())}function lt(t){if(t==null)return t;if(t instanceof Date)return Ee(t);if(typeof t=="object"&&"date"in t&&t.date instanceof Date)return Ee(t.date);if(typeof t=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(t))try{return Ee(new Date(t))}catch{return t}if(Array.isArray(t))return t.map(e=>lt(e));if(typeof t=="object"){let e={};for(let r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=lt(t[r]));return e}return t}async function As(){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;if(e&&typeof e=="object"&&!Array.isArray(e)){let n=[];for(let o in e)e[o]&&typeof e[o].url=="string"&&n.push(e[o]);e=n}return{sources:e,syncWindowDays:r}}catch(t){return console.error("[iCalendar] Error in getSources:",t),{sources:[],syncWindowDays:365}}}async function xs(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 a=new Date(r+(r.includes("T")?"":"T00:00:00")+"Z");if(isNaN(a.getTime()))return null;let i=_r(o,a);return new Date(a.getTime()-i)}function ks(t,e=365){let r=t.rrule||t.recurrenceRule;if(!r)return[t];try{let n=new ut,o=r.replace(/^RRULE:/i,""),a=new Date(t.start.includes("Z")?t.start:t.start+"Z");if(isNaN(a.getTime()))return console.error(`[iCalendar] Invalid start date for recurrence: ${t.start}`),[t];let i=g.parseString(o);i.dtstart=a,n.rrule(new g(i));for(let c of t.exdate||[])n.exdate(new Date(c.includes("Z")?c:c+"Z"));let s=new Date(a.getTime()+e*864e5),u=n.between(a,s,!0);return u.length===0?[t]:u.map(c=>{let d=Ee(c);return{...t,start:d,recurrent:!0,rrule:void 0}})}catch(n){return console.error(`[iCalendar] Error expanding recurrence for ${t.summary}:`,n),[t]}}async function Ds(t,e=365){console.log(`[iCalendar] Fetching from: ${t.url}`);try{let r=await fetch(t.url);if(!r.ok)return console.error(`[iCalendar] Fetch failed for ${t.name}: ${r.status} ${r.statusText}`),[];let n=await r.text(),o=ar(void 0,n);if(!o||!o.events)return[];let a=[];for(let i of o.events){if(i.status?.toUpperCase()==="CANCELLED")continue;let s=await xs(i);if(!s)continue;let u=Ee(s),c={...i,name:i.summary||"Untitled Event",start:u,tag:"ical-event",sourceName:t.name},d=i.start?.local?.timezone||i.start?.timezone||"UTC";d!=="UTC"&&d!=="None"&&!ct(d)&&(c.description=`(Warning: Unknown timezone "${d}") ${c.description||""}`);let p=ks(c,e);for(let l of p){let m=`${l.start}${l.uid||l.summary||""}`;l.ref=await Ss(m),a.push(lt(l))}}return a}catch(r){return console.error(`[iCalendar] Error fetching/parsing ${t.name}:`,r),[]}}async function dt(){try{let{sources:t,syncWindowDays:e}=await As();if(t.length===0)return;await H.flashNotification("Syncing calendars...","info");let r=[];for(let n of t){let o=await Ds(n,e);r.push(...o)}await we.indexObjects("$icalendar",r),await H.flashNotification(`Synced ${r.length} events`,"info")}catch(t){console.error("[iCalendar] syncCalendars failed:",t)}}async function Ir(){await de.del(Nr),await dt()}async function Ur(){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(Nr),await H.flashNotification("Calendar index cleared","info")}async function Yr(){await H.flashNotification(`iCalendar Plug ${Lr}`,"info")}var Kr={syncCalendars:dt,forceSync:Ir,clearCache:Ur,showVersion:Yr},zr={name:"icalendar",version:"0.3.25",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:{}},nc={manifest:zr,functionMapping:Kr};mt(Kr,zr,self.postMessage);export{nc as plug}; //# sourceMappingURL=icalendar.plug.js.map