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