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
41 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 Ir=Object.create;var ke=Object.defineProperty;var Lr=Object.getOwnPropertyDescriptor;var Fr=Object.getOwnPropertyNames,Lt=Object.getOwnPropertySymbols,_r=Object.getPrototypeOf,Ft=Object.prototype.hasOwnProperty,Vr=Object.prototype.propertyIsEnumerable;var _t=(r,e,t)=>e in r?ke(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,xe=(r,e)=>{for(var t in e||(e={}))Ft.call(e,t)&&_t(r,t,e[t]);if(Lt)for(var t of Lt(e))Vr.call(e,t)&&_t(r,t,e[t]);return r};var Vt=r=>ke(r,"__esModule",{value:!0});var $r=(r,e)=>{Vt(r);for(var t in e)ke(r,t,{get:e[t],enumerable:!0})},Hr=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fr(e))!Ft.call(r,o)&&o!=="default"&&ke(r,o,{get:()=>e[o],enumerable:!(t=Lr(e,o))||t.enumerable});return r},U=r=>Hr(Vt(ke(r!=null?Ir(_r(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);var d=(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:()=>Ot});var Ce=U(require("obsidian"));var oe=U(require("obsidian"));var N;(function(t){t.google="google",t.naver="naver"})(N||(N={}));var $t=U(require("obsidian"));var tt=class{getByQuery(e){return d(this,null,function*(){try{let t={q:e,maxResults:40,printType:"books"},o=window.moment.locale();o&&(t.langRestrict=o);let i=yield He("https://www.googleapis.com/books/v1/volumes",t);return(i==null?void 0:i.totalItems)?i.items.map(({volumeInfo:n})=>this.createBookItem(n)):[]}catch(t){throw console.warn(t),t}})}getISBN(e){return e==null?void 0:e.reduce((t,o)=>(o.type=="ISBN_10"&&(t.isbn10=o.identifier.trim()),o.type=="ISBN_13"&&(t.isbn13=o.identifier.trim()),t),{})}createBookItem(e){var o,i,n,s;return xe({title:e.title,subtitle:e.subtitle,author:this.formatList(e.authors),category:this.formatList(e.categories),publisher:e.publisher,totalPage:e.pageCount,coverUrl:(i=(o=e.imageLinks)==null?void 0:o.thumbnail)!=null?i:"",coverSmallUrl:(s=(n=e.imageLinks)==null?void 0:n.smallThumbnail)!=null?s:"",publishDate:e.publishedDate||"",description:e.description,link:e.canonicalVolumeLink||e.infoLink,previewLink:e.previewLink},this.getISBN(e.industryIdentifiers))}convertGoogleBookImageURLSize(e,t){return e.replace(/(&zoom)=\d/,`$1=${t}`)}formatList(e){var t,o;return(e==null?void 0:e.length)>1?e.map(i=>`${i.trim()}`).join(", "):(o=(t=e==null?void 0:e[0])==null?void 0:t.replace("N/A",""))!=null?o:""}};var rt=class{constructor(e,t){this.clientId=e;this.clientSecret=t}getByQuery(e){return d(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 He("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 xe({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})}};function Ht(r){if(r.serviceProvider===N.google)return new tt;if(r.serviceProvider===N.naver){if(!r.naverClientId||!r.naverClientSecret)throw new Error('\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.');return new rt(r.naverClientId,r.naverClientSecret)}}function He(o){return d(this,arguments,function*(r,e={},t){let i=new URL(r);return Object.entries(e).forEach(([s,a])=>{i.searchParams.append(s,a==null?void 0:a.toString())}),(yield(0,$t.requestUrl)({url:i.href,method:"GET",headers:xe({Accept:"*/*","Content-Type":"application/json; charset=utf-8"},t)})).json})}var ot=class extends oe.Modal{constructor(e,t,o){super(e.app);this.query=t,this.callback=o,this.serviceProvider=Ht(e.settings)}setBusy(e){this.isBusy=e,this.okBtnRef.setDisabled(e),this.okBtnRef.setButtonText(e?"Requesting...":"Search")}searchBook(){return d(this,null,function*(){if(!this.query)throw new Error("No query entered.");if(!this.isBusy){try{this.setBusy(!0);let e=yield this.serviceProvider.getByQuery(this.query);if(this.setBusy(!1),!(e==null?void 0:e.length)){new oe.Notice(`No results found for "${this.query}"`);return}this.callback(null,e)}catch(e){this.callback(e)}this.close()}})}submitEnterCallback(e){e.key==="Enter"&&this.searchBook()}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:"Search Book"}),e.createDiv({cls:"book-search-plugin__search-modal--input"},t=>{new oe.TextComponent(t).setValue(this.query).setPlaceholder("Search by keyword or ISBN").onChange(o=>this.query=o).inputEl.addEventListener("keydown",this.submitEnterCallback.bind(this))}),new oe.Setting(e).addButton(t=>this.okBtnRef=t.setButtonText("Search").setCta().onClick(()=>{this.searchBook()}))}onClose(){this.contentEl.empty()}};var Wt=U(require("obsidian")),it=class extends Wt.SuggestModal{constructor(e,t,o){super(e);this.suggestion=t,this.onChoose=o}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){let o=e.title,i=e.publisher?`, ${e.publisher}`:"",n=e.publishDate?`(${e.publishDate})`:"",s=e.totalPage?`, p${e.totalPage}`:"",a=`${e.author}${i}${n}${s}`;t.createEl("div",{text:o}),t.createEl("small",{text:a})}onChooseSuggestion(e){this.onChoose(null,e)}};var Xt=U(require("obsidian")),nt=class{constructor(e){this.app=e}jumpToNextCursorLocation(){return d(this,null,function*(){let e=this.app.workspace.getActiveViewOfType(Xt.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 G=U(require("obsidian"));var Gt=/^-?[0-9]*$/,st=/{{DATE(\+-?[0-9]+)?}}/,at=/{{DATE:([^}\n\r+]*)(\+-?[0-9]+)?}}/;function Wr(r){return r.replace(/[\\,#%&{}/*<>$":@.]/g,"").replace(/\s+/g," ")}function qt(r,e){let t;return e?t=Ne(r,We(e)):t=r.author?`${r.title} - ${r.author}`:r.title,Wr(t)+".md"}function Xr(r){return Object.entries(r).reduce((e,[t,o])=>(e[Gr(t)]=o,e),{})}function Ut(r,e,t=Q.snakeCase){var n,s;let o=t===Q.camelCase?r:Xr(r),i=typeof e=="string"?qr(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 Ne(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(/{{.+}}/gi,"").trim():""}function Gr(r){return r.replace(/[A-Z]/g,e=>`_${e==null?void 0:e.toLowerCase()}`)}function qr(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 Yt(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 zt(r){let e;return r.offset!==null&&r.offset!==void 0&&typeof r.offset=="number"&&(e=window.moment.duration(r.offset,"days")),r.format?window.moment().add(e).format(r.format):window.moment().add(e).format("YYYY-MM-DD")}function We(r){let e=r;for(;st.test(e);){let t=st.exec(e),o;if(t[1]){let i=t[1].replace("+","").trim();Gt.test(i)&&(o=parseInt(i))}e=Kt(e,st,zt({offset:o}))}for(;at.test(e);){let t=at.exec(e),o=t[1],i;if(t[2]){let n=t[2].replace("+","").trim();Gt.test(n)&&(i=parseInt(n))}e=Kt(e,at,zt({format:o,offset:i}))}return e}function Kt(r,e,t){return r.replace(e,function(){return t})}var wr=U(require("obsidian"));var P="top",A="bottom",k="right",T="left",Xe="auto",ie=[P,A,k,T],Z="start",le="end",Qt="clippingParents",Ge="viewport",be="popper",Jt="reference",pt=ie.reduce(function(r,e){return r.concat([e+"-"+Z,e+"-"+le])},[]),qe=[].concat(ie,[Xe]).reduce(function(r,e){return r.concat([e,e+"-"+Z,e+"-"+le])},[]),Ur="beforeRead",Yr="read",zr="afterRead",Kr="beforeMain",Qr="main",Jr="afterMain",Zr="beforeWrite",eo="write",to="afterWrite",Zt=[Ur,Yr,zr,Kr,Qr,Jr,Zr,eo,to];function M(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 J(r){var e=B(r).Element;return r instanceof e||r instanceof Element}function D(r){var e=B(r).HTMLElement;return r instanceof e||r instanceof HTMLElement}function ye(r){if(typeof ShadowRoot=="undefined")return!1;var e=B(r).ShadowRoot;return r instanceof e||r instanceof ShadowRoot}function ro(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];!D(n)||!M(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 oo(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},{});!D(i)||!M(i)||(Object.assign(i.style,a),Object.keys(n).forEach(function(l){i.removeAttribute(l)}))})}}var er={name:"applyStyles",enabled:!0,phase:"write",fn:ro,effect:oo,requires:["computeStyles"]};function R(r){return r.split("-")[0]}var Y=Math.max,ce=Math.min,ee=Math.round;function W(r,e){e===void 0&&(e=!1);var t=r.getBoundingClientRect(),o=1,i=1;if(D(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 me(r){var e=W(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&&ye(t)){var o=e;do{if(o&&r.isSameNode(o))return!0;o=o.parentNode||o.host}while(o)}return!1}function _(r){return B(r).getComputedStyle(r)}function lt(r){return["table","td","th"].indexOf(M(r))>=0}function F(r){return((J(r)?r.ownerDocument:r.document)||window.document).documentElement}function te(r){return M(r)==="html"?r:r.assignedSlot||r.parentNode||(ye(r)?r.host:null)||F(r)}function tr(r){return!D(r)||_(r).position==="fixed"?null:r.offsetParent}function io(r){var e=navigator.userAgent.toLowerCase().indexOf("firefox")!==-1,t=navigator.userAgent.indexOf("Trident")!==-1;if(t&&D(r)){var o=_(r);if(o.position==="fixed")return null}var i=te(r);for(ye(i)&&(i=i.host);D(i)&&["html","body"].indexOf(M(i))<0;){var n=_(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=tr(r);t&&lt(t)&&_(t).position==="static";)t=tr(t);return t&&(M(t)==="html"||M(t)==="body"&&_(t).position==="static")?e:t||io(r)||e}function ue(r){return["top","bottom"].indexOf(r)>=0?"x":"y"}function fe(r,e,t){return Y(r,ce(e,t))}function rr(r,e,t){var o=fe(r,e,t);return o>t?t:o}function De(){return{top:0,right:0,bottom:0,left:0}}function Me(r){return Object.assign({},De(),r)}function Re(r,e){return e.reduce(function(t,o){return t[o]=r,t},{})}var no=function(e,t){return e=typeof e=="function"?e(Object.assign({},t.rects,{placement:t.placement})):e,Me(typeof e!="number"?e:Re(e,ie))};function so(r){var e,t=r.state,o=r.name,i=r.options,n=t.elements.arrow,s=t.modifiersData.popperOffsets,a=R(t.placement),l=ue(a),c=[T,k].indexOf(a)>=0,p=c?"height":"width";if(!(!n||!s)){var m=no(i.padding,t),v=me(n),u=l==="y"?P:T,w=l==="y"?A:k,f=t.rects.reference[p]+t.rects.reference[l]-s[l]-t.rects.popper[p],g=s[l]-t.rects.reference[l],E=z(n),j=E?l==="y"?E.clientHeight||0:E.clientWidth||0:0,C=f/2-g/2,h=m[u],b=j-v[p]-m[w],x=j/2-v[p]/2+C,y=fe(h,x,b),O=l;t.modifiersData[o]=(e={},e[O]=y,e.centerOffset=y-x,e)}}function ao(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 or={name:"arrow",enabled:!0,phase:"main",fn:so,effect:ao,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function X(r){return r.split("-")[1]}var po={top:"auto",right:"auto",bottom:"auto",left:"auto"};function lo(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 ir(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,m=r.isFixed,v=s.x,u=v===void 0?0:v,w=s.y,f=w===void 0?0:w,g=typeof p=="function"?p({x:u,y:f}):{x:u,y:f};u=g.x,f=g.y;var E=s.hasOwnProperty("x"),j=s.hasOwnProperty("y"),C=T,h=P,b=window;if(c){var x=z(t),y="clientHeight",O="clientWidth";if(x===B(t)&&(x=F(t),_(x).position!=="static"&&a==="absolute"&&(y="scrollHeight",O="scrollWidth")),x=x,i===P||(i===T||i===k)&&n===le){h=A;var I=m&&x===b&&b.visualViewport?b.visualViewport.height:x[y];f-=I-o.height,f*=l?1:-1}if(i===T||(i===P||i===A)&&n===le){C=k;var L=m&&x===b&&b.visualViewport?b.visualViewport.width:x[O];u-=L-o.width,u*=l?1:-1}}var S=Object.assign({position:a},c&&po),V=p===!0?lo({x:u,y:f}):{x:u,y:f};if(u=V.x,f=V.y,l){var $;return Object.assign({},S,($={},$[h]=j?"0":"",$[C]=E?"0":"",$.transform=(b.devicePixelRatio||1)<=1?"translate("+u+"px, "+f+"px)":"translate3d("+u+"px, "+f+"px, 0)",$))}return Object.assign({},S,(e={},e[h]=j?f+"px":"",e[C]=E?u+"px":"",e.transform="",e))}function co(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:R(e.placement),variation:X(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,ir(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,ir(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 nr={name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:co,data:{}};var Ue={passive:!0};function mo(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=B(e.elements.popper),c=[].concat(e.scrollParents.reference,e.scrollParents.popper);return n&&c.forEach(function(p){p.addEventListener("scroll",t.update,Ue)}),a&&l.addEventListener("resize",t.update,Ue),function(){n&&c.forEach(function(p){p.removeEventListener("scroll",t.update,Ue)}),a&&l.removeEventListener("resize",t.update,Ue)}}var sr={name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:mo,data:{}};var uo={left:"right",right:"left",bottom:"top",top:"bottom"};function Se(r){return r.replace(/left|right|bottom|top/g,function(e){return uo[e]})}var fo={start:"end",end:"start"};function Ye(r){return r.replace(/start|end/g,function(e){return fo[e]})}function de(r){var e=B(r),t=e.pageXOffset,o=e.pageYOffset;return{scrollLeft:t,scrollTop:o}}function ge(r){return W(F(r)).left+de(r).scrollLeft}function ct(r){var e=B(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+ge(r),y:a}}function mt(r){var e,t=F(r),o=de(r),i=(e=r.ownerDocument)==null?void 0:e.body,n=Y(t.scrollWidth,t.clientWidth,i?i.scrollWidth:0,i?i.clientWidth:0),s=Y(t.scrollHeight,t.clientHeight,i?i.scrollHeight:0,i?i.clientHeight:0),a=-o.scrollLeft+ge(r),l=-o.scrollTop;return _(i||t).direction==="rtl"&&(a+=Y(t.clientWidth,i?i.clientWidth:0)-n),{width:n,height:s,x:a,y:l}}function he(r){var e=_(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(M(r))>=0?r.ownerDocument.body:D(r)&&he(r)?r:ze(te(r))}function ne(r,e){var t;e===void 0&&(e=[]);var o=ze(r),i=o===((t=r.ownerDocument)==null?void 0:t.body),n=B(o),s=i?[n].concat(n.visualViewport||[],he(o)?o:[]):o,a=e.concat(s);return i?a:a.concat(ne(te(s)))}function Ee(r){return Object.assign({},r,{left:r.x,top:r.y,right:r.x+r.width,bottom:r.y+r.height})}function go(r){var e=W(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 ar(r,e){return e===Ge?Ee(ct(r)):J(e)?go(e):Ee(mt(F(r)))}function ho(r){var e=ne(te(r)),t=["absolute","fixed"].indexOf(_(r).position)>=0,o=t&&D(r)?z(r):r;return J(o)?e.filter(function(i){return J(i)&&Ae(i,o)&&M(i)!=="body"}):[]}function ut(r,e,t){var o=e==="clippingParents"?ho(r):[].concat(e),i=[].concat(o,[t]),n=i[0],s=i.reduce(function(a,l){var c=ar(r,l);return a.top=Y(c.top,a.top),a.right=ce(c.right,a.right),a.bottom=ce(c.bottom,a.bottom),a.left=Y(c.left,a.left),a},ar(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 Ie(r){var e=r.reference,t=r.element,o=r.placement,i=o?R(o):null,n=o?X(o):null,s=e.x+e.width/2-t.width/2,a=e.y+e.height/2-t.height/2,l;switch(i){case P:l={x:s,y:e.y-t.height};break;case A:l={x:s,y:e.y+e.height};break;case k:l={x:e.x+e.width,y:a};break;case T:l={x:e.x-t.width,y:a};break;default:l={x:e.x,y:e.y}}var c=i?ue(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 le: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?Qt:n,a=t.rootBoundary,l=a===void 0?Ge:a,c=t.elementContext,p=c===void 0?be:c,m=t.altBoundary,v=m===void 0?!1:m,u=t.padding,w=u===void 0?0:u,f=Me(typeof w!="number"?w:Re(w,ie)),g=p===be?Jt:be,E=r.rects.popper,j=r.elements[v?g:p],C=ut(J(j)?j:j.contextElement||F(r.elements.popper),s,l),h=W(r.elements.reference),b=Ie({reference:h,element:E,strategy:"absolute",placement:i}),x=Ee(Object.assign({},E,b)),y=p===be?x:h,O={top:C.top-y.top+f.top,bottom:y.bottom-C.bottom+f.bottom,left:C.left-y.left+f.left,right:y.right-C.right+f.right},I=r.modifiersData.offset;if(p===be&&I){var L=I[i];Object.keys(O).forEach(function(S){var V=[k,A].indexOf(S)>=0?1:-1,$=[P,A].indexOf(S)>=0?"y":"x";O[S]+=L[$]*V})}return O}function ft(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?qe:l,p=X(o),m=p?a?pt:pt.filter(function(w){return X(w)===p}):ie,v=m.filter(function(w){return c.indexOf(w)>=0});v.length===0&&(v=m);var u=v.reduce(function(w,f){return w[f]=K(r,{placement:f,boundary:i,rootBoundary:n,padding:s})[R(f)],w},{});return Object.keys(u).sort(function(w,f){return u[w]-u[f]})}function vo(r){if(R(r)===Xe)return[];var e=Se(r);return[Ye(r),e,Ye(e)]}function wo(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,m=t.rootBoundary,v=t.altBoundary,u=t.flipVariations,w=u===void 0?!0:u,f=t.allowedAutoPlacements,g=e.options.placement,E=R(g),j=E===g,C=l||(j||!w?[Se(g)]:vo(g)),h=[g].concat(C).reduce(function(we,re){return we.concat(R(re)===Xe?ft(e,{placement:re,boundary:p,rootBoundary:m,padding:c,flipVariations:w,allowedAutoPlacements:f}):re)},[]),b=e.rects.reference,x=e.rects.popper,y=new Map,O=!0,I=h[0],L=0;L<h.length;L++){var S=h[L],V=R(S),$=X(S)===Z,Pe=[P,A].indexOf(V)>=0,Oe=Pe?"width":"height",H=K(e,{placement:S,boundary:p,rootBoundary:m,altBoundary:v,padding:c}),q=Pe?$?k:T:$?A:P;b[Oe]>x[Oe]&&(q=Se(q));var Le=Se(q),se=[];if(n&&se.push(H[V]<=0),a&&se.push(H[q]<=0,H[Le]<=0),se.every(function(we){return we})){I=S,O=!1;break}y.set(S,se)}if(O)for(var Fe=w?3:1,Qe=function(re){var Be=h.find(function(Ve){var ae=y.get(Ve);if(ae)return ae.slice(0,re).every(function(Je){return Je})});if(Be)return I=Be,"break"},Te=Fe;Te>0;Te--){var _e=Qe(Te);if(_e==="break")break}e.placement!==I&&(e.modifiersData[o]._skip=!0,e.placement=I,e.reset=!0)}}var pr={name:"flip",enabled:!0,phase:"main",fn:wo,requiresIfExists:["offset"],data:{_skip:!1}};function lr(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 cr(r){return[P,k,A,T].some(function(e){return r[e]>=0})}function xo(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=lr(s,o),c=lr(a,i,n),p=cr(l),m=cr(c);e.modifiersData[t]={referenceClippingOffsets:l,popperEscapeOffsets:c,isReferenceHidden:p,hasPopperEscaped:m},e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-reference-hidden":p,"data-popper-escaped":m})}var mr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:xo};function bo(r,e,t){var o=R(r),i=[T,P].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,[T,k].indexOf(o)>=0?{x:a,y:s}:{x:s,y:a}}function yo(r){var e=r.state,t=r.options,o=r.name,i=t.offset,n=i===void 0?[0,0]:i,s=qe.reduce(function(p,m){return p[m]=bo(m,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 ur={name:"offset",enabled:!0,phase:"main",requires:["popperOffsets"],fn:yo};function So(r){var e=r.state,t=r.name;e.modifiersData[t]=Ie({reference:e.rects.reference,element:e.rects.popper,strategy:"absolute",placement:e.placement})}var fr={name:"popperOffsets",enabled:!0,phase:"read",fn:So,data:{}};function dt(r){return r==="x"?"y":"x"}function Eo(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,m=t.padding,v=t.tether,u=v===void 0?!0:v,w=t.tetherOffset,f=w===void 0?0:w,g=K(e,{boundary:l,rootBoundary:c,padding:m,altBoundary:p}),E=R(e.placement),j=X(e.placement),C=!j,h=ue(E),b=dt(h),x=e.modifiersData.popperOffsets,y=e.rects.reference,O=e.rects.popper,I=typeof f=="function"?f(Object.assign({},e.rects,{placement:e.placement})):f,L=typeof I=="number"?{mainAxis:I,altAxis:I}:Object.assign({mainAxis:0,altAxis:0},I),S=e.modifiersData.offset?e.modifiersData.offset[e.placement]:null,V={x:0,y:0};if(!!x){if(n){var $,Pe=h==="y"?P:T,Oe=h==="y"?A:k,H=h==="y"?"height":"width",q=x[h],Le=q+g[Pe],se=q-g[Oe],Fe=u?-O[H]/2:0,Qe=j===Z?y[H]:O[H],Te=j===Z?-O[H]:-y[H],_e=e.elements.arrow,we=u&&_e?me(_e):{width:0,height:0},re=e.modifiersData["arrow#persistent"]?e.modifiersData["arrow#persistent"].padding:De(),Be=re[Pe],Ve=re[Oe],ae=fe(0,y[H],we[H]),Je=C?y[H]/2-Fe-ae-Be-L.mainAxis:Qe-ae-Be-L.mainAxis,kr=C?-y[H]/2+Fe+ae+Ve+L.mainAxis:Te+ae+Ve+L.mainAxis,Ze=e.elements.arrow&&z(e.elements.arrow),Nr=Ze?h==="y"?Ze.clientTop||0:Ze.clientLeft||0:0,Tt=($=S==null?void 0:S[h])!=null?$:0,Ar=q+Je-Tt-Nr,Dr=q+kr-Tt,Bt=fe(u?ce(Le,Ar):Le,q,u?Y(se,Dr):se);x[h]=Bt,V[h]=Bt-q}if(a){var kt,Mr=h==="x"?P:T,Rr=h==="x"?A:k,pe=x[b],$e=b==="y"?"height":"width",Nt=pe+g[Mr],At=pe-g[Rr],et=[P,T].indexOf(E)!==-1,Dt=(kt=S==null?void 0:S[b])!=null?kt:0,Mt=et?Nt:pe-y[$e]-O[$e]-Dt+L.altAxis,Rt=et?pe+y[$e]+O[$e]-Dt-L.altAxis:At,It=u&&et?rr(Mt,pe,Rt):fe(u?Mt:Nt,pe,u?Rt:At);x[b]=It,V[b]=It-pe}e.modifiersData[o]=V}}var dr={name:"preventOverflow",enabled:!0,phase:"main",fn:Eo,requiresIfExists:["offset"]};function gt(r){return{scrollLeft:r.scrollLeft,scrollTop:r.scrollTop}}function ht(r){return r===B(r)||!D(r)?de(r):gt(r)}function jo(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 vt(r,e,t){t===void 0&&(t=!1);var o=D(e),i=D(e)&&jo(e),n=F(e),s=W(r,i),a={scrollLeft:0,scrollTop:0},l={x:0,y:0};return(o||!o&&!t)&&((M(e)!=="body"||he(n))&&(a=ht(e)),D(e)?(l=W(e,!0),l.x+=e.clientLeft,l.y+=e.clientTop):n&&(l.x=ge(n))),{x:s.left+a.scrollLeft-l.x,y:s.top+a.scrollTop-l.y,width:s.width,height:s.height}}function Co(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 wt(r){var e=Co(r);return Zt.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 bt(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 gr={placement:"bottom",modifiers:[],strategy:"absolute"};function hr(){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 vr(r){r===void 0&&(r={});var e=r,t=e.defaultModifiers,o=t===void 0?[]:t,i=e.defaultOptions,n=i===void 0?gr:i;return function(a,l,c){c===void 0&&(c=n);var p={placement:"bottom",orderedModifiers:[],options:Object.assign({},gr,n),modifiersData:{},elements:{reference:a,popper:l},attributes:{},styles:{}},m=[],v=!1,u={state:p,setOptions:function(E){var j=typeof E=="function"?E(p.options):E;f(),p.options=Object.assign({},n,p.options,j),p.scrollParents={reference:J(a)?ne(a):a.contextElement?ne(a.contextElement):[],popper:ne(l)};var C=wt(bt([].concat(o,p.options.modifiers)));if(p.orderedModifiers=C.filter(function(S){return S.enabled}),!1){var h;if(getBasePlacement(p.options.placement)===auto)var b;var x,y,O,I,L}return w(),u.update()},forceUpdate:function(){if(!v){var E=p.elements,j=E.reference,C=E.popper;if(!!hr(j,C)){p.rects={reference:vt(j,z(C),p.options.strategy==="fixed"),popper:me(C)},p.reset=!1,p.placement=p.options.placement,p.orderedModifiers.forEach(function(S){return p.modifiersData[S.name]=Object.assign({},S.data)});for(var h=0,b=0;b<p.orderedModifiers.length;b++){if(p.reset===!0){p.reset=!1,b=-1;continue}var x=p.orderedModifiers[b],y=x.fn,O=x.options,I=O===void 0?{}:O,L=x.name;typeof y=="function"&&(p=y({state:p,options:I,name:L,instance:u})||p)}}}},update:xt(function(){return new Promise(function(g){u.forceUpdate(),g(p)})}),destroy:function(){f(),v=!0}};if(!hr(a,l))return u;u.setOptions(c).then(function(g){!v&&c.onFirstUpdate&&c.onFirstUpdate(g)});function w(){p.orderedModifiers.forEach(function(g){var E=g.name,j=g.options,C=j===void 0?{}:j,h=g.effect;if(typeof h=="function"){var b=h({state:p,name:E,instance:u,options:C}),x=function(){};m.push(b||x)}})}function f(){m.forEach(function(g){return g()}),m=[]}return u}}var Po=[sr,fr,nr,er,ur,pr,dr,or,mr],yt=vr({defaultModifiers:Po});var Oo=(r,e)=>(r%e+e)%e,xr=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=Oo(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)}},ve=class{constructor(e,t){this.app=e,this.inputEl=t,this.scope=new wr.Scope,this.suggestEl=createDiv("suggestion-container");let o=this.suggestEl.createDiv("suggestion");this.suggest=new xr(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=yt(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 To="{{DATE}}",br="{{DATE:}}",Bo=/{{D?A?T?E?}?}?$/i,ko=/{{D?A?T?E?:?$|{{DATE:[^\n\r}]*}}$/i,No="{{author}}",Ao=/{{a?u?t?h?o?r?}?}?$/i,Do="{{title}}",Mo=/{{t?i?t?l?e?}?}?$/i,St=class extends ve{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===br&&(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=ko.exec(e);o&&t(o,br);let i=Bo.exec(e);i&&t(i,To);let n=Ao.exec(e);n&&t(n,No);let s=Mo.exec(e);s&&t(s,Do)}};var yr=U(require("obsidian"));var Et=class extends ve{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),o=[],i=e.toLowerCase();return t.forEach(n=>{n instanceof yr.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 Sr=U(require("obsidian"));var jt=class extends ve{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),o=[],i=e.toLowerCase();return t.forEach(n=>{n instanceof Sr.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 je=U(require("obsidian")),Ct=class extends je.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:N.google}get settings(){return this.plugin.settings}saveSetting(){return d(this,null,function*(){return this.plugin.saveSettings()})}saveClientId(e){this.currentServiceProvider===N.naver&&(this.plugin.settings.naverClientId=e)}saveClientSecret(e){this.currentServiceProvider===N.naver&&(this.settings.naverClientSecret=e)}get currentClientId(){if(this.currentServiceProvider===N.naver)return this.settings.naverClientId}get currentClientSecret(){if(this.currentServiceProvider===N.naver)return this.settings.naverClientSecret}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:"Service Provider Setting"}),new je.Setting(e).setName("Client ID").addText(t=>{t.setValue(this.currentClientId).onChange(o=>this.saveClientId(o))}),new je.Setting(e).setName("Client Secret").addText(t=>{t.setValue(this.currentClientSecret).onChange(o=>this.saveClientSecret(o))}),new je.Setting(e).addButton(t=>t.setButtonText("Save").setCta().onClick(()=>d(this,null,function*(){var o;yield this.plugin.saveSettings(),this.close(),(o=this.callback)==null||o.call(this)})))}onClose(){this.contentEl.empty()}};var Er="https://github.com/anpigon/obsidian-book-search-plugin",Q;(function(t){t.snakeCase="Snake Case",t.camelCase="Camel Case"})(Q||(Q={}));var jr={folder:"",fileNameFormat:"",frontmatter:"",content:"",useDefaultFrontmatter:!0,defaultFrontmatterKeyType:Q.camelCase,templateFile:"",serviceProvider:N.google,naverClientId:"",naverClientSecret:""},Pt=class extends G.PluginSettingTab{constructor(e,t){super(e,t);this.plugin=t}get settings(){return this.plugin.settings}display(){let{containerEl:e}=this;e.empty(),e.classList.add("book-search-plugin__settings"),Cr(e,"General Settings"),new G.Setting(e).setName("New file location").setDesc("New book notes will be placed here.").addSearch(p=>{try{new Et(this.app,p.inputEl)}catch(m){}p.setPlaceholder("Example: folder1/folder2").setValue(this.plugin.settings.folder).onChange(m=>{this.plugin.settings.folder=m,this.plugin.saveSettings()})});let t=document.createDocumentFragment().createEl("code",{text:We(this.plugin.settings.fileNameFormat)||"{{title}} - {{author}}"});new G.Setting(e).setClass("book-search-plugin__settings--new_file_name").setName("New file name").setDesc("Enter the file name format.").addSearch(p=>{try{new St(this.app,p.inputEl)}catch(m){}p.setPlaceholder("Example: {{title}} - {{author}}").setValue(this.plugin.settings.fileNameFormat).onChange(m=>{this.plugin.settings.fileNameFormat=m==null?void 0:m.trim(),this.plugin.saveSettings(),t.innerHTML=We(m)||"{{title}} - {{author}}"})}),e.createEl("div",{cls:["setting-item-description","book-search-plugin__settings--new_file_name_hint"]}).append(t);let o=document.createDocumentFragment();o.createDiv({text:"Files will be available as templates."}),o.createEl("a",{text:"Example Template",href:`${Er}#example-template`}),new G.Setting(e).setName("Template file").setDesc(o).addSearch(p=>{try{new jt(this.app,p.inputEl)}catch(m){}p.setPlaceholder("Example: templates/template-file").setValue(this.plugin.settings.templateFile).onChange(m=>{this.plugin.settings.templateFile=m,this.plugin.saveSettings()})});let i,n=()=>{i.addClass("book-search-plugin__hide")},s=()=>{i.removeClass("book-search-plugin__hide")},a=(p=(m=>(m=this.settings)==null?void 0:m.serviceProvider)())=>{p===N.naver?s():n()};new G.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(p=>{var m,v;p.addOption(N.google,`${N.google} (Global)`),p.addOption(N.naver,`${N.naver} (Korean)`),p.setValue((v=(m=this.plugin.settings)==null?void 0:m.serviceProvider)!=null?v:N.google),p.onChange(u=>d(this,null,function*(){let w=u;a(w),this.settings.serviceProvider=w,yield this.plugin.saveSettings()}))}).addExtraButton(p=>{i=p.extraSettingsEl,a(),p.onClick(()=>{new Ct(this.plugin).open()})});let l=[];Pr(e,"Frontmatter Settings",l),l.push(new G.Setting(e).setClass("book-search-plugin__hide").setName("Use the default frontmatter").setDesc("If you don't want the default frontmatter to be inserted, disable it.").addToggle(p=>{p.setValue(this.plugin.settings.useDefaultFrontmatter).onChange(m=>d(this,null,function*(){let v=m;this.plugin.settings.useDefaultFrontmatter=v,yield this.plugin.saveSettings()}))}),new G.Setting(e).setClass("book-search-plugin__hide").setName("Default frontmatter key type").setDesc(Ro()).addDropdown(p=>{p.addOption(Q.snakeCase,Q.snakeCase.toString()),p.addOption(Q.camelCase,Q.camelCase.toString()),p.setValue(this.plugin.settings.defaultFrontmatterKeyType),p.onChange(m=>d(this,null,function*(){this.plugin.settings.defaultFrontmatterKeyType=m,yield this.plugin.saveSettings()}))}),new G.Setting(e).setClass("book-search-plugin__hide").setName("(Deprecated) Text to insert into frontmatter").setDesc(Or("#text-to-insert-into-frontmatter")).addTextArea(p=>{let m=this.plugin.settings.frontmatter;p.setValue(m).onChange(v=>d(this,null,function*(){let u=v;this.plugin.settings.frontmatter=u,yield this.plugin.saveSettings()}))}));let c=[];Pr(e,"Content Settings",c),c.push(new G.Setting(e).setClass("book-search-plugin__hide").setName("(Deprecated) Text to insert into content").setDesc(Or("#text-to-insert-into-content")).addTextArea(p=>{let m=this.plugin.settings.content;p.setValue(m).onChange(v=>d(this,null,function*(){let u=v;this.plugin.settings.content=u,yield this.plugin.saveSettings()}))}))}};function Ro(){let r=document.createDocumentFragment();return r.append("- Snake Case: ",r.createEl("code",{text:"total_page"}),r.createEl("br"),"- Camel Case: ",r.createEl("code",{text:"totalPage"})),r}function Cr(r,e){let t=document.createDocumentFragment();return t.createEl("h2",{text:e}),new G.Setting(r).setHeading().setName(t)}function Pr(r,e,t){return Cr(r,e).addToggle(o=>{o.onChange(i=>{t.forEach(({settingEl:n})=>{n.toggleClass("book-search-plugin__show",i)})})})}function Or(r){let e=document.createDocumentFragment();return e.append("Please use the template file.",e.createEl("br"),"The following syntaxes are available: ",e.createEl("br"),e.createEl("code",{text:"{{title}}"}),", ",e.createEl("code",{text:"{{author}}"}),", ",e.createEl("code",{text:"{{category}}"}),", ",e.createEl("code",{text:"{{publisher}}"}),", ",e.createEl("code",{text:"{{publishDate}}"}),", ",e.createEl("code",{text:"{{totalPage}}"}),", ",e.createEl("code",{text:"{{coverUrl}}"}),", ",e.createEl("code",{text:"{{isbn10}}"}),", ",e.createEl("code",{text:"{{isbn13}}"}),e.createEl("br"),"Check the ",e.createEl("a",{href:`${Er}${r}`,text:"documentation"})," for more information."),e}var Ke=U(require("obsidian"));function Tr(r,e){return d(this,null,function*(){let{metadataCache:t,vault:o}=r,i=(0,Ke.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 Ke.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")})}var Ot=class extends Ce.Plugin{onload(){return d(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 Pt(this.app,this)),console.log(`Book Search: version ${this.manifest.version} (requires obsidian ${this.manifest.minAppVersion})`)})}showNotice(e){try{new Ce.Notice(e==null?void 0:e.toString())}catch(t){}}searchBookMetadata(e){return d(this,null,function*(){let t=yield this.openBookSearchModal(e);return yield this.openBookSuggestModal(t)})}getRenderedContents(e){return d(this,null,function*(){let{templateFile:t,useDefaultFrontmatter:o,defaultFrontmatterKeyType:i,frontmatter:n,content:s}=this.settings;if(t){let c=yield Tr(this.app,t);return Ne(e,Br(c))}let a=Ne(e,n);o&&(a=Yt(Ut(e,a,i)));let l=Ne(e,s);return a?`---
${a}
---
${l}`:l})}insertMetadata(){return d(this,null,function*(){try{let e=this.app.workspace.getActiveViewOfType(Ce.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 d(this,null,function*(){try{let e=yield this.searchBookMetadata(),t=this.app.workspace.getLeaf();if(!t){console.warn("No active leaf");return}let o=yield this.getRenderedContents(e),i=qt(e,this.settings.fileNameFormat),n=`${this.settings.folder}/${i}`,s=yield this.app.vault.create(n,o);yield t.openFile(s,{state:{mode:"source"}}),t.setEphemeralState({rename:"all"}),yield new nt(this.app).jumpToNextCursorLocation()}catch(e){console.warn(e),this.showNotice(e)}})}openBookSearchModal(e=""){return d(this,null,function*(){return new Promise((t,o)=>new ot(this,e,(i,n)=>i?o(i):t(n)).open())})}openBookSuggestModal(e){return d(this,null,function*(){return new Promise((t,o)=>new it(this.app,e,(i,n)=>i?o(i):t(n)).open())})}loadSettings(){return d(this,null,function*(){this.settings=Object.assign({},jr,yield this.loadData())})}saveSettings(){return d(this,null,function*(){yield this.saveData(this.settings)})}};