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

3 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
8 months ago
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.naverCli
`).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,""")}"
2 years ago
`:`${e}: ${o}
8 months ago
`}).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
9 months ago
${p}
3 years ago
---
8 months ago
${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)})}};