Files
silverbullet-icalendar/icalendar.plug.js
sstent 7d690cdb2a
All checks were successful
Build SilverBullet Plug / build (push) Successful in 25s
Fix: Final verified build v0.3.13 with explicit naming and mapping
2026-02-17 14:48:51 -08:00

5 lines
37 KiB
JavaScript

var ft=Object.defineProperty;var I=(e,t)=>{for(var n in t)ft(e,n,{get:t[n],enumerable:!0})};function pe(e){let t=atob(e),n=t.length,r=new Uint8Array(n);for(let o=0;o<n;o++)r[o]=t.charCodeAt(o);return r}function J(e){typeof e=="string"&&(e=new TextEncoder().encode(e));let t="",n=e.byteLength;for(let r=0;r<n;r++)t+=String.fromCharCode(e[r]);return btoa(t)}var Jo=new Uint8Array(16);var Z=class{constructor(t="",n=1e3){this.prefix=t;this.maxCaptureSize=n;this.prefix=t,this.originalConsole={log:console.log.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),debug:console.debug.bind(console)},this.patchConsole()}originalConsole;logBuffer=[];patchConsole(){let t=n=>(...r)=>{let o=this.prefix?[this.prefix,...r]:r;this.originalConsole[n](...o),this.captureLog(n,r)};console.log=t("log"),console.info=t("info"),console.warn=t("warn"),console.error=t("error"),console.debug=t("debug")}captureLog(t,n){let r={level:t,timestamp:Date.now(),message:n.map(o=>{if(typeof o=="string")return o;try{return JSON.stringify(o)}catch{return String(o)}}).join(" ")};this.logBuffer.push(r),this.logBuffer.length>this.maxCaptureSize&&this.logBuffer.shift()}async postToServer(t,n){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:n})))})).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)}}}},ye;function fe(e=""){return ye=new Z(e),ye}var L=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((n,r)=>{Q++,X.set(Q,{resolve:n,reject:r}),L({type:"sys",id:Q,name:e,args:t})}));function ge(e,t,n){ee&&(L=n,self.addEventListener("message",r=>{(async()=>{let o=r.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=X.get(s);if(!i)throw Error("Invalid request id");X.delete(s),o.error?i.reject(new Error(o.error)):i.resolve(o.result)}break}})().catch(console.error)}),L({type:"manifest",manifest:t}),fe(`[${t.name} plug]`))}async function gt(e,t){if(typeof e!="string"){let n=new Uint8Array(await e.arrayBuffer()),r=n.length>0?J(n):void 0;t={method:e.method,headers:Object.fromEntries(e.headers.entries()),base64Body:r},e=e.url}return syscall("sandboxFetch.fetch",e,t)}globalThis.nativeFetch=globalThis.fetch;function vt(){globalThis.fetch=async function(e,t){let n=t&&t.body?J(new Uint8Array(await new Response(t.body).arrayBuffer())):void 0,r=await gt(e,t&&{method:t.method,headers:t.headers,base64Body:n});return new Response(r.base64Body?pe(r.base64Body):null,{status:r.status,headers:r.headers})}}ee&&vt();var b={};I(b,{alert:()=>tr,configureVimMode:()=>Er,confirm:()=>er,copyToClipboard:()=>mr,deleteLine:()=>pr,dispatch:()=>Qt,downloadFile:()=>kt,filterBox:()=>_t,flashNotification:()=>Vt,fold:()=>or,foldAll:()=>ar,getCurrentEditor:()=>At,getCurrentPage:()=>Et,getCurrentPageMeta:()=>Tt,getCurrentPath:()=>St,getCursor:()=>bt,getRecentlyOpenedPages:()=>ht,getSelection:()=>xt,getText:()=>Ct,getUiOption:()=>rr,goHistory:()=>Ft,hidePanel:()=>jt,insertAtCursor:()=>Zt,insertAtPos:()=>qt,invokeCommand:()=>Dt,isMobile:()=>Sr,moveCursor:()=>Gt,moveCursorToLine:()=>Jt,moveLineDown:()=>gr,moveLineUp:()=>fr,navigate:()=>Ot,newWindow:()=>Ut,openCommandPalette:()=>wt,openPageNavigator:()=>Nt,openSearchPanel:()=>dr,openUrl:()=>Yt,prompt:()=>Xt,rebuildEditorState:()=>Kt,redo:()=>cr,reloadConfigAndCommands:()=>zt,reloadPage:()=>It,reloadUI:()=>Lt,replaceRange:()=>Wt,save:()=>Rt,sendMessage:()=>Tr,setSelection:()=>Mt,setText:()=>Pt,setUiOption:()=>nr,showPanel:()=>$t,showProgress:()=>Ht,toggleComment:()=>yr,toggleFold:()=>sr,undo:()=>ur,unfold:()=>ir,unfoldAll:()=>lr,uploadFile:()=>Bt,vimEx:()=>vr});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function l(e,...t){return globalThis.syscall(e,...t)}function Et(){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 Ct(){return l("editor.getText")}function Pt(e,t=!1){return l("editor.setText",e,t)}function bt(){return l("editor.getCursor")}function xt(){return l("editor.getSelection")}function Mt(e,t){return l("editor.setSelection",e,t)}function Dt(e,t){return l("editor.invokeCommand",e,t)}function Rt(){return l("editor.save")}function Ot(e,t=!1,n=!1){return l("editor.navigate",e,t,n)}function Nt(e="page"){return l("editor.openPageNavigator",e)}function wt(){return l("editor.openCommandPalette")}function It(){return l("editor.reloadPage")}function Lt(){return l("editor.reloadUI")}function Kt(){return l("editor.rebuildEditorState")}function zt(){return l("editor.reloadConfigAndCommands")}function Yt(e,t=!1){return l("editor.openUrl",e,t)}function Ut(){return l("editor.newWindow")}function Ft(e){return l("editor.goHistory",e)}function kt(e,t){return l("editor.downloadFile",e,t)}function Bt(e,t){return l("editor.uploadFile",e,t)}function Vt(e,t="info"){return l("editor.flashNotification",e,t)}function _t(e,t,n="",r=""){return l("editor.filterBox",e,t,n,r)}function $t(e,t,n,r=""){return l("editor.showPanel",e,t,n,r)}function jt(e){return l("editor.hidePanel",e)}function Ht(e,t){return l("editor.showProgress",e,t)}function qt(e,t){return l("editor.insertAtPos",e,t)}function Wt(e,t,n){return l("editor.replaceRange",e,t,n)}function Gt(e,t=!1){return l("editor.moveCursor",e,t)}function Jt(e,t=1,n=!1){return l("editor.moveCursorToLine",e,t,n)}function Zt(e,t=!1,n=!1){return l("editor.insertAtCursor",e,t,n)}function Qt(e){return l("editor.dispatch",e)}function Xt(e,t=""){return l("editor.prompt",e,t)}function er(e){return l("editor.confirm",e)}function tr(e){return l("editor.alert",e)}function rr(e){return l("editor.getUiOption",e)}function nr(e,t){return l("editor.setUiOption",e,t)}function or(){return l("editor.fold")}function ir(){return l("editor.unfold")}function sr(){return l("editor.toggleFold")}function ar(){return l("editor.foldAll")}function lr(){return l("editor.unfoldAll")}function ur(){return l("editor.undo")}function cr(){return l("editor.redo")}function dr(){return l("editor.openSearchPanel")}function mr(e){return l("editor.copyToClipboard",e)}function pr(){return l("editor.deleteLine")}function yr(){return l("editor.toggleComment")}function fr(){return l("editor.moveLineUp")}function gr(){return l("editor.moveLineDown")}function vr(e){return l("editor.vimEx",e)}function Er(){return l("editor.configureVimMode")}function Tr(e,t){return l("editor.sendMessage",e,t)}function Sr(){return l("editor.isMobile")}var K={};I(K,{del:()=>xr,get:()=>br,set:()=>Pr});function Pr(e,t){return l("clientStore.set",e,t)}function br(e){return l("clientStore.get",e)}function xr(e){return l("clientStore.delete",e)}var di=new Uint8Array(16);var z={};I(z,{batchDel:()=>Fr,batchDeletePrefix:()=>Vr,batchGet:()=>Yr,batchSet:()=>Kr,del:()=>Ur,get:()=>zr,listFunctions:()=>$r,query:()=>kr,queryDelete:()=>_r,queryLua:()=>Br,set:()=>Lr});function Lr(e,t){return l("datastore.set",e,t)}function Kr(e){return l("datastore.batchSet",e)}function zr(e){return l("datastore.get",e)}function Yr(e){return l("datastore.batchGet",e)}function Ur(e){return l("datastore.delete",e)}function Fr(e){return l("datastore.batchDelete",e)}function kr(e){return l("datastore.query",e)}function Br(e,t,n){return l("datastore.queryLua",e,t,n)}function Vr(e){return l("datastore.batchDeletePrefix",e)}function _r(e,t){return l("datastore.queryDelete",e,t)}function $r(){return l("datastore.listFunctions")}var B={};I(B,{define:()=>Zr,get:()=>qr,has:()=>Jr,insert:()=>Gr,set:()=>Wr});function qr(e,t){return l("config.get",e,t)}function Wr(e,t){return l("config.set",e,t)}function Gr(e,t){return l("config.insert",e,t)}function Jr(e){return l("config.has",e)}function Zr(e,t){return l("config.define",e,t)}var V={};I(V,{ensureFullIndex:()=>tn,getObjectByRef:()=>en,indexObjects:()=>Qr,queryLuaObjects:()=>Xr});function Qr(e,t){return l("index.indexObjects",e,t)}function Xr(e,t,n,r){return l("index.queryLuaObjects",e,t,n,r)}function en(e,t,n){return l("index.getObjectByRef",e,t,n)}function tn(){return l("index.ensureFullIndex")}var P=e=>Object.fromEntries(Object.entries(e).map(([t,n])=>[n,t])),v=e=>Object.keys(e),Pe={action:"ACTION",description:"DESCRIPTION",duration:"DURATION",repeat:"REPEAT",summary:"SUMMARY",trigger:"TRIGGER",attachments:"ATTACH",attendees:"ATTENDEE"},be=P(Pe),xi=v(be),Mi=v(Pe),xe={method:"METHOD",prodId:"PRODID",version:"VERSION",name:"X-WR-CALNAME"},Me=P(xe),Di=v(Me),Ri=v(xe),De={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"},Re=P(De),Oi=v(Re),Ni=v(De),Oe={id:"TZID",lastModified:"LAST-MODIFIED",url:"TZURL"},Ne=P(Oe),wi=v(Ne),Ii=v(Oe),we={comment:"COMMENT",name:"TZNAME",offsetFrom:"TZOFFSETFROM",offsetTo:"TZOFFSETTO",recurrenceDate:"RDATE",recurrenceRule:"RRULE",start:"DTSTART"},Ie=P(we),Li=v(Ie),Ki=v(we),Le={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=P(Le),zi=v(Ke),Yi=v(Le),ze={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"},Ye=P(ze),Ui=v(Ye),Fi=v(ze),Ue={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"},Fe=P(Ue),ki=v(Fe),Bi=v(Ue),ke={stamp:"DTSTAMP",start:"DTSTART",uid:"UID",url:"URL",organizer:"ORGANIZER",attendees:"ATTENDEE",comment:"COMMENT",end:"DTEND",freeBusy:"FREEBUSY"},Be=P(ke),Vi=v(Be),_i=v(ke),Ve="BEGIN",_e="END",rn="VCALENDAR",$e="VTIMEZONE",nn="STANDARD",on="DAYLIGHT",je="VEVENT",He="VALARM",qe="VTODO",We="VJOURNAL",Ge="VFREEBUSY";var ve=e=>new RegExp(`${Ve}:${e}([\\s\\S]*?)${_e}:${e}`,"g"),sn=e=>new RegExp(`${Ve}:${e}|${_e}:${e}`,"g");var re=/\r\n|\r|\n/;var Ee=`
`,an=":",N=",",ln='"',ne=";";var Te="=";var un=Math.pow(10,8)*24*60*60*1e3,$i=-un,cn=6048e5;var Je=6e4,Ze=36e5,dn=3600,Qe=dn*24,ji=Qe*7,mn=Qe*365.2425,pn=mn/12,Hi=pn*3,Se=Symbol.for("constructDateFrom");function A(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Se in e?e[Se](t):e instanceof Date?new e.constructor(t):new Date(t)}function d(e,t){return A(t||e,e)}function ie(e,t,n){let r=d(e,n?.in);return isNaN(t)?A(n?.in||e,NaN):(t&&r.setDate(r.getDate()+t),r)}function Xe(e,t,n){let r=d(e,n?.in);if(isNaN(t))return A(n?.in||e,NaN);if(!t)return r;let o=r.getDate(),s=A(n?.in||e,r.getTime());s.setMonth(r.getMonth()+t+1,0);let i=s.getDate();return o>=i?s:(r.setFullYear(s.getFullYear(),s.getMonth(),o),r)}function H(e,t,n){return A(n?.in||e,+d(e)+t)}function yn(e,t,n){return H(e,t*Ze,n)}var fn={};function q(){return fn}function $(e,t){var n,r,o,s;let i=q(),a=t?.weekStartsOn??((r=(n=t?.locale)==null?void 0:n.options)==null?void 0:r.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=(c<a?7:0)+c-a;return u.setDate(u.getDate()-m),u.setHours(0,0,0,0),u}function gn(e,...t){let n=A.bind(null,e||t.find(r=>typeof r=="object"));return t.map(n)}function vn(e,t){let n=d(e,t?.in);return n.setHours(0,0,0,0),n}function et(e,t,n){let r=d(e,n?.in);return r.setTime(r.getTime()+t*Je),r}function En(e,t,n){return H(e,t*1e3,n)}function se(e,t,n){return ie(e,t*7,n)}function tt(e,t,n){return Xe(e,t*12,n)}function ae(e,t){let n=+d(e)-+d(t);return n<0?-1:n>0?1:n}function he(e,t){let n=d(e,t?.in),r=n.getMonth();return n.setFullYear(n.getFullYear(),r+1,0),n.setHours(23,59,59,999),n}function Tn(e,t){let[n,r]=gn(e,t.start,t.end);return{start:n,end:r}}function Sn(e,t){let{start:n,end:r}=Tn(t?.in,e),o=+n>+r,s=o?+n:+r,i=o?r:n;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(A(n,i)),i.setDate(i.getDate()+a),i.setHours(0,0,0,0);return o?u.reverse():u}function Ae(e,t){let n=d(e,t?.in);return n.setDate(1),n.setHours(0,0,0,0),n}function hn(e,t){let n=d(e,t?.in),r=n.getFullYear();return n.setFullYear(r+1,0,0),n.setHours(23,59,59,999),n}function An(e,t){let n=d(e,t?.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}function Cn(e,t){var n,r,o,s;let i=d(e,t?.in),a=i.getFullYear(),u=q(),c=t?.firstWeekContainsDate??((r=(n=t?.locale)==null?void 0:n.options)==null?void 0:r.firstWeekContainsDate)??u.firstWeekContainsDate??((s=(o=u.locale)==null?void 0:o.options)==null?void 0:s.firstWeekContainsDate)??1,m=A(t?.in||e,0);m.setFullYear(a+1,0,c),m.setHours(0,0,0,0);let E=$(m,t),y=A(t?.in||e,0);y.setFullYear(a,0,c),y.setHours(0,0,0,0);let T=$(y,t);return+i>=+E?a+1:+i>=+T?a:a-1}function Pn(e,t){var n,r,o,s;let i=q(),a=t?.firstWeekContainsDate??((r=(n=t?.locale)==null?void 0:n.options)==null?void 0:r.firstWeekContainsDate)??i.firstWeekContainsDate??((s=(o=i.locale)==null?void 0:o.options)==null?void 0:s.firstWeekContainsDate)??1,u=Cn(e,t),c=A(t?.in||e,0);return c.setFullYear(u,0,a),c.setHours(0,0,0,0),$(c,t)}function bn(e,t){let n=d(e,t?.in),r=+$(n,t)-+Pn(n,t);return Math.round(r/cn)+1}function _(e,t){return d(e,t?.in).getDay()}function rt(e,t){let n=d(e,t?.in),r=n.getFullYear(),o=n.getMonth(),s=A(n,0);return s.setFullYear(r,o+1,0),s.setHours(0,0,0,0),s.getDate()}function xn(e,t){return d(e,t?.in).getHours()}function Mn(e,t){return d(e,t?.in).getMinutes()}function nt(e,t){return d(e,t?.in).getMonth()}function Dn(e){return d(e).getSeconds()}function Rn(e,t){return d(e,t?.in).getFullYear()}function On(e,t){return+d(e)==+d(t)}function Nn(e,t,n){let r=d(e,n?.in),o=bn(r,n)-t;return r.setDate(r.getDate()-o*7),d(r,n?.in)}function j(e,t,n){var r,o,s,i;let a=q(),u=n?.weekStartsOn??((o=(r=n?.locale)==null?void 0:r.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,n?.in),m=c.getDay(),E=(t%7+7)%7,y=7-u,T=t<0||t>6?t-(m+y)%7:(E+y)%7-(m+y)%7;return ie(c,T,n)}function ot(e,t,n){let r=+d(e,n?.in),[o,s]=[+d(t.start,n?.in),+d(t.end,n?.in)].sort((i,a)=>i-a);return r>=o&&r<=s}function wn(e){let t=e/Ze;return Math.trunc(t)}function In(e){let t=e/Je;return Math.trunc(t)}function Ln(e,t,n){let r=d(e,n?.in),o=r.getFullYear(),s=r.getDate(),i=A(n?.in||e,0);i.setFullYear(o,t,15),i.setHours(0,0,0,0);let a=rt(i);return r.setMonth(t,Math.min(s,a)),r}function Kn(e,t,n){let r=d(e,n?.in);return r.setDate(t),r}function zn(e,t,n){let r=d(e,n?.in);return r.setMonth(0),r.setDate(t),r}function Yn(e,t,n){let r=d(e,n?.in);return r.setHours(t),r}function Un(e,t,n){let r=d(e,n?.in);return r.setMinutes(t),r}function Fn(e,t,n){let r=d(e,n?.in);return r.setSeconds(t),r}function kn(e,t,n){return H(e,-t,n)}function Bn(e,t,n){return se(e,-t,n)}var Vn=[nn,on];var _n=["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"];var it=["SU","MO","TU","WE","TH","FR","SA"];var R=(e,t)=>t===void 0?!1:e>=t,$n=(e,{start:t,end:n},r)=>{if(R(r.length,e.count))return;let o=e.frequency,s=e.interval||1;if(!o)return;let i=t;if(o==="SECONDLY"){for(;i<n;){if(R(r.length,e.count))return;i=En(i,s),r.push([i])}return}if(o==="MINUTELY"){for(;i<n;){if(R(r.length,e.count))return;i=et(i,s),r.push([i])}return}if(o==="HOURLY"){for(;i<n;){if(R(r.length,e.count))return;i=yn(i,s),r.push([i])}return}if(o==="DAILY"){for(;i<n;){if(R(r.length,e.count))return;i=ie(i,s),r.push([i])}return}if(o==="WEEKLY"){for(;i<n;){if(R(r.length,e.count))return;i=se(i,s),r.push([i])}return}if(o==="MONTHLY"){for(;i<n;)i=Xe(i,s),r.push([i]);return}if(o==="YEARLY"){for(;i<n;)i=tt(i,s),r.push([i]);return}},jn=(e,t,n,r)=>{let o=n.map(({day:s,occurrence:i})=>({occurrence:i,day:it.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})=>j(i,a,{weekStartsOn:r})))):e.byMonth?t.map(s=>s.flatMap(i=>o.flatMap(({day:a,occurrence:u})=>te(x(Ae(i)),x(he(i)),a,r,u)))):t.map(s=>s.flatMap(i=>o.flatMap(({day:a,occurrence:u})=>te(x(An(i)),x(hn(i)),a,r,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})=>te(x(Ae(i)),x(he(i)),a,r,u)))):e.frequency==="WEEKLY"?t.map(s=>s.flatMap(i=>o.map(({day:a})=>j(i,a,{weekStartsOn:r})))):t.map(s=>s.filter(i=>o.find(({day:a})=>a===_(i))))},te=(e,t,n,r,o)=>{if(o!==void 0){if(!(o<0)){let a=j(e,n,{weekStartsOn:r}),u=e>a;return se(a,(o||1)-1+(u?1:0))}let s=j(t,n,{weekStartsOn:r}),i=t<s;return x(vn(Bn(s,-(o||1)-1+(i?1:0))))}return Sn({start:e,end:t}).map(s=>x(s)).filter(s=>ot(s,{start:e,end:t})).filter(s=>n===_(s))},x=e=>et(e,-e.getTimezoneOffset()),Hn=(e,t,n)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t.map(r=>r.flatMap(o=>n.map(s=>Yn(o,s)))):t.map(r=>r.filter(o=>n.includes(xn(o)))),qn=(e,t,n)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"||e.frequency==="HOURLY"?t.map(r=>r.flatMap(o=>n.map(s=>Un(o,s)))):t.map(r=>r.filter(o=>n.includes(Mn(o)))),Wn=(e,t,n)=>e.frequency==="YEARLY"?t.map(r=>r.flatMap(o=>n.map(s=>Ln(o,s)))):t.map(r=>r.filter(o=>n.includes(nt(o)))),Gn=(e,t,n)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"?t.map(r=>r.flatMap(o=>{let s=rt(o);return n.map(i=>i>s?void 0:Kn(o,i)).filter(i=>!!i)})):e.frequency==="WEEKLY"?t:t.map(r=>r.filter(o=>n.includes(nt(o)))),Jn=(e,t,n)=>e.frequency==="YEARLY"||e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"||e.frequency==="HOURLY"||e.frequency==="MINUTELY"?t.map(r=>r.flatMap(o=>n.map(s=>Fn(o,s)))):t.map(r=>r.filter(o=>n.includes(Dn(o)))),Zn=(e,t,n)=>!e.byYearday&&!e.byWeekNo&&!e.byMonthday&&!e.byMonth&&!e.byDay&&!e.byHour&&!e.byMinute&&!e.bySecond?t:t.map(r=>r.sort(ae).filter((o,s)=>n.some(i=>i>0?s===0?!1:s%i===0:s===0?r.length-1+i===0:s%(r.length-1+i)===0))),Qn=(e,t,n,r)=>e.frequency==="YEARLY"?t.map(o=>o.flatMap(s=>n.map(i=>Nn(s,i,{weekStartsOn:r})))):t,Xn=(e,t,n)=>e.frequency==="YEARLY"?t.map(r=>r.flatMap(o=>n.map(s=>zn(o,s)))):e.frequency==="MONTHLY"||e.frequency==="WEEKLY"||e.frequency==="DAILY"?t:t.map(r=>r.filter(o=>n.includes(Rn(o)))),eo=(e,t,n)=>{let r=n;return e.byMonth&&(r=Wn(e,r,e.byMonth)),e.byWeekNo&&(r=Qn(e,r,e.byWeekNo,t.weekStartsOn)),e.byYearday&&(r=Xn(e,r,e.byYearday)),e.byMonthday&&(r=Gn(e,r,e.byMonthday)),e.byDay&&(r=jn(e,r,e.byDay,t.weekStartsOn)),e.byHour&&(r=Hn(e,r,e.byHour)),e.byMinute&&(r=qn(e,r,e.byMinute)),e.bySecond&&(r=Jn(e,r,e.bySecond)),e.bySetPos&&(r=Zn(e,r,e.bySetPos)),r.map(o=>o.sort(ae).filter(s=>!(t.exceptions.length>0&&t.exceptions.some(i=>On(i,s))||!ot(s,{start:t.start,end:t.end}))))},to=2,ro=(e,t)=>{var n;let r=t.start,o=((n=e.until)==null?void 0:n.date)||t?.end||tt(r,to),s=t.exceptions||[],i=(e.workweekStart?it.indexOf(e.workweekStart):1)%7,a=[[r]];$n(e,{start:r,end:o},a);let u=eo(e,{start:r,end:o,exceptions:s,weekStartsOn:i},a);return e.count?u.flat().splice(0,e.count):u.flat()},no=(e,t)=>t.flatMap(n=>!n.recurrenceRule||n.recurrenceRule.until&&n.recurrenceRule.until.date<e?n:ro(n.recurrenceRule,{start:n.start,end:e}).map(r=>({...n,start:r}))),oe=e=>{let t=e[0]==="+"?1:-1,n=Number(e.slice(1,3)),r=e.length>3?Number(e.slice(3,5)):0,o=e.length>5?Number(e.slice(5,7)):0;return((n*60+r)*60+o)*1e3*t},oo=(e,t)=>{let n="en-US",r=new Date(t.toLocaleString(n,{timeZone:"UTC"}));try{return new Date(t.toLocaleString(n,{timeZone:e})).getTime()-r.getTime()}catch{return t.getTime()-r.getTime()}},io=(e,t,n)=>{let r=n?.find(s=>s.id===t);if(r){let s=no(e,r.props).sort((u,c)=>ae(u.start,c.start));for(let u=0;u<s.length;u+=1)if(e<s[u].start){let c=s[u-1]?s[u-1].offsetTo:s[u].offsetFrom,m=c.length>5?c.substring(0,5):c;return{offset:m,milliseconds:oe(m)}}let i=s[s.length-1].offsetTo,a=i.length>5?i.substring(0,5):i;return{offset:a,milliseconds:oe(a)}}let o=oo(t,e);if(!Number.isNaN(o)){let s=o<0,i=Math.abs(wn(o)),a=Math.abs(In(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 n=e["~standard"].validate(t);if(n instanceof Promise)throw new TypeError("Schema validation must be synchronous");if(n.issues)throw new Error(JSON.stringify(n.issues,null,2));return n.value},so=(e,t)=>{var n,r,o,s;let i=((n=t.options)==null?void 0:n.VALUE)==="BINARY"?{type:"binary",encoding:((r=t.options)==null?void 0:r.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 n,r,o,s,i,a,u,c,m,E,y;return p(e,{email:O(t.value),delegatedFrom:(n=t.options)!=null&&n["DELEGATED-FROM"]?O((r=t.options)==null?void 0:r["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:((y=t.options)==null?void 0:y.RSVP)==="FALSE"?!1:void 0:void 0})},k=(e,t)=>{let n=t.value,r={};n[0]==="-"&&(r.before=!0,n=n.slice(1)),n=n.slice(1);let o=n.split("T"),s=o[0];if(s.includes("D")){let[a,u]=s.split("D");r.days=Number(a),s=u}if(s.includes("W")){let[a,u]=s.split("W");r.weeks=Number(a),s=u}let i=o[1];if(i){if(i.includes("H")){let[a,u]=i.split("H");r.hours=Number(a),i=u}if(i.includes("M")){let[a,u]=i.split("M");r.minutes=Number(a),i=u}if(i.includes("S")){let[a,u]=i.split("S");r.seconds=Number(a),i=u}}return p(e,r)},ao=(e,t)=>{let n=Number.parseInt(t.value.slice(0,4),10),r=Number.parseInt(t.value.slice(4,6),10)-1,o=Number.parseInt(t.value.slice(6,8),10),s=new Date(Date.UTC(n,r,o));return p(e,s)},Y=(e,t)=>{let n=Number.parseInt(t.value.slice(0,4),10),r=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(n,r,o,s,i,a));return p(e,u)},lo=(e,t,n)=>{let r=oe(n),o=Y(void 0,t),s=kn(o,r);return p(e,s)},uo=(e,t)=>{var n,r,o,s,i,a;if(((n=e.options)==null?void 0:n.VALUE)==="DATE")return{date:ao(void 0,e),type:(r=e.options)==null?void 0:r.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=io(c,e.options.TZID,t?.timezones);return m?{date:H(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}},f=(e,t,n)=>p(e,uo(t,n)),co=(e,t,n)=>{var r,o,s,i;let a=((r=t.options)==null?void 0:r.VALUE)==="DATE-TIME"||((o=t.options)==null?void 0:o.VALUE)==="DATE"?{type:"absolute",value:f(void 0,t,n),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)},mo=e=>e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e,st=e=>e.map(t=>{let[n,...r]=t.split(Te),o=r.join(Te);return{property:n,value:mo(o)}},{}),po=e=>e.reduce((t,n)=>(t[n.property]=n.value,t),{}),yo=e=>po(st(e)),fo=e=>{let t=!1,n;for(let s=0;s<e.length&&n===void 0;s+=1)e.charAt(s)===ln&&(t=!t),e.charAt(s)===an&&!t&&(n=s);if(n===void 0)throw Error(`Line not valid: ${e}`);let r=e.substring(0,n),o=e.substring(n+1);return{property:r,value:o}},go=e=>{let{property:t,value:n}=fo(e);if(t.includes(ne)){let[r,...o]=t.split(ne),s=yo(o);return{property:r,line:{options:s,value:n}}}return{property:t,line:{value:n}}},Ce=e=>/^[ \t]/.test(e),vo=e=>/^[A-Z]+(?:-[A-Z]+)*[:;]/.test(e),Eo=e=>{let t=[],n=e.split(re);for(;n[0]==="";)n.shift();let r=n.length;for(;r>0&&n[r-1]==="";)r-=1,n.pop();for(let o=0;o<n.length;){let s=n[o];for(o+=1;n[o]!==void 0&&(Ce(n[o])||!vo(n[o]));)n[o]===""?s+=Ee:Ce(n[o])?s+=n[o].substring(1):(s+=Ee,s+=n[o]),o+=1;t.push(s)}return t.filter(o=>o!=="")},To=(e,t,n)=>{if(!t)return e;let r={};return Object.entries(t).forEach(([o,s])=>{let i=Object.entries(n||{}).find(([c,m])=>m.name===o);if(!i){r[So(o)]=s.value;return}let a=i[1].convert(s),u=i[1].schema;if(!u){r[i[0]]=a;return}r[i[0]]=p(u,a)}),e.nonStandard=r,e},So=e=>{let t=e.startsWith("X-")?e.slice(2):e,n="",r=!1;for(let o of t)o==="-"?r=!0:(n+=r?o.toUpperCase():o.toLowerCase(),r=!1);return n},ho=e=>e.startsWith("X-"),M=(e,t,n)=>{let r=t.replace(sn(n?.icsComponent),""),o=[...new Set(Object.values(n.childComponents||{}).flatMap(({icsComponent:E})=>E))],s=Eo(o.reduce((E,y)=>E.replace(ve(y),""),r)),i=n.defaultValues||{},a={};s.forEach(E=>{var y,T;let{property:S,line:C}=go(E);ho(S)&&(a[S]=C);let g=n.objectKeyMap[S];if(!g)return;let w=(y=n.convertArrayValues)==null?void 0:y[g];if(w){let D=w({line:C});if(!D)return;(i[g]===void 0||i[g]===null||!Array.isArray(i[g]))&&(i[g]=[]),Array.isArray(D)?i[g].push(...D):i[g].push(D);return}let me=(T=n.convertValues)==null?void 0:T[g];if(me){let D=me({line:C});if(!D)return;i[g]=D;return}i[g]=C.value});let u=n.childComponents,c=u?Object.keys(u||{}):[];u&&c.length>0&&c.forEach(E=>{let y=u?.[E];if(!y)return;let T=Array.isArray(y.icsComponent)?y.icsComponent:[y.icsComponent],S=[],C=[];T.forEach(g=>{C.push(...r.matchAll(ve(g)))}),C.map(g=>g[0]).forEach(g=>{let w=y.convert(g,{data:i});w&&S.push(w)}),S.length!==0&&(i[E]=S)});let m=p(e,i);return n!=null&&n.nonStandard?To(m,a,n?.nonStandard):m},W=(e,t)=>{var n,r,o;return p(e,{name:(n=t.options)==null?void 0:n.CN,dir:(r=t.options)==null?void 0:r.DIR,sentBy:(o=t.options)!=null&&o["SENT-BY"]?O(t.options["SENT-BY"]):void 0,email:O(t.value)})},le=(e,t,n)=>{var r;return p(e,{value:f(void 0,t,n),range:(r=t.options)==null?void 0:r.RANGE})},Ao=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,Ao(t.value)),Po=(e,t)=>p(e,t.value),bo=["until"],xo=e=>bo.includes(e),Mo=["bySecond","byMinute","byHour","byMonthday","byYearday","byWeekNo","bySetPos"],Do=e=>Mo.includes(e),Ro=["byDay"],Oo=e=>Ro.includes(e),No=["count","interval"],wo=e=>No.includes(e),G=(e,t,n)=>{let r={};return st(t.value.split(ne)).forEach(o=>{let{property:s,value:i}=o,a=Ke[s];if(a){if(xo(a)){r[a]=f(void 0,{value:i,options:{VALUE:i.includes("T")?"DATE-TIME":"DATE"}},{timezones:n?.timezones});return}if(Do(a)){r[a]=i.split(N).map(u=>Number(u));return}if(a==="byMonth"){r[a]=i.split(N).map(u=>Number(u)-1);return}if(Oo(a)){r[a]=i.split(N).map(u=>Co(void 0,{value:u}));return}if(wo(a)){r[a]=Number(i);return}if(a==="frequency"){if(!i||!_n.includes(i))return;r[a]=i;return}if(a==="workweekStart"){r[a]=Po(void 0,{value:i});return}}}),p(e,r)},ue=(e,t)=>p(e,t.value),Io=(e,t)=>p(e,t.value),ce=(e,t,n)=>p(e,t.value.split(",").map(r=>f(void 0,{value:r,options:t.options},n))),Lo=(e,t)=>p(e,t.value),Ko=(e,t)=>p(e,t.value),zo=(e,t)=>p(e,t.value),U=(e,t)=>p(e,Number.parseInt(t.value,10)),Yo=e=>e.replace(/\\(([,;\\])|([nN]))/g,(t,n,r)=>r||`
`),h=(e,t)=>p(e,Yo(t.value)),Uo=(...e)=>{let[t,n,r]=e;return M(t,n,{icsComponent:He,objectKeyMap:be,convertValues:{trigger:({line:o})=>co(void 0,o,{timezones:r?.timezones}),duration:({line:o})=>k(void 0,o),repeat:({line:o})=>U(void 0,o)},convertArrayValues:{attachments:({line:o})=>so(void 0,o),attendees:({line:o})=>F(void 0,o)},nonStandard:r?.nonStandard,timezones:r?.timezones})},Fo=(...e)=>{let[t,n,r]=e,o,s=M(t,n,{icsComponent:je,objectKeyMap:Re,convertValues:{stamp:({line:i})=>f(void 0,i,{timezones:r?.timezones}),start:({line:i})=>f(void 0,i,{timezones:r?.timezones}),end:({line:i})=>f(void 0,i,{timezones:r?.timezones}),created:({line:i})=>f(void 0,i,{timezones:r?.timezones}),lastModified:({line:i})=>f(void 0,i,{timezones:r?.timezones}),categories:({line:i})=>i.value.split(N),description:({line:i})=>{var a;return(a=i.options)!=null&&a.ALTREP&&(o=i.options.ALTREP),h(void 0,i)},location:({line:i})=>h(void 0,i),comment:({line:i})=>h(void 0,i),summary:({line:i})=>h(void 0,i),recurrenceRule:({line:i})=>G(void 0,i,{timezones:r?.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})=>ue(void 0,i),recurrenceId:({line:i})=>le(void 0,i,{timezones:r?.timezones}),status:({line:i})=>Lo(void 0,i),timeTransparent:({line:i})=>Io(void 0,i)},convertArrayValues:{attendees:({line:i})=>F(void 0,i),exceptionDates:({line:i})=>ce(void 0,i,{timezones:r?.timezones})},childComponents:{alarms:{icsComponent:He,convert:i=>Uo(void 0,i,{nonStandard:r?.nonStandard,timezones:r?.timezones})}},timezones:r?.timezones,nonStandard:r?.nonStandard});return o&&(s.descriptionAltRep=o),s},ko=(...e)=>{let[t,n,r]=e,o=n.split("BEGIN:")[1].split(re)[0],s=Vn.includes(o)?o:"STANDARD",i=n.split("TZOFFSETTO:")[1].split(re)[0];return M(t,n,{icsComponent:s,objectKeyMap:Ie,defaultValues:{type:s},convertValues:{start:({line:a})=>lo(void 0,a,i),recurrenceRule:({line:a})=>G(void 0,a,{timezones:r?.timezones}),recurrenceDate:({line:a})=>f(void 0,a,{timezones:r?.timezones})},nonStandard:r?.nonStandard,timezones:r?.timezones})},Bo=(...e)=>{let[t,n,r]=e;return M(t,n,{icsComponent:$e,objectKeyMap:Ne,convertValues:{lastModified:({line:o})=>Y(void 0,o)},childComponents:{props:{icsComponent:["DAYLIGHT","STANDARD"],convert:o=>ko(void 0,o,{nonStandard:r?.nonStandard,timezones:r?.timezones})}},nonStandard:r?.nonStandard,timezones:r?.timezones})},Vo=(...e)=>{let[t,n,r]=e;return M(t,n,{icsComponent:qe,objectKeyMap:Ye,convertValues:{stamp:({line:o})=>f(void 0,o,{timezones:r?.timezones}),start:({line:o})=>f(void 0,o,{timezones:r?.timezones}),due:({line:o})=>f(void 0,o,{timezones:r?.timezones}),created:({line:o})=>f(void 0,o,{timezones:r?.timezones}),lastModified:({line:o})=>f(void 0,o,{timezones:r?.timezones}),completed:({line:o})=>f(void 0,o,{timezones:r?.timezones}),categories:({line:o})=>o.value.split(N),description:({line:o})=>h(void 0,o),location:({line:o})=>h(void 0,o),comment:({line:o})=>h(void 0,o),summary:({line:o})=>h(void 0,o),recurrenceRule:({line:o})=>G(void 0,o,{timezones:r?.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})=>ue(void 0,o),recurrenceId:({line:o})=>le(void 0,o,{timezones:r?.timezones}),status:({line:o})=>Ko(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),exceptionDates:({line:o})=>ce(void 0,o,{timezones:r?.timezones})},nonStandard:r?.nonStandard,timezones:r?.timezones})},_o=(...e)=>{let[t,n,r]=e;return M(t,n,{icsComponent:We,objectKeyMap:Fe,convertValues:{stamp:({line:o})=>f(void 0,o,{timezones:r?.timezones}),start:({line:o})=>f(void 0,o,{timezones:r?.timezones}),created:({line:o})=>f(void 0,o,{timezones:r?.timezones}),lastModified:({line:o})=>f(void 0,o,{timezones:r?.timezones}),categories:({line:o})=>o.value.split(N),description:({line:o})=>h(void 0,o),comment:({line:o})=>h(void 0,o),summary:({line:o})=>h(void 0,o),recurrenceRule:({line:o})=>G(void 0,o,{timezones:r?.timezones}),organizer:({line:o})=>W(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:r?.timezones}),status:({line:o})=>zo(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),exceptionDates:({line:o})=>ce(void 0,o,{timezones:r?.timezones})},nonStandard:r?.nonStandard,timezones:r?.timezones})},$o=(e,t)=>{var n;return p(e,{type:(n=t.options)==null?void 0:n.FBTYPE,values:t.value.split(",").map(r=>{let[o,s]=r.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,n,r]=e;return M(t,n,{icsComponent:Ge,objectKeyMap:Be,convertValues:{stamp:({line:o})=>f(void 0,o,{timezones:r?.timezones}),start:({line:o})=>f(void 0,o,{timezones:r?.timezones}),end:({line:o})=>f(void 0,o,{timezones:r?.timezones}),comment:({line:o})=>h(void 0,o),organizer:({line:o})=>W(void 0,o)},convertArrayValues:{attendees:({line:o})=>F(void 0,o),freeBusy:({line:o})=>$o(void 0,o)},nonStandard:r?.nonStandard,timezones:r?.timezones})},at=(...e)=>{let[t,n,r]=e;return M(t,n,{icsComponent:rn,objectKeyMap:Me,convertValues:{version:({line:o})=>o.value},childComponents:{timezones:{icsComponent:$e,convert:o=>Bo(void 0,o,{nonStandard:r?.nonStandard})},events:{icsComponent:je,convert:(o,{data:s})=>Fo(void 0,o,{nonStandard:r?.nonStandard,timezones:s.timezones})},todos:{icsComponent:qe,convert:(o,{data:s})=>Vo(void 0,o,{nonStandard:r?.nonStandard,timezones:s.timezones})},journals:{icsComponent:We,convert:(o,{data:s})=>_o(void 0,o,{nonStandard:r?.nonStandard,timezones:s.timezones})},freeBusy:{icsComponent:Ge,convert:(o,{data:s})=>jo(void 0,o,{nonStandard:r?.nonStandard,timezones:s.timezones})}},nonStandard:r?.nonStandard})};var lt="0.3.13",ut="icalendar:lastSync";console.log(`[iCalendar] Plug script executing at top level (Version ${lt})`);var Ho={"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 qo(){try{let e=await B.get("icalendar",{sources:[]}),t=e.sources||[],n=e.tzShift||0;return{sources:t,tzShift:n}}catch{return{sources:[],tzShift:0}}}async function Wo(e,t=0){console.log(`[iCalendar] Fetching from ${e.url}`);let n=await fetch(e.url);if(!n.ok)return console.error(`[iCalendar] Fetch failed with status ${n.status}`),[];let r=await n.text(),o=at(void 0,r);if(!o.events)return[];let s=[];for(let i of o.events){let a=i.start,u="";if(a.local&&typeof a.local.date=="string"?u=a.local.date:typeof a.date=="string"&&(u=a.date),!u)continue;let c=new Date(u.replace("Z","")+"Z"),m=a.local?.timezone||a.timezone||"UTC",E=Ho[m]??0,y=c.getTime()-E*36e5,T=new Date(y+t*36e5),S=g=>String(g).padStart(2,"0"),C=T.getFullYear()+"-"+S(T.getMonth()+1)+"-"+S(T.getDate())+"T"+S(T.getHours())+":"+S(T.getMinutes())+":"+S(T.getSeconds());s.push({...i,start:C,tag:"ical-event",sourceName:e.name})}return s}async function de(){console.log("[iCalendar] syncCalendars command triggered");try{let{sources:e,tzShift:t}=await qo();if(console.log(`[iCalendar] Found ${e.length} sources, tzShift: ${t}`),e.length===0)return;await b.flashNotification("Syncing calendars...","info");let n=[];for(let r of e){let o=await Wo(r,t);n.push(...o)}await V.indexObjects("$icalendar",n),console.log(`[iCalendar] Successfully indexed ${n.length} events`),await b.flashNotification(`Synced ${n.length} events`,"info")}catch(e){console.error("[iCalendar] Sync failed:",e)}}async function ct(){console.log("[iCalendar] forceSync command triggered"),await K.del(ut),await de()}async function dt(){if(console.log("[iCalendar] clearCache command triggered"),!await b.confirm("Clear all calendar events?"))return;let e=await z.query({prefix:["ridx","$icalendar"]}),t=[];for(let{key:n}of e)t.push(n),t.push(["idx",...n.slice(2),"$icalendar"]);t.length>0&&await z.batchDel(t),await K.del(ut),await b.flashNotification("Calendar index cleared","info")}async function mt(){console.log("[iCalendar] showVersion command triggered"),await b.flashNotification(`iCalendar Plug ${lt}`,"info")}var pt={syncCalendars:de,forceSync:ct,clearCache:dt,showVersion:mt},yt={name:"Library/sstent/icalendar",version:"0.3.13",author:"sstent",index:"icalendar.ts",functions:{syncCalendars:{path:"icalendar.ts:syncCalendars",command:"iCalendar: Sync"},forceSync:{path:"icalendar.ts:forceSync",command:"iCalendar: Force Sync"},clearCache:{path:"icalendar.ts:clearCache",command:"iCalendar: Clear Cache"},showVersion:{path:"icalendar.ts:showVersion",command:"iCalendar: Show Version"}},permissions:["http"],assets:{}},os={manifest:yt,functionMapping:pt};ge(pt,yt,self.postMessage);export{os as plug};
//# sourceMappingURL=icalendar.plug.js.map