varMr=Object.create;varIe=Object.defineProperty;varFr=Object.getOwnPropertyDescriptor;var_r=Object.getOwnPropertyNames,Ht=Object.getOwnPropertySymbols,Vr=Object.getPrototypeOf,$t=Object.prototype.hasOwnProperty,Hr=Object.prototype.propertyIsEnumerable;varWt=(r,e,t)=>einr?Ie(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,pe=(r,e)=>{for(vartine||(e={}))$t.call(e,t)&&Wt(r,t,e[t]);if(Ht)for(vartofHt(e))Hr.call(e,t)&&Wt(r,t,e[t]);returnr};varUt=r=>Ie(r,"__esModule",{value:!0});var$r=(r,e)=>{Ut(r);for(vartine)Ie(r,t,{get:e[t],enumerable:!0})},Wr=(r,e,t)=>{if(e&&typeofe=="object"||typeofe=="function")for(letoof_r(e))!$t.call(r,o)&&o!=="default"&&Ie(r,o,{get:()=>e[o],enumerable:!(t=Fr(e,o))||t.enumerable});returnr},z=r=>Wr(Ut(Ie(r!=null?Mr(Vr(r)):{},"default",r&&r.__esModule&&"default"inr?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);varf=(r,e,t)=>newPromise((o,i)=>{varn=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});varne=z(require("obsidian"));varB;(function(t){t.google="google",t.naver="naver"})(B||(B={}));varGt=z(require("obsidian"));varGe=class{constructor(e,t){this.localePreference=e;this.apiKey=t}getLanguageRestriction(e){returne==="default"?window.moment.locale():e}buildSearchParams(e,t){leto={q:e,maxResults:Ge.MAX_RESULTS,printType:Ge.PRINT_TYPE,langRestrict:this.getLanguageRestriction((t==null?void0:t.locale)||this.localePreference)};returnthis.apiKey&&(o.key=this.apiKey),o}getByQuery(e,t){returnf(this,null,function*(){try{leto=this.buildSearchParams(e,t),i=yieldXe("https://www.googleapis.com/books/v1/volumes",o);return(i==null?void0:i.totalItems)?i.items.map(({volumeInfo:n})=>this.createBookItem(n)):[]}catch(o){throwconsole.warn(o),o}})}extractISBNs(e){vart;return(t=e==null?void0:e.reduce((o,i)=>{letn=i.type==="ISBN_10"?"isbn10":"isbn13";returno[n]=i.identifier.trim(),o},{}))!=null?t:{}}extractBasicBookInfo(e){vart,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?void0:t.thumbnail)!=null?o:"",coverSmallUrl:(n=(i=e.imageLinks)==null?void0:i.smallThumbnail)!=null?n:"",publishDate:e.publishedDate||"",description:e.description,link:e.canonicalVolumeLink||e.infoLink,previewLink:e.previewLink}}createBookItem(e){returnpe(pe({title:"",subtitle:"",author:"",authors:[],category:"",categories:[],publisher:"",publishDate:"",totalPage:"",coverUrl:"",coverSmallUrl:"",description:"",link:"",previewLink:""},this.extractBasicBookInfo(e)),this.extractISBNs(e.industryIdentifiers))}formatList(e){vart;returne&&e.length>1?e.map(o=>o.trim()).join(", "):(t=e==null?void0:e[0])!=null?t:""}staticconvertGoogleBookImageURLSize(e,t){returne.replace(/(&zoom)=\d/,`$1=${t}`)}},Ne=Ge;Ne.MAX_RESULTS=40,Ne.PRINT_TYPE="books";varst=class{constructor(e,t){this.clientId=e;this.clientSecret=t}getByQuery(e){returnf(this,null,function*(){try{lett={query:e,display:50,sort:"sim"},o={"X-Naver-Client-Id":this.clientId,"X-Naver-Client-Secret":this.clientSecret},i=yieldXe("https://openapi.naver.com/v1/search/book.json",t,o);return(i==null?void0:i.total)?i.items.map(this.createBookItem):[]}catch(t){throwconsole.warn(t),t}})}createBookItem(e){vart,o;returnpe({title:e.title,author:e.author,publisher:e.publisher,coverUrl:e.image,publishDate:((t=e.pubdate)==null?void0:t.slice(0,4))||"",link:e.link,description:e.description,isbn:e.isbn},((o=e.isbn)==null?void0:o.length)>=13?{isbn13:e.isbn}:{isbn10:e.isbn})}};varXt=classextendsError{constructor(e){super(e);this.name="ConfigurationError"}};functionzt(r){switch(r.serviceProvider){caseB.google:returnnewNe(r.localePreference,r.apiKey);caseB.naver:returnUr(r),newst(r.naverClientId,r.naverClientSecret);default:thrownewError("Unsupported service provider.")}}functionUr(r){if(!r.naverCli
${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(`Failedtodownloadimage:${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)})}};