/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var M=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var H=(s,e)=>{for(var n in e)M(s,n,{get:e[n],enumerable:!0})},P=(s,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of I(e))!O.call(s,t)&&t!==n&&M(s,t,{get:()=>e[t],enumerable:!(i=B(e,t))||i.enumerable});return s};var z=s=>P(M({},"__esModule",{value:!0}),s);var et={};H(et,{dateCalcLivePreview:()=>L,default:()=>E,parseMoment:()=>C});module.exports=z(et);var g=require("obsidian"),A=require("@codemirror/state"),Y=require("@codemirror/language"),h=require("@codemirror/view"),j={debug:!1,hideResultWhileCursorInside:!0,verbose:!1};function Z(s){let e=s.dom.closest(".markdown-source-view");return!!(e!=null&&e.classList.contains("is-live-preview"))}function C(s){if(s==null||s==="")return null;if(s instanceof Date)return Number.isNaN(s.getTime())?null:s.getUTCHours()===0&&s.getUTCMinutes()===0&&s.getUTCSeconds()===0&&s.getUTCMilliseconds()===0?(0,g.moment)({year:s.getUTCFullYear(),month:s.getUTCMonth(),day:s.getUTCDate()}).startOf("day"):(0,g.moment)(s);let e=String(s).trim(),n=(0,g.moment)(e,"YYYY-MM-DD",!0);if(n.isValid())return n.startOf("day");let i=(0,g.moment)(e);return i.isValid()?i:null}function q(s){return s.format("MMMM Do, YYYY")}function R(s,e,n){let i=s.clone(),t=e.clone(),a=t.isBefore(i);a&&([i,t]=[t,i]);let o=t.diff(i,"years");i.add(o,"years");let r=t.diff(i,"months");i.add(r,"months");let c=t.diff(i,"days");i.add(c,"days");let d=t.diff(i,"hours");i.add(d,"hours");let u=t.diff(i,"minutes");if(n){let l=[];return o&&l.push(`${o} year${o===1?"":"s"}`),r&&l.push(`${r} month${r===1?"":"s"}`),c&&l.push(`${c} day${c===1?"":"s"}`),d&&l.length<3&&l.push(`${d} hour${d===1?"":"s"}`),u&&l.length<3&&l.push(`${u} minute${u===1?"":"s"}`),{text:l.join(", ")||"0 minutes",isNegative:a}}else{let l=[];return o&&l.push(`${o}y`),r&&l.push(`${r}mo`),c&&l.push(`${c}d`),d&&l.length<3&&l.push(`${d}h`),u&&l.length<3&&l.push(`${u}m`),{text:l.join(" ")||"0m",isNegative:a}}}function G(s){let e={},n=/(\w+)=("([^"\\]|\\.)*"|'([^'\\]|\\.)*'|\S+)/g,i;for(;(i=n.exec(s))!==null;){let t=i[1],a=i[2];(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),e[t]=a}return e}function F(s){if(!s)return{};if(s.includes("="))return G(s);try{let e=(0,g.parseYaml)(s);return e!=null?e:{}}catch(e){return s.trim()}}function U(s,e){var t;let n=s.trim(),i=((t=e==null?void 0:e.type)!=null?t:"").toString().toLowerCase().trim();return!i&&typeof e=="string"&&/^[A-Za-z][A-Za-z-]*$/.test(e.trim())&&(i=e.trim().toLowerCase(),e={}),!i&&/^[A-Za-z][A-Za-z-]*$/.test(n)&&(i=n.toLowerCase(),e={}),!i&&e&&typeof e=="object"&&(e.birthday||e.birthdate?i="birthday":e.to||e.until?i="countdown":e.since?i="since":e.from&&e.to&&(i="diff")),i==="bday"&&(i="birthday"),i==="until"&&(i="countdown"),i==="difference"&&(i="diff"),{type:i,cfg:e}}function V(s,e,n,i,t){let a=e.verbose!==void 0?e.verbose:t;try{switch(s){case"birthday":return K(e,n,i,a);case"countdown":return _(e,a);case"diff":return J(e,a);case"since":return Q(e,a);default:return{text:"date-calc: Unknown type. Supported: birthday, countdown, diff, since"}}}catch(o){return{text:`date-calc error: ${(o==null?void 0:o.message)||o}`}}}function K(s,e,n,i){var D,b;let t=e.metadataCache.getCache(n),a=(D=t==null?void 0:t.frontmatter)!=null?D:{},o=s.birthday||s.birthdate||s.date||(a==null?void 0:a.birthday)||(a==null?void 0:a.birthdate),r=(b=C(o))==null?void 0:b.startOf("day");if(!r)return{text:'date-calc: Missing or invalid "birthday" date.'};let c=(0,g.moment)().startOf("day"),d=c.diff(r,"years"),u=r.clone().year(c.year());u.isBefore(c,"day")&&u.add(1,"year");let l=u.diff(c,"days"),f;if(l===0)f=i?"Wish them Happy Birthday!":"Happy bday!";else if(l===1)f=i?"Their birthday is tomorrow!":"Bday's tomorrow!";else if(l>31){let p=u.diff(c,"months");f=i?`Next birthday in ${p} months.`:`Next bday in ${p}mo`}else f=i?`Next birthday in ${l} days.`:`Next bday in ${l}d`;return{text:`${i?`${d} years old`:`${d}y`}. ${f}`,tooltip:q(r)}}function _(s,e){var r;let n=C(s.to||s.date||s.until);if(!n)return{text:'date-calc: Missing or invalid "to" date.'};let i=(r=C(s.from))!=null?r:(0,g.moment)(),t=s.label?`${s.label}: `:"",a=R(i,n,e);return{text:a.isNegative?`${t}${e?"Event passed ":""}${a.text}${e?" ago":""}`:`${t}${e?"Countdown: ":""}${a.text}`}}function J(s,e){let n=C(s.from||s.start),i=C(s.to||s.end);if(!n||!i)return{text:'date-calc: Provide valid "from" and "to" dates.'};let t=R(n,i,e);return{text:e?`Difference: ${t.text}${t.isNegative?" (to is before from)":""}`:`Diff: ${t.text}${t.isNegative?" (reverse)":""}`}}function Q(s,e){let n=C(s.since||s.from||s.date);if(!n)return{text:'date-calc: Missing or invalid "since" date.'};let i=(0,g.moment)(),t=R(n,i,e);return{text:t.isNegative?`In: ${t.text}`:`Since: ${t.text}${e?" ago":""}`}}function X(s,e,n,i){if(!/^date-calc\s*:/.test(s))return{text:""};let t=s.replace(/^date-calc\s*:/,"").trim(),a=F(t),o=U(t,a);return o.type?V(o.type,o.cfg,e,n,i.verbose):{text:""}}function W(s,e,n,i){var o;let t={};try{t=(o=(0,g.parseYaml)(s))!=null?o:{}}catch(r){t=F(s.trim())}let a=U("",t);return a.type?V(a.type,a.cfg,e,n,i.verbose):{text:'date-calc: Missing "type" (birthday/countdown/diff/since).'}}var S=class extends h.WidgetType{constructor(n,i,t,a){super();this.text=n;this.tooltip=i;this.from=t;this.to=a}eq(n){return n.text===this.text&&n.tooltip===this.tooltip}toDOM(){let n=document.createElement("span");return n.className="date-calc-inline",n.textContent=this.text,n.setAttribute("contenteditable","false"),n.dataset.dcFrom=String(this.from),n.dataset.dcTo=String(this.to),this.tooltip&&(n.className+=" has-tooltip",n.setAttribute("aria-label",this.tooltip)),n}ignoreEvent(){return!1}},k=class extends h.WidgetType{constructor(n,i){super();this.text=n;this.tooltip=i}eq(n){return n.text===this.text&&n.tooltip===this.tooltip}toDOM(){let n=document.createElement("div");return n.className="date-calc-block",n.textContent=this.text,n.setAttribute("contenteditable","false"),this.tooltip&&n.setAttribute("aria-label",this.tooltip),n}};function tt(s){var c,d;let e=s.split(` `);if(e.length<2)return null;let n=e[0].match(/^(\s*)(`{3,}|~{3,})(.*)$/);if(!n)return null;let i=n[2],a=((d=((c=n[3])!=null?c:"").trim().split(/\s+/)[0])!=null?d:"").toLowerCase();if(!e[e.length-1].trim().startsWith(i))return null;let r=e.slice(1,-1).join(` `);return{lang:a,body:r}}function L(s,e){let n=/`date-calc:[^`]*`/g;return h.ViewPlugin.fromClass(class{constructor(t){this.decorations=h.Decoration.none;this.decorations=this.build(t)}update(t){(t.docChanged||t.viewportChanged||t.selectionSet)&&(this.decorations=this.build(t.view))}build(t){var u,l;if(!Z(t))return h.Decoration.none;let a=e(),o=(l=(u=s.workspace.getActiveFile())==null?void 0:u.path)!=null?l:"",r=t.state.selection.main,c=new A.RangeSetBuilder,d=new Set;for(let f of t.visibleRanges){let w=Math.max(0,f.from-2e3),D=Math.min(t.state.doc.length,f.to+2e3),b=t.state.doc.sliceString(w,D);n.lastIndex=0;let p;for(;(p=n.exec(b))!==null;){let m=w+p.index,y=m+p[0].length,$=`inline:${m}:${y}`;if(d.has($))continue;d.add($);let T=r.from<=y&&r.to>=m;if(a.hideResultWhileCursorInside&&T)continue;let v=p[0].slice(1,-1).trim(),x=X(v,s,o,a);x.text&&c.add(m,y,h.Decoration.replace({widget:new S(x.text,x.tooltip,m,y),inclusive:!1}))}}for(let f of t.visibleRanges){let w=Math.max(0,f.from-2e3),D=Math.min(t.state.doc.length,f.to+2e3);(0,Y.syntaxTree)(t.state).iterate({from:w,to:D,enter:b=>{if(b.name!=="FencedCode")return;let p=b.from,m=b.to,y=`block:${p}:${m}`;if(d.has(y))return;d.add(y);let $=r.from<=m&&r.to>=p;if(a.hideResultWhileCursorInside&&$)return;let T=t.state.doc.sliceString(p,m),v=tt(T);if(!v||v.lang!=="date-calc")return;let x=W(v.body,s,o,a);x.text&&c.add(m,m,h.Decoration.widget({widget:new k(x.text,x.tooltip),side:1,block:!0}))}})}return a.debug&&console.log("[date-calc] decorations built",{sourcePath:o}),c.finish()}},{decorations:t=>t.decorations,eventHandlers:{mousedown:(t,a)=>{var d,u;let o=(u=(d=t.target)==null?void 0:d.closest)==null?void 0:u.call(d,".date-calc-inline");if(!o)return!1;let r=Number(o.dataset.dcFrom),c=Number(o.dataset.dcTo);return!Number.isFinite(r)||!Number.isFinite(c)?!1:(a.dispatch({selection:{anchor:r,head:c},scrollIntoView:!0}),a.focus(),!0)}},provide:t=>h.EditorView.atomicRanges.of(a=>{var o,r;return(r=(o=a.plugin(t))==null?void 0:o.decorations)!=null?r:h.Decoration.none})})}var E=class extends g.Plugin{async onload(){this.settings=Object.assign({},j,await this.loadData()),this.settings.debug&&console.log("[date-calc] loaded"),this.registerEditorExtension(L(this.app,()=>this.settings)),this.registerMarkdownCodeBlockProcessor("date-calc",(n,i,t)=>{let a=W(n,this.app,t.sourcePath,this.settings);i.empty(),i.createDiv({cls:"date-calc-block",text:a.text}),a.tooltip&&i.setAttribute("aria-label",a.tooltip)}),this.addCommand({id:"date-calc-toggle-debug",name:"Date Calc: Toggle debug",callback:async()=>{this.settings.debug=!this.settings.debug,await this.saveData(this.settings),new g.Notice(`Date Calc debug: ${this.settings.debug?"ON":"OFF"}`)}}),this.addCommand({id:"date-calc-toggle-verbose",name:"Date Calc: Toggle verbose output",callback:async()=>{this.settings.verbose=!this.settings.verbose,await this.saveData(this.settings),new g.Notice(`Date Calc verbose: ${this.settings.verbose?"ON":"OFF"}`)}}),this.addSettingTab(new N(this.app,this))}},N=class extends g.PluginSettingTab{constructor(n,i){super(n,i);this.plugin=i}display(){let{containerEl:n}=this;n.empty(),n.createEl("h2",{text:"Date Calc"});let i=n.createDiv({cls:"setting-item-description"});i.createEl("a",{text:"\u{1F4D6} View Full Documentation",href:"https://github.com/thelegend09/date-calculator"}),i.style.marginBottom="1em",new g.Setting(n).setName("Debug logging").setDesc("Logs decoration activity to the console.").addToggle(u=>u.setValue(this.plugin.settings.debug).onChange(async l=>{this.plugin.settings.debug=l,await this.plugin.saveData(this.plugin.settings)})),new g.Setting(n).setName("Hide result while cursor inside").setDesc("Prevents the widget from showing while you edit inline/fenced code.").addToggle(u=>u.setValue(this.plugin.settings.hideResultWhileCursorInside).onChange(async l=>{this.plugin.settings.hideResultWhileCursorInside=l,await this.plugin.saveData(this.plugin.settings)})),new g.Setting(n).setName("Verbose output").setDesc("When enabled, show longer/wordier messages. Can be overridden per-calculation with verbose=true/false.").addToggle(u=>u.setValue(this.plugin.settings.verbose).onChange(async l=>{this.plugin.settings.verbose=l,await this.plugin.saveData(this.plugin.settings)})),n.createEl("h3",{text:"Usage Examples"});let t=n.createDiv({cls:"date-calc-examples"});t.style.fontSize="0.9em",t.style.lineHeight="1.6",t.createEl("h4",{text:"Inline Code (single backticks)"});let a=t.createEl("ul");a.createEl("li").setText("`date-calc: birthday=2003-02-15`"),a.createEl("li").setText('`date-calc: countdown to=2026-12-31 label="New Year"`'),a.createEl("li").setText("`date-calc: since=2024-01-01`"),a.createEl("li").setText("`date-calc: diff from=2024-01-01 to=2024-12-31`"),a.createEl("li").setText("`date-calc: birthday=1992-08-16 verbose=true`"),t.createEl("h4",{text:"Fenced Blocks (triple backticks)"});let o=t.createEl("pre");o.style.background="var(--background-secondary)",o.style.padding="8px",o.style.borderRadius="4px",o.style.marginBottom="8px",o.setText("```date-calc\ntype: birthday\nbirthday: 1992-08-16\n```");let r=t.createEl("pre");r.style.background="var(--background-secondary)",r.style.padding="8px",r.style.borderRadius="4px",r.style.marginBottom="8px",r.setText("```date-calc\ntype: countdown\nto: 2026-12-31 23:59\nlabel: New Year\nverbose: true\n```");let c=t.createEl("pre");c.style.background="var(--background-secondary)",c.style.padding="8px",c.style.borderRadius="4px",c.setText("```date-calc\ntype: diff\nfrom: 2024-01-01\nto: 2024-12-31\n```"),t.createEl("h4",{text:"Tips"});let d=t.createEl("ul");d.createEl("li").setText("Use YYYY-MM-DD format for dates"),d.createEl("li").setText("Add time with YYYY-MM-DD HH:mm for precise countdowns"),d.createEl("li").setText("Supported types: birthday, countdown, since, diff"),d.createEl("li").setText("Add verbose=true/false to override global setting")}};