You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
46 KiB

/*
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 Lr=Object.getOwnPropertyNames;var Nr=Object.prototype.hasOwnProperty;var Dr=(r,e)=>{for(var t in e)ut(r,t,{get:e[t],enumerable:!0})},Mr=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Lr(e))!Nr.call(r,i)&&i!==t&&ut(r,i,{get:()=>e[i],enumerable:!(o=Or(e,i))||o.enumerable});return r};var Rr=r=>Mr(ut({},"__esModule",{value:!0}),r);var Do={};Dr(Do,{default:()=>at});module.exports=Rr(Do);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 Ue("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 _e=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 Ue("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 _t(r){switch(r.serviceProvider){case"google":return new _e(r.localePreference,r.apiKey);case"naver":return Fr(r),new We(r.naverClientId,r.naverClientSecret);default:throw new Error("Unsupported service provider.")}}function Fr(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 Ue(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 Ut=/^-?[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,p;let o=t==="Camel Case"?r:jr(r),i=typeof e=="string"?_r(e):e;for(let a in i){let s=(p=(n=i[a])==null?void 0:n.toString().trim())!=null?p:"";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 _r(r){return r?r.split(`
`).map(e=>{var n,p;let t=e.indexOf(":");if(t===-1)return[e.trim(),""];let o=(n=e.slice(0,t))==null?void 0:n.trim(),i=(p=e.slice(t+1))==null?void 0:p.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,"&quot;")}"
`:`${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();Ut.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();Ut.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 R=require("obsidian");var Ur={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=Ur;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",I="bottom",k="right",P="left",ze="auto",ee=[E,I,k,P],q="start",pe="end",Kt="clippingParents",Ke="viewport",be="popper",Yt="reference",vt=ee.reduce(function(r,e){return r.concat([e+"-"+q,e+"-"+pe])},[]),Ye=[].concat(ee,[ze]).reduce(function(r,e){return r.concat([e,e+"-"+q,e+"-"+pe])},[]),Wr="beforeRead",Gr="read",Xr="afterRead",zr="beforeMain",Kr="main",Yr="afterMain",qr="beforeWrite",Qr="write",Jr="afterWrite",qt=[Wr,Gr,Xr,zr,Kr,Yr,qr,Qr,Jr];function L(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 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 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];!A(n)||!L(n)||(Object.assign(n.style,o),Object.keys(i).forEach(function(p){var a=i[p];a===!1?n.removeAttribute(p):n.setAttribute(p,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]||{},p=Object.keys(e.styles.hasOwnProperty(o)?e.styles[o]:t[o]),a=p.reduce(function(s,c){return s[c]="",s},{});!A(i)||!L(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 N(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 _(r,e,t){e===void 0&&(e=!1),t===void 0&&(t=!1);var o=r.getBoundingClientRect(),i=1,n=1;e&&A(r)&&(i=r.offsetWidth>0&&Q(o.width)/r.offsetWidth||1,n=r.offsetHeight>0&&Q(o.height)/r.offsetHeight||1);var p=V(r)?b(r):window,a=p.visualViewport,s=!Ie()&&t,c=(o.left+(s&&a?a.offsetLeft:0))/i,l=(o.top+(s&&a?a.offsetTop:0))/n,u=o.width/i,d=o.height/n;return{width:u,height:d,top:l,right:c+u,bottom:l+d,left:c,x:c,y:l}}function ue(r){var e=_(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(L(r))>=0}function M(r){return((V(r)?r.ownerDocument:r.document)||window.document).documentElement}function J(r){return L(r)==="html"?r:r.assignedSlot||r.parentNode||(Se(r)?r.host:null)||M(r)}function Jt(r){return!A(r)||H(r).position==="fixed"?null:r.offsetParent}function to(r){var e=/firefox/i.test(Ee()),t=/Trident/i.test(Ee());if(t&&A(r)){var o=H(r);if(o.position==="fixed")return null}var i=J(r);for(Se(i)&&(i=i.host);A(i)&&["html","body"].indexOf(L(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&&(L(t)==="html"||L(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 Le(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,Le(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,p=t.modifiersData.popperOffsets,a=N(t.placement),s=me(a),c=[P,k].indexOf(a)>=0,l=c?"height":"width";if(!(!n||!p)){var u=ro(i.padding,t),d=ue(n),m=s==="y"?E:P,g=s==="y"?I:k,v=t.rects.reference[l]+t.rects.reference[s]-p[s]-t.rects.popper[l],h=p[s]-t.rects.reference[s],x=z(n),T=x?s==="y"?x.clientHeight||0:x.clientWidth||0:0,C=v/2-h/2,f=u[m],w=T-d[l]-u[g],y=T/2-d[l]/2+C,S=fe(f,y,w),D=s;t.modifiersData[o]=(e={},e[D]=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 U(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,p=r.offsets,a=r.position,s=r.gpuAcceleration,c=r.adaptive,l=r.roundOffsets,u=r.isFixed,d=p.x,m=d===void 0?0:d,g=p.y,v=g===void 0?0:g,h=typeof l=="function"?l({x:m,y:v}):{x:m,y:v};m=h.x,v=h.y;var x=p.hasOwnProperty("x"),T=p.hasOwnProperty("y"),C=P,f=E,w=window;if(c){var y=z(t),S="clientHeight",D="clientWidth";if(y===b(t)&&(y=M(t),H(y).position!=="static"&&a==="absolute"&&(S="scrollHeight",D="scrollWidth")),y=y,i===E||(i===P||i===k)&&n===pe){f=I;var O=u&&y===w&&w.visualViewport?w.visualViewport.height:y[S];v-=O-o.height,v*=s?1:-1}if(i===P||(i===E||i===I)&&n===pe){C=k;var B=u&&y===w&&w.visualViewport?w.visualViewport.width:y[D];m-=B-o.width,m*=s?1:-1}}var F=Object.assign({position:a},c&&no),W=l===!0?ao({x:m,y:v},b(t)):{x:m,y:v};if(m=W.x,v=W.y,s){var $;return Object.assign({},F,($={},$[f]=T?"0":"",$[C]=x?"0":"",$.transform=(w.devicePixelRatio||1)<=1?"translate("+m+"px, "+v+"px)":"translate3d("+m+"px, "+v+"px, 0)",$))}return Object.assign({},F,(e={},e[f]=T?v+"px":"",e[C]=x?m+"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,p=n===void 0?!0:n,a=t.roundOffsets,s=a===void 0?!0:a,c={placement:N(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,tr(Object.assign({},c,{offsets:e.modifiersData.popperOffsets,position:e.options.strategy,adaptive:p,roundOffsets:s})))),e.modifiersData.arrow!=null&&(e.styles.arrow=Object.assign({},e.styles.arrow,tr(Object.assign({},c,{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,p=o.resize,a=p===void 0?!0:p,s=b(e.elements.popper),c=[].concat(e.scrollParents.reference,e.scrollParents.popper);return n&&c.forEach(function(l){l.addEventListener("scroll",t.update,qe)}),a&&s.addEventListener("resize",t.update,qe),function(){n&&c.forEach(function(l){l.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 _(M(r)).left+de(r).scrollLeft}function yt(r,e){var t=b(r),o=M(r),i=t.visualViewport,n=o.clientWidth,p=o.clientHeight,a=0,s=0;if(i){n=i.width,p=i.height;var c=Ie();(c||!c&&e==="fixed")&&(a=i.offsetLeft,s=i.offsetTop)}return{width:n,height:p,x:a+ge(r),y:s}}function xt(r){var e,t=M(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),p=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:p,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(L(r))>=0?r.ownerDocument.body:A(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),p=i?[n].concat(n.visualViewport||[],he(o)?o:[]):o,a=e.concat(p);return i?a:a.concat(te(J(p)))}function Ce(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=_(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===Ke?Ce(yt(r,t)):V(e)?uo(e,t):Ce(xt(M(r)))}function mo(r){var e=te(J(r)),t=["absolute","fixed"].indexOf(H(r).position)>=0,o=t&&A(r)?z(r):r;return V(o)?e.filter(function(i){return V(i)&&Ae(i,o)&&L(i)!=="body"}):[]}function bt(r,e,t,o){var i=e==="clippingParents"?mo(r):[].concat(e),n=[].concat(i,[t]),p=n[0],a=n.reduce(function(s,c){var l=ir(r,c,o);return s.top=X(l.top,s.top),s.right=ce(l.right,s.right),s.bottom=ce(l.bottom,s.bottom),s.left=X(l.left,s.left),s},ir(r,p,o));return a.width=a.right-a.left,a.height=a.bottom-a.top,a.x=a.left,a.y=a.top,a}function De(r){var e=r.reference,t=r.element,o=r.placement,i=o?N(o):null,n=o?U(o):null,p=e.x+e.width/2-t.width/2,a=e.y+e.height/2-t.height/2,s;switch(i){case E:s={x:p,y:e.y-t.height};break;case I:s={x:p,y:e.y+e.height};break;case k:s={x:e.x+e.width,y:a};break;case P:s={x:e.x-t.width,y:a};break;default:s={x:e.x,y:e.y}}var c=i?me(i):null;if(c!=null){var l=c==="y"?"height":"width";switch(n){case q:s[c]=s[c]-(e[l]/2-t[l]/2);break;case pe:s[c]=s[c]+(e[l]/2-t[l]/2);break;default:}}return s}function K(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=o===void 0?r.placement:o,n=t.strategy,p=n===void 0?r.strategy:n,a=t.boundary,s=a===void 0?Kt:a,c=t.rootBoundary,l=c===void 0?Ke:c,u=t.elementContext,d=u===void 0?be:u,m=t.altBoundary,g=m===void 0?!1:m,v=t.padding,h=v===void 0?0:v,x=Le(typeof h!="number"?h:Ne(h,ee)),T=d===be?Yt:be,C=r.rects.popper,f=r.elements[g?T:d],w=bt(V(f)?f:f.contextElement||M(r.elements.popper),s,l,p),y=_(r.elements.reference),S=De({reference:y,element:C,strategy:"absolute",placement:i}),D=Ce(Object.assign({},C,S)),O=d===be?D:y,B={top:w.top-O.top+x.top,bottom:O.bottom-w.bottom+x.bottom,left:w.left-O.left+x.left,right:O.right-w.right+x.right},F=r.modifiersData.offset;if(d===be&&F){var W=F[i];Object.keys(B).forEach(function($){var ie=[k,I].indexOf($)>=0?1:-1,ne=[E,I].indexOf($)>=0?"y":"x";B[$]+=W[ne]*ie})}return B}function St(r,e){e===void 0&&(e={});var t=e,o=t.placement,i=t.boundary,n=t.rootBoundary,p=t.padding,a=t.flipVariations,s=t.allowedAutoPlacements,c=s===void 0?Ye:s,l=U(o),u=l?a?vt:vt.filter(function(g){return U(g)===l}):ee,d=u.filter(function(g){return c.indexOf(g)>=0});d.length===0&&(d=u);var m=d.reduce(function(g,v){return g[v]=K(r,{placement:v,boundary:i,rootBoundary:n,padding:p})[N(v)],g},{});return Object.keys(m).sort(function(g,v){return m[g]-m[v]})}function fo(r){if(N(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,p=t.altAxis,a=p===void 0?!0:p,s=t.fallbackPlacements,c=t.padding,l=t.boundary,u=t.rootBoundary,d=t.altBoundary,m=t.flipVariations,g=m===void 0?!0:m,v=t.allowedAutoPlacements,h=e.options.placement,x=N(h),T=x===h,C=s||(T||!g?[Te(h)]:fo(h)),f=[h].concat(C).reduce(function(ve,Z){return ve.concat(N(Z)===ze?St(e,{placement:Z,boundary:l,rootBoundary:u,padding:c,flipVariations:g,allowedAutoPlacements:v}):Z)},[]),w=e.rects.reference,y=e.rects.popper,S=new Map,D=!0,O=f[0],B=0;B<f.length;B++){var F=f[B],W=N(F),$=U(F)===q,ie=[E,I].indexOf(W)>=0,ne=ie?"width":"height",j=K(e,{placement:F,boundary:l,rootBoundary:u,altBoundary:d,padding:c}),G=ie?$?k:P:$?I:E;w[ne]>y[ne]&&(G=Te(G));var Fe=Te(G),ae=[];if(n&&ae.push(j[W]<=0),a&&ae.push(j[G]<=0,j[Fe]<=0),ae.every(function(ve){return ve})){O=F,D=!1;break}S.set(F,ae)}if(D)for(var $e=g?3:1,st=function(Z){var ke=f.find(function(je){var se=S.get(je);if(se)return se.slice(0,Z).every(function(lt){return lt})});if(ke)return O=ke,"break"},Pe=$e;Pe>0;Pe--){var He=st(Pe);if(He==="break")break}e.placement!==O&&(e.modifiersData[o]._skip=!0,e.placement=O,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,k,I,P].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,p=K(e,{elementContext:"reference"}),a=K(e,{altBoundary:!0}),s=ar(p,o),c=ar(a,i,n),l=sr(s),u=sr(c);e.modifiersData[t]={referenceClippingOffsets:s,popperEscapeOffsets:c,isReferenceHidden:l,hasPopperEscaped:u},e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-reference-hidden":l,"data-popper-escaped":u})}var lr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:ho};function vo(r,e,t){var o=N(r),i=[P,E].indexOf(o)>=0?-1:1,n=typeof t=="function"?t(Object.assign({},e,{placement:r})):t,p=n[0],a=n[1];return p=p||0,a=(a||0)*i,[P,k].indexOf(o)>=0?{x:a,y:p}:{x:p,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,p=Ye.reduce(function(l,u){return l[u]=vo(u,e.rects,n),l},{}),a=p[e.placement],s=a.x,c=a.y;e.modifiersData.popperOffsets!=null&&(e.modifiersData.popperOffsets.x+=s,e.modifiersData.popperOffsets.y+=c),e.modifiersData[o]=p}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]=De({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,p=t.altAxis,a=p===void 0?!1:p,s=t.boundary,c=t.rootBoundary,l=t.altBoundary,u=t.padding,d=t.tether,m=d===void 0?!0:d,g=t.tetherOffset,v=g===void 0?0:g,h=K(e,{boundary:s,rootBoundary:c,padding:u,altBoundary:l}),x=N(e.placement),T=U(e.placement),C=!T,f=me(x),w=Et(f),y=e.modifiersData.popperOffsets,S=e.rects.reference,D=e.rects.popper,O=typeof v=="function"?v(Object.assign({},e.rects,{placement:e.placement})):v,B=typeof O=="number"?{mainAxis:O,altAxis:O}:Object.assign({mainAxis:0,altAxis:0},O),F=e.modifiersData.offset?e.modifiersData.offset[e.placement]:null,W={x:0,y:0};if(y){if(n){var $,ie=f==="y"?E:P,ne=f==="y"?I:k,j=f==="y"?"height":"width",G=y[f],Fe=G+h[ie],ae=G-h[ne],$e=m?-D[j]/2:0,st=T===q?S[j]:D[j],Pe=T===q?-D[j]:-S[j],He=e.elements.arrow,ve=m&&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=C?S[j]/2-$e-se-ke-B.mainAxis:st-se-ke-B.mainAxis,Cr=C?-S[j]/2+$e+se+je+B.mainAxis:Pe+se+je+B.mainAxis,pt=e.elements.arrow&&z(e.elements.arrow),Pr=pt?f==="y"?pt.clientTop||0:pt.clientLeft||0:0,Lt=($=F==null?void 0:F[f])!=null?$:0,kr=G+lt-Lt-Pr,Br=G+Cr-Lt,Nt=fe(m?ce(Fe,kr):Fe,G,m?X(ae,Br):ae);y[f]=Nt,W[f]=Nt-G}if(a){var Dt,Ir=f==="x"?E:P,Ar=f==="x"?I:k,le=y[w],Ve=w==="y"?"height":"width",Mt=le+h[Ir],Rt=le-h[Ar],ct=[E,P].indexOf(x)!==-1,Ft=(Dt=F==null?void 0:F[w])!=null?Dt:0,$t=ct?Mt:le-S[Ve]-D[Ve]-Ft+B.altAxis,Ht=ct?le+S[Ve]+D[Ve]-Ft-B.altAxis:Rt,jt=m&&ct?Zt($t,le,Ht):fe(m?$t:Mt,le,m?Ht:Rt);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 Ct(r){return r===b(r)||!A(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 Pt(r,e,t){t===void 0&&(t=!1);var o=A(e),i=A(e)&&bo(e),n=M(e),p=_(r,i,t),a={scrollLeft:0,scrollTop:0},s={x:0,y:0};return(o||!o&&!t)&&((L(e)!=="body"||he(n))&&(a=Ct(e)),A(e)?(s=_(e,!0),s.x+=e.clientLeft,s.y+=e.clientTop):n&&(s.x=ge(n))),{x:p.left+a.scrollLeft-s.x,y:p.top+a.scrollTop-s.y,width:p.width,height:p.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 p=[].concat(n.requires||[],n.requiresIfExists||[]);p.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;t++)e[t]=arguments[t];return!e.some(function(o){return!(o&&typeof o.getBoundingClientRect=="function")})}function dr(r){r===void 0&&(r={});var e=r,t=e.defaultModifiers,o=t===void 0?[]:t,i=e.defaultOptions,n=i===void 0?mr:i;return function(a,s,c){c===void 0&&(c=n);var l={placement:"bottom",orderedModifiers:[],options:Object.assign({},mr,n),modifiersData:{},elements:{reference:a,popper:s},attributes:{},styles:{}},u=[],d=!1,m={state:l,setOptions:function(x){var T=typeof x=="function"?x(l.options):x;v(),l.options=Object.assign({},n,l.options,T),l.scrollParents={reference:V(a)?te(a):a.contextElement?te(a.contextElement):[],popper:te(s)};var C=kt(It([].concat(o,l.options.modifiers)));return l.orderedModifiers=C.filter(function(f){return f.enabled}),g(),m.update()},forceUpdate:function(){if(!d){var x=l.elements,T=x.reference,C=x.popper;if(fr(T,C)){l.rects={reference:Pt(T,z(C),l.options.strategy==="fixed"),popper:ue(C)},l.reset=!1,l.placement=l.options.placement,l.orderedModifiers.forEach(function(B){return l.modifiersData[B.name]=Object.assign({},B.data)});for(var f=0;f<l.orderedModifiers.length;f++){if(l.reset===!0){l.reset=!1,f=-1;continue}var w=l.orderedModifiers[f],y=w.fn,S=w.options,D=S===void 0?{}:S,O=w.name;typeof y=="function"&&(l=y({state:l,options:D,name:O,instance:m})||l)}}}},update:Bt(function(){return new Promise(function(h){m.forceUpdate(),h(l)})}),destroy:function(){v(),d=!0}};if(!fr(a,s))return m;m.setOptions(c).then(function(h){!d&&c.onFirstUpdate&&c.onFirstUpdate(h)});function g(){l.orderedModifiers.forEach(function(h){var x=h.name,T=h.options,C=T===void 0?{}:T,f=h.effect;if(typeof f=="function"){var w=f({state:l,name:x,instance:m,options:C}),y=function(){};u.push(w||y)}})}function v(){u.forEach(function(h){return h()}),u=[]}return m}}var Eo=[or,cr,rr,Qt,pr,nr,ur,er,lr],At=dr({defaultModifiers:Eo});var To=(r,e)=>(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 Co="{{DATE}}",hr="{{DATE:}}",Po=/{{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),p=[];return this.processToken(n,(a,s)=>{this.lastInput=a[0],p.push(s)}),p}selectSuggestion(t){let o=this.inputEl.selectionStart,i=this.lastInput.length,n=this.inputEl.value,p=0,a=(s,c=0)=>`${n.substr(0,o-i+c)}${s}${n.substr(o)}`;this.processToken(t,(s,c)=>{t.contains(c)&&(this.inputEl.value=a(t),p=o-i+t.length,t===hr&&(p-=2))}),this.inputEl.trigger("input"),this.close(),this.inputEl.setSelectionRange(p,p)}renderSuggestion(t,o){t&&o.setText(t)}processToken(t,o){let i=ko.exec(t);i&&o(i,hr);let n=Po.exec(t);n&&o(n,Co);let p=Io.exec(t);p&&o(p,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 Me=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 Lo="https://github.com/anpigon/obsidian-book-search-plugin";var Re={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 R.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 R.Setting(o).setHeading().setName(i)}createFoldingHeader(t,o,i){return this.createHeader(o,t).addToggle(n=>{n.onChange(p=>{i.forEach(({settingEl:a})=>{a.toggleClass("book-search-plugin__show",p)})})})}createFileLocationSetting(t){new R.Setting(t).setName("New file location").setDesc("New book notes will be placed here.").addSearch(o=>{try{new Me(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 R.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)}createAPIKeySettings(t){let o=[];this.createFoldingHeader(t,"Google API Settings",o);let i="";o.push(new R.Setting(t).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(n=>{n.inputEl.type="password",n.setValue(this.plugin.settings.apiKey).onChange(async p=>{i=p})}).addButton(n=>{n.setButtonText("Save Key").onClick(async()=>{this.plugin.settings.apiKey=i,await this.plugin.saveSettings(),new R.Notice("Apikey Saved")})}))}createTemplateFileSetting(t){let o=document.createDocumentFragment();o.createDiv({text:"Files will be available as templates."}),o.createEl("a",{text:"Example Template",href:`${Lo}#example-template`}),new R.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")},p=()=>{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")},c=(l=(u=>(u=this.plugin.settings)==null?void 0:u.serviceProvider)())=>{l==="naver"?(p(),a()):(n(),s())};new R.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(l=>{var u,d;l.addOption("google","google (Global)"),l.addOption("naver","naver (Korean)"),l.setValue((d=(u=this.plugin.settings)==null?void 0:u.serviceProvider)!=null?d:"google"),l.onChange(async m=>{let g=m;c(g),this.plugin.settings.serviceProvider=g,await this.plugin.saveSettings()})}).addExtraButton(l=>{o=l.extraSettingsEl,c(),l.onClick(()=>{new Xe(this.plugin).open()})}),i=new R.Setting(t).setName("Preferred locale").setDesc("Sets the preferred locale to use when searching for books.").addDropdown(l=>{let u=window.moment.locale();l.addOption(u,`${ye[u]||u} (Default Locale)`),window.moment.locales().forEach(m=>{let g=ye[m];g&&m!==u&&l.addOption(m,g)});let d=this.plugin.settings.localePreference;l.setValue(d===Re.localePreference?u:d).onChange(async m=>{let g=m;this.plugin.settings.localePreference=g,await this.plugin.saveSettings()})}),new R.Setting(t).setName("Open New Book Note").setDesc("Enable or disable the automatic opening of the note on creation.").addToggle(l=>l.setValue(this.plugin.settings.openPageOnCompletion).onChange(async u=>{this.plugin.settings.openPageOnCompletion=u,await this.plugin.saveSettings()})),new R.Setting(t).setName("Show Cover Images in Search").setDesc("Toggle to show or hide cover images in the search results.").addToggle(l=>l.setValue(this.plugin.settings.showCoverImageInSearch).onChange(async u=>{this.plugin.settings.showCoverImageInSearch=u,await this.plugin.saveSettings()})),new R.Setting(t).setName("Ask for Locale").setDesc("Toggle to enable or disable asking for the locale every time a search is made.").addToggle(l=>l.setValue(this.plugin.settings.askForLocale).onChange(async u=>{this.plugin.settings.askForLocale=u,await this.plugin.saveSettings()})),new R.Setting(t).setName("Enable Cover Image Save").setDesc("Toggle to enable or disable saving cover images in notes.").addToggle(l=>l.setValue(this.plugin.settings.enableCoverImageSave).onChange(async u=>{this.plugin.settings.enableCoverImageSave=u,await this.plugin.saveSettings()})),new R.Setting(t).setName("Cover Image Path").setDesc("Specify the path where cover images should be saved.").addSearch(l=>{try{new Me(this.app,l.inputEl)}catch(u){}l.setPlaceholder("Enter the path (e.g., Images/Covers)").setValue(this.plugin.settings.coverImagePath).onChange(async u=>{this.plugin.settings.coverImagePath=u.trim(),await this.plugin.saveSettings()})}),this.createAPIKeySettings(t)}};var Y=require("obsidian"),rt=class extends Y.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=_t(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 Y.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 Y.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 Y.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 Y.Setting(this.contentEl).addButton(o=>{this.okBtnRef=o.setButtonText(this.SEARCH_BUTTON_TEXT).setCta().onClick(()=>this.searchBook())})}renderSelectLocale(){let t=window.moment.locale();new Y.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===Re.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,p,a;let i=t==null?void 0:t.toLowerCase();return((n=o.title)==null?void 0:n.toLowerCase().includes(i))||((p=o.author)==null?void 0:p.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 p=t.publisher?`, ${t.publisher}`:"",a=t.publishDate?`(${t.publishDate})`:"",s=t.totalPage?`, p${t.totalPage}`:"",c=`${t.author}${p}${a}${s}`;n.createEl("small",{text:c})}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,p)=>{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),p?s.format(p.substring(1).trim()):s.format("YYYY-MM-DD")})}function Er(r,e){let t=/<%(?:=)(.+)%>/g,o=No();return[...e.matchAll(t)].reduce((n,[p,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(p,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:p,frontmatter:a,content:s}=this.settings,c="";if(n){let l=e.coverLargeUrl||e.coverMediumUrl||e.coverSmallUrl||e.coverUrl;if(l){let u=ht(e,this.settings.fileNameFormat,"jpg");e.localCoverImage=await this.downloadAndSaveImage(u,p,l)}}if(t){let l=await br(this.app,t),u=Be(e,Sr(l));c+=Er(e,u)}else{let l=Be(e,a);o&&(l=zt(Xt(e,l,i)));let u=Be(e,s);c+=l?`---
${l}
---
${u}`:u}return c}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 p=n.arrayBuffer,a=`${t}/${e}`;return await this.app.vault.adapter.writeBinary(a,p),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({},Re,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};