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