You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
118 KiB

/*
-------------------------------------------
Media DB - Release Build
-------------------------------------------
By: Moritz Jung (https://www.moritzjung.dev)
Time: Sat, 22 Jun 2024 13:55:15 GMT
Version: 0.7.1
-------------------------------------------
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
-------------------------------------------
MIT License
Copyright (c) 2024 Moritz Jung
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
var ai=Object.defineProperty;var Yn=Object.getOwnPropertyDescriptor;var zn=Object.getOwnPropertyNames;var Kn=Object.prototype.hasOwnProperty;var Xn=(r,e,t)=>e in r?ai(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Jn=(r,e)=>{for(var t in e)ai(r,t,{get:e[t],enumerable:!0})},Zn=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of zn(e))!Kn.call(r,n)&&n!==t&&ai(r,n,{get:()=>e[n],enumerable:!(i=Yn(e,n))||i.enumerable});return r};var Qn=r=>Zn(ai({},"__esModule",{value:!0}),r);var K=(r,e,t)=>(Xn(r,typeof e!="symbol"?e+"":e,t),t);var da={};Jn(da,{default:()=>zi});module.exports=Qn(da);var z=require("obsidian");var C=require("obsidian");var cn=require("obsidian");var dn=require("obsidian");var N="top",H="bottom",W="right",B="left",si="auto",We=[N,H,W,B],$e="start",Ke="end",Ar="clippingParents",li="viewport",bt="popper",Nr="reference",Ki=We.reduce(function(r,e){return r.concat([e+"-"+$e,e+"-"+Ke])},[]),pi=[].concat(We,[si]).reduce(function(r,e){return r.concat([e,e+"-"+$e,e+"-"+Ke])},[]),eo="beforeRead",to="read",io="afterRead",ro="beforeMain",no="main",oo="afterMain",ao="beforeWrite",so="write",lo="afterWrite",Br=[eo,to,io,ro,no,oo,ao,so,lo];function X(r){return r?(r.nodeName||"").toLowerCase():null}function k(r){if(r==null)return window;if(r.toString()!=="[object Window]"){var e=r.ownerDocument;return e&&e.defaultView||window}return r}function de(r){var e=k(r).Element;return r instanceof e||r instanceof Element}function V(r){var e=k(r).HTMLElement;return r instanceof e||r instanceof HTMLElement}function wt(r){if(typeof ShadowRoot=="undefined")return!1;var e=k(r).ShadowRoot;return r instanceof e||r instanceof ShadowRoot}function po(r){var e=r.state;Object.keys(e.elements).forEach(function(t){var i=e.styles[t]||{},n=e.attributes[t]||{},o=e.elements[t];!V(o)||!X(o)||(Object.assign(o.style,i),Object.keys(n).forEach(function(a){var s=n[a];s===!1?o.removeAttribute(a):o.setAttribute(a,s===!0?"":s)}))})}function co(r){var e=r.state,t={popper:{position:e.options.strategy,left:"0",top:"0",margin:"0"},arrow:{position:"absolute"},reference:{}};return Object.assign(e.elements.popper.style,t.popper),e.styles=t,e.elements.arrow&&Object.assign(e.elements.arrow.style,t.arrow),function(){Object.keys(e.elements).forEach(function(i){var n=e.elements[i],o=e.attributes[i]||{},a=Object.keys(e.styles.hasOwnProperty(i)?e.styles[i]:t[i]),s=a.reduce(function(l,p){return l[p]="",l},{});!V(n)||!X(n)||(Object.assign(n.style,s),Object.keys(o).forEach(function(l){n.removeAttribute(l)}))})}}var Ir={name:"applyStyles",enabled:!0,phase:"write",fn:po,effect:co,requires:["computeStyles"]};function J(r){return r.split("-")[0]}var he=Math.max,Xe=Math.min,Re=Math.round;function xt(){var r=navigator.userAgentData;return r!=null&&r.brands&&Array.isArray(r.brands)?r.brands.map(function(e){return e.brand+"/"+e.version}).join(" "):navigator.userAgent}function jt(){return!/^((?!chrome|android).)*safari/i.test(xt())}function ce(r,e,t){e===void 0&&(e=!1),t===void 0&&(t=!1);var i=r.getBoundingClientRect(),n=1,o=1;e&&V(r)&&(n=r.offsetWidth>0&&Re(i.width)/r.offsetWidth||1,o=r.offsetHeight>0&&Re(i.height)/r.offsetHeight||1);var a=de(r)?k(r):window,s=a.visualViewport,l=!jt()&&t,p=(i.left+(l&&s?s.offsetLeft:0))/n,d=(i.top+(l&&s?s.offsetTop:0))/o,c=i.width/n,f=i.height/o;return{width:c,height:f,top:d,right:p+c,bottom:d+f,left:p,x:p,y:d}}function Je(r){var e=ce(r),t=r.offsetWidth,i=r.offsetHeight;return Math.abs(e.width-t)<=1&&(t=e.width),Math.abs(e.height-i)<=1&&(i=e.height),{x:r.offsetLeft,y:r.offsetTop,width:t,height:i}}function qt(r,e){var t=e.getRootNode&&e.getRootNode();if(r.contains(e))return!0;if(t&&wt(t)){var i=e;do{if(i&&r.isSameNode(i))return!0;i=i.parentNode||i.host}while(i)}return!1}function ae(r){return k(r).getComputedStyle(r)}function Xi(r){return["table","td","th"].indexOf(X(r))>=0}function ie(r){return((de(r)?r.ownerDocument:r.document)||window.document).documentElement}function Oe(r){return X(r)==="html"?r:r.assignedSlot||r.parentNode||(wt(r)?r.host:null)||ie(r)}function Lr(r){return!V(r)||ae(r).position==="fixed"?null:r.offsetParent}function uo(r){var e=/firefox/i.test(xt()),t=/Trident/i.test(xt());if(t&&V(r)){var i=ae(r);if(i.position==="fixed")return null}var n=Oe(r);for(wt(n)&&(n=n.host);V(n)&&["html","body"].indexOf(X(n))<0;){var o=ae(n);if(o.transform!=="none"||o.perspective!=="none"||o.contain==="paint"||["transform","perspective"].indexOf(o.willChange)!==-1||e&&o.willChange==="filter"||e&&o.filter&&o.filter!=="none")return n;n=n.parentNode}return null}function ge(r){for(var e=k(r),t=Lr(r);t&&Xi(t)&&ae(t).position==="static";)t=Lr(t);return t&&(X(t)==="html"||X(t)==="body"&&ae(t).position==="static")?e:t||uo(r)||e}function Ze(r){return["top","bottom"].indexOf(r)>=0?"x":"y"}function Qe(r,e,t){return he(r,Xe(e,t))}function Wr(r,e,t){var i=Qe(r,e,t);return i>t?t:i}function Ut(){return{top:0,right:0,bottom:0,left:0}}function Ht(r){return Object.assign({},Ut(),r)}function Vt(r,e){return e.reduce(function(t,i){return t[i]=r,t},{})}var mo=function(e,t){return e=typeof e=="function"?e(Object.assign({},t.rects,{placement:t.placement})):e,Ht(typeof e!="number"?e:Vt(e,We))};function fo(r){var e,t=r.state,i=r.name,n=r.options,o=t.elements.arrow,a=t.modifiersData.popperOffsets,s=J(t.placement),l=Ze(s),p=[B,W].indexOf(s)>=0,d=p?"height":"width";if(!(!o||!a)){var c=mo(n.padding,t),f=Je(o),u=l==="y"?N:B,M=l==="y"?H:W,g=t.rects.reference[d]+t.rects.reference[l]-a[l]-t.rects.popper[d],m=a[l]-t.rects.reference[l],_=ge(o),b=_?l==="y"?_.clientHeight||0:_.clientWidth||0:0,D=g/2-m/2,h=c[u],y=b-f[d]-c[M],w=b/2-f[d]/2+D,S=Qe(h,w,y),T=l;t.modifiersData[i]=(e={},e[T]=S,e.centerOffset=S-w,e)}}function ho(r){var e=r.state,t=r.options,i=t.element,n=i===void 0?"[data-popper-arrow]":i;n!=null&&(typeof n=="string"&&(n=e.elements.popper.querySelector(n),!n)||qt(e.elements.popper,n)&&(e.elements.arrow=n))}var jr={name:"arrow",enabled:!0,phase:"main",fn:fo,effect:ho,requires:["popperOffsets"],requiresIfExists:["preventOverflow"]};function ue(r){return r.split("-")[1]}var go={top:"auto",right:"auto",bottom:"auto",left:"auto"};function yo(r,e){var t=r.x,i=r.y,n=e.devicePixelRatio||1;return{x:Re(t*n)/n||0,y:Re(i*n)/n||0}}function qr(r){var e,t=r.popper,i=r.popperRect,n=r.placement,o=r.variation,a=r.offsets,s=r.position,l=r.gpuAcceleration,p=r.adaptive,d=r.roundOffsets,c=r.isFixed,f=a.x,u=f===void 0?0:f,M=a.y,g=M===void 0?0:M,m=typeof d=="function"?d({x:u,y:g}):{x:u,y:g};u=m.x,g=m.y;var _=a.hasOwnProperty("x"),b=a.hasOwnProperty("y"),D=B,h=N,y=window;if(p){var w=ge(t),S="clientHeight",T="clientWidth";if(w===k(t)&&(w=ie(t),ae(w).position!=="static"&&s==="absolute"&&(S="scrollHeight",T="scrollWidth")),w=w,n===N||(n===B||n===W)&&o===Ke){h=H;var E=c&&w===y&&y.visualViewport?y.visualViewport.height:w[S];g-=E-i.height,g*=l?1:-1}if(n===B||(n===N||n===H)&&o===Ke){D=W;var x=c&&w===y&&y.visualViewport?y.visualViewport.width:w[T];u-=x-i.width,u*=l?1:-1}}var v=Object.assign({position:s},p&&go),F=d===!0?yo({x:u,y:g},k(t)):{x:u,y:g};if(u=F.x,g=F.y,l){var P;return Object.assign({},v,(P={},P[h]=b?"0":"",P[D]=_?"0":"",P.transform=(y.devicePixelRatio||1)<=1?"translate("+u+"px, "+g+"px)":"translate3d("+u+"px, "+g+"px, 0)",P))}return Object.assign({},v,(e={},e[h]=b?g+"px":"",e[D]=_?u+"px":"",e.transform="",e))}function Mo(r){var e=r.state,t=r.options,i=t.gpuAcceleration,n=i===void 0?!0:i,o=t.adaptive,a=o===void 0?!0:o,s=t.roundOffsets,l=s===void 0?!0:s,p={placement:J(e.placement),variation:ue(e.placement),popper:e.elements.popper,popperRect:e.rects.popper,gpuAcceleration:n,isFixed:e.options.strategy==="fixed"};e.modifiersData.popperOffsets!=null&&(e.styles.popper=Object.assign({},e.styles.popper,qr(Object.assign({},p,{offsets:e.modifiersData.popperOffsets,position:e.options.strategy,adaptive:a,roundOffsets:l})))),e.modifiersData.arrow!=null&&(e.styles.arrow=Object.assign({},e.styles.arrow,qr(Object.assign({},p,{offsets:e.modifiersData.arrow,position:"absolute",adaptive:!1,roundOffsets:l})))),e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-placement":e.placement})}var Ur={name:"computeStyles",enabled:!0,phase:"beforeWrite",fn:Mo,data:{}};var di={passive:!0};function vo(r){var e=r.state,t=r.instance,i=r.options,n=i.scroll,o=n===void 0?!0:n,a=i.resize,s=a===void 0?!0:a,l=k(e.elements.popper),p=[].concat(e.scrollParents.reference,e.scrollParents.popper);return o&&p.forEach(function(d){d.addEventListener("scroll",t.update,di)}),s&&l.addEventListener("resize",t.update,di),function(){o&&p.forEach(function(d){d.removeEventListener("scroll",t.update,di)}),s&&l.removeEventListener("resize",t.update,di)}}var Hr={name:"eventListeners",enabled:!0,phase:"write",fn:function(){},effect:vo,data:{}};var bo={left:"right",right:"left",bottom:"top",top:"bottom"};function Tt(r){return r.replace(/left|right|bottom|top/g,function(e){return bo[e]})}var wo={start:"end",end:"start"};function ci(r){return r.replace(/start|end/g,function(e){return wo[e]})}function et(r){var e=k(r),t=e.pageXOffset,i=e.pageYOffset;return{scrollLeft:t,scrollTop:i}}function tt(r){return ce(ie(r)).left+et(r).scrollLeft}function Ji(r,e){var t=k(r),i=ie(r),n=t.visualViewport,o=i.clientWidth,a=i.clientHeight,s=0,l=0;if(n){o=n.width,a=n.height;var p=jt();(p||!p&&e==="fixed")&&(s=n.offsetLeft,l=n.offsetTop)}return{width:o,height:a,x:s+tt(r),y:l}}function Zi(r){var e,t=ie(r),i=et(r),n=(e=r.ownerDocument)==null?void 0:e.body,o=he(t.scrollWidth,t.clientWidth,n?n.scrollWidth:0,n?n.clientWidth:0),a=he(t.scrollHeight,t.clientHeight,n?n.scrollHeight:0,n?n.clientHeight:0),s=-i.scrollLeft+tt(r),l=-i.scrollTop;return ae(n||t).direction==="rtl"&&(s+=he(t.clientWidth,n?n.clientWidth:0)-o),{width:o,height:a,x:s,y:l}}function it(r){var e=ae(r),t=e.overflow,i=e.overflowX,n=e.overflowY;return/auto|scroll|overlay|hidden/.test(t+n+i)}function ui(r){return["html","body","#document"].indexOf(X(r))>=0?r.ownerDocument.body:V(r)&&it(r)?r:ui(Oe(r))}function je(r,e){var t;e===void 0&&(e=[]);var i=ui(r),n=i===((t=r.ownerDocument)==null?void 0:t.body),o=k(i),a=n?[o].concat(o.visualViewport||[],it(i)?i:[]):i,s=e.concat(a);return n?s:s.concat(je(Oe(a)))}function _t(r){return Object.assign({},r,{left:r.x,top:r.y,right:r.x+r.width,bottom:r.y+r.height})}function xo(r,e){var t=ce(r,!1,e==="fixed");return t.top=t.top+r.clientTop,t.left=t.left+r.clientLeft,t.bottom=t.top+r.clientHeight,t.right=t.left+r.clientWidth,t.width=r.clientWidth,t.height=r.clientHeight,t.x=t.left,t.y=t.top,t}function Vr(r,e,t){return e===li?_t(Ji(r,t)):de(e)?xo(e,t):_t(Zi(ie(r)))}function To(r){var e=je(Oe(r)),t=["absolute","fixed"].indexOf(ae(r).position)>=0,i=t&&V(r)?ge(r):r;return de(i)?e.filter(function(n){return de(n)&&qt(n,i)&&X(n)!=="body"}):[]}function Qi(r,e,t,i){var n=e==="clippingParents"?To(r):[].concat(e),o=[].concat(n,[t]),a=o[0],s=o.reduce(function(l,p){var d=Vr(r,p,i);return l.top=he(d.top,l.top),l.right=Xe(d.right,l.right),l.bottom=Xe(d.bottom,l.bottom),l.left=he(d.left,l.left),l},Vr(r,a,i));return s.width=s.right-s.left,s.height=s.bottom-s.top,s.x=s.left,s.y=s.top,s}function Gt(r){var e=r.reference,t=r.element,i=r.placement,n=i?J(i):null,o=i?ue(i):null,a=e.x+e.width/2-t.width/2,s=e.y+e.height/2-t.height/2,l;switch(n){case N:l={x:a,y:e.y-t.height};break;case H:l={x:a,y:e.y+e.height};break;case W:l={x:e.x+e.width,y:s};break;case B:l={x:e.x-t.width,y:s};break;default:l={x:e.x,y:e.y}}var p=n?Ze(n):null;if(p!=null){var d=p==="y"?"height":"width";switch(o){case $e:l[p]=l[p]-(e[d]/2-t[d]/2);break;case Ke:l[p]=l[p]+(e[d]/2-t[d]/2);break;default:}}return l}function ye(r,e){e===void 0&&(e={});var t=e,i=t.placement,n=i===void 0?r.placement:i,o=t.strategy,a=o===void 0?r.strategy:o,s=t.boundary,l=s===void 0?Ar:s,p=t.rootBoundary,d=p===void 0?li:p,c=t.elementContext,f=c===void 0?bt:c,u=t.altBoundary,M=u===void 0?!1:u,g=t.padding,m=g===void 0?0:g,_=Ht(typeof m!="number"?m:Vt(m,We)),b=f===bt?Nr:bt,D=r.rects.popper,h=r.elements[M?b:f],y=Qi(de(h)?h:h.contextElement||ie(r.elements.popper),l,d,a),w=ce(r.elements.reference),S=Gt({reference:w,element:D,strategy:"absolute",placement:n}),T=_t(Object.assign({},D,S)),E=f===bt?T:w,x={top:y.top-E.top+_.top,bottom:E.bottom-y.bottom+_.bottom,left:y.left-E.left+_.left,right:E.right-y.right+_.right},v=r.modifiersData.offset;if(f===bt&&v){var F=v[n];Object.keys(x).forEach(function(P){var A=[W,H].indexOf(P)>=0?1:-1,Q=[N,H].indexOf(P)>=0?"y":"x";x[P]+=F[Q]*A})}return x}function er(r,e){e===void 0&&(e={});var t=e,i=t.placement,n=t.boundary,o=t.rootBoundary,a=t.padding,s=t.flipVariations,l=t.allowedAutoPlacements,p=l===void 0?pi:l,d=ue(i),c=d?s?Ki:Ki.filter(function(M){return ue(M)===d}):We,f=c.filter(function(M){return p.indexOf(M)>=0});f.length===0&&(f=c);var u=f.reduce(function(M,g){return M[g]=ye(r,{placement:g,boundary:n,rootBoundary:o,padding:a})[J(g)],M},{});return Object.keys(u).sort(function(M,g){return u[M]-u[g]})}function _o(r){if(J(r)===si)return[];var e=Tt(r);return[ci(r),e,ci(e)]}function So(r){var e=r.state,t=r.options,i=r.name;if(!e.modifiersData[i]._skip){for(var n=t.mainAxis,o=n===void 0?!0:n,a=t.altAxis,s=a===void 0?!0:a,l=t.fallbackPlacements,p=t.padding,d=t.boundary,c=t.rootBoundary,f=t.altBoundary,u=t.flipVariations,M=u===void 0?!0:u,g=t.allowedAutoPlacements,m=e.options.placement,_=J(m),b=_===m,D=l||(b||!M?[Tt(m)]:_o(m)),h=[m].concat(D).reduce(function(ke,fe){return ke.concat(J(fe)===si?er(e,{placement:fe,boundary:d,rootBoundary:c,padding:p,flipVariations:M,allowedAutoPlacements:g}):fe)},[]),y=e.rects.reference,w=e.rects.popper,S=new Map,T=!0,E=h[0],x=0;x<h.length;x++){var v=h[x],F=J(v),P=ue(v)===$e,A=[N,H].indexOf(F)>=0,Q=A?"width":"height",U=ye(e,{placement:v,boundary:d,rootBoundary:c,altBoundary:f,padding:p}),ee=A?P?W:B:P?H:N;y[Q]>w[Q]&&(ee=Tt(ee));var _e=Tt(ee),le=[];if(o&&le.push(U[F]<=0),s&&le.push(U[ee]<=0,U[_e]<=0),le.every(function(ke){return ke})){E=v,T=!1;break}S.set(v,le)}if(T)for(var Ve=M?3:1,gt=function(fe){var Le=h.find(function(Ye){var Se=S.get(Ye);if(Se)return Se.slice(0,fe).every(function(yt){return yt})});if(Le)return E=Le,"break"},Ie=Ve;Ie>0;Ie--){var Ge=gt(Ie);if(Ge==="break")break}e.placement!==E&&(e.modifiersData[i]._skip=!0,e.placement=E,e.reset=!0)}}var Gr={name:"flip",enabled:!0,phase:"main",fn:So,requiresIfExists:["offset"],data:{_skip:!1}};function Yr(r,e,t){return t===void 0&&(t={x:0,y:0}),{top:r.top-e.height-t.y,right:r.right-e.width+t.x,bottom:r.bottom-e.height+t.y,left:r.left-e.width-t.x}}function zr(r){return[N,W,H,B].some(function(e){return r[e]>=0})}function Do(r){var e=r.state,t=r.name,i=e.rects.reference,n=e.rects.popper,o=e.modifiersData.preventOverflow,a=ye(e,{elementContext:"reference"}),s=ye(e,{altBoundary:!0}),l=Yr(a,i),p=Yr(s,n,o),d=zr(l),c=zr(p);e.modifiersData[t]={referenceClippingOffsets:l,popperEscapeOffsets:p,isReferenceHidden:d,hasPopperEscaped:c},e.attributes.popper=Object.assign({},e.attributes.popper,{"data-popper-reference-hidden":d,"data-popper-escaped":c})}var Kr={name:"hide",enabled:!0,phase:"main",requiresIfExists:["preventOverflow"],fn:Do};function Eo(r,e,t){var i=J(r),n=[B,N].indexOf(i)>=0?-1:1,o=typeof t=="function"?t(Object.assign({},e,{placement:r})):t,a=o[0],s=o[1];return a=a||0,s=(s||0)*n,[B,W].indexOf(i)>=0?{x:s,y:a}:{x:a,y:s}}function Co(r){var e=r.state,t=r.options,i=r.name,n=t.offset,o=n===void 0?[0,0]:n,a=pi.reduce(function(d,c){return d[c]=Eo(c,e.rects,o),d},{}),s=a[e.placement],l=s.x,p=s.y;e.modifiersData.popperOffsets!=null&&(e.modifiersData.popperOffsets.x+=l,e.modifiersData.popperOffsets.y+=p),e.modifiersData[i]=a}var Xr={name:"offset",enabled:!0,phase:"main",requires:["popperOffsets"],fn:Co};function Po(r){var e=r.state,t=r.name;e.modifiersData[t]=Gt({reference:e.rects.reference,element:e.rects.popper,strategy:"absolute",placement:e.placement})}var Jr={name:"popperOffsets",enabled:!0,phase:"read",fn:Po,data:{}};function tr(r){return r==="x"?"y":"x"}function Fo(r){var e=r.state,t=r.options,i=r.name,n=t.mainAxis,o=n===void 0?!0:n,a=t.altAxis,s=a===void 0?!1:a,l=t.boundary,p=t.rootBoundary,d=t.altBoundary,c=t.padding,f=t.tether,u=f===void 0?!0:f,M=t.tetherOffset,g=M===void 0?0:M,m=ye(e,{boundary:l,rootBoundary:p,padding:c,altBoundary:d}),_=J(e.placement),b=ue(e.placement),D=!b,h=Ze(_),y=tr(h),w=e.modifiersData.popperOffsets,S=e.rects.reference,T=e.rects.popper,E=typeof g=="function"?g(Object.assign({},e.rects,{placement:e.placement})):g,x=typeof E=="number"?{mainAxis:E,altAxis:E}:Object.assign({mainAxis:0,altAxis:0},E),v=e.modifiersData.offset?e.modifiersData.offset[e.placement]:null,F={x:0,y:0};if(w){if(o){var P,A=h==="y"?N:B,Q=h==="y"?H:W,U=h==="y"?"height":"width",ee=w[h],_e=ee+m[A],le=ee-m[Q],Ve=u?-T[U]/2:0,gt=b===$e?S[U]:T[U],Ie=b===$e?-T[U]:-S[U],Ge=e.elements.arrow,ke=u&&Ge?Je(Ge):{width:0,height:0},fe=e.modifiersData["arrow#persistent"]?e.modifiersData["arrow#persistent"].padding:Ut(),Le=fe[A],Ye=fe[Q],Se=Qe(0,S[U],ke[U]),yt=D?S[U]/2-Ve-Se-Le-x.mainAxis:gt-Se-Le-x.mainAxis,ei=D?-S[U]/2+Ve+Se+Ye+x.mainAxis:Ie+Se+Ye+x.mainAxis,Mt=e.elements.arrow&&ge(e.elements.arrow),ti=Mt?h==="y"?Mt.clientTop||0:Mt.clientLeft||0:0,$t=(P=v==null?void 0:v[h])!=null?P:0,ii=ee+yt-$t-ti,ri=ee+ei-$t,Rt=Qe(u?Xe(_e,ii):_e,ee,u?he(le,ri):le);w[h]=Rt,F[h]=Rt-ee}if(s){var Ot,ni=h==="x"?N:B,oi=h==="x"?H:W,De=w[y],ze=y==="y"?"height":"width",At=De+m[ni],Nt=De-m[oi],vt=[N,B].indexOf(_)!==-1,Bt=(Ot=v==null?void 0:v[y])!=null?Ot:0,It=vt?At:De-S[ze]-T[ze]-Bt+x.altAxis,Lt=vt?De+S[ze]+T[ze]-Bt-x.altAxis:Nt,Wt=u&&vt?Wr(It,De,Lt):Qe(u?It:At,De,u?Lt:Nt);w[y]=Wt,F[y]=Wt-De}e.modifiersData[i]=F}}var Zr={name:"preventOverflow",enabled:!0,phase:"main",fn:Fo,requiresIfExists:["offset"]};function ir(r){return{scrollLeft:r.scrollLeft,scrollTop:r.scrollTop}}function rr(r){return r===k(r)||!V(r)?et(r):ir(r)}function ko(r){var e=r.getBoundingClientRect(),t=Re(e.width)/r.offsetWidth||1,i=Re(e.height)/r.offsetHeight||1;return t!==1||i!==1}function nr(r,e,t){t===void 0&&(t=!1);var i=V(e),n=V(e)&&ko(e),o=ie(e),a=ce(r,n,t),s={scrollLeft:0,scrollTop:0},l={x:0,y:0};return(i||!i&&!t)&&((X(e)!=="body"||it(o))&&(s=rr(e)),V(e)?(l=ce(e,!0),l.x+=e.clientLeft,l.y+=e.clientTop):o&&(l.x=tt(o))),{x:a.left+s.scrollLeft-l.x,y:a.top+s.scrollTop-l.y,width:a.width,height:a.height}}function $o(r){var e=new Map,t=new Set,i=[];r.forEach(function(o){e.set(o.name,o)});function n(o){t.add(o.name);var a=[].concat(o.requires||[],o.requiresIfExists||[]);a.forEach(function(s){if(!t.has(s)){var l=e.get(s);l&&n(l)}}),i.push(o)}return r.forEach(function(o){t.has(o.name)||n(o)}),i}function or(r){var e=$o(r);return Br.reduce(function(t,i){return t.concat(e.filter(function(n){return n.phase===i}))},[])}function ar(r){var e;return function(){return e||(e=new Promise(function(t){Promise.resolve().then(function(){e=void 0,t(r())})})),e}}function sr(r){var e=r.reduce(function(t,i){var n=t[i.name];return t[i.name]=n?Object.assign({},n,i,{options:Object.assign({},n.options,i.options),data:Object.assign({},n.data,i.data)}):i,t},{});return Object.keys(e).map(function(t){return e[t]})}var Qr={placement:"bottom",modifiers:[],strategy:"absolute"};function en(){for(var r=arguments.length,e=new Array(r),t=0;t<r;t++)e[t]=arguments[t];return!e.some(function(i){return!(i&&typeof i.getBoundingClientRect=="function")})}function tn(r){r===void 0&&(r={});var e=r,t=e.defaultModifiers,i=t===void 0?[]:t,n=e.defaultOptions,o=n===void 0?Qr:n;return function(s,l,p){p===void 0&&(p=o);var d={placement:"bottom",orderedModifiers:[],options:Object.assign({},Qr,o),modifiersData:{},elements:{reference:s,popper:l},attributes:{},styles:{}},c=[],f=!1,u={state:d,setOptions:function(_){var b=typeof _=="function"?_(d.options):_;g(),d.options=Object.assign({},o,d.options,b),d.scrollParents={reference:de(s)?je(s):s.contextElement?je(s.contextElement):[],popper:je(l)};var D=or(sr([].concat(i,d.options.modifiers)));return d.orderedModifiers=D.filter(function(h){return h.enabled}),M(),u.update()},forceUpdate:function(){if(!f){var _=d.elements,b=_.reference,D=_.popper;if(en(b,D)){d.rects={reference:nr(b,ge(D),d.options.strategy==="fixed"),popper:Je(D)},d.reset=!1,d.placement=d.options.placement,d.orderedModifiers.forEach(function(x){return d.modifiersData[x.name]=Object.assign({},x.data)});for(var h=0;h<d.orderedModifiers.length;h++){if(d.reset===!0){d.reset=!1,h=-1;continue}var y=d.orderedModifiers[h],w=y.fn,S=y.options,T=S===void 0?{}:S,E=y.name;typeof w=="function"&&(d=w({state:d,options:T,name:E,instance:u})||d)}}}},update:ar(function(){return new Promise(function(m){u.forceUpdate(),m(d)})}),destroy:function(){g(),f=!0}};if(!en(s,l))return u;u.setOptions(p).then(function(m){!f&&p.onFirstUpdate&&p.onFirstUpdate(m)});function M(){d.orderedModifiers.forEach(function(m){var _=m.name,b=m.options,D=b===void 0?{}:b,h=m.effect;if(typeof h=="function"){var y=h({state:d,name:_,instance:u,options:D}),w=function(){};c.push(y||w)}})}function g(){c.forEach(function(m){return m()}),c=[]}return u}}var Ro=[Hr,Jr,Ur,Ir,Xr,Gr,Zr,jr,Kr],lr=tn({defaultModifiers:Ro});var pr="obsidian-media-db-plugin",dr="m.projects.code@gmail.com",ne="mediaDB",cr="0.5.2";function nn(r,e){if(e<=0)throw Error("size may not be zero or negative");return mi(r,e)}function ur(r){return/^[a-zA-Z_]+$/.test(r)}function on(r){return r.replace(/[\\,#%&{}/*<>$"@.?]*/g,"").replace(/:+/g," -")}function mr(r,e,t=!1){return r.replace(new RegExp("{{.*?}}","g"),i=>Oo(i,e,t))}function Oo(r,e,t){let i=r;i=i.substring(2),i=i.substring(0,i.length-2),i=i.trim();let n=i.split(":");if(n.length===1){let o=n[0].split("."),a=rn(o,e);return a===void 0?t?"":"{{ INVALID TEMPLATE TAG - object undefined }}":a}else if(n.length===2){let o=n[0],a=n[1].split("."),s=rn(a,e);return s===void 0?t?"":"{{ INVALID TEMPLATE TAG - object undefined }}":o==="LIST"?Array.isArray(s)?s.map(l=>`- ${l}`).join(`
`):"{{ INVALID TEMPLATE TAG - operator LIST is only applicable on an array }}":o==="ENUM"?Array.isArray(s)?s.join(", "):"{{ INVALID TEMPLATE TAG - operator ENUM is only applicable on an array }}":o==="FIRST"?Array.isArray(s)?s[0]:"{{ INVALID TEMPLATE TAG - operator FIRST is only applicable on an array }}":o==="LAST"?Array.isArray(s)?s[s.length-1]:"{{ INVALID TEMPLATE TAG - operator LAST is only applicable on an array }}":`{{ INVALID TEMPLATE TAG - unknown operator ${o} }}`}return"{{ INVALID TEMPLATE TAG }}"}function rn(r,e){let t=e;for(let i of r)t!==void 0&&(t=t[i]);return t}function an(r){let e=r.length;if(e===0)return"";let t=r[0].length;if(t===0)return"";for(let o of r)if(o.length!==t)return"";let i=[];for(let o=0;o<t;o++){let a=0;for(let s of r)s[o].length>a&&(a=s[o].length);i.push(a)}let n="";for(let o=0;o<e;o++){n+="|";for(let a=0;a<t;a++){let s=r[o][a];s+=" ".repeat(i[a]-s.length),n+=" "+s+" |"}if(n+=`
`,o===0){n+="|";for(let a=0;a<t;a++)n+=" "+"-".repeat(i[a])+" |";n+=`
`}}return n}function sn(r){return createFragment(e=>e.createDiv().innerHTML=r)}function Ao(r){return`${r.getMonth()+1}-${r.getDate()}-${r.getFullYear()}`}function No(r){return`${r.getHours()}-${r.getMinutes()}-${r.getSeconds()}`}function ln(r){return`${Ao(r)} ${No(r)}`}function mi(r,e){return(r%e+e)%e}function fr(r){return r.charAt(0).toUpperCase()+r.slice(1)}var rt=class extends Error{constructor(e){super(e)}},Yt=class extends Error{constructor(e){super(e)}};function $(r,e,t){for(let i in r)r[i]=e.hasOwnProperty(i)?e[i]:t[i]}function zt(r){return r.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b([A-Z]+)([A-Z])([a-z])/,"$1 $2$3").replace(/^./,function(e){return e.toUpperCase()})}function hr(r){return!!r.plugins.plugins["templater-obsidian"]}async function pn(r,e){let t=r.plugins.plugins["templater-obsidian"];t&&!(t!=null&&t.settings.trigger_on_file_creation)&&await t.templater.overwrite_file_commands(e)}var gr=class{constructor(e,t,i){this.owner=e,this.containerEl=t,t.on("click",".suggestion-item",this.onSuggestionClick.bind(this)),t.on("mousemove",".suggestion-item",this.onSuggestionMouseover.bind(this)),i.register([],"ArrowUp",n=>{if(!n.isComposing)return this.setSelectedItem(this.selectedItem-1,!0),!1}),i.register([],"ArrowDown",n=>{if(!n.isComposing)return this.setSelectedItem(this.selectedItem+1,!0),!1}),i.register([],"Enter",n=>{if(!n.isComposing)return this.useSelectedItem(n),!1})}onSuggestionClick(e,t){e.preventDefault();let i=this.suggestions.indexOf(t);this.setSelectedItem(i,!1),this.useSelectedItem(e)}onSuggestionMouseover(e,t){let i=this.suggestions.indexOf(t);this.setSelectedItem(i,!1)}setSuggestions(e){this.containerEl.empty();let t=[];e.forEach(i=>{let n=this.containerEl.createDiv("suggestion-item");this.owner.renderSuggestion(i,n),t.push(n)}),this.values=e,this.suggestions=t,this.setSelectedItem(0,!1)}useSelectedItem(e){let t=this.values[this.selectedItem];t&&this.owner.selectSuggestion(t,e)}setSelectedItem(e,t){let i=this.suggestions.length>0?nn(e,this.suggestions.length):0,n=this.suggestions[this.selectedItem],o=this.suggestions[i];n==null||n.removeClass("is-selected"),o==null||o.addClass("is-selected"),this.selectedItem=i,t&&o.scrollIntoView(!1)}},St=class{constructor(e,t){this.app=e,this.inputEl=t,this.scope=new dn.Scope,this.suggestEl=createDiv("suggestion-container");let i=this.suggestEl.createDiv("suggestion");this.suggest=new gr(this,i,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",n=>{n.preventDefault()})}onInputChanged(){let e=this.inputEl.value,t=this.getSuggestions(e);t.length>0&&(this.suggest.setSuggestions(t),this.open(this.app.dom.appContainerEl,this.inputEl))}open(e,t){this.app.keymap.pushScope(this.scope),e.appendChild(this.suggestEl),this.popper=lr(t,this.suggestEl,{placement:"bottom-start",modifiers:[{name:"sameWidth",enabled:!0,fn:({state:i,instance:n})=>{let o=`${i.rects.reference.width}px`;i.styles.popper.width!==o&&(i.styles.popper.width=o,n.update())},phase:"beforeWrite",requires:["computeStyles"]}]})}close(){var e;this.app.keymap.popScope(this.scope),this.suggest.setSuggestions([]),(e=this.popper)==null||e.destroy(),this.suggestEl.detach()}};var Me=class extends St{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),i=[],n=e.toLowerCase();return t.forEach(o=>{o instanceof cn.TFolder&&o.path.toLowerCase().contains(n)&&i.push(o)}),i}renderSuggestion(e,t){t.setText(e.path)}selectSuggestion(e){this.inputEl.value=e.path,this.inputEl.trigger("input"),this.close()}};var un=require("obsidian"),ve=class extends St{getSuggestions(e){let t=this.app.vault.getAllLoadedFiles(),i=[],n=e.toLowerCase();return t.forEach(o=>{o instanceof un.TFile&&o.name.toLowerCase().contains(n)&&i.push(o)}),i}renderSuggestion(e,t){t.setText(e.path)}selectSuggestion(e){this.inputEl.value=e.path,this.inputEl.trigger("input"),this.close()}};function oe(){}function yr(r){return r()}function fi(){return Object.create(null)}function Ee(r){r.forEach(yr)}function hi(r){return typeof r=="function"}function Dt(r,e){return r!=r?e==e:r!==e||r&&typeof r=="object"||typeof r=="function"}function mn(r){return Object.keys(r).length===0}var Mr=typeof window!="undefined"?window:typeof globalThis!="undefined"?globalThis:global;var gi=class r{constructor(e){K(this,"_listeners","WeakMap"in Mr?new WeakMap:void 0);K(this,"_observer");K(this,"options");this.options=e}observe(e,t){return this._listeners.set(e,t),this._getObserver().observe(e,this.options),()=>{this._listeners.delete(e),this._observer.unobserve(e)}}_getObserver(){var e;return(e=this._observer)!=null?e:this._observer=new ResizeObserver(t=>{var i;for(let n of t)r.entries.set(n.target,n),(i=this._listeners.get(n.target))==null||i(n)})}};gi.entries="WeakMap"in Mr?new WeakMap:void 0;var fn=!1;function hn(){fn=!0}function gn(){fn=!1}function I(r,e){r.appendChild(e)}function yn(r,e,t){let i=Mn(r);if(!i.getElementById(e)){let n=R("style");n.id=e,n.textContent=t,Lo(i,n)}}function Mn(r){if(!r)return document;let e=r.getRootNode?r.getRootNode():r.ownerDocument;return e&&e.host?e:r.ownerDocument}function Lo(r,e){return I(r.head||r,e),e.sheet}function G(r,e,t){r.insertBefore(e,t||null)}function L(r){r.parentNode&&r.parentNode.removeChild(r)}function Kt(r,e){for(let t=0;t<r.length;t+=1)r[t]&&r[t].d(e)}function R(r){return document.createElement(r)}function nt(r){return document.createTextNode(r)}function qe(){return nt(" ")}function yi(){return nt("")}function Xt(r,e,t,i){return r.addEventListener(e,t,i),()=>r.removeEventListener(e,t,i)}function O(r,e,t){t==null?r.removeAttribute(e):r.getAttribute(e)!==t&&r.setAttribute(e,t)}function vn(r){return Array.from(r.childNodes)}function Mi(r,e){e=""+e,r.data!==e&&(r.data=e)}function vi(r,e){r.value=e==null?"":e}function Jt(r,e,t,i){t==null?r.style.removeProperty(e):r.style.setProperty(e,t,i?"important":"")}function vr(r,e,t){for(let i=0;i<r.options.length;i+=1){let n=r.options[i];if(n.__value===e){n.selected=!0;return}}(!t||e!==void 0)&&(r.selectedIndex=-1)}function bn(r){let e=r.querySelector(":checked");return e&&e.__value}function wn(r){let e={};return r.childNodes.forEach(t=>{e[t.slot||"default"]=!0}),e}var Ue;function Ae(r){Ue=r}function Tn(){if(!Ue)throw new Error("Function called outside component initialization");return Ue}function br(r){Tn().$$.on_mount.push(r)}var ot=[];var bi=[],Ct=[],_n=[],Vo=Promise.resolve(),xr=!1;function Sn(){xr||(xr=!0,Vo.then(wi))}function at(r){Ct.push(r)}var wr=new Set,Et=0;function wi(){if(Et!==0)return;let r=Ue;do{try{for(;Et<ot.length;){let e=ot[Et];Et++,Ae(e),Go(e.$$)}}catch(e){throw ot.length=0,Et=0,e}for(Ae(null),ot.length=0,Et=0;bi.length;)bi.pop()();for(let e=0;e<Ct.length;e+=1){let t=Ct[e];wr.has(t)||(wr.add(t),t())}Ct.length=0}while(ot.length);for(;_n.length;)_n.pop()();xr=!1,wr.clear(),Ae(r)}function Go(r){if(r.fragment!==null){r.update(),Ee(r.before_update);let e=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,e),r.after_update.forEach(at)}}function Dn(r){let e=[],t=[];Ct.forEach(i=>r.indexOf(i)===-1?e.push(i):t.push(i)),t.forEach(i=>i()),Ct=e}var xi=new Set,st;function lt(){st={r:0,c:[],p:st}}function pt(){st.r||Ee(st.c),st=st.p}function Y(r,e){r&&r.i&&(xi.delete(r),r.i(e))}function se(r,e,t,i){if(r&&r.o){if(xi.has(r))return;xi.add(r),st.c.push(()=>{xi.delete(r),i&&(t&&r.d(1),i())}),r.o(e)}else i&&i()}function Ne(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}var Yo=["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"],zo=new Set([...Yo]);function Ti(r){r&&r.c()}function Zt(r,e,t){let{fragment:i,after_update:n}=r.$$;i&&i.m(e,t),at(()=>{let o=r.$$.on_mount.map(yr).filter(hi);r.$$.on_destroy?r.$$.on_destroy.push(...o):Ee(o),r.$$.on_mount=[]}),n.forEach(at)}function Qt(r,e){let t=r.$$;t.fragment!==null&&(Dn(t.after_update),Ee(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function Xo(r,e){r.$$.dirty[0]===-1&&(ot.push(r),Sn(),r.$$.dirty.fill(0)),r.$$.dirty[e/31|0]|=1<<e%31}function Pt(r,e,t,i,n,o,a=null,s=[-1]){let l=Ue;Ae(r);let p=r.$$={fragment:null,ctx:[],props:o,update:oe,not_equal:n,bound:fi(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(l?l.$$.context:[])),callbacks:fi(),dirty:s,skip_bound:!1,root:e.target||l.$$.root};a&&a(p.root);let d=!1;if(p.ctx=t?t(r,e.props||{},(c,f,...u)=>{let M=u.length?u[0]:f;return p.ctx&&n(p.ctx[c],p.ctx[c]=M)&&(!p.skip_bound&&p.bound[c]&&p.bound[c](M),d&&Xo(r,c)),f}):[],p.update(),d=!0,Ee(p.before_update),p.fragment=i?i(p.ctx):!1,e.target){if(e.hydrate){hn();let c=vn(e.target);p.fragment&&p.fragment.l(c),c.forEach(L)}else p.fragment&&p.fragment.c();e.intro&&Y(r.$$.fragment),Zt(r,e.target,e.anchor),gn(),wi()}Ae(l)}var Jo;typeof HTMLElement=="function"&&(Jo=class extends HTMLElement{constructor(e,t,i){super();K(this,"$$ctor");K(this,"$$s");K(this,"$$c");K(this,"$$cn",!1);K(this,"$$d",{});K(this,"$$r",!1);K(this,"$$p_d",{});K(this,"$$l",{});K(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=t,i&&this.attachShadow({mode:"open"})}addEventListener(e,t,i){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(t),this.$$c){let n=this.$$c.$on(e,t);this.$$l_u.set(t,n)}super.addEventListener(e,t,i)}removeEventListener(e,t,i){if(super.removeEventListener(e,t,i),this.$$c){let n=this.$$l_u.get(t);n&&(n(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(o){return()=>{let a;return{c:function(){a=R("slot"),o!=="default"&&O(a,"name",o)},m:function(p,d){G(p,a,d)},d:function(p){p&&L(a)}}}};if(await Promise.resolve(),!this.$$cn||this.$$c)return;let t={},i=wn(this);for(let o of this.$$s)o in i&&(t[o]=[e(o)]);for(let o of this.attributes){let a=this.$$g_p(o.name);a in this.$$d||(this.$$d[a]=Tr(a,o.value,this.$$p_d,"toProp"))}for(let o in this.$$p_d)!(o in this.$$d)&&this[o]!==void 0&&(this.$$d[o]=this[o],delete this[o]);this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});let n=()=>{this.$$r=!0;for(let o in this.$$p_d)if(this.$$d[o]=this.$$c.$$.ctx[this.$$c.$$.props[o]],this.$$p_d[o].reflect){let a=Tr(o,this.$$d[o],this.$$p_d,"toAttribute");a==null?this.removeAttribute(this.$$p_d[o].attribute||o):this.setAttribute(this.$$p_d[o].attribute||o,a)}this.$$r=!1};this.$$c.$$.after_update.push(n),n();for(let o in this.$$l)for(let a of this.$$l[o]){let s=this.$$c.$on(o,a);this.$$l_u.set(a,s)}this.$$l={}}}attributeChangedCallback(e,t,i){var n;this.$$r||(e=this.$$g_p(e),this.$$d[e]=Tr(e,i,this.$$p_d,"toProp"),(n=this.$$c)==null||n.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===e||!this.$$p_d[t].attribute&&t.toLowerCase()===e)||e}});function Tr(r,e,t,i){var o;let n=(o=t[r])==null?void 0:o.type;if(e=n==="Boolean"&&typeof e!="boolean"?e!=null:e,!i||!t[r])return e;if(i==="toAttribute")switch(n){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e==null?null:e;default:return e}else switch(n){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}var Be=class{constructor(){K(this,"$$");K(this,"$$set")}$destroy(){Qt(this,1),this.$destroy=oe}$on(e,t){if(!hi(t))return oe;let i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(t),()=>{let n=i.indexOf(t);n!==-1&&i.splice(n,1)}}$set(e){this.$$set&&!mn(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}};var En="4";typeof window!="undefined"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(En);var Cn=["default","remap","remove"],Ft=class r{constructor(e,t){this.type=e,this.properties=t!=null?t:[]}validate(){console.debug(`MDB | validated property mappings for ${this.type}`);for(let e of this.properties){let t=e.validate();if(!t.res)return{res:!1,err:t.err}}for(let e of this.getMappedProperties()){let t=this.getMappedProperties().filter(i=>i.newProperty===e.newProperty);if(t.length!==0){if(t.length!==1)return{res:!1,err:new Yt(`Multiple remapped properties (${t.map(i=>i.toString()).toString()}) may not share the same name.`)}}}for(let e of this.getMappedProperties())if(this.properties.filter(i=>i.newProperty===e.property).length!==0)return{res:!1,err:new Yt(`Remapped property (${e}) may not share it's new name with an existing property.`)};return{res:!0}}getMappedProperties(){return this.properties.filter(e=>e.mapping==="remap")}copy(){let e=new r(this.type);for(let t of this.properties){let i=new dt(t.property,t.newProperty,t.mapping,t.locked);e.properties.push(i)}return e}},dt=class{constructor(e,t,i,n){this.property=e,this.newProperty=t,this.mapping=i,this.locked=n!=null?n:!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 Fn=require("obsidian");function Zo(r){yn(r,"svelte-pwdquc",".icon-wrapper.svelte-pwdquc{display:inline-block;position:relative;width:20px}.icon.svelte-pwdquc{position:absolute;height:20px;width:20px;top:calc(50% - 10px)}")}function Pn(r){let e,t;return{c(){e=R("div"),t=R("div"),O(t,"class","icon svelte-pwdquc"),O(e,"class","icon-wrapper svelte-pwdquc")},m(i,n){G(i,e,n),I(e,t),r[3](t)},p:oe,d(i){i&&L(e),r[3](null)}}}function Qo(r){let e,t=r[0].length>0&&Pn(r);return{c(){t&&t.c(),e=yi()},m(i,n){t&&t.m(i,n),G(i,e,n)},p(i,[n]){i[0].length>0?t?t.p(i,n):(t=Pn(i),t.c(),t.m(e.parentNode,e)):t&&(t.d(1),t=null)},i:oe,o:oe,d(i){i&&L(e),t&&t.d(i)}}}function ea(r,e,t){let{iconName:i=""}=e,{iconSize:n=20}=e,o;br(()=>{(0,Fn.setIcon)(o,i,n)});function a(s){bi[s?"unshift":"push"](()=>{o=s,t(1,o)})}return r.$$set=s=>{"iconName"in s&&t(0,i=s.iconName),"iconSize"in s&&t(2,n=s.iconSize)},[i,o,n,a]}var _r=class extends Be{constructor(e){super(),Pt(this,e,ea,Qo,Dt,{iconName:0,iconSize:2},Zo)}},kn=_r;function $n(r,e,t){let i=r.slice();return i[7]=e[t],i[8]=e,i[9]=t,i}function ta(r,e,t){let i=r.slice();return i[10]=e[t],i}function ia(r){let e,t,i,n,o,a,s=Ne(Cn),l=[];for(let c=0;c<s.length;c+=1)l[c]=na(ta(r,s,c));function p(){r[3].call(e,r[8],r[9])}let d=r[7].mapping==="remap"&&Rn(r);return{c(){e=R("select");for(let c=0;c<l.length;c+=1)l[c].c();t=qe(),d&&d.c(),i=yi(),O(e,"class","dropdown"),r[7].mapping===void 0&&at(p)},m(c,f){G(c,e,f);for(let u=0;u<l.length;u+=1)l[u]&&l[u].m(e,null);vr(e,r[7].mapping,!0),G(c,t,f),d&&d.m(c,f),G(c,i,f),n=!0,o||(a=Xt(e,"change",p),o=!0)},p(c,f){r=c,f&1&&vr(e,r[7].mapping),r[7].mapping==="remap"?d?(d.p(r,f),f&1&&Y(d,1)):(d=Rn(r),d.c(),Y(d,1),d.m(i.parentNode,i)):d&&(lt(),se(d,1,1,()=>{d=null}),pt())},i(c){n||(Y(d),n=!0)},o(c){se(d),n=!1},d(c){c&&(L(e),L(t),L(i)),Kt(l,c),d&&d.d(c),o=!1,a()}}}function ra(r){let e;return{c(){e=R("div"),e.textContent="property can not be remapped",O(e,"class","media-db-plugin-property-binding-text")},m(t,i){G(t,e,i)},p:oe,i:oe,o:oe,d(t){t&&L(e)}}}function na(r){let e,t;return{c(){e=R("option"),e.textContent=`${r[10]} `,e.__value=t=r[10],vi(e,e.__value)},m(i,n){G(i,e,n)},p:oe,d(i){i&&L(e)}}}function Rn(r){let e,t,i,n,o,a,s;e=new kn({props:{iconName:"arrow-right"}});function l(){r[4].call(n,r[8],r[9])}return{c(){Ti(e.$$.fragment),t=qe(),i=R("div"),n=R("input"),O(n,"type","text"),O(n,"spellcheck","false"),O(i,"class","media-db-plugin-property-mapping-to")},m(p,d){Zt(e,p,d),G(p,t,d),G(p,i,d),I(i,n),vi(n,r[7].newProperty),o=!0,a||(s=Xt(n,"input",l),a=!0)},p(p,d){r=p,d&1&&n.value!==r[7].newProperty&&vi(n,r[7].newProperty)},i(p){o||(Y(e.$$.fragment,p),o=!0)},o(p){se(e.$$.fragment,p),o=!1},d(p){p&&(L(t),L(i)),Qt(e,p),a=!1,s()}}}function On(r){let e,t,i,n,o=r[7].property+"",a,s,l,p,d,c,f=[ra,ia],u=[];function M(g,m){return g[7].locked?0:1}return l=M(r,-1),p=u[l]=f[l](r),{c(){e=R("div"),t=R("div"),i=R("pre"),n=R("code"),a=nt(o),s=qe(),p.c(),d=qe(),O(i,"class","media-db-plugin-property-mapping-element-property-name"),O(t,"class","media-db-plugin-property-mapping-element-property-name-wrapper"),O(e,"class","media-db-plugin-property-mapping-element")},m(g,m){G(g,e,m),I(e,t),I(t,i),I(i,n),I(n,a),I(e,s),u[l].m(e,null),I(e,d),c=!0},p(g,m){(!c||m&1)&&o!==(o=g[7].property+"")&&Mi(a,o);let _=l;l=M(g,m),l===_?u[l].p(g,m):(lt(),se(u[_],1,1,()=>{u[_]=null}),pt(),p=u[l],p?p.p(g,m):(p=u[l]=f[l](g),p.c()),Y(p,1),p.m(e,d))},i(g){c||(Y(p),c=!0)},o(g){se(p),c=!1},d(g){g&&L(e),u[l].d()}}}function An(r){var n,o;let e,t=((o=(n=r[2])==null?void 0:n.err)==null?void 0:o.message)+"",i;return{c(){e=R("div"),i=nt(t),O(e,"class","media-db-plugin-property-mapping-validation")},m(a,s){G(a,e,s),I(e,i)},p(a,s){var l,p;s&4&&t!==(t=((p=(l=a[2])==null?void 0:l.err)==null?void 0:p.message)+"")&&Mi(i,t)},d(a){a&&L(e)}}}function oa(r){var D;let e,t,i=fr(r[0].type)+"",n,o,a,s,l,p,d,c,f,u,M,g=Ne(r[0].properties),m=[];for(let h=0;h<g.length;h+=1)m[h]=On($n(r,g,h));let _=h=>se(m[h],1,1,()=>{m[h]=null}),b=!((D=r[2])!=null&&D.res)&&An(r);return{c(){var h;e=R("div"),t=R("div"),n=nt(i),o=qe(),a=R("div");for(let y=0;y<m.length;y+=1)m[y].c();s=qe(),b&&b.c(),l=qe(),p=R("button"),d=nt("Save"),O(t,"class","setting-item-name"),O(a,"class","media-db-plugin-property-mappings-container"),O(p,"class",c="media-db-plugin-property-mappings-save-button "+((h=r[2])!=null&&h.res?"mod-cta":"mod-muted")),O(e,"class","media-db-plugin-property-mappings-model-container")},m(h,y){G(h,e,y),I(e,t),I(t,n),I(e,o),I(e,a);for(let w=0;w<m.length;w+=1)m[w]&&m[w].m(a,null);I(e,s),b&&b.m(e,null),I(e,l),I(e,p),I(p,d),f=!0,u||(M=Xt(p,"click",r[5]),u=!0)},p(h,[y]){var w,S;if((!f||y&1)&&i!==(i=fr(h[0].type)+"")&&Mi(n,i),y&1){g=Ne(h[0].properties);let T;for(T=0;T<g.length;T+=1){let E=$n(h,g,T);m[T]?(m[T].p(E,y),Y(m[T],1)):(m[T]=On(E),m[T].c(),Y(m[T],1),m[T].m(a,null))}for(lt(),T=g.length;T<m.length;T+=1)_(T);pt()}(w=h[2])!=null&&w.res?b&&(b.d(1),b=null):b?b.p(h,y):(b=An(h),b.c(),b.m(e,l)),(!f||y&4&&c!==(c="media-db-plugin-property-mappings-save-button "+((S=h[2])!=null&&S.res?"mod-cta":"mod-muted")))&&O(p,"class",c)},i(h){if(!f){for(let y=0;y<g.length;y+=1)Y(m[y]);f=!0}},o(h){m=m.filter(Boolean);for(let y=0;y<m.length;y+=1)se(m[y]);f=!1},d(h){h&&L(e),Kt(m,h),b&&b.d(),u=!1,M()}}}function aa(r,e,t){let{model:i}=e,{save:n}=e,o;function a(d){t(2,o=d.validate())}function s(d,c){d[c].mapping=bn(this),t(0,i)}function l(d,c){d[c].newProperty=this.value,t(0,i)}let p=()=>{i.validate().res&&n(i)};return r.$$set=d=>{"model"in d&&t(0,i=d.model),"save"in d&&t(1,n=d.save)},r.$$.update=()=>{r.$$.dirty&1&&a(i)},[i,n,o,s,l,p]}var Sr=class extends Be{constructor(e){super(),Pt(this,e,aa,oa,Dt,{model:0,save:1})}},Bn=Sr;function In(r,e,t){let i=r.slice();return i[2]=e[t],i}function Ln(r){let e,t;return e=new Bn({props:{model:r[2],save:r[1]}}),{c(){Ti(e.$$.fragment)},m(i,n){Zt(e,i,n),t=!0},p(i,n){let o={};n&1&&(o.model=i[2]),n&2&&(o.save=i[1]),e.$set(o)},i(i){t||(Y(e.$$.fragment,i),t=!0)},o(i){se(e.$$.fragment,i),t=!1},d(i){Qt(e,i)}}}function sa(r){let e,t,i=Ne(r[0]),n=[];for(let a=0;a<i.length;a+=1)n[a]=Ln(In(r,i,a));let o=a=>se(n[a],1,1,()=>{n[a]=null});return{c(){e=R("div");for(let a=0;a<n.length;a+=1)n[a].c();O(e,"class","setting-item"),Jt(e,"display","flex"),Jt(e,"gap","10px"),Jt(e,"flex-direction","column"),Jt(e,"align-items","stretch")},m(a,s){G(a,e,s);for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(e,null);t=!0},p(a,[s]){if(s&3){i=Ne(a[0]);let l;for(l=0;l<i.length;l+=1){let p=In(a,i,l);n[l]?(n[l].p(p,s),Y(n[l],1)):(n[l]=Ln(p),n[l].c(),Y(n[l],1),n[l].m(e,null))}for(lt(),l=i.length;l<n.length;l+=1)o(l);pt()}},i(a){if(!t){for(let s=0;s<i.length;s+=1)Y(n[s]);t=!0}},o(a){n=n.filter(Boolean);for(let s=0;s<n.length;s+=1)se(n[s]);t=!1},d(a){a&&L(e),Kt(n,a)}}}function la(r,e,t){let{models:i=[]}=e,{save:n}=e;return r.$$set=o=>{"models"in o&&t(0,i=o.models),"save"in o&&t(1,n=o.save)},[i,n]}var Dr=class extends Be{constructor(e){super(),Pt(this,e,la,sa,Dt,{models:0,save:1})}},Wn=Dr;var Er=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 e=structuredClone(this);return delete e.userData,e}};var me=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},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"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},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"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},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"manga","light-novel"]}getMediaType(){return"manga"}getSummary(){return this.title+" ("+this.year+")"}};var pe=class extends Z{constructor(e={}){super(),this.developers=void 0,this.publishers=void 0,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},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"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={},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"wiki"]}getMediaType(){return"wiki"}getWithOutUserData(){let e=structuredClone(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},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"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},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"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.isbn=void 0,this.isbn13=void 0,this.released=void 0,this.userData={read:void 0,lastRead:void 0,personalRating:void 0},$(this,e,this),e.hasOwnProperty("userData")||$(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ne,"book"]}getMediaType(){return"book"}getSummary(){return this.englishTitle+" ("+this.year+") - "+this.author}};var Pe=["movie","series","manga","game","wiki","musicRelease","boardgame","book"],_i=class{constructor(){}updateTemplates(e){this.mediaFileNameTemplateMap=new Map,this.mediaFileNameTemplateMap.set("movie",e.movieFileNameTemplate),this.mediaFileNameTemplateMap.set("series",e.seriesFileNameTemplate),this.mediaFileNameTemplateMap.set("manga",e.mangaFileNameTemplate),this.mediaFileNameTemplateMap.set("game",e.gameFileNameTemplate),this.mediaFileNameTemplateMap.set("wiki",e.wikiFileNameTemplate),this.mediaFileNameTemplateMap.set("musicRelease",e.musicReleaseFileNameTemplate),this.mediaFileNameTemplateMap.set("boardgame",e.boardgameFileNameTemplate),this.mediaFileNameTemplateMap.set("book",e.bookFileNameTemplate),this.mediaTemplateMap=new Map,this.mediaTemplateMap.set("movie",e.movieTemplate),this.mediaTemplateMap.set("series",e.seriesTemplate),this.mediaTemplateMap.set("manga",e.mangaTemplate),this.mediaTemplateMap.set("game",e.gameTemplate),this.mediaTemplateMap.set("wiki",e.wikiTemplate),this.mediaTemplateMap.set("musicRelease",e.musicReleaseTemplate),this.mediaTemplateMap.set("boardgame",e.boardgameTemplate),this.mediaTemplateMap.set("book",e.bookTemplate)}updateFolders(e){this.mediaFolderMap=new Map,this.mediaFolderMap.set("movie",e.movieFolder),this.mediaFolderMap.set("series",e.seriesFolder),this.mediaFolderMap.set("manga",e.mangaFolder),this.mediaFolderMap.set("game",e.gameFolder),this.mediaFolderMap.set("wiki",e.wikiFolder),this.mediaFolderMap.set("musicRelease",e.musicReleaseFolder),this.mediaFolderMap.set("boardgame",e.boardgameFolder),this.mediaFolderMap.set("book",e.bookFolder)}getFileName(e){return mr(this.mediaFileNameTemplateMap.get(e.getMediaType()),e,!0)}async getTemplate(e,t){let i=this.mediaTemplateMap.get(e.getMediaType());if(!i)return"";let n=t.vault.getAbstractFileByPath(i);if((!n||n instanceof Er.TFolder)&&(n=t.vault.getFiles().filter(a=>a.name===i).first(),!n))return"";let o=await t.vault.cachedRead(n);return mr(o,e)}async getFolder(e,t){let i=this.mediaFolderMap.get(e.getMediaType());i||(i="/"),await t.vault.adapter.exists(i)||await t.vault.createFolder(i);let n=t.vault.getAbstractFileByPath(i);if(!(n instanceof Er.TFolder))throw Error(`Expected ${n} to be instance of TFolder`);return n}createMediaTypeModelFromMediaType(e,t){if(t==="movie")return new me(e);if(t==="series")return new Ce(e);if(t==="manga")return new ct(e);if(t==="game")return new pe(e);if(t==="wiki")return new ut(e);if(t==="musicRelease")return new mt(e);if(t==="boardgame")return new ft(e);if(t==="book")return new ht(e)}};var j={OMDbKey:"",MobyGamesKey:"",sfwFilter:!0,templates:!0,customDateFormat:"L",openNoteInNewTab:!0,useDefaultFrontMatter:!0,enableTemplaterIntegration:!1,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:[]},pa=["type","id","dataSource"];function jn(r){let e=j,t=[];for(let i of Pe){let o=r.mediaTypeManager.createMediaTypeModelFromMediaType({},i).toMetaDataObject(),a=new Ft(i);for(let s of Object.keys(o))a.properties.push(new dt(s,"","default",pa.contains(s)));t.push(a)}return e.propertyMappingModels=t,e}var Si=class extends C.PluginSettingTab{constructor(e,t){super(e,t),this.plugin=t}display(){let{containerEl:e}=this;if(e.empty(),e.createEl("h2",{text:"Media DB Plugin Settings"}),new C.Setting(e).setName("OMDb API key").setDesc('API key for "www.omdbapi.com".').addText(t=>{t.setPlaceholder("API key").setValue(this.plugin.settings.OMDbKey).onChange(i=>{this.plugin.settings.OMDbKey=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Moby Games key").setDesc('API key for "www.mobygames.com".').addText(t=>{t.setPlaceholder("API key").setValue(this.plugin.settings.MobyGamesKey).onChange(i=>{this.plugin.settings.MobyGamesKey=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("SFW filter").setDesc("Only shows SFW results for APIs that offer filtering.").addToggle(t=>{t.setValue(this.plugin.settings.sfwFilter).onChange(i=>{this.plugin.settings.sfwFilter=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Resolve {{ tags }} in templates").setDesc("Whether to resolve {{ tags }} in templates. The spaces inside the curly braces are important.").addToggle(t=>{t.setValue(this.plugin.settings.templates).onChange(i=>{this.plugin.settings.templates=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Date format").setDesc(sn("Your custom date format. Use <em>'YYYY-MM-DD'</em> for example.<br>For more syntax, refer to <a href='https://momentjs.com/docs/#/displaying/format/'>format reference</a>.<br>Your current syntax looks like this: <b><a id='media-db-dateformat-preview' style='pointer-events: none; cursor: default; text-decoration: none;'>"+this.plugin.dateFormatter.getPreview()+"</a></b>")).addText(t=>{t.setPlaceholder(j.customDateFormat).setValue(this.plugin.settings.customDateFormat===j.customDateFormat?"":this.plugin.settings.customDateFormat).onChange(i=>{let n=i||j.customDateFormat;this.plugin.settings.customDateFormat=n,document.getElementById("media-db-dateformat-preview").textContent=this.plugin.dateFormatter.getPreview(n),this.plugin.saveSettings()})}),new C.Setting(e).setName("Open note in new tab").setDesc("Open the newly created note in a new tab.").addToggle(t=>{t.setValue(this.plugin.settings.openNoteInNewTab).onChange(i=>{this.plugin.settings.openNoteInNewTab=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Use default front matter").setDesc("Whether to use the default front matter. If disabled, the front matter from the template will be used. Same as mapping everything to remove.").addToggle(t=>{t.setValue(this.plugin.settings.useDefaultFrontMatter).onChange(i=>{this.plugin.settings.useDefaultFrontMatter=i,this.plugin.saveSettings(),this.display()})}),new C.Setting(e).setName("Enable Templater integration").setDesc("Enable integration with the templater plugin, this also needs templater to be installed. Warning: Templater allows you to execute arbitrary JavaScript code and system commands.").addToggle(t=>{t.setValue(this.plugin.settings.enableTemplaterIntegration).onChange(i=>{this.plugin.settings.enableTemplaterIntegration=i,this.plugin.saveSettings()})}),e.createEl("h3",{text:"New File Location"}),new C.Setting(e).setName("Movie Folder").setDesc("Where newly imported movies should be placed.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.movieFolder).setValue(this.plugin.settings.movieFolder).onChange(i=>{this.plugin.settings.movieFolder=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Series Folder").setDesc("Where newly imported series should be placed.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.seriesFolder).setValue(this.plugin.settings.seriesFolder).onChange(i=>{this.plugin.settings.seriesFolder=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Manga Folder").setDesc("Where newly imported manga should be placed.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.mangaFolder).setValue(this.plugin.settings.mangaFolder).onChange(i=>{this.plugin.settings.mangaFolder=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Game Folder").setDesc("Where newly imported games should be placed.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.gameFolder).setValue(this.plugin.settings.gameFolder).onChange(i=>{this.plugin.settings.gameFolder=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Wiki Folder").setDesc("Where newly imported wiki articles should be placed.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.wikiFolder).setValue(this.plugin.settings.wikiFolder).onChange(i=>{this.plugin.settings.wikiFolder=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Music Folder").setDesc("Where newly imported music should be placed.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.musicReleaseFolder).setValue(this.plugin.settings.musicReleaseFolder).onChange(i=>{this.plugin.settings.musicReleaseFolder=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Board Game Folder").setDesc("Where newly imported board games should be places.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.boardgameFolder).setValue(this.plugin.settings.boardgameFolder).onChange(i=>{this.plugin.settings.boardgameFolder=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Book Folder").setDesc("Where newly imported books should be placed.").addSearch(t=>{new Me(this.app,t.inputEl),t.setPlaceholder(j.bookFolder).setValue(this.plugin.settings.bookFolder).onChange(i=>{this.plugin.settings.bookFolder=i,this.plugin.saveSettings()})}),e.createEl("h3",{text:"Template Settings"}),new C.Setting(e).setName("Movie template").setDesc("Template file to be used when creating a new note for a movie.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: movieTemplate.md").setValue(this.plugin.settings.movieTemplate).onChange(i=>{this.plugin.settings.movieTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Series template").setDesc("Template file to be used when creating a new note for a series.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: seriesTemplate.md").setValue(this.plugin.settings.seriesTemplate).onChange(i=>{this.plugin.settings.seriesTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Manga template").setDesc("Template file to be used when creating a new note for a manga.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: mangaTemplate.md").setValue(this.plugin.settings.mangaTemplate).onChange(i=>{this.plugin.settings.mangaTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Game template").setDesc("Template file to be used when creating a new note for a game.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: gameTemplate.md").setValue(this.plugin.settings.gameTemplate).onChange(i=>{this.plugin.settings.gameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Wiki template").setDesc("Template file to be used when creating a new note for a wiki entry.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: wikiTemplate.md").setValue(this.plugin.settings.wikiTemplate).onChange(i=>{this.plugin.settings.wikiTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Music Release template").setDesc("Template file to be used when creating a new note for a music release.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: musicReleaseTemplate.md").setValue(this.plugin.settings.musicReleaseTemplate).onChange(i=>{this.plugin.settings.musicReleaseTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Board Game template").setDesc("Template file to be used when creating a new note for a boardgame.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: boardgameTemplate.md").setValue(this.plugin.settings.boardgameTemplate).onChange(i=>{this.plugin.settings.boardgameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Book template").setDesc("Template file to be used when creating a new note for a book.").addSearch(t=>{new ve(this.app,t.inputEl),t.setPlaceholder("Example: bookTemplate.md").setValue(this.plugin.settings.bookTemplate).onChange(i=>{this.plugin.settings.bookTemplate=i,this.plugin.saveSettings()})}),e.createEl("h3",{text:"File Name Settings"}),new C.Setting(e).setName("Movie file name template").setDesc("Template for the file name used when creating a new note for a movie.").addText(t=>{t.setPlaceholder(`Example: ${j.movieFileNameTemplate}`).setValue(this.plugin.settings.movieFileNameTemplate).onChange(i=>{this.plugin.settings.movieFileNameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Series file name template").setDesc("Template for the file name used when creating a new note for a series.").addText(t=>{t.setPlaceholder(`Example: ${j.seriesFileNameTemplate}`).setValue(this.plugin.settings.seriesFileNameTemplate).onChange(i=>{this.plugin.settings.seriesFileNameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Manga file name template").setDesc("Template for the file name used when creating a new note for a manga.").addText(t=>{t.setPlaceholder(`Example: ${j.mangaFileNameTemplate}`).setValue(this.plugin.settings.mangaFileNameTemplate).onChange(i=>{this.plugin.settings.mangaFileNameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Game file name template").setDesc("Template for the file name used when creating a new note for a game.").addText(t=>{t.setPlaceholder(`Example: ${j.gameFileNameTemplate}`).setValue(this.plugin.settings.gameFileNameTemplate).onChange(i=>{this.plugin.settings.gameFileNameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Wiki file name template").setDesc("Template for the file name used when creating a new note for a wiki entry.").addText(t=>{t.setPlaceholder(`Example: ${j.wikiFileNameTemplate}`).setValue(this.plugin.settings.wikiFileNameTemplate).onChange(i=>{this.plugin.settings.wikiFileNameTemplate=i,this.plugin.saveSettings()})}),new C.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(t=>{t.setPlaceholder(`Example: ${j.musicReleaseFileNameTemplate}`).setValue(this.plugin.settings.musicReleaseFileNameTemplate).onChange(i=>{this.plugin.settings.musicReleaseFileNameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Board Game file name template").setDesc("Template for the file name used when creating a new note for a boardgame.").addText(t=>{t.setPlaceholder(`Example: ${j.boardgameFileNameTemplate}`).setValue(this.plugin.settings.boardgameFileNameTemplate).onChange(i=>{this.plugin.settings.boardgameFileNameTemplate=i,this.plugin.saveSettings()})}),new C.Setting(e).setName("Book file name template").setDesc("Template for the file name used when creating a new note for a book.").addText(t=>{t.setPlaceholder(`Example: ${j.bookFileNameTemplate}`).setValue(this.plugin.settings.bookFileNameTemplate).onChange(i=>{this.plugin.settings.bookFileNameTemplate=i,this.plugin.saveSettings()})}),this.plugin.settings.useDefaultFrontMatter){e.createEl("h3",{text:"Property Mappings"});let t=e.createEl("div");t.innerHTML=`
<p>Allow you to remap the metadata fields of newly created media db entries.</p>
<p>
The different options are:
<lu>
<li>"default": does no remapping and keeps the metadata field as it is</li>
<li>"remap": renames the metadata field to what ever you specify</li>
<li>"remove": removes the metadata field entirely</li>
</lu>
</p>
<p>
Don't forget to save your changes using the save button for each individual category.
</p>`,new Wn({target:this.containerEl,props:{models:this.plugin.settings.propertyMappingModels.map(i=>i.copy()),save:i=>{let n=[];for(let o of this.plugin.settings.propertyMappingModels)o.type===i.type?n.push(i):n.push(o);this.plugin.settings.propertyMappingModels=n,new C.Notice(`MDB: Property Mappings for ${i.type} saved successfully.`),this.plugin.saveSettings()}}})}}};var Di=class{constructor(){this.apis=[]}async query(e,t){console.debug(`MDB | api manager queried with "${e}"`);let i=this.apis.filter(n=>t.contains(n.apiName)).map(async n=>{try{return await n.searchByTitle(e)}catch(o){console.warn(o)}});return(await Promise.all(i)).flat()}async queryDetailedInfo(e){return await this.queryDetailedInfoById(e.id,e.dataSource)}async queryDetailedInfoById(e,t){for(let i of this.apis)if(i.apiName===t)return i.getById(e)}getApiByName(e){for(let t of this.apis)if(t.apiName===e)return t;return null}registerAPI(e){this.apis.push(e)}};var q=class{hasType(e){return this.types.contains(e)}hasTypeOverlap(e){return e.some(t=>this.hasType(t))}};var Ei=class extends q{constructor(t){super();this.apiDateFormat="DD MMM YYYY";this.plugin=t,this.apiName="OMDbAPI",this.apiDescription="A free API for Movies, Series and Games.",this.apiUrl="https://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(t){if(console.log(`MDB | api "${this.apiName}" queried by Title`),!this.plugin.settings.OMDbKey)throw Error(`MDB | API key for ${this.apiName} missing.`);let i=`https://www.omdbapi.com/?s=${encodeURIComponent(t)}&apikey=${this.plugin.settings.OMDbKey}`,n=await fetch(i);if(n.status===401)throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o=await n.json();if(o.Response==="False"){if(o.Error==="Movie not found!")return[];throw Error(`MDB | Received error from ${this.apiName}:
${JSON.stringify(o,void 0,4)}`)}if(!o.Search)return[];let a=[];for(let s of o.Search){let l=this.typeMappings.get(s.Type.toLowerCase());l!==void 0&&(l==="movie"?a.push(new me({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(t){var s,l,p,d,c,f,u,M,g,m,_,b,D,h,y,w,S,T,E,x,v,F,P,A,Q,U,ee,_e,le;if(console.log(`MDB | api "${this.apiName}" queried by ID`),!this.plugin.settings.OMDbKey)throw Error(`MDB | API key for ${this.apiName} missing.`);let i=`https://www.omdbapi.com/?i=${encodeURIComponent(t)}&apikey=${this.plugin.settings.OMDbKey}`,n=await fetch(i);if(n.status===401)throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o=await n.json();if(o.Response==="False")throw Error(`MDB | Received error from ${this.apiName}: ${o.Error}`);let a=this.typeMappings.get(o.Type.toLowerCase());if(a===void 0)throw Error(`${o.type.toLowerCase()} is an unsupported type.`);if(a==="movie")return new me({type:a,title:o.Title,englishTitle:o.Title,year:o.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${o.imdbID}/`,id:o.imdbID,plot:(s=o.Plot)!=null?s:"",genres:(p=(l=o.Genre)==null?void 0:l.split(", "))!=null?p:[],director:(c=(d=o.Director)==null?void 0:d.split(", "))!=null?c:[],writer:(u=(f=o.Writer)==null?void 0:f.split(", "))!=null?u:[],studio:["N/A"],duration:(M=o.Runtime)!=null?M:"unknown",onlineRating:Number.parseFloat((g=o.imdbRating)!=null?g:0),actors:(_=(m=o.Actors)==null?void 0:m.split(", "))!=null?_:[],image:(b=o.Poster)!=null?b:"",released:!0,streamingServices:[],premiere:(D=this.plugin.dateFormatter.format(o.Released,this.apiDateFormat))!=null?D:"unknown",userData:{watched:!1,lastWatched:"",personalRating:0}});if(a==="series")return new Ce({type:a,title:o.Title,englishTitle:o.Title,year:o.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${o.imdbID}/`,id:o.imdbID,plot:(h=o.Plot)!=null?h:"",genres:(w=(y=o.Genre)==null?void 0:y.split(", "))!=null?w:[],writer:(T=(S=o.Writer)==null?void 0:S.split(", "))!=null?T:[],studio:[],episodes:0,duration:(E=o.Runtime)!=null?E:"unknown",onlineRating:Number.parseFloat((x=o.imdbRating)!=null?x:0),actors:(F=(v=o.Actors)==null?void 0:v.split(", "))!=null?F:[],image:(P=o.Poster)!=null?P:"",released:!0,streamingServices:[],airing:!1,airedFrom:(A=this.plugin.dateFormatter.format(o.Released,this.apiDateFormat))!=null?A:"unknown",airedTo:"unknown",userData:{watched:!1,lastWatched:"",personalRating:0}});if(a==="game")return new pe({type:a,title:o.Title,englishTitle:o.Title,year:o.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${o.imdbID}/`,id:o.imdbID,developers:[],publishers:[],genres:(U=(Q=o.Genre)==null?void 0:Q.split(", "))!=null?U:[],onlineRating:Number.parseFloat((ee=o.imdbRating)!=null?ee:0),image:(_e=o.Poster)!=null?_e:"",released:!0,releaseDate:(le=this.plugin.dateFormatter.format(o.Released,this.apiDateFormat))!=null?le:"unknown",userData:{played:!1,personalRating:0}})}};var Ci=class extends q{constructor(t){super();this.apiDateFormat="YYYY-MM-DDTHH:mm:ssZ";this.plugin=t,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(t){var s,l,p,d,c,f,u,M,g,m,_,b,D,h,y,w,S,T,E;console.log(`MDB | api "${this.apiName}" queried by Title`);let i=`https://api.jikan.moe/v4/anime?q=${encodeURIComponent(t)}&limit=20${this.plugin.settings.sfwFilter?"&sfw":""}`,n=await fetch(i);if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o=await n.json(),a=[];for(let x of o.data){let v=this.typeMappings.get((s=x.type)==null?void 0:s.toLowerCase());v===void 0&&a.push(new me({subType:"",title:x.title,englishTitle:(l=x.title_english)!=null?l:x.title,year:(u=(f=x.year)!=null?f:(c=(d=(p=x.aired)==null?void 0:p.prop)==null?void 0:d.from)==null?void 0:c.year)!=null?u:"",dataSource:this.apiName,id:x.mal_id})),v==="movie"||v==="special"?a.push(new me({subType:v,title:x.title,englishTitle:(M=x.title_english)!=null?M:x.title,year:(D=(b=x.year)!=null?b:(_=(m=(g=x.aired)==null?void 0:g.prop)==null?void 0:m.from)==null?void 0:_.year)!=null?D:"",dataSource:this.apiName,id:x.mal_id})):(v==="series"||v==="ova")&&a.push(new Ce({subType:v,title:x.title,englishTitle:(h=x.title_english)!=null?h:x.title,year:(E=(T=x.year)!=null?T:(S=(w=(y=x.aired)==null?void 0:y.prop)==null?void 0:w.from)==null?void 0:S.year)!=null?E:"",dataSource:this.apiName,id:x.mal_id}))}return a}async getById(t){var l,p,d,c,f,u,M,g,m,_,b,D,h,y,w,S,T,E,x,v,F,P,A,Q,U,ee,_e,le,Ve,gt,Ie,Ge,ke,fe,Le,Ye,Se,yt,ei,Mt,ti,$t,ii,ri,Rt,Ot,ni,oi,De,ze,At,Nt,vt,Bt,It,Lt,Wt,$r,Rr,Or;console.log(`MDB | api "${this.apiName}" queried by ID`);let i=`https://api.jikan.moe/v4/anime/${encodeURIComponent(t)}/full`,n=await fetch(i);if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let a=(await n.json()).data,s=this.typeMappings.get((l=a.type)==null?void 0:l.toLowerCase());if(s===void 0)return new me({subType:"",title:a.title,englishTitle:(p=a.title_english)!=null?p:a.title,year:(M=(u=a.year)!=null?u:(f=(c=(d=a.aired)==null?void 0:d.prop)==null?void 0:c.from)==null?void 0:f.year)!=null?M:"",dataSource:this.apiName,url:a.url,id:a.mal_id,plot:a.synopsis,genres:(m=(g=a.genres)==null?void 0:g.map(te=>te.name))!=null?m:[],director:[],writer:[],studio:(b=(_=a.studios)==null?void 0:_.map(te=>te.name).join(", "))!=null?b:"unknown",duration:(D=a.duration)!=null?D:"unknown",onlineRating:(h=a.score)!=null?h:0,actors:[],image:(S=(w=(y=a.images)==null?void 0:y.jpg)==null?void 0:w.image_url)!=null?S:"",released:!0,premiere:(E=this.plugin.dateFormatter.format((T=a.aired)==null?void 0:T.from,this.apiDateFormat))!=null?E:"unknown",streamingServices:(v=(x=a.streaming)==null?void 0:x.map(te=>te.name))!=null?v:[],userData:{watched:!1,lastWatched:"",personalRating:0}});if(s==="movie"||s==="special")return new me({subType:s,title:a.title,englishTitle:(F=a.title_english)!=null?F:a.title,year:(ee=(U=a.year)!=null?U:(Q=(A=(P=a.aired)==null?void 0:P.prop)==null?void 0:A.from)==null?void 0:Q.year)!=null?ee:"",dataSource:this.apiName,url:a.url,id:a.mal_id,plot:a.synopsis,genres:(le=(_e=a.genres)==null?void 0:_e.map(te=>te.name))!=null?le:[],director:[],writer:[],studio:(gt=(Ve=a.studios)==null?void 0:Ve.map(te=>te.name).join(", "))!=null?gt:"unknown",duration:(Ie=a.duration)!=null?Ie:"unknown",onlineRating:(Ge=a.score)!=null?Ge:0,actors:[],image:(Le=(fe=(ke=a.images)==null?void 0:ke.jpg)==null?void 0:fe.image_url)!=null?Le:"",released:!0,premiere:(Se=this.plugin.dateFormatter.format((Ye=a.aired)==null?void 0:Ye.from,this.apiDateFormat))!=null?Se:"unknown",streamingServices:(ei=(yt=a.streaming)==null?void 0:yt.map(te=>te.name))!=null?ei:[],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=(ri=a.year)!=null?ri:(ii=($t=(ti=a.aired)==null?void 0:ti.prop)==null?void 0:$t.from)==null?void 0:ii.year)!=null?Rt:"",dataSource:this.apiName,url:a.url,id:a.mal_id,plot:a.synopsis,genres:(ni=(Ot=a.genres)==null?void 0:Ot.map(te=>te.name))!=null?ni:[],writer:[],studio:(De=(oi=a.studios)==null?void 0:oi.map(te=>te.name))!=null?De:[],episodes:a.episodes,duration:(ze=a.duration)!=null?ze:"unknown",onlineRating:(At=a.score)!=null?At:0,streamingServices:(vt=(Nt=a.streaming)==null?void 0:Nt.map(te=>te.name))!=null?vt:[],image:(Lt=(It=(Bt=a.images)==null?void 0:Bt.jpg)==null?void 0:It.image_url)!=null?Lt:"",released:!0,airedFrom:($r=this.plugin.dateFormatter.format((Wt=a.aired)==null?void 0:Wt.from,this.apiDateFormat))!=null?$r:"unknown",airedTo:(Or=this.plugin.dateFormatter.format((Rr=a.aired)==null?void 0:Rr.to,this.apiDateFormat))!=null?Or:"unknown",airing:a.airing,userData:{watched:!1,lastWatched:"",personalRating:0}})}};var Pi=class extends q{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 a,s,l,p,d,c,f,u,M,g,m,_,b,D,h,y,w,S,T,E,x;console.log(`MDB | api "${this.apiName}" queried by Title`);let t=`https://api.jikan.moe/v4/manga?q=${encodeURIComponent(e)}&limit=20${this.plugin.settings.sfwFilter?"&sfw":""}`,i=await fetch(t);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let n=await i.json(),o=[];for(let v of n.data){let F=this.typeMappings.get((a=v.type)==null?void 0:a.toLowerCase());o.push(new ct({subType:F,title:v.title,plot:v.synopsis,englishTitle:(s=v.title_english)!=null?s:v.title,alternateTitles:(p=(l=v.titles)==null?void 0:l.map(P=>P.title))!=null?p:[],year:(M=(u=v.year)!=null?u:(f=(c=(d=v.published)==null?void 0:d.prop)==null?void 0:c.from)==null?void 0:f.year)!=null?M:"",dataSource:this.apiName,url:v.url,id:v.mal_id,genres:(m=(g=v.genres)==null?void 0:g.map(P=>P.name))!=null?m:[],authors:(b=(_=v.authors)==null?void 0:_.map(P=>P.name))!=null?b:[],chapters:v.chapters,volumes:v.volumes,onlineRating:(D=v.score)!=null?D:0,image:(w=(y=(h=v.images)==null?void 0:h.jpg)==null?void 0:y.image_url)!=null?w:"",released:!0,publishedFrom:(T=new Date((S=v.published)==null?void 0:S.from).toLocaleDateString())!=null?T:"unknown",publishedTo:(x=new Date((E=v.published)==null?void 0:E.to).toLocaleDateString())!=null?x:"unknown",status:v.status,userData:{watched:!1,lastWatched:"",personalRating:0}}))}return o}async getById(e){var s,l,p,d,c,f,u,M,g,m,_,b,D,h,y,w,S,T,E,x,v,F,P;console.log(`MDB | api "${this.apiName}" queried by ID`);let t=`https://api.jikan.moe/v4/manga/${encodeURIComponent(e)}/full`,i=await fetch(t);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let o=(await i.json()).data,a=this.typeMappings.get((s=o.type)==null?void 0:s.toLowerCase());return new ct({subType:a,title:o.title,englishTitle:(l=o.title_english)!=null?l:o.title,alternateTitles:(d=(p=o.titles)==null?void 0:p.map(A=>A.title))!=null?d:[],year:(g=(M=o.year)!=null?M:(u=(f=(c=o.published)==null?void 0:c.prop)==null?void 0:f.from)==null?void 0:u.year)!=null?g:"",dataSource:this.apiName,url:o.url,id:o.mal_id,plot:(_=((m=o.synopsis)!=null?m:"unknown").replace(/"/g,"'"))!=null?_:"unknown",genres:(D=(b=o.genres)==null?void 0:b.map(A=>A.name))!=null?D:[],authors:(y=(h=o.authors)==null?void 0:h.map(A=>A.name))!=null?y:[],chapters:o.chapters,volumes:o.volumes,onlineRating:(w=o.score)!=null?w:0,image:(E=(T=(S=o.images)==null?void 0:S.jpg)==null?void 0:T.image_url)!=null?E:"",released:!0,publishedFrom:(v=new Date((x=o.published)==null?void 0:x.from).toLocaleDateString())!=null?v:"unknown",publishedTo:(P=new Date((F=o.published)==null?void 0:F.to).toLocaleDateString())!=null?P:"unknown",status:o.status,userData:{watched:!1,lastWatched:"",personalRating:0}})}};var Fi=class extends q{constructor(t){super();this.apiDateFormat="YYYY-MM-DDTHH:mm:ssZ";this.plugin=t,this.apiName="Wikipedia API",this.apiDescription="The API behind Wikipedia",this.apiUrl="https://www.wikipedia.com",this.types=["wiki"]}async searchByTitle(t){console.log(`MDB | api "${this.apiName}" queried by Title`);let i=`https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${encodeURIComponent(t)}&srlimit=20&utf8=&format=json&origin=*`,n=await fetch(i);if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o=await n.json();console.debug(o);let a=[];for(let s of o.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(t){var s;console.log(`MDB | api "${this.apiName}" queried by ID`);let i=`https://en.wikipedia.org/w/api.php?action=query&prop=info&pageids=${encodeURIComponent(t)}&inprop=url&format=json&origin=*`,n=await fetch(i);if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o=await n.json(),a=Object.entries((s=o==null?void 0:o.query)==null?void 0:s.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 Cr=require("obsidian");var ki=class extends q{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 t=`https://musicbrainz.org/ws/2/release-group?query=${encodeURIComponent(e)}&limit=20&fmt=json`,i=await(0,Cr.requestUrl)({url:t,headers:{"User-Agent":`${pr}/${cr} (${dr})`}});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let n=await i.json,o=[];for(let a of n["release-groups"])o.push(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(s=>s.name),subType:a["primary-type"]}));return o}async getById(e){console.log(`MDB | api "${this.apiName}" queried by ID`);let t=`https://musicbrainz.org/ws/2/release-group/${encodeURIComponent(e)}?inc=releases+artists+tags+ratings+genres&fmt=json`,i=await(0,Cr.requestUrl)({url:t,headers:{"User-Agent":`${pr}/${cr} (${dr})`}});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let n=await i.json;return new mt({type:"musicRelease",title:n.title,englishTitle:n.title,year:new Date(n["first-release-date"]).getFullYear().toString(),dataSource:this.apiName,url:"https://musicbrainz.org/release-group/"+n.id,id:n.id,image:"https://coverartarchive.org/release-group/"+n.id+"/front",artists:n["artist-credit"].map(o=>o.name),genres:n.genres.map(o=>o.name),subType:n["primary-type"],rating:n.rating.value*2,userData:{personalRating:0}})}};var Pr=require("obsidian");var $i=class extends q{constructor(t){super();this.apiDateFormat="DD MMM, YYYY";this.plugin=t,this.apiName="SteamAPI",this.apiDescription="A free API for all Steam games.",this.apiUrl="https://www.steampowered.com/",this.types=["game"],this.typeMappings=new Map,this.typeMappings.set("game","game")}async searchByTitle(t){console.log(`MDB | api "${this.apiName}" queried by Title`);let i=`https://steamcommunity.com/actions/SearchApps/${encodeURIComponent(t)}`,n=await(0,Pr.requestUrl)({url:i});if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o=await n.json,a=[];for(let s of o)a.push(new pe({type:"game",title:s.name,englishTitle:s.name,year:"",dataSource:this.apiName,id:s.appid}));return a}async getById(t){var a,s,l,p,d,c,f,u;console.log(`MDB | api "${this.apiName}" queried by ID`);let i=`https://store.steampowered.com/api/appdetails?appids=${encodeURIComponent(t)}&l=en`,n=await(0,Pr.requestUrl)({url:i});if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o;for(let[M,g]of Object.entries(await n.json))M===String(t)&&(o=g.data);if(!o)throw Error("MDB | API returned invalid data.");return new pe({type:"game",title:o.name,englishTitle:o.name,year:new Date(o.release_date.date).getFullYear().toString(),dataSource:this.apiName,url:`https://store.steampowered.com/app/${o.steam_appid}`,id:o.steam_appid,developers:o.developers,publishers:o.publishers,genres:(s=(a=o.genres)==null?void 0:a.map(M=>M.description))!=null?s:[],onlineRating:Number.parseFloat((p=(l=o.metacritic)==null?void 0:l.score)!=null?p:0),image:(d=o.header_image)!=null?d:"",released:!((c=o.release_date)!=null&&c.comming_soon),releaseDate:(u=this.plugin.dateFormatter.format((f=o.release_date)==null?void 0:f.date,this.apiDateFormat))!=null?u:"unknown",userData:{played:!1,personalRating:0}})}};var Fr=require("obsidian");var Ri=class extends q{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 s,l,p,d;console.log(`MDB | api "${this.apiName}" queried by Title`);let t=`${this.apiUrl}/search?search=${encodeURIComponent(e)}`,i=await(0,Fr.requestUrl)({url:t});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let n=i.text,o=new window.DOMParser().parseFromString(n,"text/xml"),a=[];for(let c of Array.from(o.querySelectorAll("boardgame"))){let f=c.attributes.getNamedItem("objectid").value,u=(l=(s=c.querySelector("name[primary=true]"))==null?void 0:s.textContent)!=null?l:c.querySelector("name").textContent,M=(d=(p=c.querySelector("yearpublished"))==null?void 0:p.textContent)!=null?d:"";a.push(new ft({dataSource:this.apiName,id:f,title:u,englishTitle:u,year:M}))}return a}async getById(e){var _,b,D,h,y,w,S,T,E,x,v,F,P,A;console.log(`MDB | api "${this.apiName}" queried by ID`);let t=`${this.apiUrl}/boardgame/${encodeURIComponent(e)}?stats=1`,i=await(0,Fr.requestUrl)({url:t});if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let n=i.text,a=new window.DOMParser().parseFromString(n,"text/xml").querySelector("boardgame"),s=a.querySelector("name[primary=true]").textContent,l=(b=(_=a.querySelector("yearpublished"))==null?void 0:_.textContent)!=null?b:"",p=(h=(D=a.querySelector("image"))==null?void 0:D.textContent)!=null?h:void 0,d=Number.parseFloat((w=(y=a.querySelector("statistics ratings average"))==null?void 0:y.textContent)!=null?w:"0"),c=Array.from(a.querySelectorAll("boardgamecategory")).map(Q=>Q.textContent),f=Number.parseFloat((T=(S=a.querySelector("averageweight"))==null?void 0:S.textContent)!=null?T:"0"),u=Number.parseFloat((x=(E=a.querySelector("minplayers"))==null?void 0:E.textContent)!=null?x:"0"),M=Number.parseFloat((F=(v=a.querySelector("maxplayers"))==null?void 0:v.textContent)!=null?F:"0"),g=((A=(P=a.querySelector("playingtime"))==null?void 0:P.textContent)!=null?A:"unknown")+" minutes",m=Array.from(a.querySelectorAll("boardgamepublisher")).map(Q=>Q.textContent);return new ft({title:s,englishTitle:s,year:l==="0"?"":l,dataSource:this.apiName,url:`https://boardgamegeek.com/boardgame/${e}`,id:e,genres:c,onlineRating:d,complexityRating:f,minPlayers:u,maxPlayers:M,playtime:g,publishers:m,image:p,released:!0,userData:{played:!1,personalRating:0}})}};var Oi=class extends q{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 a,s;console.log(`MDB | api "${this.apiName}" queried by Title`);let t=`https://openlibrary.org/search.json?title=${encodeURIComponent(e)}`,i=await fetch(t);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let n=await i.json(),o=[];for(let l of n.docs)o.push(new ht({title:l.title,englishTitle:(a=l.title_english)!=null?a:l.title,year:l.first_publish_year,dataSource:this.apiName,id:l.key,author:(s=l.author_name)!=null?s:"unknown"}));return o}async getById(e){var a,s,l,p,d,c,f,u,M;console.log(`MDB | api "${this.apiName}" queried by ID`);let t=`https://openlibrary.org/search.json?q=key:${encodeURIComponent(e)}`,i=await fetch(t);if(i.status!==200)throw Error(`MDB | Received status code ${i.status} from ${this.apiName}.`);let o=(await i.json()).docs[0];return new ht({title:o.title,year:o.first_publish_year,dataSource:this.apiName,url:"https://openlibrary.org"+o.key,id:o.key,isbn:(s=((a=o.isbn)!=null?a:[]).find(g=>g.length<=10))!=null?s:"unknown",isbn13:(p=((l=o.isbn)!=null?l:[]).find(g=>g.length==13))!=null?p:"unknown",englishTitle:(d=o.title_english)!=null?d:o.title,author:(c=o.author_name)!=null?c:"unknown",plot:(f=o.description)!=null?f:"unknown",pages:(u=o.number_of_pages_median)!=null?u:"unknown",onlineRating:Number.parseFloat(Number((M=o.ratings_average)!=null?M:0).toFixed(2)),image:"https://covers.openlibrary.org/b/OLID/"+o.cover_edition_key+"-L.jpg",released:!0,userData:{read:!1,lastRead:"",personalRating:0}})}};var kr=require("obsidian");var Ai=class extends q{constructor(t){super();this.apiDateFormat="YYYY-DD-MM";this.plugin=t,this.apiName="MobyGamesAPI",this.apiDescription="A free API for games.",this.apiUrl="https://api.mobygames.com/v1",this.types=["game"]}async searchByTitle(t){if(console.log(`MDB | api "${this.apiName}" queried by Title`),!this.plugin.settings.MobyGamesKey)throw Error(`MDB | API key for ${this.apiName} missing.`);let i=`${this.apiUrl}/games?title=${encodeURIComponent(t)}&api_key=${this.plugin.settings.MobyGamesKey}`,n=await(0,kr.requestUrl)({url:i});if(n.status===401)throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);if(n.status===429)throw Error(`MDB | Too many requests for ${this.apiName}, you've exceeded your API quota.`);if(n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let o=await n.json,a=[];for(let s of o.games)a.push(new pe({type:"game",title:s.title,englishTitle:s.title,year:new Date(s.platforms[0].first_release_date).getFullYear().toString(),dataSource:this.apiName,id:s.game_id}));return a}async getById(t){var s,l,p,d,c;if(console.log(`MDB | api "${this.apiName}" queried by ID`),!this.plugin.settings.MobyGamesKey)throw Error(`MDB | API key for ${this.apiName} missing.`);let i=`${this.apiUrl}/games?id=${encodeURIComponent(t)}&api_key=${this.plugin.settings.MobyGamesKey}`,n=await(0,kr.requestUrl)({url:i});if(console.debug(n),n.status!==200)throw Error(`MDB | Received status code ${n.status} from ${this.apiName}.`);let a=(await n.json).games[0];return new pe({type:"game",title:a.title,englishTitle:a.title,year:new Date(a.platforms[0].first_release_date).getFullYear().toString(),dataSource:this.apiName,url:`https://www.mobygames.com/game/${a.game_id}`,id:a.game_id,developers:[],publishers:[],genres:(l=(s=a.genres)==null?void 0:s.map(f=>f.genre_name))!=null?l:[],onlineRating:a.moby_score,image:(d=(p=a.sample_cover)==null?void 0:p.image)!=null?d:"",released:!0,releaseDate:(c=a.platforms[0].first_release_date)!=null?c:"unknown",userData:{played:!1,personalRating:0}})}};var Ni=class{constructor(e){this.plugin=e}convertObject(e){if(!e.hasOwnProperty("type")||Pe.filter(n=>n.toString()==e.type).length<1)return e;let t=this.plugin.settings.propertyMappingModels.find(n=>n.type===e.type).properties,i={};for(let[n,o]of Object.entries(e))for(let a of t)if(a.property===n){a.mapping==="remap"?i[a.newProperty]=o:a.mapping==="remove"||a.mapping==="default"&&(i[n]=o);break}return i}convertObjectBack(e){if(!e.hasOwnProperty("type")||Pe.contains(e.type))return e;let t=this.plugin.settings.propertyMappingModels.find(n=>n.type===e.type).properties,i={};e:for(let[n,o]of Object.entries(e)){for(let a of t)if(a.property===n){i[n]=o;continue e}for(let a of t)if(a.newProperty===n){i[a.property]=o;continue e}}return i}};var Fe=require("obsidian"),Bi=class extends Fe.Modal{constructor(e,t,i){super(e),this.plugin=t,this.onSubmit=i,this.selectedApi=t.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 t=e.createEl("div",{cls:"media-db-plugin-list-wrapper"});t.createEl("div",{cls:"media-db-plugin-list-text-wrapper"}).createEl("span",{text:"API to search",cls:"media-db-plugin-list-text"});let n=new Fe.DropdownComponent(t);n.onChange(c=>{this.selectedApi=c});for(let c of this.plugin.apiManager.apis)n.addOption(c.apiName,c.apiName);t.appendChild(n.selectEl),e.createDiv({cls:"media-db-plugin-spacer"}),e.createEl("h3",{text:"Append note content to Media DB entry."});let o=e.createEl("div",{cls:"media-db-plugin-list-wrapper"});o.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 s=o.createEl("div",{cls:"media-db-plugin-list-toggle"}),l=new Fe.ToggleComponent(o);l.setValue(!1),l.onChange(c=>this.appendContent=c),s.appendChild(l.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 p="title",d=new Fe.TextComponent(e);d.inputEl.style.width="100%",d.setPlaceholder(p),d.onChange(c=>this.titleFieldName=c),d.inputEl.addEventListener("keydown",c=>{c.key==="Enter"&&this.submit()}),e.appendChild(d.inputEl),e.createDiv({cls:"media-db-plugin-spacer"}),new Fe.Setting(e).addButton(c=>{c.setButtonText("Cancel"),c.onClick(()=>this.close()),c.buttonEl.addClass("media-db-plugin-button")}).addButton(c=>{c.setButtonText("Ok"),c.setCta(),c.onClick(()=>{this.submit()}),c.buttonEl.addClass("media-db-plugin-button"),this.searchBtn=c})}onClose(){let{contentEl:e}=this;e.empty()}};var be=require("obsidian");var Ii=class extends be.Modal{constructor(e,t){t=Object.assign({},qn,t),super(e.app),this.plugin=e,this.selectedApis=[],this.title=t.modalTitle,this.query=t.prefilledSearchString;for(let i of this.plugin.apiManager.apis)this.selectedApis.push({name:i.apiName,selected:t.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(t=>t.selected).map(t=>t.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 t="Search by title",i=new be.TextComponent(e);i.inputEl.style.width="100%",i.setPlaceholder(t),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 o=e.createEl("div",{cls:"media-db-plugin-list-wrapper"}),a=o.createEl("div",{cls:"media-db-plugin-list-text-wrapper"});a.createEl("span",{text:n.apiName,cls:"media-db-plugin-list-text"}),a.createEl("small",{text:n.apiDescription,cls:"media-db-plugin-list-text"});let s=o.createEl("div",{cls:"media-db-plugin-list-toggle"}),l=new be.ToggleComponent(s);l.setTooltip(n.apiName),l.setValue(this.selectedApis.find(p=>p.name===n.apiName).selected),l.onChange(p=>{this.selectedApis.find(d=>d.name===n.apiName).selected=p}),s.appendChild(l.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 we=require("obsidian");var Li=class extends we.Modal{constructor(e,t){t=Object.assign({},Un,t),super(e.app),this.plugin=e,this.title=t.modalTitle,this.selectedApi=t.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 we.Notice("MDB | no Id entered");return}if(!this.selectedApi){new we.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 t="Search by id",i=new we.TextComponent(e);i.inputEl.style.width="100%",i.setPlaceholder(t),i.onChange(s=>this.query=s),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 a=new we.DropdownComponent(n);a.onChange(s=>{this.selectedApi=s});for(let s of this.plugin.apiManager.apis)a.addOption(s.apiName,s.apiName);n.appendChild(a.selectEl),e.createDiv({cls:"media-db-plugin-spacer"}),new we.Setting(e).addButton(s=>{s.setButtonText("Cancel"),s.onClick(()=>this.close()),s.buttonEl.addClass("media-db-plugin-button")}).addButton(s=>{s.setButtonText("Ok"),s.setCta(),s.onClick(()=>{this.search()}),s.buttonEl.addClass("media-db-plugin-button"),this.searchBtn=s})}onClose(){this.closeCallback();let{contentEl:e}=this;e.empty()}};var qi=require("obsidian");var Wi=class{constructor(e,t,i,n,o=!1){this.value=e,this.id=i,this.active=o,this.selectModal=n,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=t.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(e){this.highlighted=e,this.highlighted?(this.addClass(this.hoverClass),this.selectModal.deHighlightAllOtherElements(this.id)):this.removeClass(this.hoverClass)}isActive(){return this.active}setActive(e){this.active=e,this.update()}update(){this.active?this.addClass(this.activeClass):this.removeClass(this.activeClass)}addClass(e){this.element.hasClass(e)||this.element.addClass(e)}removeClass(e){this.element.hasClass(e)&&this.element.removeClass(e)}};var ji=class extends qi.Modal{constructor(e,t,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=t,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 t of this.selectModalElements)t.id!==e&&t.setActive(!1)}deHighlightAllOtherElements(e){for(let t of this.selectModalElements)t.id!==e&&t.setHighlighted(!1)}async onOpen(){var o;let{contentEl:e,titleEl:t}=this;t.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 a of this.elements){let s=new Wi(a,this.elementWrapper,i,this,!1);this.selectModalElements.push(s),this.renderElement(a,s.element),i+=1}(o=this.selectModalElements.first())==null||o.element.scrollIntoView();let n=new qi.Setting(e);n.addButton(a=>{a.setButtonText("Cancel"),a.onClick(()=>this.close()),a.buttonEl.addClass("media-db-plugin-button"),this.cancelButton=a}),this.addSkipButton&&n.addButton(a=>{a.setButtonText("Skip"),a.onClick(()=>this.skip()),a.buttonEl.addClass("media-db-plugin-button"),this.skipButton=a}),n.addButton(a=>{a.setButtonText("Ok"),a.setCta(),a.onClick(()=>this.submit()),a.buttonEl.addClass("media-db-plugin-button"),this.submitButton=a})}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 t=e.id+1;return t=mi(t,this.selectModalElements.length),this.selectModalElements.filter(i=>i.id===t).first()}getPreviousSelectModalElement(e){let t=e.id-1;return t=mi(t,this.selectModalElements.length),this.selectModalElements.filter(i=>i.id===t).first()}};var Ui=class extends ji{constructor(e,t){t=Object.assign({},Hn,t),super(e.app,t.elements,t.multiSelect),this.plugin=e,this.title=t.modalTitle,this.description="Select one or multiple search results.",this.addSkipButton=t.skipButton,this.busy=!1,this.sendCallback=!1}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}setSkipCallback(e){this.skipCallback=e}renderElement(e,t){t.createEl("div",{text:this.plugin.mediaTypeManager.getFileName(e)}),t.createEl("small",{text:`${e.getSummary()}
`}),t.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 Te=require("obsidian");var He=require("obsidian");var Hi=class extends He.Modal{constructor(e,t){t=Object.assign({},Vn,t),super(e.app),this.plugin=e,this.title=t.modalTitle,this.elements=t.elements,this.markdownComponent=new He.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 t=e.createDiv({cls:"media-db-plugin-preview-wrapper"});this.markdownComponent.load();for(let n of this.elements){t.createEl("h3",{text:n.englishTitle});let o=t.createDiv({cls:"media-db-plugin-preview"}),a=this.plugin.generateMediaDbNoteFrontmatterPreview(n);a=`\`\`\`yaml
${a}\`\`\``;try{await He.MarkdownRenderer.render(this.app,a,o,"",this.markdownComponent)}catch(s){console.warn("mdb | error during rendering of preview",s)}}e.createDiv({cls:"media-db-plugin-spacer"});let i=new He.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 xe=require("obsidian");var Vi=class extends xe.Modal{constructor(e,t){t=Object.assign({},Gn,t),super(e.app),this.plugin=e,this.selectedTypes=[],this.title=t.modalTitle,this.query=t.prefilledSearchString;for(let i of Pe)this.selectedTypes.push({name:i,selected:t.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 xe.Notice("MDB | Query too short");return}let e=this.selectedTypes.filter(t=>t.selected).map(t=>t.name);if(e.length===0){new xe.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 t="Search by title",i=new xe.TextComponent(e),n=null;i.inputEl.style.width="100%",i.setPlaceholder(t),i.setValue(this.query),i.onChange(o=>this.query=o),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 o of Pe){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(o),cls:"media-db-plugin-list-text"});let l=a.createEl("div",{cls:"media-db-plugin-list-toggle"}),p=new xe.ToggleComponent(l);p.setTooltip(zt(o)),p.setValue(this.selectedTypes.find(d=>d.name===o).selected),p.getValue()&&(n=p),p.onChange(d=>{d?(n&&n!==p&&(n.setValue(!1),this.selectedTypes.find(c=>c.name===o).selected=!1),n=p,this.selectedTypes.find(c=>c.name===o).selected=!0):(n=null,this.selectedTypes.find(c=>c.name===o).selected=!1)}),l.appendChild(p.toggleEl)}e.createDiv({cls:"media-db-plugin-spacer"}),new xe.Setting(e).addButton(o=>{o.setButtonText("Cancel"),o.onClick(()=>this.close()),o.buttonEl.addClass("media-db-plugin-button")}).addButton(o=>{o.setButtonText("Ok"),o.setCta(),o.onClick(()=>{this.search()}),o.buttonEl.addClass("media-db-plugin-button"),this.searchBtn=o})}onClose(){this.closeCallback();let{contentEl:e}=this;e.empty()}};var Gn={modalTitle:"Media DB Search",preselectedTypes:[],prefilledSearchString:""},qn={modalTitle:"Media DB Advanced Search",preselectedAPIs:[],prefilledSearchString:""},Un={modalTitle:"Media DB Id Search",preselectedAPI:"",prefilledSearchString:""},Hn={modalTitle:"Media DB Search Results",elements:[],multiSelect:!0,skipButton:!1},Vn={modalTitle:"Media DB Preview",elements:[]},Gi=class{constructor(e){this.plugin=e}async createSearchModal(e){let t=new Vi(this.plugin,e);return{searchModalResult:await new Promise(n=>{t.setSubmitCallback(o=>n({code:"SUCCESS",data:o})),t.setCloseCallback(o=>{o&&n({code:"ERROR",error:o}),n({code:"CLOSE"})}),t.open()}),searchModal:t}}async openSearchModal(e,t){let{searchModalResult:i,searchModal:n}=await this.createSearchModal(e);if(console.debug(`MDB | searchModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new Te.Notice(i.error.toString()),n.close();return}if(i.code!=="CLOSE")try{let o=await t(i.data);return n.close(),o}catch(o){console.warn(o),new Te.Notice(o.toString()),n.close();return}}async createAdvancedSearchModal(e){let t=new Ii(this.plugin,e);return{advancedSearchModalResult:await new Promise(n=>{t.setSubmitCallback(o=>n({code:"SUCCESS",data:o})),t.setCloseCallback(o=>{o&&n({code:"ERROR",error:o}),n({code:"CLOSE"})}),t.open()}),advancedSearchModal:t}}async openAdvancedSearchModal(e,t){let{advancedSearchModalResult:i,advancedSearchModal:n}=await this.createAdvancedSearchModal(e);if(console.debug(`MDB | advencedSearchModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new Te.Notice(i.error.toString()),n.close();return}if(i.code!=="CLOSE")try{let o=await t(i.data);return n.close(),o}catch(o){console.warn(o),new Te.Notice(o.toString()),n.close();return}}async createIdSearchModal(e){let t=new Li(this.plugin,e);return{idSearchModalResult:await new Promise(n=>{t.setSubmitCallback(o=>n({code:"SUCCESS",data:o})),t.setCloseCallback(o=>{o&&n({code:"ERROR",error:o}),n({code:"CLOSE"})}),t.open()}),idSearchModal:t}}async openIdSearchModal(e,t){let{idSearchModalResult:i,idSearchModal:n}=await this.createIdSearchModal(e);if(console.debug(`MDB | idSearchModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new Te.Notice(i.error.toString()),n.close();return}if(i.code!=="CLOSE")try{let o=await t(i.data);return n.close(),o}catch(o){console.warn(o),new Te.Notice(o.toString()),n.close();return}}async createSelectModal(e){let t=new Ui(this.plugin,e);return{selectModalResult:await new Promise(n=>{t.setSubmitCallback(o=>n({code:"SUCCESS",data:o})),t.setSkipCallback(()=>n({code:"SKIP"})),t.setCloseCallback(o=>{o&&n({code:"ERROR",error:o}),n({code:"CLOSE"})}),t.open()}),selectModal:t}}async openSelectModal(e,t){let{selectModalResult:i,selectModal:n}=await this.createSelectModal(e);if(console.debug(`MDB | selectModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new Te.Notice(i.error.toString()),n.close();return}if(i.code!=="CLOSE"&&i.code!=="SKIP")try{let o=await t(i.data);return n.close(),o}catch(o){console.warn(o),new Te.Notice(o.toString()),n.close();return}}async createPreviewModal(e){let t=new Hi(this.plugin,e);return{previewModalResult:await new Promise(n=>{t.setSubmitCallback(o=>n({code:"SUCCESS",data:o})),t.setCloseCallback(o=>{o&&n({code:"ERROR",error:o}),n({code:"CLOSE"})}),t.open()}),previewModal:t}}async openPreviewModal(e,t){let{previewModalResult:i,previewModal:n}=await this.createPreviewModal(e);if(console.debug(`MDB | previewModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new Te.Notice(i.error.toString()),n.close();return}if(i.code!=="CLOSE")try{let o=await t(i.data);return n.close(),o}catch(o){console.warn(o),new Te.Notice(o.toString()),n.close();return}}};var kt=require("obsidian"),Yi=class{constructor(){this.toFormat="YYYY-MM-DD",this.locale=new Intl.DateTimeFormat().resolvedOptions().locale}setFormat(e){this.toFormat=e}getPreview(e){let t=(0,kt.moment)();return e||(e=this.toFormat),t.locale(this.locale).format(e)}format(e,t,i="en"){if(!e)return null;let n;return t?n=(0,kt.moment)(e,t,i):this.hasMomentFormat(e)?n=(0,kt.moment)(e):n=(0,kt.moment)(new Date(e)),n.isValid()?n.locale(this.locale).format(this.toFormat):null}hasMomentFormat(e){return(0,kt.moment)(e,!0).isValid()}};var zi=class extends z.Plugin{constructor(){super(...arguments);this.frontMatterRexExpPattern="^(---)\\n[\\s\\S]*?\\n---"}async onload(){this.apiManager=new Di,this.apiManager.registerAPI(new Ei(this)),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 _i,this.modelPropertyMapper=new Ni(this),this.modalHelper=new Gi(this),this.dateFormatter=new Yi,await this.loadSettings(),this.addSettingTab(new Si(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",(i,n)=>{n instanceof z.TFolder&&i.addItem(o=>{o.setTitle("Import folder as Media DB entries").setIcon("database").onClick(()=>this.createEntriesFromFolder(n))})})),this.addCommand({id:"open-media-db-search-modal",name:"Create Media DB entry",callback:()=>this.createEntryWithSearchModal()});for(let i of Pe)this.addCommand({id:`open-media-db-search-modal-with-${i}`,name:`Create Media DB entry (${zt(i)})`,callback:()=>this.createEntryWithSearchModal({preselectedTypes:[i]})});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:i=>this.app.workspace.getActiveFile()?(i||this.updateActiveNote(!1),!0):!1}),this.addCommand({id:"update-media-db-note-metadata",name:"Update metadata",checkCallback:i=>this.app.workspace.getActiveFile()?(i||this.updateActiveNote(!0),!0):!1}),this.addCommand({id:"add-media-db-link",name:"Insert link",checkCallback:i=>this.app.workspace.getActiveFile()?(i||this.createLinkWithSearchModal(),!0):!1})}async createLinkWithSearchModal(){let t=await this.modalHelper.openAdvancedSearchModal({},async a=>await this.apiManager.query(a.query,a.apis));if(!t)return;let i=await this.modalHelper.openSelectModal({elements:t,multiSelect:!1},async a=>await this.queryDetails(a.selected));if(!i||i.length<1)return;let n=`[${i[0].title}](${i[0].url})`,o=this.app.workspace.getActiveViewOfType(z.MarkdownView);o&&o.editor.replaceRange(n,o.editor.getCursor())}async createEntryWithSearchModal(t){let i=[],n=await this.modalHelper.openSearchModal(t!=null?t:{},async s=>{i=s.types;let l=this.apiManager.apis.filter(p=>p.hasTypeOverlap(s.types)).map(p=>p.apiName);try{return console.log(l),await this.apiManager.query(s.query,l)}catch(p){return console.warn(p),[]}});if(!n)return;n=n.filter(s=>i.contains(s.type));let o,a;for(;!a;){if(o=await this.modalHelper.openSelectModal({elements:n},async s=>await this.queryDetails(s.selected)),!o)return;a=await this.modalHelper.openPreviewModal({elements:o},async s=>s.confirmed)}await this.createMediaDbNotes(o)}async createEntryWithAdvancedSearchModal(){let t=await this.modalHelper.openAdvancedSearchModal({},async o=>await this.apiManager.query(o.query,o.apis));if(!t)return;let i,n;for(;!n;){if(i=await this.modalHelper.openSelectModal({elements:t},async o=>await this.queryDetails(o.selected)),!i)return;n=await this.modalHelper.openPreviewModal({elements:i},async o=>o.confirmed)}await this.createMediaDbNotes(i)}async createEntryWithIdSearchModal(){let t,i;for(;!i;){if(t=await this.modalHelper.openIdSearchModal({},async n=>await this.apiManager.queryDetailedInfoById(n.query,n.api)),!t)return;i=await this.modalHelper.openPreviewModal({elements:[t]},async n=>n.confirmed)}await this.createMediaDbNoteFromModel(t,{attachTemplate:!0,openNote:!0})}async createMediaDbNotes(t,i){for(let n of t)await this.createMediaDbNoteFromModel(n,{attachTemplate:!0,attachFile:i})}async queryDetails(t){let i=[];for(let n of t)try{i.push(await this.apiManager.queryDetailedInfo(n))}catch(o){console.warn(o),new z.Notice(o.toString())}return i}async createMediaDbNoteFromModel(t,i){try{console.debug("MDB | creating new note"),i.openNote=this.settings.openNoteInNewTab;let n=await this.generateMediaDbNoteContents(t,i);i.folder||(i.folder=await this.mediaTypeManager.getFolder(t,this.app));let o=await this.createNote(this.mediaTypeManager.getFileName(t),n,i);this.settings.enableTemplaterIntegration&&await pn(this.app,o)}catch(n){console.warn(n),new z.Notice(n.toString())}}generateMediaDbNoteFrontmatterPreview(t){let i=this.modelPropertyMapper.convertObject(t.toMetaDataObject());return(0,z.stringifyYaml)(i)}async generateMediaDbNoteContents(t,i){let n=await this.mediaTypeManager.getTemplate(t,this.app);return this.generateContentWithDefaultFrontMatter(t,i,n)}async generateContentWithDefaultFrontMatter(t,i,n){let o;this.settings.useDefaultFrontMatter?o=this.modelPropertyMapper.convertObject(t.toMetaDataObject()):o={id:t.id,type:t.type,dataSource:t.dataSource};let a="";return n=i.attachTemplate?n:"",{fileMetadata:o,fileContent:a}=await this.attachFile(o,a,i.attachFile),{fileMetadata:o,fileContent:a}=await this.attachTemplate(o,a,n),this.settings.enableTemplaterIntegration&&hr(this.app)?a=`---
<%* const media = ${JSON.stringify(t)} %>
${(0,z.stringifyYaml)(o)}---
${a}`:a=`---
${(0,z.stringifyYaml)(o)}---
${a}`,a}async generateContentWithCustomFrontMatter(t,i,n){let o=new RegExp(this.frontMatterRexExpPattern),a=this.getMetaDataFromFileContent(n),s=n.replace(o,"");if(i.attachFile){let l=this.app.metadataCache.getFileCache(i.attachFile).frontmatter;s=await this.app.vault.read(i.attachFile),s=s.replace(o,""),s=s.startsWith(`
`)?s.substring(1):s,Object.keys(l).forEach(p=>{let d=l[p];!a[p]&&d&&(a[p]=d)})}return a.id||(a.id=t.id),a.type||(a.type=t.type),a.dataSource||(a.dataSource=t.dataSource),this.settings.enableTemplaterIntegration&&hr(this.app)?s=`---
<%* const media = ${JSON.stringify(t)} %>
${(0,z.stringifyYaml)(a)}---
${s}`:s=`---
${(0,z.stringifyYaml)(a)}---
${s}`,s}async attachFile(t,i,n){if(!n)return{fileMetadata:t,fileContent:i};let o=this.getMetadataFromFileCache(n);t=Object.assign(o,t);let a=await this.app.vault.read(n),s=new RegExp(this.frontMatterRexExpPattern);return a=a.replace(s,""),a=a.startsWith(`
`)?a.substring(1):a,i+=a,{fileMetadata:t,fileContent:i}}async attachTemplate(t,i,n){if(!n)return{fileMetadata:t,fileContent:i};let o=this.getMetaDataFromFileContent(n);t=Object.assign(o,t);let a=new RegExp(this.frontMatterRexExpPattern),s=n.replace(a,"");return i+=s,{fileMetadata:t,fileContent:i}}getMetaDataFromFileContent(t){let i,o=new RegExp(this.frontMatterRexExpPattern).exec(t);if(!o)return{};let a=o[0];return a?(a=a.substring(4),a=a.substring(0,a.length-3),i=(0,z.parseYaml)(a),i||(i={}),console.debug("MDB | metadata read from file content",i),i):{}}getMetadataFromFileCache(t){let i=this.app.metadataCache.getFileCache(t).frontmatter;return structuredClone(i!=null?i:{})}async createNote(t,i,n){var p;let o=(p=n.folder)!=null?p:this.app.vault.getAbstractFileByPath("/");t=on(t);let a=`${o.path}/${t}.md`,s=this.app.vault.getAbstractFileByPath(a);s&&await this.app.vault.delete(s);let l=await this.app.vault.create(a,i);if(console.debug(`MDB | created new file at ${a}`),n.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"}})}return l}async updateActiveNote(t=!1){let i=this.app.workspace.getActiveFile();if(!i)throw new Error("MDB | there is no active note");let n=this.getMetadataFromFileCache(i);if(n=this.modelPropertyMapper.convertObjectBack(n),console.debug("MDB | read metadata",n),!(n!=null&&n.type)||!(n!=null&&n.dataSource)||!(n!=null&&n.id))throw new Error("MDB | active note is not a Media DB entry or is missing metadata");let o=n,a=this.mediaTypeManager.createMediaTypeModelFromMediaType(o,o.type),s=await this.apiManager.queryDetailedInfoById(o.id,o.dataSource);s&&(s=Object.assign(a,s.getWithOutUserData()),t?await this.createMediaDbNoteFromModel(s,{attachFile:i,folder:i.parent,openNote:!0}):await this.createMediaDbNoteFromModel(s,{attachTemplate:!0,folder:i.parent,openNote:!0}))}async createEntriesFromFolder(t){let i=[],n=!1,{selectedAPI:o,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 t.children)if(l instanceof z.TFile){let p=l;if(n){i.push({filePath:p.path,error:"user canceled"});continue}let c=this.getMetadataFromFileCache(p)[a];if(!c){i.push({filePath:p.path,error:`metadata field '${a}' not found or empty`});continue}let f=[];try{f=await this.apiManager.query(c,[o])}catch(m){i.push({filePath:p.path,error:m.toString()});continue}if(!f||f.length===0){i.push({filePath:p.path,error:"no search results"});continue}let{selectModalResult:u,selectModal:M}=await this.modalHelper.createSelectModal({elements:f,skipButton:!0,modalTitle:`Results for '${c}'`});if(u.code==="ERROR"){i.push({filePath:p.path,error:u.error.message}),M.close();continue}if(u.code==="CLOSE"){i.push({filePath:p.path,error:"user canceled"}),M.close(),n=!0;continue}if(u.code==="SKIP"){i.push({filePath:p.path,error:"user skipped"}),M.close();continue}if(u.data.selected.length===0){i.push({filePath:p.path,error:"no search results selected"});continue}let g=await this.queryDetails(u.data.selected);await this.createMediaDbNotes(g,s?p:null),M.close()}i.length>0&&await this.createErroredFilesReport(i)}async createErroredFilesReport(t){let i=`MDB - bulk import error report ${ln(new Date)}`,n=`${i}.md`,o=[["file","error"]].concat(t.map(s=>[s.filePath,s.error])),a=`# ${i}
${an(o)}`;await this.app.vault.create(n,a)}async loadSettings(){let t=await this.loadData(),i=jn(this),n=Object.assign({},i,t),o=[];for(let a of i.propertyMappingModels){let s=n.propertyMappingModels.find(l=>l.type===a.type);if(s===void 0)o.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))}o.push(new Ft(s.type,l))}}n.propertyMappingModels=o,this.settings=n}async saveSettings(){this.mediaTypeManager.updateTemplates(this.settings),this.mediaTypeManager.updateFolders(this.settings),this.dateFormatter.setFormat(this.settings.customDateFormat),await this.saveData(this.settings)}};