/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var Lr=Object.create;var ke=Object.defineProperty;var Fr=Object.getOwnPropertyDescriptor;var _r=Object.getOwnPropertyNames,Lt=Object.getOwnPropertySymbols,Vr=Object.getPrototypeOf,Ft=Object.prototype.hasOwnProperty,Hr=Object.prototype.propertyIsEnumerable;var _t=(r,e,t)=>e in r?ke(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,we=(r,e)=>{for(var t in e||(e={}))Ft.call(e,t)&&_t(r,t,e[t]);if(Lt)for(var t of Lt(e))Hr.call(e,t)&&_t(r,t,e[t]);return r};var Vt=r=>ke(r,"__esModule",{value:!0});var $r=(r,e)=>{Vt(r);for(var t in e)ke(r,t,{get:e[t],enumerable:!0})},Wr=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _r(e))!Ft.call(r,o)&&o!=="default"&&ke(r,o,{get:()=>e[o],enumerable:!(t=Fr(e,o))||t.enumerable});return r},W=r=>Wr(Vt(ke(r!=null?Lr(Vr(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var d=(r,e,t)=>new Promise((o,i)=>{var n=p=>{try{s(t.next(p))}catch(c){i(c)}},a=p=>{try{s(t.throw(p))}catch(c){i(c)}},s=p=>p.done?o(p.value):Promise.resolve(p.value).then(n,a);s((t=t.apply(r,e)).next())});$r(exports,{default:()=>Ot});var kr=W(require("path")),Ce=W(require("obsidian"));var xe=W(require("obsidian"));var N;(function(t){t.google="google",t.naver="naver"})(N||(N={}));var Ht=W(require("obsidian"));var tt=class{getByQuery(e){return d(this,null,function*(){try{let t={q:e,maxResults:40,printType:"books"},o=window.moment.locale();o&&(t.langRestrict=o);let i=yield $e("https://www.googleapis.com/books/v1/volumes",t);if(i.totalItems==0)throw new Error("No results found.");return i.items.map(({volumeInfo:n})=>this.createBookItem(n))}catch(t){throw console.warn(t),t}})}getISBN(e){return e==null?void 0:e.reduce((t,o)=>(o.type=="ISBN_10"&&(t.isbn10=o.identifier.trim()),o.type=="ISBN_13"&&(t.isbn13=o.identifier.trim()),t),{})}createBookItem(e){var o,i,n,a,s;return we({title:e.title,author:this.formatList(e.authors),category:this.formatList(e.categories),publisher:e.publisher,totalPage:e.pageCount,coverUrl:(i=(o=e.imageLinks)==null?void 0:o.thumbnail)!=null?i:"",coverSmallUrl:(a=(n=e.imageLinks)==null?void 0:n.smallThumbnail)!=null?a:"",publishDate:((s=e.publishedDate)==null?void 0:s.slice(0,4))||"",description:e.description,link:e.canonicalVolumeLink||e.infoLink,previewLink:e.previewLink},this.getISBN(e.industryIdentifiers))}convertGoogleBookImageURLSize(e,t){return e.replace(/(&zoom)=\d/,`$1=${t}`)}formatList(e){var t,o;return(e==null?void 0:e.length)>1?e.map(i=>`${i.trim()}`).join(", "):(o=(t=e==null?void 0:e[0])==null?void 0:t.replace("N/A",""))!=null?o:""}};var rt=class{constructor(e,t){this.clientId=e;this.clientSecret=t}getByQuery(e){return d(this,null,function*(){try{let t={query:e,display:50,sort:"sim"},o={"X-Naver-Client-Id":this.clientId,"X-Naver-Client-Secret":this.clientSecret},i=yield $e("https://openapi.naver.com/v1/search/book.json",t,o);if(i.total==0)throw new Error("No results found.");return i.items.map(this.createBookItem)}catch(t){throw console.warn(t),t}})}createBookItem(e){var t,o;return we({title:e.title,author:e.author,publisher:e.publisher,coverUrl:e.image,publishDate:((t=e.pubdate)==null?void 0:t.slice(0,4))||"",link:e.link,description:e.description,isbn:e.isbn},((o=e.isbn)==null?void 0:o.length)>=13?{isbn13:e.isbn}:{isbn10:e.isbn})}};function $t(r){if(r.serviceProvider===N.google)return new tt;if(r.serviceProvider===N.naver){if(!r.naverClientId||!r.naverClientSecret)throw new Error("\uB124\uC774\uBC84 \uAC1C\uBC1C\uC790\uC13C\uD130\uC5D0\uC11C `Client ID`\uC640 `Client Secret`\uB97C \uBC1C\uAE09\uBC1B\uC544 \uC124\uC815\uD574\uC8FC\uC138\uC694.");return new rt(r.naverClientId,r.naverClientSecret)}}function $e(o){return d(this,arguments,function*(r,e={},t){let i=new URL(r);return Object.entries(e).forEach(([a,s])=>{i.searchParams.append(a,s==null?void 0:s.toString())}),(yield(0,Ht.requestUrl)({url:i.href,method:"GET",headers:we({Accept:"*/*","Content-Type":"application/json; charset=utf-8"},t)})).json})}var ot=class extends xe.Modal{constructor(e,t,o){super(e.app);this.query=t,this.callback=o,this.serviceProvider=$t(e.settings)}searchBook(){return d(this,null,function*(){if(!this.query)throw new Error("No query entered.");if(!this.isBusy)try{this.isBusy=!0,this.okBtnRef.setDisabled(!1),this.okBtnRef.setButtonText("Requesting...");let e=yield this.serviceProvider.getByQuery(this.query);this.callback(null,e)}catch(e){this.callback(e)}finally{this.close()}})}submitEnterCallback(e){e.key==="Enter"&&this.searchBook()}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:"Search Book"}),e.createDiv({cls:"book-search-plugin__search-modal--input"},t=>{new xe.TextComponent(t).setValue(this.query).setPlaceholder("Search by keyword or ISBN").onChange(o=>this.query=o).inputEl.addEventListener("keydown",this.submitEnterCallback.bind(this))}),new xe.Setting(e).addButton(t=>t.setButtonText("Cancel").onClick(()=>this.close())).addButton(t=>this.okBtnRef=t.setButtonText("Ok").setCta().onClick(()=>{this.searchBook()}))}onClose(){this.contentEl.empty()}};var Wt=W(require("obsidian")),it=class extends Wt.SuggestModal{constructor(e,t,o){super(e);this.suggestion=t,this.onChoose=o}getSuggestions(e){return this.suggestion.filter(t=>{var i,n,a;let o=e==null?void 0:e.toLowerCase();return((i=t.title)==null?void 0:i.toLowerCase().includes(o))||((n=t.author)==null?void 0:n.toLowerCase().includes(o))||((a=t.publisher)==null?void 0:a.toLowerCase().includes(o))})}renderSuggestion(e,t){let o=e.title,i=e.publisher?`, ${e.publisher}`:"",n=e.publishDate?`(${e.publishDate})`:"",a=e.totalPage?`, p${e.totalPage}`:"",s=`${e.author}${i}${n}${a}`;t.createEl("div",{text:o}),t.createEl("small",{text:s})}onChooseSuggestion(e){this.onChoose(null,e)}};var Xt=W(require("obsidian")),nt=class{constructor(e){this.app=e}jumpToNextCursorLocation(){return d(this,null,function*(){let e=this.app.workspace.getActiveViewOfType(Xt.MarkdownView);if(!e)return;let o=(yield this.app.vault.cachedRead(e.file)).length+1,i=e.editor;i.focus(),i.setCursor(o,0)})}};var U=W(require("obsidian"));var Gt=/^-?[0-9]*$/,st=/{{DATE(\+-?[0-9]+)?}}/,at=/{{DATE:([^}\n\r+]*)(\+-?[0-9]+)?}}/;function Xr(r){return r.replace(/[\\,#%&{}/*<>$":@.]/g,"").replace(/\s+/g," ")}function Ut(r,e){let t;return e?t=Ne(r,We(e)):t=r.author?`${r.title} - ${r.author}`:r.title,Xr(t)+".md"}function Gr(r){return Object.entries(r).reduce((e,[t,o])=>(e[Ur(t)]=o,e),{})}function qt(r,e,t=Q.snakeCase){var n,a;let o=t===Q.camelCase?r:Gr(r),i=typeof e=="string"?qr(e):e;for(let s in i){let p=(a=(n=i[s])==null?void 0:n.toString().trim())!=null?a:"";o[s]&&o[s]!==p?o[s]=`${o[s]}, ${p}`:o[s]=p}return o}function Ne(r,e){return(e==null?void 0:e.trim())?Object.entries(r).reduce((o,[i,n=""])=>o.replace(new RegExp(`{{${i}}}`,"ig"),n),e).replace(/{{.+}}/gi,"").trim():""}function Ur(r){return r.replace(/[A-Z]/g,e=>`_${e==null?void 0:e.toLowerCase()}`)}function qr(r){return r?r.split(` `).map(e=>{var n,a;let t=e.indexOf(":");if(t===-1)return[e.trim(),""];let o=(n=e.slice(0,t))==null?void 0:n.trim(),i=(a=e.slice(t+1))==null?void 0:a.trim();return[o,i]}).reduce((e,[t,o])=>{var i;return t&&(e[t]=(i=o==null?void 0:o.trim())!=null?i:""),e},{}):{}}function Yt(r){return Object.entries(r).map(([e,t])=>{var i;let o=(i=t==null?void 0:t.toString().trim())!=null?i:"";return/\r|\n/.test(o)?"":/:\s/.test(o)?`${e}: "${o.replace(/"/g,""")}" `:`${e}: ${o} `}).join("").trim()}function zt(r){let e;return r.offset!==null&&r.offset!==void 0&&typeof r.offset=="number"&&(e=window.moment.duration(r.offset,"days")),r.format?window.moment().add(e).format(r.format):window.moment().add(e).format("YYYY-MM-DD")}function We(r){let e=r;for(;st.test(e);){let t=st.exec(e),o;if(t[1]){let i=t[1].replace("+","").trim();Gt.test(i)&&(o=parseInt(i))}e=Kt(e,st,zt({offset:o}))}for(;at.test(e);){let t=at.exec(e),o=t[1],i;if(t[2]){let n=t[2].replace("+","").trim();Gt.test(n)&&(i=parseInt(n))}e=Kt(e,at,zt({format:o,offset:i}))}return e}function Kt(r,e,t){return r.replace(e,function(){return t})}var wr=W(require("obsidian"));var P="top",D="bottom",k="right",T="left",Xe="auto",oe=[P,D,k,T],Z="start",le="end",Qt="clippingParents",Ge="viewport",be="popper",Jt="reference",lt=oe.reduce(function(r,e){return r.concat([e+"-"+Z,e+"-"+le])},[]),Ue=[].concat(oe,[Xe]).reduce(function(r,e){return r.concat([e,e+"-"+Z,e+"-"+le])},[]),Yr="beforeRead",zr="read",Kr="afterRead",Qr="beforeMain",Jr="main",Zr="afterMain",eo="beforeWrite",to="write",ro="afterWrite",Zt=[Yr,zr,Kr,Qr,Jr,Zr,eo,to,ro];function M(r){return r?(r.nodeName||"").toLowerCase():null}function B(r){if(r==null)return window;if(r.toString()!=="[object Window]"){var e=r.ownerDocument;return e&&e.defaultView||window}return r}function J(r){var e=B(r).Element;return r instanceof e||r instanceof Element}function A(r){var e=B(r).HTMLElement;return r instanceof e||r instanceof HTMLElement}function ye(r){if(typeof ShadowRoot=="undefined")return!1;var e=B(r).ShadowRoot;return r instanceof e||r instanceof ShadowRoot}function oo(r){var e=r.state;Object.keys(e.elements).forEach(function(t){var o=e.styles[t]||{},i=e.attributes[t]||{},n=e.elements[t];!A(n)||!M(n)||(Object.assign(n.style,o),Object.keys(i).forEach(function(a){var s=i[a];s===!1?n.removeAttribute(a):n.setAttribute(a,s===!0?"":s)}))})}function io(r){var e=r.state,t={popper:{position:e.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};return Object.assign(e.elements.popper.style,t.popper),e.styles=t,e.elements.arrow&&Object.assign(e.elements.arrow.style,t.arrow),function(){Object.keys(e.elements).forEach(function(o){var i=e.elements[o],n=e.attributes[o]||{},a=Object.keys(e.styles.hasOwnProperty(o)?e.styles[o]:t[o]),s=a.reduce(function(p,c){return p[c]="",p},{});!A(i)||!M(i)||(Object.assign(i.style,s),Object.keys(n).forEach(function(p){i.removeAttribute(p)}))})}}var er={name:"applyStyles",enabled:!0,phase:"write",fn:oo,effect:io,requires:["computeStyles"]};function R(r){return r.split("-")[0]}var Y=Math.max,pe=Math.min,ee=Math.round;function X(r,e){e===void 0&&(e=!1);var t=r.getBoundingClientRect(),o=1,i=1;if(A(r)&&e){var n=r.offsetHeight,a=r.offsetWidth;a>0&&(o=ee(t.width)/a||1),n>0&&(i=ee(t.height)/n||1)}return{width:t.width/o,height:t.height/i,top:t.top/i,right:t.right/o,bottom:t.bottom/i,left:t.left/o,x:t.left/o,y:t.top/i}}function ce(r){var e=X(r),t=r.offsetWidth,o=r.offsetHeight;return Math.abs(e.width-t)<=1&&(t=e.width),Math.abs(e.height-o)<=1&&(o=e.height),{x:r.offsetLeft,y:r.offsetTop,width:t,height:o}}function De(r,e){var t=e.getRootNode&&e.getRootNode();if(r.contains(e))return!0;if(t&&ye(t)){var o=e;do{if(o&&r.isSameNode(o))return!0;o=o.parentNode||o.host}while(o)}return!1}function _(r){return B(r).getComputedStyle(r)}function pt(r){return["table","td","th"].indexOf(M(r))>=0}function F(r){return((J(r)?r.ownerDocument:r.document)||window.document).documentElement}function te(r){return M(r)==="html"?r:r.assignedSlot||r.parentNode||(ye(r)?r.host:null)||F(r)}function tr(r){return!A(r)||_(r).position==="fixed"?null:r.offsetParent}function no(r){var e=navigator.userAgent.toLowerCase().indexOf("firefox")!==-1,t=navigator.userAgent.indexOf("Trident")!==-1;if(t&&A(r)){var o=_(r);if(o.position==="fixed")return null}var i=te(r);for(ye(i)&&(i=i.host);A(i)&&["html","body"].indexOf(M(i))<0;){var n=_(i);if(n.transform!=="none"||n.perspective!=="none"||n.contain==="paint"||["transform","perspective"].indexOf(n.willChange)!==-1||e&&n.willChange==="filter"||e&&n.filter&&n.filter!=="none")return i;i=i.parentNode}return null}function z(r){for(var e=B(r),t=tr(r);t&&pt(t)&&_(t).position==="static";)t=tr(t);return t&&(M(t)==="html"||M(t)==="body"&&_(t).position==="static")?e:t||no(r)||e}function me(r){return["top","bottom"].indexOf(r)>=0?"x":"y"}function ue(r,e,t){return Y(r,pe(e,t))}function rr(r,e,t){var o=ue(r,e,t);return o>t?t:o}function Ae(){return{top:0,right:0,bottom:0,left:0}}function Me(r){return Object.assign({},Ae(),r)}function Re(r,e){return e.reduce(function(t,o){return t[o]=r,t},{})}var so=function(e,t){return e=typeof e=="function"?e(Object.assign({},t.rects,{placement:t.placement})):e,Me(typeof e!="number"?e:Re(e,oe))};function ao(r){var e,t=r.state,o=r.name,i=r.options,n=t.elements.arrow,a=t.modifiersData.popperOffsets,s=R(t.placement),p=me(s),c=[T,k].indexOf(s)>=0,l=c?"height":"width";if(!(!n||!a)){var m=so(i.padding,t),v=ce(n),u=p==="y"?P:T,w=p==="y"?D:k,f=t.rects.reference[l]+t.rects.reference[p]-a[p]-t.rects.popper[l],g=a[p]-t.rects.reference[p],E=z(n),j=E?p==="y"?E.clientHeight||0:E.clientWidth||0:0,C=f/2-g/2,h=m[u],b=j-v[l]-m[w],x=j/2-v[l]/2+C,y=ue(h,x,b),O=p;t.modifiersData[o]=(e={},e[O]=y,e.centerOffset=y-x,e)}}function lo(r){var e=r.state,t=r.options,o=t.element,i=o===void 0?"[data-popper-arrow]":o;i!=null&&(typeof i=="string"&&(i=e.elements.popper.querySelector(i),!i)||!De(e.elements.popper,i)||(e.elements.arrow=i))}var or={name:"arrow",enabled:!0,phase:"main",fn:ao,effect:lo,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function G(r){return r.split("-")[1]}var po={top:"auto",right:"auto",bottom:"auto",left:"auto"};function co(r){var e=r.x,t=r.y,o=window,i=o.devicePixelRatio||1;return{x:ee(e*i)/i||0,y:ee(t*i)/i||0}}function ir(r){var e,t=r.popper,o=r.popperRect,i=r.placement,n=r.variation,a=r.offsets,s=r.position,p=r.gpuAcceleration,c=r.adaptive,l=r.roundOffsets,m=r.isFixed,v=a.x,u=v===void 0?0:v,w=a.y,f=w===void 0?0:w,g=typeof l=="function"?l({x:u,y:f}):{x:u,y:f};u=g.x,f=g.y;var E=a.hasOwnProperty("x"),j=a.hasOwnProperty("y"),C=T,h=P,b=window;if(c){var x=z(t),y="clientHeight",O="clientWidth";if(x===B(t)&&(x=F(t),_(x).position!=="static"&&s==="absolute"&&(y="scrollHeight",O="scrollWidth")),x=x,i===P||(i===T||i===k)&&n===le){h=D;var I=m&&x===b&&b.visualViewport?b.visualViewport.height:x[y];f-=I-o.height,f*=p?1:-1}if(i===T||(i===P||i===D)&&n===le){C=k;var L=m&&x===b&&b.visualViewport?b.visualViewport.width:x[O];u-=L-o.width,u*=p?1:-1}}var S=Object.assign({position:s},c&&po),V=l===!0?co({x:u,y:f}):{x:u,y:f};if(u=V.x,f=V.y,p){var H;return Object.assign({},S,(H={},H[h]=j?"0":"",H[C]=E?"0":"",H.transform=(b.devicePixelRatio||1)<=1?"translate("+u+"px, "+f+"px)":"translate3d("+u+"px, "+f+"px, 0)",H))}return Object.assign({},S,(e={},e[h]=j?f+"px":"",e[C]=E?u+"px":"",e.transform="",e))}function mo(r){var e=r.state,t=r.options,o=t.gpuAcceleration,i=o===void 0?!0:o,n=t.adaptive,a=n===void 0?!0:n,s=t.roundOffsets,p=s===void 0?!0:s;if(!1)var c;var l={placement:R(e.placement),variation:G(e.placement),popper:e.elements.popper,popperRect:e.rects.popper,gpuAcceleration:i,isFixed:e.options.strategy==="fixed"};e.modifiersData.popperOffsets!=null&&(e.styles.popper=Object.assign({},e.styles.popper,ir(Object.assign({},l,{offsets:e.modifiersData.popperOffsets,position:e.options.strategy,adaptive:a,roundOffsets:p})))),e.modifiersData.arrow!=null&&(e.styles.arrow=Object.assign({},e.styles.arrow,ir(Object.assign({},l,{offsets:e.modifiersData.arrow,position:"absolute",adaptive:!1,roundOffsets:p})))),e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-placement":e.placement})}var nr={name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:mo,data:{}};var qe={passive:!0};function uo(r){var e=r.state,t=r.instance,o=r.options,i=o.scroll,n=i===void 0?!0:i,a=o.resize,s=a===void 0?!0:a,p=B(e.elements.popper),c=[].concat(e.scrollParents.reference,e.scrollParents.popper);return n&&c.forEach(function(l){l.addEventListener("scroll",t.update,qe)}),s&&p.addEventListener("resize",t.update,qe),function(){n&&c.forEach(function(l){l.removeEventListener("scroll",t.update,qe)}),s&&p.removeEventListener("resize",t.update,qe)}}var sr={name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:uo,data:{}};var fo={left:"right",right:"left",bottom:"top",top:"bottom"};function Se(r){return r.replace(/left|right|bottom|top/g,function(e){return fo[e]})}var go={start:"end",end:"start"};function Ye(r){return r.replace(/start|end/g,function(e){return go[e]})}function fe(r){var e=B(r),t=e.pageXOffset,o=e.pageYOffset;return{scrollLeft:t,scrollTop:o}}function de(r){return X(F(r)).left+fe(r).scrollLeft}function ct(r){var e=B(r),t=F(r),o=e.visualViewport,i=t.clientWidth,n=t.clientHeight,a=0,s=0;return o&&(i=o.width,n=o.height,/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(a=o.offsetLeft,s=o.offsetTop)),{width:i,height:n,x:a+de(r),y:s}}function mt(r){var e,t=F(r),o=fe(r),i=(e=r.ownerDocument)==null?void 0:e.body,n=Y(t.scrollWidth,t.clientWidth,i?i.scrollWidth:0,i?i.clientWidth:0),a=Y(t.scrollHeight,t.clientHeight,i?i.scrollHeight:0,i?i.clientHeight:0),s=-o.scrollLeft+de(r),p=-o.scrollTop;return _(i||t).direction==="rtl"&&(s+=Y(t.clientWidth,i?i.clientWidth:0)-n),{width:n,height:a,x:s,y:p}}function ge(r){var e=_(r),t=e.overflow,o=e.overflowX,i=e.overflowY;return/auto|scroll|overlay|hidden/.test(t+i+o)}function ze(r){return["html","body","#document"].indexOf(M(r))>=0?r.ownerDocument.body:A(r)&&ge(r)?r:ze(te(r))}function ie(r,e){var t;e===void 0&&(e=[]);var o=ze(r),i=o===((t=r.ownerDocument)==null?void 0:t.body),n=B(o),a=i?[n].concat(n.visualViewport||[],ge(o)?o:[]):o,s=e.concat(a);return i?s:s.concat(ie(te(a)))}function Ee(r){return Object.assign({},r,{left:r.x,top:r.y,right:r.x+r.width,bottom:r.y+r.height})}function ho(r){var e=X(r);return e.top=e.top+r.clientTop,e.left=e.left+r.clientLeft,e.bottom=e.top+r.clientHeight,e.right=e.left+r.clientWidth,e.width=r.clientWidth,e.height=r.clientHeight,e.x=e.left,e.y=e.top,e}function ar(r,e){return e===Ge?Ee(ct(r)):J(e)?ho(e):Ee(mt(F(r)))}function vo(r){var e=ie(te(r)),t=["absolute","fixed"].indexOf(_(r).position)>=0,o=t&&A(r)?z(r):r;return J(o)?e.filter(function(i){return J(i)&&De(i,o)&&M(i)!=="body"}):[]}function ut(r,e,t){var o=e==="clippingParents"?vo(r):[].concat(e),i=[].concat(o,[t]),n=i[0],a=i.reduce(function(s,p){var c=ar(r,p);return s.top=Y(c.top,s.top),s.right=pe(c.right,s.right),s.bottom=pe(c.bottom,s.bottom),s.left=Y(c.left,s.left),s},ar(r,n));return a.width=a.right-a.left,a.height=a.bottom-a.top,a.x=a.left,a.y=a.top,a}function Ie(r){var e=r.reference,t=r.element,o=r.placement,i=o?R(o):null,n=o?G(o):null,a=e.x+e.width/2-t.width/2,s=e.y+e.height/2-t.height/2,p;switch(i){case P:p={x:a,y:e.y-t.height};break;case D:p={x:a,y:e.y+e.height};break;case k:p={x:e.x+e.width,y:s};break;case T:p={x:e.x-t.width,y:s};break;default:p={x:e.x,y:e.y}}var c=i?me(i):null;if(c!=null){var l=c==="y"?"height":"width";switch(n){case Z:p[c]=p[c]-(e[l]/2-t[l]/2);break;case le:p[c]=p[c]+(e[l]/2-t[l]/2);break;default:}}return p}function K(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=o===void 0?r.placement:o,n=t.boundary,a=n===void 0?Qt:n,s=t.rootBoundary,p=s===void 0?Ge:s,c=t.elementContext,l=c===void 0?be:c,m=t.altBoundary,v=m===void 0?!1:m,u=t.padding,w=u===void 0?0:u,f=Me(typeof w!="number"?w:Re(w,oe)),g=l===be?Jt:be,E=r.rects.popper,j=r.elements[v?g:l],C=ut(J(j)?j:j.contextElement||F(r.elements.popper),a,p),h=X(r.elements.reference),b=Ie({reference:h,element:E,strategy:"absolute",placement:i}),x=Ee(Object.assign({},E,b)),y=l===be?x:h,O={top:C.top-y.top+f.top,bottom:y.bottom-C.bottom+f.bottom,left:C.left-y.left+f.left,right:y.right-C.right+f.right},I=r.modifiersData.offset;if(l===be&&I){var L=I[i];Object.keys(O).forEach(function(S){var V=[k,D].indexOf(S)>=0?1:-1,H=[P,D].indexOf(S)>=0?"y":"x";O[S]+=L[H]*V})}return O}function ft(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=t.boundary,n=t.rootBoundary,a=t.padding,s=t.flipVariations,p=t.allowedAutoPlacements,c=p===void 0?Ue:p,l=G(o),m=l?s?lt:lt.filter(function(w){return G(w)===l}):oe,v=m.filter(function(w){return c.indexOf(w)>=0});v.length===0&&(v=m);var u=v.reduce(function(w,f){return w[f]=K(r,{placement:f,boundary:i,rootBoundary:n,padding:a})[R(f)],w},{});return Object.keys(u).sort(function(w,f){return u[w]-u[f]})}function wo(r){if(R(r)===Xe)return[];var e=Se(r);return[Ye(r),e,Ye(e)]}function xo(r){var e=r.state,t=r.options,o=r.name;if(!e.modifiersData[o]._skip){for(var i=t.mainAxis,n=i===void 0?!0:i,a=t.altAxis,s=a===void 0?!0:a,p=t.fallbackPlacements,c=t.padding,l=t.boundary,m=t.rootBoundary,v=t.altBoundary,u=t.flipVariations,w=u===void 0?!0:u,f=t.allowedAutoPlacements,g=e.options.placement,E=R(g),j=E===g,C=p||(j||!w?[Se(g)]:wo(g)),h=[g].concat(C).reduce(function(ve,re){return ve.concat(R(re)===Xe?ft(e,{placement:re,boundary:l,rootBoundary:m,padding:c,flipVariations:w,allowedAutoPlacements:f}):re)},[]),b=e.rects.reference,x=e.rects.popper,y=new Map,O=!0,I=h[0],L=0;L=0,Oe=Pe?"width":"height",$=K(e,{placement:S,boundary:l,rootBoundary:m,altBoundary:v,padding:c}),q=Pe?H?k:T:H?D:P;b[Oe]>x[Oe]&&(q=Se(q));var Le=Se(q),ne=[];if(n&&ne.push($[V]<=0),s&&ne.push($[q]<=0,$[Le]<=0),ne.every(function(ve){return ve})){I=S,O=!1;break}y.set(S,ne)}if(O)for(var Fe=w?3:1,Qe=function(re){var Be=h.find(function(Ve){var se=y.get(Ve);if(se)return se.slice(0,re).every(function(Je){return Je})});if(Be)return I=Be,"break"},Te=Fe;Te>0;Te--){var _e=Qe(Te);if(_e==="break")break}e.placement!==I&&(e.modifiersData[o]._skip=!0,e.placement=I,e.reset=!0)}}var lr={name:"flip",enabled:!0,phase:"main",fn:xo,requiresIfExists:["offset"],data:{_skip:!1}};function pr(r,e,t){return t===void 0&&(t={x:0,y:0}),{top:r.top-e.height-t.y,right:r.right-e.width+t.x,bottom:r.bottom-e.height+t.y,left:r.left-e.width-t.x}}function cr(r){return[P,k,D,T].some(function(e){return r[e]>=0})}function bo(r){var e=r.state,t=r.name,o=e.rects.reference,i=e.rects.popper,n=e.modifiersData.preventOverflow,a=K(e,{elementContext:"reference"}),s=K(e,{altBoundary:!0}),p=pr(a,o),c=pr(s,i,n),l=cr(p),m=cr(c);e.modifiersData[t]={referenceClippingOffsets:p,popperEscapeOffsets:c,isReferenceHidden:l,hasPopperEscaped:m},e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-reference-hidden":l,"data-popper-escaped":m})}var mr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:bo};function yo(r,e,t){var o=R(r),i=[T,P].indexOf(o)>=0?-1:1,n=typeof t=="function"?t(Object.assign({},e,{placement:r})):t,a=n[0],s=n[1];return a=a||0,s=(s||0)*i,[T,k].indexOf(o)>=0?{x:s,y:a}:{x:a,y:s}}function So(r){var e=r.state,t=r.options,o=r.name,i=t.offset,n=i===void 0?[0,0]:i,a=Ue.reduce(function(l,m){return l[m]=yo(m,e.rects,n),l},{}),s=a[e.placement],p=s.x,c=s.y;e.modifiersData.popperOffsets!=null&&(e.modifiersData.popperOffsets.x+=p,e.modifiersData.popperOffsets.y+=c),e.modifiersData[o]=a}var ur={name:"offset",enabled:!0,phase:"main",requires:["popperOffsets"],fn:So};function Eo(r){var e=r.state,t=r.name;e.modifiersData[t]=Ie({reference:e.rects.reference,element:e.rects.popper,strategy:"absolute",placement:e.placement})}var fr={name:"popperOffsets",enabled:!0,phase:"read",fn:Eo,data:{}};function dt(r){return r==="x"?"y":"x"}function jo(r){var e=r.state,t=r.options,o=r.name,i=t.mainAxis,n=i===void 0?!0:i,a=t.altAxis,s=a===void 0?!1:a,p=t.boundary,c=t.rootBoundary,l=t.altBoundary,m=t.padding,v=t.tether,u=v===void 0?!0:v,w=t.tetherOffset,f=w===void 0?0:w,g=K(e,{boundary:p,rootBoundary:c,padding:m,altBoundary:l}),E=R(e.placement),j=G(e.placement),C=!j,h=me(E),b=dt(h),x=e.modifiersData.popperOffsets,y=e.rects.reference,O=e.rects.popper,I=typeof f=="function"?f(Object.assign({},e.rects,{placement:e.placement})):f,L=typeof I=="number"?{mainAxis:I,altAxis:I}:Object.assign({mainAxis:0,altAxis:0},I),S=e.modifiersData.offset?e.modifiersData.offset[e.placement]:null,V={x:0,y:0};if(!!x){if(n){var H,Pe=h==="y"?P:T,Oe=h==="y"?D:k,$=h==="y"?"height":"width",q=x[h],Le=q+g[Pe],ne=q-g[Oe],Fe=u?-O[$]/2:0,Qe=j===Z?y[$]:O[$],Te=j===Z?-O[$]:-y[$],_e=e.elements.arrow,ve=u&&_e?ce(_e):{width:0,height:0},re=e.modifiersData["arrow#persistent"]?e.modifiersData["arrow#persistent"].padding:Ae(),Be=re[Pe],Ve=re[Oe],se=ue(0,y[$],ve[$]),Je=C?y[$]/2-Fe-se-Be-L.mainAxis:Qe-se-Be-L.mainAxis,Nr=C?-y[$]/2+Fe+se+Ve+L.mainAxis:Te+se+Ve+L.mainAxis,Ze=e.elements.arrow&&z(e.elements.arrow),Dr=Ze?h==="y"?Ze.clientTop||0:Ze.clientLeft||0:0,Tt=(H=S==null?void 0:S[h])!=null?H:0,Ar=q+Je-Tt-Dr,Mr=q+Nr-Tt,Bt=ue(u?pe(Le,Ar):Le,q,u?Y(ne,Mr):ne);x[h]=Bt,V[h]=Bt-q}if(s){var kt,Rr=h==="x"?P:T,Ir=h==="x"?D:k,ae=x[b],He=b==="y"?"height":"width",Nt=ae+g[Rr],Dt=ae-g[Ir],et=[P,T].indexOf(E)!==-1,At=(kt=S==null?void 0:S[b])!=null?kt:0,Mt=et?Nt:ae-y[He]-O[He]-At+L.altAxis,Rt=et?ae+y[He]+O[He]-At-L.altAxis:Dt,It=u&&et?rr(Mt,ae,Rt):ue(u?Mt:Nt,ae,u?Rt:Dt);x[b]=It,V[b]=It-ae}e.modifiersData[o]=V}}var dr={name:"preventOverflow",enabled:!0,phase:"main",fn:jo,requiresIfExists:["offset"]};function gt(r){return{scrollLeft:r.scrollLeft,scrollTop:r.scrollTop}}function ht(r){return r===B(r)||!A(r)?fe(r):gt(r)}function Co(r){var e=r.getBoundingClientRect(),t=ee(e.width)/r.offsetWidth||1,o=ee(e.height)/r.offsetHeight||1;return t!==1||o!==1}function vt(r,e,t){t===void 0&&(t=!1);var o=A(e),i=A(e)&&Co(e),n=F(e),a=X(r,i),s={scrollLeft:0,scrollTop:0},p={x:0,y:0};return(o||!o&&!t)&&((M(e)!=="body"||ge(n))&&(s=ht(e)),A(e)?(p=X(e,!0),p.x+=e.clientLeft,p.y+=e.clientTop):n&&(p.x=de(n))),{x:a.left+s.scrollLeft-p.x,y:a.top+s.scrollTop-p.y,width:a.width,height:a.height}}function Po(r){var e=new Map,t=new Set,o=[];r.forEach(function(n){e.set(n.name,n)});function i(n){t.add(n.name);var a=[].concat(n.requires||[],n.requiresIfExists||[]);a.forEach(function(s){if(!t.has(s)){var p=e.get(s);p&&i(p)}}),o.push(n)}return r.forEach(function(n){t.has(n.name)||i(n)}),o}function wt(r){var e=Po(r);return Zt.reduce(function(t,o){return t.concat(e.filter(function(i){return i.phase===o}))},[])}function xt(r){var e;return function(){return e||(e=new Promise(function(t){Promise.resolve().then(function(){e=void 0,t(r())})})),e}}function bt(r){var e=r.reduce(function(t,o){var i=t[o.name];return t[o.name]=i?Object.assign({},i,o,{options:Object.assign({},i.options,o.options),data:Object.assign({},i.data,o.data)}):o,t},{});return Object.keys(e).map(function(t){return e[t]})}var gr={placement:"bottom",modifiers:[],strategy:"absolute"};function hr(){for(var r=arguments.length,e=new Array(r),t=0;t(r%e+e)%e,xr=class{constructor(e,t,o){this.owner=e,this.containerEl=t,t.on("click",".suggestion-item",this.onSuggestionClick.bind(this)),t.on("mousemove",".suggestion-item",this.onSuggestionMouseover.bind(this)),o.register([],"ArrowUp",i=>{if(!i.isComposing)return this.setSelectedItem(this.selectedItem-1,!0),!1}),o.register([],"ArrowDown",i=>{if(!i.isComposing)return this.setSelectedItem(this.selectedItem+1,!0),!1}),o.register([],"Enter",i=>{if(!i.isComposing)return this.useSelectedItem(i),!1})}onSuggestionClick(e,t){e.preventDefault();let o=this.suggestions.indexOf(t);this.setSelectedItem(o,!1),this.useSelectedItem(e)}onSuggestionMouseover(e,t){let o=this.suggestions.indexOf(t);this.setSelectedItem(o,!1)}setSuggestions(e){this.containerEl.empty();let t=[];e.forEach(o=>{let i=this.containerEl.createDiv("suggestion-item");this.owner.renderSuggestion(o,i),t.push(i)}),this.values=e,this.suggestions=t,this.setSelectedItem(0,!1)}useSelectedItem(e){let t=this.values[this.selectedItem];t&&this.owner.selectSuggestion(t,e)}setSelectedItem(e,t){let o=To(e,this.suggestions.length),i=this.suggestions[this.selectedItem],n=this.suggestions[o];i==null||i.removeClass("is-selected"),n==null||n.addClass("is-selected"),this.selectedItem=o,t&&n.scrollIntoView(!1)}},he=class{constructor(e,t){this.app=e,this.inputEl=t,this.scope=new wr.Scope,this.suggestEl=createDiv("suggestion-container");let o=this.suggestEl.createDiv("suggestion");this.suggest=new xr(this,o,this.scope),this.scope.register([],"Escape",this.close.bind(this)),this.inputEl.addEventListener("input",this.onInputChanged.bind(this)),this.inputEl.addEventListener("focus",this.onInputChanged.bind(this)),this.inputEl.addEventListener("blur",this.close.bind(this)),this.suggestEl.on("mousedown",".suggestion-container",i=>{i.preventDefault()})}onInputChanged(){let e=this.inputEl.value,t=this.getSuggestions(e);if(!t){this.close();return}t.length>0?(this.suggest.setSuggestions(t),this.open(this.app.dom.appContainerEl,this.inputEl)):this.close()}open(e,t){this.app.keymap.pushScope(this.scope),e.appendChild(this.suggestEl),this.popper=yt(t,this.suggestEl,{placement:"bottom-start",modifiers:[{name:"sameWidth",enabled:!0,fn:({state:o,instance:i})=>{let n=`${o.rects.reference.width}px`;o.styles.popper.width!==n&&(o.styles.popper.width=n,i.update())},phase:"beforeWrite",requires:["computeStyles"]}]})}close(){this.app.keymap.popScope(this.scope),this.suggest.setSuggestions([]),this.popper&&this.popper.destroy(),this.suggestEl.detach()}};var Bo="{{DATE}}",br="{{DATE:}}",ko=/{{D?A?T?E?}?}?$/i,No=/{{D?A?T?E?:?$|{{DATE:[^\n\r}]*}}$/i,Do="{{author}}",Ao=/{{a?u?t?h?o?r?}?}?$/i,Mo="{{title}}",Ro=/{{t?i?t?l?e?}?}?$/i,St=class extends he{constructor(e,t){super(e,t);this.app=e;this.inputEl=t;this.lastInput=""}getSuggestions(e){let t=this.inputEl.selectionStart,o=15,i=e.substr(t-o,o),n=[];return this.processToken(i,(a,s)=>{this.lastInput=a[0],n.push(s)}),n}selectSuggestion(e){let t=this.inputEl.selectionStart,o=this.lastInput.length,i=this.inputEl.value,n=0,a=(s,p=0)=>`${i.substr(0,t-o+p)}${s}${i.substr(t)}`;this.processToken(e,(s,p)=>{e.contains(p)&&(this.inputEl.value=a(e),n=t-o+e.length,e===br&&(n-=2))}),this.inputEl.trigger("input"),this.close(),this.inputEl.setSelectionRange(n,n)}renderSuggestion(e,t){e&&t.setText(e)}processToken(e,t){let o=No.exec(e);o&&t(o,br);let i=ko.exec(e);i&&t(i,Bo);let n=Ao.exec(e);n&&t(n,Do);let a=Ro.exec(e);a&&t(a,Mo)}};var yr=W(require("obsidian"));var Et=class extends he{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),o=[],i=e.toLowerCase();return t.forEach(n=>{n instanceof yr.TFolder&&n.path.toLowerCase().contains(i)&&o.push(n)}),o}renderSuggestion(e,t){t.setText(e.path)}selectSuggestion(e){this.inputEl.value=e.path,this.inputEl.trigger("input"),this.close()}};var Sr=W(require("obsidian"));var jt=class extends he{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),o=[],i=e.toLowerCase();return t.forEach(n=>{n instanceof Sr.TFile&&n.extension==="md"&&n.path.toLowerCase().contains(i)&&o.push(n)}),o}renderSuggestion(e,t){t.setText(e.path)}selectSuggestion(e){this.inputEl.value=e.path,this.inputEl.trigger("input"),this.close()}};var je=W(require("obsidian")),Ct=class extends je.Modal{constructor(e,t){super(e.app);this.callback=t;var o,i;this.plugin=e,this.currentServiceProvider=(i=(o=e.settings)==null?void 0:o.serviceProvider)!=null?i:N.google}get settings(){return this.plugin.settings}saveSetting(){return d(this,null,function*(){return this.plugin.saveSettings()})}saveClientId(e){this.currentServiceProvider===N.naver&&(this.plugin.settings.naverClientId=e)}saveClientSecret(e){this.currentServiceProvider===N.naver&&(this.settings.naverClientSecret=e)}get currentClientId(){if(this.currentServiceProvider===N.naver)return this.settings.naverClientId}get currentClientSecret(){if(this.currentServiceProvider===N.naver)return this.settings.naverClientSecret}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:"Service Provider Setting"}),new je.Setting(e).setName("Client ID").addText(t=>{t.setValue(this.currentClientId).onChange(o=>this.saveClientId(o))}),new je.Setting(e).setName("Client Secret").addText(t=>{t.setValue(this.currentClientSecret).onChange(o=>this.saveClientSecret(o))}),new je.Setting(e).addButton(t=>t.setButtonText("Save").setCta().onClick(()=>d(this,null,function*(){var o;yield this.plugin.saveSettings(),this.close(),(o=this.callback)==null||o.call(this)})))}onClose(){this.contentEl.empty()}};var Er="https://github.com/anpigon/obsidian-book-search-plugin",Q;(function(t){t.snakeCase="Snake Case",t.camelCase="Camel Case"})(Q||(Q={}));var jr={folder:"",fileNameFormat:"",frontmatter:"",content:"",useDefaultFrontmatter:!0,defaultFrontmatterKeyType:Q.camelCase,templateFile:"",serviceProvider:N.google,naverClientId:"",naverClientSecret:""},Pt=class extends U.PluginSettingTab{constructor(e,t){super(e,t);this.plugin=t}get settings(){return this.plugin.settings}display(){let{containerEl:e}=this;e.empty(),e.classList.add("book-search-plugin__settings"),Cr(e,"General Settings"),new U.Setting(e).setName("New file location").setDesc("New book notes will be placed here.").addSearch(l=>{try{new Et(this.app,l.inputEl)}catch(m){}l.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.folder).onChange(m=>{this.plugin.settings.folder=m,this.plugin.saveSettings()})});let t=document.createDocumentFragment().createEl("code",{text:We(this.plugin.settings.fileNameFormat)||"{{title}} - {{author}}"});new U.Setting(e).setClass("book-search-plugin__settings--new_file_name").setName("New file name").setDesc("Enter the file name format.").addSearch(l=>{try{new St(this.app,l.inputEl)}catch(m){}l.setPlaceholder("Example: {{title}} - {{author}}").setValue(this.plugin.settings.fileNameFormat).onChange(m=>{this.plugin.settings.fileNameFormat=m==null?void 0:m.trim(),this.plugin.saveSettings(),t.innerHTML=We(m)||"{{title}} - {{author}}"})}),e.createEl("div",{cls:["setting-item-description","book-search-plugin__settings--new_file_name_hint"]}).append(t);let o=document.createDocumentFragment();o.createDiv({text:"Files will be available as templates."}),o.createEl("a",{text:"Example Template",href:`${Er}#example-template`}),new U.Setting(e).setName("Template file").setDesc(o).addSearch(l=>{try{new jt(this.app,l.inputEl)}catch(m){}l.setPlaceholder("Example: templates/template-file").setValue(this.plugin.settings.templateFile).onChange(m=>{this.plugin.settings.templateFile=m,this.plugin.saveSettings()})});let i,n=()=>{i.addClass("book-search-plugin__hide")},a=()=>{i.removeClass("book-search-plugin__hide")},s=(l=(m=>(m=this.settings)==null?void 0:m.serviceProvider)())=>{l===N.naver?a():n()};new U.Setting(e).setName("Service Provider").setDesc("Choose the service provider you want to use to search your books.").setClass("book-search-plugin__settings--service_provider").addDropdown(l=>{var m,v;l.addOption(N.google,`${N.google} (Global)`),l.addOption(N.naver,`${N.naver} (Korean)`),l.setValue((v=(m=this.plugin.settings)==null?void 0:m.serviceProvider)!=null?v:N.google),l.onChange(u=>d(this,null,function*(){let w=u;s(w),this.settings.serviceProvider=w,yield this.plugin.saveSettings()}))}).addExtraButton(l=>{i=l.extraSettingsEl,s(),l.onClick(()=>{new Ct(this.plugin).open()})});let p=[];Pr(e,"Frontmatter Settings",p),p.push(new U.Setting(e).setClass("book-search-plugin__hide").setName("Use the default frontmatter").setDesc("If you don't want the default frontmatter to be inserted, disable it.").addToggle(l=>{l.setValue(this.plugin.settings.useDefaultFrontmatter).onChange(m=>d(this,null,function*(){let v=m;this.plugin.settings.useDefaultFrontmatter=v,yield this.plugin.saveSettings()}))}),new U.Setting(e).setClass("book-search-plugin__hide").setName("Default frontmatter key type").setDesc(Io()).addDropdown(l=>{l.addOption(Q.snakeCase,Q.snakeCase.toString()),l.addOption(Q.camelCase,Q.camelCase.toString()),l.setValue(this.plugin.settings.defaultFrontmatterKeyType),l.onChange(m=>d(this,null,function*(){this.plugin.settings.defaultFrontmatterKeyType=m,yield this.plugin.saveSettings()}))}),new U.Setting(e).setClass("book-search-plugin__hide").setName("(Deprecated) Text to insert into frontmatter").setDesc(Or("#text-to-insert-into-frontmatter")).addTextArea(l=>{let m=this.plugin.settings.frontmatter;l.setValue(m).onChange(v=>d(this,null,function*(){let u=v;this.plugin.settings.frontmatter=u,yield this.plugin.saveSettings()}))}));let c=[];Pr(e,"Content Settings",c),c.push(new U.Setting(e).setClass("book-search-plugin__hide").setName("(Deprecated) Text to insert into content").setDesc(Or("#text-to-insert-into-content")).addTextArea(l=>{let m=this.plugin.settings.content;l.setValue(m).onChange(v=>d(this,null,function*(){let u=v;this.plugin.settings.content=u,yield this.plugin.saveSettings()}))}))}};function Io(){let r=document.createDocumentFragment();return r.append("- Snake Case: ",r.createEl("code",{text:"total_page"}),r.createEl("br"),"- Camel Case: ",r.createEl("code",{text:"totalPage"})),r}function Cr(r,e){let t=document.createDocumentFragment();return t.createEl("h2",{text:e}),new U.Setting(r).setHeading().setName(t)}function Pr(r,e,t){return Cr(r,e).addToggle(o=>{o.onChange(i=>{t.forEach(({settingEl:n})=>{n.toggleClass("book-search-plugin__show",i)})})})}function Or(r){let e=document.createDocumentFragment();return e.append("Please use the template file.",e.createEl("br"),"The following syntaxes are available: ",e.createEl("br"),e.createEl("code",{text:"{{title}}"}),", ",e.createEl("code",{text:"{{author}}"}),", ",e.createEl("code",{text:"{{category}}"}),", ",e.createEl("code",{text:"{{publisher}}"}),", ",e.createEl("code",{text:"{{publishDate}}"}),", ",e.createEl("code",{text:"{{totalPage}}"}),", ",e.createEl("code",{text:"{{coverUrl}}"}),", ",e.createEl("code",{text:"{{isbn10}}"}),", ",e.createEl("code",{text:"{{isbn13}}"}),e.createEl("br"),"Check the ",e.createEl("a",{href:`${Er}${r}`,text:"documentation"})," for more information."),e}var Ke=W(require("obsidian"));function Tr(r,e){return d(this,null,function*(){let{metadataCache:t,vault:o}=r,i=(0,Ke.normalizePath)(e!=null?e:"");if(e==="/")return Promise.resolve("");try{let n=t.getFirstLinkpathDest(i,"");return n?o.cachedRead(n):""}catch(n){return console.error(`Failed to read the daily note template '${i}'`,n),new Ke.Notice("Failed to read the daily note template"),""}})}function Br(r){return r.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(e,t,o,i,n,a)=>{let s=window.moment(),p=window.moment().clone().set({hour:s.get("hour"),minute:s.get("minute"),second:s.get("second")});return o&&p.add(parseInt(i,10),n),a?p.format(a.substring(1).trim()):p.format("YYYY-MM-DD")})}var Ot=class extends Ce.Plugin{onload(){return d(this,null,function*(){yield this.loadSettings(),this.addRibbonIcon("book","Create new book note",()=>this.createNewBookNote()).addClass("obsidian-book-search-plugin-ribbon-class"),this.addCommand({id:"open-book-search-modal",name:"Create new book note",callback:this.createNewBookNote}),this.addCommand({id:"open-book-search-modal-to-insert",name:"Insert the metadata",callback:this.insertMetadata}),this.addSettingTab(new Pt(this.app,this))})}showNotice(e){try{new Ce.Notice(e==null?void 0:e.toString())}catch(t){}}searchBookMetadata(e){return d(this,null,function*(){let t=yield this.openBookSearchModal(e);return yield this.openBookSuggestModal(t)})}getRenderedContents(e){return d(this,null,function*(){let{templateFile:t,useDefaultFrontmatter:o,defaultFrontmatterKeyType:i,frontmatter:n,content:a}=this.settings;if(t){let c=yield Tr(this.app,t);return Ne(e,Br(c))}let s=Ne(e,n);o&&(s=Yt(qt(e,s,i)));let p=Ne(e,a);return s?`--- ${s} --- ${p}`:p})}insertMetadata(){return d(this,null,function*(){let e=this.app.workspace.getActiveViewOfType(Ce.MarkdownView);if(!e){console.warn("Can not find an active markdown view");return}let t=yield this.searchBookMetadata(e.file.basename);if(!e.editor){console.warn("Can not find editor from the active markdown view");return}try{let o=yield this.getRenderedContents(t);e.editor.replaceRange(o,{line:0,ch:0})}catch(o){console.warn(o),this.showNotice(o)}})}createNewBookNote(){return d(this,null,function*(){let e=yield this.searchBookMetadata(),t=this.app.workspace.getLeaf();if(!t){console.warn("No active leaf");return}try{let o=yield this.getRenderedContents(e),i=Ut(e,this.settings.fileNameFormat),n=kr.join(this.settings.folder,i),a=yield this.app.vault.create(n,o);yield t.openFile(a,{state:{mode:"source"}}),t.setEphemeralState({rename:"all"}),yield new nt(this.app).jumpToNextCursorLocation()}catch(o){console.warn(o),this.showNotice(o)}})}openBookSearchModal(e=""){return d(this,null,function*(){return new Promise((t,o)=>new ot(this,e,(i,n)=>i?o(i):t(n)).open())})}openBookSuggestModal(e){return d(this,null,function*(){return new Promise((t,o)=>new it(this.app,e,(i,n)=>i?o(i):t(n)).open())})}loadSettings(){return d(this,null,function*(){this.settings=Object.assign({},jr,yield this.loadData())})}saveSettings(){return d(this,null,function*(){yield this.saveData(this.settings)})}};