From 47b5816b58c398dd801944753bde54fd70fa6c6c Mon Sep 17 00:00:00 2001
From: Thomas Peetz p)throw new Error(`Chunk size (${r}) is larger than the maximum chunk size (${p}). Please check your chunk separator.`);let w=await G(m,{chunk:z});Q.push(w)}let R=nh(b,c,Z,d,Y),J=["prompting",`${Q.length} prompts being sent.`];l.setMessage(J[0],J[1]);let E=new Nt(5,1e3*30),H=Promise.all(Q.map(z=>E.add(()=>R(z)))),k=(await Yt(H,100,z=>{l.setMessage(J[0],`${J[1]} (${(z/1e3).toFixed(2)}s)`)},z=>{l.setMessage("finished",`Took ${(z/1e3).toFixed(2)}s.`)})).map(z=>z.content).join(I.resultJoiner),f=("> "+k).replace(/\n/g,`
-> `),L={[W]:k,[`${W}-quoted`]:f};return setTimeout(()=>l.hide(),5e3),L}catch(c){throw l.setMessage("dead",c.message),setTimeout(()=>l.hide(),5e3),c}}var sd=require("obsidian"),TY=class b extends sd.Modal{constructor(G,l,c=[]){super(G);this.items=l;this.selectedItems=c;this._selectedItems=[...c],this.promise=new Promise((Z,W)=>{this.resolvePromise=Z,this.rejectPromise=W}),this.display(),this.open()}static Open(G,l,c){return new b(G,l,c).promise}display(){this.contentEl.empty(),this.containerEl.addClass("quickAddModal","checkboxPrompt"),this.addCheckboxRows(),this.addSubmitButton()}onClose(){super.onClose(),this.resolved||this.rejectPromise("no input given.")}addCheckboxRows(){let G=this.contentEl.createDiv("checkboxRowContainer");this.items.forEach(l=>this.addCheckboxRow(l,G))}addCheckboxRow(G,l){let c=l.createDiv("checkboxRow");c.createEl("span",{text:G}),new sd.ToggleComponent(c).setTooltip(`Toggle ${G}`).setValue(this._selectedItems.contains(G)).onChange(W=>{if(W)this._selectedItems.push(G);else{let d=this._selectedItems.findIndex(m=>G===m);this._selectedItems.splice(d,1)}})}addSubmitButton(){let G=this.contentEl.createDiv("submitButtonContainer");new sd.ButtonComponent(G).setButtonText("Submit").setCta().onClick(c=>{this.resolved=!0,this.resolvePromise(this._selectedItems),this.close()})}};var Fh=require("obsidian"),SY=class b extends Fh.Modal{constructor(G,l,c){super(G);this.header=l;this.text=c;this.waitForClose=new Promise(Z=>{this.resolvePromise=Z}),this.open(),this.display()}static Show(G,l,c){return new b(G,l,c).waitForClose}display(){this.contentEl.empty(),this.titleEl.textContent=this.header,String.isString(this.text)?this.contentEl.createEl("p",{text:this.text}):Array.isArray(this.text)&&this.text.forEach(c=>this.contentEl.createEl("p",{text:c}));let G=this.contentEl.createDiv(),l=new Fh.ButtonComponent(G).setButtonText("OK").onClick(()=>this.close());Object.assign(G.style,{display:"flex",justifyContent:"flex-end"}),l.buttonEl.focus()}onClose(){super.onClose(),this.resolvePromise()}};var wd=require("obsidian");var ZW=class b extends wd.Modal{constructor(G,l,c,Z,W){super(G);this.header=l;this.linkSourcePath=W;this.didSubmit=!1;this.submitClickCallback=G=>this.submit();this.cancelClickCallback=G=>this.cancel();this.submitEnterCallback=G=>{(G.ctrlKey||G.metaKey)&&G.key==="Enter"&&(G.preventDefault(),this.submit())};this.placeholder=c??"",this.input=Z??"",this.waitForClose=new Promise((d,m)=>{this.resolvePromise=d,this.rejectPromise=m}),this.display(),this.open(),this.fileSuggester=new ed(G,this.inputComponent.inputEl,{sourcePath:this.linkSourcePath}),this.tagSuggester=new Qd(G,this.inputComponent.inputEl)}static Prompt(G,l,c,Z){return new b(G,l,c,Z,void 0).waitForClose}static PromptWithContext(G,l,c,Z,W){return new b(G,l,c,Z,W).waitForClose}display(){this.containerEl.addClass("quickAddModal","qaWideInputPrompt"),this.contentEl.empty(),this.titleEl.textContent=this.header;let G=this.contentEl.createDiv();this.inputComponent=this.createInputField(G,this.placeholder,this.input),this.createButtonBar(G)}createInputField(G,l,c){let Z=new wd.TextAreaComponent(G);return Z.inputEl.classList.add("wideInputPromptInputEl"),Z.inputEl.setAttribute("dir","auto"),Z.setPlaceholder(l??"").setValue(c??"").onChange(W=>this.input=W).inputEl.addEventListener("keydown",this.submitEnterCallback),Z}createButton(G,l,c){let Z=new wd.ButtonComponent(G);return Z.setButtonText(l).onClick(c),Z}createButtonBar(G){let l=G.createDiv();this.createButton(l,"Ok",this.submitClickCallback).setCta().buttonEl.style.marginRight="0",this.createButton(l,"Cancel",this.cancelClickCallback),l.style.display="flex",l.style.flexDirection="row-reverse",l.style.justifyContent="flex-start",l.style.marginTop="1rem",l.style.gap="0.5rem"}escapeBackslashes(G){return G.replace(/\\/g,"\\\\")}submit(){this.didSubmit||(this.didSubmit=!0,this.input=this.escapeBackslashes(this.input),this.close())}cancel(){this.close()}resolveInput(){this.didSubmit?this.resolvePromise(this.input):this.rejectPromise("No input given.")}removeInputListener(){this.inputComponent.inputEl.removeEventListener("keydown",this.submitEnterCallback)}onOpen(){super.onOpen(),this.inputComponent.inputEl.focus(),this.inputComponent.inputEl.select()}onClose(){super.onClose(),this.resolveInput(),this.removeInputListener()}};var fY=require("obsidian"),hb=class b extends fY.Modal{constructor(G,l,c){super(G);this.header=l;this.text=c;this.didSubmit=!1;this.waitForClose=new Promise((Z,W)=>{this.resolvePromise=Z,this.rejectPromise=W}),this.open(),this.display()}static Prompt(G,l,c){return new b(G,l,c).waitForClose}display(){this.containerEl.addClass("quickAddModal","qaYesNoPrompt"),this.contentEl.empty(),this.titleEl.textContent=this.header,this.contentEl.createEl("p",{text:this.text});let G=this.contentEl.createDiv({cls:"yesNoPromptButtonContainer"}),l=new fY.ButtonComponent(G).setButtonText("No").onClick(()=>this.submit(!1)),c=new fY.ButtonComponent(G).setButtonText("Yes").onClick(()=>this.submit(!0)).setWarning();c.buttonEl.focus(),ei([l.buttonEl,c.buttonEl])}submit(G){this.input=G,this.didSubmit=!0,this.close()}onClose(){super.onClose(),this.didSubmit?this.resolvePromise(this.input):this.rejectPromise("No answer given.")}};function ei(b){b.forEach(I=>{I.addEventListener("keydown",G=>{if(G.key==="ArrowRight"||G.key==="ArrowLeft"){let c=(b.indexOf(I)+(G.key==="ArrowRight"?1:-1)+b.length)%b.length;b[c].focus(),G.preventDefault()}})})}var mG=require("obsidian");var vd=class{static parse(I){let G=I.split("|").map(Z=>Z.trim()),l=G[0],c={};for(let Z=1;Zp)throw new Error(`Chunk size (${r}) is larger than the maximum chunk size (${p}). Please check your chunk separator.`);let w=await G(m,{chunk:z});Q.push(w)}let R=nh(b,c,Z,d,Y),J=["prompting",`${Q.length} prompts being sent.`];l.setMessage(J[0],J[1]);let E=new mt(5,1e3*30),H=Promise.all(Q.map(z=>E.add(()=>R(z)))),k=(await Nt(H,100,z=>{l.setMessage(J[0],`${J[1]} (${(z/1e3).toFixed(2)}s)`)},z=>{l.setMessage("finished",`Took ${(z/1e3).toFixed(2)}s.`)})).map(z=>z.content).join(I.resultJoiner),f=("> "+k).replace(/\n/g,`
+> `),L={[W]:k,[`${W}-quoted`]:f};return setTimeout(()=>l.hide(),5e3),L}catch(c){throw l.setMessage("dead",c.message),setTimeout(()=>l.hide(),5e3),c}}var sd=require("obsidian"),TY=class b extends sd.Modal{constructor(G,l,c=[]){super(G);this.items=l;this.selectedItems=c;this._selectedItems=[...c],this.promise=new Promise((Z,W)=>{this.resolvePromise=Z,this.rejectPromise=W}),this.display(),this.open()}static Open(G,l,c){return new b(G,l,c).promise}display(){this.contentEl.empty(),this.containerEl.addClass("quickAddModal","checkboxPrompt"),this.addCheckboxRows(),this.addSubmitButton()}onClose(){super.onClose(),this.resolved||this.rejectPromise("no input given.")}addCheckboxRows(){let G=this.contentEl.createDiv("checkboxRowContainer");this.items.forEach(l=>this.addCheckboxRow(l,G))}addCheckboxRow(G,l){let c=l.createDiv("checkboxRow");c.createEl("span",{text:G}),new sd.ToggleComponent(c).setTooltip(`Toggle ${G}`).setValue(this._selectedItems.contains(G)).onChange(W=>{if(W)this._selectedItems.push(G);else{let d=this._selectedItems.findIndex(m=>G===m);this._selectedItems.splice(d,1)}})}addSubmitButton(){let G=this.contentEl.createDiv("submitButtonContainer");new sd.ButtonComponent(G).setButtonText("Submit").setCta().onClick(c=>{this.resolved=!0,this.resolvePromise(this._selectedItems),this.close()})}};var Fh=require("obsidian"),SY=class b extends Fh.Modal{constructor(G,l,c){super(G);this.header=l;this.text=c;this.waitForClose=new Promise(Z=>{this.resolvePromise=Z}),this.open(),this.display()}static Show(G,l,c){return new b(G,l,c).waitForClose}display(){this.contentEl.empty(),this.titleEl.textContent=this.header,String.isString(this.text)?this.contentEl.createEl("p",{text:this.text}):Array.isArray(this.text)&&this.text.forEach(c=>this.contentEl.createEl("p",{text:c}));let G=this.contentEl.createDiv(),l=new Fh.ButtonComponent(G).setButtonText("OK").onClick(()=>this.close());Object.assign(G.style,{display:"flex",justifyContent:"flex-end"}),l.buttonEl.focus()}onClose(){super.onClose(),this.resolvePromise()}};var wd=require("obsidian");var ZW=class b extends wd.Modal{constructor(G,l,c,Z,W){super(G);this.header=l;this.linkSourcePath=W;this.didSubmit=!1;this.submitClickCallback=G=>this.submit();this.cancelClickCallback=G=>this.cancel();this.submitEnterCallback=G=>{(G.ctrlKey||G.metaKey)&&G.key==="Enter"&&(G.preventDefault(),this.submit())};this.placeholder=c??"",this.input=Z??"",this.waitForClose=new Promise((d,m)=>{this.resolvePromise=d,this.rejectPromise=m}),this.display(),this.open(),this.fileSuggester=new ed(G,this.inputComponent.inputEl,{sourcePath:this.linkSourcePath}),this.tagSuggester=new Qd(G,this.inputComponent.inputEl)}static Prompt(G,l,c,Z){return new b(G,l,c,Z,void 0).waitForClose}static PromptWithContext(G,l,c,Z,W){return new b(G,l,c,Z,W).waitForClose}display(){this.containerEl.addClass("quickAddModal","qaWideInputPrompt"),this.contentEl.empty(),this.titleEl.textContent=this.header;let G=this.contentEl.createDiv();this.inputComponent=this.createInputField(G,this.placeholder,this.input),this.createButtonBar(G)}createInputField(G,l,c){let Z=new wd.TextAreaComponent(G);return Z.inputEl.classList.add("wideInputPromptInputEl"),Z.inputEl.setAttribute("dir","auto"),Z.setPlaceholder(l??"").setValue(c??"").onChange(W=>this.input=W).inputEl.addEventListener("keydown",this.submitEnterCallback),Z}createButton(G,l,c){let Z=new wd.ButtonComponent(G);return Z.setButtonText(l).onClick(c),Z}createButtonBar(G){let l=G.createDiv();this.createButton(l,"Ok",this.submitClickCallback).setCta().buttonEl.style.marginRight="0",this.createButton(l,"Cancel",this.cancelClickCallback),l.style.display="flex",l.style.flexDirection="row-reverse",l.style.justifyContent="flex-start",l.style.marginTop="1rem",l.style.gap="0.5rem"}escapeBackslashes(G){return G.replace(/\\/g,"\\\\")}submit(){this.didSubmit||(this.didSubmit=!0,this.input=this.escapeBackslashes(this.input),this.close())}cancel(){this.close()}resolveInput(){this.didSubmit?this.resolvePromise(this.input):this.rejectPromise("No input given.")}removeInputListener(){this.inputComponent.inputEl.removeEventListener("keydown",this.submitEnterCallback)}onOpen(){super.onOpen(),this.inputComponent.inputEl.focus(),this.inputComponent.inputEl.select()}onClose(){super.onClose(),this.resolveInput(),this.removeInputListener()}};var fY=require("obsidian"),hb=class b extends fY.Modal{constructor(G,l,c){super(G);this.header=l;this.text=c;this.didSubmit=!1;this.waitForClose=new Promise((Z,W)=>{this.resolvePromise=Z,this.rejectPromise=W}),this.open(),this.display()}static Prompt(G,l,c){return new b(G,l,c).waitForClose}display(){this.containerEl.addClass("quickAddModal","qaYesNoPrompt"),this.contentEl.empty(),this.titleEl.textContent=this.header,this.contentEl.createEl("p",{text:this.text});let G=this.contentEl.createDiv({cls:"yesNoPromptButtonContainer"}),l=new fY.ButtonComponent(G).setButtonText("No").onClick(()=>this.submit(!1)),c=new fY.ButtonComponent(G).setButtonText("Yes").onClick(()=>this.submit(!0)).setWarning();c.buttonEl.focus(),ei([l.buttonEl,c.buttonEl])}submit(G){this.input=G,this.didSubmit=!0,this.close()}onClose(){super.onClose(),this.didSubmit?this.resolvePromise(this.input):this.rejectPromise("No answer given.")}};function ei(b){b.forEach(I=>{I.addEventListener("keydown",G=>{if(G.key==="ArrowRight"||G.key==="ArrowLeft"){let c=(b.indexOf(I)+(G.key==="ArrowRight"?1:-1)+b.length)%b.length;b[c].focus(),G.preventDefault()}})})}var mG=require("obsidian");var vd=class{static parse(I){let G=I.split("|").map(Z=>Z.trim()),l=G[0],c={};for(let Z=1;Z
Select choices to bundle. Dependencies are added automatically.
',l=K(),c=v("section"),Z=v("input"),d=K(),m=v("div"),N=v("button"),N.textContent="Select visible",Y=K(),a=v("button"),a.textContent="Clear selection",V=K(),h=v("section"),II.c(),n=K(),X=v("section"),p=v("h3"),p.textContent="Package summary",e=K(),Q=v("div"),s=v("div"),R=v("strong"),E=NI(J),H=K(),g=v("span"),g.textContent="Selected choices",C=K(),k=v("div"),f=v("strong"),z=NI(L),r=K(),w=v("span"),w.textContent="Total packaged",i=K(),o=v("div"),B=v("strong"),_=NI(j),YI=K(),aI=v("span"),aI.textContent="Auto-included",QI=K(),vI=v("div"),tI=v("strong"),EI=NI(VI),_I=K(),RG=v("span"),RG.textContent="Scripts embedded",EG=K(),tG=v("div"),eb=v("strong"),Bl=NI(Ul),Yl=K(),al=v("span"),al.textContent="Templates embedded",T=K(),P&&P.c(),LI=K(),hI&&hI.c(),xI=K(),KI=v("section"),Pl=v("div"),Vl=v("button"),lG.c(),rc=K(),nc=v("div"),_l=v("label"),Lc=v("span"),Lc.textContent="Save to file",hZ=K(),kc=v("div"),Qb=v("input"),Aa=K(),Hb=v("button"),OG.c(),tm=K(),RZ=v("section"),ub=v("button"),ra=NI("Cancel"),t(G,"class","svelte-iqd8ho"),t(Z,"type","text"),t(Z,"placeholder","Filter choices"),t(Z,"autocapitalize","off"),t(Z,"autocorrect","off"),t(Z,"spellcheck",W=!1),t(Z,"class","svelte-iqd8ho"),t(N,"type","button"),t(N,"class","svelte-iqd8ho"),t(a,"type","button"),t(a,"class","svelte-iqd8ho"),t(m,"class","controlButtons svelte-iqd8ho"),t(c,"class","controls svelte-iqd8ho"),t(h,"class","choiceList svelte-iqd8ho"),t(p,"class","svelte-iqd8ho"),t(R,"class","svelte-iqd8ho"),t(s,"class","svelte-iqd8ho"),t(f,"class","svelte-iqd8ho"),t(k,"class","svelte-iqd8ho"),t(B,"class","svelte-iqd8ho"),t(o,"class","svelte-iqd8ho"),t(tI,"class","svelte-iqd8ho"),t(vI,"class","svelte-iqd8ho"),t(eb,"class","svelte-iqd8ho"),t(tG,"class","svelte-iqd8ho"),t(Q,"class","summaryGrid svelte-iqd8ho"),t(X,"class","summary svelte-iqd8ho"),t(Vl,"type","button"),t(Vl,"class","secondary svelte-iqd8ho"),Vl.disabled=Ol=b[5]!==null,t(Pl,"class","actionGroup svelte-iqd8ho"),t(Qb,"type","text"),t(Qb,"placeholder","QuickAdd Packages/quickadd-package-YYYY-MM-DD.quickadd.json"),t(Qb,"class","svelte-iqd8ho"),t(Hb,"type","button"),Hb.disabled=nZ=b[5]!==null,t(Hb,"class","svelte-iqd8ho"),t(kc,"class","saveRow svelte-iqd8ho"),t(nc,"class","actionGroup svelte-iqd8ho"),t(KI,"class","actions svelte-iqd8ho"),t(ub,"type","button"),t(ub,"class","secondary svelte-iqd8ho"),ub.disabled=u=b[5]!==null,t(RZ,"class","footer svelte-iqd8ho"),t(I,"class","exportPackageModal svelte-iqd8ho")},m(MG,FG){cI(MG,I,FG),F(I,G),F(I,l),F(I,c),F(c,Z),DI(Z,b[1]),F(c,d),F(c,m),F(m,N),F(m,Y),F(m,a),F(I,V),F(I,h),II.m(h,null),F(I,n),F(I,X),F(X,p),F(X,e),F(X,Q),F(Q,s),F(s,R),F(R,E),F(s,H),F(s,g),F(Q,C),F(Q,k),F(k,f),F(f,z),F(k,r),F(k,w),F(Q,i),F(Q,o),F(o,B),F(B,_),F(o,YI),F(o,aI),F(Q,QI),F(Q,vI),F(vI,tI),F(tI,EI),F(vI,_I),F(vI,RG),F(Q,EG),F(Q,tG),F(tG,eb),F(eb,Bl),F(tG,Yl),F(tG,al),F(X,T),P&&P.m(X,null),F(I,LI),hI&&hI.m(I,null),F(I,xI),F(I,KI),F(KI,Pl),F(Pl,Vl),lG.m(Vl,null),F(KI,rc),F(KI,nc),F(nc,_l),F(_l,Lc),F(_l,hZ),F(_l,kc),F(kc,Qb),DI(Qb,b[3]),F(kc,Aa),F(kc,Hb),OG.m(Hb,null),F(I,tm),F(I,RZ),F(RZ,ub),F(ub,ra),A||(x=[S(Z,"input",b[21]),S(N,"click",b[11]),S(a,"click",b[12]),S(Vl,"click",b[13]),S(Qb,"input",b[24]),S(Hb,"click",b[14]),S(ub,"click",function(){gI(b[0])&&b[0].apply(this,arguments)})],A=!0)},p(MG,FG){b=MG,FG[0]&2&&Z.value!==b[1]&&DI(Z,b[1]),$===($=D(b,FG))&&II?II.p(b,FG):(II.d(1),II=$(b),II&&(II.c(),II.m(h,null))),FG[0]&256&&J!==(J=b[8].rootCount+"")&&sI(E,J),FG[0]&256&&L!==(L=b[8].totalChoices+"")&&sI(z,L),FG[0]&256&&j!==(j=b[8].dependencyCount+"")&&sI(_,j),FG[0]&256&&VI!==(VI=b[8].userScripts+b[8].conditionalScripts+"")&&sI(EI,VI),FG[0]&256&&Ul!==(Ul=b[8].templateFiles+b[8].captureTemplates+"")&&sI(Bl,Ul),b[8].missingChoiceIds.length>0?P?P.p(b,FG):(P=ov(b),P.c(),P.m(X,null)):P&&(P.d(1),P=null),b[4]?hI?hI.p(b,FG):(hI=Cv(b),hI.c(),hI.m(I,xI)):hI&&(hI.d(1),hI=null),JG!==(JG=$I(b,FG))&&(lG.d(1),lG=JG(b),lG&&(lG.c(),lG.m(Vl,null))),FG[0]&32&&Ol!==(Ol=b[5]!==null)&&(Vl.disabled=Ol),FG[0]&8&&Qb.value!==b[3]&&DI(Qb,b[3]),BG!==(BG=$l(b,FG))&&(OG.d(1),OG=BG(b),OG&&(OG.c(),OG.m(Hb,null))),FG[0]&32&&nZ!==(nZ=b[5]!==null)&&(Hb.disabled=nZ),FG[0]&32&&u!==(u=b[5]!==null)&&(ub.disabled=u)},i:SI,o:SI,d(MG){MG&&lI(I),II.d(),P&&P.d(),hI&&hI.d(),lG.d(),OG.d(),A=!1,uI(x)}}}function rv(b,I=[],G=0,l=null){let c=[];for(let Z of b){let W=[...I,Z.name];c.push({choice:Z,id:Z.id,path:W,depth:G,parentId:l}),Lv(Z)&&c.push(...rv(Z.choices??[],W,G+1,Z.id))}return c}function Lv(b){return b.type==="Multi"}function jL(b,I){let G=I.trim().toLowerCase();return G?b.filter(l=>`${l.path.join(" ")} ${l.choice.type}`.toLowerCase().includes(G)):b}function kv(b){let I=[];if(Lv(b)){let G=b.choices??[];for(let l of G)I.push(l.id,...kv(l))}return I}function KL(b,I){let G=[];for(let l of b)I.has(l.id)&&(!l.parentId||!I.has(l.parentId))&&G.push(l.id);return G}function DL(b){let{missingChoiceIds:I,missingAssets:G}=b;return I.length===0&&G.length===0?null:{missingChoices:I,missingAssets:G}}async function TL(b){if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(b);return}let I=document.createElement("textarea");I.value=b,I.setAttribute("readonly","true"),I.style.position="fixed",I.style.opacity="0",document.body.appendChild(I),I.focus(),I.select();let G=document.execCommand("copy");if(document.body.removeChild(I),!G)throw new Error("Clipboard copy is not supported in this environment.")}function SL(b,I,G){let l,c,Z,W,{app:d}=I,{plugin:m}=I,{allChoices:N}=I,{close:Y}=I,a={"user-script":"User script","conditional-script":"Conditional script",template:"Template file","capture-template":"Capture template"},V="",h=new Set,n=new Set,X=[],p=Hv(),e=null,Q=null;function s(w,i){let o=[w.id,...kv(w)];if(i){let B=new Set(h);for(let j of o)B.add(j);if(G(2,h=B),n.size>0){let j=new Set(n);for(let _ of o)j.delete(_);G(18,n=j)}}else{let B=new Set(h);for(let _ of o)B.delete(_);G(2,h=B);let j=new Set(n);for(let _ of o)j.add(_);G(18,n=j)}}function R(w){let i=l.find(B=>B.id===w);if(!i)return;let o=h.has(w);s(i.choice,!o),G(4,e=null)}function J(){for(let w of c)s(w.choice,!0);G(4,e=null)}function E(){G(2,h=new Set),G(18,n=new Set),G(4,e=null)}function H(w,i,o){if(i.length===0)return{rootCount:0,totalChoices:0,dependencyCount:0,missingChoiceIds:[],userScripts:0,conditionalScripts:0,templateFiles:0,captureTemplates:0};let B=M2(w,i,{excludedChoiceIds:o}),j=j2(B.catalog,B.choiceIds),_=K2(B.catalog,B.choiceIds);return{rootCount:i.length,totalChoices:B.choiceIds.length,dependencyCount:Math.max(B.choiceIds.length-i.length,0),missingChoiceIds:B.missingChoiceIds,userScripts:j.userScriptPaths.size,conditionalScripts:j.conditionalScriptPaths.size,templateFiles:_.templatePaths.size,captureTemplates:_.captureTemplatePaths.size}}async function g(){if(X.length===0)return new Vc.Notice("Select at least one choice to export."),null;try{let w=await uv(d,{choices:N,rootChoiceIds:X,excludedChoiceIds:Array.from(n),quickAddVersion:m.manifest.version});return G(4,e=DL(w)),w}catch(w){return console.error(w),G(4,e=null),new Vc.Notice(`Export failed: ${w?.message??String(w)}`),null}}async function C(){if(!Q){G(5,Q="copy");try{let w=await g();if(!w)return;let i=JSON.stringify(w.pkg,null,2);await TL(i),new Vc.Notice(`Copied package (${w.pkg.choices.length} choice${w.pkg.choices.length===1?"":"s"}) to clipboard.`),e?new Vc.Notice("Package copied with warnings. Review details below."):Y()}catch(w){console.error(w),new Vc.Notice(`Copy failed: ${w?.message??String(w)}`)}finally{G(5,Q=null)}}}async function k(){if(Q)return;let w=p.trim();if(!w){new Vc.Notice("Enter a file path before saving.");return}G(5,Q="save");try{let i=await g();if(!i)return;await wv(d,i.pkg,w),new Vc.Notice(`Saved package (${i.pkg.choices.length} choice${i.pkg.choices.length===1?"":"s"}) to '${w}'.`),e?new Vc.Notice("Package saved with warnings. Review details below."):Y()}catch(i){console.error(i),new Vc.Notice(`Save failed: ${i?.message??String(i)}`)}finally{G(5,Q=null)}}function f(){V=this.value,G(1,V)}let L=w=>R(w.id),z=w=>W.get(w)??w;function r(){p=this.value,G(3,p)}return b.$$set=w=>{"app"in w&&G(15,d=w.app),"plugin"in w&&G(16,m=w.plugin),"allChoices"in w&&G(17,N=w.allChoices),"close"in w&&G(0,Y=w.close)},b.$$.update=()=>{b.$$.dirty[0]&131072&&G(20,l=rv(N)),b.$$.dirty[0]&1048578&&G(6,c=jL(l,V)),b.$$.dirty[0]&1048580&&G(19,X=KL(l,h)),b.$$.dirty[0]&917504&&G(8,Z=H(N,X,n)),b.$$.dirty[0]&1048576&&G(7,W=new Map(l.map(w=>[w.id,w.path.join(" / ")])))},[Y,V,h,p,e,Q,c,W,Z,a,R,J,E,C,k,d,m,N,n,X,l,f,L,z,r]}var BX=class extends oI{constructor(I){super(),zI(this,I,SL,ML,kI,{app:15,plugin:16,allChoices:17,close:0},LL,[-1,-1])}},zv=BX;var S2=class extends xv.Modal{constructor(G,l,c){super(G);this.plugin=l;this.choices=c;this.component=null}onOpen(){this.modalEl.addClass("quickAddModal","packageExportModal"),this.component=new zv({target:this.contentEl,props:{app:this.app,plugin:this.plugin,allChoices:this.choices,close:()=>this.close()}})}onClose(){this.component&&(this.component.$destroy(),this.component=null)}};var bE=require("obsidian");var QW=require("obsidian");var Uv=require("obsidian");function Bv(b){let I;try{I=JSON.parse(b)}catch(G){throw new Error(`Package content is not valid JSON: ${G?.message??G}`)}if(!nv(I))throw new Error("Content is not a valid QuickAdd package.");if(I.schemaVersion>1)throw new Error(`Package schema version ${I.schemaVersion} is newer than this plugin supports (${1}).`);return I}async function Ov(b,I,G){let l=new Map(Lb(I).map(W=>[W.id,W])),c=G.choices.map(W=>({choiceId:W.choice.id,name:W.choice.name,parentChoiceId:W.parentChoiceId,pathHint:W.pathHint??[],exists:l.has(W.choice.id)})),Z=[];for(let W of G.assets){let d=await b.vault.adapter.exists(W.originalPath);Z.push({originalPath:W.originalPath,exists:d,kind:W.kind})}return{choiceConflicts:c,assetConflicts:Z}}async function Mv(b){let{app:I,existingChoices:G,pkg:l}=b,c=new Map(b.choiceDecisions.map(H=>[H.choiceId,H.mode])),Z=new Map(b.assetDecisions.map(H=>[H.originalPath,H])),W=new Map(l.choices.map(H=>[H.choice.id,H])),d=new Set,m=new Map,N=new Set,Y=H=>{if(m.has(H))return m.get(H);if(N.has(H))return!0;if(N.add(H),c.get(H)==="skip")return m.set(H,!1),N.delete(H),!1;let C=W.get(H);if(!C)return m.set(H,!1),N.delete(H),!1;let k=C.parentChoiceId;if(!k||!W.has(k)||c.get(k)==="skip")return m.set(H,!0),N.delete(H),!0;let L=Y(k);return m.set(H,L),N.delete(H),L};for(let H of l.choices)Y(H.choice.id)&&d.add(H.choice.id);let a=new Set,V=new Map,h=H=>{if(!d.has(H))return!1;if(a.has(H))return!0;if(c.get(H)==="duplicate")return a.add(H),!0;let k=W.get(H)?.parentChoiceId??null;return k&&(c.get(k)==="duplicate"||d.has(k)&&h(k))?(a.add(H),!0):!1};for(let H of l.choices){if(!d.has(H.choice.id))continue;let C=h(H.choice.id)?tl():H.choice.id;V.set(H.choice.id,C)}let n=cG(G),X=[],p=[],e=[],Q=new Map;for(let H of l.choices){if(!d.has(H.choice.id)){e.push(H.choice.id);continue}let g=cG(H.choice),C=jX(g,V,d);Q.set(H.choice.id,C)}let s=new Set;for(let H of l.choices){let g=H.choice.id;if(!d.has(g)||s.has(g))continue;let C=Q.get(g);if(!C)continue;let k=C.id,f=c.get(g)??"import",L=H.parentChoiceId;if(L&&d.has(L)?Q.get(L):null){s.add(g);continue}if((f==="overwrite"||f==="import")&&jv(n,C)){p.push(k),s.add(g);continue}if(L){let w=V.get(L)??L;if(Kv(n,w,C)){X.push(k),s.add(g);continue}let o=qL(n,H.pathHint.slice(0,-1));if(o){Dv(o,C),X.push(k),s.add(g);continue}M.logWarning(`QuickAdd import: could not locate parent for '${H.choice.name}'. Adding to root.`)}let r=n.findIndex(w=>w.id===k);r!==-1?(n.splice(r,1,C),p.push(k)):(n.push(C),X.push(k)),s.add(g)}let R=new Map,J=[],E=[];for(let H of l.assets){let g=Z.get(H.originalPath),C=g?.destinationPath?.trim(),k=C?(0,Uv.normalizePath)(C):H.originalPath,f=await fL(I,k);if((g?.mode??(f?"overwrite":"write"))==="skip"){E.push(k);continue}await PL(I,k);let z=ev(H.content);await I.vault.adapter.write(k,z),J.push(k),R.set(H.originalPath,k)}for(let H of Q.values())KX(H,R);return{updatedChoices:n,addedChoiceIds:X,overwrittenChoiceIds:p,skippedChoiceIds:e,writtenAssets:J,skippedAssets:E}}async function fL(b,I){try{return await b.vault.adapter.exists(I)}catch{return!1}}function jX(b,I,G){let l=b.id,c=I.get(l)??l;b.id=c;let Z=c!==l;if(b.type==="Macro"){let W=b;Z&&(W.macro.id=tl()),OX(W.macro.commands,I,G,Z)}if(b.type==="Multi"){let W=b;Array.isArray(W.choices)&&(W.choices=W.choices.filter(d=>G.has(d.id)).map(d=>jX(d,I,G)))}return b}function OX(b,I,G,l){for(let c of b)if(c)switch(l&&(c.id=tl()),c.type){case"Choice":{let Z=c,W=I.get(Z.choiceId);W&&(Z.choiceId=W);break}case"Conditional":{let Z=c;OX(Z.thenCommands,I,G,l),OX(Z.elseCommands,I,G,l);break}case"NestedChoice":{let Z=c;Z.choice&&G.has(Z.choice.id)&&(Z.choice=jX(Z.choice,I,G));break}default:break}}function jv(b,I){for(let G=0;GSelect a package file, review conflicts, and choose how to import each item.
',l=K(),c=v("section"),Z=v("label"),W=v("span"),W.textContent="Paste package JSON",d=K(),m=v("textarea"),N=K(),E&&E.c(),Y=K(),H&&H.c(),a=K(),V=v("section"),h=v("button"),n=NI("Cancel"),X=K(),p=v("button"),k.c(),t(G,"class","svelte-x9dt2q"),t(W,"class","svelte-x9dt2q"),t(m,"placeholder","Paste the contents of a .quickadd.json package here"),t(m,"rows","8"),t(m,"class","svelte-x9dt2q"),t(Z,"class","svelte-x9dt2q"),t(c,"class","pasteSection svelte-x9dt2q"),t(h,"type","button"),t(h,"class","secondary svelte-x9dt2q"),h.disabled=b[4],t(p,"type","button"),t(p,"class","primary svelte-x9dt2q"),p.disabled=e=b[4]||!b[1]||!b[2],t(V,"class","footer svelte-x9dt2q"),t(I,"class","importPackageModal svelte-x9dt2q")},m(f,L){cI(f,I,L),F(I,G),F(I,l),F(I,c),F(c,Z),F(Z,W),F(Z,d),F(Z,m),DI(m,b[8]),F(c,N),E&&E.m(c,null),F(I,Y),H&&H.m(I,null),F(I,a),F(I,V),F(V,h),F(h,n),F(V,X),F(V,p),k.m(p,null),Q||(s=[S(m,"input",b[19]),S(m,"input",b[16]),S(h,"click",function(){gI(b[0])&&b[0].apply(this,arguments)}),S(p,"click",function(){gI(b[10]?b[0]:b[17])&&(b[10]?b[0]:b[17]).apply(this,arguments)})],Q=!0)},p(f,L){b=f,L[0]&256&&DI(m,b[8]),J===(J=R(b,L))&&E?E.p(b,L):(E&&E.d(1),E=J&&J(b),E&&(E.c(),E.m(c,null))),b[1]&&b[2]?H?H.p(b,L):(H=fv(b),H.c(),H.m(I,a)):H&&(H.d(1),H=null),L[0]&16&&(h.disabled=b[4]),C!==(C=g(b,L))&&(k.d(1),k=C(b),k&&(k.c(),k.m(p,null))),L[0]&22&&e!==(e=b[4]||!b[1]||!b[2])&&(p.disabled=e)},i:SI,o:SI,d(f){f&&lI(I),E&&E.d(),H&&H.d(),k.d(),Q=!1,uI(s)}}}function N3(b,I){let G=I.destinationExists;return I.mode==="skip"?{className:"assetBadge--info",label:"Skipped"}:I.mode==="overwrite"?{className:G?"assetBadge--warning":"assetBadge--info",label:G?"Will overwrite":"Overwrite"}:{className:G?"assetBadge--warning":"assetBadge--info",label:G?"Will overwrite":"New file"}}function GE(b){return!b||b.length===0?"Root":b.slice(0,-1).join(" \u203A ")||"Root"}function Y3(b,I,G){let{app:l}=I,{close:c}=I,Z=null,W=null,d=null,m=!1,N=null,Y=new Map,a=new Map,V="",h=!1,n=0,X=!1;function p(i){let o=dI.getState().templateFolderPath?.trim(),B=i.kind==="template"||i.kind==="capture-template";if(o&&B){let j=i.originalPath.split("/").pop()??i.originalPath,_=o.replace(/\/+$/,"");return _?`${_}/${j}`:j}return i.originalPath}function e(i){let o=i.trim();if(!o)return!1;let B=(0,QW.normalizePath)(o);return!!l.vault.getAbstractFileByPath(B)}function Q(){if(G(6,Y=new Map),G(7,a=new Map),!!W){for(let i of W.choiceConflicts){let o=i.exists?"overwrite":"import";Y.set(i.choiceId,o)}for(let i of W.assetConflicts){let o=p(i),B=i.exists||e(o),j=B?"overwrite":"write";a.set(i.originalPath,{mode:j,destinationPath:o,destinationExists:B})}}}function s(i,o){let B=new Map(Y);B.set(i,o),G(6,Y=B)}function R(i,o){let j={...a.get(i)??{mode:o,destinationPath:i,destinationExists:e(i)},mode:o},_=new Map(a);_.set(i,j),G(7,a=_)}function J(i,o){let B=a.get(i.originalPath)??{mode:"write",destinationPath:i.originalPath,destinationExists:e(i.originalPath)},j=o.trim(),_=j||i.originalPath,YI=j||o,aI=e(_),QI=B.mode;B.mode!=="skip"&&(aI&&B.mode==="write"?QI="overwrite":!aI&&B.mode==="overwrite"&&(QI="write"));let vI={...B,mode:QI,destinationPath:YI,destinationExists:aI},tI=new Map(a);tI.set(i.originalPath,vI),G(7,a=tI)}function E(i,o){let j=o.currentTarget.value;s(i,j)}function H(i,o){let j=o.currentTarget.value;R(i,j)}function g(i,o){let B=o.currentTarget.value;J(i,B)}async function C(i){let o=i.trim(),B=++n;if(G(5,N=null),G(10,X=!1),!o){G(1,Z=null),G(2,W=null),G(6,Y=new Map),G(7,a=new Map),G(3,d=null);return}G(9,h=!0);try{let j=Bv(o),_=await Ov(l,dI.getState().choices,j);if(B!==n)return;G(1,Z={pkg:j,path:"[pasted]"}),G(2,W=_),G(3,d=null),Q()}catch(j){if(B!==n)return;G(3,d=j?.message??String(j)),G(1,Z=null),G(2,W=null),G(6,Y=new Map),G(7,a=new Map)}finally{B===n&&G(9,h=!1)}}function k(i){let o=i.currentTarget.value;G(8,V=o),C(o)}async function f(){if(X){new QW.Notice("This package has already been imported.");return}if(!Z||!W){new QW.Notice("Load a package before importing.");return}G(4,m=!0),G(5,N=null);try{let i=W.choiceConflicts.map(j=>{let _=Y.get(j.choiceId)??"import",YI=j.exists||_!=="overwrite"?_:"import";return{choiceId:j.choiceId,mode:YI}}),o=W.assetConflicts.map(j=>{let _=a.get(j.originalPath),YI=_?.destinationPath?.trim()||j.originalPath,aI=_?.destinationExists??(j.exists?!0:e(YI)),QI=_?.mode??(aI?"overwrite":"write");return{originalPath:j.originalPath,destinationPath:YI,mode:QI}}),B=await Mv({app:l,existingChoices:dI.getState().choices,pkg:Z.pkg,choiceDecisions:i,assetDecisions:o});dI.setState(j=>({...j,choices:B.updatedChoices})),G(5,N={added:B.addedChoiceIds.length,overwritten:B.overwrittenChoiceIds.length,skipped:B.skippedChoiceIds.length,assetsWritten:B.writtenAssets.length,assetsSkipped:B.skippedAssets.length}),G(10,X=!0),new QW.Notice(`Imported ${B.addedChoiceIds.length+B.overwrittenChoiceIds.length} choice${B.addedChoiceIds.length+B.overwrittenChoiceIds.length===1?"":"s"} successfully.`)}catch(i){console.error(i),new QW.Notice(`Import failed: ${i?.message??i}`)}finally{G(4,m=!1)}}function L(){V=this.value,G(8,V)}let z=(i,o)=>E(i.choiceId,o),r=(i,o)=>g(i,o),w=(i,o)=>H(i.originalPath,o);return b.$$set=i=>{"app"in i&&G(18,l=i.app),"close"in i&&G(0,c=i.close)},[c,Z,W,d,m,N,Y,a,V,h,X,p,e,E,H,g,k,f,l,L,z,r,w]}var DX=class extends oI{constructor(I){super(),zI(this,I,Y3,m3,kI,{app:18,close:0},_L,[-1,-1])}},lE=DX;var f2=class extends bE.Modal{constructor(G){super(G);this.component=null}onOpen(){this.modalEl.addClass("quickAddModal","packageImportModal"),this.component=new lE({target:this.contentEl,props:{app:this.app,close:()=>this.close()}})}onClose(){this.component?.$destroy(),this.component=null}};var ja={choices:[],inputPrompt:"single-line",devMode:!1,templateFolderPath:"",announceUpdates:"all",version:"0.0.0",globalVariables:{},onePageInputEnabled:!1,disableOnlineFeatures:!0,enableRibbonIcon:!1,showCaptureNotification:!0,showInputCancellationNotification:!1,enableTemplatePropertyTypes:!1,ai:{defaultModel:"Ask me",defaultSystemPrompt:'As an AI assistant within Obsidian, your primary goal is to help users manage their ideas and knowledge more effectively. Format your responses using Markdown syntax. Please use the [[Obsidian]] link format. You can write aliases for the links by writing [[Obsidian|the alias after the pipe symbol]]. To use mathematical notation, use LaTeX syntax. LaTeX syntax for larger equations should be on separate lines, surrounded with double dollar signs ($$). You can also inline math expressions by wrapping it in $ symbols. For example, use $$w_{ij}^{ ext{new}}:=w_{ij}^{ ext{current}}+etacdotdelta_jcdot x_{ij}$$ on a separate line, but you can write "($eta$ = learning rate, $delta_j$ = error term, $x_{ij}$ = input)" inline.',promptTemplatesFolderPath:"",showAssistant:!0,providers:B2},migrations:{migrateToMacroIDFromEmbeddedMacro:!0,useQuickAddTemplateFolder:!1,incrementFileNameSettingMoveToDefaultBehavior:!1,mutualExclusionInsertAfterAndWriteToBottomOfFile:!1,setVersionAfterUpdateModalRelease:!1,addDefaultAIProviders:!1,removeMacroIndirection:!1,migrateFileOpeningSettings:!1,setProviderModelDiscoveryMode:!1}},q2=class extends Zl.PluginSettingTab{constructor(I,G){super(I,G),this.plugin=G}display(){let{containerEl:I}=this;I.empty(),I.createEl("h2",{text:"QuickAdd Settings"}),this.addChoicesSetting(),this.addPackagesSetting(),this.addUseMultiLineInputPromptSetting(),this.addTemplateFolderPathSetting(),this.addAnnounceUpdatesSetting(),this.addShowCaptureNotificationSetting(),this.addShowInputCancellationNotificationSetting(),this.addTemplatePropertyTypesSetting(),this.addGlobalVariablesSetting(),this.addOnePageInputSetting(),this.addDisableOnlineFeaturesSetting(),this.addEnableRibbonIconSetting(),this.addDevelopmentInfoSetting()}addDevelopmentInfoSetting(){}addGlobalVariablesSetting(){let I=new Zl.Setting(this.containerEl);I.infoEl.remove(),I.settingEl.style.display="block",new av({target:I.settingEl,props:{app:this.app,plugin:this.plugin}})}addAnnounceUpdatesSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Announce Updates"),I.setDesc("Display release notes when a new version is installed. This includes new features, demo videos, and bug fixes."),I.addDropdown(G=>{let l=dI.getState().announceUpdates;G.addOption("all","Show updates on each new release").addOption("major","Show updates only on major releases (new features, breaking changes)").addOption("none","Don't show").setValue(l).onChange(c=>{dI.setState({announceUpdates:c})})})}addShowCaptureNotificationSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Show Capture Notifications"),I.setDesc("Display a notification when content is captured successfully to confirm the operation completed."),I.addToggle(G=>{G.setValue(dI.getState().showCaptureNotification),G.onChange(l=>{dI.setState({showCaptureNotification:l})})})}addShowInputCancellationNotificationSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Show Input Cancellation Notifications"),I.setDesc("Display a notification when an input prompt is cancelled without submitting. Disable this to avoid extra notices when dismissing prompts."),I.addToggle(G=>{G.setValue(dI.getState().showInputCancellationNotification),G.onChange(l=>{dI.setState({showInputCancellationNotification:l})})})}addTemplatePropertyTypesSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Format template variables as proper property types (Beta)"),I.setDesc("When enabled, template variables in front matter will be formatted as proper Obsidian property types. Arrays become List properties, numbers become Number properties, booleans become Checkbox properties, etc. This is a beta feature that may have edge cases."),I.addToggle(G=>{G.setValue(dI.getState().enableTemplatePropertyTypes),G.onChange(l=>{dI.setState({enableTemplatePropertyTypes:l})})})}hide(){this.choiceView&&this.choiceView.$destroy()}addChoicesSetting(){let I=new Zl.Setting(this.containerEl);I.infoEl.remove(),I.settingEl.style.display="block",this.choiceView=new mv({target:I.settingEl,props:{app:this.app,plugin:this.plugin,choices:dI.getState().choices,saveChoices:G=>{dI.setState({choices:G})}}})}addPackagesSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Packages"),I.setDesc("Bundle or import QuickAdd automations as reusable packages."),I.addButton(G=>G.setButtonText("Export package\u2026").setCta().onClick(()=>{let l=dI.getState().choices;new S2(this.app,this.plugin,l).open()})),I.addButton(G=>G.setButtonText("Import package\u2026").onClick(()=>{new f2(this.app).open()}))}addUseMultiLineInputPromptSetting(){new Zl.Setting(this.containerEl).setName("Use Multi-line Input Prompt").setDesc("Use multi-line input prompt instead of single-line input prompt").addToggle(I=>I.setValue(this.plugin.settings.inputPrompt==="multi-line").setTooltip("Use multi-line input prompt").onChange(G=>{G?dI.setState({inputPrompt:"multi-line"}):dI.setState({inputPrompt:"single-line"})}))}addTemplateFolderPathSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Template Folder Path"),I.setDesc("Path to the folder where templates are stored. Used to suggest template files when configuring QuickAdd."),I.addText(G=>{G.setPlaceholder("templates/").setValue(dI.getState().templateFolderPath).onChange(l=>{dI.setState({templateFolderPath:l})}),new Xl(this.app,G.inputEl,this.app.vault.getAllLoadedFiles().filter(l=>l instanceof Zl.TFolder&&l.path!=="/").map(l=>l.path))})}addOnePageInputSetting(){new Zl.Setting(this.containerEl).setName("One-page input for choices (Beta)").setDesc("Experimental. Resolve variables up front and show a single dynamic form before executing Template/Capture choices. See Advanced \u2192 One-page Inputs in docs.").addToggle(I=>I.setValue(dI.getState().onePageInputEnabled).onChange(G=>{dI.setState({onePageInputEnabled:G})}))}addDisableOnlineFeaturesSetting(){new Zl.Setting(this.containerEl).setName("Disable AI & Online features").setDesc("This prevents the plugin from making requests to external providers like OpenAI. You can still use User Scripts to execute arbitrary code, including contacting external providers. However, this setting disables plugin features like the AI Assistant from doing so. You need to disable this setting to use the AI Assistant.").addToggle(I=>I.setValue(dI.getState().disableOnlineFeatures).onChange(G=>{dI.setState({disableOnlineFeatures:G}),this.display()}))}addEnableRibbonIconSetting(){new Zl.Setting(this.containerEl).setName("Show icon in sidebar").setDesc("Add QuickAdd icon to the sidebar ribbon. Requires a reload.").addToggle(I=>{I.setValue(dI.getState().enableRibbonIcon).onChange(G=>{dI.setState({enableRibbonIcon:G}),this.display()})})}};var hm=class{formatOutputString(I){return`QuickAdd: (${I.level}) ${I.message}`}getQuickAddError(I,G,l,c){return{message:I,level:G,time:Date.now(),stack:l,originalError:c}}};var Ja=class extends hm{constructor(){super(...arguments);this.ErrorLog=[]}logError(G,l,c){let Z=this.getQuickAddError(G,"ERROR",l,c);this.addMessageToErrorLog(Z);let W=c||new Error(G);console.error(this.formatOutputString(Z),W)}logWarning(G,l,c){let Z=this.getQuickAddError(G,"WARNING",l,c);this.addMessageToErrorLog(Z);let W=c||new Error(G);console.warn(this.formatOutputString(Z),W)}logMessage(G,l,c){let Z=this.getQuickAddError(G,"LOG",l,c);this.addMessageToErrorLog(Z),c?console.log(this.formatOutputString(Z),c):console.log(this.formatOutputString(Z))}addMessageToErrorLog(G){this.ErrorLog.push(G),this.ErrorLog.length>QF&&(this.ErrorLog=this.ErrorLog.slice(-QF))}clearErrorLog(){this.ErrorLog=[]}};var TX=require("obsidian");var P2=class extends hm{constructor(G){super();this.plugin=G}logError(G,l,c){let Z=this.getQuickAddError(G,"ERROR",l,c);new TX.Notice(this.formatOutputString(Z),15e3)}logWarning(G,l,c){let Z=this.getQuickAddError(G,"WARNING",l,c);new TX.Notice(this.formatOutputString(Z))}logMessage(G,l,c){}};var _2=class{constructor(I,G,l,c){this.app=I;this.plugin=G;this.choices=l;this.choiceExecutor=c}async run(){let I=Lb(this.choices).filter(G=>G.type==="Macro"&&G.runOnStartup);for(let G of I)await new cc(this.app,this.plugin,G,this.choiceExecutor,new Map).run()}};var cE=require("obsidian");var $2=class extends qd{constructor(I,G,l,c){super(I,G,c),this.choiceExecutor=c,this.choice=l}async run(){try{Dl(this.choice.templatePath,()=>`Invalid template path for ${this.choice.name}. ${this.choice.templatePath.length===0?"Template path is empty.":`Template path is not valid: ${this.choice.templatePath}`}`);let I=qc(this.choice.appendLink);this.setLinkToCurrentFileBehavior(I.enabled&&!I.requireActiveFile?"optional":"required");let G="";if(this.choice.folder.enabled)G=await this.getFolderPath();else{let m=this.app.fileManager.getNewFileParent(this.app.workspace.getActiveFile()?.path??"");G=m===this.app.vault.getRoot()?"":m.path}let l=this.choice.fileNameFormat.enabled?this.choice.fileNameFormat.format:QZ,c=await this.formatter.formatFileName(l,this.choice.name),Z=this.normalizeTemplateFilePath(G,c,this.choice.templatePath);this.choice.fileExistsMode===sZ&&(Z=await this.incrementFileName(Z));let W,d=!1;if(await this.app.vault.adapter.exists(Z)){let m=this.app.vault.getAbstractFileByPath(Z);if(!(m instanceof cE.TFile)||m.extension!=="md"&&m.extension!=="canvas"){M.logError(`'${Z}' already exists and is not a valid markdown or canvas file.`);return}let N=this.choice.fileExistsMode;if(!this.choice.setFileExistsBehavior)try{N=await Fl.Suggest(this.app,[...on],[...on])}catch(Y){throw XG(Y)?new qI("Input cancelled by user"):Y}switch(N){case zW:W=await this.appendToFileWithTemplate(m,this.choice.templatePath,"top");break;case kW:W=await this.appendToFileWithTemplate(m,this.choice.templatePath,"bottom");break;case xW:W=await this.overwriteFileWithTemplate(m,this.choice.templatePath);break;case wZ:W=m,d=!0,M.logMessage(`Opening existing file: ${m.path}`);break;case sZ:{let Y=await this.incrementFileName(Z);W=await this.createFileWithTemplate(Y,this.choice.templatePath);break}default:M.logWarning("File not written to.");return}}else if(W=await this.createFileWithTemplate(Z,this.choice.templatePath),!W){M.logWarning(`Could not create file '${Z}'.`);return}if(I.enabled&&W&&rV(this.app,W,I),(this.choice.openFile||d)&&W){let m=this.choice.fileOpening.focus??!0;LV(this.app,W,m)||await ad(this.app,W,this.choice.fileOpening),await AV(this.app,W)}}catch(I){if(WZ(I,{logPrefix:"Template execution aborted",noticePrefix:"Template execution aborted",defaultReason:"Template execution aborted"})){this.choiceExecutor.signalAbort?.(I);return}IG(I,`Error running template choice "${this.choice.name}"`)}}async formatFolderPaths(I){return await Promise.all(I.map(async l=>await this.formatter.formatFolderPath(l)))}async getFolderPath(){let I=await this.formatFolderPaths([...this.choice.folder.folders]);if(this.choice.folder?.chooseFromSubfolders&&!(this.choice.folder?.chooseWhenCreatingNote||this.choice.folder?.createInSameFolderAsActiveFile)){let l=rY(this.app).filter(c=>I.some(Z=>c.startsWith(Z)));return await this.getOrCreateFolder(l)}if(this.choice.folder?.chooseWhenCreatingNote){let G=rY(this.app);return await this.getOrCreateFolder(G)}if(this.choice.folder?.createInSameFolderAsActiveFile){let G=this.app.workspace.getActiveFile();return!G||!G.parent?(M.logWarning("No active file or active file has no parent. Cannot create file in same folder as active file. Creating in root folder."),""):this.getOrCreateFolder([G.parent.path])}return await this.getOrCreateFolder(I)}};var Ip=require("obsidian");var In=class{isResolved(){return!this.hasConflicts}isConflicted(){return this.hasConflicts}},ya=class b extends In{constructor(I,G,l){super(),this.left=I,this.base=G,this.right=l,this.hasConflicts=!0}static create(I){return new b(I.left,I.base,I.right)}apply(I){return b.create({left:I(this.left),base:I(this.base),right:I(this.right)})}},pb=class b extends In{constructor(I){super(),this.hasConflicts=!1,this.result=I}combine(I){this.result=this.result.concat(I.result)}apply(I){return new b(I(this.result))}};var ic=class b{constructor(I,G){this.left=I,this.right=G}static executeDiff(I,G){if(!I.push)throw new Error("Argument is not an array");let l=b.diff(I,G);return new fX(I,G,l).convertToTypedOutput()}static diff(I,G){return new b(I,G).performDiff()}performDiff(){let I=this.identifyUniquePositions();I.sort((Z,W)=>W[0]-Z[0]);let[G,l]=this.findNextChange(),c=new Gn(G,l,[]);return I.forEach(Z=>{c=this.getDifferences(c,Z)}),c.changeRanges}getDifferences(I,G){let[l,c]=[I.leftChangePos,I.rightChangePos],[Z,W]=G;if(ZSelect choices to bundle. Dependencies are added automatically.
',l=K(),c=v("section"),Z=v("input"),d=K(),m=v("div"),N=v("button"),N.textContent="Select visible",Y=K(),a=v("button"),a.textContent="Clear selection",V=K(),h=v("section"),II.c(),n=K(),X=v("section"),p=v("h3"),p.textContent="Package summary",e=K(),Q=v("div"),s=v("div"),R=v("strong"),E=NI(J),H=K(),g=v("span"),g.textContent="Selected choices",C=K(),k=v("div"),f=v("strong"),z=NI(L),r=K(),w=v("span"),w.textContent="Total packaged",i=K(),o=v("div"),B=v("strong"),_=NI(j),YI=K(),aI=v("span"),aI.textContent="Auto-included",QI=K(),vI=v("div"),tI=v("strong"),EI=NI(VI),_I=K(),RG=v("span"),RG.textContent="Scripts embedded",EG=K(),tG=v("div"),eb=v("strong"),Bl=NI(Ul),Yl=K(),al=v("span"),al.textContent="Templates embedded",T=K(),P&&P.c(),LI=K(),hI&&hI.c(),xI=K(),KI=v("section"),Pl=v("div"),Vl=v("button"),lG.c(),rc=K(),nc=v("div"),_l=v("label"),Lc=v("span"),Lc.textContent="Save to file",hZ=K(),kc=v("div"),Qb=v("input"),Aa=K(),Hb=v("button"),OG.c(),tm=K(),RZ=v("section"),ub=v("button"),ra=NI("Cancel"),t(G,"class","svelte-iqd8ho"),t(Z,"type","text"),t(Z,"placeholder","Filter choices"),t(Z,"autocapitalize","off"),t(Z,"autocorrect","off"),t(Z,"spellcheck",W=!1),t(Z,"class","svelte-iqd8ho"),t(N,"type","button"),t(N,"class","svelte-iqd8ho"),t(a,"type","button"),t(a,"class","svelte-iqd8ho"),t(m,"class","controlButtons svelte-iqd8ho"),t(c,"class","controls svelte-iqd8ho"),t(h,"class","choiceList svelte-iqd8ho"),t(p,"class","svelte-iqd8ho"),t(R,"class","svelte-iqd8ho"),t(s,"class","svelte-iqd8ho"),t(f,"class","svelte-iqd8ho"),t(k,"class","svelte-iqd8ho"),t(B,"class","svelte-iqd8ho"),t(o,"class","svelte-iqd8ho"),t(tI,"class","svelte-iqd8ho"),t(vI,"class","svelte-iqd8ho"),t(eb,"class","svelte-iqd8ho"),t(tG,"class","svelte-iqd8ho"),t(Q,"class","summaryGrid svelte-iqd8ho"),t(X,"class","summary svelte-iqd8ho"),t(Vl,"type","button"),t(Vl,"class","secondary svelte-iqd8ho"),Vl.disabled=Ol=b[5]!==null,t(Pl,"class","actionGroup svelte-iqd8ho"),t(Qb,"type","text"),t(Qb,"placeholder","QuickAdd Packages/quickadd-package-YYYY-MM-DD.quickadd.json"),t(Qb,"class","svelte-iqd8ho"),t(Hb,"type","button"),Hb.disabled=nZ=b[5]!==null,t(Hb,"class","svelte-iqd8ho"),t(kc,"class","saveRow svelte-iqd8ho"),t(nc,"class","actionGroup svelte-iqd8ho"),t(KI,"class","actions svelte-iqd8ho"),t(ub,"type","button"),t(ub,"class","secondary svelte-iqd8ho"),ub.disabled=u=b[5]!==null,t(RZ,"class","footer svelte-iqd8ho"),t(I,"class","exportPackageModal svelte-iqd8ho")},m(MG,FG){cI(MG,I,FG),F(I,G),F(I,l),F(I,c),F(c,Z),DI(Z,b[1]),F(c,d),F(c,m),F(m,N),F(m,Y),F(m,a),F(I,V),F(I,h),II.m(h,null),F(I,n),F(I,X),F(X,p),F(X,e),F(X,Q),F(Q,s),F(s,R),F(R,E),F(s,H),F(s,g),F(Q,C),F(Q,k),F(k,f),F(f,z),F(k,r),F(k,w),F(Q,i),F(Q,o),F(o,B),F(B,_),F(o,YI),F(o,aI),F(Q,QI),F(Q,vI),F(vI,tI),F(tI,EI),F(vI,_I),F(vI,RG),F(Q,EG),F(Q,tG),F(tG,eb),F(eb,Bl),F(tG,Yl),F(tG,al),F(X,T),P&&P.m(X,null),F(I,LI),hI&&hI.m(I,null),F(I,xI),F(I,KI),F(KI,Pl),F(Pl,Vl),lG.m(Vl,null),F(KI,rc),F(KI,nc),F(nc,_l),F(_l,Lc),F(_l,hZ),F(_l,kc),F(kc,Qb),DI(Qb,b[3]),F(kc,Aa),F(kc,Hb),OG.m(Hb,null),F(I,tm),F(I,RZ),F(RZ,ub),F(ub,ra),A||(x=[S(Z,"input",b[21]),S(N,"click",b[11]),S(a,"click",b[12]),S(Vl,"click",b[13]),S(Qb,"input",b[24]),S(Hb,"click",b[14]),S(ub,"click",function(){gI(b[0])&&b[0].apply(this,arguments)})],A=!0)},p(MG,FG){b=MG,FG[0]&2&&Z.value!==b[1]&&DI(Z,b[1]),$===($=D(b,FG))&&II?II.p(b,FG):(II.d(1),II=$(b),II&&(II.c(),II.m(h,null))),FG[0]&256&&J!==(J=b[8].rootCount+"")&&sI(E,J),FG[0]&256&&L!==(L=b[8].totalChoices+"")&&sI(z,L),FG[0]&256&&j!==(j=b[8].dependencyCount+"")&&sI(_,j),FG[0]&256&&VI!==(VI=b[8].userScripts+b[8].conditionalScripts+"")&&sI(EI,VI),FG[0]&256&&Ul!==(Ul=b[8].templateFiles+b[8].captureTemplates+"")&&sI(Bl,Ul),b[8].missingChoiceIds.length>0?P?P.p(b,FG):(P=ov(b),P.c(),P.m(X,null)):P&&(P.d(1),P=null),b[4]?hI?hI.p(b,FG):(hI=Cv(b),hI.c(),hI.m(I,xI)):hI&&(hI.d(1),hI=null),JG!==(JG=$I(b,FG))&&(lG.d(1),lG=JG(b),lG&&(lG.c(),lG.m(Vl,null))),FG[0]&32&&Ol!==(Ol=b[5]!==null)&&(Vl.disabled=Ol),FG[0]&8&&Qb.value!==b[3]&&DI(Qb,b[3]),BG!==(BG=$l(b,FG))&&(OG.d(1),OG=BG(b),OG&&(OG.c(),OG.m(Hb,null))),FG[0]&32&&nZ!==(nZ=b[5]!==null)&&(Hb.disabled=nZ),FG[0]&32&&u!==(u=b[5]!==null)&&(ub.disabled=u)},i:SI,o:SI,d(MG){MG&&lI(I),II.d(),P&&P.d(),hI&&hI.d(),lG.d(),OG.d(),A=!1,uI(x)}}}function rv(b,I=[],G=0,l=null){let c=[];for(let Z of b){let W=[...I,Z.name];c.push({choice:Z,id:Z.id,path:W,depth:G,parentId:l}),Lv(Z)&&c.push(...rv(Z.choices??[],W,G+1,Z.id))}return c}function Lv(b){return b.type==="Multi"}function jL(b,I){let G=I.trim().toLowerCase();return G?b.filter(l=>`${l.path.join(" ")} ${l.choice.type}`.toLowerCase().includes(G)):b}function kv(b){let I=[];if(Lv(b)){let G=b.choices??[];for(let l of G)I.push(l.id,...kv(l))}return I}function KL(b,I){let G=[];for(let l of b)I.has(l.id)&&(!l.parentId||!I.has(l.parentId))&&G.push(l.id);return G}function DL(b){let{missingChoiceIds:I,missingAssets:G}=b;return I.length===0&&G.length===0?null:{missingChoices:I,missingAssets:G}}async function TL(b){if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(b);return}let I=document.createElement("textarea");I.value=b,I.setAttribute("readonly","true"),I.style.position="fixed",I.style.opacity="0",document.body.appendChild(I),I.focus(),I.select();let G=document.execCommand("copy");if(document.body.removeChild(I),!G)throw new Error("Clipboard copy is not supported in this environment.")}function SL(b,I,G){let l,c,Z,W,{app:d}=I,{plugin:m}=I,{allChoices:N}=I,{close:Y}=I,a={"user-script":"User script","conditional-script":"Conditional script",template:"Template file","capture-template":"Capture template"},V="",h=new Set,n=new Set,X=[],p=Hv(),e=null,Q=null;function s(w,i){let o=[w.id,...kv(w)];if(i){let B=new Set(h);for(let j of o)B.add(j);if(G(2,h=B),n.size>0){let j=new Set(n);for(let _ of o)j.delete(_);G(18,n=j)}}else{let B=new Set(h);for(let _ of o)B.delete(_);G(2,h=B);let j=new Set(n);for(let _ of o)j.add(_);G(18,n=j)}}function R(w){let i=l.find(B=>B.id===w);if(!i)return;let o=h.has(w);s(i.choice,!o),G(4,e=null)}function J(){for(let w of c)s(w.choice,!0);G(4,e=null)}function E(){G(2,h=new Set),G(18,n=new Set),G(4,e=null)}function H(w,i,o){if(i.length===0)return{rootCount:0,totalChoices:0,dependencyCount:0,missingChoiceIds:[],userScripts:0,conditionalScripts:0,templateFiles:0,captureTemplates:0};let B=M2(w,i,{excludedChoiceIds:o}),j=j2(B.catalog,B.choiceIds),_=K2(B.catalog,B.choiceIds);return{rootCount:i.length,totalChoices:B.choiceIds.length,dependencyCount:Math.max(B.choiceIds.length-i.length,0),missingChoiceIds:B.missingChoiceIds,userScripts:j.userScriptPaths.size,conditionalScripts:j.conditionalScriptPaths.size,templateFiles:_.templatePaths.size,captureTemplates:_.captureTemplatePaths.size}}async function g(){if(X.length===0)return new Vc.Notice("Select at least one choice to export."),null;try{let w=await uv(d,{choices:N,rootChoiceIds:X,excludedChoiceIds:Array.from(n),quickAddVersion:m.manifest.version});return G(4,e=DL(w)),w}catch(w){return console.error(w),G(4,e=null),new Vc.Notice(`Export failed: ${w?.message??String(w)}`),null}}async function C(){if(!Q){G(5,Q="copy");try{let w=await g();if(!w)return;let i=JSON.stringify(w.pkg,null,2);await TL(i),new Vc.Notice(`Copied package (${w.pkg.choices.length} choice${w.pkg.choices.length===1?"":"s"}) to clipboard.`),e?new Vc.Notice("Package copied with warnings. Review details below."):Y()}catch(w){console.error(w),new Vc.Notice(`Copy failed: ${w?.message??String(w)}`)}finally{G(5,Q=null)}}}async function k(){if(Q)return;let w=p.trim();if(!w){new Vc.Notice("Enter a file path before saving.");return}G(5,Q="save");try{let i=await g();if(!i)return;await wv(d,i.pkg,w),new Vc.Notice(`Saved package (${i.pkg.choices.length} choice${i.pkg.choices.length===1?"":"s"}) to '${w}'.`),e?new Vc.Notice("Package saved with warnings. Review details below."):Y()}catch(i){console.error(i),new Vc.Notice(`Save failed: ${i?.message??String(i)}`)}finally{G(5,Q=null)}}function f(){V=this.value,G(1,V)}let L=w=>R(w.id),z=w=>W.get(w)??w;function r(){p=this.value,G(3,p)}return b.$$set=w=>{"app"in w&&G(15,d=w.app),"plugin"in w&&G(16,m=w.plugin),"allChoices"in w&&G(17,N=w.allChoices),"close"in w&&G(0,Y=w.close)},b.$$.update=()=>{b.$$.dirty[0]&131072&&G(20,l=rv(N)),b.$$.dirty[0]&1048578&&G(6,c=jL(l,V)),b.$$.dirty[0]&1048580&&G(19,X=KL(l,h)),b.$$.dirty[0]&917504&&G(8,Z=H(N,X,n)),b.$$.dirty[0]&1048576&&G(7,W=new Map(l.map(w=>[w.id,w.path.join(" / ")])))},[Y,V,h,p,e,Q,c,W,Z,a,R,J,E,C,k,d,m,N,n,X,l,f,L,z,r]}var UX=class extends oI{constructor(I){super(),zI(this,I,SL,ML,kI,{app:15,plugin:16,allChoices:17,close:0},LL,[-1,-1])}},zv=UX;var S2=class extends xv.Modal{constructor(G,l,c){super(G);this.plugin=l;this.choices=c;this.component=null}onOpen(){this.modalEl.addClass("quickAddModal","packageExportModal"),this.component=new zv({target:this.contentEl,props:{app:this.app,plugin:this.plugin,allChoices:this.choices,close:()=>this.close()}})}onClose(){this.component&&(this.component.$destroy(),this.component=null)}};var bE=require("obsidian");var QW=require("obsidian");var Uv=require("obsidian");function Bv(b){let I;try{I=JSON.parse(b)}catch(G){throw new Error(`Package content is not valid JSON: ${G?.message??G}`)}if(!nv(I))throw new Error("Content is not a valid QuickAdd package.");if(I.schemaVersion>1)throw new Error(`Package schema version ${I.schemaVersion} is newer than this plugin supports (${1}).`);return I}async function Ov(b,I,G){let l=new Map(Lb(I).map(W=>[W.id,W])),c=G.choices.map(W=>({choiceId:W.choice.id,name:W.choice.name,parentChoiceId:W.parentChoiceId,pathHint:W.pathHint??[],exists:l.has(W.choice.id)})),Z=[];for(let W of G.assets){let d=await b.vault.adapter.exists(W.originalPath);Z.push({originalPath:W.originalPath,exists:d,kind:W.kind})}return{choiceConflicts:c,assetConflicts:Z}}async function Mv(b){let{app:I,existingChoices:G,pkg:l}=b,c=new Map(b.choiceDecisions.map(H=>[H.choiceId,H.mode])),Z=new Map(b.assetDecisions.map(H=>[H.originalPath,H])),W=new Map(l.choices.map(H=>[H.choice.id,H])),d=new Set,m=new Map,N=new Set,Y=H=>{if(m.has(H))return m.get(H);if(N.has(H))return!0;if(N.add(H),c.get(H)==="skip")return m.set(H,!1),N.delete(H),!1;let C=W.get(H);if(!C)return m.set(H,!1),N.delete(H),!1;let k=C.parentChoiceId;if(!k||!W.has(k)||c.get(k)==="skip")return m.set(H,!0),N.delete(H),!0;let L=Y(k);return m.set(H,L),N.delete(H),L};for(let H of l.choices)Y(H.choice.id)&&d.add(H.choice.id);let a=new Set,V=new Map,h=H=>{if(!d.has(H))return!1;if(a.has(H))return!0;if(c.get(H)==="duplicate")return a.add(H),!0;let k=W.get(H)?.parentChoiceId??null;return k&&(c.get(k)==="duplicate"||d.has(k)&&h(k))?(a.add(H),!0):!1};for(let H of l.choices){if(!d.has(H.choice.id))continue;let C=h(H.choice.id)?tl():H.choice.id;V.set(H.choice.id,C)}let n=cG(G),X=[],p=[],e=[],Q=new Map;for(let H of l.choices){if(!d.has(H.choice.id)){e.push(H.choice.id);continue}let g=cG(H.choice),C=MX(g,V,d);Q.set(H.choice.id,C)}let s=new Set;for(let H of l.choices){let g=H.choice.id;if(!d.has(g)||s.has(g))continue;let C=Q.get(g);if(!C)continue;let k=C.id,f=c.get(g)??"import",L=H.parentChoiceId;if(L&&d.has(L)?Q.get(L):null){s.add(g);continue}if((f==="overwrite"||f==="import")&&jv(n,C)){p.push(k),s.add(g);continue}if(L){let w=V.get(L)??L;if(Kv(n,w,C)){X.push(k),s.add(g);continue}let o=qL(n,H.pathHint.slice(0,-1));if(o){Dv(o,C),X.push(k),s.add(g);continue}M.logWarning(`QuickAdd import: could not locate parent for '${H.choice.name}'. Adding to root.`)}let r=n.findIndex(w=>w.id===k);r!==-1?(n.splice(r,1,C),p.push(k)):(n.push(C),X.push(k)),s.add(g)}let R=new Map,J=[],E=[];for(let H of l.assets){let g=Z.get(H.originalPath),C=g?.destinationPath?.trim(),k=C?(0,Uv.normalizePath)(C):H.originalPath,f=await fL(I,k);if((g?.mode??(f?"overwrite":"write"))==="skip"){E.push(k);continue}await PL(I,k);let z=ev(H.content);await I.vault.adapter.write(k,z),J.push(k),R.set(H.originalPath,k)}for(let H of Q.values())jX(H,R);return{updatedChoices:n,addedChoiceIds:X,overwrittenChoiceIds:p,skippedChoiceIds:e,writtenAssets:J,skippedAssets:E}}async function fL(b,I){try{return await b.vault.adapter.exists(I)}catch{return!1}}function MX(b,I,G){let l=b.id,c=I.get(l)??l;b.id=c;let Z=c!==l;if(b.type==="Macro"){let W=b;Z&&(W.macro.id=tl()),BX(W.macro.commands,I,G,Z)}if(b.type==="Multi"){let W=b;Array.isArray(W.choices)&&(W.choices=W.choices.filter(d=>G.has(d.id)).map(d=>MX(d,I,G)))}return b}function BX(b,I,G,l){for(let c of b)if(c)switch(l&&(c.id=tl()),c.type){case"Choice":{let Z=c,W=I.get(Z.choiceId);W&&(Z.choiceId=W);break}case"Conditional":{let Z=c;BX(Z.thenCommands,I,G,l),BX(Z.elseCommands,I,G,l);break}case"NestedChoice":{let Z=c;Z.choice&&G.has(Z.choice.id)&&(Z.choice=MX(Z.choice,I,G));break}default:break}}function jv(b,I){for(let G=0;GSelect a package file, review conflicts, and choose how to import each item.
',l=K(),c=v("section"),Z=v("label"),W=v("span"),W.textContent="Paste package JSON",d=K(),m=v("textarea"),N=K(),E&&E.c(),Y=K(),H&&H.c(),a=K(),V=v("section"),h=v("button"),n=NI("Cancel"),X=K(),p=v("button"),k.c(),t(G,"class","svelte-x9dt2q"),t(W,"class","svelte-x9dt2q"),t(m,"placeholder","Paste the contents of a .quickadd.json package here"),t(m,"rows","8"),t(m,"class","svelte-x9dt2q"),t(Z,"class","svelte-x9dt2q"),t(c,"class","pasteSection svelte-x9dt2q"),t(h,"type","button"),t(h,"class","secondary svelte-x9dt2q"),h.disabled=b[4],t(p,"type","button"),t(p,"class","primary svelte-x9dt2q"),p.disabled=e=b[4]||!b[1]||!b[2],t(V,"class","footer svelte-x9dt2q"),t(I,"class","importPackageModal svelte-x9dt2q")},m(f,L){cI(f,I,L),F(I,G),F(I,l),F(I,c),F(c,Z),F(Z,W),F(Z,d),F(Z,m),DI(m,b[8]),F(c,N),E&&E.m(c,null),F(I,Y),H&&H.m(I,null),F(I,a),F(I,V),F(V,h),F(h,n),F(V,X),F(V,p),k.m(p,null),Q||(s=[S(m,"input",b[19]),S(m,"input",b[16]),S(h,"click",function(){gI(b[0])&&b[0].apply(this,arguments)}),S(p,"click",function(){gI(b[10]?b[0]:b[17])&&(b[10]?b[0]:b[17]).apply(this,arguments)})],Q=!0)},p(f,L){b=f,L[0]&256&&DI(m,b[8]),J===(J=R(b,L))&&E?E.p(b,L):(E&&E.d(1),E=J&&J(b),E&&(E.c(),E.m(c,null))),b[1]&&b[2]?H?H.p(b,L):(H=fv(b),H.c(),H.m(I,a)):H&&(H.d(1),H=null),L[0]&16&&(h.disabled=b[4]),C!==(C=g(b,L))&&(k.d(1),k=C(b),k&&(k.c(),k.m(p,null))),L[0]&22&&e!==(e=b[4]||!b[1]||!b[2])&&(p.disabled=e)},i:SI,o:SI,d(f){f&&lI(I),E&&E.d(),H&&H.d(),k.d(),Q=!1,uI(s)}}}function N3(b,I){let G=I.destinationExists;return I.mode==="skip"?{className:"assetBadge--info",label:"Skipped"}:I.mode==="overwrite"?{className:G?"assetBadge--warning":"assetBadge--info",label:G?"Will overwrite":"Overwrite"}:{className:G?"assetBadge--warning":"assetBadge--info",label:G?"Will overwrite":"New file"}}function GE(b){return!b||b.length===0?"Root":b.slice(0,-1).join(" \u203A ")||"Root"}function Y3(b,I,G){let{app:l}=I,{close:c}=I,Z=null,W=null,d=null,m=!1,N=null,Y=new Map,a=new Map,V="",h=!1,n=0,X=!1;function p(i){let o=dI.getState().templateFolderPath?.trim(),B=i.kind==="template"||i.kind==="capture-template";if(o&&B){let j=i.originalPath.split("/").pop()??i.originalPath,_=o.replace(/\/+$/,"");return _?`${_}/${j}`:j}return i.originalPath}function e(i){let o=i.trim();if(!o)return!1;let B=(0,QW.normalizePath)(o);return!!l.vault.getAbstractFileByPath(B)}function Q(){if(G(6,Y=new Map),G(7,a=new Map),!!W){for(let i of W.choiceConflicts){let o=i.exists?"overwrite":"import";Y.set(i.choiceId,o)}for(let i of W.assetConflicts){let o=p(i),B=i.exists||e(o),j=B?"overwrite":"write";a.set(i.originalPath,{mode:j,destinationPath:o,destinationExists:B})}}}function s(i,o){let B=new Map(Y);B.set(i,o),G(6,Y=B)}function R(i,o){let j={...a.get(i)??{mode:o,destinationPath:i,destinationExists:e(i)},mode:o},_=new Map(a);_.set(i,j),G(7,a=_)}function J(i,o){let B=a.get(i.originalPath)??{mode:"write",destinationPath:i.originalPath,destinationExists:e(i.originalPath)},j=o.trim(),_=j||i.originalPath,YI=j||o,aI=e(_),QI=B.mode;B.mode!=="skip"&&(aI&&B.mode==="write"?QI="overwrite":!aI&&B.mode==="overwrite"&&(QI="write"));let vI={...B,mode:QI,destinationPath:YI,destinationExists:aI},tI=new Map(a);tI.set(i.originalPath,vI),G(7,a=tI)}function E(i,o){let j=o.currentTarget.value;s(i,j)}function H(i,o){let j=o.currentTarget.value;R(i,j)}function g(i,o){let B=o.currentTarget.value;J(i,B)}async function C(i){let o=i.trim(),B=++n;if(G(5,N=null),G(10,X=!1),!o){G(1,Z=null),G(2,W=null),G(6,Y=new Map),G(7,a=new Map),G(3,d=null);return}G(9,h=!0);try{let j=Bv(o),_=await Ov(l,dI.getState().choices,j);if(B!==n)return;G(1,Z={pkg:j,path:"[pasted]"}),G(2,W=_),G(3,d=null),Q()}catch(j){if(B!==n)return;G(3,d=j?.message??String(j)),G(1,Z=null),G(2,W=null),G(6,Y=new Map),G(7,a=new Map)}finally{B===n&&G(9,h=!1)}}function k(i){let o=i.currentTarget.value;G(8,V=o),C(o)}async function f(){if(X){new QW.Notice("This package has already been imported.");return}if(!Z||!W){new QW.Notice("Load a package before importing.");return}G(4,m=!0),G(5,N=null);try{let i=W.choiceConflicts.map(j=>{let _=Y.get(j.choiceId)??"import",YI=j.exists||_!=="overwrite"?_:"import";return{choiceId:j.choiceId,mode:YI}}),o=W.assetConflicts.map(j=>{let _=a.get(j.originalPath),YI=_?.destinationPath?.trim()||j.originalPath,aI=_?.destinationExists??(j.exists?!0:e(YI)),QI=_?.mode??(aI?"overwrite":"write");return{originalPath:j.originalPath,destinationPath:YI,mode:QI}}),B=await Mv({app:l,existingChoices:dI.getState().choices,pkg:Z.pkg,choiceDecisions:i,assetDecisions:o});dI.setState(j=>({...j,choices:B.updatedChoices})),G(5,N={added:B.addedChoiceIds.length,overwritten:B.overwrittenChoiceIds.length,skipped:B.skippedChoiceIds.length,assetsWritten:B.writtenAssets.length,assetsSkipped:B.skippedAssets.length}),G(10,X=!0),new QW.Notice(`Imported ${B.addedChoiceIds.length+B.overwrittenChoiceIds.length} choice${B.addedChoiceIds.length+B.overwrittenChoiceIds.length===1?"":"s"} successfully.`)}catch(i){console.error(i),new QW.Notice(`Import failed: ${i?.message??i}`)}finally{G(4,m=!1)}}function L(){V=this.value,G(8,V)}let z=(i,o)=>E(i.choiceId,o),r=(i,o)=>g(i,o),w=(i,o)=>H(i.originalPath,o);return b.$$set=i=>{"app"in i&&G(18,l=i.app),"close"in i&&G(0,c=i.close)},[c,Z,W,d,m,N,Y,a,V,h,X,p,e,E,H,g,k,f,l,L,z,r,w]}var KX=class extends oI{constructor(I){super(),zI(this,I,Y3,m3,kI,{app:18,close:0},_L,[-1,-1])}},lE=KX;var f2=class extends bE.Modal{constructor(G){super(G);this.component=null}onOpen(){this.modalEl.addClass("quickAddModal","packageImportModal"),this.component=new lE({target:this.contentEl,props:{app:this.app,close:()=>this.close()}})}onClose(){this.component?.$destroy(),this.component=null}};var ja={choices:[],inputPrompt:"single-line",devMode:!1,templateFolderPath:"",announceUpdates:"all",version:"0.0.0",globalVariables:{},onePageInputEnabled:!1,disableOnlineFeatures:!0,enableRibbonIcon:!1,showCaptureNotification:!0,showInputCancellationNotification:!1,enableTemplatePropertyTypes:!1,ai:{defaultModel:"Ask me",defaultSystemPrompt:'As an AI assistant within Obsidian, your primary goal is to help users manage their ideas and knowledge more effectively. Format your responses using Markdown syntax. Please use the [[Obsidian]] link format. You can write aliases for the links by writing [[Obsidian|the alias after the pipe symbol]]. To use mathematical notation, use LaTeX syntax. LaTeX syntax for larger equations should be on separate lines, surrounded with double dollar signs ($$). You can also inline math expressions by wrapping it in $ symbols. For example, use $$w_{ij}^{ ext{new}}:=w_{ij}^{ ext{current}}+etacdotdelta_jcdot x_{ij}$$ on a separate line, but you can write "($eta$ = learning rate, $delta_j$ = error term, $x_{ij}$ = input)" inline.',promptTemplatesFolderPath:"",showAssistant:!0,providers:B2},migrations:{migrateToMacroIDFromEmbeddedMacro:!0,useQuickAddTemplateFolder:!1,incrementFileNameSettingMoveToDefaultBehavior:!1,mutualExclusionInsertAfterAndWriteToBottomOfFile:!1,setVersionAfterUpdateModalRelease:!1,addDefaultAIProviders:!1,removeMacroIndirection:!1,migrateFileOpeningSettings:!1,setProviderModelDiscoveryMode:!1}},q2=class extends Zl.PluginSettingTab{constructor(I,G){super(I,G),this.plugin=G}display(){let{containerEl:I}=this;I.empty(),I.createEl("h2",{text:"QuickAdd Settings"}),this.addChoicesSetting(),this.addPackagesSetting(),this.addUseMultiLineInputPromptSetting(),this.addTemplateFolderPathSetting(),this.addAnnounceUpdatesSetting(),this.addShowCaptureNotificationSetting(),this.addShowInputCancellationNotificationSetting(),this.addTemplatePropertyTypesSetting(),this.addGlobalVariablesSetting(),this.addOnePageInputSetting(),this.addDisableOnlineFeaturesSetting(),this.addEnableRibbonIconSetting(),this.addDevelopmentInfoSetting()}addDevelopmentInfoSetting(){}addGlobalVariablesSetting(){let I=new Zl.Setting(this.containerEl);I.infoEl.remove(),I.settingEl.style.display="block",new av({target:I.settingEl,props:{app:this.app,plugin:this.plugin}})}addAnnounceUpdatesSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Announce Updates"),I.setDesc("Display release notes when a new version is installed. This includes new features, demo videos, and bug fixes."),I.addDropdown(G=>{let l=dI.getState().announceUpdates;G.addOption("all","Show updates on each new release").addOption("major","Show updates only on major releases (new features, breaking changes)").addOption("none","Don't show").setValue(l).onChange(c=>{dI.setState({announceUpdates:c})})})}addShowCaptureNotificationSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Show Capture Notifications"),I.setDesc("Display a notification when content is captured successfully to confirm the operation completed."),I.addToggle(G=>{G.setValue(dI.getState().showCaptureNotification),G.onChange(l=>{dI.setState({showCaptureNotification:l})})})}addShowInputCancellationNotificationSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Show Input Cancellation Notifications"),I.setDesc("Display a notification when an input prompt is cancelled without submitting. Disable this to avoid extra notices when dismissing prompts."),I.addToggle(G=>{G.setValue(dI.getState().showInputCancellationNotification),G.onChange(l=>{dI.setState({showInputCancellationNotification:l})})})}addTemplatePropertyTypesSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Format template variables as proper property types (Beta)"),I.setDesc("When enabled, template variables in front matter will be formatted as proper Obsidian property types. Arrays become List properties, numbers become Number properties, booleans become Checkbox properties, etc. This is a beta feature that may have edge cases."),I.addToggle(G=>{G.setValue(dI.getState().enableTemplatePropertyTypes),G.onChange(l=>{dI.setState({enableTemplatePropertyTypes:l})})})}hide(){this.choiceView&&this.choiceView.$destroy()}addChoicesSetting(){let I=new Zl.Setting(this.containerEl);I.infoEl.remove(),I.settingEl.style.display="block",this.choiceView=new mv({target:I.settingEl,props:{app:this.app,plugin:this.plugin,choices:dI.getState().choices,saveChoices:G=>{dI.setState({choices:G})}}})}addPackagesSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Packages"),I.setDesc("Bundle or import QuickAdd automations as reusable packages."),I.addButton(G=>G.setButtonText("Export package\u2026").setCta().onClick(()=>{let l=dI.getState().choices;new S2(this.app,this.plugin,l).open()})),I.addButton(G=>G.setButtonText("Import package\u2026").onClick(()=>{new f2(this.app).open()}))}addUseMultiLineInputPromptSetting(){new Zl.Setting(this.containerEl).setName("Use Multi-line Input Prompt").setDesc("Use multi-line input prompt instead of single-line input prompt").addToggle(I=>I.setValue(this.plugin.settings.inputPrompt==="multi-line").setTooltip("Use multi-line input prompt").onChange(G=>{G?dI.setState({inputPrompt:"multi-line"}):dI.setState({inputPrompt:"single-line"})}))}addTemplateFolderPathSetting(){let I=new Zl.Setting(this.containerEl);I.setName("Template Folder Path"),I.setDesc("Path to the folder where templates are stored. Used to suggest template files when configuring QuickAdd."),I.addText(G=>{G.setPlaceholder("templates/").setValue(dI.getState().templateFolderPath).onChange(l=>{dI.setState({templateFolderPath:l})}),new Xl(this.app,G.inputEl,this.app.vault.getAllLoadedFiles().filter(l=>l instanceof Zl.TFolder&&l.path!=="/").map(l=>l.path))})}addOnePageInputSetting(){new Zl.Setting(this.containerEl).setName("One-page input for choices (Beta)").setDesc("Experimental. Resolve variables up front and show a single dynamic form before executing Template/Capture choices. See Advanced \u2192 One-page Inputs in docs.").addToggle(I=>I.setValue(dI.getState().onePageInputEnabled).onChange(G=>{dI.setState({onePageInputEnabled:G})}))}addDisableOnlineFeaturesSetting(){new Zl.Setting(this.containerEl).setName("Disable AI & Online features").setDesc("This prevents the plugin from making requests to external providers like OpenAI. You can still use User Scripts to execute arbitrary code, including contacting external providers. However, this setting disables plugin features like the AI Assistant from doing so. You need to disable this setting to use the AI Assistant.").addToggle(I=>I.setValue(dI.getState().disableOnlineFeatures).onChange(G=>{dI.setState({disableOnlineFeatures:G}),this.display()}))}addEnableRibbonIconSetting(){new Zl.Setting(this.containerEl).setName("Show icon in sidebar").setDesc("Add QuickAdd icon to the sidebar ribbon. Requires a reload.").addToggle(I=>{I.setValue(dI.getState().enableRibbonIcon).onChange(G=>{dI.setState({enableRibbonIcon:G}),this.display()})})}};var hm=class{formatOutputString(I){return`QuickAdd: (${I.level}) ${I.message}`}getQuickAddError(I,G,l,c){return{message:I,level:G,time:Date.now(),stack:l,originalError:c}}};var Ja=class extends hm{constructor(){super(...arguments);this.ErrorLog=[]}logError(G,l,c){let Z=this.getQuickAddError(G,"ERROR",l,c);this.addMessageToErrorLog(Z);let W=c||new Error(G);console.error(this.formatOutputString(Z),W)}logWarning(G,l,c){let Z=this.getQuickAddError(G,"WARNING",l,c);this.addMessageToErrorLog(Z);let W=c||new Error(G);console.warn(this.formatOutputString(Z),W)}logMessage(G,l,c){let Z=this.getQuickAddError(G,"LOG",l,c);this.addMessageToErrorLog(Z),c?console.log(this.formatOutputString(Z),c):console.log(this.formatOutputString(Z))}addMessageToErrorLog(G){this.ErrorLog.push(G),this.ErrorLog.length>eF&&(this.ErrorLog=this.ErrorLog.slice(-eF))}clearErrorLog(){this.ErrorLog=[]}};var DX=require("obsidian");var P2=class extends hm{constructor(G){super();this.plugin=G}logError(G,l,c){let Z=this.getQuickAddError(G,"ERROR",l,c);new DX.Notice(this.formatOutputString(Z),15e3)}logWarning(G,l,c){let Z=this.getQuickAddError(G,"WARNING",l,c);new DX.Notice(this.formatOutputString(Z))}logMessage(G,l,c){}};var _2=class{constructor(I,G,l,c){this.app=I;this.plugin=G;this.choices=l;this.choiceExecutor=c}async run(){let I=Lb(this.choices).filter(G=>G.type==="Macro"&&G.runOnStartup);for(let G of I)await new cc(this.app,this.plugin,G,this.choiceExecutor,new Map).run()}};var cE=require("obsidian");var $2=class extends qd{constructor(I,G,l,c){super(I,G,c),this.choiceExecutor=c,this.choice=l}async run(){try{Dl(this.choice.templatePath,()=>`Invalid template path for ${this.choice.name}. ${this.choice.templatePath.length===0?"Template path is empty.":`Template path is not valid: ${this.choice.templatePath}`}`);let I=qc(this.choice.appendLink);this.setLinkToCurrentFileBehavior(I.enabled&&!I.requireActiveFile?"optional":"required");let G="";if(this.choice.folder.enabled)G=await this.getFolderPath();else{let m=this.app.fileManager.getNewFileParent(this.app.workspace.getActiveFile()?.path??"");G=m===this.app.vault.getRoot()?"":m.path}let l=this.choice.fileNameFormat.enabled?this.choice.fileNameFormat.format:QZ,c=await this.formatter.formatFileName(l,this.choice.name),Z=this.normalizeTemplateFilePath(G,c,this.choice.templatePath);this.choice.fileExistsMode===sZ&&(Z=await this.incrementFileName(Z));let W,d=!1;if(await this.app.vault.adapter.exists(Z)){let m=this.app.vault.getAbstractFileByPath(Z);if(!(m instanceof cE.TFile)||m.extension!=="md"&&m.extension!=="canvas"){M.logError(`'${Z}' already exists and is not a valid markdown or canvas file.`);return}let N=this.choice.fileExistsMode;if(!this.choice.setFileExistsBehavior)try{N=await Fl.Suggest(this.app,[...yn],[...yn])}catch(Y){throw XG(Y)?new qI("Input cancelled by user"):Y}switch(N){case zW:W=await this.appendToFileWithTemplate(m,this.choice.templatePath,"top");break;case kW:W=await this.appendToFileWithTemplate(m,this.choice.templatePath,"bottom");break;case xW:W=await this.overwriteFileWithTemplate(m,this.choice.templatePath);break;case wZ:W=m,d=!0,M.logMessage(`Opening existing file: ${m.path}`);break;case sZ:{let Y=await this.incrementFileName(Z);W=await this.createFileWithTemplate(Y,this.choice.templatePath);break}default:M.logWarning("File not written to.");return}}else if(W=await this.createFileWithTemplate(Z,this.choice.templatePath),!W){M.logWarning(`Could not create file '${Z}'.`);return}if(I.enabled&&W&&rV(this.app,W,I),(this.choice.openFile||d)&&W){let m=this.choice.fileOpening.focus??!0;LV(this.app,W,m)||await ad(this.app,W,this.choice.fileOpening),await AV(this.app,W)}}catch(I){if(WZ(I,{logPrefix:"Template execution aborted",noticePrefix:"Template execution aborted",defaultReason:"Template execution aborted"})){this.choiceExecutor.signalAbort?.(I);return}IG(I,`Error running template choice "${this.choice.name}"`)}}async formatFolderPaths(I){return await Promise.all(I.map(async l=>await this.formatter.formatFolderPath(l)))}async getFolderPath(){let I=await this.formatFolderPaths([...this.choice.folder.folders]);if(this.choice.folder?.chooseFromSubfolders&&!(this.choice.folder?.chooseWhenCreatingNote||this.choice.folder?.createInSameFolderAsActiveFile)){let l=rY(this.app).filter(c=>I.some(Z=>c.startsWith(Z)));return await this.getOrCreateFolder(l)}if(this.choice.folder?.chooseWhenCreatingNote){let G=rY(this.app);return await this.getOrCreateFolder(G)}if(this.choice.folder?.createInSameFolderAsActiveFile){let G=this.app.workspace.getActiveFile();return!G||!G.parent?(M.logWarning("No active file or active file has no parent. Cannot create file in same folder as active file. Creating in root folder."),""):this.getOrCreateFolder([G.parent.path])}return await this.getOrCreateFolder(I)}};var $X=require("obsidian");var In=class{isResolved(){return!this.hasConflicts}isConflicted(){return this.hasConflicts}},ya=class b extends In{constructor(I,G,l){super(),this.left=I,this.base=G,this.right=l,this.hasConflicts=!0}static create(I){return new b(I.left,I.base,I.right)}apply(I){return b.create({left:I(this.left),base:I(this.base),right:I(this.right)})}},pb=class b extends In{constructor(I){super(),this.hasConflicts=!1,this.result=I}combine(I){this.result=this.result.concat(I.result)}apply(I){return new b(I(this.result))}};var ic=class b{constructor(I,G){this.left=I,this.right=G}static executeDiff(I,G){if(!I.push)throw new Error("Argument is not an array");let l=b.diff(I,G);return new SX(I,G,l).convertToTypedOutput()}static diff(I,G){return new b(I,G).performDiff()}performDiff(){let I=this.identifyUniquePositions();I.sort((Z,W)=>W[0]-Z[0]);let[G,l]=this.findNextChange(),c=new Gn(G,l,[]);return I.forEach(Z=>{c=this.getDifferences(c,Z)}),c.changeRanges}getDifferences(I,G){let[l,c]=[I.leftChangePos,I.rightChangePos],[Z,W]=G;if(Z