forked from GitHubMirrors/silverbullet-icalendar
5 lines
39 KiB
JavaScript
5 lines
39 KiB
JavaScript
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<r;o++)n[o]=t.charCodeAt(o);return n}function Q(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 ea=new Uint8Array(16);var X=class{prefix;maxCaptureSize;originalConsole;logBuffer;constructor(t="",r=1e3){this.prefix=t,this.maxCaptureSize=r,this.logBuffer=[],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()}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(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 X(e),Ee}var Y=e=>{throw new Error("Not initialized yet")},ne=typeof window>"u"&&typeof globalThis.WebSocketPair>"u";typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var te=new Map,ee=0;ne&&(globalThis.syscall=async(e,...t)=>await new Promise((r,n)=>{ee++,te.set(ee,{resolve:r,reject:n}),Y({type:"sys",id:ee,name:e,args:t})}));function Te(e,t,r){ne&&(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=te.get(i);if(!a)throw Error("Invalid request id");te.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?Q(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?Q(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})}}ne&&Tt();var T={};z(T,{alert:()=>rn,configureVimMode:()=>Sn,confirm:()=>nn,copyToClipboard:()=>mn,deleteLine:()=>yn,dispatch:()=>en,downloadFile:()=>Vt,filterBox:()=>Ht,flashNotification:()=>$t,fold:()=>sn,foldAll:()=>cn,getCurrentEditor:()=>xt,getCurrentPage:()=>ht,getCurrentPageMeta:()=>St,getCurrentPath:()=>At,getCursor:()=>Mt,getRecentlyOpenedPages:()=>Ct,getSelection:()=>bt,getText:()=>Dt,getUiOption:()=>on,goHistory:()=>Pt,hidePanel:()=>jt,insertAtCursor:()=>Xt,insertAtPos:()=>Gt,invokeCommand:()=>wt,isMobile:()=>Cn,moveCursor:()=>Zt,moveCursorToLine:()=>Qt,moveLineDown:()=>Tn,moveLineUp:()=>gn,navigate:()=>It,newWindow:()=>Bt,openCommandPalette:()=>zt,openPageNavigator:()=>Lt,openSearchPanel:()=>vn,openUrl:()=>Ft,prompt:()=>tn,rebuildEditorState:()=>kt,redo:()=>fn,reloadConfigAndCommands:()=>Ut,reloadPage:()=>Yt,reloadUI:()=>Kt,replaceRange:()=>Jt,save:()=>Nt,sendMessage:()=>An,setSelection:()=>Ot,setText:()=>Rt,setUiOption:()=>an,showPanel:()=>qt,showProgress:()=>Wt,toggleComment:()=>En,toggleFold:()=>un,undo:()=>pn,unfold:()=>ln,unfoldAll:()=>dn,uploadFile:()=>_t,vimEx:()=>hn});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});function l(e,...t){return globalThis.syscall(e,...t)}function ht(){return l("editor.getCurrentPage")}function St(){return l("editor.getCurrentPageMeta")}function At(){return l("editor.getCurrentPath")}function Ct(){return l("editor.getRecentlyOpenedPages")}function xt(){return l("editor.getCurrentEditor")}function Dt(){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 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 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 fn(){return l("editor.redo")}function vn(){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 hn(e){return l("editor.vimEx",e)}function Sn(){return l("editor.configureVimMode")}function An(e,t){return l("editor.sendMessage",e,t)}function Cn(){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:()=>jn,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 jn(){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")}function _(e){return e.getFullYear()+"-"+String(e.getMonth()+1).padStart(2,"0")+"-"+String(e.getDate()).padStart(2,"0")+"T"+String(e.getHours()).padStart(2,"0")+":"+String(e.getMinutes()).padStart(2,"0")+":"+String(e.getSeconds()).padStart(2,"0")+"."+String(e.getMilliseconds()).padStart(3,"0")}var A=e=>Object.fromEntries(Object.entries(e).map(([t,r])=>[r,t])),E=e=>Object.keys(e),Me={action:"ACTION",description:"DESCRIPTION",duration:"DURATION",repeat:"REPEAT",summary:"SUMMARY",trigger:"TRIGGER",attachments:"ATTACH",attendees:"ATTENDEE"},be=A(Me),Na=E(be),Ia=E(Me),Oe={method:"METHOD",prodId:"PRODID",version:"VERSION",name:"X-WR-CALNAME"},we=A(Oe),La=E(we),za=E(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=A(Ne),Ya=E(Ie),Ka=E(Ne),Le={id:"TZID",lastModified:"LAST-MODIFIED",url:"TZURL"},ze=A(Le),ka=E(ze),Ua=E(Le),Ye={comment:"COMMENT",name:"TZNAME",offsetFrom:"TZOFFSETFROM",offsetTo:"TZOFFSETTO",recurrenceDate:"RDATE",recurrenceRule:"RRULE",start:"DTSTART"},Ke=A(Ye),Fa=E(Ke),Ba=E(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=A(ke),Pa=E(Ue),Va=E(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=A(Fe),_a=E(Be),$a=E(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=A(Pe),Ha=E(Ve),qa=E(Pe),_e={stamp:"DTSTAMP",start:"DTSTART",uid:"UID",url:"URL",organizer:"ORGANIZER",attendees:"ATTENDEE",comment:"COMMENT",end:"DTEND",freeBusy:"FREEBUSY"},$e=A(_e),ja=E($e),Wa=E(_e),He="BEGIN",qe="END",ar="VCALENDAR",je="VTIMEZONE",ir="STANDARD",sr="DAYLIGHT",We="VEVENT",Ge="VALARM",Je="VTODO",Ze="VJOURNAL",Qe="VFREEBUSY";var he=e=>new RegExp(`${He}:${e}([\\s\\S]*?)${qe}:${e}`,"g"),lr=e=>new RegExp(`${He}:${e}|${qe}:${e}`,"g");var oe=/\r\n|\r|\n/;var Se=`
|
|
`,ur=":",I=",",cr='"',ae=";";var Ae="=";var dr=Math.pow(10,8)*24*60*60*1e3,Ga=-dr,pr=6048e5;var Xe=6e4,et=36e5,fr=3600,tt=fr*24,Ja=tt*7,vr=tt*365.2425,mr=vr/12,Za=mr*3,Ce=Symbol.for("constructDateFrom");function S(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Ce in e?e[Ce](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 nt(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 j(e,t,r){return S(r?.in||e,+d(e)+t)}function yr(e,t,r){return j(e,t*et,r)}var Er={};function W(){return Er}function H(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(),p=(c<s?7:0)+c-s;return u.setDate(u.getDate()-p),u.setHours(0,0,0,0),u}function gr(e,...t){let r=S.bind(null,e||t.find(n=>typeof n=="object"));return t.map(r)}function Tr(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*Xe),n}function hr(e,t,r){return j(e,t*1e3,r)}function le(e,t,r){return se(e,t*7,r)}function ot(e,t,r){return nt(e,t*12,r)}function ue(e,t){let r=+d(e)-+d(t);return r<0?-1:r>0?1:r}function xe(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 Sr(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}=Sr(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 De(e,t){let r=d(e,t?.in);return r.setDate(1),r.setHours(0,0,0,0),r}function Cr(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 xr(e,t){let r=d(e,t?.in);return r.setFullYear(r.getFullYear(),0,1),r.setHours(0,0,0,0),r}function Dr(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,p=S(t?.in||e,0);p.setFullYear(s+1,0,c),p.setHours(0,0,0,0);let y=H(p,t),m=S(t?.in||e,0);m.setFullYear(s,0,c),m.setHours(0,0,0,0);let C=H(m,t);return+a>=+y?s+1:+a>=+C?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=Dr(e,t),c=S(t?.in||e,0);return c.setFullYear(u,0,s),c.setHours(0,0,0,0),H(c,t)}function Mr(e,t){let r=d(e,t?.in),n=+H(r,t)-+Rr(r,t);return Math.round(n/pr)+1}function $(e,t){return d(e,t?.in).getDay()}function at(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 br(e,t){return d(e,t?.in).getHours()}function Or(e,t){return d(e,t?.in).getMinutes()}function it(e,t){return d(e,t?.in).getMonth()}function wr(e){return d(e).getSeconds()}function Nr(e,t){return d(e,t?.in).getFullYear()}function Ir(e,t){return+d(e)==+d(t)}function Lr(e,t,r){let n=d(e,r?.in),o=Mr(n,r)-t;return n.setDate(n.getDate()-o*7),d(n,r?.in)}function q(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),p=c.getDay(),y=(t%7+7)%7,m=7-u,C=t<0||t>6?t-(p+m)%7:(y+m)%7-(p+m)%7;return se(c,C,r)}function st(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 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=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=at(a);return n.setMonth(t,Math.min(i,s)),n}function kr(e,t,r){let n=d(e,r?.in);return n.setDate(t),n}function Ur(e,t,r){let n=d(e,r?.in);return n.setMonth(0),n.setDate(t),n}function Fr(e,t,r){let n=d(e,r?.in);return n.setHours(t),n}function Br(e,t,r){let n=d(e,r?.in);return n.setMinutes(t),n}function Pr(e,t,r){let n=d(e,r?.in);return n.setSeconds(t),n}function Vr(e,t,r){return j(e,-t,r)}function _r(e,t,r){return le(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<r;){if(w(n.length,e.count))return;a=hr(a,i),n.push([a])}return}if(o==="MINUTELY"){for(;a<r;){if(w(n.length,e.count))return;a=rt(a,i),n.push([a])}return}if(o==="HOURLY"){for(;a<r;){if(w(n.length,e.count))return;a=yr(a,i),n.push([a])}return}if(o==="DAILY"){for(;a<r;){if(w(n.length,e.count))return;a=se(a,i),n.push([a])}return}if(o==="WEEKLY"){for(;a<r;){if(w(n.length,e.count))return;a=le(a,i),n.push([a])}return}if(o==="MONTHLY"){for(;a<r;)a=nt(a,i),n.push([a]);return}if(o==="YEARLY"){for(;a<r;)a=ot(a,i),n.push([a]);return}},jr=(e,t,r,n)=>{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})=>q(a,s,{weekStartsOn:n})))):e.byMonth?t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>re(x(De(a)),x(xe(a)),s,n,u)))):t.map(i=>i.flatMap(a=>o.flatMap(({day:s,occurrence:u})=>re(x(xr(a)),x(Cr(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})=>re(x(De(a)),x(xe(a)),s,n,u)))):e.frequency==="WEEKLY"?t.map(i=>i.flatMap(a=>o.map(({day:s})=>q(a,s,{weekStartsOn:n})))):t.map(i=>i.filter(a=>o.find(({day:s})=>s===$(a))))},re=(e,t,r,n,o)=>{if(o!==void 0){if(!(o<0)){let s=q(e,r,{weekStartsOn:n}),u=e>s;return le(s,(o||1)-1+(u?1:0))}let i=q(t,r,{weekStartsOn:n}),a=t<i;return x(Tr(_r(i,-(o||1)-1+(a?1:0))))}return Ar({start:e,end:t}).map(i=>x(i)).filter(i=>st(i,{start:e,end:t})).filter(i=>r===$(i))},x=e=>rt(e,-e.getTimezoneOffset()),Wr=(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(ue).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=jr(e,n,e.byDay,t.weekStartsOn)),e.byHour&&(n=Wr(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(ue).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<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},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,c)=>ue(u.start,c.start));for(let u=0;u<i.length;u+=1)if(e<i[u].start){let c=i[u-1]?i[u-1].offsetTo:i[u].offsetFrom,p=c.length>5?c.substring(0,5):c;return{offset:p,milliseconds:ie(p)}}let a=i[i.length-1].offsetTo,s=a.length>5?a.substring(0,5):a;return{offset:s,milliseconds:ie(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(),c=s.toString().length===1?`0${s}`:s.toString();return{offset:`${i?"-":"+"}${u}${c}`,milliseconds:o}}};var f=(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 f(e,a)},N=e=>e.replace(/mailto:/gi,""),B=(e,t)=>{var r,n,o,i,a,s,u,c,p,y,m;return f(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:(p=t.options)!=null&&p.RSVP?((y=t.options)==null?void 0:y.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 f(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 f(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 f(e,u)},co=(e,t,r)=>{let n=ie(r),o=U(void 0,t),i=Vr(o,n);return f(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",c=U(void 0,e);if(!((i=e.options)!=null&&i.TZID))return{date:c,type:u};let p=so(c,e.options.TZID,t?.timezones);return p?{date:j(c,-p.milliseconds),type:u,local:(a=e.options)!=null&&a.TZID?{date:c,timezone:(s=e.options)==null?void 0:s.TZID,tzoffset:p.offset}:void 0}:{date:c,type:u}},v=(e,t,r)=>f(e,po(t,r)),fo=(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:v(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 f(e,s)},vo=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:vo(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<e.length&&r===void 0;i+=1)e.charAt(i)===cr&&(t=!t),e.charAt(i)===ur&&!t&&(r=i);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}},go=e=>{let{property:t,value:r}=Eo(e);if(t.includes(ae)){let[n,...o]=t.split(ae),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),ho=e=>{let t=[],r=e.split(oe);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 i=r[o];for(o+=1;r[o]!==void 0&&(Re(r[o])||!To(r[o]));)r[o]===""?i+=Se:Re(r[o])?i+=r[o].substring(1):(i+=Se,i+=r[o]),o+=1;t.push(i)}return t.filter(o=>o!=="")},So=(e,t,r)=>{if(!t)return e;let n={};return Object.entries(t).forEach(([o,i])=>{let a=Object.entries(r||{}).find(([c,p])=>p.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]]=f(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},Co=e=>e.startsWith("X-"),D=(e,t,r)=>{let n=t.replace(lr(r?.icsComponent),""),o=[...new Set(Object.values(r.childComponents||{}).flatMap(({icsComponent:y})=>y))],i=ho(o.reduce((y,m)=>y.replace(he(m),""),n)),a=r.defaultValues||{},s={};i.forEach(y=>{var m,C;let{property:R,line:M}=go(y);Co(R)&&(s[R]=M);let g=r.objectKeyMap[R];if(!g)return;let L=(m=r.convertArrayValues)==null?void 0:m[g];if(L){let b=L({line:M});if(!b)return;(a[g]===void 0||a[g]===null||!Array.isArray(a[g]))&&(a[g]=[]),Array.isArray(b)?a[g].push(...b):a[g].push(b);return}let me=(C=r.convertValues)==null?void 0:C[g];if(me){let b=me({line:M});if(!b)return;a[g]=b;return}a[g]=M.value});let u=r.childComponents,c=u?Object.keys(u||{}):[];u&&c.length>0&&c.forEach(y=>{let m=u?.[y];if(!m)return;let C=Array.isArray(m.icsComponent)?m.icsComponent:[m.icsComponent],R=[],M=[];C.forEach(g=>{M.push(...n.matchAll(he(g)))}),M.map(g=>g[0]).forEach(g=>{let L=m.convert(g,{data:a});L&&R.push(L)}),R.length!==0&&(a[y]=R)});let p=f(e,a);return r!=null&&r.nonStandard?So(p,s,r?.nonStandard):p},G=(e,t)=>{var r,n,o;return f(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)})},ce=(e,t,r)=>{var n;return f(e,{value:v(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)}},Do=(e,t)=>f(e,xo(t.value)),Ro=(e,t)=>f(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),J=(e,t,r)=>{let n={};return ut(t.value.split(ae)).forEach(o=>{let{property:i,value:a}=o,s=Ue[i];if(s){if(bo(s)){n[s]=v(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=>Do(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}}}),f(e,n)},de=(e,t)=>f(e,t.value),Yo=(e,t)=>f(e,t.value),pe=(e,t,r)=>f(e,t.value.split(",").map(n=>v(void 0,{value:n,options:t.options},r))),Ko=(e,t)=>f(e,t.value),ko=(e,t)=>f(e,t.value),Uo=(e,t)=>f(e,t.value),F=(e,t)=>f(e,Number.parseInt(t.value,10)),Fo=e=>e.replace(/\\(([,;\\])|([nN]))/g,(t,r,n)=>n||`
|
|
`),h=(e,t)=>f(e,Fo(t.value)),Bo=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:Ge,objectKeyMap:be,convertValues:{trigger:({line:o})=>fo(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=D(t,r,{icsComponent:We,objectKeyMap:Ie,convertValues:{stamp:({line:a})=>v(void 0,a,{timezones:n?.timezones}),start:({line:a})=>v(void 0,a,{timezones:n?.timezones}),end:({line:a})=>v(void 0,a,{timezones:n?.timezones}),created:({line:a})=>v(void 0,a,{timezones:n?.timezones}),lastModified:({line:a})=>v(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),h(void 0,a)},location:({line:a})=>h(void 0,a),comment:({line:a})=>h(void 0,a),summary:({line:a})=>h(void 0,a),recurrenceRule:({line:a})=>J(void 0,a,{timezones:n?.timezones}),duration:({line:a})=>P(void 0,a),organizer:({line:a})=>G(void 0,a),sequence:({line:a})=>F(void 0,a),class:({line:a})=>de(void 0,a),recurrenceId:({line:a})=>ce(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})=>pe(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(oe)[0],i=$r.includes(o)?o:"STANDARD",a=r.split("TZOFFSETTO:")[1].split(oe)[0];return D(t,r,{icsComponent:i,objectKeyMap:Ke,defaultValues:{type:i},convertValues:{start:({line:s})=>co(void 0,s,a),recurrenceRule:({line:s})=>J(void 0,s,{timezones:n?.timezones}),recurrenceDate:({line:s})=>v(void 0,s,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},_o=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:je,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 D(t,r,{icsComponent:Je,objectKeyMap:Be,convertValues:{stamp:({line:o})=>v(void 0,o,{timezones:n?.timezones}),start:({line:o})=>v(void 0,o,{timezones:n?.timezones}),due:({line:o})=>v(void 0,o,{timezones:n?.timezones}),created:({line:o})=>v(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>v(void 0,o,{timezones:n?.timezones}),completed:({line:o})=>v(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(I),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})=>J(void 0,o,{timezones:n?.timezones}),duration:({line:o})=>P(void 0,o),organizer:({line:o})=>G(void 0,o),sequence:({line:o})=>F(void 0,o),percentComplete:({line:o})=>F(void 0,o),class:({line:o})=>de(void 0,o),recurrenceId:({line:o})=>ce(void 0,o,{timezones:n?.timezones}),status:({line:o})=>ko(void 0,o)},convertArrayValues:{attendees:({line:o})=>B(void 0,o),exceptionDates:({line:o})=>pe(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},Ho=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:Ze,objectKeyMap:Ve,convertValues:{stamp:({line:o})=>v(void 0,o,{timezones:n?.timezones}),start:({line:o})=>v(void 0,o,{timezones:n?.timezones}),created:({line:o})=>v(void 0,o,{timezones:n?.timezones}),lastModified:({line:o})=>v(void 0,o,{timezones:n?.timezones}),categories:({line:o})=>o.value.split(I),description:({line:o})=>h(void 0,o),comment:({line:o})=>h(void 0,o),summary:({line:o})=>h(void 0,o),recurrenceRule:({line:o})=>J(void 0,o,{timezones:n?.timezones}),organizer:({line:o})=>G(void 0,o),sequence:({line:o})=>F(void 0,o),class:({line:o})=>de(void 0,o),recurrenceId:({line:o})=>ce(void 0,o,{timezones:n?.timezones}),status:({line:o})=>Uo(void 0,o)},convertArrayValues:{attendees:({line:o})=>B(void 0,o),exceptionDates:({line:o})=>pe(void 0,o,{timezones:n?.timezones})},nonStandard:n?.nonStandard,timezones:n?.timezones})},qo=(e,t)=>{var r;return f(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}})})},jo=(...e)=>{let[t,r,n]=e;return D(t,r,{icsComponent:Qe,objectKeyMap:$e,convertValues:{stamp:({line:o})=>v(void 0,o,{timezones:n?.timezones}),start:({line:o})=>v(void 0,o,{timezones:n?.timezones}),end:({line:o})=>v(void 0,o,{timezones:n?.timezones}),comment:({line:o})=>h(void 0,o),organizer:({line:o})=>G(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 D(t,r,{icsComponent:ar,objectKeyMap:we,convertValues:{version:({line:o})=>o.value},childComponents:{timezones:{icsComponent:je,convert:o=>_o(void 0,o,{nonStandard:n?.nonStandard})},events:{icsComponent:We,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})=>jo(void 0,o,{nonStandard:n?.nonStandard,timezones:i.timezones})}},nonStandard:n?.nonStandard})};var dt="0.2.6",Z="icalendar:lastSync",Wo=21600;console.log(`[iCalendar] Plug loading (Version ${dt})...`);console.log(`[iCalendar] Environment Timezone Offset: ${new Date().getTimezoneOffset()} minutes`);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 fe(e,t){if(e==null)return e;if(e instanceof Date){let r=_(e);return console.log(`[iCalendar] Localizing Date Object: UTC=${e.toISOString()} -> Local=${r}`),r}if(Go(e)&&e.date instanceof Date){let r=_(e.date);return console.log(`[iCalendar] Localizing ICS Date: UTC=${e.date.toISOString()} -> Local=${r} (TZID: ${e.timezone||"none"})`),r}if(typeof e=="string"&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(e))return _(new Date(e));if(Array.isArray(e))return e.map(r=>fe(r,t));if(typeof e=="object"){let r={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=fe(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){if(typeof n.url!="string"){console.error("[iCalendar] Invalid source (missing url):",n);continue}r.push({url:n.url,name:typeof n.name=="string"?n.name:void 0})}return r}async function Qo(e){let t=e.url.trim(),r=/\s/g;if(r.test(t)){let s=t.match(r)?.map(u=>u.charCodeAt(0)).join(", ");console.log(`[iCalendar] URL contains whitespace (charCodes: ${s}), encoding: "${t}"`),t=t.replace(/\s/g,u=>encodeURIComponent(u))}console.log(`[iCalendar] Fetching: ${t}`);let n=await fetch(t,{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){let s=(await n.text()).slice(0,200).replace(/\n/g," ");throw console.error(`[iCalendar] HTTP ${n.status} Error:`,{url:t,status:n.status,statusText:n.statusText,bodyPreview:s}),new Error(`HTTP ${n.status}: ${n.statusText||"Error"} - ${s}`)}let o=await n.text();console.log(`[iCalendar] Raw ICS Snippet (first 500 chars): ${o.slice(0,500).replace(/\n/g," ")}`);let i=ct(void 0,o);return!i.events||i.events.length===0?[]:await Promise.all(i.events.map(async a=>{let s=`${a.start?.date||""}${a.uid||a.summary||""}`,u=await Jo(s);return fe({...a,ref:u,tag:"ical-event",sourceName:e.name},i.timezones)}))}async function ve(){try{let r=((await k.get("icalendar",{sources:[]})).cacheDuration??Wo)*1e3,n=await Zo();if(n.length===0)return;let o=await O.get(Z),i=Date.now();if(o&&i-o<r){let c=Math.round((i-o)/1e3);console.log(`[iCalendar] Using cached data (${c}s old)`);return}console.log(`[iCalendar] Syncing ${n.length} calendar source(s)...`),await T.flashNotification("Syncing calendars...","info");let a=[],s=0;for(let c of n){let p=c.name||c.url;try{let y=await Qo(c);a.push(...y),s++}catch(y){console.error(`[iCalendar] Failed to sync "${p}":`,y),await T.flashNotification(`Failed to sync "${p}"`,"error")}}await V.indexObjects("$icalendar",a),await O.set(Z,i);let u=`Synced ${a.length} events from ${s}/${n.length} source(s)`;console.log(`[iCalendar] ${u}`),await T.flashNotification(u,"info")}catch(e){console.error("[iCalendar] Sync failed:",e),await T.flashNotification("Failed to sync calendars","error")}}async function pt(){await O.del(Z),console.log("[iCalendar] Cache cleared, forcing fresh sync"),await T.flashNotification("Forcing fresh calendar sync...","info"),await ve()}async function ft(){if(await T.confirm("Are you sure you want to clear all calendar events and cache? This will remove all indexed calendar data."))try{let e="$icalendar";console.log("[iCalendar] Clearing index for",e);let t="idx",r="ridx",n=[],o=await K.query({prefix:[r,e]});for(let{key:i}of o)n.push(i),n.push([t,...i.slice(2),e]);n.length>0&&(await K.batchDel(n),console.log("[iCalendar] Deleted",n.length,"entries")),await O.del(Z),console.log("[iCalendar] Calendar index and cache cleared"),await T.flashNotification("Calendar index and cache cleared","info")}catch(e){console.error("[iCalendar] Failed to clear cache:",e),await T.flashNotification(`Failed to clear cache: ${e instanceof Error?e.message:String(e)}`,"error")}}async function vt(){await T.flashNotification(`iCalendar Plug ${dt}`,"info")}var mt={syncCalendars:ve,forceSync:pt,clearCache:ft,showVersion:vt},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:{}},li={manifest:yt,functionMapping:mt};Te(mt,yt,self.postMessage);export{li as plug};
|
|
//# sourceMappingURL=icalendar.plug.js.map
|