Files
silverbullet-icalendar/icalendar.plug.js
sstent 9b54e2d8a8
All checks were successful
Build SilverBullet Plug / build (push) Successful in 30s
Fix: Restore proven recursive date sanitization and unique indexing from deb30ab and iterate to 0.3.25
2026-02-18 10:26:50 -08:00

5 lines
38 KiB
JavaScript

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