diff --git a/icalendar.plug.js b/icalendar.plug.js index a4740f5..719c9cb 100644 --- a/icalendar.plug.js +++ b/icalendar.plug.js @@ -1,4 +1,4 @@ -var Et=Object.defineProperty;var z=(e,t)=>{for(var r in t)Et(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(a=>({...a,source:r})))})).ok)throw new Error("Failed to post logs to server")}catch(i){console.warn("Could not post logs to server",i.message),this.logBuffer.unshift(...o)}}}},Ee;function ge(e=""){return Ee=new Q(e),Ee}var Y=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}),Y({type:"sys",id:X,name:e,args:t})}));function Te(e,t,r){te&&(Y=r,self.addEventListener("message",n=>{(async()=>{let o=n.data;switch(o.type){case"inv":{let i=e[o.name];if(!i)throw new Error(`Function not loaded: ${o.name}`);try{let a=await Promise.resolve(i(...o.args||[]));Y({type:"invr",id:o.id,result:a})}catch(a){console.error("An exception was thrown as a result of invoking function",o.name,"error:",a.message),Y({type:"invr",id:o.id,error:a.message})}}break;case"sysr":{let i=o.id,a=ee.get(i);if(!a)throw Error("Invalid request id");ee.delete(i),o.error?a.reject(new Error(o.error)):a.resolve(o.result)}break}})().catch(console.error)}),Y({type:"manifest",manifest:t}),ge(`[${t.name} plug]`))}async function gt(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 gt(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 D={};z(D,{alert:()=>rn,configureVimMode:()=>hn,confirm:()=>nn,copyToClipboard:()=>mn,deleteLine:()=>yn,dispatch:()=>en,downloadFile:()=>Vt,filterBox:()=>Ht,flashNotification:()=>$t,fold:()=>sn,foldAll:()=>cn,getCurrentEditor:()=>xt,getCurrentPage:()=>St,getCurrentPageMeta:()=>ht,getCurrentPath:()=>At,getCursor:()=>Mt,getRecentlyOpenedPages:()=>Dt,getSelection:()=>bt,getText:()=>Ct,getUiOption:()=>on,goHistory:()=>Pt,hidePanel:()=>Wt,insertAtCursor:()=>Xt,insertAtPos:()=>Gt,invokeCommand:()=>wt,isMobile:()=>Dn,moveCursor:()=>Zt,moveCursorToLine:()=>Qt,moveLineDown:()=>Tn,moveLineUp:()=>gn,navigate:()=>It,newWindow:()=>Bt,openCommandPalette:()=>zt,openPageNavigator:()=>Lt,openSearchPanel:()=>fn,openUrl:()=>Ft,prompt:()=>tn,rebuildEditorState:()=>kt,redo:()=>vn,reloadConfigAndCommands:()=>Ut,reloadPage:()=>Yt,reloadUI:()=>Kt,replaceRange:()=>Jt,save:()=>Nt,sendMessage:()=>An,setSelection:()=>Ot,setText:()=>Rt,setUiOption:()=>an,showPanel:()=>qt,showProgress:()=>jt,toggleComment:()=>En,toggleFold:()=>un,undo:()=>pn,unfold:()=>ln,unfoldAll:()=>dn,uploadFile:()=>_t,vimEx:()=>Sn});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 Dt(){return l("editor.getRecentlyOpenedPages")}function xt(){return l("editor.getCurrentEditor")}function Ct(){return l("editor.getText")}function Rt(e,t=!1){return l("editor.setText",e,t)}function Mt(){return l("editor.getCursor")}function bt(){return l("editor.getSelection")}function Ot(e,t){return l("editor.setSelection",e,t)}function wt(e,t){return l("editor.invokeCommand",e,t)}function Nt(){return l("editor.save")}function It(e,t=!1,r=!1){return l("editor.navigate",e,t,r)}function Lt(e="page"){return l("editor.openPageNavigator",e)}function zt(){return l("editor.openCommandPalette")}function Yt(){return l("editor.reloadPage")}function Kt(){return l("editor.reloadUI")}function kt(){return l("editor.rebuildEditorState")}function Ut(){return l("editor.reloadConfigAndCommands")}function Ft(e,t=!1){return l("editor.openUrl",e,t)}function Bt(){return l("editor.newWindow")}function Pt(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 Wt(e){return l("editor.hidePanel",e)}function jt(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 en(e){return l("editor.dispatch",e)}function tn(e,t=""){return l("editor.prompt",e,t)}function nn(e){return l("editor.confirm",e)}function rn(e){return l("editor.alert",e)}function on(e){return l("editor.getUiOption",e)}function an(e,t){return l("editor.setUiOption",e,t)}function sn(){return l("editor.fold")}function ln(){return l("editor.unfold")}function un(){return l("editor.toggleFold")}function cn(){return l("editor.foldAll")}function dn(){return l("editor.unfoldAll")}function pn(){return l("editor.undo")}function vn(){return l("editor.redo")}function fn(){return l("editor.openSearchPanel")}function mn(e){return l("editor.copyToClipboard",e)}function yn(){return l("editor.deleteLine")}function En(){return l("editor.toggleComment")}function gn(){return l("editor.moveLineUp")}function Tn(){return l("editor.moveLineDown")}function Sn(e){return l("editor.vimEx",e)}function hn(){return l("editor.configureVimMode")}function An(e,t){return l("editor.sendMessage",e,t)}function Dn(){return l("editor.isMobile")}var O={};z(O,{del:()=>On,get:()=>bn,set:()=>Mn});function Mn(e,t){return l("clientStore.set",e,t)}function bn(e){return l("clientStore.get",e)}function On(e){return l("clientStore.delete",e)}var ma=new Uint8Array(16);var K={};z(K,{batchDel:()=>Vn,batchDeletePrefix:()=>Hn,batchGet:()=>Bn,batchSet:()=>Un,del:()=>Pn,get:()=>Fn,listFunctions:()=>Wn,query:()=>_n,queryDelete:()=>qn,queryLua:()=>$n,set:()=>kn});function kn(e,t){return l("datastore.set",e,t)}function Un(e){return l("datastore.batchSet",e)}function Fn(e){return l("datastore.get",e)}function Bn(e){return l("datastore.batchGet",e)}function Pn(e){return l("datastore.delete",e)}function Vn(e){return l("datastore.batchDelete",e)}function _n(e){return l("datastore.query",e)}function $n(e,t,r){return l("datastore.queryLua",e,t,r)}function Hn(e){return l("datastore.batchDeletePrefix",e)}function qn(e,t){return l("datastore.queryDelete",e,t)}function Wn(){return l("datastore.listFunctions")}var k={};z(k,{define:()=>er,get:()=>Jn,has:()=>Xn,insert:()=>Qn,set:()=>Zn});function Jn(e,t){return l("config.get",e,t)}function Zn(e,t){return l("config.set",e,t)}function Qn(e,t){return l("config.insert",e,t)}function Xn(e){return l("config.has",e)}function er(e,t){return l("config.define",e,t)}var V={};z(V,{ensureFullIndex:()=>or,getObjectByRef:()=>rr,indexObjects:()=>tr,queryLuaObjects:()=>nr});function tr(e,t){return l("index.indexObjects",e,t)}function nr(e,t,r,n){return l("index.queryLuaObjects",e,t,r,n)}function rr(e,t,r){return l("index.getObjectByRef",e,t,r)}function or(){return l("index.ensureFullIndex")}var h=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[r,t])),y=e=>Object.keys(e),Me={action:"ACTION",description:"DESCRIPTION",duration:"DURATION",repeat:"REPEAT",summary:"SUMMARY",trigger:"TRIGGER",attachments:"ATTACH",attendees:"ATTENDEE"},be=h(Me),wa=y(be),Na=y(Me),Oe={method:"METHOD",prodId:"PRODID",version:"VERSION",name:"X-WR-CALNAME"},we=h(Oe),Ia=y(we),La=y(Oe),Ne={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"},Ie=h(Ne),za=y(Ie),Ya=y(Ne),Le={id:"TZID",lastModified:"LAST-MODIFIED",url:"TZURL"},ze=h(Le),Ka=y(ze),ka=y(Le),Ye={comment:"COMMENT",name:"TZNAME",offsetFrom:"TZOFFSETFROM",offsetTo:"TZOFFSETTO",recurrenceDate:"RDATE",recurrenceRule:"RRULE",start:"DTSTART"},Ke=h(Ye),Ua=y(Ke),Fa=y(Ye),ke={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"},Ue=h(ke),Ba=y(Ue),Pa=y(ke),Fe={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"},Be=h(Fe),Va=y(Be),_a=y(Fe),Pe={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"},Ve=h(Pe),$a=y(Ve),Ha=y(Pe),_e={stamp:"DTSTAMP",start:"DTSTART",uid:"UID",url:"URL",organizer:"ORGANIZER",attendees:"ATTENDEE",comment:"COMMENT",end:"DTEND",freeBusy:"FREEBUSY"},$e=h(_e),qa=y($e),Wa=y(_e),He="BEGIN",qe="END",ar="VCALENDAR",We="VTIMEZONE",ir="STANDARD",sr="DAYLIGHT",je="VEVENT",Ge="VALARM",Je="VTODO",Ze="VJOURNAL",Qe="VFREEBUSY";var Se=e=>new RegExp(`${He}:${e}([\\s\\S]*?)${qe}:${e}`,"g"),lr=e=>new RegExp(`${He}:${e}|${qe}:${e}`,"g");var re=/\r\n|\r|\n/;var he=` -`,ur=":",I=",",cr='"',oe=";";var Ae="=";var dr=Math.pow(10,8)*24*60*60*1e3,ja=-dr,pr=6048e5;var Xe=6e4,et=36e5,vr=3600,tt=vr*24,Ga=tt*7,fr=tt*365.2425,mr=fr/12,Ja=mr*3,De=Symbol.for("constructDateFrom");function S(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&De in e?e[De](t):e instanceof Date?new e.constructor(t):new Date(t)}function c(e,t){return S(t||e,e)}function ie(e,t,r){let n=c(e,r?.in);return isNaN(t)?S(r?.in||e,NaN):(t&&n.setDate(n.getDate()+t),n)}function nt(e,t,r){let n=c(e,r?.in);if(isNaN(t))return S(r?.in||e,NaN);if(!t)return n;let o=n.getDate(),i=S(r?.in||e,n.getTime());i.setMonth(n.getMonth()+t+1,0);let a=i.getDate();return o>=a?i:(n.setFullYear(i.getFullYear(),i.getMonth(),o),n)}function q(e,t,r){return S(r?.in||e,+c(e)+t)}function yr(e,t,r){return q(e,t*et,r)}var Er={};function W(){return Er}function $(e,t){var r,n,o,i;let a=W(),s=t?.weekStartsOn??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.weekStartsOn)??a.weekStartsOn??((i=(o=a.locale)==null?void 0:o.options)==null?void 0:i.weekStartsOn)??0,u=c(e,t?.in),d=u.getDay(),v=(dtypeof n=="object"));return t.map(r)}function Tr(e,t){let r=c(e,t?.in);return r.setHours(0,0,0,0),r}function rt(e,t,r){let n=c(e,r?.in);return n.setTime(n.getTime()+t*Xe),n}function Sr(e,t,r){return q(e,t*1e3,r)}function se(e,t,r){return ie(e,t*7,r)}function ot(e,t,r){return nt(e,t*12,r)}function le(e,t){let r=+c(e)-+c(t);return r<0?-1:r>0?1:r}function xe(e,t){let r=c(e,t?.in),n=r.getMonth();return r.setFullYear(r.getFullYear(),n+1,0),r.setHours(23,59,59,999),r}function hr(e,t){let[r,n]=gr(e,t.start,t.end);return{start:r,end:n}}function Ar(e,t){let{start:r,end:n}=hr(t?.in,e),o=+r>+n,i=o?+r:+n,a=o?n:r;a.setHours(0,0,0,0);let s=t?.step??1;if(!s)return[];s<0&&(s=-s,o=!o);let u=[];for(;+a<=i;)u.push(S(r,a)),a.setDate(a.getDate()+s),a.setHours(0,0,0,0);return o?u.reverse():u}function Ce(e,t){let r=c(e,t?.in);return r.setDate(1),r.setHours(0,0,0,0),r}function Dr(e,t){let r=c(e,t?.in),n=r.getFullYear();return r.setFullYear(n+1,0,0),r.setHours(23,59,59,999),r}function xr(e,t){let r=c(e,t?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function Cr(e,t){var r,n,o,i;let a=c(e,t?.in),s=a.getFullYear(),u=W(),d=t?.firstWeekContainsDate??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??u.firstWeekContainsDate??((i=(o=u.locale)==null?void 0:o.options)==null?void 0:i.firstWeekContainsDate)??1,v=S(t?.in||e,0);v.setFullYear(s+1,0,d),v.setHours(0,0,0,0);let g=$(v,t),m=S(t?.in||e,0);m.setFullYear(s,0,d),m.setHours(0,0,0,0);let A=$(m,t);return+a>=+g?s+1:+a>=+A?s:s-1}function Rr(e,t){var r,n,o,i;let a=W(),s=t?.firstWeekContainsDate??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??a.firstWeekContainsDate??((i=(o=a.locale)==null?void 0:o.options)==null?void 0:i.firstWeekContainsDate)??1,u=Cr(e,t),d=S(t?.in||e,0);return d.setFullYear(u,0,s),d.setHours(0,0,0,0),$(d,t)}function Mr(e,t){let r=c(e,t?.in),n=+$(r,t)-+Rr(r,t);return Math.round(n/pr)+1}function _(e,t){return c(e,t?.in).getDay()}function at(e,t){let r=c(e,t?.in),n=r.getFullYear(),o=r.getMonth(),i=S(r,0);return i.setFullYear(n,o+1,0),i.setHours(0,0,0,0),i.getDate()}function br(e,t){return c(e,t?.in).getHours()}function Or(e,t){return c(e,t?.in).getMinutes()}function it(e,t){return c(e,t?.in).getMonth()}function wr(e){return c(e).getSeconds()}function Nr(e,t){return c(e,t?.in).getFullYear()}function Ir(e,t){return+c(e)==+c(t)}function Lr(e,t,r){let n=c(e,r?.in),o=Mr(n,r)-t;return n.setDate(n.getDate()-o*7),c(n,r?.in)}function H(e,t,r){var n,o,i,a;let s=W(),u=r?.weekStartsOn??((o=(n=r?.locale)==null?void 0:n.options)==null?void 0:o.weekStartsOn)??s.weekStartsOn??((a=(i=s.locale)==null?void 0:i.options)==null?void 0:a.weekStartsOn)??0,d=c(e,r?.in),v=d.getDay(),g=(t%7+7)%7,m=7-u,A=t<0||t>6?t-(v+m)%7:(g+m)%7-(v+m)%7;return ie(d,A,r)}function st(e,t,r){let n=+c(e,r?.in),[o,i]=[+c(t.start,r?.in),+c(t.end,r?.in)].sort((a,s)=>a-s);return n>=o&&n<=i}function zr(e){let t=e/et;return Math.trunc(t)}function Yr(e){let t=e/Xe;return Math.trunc(t)}function Kr(e,t,r){let n=c(e,r?.in),o=n.getFullYear(),i=n.getDate(),a=S(r?.in||e,0);a.setFullYear(o,t,15),a.setHours(0,0,0,0);let s=at(a);return n.setMonth(t,Math.min(i,s)),n}function kr(e,t,r){let n=c(e,r?.in);return n.setDate(t),n}function Ur(e,t,r){let n=c(e,r?.in);return n.setMonth(0),n.setDate(t),n}function Fr(e,t,r){let n=c(e,r?.in);return n.setHours(t),n}function Br(e,t,r){let n=c(e,r?.in);return n.setMinutes(t),n}function Pr(e,t,r){let n=c(e,r?.in);return n.setSeconds(t),n}function Vr(e,t,r){return q(e,-t,r)}function _r(e,t,r){return se(e,-t,r)}var $r=[ir,sr];var Hr=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"];var lt=["SU","MO","TU","WE","TH","FR","SA"];var w=(e,t)=>t===void 0?!1:e>=t,qr=(e,{start:t,end:r},n)=>{if(w(n.length,e.count))return;let o=e.frequency,i=e.interval||1;if(!o)return;let a=t;if(o==="SECONDLY"){for(;a{let o=r.map(({day:i,occurrence:a})=>({occurrence:a,day:lt.indexOf(i)}));return e.frequency==="YEARLY"?e.byYearday||e.byMonthday?t.map(i=>i.filter(a=>o.find(({day:s})=>s===_(a)))):e.byWeekNo?t.map(i=>i.flatMap(a=>o.map(({day:s})=>H(a,s,{weekStartsOn:n})))):e.byMonth?t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>ne(x(Ce(a)),x(xe(a)),s,n,u)))):t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>ne(x(xr(a)),x(Dr(a)),s,n,u)))):e.frequency==="MONTHLY"?e.byMonthday?t.map(i=>i.filter(a=>o.find(({day:s})=>s===_(a)))):t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>ne(x(Ce(a)),x(xe(a)),s,n,u)))):e.frequency==="WEEKLY"?t.map(i=>i.flatMap(a=>o.map(({day:s})=>H(a,s,{weekStartsOn:n})))):t.map(i=>i.filter(a=>o.find(({day:s})=>s===_(a))))},ne=(e,t,r,n,o)=>{if(o!==void 0){if(!(o<0)){let s=H(e,r,{weekStartsOn:n}),u=e>s;return se(s,(o||1)-1+(u?1:0))}let i=H(t,r,{weekStartsOn:n}),a=tx(i)).filter(i=>st(i,{start:e,end:t})).filter(i=>r===_(i))},x=e=>rt(e,-e.getTimezoneOffset()),jr=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t.map(n=>n.flatMap(o=>r.map(i=>Fr(o,i)))):t.map(n=>n.filter(o=>r.includes(br(o)))),Gr=(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(i=>Br(o,i)))):t.map(n=>n.filter(o=>r.includes(Or(o)))),Jr=(e,t,r)=>e.frequency==="YEARLY"?t.map(n=>n.flatMap(o=>r.map(i=>Kr(o,i)))):t.map(n=>n.filter(o=>r.includes(it(o)))),Zr=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"?t.map(n=>n.flatMap(o=>{let i=at(o);return r.map(a=>a>i?void 0:kr(o,a)).filter(a=>!!a)})):e.frequency==="WEEKLY"?t:t.map(n=>n.filter(o=>r.includes(it(o)))),Qr=(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(i=>Pr(o,i)))):t.map(n=>n.filter(o=>r.includes(wr(o)))),Xr=(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,i)=>r.some(a=>a>0?i===0?!1:i%a===0:i===0?n.length-1+a===0:i%(n.length-1+a)===0))),eo=(e,t,r,n)=>e.frequency==="YEARLY"?t.map(o=>o.flatMap(i=>r.map(a=>Lr(i,a,{weekStartsOn:n})))):t,to=(e,t,r)=>e.frequency==="YEARLY"?t.map(n=>n.flatMap(o=>r.map(i=>Ur(o,i)))):e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t:t.map(n=>n.filter(o=>r.includes(Nr(o)))),no=(e,t,r)=>{let n=r;return e.byMonth&&(n=Jr(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=Zr(e,n,e.byMonthday)),e.byDay&&(n=Wr(e,n,e.byDay,t.weekStartsOn)),e.byHour&&(n=jr(e,n,e.byHour)),e.byMinute&&(n=Gr(e,n,e.byMinute)),e.bySecond&&(n=Qr(e,n,e.bySecond)),e.bySetPos&&(n=Xr(e,n,e.bySetPos)),n.map(o=>o.sort(le).filter(i=>!(t.exceptions.length>0&&t.exceptions.some(a=>Ir(a,i))||!st(i,{start:t.start,end:t.end}))))},ro=2,oo=(e,t)=>{var r;let n=t.start,o=((r=e.until)==null?void 0:r.date)||t?.end||ot(n,ro),i=t.exceptions||[],a=(e.workweekStart?lt.indexOf(e.workweekStart):1)%7,s=[[n]];qr(e,{start:n,end:o},s);let u=no(e,{start:n,end:o,exceptions:i,weekStartsOn:a},s);return e.count?u.flat().splice(0,e.count):u.flat()},ao=(e,t)=>t.flatMap(r=>!r.recurrenceRule||r.recurrenceRule.until&&r.recurrenceRule.until.date({...r,start:n}))),ae=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},io=(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()}},so=(e,t,r)=>{let n=r?.find(i=>i.id===t);if(n){let i=ao(e,n.props).sort((u,d)=>le(u.start,d.start));for(let u=0;u5?d.substring(0,5):d;return{offset:v,milliseconds:ae(v)}}let a=i[i.length-1].offsetTo,s=a.length>5?a.substring(0,5):a;return{offset:s,milliseconds:ae(s)}}let o=io(t,e);if(!Number.isNaN(o)){let i=o<0,a=Math.abs(zr(o)),s=Math.abs(Yr(o))-a*60,u=a.toString().length===1?`0${a}`:a.toString(),d=s.toString().length===1?`0${s}`:s.toString();return{offset:`${i?"-":"+"}${u}${d}`,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,i;let a=((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:(i=t.options)==null?void 0:i.FMTTYPE};return p(e,a)},N=e=>e.replace(/mailto:/gi,""),B=(e,t)=>{var r,n,o,i,a,s,u,d,v,g,m;return p(e,{email:N(t.value),delegatedFrom:(r=t.options)!=null&&r["DELEGATED-FROM"]?N((n=t.options)==null?void 0:n["DELEGATED-FROM"]):void 0,dir:(o=t.options)==null?void 0:o.DIR,member:(i=t.options)!=null&&i.MEMBER?N(t.options.MEMBER):void 0,name:(a=t.options)==null?void 0:a.CN,partstat:(s=t.options)==null?void 0:s.PARTSTAT,role:(u=t.options)==null?void 0:u.ROLE,sentBy:(d=t.options)!=null&&d["SENT-BY"]?N(t.options["SENT-BY"]):void 0,rsvp:(v=t.options)!=null&&v.RSVP?((g=t.options)==null?void 0:g.RSVP)==="TRUE"?!0:((m=t.options)==null?void 0:m.RSVP)==="FALSE"?!1:void 0:void 0})},P=(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"),i=o[0];if(i.includes("D")){let[s,u]=i.split("D");n.days=Number(s),i=u}if(i.includes("W")){let[s,u]=i.split("W");n.weeks=Number(s),i=u}let a=o[1];if(a){if(a.includes("H")){let[s,u]=a.split("H");n.hours=Number(s),a=u}if(a.includes("M")){let[s,u]=a.split("M");n.minutes=Number(s),a=u}if(a.includes("S")){let[s,u]=a.split("S");n.seconds=Number(s),a=u}}return 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),i=new Date(Date.UTC(r,n,o));return p(e,i)},U=(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),i=Number.parseInt(t.value.slice(9,11),10),a=Number.parseInt(t.value.slice(11,13),10),s=Number.parseInt(t.value.slice(13,15),10),u=new Date(Date.UTC(r,n,o,i,a,s));return p(e,u)},co=(e,t,r)=>{let n=ae(r),o=U(void 0,t),i=Vr(o,n);return p(e,i)},po=(e,t)=>{var r,n,o,i,a,s;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",d=U(void 0,e);if(!((i=e.options)!=null&&i.TZID))return{date:d,type:u};let v=so(d,e.options.TZID,t?.timezones);return v?{date:q(d,-v.milliseconds),type:u,local:(a=e.options)!=null&&a.TZID?{date:d,timezone:(s=e.options)==null?void 0:s.TZID,tzoffset:v.offset}:void 0}:{date:d,type:u}},f=(e,t,r)=>p(e,po(t,r)),vo=(e,t,r)=>{var n,o,i,a;let s=((n=t.options)==null?void 0:n.VALUE)==="DATE-TIME"||((o=t.options)==null?void 0:o.VALUE)==="DATE"?{type:"absolute",value:f(void 0,t,r),options:{related:(i=t.options)==null?void 0:i.RELATED}}:{type:"relative",value:P(void 0,t),options:{related:(a=t.options)==null?void 0:a.RELATED}};return p(e,s)},fo=e=>e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e,ut=e=>e.map(t=>{let[r,...n]=t.split(Ae),o=n.join(Ae);return{property:r,value:fo(o)}},{}),mo=e=>e.reduce((t,r)=>(t[r.property]=r.value,t),{}),yo=e=>mo(ut(e)),Eo=e=>{let t=!1,r;for(let i=0;i{let{property:t,value:r}=Eo(e);if(t.includes(oe)){let[n,...o]=t.split(oe),i=yo(o);return{property:n,line:{options:i,value:r}}}return{property:t,line:{value:r}}},Re=e=>/^[ \t]/.test(e),To=e=>/^[A-Z]+(?:-[A-Z]+)*[:;]/.test(e),So=e=>{let t=[],r=e.split(re);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,i])=>{let a=Object.entries(r||{}).find(([d,v])=>v.name===o);if(!a){n[Ao(o)]=i.value;return}let s=a[1].convert(i),u=a[1].schema;if(!u){n[a[0]]=s;return}n[a[0]]=p(u,s)}),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},Do=e=>e.startsWith("X-"),C=(e,t,r)=>{let n=t.replace(lr(r?.icsComponent),""),o=[...new Set(Object.values(r.childComponents||{}).flatMap(({icsComponent:g})=>g))],i=So(o.reduce((g,m)=>g.replace(Se(m),""),n)),a=r.defaultValues||{},s={};i.forEach(g=>{var m,A;let{property:R,line:M}=go(g);Do(R)&&(s[R]=M);let E=r.objectKeyMap[R];if(!E)return;let L=(m=r.convertArrayValues)==null?void 0:m[E];if(L){let b=L({line:M});if(!b)return;(a[E]===void 0||a[E]===null||!Array.isArray(a[E]))&&(a[E]=[]),Array.isArray(b)?a[E].push(...b):a[E].push(b);return}let me=(A=r.convertValues)==null?void 0:A[E];if(me){let b=me({line:M});if(!b)return;a[E]=b;return}a[E]=M.value});let u=r.childComponents,d=u?Object.keys(u||{}):[];u&&d.length>0&&d.forEach(g=>{let m=u?.[g];if(!m)return;let A=Array.isArray(m.icsComponent)?m.icsComponent:[m.icsComponent],R=[],M=[];A.forEach(E=>{M.push(...n.matchAll(Se(E)))}),M.map(E=>E[0]).forEach(E=>{let L=m.convert(E,{data:a});L&&R.push(L)}),R.length!==0&&(a[g]=R)});let v=p(e,a);return r!=null&&r.nonStandard?ho(v,s,r?.nonStandard):v},j=(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"]?N(t.options["SENT-BY"]):void 0,email:N(t.value)})},ue=(e,t,r)=>{var n;return p(e,{value:f(void 0,t,r),range:(n=t.options)==null?void 0:n.RANGE})},xo=e=>{if(e.length===2)return{day:e};let t=e.slice(0,-2);return{day:e.replace(t,""),occurrence:Number(t)}},Co=(e,t)=>p(e,xo(t.value)),Ro=(e,t)=>p(e,t.value),Mo=["until"],bo=e=>Mo.includes(e),Oo=["bySecond","byMinute","byHour","byMonthday","byYearday","byWeekNo","bySetPos"],wo=e=>Oo.includes(e),No=["byDay"],Io=e=>No.includes(e),Lo=["count","interval"],zo=e=>Lo.includes(e),G=(e,t,r)=>{let n={};return ut(t.value.split(oe)).forEach(o=>{let{property:i,value:a}=o,s=Ue[i];if(s){if(bo(s)){n[s]=f(void 0,{value:a,options:{VALUE:a.includes("T")?"DATE-TIME":"DATE"}},{timezones:r?.timezones});return}if(wo(s)){n[s]=a.split(I).map(u=>Number(u));return}if(s==="byMonth"){n[s]=a.split(I).map(u=>Number(u)-1);return}if(Io(s)){n[s]=a.split(I).map(u=>Co(void 0,{value:u}));return}if(zo(s)){n[s]=Number(a);return}if(s==="frequency"){if(!a||!Hr.includes(a))return;n[s]=a;return}if(s==="workweekStart"){n[s]=Ro(void 0,{value:a});return}}}),p(e,n)},ce=(e,t)=>p(e,t.value),Yo=(e,t)=>p(e,t.value),de=(e,t,r)=>p(e,t.value.split(",").map(n=>f(void 0,{value:n,options:t.options},r))),Ko=(e,t)=>p(e,t.value),ko=(e,t)=>p(e,t.value),Uo=(e,t)=>p(e,t.value),F=(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)),Bo=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:Ge,objectKeyMap:be,convertValues:{trigger:({line:o})=>vo(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>P(void 0,o),repeat:({line:o})=>F(void 0,o)},convertArrayValues:{attachments:({line:o})=>lo(void 0,o),attendees:({line:o})=>B(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},Po=(...e)=>{let[t,r,n]=e,o,i=C(t,r,{icsComponent:je,objectKeyMap:Ie,convertValues:{stamp:({line:a})=>f(void 0,a,{timezones:n?.timezones}),start:({line:a})=>f(void 0,a,{timezones:n?.timezones}),end:({line:a})=>f(void 0,a,{timezones:n?.timezones}),created:({line:a})=>f(void 0,a,{timezones:n?.timezones}),lastModified:({line:a})=>f(void 0,a,{timezones:n?.timezones}),categories:({line:a})=>a.value.split(I),description:({line:a})=>{var s;return(s=a.options)!=null&&s.ALTREP&&(o=a.options.ALTREP),T(void 0,a)},location:({line:a})=>T(void 0,a),comment:({line:a})=>T(void 0,a),summary:({line:a})=>T(void 0,a),recurrenceRule:({line:a})=>G(void 0,a,{timezones:n?.timezones}),duration:({line:a})=>P(void 0,a),organizer:({line:a})=>j(void 0,a),sequence:({line:a})=>F(void 0,a),class:({line:a})=>ce(void 0,a),recurrenceId:({line:a})=>ue(void 0,a,{timezones:n?.timezones}),status:({line:a})=>Ko(void 0,a),timeTransparent:({line:a})=>Yo(void 0,a)},convertArrayValues:{attendees:({line:a})=>B(void 0,a),exceptionDates:({line:a})=>de(void 0,a,{timezones:n?.timezones})},childComponents:{alarms:{icsComponent:Ge,convert:a=>Bo(void 0,a,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},timezones:n?.timezones,nonStandard:n?.nonStandard});return o&&(i.descriptionAltRep=o),i},Vo=(...e)=>{let[t,r,n]=e,o=r.split("BEGIN:")[1].split(re)[0],i=$r.includes(o)?o:"STANDARD",a=r.split("TZOFFSETTO:")[1].split(re)[0];return C(t,r,{icsComponent:i,objectKeyMap:Ke,defaultValues:{type:i},convertValues:{start:({line:s})=>co(void 0,s,a),recurrenceRule:({line:s})=>G(void 0,s,{timezones:n?.timezones}),recurrenceDate:({line:s})=>f(void 0,s,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},_o=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:We,objectKeyMap:ze,convertValues:{lastModified:({line:o})=>U(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 C(t,r,{icsComponent:Je,objectKeyMap:Be,convertValues:{stamp:({line:o})=>f(void 0,o,{timezones:n?.timezones}),start:({line:o})=>f(void 0,o,{timezones:n?.timezones}),due:({line:o})=>f(void 0,o,{timezones:n?.timezones}),created:({line:o})=>f(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>f(void 0,o,{timezones:n?.timezones}),completed:({line:o})=>f(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(I),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})=>P(void 0,o),organizer:({line:o})=>j(void 0,o),sequence:({line:o})=>F(void 0,o),percentComplete:({line:o})=>F(void 0,o),class:({line:o})=>ce(void 0,o),recurrenceId:({line:o})=>ue(void 0,o,{timezones:n?.timezones}),status:({line:o})=>ko(void 0,o)},convertArrayValues:{attendees:({line:o})=>B(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 C(t,r,{icsComponent:Ze,objectKeyMap:Ve,convertValues:{stamp:({line:o})=>f(void 0,o,{timezones:n?.timezones}),start:({line:o})=>f(void 0,o,{timezones:n?.timezones}),created:({line:o})=>f(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>f(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(I),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})=>j(void 0,o),sequence:({line:o})=>F(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})=>B(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,i]=n.split("/"),a=U(void 0,{value:o});if(i.startsWith("PT")){let u=P(void 0,{value:i});return{start:a,duration:u}}let s=U(void 0,{value:i});return{start:a,end:s}})})},Wo=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:Qe,objectKeyMap:$e,convertValues:{stamp:({line:o})=>f(void 0,o,{timezones:n?.timezones}),start:({line:o})=>f(void 0,o,{timezones:n?.timezones}),end:({line:o})=>f(void 0,o,{timezones:n?.timezones}),comment:({line:o})=>T(void 0,o),organizer:({line:o})=>j(void 0,o)},convertArrayValues:{attendees:({line:o})=>B(void 0,o),freeBusy:({line:o})=>qo(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},ct=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:ar,objectKeyMap:we,convertValues:{version:({line:o})=>o.value},childComponents:{timezones:{icsComponent:We,convert:o=>_o(void 0,o,{nonStandard:n?.nonStandard})},events:{icsComponent:je,convert:(o,{data:i})=>Po(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},todos:{icsComponent:Je,convert:(o,{data:i})=>$o(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},journals:{icsComponent:Ze,convert:(o,{data:i})=>Ho(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},freeBusy:{icsComponent:Qe,convert:(o,{data:i})=>Wo(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})}},nonStandard:n?.nonStandard})};var dt="0.2.11",J="icalendar:lastSync",jo=21600;console.log(`[iCalendar] Plug loading (Version ${dt})...`);function pe(e,t=0){t!==0&&(e=new Date(e.getTime()+t*36e5));let r=n=>String(n).padStart(2,"0");return e.getFullYear()+"-"+r(e.getMonth()+1)+"-"+r(e.getDate())+"T"+r(e.getHours())+":"+r(e.getMinutes())+":"+r(e.getSeconds())+"."+String(e.getMilliseconds()).padStart(3,"0")}function Go(e){return e&&typeof e=="object"&&"date"in e&&"type"in e}async function Jo(e){let r=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")}function ve(e,t=0){if(e==null)return e;if(e instanceof Date)return pe(e,t);if(Go(e)&&e.date instanceof Date){let r=e.local?.date instanceof Date?e.local.date:e.date;return pe(r,t)}if(typeof e=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(e)){let r=e.endsWith("Z")?e:e+"Z";return pe(new Date(r),t)}if(Array.isArray(e))return e.map(r=>ve(r,t));if(typeof e=="object"){let r={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=ve(e[n],t));return r}return e}async function Zo(){let e=await k.get("icalendar",{sources:[]});if(!e.sources)return[];let t=e.sources;Array.isArray(t)||(t=[t]);let r=[];for(let n of t)typeof n.url=="string"&&r.push({url:n.url,name:n.name});return r}async function Qo(e,t=0){let r=e.url.trim();r.includes(" ")&&(r=encodeURI(r));let n=await fetch(r,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}});if(!n.ok)throw new Error(`HTTP ${n.status}`);let o=await n.text(),i=ct(void 0,o);return i.events?await Promise.all(i.events.map(async a=>{let s=`${a.start?.date||""}${a.uid||a.summary||""}`,u=await Jo(s);return ve({...a,ref:u,tag:"ical-event",sourceName:e.name},t)})):[]}async function fe(){try{let e=await k.get("icalendar",{sources:[]}),t=e.tzShift??0,r=(e.cacheDuration??jo)*1e3,n=await Zo();if(n.length===0)return;let o=await O.get(J),i=Date.now();if(o&&i-o0&&await K.batchDel(t),await O.del(J),await D.flashNotification("Calendar index cleared","info")}catch(e){console.error("[iCalendar] Failed to clear cache:",e)}}async function ft(){await D.flashNotification(`iCalendar Plug ${dt}`,"info")}var mt={syncCalendars:fe,forceSync:pt,clearCache:vt,showVersion:ft},yt={name:"icalendar",requiredPermissions:["fetch"],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}}},config:{"schema.config.properties.icalendar":{type:"object",required:["sources"],properties:{sources:{type:"array",minItems:1,items:{type:"object",required:["url"],properties:{url:{type:"string"},name:{type:"string"}}}},cacheDuration:{type:"number",description:"Interval between two calendar synchronizations (default: 21600 = 6 hours)"}}}},assets:{}},ii={manifest:yt,functionMapping:mt};Te(mt,yt,self.postMessage);export{ii as plug}; +var ft=Object.defineProperty;var L=(e,t)=>{for(var r in t)ft(e,r,{get:t[r],enumerable:!0})};function me(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(a=>({...a,source:r})))})).ok)throw new Error("Failed to post logs to server")}catch(i){console.warn("Could not post logs to server",i.message),this.logBuffer.unshift(...o)}}}},fe;function ye(e=""){return fe=new Z(e),fe}var z=e=>{throw new Error("Not initialized yet")},ee=typeof window>"u"&&typeof globalThis.WebSocketPair>"u";typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var X=new Map,Q=0;ee&&(globalThis.syscall=async(e,...t)=>await new Promise((r,n)=>{Q++,X.set(Q,{resolve:r,reject:n}),z({type:"sys",id:Q,name:e,args:t})}));function Ee(e,t,r){ee&&(z=r,self.addEventListener("message",n=>{(async()=>{let o=n.data;switch(o.type){case"inv":{let i=e[o.name];if(!i)throw new Error(`Function not loaded: ${o.name}`);try{let a=await Promise.resolve(i(...o.args||[]));z({type:"invr",id:o.id,result:a})}catch(a){console.error("An exception was thrown as a result of invoking function",o.name,"error:",a.message),z({type:"invr",id:o.id,error:a.message})}}break;case"sysr":{let i=o.id,a=X.get(i);if(!a)throw Error("Invalid request id");X.delete(i),o.error?a.reject(new Error(o.error)):a.resolve(o.result)}break}})().catch(console.error)}),z({type:"manifest",manifest:t}),ye(`[${t.name} plug]`))}async function yt(e,t){if(typeof e!="string"){let r=new Uint8Array(await e.arrayBuffer()),n=r.length>0?J(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 Et(){globalThis.fetch=async function(e,t){let r=t&&t.body?J(new Uint8Array(await new Response(t.body).arrayBuffer())):void 0,n=await yt(e,t&&{method:t.method,headers:t.headers,base64Body:r});return new Response(n.base64Body?me(n.base64Body):null,{status:n.status,headers:n.headers})}}ee&&Et();var x={};L(x,{alert:()=>tn,configureVimMode:()=>Tn,confirm:()=>en,copyToClipboard:()=>vn,deleteLine:()=>mn,dispatch:()=>Qt,downloadFile:()=>Bt,filterBox:()=>_t,flashNotification:()=>Vt,fold:()=>on,foldAll:()=>ln,getCurrentEditor:()=>At,getCurrentPage:()=>gt,getCurrentPageMeta:()=>Tt,getCurrentPath:()=>St,getCursor:()=>Ct,getRecentlyOpenedPages:()=>ht,getSelection:()=>Mt,getText:()=>xt,getUiOption:()=>nn,goHistory:()=>Ft,hidePanel:()=>Ht,insertAtCursor:()=>Zt,insertAtPos:()=>Wt,invokeCommand:()=>bt,isMobile:()=>hn,moveCursor:()=>Gt,moveCursorToLine:()=>Jt,moveLineDown:()=>En,moveLineUp:()=>yn,navigate:()=>Nt,newWindow:()=>Ut,openCommandPalette:()=>It,openPageNavigator:()=>wt,openSearchPanel:()=>pn,openUrl:()=>kt,prompt:()=>Xt,rebuildEditorState:()=>Yt,redo:()=>dn,reloadConfigAndCommands:()=>Kt,reloadPage:()=>Lt,reloadUI:()=>zt,replaceRange:()=>jt,save:()=>Ot,sendMessage:()=>Sn,setSelection:()=>Rt,setText:()=>Dt,setUiOption:()=>rn,showPanel:()=>$t,showProgress:()=>qt,toggleComment:()=>fn,toggleFold:()=>sn,undo:()=>cn,unfold:()=>an,unfoldAll:()=>un,uploadFile:()=>Pt,vimEx:()=>gn});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function l(e,...t){return globalThis.syscall(e,...t)}function gt(){return l("editor.getCurrentPage")}function Tt(){return l("editor.getCurrentPageMeta")}function St(){return l("editor.getCurrentPath")}function ht(){return l("editor.getRecentlyOpenedPages")}function At(){return l("editor.getCurrentEditor")}function xt(){return l("editor.getText")}function Dt(e,t=!1){return l("editor.setText",e,t)}function Ct(){return l("editor.getCursor")}function Mt(){return l("editor.getSelection")}function Rt(e,t){return l("editor.setSelection",e,t)}function bt(e,t){return l("editor.invokeCommand",e,t)}function Ot(){return l("editor.save")}function Nt(e,t=!1,r=!1){return l("editor.navigate",e,t,r)}function wt(e="page"){return l("editor.openPageNavigator",e)}function It(){return l("editor.openCommandPalette")}function Lt(){return l("editor.reloadPage")}function zt(){return l("editor.reloadUI")}function Yt(){return l("editor.rebuildEditorState")}function Kt(){return l("editor.reloadConfigAndCommands")}function kt(e,t=!1){return l("editor.openUrl",e,t)}function Ut(){return l("editor.newWindow")}function Ft(e){return l("editor.goHistory",e)}function Bt(e,t){return l("editor.downloadFile",e,t)}function Pt(e,t){return l("editor.uploadFile",e,t)}function Vt(e,t="info"){return l("editor.flashNotification",e,t)}function _t(e,t,r="",n=""){return l("editor.filterBox",e,t,r,n)}function $t(e,t,r,n=""){return l("editor.showPanel",e,t,r,n)}function Ht(e){return l("editor.hidePanel",e)}function qt(e,t){return l("editor.showProgress",e,t)}function Wt(e,t){return l("editor.insertAtPos",e,t)}function jt(e,t,r){return l("editor.replaceRange",e,t,r)}function Gt(e,t=!1){return l("editor.moveCursor",e,t)}function Jt(e,t=1,r=!1){return l("editor.moveCursorToLine",e,t,r)}function Zt(e,t=!1,r=!1){return l("editor.insertAtCursor",e,t,r)}function Qt(e){return l("editor.dispatch",e)}function Xt(e,t=""){return l("editor.prompt",e,t)}function en(e){return l("editor.confirm",e)}function tn(e){return l("editor.alert",e)}function nn(e){return l("editor.getUiOption",e)}function rn(e,t){return l("editor.setUiOption",e,t)}function on(){return l("editor.fold")}function an(){return l("editor.unfold")}function sn(){return l("editor.toggleFold")}function ln(){return l("editor.foldAll")}function un(){return l("editor.unfoldAll")}function cn(){return l("editor.undo")}function dn(){return l("editor.redo")}function pn(){return l("editor.openSearchPanel")}function vn(e){return l("editor.copyToClipboard",e)}function mn(){return l("editor.deleteLine")}function fn(){return l("editor.toggleComment")}function yn(){return l("editor.moveLineUp")}function En(){return l("editor.moveLineDown")}function gn(e){return l("editor.vimEx",e)}function Tn(){return l("editor.configureVimMode")}function Sn(e,t){return l("editor.sendMessage",e,t)}function hn(){return l("editor.isMobile")}var P={};L(P,{del:()=>Rn,get:()=>Mn,set:()=>Cn});function Cn(e,t){return l("clientStore.set",e,t)}function Mn(e){return l("clientStore.get",e)}function Rn(e){return l("clientStore.delete",e)}var fa=new Uint8Array(16);var Y={};L(Y,{batchDel:()=>Bn,batchDeletePrefix:()=>_n,batchGet:()=>Un,batchSet:()=>Kn,del:()=>Fn,get:()=>kn,listFunctions:()=>Hn,query:()=>Pn,queryDelete:()=>$n,queryLua:()=>Vn,set:()=>Yn});function Yn(e,t){return l("datastore.set",e,t)}function Kn(e){return l("datastore.batchSet",e)}function kn(e){return l("datastore.get",e)}function Un(e){return l("datastore.batchGet",e)}function Fn(e){return l("datastore.delete",e)}function Bn(e){return l("datastore.batchDelete",e)}function Pn(e){return l("datastore.query",e)}function Vn(e,t,r){return l("datastore.queryLua",e,t,r)}function _n(e){return l("datastore.batchDeletePrefix",e)}function $n(e,t){return l("datastore.queryDelete",e,t)}function Hn(){return l("datastore.listFunctions")}var K={};L(K,{define:()=>Qn,get:()=>jn,has:()=>Zn,insert:()=>Jn,set:()=>Gn});function jn(e,t){return l("config.get",e,t)}function Gn(e,t){return l("config.set",e,t)}function Jn(e,t){return l("config.insert",e,t)}function Zn(e){return l("config.has",e)}function Qn(e,t){return l("config.define",e,t)}var V={};L(V,{ensureFullIndex:()=>nr,getObjectByRef:()=>tr,indexObjects:()=>Xn,queryLuaObjects:()=>er});function Xn(e,t){return l("index.indexObjects",e,t)}function er(e,t,r,n){return l("index.queryLuaObjects",e,t,r,n)}function tr(e,t,r){return l("index.getObjectByRef",e,t,r)}function nr(){return l("index.ensureFullIndex")}var h=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[r,t])),y=e=>Object.keys(e),Ce={action:"ACTION",description:"DESCRIPTION",duration:"DURATION",repeat:"REPEAT",summary:"SUMMARY",trigger:"TRIGGER",attachments:"ATTACH",attendees:"ATTENDEE"},Me=h(Ce),Na=y(Me),wa=y(Ce),Re={method:"METHOD",prodId:"PRODID",version:"VERSION",name:"X-WR-CALNAME"},be=h(Re),Ia=y(be),La=y(Re),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=h(Oe),za=y(Ne),Ya=y(Oe),we={id:"TZID",lastModified:"LAST-MODIFIED",url:"TZURL"},Ie=h(we),Ka=y(Ie),ka=y(we),Le={comment:"COMMENT",name:"TZNAME",offsetFrom:"TZOFFSETFROM",offsetTo:"TZOFFSETTO",recurrenceDate:"RDATE",recurrenceRule:"RRULE",start:"DTSTART"},ze=h(Le),Ua=y(ze),Fa=y(Le),Ye={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"},Ke=h(Ye),Ba=y(Ke),Pa=y(Ye),ke={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"},Ue=h(ke),Va=y(Ue),_a=y(ke),Fe={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=h(Fe),$a=y(Be),Ha=y(Fe),Pe={stamp:"DTSTAMP",start:"DTSTART",uid:"UID",url:"URL",organizer:"ORGANIZER",attendees:"ATTENDEE",comment:"COMMENT",end:"DTEND",freeBusy:"FREEBUSY"},Ve=h(Pe),qa=y(Ve),Wa=y(Pe),_e="BEGIN",$e="END",rr="VCALENDAR",He="VTIMEZONE",or="STANDARD",ar="DAYLIGHT",qe="VEVENT",We="VALARM",je="VTODO",Ge="VJOURNAL",Je="VFREEBUSY";var ge=e=>new RegExp(`${_e}:${e}([\\s\\S]*?)${$e}:${e}`,"g"),ir=e=>new RegExp(`${_e}:${e}|${$e}:${e}`,"g");var ne=/\r\n|\r|\n/;var Te=` +`,sr=":",w=",",lr='"',re=";";var Se="=";var ur=Math.pow(10,8)*24*60*60*1e3,ja=-ur,cr=6048e5;var Ze=6e4,Qe=36e5,dr=3600,Xe=dr*24,Ga=Xe*7,pr=Xe*365.2425,vr=pr/12,Ja=vr*3,he=Symbol.for("constructDateFrom");function S(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&he in e?e[he](t):e instanceof Date?new e.constructor(t):new Date(t)}function d(e,t){return S(t||e,e)}function ae(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 et(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(),i=S(r?.in||e,n.getTime());i.setMonth(n.getMonth()+t+1,0);let a=i.getDate();return o>=a?i:(n.setFullYear(i.getFullYear(),i.getMonth(),o),n)}function q(e,t,r){return S(r?.in||e,+d(e)+t)}function mr(e,t,r){return q(e,t*Qe,r)}var fr={};function W(){return fr}function $(e,t){var r,n,o,i;let a=W(),s=t?.weekStartsOn??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.weekStartsOn)??a.weekStartsOn??((i=(o=a.locale)==null?void 0:o.options)==null?void 0:i.weekStartsOn)??0,u=d(e,t?.in),c=u.getDay(),v=(ctypeof n=="object"));return t.map(r)}function Er(e,t){let r=d(e,t?.in);return r.setHours(0,0,0,0),r}function tt(e,t,r){let n=d(e,r?.in);return n.setTime(n.getTime()+t*Ze),n}function gr(e,t,r){return q(e,t*1e3,r)}function ie(e,t,r){return ae(e,t*7,r)}function nt(e,t,r){return et(e,t*12,r)}function se(e,t){let r=+d(e)-+d(t);return r<0?-1:r>0?1:r}function Ae(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 Tr(e,t){let[r,n]=yr(e,t.start,t.end);return{start:r,end:n}}function Sr(e,t){let{start:r,end:n}=Tr(t?.in,e),o=+r>+n,i=o?+r:+n,a=o?n:r;a.setHours(0,0,0,0);let s=t?.step??1;if(!s)return[];s<0&&(s=-s,o=!o);let u=[];for(;+a<=i;)u.push(S(r,a)),a.setDate(a.getDate()+s),a.setHours(0,0,0,0);return o?u.reverse():u}function xe(e,t){let r=d(e,t?.in);return r.setDate(1),r.setHours(0,0,0,0),r}function hr(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 Ar(e,t){let r=d(e,t?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function xr(e,t){var r,n,o,i;let a=d(e,t?.in),s=a.getFullYear(),u=W(),c=t?.firstWeekContainsDate??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??u.firstWeekContainsDate??((i=(o=u.locale)==null?void 0:o.options)==null?void 0:i.firstWeekContainsDate)??1,v=S(t?.in||e,0);v.setFullYear(s+1,0,c),v.setHours(0,0,0,0);let g=$(v,t),f=S(t?.in||e,0);f.setFullYear(s,0,c),f.setHours(0,0,0,0);let A=$(f,t);return+a>=+g?s+1:+a>=+A?s:s-1}function Dr(e,t){var r,n,o,i;let a=W(),s=t?.firstWeekContainsDate??((n=(r=t?.locale)==null?void 0:r.options)==null?void 0:n.firstWeekContainsDate)??a.firstWeekContainsDate??((i=(o=a.locale)==null?void 0:o.options)==null?void 0:i.firstWeekContainsDate)??1,u=xr(e,t),c=S(t?.in||e,0);return c.setFullYear(u,0,s),c.setHours(0,0,0,0),$(c,t)}function Cr(e,t){let r=d(e,t?.in),n=+$(r,t)-+Dr(r,t);return Math.round(n/cr)+1}function _(e,t){return d(e,t?.in).getDay()}function rt(e,t){let r=d(e,t?.in),n=r.getFullYear(),o=r.getMonth(),i=S(r,0);return i.setFullYear(n,o+1,0),i.setHours(0,0,0,0),i.getDate()}function Mr(e,t){return d(e,t?.in).getHours()}function Rr(e,t){return d(e,t?.in).getMinutes()}function ot(e,t){return d(e,t?.in).getMonth()}function br(e){return d(e).getSeconds()}function Or(e,t){return d(e,t?.in).getFullYear()}function Nr(e,t){return+d(e)==+d(t)}function wr(e,t,r){let n=d(e,r?.in),o=Cr(n,r)-t;return n.setDate(n.getDate()-o*7),d(n,r?.in)}function H(e,t,r){var n,o,i,a;let s=W(),u=r?.weekStartsOn??((o=(n=r?.locale)==null?void 0:n.options)==null?void 0:o.weekStartsOn)??s.weekStartsOn??((a=(i=s.locale)==null?void 0:i.options)==null?void 0:a.weekStartsOn)??0,c=d(e,r?.in),v=c.getDay(),g=(t%7+7)%7,f=7-u,A=t<0||t>6?t-(v+f)%7:(g+f)%7-(v+f)%7;return ae(c,A,r)}function at(e,t,r){let n=+d(e,r?.in),[o,i]=[+d(t.start,r?.in),+d(t.end,r?.in)].sort((a,s)=>a-s);return n>=o&&n<=i}function Ir(e){let t=e/Qe;return Math.trunc(t)}function Lr(e){let t=e/Ze;return Math.trunc(t)}function zr(e,t,r){let n=d(e,r?.in),o=n.getFullYear(),i=n.getDate(),a=S(r?.in||e,0);a.setFullYear(o,t,15),a.setHours(0,0,0,0);let s=rt(a);return n.setMonth(t,Math.min(i,s)),n}function Yr(e,t,r){let n=d(e,r?.in);return n.setDate(t),n}function Kr(e,t,r){let n=d(e,r?.in);return n.setMonth(0),n.setDate(t),n}function kr(e,t,r){let n=d(e,r?.in);return n.setHours(t),n}function Ur(e,t,r){let n=d(e,r?.in);return n.setMinutes(t),n}function Fr(e,t,r){let n=d(e,r?.in);return n.setSeconds(t),n}function Br(e,t,r){return q(e,-t,r)}function Pr(e,t,r){return ie(e,-t,r)}var Vr=[or,ar];var _r=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"];var it=["SU","MO","TU","WE","TH","FR","SA"];var O=(e,t)=>t===void 0?!1:e>=t,$r=(e,{start:t,end:r},n)=>{if(O(n.length,e.count))return;let o=e.frequency,i=e.interval||1;if(!o)return;let a=t;if(o==="SECONDLY"){for(;a{let o=r.map(({day:i,occurrence:a})=>({occurrence:a,day:it.indexOf(i)}));return e.frequency==="YEARLY"?e.byYearday||e.byMonthday?t.map(i=>i.filter(a=>o.find(({day:s})=>s===_(a)))):e.byWeekNo?t.map(i=>i.flatMap(a=>o.map(({day:s})=>H(a,s,{weekStartsOn:n})))):e.byMonth?t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>te(D(xe(a)),D(Ae(a)),s,n,u)))):t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>te(D(Ar(a)),D(hr(a)),s,n,u)))):e.frequency==="MONTHLY"?e.byMonthday?t.map(i=>i.filter(a=>o.find(({day:s})=>s===_(a)))):t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>te(D(xe(a)),D(Ae(a)),s,n,u)))):e.frequency==="WEEKLY"?t.map(i=>i.flatMap(a=>o.map(({day:s})=>H(a,s,{weekStartsOn:n})))):t.map(i=>i.filter(a=>o.find(({day:s})=>s===_(a))))},te=(e,t,r,n,o)=>{if(o!==void 0){if(!(o<0)){let s=H(e,r,{weekStartsOn:n}),u=e>s;return ie(s,(o||1)-1+(u?1:0))}let i=H(t,r,{weekStartsOn:n}),a=tD(i)).filter(i=>at(i,{start:e,end:t})).filter(i=>r===_(i))},D=e=>tt(e,-e.getTimezoneOffset()),qr=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t.map(n=>n.flatMap(o=>r.map(i=>kr(o,i)))):t.map(n=>n.filter(o=>r.includes(Mr(o)))),Wr=(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(i=>Ur(o,i)))):t.map(n=>n.filter(o=>r.includes(Rr(o)))),jr=(e,t,r)=>e.frequency==="YEARLY"?t.map(n=>n.flatMap(o=>r.map(i=>zr(o,i)))):t.map(n=>n.filter(o=>r.includes(ot(o)))),Gr=(e,t,r)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"?t.map(n=>n.flatMap(o=>{let i=rt(o);return r.map(a=>a>i?void 0:Yr(o,a)).filter(a=>!!a)})):e.frequency==="WEEKLY"?t:t.map(n=>n.filter(o=>r.includes(ot(o)))),Jr=(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(i=>Fr(o,i)))):t.map(n=>n.filter(o=>r.includes(br(o)))),Zr=(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(se).filter((o,i)=>r.some(a=>a>0?i===0?!1:i%a===0:i===0?n.length-1+a===0:i%(n.length-1+a)===0))),Qr=(e,t,r,n)=>e.frequency==="YEARLY"?t.map(o=>o.flatMap(i=>r.map(a=>wr(i,a,{weekStartsOn:n})))):t,Xr=(e,t,r)=>e.frequency==="YEARLY"?t.map(n=>n.flatMap(o=>r.map(i=>Kr(o,i)))):e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t:t.map(n=>n.filter(o=>r.includes(Or(o)))),eo=(e,t,r)=>{let n=r;return e.byMonth&&(n=jr(e,n,e.byMonth)),e.byWeekNo&&(n=Qr(e,n,e.byWeekNo,t.weekStartsOn)),e.byYearday&&(n=Xr(e,n,e.byYearday)),e.byMonthday&&(n=Gr(e,n,e.byMonthday)),e.byDay&&(n=Hr(e,n,e.byDay,t.weekStartsOn)),e.byHour&&(n=qr(e,n,e.byHour)),e.byMinute&&(n=Wr(e,n,e.byMinute)),e.bySecond&&(n=Jr(e,n,e.bySecond)),e.bySetPos&&(n=Zr(e,n,e.bySetPos)),n.map(o=>o.sort(se).filter(i=>!(t.exceptions.length>0&&t.exceptions.some(a=>Nr(a,i))||!at(i,{start:t.start,end:t.end}))))},to=2,no=(e,t)=>{var r;let n=t.start,o=((r=e.until)==null?void 0:r.date)||t?.end||nt(n,to),i=t.exceptions||[],a=(e.workweekStart?it.indexOf(e.workweekStart):1)%7,s=[[n]];$r(e,{start:n,end:o},s);let u=eo(e,{start:n,end:o,exceptions:i,weekStartsOn:a},s);return e.count?u.flat().splice(0,e.count):u.flat()},ro=(e,t)=>t.flatMap(r=>!r.recurrenceRule||r.recurrenceRule.until&&r.recurrenceRule.until.date({...r,start:n}))),oe=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},oo=(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(i=>i.id===t);if(n){let i=ro(e,n.props).sort((u,c)=>se(u.start,c.start));for(let u=0;u5?c.substring(0,5):c;return{offset:v,milliseconds:oe(v)}}let a=i[i.length-1].offsetTo,s=a.length>5?a.substring(0,5):a;return{offset:s,milliseconds:oe(s)}}let o=oo(t,e);if(!Number.isNaN(o)){let i=o<0,a=Math.abs(Ir(o)),s=Math.abs(Lr(o))-a*60,u=a.toString().length===1?`0${a}`:a.toString(),c=s.toString().length===1?`0${s}`:s.toString();return{offset:`${i?"-":"+"}${u}${c}`,milliseconds:o}}};var 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},io=(e,t)=>{var r,n,o,i;let a=((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:(i=t.options)==null?void 0:i.FMTTYPE};return p(e,a)},N=e=>e.replace(/mailto:/gi,""),F=(e,t)=>{var r,n,o,i,a,s,u,c,v,g,f;return p(e,{email:N(t.value),delegatedFrom:(r=t.options)!=null&&r["DELEGATED-FROM"]?N((n=t.options)==null?void 0:n["DELEGATED-FROM"]):void 0,dir:(o=t.options)==null?void 0:o.DIR,member:(i=t.options)!=null&&i.MEMBER?N(t.options.MEMBER):void 0,name:(a=t.options)==null?void 0:a.CN,partstat:(s=t.options)==null?void 0:s.PARTSTAT,role:(u=t.options)==null?void 0:u.ROLE,sentBy:(c=t.options)!=null&&c["SENT-BY"]?N(t.options["SENT-BY"]):void 0,rsvp:(v=t.options)!=null&&v.RSVP?((g=t.options)==null?void 0:g.RSVP)==="TRUE"?!0:((f=t.options)==null?void 0:f.RSVP)==="FALSE"?!1:void 0:void 0})},B=(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"),i=o[0];if(i.includes("D")){let[s,u]=i.split("D");n.days=Number(s),i=u}if(i.includes("W")){let[s,u]=i.split("W");n.weeks=Number(s),i=u}let a=o[1];if(a){if(a.includes("H")){let[s,u]=a.split("H");n.hours=Number(s),a=u}if(a.includes("M")){let[s,u]=a.split("M");n.minutes=Number(s),a=u}if(a.includes("S")){let[s,u]=a.split("S");n.seconds=Number(s),a=u}}return p(e,n)},so=(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),i=new Date(Date.UTC(r,n,o));return p(e,i)},k=(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),i=Number.parseInt(t.value.slice(9,11),10),a=Number.parseInt(t.value.slice(11,13),10),s=Number.parseInt(t.value.slice(13,15),10),u=new Date(Date.UTC(r,n,o,i,a,s));return p(e,u)},lo=(e,t,r)=>{let n=oe(r),o=k(void 0,t),i=Br(o,n);return p(e,i)},uo=(e,t)=>{var r,n,o,i,a,s;if(((r=e.options)==null?void 0:r.VALUE)==="DATE")return{date:so(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=k(void 0,e);if(!((i=e.options)!=null&&i.TZID))return{date:c,type:u};let v=ao(c,e.options.TZID,t?.timezones);return v?{date:q(c,-v.milliseconds),type:u,local:(a=e.options)!=null&&a.TZID?{date:c,timezone:(s=e.options)==null?void 0:s.TZID,tzoffset:v.offset}:void 0}:{date:c,type:u}},m=(e,t,r)=>p(e,uo(t,r)),co=(e,t,r)=>{var n,o,i,a;let s=((n=t.options)==null?void 0:n.VALUE)==="DATE-TIME"||((o=t.options)==null?void 0:o.VALUE)==="DATE"?{type:"absolute",value:m(void 0,t,r),options:{related:(i=t.options)==null?void 0:i.RELATED}}:{type:"relative",value:B(void 0,t),options:{related:(a=t.options)==null?void 0:a.RELATED}};return p(e,s)},po=e=>e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e,st=e=>e.map(t=>{let[r,...n]=t.split(Se),o=n.join(Se);return{property:r,value:po(o)}},{}),vo=e=>e.reduce((t,r)=>(t[r.property]=r.value,t),{}),mo=e=>vo(st(e)),fo=e=>{let t=!1,r;for(let i=0;i{let{property:t,value:r}=fo(e);if(t.includes(re)){let[n,...o]=t.split(re),i=mo(o);return{property:n,line:{options:i,value:r}}}return{property:t,line:{value:r}}},De=e=>/^[ \t]/.test(e),Eo=e=>/^[A-Z]+(?:-[A-Z]+)*[:;]/.test(e),go=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!=="")},To=(e,t,r)=>{if(!t)return e;let n={};return Object.entries(t).forEach(([o,i])=>{let a=Object.entries(r||{}).find(([c,v])=>v.name===o);if(!a){n[So(o)]=i.value;return}let s=a[1].convert(i),u=a[1].schema;if(!u){n[a[0]]=s;return}n[a[0]]=p(u,s)}),e.nonStandard=n,e},So=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},ho=e=>e.startsWith("X-"),C=(e,t,r)=>{let n=t.replace(ir(r?.icsComponent),""),o=[...new Set(Object.values(r.childComponents||{}).flatMap(({icsComponent:g})=>g))],i=go(o.reduce((g,f)=>g.replace(ge(f),""),n)),a=r.defaultValues||{},s={};i.forEach(g=>{var f,A;let{property:M,line:R}=yo(g);ho(M)&&(s[M]=R);let E=r.objectKeyMap[M];if(!E)return;let I=(f=r.convertArrayValues)==null?void 0:f[E];if(I){let b=I({line:R});if(!b)return;(a[E]===void 0||a[E]===null||!Array.isArray(a[E]))&&(a[E]=[]),Array.isArray(b)?a[E].push(...b):a[E].push(b);return}let ve=(A=r.convertValues)==null?void 0:A[E];if(ve){let b=ve({line:R});if(!b)return;a[E]=b;return}a[E]=R.value});let u=r.childComponents,c=u?Object.keys(u||{}):[];u&&c.length>0&&c.forEach(g=>{let f=u?.[g];if(!f)return;let A=Array.isArray(f.icsComponent)?f.icsComponent:[f.icsComponent],M=[],R=[];A.forEach(E=>{R.push(...n.matchAll(ge(E)))}),R.map(E=>E[0]).forEach(E=>{let I=f.convert(E,{data:a});I&&M.push(I)}),M.length!==0&&(a[g]=M)});let v=p(e,a);return r!=null&&r.nonStandard?To(v,s,r?.nonStandard):v},j=(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"]?N(t.options["SENT-BY"]):void 0,email:N(t.value)})},le=(e,t,r)=>{var n;return p(e,{value:m(void 0,t,r),range:(n=t.options)==null?void 0:n.RANGE})},Ao=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,Ao(t.value)),Do=(e,t)=>p(e,t.value),Co=["until"],Mo=e=>Co.includes(e),Ro=["bySecond","byMinute","byHour","byMonthday","byYearday","byWeekNo","bySetPos"],bo=e=>Ro.includes(e),Oo=["byDay"],No=e=>Oo.includes(e),wo=["count","interval"],Io=e=>wo.includes(e),G=(e,t,r)=>{let n={};return st(t.value.split(re)).forEach(o=>{let{property:i,value:a}=o,s=Ke[i];if(s){if(Mo(s)){n[s]=m(void 0,{value:a,options:{VALUE:a.includes("T")?"DATE-TIME":"DATE"}},{timezones:r?.timezones});return}if(bo(s)){n[s]=a.split(w).map(u=>Number(u));return}if(s==="byMonth"){n[s]=a.split(w).map(u=>Number(u)-1);return}if(No(s)){n[s]=a.split(w).map(u=>xo(void 0,{value:u}));return}if(Io(s)){n[s]=Number(a);return}if(s==="frequency"){if(!a||!_r.includes(a))return;n[s]=a;return}if(s==="workweekStart"){n[s]=Do(void 0,{value:a});return}}}),p(e,n)},ue=(e,t)=>p(e,t.value),Lo=(e,t)=>p(e,t.value),ce=(e,t,r)=>p(e,t.value.split(",").map(n=>m(void 0,{value:n,options:t.options},r))),zo=(e,t)=>p(e,t.value),Yo=(e,t)=>p(e,t.value),Ko=(e,t)=>p(e,t.value),U=(e,t)=>p(e,Number.parseInt(t.value,10)),ko=e=>e.replace(/\\(([,;\\])|([nN]))/g,(t,r,n)=>n||` +`),T=(e,t)=>p(e,ko(t.value)),Uo=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:We,objectKeyMap:Me,convertValues:{trigger:({line:o})=>co(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>B(void 0,o),repeat:({line:o})=>U(void 0,o)},convertArrayValues:{attachments:({line:o})=>io(void 0,o),attendees:({line:o})=>F(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},Fo=(...e)=>{let[t,r,n]=e,o,i=C(t,r,{icsComponent:qe,objectKeyMap:Ne,convertValues:{stamp:({line:a})=>m(void 0,a,{timezones:n?.timezones}),start:({line:a})=>m(void 0,a,{timezones:n?.timezones}),end:({line:a})=>m(void 0,a,{timezones:n?.timezones}),created:({line:a})=>m(void 0,a,{timezones:n?.timezones}),lastModified:({line:a})=>m(void 0,a,{timezones:n?.timezones}),categories:({line:a})=>a.value.split(w),description:({line:a})=>{var s;return(s=a.options)!=null&&s.ALTREP&&(o=a.options.ALTREP),T(void 0,a)},location:({line:a})=>T(void 0,a),comment:({line:a})=>T(void 0,a),summary:({line:a})=>T(void 0,a),recurrenceRule:({line:a})=>G(void 0,a,{timezones:n?.timezones}),duration:({line:a})=>B(void 0,a),organizer:({line:a})=>j(void 0,a),sequence:({line:a})=>U(void 0,a),class:({line:a})=>ue(void 0,a),recurrenceId:({line:a})=>le(void 0,a,{timezones:n?.timezones}),status:({line:a})=>zo(void 0,a),timeTransparent:({line:a})=>Lo(void 0,a)},convertArrayValues:{attendees:({line:a})=>F(void 0,a),exceptionDates:({line:a})=>ce(void 0,a,{timezones:n?.timezones})},childComponents:{alarms:{icsComponent:We,convert:a=>Uo(void 0,a,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},timezones:n?.timezones,nonStandard:n?.nonStandard});return o&&(i.descriptionAltRep=o),i},Bo=(...e)=>{let[t,r,n]=e,o=r.split("BEGIN:")[1].split(ne)[0],i=Vr.includes(o)?o:"STANDARD",a=r.split("TZOFFSETTO:")[1].split(ne)[0];return C(t,r,{icsComponent:i,objectKeyMap:ze,defaultValues:{type:i},convertValues:{start:({line:s})=>lo(void 0,s,a),recurrenceRule:({line:s})=>G(void 0,s,{timezones:n?.timezones}),recurrenceDate:({line:s})=>m(void 0,s,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},Po=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:He,objectKeyMap:Ie,convertValues:{lastModified:({line:o})=>k(void 0,o)},childComponents:{props:{icsComponent:["DAYLIGHT","STANDARD"],convert:o=>Bo(void 0,o,{nonStandard:n?.nonStandard,timezones:n?.timezones})}},nonStandard:n?.nonStandard,timezones:n?.timezones})},Vo=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:je,objectKeyMap:Ue,convertValues:{stamp:({line:o})=>m(void 0,o,{timezones:n?.timezones}),start:({line:o})=>m(void 0,o,{timezones:n?.timezones}),due:({line:o})=>m(void 0,o,{timezones:n?.timezones}),created:({line:o})=>m(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>m(void 0,o,{timezones:n?.timezones}),completed:({line:o})=>m(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(w),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})=>B(void 0,o),organizer:({line:o})=>j(void 0,o),sequence:({line:o})=>U(void 0,o),percentComplete:({line:o})=>U(void 0,o),class:({line:o})=>ue(void 0,o),recurrenceId:({line:o})=>le(void 0,o,{timezones:n?.timezones}),status:({line:o})=>Yo(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),exceptionDates:({line:o})=>ce(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},_o=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:Ge,objectKeyMap:Be,convertValues:{stamp:({line:o})=>m(void 0,o,{timezones:n?.timezones}),start:({line:o})=>m(void 0,o,{timezones:n?.timezones}),created:({line:o})=>m(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>m(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(w),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})=>j(void 0,o),sequence:({line:o})=>U(void 0,o),class:({line:o})=>ue(void 0,o),recurrenceId:({line:o})=>le(void 0,o,{timezones:n?.timezones}),status:({line:o})=>Ko(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),exceptionDates:({line:o})=>ce(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},$o=(e,t)=>{var r;return p(e,{type:(r=t.options)==null?void 0:r.FBTYPE,values:t.value.split(",").map(n=>{let[o,i]=n.split("/"),a=k(void 0,{value:o});if(i.startsWith("PT")){let u=B(void 0,{value:i});return{start:a,duration:u}}let s=k(void 0,{value:i});return{start:a,end:s}})})},Ho=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:Je,objectKeyMap:Ve,convertValues:{stamp:({line:o})=>m(void 0,o,{timezones:n?.timezones}),start:({line:o})=>m(void 0,o,{timezones:n?.timezones}),end:({line:o})=>m(void 0,o,{timezones:n?.timezones}),comment:({line:o})=>T(void 0,o),organizer:({line:o})=>j(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),freeBusy:({line:o})=>$o(void 0,o)},nonStandard:n?.nonStandard,timezones:n?.timezones})},lt=(...e)=>{let[t,r,n]=e;return C(t,r,{icsComponent:rr,objectKeyMap:be,convertValues:{version:({line:o})=>o.value},childComponents:{timezones:{icsComponent:He,convert:o=>Po(void 0,o,{nonStandard:n?.nonStandard})},events:{icsComponent:qe,convert:(o,{data:i})=>Fo(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},todos:{icsComponent:je,convert:(o,{data:i})=>Vo(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},journals:{icsComponent:Ge,convert:(o,{data:i})=>_o(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})},freeBusy:{icsComponent:Je,convert:(o,{data:i})=>Ho(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})}},nonStandard:n?.nonStandard})};var ut="0.2.12",qo="icalendar:lastSync";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};console.log(`[iCalendar] Plug loading (Version ${ut})...`);function jo(e,t=0){let r=e.local&&typeof e.local.date=="string"?e.local.date:typeof e.date=="string"?e.date:"";if(!r)return"";let n=new Date(r.replace("Z","")+"Z"),o=e.local?.timezone||e.timezone||"UTC",i=Wo[o]||0,a=n.getTime()-i*36e5;t!==0&&(a+=t*36e5);let s=new Date(a),u=c=>String(c).padStart(2,"0");return s.getFullYear()+"-"+u(s.getMonth()+1)+"-"+u(s.getDate())+"T"+u(s.getHours())+":"+u(s.getMinutes())+":"+u(s.getSeconds())+"."+String(s.getMilliseconds()).padStart(3,"0")}function Go(e){return e&&typeof e=="object"&&"date"in e&&"type"in e}async function Jo(e){let r=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")}function de(e,t=0){if(e==null)return e;if(Go(e))return jo(e,t);if(e instanceof Date){let r=new Date(e.getTime()+t*36e5),n=o=>String(o).padStart(2,"0");return r.getFullYear()+"-"+n(r.getMonth()+1)+"-"+n(r.getDate())+"T"+n(r.getHours())+":"+n(r.getMinutes())+":"+n(r.getSeconds())+".000"}if(Array.isArray(e))return e.map(r=>de(r,t));if(typeof e=="object"){let r={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=de(e[n],t));return r}return e}async function Zo(){let e=await K.get("icalendar",{sources:[]});if(!e.sources)return[];let t=e.sources;return Array.isArray(t)||(t=[t]),t.filter(r=>typeof r.url=="string")}async function Qo(e,t=0){let r=e.url.trim();r.includes(" ")&&(r=encodeURI(r));let n=await fetch(r,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}});if(!n.ok)throw new Error(`HTTP ${n.status}`);let o=await n.text(),i=lt(void 0,o);return i.events?await Promise.all(i.events.map(async a=>{let s=`${a.start?.date||""}${a.uid||a.summary||""}`,u=await Jo(s);return de({...a,ref:u,tag:"ical-event",sourceName:e.name},t)})):[]}async function pe(){try{let t=(await K.get("icalendar",{sources:[]})).tzShift??0,r=await Zo();if(r.length===0)return;await x.flashNotification("Syncing calendars...","info");let n=[];for(let o of r)try{let i=await Qo(o,t);n.push(...i)}catch(i){console.error(`[iCalendar] Failed to sync ${o.name}:`,i)}await V.indexObjects("$icalendar",n),await x.flashNotification(`Synced ${n.length} events`,"info")}catch(e){console.error("[iCalendar] Sync failed:",e)}}async function ct(){await P.del(qo),await pe()}async function dt(){if(!await x.confirm("Clear all calendar events?"))return;let e=await Y.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 Y.batchDel(t),await x.flashNotification("Calendar index cleared","info")}async function pt(){await x.flashNotification(`iCalendar Plug ${ut}`,"info")}var vt={syncCalendars:pe,forceSync:ct,clearCache:dt,showVersion:pt},mt={name:"icalendar",requiredPermissions:["fetch"],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}}},config:{"schema.config.properties.icalendar":{type:"object",required:["sources"],properties:{sources:{type:"array",minItems:1,items:{type:"object",required:["url"],properties:{url:{type:"string"},name:{type:"string"}}}},cacheDuration:{type:"number",description:"Interval between two calendar synchronizations (default: 21600 = 6 hours)"}}}},assets:{}},ii={manifest:mt,functionMapping:vt};Ee(vt,mt,self.postMessage);export{ii as plug}; //# sourceMappingURL=icalendar.plug.js.map