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