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