/* ------------------------------------------- Media DB Plugin - Release Build ------------------------------------------- By: Moritz Jung (https://mprojectscode.github.io/) Time: Tue, 12 Dec 2023 20:23:33 GMT Version: 0.6.0 ------------------------------------------- THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var si=Object.defineProperty;var Vo=Object.getOwnPropertyDescriptor;var Yo=Object.getOwnPropertyNames;var Go=Object.prototype.hasOwnProperty;var zo=(o,t,e)=>t in o?si(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var Ko=(o,t)=>{for(var e in t)si(o,e,{get:t[e],enumerable:!0})},Xo=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Yo(t))!Go.call(o,i)&&i!==e&&si(o,i,{get:()=>t[i],enumerable:!(r=Vo(t,i))||r.enumerable});return o};var Zo=o=>Xo(si({},"__esModule",{value:!0}),o);var z=(o,t,e)=>(zo(o,typeof t!="symbol"?t+"":t,e),e);var la={};Ko(la,{default:()=>zi});module.exports=Zo(la);var ne=require("obsidian");var P=require("obsidian");var so=require("obsidian");var ao=require("obsidian");var B="top",H="bottom",q="right",L="left",li="auto",We=[B,H,q,L],Re="start",Ke="end",Rr="clippingParents",pi="viewport",vt="popper",Or="reference",Ki=We.reduce(function(o,t){return o.concat([t+"-"+Re,t+"-"+Ke])},[]),di=[].concat(We,[li]).reduce(function(o,t){return o.concat([t,t+"-"+Re,t+"-"+Ke])},[]),Jo="beforeRead",Qo="read",en="afterRead",tn="beforeMain",rn="main",on="afterMain",nn="beforeWrite",an="write",sn="afterWrite",Ar=[Jo,Qo,en,tn,rn,on,nn,an,sn];function K(o){return o?(o.nodeName||"").toLowerCase():null}function $(o){if(o==null)return window;if(o.toString()!=="[object Window]"){var t=o.ownerDocument;return t&&t.defaultView||window}return o}function pe(o){var t=$(o).Element;return o instanceof t||o instanceof Element}function V(o){var t=$(o).HTMLElement;return o instanceof t||o instanceof HTMLElement}function wt(o){if(typeof ShadowRoot=="undefined")return!1;var t=$(o).ShadowRoot;return o instanceof t||o instanceof ShadowRoot}function ln(o){var t=o.state;Object.keys(t.elements).forEach(function(e){var r=t.styles[e]||{},i=t.attributes[e]||{},n=t.elements[e];!V(n)||!K(n)||(Object.assign(n.style,r),Object.keys(i).forEach(function(a){var s=i[a];s===!1?n.removeAttribute(a):n.setAttribute(a,s===!0?"":s)}))})}function pn(o){var t=o.state,e={popper:{position:t.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};return Object.assign(t.elements.popper.style,e.popper),t.styles=e,t.elements.arrow&&Object.assign(t.elements.arrow.style,e.arrow),function(){Object.keys(t.elements).forEach(function(r){var i=t.elements[r],n=t.attributes[r]||{},a=Object.keys(t.styles.hasOwnProperty(r)?t.styles[r]:e[r]),s=a.reduce(function(l,p){return l[p]="",l},{});!V(i)||!K(i)||(Object.assign(i.style,s),Object.keys(n).forEach(function(l){i.removeAttribute(l)}))})}}var Nr={name:"applyStyles",enabled:!0,phase:"write",fn:ln,effect:pn,requires:["computeStyles"]};function X(o){return o.split("-")[0]}var fe=Math.max,Xe=Math.min,Oe=Math.round;function xt(){var o=navigator.userAgentData;return o!=null&&o.brands&&Array.isArray(o.brands)?o.brands.map(function(t){return t.brand+"/"+t.version}).join(" "):navigator.userAgent}function Wt(){return!/^((?!chrome|android).)*safari/i.test(xt())}function de(o,t,e){t===void 0&&(t=!1),e===void 0&&(e=!1);var r=o.getBoundingClientRect(),i=1,n=1;t&&V(o)&&(i=o.offsetWidth>0&&Oe(r.width)/o.offsetWidth||1,n=o.offsetHeight>0&&Oe(r.height)/o.offsetHeight||1);var a=pe(o)?$(o):window,s=a.visualViewport,l=!Wt()&&e,p=(r.left+(l&&s?s.offsetLeft:0))/i,d=(r.top+(l&&s?s.offsetTop:0))/n,c=r.width/i,u=r.height/n;return{width:c,height:u,top:d,right:p+c,bottom:d+u,left:p,x:p,y:d}}function Ze(o){var t=de(o),e=o.offsetWidth,r=o.offsetHeight;return Math.abs(t.width-e)<=1&&(e=t.width),Math.abs(t.height-r)<=1&&(r=t.height),{x:o.offsetLeft,y:o.offsetTop,width:e,height:r}}function qt(o,t){var e=t.getRootNode&&t.getRootNode();if(o.contains(t))return!0;if(e&&wt(e)){var r=t;do{if(r&&o.isSameNode(r))return!0;r=r.parentNode||r.host}while(r)}return!1}function ae(o){return $(o).getComputedStyle(o)}function Xi(o){return["table","td","th"].indexOf(K(o))>=0}function ee(o){return((pe(o)?o.ownerDocument:o.document)||window.document).documentElement}function Ae(o){return K(o)==="html"?o:o.assignedSlot||o.parentNode||(wt(o)?o.host:null)||ee(o)}function Br(o){return!V(o)||ae(o).position==="fixed"?null:o.offsetParent}function dn(o){var t=/firefox/i.test(xt()),e=/Trident/i.test(xt());if(e&&V(o)){var r=ae(o);if(r.position==="fixed")return null}var i=Ae(o);for(wt(i)&&(i=i.host);V(i)&&["html","body"].indexOf(K(i))<0;){var n=ae(i);if(n.transform!=="none"||n.perspective!=="none"||n.contain==="paint"||["transform","perspective"].indexOf(n.willChange)!==-1||t&&n.willChange==="filter"||t&&n.filter&&n.filter!=="none")return i;i=i.parentNode}return null}function he(o){for(var t=$(o),e=Br(o);e&&Xi(e)&&ae(e).position==="static";)e=Br(e);return e&&(K(e)==="html"||K(e)==="body"&&ae(e).position==="static")?t:e||dn(o)||t}function Je(o){return["top","bottom"].indexOf(o)>=0?"x":"y"}function Qe(o,t,e){return fe(o,Xe(t,e))}function Ir(o,t,e){var r=Qe(o,t,e);return r>e?e:r}function Ut(){return{top:0,right:0,bottom:0,left:0}}function Ht(o){return Object.assign({},Ut(),o)}function Vt(o,t){return t.reduce(function(e,r){return e[r]=o,e},{})}var cn=function(t,e){return t=typeof t=="function"?t(Object.assign({},e.rects,{placement:e.placement})):t,Ht(typeof t!="number"?t:Vt(t,We))};function un(o){var t,e=o.state,r=o.name,i=o.options,n=e.elements.arrow,a=e.modifiersData.popperOffsets,s=X(e.placement),l=Je(s),p=[L,q].indexOf(s)>=0,d=p?"height":"width";if(!(!n||!a)){var c=cn(i.padding,e),u=Ze(n),m=l==="y"?B:L,M=l==="y"?H:q,g=e.rects.reference[d]+e.rects.reference[l]-a[l]-e.rects.popper[d],f=a[l]-e.rects.reference[l],T=he(n),w=T?l==="y"?T.clientHeight||0:T.clientWidth||0:0,D=g/2-f/2,h=c[m],y=w-u[d]-c[M],b=w/2-u[d]/2+D,_=Qe(h,b,y),x=l;e.modifiersData[r]=(t={},t[x]=_,t.centerOffset=_-b,t)}}function mn(o){var t=o.state,e=o.options,r=e.element,i=r===void 0?"[data-popper-arrow]":r;i!=null&&(typeof i=="string"&&(i=t.elements.popper.querySelector(i),!i)||qt(t.elements.popper,i)&&(t.elements.arrow=i))}var Lr={name:"arrow",enabled:!0,phase:"main",fn:un,effect:mn,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function ce(o){return o.split("-")[1]}var fn={top:"auto",right:"auto",bottom:"auto",left:"auto"};function hn(o,t){var e=o.x,r=o.y,i=t.devicePixelRatio||1;return{x:Oe(e*i)/i||0,y:Oe(r*i)/i||0}}function jr(o){var t,e=o.popper,r=o.popperRect,i=o.placement,n=o.variation,a=o.offsets,s=o.position,l=o.gpuAcceleration,p=o.adaptive,d=o.roundOffsets,c=o.isFixed,u=a.x,m=u===void 0?0:u,M=a.y,g=M===void 0?0:M,f=typeof d=="function"?d({x:m,y:g}):{x:m,y:g};m=f.x,g=f.y;var T=a.hasOwnProperty("x"),w=a.hasOwnProperty("y"),D=L,h=B,y=window;if(p){var b=he(e),_="clientHeight",x="clientWidth";if(b===$(e)&&(b=ee(e),ae(b).position!=="static"&&s==="absolute"&&(_="scrollHeight",x="scrollWidth")),b=b,i===B||(i===L||i===q)&&n===Ke){h=H;var E=c&&b===y&&y.visualViewport?y.visualViewport.height:b[_];g-=E-r.height,g*=l?1:-1}if(i===L||(i===B||i===H)&&n===Ke){D=q;var v=c&&b===y&&y.visualViewport?y.visualViewport.width:b[x];m-=v-r.width,m*=l?1:-1}}var C=Object.assign({position:s},p&&fn),S=d===!0?hn({x:m,y:g},$(e)):{x:m,y:g};if(m=S.x,g=S.y,l){var F;return Object.assign({},C,(F={},F[h]=w?"0":"",F[D]=T?"0":"",F.transform=(y.devicePixelRatio||1)<=1?"translate("+m+"px, "+g+"px)":"translate3d("+m+"px, "+g+"px, 0)",F))}return Object.assign({},C,(t={},t[h]=w?g+"px":"",t[D]=T?m+"px":"",t.transform="",t))}function gn(o){var t=o.state,e=o.options,r=e.gpuAcceleration,i=r===void 0?!0:r,n=e.adaptive,a=n===void 0?!0:n,s=e.roundOffsets,l=s===void 0?!0:s,p={placement:X(t.placement),variation:ce(t.placement),popper:t.elements.popper,popperRect:t.rects.popper,gpuAcceleration:i,isFixed:t.options.strategy==="fixed"};t.modifiersData.popperOffsets!=null&&(t.styles.popper=Object.assign({},t.styles.popper,jr(Object.assign({},p,{offsets:t.modifiersData.popperOffsets,position:t.options.strategy,adaptive:a,roundOffsets:l})))),t.modifiersData.arrow!=null&&(t.styles.arrow=Object.assign({},t.styles.arrow,jr(Object.assign({},p,{offsets:t.modifiersData.arrow,position:"absolute",adaptive:!1,roundOffsets:l})))),t.attributes.popper=Object.assign({},t.attributes.popper,{"data-popper-placement":t.placement})}var Wr={name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:gn,data:{}};var ci={passive:!0};function yn(o){var t=o.state,e=o.instance,r=o.options,i=r.scroll,n=i===void 0?!0:i,a=r.resize,s=a===void 0?!0:a,l=$(t.elements.popper),p=[].concat(t.scrollParents.reference,t.scrollParents.popper);return n&&p.forEach(function(d){d.addEventListener("scroll",e.update,ci)}),s&&l.addEventListener("resize",e.update,ci),function(){n&&p.forEach(function(d){d.removeEventListener("scroll",e.update,ci)}),s&&l.removeEventListener("resize",e.update,ci)}}var qr={name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:yn,data:{}};var Mn={left:"right",right:"left",bottom:"top",top:"bottom"};function Tt(o){return o.replace(/left|right|bottom|top/g,function(t){return Mn[t]})}var bn={start:"end",end:"start"};function ui(o){return o.replace(/start|end/g,function(t){return bn[t]})}function et(o){var t=$(o),e=t.pageXOffset,r=t.pageYOffset;return{scrollLeft:e,scrollTop:r}}function tt(o){return de(ee(o)).left+et(o).scrollLeft}function Zi(o,t){var e=$(o),r=ee(o),i=e.visualViewport,n=r.clientWidth,a=r.clientHeight,s=0,l=0;if(i){n=i.width,a=i.height;var p=Wt();(p||!p&&t==="fixed")&&(s=i.offsetLeft,l=i.offsetTop)}return{width:n,height:a,x:s+tt(o),y:l}}function Ji(o){var t,e=ee(o),r=et(o),i=(t=o.ownerDocument)==null?void 0:t.body,n=fe(e.scrollWidth,e.clientWidth,i?i.scrollWidth:0,i?i.clientWidth:0),a=fe(e.scrollHeight,e.clientHeight,i?i.scrollHeight:0,i?i.clientHeight:0),s=-r.scrollLeft+tt(o),l=-r.scrollTop;return ae(i||e).direction==="rtl"&&(s+=fe(e.clientWidth,i?i.clientWidth:0)-n),{width:n,height:a,x:s,y:l}}function it(o){var t=ae(o),e=t.overflow,r=t.overflowX,i=t.overflowY;return/auto|scroll|overlay|hidden/.test(e+i+r)}function mi(o){return["html","body","#document"].indexOf(K(o))>=0?o.ownerDocument.body:V(o)&&it(o)?o:mi(Ae(o))}function qe(o,t){var e;t===void 0&&(t=[]);var r=mi(o),i=r===((e=o.ownerDocument)==null?void 0:e.body),n=$(r),a=i?[n].concat(n.visualViewport||[],it(r)?r:[]):r,s=t.concat(a);return i?s:s.concat(qe(Ae(a)))}function _t(o){return Object.assign({},o,{left:o.x,top:o.y,right:o.x+o.width,bottom:o.y+o.height})}function vn(o,t){var e=de(o,!1,t==="fixed");return e.top=e.top+o.clientTop,e.left=e.left+o.clientLeft,e.bottom=e.top+o.clientHeight,e.right=e.left+o.clientWidth,e.width=o.clientWidth,e.height=o.clientHeight,e.x=e.left,e.y=e.top,e}function Ur(o,t,e){return t===pi?_t(Zi(o,e)):pe(t)?vn(t,e):_t(Ji(ee(o)))}function wn(o){var t=qe(Ae(o)),e=["absolute","fixed"].indexOf(ae(o).position)>=0,r=e&&V(o)?he(o):o;return pe(r)?t.filter(function(i){return pe(i)&&qt(i,r)&&K(i)!=="body"}):[]}function Qi(o,t,e,r){var i=t==="clippingParents"?wn(o):[].concat(t),n=[].concat(i,[e]),a=n[0],s=n.reduce(function(l,p){var d=Ur(o,p,r);return l.top=fe(d.top,l.top),l.right=Xe(d.right,l.right),l.bottom=Xe(d.bottom,l.bottom),l.left=fe(d.left,l.left),l},Ur(o,a,r));return s.width=s.right-s.left,s.height=s.bottom-s.top,s.x=s.left,s.y=s.top,s}function Yt(o){var t=o.reference,e=o.element,r=o.placement,i=r?X(r):null,n=r?ce(r):null,a=t.x+t.width/2-e.width/2,s=t.y+t.height/2-e.height/2,l;switch(i){case B:l={x:a,y:t.y-e.height};break;case H:l={x:a,y:t.y+t.height};break;case q:l={x:t.x+t.width,y:s};break;case L:l={x:t.x-e.width,y:s};break;default:l={x:t.x,y:t.y}}var p=i?Je(i):null;if(p!=null){var d=p==="y"?"height":"width";switch(n){case Re:l[p]=l[p]-(t[d]/2-e[d]/2);break;case Ke:l[p]=l[p]+(t[d]/2-e[d]/2);break;default:}}return l}function ge(o,t){t===void 0&&(t={});var e=t,r=e.placement,i=r===void 0?o.placement:r,n=e.strategy,a=n===void 0?o.strategy:n,s=e.boundary,l=s===void 0?Rr:s,p=e.rootBoundary,d=p===void 0?pi:p,c=e.elementContext,u=c===void 0?vt:c,m=e.altBoundary,M=m===void 0?!1:m,g=e.padding,f=g===void 0?0:g,T=Ht(typeof f!="number"?f:Vt(f,We)),w=u===vt?Or:vt,D=o.rects.popper,h=o.elements[M?w:u],y=Qi(pe(h)?h:h.contextElement||ee(o.elements.popper),l,d,a),b=de(o.elements.reference),_=Yt({reference:b,element:D,strategy:"absolute",placement:i}),x=_t(Object.assign({},D,_)),E=u===vt?x:b,v={top:y.top-E.top+T.top,bottom:E.bottom-y.bottom+T.bottom,left:y.left-E.left+T.left,right:E.right-y.right+T.right},C=o.modifiersData.offset;if(u===vt&&C){var S=C[i];Object.keys(v).forEach(function(F){var k=[q,H].indexOf(F)>=0?1:-1,te=[B,H].indexOf(F)>=0?"y":"x";v[F]+=S[te]*k})}return v}function er(o,t){t===void 0&&(t={});var e=t,r=e.placement,i=e.boundary,n=e.rootBoundary,a=e.padding,s=e.flipVariations,l=e.allowedAutoPlacements,p=l===void 0?di:l,d=ce(r),c=d?s?Ki:Ki.filter(function(M){return ce(M)===d}):We,u=c.filter(function(M){return p.indexOf(M)>=0});u.length===0&&(u=c);var m=u.reduce(function(M,g){return M[g]=ge(o,{placement:g,boundary:i,rootBoundary:n,padding:a})[X(g)],M},{});return Object.keys(m).sort(function(M,g){return m[M]-m[g]})}function xn(o){if(X(o)===li)return[];var t=Tt(o);return[ui(o),t,ui(t)]}function Tn(o){var t=o.state,e=o.options,r=o.name;if(!t.modifiersData[r]._skip){for(var i=e.mainAxis,n=i===void 0?!0:i,a=e.altAxis,s=a===void 0?!0:a,l=e.fallbackPlacements,p=e.padding,d=e.boundary,c=e.rootBoundary,u=e.altBoundary,m=e.flipVariations,M=m===void 0?!0:m,g=e.allowedAutoPlacements,f=t.options.placement,T=X(f),w=T===f,D=l||(w||!M?[Tt(f)]:xn(f)),h=[f].concat(D).reduce(function($e,me){return $e.concat(X(me)===li?er(t,{placement:me,boundary:d,rootBoundary:c,padding:p,flipVariations:M,allowedAutoPlacements:g}):me)},[]),y=t.rects.reference,b=t.rects.popper,_=new Map,x=!0,E=h[0],v=0;v=0,te=k?"width":"height",N=ge(t,{placement:C,boundary:d,rootBoundary:c,altBoundary:u,padding:p}),I=k?F?q:L:F?H:B;y[te]>b[te]&&(I=Tt(I));var Te=Tt(I),le=[];if(n&&le.push(N[S]<=0),s&&le.push(N[I]<=0,N[Te]<=0),le.every(function($e){return $e})){E=C,x=!1;break}_.set(C,le)}if(x)for(var _e=M?3:1,gt=function(me){var je=h.find(function(Ge){var Se=_.get(Ge);if(Se)return Se.slice(0,me).every(function(yt){return yt})});if(je)return E=je,"break"},Le=_e;Le>0;Le--){var Ye=gt(Le);if(Ye==="break")break}t.placement!==E&&(t.modifiersData[r]._skip=!0,t.placement=E,t.reset=!0)}}var Hr={name:"flip",enabled:!0,phase:"main",fn:Tn,requiresIfExists:["offset"],data:{_skip:!1}};function Vr(o,t,e){return e===void 0&&(e={x:0,y:0}),{top:o.top-t.height-e.y,right:o.right-t.width+e.x,bottom:o.bottom-t.height+e.y,left:o.left-t.width-e.x}}function Yr(o){return[B,q,H,L].some(function(t){return o[t]>=0})}function _n(o){var t=o.state,e=o.name,r=t.rects.reference,i=t.rects.popper,n=t.modifiersData.preventOverflow,a=ge(t,{elementContext:"reference"}),s=ge(t,{altBoundary:!0}),l=Vr(a,r),p=Vr(s,i,n),d=Yr(l),c=Yr(p);t.modifiersData[e]={referenceClippingOffsets:l,popperEscapeOffsets:p,isReferenceHidden:d,hasPopperEscaped:c},t.attributes.popper=Object.assign({},t.attributes.popper,{"data-popper-reference-hidden":d,"data-popper-escaped":c})}var Gr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:_n};function Sn(o,t,e){var r=X(o),i=[L,B].indexOf(r)>=0?-1:1,n=typeof e=="function"?e(Object.assign({},t,{placement:o})):e,a=n[0],s=n[1];return a=a||0,s=(s||0)*i,[L,q].indexOf(r)>=0?{x:s,y:a}:{x:a,y:s}}function Dn(o){var t=o.state,e=o.options,r=o.name,i=e.offset,n=i===void 0?[0,0]:i,a=di.reduce(function(d,c){return d[c]=Sn(c,t.rects,n),d},{}),s=a[t.placement],l=s.x,p=s.y;t.modifiersData.popperOffsets!=null&&(t.modifiersData.popperOffsets.x+=l,t.modifiersData.popperOffsets.y+=p),t.modifiersData[r]=a}var zr={name:"offset",enabled:!0,phase:"main",requires:["popperOffsets"],fn:Dn};function En(o){var t=o.state,e=o.name;t.modifiersData[e]=Yt({reference:t.rects.reference,element:t.rects.popper,strategy:"absolute",placement:t.placement})}var Kr={name:"popperOffsets",enabled:!0,phase:"read",fn:En,data:{}};function tr(o){return o==="x"?"y":"x"}function Cn(o){var t=o.state,e=o.options,r=o.name,i=e.mainAxis,n=i===void 0?!0:i,a=e.altAxis,s=a===void 0?!1:a,l=e.boundary,p=e.rootBoundary,d=e.altBoundary,c=e.padding,u=e.tether,m=u===void 0?!0:u,M=e.tetherOffset,g=M===void 0?0:M,f=ge(t,{boundary:l,rootBoundary:p,padding:c,altBoundary:d}),T=X(t.placement),w=ce(t.placement),D=!w,h=Je(T),y=tr(h),b=t.modifiersData.popperOffsets,_=t.rects.reference,x=t.rects.popper,E=typeof g=="function"?g(Object.assign({},t.rects,{placement:t.placement})):g,v=typeof E=="number"?{mainAxis:E,altAxis:E}:Object.assign({mainAxis:0,altAxis:0},E),C=t.modifiersData.offset?t.modifiersData.offset[t.placement]:null,S={x:0,y:0};if(b){if(n){var F,k=h==="y"?B:L,te=h==="y"?H:q,N=h==="y"?"height":"width",I=b[h],Te=I+f[k],le=I-f[te],_e=m?-x[N]/2:0,gt=w===Re?_[N]:x[N],Le=w===Re?-x[N]:-_[N],Ye=t.elements.arrow,$e=m&&Ye?Ze(Ye):{width:0,height:0},me=t.modifiersData["arrow#persistent"]?t.modifiersData["arrow#persistent"].padding:Ut(),je=me[k],Ge=me[te],Se=Qe(0,_[N],$e[N]),yt=D?_[N]/2-_e-Se-je-v.mainAxis:gt-Se-je-v.mainAxis,ti=D?-_[N]/2+_e+Se+Ge+v.mainAxis:Le+Se+Ge+v.mainAxis,Mt=t.elements.arrow&&he(t.elements.arrow),ii=Mt?h==="y"?Mt.clientTop||0:Mt.clientLeft||0:0,$t=(F=C==null?void 0:C[h])!=null?F:0,ri=I+yt-$t-ii,oi=I+ti-$t,Rt=Qe(m?Xe(Te,ri):Te,I,m?fe(le,oi):le);b[h]=Rt,S[h]=Rt-I}if(s){var Ot,ni=h==="x"?B:L,ai=h==="x"?H:q,De=b[y],ze=y==="y"?"height":"width",At=De+f[ni],Nt=De-f[ai],bt=[B,L].indexOf(T)!==-1,Bt=(Ot=C==null?void 0:C[y])!=null?Ot:0,It=bt?At:De-_[ze]-x[ze]-Bt+v.altAxis,Lt=bt?De+_[ze]+x[ze]-Bt-v.altAxis:Nt,jt=m&&bt?Ir(It,De,Lt):Qe(m?It:At,De,m?Lt:Nt);b[y]=jt,S[y]=jt-De}t.modifiersData[r]=S}}var Xr={name:"preventOverflow",enabled:!0,phase:"main",fn:Cn,requiresIfExists:["offset"]};function ir(o){return{scrollLeft:o.scrollLeft,scrollTop:o.scrollTop}}function rr(o){return o===$(o)||!V(o)?et(o):ir(o)}function Pn(o){var t=o.getBoundingClientRect(),e=Oe(t.width)/o.offsetWidth||1,r=Oe(t.height)/o.offsetHeight||1;return e!==1||r!==1}function or(o,t,e){e===void 0&&(e=!1);var r=V(t),i=V(t)&&Pn(t),n=ee(t),a=de(o,i,e),s={scrollLeft:0,scrollTop:0},l={x:0,y:0};return(r||!r&&!e)&&((K(t)!=="body"||it(n))&&(s=rr(t)),V(t)?(l=de(t,!0),l.x+=t.clientLeft,l.y+=t.clientTop):n&&(l.x=tt(n))),{x:a.left+s.scrollLeft-l.x,y:a.top+s.scrollTop-l.y,width:a.width,height:a.height}}function Fn(o){var t=new Map,e=new Set,r=[];o.forEach(function(n){t.set(n.name,n)});function i(n){e.add(n.name);var a=[].concat(n.requires||[],n.requiresIfExists||[]);a.forEach(function(s){if(!e.has(s)){var l=t.get(s);l&&i(l)}}),r.push(n)}return o.forEach(function(n){e.has(n.name)||i(n)}),r}function nr(o){var t=Fn(o);return Ar.reduce(function(e,r){return e.concat(t.filter(function(i){return i.phase===r}))},[])}function ar(o){var t;return function(){return t||(t=new Promise(function(e){Promise.resolve().then(function(){t=void 0,e(o())})})),t}}function sr(o){var t=o.reduce(function(e,r){var i=e[r.name];return e[r.name]=i?Object.assign({},i,r,{options:Object.assign({},i.options,r.options),data:Object.assign({},i.data,r.data)}):r,e},{});return Object.keys(t).map(function(e){return t[e]})}var Zr={placement:"bottom",modifiers:[],strategy:"absolute"};function Jr(){for(var o=arguments.length,t=new Array(o),e=0;e$"@.?]*/g,"").replace(/:+/g," -")}function mr(o,t){return o.replace(new RegExp("{{.*?}}","g"),e=>$n(e,t))}function $n(o,t){let e=o;e=e.substring(2),e=e.substring(0,e.length-2),e=e.trim();let r=e.split(":");if(r.length===1){let i=r[0].split("."),n=eo(i,t);return n===void 0?"{{ INVALID TEMPLATE TAG - object undefined }}":n}else if(r.length===2){let i=r[0],n=r[1].split("."),a=eo(n,t);return a===void 0?"{{ INVALID TEMPLATE TAG - object undefined }}":i==="LIST"?Array.isArray(a)?a.map(s=>`- ${s}`).join(` `):"{{ INVALID TEMPLATE TAG - operator LIST is only applicable on an array }}":i==="ENUM"?Array.isArray(a)?a.join(", "):"{{ INVALID TEMPLATE TAG - operator ENUM is only applicable on an array }}":`{{ INVALID TEMPLATE TAG - unknown operator ${i} }}`}return"{{ INVALID TEMPLATE TAG }}"}function eo(o,t){let e=t;for(let r of o)e!==void 0&&(e=e[r]);return e}function ro(o){let t=o.length;if(t===0)return"";let e=o[0].length;if(e===0)return"";for(let n of o)if(n.length!==e)return"";let r=[];for(let n=0;na&&(a=s[n].length);r.push(a)}let i="";for(let n=0;ncreateFragment(t=>t.createDiv().innerHTML=o);function Rn(o){return`${o.getMonth()+1}-${o.getDate()}-${o.getFullYear()}`}function On(o){return`${o.getHours()}-${o.getMinutes()}-${o.getSeconds()}`}function no(o){return`${Rn(o)} ${On(o)}`}function fi(o,t){return(o%t+t)%t}function fr(o){return o.charAt(0).toUpperCase()+o.slice(1)}var rt=class extends Error{constructor(t){super(t)}},Gt=class extends Error{constructor(t){super(t)}};function R(o,t,e){for(let r in o)o[r]=t.hasOwnProperty(r)?t[r]:e[r]}function zt(o){return o.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b([A-Z]+)([A-Z])([a-z])/,"$1 $2$3").replace(/^./,function(t){return t.toUpperCase()})}var hr=class{constructor(t,e,r){this.owner=t,this.containerEl=e,e.on("click",".suggestion-item",this.onSuggestionClick.bind(this)),e.on("mousemove",".suggestion-item",this.onSuggestionMouseover.bind(this)),r.register([],"ArrowUp",i=>{if(!i.isComposing)return this.setSelectedItem(this.selectedItem-1,!0),!1}),r.register([],"ArrowDown",i=>{if(!i.isComposing)return this.setSelectedItem(this.selectedItem+1,!0),!1}),r.register([],"Enter",i=>{if(!i.isComposing)return this.useSelectedItem(i),!1})}onSuggestionClick(t,e){t.preventDefault();let r=this.suggestions.indexOf(e);this.setSelectedItem(r,!1),this.useSelectedItem(t)}onSuggestionMouseover(t,e){let r=this.suggestions.indexOf(e);this.setSelectedItem(r,!1)}setSuggestions(t){this.containerEl.empty();let e=[];t.forEach(r=>{let i=this.containerEl.createDiv("suggestion-item");this.owner.renderSuggestion(r,i),e.push(i)}),this.values=t,this.suggestions=e,this.setSelectedItem(0,!1)}useSelectedItem(t){let e=this.values[this.selectedItem];e&&this.owner.selectSuggestion(e,t)}setSelectedItem(t,e){let r=this.suggestions.length>0?to(t,this.suggestions.length):0,i=this.suggestions[this.selectedItem],n=this.suggestions[r];i==null||i.removeClass("is-selected"),n==null||n.addClass("is-selected"),this.selectedItem=r,e&&n.scrollIntoView(!1)}},St=class{constructor(t,e){this.app=t,this.inputEl=e,this.scope=new ao.Scope,this.suggestEl=createDiv("suggestion-container");let r=this.suggestEl.createDiv("suggestion");this.suggest=new hr(this,r,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 t=this.inputEl.value,e=this.getSuggestions(t);e.length>0&&(this.suggest.setSuggestions(e),this.open(this.app.dom.appContainerEl,this.inputEl))}open(t,e){this.app.keymap.pushScope(this.scope),t.appendChild(this.suggestEl),this.popper=lr(e,this.suggestEl,{placement:"bottom-start",modifiers:[{name:"sameWidth",enabled:!0,fn:({state:r,instance:i})=>{let n=`${r.rects.reference.width}px`;r.styles.popper.width!==n&&(r.styles.popper.width=n,i.update())},phase:"beforeWrite",requires:["computeStyles"]}]})}close(){this.app.keymap.popScope(this.scope),this.suggest.setSuggestions([]),this.popper.destroy(),this.suggestEl.detach()}};var ye=class extends St{getSuggestions(t){let e=this.app.vault.getAllLoadedFiles(),r=[],i=t.toLowerCase();return e.forEach(n=>{n instanceof so.TFolder&&n.path.toLowerCase().contains(i)&&r.push(n)}),r}renderSuggestion(t,e){e.setText(t.path)}selectSuggestion(t){this.inputEl.value=t.path,this.inputEl.trigger("input"),this.close()}};var lo=require("obsidian"),Me=class extends St{getSuggestions(t){let e=this.app.vault.getAllLoadedFiles(),r=[],i=t.toLowerCase();return e.forEach(n=>{n instanceof lo.TFile&&n.name.toLowerCase().contains(i)&&r.push(n)}),r}renderSuggestion(t,e){e.setText(t.name)}selectSuggestion(t){this.inputEl.value=t.name,this.inputEl.trigger("input"),this.close()}};function re(){}function gr(o){return o()}function hi(){return Object.create(null)}function Ee(o){o.forEach(gr)}function gi(o){return typeof o=="function"}function Dt(o,t){return o!=o?t==t:o!==t||o&&typeof o=="object"||typeof o=="function"}function po(o){return Object.keys(o).length===0}var yr=typeof window!="undefined"?window:typeof globalThis!="undefined"?globalThis:global;var yi=class o{constructor(t){z(this,"_listeners","WeakMap"in yr?new WeakMap:void 0);z(this,"_observer");z(this,"options");this.options=t}observe(t,e){return this._listeners.set(t,e),this._getObserver().observe(t,this.options),()=>{this._listeners.delete(t),this._observer.unobserve(t)}}_getObserver(){var t;return(t=this._observer)!=null?t:this._observer=new ResizeObserver(e=>{var r;for(let i of e)o.entries.set(i.target,i),(r=this._listeners.get(i.target))==null||r(i)})}};yi.entries="WeakMap"in yr?new WeakMap:void 0;var co=!1;function uo(){co=!0}function mo(){co=!1}function j(o,t){o.appendChild(t)}function fo(o,t,e){let r=ho(o);if(!r.getElementById(t)){let i=O("style");i.id=t,i.textContent=e,Bn(r,i)}}function ho(o){if(!o)return document;let t=o.getRootNode?o.getRootNode():o.ownerDocument;return t&&t.host?t:o.ownerDocument}function Bn(o,t){return j(o.head||o,t),t.sheet}function Y(o,t,e){o.insertBefore(t,e||null)}function W(o){o.parentNode&&o.parentNode.removeChild(o)}function Kt(o,t){for(let e=0;eo.removeEventListener(t,e,r)}function A(o,t,e){e==null?o.removeAttribute(t):o.getAttribute(t)!==e&&o.setAttribute(t,e)}function go(o){return Array.from(o.childNodes)}function bi(o,t){t=""+t,o.data!==t&&(o.data=t)}function vi(o,t){o.value=t==null?"":t}function Zt(o,t,e,r){e==null?o.style.removeProperty(t):o.style.setProperty(t,e,r?"important":"")}function Mr(o,t,e){for(let r=0;r{t[e.slot||"default"]=!0}),t}var He;function Ne(o){He=o}function vo(){if(!He)throw new Error("Function called outside component initialization");return He}function br(o){vo().$$.on_mount.push(o)}var nt=[];var wi=[],Ct=[],wo=[],Un=Promise.resolve(),wr=!1;function xo(){wr||(wr=!0,Un.then(xi))}function at(o){Ct.push(o)}var vr=new Set,Et=0;function xi(){if(Et!==0)return;let o=He;do{try{for(;Eto.indexOf(r)===-1?t.push(r):e.push(r)),e.forEach(r=>r()),Ct=t}var Ti=new Set,st;function lt(){st={r:0,c:[],p:st}}function pt(){st.r||Ee(st.c),st=st.p}function G(o,t){o&&o.i&&(Ti.delete(o),o.i(t))}function se(o,t,e,r){if(o&&o.o){if(Ti.has(o))return;Ti.add(o),st.c.push(()=>{Ti.delete(o),r&&(e&&o.d(1),r())}),o.o(t)}else r&&r()}function Be(o){return(o==null?void 0:o.length)!==void 0?o:Array.from(o)}var Vn=["allowfullscreen","allowpaymentrequest","async","autofocus","autoplay","checked","controls","default","defer","disabled","formnovalidate","hidden","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","selected"],Yn=new Set([...Vn]);function _i(o){o&&o.c()}function Jt(o,t,e){let{fragment:r,after_update:i}=o.$$;r&&r.m(t,e),at(()=>{let n=o.$$.on_mount.map(gr).filter(gi);o.$$.on_destroy?o.$$.on_destroy.push(...n):Ee(n),o.$$.on_mount=[]}),i.forEach(at)}function Qt(o,t){let e=o.$$;e.fragment!==null&&(To(e.after_update),Ee(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function zn(o,t){o.$$.dirty[0]===-1&&(nt.push(o),xo(),o.$$.dirty.fill(0)),o.$$.dirty[t/31|0]|=1<{let M=m.length?m[0]:u;return p.ctx&&i(p.ctx[c],p.ctx[c]=M)&&(!p.skip_bound&&p.bound[c]&&p.bound[c](M),d&&zn(o,c)),u}):[],p.update(),d=!0,Ee(p.before_update),p.fragment=r?r(p.ctx):!1,t.target){if(t.hydrate){uo();let c=go(t.target);p.fragment&&p.fragment.l(c),c.forEach(W)}else p.fragment&&p.fragment.c();t.intro&&G(o.$$.fragment),Jt(o,t.target,t.anchor),mo(),xi()}Ne(l)}var Kn;typeof HTMLElement=="function"&&(Kn=class extends HTMLElement{constructor(t,e,r){super();z(this,"$$ctor");z(this,"$$s");z(this,"$$c");z(this,"$$cn",!1);z(this,"$$d",{});z(this,"$$r",!1);z(this,"$$p_d",{});z(this,"$$l",{});z(this,"$$l_u",new Map);this.$$ctor=t,this.$$s=e,r&&this.attachShadow({mode:"open"})}addEventListener(t,e,r){if(this.$$l[t]=this.$$l[t]||[],this.$$l[t].push(e),this.$$c){let i=this.$$c.$on(t,e);this.$$l_u.set(e,i)}super.addEventListener(t,e,r)}removeEventListener(t,e,r){if(super.removeEventListener(t,e,r),this.$$c){let i=this.$$l_u.get(e);i&&(i(),this.$$l_u.delete(e))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let t=function(n){return()=>{let a;return{c:function(){a=O("slot"),n!=="default"&&A(a,"name",n)},m:function(p,d){Y(p,a,d)},d:function(p){p&&W(a)}}}};if(await Promise.resolve(),!this.$$cn)return;let e={},r=Mo(this);for(let n of this.$$s)n in r&&(e[n]=[t(n)]);for(let n of this.attributes){let a=this.$$g_p(n.name);a in this.$$d||(this.$$d[a]=xr(a,n.value,this.$$p_d,"toProp"))}for(let n in this.$$p_d)!(n in this.$$d)&&this[n]!==void 0&&(this.$$d[n]=this[n],delete this[n]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:e,$$scope:{ctx:[]}}});let i=()=>{this.$$r=!0;for(let n in this.$$p_d)if(this.$$d[n]=this.$$c.$$.ctx[this.$$c.$$.props[n]],this.$$p_d[n].reflect){let a=xr(n,this.$$d[n],this.$$p_d,"toAttribute");a==null?this.removeAttribute(this.$$p_d[n].attribute||n):this.setAttribute(this.$$p_d[n].attribute||n,a)}this.$$r=!1};this.$$c.$$.after_update.push(i),i();for(let n in this.$$l)for(let a of this.$$l[n]){let s=this.$$c.$on(n,a);this.$$l_u.set(a,s)}this.$$l={}}}attributeChangedCallback(t,e,r){var i;this.$$r||(t=this.$$g_p(t),this.$$d[t]=xr(t,r,this.$$p_d,"toProp"),(i=this.$$c)==null||i.$set({[t]:this.$$d[t]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(t){return Object.keys(this.$$p_d).find(e=>this.$$p_d[e].attribute===t||!this.$$p_d[e].attribute&&e.toLowerCase()===t)||t}});function xr(o,t,e,r){var n;let i=(n=e[o])==null?void 0:n.type;if(t=i==="Boolean"&&typeof t!="boolean"?t!=null:t,!r||!e[o])return t;if(r==="toAttribute")switch(i){case"Object":case"Array":return t==null?null:JSON.stringify(t);case"Boolean":return t?"":null;case"Number":return t==null?null:t;default:return t}else switch(i){case"Object":case"Array":return t&&JSON.parse(t);case"Boolean":return t;case"Number":return t!=null?+t:t;default:return t}}var Ie=class{constructor(){z(this,"$$");z(this,"$$set")}$destroy(){Qt(this,1),this.$destroy=re}$on(t,e){if(!gi(e))return re;let r=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return r.push(e),()=>{let i=r.indexOf(e);i!==-1&&r.splice(i,1)}}$set(t){this.$$set&&!po(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}};var _o="4";typeof window!="undefined"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(_o);var So=["default","remap","remove"],Ft=class o{constructor(t,e){this.type=t,this.properties=e!=null?e:[]}validate(){console.debug(`MDB | validated property mappings for ${this.type}`);for(let t of this.properties){let e=t.validate();if(!e.res)return{res:!1,err:e.err}}for(let t of this.getMappedProperties()){let e=this.getMappedProperties().filter(r=>r.newProperty===t.newProperty);if(e.length!==0){if(e.length!==1)return{res:!1,err:new Gt(`Multiple remapped properties (${e.map(r=>r.toString()).toString()}) may not share the same name.`)}}}for(let t of this.getMappedProperties())if(this.properties.filter(r=>r.newProperty===t.property).length!==0)return{res:!1,err:new Gt(`Remapped property (${t}) may not share it's new name with an existing property.`)};return{res:!0}}getMappedProperties(){return this.properties.filter(t=>t.mapping==="remap")}copy(){let t=new o(this.type);for(let e of this.properties){let r=new dt(e.property,e.newProperty,e.mapping,e.locked);t.properties.push(r)}return t}},dt=class{constructor(t,e,r,i){this.property=t,this.newProperty=e,this.mapping=r,this.locked=i!=null?i:!1}validate(){if(this.locked){if(this.mapping==="remove")return{res:!1,err:new rt(`Error in property mapping "${this.toString()}": locked property may not be removed.`)};if(this.mapping==="remap")return{res:!1,err:new rt(`Error in property mapping "${this.toString()}": locked property may not be remapped.`)}}return this.mapping==="default"?{res:!0}:this.mapping==="remove"?{res:!0}:!this.property||!ur(this.property)?{res:!1,err:new rt(`Error in property mapping "${this.toString()}": property may not be empty and only contain letters and underscores.`)}:!this.newProperty||!ur(this.newProperty)?{res:!1,err:new rt(`Error in property mapping "${this.toString()}": new property may not be empty and only contain letters and underscores.`)}:{res:!0}}toString(){return this.mapping==="default"?this.property:this.mapping==="remap"?`${this.property} -> ${this.newProperty}`:this.mapping==="remove"?`remove ${this.property}`:this.property}};var Eo=require("obsidian");function Xn(o){fo(o,"svelte-klmgqw",".icon-wrapper.svelte-klmgqw{display:inline-block;position:relative;width:20px}.icon.svelte-klmgqw{position:absolute;height:20px;width:20px;top:calc(50% - 10px)}")}function Do(o){let t,e;return{c(){t=O("div"),e=O("div"),A(e,"class","icon svelte-klmgqw"),A(t,"class","icon-wrapper svelte-klmgqw")},m(r,i){Y(r,t,i),j(t,e),o[3](e)},p:re,d(r){r&&W(t),o[3](null)}}}function Zn(o){let t,e=o[0].length>0&&Do(o);return{c(){e&&e.c(),t=Mi()},m(r,i){e&&e.m(r,i),Y(r,t,i)},p(r,[i]){r[0].length>0?e?e.p(r,i):(e=Do(r),e.c(),e.m(t.parentNode,t)):e&&(e.d(1),e=null)},i:re,o:re,d(r){r&&W(t),e&&e.d(r)}}}function Jn(o,t,e){let{iconName:r=""}=t,{iconSize:i=20}=t,n;br(()=>{(0,Eo.setIcon)(n,r,i)});function a(s){wi[s?"unshift":"push"](()=>{n=s,e(1,n)})}return o.$$set=s=>{"iconName"in s&&e(0,r=s.iconName),"iconSize"in s&&e(2,i=s.iconSize)},[r,n,i,a]}var Tr=class extends Ie{constructor(t){super(),Pt(this,t,Jn,Zn,Dt,{iconName:0,iconSize:2},Xn)}},Co=Tr;function Po(o,t,e){let r=o.slice();return r[7]=t[e],r[8]=t,r[9]=e,r}function Qn(o,t,e){let r=o.slice();return r[10]=t[e],r}function ea(o){let t,e,r,i,n,a,s=Be(So),l=[];for(let c=0;c{d=null}),pt())},i(c){i||(G(d),i=!0)},o(c){se(d),i=!1},d(c){c&&(W(t),W(e),W(r)),Kt(l,c),d&&d.d(c),n=!1,a()}}}function ta(o){let t;return{c(){t=O("div"),t.textContent="property can not be remapped",A(t,"class","media-db-plugin-property-binding-text")},m(e,r){Y(e,t,r)},p:re,i:re,o:re,d(e){e&&W(t)}}}function ia(o){let t,e;return{c(){t=O("option"),t.textContent=`${o[10]} `,t.__value=e=o[10],vi(t,t.__value)},m(r,i){Y(r,t,i)},p:re,d(r){r&&W(t)}}}function Fo(o){let t,e,r,i,n,a,s;t=new Co({props:{iconName:"arrow-right"}});function l(){o[4].call(i,o[8],o[9])}return{c(){_i(t.$$.fragment),e=Ue(),r=O("div"),i=O("input"),A(i,"type","text"),A(i,"spellcheck","false"),A(r,"class","media-db-plugin-property-mapping-to")},m(p,d){Jt(t,p,d),Y(p,e,d),Y(p,r,d),j(r,i),vi(i,o[7].newProperty),n=!0,a||(s=Xt(i,"input",l),a=!0)},p(p,d){o=p,d&1&&i.value!==o[7].newProperty&&vi(i,o[7].newProperty)},i(p){n||(G(t.$$.fragment,p),n=!0)},o(p){se(t.$$.fragment,p),n=!1},d(p){p&&(W(e),W(r)),Qt(t,p),a=!1,s()}}}function ko(o){let t,e,r,i,n=o[7].property+"",a,s,l,p,d,c,u=[ta,ea],m=[];function M(g,f){return g[7].locked?0:1}return l=M(o,-1),p=m[l]=u[l](o),{c(){t=O("div"),e=O("div"),r=O("pre"),i=O("code"),a=ot(n),s=Ue(),p.c(),d=Ue(),A(r,"class","media-db-plugin-property-mapping-element-property-name"),A(e,"class","media-db-plugin-property-mapping-element-property-name-wrapper"),A(t,"class","media-db-plugin-property-mapping-element")},m(g,f){Y(g,t,f),j(t,e),j(e,r),j(r,i),j(i,a),j(t,s),m[l].m(t,null),j(t,d),c=!0},p(g,f){(!c||f&1)&&n!==(n=g[7].property+"")&&bi(a,n);let T=l;l=M(g,f),l===T?m[l].p(g,f):(lt(),se(m[T],1,1,()=>{m[T]=null}),pt(),p=m[l],p?p.p(g,f):(p=m[l]=u[l](g),p.c()),G(p,1),p.m(t,d))},i(g){c||(G(p),c=!0)},o(g){se(p),c=!1},d(g){g&&W(t),m[l].d()}}}function $o(o){var i,n;let t,e=((n=(i=o[2])==null?void 0:i.err)==null?void 0:n.message)+"",r;return{c(){t=O("div"),r=ot(e),A(t,"class","media-db-plugin-property-mapping-validation")},m(a,s){Y(a,t,s),j(t,r)},p(a,s){var l,p;s&4&&e!==(e=((p=(l=a[2])==null?void 0:l.err)==null?void 0:p.message)+"")&&bi(r,e)},d(a){a&&W(t)}}}function ra(o){var D;let t,e,r=fr(o[0].type)+"",i,n,a,s,l,p,d,c,u,m,M,g=Be(o[0].properties),f=[];for(let h=0;hse(f[h],1,1,()=>{f[h]=null}),w=!((D=o[2])!=null&&D.res)&&$o(o);return{c(){var h;t=O("div"),e=O("div"),i=ot(r),n=Ue(),a=O("div");for(let y=0;y{r.validate().res&&i(r)};return o.$$set=d=>{"model"in d&&e(0,r=d.model),"save"in d&&e(1,i=d.save)},o.$$.update=()=>{o.$$.dirty&1&&a(r)},[r,i,n,s,l,p]}var _r=class extends Ie{constructor(t){super(),Pt(this,t,oa,ra,Dt,{model:0,save:1})}},Oo=_r;function Ao(o,t,e){let r=o.slice();return r[2]=t[e],r}function No(o){let t,e;return t=new Oo({props:{model:o[2],save:o[1]}}),{c(){_i(t.$$.fragment)},m(r,i){Jt(t,r,i),e=!0},p(r,i){let n={};i&1&&(n.model=r[2]),i&2&&(n.save=r[1]),t.$set(n)},i(r){e||(G(t.$$.fragment,r),e=!0)},o(r){se(t.$$.fragment,r),e=!1},d(r){Qt(t,r)}}}function na(o){let t,e,r=Be(o[0]),i=[];for(let a=0;ase(i[a],1,1,()=>{i[a]=null});return{c(){t=O("div");for(let a=0;a{"models"in n&&e(0,r=n.models),"save"in n&&e(1,i=n.save)},[r,i]}var Sr=class extends Ie{constructor(t){super(),Pt(this,t,aa,na,Dt,{models:0,save:1})}},Bo=Sr;var Io=require("obsidian");var Z=class{constructor(){this.type=void 0,this.subType=void 0,this.title=void 0,this.englishTitle=void 0,this.year=void 0,this.dataSource=void 0,this.url=void 0,this.id=void 0,this.userData={}}toMetaDataObject(){return{...this.getWithOutUserData(),...this.userData,tags:this.getTags().join("/")}}getWithOutUserData(){let t=Object.assign({},this);return delete t.userData,t}};var ue=class extends Z{constructor(e={}){super();this.plot=void 0,this.genres=void 0,this.director=void 0,this.writer=void 0,this.studio=void 0,this.duration=void 0,this.onlineRating=void 0,this.actors=void 0,this.image=void 0,this.released=void 0,this.streamingServices=void 0,this.premiere=void 0,this.userData={watched:void 0,lastWatched:void 0,personalRating:void 0},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"tv","movie"]}getMediaType(){return"movie"}getSummary(){return this.englishTitle+" ("+this.year+")"}};var Ce=class extends Z{constructor(e={}){super();this.plot=void 0,this.genres=void 0,this.writer=void 0,this.studio=void 0,this.episodes=void 0,this.duration=void 0,this.onlineRating=void 0,this.actors=void 0,this.image=void 0,this.released=void 0,this.streamingServices=void 0,this.airing=void 0,this.airedFrom=void 0,this.airedTo=void 0,this.userData={watched:void 0,lastWatched:void 0,personalRating:void 0},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"tv","series"]}getMediaType(){return"series"}getSummary(){return this.title+" ("+this.year+")"}};var ct=class extends Z{constructor(e={}){super();this.plot=void 0,this.genres=void 0,this.authors=void 0,this.alternateTitles=void 0,this.chapters=void 0,this.volumes=void 0,this.onlineRating=void 0,this.image=void 0,this.released=void 0,this.status=void 0,this.publishedFrom=void 0,this.publishedTo=void 0,this.userData={watched:void 0,lastWatched:void 0,personalRating:void 0},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"manga","light-novel"]}getMediaType(){return"manga"}getSummary(){return this.title+" ("+this.year+")"}};var Pe=class extends Z{constructor(e={}){super();this.genres=void 0,this.onlineRating=void 0,this.image=void 0,this.released=void 0,this.releaseDate=void 0,this.userData={played:void 0,personalRating:void 0},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"game"]}getMediaType(){return"game"}getSummary(){return this.englishTitle+" ("+this.year+")"}};var ut=class extends Z{constructor(e={}){super();this.wikiUrl=void 0,this.lastUpdated=void 0,this.length=void 0,this.article=void 0,this.userData={},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"wiki"]}getMediaType(){return"wiki"}getWithOutUserData(){let e=Object.assign({},this);return delete e.userData,delete e.article,e}getSummary(){return this.title}};var mt=class extends Z{constructor(e={}){super();this.genres=void 0,this.artists=void 0,this.image=void 0,this.rating=void 0,this.userData={personalRating:void 0},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"music",this.subType]}getMediaType(){return"musicRelease"}getSummary(){let e=this.title+" ("+this.year+")";return this.artists.length>0&&(e+=" - "+this.artists.join(", ")),e}};var ft=class extends Z{constructor(e={}){super();this.genres=void 0,this.onlineRating=void 0,this.minPlayers=void 0,this.maxPlayers=void 0,this.playtime=void 0,this.publishers=void 0,this.complexityRating=void 0,this.image=void 0,this.released=void 0,this.userData={played:void 0,personalRating:void 0},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"boardgame"]}getMediaType(){return"boardgame"}getSummary(){return this.englishTitle+" ("+this.year+")"}};var ht=class extends Z{constructor(e={}){super();this.author=void 0,this.pages=void 0,this.image=void 0,this.onlineRating=void 0,this.released=void 0,this.userData={read:void 0,lastRead:void 0,personalRating:void 0},R(this,e,this),e.hasOwnProperty("userData")||R(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ie,"book"]}getMediaType(){return"book"}getSummary(){return this.englishTitle+" ("+this.year+")"}};var Fe=["movie","series","manga","game","wiki","musicRelease","boardgame","book"],Si=class{constructor(){}updateTemplates(t){this.mediaFileNameTemplateMap=new Map,this.mediaFileNameTemplateMap.set("movie",t.movieFileNameTemplate),this.mediaFileNameTemplateMap.set("series",t.seriesFileNameTemplate),this.mediaFileNameTemplateMap.set("manga",t.mangaFileNameTemplate),this.mediaFileNameTemplateMap.set("game",t.gameFileNameTemplate),this.mediaFileNameTemplateMap.set("wiki",t.wikiFileNameTemplate),this.mediaFileNameTemplateMap.set("musicRelease",t.musicReleaseFileNameTemplate),this.mediaFileNameTemplateMap.set("boardgame",t.boardgameFileNameTemplate),this.mediaFileNameTemplateMap.set("book",t.bookFileNameTemplate),this.mediaTemplateMap=new Map,this.mediaTemplateMap.set("movie",t.movieTemplate),this.mediaTemplateMap.set("series",t.seriesTemplate),this.mediaTemplateMap.set("manga",t.mangaTemplate),this.mediaTemplateMap.set("game",t.gameTemplate),this.mediaTemplateMap.set("wiki",t.wikiTemplate),this.mediaTemplateMap.set("musicRelease",t.musicReleaseTemplate),this.mediaTemplateMap.set("boardgame",t.boardgameTemplate),this.mediaTemplateMap.set("book",t.bookTemplate)}updateFolders(t){this.mediaFolderMap=new Map,this.mediaFolderMap.set("movie",t.movieFolder),this.mediaFolderMap.set("series",t.seriesFolder),this.mediaFolderMap.set("manga",t.mangaFolder),this.mediaFolderMap.set("game",t.gameFolder),this.mediaFolderMap.set("wiki",t.wikiFolder),this.mediaFolderMap.set("musicRelease",t.musicReleaseFolder),this.mediaFolderMap.set("boardgame",t.boardgameFolder),this.mediaFolderMap.set("book",t.bookFolder)}getFileName(t){return mr(this.mediaFileNameTemplateMap.get(t.getMediaType()),t)}async getTemplate(t,e){let r=this.mediaTemplateMap.get(t.getMediaType());if(!r)return"";let i=e.vault.getFiles().filter(a=>a.name===r).first();if(!i)return"";let n=await e.vault.cachedRead(i);return mr(n,t)}async getFolder(t,e){let r=this.mediaFolderMap.get(t.getMediaType());r||(r="/"),await e.vault.adapter.exists(r)||await e.vault.createFolder(r);let i=e.vault.getAbstractFileByPath(r);if(!(i instanceof Io.TFolder))throw Error(`Expected ${i} to be instance of TFolder`);return i}createMediaTypeModelFromMediaType(t,e){if(e==="movie")return new ue(t);if(e==="series")return new Ce(t);if(e==="manga")return new ct(t);if(e==="game")return new Pe(t);if(e==="wiki")return new ut(t);if(e==="musicRelease")return new mt(t);if(e==="boardgame")return new ft(t);if(e==="book")return new ht(t)}};var U={OMDbKey:"",sfwFilter:!0,useCustomYamlStringifier:!0,templates:!0,customDateFormat:"L",movieTemplate:"",seriesTemplate:"",mangaTemplate:"",gameTemplate:"",wikiTemplate:"",musicReleaseTemplate:"",boardgameTemplate:"",bookTemplate:"",movieFileNameTemplate:"{{ title }} ({{ year }})",seriesFileNameTemplate:"{{ title }} ({{ year }})",mangaFileNameTemplate:"{{ title }} ({{ year }})",gameFileNameTemplate:"{{ title }} ({{ year }})",wikiFileNameTemplate:"{{ title }}",musicReleaseFileNameTemplate:"{{ title }} (by {{ ENUM:artists }} - {{ year }})",boardgameFileNameTemplate:"{{ title }} ({{ year }})",bookFileNameTemplate:"{{ title }} ({{ year }})",moviePropertyConversionRules:"",seriesPropertyConversionRules:"",mangaPropertyConversionRules:"",gamePropertyConversionRules:"",wikiPropertyConversionRules:"",musicReleasePropertyConversionRules:"",boardgamePropertyConversionRules:"",bookPropertyConversionRules:"",movieFolder:"Media DB/movies",seriesFolder:"Media DB/series",mangaFolder:"Media DB/manga",gameFolder:"Media DB/games",wikiFolder:"Media DB/wiki",musicReleaseFolder:"Media DB/music",boardgameFolder:"Media DB/boardgames",bookFolder:"Media DB/books",propertyMappingModels:[]},sa=["type","id","dataSource"];function Lo(o){let t=U,e=[];for(let r of Fe){let n=o.mediaTypeManager.createMediaTypeModelFromMediaType({},r).toMetaDataObject(),a=new Ft(r);for(let s of Object.keys(n))a.properties.push(new dt(s,"","default",sa.contains(s)));e.push(a)}return t.propertyMappingModels=e,t}var Di=class extends P.PluginSettingTab{constructor(e,r){super(e,r);this.plugin=r}display(){let{containerEl:e}=this;e.empty(),e.createEl("h2",{text:"Media DB Plugin Settings"}),new P.Setting(e).setName("OMDb API key").setDesc('API key for "www.omdbapi.com".').addText(i=>{i.setPlaceholder("API key").setValue(this.plugin.settings.OMDbKey).onChange(n=>{this.plugin.settings.OMDbKey=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("SFW filter").setDesc("Only shows SFW results for APIs that offer filtering.").addToggle(i=>{i.setValue(this.plugin.settings.sfwFilter).onChange(n=>{this.plugin.settings.sfwFilter=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("YAML formatter").setDesc("Add optional quotation marks around strings in the metadata block.").addToggle(i=>{i.setValue(this.plugin.settings.useCustomYamlStringifier).onChange(n=>{this.plugin.settings.useCustomYamlStringifier=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Resolve {{ tags }} in templates").setDesc("Whether to resolve {{ tags }} in templates. The spaces inside the curly braces are important.").addToggle(i=>{i.setValue(this.plugin.settings.templates).onChange(n=>{this.plugin.settings.templates=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Date format").setDesc(oo("Your custom date format. Use 'YYYY-MM-DD' for example.
For more syntax, refer to format reference.
Your current syntax looks like this: "+this.plugin.dateFormatter.getPreview()+"")).addText(i=>{i.setPlaceholder(U.customDateFormat).setValue(this.plugin.settings.customDateFormat===U.customDateFormat?"":this.plugin.settings.customDateFormat).onChange(n=>{let a=n||U.customDateFormat;this.plugin.settings.customDateFormat=a,document.getElementById("media-db-dateformat-preview").textContent=this.plugin.dateFormatter.getPreview(a),this.plugin.saveSettings()})}),e.createEl("h3",{text:"New File Location"}),new P.Setting(e).setName("Movie Folder").setDesc("Where newly imported movies should be placed.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.movieFolder).setValue(this.plugin.settings.movieFolder).onChange(n=>{this.plugin.settings.movieFolder=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Series Folder").setDesc("Where newly imported series should be placed.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.seriesFolder).setValue(this.plugin.settings.seriesFolder).onChange(n=>{this.plugin.settings.seriesFolder=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Manga Folder").setDesc("Where newly imported manga should be placed.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.mangaFolder).setValue(this.plugin.settings.mangaFolder).onChange(n=>{this.plugin.settings.mangaFolder=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Game Folder").setDesc("Where newly imported games should be placed.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.gameFolder).setValue(this.plugin.settings.gameFolder).onChange(n=>{this.plugin.settings.gameFolder=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Wiki Folder").setDesc("Where newly imported wiki articles should be placed.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.wikiFolder).setValue(this.plugin.settings.wikiFolder).onChange(n=>{this.plugin.settings.wikiFolder=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Music Folder").setDesc("Where newly imported music should be placed.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.musicReleaseFolder).setValue(this.plugin.settings.musicReleaseFolder).onChange(n=>{this.plugin.settings.musicReleaseFolder=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Board Game Folder").setDesc("Where newly imported board games should be places.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.boardgameFolder).setValue(this.plugin.settings.boardgameFolder).onChange(n=>{this.plugin.settings.boardgameFolder=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Book Folder").setDesc("Where newly imported books should be placed.").addSearch(i=>{new ye(this.app,i.inputEl),i.setPlaceholder(U.bookFolder).setValue(this.plugin.settings.bookFolder).onChange(n=>{this.plugin.settings.bookFolder=n,this.plugin.saveSettings()})}),e.createEl("h3",{text:"Template Settings"}),new P.Setting(e).setName("Movie template").setDesc("Template file to be used when creating a new note for a movie.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: movieTemplate.md").setValue(this.plugin.settings.movieTemplate).onChange(n=>{this.plugin.settings.movieTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Series template").setDesc("Template file to be used when creating a new note for a series.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: seriesTemplate.md").setValue(this.plugin.settings.seriesTemplate).onChange(n=>{this.plugin.settings.seriesTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Manga template").setDesc("Template file to be used when creating a new note for a manga.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: mangaTemplate.md").setValue(this.plugin.settings.mangaTemplate).onChange(n=>{this.plugin.settings.mangaTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Game template").setDesc("Template file to be used when creating a new note for a game.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: gameTemplate.md").setValue(this.plugin.settings.gameTemplate).onChange(n=>{this.plugin.settings.gameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Wiki template").setDesc("Template file to be used when creating a new note for a wiki entry.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: wikiTemplate.md").setValue(this.plugin.settings.wikiTemplate).onChange(n=>{this.plugin.settings.wikiTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Music Release template").setDesc("Template file to be used when creating a new note for a music release.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: musicReleaseTemplate.md").setValue(this.plugin.settings.musicReleaseTemplate).onChange(n=>{this.plugin.settings.musicReleaseTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Board Game template").setDesc("Template file to be used when creating a new note for a boardgame.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: boardgameTemplate.md").setValue(this.plugin.settings.boardgameTemplate).onChange(n=>{this.plugin.settings.boardgameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Book template").setDesc("Template file to be used when creating a new note for a book.").addSearch(i=>{new Me(this.app,i.inputEl),i.setPlaceholder("Example: bookTemplate.md").setValue(this.plugin.settings.bookTemplate).onChange(n=>{this.plugin.settings.bookTemplate=n,this.plugin.saveSettings()})}),e.createEl("h3",{text:"File Name Settings"}),new P.Setting(e).setName("Movie file name template").setDesc("Template for the file name used when creating a new note for a movie.").addText(i=>{i.setPlaceholder(`Example: ${U.movieFileNameTemplate}`).setValue(this.plugin.settings.movieFileNameTemplate).onChange(n=>{this.plugin.settings.movieFileNameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Series file name template").setDesc("Template for the file name used when creating a new note for a series.").addText(i=>{i.setPlaceholder(`Example: ${U.seriesFileNameTemplate}`).setValue(this.plugin.settings.seriesFileNameTemplate).onChange(n=>{this.plugin.settings.seriesFileNameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Manga file name template").setDesc("Template for the file name used when creating a new note for a manga.").addText(i=>{i.setPlaceholder(`Example: ${U.mangaFileNameTemplate}`).setValue(this.plugin.settings.mangaFileNameTemplate).onChange(n=>{this.plugin.settings.mangaFileNameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Game file name template").setDesc("Template for the file name used when creating a new note for a game.").addText(i=>{i.setPlaceholder(`Example: ${U.gameFileNameTemplate}`).setValue(this.plugin.settings.gameFileNameTemplate).onChange(n=>{this.plugin.settings.gameFileNameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Wiki file name template").setDesc("Template for the file name used when creating a new note for a wiki entry.").addText(i=>{i.setPlaceholder(`Example: ${U.wikiFileNameTemplate}`).setValue(this.plugin.settings.wikiFileNameTemplate).onChange(n=>{this.plugin.settings.wikiFileNameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Music Release file name template").setDesc("Template for the file name used when creating a new note for a music release.").addText(i=>{i.setPlaceholder(`Example: ${U.musicReleaseFileNameTemplate}`).setValue(this.plugin.settings.musicReleaseFileNameTemplate).onChange(n=>{this.plugin.settings.musicReleaseFileNameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Board Game file name template").setDesc("Template for the file name used when creating a new note for a boardgame.").addText(i=>{i.setPlaceholder(`Example: ${U.boardgameFileNameTemplate}`).setValue(this.plugin.settings.boardgameFileNameTemplate).onChange(n=>{this.plugin.settings.boardgameFileNameTemplate=n,this.plugin.saveSettings()})}),new P.Setting(e).setName("Book file name template").setDesc("Template for the file name used when creating a new note for a book.").addText(i=>{i.setPlaceholder(`Example: ${U.bookFileNameTemplate}`).setValue(this.plugin.settings.bookFileNameTemplate).onChange(n=>{this.plugin.settings.bookFileNameTemplate=n,this.plugin.saveSettings()})}),e.createEl("h3",{text:"Property Mappings"});let r=e.createEl("div");r.innerHTML=`

Allow you to remap the metadata fields of newly created media db entries.

The different options are:

  • "default": does no remapping and keeps the metadata field as it is
  • "remap": renames the metadata field to what ever you specify
  • "remove": removes the metadata field entirely
  • Don't forget to save your changes using the save button for each individual category.

    `,new Bo({target:this.containerEl,props:{models:this.plugin.settings.propertyMappingModels.map(i=>i.copy()),save:i=>{let n=[];for(let a of this.plugin.settings.propertyMappingModels)a.type===i.type?n.push(i):n.push(a);this.plugin.settings.propertyMappingModels=n,new P.Notice(`MDB: Property Mappings for ${i.type} saved successfully.`),this.plugin.saveSettings()}}})}};var Ei=class{constructor(){this.apis=[]}async query(t,e){console.debug(`MDB | api manager queried with "${t}"`);let r=[];for(let i of this.apis)if(e.contains(i.apiName)){let n=await i.searchByTitle(t);r=r.concat(n)}return r}async queryDetailedInfo(t){return await this.queryDetailedInfoById(t.id,t.dataSource)}async queryDetailedInfoById(t,e){for(let r of this.apis)if(r.apiName===e)return r.getById(t)}getApiByName(t){for(let e of this.apis)if(e.apiName===t)return e;return null}registerAPI(t){this.apis.push(t)}};var J=class{hasType(t){return this.types.contains(t)}hasTypeOverlap(t){for(let e of t)if(this.hasType(e))return!0;return!1}};var Ci=class extends J{constructor(e){super();this.apiDateFormat="DD MMM YYYY";this.plugin=e,this.apiName="OMDbAPI",this.apiDescription="A free API for Movies, Series and Games.",this.apiUrl="http://www.omdbapi.com/",this.types=["movie","series","game"],this.typeMappings=new Map,this.typeMappings.set("movie","movie"),this.typeMappings.set("series","series"),this.typeMappings.set("game","game")}async searchByTitle(e){console.log(`MDB | api "${this.apiName}" queried by Title`);let r=`http://www.omdbapi.com/?s=${encodeURIComponent(e)}&apikey=${this.plugin.settings.OMDbKey}`,i=await fetch(r);if(i.status===401)throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();if(n.Response==="False"){if(n.Error==="Movie not found!")return[];throw Error(`MDB | Received error from ${this.apiName}: ${JSON.stringify(n,void 0,4)}`)}if(!n.Search)return[];console.debug(n.Search);let a=[];for(let s of n.Search){let l=this.typeMappings.get(s.Type.toLowerCase());l!==void 0&&(l==="movie"?a.push(new ue({type:l,title:s.Title,englishTitle:s.Title,year:s.Year,dataSource:this.apiName,id:s.imdbID})):l==="series"?a.push(new Ce({type:l,title:s.Title,englishTitle:s.Title,year:s.Year,dataSource:this.apiName,id:s.imdbID})):l==="game"&&a.push(new Pe({type:l,title:s.Title,englishTitle:s.Title,year:s.Year,dataSource:this.apiName,id:s.imdbID})))}return a}async getById(e){var s,l,p,d,c,u,m,M,g,f,T,w,D,h,y,b,_,x,E,v,C,S,F,k,te,N,I,Te,le;console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`http://www.omdbapi.com/?i=${encodeURIComponent(e)}&apikey=${this.plugin.settings.OMDbKey}`,i=await fetch(r);if(i.status===401)throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();if(n.Response==="False")throw Error(`MDB | Received error from ${this.apiName}: ${n.Error}`);let a=this.typeMappings.get(n.Type.toLowerCase());if(a===void 0)throw Error(`${n.type.toLowerCase()} is an unsupported type.`);if(a==="movie")return new ue({type:a,title:n.Title,englishTitle:n.Title,year:n.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${n.imdbID}/`,id:n.imdbID,plot:(s=n.Plot)!=null?s:"",genres:(p=(l=n.Genre)==null?void 0:l.split(", "))!=null?p:[],director:(c=(d=n.Director)==null?void 0:d.split(", "))!=null?c:[],writer:(m=(u=n.Writer)==null?void 0:u.split(", "))!=null?m:[],studio:["N/A"],duration:(M=n.Runtime)!=null?M:"unknown",onlineRating:Number.parseFloat((g=n.imdbRating)!=null?g:0),actors:(T=(f=n.Actors)==null?void 0:f.split(", "))!=null?T:[],image:(w=n.Poster)!=null?w:"",released:!0,streamingServices:[],premiere:(D=this.plugin.dateFormatter.format(n.Released,this.apiDateFormat))!=null?D:"unknown",userData:{watched:!1,lastWatched:"",personalRating:0}});if(a==="series")return new Ce({type:a,title:n.Title,englishTitle:n.Title,year:n.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${n.imdbID}/`,id:n.imdbID,plot:(h=n.Plot)!=null?h:"",genres:(b=(y=n.Genre)==null?void 0:y.split(", "))!=null?b:[],writer:(x=(_=n.Writer)==null?void 0:_.split(", "))!=null?x:[],studio:[],episodes:0,duration:(E=n.Runtime)!=null?E:"unknown",onlineRating:Number.parseFloat((v=n.imdbRating)!=null?v:0),actors:(S=(C=n.Actors)==null?void 0:C.split(", "))!=null?S:[],image:(F=n.Poster)!=null?F:"",released:!0,streamingServices:[],airing:!1,airedFrom:(k=this.plugin.dateFormatter.format(n.Released,this.apiDateFormat))!=null?k:"unknown",airedTo:"unknown",userData:{watched:!1,lastWatched:"",personalRating:0}});if(a==="game")return new Pe({type:a,title:n.Title,englishTitle:n.Title,year:n.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${n.imdbID}/`,id:n.imdbID,genres:(N=(te=n.Genre)==null?void 0:te.split(", "))!=null?N:[],onlineRating:Number.parseFloat((I=n.imdbRating)!=null?I:0),image:(Te=n.Poster)!=null?Te:"",released:!0,releaseDate:(le=this.plugin.dateFormatter.format(n.Released,this.apiDateFormat))!=null?le:"unknown",userData:{played:!1,personalRating:0}})}};var Pi=class extends J{constructor(e){super();this.apiDateFormat="YYYY-MM-DDTHH:mm:ssZ";this.plugin=e,this.apiName="MALAPI",this.apiDescription="A free API for Anime. Some results may take a long time to load.",this.apiUrl="https://jikan.moe/",this.types=["movie","series"],this.typeMappings=new Map,this.typeMappings.set("movie","movie"),this.typeMappings.set("special","special"),this.typeMappings.set("tv","series"),this.typeMappings.set("ova","ova")}async searchByTitle(e){var s,l,p,d,c,u,m,M,g,f,T,w,D,h,y,b,_,x,E;console.log(`MDB | api "${this.apiName}" queried by Title`);let r=`https://api.jikan.moe/v4/anime?q=${encodeURIComponent(e)}&limit=20${this.plugin.settings.sfwFilter?"&sfw":""}`,i=await fetch(r);if(console.debug(i),i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=[];for(let v of n.data){let C=this.typeMappings.get((s=v.type)==null?void 0:s.toLowerCase());C===void 0&&a.push(new ue({subType:"",title:v.title,englishTitle:(l=v.title_english)!=null?l:v.title,year:(m=(u=v.year)!=null?u:(c=(d=(p=v.aired)==null?void 0:p.prop)==null?void 0:d.from)==null?void 0:c.year)!=null?m:"",dataSource:this.apiName,id:v.mal_id})),C==="movie"||C==="special"?a.push(new ue({subType:C,title:v.title,englishTitle:(M=v.title_english)!=null?M:v.title,year:(D=(w=v.year)!=null?w:(T=(f=(g=v.aired)==null?void 0:g.prop)==null?void 0:f.from)==null?void 0:T.year)!=null?D:"",dataSource:this.apiName,id:v.mal_id})):(C==="series"||C==="ova")&&a.push(new Ce({subType:C,title:v.title,englishTitle:(h=v.title_english)!=null?h:v.title,year:(E=(x=v.year)!=null?x:(_=(b=(y=v.aired)==null?void 0:y.prop)==null?void 0:b.from)==null?void 0:_.year)!=null?E:"",dataSource:this.apiName,id:v.mal_id}))}return a}async getById(e){var l,p,d,c,u,m,M,g,f,T,w,D,h,y,b,_,x,E,v,C,S,F,k,te,N,I,Te,le,_e,gt,Le,Ye,$e,me,je,Ge,Se,yt,ti,Mt,ii,$t,ri,oi,Rt,Ot,ni,ai,De,ze,At,Nt,bt,Bt,It,Lt,jt,Pr,Fr,kr;console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`https://api.jikan.moe/v4/anime/${encodeURIComponent(e)}/full`,i=await fetch(r);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=n.data,s=this.typeMappings.get((l=a.type)==null?void 0:l.toLowerCase());if(s===void 0)return new ue({subType:"",title:a.title,englishTitle:(p=a.title_english)!=null?p:a.title,year:(M=(m=a.year)!=null?m:(u=(c=(d=a.aired)==null?void 0:d.prop)==null?void 0:c.from)==null?void 0:u.year)!=null?M:"",dataSource:this.apiName,url:a.url,id:a.mal_id,plot:a.synopsis,genres:(f=(g=a.genres)==null?void 0:g.map(Q=>Q.name))!=null?f:[],director:[],writer:[],studio:(w=(T=a.studios)==null?void 0:T.map(Q=>Q.name).join(", "))!=null?w:"unknown",duration:(D=a.duration)!=null?D:"unknown",onlineRating:(h=a.score)!=null?h:0,actors:[],image:(_=(b=(y=a.images)==null?void 0:y.jpg)==null?void 0:b.image_url)!=null?_:"",released:!0,premiere:(E=this.plugin.dateFormatter.format((x=a.aired)==null?void 0:x.from,this.apiDateFormat))!=null?E:"unknown",streamingServices:(C=(v=a.streaming)==null?void 0:v.map(Q=>Q.name))!=null?C:[],userData:{watched:!1,lastWatched:"",personalRating:0}});if(s==="movie"||s==="special")return new ue({subType:s,title:a.title,englishTitle:(S=a.title_english)!=null?S:a.title,year:(I=(N=a.year)!=null?N:(te=(k=(F=a.aired)==null?void 0:F.prop)==null?void 0:k.from)==null?void 0:te.year)!=null?I:"",dataSource:this.apiName,url:a.url,id:a.mal_id,plot:a.synopsis,genres:(le=(Te=a.genres)==null?void 0:Te.map(Q=>Q.name))!=null?le:[],director:[],writer:[],studio:(gt=(_e=a.studios)==null?void 0:_e.map(Q=>Q.name).join(", "))!=null?gt:"unknown",duration:(Le=a.duration)!=null?Le:"unknown",onlineRating:(Ye=a.score)!=null?Ye:0,actors:[],image:(je=(me=($e=a.images)==null?void 0:$e.jpg)==null?void 0:me.image_url)!=null?je:"",released:!0,premiere:(Se=this.plugin.dateFormatter.format((Ge=a.aired)==null?void 0:Ge.from,this.apiDateFormat))!=null?Se:"unknown",streamingServices:(ti=(yt=a.streaming)==null?void 0:yt.map(Q=>Q.name))!=null?ti:[],userData:{watched:!1,lastWatched:"",personalRating:0}});if(s==="series"||s==="ova")return new Ce({subType:s,title:a.title,englishTitle:(Mt=a.title_english)!=null?Mt:a.title,year:(Rt=(oi=a.year)!=null?oi:(ri=($t=(ii=a.aired)==null?void 0:ii.prop)==null?void 0:$t.from)==null?void 0:ri.year)!=null?Rt:"",dataSource:this.apiName,url:a.url,id:a.mal_id,genres:(ni=(Ot=a.genres)==null?void 0:Ot.map(Q=>Q.name))!=null?ni:[],writer:[],studio:(De=(ai=a.studios)==null?void 0:ai.map(Q=>Q.name))!=null?De:[],episodes:a.episodes,duration:(ze=a.duration)!=null?ze:"unknown",onlineRating:(At=a.score)!=null?At:0,streamingServices:(bt=(Nt=a.streaming)==null?void 0:Nt.map(Q=>Q.name))!=null?bt:[],image:(Lt=(It=(Bt=a.images)==null?void 0:Bt.jpg)==null?void 0:It.image_url)!=null?Lt:"",released:!0,airedFrom:(Pr=this.plugin.dateFormatter.format((jt=a.aired)==null?void 0:jt.from,this.apiDateFormat))!=null?Pr:"unknown",airedTo:(kr=this.plugin.dateFormatter.format((Fr=a.aired)==null?void 0:Fr.to,this.apiDateFormat))!=null?kr:"unknown",airing:a.airing,userData:{watched:!1,lastWatched:"",personalRating:0}})}};var Fi=class extends J{constructor(e){super();this.plugin=e,this.apiName="MALAPI Manga",this.apiDescription="A free API for Manga. Some results may take a long time to load.",this.apiUrl="https://jikan.moe/",this.types=["manga"],this.typeMappings=new Map,this.typeMappings.set("manga","manga"),this.typeMappings.set("manhwa","manhwa"),this.typeMappings.set("doujinshi","doujin"),this.typeMappings.set("one-shot","oneshot"),this.typeMappings.set("manhua","manhua"),this.typeMappings.set("light novel","light-novel"),this.typeMappings.set("novel","novel")}async searchByTitle(e){var s,l,p,d,c,u,m,M,g,f,T,w,D,h,y,b,_,x,E,v,C;console.log(`MDB | api "${this.apiName}" queried by Title`);let r=`https://api.jikan.moe/v4/manga?q=${encodeURIComponent(e)}&limit=20${this.plugin.settings.sfwFilter?"&sfw":""}`,i=await fetch(r);if(console.debug(i),i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=[];for(let S of n.data){let F=this.typeMappings.get((s=S.type)==null?void 0:s.toLowerCase());a.push(new ct({subType:F,title:S.title,plot:S.synopsis,englishTitle:(l=S.title_english)!=null?l:S.title,alternateTitles:(d=(p=S.titles)==null?void 0:p.map(k=>k.title))!=null?d:[],year:(g=(M=S.year)!=null?M:(m=(u=(c=S.published)==null?void 0:c.prop)==null?void 0:u.from)==null?void 0:m.year)!=null?g:"",dataSource:this.apiName,url:S.url,id:S.mal_id,genres:(T=(f=S.genres)==null?void 0:f.map(k=>k.name))!=null?T:[],authors:(D=(w=S.authors)==null?void 0:w.map(k=>k.name))!=null?D:[],chapters:S.chapters,volumes:S.volumes,onlineRating:(h=S.score)!=null?h:0,image:(_=(b=(y=S.images)==null?void 0:y.jpg)==null?void 0:b.image_url)!=null?_:"",released:!0,publishedFrom:(E=new Date((x=S.published)==null?void 0:x.from).toLocaleDateString())!=null?E:"unknown",publishedTo:(C=new Date((v=S.published)==null?void 0:v.to).toLocaleDateString())!=null?C:"unknown",status:S.status,userData:{watched:!1,lastWatched:"",personalRating:0}}))}return a}async getById(e){var p,d,c,u,m,M,g,f,T,w,D,h,y,b,_,x,E,v,C,S,F;console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`https://api.jikan.moe/v4/manga/${encodeURIComponent(e)}/full`,i=await fetch(r);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=n.data,s=this.typeMappings.get((p=a.type)==null?void 0:p.toLowerCase());return new ct({subType:s,title:a.title,englishTitle:(d=a.title_english)!=null?d:a.title,alternateTitles:(u=(c=a.titles)==null?void 0:c.map(k=>k.title))!=null?u:[],year:(T=(f=a.year)!=null?f:(g=(M=(m=a.published)==null?void 0:m.prop)==null?void 0:M.from)==null?void 0:g.year)!=null?T:"",dataSource:this.apiName,url:a.url,id:a.mal_id,plot:a.synopsis,genres:(D=(w=a.genres)==null?void 0:w.map(k=>k.name))!=null?D:[],authors:(y=(h=a.authors)==null?void 0:h.map(k=>k.name))!=null?y:[],chapters:a.chapters,volumes:a.volumes,onlineRating:(b=a.score)!=null?b:0,image:(E=(x=(_=a.images)==null?void 0:_.jpg)==null?void 0:x.image_url)!=null?E:"",released:!0,publishedFrom:(C=new Date((v=a.published)==null?void 0:v.from).toLocaleDateString())!=null?C:"unknown",publishedTo:(F=new Date((S=a.published)==null?void 0:S.to).toLocaleDateString())!=null?F:"unknown",status:a.status,userData:{watched:!1,lastWatched:"",personalRating:0}})}};var ki=class extends J{constructor(e){super();this.apiDateFormat="YYYY-MM-DDTHH:mm:ssZ";this.plugin=e,this.apiName="Wikipedia API",this.apiDescription="The API behind Wikipedia",this.apiUrl="https://www.wikipedia.com",this.types=["wiki"]}async searchByTitle(e){console.log(`MDB | api "${this.apiName}" queried by Title`);let r=`https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(e)}&srlimit=20&utf8=&format=json&origin=*`,i=await fetch(r);if(console.debug(i),i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=[];for(let s of n.query.search)a.push(new ut({type:"wiki",title:s.title,englishTitle:s.title,year:"",dataSource:this.apiName,id:s.pageid}));return a}async getById(e){var l;console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`https://en.wikipedia.org/w/api.php?action=query&prop=info&pageids=${encodeURIComponent(e)}&inprop=url&format=json&origin=*`,i=await fetch(r);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=Object.entries((l=n==null?void 0:n.query)==null?void 0:l.pages)[0][1];return new ut({type:"wiki",title:a.title,englishTitle:a.title,year:"",dataSource:this.apiName,url:a.fullurl,id:a.pageid,wikiUrl:a.fullurl,lastUpdated:this.plugin.dateFormatter.format(a.touched,this.apiDateFormat),length:a.length,userData:{}})}};var Dr=require("obsidian");var $i=class extends J{constructor(e){super();this.plugin=e,this.apiName="MusicBrainz API",this.apiDescription="Free API for music albums.",this.apiUrl="https://musicbrainz.org/",this.types=["musicRelease"]}async searchByTitle(e){console.log(`MDB | api "${this.apiName}" queried by Title`);let r=`https://musicbrainz.org/ws/2/release-group?query=${encodeURIComponent(e)}&limit=20&fmt=json`,i=await(0,Dr.requestUrl)({url:r,headers:{"User-Agent":`${pr}/${cr} (${dr})`}});if(console.debug(i),i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json;console.debug(n);let a=[];for(let s of n["release-groups"])a.push(new mt({type:"musicRelease",title:s.title,englishTitle:s.title,year:new Date(s["first-release-date"]).getFullYear().toString(),dataSource:this.apiName,url:"https://musicbrainz.org/release-group/"+s.id,id:s.id,image:"https://coverartarchive.org/release-group/"+s.id+"/front",artists:s["artist-credit"].map(l=>l.name),subType:s["primary-type"]}));return a}async getById(e){console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`https://musicbrainz.org/ws/2/release-group/${encodeURIComponent(e)}?inc=releases+artists+tags+ratings+genres&fmt=json`,i=await(0,Dr.requestUrl)({url:r,headers:{"User-Agent":`${pr}/${cr} (${dr})`}});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json;console.debug(n);let a=n;return new mt({type:"musicRelease",title:a.title,englishTitle:a.title,year:new Date(a["first-release-date"]).getFullYear().toString(),dataSource:this.apiName,url:"https://musicbrainz.org/release-group/"+a.id,id:a.id,image:"https://coverartarchive.org/release-group/"+a.id+"/front",artists:a["artist-credit"].map(l=>l.name),genres:a.genres.map(l=>l.name),subType:a["primary-type"],rating:a.rating.value*2,userData:{personalRating:0}})}};var Er=require("obsidian");var Ri=class extends J{constructor(e){super();this.apiDateFormat="DD MMM, YYYY";this.plugin=e,this.apiName="SteamAPI",this.apiDescription="A free API for all Steam games.",this.apiUrl="http://www.steampowered.com/",this.types=["game"],this.typeMappings=new Map,this.typeMappings.set("game","game")}async searchByTitle(e){console.log(`MDB | api "${this.apiName}" queried by Title`);let i=await(0,Er.requestUrl)({url:"http://api.steampowered.com/ISteamApps/GetAppList/v0002/?format=json"});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json;console.debug(n);let a=[];for(let l of n.applist.apps)if(l.name.toLowerCase().includes(e.toLowerCase())&&a.push(l),a.length>20)break;let s=[];for(let l of a)s.push(new Pe({type:"game",title:l.name,englishTitle:l.name,year:"",dataSource:this.apiName,id:l.appid}));return s}async getById(e){var s,l,p,d,c,u,m,M;console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`http://store.steampowered.com/api/appdetails?appids=${encodeURIComponent(e)}&l=en`,i=await(0,Er.requestUrl)({url:r});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);console.debug(await i.json);let n;for(let[g,f]of Object.entries(await i.json))g===String(e)&&(n=f.data);if(!n)throw Error("MDB | API returned invalid data.");return console.debug(n),new Pe({type:"game",title:n.name,englishTitle:n.name,year:new Date(n.release_date.date).getFullYear().toString(),dataSource:this.apiName,url:`https://store.steampowered.com/app/${n.steam_appid}`,id:n.steam_appid,genres:(l=(s=n.genres)==null?void 0:s.map(g=>g.description))!=null?l:[],onlineRating:Number.parseFloat((d=(p=n.metacritic)==null?void 0:p.score)!=null?d:0),image:(c=n.header_image)!=null?c:"",released:!((u=n.release_date)!=null&&u.comming_soon),releaseDate:(M=this.plugin.dateFormatter.format((m=n.release_date)==null?void 0:m.date,this.apiDateFormat))!=null?M:"unknown",userData:{played:!1,personalRating:0}})}};var Cr=require("obsidian");var Oi=class extends J{constructor(e){super();this.plugin=e,this.apiName="BoardGameGeekAPI",this.apiDescription="A free API for BoardGameGeek things.",this.apiUrl="https://api.geekdo.com/xmlapi",this.types=["boardgame"]}async searchByTitle(e){var l,p,d,c;console.log(`MDB | api "${this.apiName}" queried by Title`);let r=`${this.apiUrl}/search?search=${encodeURIComponent(e)}`,i=await(0,Cr.requestUrl)({url:r});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=i.text,a=new window.DOMParser().parseFromString(n,"text/xml");console.debug(a);let s=[];for(let u of Array.from(a.querySelectorAll("boardgame"))){let m=u.attributes.getNamedItem("objectid").value,M=(p=(l=u.querySelector("name[primary=true]"))==null?void 0:l.textContent)!=null?p:u.querySelector("name").textContent,g=(c=(d=u.querySelector("yearpublished"))==null?void 0:d.textContent)!=null?c:"";s.push(new ft({dataSource:this.apiName,id:m,title:M,englishTitle:M,year:g}))}return s}async getById(e){var D,h,y,b,_,x,E,v,C,S,F,k,te,N;console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`${this.apiUrl}/boardgame/${encodeURIComponent(e)}?stats=1`,i=await(0,Cr.requestUrl)({url:r});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=i.text,a=new window.DOMParser().parseFromString(n,"text/xml");console.debug(a);let s=a.querySelector("boardgame"),l=s.querySelector("name[primary=true]").textContent,p=(h=(D=s.querySelector("yearpublished"))==null?void 0:D.textContent)!=null?h:"",d=(b=(y=s.querySelector("image"))==null?void 0:y.textContent)!=null?b:void 0,c=Number.parseFloat((x=(_=s.querySelector("statistics ratings average"))==null?void 0:_.textContent)!=null?x:"0"),u=Array.from(s.querySelectorAll("boardgamecategory")).map(I=>I.textContent),m=Number.parseFloat((v=(E=s.querySelector("averageweight"))==null?void 0:E.textContent)!=null?v:"0"),M=Number.parseFloat((S=(C=s.querySelector("minplayers"))==null?void 0:C.textContent)!=null?S:"0"),g=Number.parseFloat((k=(F=s.querySelector("maxplayers"))==null?void 0:F.textContent)!=null?k:"0"),f=((N=(te=s.querySelector("playingtime"))==null?void 0:te.textContent)!=null?N:"unknown")+" minutes",T=Array.from(s.querySelectorAll("boardgamepublisher")).map(I=>I.textContent);return new ft({title:l,englishTitle:l,year:p==="0"?"":p,dataSource:this.apiName,url:`https://boardgamegeek.com/boardgame/${e}`,id:e,genres:u,onlineRating:c,complexityRating:m,minPlayers:M,maxPlayers:g,playtime:f,publishers:T,image:d,released:!0,userData:{played:!1,personalRating:0}})}};var Ai=class extends J{constructor(e){super();this.plugin=e,this.apiName="OpenLibraryAPI",this.apiDescription="A free API for books",this.apiUrl="https://openlibrary.org/",this.types=["book"]}async searchByTitle(e){var s;console.log(`MDB | api "${this.apiName}" queried by Title`);let r=`https://openlibrary.org/search.json?title=${encodeURIComponent(e)}`,i=await fetch(r);if(console.debug(i),i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=[];for(let l of n.docs)a.push(new ht({title:l.title,englishTitle:(s=l.title_english)!=null?s:l.title,year:l.first_publish_year,dataSource:this.apiName,id:l.key}));return a}async getById(e){var l,p,d,c,u;console.log(`MDB | api "${this.apiName}" queried by ID`);let r=`https://openlibrary.org/search.json?q=key:${encodeURIComponent(e)}`,i=await fetch(r);if(console.debug(i),i.status!==200)throw Error(`MDB | Received status code ${i.status} from an API.`);let n=await i.json();console.debug(n);let a=n.docs[0];return new ht({title:a.title,year:a.first_publish_year,dataSource:this.apiName,url:"https://openlibrary.org"+a.key,id:a.key,englishTitle:(l=a.title_english)!=null?l:a.title,author:(p=a.author_name)!=null?p:"unknown",plot:(d=a.description)!=null?d:"unknown",pages:(c=a.number_of_pages_median)!=null?c:"unknown",onlineRating:Number.parseFloat(Number((u=a.ratings_average)!=null?u:0).toFixed(2)),image:"https://covers.openlibrary.org/b/OLID/"+a.cover_edition_key+"-L.jpg",released:!0,userData:{read:!1,lastRead:"",personalRating:0}})}};var Ni=class{constructor(t){this.plugin=t}convertObject(t){if(!t.hasOwnProperty("type")||Fe.filter(i=>i.toString()==t.type).length<1)return t;let e=this.plugin.settings.propertyMappingModels.find(i=>i.type===t.type).properties,r={};for(let[i,n]of Object.entries(t))for(let a of e)if(a.property===i){a.mapping==="remap"?r[a.newProperty]=n:a.mapping==="remove"||a.mapping==="default"&&(r[i]=n);break}return r}convertObjectBack(t){if(!t.hasOwnProperty("type")||Fe.contains(t.type))return t;let e=this.plugin.settings.propertyMappingModels.find(i=>i.type===t.type).properties,r={};e:for(let[i,n]of Object.entries(t)){for(let a of e)if(a.property===i){r[i]=n;continue e}for(let a of e)if(a.newProperty===i){r[a.property]=n;continue e}}return r}};var ei=class o{static toYaml(t){let e="";for(let[r,i]of Object.entries(t))e+=`${r}: ${o.toYamlString(i,0)} `;return e}static toYamlString(t,e){if(t==null)return"null";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="number")return t.toString();if(typeof t=="string")return'"'+t.replace('"','\\"')+'"';if(typeof t=="object"){let r="";if(Array.isArray(t))for(let i of t)r+=` ${o.calculateSpacing(e)} - ${o.toYamlString(i,e+1)}`;else for(let[i,n]of Object.entries(t))r+=` ${o.calculateSpacing(e)} ${i}: ${o.toYamlString(n,e+1)}`;return r}}static calculateSpacing(t){return" ".repeat(t*4)}};var ke=require("obsidian"),Bi=class extends ke.Modal{constructor(e,r,i){super(e);this.plugin=r,this.onSubmit=i,this.selectedApi=r.apiManager.apis[0].apiName}submit(){this.onSubmit(this.selectedApi,this.titleFieldName,this.appendContent),this.close()}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:"Import folder as Media DB entries"});let r=e.createEl("div",{cls:"media-db-plugin-list-wrapper"});r.createEl("div",{cls:"media-db-plugin-list-text-wrapper"}).createEl("span",{text:"API to search",cls:"media-db-plugin-list-text"});let n=new ke.DropdownComponent(r);n.onChange(u=>{this.selectedApi=u});for(let u of this.plugin.apiManager.apis)n.addOption(u.apiName,u.apiName);r.appendChild(n.selectEl),e.createDiv({cls:"media-db-plugin-spacer"}),e.createEl("h3",{text:"Append note content to Media DB entry."});let a=e.createEl("div",{cls:"media-db-plugin-list-wrapper"});a.createEl("div",{cls:"media-db-plugin-list-text-wrapper"}).createEl("span",{text:"If this is enabled, the plugin will override metadata fields with the same name.",cls:"media-db-plugin-list-text"});let l=a.createEl("div",{cls:"media-db-plugin-list-toggle"}),p=new ke.ToggleComponent(a);p.setValue(!1),p.onChange(u=>this.appendContent=u),l.appendChild(p.toggleEl),e.createDiv({cls:"media-db-plugin-spacer"}),e.createEl("h3",{text:"The name of the metadata field that should be used as the title to query."});let d="title",c=new ke.TextComponent(e);c.inputEl.style.width="100%",c.setPlaceholder(d),c.onChange(u=>this.titleFieldName=u),c.inputEl.addEventListener("keydown",u=>{u.key==="Enter"&&this.submit()}),e.appendChild(c.inputEl),e.createDiv({cls:"media-db-plugin-spacer"}),new ke.Setting(e).addButton(u=>{u.setButtonText("Cancel"),u.onClick(()=>this.close()),u.buttonEl.addClass("media-db-plugin-button")}).addButton(u=>{u.setButtonText("Ok"),u.setCta(),u.onClick(()=>{this.submit()}),u.buttonEl.addClass("media-db-plugin-button"),this.searchBtn=u})}onClose(){let{contentEl:e}=this;e.empty()}};var be=require("obsidian");var Ii=class extends be.Modal{constructor(e,r){r=Object.assign({},jo,r);super(e.app);this.plugin=e,this.selectedApis=[],this.title=r.modalTitle,this.query=r.prefilledSearchString;for(let i of this.plugin.apiManager.apis)this.selectedApis.push({name:i.apiName,selected:r.preselectedAPIs.contains(i.apiName)})}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}keyPressCallback(e){e.key==="Enter"&&this.search()}async search(){if(!this.query||this.query.length<3){new be.Notice("MDB | Query too short");return}let e=this.selectedApis.filter(r=>r.selected).map(r=>r.name);if(e.length===0){new be.Notice("MDB | No API selected");return}this.isBusy||(this.isBusy=!0,this.searchBtn.setDisabled(!1),this.searchBtn.setButtonText("Searching..."),this.submitCallback({query:this.query,apis:e}))}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:this.title});let r="Search by title",i=new be.TextComponent(e);i.inputEl.style.width="100%",i.setPlaceholder(r),i.setValue(this.query),i.onChange(n=>this.query=n),i.inputEl.addEventListener("keydown",this.keyPressCallback.bind(this)),e.appendChild(i.inputEl),i.inputEl.focus(),e.createDiv({cls:"media-db-plugin-spacer"}),e.createEl("h3",{text:"APIs to search"});for(let n of this.plugin.apiManager.apis){let a=e.createEl("div",{cls:"media-db-plugin-list-wrapper"}),s=a.createEl("div",{cls:"media-db-plugin-list-text-wrapper"});s.createEl("span",{text:n.apiName,cls:"media-db-plugin-list-text"}),s.createEl("small",{text:n.apiDescription,cls:"media-db-plugin-list-text"});let l=a.createEl("div",{cls:"media-db-plugin-list-toggle"}),p=new be.ToggleComponent(l);p.setTooltip(n.apiName),p.setValue(this.selectedApis.find(d=>d.name===n.apiName).selected),p.onChange(d=>{this.selectedApis.find(c=>c.name===n.apiName).selected=d}),l.appendChild(p.toggleEl)}e.createDiv({cls:"media-db-plugin-spacer"}),new be.Setting(e).addButton(n=>{n.setButtonText("Cancel"),n.onClick(()=>this.close()),n.buttonEl.addClass("media-db-plugin-button")}).addButton(n=>{n.setButtonText("Ok"),n.setCta(),n.onClick(()=>{this.search()}),n.buttonEl.addClass("media-db-plugin-button"),this.searchBtn=n})}onClose(){this.closeCallback();let{contentEl:e}=this;e.empty()}};var ve=require("obsidian");var Li=class extends ve.Modal{constructor(e,r){r=Object.assign({},Wo,r);super(e.app);this.plugin=e,this.title=r.modalTitle,this.selectedApi=r.preselectedAPI||e.apiManager.apis[0].apiName}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}keyPressCallback(e){e.key==="Enter"&&this.search()}async search(){if(!this.query){new ve.Notice("MDB | no Id entered");return}if(!this.selectedApi){new ve.Notice("MDB | No API selected");return}this.isBusy||(this.isBusy=!0,this.searchBtn.setDisabled(!1),this.searchBtn.setButtonText("Searching..."),this.submitCallback({query:this.query,api:this.selectedApi}))}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:this.title});let r="Search by id",i=new ve.TextComponent(e);i.inputEl.style.width="100%",i.setPlaceholder(r),i.onChange(l=>this.query=l),i.inputEl.addEventListener("keydown",this.keyPressCallback.bind(this)),e.appendChild(i.inputEl),i.inputEl.focus(),e.createDiv({cls:"media-db-plugin-spacer"});let n=e.createEl("div",{cls:"media-db-plugin-list-wrapper"});n.createEl("div",{cls:"media-db-plugin-list-text-wrapper"}).createEl("span",{text:"API to search",cls:"media-db-plugin-list-text"});let s=new ve.DropdownComponent(n);s.onChange(l=>{this.selectedApi=l});for(let l of this.plugin.apiManager.apis)s.addOption(l.apiName,l.apiName);n.appendChild(s.selectEl),e.createDiv({cls:"media-db-plugin-spacer"}),new ve.Setting(e).addButton(l=>{l.setButtonText("Cancel"),l.onClick(()=>this.close()),l.buttonEl.addClass("media-db-plugin-button")}).addButton(l=>{l.setButtonText("Ok"),l.setCta(),l.onClick(()=>{this.search()}),l.buttonEl.addClass("media-db-plugin-button"),this.searchBtn=l})}onClose(){this.closeCallback();let{contentEl:e}=this;e.empty()}};var qi=require("obsidian");var ji=class{constructor(t,e,r,i,n=!1){this.value=t,this.id=r,this.active=n,this.selectModal=i,this.cssClass="media-db-plugin-select-element",this.activeClass="media-db-plugin-select-element-selected",this.hoverClass="media-db-plugin-select-element-hover",this.element=e.createDiv({cls:this.cssClass}),this.element.id=this.getHTMLId(),this.element.on("click","#"+this.getHTMLId(),()=>{this.setActive(!this.active),this.selectModal.allowMultiSelect||this.selectModal.disableAllOtherElements(this.id)}),this.element.on("mouseenter","#"+this.getHTMLId(),()=>{this.setHighlighted(!0)}),this.element.on("mouseleave","#"+this.getHTMLId(),()=>{this.setHighlighted(!1)})}getHTMLId(){return`media-db-plugin-select-element-${this.id}`}isHighlighted(){return this.highlighted}setHighlighted(t){this.highlighted=t,this.highlighted?(this.addClass(this.hoverClass),this.selectModal.deHighlightAllOtherElements(this.id)):this.removeClass(this.hoverClass)}isActive(){return this.active}setActive(t){this.active=t,this.update()}update(){this.active?this.addClass(this.activeClass):this.removeClass(this.activeClass)}addClass(t){this.element.hasClass(t)||this.element.addClass(t)}removeClass(t){this.element.hasClass(t)&&this.element.removeClass(t)}};var Wi=class extends qi.Modal{constructor(e,r,i=!0){super(e);this.allowMultiSelect=i,this.title="",this.description="",this.addSkipButton=!1,this.cancelButton=void 0,this.skipButton=void 0,this.submitButton=void 0,this.elementWrapper=void 0,this.elements=r,this.selectModalElements=[],this.scope.register([],"ArrowUp",n=>{this.highlightUp(),n.preventDefault()}),this.scope.register([],"ArrowDown",n=>{this.highlightDown(),n.preventDefault()}),this.scope.register([],"ArrowRight",()=>{this.activateHighlighted()}),this.scope.register([]," ",n=>{this.elementWrapper&&this.elementWrapper===document.activeElement&&(this.activateHighlighted(),n.preventDefault())}),this.scope.register([],"Enter",()=>this.submit())}disableAllOtherElements(e){for(let r of this.selectModalElements)r.id!==e&&r.setActive(!1)}deHighlightAllOtherElements(e){for(let r of this.selectModalElements)r.id!==e&&r.setHighlighted(!1)}async onOpen(){var a;let{contentEl:e,titleEl:r}=this;r.createEl("h2",{text:this.title}),e.addClass("media-db-plugin-select-modal"),e.createEl("p",{text:this.description}),this.elementWrapper=e.createDiv({cls:"media-db-plugin-select-wrapper"}),this.elementWrapper.tabIndex=0;let i=0;for(let s of this.elements){let l=new ji(s,this.elementWrapper,i,this,!1);this.selectModalElements.push(l),this.renderElement(s,l.element),i+=1}(a=this.selectModalElements.first())==null||a.element.scrollIntoView();let n=new qi.Setting(e);n.addButton(s=>{s.setButtonText("Cancel"),s.onClick(()=>this.close()),s.buttonEl.addClass("media-db-plugin-button"),this.cancelButton=s}),this.addSkipButton&&n.addButton(s=>{s.setButtonText("Skip"),s.onClick(()=>this.skip()),s.buttonEl.addClass("media-db-plugin-button"),this.skipButton=s}),n.addButton(s=>{s.setButtonText("Ok"),s.setCta(),s.onClick(()=>this.submit()),s.buttonEl.addClass("media-db-plugin-button"),this.submitButton=s})}activateHighlighted(){for(let e of this.selectModalElements)e.isHighlighted()&&(e.setActive(!e.isActive()),this.allowMultiSelect||this.disableAllOtherElements(e.id))}highlightUp(){for(let e of this.selectModalElements)if(e.isHighlighted()){this.getPreviousSelectModalElement(e).setHighlighted(!0);return}this.selectModalElements.last().setHighlighted(!0)}highlightDown(){for(let e of this.selectModalElements)if(e.isHighlighted()){this.getNextSelectModalElement(e).setHighlighted(!0);return}this.selectModalElements.first().setHighlighted(!0)}getNextSelectModalElement(e){let r=e.id+1;return r=fi(r,this.selectModalElements.length),this.selectModalElements.filter(i=>i.id===r).first()}getPreviousSelectModalElement(e){let r=e.id-1;return r=fi(r,this.selectModalElements.length),this.selectModalElements.filter(i=>i.id===r).first()}};var Ui=class extends Wi{constructor(e,r){r=Object.assign({},qo,r);super(e.app,r.elements,r.multiSelect);this.plugin=e,this.title=r.modalTitle,this.description="Select one or multiple search results.",this.addSkipButton=r.skipButton,this.busy=!1,this.sendCallback=!1}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}setSkipCallback(e){this.skipCallback=e}renderElement(e,r){r.createEl("div",{text:this.plugin.mediaTypeManager.getFileName(e)}),r.createEl("small",{text:`${e.getSummary()} `}),r.createEl("small",{text:`${e.type.toUpperCase()+(e.subType?` (${e.subType})`:"")} from ${e.dataSource}`})}submit(){this.busy||(this.busy=!0,this.submitButton.setButtonText("Creating entry..."),this.submitCallback({selected:this.selectModalElements.filter(e=>e.isActive()).map(e=>e.value)}))}skip(){this.skipButton.setButtonText("Skipping..."),this.skipCallback()}onClose(){this.closeCallback()}};var xe=require("obsidian");var Ve=require("obsidian");var Hi=class extends Ve.Modal{constructor(e,r){r=Object.assign({},Uo,r);super(e.app);this.plugin=e,this.title=r.modalTitle,this.elements=r.elements,this.markdownComponent=new Ve.Component}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}async preview(){let{contentEl:e}=this;e.addClass("media-db-plugin-preview-modal"),e.createEl("h2",{text:this.title});let r=e.createDiv({cls:"media-db-plugin-preview-wrapper"});this.markdownComponent.load();for(let n of this.elements){r.createEl("h3",{text:n.englishTitle});let a=r.createDiv({cls:"media-db-plugin-preview"}),s=this.plugin.generateMediaDbNoteFrontmatterPreview(n);s=`\`\`\`yaml ${s}\`\`\``;try{await Ve.MarkdownRenderer.render(this.app,s,a,"",this.markdownComponent)}catch(l){console.warn("mdb | error during rendering of preview",l)}}e.createDiv({cls:"media-db-plugin-spacer"});let i=new Ve.Setting(e);i.addButton(n=>{n.setButtonText("Cancel"),n.onClick(()=>this.close()),n.buttonEl.addClass("media-db-plugin-button"),this.cancelButton=n}),i.addButton(n=>{n.setButtonText("Ok"),n.setCta(),n.onClick(()=>this.submitCallback({confirmed:!0})),n.buttonEl.addClass("media-db-plugin-button"),this.submitButton=n})}onOpen(){this.preview()}onClose(){this.markdownComponent.unload(),this.closeCallback()}};var we=require("obsidian");var Vi=class extends we.Modal{constructor(e,r){r=Object.assign({},Ho,r);super(e.app);this.plugin=e,this.selectedTypes=[],this.title=r.modalTitle,this.query=r.prefilledSearchString;for(let i of Fe)this.selectedTypes.push({name:i,selected:r.preselectedTypes.contains(i)})}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}keyPressCallback(e){e.key==="Enter"&&this.search()}async search(){if(!this.query||this.query.length<3){new we.Notice("MDB | Query too short");return}let e=this.selectedTypes.filter(r=>r.selected).map(r=>r.name);if(e.length===0){new we.Notice("MDB | No Type selected");return}this.isBusy||(this.isBusy=!0,this.searchBtn.setDisabled(!1),this.searchBtn.setButtonText("Searching..."),this.submitCallback({query:this.query,types:e}))}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:this.title});let r="Search by title",i=new we.TextComponent(e);i.inputEl.style.width="100%",i.setPlaceholder(r),i.setValue(this.query),i.onChange(n=>this.query=n),i.inputEl.addEventListener("keydown",this.keyPressCallback.bind(this)),e.appendChild(i.inputEl),i.inputEl.focus(),e.createDiv({cls:"media-db-plugin-spacer"}),e.createEl("h3",{text:"APIs to search"});for(let n of Fe){let a=e.createEl("div",{cls:"media-db-plugin-list-wrapper"});a.createEl("div",{cls:"media-db-plugin-list-text-wrapper"}).createEl("span",{text:zt(n),cls:"media-db-plugin-list-text"});let l=a.createEl("div",{cls:"media-db-plugin-list-toggle"}),p=new we.ToggleComponent(l);p.setTooltip(zt(n)),p.setValue(this.selectedTypes.find(d=>d.name===n).selected),p.onChange(d=>{this.selectedTypes.find(c=>c.name===n).selected=d}),l.appendChild(p.toggleEl)}e.createDiv({cls:"media-db-plugin-spacer"}),new we.Setting(e).addButton(n=>{n.setButtonText("Cancel"),n.onClick(()=>this.close()),n.buttonEl.addClass("media-db-plugin-button")}).addButton(n=>{n.setButtonText("Ok"),n.setCta(),n.onClick(()=>{this.search()}),n.buttonEl.addClass("media-db-plugin-button"),this.searchBtn=n})}onClose(){this.closeCallback();let{contentEl:e}=this;e.empty()}};var Ho={modalTitle:"Media DB Search",preselectedTypes:[],prefilledSearchString:""},jo={modalTitle:"Media DB Advanced Search",preselectedAPIs:[],prefilledSearchString:""},Wo={modalTitle:"Media DB Id Search",preselectedAPI:"",prefilledSearchString:""},qo={modalTitle:"Media DB Search Results",elements:[],multiSelect:!0,skipButton:!1},Uo={modalTitle:"Media DB Preview",elements:[]},Yi=class{constructor(t){this.plugin=t}async createSearchModal(t){let e=new Vi(this.plugin,t);return{searchModalResult:await new Promise(i=>{e.setSubmitCallback(n=>i({code:0,data:n})),e.setCloseCallback(n=>{n&&i({code:3,error:n}),i({code:2})}),e.open()}),searchModal:e}}async openSearchModal(t,e){let{searchModalResult:r,searchModal:i}=await this.createSearchModal(t);if(console.debug(`MDB | searchModal closed with code ${r.code}`),r.code===3){console.warn(r.error),new xe.Notice(r.error.toString()),i.close();return}if(r.code!==2)try{let n=await e(r.data);return i.close(),n}catch(n){console.warn(n),new xe.Notice(n.toString()),i.close();return}}async createAdvancedSearchModal(t){let e=new Ii(this.plugin,t);return{advancedSearchModalResult:await new Promise(i=>{e.setSubmitCallback(n=>i({code:0,data:n})),e.setCloseCallback(n=>{n&&i({code:3,error:n}),i({code:2})}),e.open()}),advancedSearchModal:e}}async openAdvancedSearchModal(t,e){let{advancedSearchModalResult:r,advancedSearchModal:i}=await this.createAdvancedSearchModal(t);if(console.debug(`MDB | advencedSearchModal closed with code ${r.code}`),r.code===3){console.warn(r.error),new xe.Notice(r.error.toString()),i.close();return}if(r.code!==2)try{let n=await e(r.data);return i.close(),n}catch(n){console.warn(n),new xe.Notice(n.toString()),i.close();return}}async createIdSearchModal(t){let e=new Li(this.plugin,t);return{idSearchModalResult:await new Promise(i=>{e.setSubmitCallback(n=>i({code:0,data:n})),e.setCloseCallback(n=>{n&&i({code:3,error:n}),i({code:2})}),e.open()}),idSearchModal:e}}async openIdSearchModal(t,e){let{idSearchModalResult:r,idSearchModal:i}=await this.createIdSearchModal(t);if(console.debug(`MDB | idSearchModal closed with code ${r.code}`),r.code===3){console.warn(r.error),new xe.Notice(r.error.toString()),i.close();return}if(r.code!==2)try{let n=await e(r.data);return i.close(),n}catch(n){console.warn(n),new xe.Notice(n.toString()),i.close();return}}async createSelectModal(t){let e=new Ui(this.plugin,t);return{selectModalResult:await new Promise(i=>{e.setSubmitCallback(n=>i({code:0,data:n})),e.setSkipCallback(()=>i({code:1})),e.setCloseCallback(n=>{n&&i({code:3,error:n}),i({code:2})}),e.open()}),selectModal:e}}async openSelectModal(t,e){let{selectModalResult:r,selectModal:i}=await this.createSelectModal(t);if(console.debug(`MDB | selectModal closed with code ${r.code}`),r.code===3){console.warn(r.error),new xe.Notice(r.error.toString()),i.close();return}if(r.code!==2&&r.code!==1)try{let n=await e(r.data);return i.close(),n}catch(n){console.warn(n),new xe.Notice(n.toString()),i.close();return}}async createPreviewModal(t){let e=new Hi(this.plugin,t);return{previewModalResult:await new Promise(i=>{e.setSubmitCallback(n=>i({code:0,data:n})),e.setCloseCallback(n=>{n&&i({code:3,error:n}),i({code:2})}),e.open()}),previewModal:e}}async openPreviewModal(t,e){let{previewModalResult:r,previewModal:i}=await this.createPreviewModal(t);if(console.debug(`MDB | previewModal closed with code ${r.code}`),r.code===3){console.warn(r.error),new xe.Notice(r.error.toString()),i.close();return}if(r.code!==2)try{let n=await e(r.data);return i.close(),n}catch(n){console.warn(n),new xe.Notice(n.toString()),i.close();return}}};var kt=require("obsidian"),Gi=class{constructor(){this.toFormat="YYYY-MM-DD",this.locale=new Intl.DateTimeFormat().resolvedOptions().locale}setFormat(t){this.toFormat=t}getPreview(t){let e=(0,kt.moment)();return t||(t=this.toFormat),e.locale(this.locale).format(t)}format(t,e,r="en"){if(!t)return null;let i;return e?i=(0,kt.moment)(t,e,r):this.hasMomentFormat(t)?i=(0,kt.moment)(t):i=(0,kt.moment)(new Date(t)),i.isValid()?i.locale(this.locale).format(this.toFormat):null}hasMomentFormat(t){return(0,kt.moment)(t,!0).isValid()}};var zi=class extends ne.Plugin{constructor(){super(...arguments);this.frontMatterRexExpPattern="^(---)\\n[\\s\\S]*?\\n---"}async onload(){this.apiManager=new Ei,this.apiManager.registerAPI(new Ci(this)),this.apiManager.registerAPI(new Pi(this)),this.apiManager.registerAPI(new Fi(this)),this.apiManager.registerAPI(new ki(this)),this.apiManager.registerAPI(new $i(this)),this.apiManager.registerAPI(new Ri(this)),this.apiManager.registerAPI(new Oi(this)),this.apiManager.registerAPI(new Ai(this)),this.mediaTypeManager=new Si,this.modelPropertyMapper=new Ni(this),this.modalHelper=new Yi(this),this.dateFormatter=new Gi,await this.loadSettings(),this.addSettingTab(new Di(this.app,this)),this.mediaTypeManager.updateTemplates(this.settings),this.mediaTypeManager.updateFolders(this.settings),this.dateFormatter.setFormat(this.settings.customDateFormat),this.addRibbonIcon("database","Add new Media DB entry",()=>this.createEntryWithAdvancedSearchModal()).addClass("obsidian-media-db-plugin-ribbon-class"),this.registerEvent(this.app.workspace.on("file-menu",(r,i)=>{i instanceof ne.TFolder&&r.addItem(n=>{n.setTitle("Import folder as Media DB entries").setIcon("database").onClick(()=>this.createEntriesFromFolder(i))})})),this.addCommand({id:"open-media-db-search-modal",name:"Create Media DB entry",callback:()=>this.createEntryWithSearchModal()});for(let r of Fe)this.addCommand({id:`open-media-db-search-modal-with-${r}`,name:`Create Media DB entry (${zt(r)})`,callback:()=>this.createEntryWithSearchModal({preselectedTypes:[r]})});this.addCommand({id:"open-media-db-advanced-search-modal",name:"Create Media DB entry (advanced search)",callback:()=>this.createEntryWithAdvancedSearchModal()}),this.addCommand({id:"open-media-db-id-search-modal",name:"Create Media DB entry by id",callback:()=>this.createEntryWithIdSearchModal()}),this.addCommand({id:"update-media-db-note",name:"Update open note (this will recreate the note)",checkCallback:r=>this.app.workspace.getActiveFile()?(r||this.updateActiveNote(!1),!0):!1}),this.addCommand({id:"update-media-db-note-metadata",name:"Update metadata",checkCallback:r=>this.app.workspace.getActiveFile()?(r||this.updateActiveNote(!0),!0):!1}),this.addCommand({id:"add-media-db-link",name:"Insert link",checkCallback:r=>this.app.workspace.getActiveFile()?(r||this.createLinkWithSearchModal(),!0):!1})}async createLinkWithSearchModal(){let e=await this.modalHelper.openAdvancedSearchModal({},async a=>await this.apiManager.query(a.query,a.apis));if(!e)return;let r=await this.modalHelper.openSelectModal({elements:e,multiSelect:!1},async a=>await this.queryDetails(a.selected));if(!r||r.length<1)return;let i=`[${r[0].title}](${r[0].url})`,n=this.app.workspace.getActiveViewOfType(ne.MarkdownView);n&&n.editor.replaceRange(i,n.editor.getCursor())}async createEntryWithSearchModal(e){let r=[],i=await this.modalHelper.openSearchModal(e!=null?e:{},async s=>{r=s.types;let l=this.apiManager.apis.filter(p=>p.hasTypeOverlap(s.types)).map(p=>p.apiName);return await this.apiManager.query(s.query,l)});if(!i)return;i=i.filter(s=>r.contains(s.type));let n,a;for(;!a;){if(n=await this.modalHelper.openSelectModal({elements:i},async s=>await this.queryDetails(s.selected)),!n)return;a=await this.modalHelper.openPreviewModal({elements:n},async s=>s.confirmed)}await this.createMediaDbNotes(n)}async createEntryWithAdvancedSearchModal(){let e=await this.modalHelper.openAdvancedSearchModal({},async n=>await this.apiManager.query(n.query,n.apis));if(!e)return;let r,i;for(;!i;){if(r=await this.modalHelper.openSelectModal({elements:e},async n=>await this.queryDetails(n.selected)),!r)return;i=await this.modalHelper.openPreviewModal({elements:r},async n=>n.confirmed)}await this.createMediaDbNotes(r)}async createEntryWithIdSearchModal(){let e,r;for(;!r;){if(e=await this.modalHelper.openIdSearchModal({},async i=>await this.apiManager.queryDetailedInfoById(i.query,i.api)),!e)return;r=await this.modalHelper.openPreviewModal({elements:[e]},async i=>i.confirmed)}await this.createMediaDbNoteFromModel(e,{attachTemplate:!0,openNote:!0})}async createMediaDbNotes(e,r){for(let i of e)await this.createMediaDbNoteFromModel(i,{attachTemplate:!0,attachFile:r})}async queryDetails(e){let r=[];for(let i of e)try{r.push(await this.apiManager.queryDetailedInfo(i))}catch(n){console.warn(n),new ne.Notice(n.toString())}return r}async createMediaDbNoteFromModel(e,r){try{console.debug("MDB | creating new note");let i=await this.generateMediaDbNoteContents(e,r);r.folder||(r.folder=await this.mediaTypeManager.getFolder(e,this.app)),await this.createNote(this.mediaTypeManager.getFileName(e),i,r)}catch(i){console.warn(i),new ne.Notice(i.toString())}}generateMediaDbNoteFrontmatterPreview(e){let r=this.modelPropertyMapper.convertObject(e.toMetaDataObject());return this.settings.useCustomYamlStringifier?ei.toYaml(r):(0,ne.stringifyYaml)(r)}async generateMediaDbNoteContents(e,r){let i=this.modelPropertyMapper.convertObject(e.toMetaDataObject()),n="",a=r.attachTemplate?await this.mediaTypeManager.getTemplate(e,this.app):"";return{fileMetadata:i,fileContent:n}=await this.attachFile(i,n,r.attachFile),{fileMetadata:i,fileContent:n}=await this.attachTemplate(i,n,a),n=`--- ${this.settings.useCustomYamlStringifier?ei.toYaml(i):(0,ne.stringifyYaml)(i)}--- `+n,n}async attachFile(e,r,i){if(!i)return{fileMetadata:e,fileContent:r};let n=this.getMetadataFromFileCache(i);e=Object.assign(n,e);let a=await this.app.vault.read(i),s=new RegExp(this.frontMatterRexExpPattern);return a=a.replace(s,""),a=a.startsWith(` `)?a.substring(1):a,r+=a,{fileMetadata:e,fileContent:r}}async attachTemplate(e,r,i){if(!i)return{fileMetadata:e,fileContent:r};let n=this.getMetaDataFromFileContent(i);e=Object.assign(n,e);let a=new RegExp(this.frontMatterRexExpPattern),s=i.replace(a,"");return r+=s,{fileMetadata:e,fileContent:r}}getMetaDataFromFileContent(e){let r,n=new RegExp(this.frontMatterRexExpPattern).exec(e);if(!n)return{};let a=n[0];return a?(a=a.substring(4),a=a.substring(0,a.length-3),r=(0,ne.parseYaml)(a),r||(r={}),console.debug("MDB | metadata read from file content",r),r):{}}getMetadataFromFileCache(e){let r=this.app.metadataCache.getFileCache(e).frontmatter;return r?(r=Object.assign({},r),delete r.position):r={},r}async createNote(e,r,i){var p;let n=(p=i.folder)!=null?p:this.app.vault.getAbstractFileByPath("/");e=io(e);let a=`${n.path}/${e}.md`,s=this.app.vault.getAbstractFileByPath(a);s&&await this.app.vault.delete(s);let l=await this.app.vault.create(a,r);if(console.debug(`MDB | created new file at ${a}`),i.openNote){let d=this.app.workspace.getUnpinnedLeaf();if(!d){console.warn("MDB | no active leaf, not opening newly created note");return}await d.openFile(l,{state:{mode:"source"}})}}async updateActiveNote(e=!1){let r=this.app.workspace.getActiveFile();if(!r)throw new Error("MDB | there is no active note");let i=this.getMetadataFromFileCache(r);if(i=this.modelPropertyMapper.convertObjectBack(i),console.debug("MDB | read metadata",i),!(i!=null&&i.type)||!(i!=null&&i.dataSource)||!(i!=null&&i.id))throw new Error("MDB | active note is not a Media DB entry or is missing metadata");let n=this.mediaTypeManager.createMediaTypeModelFromMediaType(i,i.type),a=await this.apiManager.queryDetailedInfoById(i.id,i.dataSource);a&&(a=Object.assign(n,a.getWithOutUserData()),console.debug("MDB | deleting old entry"),e?await this.createMediaDbNoteFromModel(a,{attachFile:r,folder:r.parent,openNote:!0}):await this.createMediaDbNoteFromModel(a,{attachTemplate:!0,folder:r.parent,openNote:!0}))}async createEntriesFromFolder(e){let r=[],i=!1,{selectedAPI:n,titleFieldName:a,appendContent:s}=await new Promise(l=>{new Bi(this.app,this,(p,d,c)=>{l({selectedAPI:p,titleFieldName:d,appendContent:c})}).open()});for(let l of e.children)if(l instanceof ne.TFile){let p=l;if(i){r.push({filePath:p.path,error:"user canceled"});continue}let c=this.getMetadataFromFileCache(p)[a];if(!c){r.push({filePath:p.path,error:`metadata field '${a}' not found or empty`});continue}let u=[];try{u=await this.apiManager.query(c,[n])}catch(f){r.push({filePath:p.path,error:f.toString()});continue}if(!u||u.length===0){r.push({filePath:p.path,error:"no search results"});continue}let{selectModalResult:m,selectModal:M}=await this.modalHelper.createSelectModal({elements:u,skipButton:!0,modalTitle:`Results for '${c}'`});if(m.code===3){r.push({filePath:p.path,error:m.error.message}),M.close();continue}if(m.code===2){r.push({filePath:p.path,error:"user canceled"}),M.close(),i=!0;continue}if(m.code===1){r.push({filePath:p.path,error:"user skipped"}),M.close();continue}if(m.data.selected.length===0){r.push({filePath:p.path,error:"no search results selected"});continue}let g=await this.queryDetails(m.data.selected);await this.createMediaDbNotes(g,s?p:null),M.close()}r.length>0&&await this.createErroredFilesReport(r)}async createErroredFilesReport(e){let r=`MDB - bulk import error report ${no(new Date)}`,i=`${r}.md`,n=[["file","error"]].concat(e.map(s=>[s.filePath,s.error])),a=`# ${r} ${ro(n)}`;await this.app.vault.create(i,a)}async loadSettings(){let e=await this.loadData(),r=Lo(this),i=Object.assign({},r,e),n=[];for(let a of r.propertyMappingModels){let s=i.propertyMappingModels.find(l=>l.type===a.type);if(s===void 0)n.push(a);else{let l=[];for(let p of a.properties){let d=s.properties.find(c=>c.property===p.property);d===void 0?l.push(p):l.push(new dt(d.property,d.newProperty,d.mapping,p.locked))}n.push(new Ft(s.type,l))}}i.propertyMappingModels=n,this.settings=i}async saveSettings(){this.mediaTypeManager.updateTemplates(this.settings),this.mediaTypeManager.updateFolders(this.settings),this.dateFormatter.setFormat(this.settings.customDateFormat),await this.saveData(this.settings)}};