/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var Mr=Object.create;var ke=Object.defineProperty;var Rr=Object.getOwnPropertyDescriptor;var Lr=Object.getOwnPropertyNames,Ft=Object.getOwnPropertySymbols,Fr=Object.getPrototypeOf,_t=Object.prototype.hasOwnProperty,_r=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,ye=(r,e)=>{for(var t in e||(e={}))_t.call(e,t)&&$t(r,t,e[t]);if(Ft)for(var t of Ft(e))_r.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})},Vr=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Lr(e))!_t.call(r,o)&&o!=="default"&&ke(r,o,{get:()=>e[o],enumerable:!(t=Rr(e,o))||t.enumerable});return r},q=r=>Vr(Vt(ke(r!=null?Mr(Fr(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var h=(r,e,t)=>new Promise((o,i)=>{var n=l=>{try{a(t.next(l))}catch(u){i(u)}},s=l=>{try{a(t.throw(l))}catch(u){i(u)}},a=l=>l.done?o(l.value):Promise.resolve(l.value).then(n,s);a((t=t.apply(r,e)).next())});$r(exports,{default:()=>Tt});var ne=q(require("obsidian"));var re=q(require("obsidian"));var I;(function(t){t.google="google",t.naver="naver"})(I||(I={}));var Ht=q(require("obsidian"));var rt=class{constructor(e,t){this.localePreference=e;this.apiKey=t}getByQuery(e){return h(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,this.apiKey!==""&&(t.key=this.apiKey);let i=yield He("https://www.googleapis.com/books/v1/volumes",t);return(i==null?void 0:i.totalItems)?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,s;return ye({title:e.title,subtitle:e.subtitle,author:this.formatList(e.authors),authors:e.authors,category:this.formatList(e.categories),categories:e.categories,publisher:e.publisher,totalPage:e.pageCount,coverUrl:(i=(o=e.imageLinks)==null?void 0:o.thumbnail)!=null?i:"",coverSmallUrl:(s=(n=e.imageLinks)==null?void 0:n.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(i=>`${i.trim()}`).join(", "):(o=(t=e==null?void 0:e[0])==null?void 0:t.replace("N/A",""))!=null?o:""}};var ot=class{constructor(e,t){this.clientId=e;this.clientSecret=t}getByQuery(e){return h(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 He("https://openapi.naver.com/v1/search/book.json",t,o);return(i==null?void 0:i.total)?i.items.map(this.createBookItem):[]}catch(t){throw console.warn(t),t}})}createBookItem(e){var t,o;return ye({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 Wt(r){if(r.serviceProvider===I.google)return new rt(r.localePreference,r.apiKey);if(r.serviceProvider===I.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 ot(r.naverClientId,r.naverClientSecret)}}function He(o){return h(this,arguments,function*(r,e={},t){let i=new URL(r);return Object.entries(e).forEach(([s,a])=>{i.searchParams.append(s,a==null?void 0:a.toString())}),(yield(0,Ht.requestUrl)({url:i.href,method:"GET",headers:ye({Accept:"*/*","Content-Type":"application/json; charset=utf-8"},t)})).json})}var it=class extends re.Modal{constructor(e,t,o){super(e.app);this.query=t;this.callback=o;this.isBusy=!1;this.serviceProvider=Wt(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 h(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 re.Notice(`No results found for "${this.query}"`);return}this.callback(null,e)}catch(e){this.callback(e)}this.close()}})}submitEnterCallback(e){e.key==="Enter"&&!e.isComposing&&this.searchBook()}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:"Search Book"}),e.createDiv({cls:"book-search-plugin__search-modal--input"},t=>{new re.TextComponent(t).setValue(this.query).setPlaceholder("Search by keyword or ISBN").onChange(o=>this.query=o).inputEl.addEventListener("keydown",this.submitEnterCallback.bind(this))}),new re.Setting(e).addButton(t=>this.okBtnRef=t.setButtonText("Search").setCta().onClick(()=>{this.searchBook()}))}onClose(){this.contentEl.empty()}};var Gt=q(require("obsidian")),nt=class extends Gt.SuggestModal{constructor(e,t,o,i){super(e);this.suggestion=o;this.onChoose=i;this.showCoverImageInSearch=t}getSuggestions(e){return this.suggestion.filter(t=>{var i,n,s;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))||((s=t.publisher)==null?void 0:s.toLowerCase().includes(o))})}renderSuggestion(e,t){t.addClass("book-suggestion-item");let o=e.coverLargeUrl||e.coverMediumUrl||e.coverSmallUrl||e.coverUrl;this.showCoverImageInSearch&&o&&t.createEl("img",{cls:"book-cover-image",attr:{src:o,alt:`Cover Image for ${e.title}`}});let i=t.createEl("div",{cls:"book-text-info"});i.createEl("div",{text:e.title});let n=e.publisher?`, ${e.publisher}`:"",s=e.publishDate?`(${e.publishDate})`:"",a=e.totalPage?`, p${e.totalPage}`:"",l=`${e.author}${n}${s}${a}`;i.createEl("small",{text:l})}onChooseSuggestion(e){this.onChoose(null,e)}};var Ut=q(require("obsidian")),st=class{constructor(e){this.app=e}jumpToNextCursorLocation(){return h(this,null,function*(){let e=this.app.workspace.getActiveViewOfType(Ut.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 _=q(require("obsidian"));var Xt=/^-?[0-9]*$/,at=/{{DATE(\+-?[0-9]+)?}}/,lt=/{{DATE:([^}\n\r+]*)(\+-?[0-9]+)?}}/;function Hr(r){return r.replace(/[\\,#%&{}/*<>$":@.?|]/g,"").replace(/\s+/g," ")}function pt(r,e,t="md"){let o;return e?o=Ie(r,We(e)):o=r.author?`${r.title} - ${r.author}`:r.title,Hr(o)+`.${t}`}function Wr(r){return Object.entries(r).reduce((e,[t,o])=>(e[Gr(t)]=o,e),{})}function qt(r,e,t=be.snakeCase){var n,s;let o=t===be.camelCase?r:Wr(r),i=typeof e=="string"?Ur(e):e;for(let a in i){let l=(s=(n=i[a])==null?void 0:n.toString().trim())!=null?s:"";o[a]&&o[a]!==l?o[a]=`${o[a]}, ${l}`:o[a]=l}return o}function Ie(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(/{{\w+}}/gi,"").trim():""}function Gr(r){return r.replace(/[A-Z]/g,e=>`_${e==null?void 0:e.toLowerCase()}`)}function Ur(r){return r?r.split(` `).map(e=>{var n,s;let t=e.indexOf(":");if(t===-1)return[e.trim(),""];let o=(n=e.slice(0,t))==null?void 0:n.trim(),i=(s=e.slice(t+1))==null?void 0:s.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 Kt(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(;at.test(e);){let t=at.exec(e),o=0;if(t==null?void 0:t[1]){let i=t[1].replace("+","").trim();Xt.test(i)&&(o=parseInt(i))}e=zt(e,at,Kt({offset:o}))}for(;lt.test(e);){let t=lt.exec(e),o=t==null?void 0:t[1],i=0;if(t==null?void 0:t[2]){let n=t[2].replace("+","").trim();Xt.test(n)&&(i=parseInt(n))}e=zt(e,lt,Kt({format:o,offset:i}))}return e}function zt(r,e,t){return r.replace(e,function(){return t})}var wr=q(require("obsidian"));var j="top",N="bottom",k="right",T="left",Ge="auto",oe=[j,N,k,T],J="start",pe="end",Qt="clippingParents",Ue="viewport",xe="popper",Jt="reference",ct=oe.reduce(function(r,e){return r.concat([e+"-"+J,e+"-"+pe])},[]),Xe=[].concat(oe,[Ge]).reduce(function(r,e){return r.concat([e,e+"-"+J,e+"-"+pe])},[]),Xr="beforeRead",qr="read",Yr="afterRead",Kr="beforeMain",zr="main",Qr="afterMain",Jr="beforeWrite",Zr="write",eo="afterWrite",Zt=[Xr,qr,Yr,Kr,zr,Qr,Jr,Zr,eo];function D(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 Q(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 Se(r){if(typeof ShadowRoot=="undefined")return!1;var e=B(r).ShadowRoot;return r instanceof e||r instanceof ShadowRoot}function to(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)||!D(n)||(Object.assign(n.style,o),Object.keys(i).forEach(function(s){var a=i[s];a===!1?n.removeAttribute(s):n.setAttribute(s,a===!0?"":a)}))})}function ro(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]||{},s=Object.keys(e.styles.hasOwnProperty(o)?e.styles[o]:t[o]),a=s.reduce(function(l,u){return l[u]="",l},{});!A(i)||!D(i)||(Object.assign(i.style,a),Object.keys(n).forEach(function(l){i.removeAttribute(l)}))})}}var er={name:"applyStyles",enabled:!0,phase:"write",fn:to,effect:ro,requires:["computeStyles"]};function M(r){return r.split("-")[0]}var Y=Math.max,ce=Math.min,Z=Math.round;function G(r,e){e===void 0&&(e=!1);var t=r.getBoundingClientRect(),o=1,i=1;if(A(r)&&e){var n=r.offsetHeight,s=r.offsetWidth;s>0&&(o=Z(t.width)/s||1),n>0&&(i=Z(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 me(r){var e=G(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 Ne(r,e){var t=e.getRootNode&&e.getRootNode();if(r.contains(e))return!0;if(t&&Se(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 mt(r){return["table","td","th"].indexOf(D(r))>=0}function F(r){return((Q(r)?r.ownerDocument:r.document)||window.document).documentElement}function ee(r){return D(r)==="html"?r:r.assignedSlot||r.parentNode||(Se(r)?r.host:null)||F(r)}function tr(r){return!A(r)||$(r).position==="fixed"?null:r.offsetParent}function oo(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=ee(r);for(Se(i)&&(i=i.host);A(i)&&["html","body"].indexOf(D(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 K(r){for(var e=B(r),t=tr(r);t&&mt(t)&&$(t).position==="static";)t=tr(t);return t&&(D(t)==="html"||D(t)==="body"&&$(t).position==="static")?e:t||oo(r)||e}function ue(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 De(r){return Object.assign({},Ae(),r)}function Me(r,e){return e.reduce(function(t,o){return t[o]=r,t},{})}var io=function(e,t){return e=typeof e=="function"?e(Object.assign({},t.rects,{placement:t.placement})):e,De(typeof e!="number"?e:Me(e,oe))};function no(r){var e,t=r.state,o=r.name,i=r.options,n=t.elements.arrow,s=t.modifiersData.popperOffsets,a=M(t.placement),l=ue(a),u=[T,k].indexOf(a)>=0,p=u?"height":"width";if(!(!n||!s)){var d=io(i.padding,t),E=me(n),c=l==="y"?j:T,m=l==="y"?N:k,f=t.rects.reference[p]+t.rects.reference[l]-s[l]-t.rects.popper[p],g=s[l]-t.rects.reference[l],y=K(n),P=y?l==="y"?y.clientHeight||0:y.clientWidth||0:0,C=f/2-g/2,v=d[c],b=P-E[p]-d[m],w=P/2-E[p]/2+C,x=fe(v,w,b),O=l;t.modifiersData[o]=(e={},e[O]=x,e.centerOffset=x-w,e)}}function so(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)||!Ne(e.elements.popper,i)||(e.elements.arrow=i))}var or={name:"arrow",enabled:!0,phase:"main",fn:no,effect:so,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function U(r){return r.split("-")[1]}var ao={top:"auto",right:"auto",bottom:"auto",left:"auto"};function lo(r){var e=r.x,t=r.y,o=window,i=o.devicePixelRatio||1;return{x:Z(e*i)/i||0,y:Z(t*i)/i||0}}function ir(r){var e,t=r.popper,o=r.popperRect,i=r.placement,n=r.variation,s=r.offsets,a=r.position,l=r.gpuAcceleration,u=r.adaptive,p=r.roundOffsets,d=r.isFixed,E=s.x,c=E===void 0?0:E,m=s.y,f=m===void 0?0:m,g=typeof p=="function"?p({x:c,y:f}):{x:c,y:f};c=g.x,f=g.y;var y=s.hasOwnProperty("x"),P=s.hasOwnProperty("y"),C=T,v=j,b=window;if(u){var w=K(t),x="clientHeight",O="clientWidth";if(w===B(t)&&(w=F(t),$(w).position!=="static"&&a==="absolute"&&(x="scrollHeight",O="scrollWidth")),w=w,i===j||(i===T||i===k)&&n===pe){v=N;var R=d&&w===b&&b.visualViewport?b.visualViewport.height:w[x];f-=R-o.height,f*=l?1:-1}if(i===T||(i===j||i===N)&&n===pe){C=k;var L=d&&w===b&&b.visualViewport?b.visualViewport.width:w[O];c-=L-o.width,c*=l?1:-1}}var S=Object.assign({position:a},u&&ao),V=p===!0?lo({x:c,y:f}):{x:c,y:f};if(c=V.x,f=V.y,l){var H;return Object.assign({},S,(H={},H[v]=P?"0":"",H[C]=y?"0":"",H.transform=(b.devicePixelRatio||1)<=1?"translate("+c+"px, "+f+"px)":"translate3d("+c+"px, "+f+"px, 0)",H))}return Object.assign({},S,(e={},e[v]=P?f+"px":"",e[C]=y?c+"px":"",e.transform="",e))}function po(r){var e=r.state,t=r.options,o=t.gpuAcceleration,i=o===void 0?!0:o,n=t.adaptive,s=n===void 0?!0:n,a=t.roundOffsets,l=a===void 0?!0:a;if(!1)var u;var p={placement:M(e.placement),variation:U(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({},p,{offsets:e.modifiersData.popperOffsets,position:e.options.strategy,adaptive:s,roundOffsets:l})))),e.modifiersData.arrow!=null&&(e.styles.arrow=Object.assign({},e.styles.arrow,ir(Object.assign({},p,{offsets:e.modifiersData.arrow,position:"absolute",adaptive:!1,roundOffsets:l})))),e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-placement":e.placement})}var nr={name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:po,data:{}};var qe={passive:!0};function co(r){var e=r.state,t=r.instance,o=r.options,i=o.scroll,n=i===void 0?!0:i,s=o.resize,a=s===void 0?!0:s,l=B(e.elements.popper),u=[].concat(e.scrollParents.reference,e.scrollParents.popper);return n&&u.forEach(function(p){p.addEventListener("scroll",t.update,qe)}),a&&l.addEventListener("resize",t.update,qe),function(){n&&u.forEach(function(p){p.removeEventListener("scroll",t.update,qe)}),a&&l.removeEventListener("resize",t.update,qe)}}var sr={name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:co,data:{}};var mo={left:"right",right:"left",bottom:"top",top:"bottom"};function Ee(r){return r.replace(/left|right|bottom|top/g,function(e){return mo[e]})}var uo={start:"end",end:"start"};function Ye(r){return r.replace(/start|end/g,function(e){return uo[e]})}function de(r){var e=B(r),t=e.pageXOffset,o=e.pageYOffset;return{scrollLeft:t,scrollTop:o}}function ge(r){return G(F(r)).left+de(r).scrollLeft}function ut(r){var e=B(r),t=F(r),o=e.visualViewport,i=t.clientWidth,n=t.clientHeight,s=0,a=0;return o&&(i=o.width,n=o.height,/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(s=o.offsetLeft,a=o.offsetTop)),{width:i,height:n,x:s+ge(r),y:a}}function ft(r){var e,t=F(r),o=de(r),i=(e=r.ownerDocument)==null?void 0:e.body,n=Y(t.scrollWidth,t.clientWidth,i?i.scrollWidth:0,i?i.clientWidth:0),s=Y(t.scrollHeight,t.clientHeight,i?i.scrollHeight:0,i?i.clientHeight:0),a=-o.scrollLeft+ge(r),l=-o.scrollTop;return $(i||t).direction==="rtl"&&(a+=Y(t.clientWidth,i?i.clientWidth:0)-n),{width:n,height:s,x:a,y:l}}function he(r){var e=$(r),t=e.overflow,o=e.overflowX,i=e.overflowY;return/auto|scroll|overlay|hidden/.test(t+i+o)}function Ke(r){return["html","body","#document"].indexOf(D(r))>=0?r.ownerDocument.body:A(r)&&he(r)?r:Ke(ee(r))}function ie(r,e){var t;e===void 0&&(e=[]);var o=Ke(r),i=o===((t=r.ownerDocument)==null?void 0:t.body),n=B(o),s=i?[n].concat(n.visualViewport||[],he(o)?o:[]):o,a=e.concat(s);return i?a:a.concat(ie(ee(s)))}function Pe(r){return Object.assign({},r,{left:r.x,top:r.y,right:r.x+r.width,bottom:r.y+r.height})}function fo(r){var e=G(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===Ue?Pe(ut(r)):Q(e)?fo(e):Pe(ft(F(r)))}function go(r){var e=ie(ee(r)),t=["absolute","fixed"].indexOf($(r).position)>=0,o=t&&A(r)?K(r):r;return Q(o)?e.filter(function(i){return Q(i)&&Ne(i,o)&&D(i)!=="body"}):[]}function dt(r,e,t){var o=e==="clippingParents"?go(r):[].concat(e),i=[].concat(o,[t]),n=i[0],s=i.reduce(function(a,l){var u=ar(r,l);return a.top=Y(u.top,a.top),a.right=ce(u.right,a.right),a.bottom=ce(u.bottom,a.bottom),a.left=Y(u.left,a.left),a},ar(r,n));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,i=o?M(o):null,n=o?U(o):null,s=e.x+e.width/2-t.width/2,a=e.y+e.height/2-t.height/2,l;switch(i){case j:l={x:s,y:e.y-t.height};break;case N:l={x:s,y:e.y+e.height};break;case k:l={x:e.x+e.width,y:a};break;case T:l={x:e.x-t.width,y:a};break;default:l={x:e.x,y:e.y}}var u=i?ue(i):null;if(u!=null){var p=u==="y"?"height":"width";switch(n){case J:l[u]=l[u]-(e[p]/2-t[p]/2);break;case pe:l[u]=l[u]+(e[p]/2-t[p]/2);break;default:}}return l}function z(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=o===void 0?r.placement:o,n=t.boundary,s=n===void 0?Qt:n,a=t.rootBoundary,l=a===void 0?Ue:a,u=t.elementContext,p=u===void 0?xe:u,d=t.altBoundary,E=d===void 0?!1:d,c=t.padding,m=c===void 0?0:c,f=De(typeof m!="number"?m:Me(m,oe)),g=p===xe?Jt:xe,y=r.rects.popper,P=r.elements[E?g:p],C=dt(Q(P)?P:P.contextElement||F(r.elements.popper),s,l),v=G(r.elements.reference),b=Re({reference:v,element:y,strategy:"absolute",placement:i}),w=Pe(Object.assign({},y,b)),x=p===xe?w:v,O={top:C.top-x.top+f.top,bottom:x.bottom-C.bottom+f.bottom,left:C.left-x.left+f.left,right:x.right-C.right+f.right},R=r.modifiersData.offset;if(p===xe&&R){var L=R[i];Object.keys(O).forEach(function(S){var V=[k,N].indexOf(S)>=0?1:-1,H=[j,N].indexOf(S)>=0?"y":"x";O[S]+=L[H]*V})}return O}function gt(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=t.boundary,n=t.rootBoundary,s=t.padding,a=t.flipVariations,l=t.allowedAutoPlacements,u=l===void 0?Xe:l,p=U(o),d=p?a?ct:ct.filter(function(m){return U(m)===p}):oe,E=d.filter(function(m){return u.indexOf(m)>=0});E.length===0&&(E=d);var c=E.reduce(function(m,f){return m[f]=z(r,{placement:f,boundary:i,rootBoundary:n,padding:s})[M(f)],m},{});return Object.keys(c).sort(function(m,f){return c[m]-c[f]})}function ho(r){if(M(r)===Ge)return[];var e=Ee(r);return[Ye(r),e,Ye(e)]}function vo(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,s=t.altAxis,a=s===void 0?!0:s,l=t.fallbackPlacements,u=t.padding,p=t.boundary,d=t.rootBoundary,E=t.altBoundary,c=t.flipVariations,m=c===void 0?!0:c,f=t.allowedAutoPlacements,g=e.options.placement,y=M(g),P=y===g,C=l||(P||!m?[Ee(g)]:ho(g)),v=[g].concat(C).reduce(function(we,te){return we.concat(M(te)===Ge?gt(e,{placement:te,boundary:p,rootBoundary:d,padding:u,flipVariations:m,allowedAutoPlacements:f}):te)},[]),b=e.rects.reference,w=e.rects.popper,x=new Map,O=!0,R=v[0],L=0;L=0,Oe=je?"width":"height",W=z(e,{placement:S,boundary:p,rootBoundary:d,altBoundary:E,padding:u}),X=je?H?k:T:H?N:j;b[Oe]>w[Oe]&&(X=Ee(X));var Le=Ee(X),se=[];if(n&&se.push(W[V]<=0),a&&se.push(W[X]<=0,W[Le]<=0),se.every(function(we){return we})){R=S,O=!1;break}x.set(S,se)}if(O)for(var Fe=m?3:1,Je=function(te){var Be=v.find(function($e){var ae=x.get($e);if(ae)return ae.slice(0,te).every(function(Ze){return Ze})});if(Be)return R=Be,"break"},Te=Fe;Te>0;Te--){var _e=Je(Te);if(_e==="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:vo,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[j,k,N,T].some(function(e){return r[e]>=0})}function wo(r){var e=r.state,t=r.name,o=e.rects.reference,i=e.rects.popper,n=e.modifiersData.preventOverflow,s=z(e,{elementContext:"reference"}),a=z(e,{altBoundary:!0}),l=pr(s,o),u=pr(a,i,n),p=cr(l),d=cr(u);e.modifiersData[t]={referenceClippingOffsets:l,popperEscapeOffsets:u,isReferenceHidden:p,hasPopperEscaped:d},e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-reference-hidden":p,"data-popper-escaped":d})}var mr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:wo};function yo(r,e,t){var o=M(r),i=[T,j].indexOf(o)>=0?-1:1,n=typeof t=="function"?t(Object.assign({},e,{placement:r})):t,s=n[0],a=n[1];return s=s||0,a=(a||0)*i,[T,k].indexOf(o)>=0?{x:a,y:s}:{x:s,y:a}}function bo(r){var e=r.state,t=r.options,o=r.name,i=t.offset,n=i===void 0?[0,0]:i,s=Xe.reduce(function(p,d){return p[d]=yo(d,e.rects,n),p},{}),a=s[e.placement],l=a.x,u=a.y;e.modifiersData.popperOffsets!=null&&(e.modifiersData.popperOffsets.x+=l,e.modifiersData.popperOffsets.y+=u),e.modifiersData[o]=s}var ur={name:"offset",enabled:!0,phase:"main",requires:["popperOffsets"],fn:bo};function xo(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:xo,data:{}};function ht(r){return r==="x"?"y":"x"}function So(r){var e=r.state,t=r.options,o=r.name,i=t.mainAxis,n=i===void 0?!0:i,s=t.altAxis,a=s===void 0?!1:s,l=t.boundary,u=t.rootBoundary,p=t.altBoundary,d=t.padding,E=t.tether,c=E===void 0?!0:E,m=t.tetherOffset,f=m===void 0?0:m,g=z(e,{boundary:l,rootBoundary:u,padding:d,altBoundary:p}),y=M(e.placement),P=U(e.placement),C=!P,v=ue(y),b=ht(v),w=e.modifiersData.popperOffsets,x=e.rects.reference,O=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(n){var H,je=v==="y"?j:T,Oe=v==="y"?N:k,W=v==="y"?"height":"width",X=w[v],Le=X+g[je],se=X-g[Oe],Fe=c?-O[W]/2:0,Je=P===J?x[W]:O[W],Te=P===J?-O[W]:-x[W],_e=e.elements.arrow,we=c&&_e?me(_e):{width:0,height:0},te=e.modifiersData["arrow#persistent"]?e.modifiersData["arrow#persistent"].padding:Ae(),Be=te[je],$e=te[Oe],ae=fe(0,x[W],we[W]),Ze=C?x[W]/2-Fe-ae-Be-L.mainAxis:Je-ae-Be-L.mainAxis,Br=C?-x[W]/2+Fe+ae+$e+L.mainAxis:Te+ae+$e+L.mainAxis,et=e.elements.arrow&&K(e.elements.arrow),kr=et?v==="y"?et.clientTop||0:et.clientLeft||0:0,Bt=(H=S==null?void 0:S[v])!=null?H:0,Ir=X+Ze-Bt-kr,Nr=X+Br-Bt,kt=fe(c?ce(Le,Ir):Le,X,c?Y(se,Nr):se);w[v]=kt,V[v]=kt-X}if(a){var It,Ar=v==="x"?j:T,Dr=v==="x"?N:k,le=w[b],Ve=b==="y"?"height":"width",Nt=le+g[Ar],At=le-g[Dr],tt=[j,T].indexOf(y)!==-1,Dt=(It=S==null?void 0:S[b])!=null?It:0,Mt=tt?Nt:le-x[Ve]-O[Ve]-Dt+L.altAxis,Rt=tt?le+x[Ve]+O[Ve]-Dt-L.altAxis:At,Lt=c&&tt?rr(Mt,le,Rt):fe(c?Mt:Nt,le,c?Rt:At);w[b]=Lt,V[b]=Lt-le}e.modifiersData[o]=V}}var dr={name:"preventOverflow",enabled:!0,phase:"main",fn:So,requiresIfExists:["offset"]};function vt(r){return{scrollLeft:r.scrollLeft,scrollTop:r.scrollTop}}function wt(r){return r===B(r)||!A(r)?de(r):vt(r)}function Eo(r){var e=r.getBoundingClientRect(),t=Z(e.width)/r.offsetWidth||1,o=Z(e.height)/r.offsetHeight||1;return t!==1||o!==1}function yt(r,e,t){t===void 0&&(t=!1);var o=A(e),i=A(e)&&Eo(e),n=F(e),s=G(r,i),a={scrollLeft:0,scrollTop:0},l={x:0,y:0};return(o||!o&&!t)&&((D(e)!=="body"||he(n))&&(a=wt(e)),A(e)?(l=G(e,!0),l.x+=e.clientLeft,l.y+=e.clientTop):n&&(l.x=ge(n))),{x:s.left+a.scrollLeft-l.x,y:s.top+a.scrollTop-l.y,width:s.width,height:s.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 s=[].concat(n.requires||[],n.requiresIfExists||[]);s.forEach(function(a){if(!t.has(a)){var l=e.get(a);l&&i(l)}}),o.push(n)}return r.forEach(function(n){t.has(n.name)||i(n)}),o}function bt(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 St(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,yr=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=jo(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)}},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 yr(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=Et(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 Oo="{{DATE}}",br="{{DATE:}}",To=/{{D?A?T?E?}?}?$/i,Bo=/{{D?A?T?E?:?$|{{DATE:[^\n\r}]*}}$/i,ko="{{author}}",Io=/{{a?u?t?h?o?r?}?}?$/i,No="{{title}}",Ao=/{{t?i?t?l?e?}?}?$/i,Pt=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,i=e.substr(t-o,o),n=[];return this.processToken(i,(s,a)=>{this.lastInput=s[0],n.push(a)}),n}selectSuggestion(e){let t=this.inputEl.selectionStart,o=this.lastInput.length,i=this.inputEl.value,n=0,s=(a,l=0)=>`${i.substr(0,t-o+l)}${a}${i.substr(t)}`;this.processToken(e,(a,l)=>{e.contains(l)&&(this.inputEl.value=s(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=Bo.exec(e);o&&t(o,br);let i=To.exec(e);i&&t(i,Oo);let n=Io.exec(e);n&&t(n,ko);let s=Ao.exec(e);s&&t(s,No)}};var xr=q(require("obsidian"));var ze=class extends ve{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),o=[],i=e.toLowerCase();return t.forEach(n=>{n instanceof xr.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=q(require("obsidian"));var Ct=class extends ve{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 Ce=q(require("obsidian")),jt=class extends Ce.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:I.google}get settings(){return this.plugin.settings}saveSetting(){return h(this,null,function*(){return this.plugin.saveSettings()})}saveClientId(e){this.currentServiceProvider===I.naver&&(this.plugin.settings.naverClientId=e)}saveClientSecret(e){this.currentServiceProvider===I.naver&&(this.settings.naverClientSecret=e)}get currentClientId(){return this.currentServiceProvider===I.naver?this.settings.naverClientId:""}get currentClientSecret(){return this.currentServiceProvider===I.naver?this.settings.naverClientSecret:""}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:"Service Provider Setting"}),new Ce.Setting(e).setName("Client ID").addText(t=>{t.setValue(this.currentClientId).onChange(o=>this.saveClientId(o))}),new Ce.Setting(e).setName("Client Secret").addText(t=>{t.setValue(this.currentClientSecret).onChange(o=>this.saveClientSecret(o))}),new Ce.Setting(e).addButton(t=>t.setButtonText("Save").setCta().onClick(()=>h(this,null,function*(){var o;yield this.plugin.saveSettings(),this.close(),(o=this.callback)==null||o.call(this)})))}onClose(){this.contentEl.empty()}};var Do="https://github.com/anpigon/obsidian-book-search-plugin",be;(function(t){t.snakeCase="Snake Case",t.camelCase="Camel Case"})(be||(be={}));var Er={folder:"",fileNameFormat:"",frontmatter:"",content:"",useDefaultFrontmatter:!0,defaultFrontmatterKeyType:be.camelCase,templateFile:"",serviceProvider:I.google,naverClientId:"",naverClientSecret:"",localePreference:"default",apiKey:"",openPageOnCompletion:!0,showCoverImageInSearch:!1,enableCoverImageSave:!1,coverImagePath:""},Ot=class extends _.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 _.Setting(e).setName("New file location").setDesc("New book notes will be placed here.").addSearch(c=>{try{new ze(this.app,c.inputEl)}catch(m){}c.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 _.Setting(e).setClass("book-search-plugin__settings--new_file_name").setName("New file name").setDesc("Enter the file name format.").addSearch(c=>{try{new Pt(this.app,c.inputEl)}catch(m){}c.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:`${Do}#example-template`}),new _.Setting(e).setName("Template file").setDesc(o).addSearch(c=>{try{new Ct(this.app,c.inputEl)}catch(m){}c.setPlaceholder("Example: templates/template-file").setValue(this.plugin.settings.templateFile).onChange(m=>{this.plugin.settings.templateFile=m,this.plugin.saveSettings()})});let i,n,s=()=>{i.addClass("book-search-plugin__hide")},a=()=>{i.removeClass("book-search-plugin__hide")},l=()=>{n!==void 0&&n.settingEl.addClass("book-search-plugin__hide")},u=()=>{n!==void 0&&n.settingEl.removeClass("book-search-plugin__hide")},p=(c=(m=>(m=this.settings)==null?void 0:m.serviceProvider)())=>{c===I.naver?(a(),l()):(s(),u())};new _.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(c=>{var m,f;c.addOption(I.google,`${I.google} (Global)`),c.addOption(I.naver,`${I.naver} (Korean)`),c.setValue((f=(m=this.plugin.settings)==null?void 0:m.serviceProvider)!=null?f:I.google),c.onChange(g=>h(this,null,function*(){let y=g;p(y),this.settings.serviceProvider=y,yield this.plugin.saveSettings()}))}).addExtraButton(c=>{i=c.extraSettingsEl,p(),c.onClick(()=>{new jt(this.plugin).open()})}),n=new _.Setting(e).setName("Preferred locale").setDesc("Sets the preferred locale to use when searching for books.").addDropdown(c=>{let m=window.moment.locale();c.addOption(m,`${m} (Default Locale)`),window.moment.locales().forEach(g=>{c.addOption(g,g)});let f=this.settings.localePreference;f==="default"?c.setValue(m):c.setValue(f),c.onChange(g=>h(this,null,function*(){let y=g;this.settings.localePreference=y,yield this.plugin.saveSettings()}))}),new _.Setting(e).setName("Open New Book Note").setDesc("Enable or disable the automatic opening of the note on creation.").addToggle(c=>c.setValue(this.plugin.settings.openPageOnCompletion).onChange(m=>h(this,null,function*(){this.plugin.settings.openPageOnCompletion=m,yield this.plugin.saveSettings()}))),new _.Setting(e).setName("Show Cover Images in Search").setDesc("Toggle to show or hide cover images in the search results.").addToggle(c=>c.setValue(this.plugin.settings.showCoverImageInSearch).onChange(m=>h(this,null,function*(){this.plugin.settings.showCoverImageInSearch=m,yield this.plugin.saveSettings()}))),new _.Setting(e).setName("Enable Cover Image Save").setDesc("Toggle to enable or disable saving cover images in notes.").addToggle(c=>c.setValue(this.plugin.settings.enableCoverImageSave).onChange(m=>h(this,null,function*(){this.plugin.settings.enableCoverImageSave=m,yield this.plugin.saveSettings()}))),new _.Setting(e).setName("Cover Image Path").setDesc("Specify the path where cover images should be saved.").addSearch(c=>{try{new ze(this.app,c.inputEl)}catch(m){}c.setPlaceholder("Enter the path (e.g., Images/Covers)").setValue(this.plugin.settings.coverImagePath).onChange(m=>h(this,null,function*(){this.plugin.settings.coverImagePath=m.trim(),yield this.plugin.saveSettings()}))});let d=[];Mo(e,"Google API Settings",d);let E="";d.push(new _.Setting(e).setClass("book-search-plugin__hide").setName("Google Book API Key").setDesc("Add your Books API key. **WARNING** please use this field after you must understand Google Cloud API, such as API key security.").addText(c=>{c.inputEl.type="password",c.setValue(this.plugin.settings.apiKey).onChange(m=>h(this,null,function*(){E=m}))}).addButton(c=>{c.setButtonText("Save Key").onClick(()=>h(this,null,function*(){this.plugin.settings.apiKey=E,yield this.plugin.saveSettings(),new _.Notice("Apikey Saved")}))}))}};function Pr(r,e){let t=document.createDocumentFragment();return t.createEl("h2",{text:e}),new _.Setting(r).setHeading().setName(t)}function Mo(r,e,t){return Pr(r,e).addToggle(o=>{o.onChange(i=>{t.forEach(({settingEl:n})=>{n.toggleClass("book-search-plugin__show",i)})})})}var Qe=q(require("obsidian"));function Cr(r,e){return h(this,null,function*(){let{metadataCache:t,vault:o}=r,i=(0,Qe.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 Qe.Notice("Failed to read the daily note template"),""}})}function jr(r){return r.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(e,t,o,i,n,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(i,10),n),s?l.format(s.substring(1).trim()):l.format("YYYY-MM-DD")})}function Or(r,e){let t=/<%(?:=)(.+)%>/g,o=Ro();return[...e.matchAll(t)].reduce((n,[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 n.replace(s,l)}catch(l){console.warn(l)}return n},e)}function Ro(){try{return new Function("return (function(){}).constructor")()}catch(r){throw console.warn(r),r instanceof SyntaxError?Error("Bad template syntax"):r}}function Tr(r,e){return h(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 ne.Plugin{onload(){return h(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 Ot(this.app,this)),console.log(`Book Search: version ${this.manifest.version} (requires obsidian ${this.manifest.minAppVersion})`)})}showNotice(e){try{new ne.Notice(e==null?void 0:e.toString())}catch(t){}}searchBookMetadata(e){return h(this,null,function*(){let t=yield this.openBookSearchModal(e);return yield this.openBookSuggestModal(t)})}getRenderedContents(e){return h(this,null,function*(){let{templateFile:t,useDefaultFrontmatter:o,defaultFrontmatterKeyType:i,enableCoverImageSave:n,coverImagePath:s,frontmatter:a,content:l}=this.settings,u="";if(n){let p=e.coverLargeUrl||e.coverMediumUrl||e.coverSmallUrl||e.coverUrl;if(p){let d=pt(e,this.settings.fileNameFormat,"jpg");e.localCoverImage=yield this.downloadAndSaveImage(d,s,p)}}if(t){let p=yield Cr(this.app,t),d=Ie(e,jr(p));u+=Or(e,d)}else{let p=Ie(e,a);o&&(p=Yt(qt(e,p,i)));let d=Ie(e,l);u+=p?`--- ${p} --- ${d}`:d}return u})}downloadAndSaveImage(e,t,o){return h(this,null,function*(){let{enableCoverImageSave:i}=this.settings;if(!i)return console.warn("Cover image saving is not enabled."),"";try{let n=yield(0,ne.requestUrl)({url:o,method:"GET",headers:{Accept:"image/*"}});if(console.log(n.headers),n.status!==200)throw new Error(`Failed to download image: ${n.status}`);let s=n.arrayBuffer,a=`${t}/${e}`;return yield this.app.vault.adapter.writeBinary(a,s),a}catch(n){return console.error("Error downloading or saving image:",n),""}})}insertMetadata(){return h(this,null,function*(){try{let e=this.app.workspace.getActiveViewOfType(ne.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 h(this,null,function*(){try{let e=yield this.searchBookMetadata(),t=yield this.getRenderedContents(e),o=pt(e,this.settings.fileNameFormat),i=`${this.settings.folder}/${o}`,n=yield this.app.vault.create(i,t);yield Tr(this.app,n),this.openNewBookNote(n)}catch(e){console.warn(e),this.showNotice(e)}})}openNewBookNote(e){return h(this,null,function*(){if(!this.settings.openPageOnCompletion)return;let t=this.app.workspace.getLeaf();if(!t){console.warn("No active leaf");return}yield t.openFile(e,{state:{mode:"source"}}),t.setEphemeralState({rename:"all"}),yield new st(this.app).jumpToNextCursorLocation()})}openBookSearchModal(e=""){return h(this,null,function*(){return new Promise((t,o)=>new it(this,e,(i,n)=>i?o(i):t(n)).open())})}openBookSuggestModal(e){return h(this,null,function*(){return new Promise((t,o)=>new nt(this.app,this.settings.showCoverImageInSearch,e,(i,n)=>i?o(i):t(n)).open())})}loadSettings(){return h(this,null,function*(){this.settings=Object.assign({},Er,yield this.loadData())})}saveSettings(){return h(this,null,function*(){yield this.saveData(this.settings)})}};