/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var ut=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var Nr=Object.prototype.hasOwnProperty;var Lr=(r,e)=>{for(var t in e)ut(r,t,{get:e[t],enumerable:!0})},Rr=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Dr(e))!Nr.call(r,i)&&i!==t&&ut(r,i,{get:()=>e[i],enumerable:!(o=Or(e,i))||o.enumerable});return r};var Fr=r=>Rr(ut({},"__esModule",{value:!0}),r);var Lo={};Lr(Lo,{default:()=>at});module.exports=Fr(Lo);var oe=require("obsidian");var Vt=require("obsidian");var we=class we{constructor(e,t){this.localePreference=e;this.apiKey=t}getLanguageRestriction(e){return e==="default"?window.moment.locale():e}buildSearchParams(e,t){let o={q:e,maxResults:we.MAX_RESULTS,printType:we.PRINT_TYPE,langRestrict:this.getLanguageRestriction((t==null?void 0:t.locale)||this.localePreference)};return this.apiKey&&(o.key=this.apiKey),o}async getByQuery(e,t){try{let o=this.buildSearchParams(e,t),i=await _e("https://www.googleapis.com/books/v1/volumes",o);return i!=null&&i.totalItems?i.items.map(({volumeInfo:n})=>this.createBookItem(n)):[]}catch(o){throw console.warn(o),o}}extractISBNs(e){var t;return(t=e==null?void 0:e.reduce((o,i)=>{let n=i.type==="ISBN_10"?"isbn10":"isbn13";return o[n]=i.identifier.trim(),o},{}))!=null?t:{}}extractBasicBookInfo(e){var t,o,i,n;return{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:(o=(t=e.imageLinks)==null?void 0:t.thumbnail)!=null?o:"",coverSmallUrl:(n=(i=e.imageLinks)==null?void 0:i.smallThumbnail)!=null?n:"",publishDate:e.publishedDate||"",description:e.description,link:e.canonicalVolumeLink||e.infoLink,previewLink:e.previewLink}}createBookItem(e){return{title:"",subtitle:"",author:"",authors:[],category:"",categories:[],publisher:"",publishDate:"",totalPage:"",coverUrl:"",coverSmallUrl:"",description:"",link:"",previewLink:"",...this.extractBasicBookInfo(e),...this.extractISBNs(e.industryIdentifiers)}}formatList(e){var t;return e&&e.length>1?e.map(o=>o.trim()).join(", "):(t=e==null?void 0:e[0])!=null?t:""}static convertGoogleBookImageURLSize(e,t){return e.replace(/(&zoom)=\d/,`$1=${t}`)}};we.MAX_RESULTS=40,we.PRINT_TYPE="books";var Ue=we;var We=class{constructor(e,t){this.clientId=e;this.clientSecret=t}async getByQuery(e){try{let t={query:e,display:50,sort:"sim"},o={"X-Naver-Client-Id":this.clientId,"X-Naver-Client-Secret":this.clientSecret},i=await _e("https://openapi.naver.com/v1/search/book.json",t,o);return i!=null&&i.total?i.items.map(this.createBookItem):[]}catch(t){throw console.warn(t),t}}createBookItem(e){var t,o;return{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}}}};var mt=class extends Error{constructor(e){super(e),this.name="ConfigurationError"}};function Ut(r){switch(r.serviceProvider){case"google":return new Ue(r.localePreference,r.apiKey);case"naver":return Mr(r),new We(r.naverClientId,r.naverClientSecret);default:throw new Error("Unsupported service provider.")}}function Mr(r){if(!r.naverClientId||!r.naverClientSecret)throw new mt('\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.')}async function _e(r,e={},t){let o=new URL(r);return $r(o,e),(await(0,Vt.requestUrl)({url:o.href,method:"GET",headers:{Accept:"*/*","Content-Type":"application/json; charset=utf-8",...t}})).json}function $r(r,e){Object.entries(e).forEach(([t,o])=>{r.searchParams.append(t,o.toString())})}var _t=/^-?[0-9]*$/,dt=/{{DATE(\+-?[0-9]+)?}}/,gt=/{{DATE:([^}\n\r+]*)(\+-?[0-9]+)?}}/;function Hr(r){return r.replace(/[\\,#%&{}/*<>$":@.?|]/g,"").replace(/\s+/g," ")}function ht(r,e,t="md"){let o;return e?o=Be(r,Ge(e)):o=r.author?`${r.title} - ${r.author}`:r.title,Hr(o)+`.${t}`}function jr(r){return Object.entries(r).reduce((e,[t,o])=>(e[Vr(t)]=o,e),{})}function Xt(r,e,t="Snake Case"){var n,l;let o=t==="Camel Case"?r:jr(r),i=typeof e=="string"?Ur(e):e;for(let a in i){let s=(l=(n=i[a])==null?void 0:n.toString().trim())!=null?l:"";o[a]&&o[a]!==s?o[a]=`${o[a]}, ${s}`:o[a]=s}return o}function Be(r,e){return e!=null&&e.trim()?Object.entries(r).reduce((o,[i,n=""])=>o.replace(new RegExp(`{{${i}}}`,"ig"),n),e).replace(/{{\w+}}/gi,"").trim():""}function Vr(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,l;let t=e.indexOf(":");if(t===-1)return[e.trim(),""];let o=(n=e.slice(0,t))==null?void 0:n.trim(),i=(l=e.slice(t+1))==null?void 0:l.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 zt(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 Wt(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&&r.format?window.moment().add(e).format(r==null?void 0:r.format):window.moment().add(e).format("YYYY-MM-DD")}function Ge(r){let e=r;for(;dt.test(e);){let t=dt.exec(e),o=0;if(t!=null&&t[1]){let i=t[1].replace("+","").trim();_t.test(i)&&(o=parseInt(i))}e=Gt(e,dt,Wt({offset:o}))}for(;gt.test(e);){let t=gt.exec(e),o=t==null?void 0:t[1],i=0;if(t!=null&&t[2]){let n=t[2].replace("+","").trim();_t.test(n)&&(i=parseInt(n))}e=Gt(e,gt,Wt({format:o,offset:i}))}return e}function Gt(r,e,t){return r.replace(e,function(){return t})}var k=require("obsidian");var _r={en:"English",af:"Afrikaans","ar-dz":"Arabic (Algeria)","ar-kw":"Arabic (Kuwait)","ar-ly":"Arabic (Libya)","ar-ma":"Arabic (Morocco)","ar-sa":"Arabic (Saudi Arabia)","ar-tn":"Arabic (Tunisia)",ar:"Arabic",az:"Azerbaijani",be:"Belarusian",bg:"Bulgarian",bm:"Bambara",bn:"Bengali",bo:"Tibetan",br:"Breton",bs:"Bosnian",ca:"Catalan",cs:"Czech",cv:"Chuvash",cy:"Welsh",da:"Danish","de-at":"German (Austria)","de-ch":"German (Switzerland)",de:"German",dv:"Divehi",el:"Greek","en-au":"English (Australia)","en-ca":"English (Canada)","en-gb":"English (United Kingdom)","en-ie":"English (Ireland)","en-nz":"English (New Zealand)",eo:"Esperanto","es-do":"Spanish (Dominican Republic)","es-us":"Spanish (United States)",es:"Spanish",et:"Estonian",eu:"Basque",fa:"Persian",fi:"Finnish",fo:"Faroese","fr-ca":"French (Canada)","fr-ch":"French (Switzerland)",fr:"French",fy:"Western Frisian",gd:"Scottish Gaelic",gl:"Galician","gom-latn":"gom (Latin)",gu:"Gujarati",he:"Hebrew",hi:"Hindi",hr:"Croatian",hu:"Hungarian","hy-am":"Armenian (Armenia)",id:"Indonesian",is:"Icelandic",it:"Italian",ja:"Japanese",jv:"Javanese",ka:"Georgian",kk:"Kazakh",km:"Khmer",kn:"Kannada",ko:"Korean",ky:"Kirghiz",lb:"Luxembourgish",lo:"Lao",lt:"Lithuanian",lv:"Latvian",me:"me",mi:"Maori",mk:"Macedonian",ml:"Malayalam",mr:"Marathi","ms-my":"Malay (Malaysia)",ms:"Malay",mt:"Maltese",my:"Burmese",nb:"Norwegian Bokm\xE5l",ne:"Nepali","nl-be":"Dutch (Belgium)",nl:"Dutch",nn:"Norwegian Nynorsk","pa-in":"Punjabi (India)",pl:"Polish","pt-br":"Portuguese (Brazil)",pt:"Portuguese",ro:"Romanian",ru:"Russian",sd:"Sindhi",se:"Northern Sami",si:"Sinhala",sk:"Slovak",sl:"Slovenian",sq:"Albanian","sr-cyrl":"Serbian (Cyrillic)",sr:"Serbian",ss:"Swati",sv:"Swedish",sw:"Swahili",ta:"Tamil",te:"Telugu",tet:"Tetum",th:"Thai","tl-ph":"Tagalog (Philippines)",tlh:"Klingon",tr:"Turkish",tzl:"tzl","tzm-latn":"tzm (Latin)",tzm:"tzm",uk:"Ukrainian",ur:"Urdu","uz-latn":"Uzbek (Latin)",uz:"Uzbek",vi:"Vietnamese","x-pseudo":"x-pseudo",yo:"Yoruba","zh-cn":"Chinese (China)","zh-hk":"Chinese (Hong Kong SAR China)","zh-tw":"Chinese (Taiwan)","zh-mo":"Chinese (Macau SAR China)"},ye=_r;var xe=require("obsidian"),Xe=class extends xe.Modal{constructor(t,o){var i,n;super(t.app);this.callback=o;this.plugin=t,this.currentServiceProvider=(n=(i=t.settings)==null?void 0:i.serviceProvider)!=null?n:"google"}get settings(){return this.plugin.settings}async saveSetting(){return this.plugin.saveSettings()}saveClientId(t){this.currentServiceProvider==="naver"&&(this.plugin.settings.naverClientId=t)}saveClientSecret(t){this.currentServiceProvider==="naver"&&(this.settings.naverClientSecret=t)}get currentClientId(){return this.currentServiceProvider==="naver"?this.settings.naverClientId:""}get currentClientSecret(){return this.currentServiceProvider==="naver"?this.settings.naverClientSecret:""}onOpen(){let{contentEl:t}=this;t.createEl("h2",{text:"Service Provider Setting"}),new xe.Setting(t).setName("Client ID").addText(o=>{o.setValue(this.currentClientId).onChange(i=>this.saveClientId(i))}),new xe.Setting(t).setName("Client Secret").addText(o=>{o.setValue(this.currentClientSecret).onChange(i=>this.saveClientSecret(i))}),new xe.Setting(t).addButton(o=>o.setButtonText("Save").setCta().onClick(async()=>{var i;await this.plugin.saveSettings(),this.close(),(i=this.callback)==null||i.call(this)}))}onClose(){this.contentEl.empty()}};var gr=require("obsidian");var E="top",A="bottom",B="right",C="left",ze="auto",ee=[E,A,B,C],q="start",pe="end",Yt="clippingParents",Ye="viewport",be="popper",Kt="reference",vt=ee.reduce(function(r,e){return r.concat([e+"-"+q,e+"-"+pe])},[]),Ke=[].concat(ee,[ze]).reduce(function(r,e){return r.concat([e,e+"-"+q,e+"-"+pe])},[]),Wr="beforeRead",Gr="read",Xr="afterRead",zr="beforeMain",Yr="main",Kr="afterMain",qr="beforeWrite",Qr="write",Jr="afterWrite",qt=[Wr,Gr,Xr,zr,Yr,Kr,qr,Qr,Jr];function N(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 V(r){var e=b(r).Element;return r instanceof e||r instanceof Element}function O(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 Zr(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];!O(n)||!N(n)||(Object.assign(n.style,o),Object.keys(i).forEach(function(l){var a=i[l];a===!1?n.removeAttribute(l):n.setAttribute(l,a===!0?"":a)}))})}function eo(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]||{},l=Object.keys(e.styles.hasOwnProperty(o)?e.styles[o]:t[o]),a=l.reduce(function(s,u){return s[u]="",s},{});!O(i)||!N(i)||(Object.assign(i.style,a),Object.keys(n).forEach(function(s){i.removeAttribute(s)}))})}}var Qt={name:"applyStyles",enabled:!0,phase:"write",fn:Zr,effect:eo,requires:["computeStyles"]};function L(r){return r.split("-")[0]}var X=Math.max,ce=Math.min,Q=Math.round;function Ee(){var r=navigator.userAgentData;return r!=null&&r.brands&&Array.isArray(r.brands)?r.brands.map(function(e){return e.brand+"/"+e.version}).join(" "):navigator.userAgent}function Ie(){return!/^((?!chrome|android).)*safari/i.test(Ee())}function U(r,e,t){e===void 0&&(e=!1),t===void 0&&(t=!1);var o=r.getBoundingClientRect(),i=1,n=1;e&&O(r)&&(i=r.offsetWidth>0&&Q(o.width)/r.offsetWidth||1,n=r.offsetHeight>0&&Q(o.height)/r.offsetHeight||1);var l=V(r)?b(r):window,a=l.visualViewport,s=!Ie()&&t,u=(o.left+(s&&a?a.offsetLeft:0))/i,p=(o.top+(s&&a?a.offsetTop:0))/n,d=o.width/i,m=o.height/n;return{width:d,height:m,top:p,right:u+d,bottom:p+m,left:u,x:u,y:p}}function ue(r){var e=U(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 Ae(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 H(r){return b(r).getComputedStyle(r)}function wt(r){return["table","td","th"].indexOf(N(r))>=0}function F(r){return((V(r)?r.ownerDocument:r.document)||window.document).documentElement}function J(r){return N(r)==="html"?r:r.assignedSlot||r.parentNode||(Se(r)?r.host:null)||F(r)}function Jt(r){return!O(r)||H(r).position==="fixed"?null:r.offsetParent}function to(r){var e=/firefox/i.test(Ee()),t=/Trident/i.test(Ee());if(t&&O(r)){var o=H(r);if(o.position==="fixed")return null}var i=J(r);for(Se(i)&&(i=i.host);O(i)&&["html","body"].indexOf(N(i))<0;){var n=H(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=Jt(r);t&&wt(t)&&H(t).position==="static";)t=Jt(t);return t&&(N(t)==="html"||N(t)==="body"&&H(t).position==="static")?e:t||to(r)||e}function me(r){return["top","bottom"].indexOf(r)>=0?"x":"y"}function fe(r,e,t){return X(r,ce(e,t))}function Zt(r,e,t){var o=fe(r,e,t);return o>t?t:o}function Oe(){return{top:0,right:0,bottom:0,left:0}}function De(r){return Object.assign({},Oe(),r)}function Ne(r,e){return e.reduce(function(t,o){return t[o]=r,t},{})}var ro=function(e,t){return e=typeof e=="function"?e(Object.assign({},t.rects,{placement:t.placement})):e,De(typeof e!="number"?e:Ne(e,ee))};function oo(r){var e,t=r.state,o=r.name,i=r.options,n=t.elements.arrow,l=t.modifiersData.popperOffsets,a=L(t.placement),s=me(a),u=[C,B].indexOf(a)>=0,p=u?"height":"width";if(!(!n||!l)){var d=ro(i.padding,t),m=ue(n),c=s==="y"?E:C,v=s==="y"?A:B,g=t.rects.reference[p]+t.rects.reference[s]-l[s]-t.rects.popper[p],f=l[s]-t.rects.reference[s],x=z(n),T=x?s==="y"?x.clientHeight||0:x.clientWidth||0:0,P=g/2-f/2,h=d[c],w=T-m[p]-d[v],y=T/2-m[p]/2+P,S=fe(h,y,w),R=s;t.modifiersData[o]=(e={},e[R]=S,e.centerOffset=S-y,e)}}function io(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)||Ae(e.elements.popper,i)&&(e.elements.arrow=i))}var er={name:"arrow",enabled:!0,phase:"main",fn:oo,effect:io,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function _(r){return r.split("-")[1]}var no={top:"auto",right:"auto",bottom:"auto",left:"auto"};function ao(r,e){var t=r.x,o=r.y,i=e.devicePixelRatio||1;return{x:Q(t*i)/i||0,y:Q(o*i)/i||0}}function tr(r){var e,t=r.popper,o=r.popperRect,i=r.placement,n=r.variation,l=r.offsets,a=r.position,s=r.gpuAcceleration,u=r.adaptive,p=r.roundOffsets,d=r.isFixed,m=l.x,c=m===void 0?0:m,v=l.y,g=v===void 0?0:v,f=typeof p=="function"?p({x:c,y:g}):{x:c,y:g};c=f.x,g=f.y;var x=l.hasOwnProperty("x"),T=l.hasOwnProperty("y"),P=C,h=E,w=window;if(u){var y=z(t),S="clientHeight",R="clientWidth";if(y===b(t)&&(y=F(t),H(y).position!=="static"&&a==="absolute"&&(S="scrollHeight",R="scrollWidth")),y=y,i===E||(i===C||i===B)&&n===pe){h=A;var D=d&&y===w&&w.visualViewport?w.visualViewport.height:y[S];g-=D-o.height,g*=s?1:-1}if(i===C||(i===E||i===A)&&n===pe){P=B;var I=d&&y===w&&w.visualViewport?w.visualViewport.width:y[R];c-=I-o.width,c*=s?1:-1}}var M=Object.assign({position:a},u&&no),W=p===!0?ao({x:c,y:g},b(t)):{x:c,y:g};if(c=W.x,g=W.y,s){var $;return Object.assign({},M,($={},$[h]=T?"0":"",$[P]=x?"0":"",$.transform=(w.devicePixelRatio||1)<=1?"translate("+c+"px, "+g+"px)":"translate3d("+c+"px, "+g+"px, 0)",$))}return Object.assign({},M,(e={},e[h]=T?g+"px":"",e[P]=x?c+"px":"",e.transform="",e))}function so(r){var e=r.state,t=r.options,o=t.gpuAcceleration,i=o===void 0?!0:o,n=t.adaptive,l=n===void 0?!0:n,a=t.roundOffsets,s=a===void 0?!0:a,u={placement:L(e.placement),variation:_(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,tr(Object.assign({},u,{offsets:e.modifiersData.popperOffsets,position:e.options.strategy,adaptive:l,roundOffsets:s})))),e.modifiersData.arrow!=null&&(e.styles.arrow=Object.assign({},e.styles.arrow,tr(Object.assign({},u,{offsets:e.modifiersData.arrow,position:"absolute",adaptive:!1,roundOffsets:s})))),e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-placement":e.placement})}var rr={name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:so,data:{}};var qe={passive:!0};function lo(r){var e=r.state,t=r.instance,o=r.options,i=o.scroll,n=i===void 0?!0:i,l=o.resize,a=l===void 0?!0:l,s=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&&s.addEventListener("resize",t.update,qe),function(){n&&u.forEach(function(p){p.removeEventListener("scroll",t.update,qe)}),a&&s.removeEventListener("resize",t.update,qe)}}var or={name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:lo,data:{}};var po={left:"right",right:"left",bottom:"top",top:"bottom"};function Te(r){return r.replace(/left|right|bottom|top/g,function(e){return po[e]})}var co={start:"end",end:"start"};function Qe(r){return r.replace(/start|end/g,function(e){return co[e]})}function de(r){var e=b(r),t=e.pageXOffset,o=e.pageYOffset;return{scrollLeft:t,scrollTop:o}}function ge(r){return U(F(r)).left+de(r).scrollLeft}function yt(r,e){var t=b(r),o=F(r),i=t.visualViewport,n=o.clientWidth,l=o.clientHeight,a=0,s=0;if(i){n=i.width,l=i.height;var u=Ie();(u||!u&&e==="fixed")&&(a=i.offsetLeft,s=i.offsetTop)}return{width:n,height:l,x:a+ge(r),y:s}}function xt(r){var e,t=F(r),o=de(r),i=(e=r.ownerDocument)==null?void 0:e.body,n=X(t.scrollWidth,t.clientWidth,i?i.scrollWidth:0,i?i.clientWidth:0),l=X(t.scrollHeight,t.clientHeight,i?i.scrollHeight:0,i?i.clientHeight:0),a=-o.scrollLeft+ge(r),s=-o.scrollTop;return H(i||t).direction==="rtl"&&(a+=X(t.clientWidth,i?i.clientWidth:0)-n),{width:n,height:l,x:a,y:s}}function he(r){var e=H(r),t=e.overflow,o=e.overflowX,i=e.overflowY;return/auto|scroll|overlay|hidden/.test(t+i+o)}function Je(r){return["html","body","#document"].indexOf(N(r))>=0?r.ownerDocument.body:O(r)&&he(r)?r:Je(J(r))}function te(r,e){var t;e===void 0&&(e=[]);var o=Je(r),i=o===((t=r.ownerDocument)==null?void 0:t.body),n=b(o),l=i?[n].concat(n.visualViewport||[],he(o)?o:[]):o,a=e.concat(l);return i?a:a.concat(te(J(l)))}function Pe(r){return Object.assign({},r,{left:r.x,top:r.y,right:r.x+r.width,bottom:r.y+r.height})}function uo(r,e){var t=U(r,!1,e==="fixed");return t.top=t.top+r.clientTop,t.left=t.left+r.clientLeft,t.bottom=t.top+r.clientHeight,t.right=t.left+r.clientWidth,t.width=r.clientWidth,t.height=r.clientHeight,t.x=t.left,t.y=t.top,t}function ir(r,e,t){return e===Ye?Pe(yt(r,t)):V(e)?uo(e,t):Pe(xt(F(r)))}function mo(r){var e=te(J(r)),t=["absolute","fixed"].indexOf(H(r).position)>=0,o=t&&O(r)?z(r):r;return V(o)?e.filter(function(i){return V(i)&&Ae(i,o)&&N(i)!=="body"}):[]}function bt(r,e,t,o){var i=e==="clippingParents"?mo(r):[].concat(e),n=[].concat(i,[t]),l=n[0],a=n.reduce(function(s,u){var p=ir(r,u,o);return s.top=X(p.top,s.top),s.right=ce(p.right,s.right),s.bottom=ce(p.bottom,s.bottom),s.left=X(p.left,s.left),s},ir(r,l,o));return a.width=a.right-a.left,a.height=a.bottom-a.top,a.x=a.left,a.y=a.top,a}function Le(r){var e=r.reference,t=r.element,o=r.placement,i=o?L(o):null,n=o?_(o):null,l=e.x+e.width/2-t.width/2,a=e.y+e.height/2-t.height/2,s;switch(i){case E:s={x:l,y:e.y-t.height};break;case A:s={x:l,y:e.y+e.height};break;case B:s={x:e.x+e.width,y:a};break;case C:s={x:e.x-t.width,y:a};break;default:s={x:e.x,y:e.y}}var u=i?me(i):null;if(u!=null){var p=u==="y"?"height":"width";switch(n){case q:s[u]=s[u]-(e[p]/2-t[p]/2);break;case pe:s[u]=s[u]+(e[p]/2-t[p]/2);break;default:}}return s}function Y(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=o===void 0?r.placement:o,n=t.strategy,l=n===void 0?r.strategy:n,a=t.boundary,s=a===void 0?Yt:a,u=t.rootBoundary,p=u===void 0?Ye:u,d=t.elementContext,m=d===void 0?be:d,c=t.altBoundary,v=c===void 0?!1:c,g=t.padding,f=g===void 0?0:g,x=De(typeof f!="number"?f:Ne(f,ee)),T=m===be?Kt:be,P=r.rects.popper,h=r.elements[v?T:m],w=bt(V(h)?h:h.contextElement||F(r.elements.popper),s,p,l),y=U(r.elements.reference),S=Le({reference:y,element:P,strategy:"absolute",placement:i}),R=Pe(Object.assign({},P,S)),D=m===be?R:y,I={top:w.top-D.top+x.top,bottom:D.bottom-w.bottom+x.bottom,left:w.left-D.left+x.left,right:D.right-w.right+x.right},M=r.modifiersData.offset;if(m===be&&M){var W=M[i];Object.keys(I).forEach(function($){var ie=[B,A].indexOf($)>=0?1:-1,ne=[E,A].indexOf($)>=0?"y":"x";I[$]+=W[ne]*ie})}return I}function St(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=t.boundary,n=t.rootBoundary,l=t.padding,a=t.flipVariations,s=t.allowedAutoPlacements,u=s===void 0?Ke:s,p=_(o),d=p?a?vt:vt.filter(function(v){return _(v)===p}):ee,m=d.filter(function(v){return u.indexOf(v)>=0});m.length===0&&(m=d);var c=m.reduce(function(v,g){return v[g]=Y(r,{placement:g,boundary:i,rootBoundary:n,padding:l})[L(g)],v},{});return Object.keys(c).sort(function(v,g){return c[v]-c[g]})}function fo(r){if(L(r)===ze)return[];var e=Te(r);return[Qe(r),e,Qe(e)]}function go(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,l=t.altAxis,a=l===void 0?!0:l,s=t.fallbackPlacements,u=t.padding,p=t.boundary,d=t.rootBoundary,m=t.altBoundary,c=t.flipVariations,v=c===void 0?!0:c,g=t.allowedAutoPlacements,f=e.options.placement,x=L(f),T=x===f,P=s||(T||!v?[Te(f)]:fo(f)),h=[f].concat(P).reduce(function(ve,Z){return ve.concat(L(Z)===ze?St(e,{placement:Z,boundary:p,rootBoundary:d,padding:u,flipVariations:v,allowedAutoPlacements:g}):Z)},[]),w=e.rects.reference,y=e.rects.popper,S=new Map,R=!0,D=h[0],I=0;I=0,ne=ie?"width":"height",j=Y(e,{placement:M,boundary:p,rootBoundary:d,altBoundary:m,padding:u}),G=ie?$?B:C:$?A:E;w[ne]>y[ne]&&(G=Te(G));var Me=Te(G),ae=[];if(n&&ae.push(j[W]<=0),a&&ae.push(j[G]<=0,j[Me]<=0),ae.every(function(ve){return ve})){D=M,R=!1;break}S.set(M,ae)}if(R)for(var $e=v?3:1,st=function(Z){var ke=h.find(function(je){var se=S.get(je);if(se)return se.slice(0,Z).every(function(lt){return lt})});if(ke)return D=ke,"break"},Ce=$e;Ce>0;Ce--){var He=st(Ce);if(He==="break")break}e.placement!==D&&(e.modifiersData[o]._skip=!0,e.placement=D,e.reset=!0)}}var nr={name:"flip",enabled:!0,phase:"main",fn:go,requiresIfExists:["offset"],data:{_skip:!1}};function ar(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 sr(r){return[E,B,A,C].some(function(e){return r[e]>=0})}function ho(r){var e=r.state,t=r.name,o=e.rects.reference,i=e.rects.popper,n=e.modifiersData.preventOverflow,l=Y(e,{elementContext:"reference"}),a=Y(e,{altBoundary:!0}),s=ar(l,o),u=ar(a,i,n),p=sr(s),d=sr(u);e.modifiersData[t]={referenceClippingOffsets:s,popperEscapeOffsets:u,isReferenceHidden:p,hasPopperEscaped:d},e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-reference-hidden":p,"data-popper-escaped":d})}var lr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:ho};function vo(r,e,t){var o=L(r),i=[C,E].indexOf(o)>=0?-1:1,n=typeof t=="function"?t(Object.assign({},e,{placement:r})):t,l=n[0],a=n[1];return l=l||0,a=(a||0)*i,[C,B].indexOf(o)>=0?{x:a,y:l}:{x:l,y:a}}function wo(r){var e=r.state,t=r.options,o=r.name,i=t.offset,n=i===void 0?[0,0]:i,l=Ke.reduce(function(p,d){return p[d]=vo(d,e.rects,n),p},{}),a=l[e.placement],s=a.x,u=a.y;e.modifiersData.popperOffsets!=null&&(e.modifiersData.popperOffsets.x+=s,e.modifiersData.popperOffsets.y+=u),e.modifiersData[o]=l}var pr={name:"offset",enabled:!0,phase:"main",requires:["popperOffsets"],fn:wo};function yo(r){var e=r.state,t=r.name;e.modifiersData[t]=Le({reference:e.rects.reference,element:e.rects.popper,strategy:"absolute",placement:e.placement})}var cr={name:"popperOffsets",enabled:!0,phase:"read",fn:yo,data:{}};function Et(r){return r==="x"?"y":"x"}function xo(r){var e=r.state,t=r.options,o=r.name,i=t.mainAxis,n=i===void 0?!0:i,l=t.altAxis,a=l===void 0?!1:l,s=t.boundary,u=t.rootBoundary,p=t.altBoundary,d=t.padding,m=t.tether,c=m===void 0?!0:m,v=t.tetherOffset,g=v===void 0?0:v,f=Y(e,{boundary:s,rootBoundary:u,padding:d,altBoundary:p}),x=L(e.placement),T=_(e.placement),P=!T,h=me(x),w=Et(h),y=e.modifiersData.popperOffsets,S=e.rects.reference,R=e.rects.popper,D=typeof g=="function"?g(Object.assign({},e.rects,{placement:e.placement})):g,I=typeof D=="number"?{mainAxis:D,altAxis:D}:Object.assign({mainAxis:0,altAxis:0},D),M=e.modifiersData.offset?e.modifiersData.offset[e.placement]:null,W={x:0,y:0};if(y){if(n){var $,ie=h==="y"?E:C,ne=h==="y"?A:B,j=h==="y"?"height":"width",G=y[h],Me=G+f[ie],ae=G-f[ne],$e=c?-R[j]/2:0,st=T===q?S[j]:R[j],Ce=T===q?-R[j]:-S[j],He=e.elements.arrow,ve=c&&He?ue(He):{width:0,height:0},Z=e.modifiersData["arrow#persistent"]?e.modifiersData["arrow#persistent"].padding:Oe(),ke=Z[ie],je=Z[ne],se=fe(0,S[j],ve[j]),lt=P?S[j]/2-$e-se-ke-I.mainAxis:st-se-ke-I.mainAxis,Pr=P?-S[j]/2+$e+se+je+I.mainAxis:Ce+se+je+I.mainAxis,pt=e.elements.arrow&&z(e.elements.arrow),Cr=pt?h==="y"?pt.clientTop||0:pt.clientLeft||0:0,Dt=($=M==null?void 0:M[h])!=null?$:0,kr=G+lt-Dt-Cr,Br=G+Pr-Dt,Nt=fe(c?ce(Me,kr):Me,G,c?X(ae,Br):ae);y[h]=Nt,W[h]=Nt-G}if(a){var Lt,Ir=h==="x"?E:C,Ar=h==="x"?A:B,le=y[w],Ve=w==="y"?"height":"width",Rt=le+f[Ir],Ft=le-f[Ar],ct=[E,C].indexOf(x)!==-1,Mt=(Lt=M==null?void 0:M[w])!=null?Lt:0,$t=ct?Rt:le-S[Ve]-R[Ve]-Mt+I.altAxis,Ht=ct?le+S[Ve]+R[Ve]-Mt-I.altAxis:Ft,jt=c&&ct?Zt($t,le,Ht):fe(c?$t:Rt,le,c?Ht:Ft);y[w]=jt,W[w]=jt-le}e.modifiersData[o]=W}}var ur={name:"preventOverflow",enabled:!0,phase:"main",fn:xo,requiresIfExists:["offset"]};function Tt(r){return{scrollLeft:r.scrollLeft,scrollTop:r.scrollTop}}function Pt(r){return r===b(r)||!O(r)?de(r):Tt(r)}function bo(r){var e=r.getBoundingClientRect(),t=Q(e.width)/r.offsetWidth||1,o=Q(e.height)/r.offsetHeight||1;return t!==1||o!==1}function Ct(r,e,t){t===void 0&&(t=!1);var o=O(e),i=O(e)&&bo(e),n=F(e),l=U(r,i,t),a={scrollLeft:0,scrollTop:0},s={x:0,y:0};return(o||!o&&!t)&&((N(e)!=="body"||he(n))&&(a=Pt(e)),O(e)?(s=U(e,!0),s.x+=e.clientLeft,s.y+=e.clientTop):n&&(s.x=ge(n))),{x:l.left+a.scrollLeft-s.x,y:l.top+a.scrollTop-s.y,width:l.width,height:l.height}}function So(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 l=[].concat(n.requires||[],n.requiresIfExists||[]);l.forEach(function(a){if(!t.has(a)){var s=e.get(a);s&&i(s)}}),o.push(n)}return r.forEach(function(n){t.has(n.name)||i(n)}),o}function kt(r){var e=So(r);return qt.reduce(function(t,o){return t.concat(e.filter(function(i){return i.phase===o}))},[])}function Bt(r){var e;return function(){return e||(e=new Promise(function(t){Promise.resolve().then(function(){e=void 0,t(r())})})),e}}function It(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 mr={placement:"bottom",modifiers:[],strategy:"absolute"};function fr(){for(var r=arguments.length,e=new Array(r),t=0;t(r%e+e)%e,Ot=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)}},re=class{constructor(e,t){this.app=e;this.inputEl=t;this.scope=new gr.Scope,this.suggestEl=createDiv("suggestion-container");let o=this.suggestEl.createDiv("suggestion");this.suggest=new Ot(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=At(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 Po="{{DATE}}",hr="{{DATE:}}",Co=/{{D?A?T?E?}?}?$/i,ko=/{{D?A?T?E?:?$|{{DATE:[^\n\r}]*}}$/i,Bo="{{author}}",Io=/{{a?u?t?h?o?r?}?}?$/i,Ao="{{title}}",Oo=/{{t?i?t?l?e?}?}?$/i,Ze=class extends re{constructor(t,o){super(t,o);this.app=t;this.inputEl=o;this.lastInput=""}getSuggestions(t){let o=this.inputEl.selectionStart,i=15,n=t.substr(o-i,i),l=[];return this.processToken(n,(a,s)=>{this.lastInput=a[0],l.push(s)}),l}selectSuggestion(t){let o=this.inputEl.selectionStart,i=this.lastInput.length,n=this.inputEl.value,l=0,a=(s,u=0)=>`${n.substr(0,o-i+u)}${s}${n.substr(o)}`;this.processToken(t,(s,u)=>{t.contains(u)&&(this.inputEl.value=a(t),l=o-i+t.length,t===hr&&(l-=2))}),this.inputEl.trigger("input"),this.close(),this.inputEl.setSelectionRange(l,l)}renderSuggestion(t,o){t&&o.setText(t)}processToken(t,o){let i=ko.exec(t);i&&o(i,hr);let n=Co.exec(t);n&&o(n,Po);let l=Io.exec(t);l&&o(l,Bo);let a=Oo.exec(t);a&&o(a,Ao)}};var vr=require("obsidian");var et=class extends re{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),o=[],i=e.toLowerCase();return t.forEach(n=>{n instanceof vr.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 wr=require("obsidian");var Re=class extends re{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),o=[],i=e.toLowerCase();return t.forEach(n=>{n instanceof wr.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 Do="https://github.com/anpigon/obsidian-book-search-plugin";var Fe={folder:"",fileNameFormat:"",frontmatter:"",content:"",useDefaultFrontmatter:!0,defaultFrontmatterKeyType:"Camel Case",templateFile:"",serviceProvider:"google",naverClientId:"",naverClientSecret:"",localePreference:"default",apiKey:"",openPageOnCompletion:!0,showCoverImageInSearch:!1,enableCoverImageSave:!1,coverImagePath:"",askForLocale:!0},tt=class extends k.PluginSettingTab{constructor(t,o){super(t,o);this.plugin=o}createGeneralSettings(t){this.createHeader("General Settings",t),this.createFileLocationSetting(t),this.createFileNameFormatSetting(t)}createHeader(t,o){let i=document.createDocumentFragment();return i.createEl("h2",{text:t}),new k.Setting(o).setHeading().setName(i)}createFileLocationSetting(t){new k.Setting(t).setName("New file location").setDesc("New book notes will be placed here.").addSearch(o=>{try{new Re(this.app,o.inputEl)}catch(i){console.error(i)}o.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.folder).onChange(i=>{this.plugin.settings.folder=i,this.plugin.saveSettings()})})}createFileNameFormatSetting(t){let o=document.createDocumentFragment().createEl("code",{text:Ge(this.plugin.settings.fileNameFormat)||"{{title}} - {{author}}"});new k.Setting(t).setClass("book-search-plugin__settings--new_file_name").setName("New file name").setDesc("Enter the file name format.").addSearch(i=>{try{new Ze(this.app,i.inputEl)}catch(n){console.error(n)}i.setPlaceholder("Example: {{title}} - {{author}}").setValue(this.plugin.settings.fileNameFormat).onChange(n=>{this.plugin.settings.fileNameFormat=n==null?void 0:n.trim(),this.plugin.saveSettings(),o.innerHTML=Ge(n)||"{{title}} - {{author}}"})}),t.createEl("div",{cls:["setting-item-description","book-search-plugin__settings--new_file_name_hint"]}).append(o)}createTemplateFileSetting(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 k.Setting(t).setName("Template file").setDesc(o).addSearch(i=>{try{new et(this.app,i.inputEl)}catch(n){}i.setPlaceholder("Example: templates/template-file").setValue(this.plugin.settings.templateFile).onChange(n=>{this.plugin.settings.templateFile=n,this.plugin.saveSettings()})})}display(){let{containerEl:t}=this;t.empty(),t.classList.add("book-search-plugin__settings"),this.createGeneralSettings(t),this.createTemplateFileSetting(t);let o,i,n=()=>{o.addClass("book-search-plugin__hide")},l=()=>{o.removeClass("book-search-plugin__hide")},a=()=>{i!==void 0&&i.settingEl.addClass("book-search-plugin__hide")},s=()=>{i!==void 0&&i.settingEl.removeClass("book-search-plugin__hide")},u=(m=(c=>(c=this.plugin.settings)==null?void 0:c.serviceProvider)())=>{m==="naver"?(l(),a()):(n(),s())};new k.Setting(t).setName("Service Provider").setDesc("Choose the service provider you want to use to search your books.").setClass("book-search-plugin__settings--service_provider").addDropdown(m=>{var c,v;m.addOption("google","google (Global)"),m.addOption("naver","naver (Korean)"),m.setValue((v=(c=this.plugin.settings)==null?void 0:c.serviceProvider)!=null?v:"google"),m.onChange(async g=>{let f=g;u(f),this.plugin.settings.serviceProvider=f,await this.plugin.saveSettings()})}).addExtraButton(m=>{o=m.extraSettingsEl,u(),m.onClick(()=>{new Xe(this.plugin).open()})}),i=new k.Setting(t).setName("Preferred locale").setDesc("Sets the preferred locale to use when searching for books.").addDropdown(m=>{let c=window.moment.locale();m.addOption(c,`${ye[c]||c} (Default Locale)`),window.moment.locales().forEach(g=>{let f=ye[g];f&&g!==c&&m.addOption(g,f)});let v=this.plugin.settings.localePreference;m.setValue(v===Fe.localePreference?c:v).onChange(async g=>{let f=g;this.plugin.settings.localePreference=f,await this.plugin.saveSettings()})}),new k.Setting(t).setName("Open New Book Note").setDesc("Enable or disable the automatic opening of the note on creation.").addToggle(m=>m.setValue(this.plugin.settings.openPageOnCompletion).onChange(async c=>{this.plugin.settings.openPageOnCompletion=c,await this.plugin.saveSettings()})),new k.Setting(t).setName("Show Cover Images in Search").setDesc("Toggle to show or hide cover images in the search results.").addToggle(m=>m.setValue(this.plugin.settings.showCoverImageInSearch).onChange(async c=>{this.plugin.settings.showCoverImageInSearch=c,await this.plugin.saveSettings()})),new k.Setting(t).setName("Ask for Locale").setDesc("Toggle to enable or disable asking for the locale every time a search is made.").addToggle(m=>m.setValue(this.plugin.settings.askForLocale).onChange(async c=>{this.plugin.settings.askForLocale=c,await this.plugin.saveSettings()})),new k.Setting(t).setName("Enable Cover Image Save").setDesc("Toggle to enable or disable saving cover images in notes.").addToggle(m=>m.setValue(this.plugin.settings.enableCoverImageSave).onChange(async c=>{this.plugin.settings.enableCoverImageSave=c,await this.plugin.saveSettings()})),new k.Setting(t).setName("Cover Image Path").setDesc("Specify the path where cover images should be saved.").addSearch(m=>{try{new Re(this.app,m.inputEl)}catch(c){}m.setPlaceholder("Enter the path (e.g., Images/Covers)").setValue(this.plugin.settings.coverImagePath).onChange(async c=>{this.plugin.settings.coverImagePath=c.trim(),await this.plugin.saveSettings()})}),this.createHeader("Google API Settings",t),new k.Setting(t).setName("Description About Google API Settings").setDesc("**WARNING** please use this field after you must understand Google Cloud API, such as API key security."),new k.Setting(t).setName("Status Check").setDesc("check whether API key is saved. It does not guarantee that the API key is valid or invalid.").addButton(m=>{m.setButtonText("API Check").onClick(async()=>{this.plugin.settings.apiKey.length?new k.Notice("API key exist."):new k.Notice("API key does not exist.")})});let p=document.createDocumentFragment();p.createDiv({text:"Set your Books API key."}),p.createDiv({text:"For security reason, saved API key is not shown in this textarea after saved."});let d="";new k.Setting(t).setName("Set API Key").setDesc(p).addText(m=>{m.inputEl.type="password",m.setValue("").onChange(async c=>{d=c})}).addButton(m=>{m.setButtonText("Save Key").onClick(async()=>{this.plugin.settings.apiKey=d,await this.plugin.saveSettings(),new k.Notice("API key Saved")})})}};var K=require("obsidian"),rt=class extends K.Modal{constructor(t,o,i){super(t.app);this.plugin=t;this.query=o;this.callback=i;this.SEARCH_BUTTON_TEXT="Search";this.REQUESTING_BUTTON_TEXT="Requesting...";this.isBusy=!1;this.options={locale:t.settings.localePreference},this.serviceProvider=Ut(t.settings)}setBusy(t){var o;this.isBusy=t,(o=this.okBtnRef)==null||o.setDisabled(t).setButtonText(t?this.REQUESTING_BUTTON_TEXT:this.SEARCH_BUTTON_TEXT)}async searchBook(){if(!this.query)return void new K.Notice("No query entered.");if(!this.isBusy){this.setBusy(!0);try{let t=await this.serviceProvider.getByQuery(this.query,this.options);if(!(t!=null&&t.length))return void new K.Notice(`No results found for "${this.query}"`);this.callback(null,t)}catch(t){this.callback(t)}finally{this.setBusy(!1),this.close()}}}onOpen(){let{contentEl:t}=this;t.createEl("h2",{text:"Search Book"}),this.plugin.settings.serviceProvider==="google"&&this.plugin.settings.askForLocale&&this.renderSelectLocale(),t.createDiv({cls:"book-search-plugin__search-modal--input"},o=>{new K.TextComponent(o).setValue(this.query).setPlaceholder("Search by keyword or ISBN").onChange(i=>this.query=i).inputEl.addEventListener("keydown",i=>i.key==="Enter"&&!i.isComposing&&this.searchBook())}),new K.Setting(this.contentEl).addButton(o=>{this.okBtnRef=o.setButtonText(this.SEARCH_BUTTON_TEXT).setCta().onClick(()=>this.searchBook())})}renderSelectLocale(){let t=window.moment.locale();new K.Setting(this.contentEl).setName("Locale").addDropdown(o=>{o.addOption(t,`${ye[t]||t}`),window.moment.locales().forEach(i=>{let n=ye[i];n&&i!==t&&o.addOption(i,n)}),o.setValue(this.options.locale===Fe.localePreference?t:this.options.locale).onChange(i=>this.options.locale=i)})}onClose(){let{contentEl:t}=this;t.empty()}};var yr=require("obsidian"),ot=class extends yr.SuggestModal{constructor(t,o,i,n){super(t);this.suggestion=i;this.onChoose=n;this.showCoverImageInSearch=o}getSuggestions(t){return this.suggestion.filter(o=>{var n,l,a;let i=t==null?void 0:t.toLowerCase();return((n=o.title)==null?void 0:n.toLowerCase().includes(i))||((l=o.author)==null?void 0:l.toLowerCase().includes(i))||((a=o.publisher)==null?void 0:a.toLowerCase().includes(i))})}renderSuggestion(t,o){o.addClass("book-suggestion-item");let i=t.coverLargeUrl||t.coverMediumUrl||t.coverSmallUrl||t.coverUrl;this.showCoverImageInSearch&&i&&o.createEl("img",{cls:"book-cover-image",attr:{src:i,alt:`Cover Image for ${t.title}`}});let n=o.createEl("div",{cls:"book-text-info"});n.createEl("div",{text:t.title});let l=t.publisher?`, ${t.publisher}`:"",a=t.publishDate?`(${t.publishDate})`:"",s=t.totalPage?`, p${t.totalPage}`:"",u=`${t.author}${l}${a}${s}`;n.createEl("small",{text:u})}onChooseSuggestion(t){this.onChoose(null,t)}};var xr=require("obsidian"),it=class{constructor(e){this.app=e}async jumpToNextCursorLocation(){let e=this.app.workspace.getActiveViewOfType(xr.MarkdownView);if(!e)return;let o=(await this.app.vault.cachedRead(e.file)).length+1,i=e.editor;i.focus(),i.setCursor(o,0)}};var nt=require("obsidian");async function br(r,e){let{metadataCache:t,vault:o}=r,i=(0,nt.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 nt.Notice("Failed to read the daily note template"),""}}function Sr(r){return r.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(e,t,o,i,n,l)=>{let a=window.moment(),s=window.moment().clone().set({hour:a.get("hour"),minute:a.get("minute"),second:a.get("second")});return o&&s.add(parseInt(i,10),n),l?s.format(l.substring(1).trim()):s.format("YYYY-MM-DD")})}function Er(r,e){let t=/<%(?:=)(.+)%>/g,o=No();return[...e.matchAll(t)].reduce((n,[l,a])=>{try{let s=new o(["const [book] = arguments",`const output = ${a}`,'if(typeof output === "string") return output',"return JSON.stringify(output)"].join(";"))(r);return n.replace(l,s)}catch(s){console.warn(s)}return n},e)}function No(){try{return new Function("return (function(){}).constructor")()}catch(r){throw console.warn(r),r instanceof SyntaxError?Error("Bad template syntax"):r}}async function Tr(r,e){let t=r.plugins.plugins["templater-obsidian"];t&&!(t!=null&&t.settings.trigger_on_file_creation)&&await t.templater.overwrite_file_commands(e)}var at=class extends oe.Plugin{async onload(){await 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 tt(this.app,this)),console.log(`Book Search: version ${this.manifest.version} (requires obsidian ${this.manifest.minAppVersion})`)}showNotice(e){try{new oe.Notice(e==null?void 0:e.toString())}catch(t){}}async searchBookMetadata(e){let t=await this.openBookSearchModal(e);return await this.openBookSuggestModal(t)}async getRenderedContents(e){let{templateFile:t,useDefaultFrontmatter:o,defaultFrontmatterKeyType:i,enableCoverImageSave:n,coverImagePath:l,frontmatter:a,content:s}=this.settings,u="";if(n){let p=e.coverLargeUrl||e.coverMediumUrl||e.coverSmallUrl||e.coverUrl;if(p){let d=ht(e,this.settings.fileNameFormat,"jpg");e.localCoverImage=await this.downloadAndSaveImage(d,l,p)}}if(t){let p=await br(this.app,t),d=Be(e,Sr(p));u+=Er(e,d)}else{let p=Be(e,a);o&&(p=zt(Xt(e,p,i)));let d=Be(e,s);u+=p?`--- ${p} --- ${d}`:d}return u}async downloadAndSaveImage(e,t,o){let{enableCoverImageSave:i}=this.settings;if(!i)return console.warn("Cover image saving is not enabled."),"";try{let n=await(0,oe.requestUrl)({url:o,method:"GET",headers:{Accept:"image/*"}});if(n.status!==200)throw new Error(`Failed to download image: ${n.status}`);let l=n.arrayBuffer,a=`${t}/${e}`;return await this.app.vault.adapter.writeBinary(a,l),a}catch(n){return console.error("Error downloading or saving image:",n),""}}async insertMetadata(){try{let e=this.app.workspace.getActiveViewOfType(oe.MarkdownView);if(!e){console.warn("Can not find an active markdown view");return}let t=await this.searchBookMetadata(e.file.basename);if(!e.editor){console.warn("Can not find editor from the active markdown view");return}let o=await this.getRenderedContents(t);e.editor.replaceRange(o,{line:0,ch:0})}catch(e){console.warn(e),this.showNotice(e)}}async createNewBookNote(){try{let e=await this.searchBookMetadata(),t=await this.getRenderedContents(e),o=ht(e,this.settings.fileNameFormat),i=`${this.settings.folder}/${o}`,n=await this.app.vault.create(i,t);await Tr(this.app,n),this.openNewBookNote(n)}catch(e){console.warn(e),this.showNotice(e)}}async openNewBookNote(e){if(!this.settings.openPageOnCompletion)return;let t=this.app.workspace.getLeaf();if(!t){console.warn("No active leaf");return}await t.openFile(e,{state:{mode:"source"}}),t.setEphemeralState({rename:"all"}),await new it(this.app).jumpToNextCursorLocation()}async openBookSearchModal(e=""){return new Promise((t,o)=>new rt(this,e,(i,n)=>i?o(i):t(n)).open())}async openBookSuggestModal(e){return new Promise((t,o)=>new ot(this.app,this.settings.showCoverImageInSearch,e,(i,n)=>i?o(i):t(n)).open())}async loadSettings(){this.settings=Object.assign({},Fe,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};