/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var O=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var st=(s,o)=>{for(var t in o)O(s,t,{get:o[t],enumerable:!0})},ot=(s,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of et(o))!nt.call(s,e)&&e!==t&&O(s,e,{get:()=>o[e],enumerable:!(n=tt(o,e))||n.enumerable});return s};var it=s=>ot(O({},"__esModule",{value:!0}),s);var gt={};st(gt,{default:()=>W});module.exports=it(gt);var T=require("obsidian");var H={debug:!1,hideResultWhileCursorInside:!0,verbose:!1};var k=require("obsidian");var w=require("obsidian"),at=/^([+-]\d+)\s*(d|days?|w|weeks?|mo|months?|y|years?|h|hours?|m|min|minutes?)$/i,rt={d:"days",day:"days",days:"days",w:"weeks",week:"weeks",weeks:"weeks",mo:"months",month:"months",months:"months",y:"years",year:"years",years:"years",h:"hours",hour:"hours",hours:"hours",m:"minutes",min:"minutes",minute:"minutes",minutes:"minutes"};function S(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,w.moment)({year:s.getUTCFullYear(),month:s.getUTCMonth(),day:s.getUTCDate()}).startOf("day"):(0,w.moment)(s);let o=String(s).trim(),t=o.toLowerCase();if(t==="now")return(0,w.moment)();if(t==="today")return(0,w.moment)().startOf("day");if(t==="tomorrow")return(0,w.moment)().add(1,"day").startOf("day");if(t==="yesterday")return(0,w.moment)().subtract(1,"day").startOf("day");let n=at.exec(o);if(n){let r=parseInt(n[1],10),a=rt[n[2].toLowerCase()];return(0,w.moment)().add(r,a)}let e=(0,w.moment)(o,"YYYY-MM-DD",!0);if(e.isValid())return e.startOf("day");let i=(0,w.moment)(o);return i.isValid()?i:null}function M(s,o,t){let n=s.clone(),e=o.clone(),i=e.isBefore(n);i&&([n,e]=[e,n]);let r=e.diff(n,"years");n.add(r,"years");let a=e.diff(n,"months");n.add(a,"months");let d=e.diff(n,"days");n.add(d,"days");let l=e.diff(n,"hours");n.add(l,"hours");let u=e.diff(n,"minutes");if(t){let c=[];return r&&c.push(`${r} year${r===1?"":"s"}`),a&&c.push(`${a} month${a===1?"":"s"}`),d&&c.push(`${d} day${d===1?"":"s"}`),l&&c.length<3&&c.push(`${l} hour${l===1?"":"s"}`),u&&c.length<3&&c.push(`${u} minute${u===1?"":"s"}`),{text:c.join(", ")||"0 minutes",isNegative:i}}else{let c=[];return r&&c.push(`${r}y`),a&&c.push(`${a}mo`),d&&c.push(`${d}d`),l&&c.length<3&&c.push(`${l}h`),u&&c.length<3&&c.push(`${u}m`),{text:c.join(" ")||"0m",isNegative:i}}}var z=require("obsidian");function _(s){let{verbose:o,...t}=s;if(o===void 0)return t;let n=typeof o=="boolean"?o:String(o).toLowerCase()==="true";return{...t,verbose:n}}function ct(s){let o={},t=/(\w+)=("([^"\\]|\\.)*"|'([^'\\]|\\.)*'|\S+)/g,n;for(;(n=t.exec(s))!==null;){let e=n[1],i=n[2];(i.startsWith('"')&&i.endsWith('"')||i.startsWith("'")&&i.endsWith("'"))&&(i=i.slice(1,-1)),o[e]=i}return o}function V(s){try{let o=(0,z.parseYaml)(s);return o==null?{}:typeof o=="string"?o:typeof o=="object"&&!Array.isArray(o)?_(o):s.trim()}catch(o){return s.trim()}}function j(s){return s?s.includes("=")?_(ct(s)):V(s):{}}function P(s,o){var i;let t=s.trim(),n=typeof o=="string"?{}:o,e=(typeof o=="string"?"":(i=o.type)!=null?i:"").toLowerCase().trim();return!e&&typeof o=="string"&&/^[A-Za-z][A-Za-z-]*$/.test(o.trim())&&(e=o.trim().toLowerCase(),n={}),!e&&/^[A-Za-z][A-Za-z-]*$/.test(t)&&(e=t.toLowerCase(),n={}),e||(n.birthday||n.birthdate?e="birthday":n.from&&n.to||n.start&&n.end?e="diff":n.to||n.until?e="countdown":(n.since||n.from)&&(e="since")),(e==="bday"||e==="age")&&(e="birthday"),(e==="until"||e==="remaining")&&(e="countdown"),e==="difference"&&(e="diff"),e==="elapsed"&&(e="since"),{type:e,cfg:n}}function G(s){var d,l;let o=s.split(` `);if(o.length<2)return null;let t=o[0].match(/^(\s*)(`{3,}|~{3,})(.*)$/);if(!t)return null;let n=t[2],i=((l=((d=t[3])!=null?d:"").trim().split(/\s+/)[0])!=null?l:"").toLowerCase();if(!o[o.length-1].trim().startsWith(n))return null;let a=o.slice(1,-1).join(` `);return{lang:i,body:a}}function b(s,o){let t=s==null?void 0:s[o];return typeof t=="string"||t instanceof Date?t:void 0}function Z(s,o,t,n,e){let i=o.verbose!==void 0?o.verbose:e;try{switch(s){case"birthday":return lt(o,t,n,i);case"countdown":return dt(o,t,n,i);case"diff":return ut(o,t,n,i);case"since":return ft(o,t,n,i);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 lt(s,o,t,n){var h,y,m,x,v,$,E;let e=(h=o.metadataCache.getCache(t))==null?void 0:h.frontmatter,i=(v=(x=(m=(y=s.birthday)!=null?y:s.birthdate)!=null?m:s.date)!=null?x:b(e,"birthday"))!=null?v:b(e,"birthdate"),r=($=S(i))==null?void 0:$.startOf("day");if(!r)return{text:'date-calc: Missing or invalid "birthday" date.'};let a=(0,k.moment)().startOf("day"),d=a.diff(r,"years"),l=r.clone().year(a.year());l.isBefore(a,"day")&&l.add(1,"year");let u=l.diff(a,"days"),c;if(u===0)c=n?"Wish them Happy Birthday!":"Happy bday!";else if(u===1)c=n?"Their birthday is tomorrow!":"Bday's tomorrow!";else if(u>31){let C=l.diff(a,"months");c=n?`Next birthday in ${C} months.`:`Next bday in ${C}mo`}else c=n?`Next birthday in ${u} days.`:`Next bday in ${u}d`;let g=n?`${d} years old`:`${d}y`,f=b(e,"name");return{text:`${(E=s.label)!=null?E:typeof f=="string"?`${f}'s age:`:"Age:"} ${g}. ${c}`,tooltip:r.format("MMMM Do, YYYY")}}function dt(s,o,t,n){var u,c,g,f,p;let e=(u=o.metadataCache.getCache(t))==null?void 0:u.frontmatter,i=S((p=(f=(g=(c=s.to)!=null?c:s.date)!=null?g:s.until)!=null?f:b(e,"to"))!=null?p:b(e,"deadline"));if(!i)return{text:'date-calc: Missing or invalid "to" date.'};let r=(0,k.moment)(),a=s.label?`${s.label} `:"",d=M(r,i,n);return{text:d.isNegative?`${a}${n?"Event passed ":""}${d.text}${n?" ago":""}`:`${a}${n?"Countdown: ":""}${d.text}`}}function ut(s,o,t,n){var l,u,c,g,f,p,h;let e=(l=o.metadataCache.getCache(t))==null?void 0:l.frontmatter,i=S((g=(c=(u=s.from)!=null?u:s.start)!=null?c:b(e,"from"))!=null?g:b(e,"start")),r=S((h=(p=(f=s.to)!=null?f:s.end)!=null?p:b(e,"to"))!=null?h:b(e,"end"));if(!i||!r)return{text:'date-calc: Provide valid "from" and "to" dates.'};let a=M(i,r,n);return{text:n?`Difference: ${a.text}${a.isNegative?" (to is before from)":""}`:`Diff: ${a.text}${a.isNegative?" (reverse)":""}`}}function ft(s,o,t,n){var l,u,c,g,f;let e=(l=o.metadataCache.getCache(t))==null?void 0:l.frontmatter,i=S((f=(g=(c=(u=s.since)!=null?u:s.from)!=null?c:s.date)!=null?g:b(e,"since"))!=null?f:b(e,"created"));if(!i)return{text:'date-calc: Missing or invalid "since" date.'};let r=(0,k.moment)(),a=M(i,r,n);return{text:a.isNegative?`In: ${a.text}`:`Since: ${a.text}${n?" ago":""}`}}function A(s,o,t,n){if(!/^date-calc\s*:/.test(s))return{text:""};let e=s.replace(/^date-calc\s*:/,"").trim(),i=j(e),r=P(e,i);return r.type?Z(r.type,r.cfg,o,t,n.verbose):{text:'date-calc: Missing or unrecognized "type" (birthday/countdown/diff/since).'}}function N(s,o,t,n){let e=V(s),i=P("",e);return i.type?Z(i.type,i.cfg,o,t,n.verbose):{text:'date-calc: Missing "type" (birthday/countdown/diff/since).'}}var K=require("@codemirror/state"),J=require("@codemirror/language"),D=require("@codemirror/view");var Y=require("@codemirror/view");function B(s,o){let t=document.createElement("span");return t.className="date-calc-inline",t.textContent=s,o&&(t.className+=" has-tooltip",t.setAttribute("aria-label",o)),t}var F=class extends Y.WidgetType{constructor(t,n,e,i){super();this.text=t;this.tooltip=n;this.from=e;this.to=i}eq(t){return t.text===this.text&&t.tooltip===this.tooltip}toDOM(){let t=B(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}},I=class extends Y.WidgetType{constructor(t,n){super();this.text=t;this.tooltip=n}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 q=/`date-calc:[^`]*`/g,L=2e3;function Q(s,o){return D.ViewPlugin.fromClass(class{constructor(t){this.decorations=D.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,c;let n=t.dom.closest(".markdown-source-view");if(!(n!=null&&n.classList.contains("is-live-preview")))return D.Decoration.none;let e=o(),i=(c=(u=s.workspace.getActiveFile())==null?void 0:u.path)!=null?c:"",r=t.state.selection.main,a=new Set,d=[];for(let g of t.visibleRanges){let f=Math.max(0,g.from-L),p=Math.min(t.state.doc.length,g.to+L),h=t.state.doc.sliceString(f,p);q.lastIndex=0;let y;for(;(y=q.exec(h))!==null;){let m=f+y.index,x=m+y[0].length,v=`inline:${m}:${x}`;if(a.has(v))continue;a.add(v);let $=r.from<=x&&r.to>=m;if(e.hideResultWhileCursorInside&&$)continue;let E=y[0].slice(1,-1).trim(),C=A(E,s,i,e);C.text&&d.push({from:m,to:x,deco:D.Decoration.replace({widget:new F(C.text,C.tooltip,m,x),inclusive:!1})})}}for(let g of t.visibleRanges){let f=Math.max(0,g.from-L),p=Math.min(t.state.doc.length,g.to+L);(0,J.syntaxTree)(t.state).iterate({from:f,to:p,enter:h=>{if(h.name!=="FencedCode")return;let y=h.from,m=h.to,x=`block:${y}:${m}`;if(a.has(x))return;a.add(x);let v=r.from<=m&&r.to>=y;if(e.hideResultWhileCursorInside&&v)return;let $=t.state.doc.sliceString(y,m),E=G($);if(!E||E.lang!=="date-calc")return;let C=N(E.body,s,i,e);C.text&&d.push({from:m,to:m,deco:D.Decoration.widget({widget:new I(C.text,C.tooltip),side:1,block:!0})})}})}e.debug&&console.log("[date-calc] decorations built",{sourcePath:i,count:d.length}),d.sort((g,f)=>g.from-f.from||g.to-f.to);let l=new K.RangeSetBuilder;for(let{from:g,to:f,deco:p}of d)l.add(g,f,p);return l.finish()}},{decorations:t=>t.decorations,eventHandlers:{mousedown:(t,n)=>{var a,d;let e=(d=(a=t.target)==null?void 0:a.closest)==null?void 0:d.call(a,".date-calc-inline");if(!e)return!1;let i=Number(e.dataset.dcFrom),r=Number(e.dataset.dcTo);return!Number.isFinite(i)||!Number.isFinite(r)?!1:(n.dispatch({selection:{anchor:i,head:r},scrollIntoView:!0}),n.focus(),!0)}},provide:t=>D.EditorView.atomicRanges.of(n=>{var e,i;return(i=(e=n.plugin(t))==null?void 0:e.decorations)!=null?i:D.Decoration.none})})}var R=require("obsidian"),X="https://gitea.mithrilforge.dev/olivier/date-calculator",U=class extends R.PluginSettingTab{constructor(t,n){super(t,n);this.plugin=n}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} Full syntax reference (README)",href:X}),new R.Setting(t).setName("Debug logging").setDesc("Logs decoration activity to the console.").addToggle(l=>l.setValue(this.plugin.settings.debug).onChange(async u=>{this.plugin.settings.debug=u,await this.plugin.saveData(this.plugin.settings)})),new R.Setting(t).setName("Hide result while cursor inside").setDesc("Prevents the widget from showing while you edit inline/fenced code.").addToggle(l=>l.setValue(this.plugin.settings.hideResultWhileCursorInside).onChange(async u=>{this.plugin.settings.hideResultWhileCursorInside=u,await this.plugin.saveData(this.plugin.settings)})),new R.Setting(t).setName("Verbose output").setDesc("When enabled, show longer/wordier messages. Can be overridden per-calculation with verbose=true/false.").addToggle(l=>l.setValue(this.plugin.settings.verbose).onChange(async u=>{this.plugin.settings.verbose=u,await this.plugin.saveData(this.plugin.settings)})),t.createEl("h3",{text:"Syntax at a glance"});let e=t.createDiv({cls:"date-calc-examples"});e.createEl("p",{text:"Use `date-calc: ...` inline, or a fenced ```date-calc block with type: set explicitly (or inferred from which fields you give)."});let i=e.createEl("ul"),r=(l,u,c,g)=>{let f=i.createEl("li");f.createEl("strong",{text:l}),f.appendText(` (${u}) \u2014 ${c} `),f.createEl("br"),f.createEl("code",{text:g})};r("birthday","bday, age","age + days until next birthday.","birthday/birthdate/date, label"),r("countdown","until, remaining","time until a date, always from now.","to/until/date, label"),r("since","elapsed","time since a date, always from now.","since/from/date"),r("diff","difference","time between two fixed dates (neither has to be now).","from/start, to/end"),e.createEl("h4",{text:"Relative dates"}),e.createEl("p",{text:"today, now, tomorrow, yesterday, or an offset like +7d / -3mo / +2w (always relative to now)."}),e.createEl("h4",{text:"Frontmatter fallback"}),e.createEl("p",{text:"Every type reads its date(s) from frontmatter if not given inline: birthday/birthdate, to/deadline, since/created, from/start + to/end."}),e.createEl("h4",{text:"Examples"});let a=e.createEl("ul");a.createEl("li").createEl("code",{text:"date-calc: birthday=1992-08-16"}),a.createEl("li").createEl("code",{text:'date-calc: to=2026-12-31 label="New Year:"'}),a.createEl("li").createEl("code",{text:"date-calc: since=2024-01-01"}),a.createEl("li").createEl("code",{text:"date-calc: from=2024-01-01 to=today"}),a.createEl("li").createEl("pre",{cls:"date-calc-example-block"}).setText('```date-calc\ntype: countdown\nto: +30d\nlabel: "Sprint:"\nverbose: true\n```');let d=e.createEl("p");d.appendText("Full field reference, custom styling, and more examples: "),d.createEl("a",{text:"README on Gitea",href:X}),d.appendText(".")}};var W=class extends T.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,n,e)=>{let i=N(t,this.app,e.sourcePath,this.settings);n.empty(),n.createDiv({cls:"date-calc-block",text:i.text}),i.tooltip&&n.setAttribute("aria-label",i.tooltip)}),this.registerMarkdownPostProcessor((t,n)=>{var i;let e=t.querySelectorAll("code");for(let r=0;r{this.settings.debug=!this.settings.debug,await this.saveData(this.settings),new T.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 T.Notice(`Date Calc verbose: ${this.settings.verbose?"ON":"OFF"}`)}}),this.addSettingTab(new U(this.app,this))}};