1!function(){"use strict";function t(t){if(t instanceof Date)return new Date(t.getFullYear(),t.getMonth(),t.getDate());let[e,n,a]=t.split("-").map(Number);return new Date(e,n-1,a)}function e(e,n){let a=t(e);return a.setDate(a.getDate()+n),a}function n(e,n){return Math.round((t(e).getTime()-t(n).getTime())/864e5)}function a(t,e,n){return Math.min(Math.max(t,e),n)}function o(t,e){return e.getTime()<t.getTime()?null:{start:t,end:e}}let r=["cramps","fatigue","mood_swings","nausea","headache","bloating","back_pain","cravings","breast_tenderness","acne","insomnia"],i={defaultCycleLength:28,defaultPeriodDuration:5,reminderEnabled:!1};function l(t){return!!(t&&/^\d{4}-\d{2}-\d{2}$/.test(t))}function c(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():"cycle-".concat(Date.now(),"-").concat(Math.random().toString(16).slice(2))}function s(t){return Array.from(new Set(t.map(t=>t.trim()).filter(Boolean)))}function d(){return{version:"1.0",cycles:[],customSymptoms:[],settings:i,lastUpdated:new Date().toISOString(),dismissedAnomalyKeys:[]}}function u(e){var o,i,d,u;let y=(u=(null!==(o=e.cycles)&&void 0!==o?o:[]).map(e=>(function(e){var n,a;if(!l(e.startDate))return null;let o=l(e.endDate)&&t(e.endDate).getTime()>=t(e.startDate).getTime()?e.endDate:void 0,r="spotting"===e.flowIntensity||"light"===e.flowIntensity||"medium"===e.flowIntensity||"heavy"===e.flowIntensity?e.flowIntensity:void 0,i=s(null!==(n=e.symptoms)&&void 0!==n?n:[]),d=e.createdAt||new Date().toISOString(),u=e.updatedAt||d;return{id:e.id||c(),startDate:e.startDate,endDate:o,flowIntensity:r,symptoms:i,notes:(null==(a=e.notes)?void 0:a.trim().slice(0,500))||void 0,cycleLength:e.cycleLength,createdAt:d,updatedAt:u}})(e)).filter(t=>!!t).sort((t,e)=>e.startDate.localeCompare(t.startDate))).map((e,a)=>{let o=u[a+1],r=o&&l(o.startDate)?n(t(e.startDate),t(o.startDate)):void 0;return{...e,cycleLength:r}});return{version:"1.0",cycles:y,customSymptoms:s([...null!==(i=e.customSymptoms)&&void 0!==i?i:[],...function(t){let e=new Set(r);return s(t.flatMap(t=>t.symptoms).filter(t=>!e.has(t))).slice(0,5)}(y)]).slice(0,5),settings:function(t,e){var n,o,r,i;let l=m(t),c=f(t);return{defaultCycleLength:a(Math.round(null!==(o=null!==(n=null==e?void 0:e.defaultCycleLength)&&void 0!==n?n:l)&&void 0!==o?o:28),21,45),defaultPeriodDuration:a(Math.round(null!==(i=null!==(r=null==e?void 0:e.defaultPeriodDuration)&&void 0!==r?r:c)&&void 0!==i?i:5),2,10),reminderEnabled:!!(null==e?void 0:e.reminderEnabled)}}(y,e.settings),lastUpdated:e.lastUpdated||new Date().toISOString(),dismissedAnomalyKeys:s(null!==(d=e.dismissedAnomalyKeys)&&void 0!==d?d:[])}}function y(t){let e=new Date().toISOString();return u({version:"1.0",cycles:t.map(t=>{var n;
1return{id:t.id||c(),startDate:t.startDate,endDate:t.endDate,symptoms:null!==(n=t.symptoms)&&void 0!==n?n:[],notes:t.notes,createdAt:e,updatedAt:e}}),customSymptoms:[],settings:i,lastUpdated:e})}function D(e){return e.endDate?n(t(e.endDate),t(e.startDate))+1:null}function m(t){let e=t.map(t=>t.cycleLength).filter(t=>"number"==typeof t);return e.length?Math.round(e.reduce((t,e)=>t+e,0)/e.length*10)/10:null}function f(t){let e=t.map(t=>D(t)).filter(t=>"number"==typeof t);return e.length?Math.round(e.reduce((t,e)=>t+e,0)/e.length*10)/10:null}function g(n){var r,i;let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:6;if(!(null==n?void 0:n.cycles.length))return[];let c=n.cycles[0],s=Math.round(null!==(r=m(n.cycles))&&void 0!==r?r:n.settings.defaultCycleLength),d=Math.round(null!==(i=f(n.cycles))&&void 0!==i?i:n.settings.defaultPeriodDuration);return function(n){let r=a(Math.round(n.cycleLength),21,45),i=a(Math.round(n.periodDuration),2,10),l=a(Math.round(n.monthsToPredict),3,12),c=t(n.lastPeriodDate),s=function(e,n){let a=t(e),o=a.getDate();a.setDate(1),a.setMonth(a.getMonth()+n);let r=new Date(a.getFullYear(),a.getMonth()+1,0).getDate();return a.setDate(Math.min(o,r)),a}(c,l),d=[],u=c,y=0;for(;u.getTime()<=s.getTime()&&y<18;)d.push(function(n,a,r,i){let l=t(n),c=e(l,r-1),s=e(l,a),d=e(s,-14),u=e(d,-5),y=e(d,1);return{cycleIndex:i,periodStart:l,periodEnd:c,ovulationDate:d,fertileWindowStart:u,fertileWindowEnd:y,safePeriodsBeforeOvulation:o(e(c,1),e(u,-1)),safePeriodsAfterOvulation:o(e(y,1),e(s,-1)),nextPeriodStart:s}}(u,r,i,y)),u=e(u,r),y+=1;return d}({lastPeriodDate:new Date(c.startDate),cycleLength:s,periodDuration:d,monthsToPredict:a(l,3,12)})}function p(t){return"".concat(t.getFullYear()).concat("".concat(t.getMonth()+1).padStart(2,"0")).concat("".concat(t.getDate()).padStart(2,"0"))}function v(t){var n;let{uid:a,title:o,start:r,end:i=r,description:l,category:c,alarmDaysBefore:s}=t,d=["BEGIN:VEVENT","UID:".concat(a),"DTSTAMP:".concat((n=new Date,"".concat(n.getUTCFullYear()).concat("".concat(n.getUTCMonth()+1).padStart(2,"0")).concat("".concat(n.getUTCDate()).padStart(2,"0"),"T").concat("".concat(n.getUTCHours()).padStart(2,"0")).concat("".concat(n.getUTCMinutes()).padStart(2,"0")).concat("".concat(n.getUTCSeconds()).padStart(2,"0"),"Z"))),"DTSTART;VALUE=DATE:".concat(p(r)),"DTEND;VALUE=DATE:".concat(p(e(i,1))),"SUMMARY:".concat(o),"DESCRIPTION:".concat(l.replace(/\n/g,"\\n")),"CATEGORIES:".concat(c)];return s&&d.push("BEGIN:VALARM","ACTION:DISPLAY","DESCRIPTION:".concat(o),"TRIGGER:-P".concat(s,"D"),"END:VALARM"),d.push("END:VEVENT"),d.join("\r\n")}self.addEventListener("message",t=>{var e;let{format:n,trackerData:a}=t.data,o=a&&"object"==typeof a?"version"in a&&"1.0"===a.version&&"cycles"in a?u(a):Array.isArray(a)?y(a):Array.isArray(null===(e=a.state)||void 0===e?void 0:e.entries)?y(a.state.entries):"cycles"in a?u(a):d():d();if("csv"===n){self.postMessage([["Cycle Start","Cycle End","Duration (days)","Cycle Length (days)","Flow","Symptoms","Notes"],...o.cycles.map(t=>{var e,n,a,o,r,i,l;return[t.startDate,null!==(a=t.endDate)&&void 0!==a?a:"",null!==(o=null===(e=D(t))||void 0===e?void 0:e.toString())&&void 0!==o?o:"",null!==(r=null===(n=t.cycleLength)||void 0===n?void 0:n.toString())&&void 0!==r?r:"â",(l=t.flowIntensity)?l.charAt(0).toUpperCase()+l.slice(1):"",t.symptoms.join(", "),null!==(i=t.notes)&&void 0!==i?i:""]})].map(t=>t.map(t=>'"'.concat(t.replace(/"/g,'""'),'"')).join(",")).join("\n"));return}if("json"===n){self.postMessage(JSON.stringify(function(t){var e,n;let a=m(t.cycles),o=f(t.cycles),r=t.cycles[t.cycles.length-1],i=t.cycles[0];return{version:"1.0",exportedAt:new Date().toISOString(),source:"https://periodcalculator.info/period-tracker",summary:{totalCycles:t.cycles.length,averageCycleLength:a,averagePeriodDuration:o,dateRange:{from:null!==(e=null==r?void 0:r.startDate)&&void 0!==e?e:null,to:null!==(n=null==i?void 0:i.startDate)&&void 0!==n?n:null}},cycles:t.cycles,customSymptoms:t.customSymptoms,settings:t.settings}}(o),null,2));return}let r=g(o,6);self.postMessage(function(t,e){var n;let a=(null==e?void 0:e.length)?e:g(t,6),o=null!==(n=m(t.cycles))&&void 0!==n?n:t.settings.defaultCycleLength;return["BEGIN:VCALENDAR","VERSION:2.0","PRODID:-//Period Calculator//Period Tracker//EN","CALSCALE:GREGORIAN","METHOD:PUBLISH",...a.slice(0,6).flatMap((t,e)=>[v({uid:"period-".concat(e,"-").concat(t.periodStart.toISOString(),"@periodcalculator.info"),title:"\uD83D\uDD34 Period Expected",start:t.periodStart,end:t.periodEnd,description:"Predicted period start based on your average ".concat(o.toFixed(1),"-day cycle."),category:"PERIOD",alarmDaysBefore:2}),v({uid:"ovulation-".concat(e,"-").concat(t.ovulationDate.toISOString(),"@periodcalculator.info"),title:"\uD83D\uDFE3 Estimated Ovulation Day",start:t.ovulationDate,description:"Estimated ovulation based on your tracked cycle data.",category:"OVULATION",alarmDaysBefore:1}),v({uid:"fertile-".concat(e,"-").concat(t.fertileWindowStart.toISOString(),"@periodcalculator.info"),title:"\uD83C\uDF38 Fertile Window",start:t.fertileWindowStart,end:t.fertileWindowEnd,description:"Estimated fertile window based on your tracked cycle data.",category:"FERTILE"})]),"END:VCALENDAR"].join("\r\n")}(o,r))})}(),_N_E={};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.