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.

101 lines
154 KiB

3 years ago
/*
-------------------------------------------
8 months ago
Media DB - Release Build
-------------------------------------------
8 months ago
By: Moritz Jung (https://www.moritzjung.dev)
3 days ago
Time: Mon, 27 Jan 2025 20:54:57 GMT
Version: 0.8.0
-------------------------------------------
3 years ago
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
8 months ago
-------------------------------------------
MIT License
3 days ago
Copyright (c) 2025 Moritz Jung
8 months ago
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.
3 years ago
*/
3 days ago
"use strict";var zi=Object.defineProperty;var Ll=Object.getOwnPropertyDescriptor;var ql=Object.getOwnPropertyNames;var Ul=Object.prototype.hasOwnProperty;var ka=t=>{throw TypeError(t)};var Hl=(t,r,e)=>r in t?zi(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var Wl=(t,r)=>{for(var e in r)zi(t,e,{get:r[e],enumerable:!0})},Vl=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ql(r))!Ul.call(t,o)&&o!==e&&zi(t,o,{get:()=>r[o],enumerable:!(i=Ll(r,o))||i.enumerable});return t};var Yl=t=>Vl(zi({},"__esModule",{value:!0}),t);var p=(t,r,e)=>Hl(t,typeof r!="symbol"?r+"":r,e),Aa=(t,r,e)=>r.has(t)||ka("Cannot "+e);var xe=(t,r,e)=>(Aa(t,r,"read from private field"),e?e.call(t):r.get(t)),Xi=(t,r,e)=>r.has(t)?ka("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(t):r.set(t,e),Zi=(t,r,e,i)=>(Aa(t,r,"write to private field"),i?i.call(t,e):r.set(t,e),e);var ed={};Wl(ed,{default:()=>tn});module.exports=Yl(ed);var oe=require("obsidian");var rn=require("obsidian");var Ji=class{constructor(){p(this,"apis");this.apis=[]}async query(r,e){console.debug(`MDB | api manager queried with "${r}"`);let i=this.apis.filter(o=>e.contains(o.apiName)).map(async o=>{try{return await o.searchByTitle(r)}catch(n){return new rn.Notice(`Error querying ${o.apiName}: ${n}`),console.warn(n),[]}});return(await Promise.all(i)).flat()}async queryDetailedInfo(r){return await this.queryDetailedInfoById(r.id,r.dataSource)}async queryDetailedInfoById(r,e){for(let i of this.apis)if(i.apiName===e)try{return i.getById(r)}catch(o){new rn.Notice(`Error querying ${i.apiName}: ${o}`),console.warn(o);return}}getApiByName(r){for(let e of this.apis)if(e.apiName===r)return e}registerAPI(r){this.apis.push(r)}};var cn=require("obsidian");var on="obsidian-media-db-plugin",nn="m.projects.code@gmail.com",ge="mediaDB",an="0.5.2";function Na(t,r){if(r<=0)throw Error("size may not be zero or negative");return Qi(t,r)}function sn(t){return/^[\p{Letter}\p{M}_]+$/u.test(t)}function Fa(t){return t.replace(/[\\,#%&{}/*<>$"@.?]*/g,"").replace(/:+/g," -")}function ln(t,r,e=!1){return t.replace(new RegExp("{{.*?}}","g"),i=>jl(i,r,e))}function jl(t,r,e){let i=t;i=i.substring(2),i=i.substring(0,i.length-2),i=i.trim();let o=i.split(":");if(o.length===1){let n=o[0].split("."),a=Ra(n,r);return a===void 0?e?"":"{{ INVALID TEMPLATE TAG - object undefined }}":a}else if(o.length===2){let n=o[0],a=o[1].split("."),s=Ra(a,r);return s===void 0?e?"":"{{ INVALID TEMPLATE TAG - object undefined }}":n==="LIST"?Array.isArray(s)?s.map(l=>`- ${l}`).join(`
`):"{{ INVALID TEMPLATE TAG - operator LIST is only applicable on an array }}":n==="ENUM"?Array.isArray(s)?s.join(", "):"{{ INVALID TEMPLATE TAG - operator ENUM is only applicable on an array }}":n==="FIRST"?Array.isArray(s)?s[0]:"{{ INVALID TEMPLATE TAG - operator FIRST is only applicable on an array }}":n==="LAST"?Array.isArray(s)?s[s.length-1]:"{{ INVALID TEMPLATE TAG - operator LAST is only applicable on an array }}":`{{ INVALID TEMPLATE TAG - unknown operator ${n} }}`}return"{{ INVALID TEMPLATE TAG }}"}function Ra(t,r){let e=r;for(let i of t)e!==void 0&&(e=e[i]);return e}function Ia(t){let r=t.length;if(r===0)return"";let e=t[0].length;if(e===0)return"";for(let n of t)if(n.length!==e)return"";let i=[];for(let n=0;n<e;n++){let a=0;for(let s of t)s[n].length>a&&(a=s[n].length);i.push(a)}let o="";for(let n=0;n<r;n++){o+="|";for(let a=0;a<e;a++){let s=t[n][a];s+=" ".repeat(i[a]-s.length),o+=" "+s+" |"}if(o+=`
`,n===0){o+="|";for(let a=0;a<e;a++)o+=" "+"-".repeat(i[a])+" |";o+=`
`}}return o}function Oa(t){return createFragment(r=>r.createDiv().innerHTML=t)}function Gl(t){return`${t.getMonth()+1}-${t.getDate()}-${t.getFullYear()}`}function Kl(t){return`${t.getHours()}-${t.getMinutes()}-${t.getSeconds()}`}function Ba(t){return`${Gl(t)} ${Kl(t)}`}function Qi(t,r){return(t%r+r)%r}function La(t){return t.charAt(0).toUpperCase()+t.slice(1)}var Jt=class extends Error{constructor(r){super(r)}},gi=class extends Error{constructor(r){super(r)}};function W(t,r,e){for(let i in t)t[i]=r.hasOwnProperty(i)?r[i]:e[i]}function vi(t){return t.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b([A-Z]+)([A-Z])([a-z])/,"$1 $2$3").replace(/^./,function(r){return r.toUpperCase()})}function pn(t){return!!t.plugins.plugins["templater-obsidian"]}async function qa(t,r){let e=t.plugins.plugins["templater-obsidian"];e&&!(e!=null&&e.settings.trigger_on_file_creation)&&await e.templater.overwrite_file_commands(r)}var ne=class{constructor(){p(this,"type");p(this,"subType");p(this,"title");p(this,"englishTitle");p(this,"year");p(this,"dataSource");p(this,"url");p(this,"id");p(this,"userData");this.type="",this.subType="",this.title="",this.englishTitle="",this.year="",this.dataSource="",this.url="",this.id="",this.userData={}}toMetaDataObject(){return{...this.getWithOutUserData(),...this.userData,tags:this.getTags().join("/")}}getWithOutUserData(){let r=structuredClone(this);return delete r.userData,r}};var Qt=class extends ne{constructor(e){super();p(this,"genres");p(this,"onlineRating");p(this,"complexityRating");p(this,"minPlayers");p(this,"maxPlayers");p(this,"playtime");p(this,"publishers");p(this,"image");p(this,"released");p(this,"userData");this.genres=[],this.onlineRating=0,this.complexityRating=0,this.minPlayers=0,this.maxPlayers=0,this.playtime="",this.publishers=[],this.image="",this.released=!1,this.userData={played:!1,personalRating:0},W(this,e,this),e.hasOwnProperty("userData")||W(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ge,"boardgame"]}getMediaType(){return"boardgame"}getSummary(){return this.englishTitle+" ("+this.year+")"}};var j=class{constructor(){p(this,"apiName");p(this,"apiUrl");p(this,"apiDescription");p(this,"types");p(this,"plugin")}hasType(r){return this.types.contains(r)}hasTypeOverlap(r){return r.some(e=>this.hasType(e))}};var eo=class extends j{constructor(e){super();p(this,"plugin");this.plugin=e,this.apiName="BoardGameGeekAPI",this.apiDescription="A free API for BoardGameGeek things.",this.apiUrl="https://api.geekdo.com/xmlapi",this.types=["boardgame"]}async searchByTitle(e){var l,d,c,u,f,m,g;console.log(`MDB | api "${this.apiName}" queried by Title`);let i=`${this.apiUrl}/search?search=${encodeURIComponent(e)}`,o=await(0,cn.requestUrl)({url:i});if(o.status!==200)throw Error(`MDB | Received status code ${o.status} from ${this.apiName}.`);let n=o.text,a=new window.DOMParser().parseFromString(n,"text/xml"),s=[];for(let h of Array.from(a.querySelectorAll("boardgame"))){let v=(l=h.attributes.getNamedItem("objectid"))==null?void 0:l.value,b=(f=(u=(d=h.querySelector("name[primary=true]"))==null?void 0:d.textContent)!=null?u:(c=h.querySelector("name"))==null?void 0:c.textContent)!=null?f:void 0,E=(g=(m=h.querySelector("yearpublished"))==null?void 0:m.textContent)!=null?g:"";s.push(new Qt({dataSource:this.apiName,id:v,title:b,englishTitle:b,year:E}))}return s}async getById(e){var E,T,M,_,y,$,A,D,x,C,S,O,L,U,H;console.log(`MDB | api "${this.apiName}" queried by ID`);let i=`${this.apiUrl}/boardgame/${encodeURIComponent(e)}?stats=1`,o=await(0,cn.requestUrl)({url:i});if(o.status!==200)throw Error(`MDB | Received status code ${o.status} from ${this.apiName}.`);let n=o.text,s=new window.DOMParser().parseFromString(n,"text/xml").querySelector("boardgame");if(!s)throw Error(`MDB | Received invalid data from ${this.apiName}.`);let l=(E=s.querySelector("name[primary=true]"))==null?void 0:E.textContent,d=(M=(T=s.querySelector("yearpublished"))==null?void 0:T.textContent)!=null?M:"",c=(y=(_=s.querySelector("image"))==null?void 0:_.textContent)!=null?y:void 0,u=Number.parseFloat((A=($=
${JSON.stringify(n,void 0,4)}`)}if(!n.Search)return[];let a=[];for(let s of n.Search){let l=this.typeMappings.get(s.Type.toLowerCase());l!==void 0&&(l==="movie"?a.push(new Ue({type:l,title:s.Title,englishTitle:s.Title,year:s.Year,dataSource:this.apiName,id:s.imdbID})):l==="series"?a.push(new ht({type:l,title:s.Title,englishTitle:s.Title,year:s.Year,dataSource:this.apiName,id:s.imdbID})):l==="game"&&a.push(new ve({type:l,title:s.Title,englishTitle:s.Title,year:s.Year,dataSource:this.apiName,id:s.imdbID})))}return a}async getById(e){var s,l,d,c,u,f,m,g,h,v,b,E,T,M,_,y,$,A,D,x,C,S,O,L,U,H,q,Ne,he;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(e)}&apikey=${this.plugin.settings.OMDbKey}`,o=await fetch(i);if(o.status===401)throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);if(o.status!==200)throw Error(`MDB | Received status code ${o.status} from ${this.apiName}.`);let n=await o.json();if(n.Response==="False")throw Error(`MDB | Received error from ${this.apiName}: ${n.Error}`);let a=this.typeMappings.get(n.Type.toLowerCase());if(a===void 0)throw Error(`${n.type.toLowerCase()} is an unsupported type.`);if(a==="movie")return new Ue({type:a,title:n.Title,englishTitle:n.Title,year:n.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${n.imdbID}/`,id:n.imdbID,plot:(s=n.Plot)!=null?s:"",genres:(d=(l=n.Genre)==null?void 0:l.split(", "))!=null?d:[],director:(u=(c=n.Director)==null?void 0:c.split(", "))!=null?u:[],writer:(m=(f=n.Writer)==null?void 0:f.split(", "))!=null?m:[],studio:["N/A"],duration:(g=n.Runtime)!=null?g:"unknown",onlineRating:Number.parseFloat((h=n.imdbRating)!=null?h:0),actors:(b=(v=n.Actors)==null?void 0:v.split(", "))!=null?b:[],image:(E=n.Poster)!=null?E:"",released:!0,streamingServices:[],premiere:(T=this.plugin.dateFormatter.format(n.Released,this.apiDateFormat))!=null?T:"unknown",userData:{watched:!1,lastWatched:"",personalRating:0}});if(a==="series")return new ht({type:a,title:n.Title,englishTitle:n.Title,year:n.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${n.imdbID}/`,id:n.imdbID,plot:(M=n.Plot)!=null?M:"",genres:(y=(_=n.Genre)==null?void 0:_.split(", "))!=null?y:[],writer:(A=($=n.Writer)==null?void 0:$.split(", "))!=null?A:[],studio:[],episodes:0,duration:(D=n.Runtime)!=null?D:"unknown",onlineRating:Number.parseFloat((x=n.imdbRating)!=null?x:0),actors:(S=(C=n.Actors)==null?void 0:C.split(", "))!=null?S:[],image:(O=n.Poster)!=null?O:"",released:!0,streamingServices:[],airing:!1,airedFrom:(L=this.plugin.dateFormatter.format(n.Released,this.apiDateFormat))!=null?L:"unknown",airedTo:"unknown",userData:{watched:!1,lastWatched:"",personalRating:0}});if(a==="game")return new ve({type:a,title:n.Title,englishTitle:n.Title,year:n.Year,dataSource:this.apiName,url:`https://www.imdb.com/title/${n.imdbID}/`,id:n.imdbID,developers:[],publishers:[],genres:(H=(U=n.Genre)==null?void 0:U.split(", "))!=null?H:[],onlineRating:Number.parseFloat((q=n.imdbRating)!=null?q:0),image:(Ne=n.Poster)!=null?Ne:"",released:!0,releaseDate:(he=this.plugin.dateFormatter.format(n.Released,this.apiDateFormat))!=null?he:"unknown",userData:{played:!1,personalRating:0}});throw new Error(`MDB | Unknown media type for id ${e}`)}};var rr=class extends ne{constructor(e){super();p(this,"author");p(this,"plot");p(this,"pages");p(this,"image");p(this,"onlineRating");p(this,"isbn");p(this,"isbn13");p(this,"released");p(this,"userData");this.author="",this.plot="",this.pages=0,this.image="",this.onlineRating=0,this.isbn=0,this.isbn13=0,this.released=!1,this.userData={read:!1,lastRead:"",personalRating:0},W(this,e,this),e.hasOwnProperty("userData")||W(this.userData,e,this.userData),this.type=this.getMediaType()}getTags(){return[ge,"book"]}getMediaType(){return"book"}getSummary(){return this.englishTitle+" ("+this.year+") - "+this.author}};var so=class extends j{constructor(e){super();p(this,"plugin");this.plugin=e,this.apiName="OpenLibraryAPI",thi
A derived value cannot reference itself recursively
https://svelte.dev/e/derived_references_self`);throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/derived_references_self")}function Xa(t){if(w){let r=new Error(`effect_in_teardown
\`${t}\` cannot be used inside an effect cleanup function
https://svelte.dev/e/effect_in_teardown`);throw r.name="Svelte error",r}else throw new Error("https://svelte.dev/e/effect_in_teardown")}function Za(){if(w){let t=new Error("effect_in_unowned_derived\nEffect cannot be created inside a `$derived` value that was not itself created inside an effect\nhttps://svelte.dev/e/effect_in_unowned_derived");throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/effect_in_unowned_derived")}function Ja(t){if(w){let r=new Error(`effect_orphan
\`${t}\` can only be used inside an effect (e.g. during component initialisation)
https://svelte.dev/e/effect_orphan`);throw r.name="Svelte error",r}else throw new Error("https://svelte.dev/e/effect_orphan")}function Qa(){if(w){let t=new Error(`effect_update_depth_exceeded
Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops
https://svelte.dev/e/effect_update_depth_exceeded`);throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/effect_update_depth_exceeded")}function es(){if(w){let t=new Error(`hydration_failed
Failed to hydrate the application
https://svelte.dev/e/hydration_failed`);throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/hydration_failed")}function ts(t){if(w){let r=new Error(`props_invalid_value
Cannot do \`bind:${t}={undefined}\` when \`${t}\` has a fallback value
https://svelte.dev/e/props_invalid_value`);throw r.name="Svelte error",r}else throw new Error("https://svelte.dev/e/props_invalid_value")}function rs(t){if(w){let r=new Error(`rune_outside_svelte
The \`${t}\` rune is only available inside \`.svelte\` and \`.svelte.js/ts\` files
https://svelte.dev/e/rune_outside_svelte`);throw r.name="Svelte error",r}else throw new Error("https://svelte.dev/e/rune_outside_svelte")}function is(){if(w){let t=new Error("state_descriptors_fixed\nProperty descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.\nhttps://svelte.dev/e/state_descriptors_fixed");throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/state_descriptors_fixed")}function os(){if(w){let t=new Error("state_prototype_fixed\nCannot set prototype of `$state` object\nhttps://svelte.dev/e/state_prototype_fixed");throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/state_prototype_fixed")}function ns(){if(w){let t=new Error("state_unsafe_local_read\nReading state that was created inside the same derived is forbidden. Consider using `untrack` to read locally created state\nhttps://svelte.dev/e/state_unsafe_local_read");throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/state_unsafe_local_read")}function as(){if(w){let t=new Error("state_unsafe_mutation\nUpdating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`\nhttps://svelte.dev/e/state_unsafe_mutation");throw t.name="Svelte error",t}else throw new Error("https://svelte.dev/e/state_unsafe_mutation")}var St=!1,vt=!1;var Rr="[",sr="[!",lr="]",Bt={};var Z=Symbol(),Te=Symbol("filename"),ss=Symbol("hmr");var wi=null;function Ct(t){let r=Error(),e=r.stack;if(e){let i=e.split(`
`),o=[`
`];for(let n=0;n<i.length;n++){let a=i[n];if(a!=="Error"){if(a.includes("validate_each_keys"))return null;a.includes("svelte/src/internal")||o.push(a)}}if(o.length===1)return null;ce(r,"stack",{value:o.join(`
`)}),ce(r,"name",{value:`${t}Error`})}return r}var pr=new Set;function Mn(t){pr=t}function J(t,r){var e={f:0,v:t,reactions:null,equals:ho,rv:0,wv:0};return w&&vt&&(e.created=r!=null?r:Ct("CreatedAt"),e.debug=null),e}function Mi(t){return Zl(J(t))}function Lt(t,r=!1){var i,o;let e=J(t);return r||(e.equals=Ar),St&&B!==null&&B.l!==null&&((o=(i=B.l).s)!=null?o:i.s=[]).push(e),e}function Zl(t){return I!==null&&I.f&2&&(rt===null?cs([t]):rt.push(t)),t}function G(t,r){return I!==null&&Pt()&&I.f&18&&(rt===null||!rt.includes(t))&&as(),Ir(t,r)}function Ir(t,r){var o;if(!t.equals(r)){var e=t.v;if(t.v=r,t.wv=xi(),w&&vt&&(t.updated=Ct("UpdatedAt"),k!=null&&(t.trace_need_increase=!0,(o=t.trace_v)!=null||(t.trace_v=e))),ps(t,2048),Pt()&&k!==null&&k.f&1024&&!(k.f&96)&&(_t===null?ds([t]):_t.push(t)),w&&pr.size>0){let n=Array.from(pr);var i=$t;Nr(!0);try{for(let a of n)a.f&1024&&Ce(a,4096),qt(a)&&cr(a)}finally{Nr(i)}pr.clear()}}return r}function ps(t,r){var e=t.reactions;if(e!==null)for(var i=Pt(),o=e.length,n=0;n<o;n++){var a=e[n],s=a.f;if(!(s&2048)&&!(!i&&a===k)){if(w&&s&262144){pr.add(a);continue}Ce(a,r),s&1280&&(s&2?ps(a,4096):Ti(a))}}}var Ei="font-weight: bold",Di="font-weight: normal";function us(t,r,e){w?console.warn(`%c[svelte] hydration_attribute_changed
%cThe \`${t}\` attribute on \`${r}\` changed its value between server and client renders. The client value, \`${e}\`, will be ignored in favour of the server value
https://svelte.dev/e/hydration_attribute_changed`,Ei,Di):console.warn("https://svelte.dev/e/hydration_attribute_changed")}function Or(t){w?console.warn(`%c[svelte] hydration_mismatch
%c${t?`Hydration failed because the initial UI does not match what was rendered on the server. The error occurred near ${t}`:"Hydration failed because the initial UI does not match what was rendered on the server"}
https://svelte.dev/e/hydration_mismatch`,Ei,Di):console.warn("https://svelte.dev/e/hydration_mismatch")}function fs(){w?console.warn(`%c[svelte] lifecycle_double_unmount
%cTried to unmount a component that was not mounted
https://svelte.dev/e/lifecycle_double_unmount`,Ei,Di):console.warn("https://svelte.dev/e/lifecycle_double_unmount")}function xn(t,r){w?console.warn(`%c[svelte] ownership_invalid_mutation
%c${t?`${t} mutated a value owned by ${r}. This is strongly discouraged. Consider passing values to child components with \`bind:\`, or use a callback instead`:"Mutating a value outside the component that created it is strongly discouraged. Consider passing values to child components with `bind:`, or use a callback instead"}
https://svelte.dev/e/ownership_invalid_mutation`,Ei,Di):console.warn("https://svelte.dev/e/ownership_invalid_mutation")}function vo(t){w?console.warn(`%c[svelte] state_proxy_equality_mismatch
%cReactive \`$state(...)\` proxies and the values they proxy have different identities. Because of this, comparisons with \`${t}\` will produce unexpected results
https://svelte.dev/e/state_proxy_equality_mismatch`,Ei,Di):console.warn("https://svelte.dev/e/state_proxy_equality_mismatch")}var P=!1;function $e(t){P=t}var F;function K(t){if(t===null)throw Or(),Bt;return F=t}function _e(){return K(Ee(F))}function fe(t){if(P){if(Ee(F)!==null)throw Or(),Bt;F=t}}function Br(){for(var t=0,r=F;;){if(r.nodeType===8){var e=r.data;if(e===lr){if(t===0)return r;t-=1}else(e===Rr||e===sr)&&(t+=1)}var i=Ee(r);r.remove(),r=i}}var Jl={},Ql=/at (?:.+ \()?(.+):(\d+):(\d+)\)?$/,ep=/@(.+):(\d+):(\d+)$/;function tp(){var e;let t=new Error().stack;if(!t)return null;let r=[];for(let i of t.split(`
`)){let o=(e=Ql.exec(i))!=null?e:ep.exec(i);o&&r.push({file:o[1],line:+o[2],column:+o[3]})}return r}function ms(){var r;let t=(r=tp())==null?void 0:r.slice(4);if(!t)return null;for(let e=0;e<t.length;e++){let i=t[e],o=Jl[i.file];if(!o){if(e===0)return null;continue}for(let n of o){if(n.end==null)return null;if(n.start.line<i.line&&n.end.line>i.line)return n.component}}return null}var rp=Symbol("ADD_OWNER");function Tn(t,r){if(r.owners!==null)for(;t;){if(t.owners===null){r.owners=null;break}for(let e of t.owners)r.owners.add(e);t=t.parent}}function hs(t,r){return t.owners===null?!0:t.owners.has(r)||t.parent!==null&&hs(t.parent,r)}function gs(t){var r,e;return(e=(r=t==null?void 0:t.owners)==null?void 0:r.values().next().value)!=null?e:gs(t.parent)}var ip=!1;function vs(t){if(ip)return;let r=ms();if(r&&!hs(t,r)){let e=gs(t);e[Te]!==r[Te]?xn(r[Te],e[Te]):xn()}}function bt(t,r=null,e){var d,c;var i=null;if(w&&vt&&(i=Ct("CreatedAt")),typeof t!="object"||t===null||Fe in t)return t;let o=nr(t);if(o!==_n&&o!==Ga)return t;var n=new Map,a=et(t),s=J(0);a&&n.set("length",J(t.length,i));var l;if(w)if(l={parent:r,owners:null},e){let u=(c=(d=e.v)==null?void 0:d[ar])==null?void 0:c.owners;l.owners=u?new Set(u):null}else l.owners=r===null?B!==null?new Set([B.function]):null:new Set;return new Proxy(t,{defineProperty(u,f,m){(!("value"in m)||m.configurable===!1||m.enumerable===!1||m.writable===!1)&&is();var g=n.get(f);return g===void 0?(g=J(m.value,i),n.set(f,g)):G(g,bt(m.value,l)),!0},deleteProperty(u,f){var m=n.get(f);if(m===void 0)f in u&&n.set(f,J(Z,i));else{if(a&&typeof f=="string"){var g=n.get("length"),h=Number(f);Number.isInteger(h)&&h<g.v&&G(g,h)}G(m,Z),_s(s)}return!0},get(u,f,m){var E;if(w&&f===ar)return l;if(f===Fe)return t;var g=n.get(f),h=f in u;if(g===void 0&&(!h||(E=tt(u,f))!=null&&E.writable)&&(g=J(bt(h?u[f]:Z,l),i),n.set(f,g)),g!==void 0){var v=R(g);if(w){var b=v==null?void 0:v[ar];b&&(b==null?void 0:b.parent)!==l&&Tn(l,b)}return v===Z?void 0:v}return Reflect.get(u,f,m)},getOwnPropertyDescriptor(u,f){var m=Reflect.getOwnPropertyDescriptor(u,f);if(m&&"value"in m){var g=n.get(f);g&&(m.value=R(g))}else if(m===void 0){var h=n.get(f),v=h==null?void 0:h.v;if(h!==void 0&&v!==Z)return{enumerable:!0,configurable:!0,value:v,writable:!0}}return m},has(u,f){var v;if(w&&f===ar||f===Fe)return!0;var m=n.get(f),g=m!==void 0&&m.v!==Z||Reflect.has(u,f);if(m!==void 0||k!==null&&(!g||(v=tt(u,f))!=null&&v.writable)){m===void 0&&(m=J(g?bt(u[f],l):Z,i),n.set(f,m));var h=R(m);if(h===Z)return!1}return g},set(u,f,m,g){var $;var h=n.get(f),v=f in u;if(a&&f==="length")for(var b=m;b<h.v;b+=1){var E=n.get(b+"");E!==void 0?G(E,Z):b in u&&(E=J(Z,i),n.set(b+"",E))}if(h===void 0?(!v||($=tt(u,f))!=null&&$.writable)&&(h=J(void 0,i),G(h,bt(m,l)),n.set(f,h)):(v=h.v!==Z,G(h,bt(m,l))),w){var T=m==null?void 0:m[ar];T&&(T==null?void 0:T.parent)!==l&&Tn(l,T),vs(l)}var M=Reflect.getOwnPropertyDescriptor(u,f);if(M!=null&&M.set&&M.set.call(g,m),!v){if(a&&typeof f=="string"){var _=n.get("length"),y=Number(f);Number.isInteger(y)&&y>=_.v&&G(_,y+1)}_s(s)}return!0},ownKeys(u){R(s);var f=Reflect.ownKeys(u).filter(h=>{var v=n.get(h);return v===void 0||v.v!==Z});for(var[m,g]of n)g.v!==Z&&!(m in u)&&f.push(m);return f},setPrototypeOf(){os()}})}function _s(t,r=1){G(t,t.v+r)}function Lr(t){return t!==null&&typeof t=="object"&&Fe in t?t[Fe]:t}function En(t,r){return Object.is(Lr(t),Lr(r))}function ys(){let t=Array.prototype,r=Array.__svelte_cleanup;r&&r();let{indexOf:e,lastIndexOf:i,includes:o}=t;t.indexOf=function(n,a){let s=e.call(this,n,a);if(s===-1){for(let l=a!=null?a:0;l<this.length;l+=1)if(Lr(this[l])===n){vo("array.indexOf(...)");break}}return s},t.lastIndexOf=function(n,a){let s=i.call(this,n,a!=null?a:this.length-1);if(s===-1){for(let l=0;l<=(a!=null?a:this.length-1);l+=1)if(Lr(this[l])===n){vo("array.lastIndexOf(...)");break}}return s},t.includes=function(n,a){let s=o.call(this,n,a);if(!s){for(let l=0;l<this.length;l+=1)if(Lr(this[l])===n){vo("array.includes(...)");break}}return s},Array.__svelte_cleanup=()=>{t.indexOf=e,t.lastIndexOf=i,t.includes=o}}var Dn,ws,bs,Ms;fu
\`${t}(...)\` can only be used during component initialisation
https://svelte.dev/e/lifecycle_outside_component`);throw r.name="Svelte error",r}else throw new Error("https://svelte.dev/e/lifecycle_outside_component")}var Bs=0,pp=1,Rs=new WeakSet,Do=!1,So=Bs,ki=!1,Yr=null,$t=!1,Mo=!1;function Nr(t){$t=t}function An(t){Mo=t}var fr=[],jr=0,Ai=[],I=null;function De(t){I=t}var k=null;function te(t){k=t}var rt=null;function cs(t){rt=t}var Re=null,Le=0,_t=null;function ds(t){_t=t}var Ls=1,$o=0,kt=!1,bi=null;var B=null;var Ye=null;function xi(){return++Ls}function Pt(){return!St||B!==null&&B.l===null}function qt(t){var d,c;var r=t.f;if(r&2048)return!0;if(r&4096){var e=t.deps,i=(r&256)!==0;if(e!==null){var o,n,a=(r&512)!==0,s=i&&k!==null&&!kt,l=e.length;if(a||s){for(o=0;o<l;o++)n=e[o],(a||!((d=n==null?void 0:n.reactions)!=null&&d.includes(t)))&&((c=n.reactions)!=null?c:n.reactions=[]).push(t);a&&(t.f^=512)}for(o=0;o<l;o++)if(n=e[o],qt(n)&&kn(n),n.wv>t.wv)return!0}(!i||k!==null&&!kt)&&Ce(t,1024)}return!1}function Ns(t,r){for(var e=r;e!==null;){if(e.f&128)try{e.fn(t);return}catch(i){e.f^=128}e=e.parent}throw Do=!1,t}function Fs(t){return(t.f&16384)===0&&(t.parent===null||(t.parent.f&128)===0)}function Gr(t,r,e,i){var c,u;if(Do){if(e===null&&(Do=!1),Fs(r))throw t;return}if(e!==null&&(Do=!0),!w||i===null||!(t instanceof Error)||Rs.has(t)){Ns(t,r);return}Rs.add(t);let o=[],n=(c=r.fn)==null?void 0:c.name;n&&o.push(n);let a=i;for(;a!==null;){if(w){var s=(u=a.function)==null?void 0:u[Te];if(s){let f=s.split("/").pop();o.push(f)}}a=a.p}let l=/Firefox/.test(navigator.userAgent)?" ":" ";ce(t,"message",{value:t.message+`
${o.map(f=>`
${l}in ${f}`).join("")}
`}),ce(t,"component_stack",{value:o});let d=t.stack;if(d){let f=d.split(`
`),m=[];for(let g=0;g<f.length;g++){let h=f[g];h.includes("svelte/src/internal")||m.push(h)}ce(t,"stack",{value:m.join(`
`)})}if(Ns(t,r),Fs(r))throw t}function qs(t,r,e=0){var i=t.reactions;if(i!==null)for(var o=0;o<i.length;o++){var n=i[o];n.f&2?qs(n,r,e+1):r===n&&(e===0?Ce(n,2048):n.f&1024&&Ce(n,4096),Ti(n))}}function wo(t){var f,m;var r=Re,e=Le,i=_t,o=I,n=kt,a=rt,s=B,l=t.f;Re=null,Le=0,_t=null,I=l&96?null:t,kt=!$t&&(l&256)!==0,rt=null,B=t.ctx,$o++;try{var d=(0,t.fn)(),c=t.deps;if(Re!==null){var u;if(dr(t,Le),c!==null&&Le>0)for(c.length=Le+Re.length,u=0;u<Re.length;u++)c[Le+u]=Re[u];else t.deps=c=Re;if(!kt)for(u=Le;u<c.length;u++)((m=(f=c[u]).reactions)!=null?m:f.reactions=[]).push(t)}else c!==null&&Le<c.length&&(dr(t,Le),c.length=Le);if(Pt()&&_t!==null&&!(t.f&6146))for(u=0;u<_t.length;u++)qs(_t[u],t);return o!==null&&$o++,d}finally{Re=r,Le=e,_t=i,I=o,kt=n,rt=a,B=s}}function cp(t,r){let e=r.reactions;if(e!==null){var i=ja.call(e,t);if(i!==-1){var o=e.length-1;o===0?e=r.reactions=null:(e[i]=e[o],e.pop())}}e===null&&r.f&2&&(Re===null||!Re.includes(r))&&(Ce(r,4096),r.f&768||(r.f^=512),dr(r,0))}function dr(t,r){var e=t.deps;if(e!==null)for(var i=r;i<e.length;i++)cp(t,e[i])}function cr(t){var r=t.f;if(!(r&16384)){Ce(t,1024);var e=k,i=B;if(k=t,w){var o=Ye;Ye=t.component_function}try{r&16?Ss(t):On(t),In(t),Fn(t);var n=wo(t);t.teardown=typeof n=="function"?n:null,t.wv=Ls;var a=t.deps;if(w&&vt&&t.f&2048&&a!==null)for(let l=0;l<a.length;l++){var s=a[l];s.trace_need_increase&&(s.wv=xi(),s.trace_need_increase=void 0,s.trace_v=void 0)}w&&Ai.push(t)}catch(l){Gr(l,t,e,i||t.ctx)}finally{k=e,w&&(Ye=o)}}}function Is(){console.error("Last ten effects were: ",Ai.slice(-10).map(t=>t.fn)),Ai=[]}function Us(){if(jr>1e3){jr=0;try{Qa()}catch(t){if(w&&ce(t,"stack",{value:""}),Yr!==null)if(w)try{Gr(t,Yr,null,null)}catch(r){throw Is(),r}else Gr(t,Yr,null,null);else throw w&&Is(),t}}jr++}function Hs(t){var r=t.length;if(r!==0){Us();var e=$t;$t=!0;try{for(var i=0;i<r;i++){var o=t[i];o.f&1024||(o.f^=1024);var n=[];Ws(o,n),dp(n)}}finally{$t=e}}}function dp(t){var r=t.length;if(r!==0)for(var e=0;e<r;e++){var i=t[e];if(!(i.f&24576))try{qt(i)&&(cr(i),i.deps===null&&i.first===null&&i.nodes_start===null&&(i.teardown===null?Bn(i):i.fn=null))}catch(o){Gr(o,i,null,i.ctx)}}}function up(){if(ki=!1,jr>1001)return;let t=fr;fr=[],Hs(t),ki||(jr=0,Yr=null,w&&(Ai=[]))}function Ti(t){So===Bs&&(ki||(ki=!0,queueMicrotask(up))),Yr=t;for(var r=t;r.parent!==null;){r=r.parent;var e=r.f;if(e&96){if(!(e&1024))return;r.f^=1024}}fr.push(r)}function Ws(t,r){var e=t.first,i=[];e:for(;e!==null;){var o=e.f,n=(o&32)!==0,a=n&&(o&1024)!==0,s=e.next;if(!a&&!(o&8192))if(o&8){if(n)e.f^=1024;else try{qt(e)&&cr(e)}catch(u){Gr(u,e,null,e.ctx)}var l=e.first;if(l!==null){e=l;continue}}else o&4&&i.push(e);if(s===null){let u=e.parent;for(;u!==null;){if(t===u)break e;var d=u.next;if(d!==null){e=d;continue e}u=u.parent}}e=s}for(var c=0;c<i.length;c++)l=i[c],r.push(l),Ws(l,r)}function Kr(t){var r=So,e=fr;try{Us();let o=[];So=pp,fr=o,ki=!1,Hs(e);var i=t==null?void 0:t();return As(),(fr.length>0||o.length>0)&&Kr(),jr=0,Yr=null,w&&(Ai=[]),i}finally{So=r,fr=e}}function R(t){var u,f;var r=t.f,e=(r&2)!==0;if(e&&r&16384){var i=Pn(t);return $i(t),i}if(bi!==null&&bi.add(t),I!==null){rt!==null&&rt.includes(t)&&ns();var o=I.deps;t.rv<$o&&(t.rv=$o,Re===null&&o!==null&&o[Le]===t?Le++:Re===null?Re=[t]:Re.push(t))}else if(e&&t.deps===null)for(var n=t,a=n.parent,s=n;a!==null;)if(a.f&2){var l=a;s=l,a=l.parent}else{var d=a;(u=d.deriveds)!=null&&u.includes(s)||((f=d.deriveds)!=null?f:d.deriveds=[]).push(s);break}if(e&&(n=t,qt(n)&&kn(n)),w&&vt&&wi!==null&&I!==null&&wi.reaction===I){if(t.debug)t.debug();else if(t.created){var c=wi.entries.get(t);c===void 0&&(c={read:[]},wi.entries.set(t,c)),c.read.push(Ct("TracedAt"))}}return t.v}function Y(t){let r=I;try{return I=null,t()}finally{I=r}}var fp=-7169;function Ce(t,r){t.f=t.f&fp|r}function mr(t,r=!1,e){B={p:B,c:null,e:null,m:!1,s:t,x:null,l:null},St&&!r&&(B.l={s:null,u:null,r1:[],r2:J(!1)}),w&&(B.function=e,Ye=e)}function hr(t){var a,s;let r=B;if(r!==null){t!==void 0&&(r.x=t);let l=r.e;if(l!==null){var e=k,i=I;r.e=null;try{for(var o=0;o<l.length;o++){var n=l[o];te(n.effect),De(n.reaction
7 months ago
<p>Choose how metadata fields are mapped to property names. The options are:</p>
<ul>
<li><strong>default</strong>: keep the original name.</li>
<li><strong>remap</strong>: rename the property.</li>
<li><strong>remove</strong>: remove the property entirely.</li>
</ul>
<p>
Don't forget to save your changes using the save button for each individual category.
3 days ago
</p>`,Zr(ua,{target:this.containerEl,props:{models:this.plugin.settings.propertyMappingModels.map(o=>o.copy()),save:o=>{let n=[];for(let a of this.plugin.settings.propertyMappingModels)a.type===o.type?n.push(o):n.push(a);this.plugin.settings.propertyMappingModels=n,new N.Notice(`MDB: Property mappings for ${o.type} saved successfully.`),this.plugin.saveSettings()}}})}}};var ai=require("obsidian");var Yo=class{constructor(){p(this,"toFormat");p(this,"locale");this.toFormat="YYYY-MM-DD",this.locale=new Intl.DateTimeFormat().resolvedOptions().locale}setFormat(r){this.toFormat=r}getPreview(r){let e=(0,ai.moment)();return r||(r=this.toFormat),e.locale(this.locale).format(r)}format(r,e,i="en"){if(!r)return null;let o;return e?o=(0,ai.moment)(r,e,i):this.hasMomentFormat(r)?o=(0,ai.moment)(r):o=(0,ai.moment)(new Date(r)),o.isValid()?o.locale(this.locale).format(this.toFormat):null}hasMomentFormat(r){return(0,ai.moment)(r,!0).isValid()}};var ut=require("obsidian");var Gt=require("obsidian");var jo=class extends Gt.Modal{constructor(e,i){var o,n;i=Object.assign({},Nl,i);super(e.app);p(this,"plugin");p(this,"elements");p(this,"title");p(this,"markdownComponent");p(this,"submitCallback");p(this,"closeCallback");this.plugin=e,this.title=(o=i.modalTitle)!=null?o:"",this.elements=(n=i.elements)!=null?n:[],this.markdownComponent=new Gt.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 i=e.createDiv({cls:"media-db-plugin-preview-wrapper"});this.markdownComponent.load();for(let n of this.elements){i.createEl("h3",{text:n.englishTitle});let a=i.createDiv({cls:"media-db-plugin-preview"}),s=this.plugin.generateMediaDbNoteFrontmatterPreview(n);s=`\`\`\`yaml
${s}\`\`\``;try{await Gt.MarkdownRenderer.render(this.app,s,a,"",this.markdownComponent)}catch(l){console.warn("mdb | error during rendering of preview",l)}}e.createDiv({cls:"media-db-plugin-spacer"});let o=new Gt.Setting(e);o.addButton(n=>{n.setButtonText("Cancel"),n.onClick(()=>this.close()),n.buttonEl.addClass("media-db-plugin-button")}),o.addButton(n=>{n.setButtonText("Ok"),n.setCta(),n.onClick(()=>{var a;return(a=this.submitCallback)==null?void 0:a.call(this,{confirmed:!0})}),n.buttonEl.addClass("media-db-plugin-button")})}onOpen(){this.preview()}onClose(){var e;this.markdownComponent.unload(),(e=this.closeCallback)==null||e.call(this)}};var pt=require("obsidian");var Go=class extends pt.Modal{constructor(e,i){var o,n;i=Object.assign({},Fl,i);super(e.app);p(this,"plugin");p(this,"query");p(this,"isBusy");p(this,"title");p(this,"selectedApis");p(this,"searchBtn");p(this,"submitCallback");p(this,"closeCallback");this.plugin=e,this.selectedApis=[],this.title=(o=i.modalTitle)!=null?o:"",this.query=(n=i.prefilledSearchString)!=null?n:"",this.isBusy=!1}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}keyPressCallback(e){e.key==="Enter"&&this.search()}async search(){var i,o,n;if(!this.query||this.query.length<3){new pt.Notice("MDB | Query too short");return}let e=this.selectedApis;if(e.length===0){new pt.Notice("MDB | No API selected");return}this.isBusy||(this.isBusy=!0,(i=this.searchBtn)==null||i.setDisabled(!1),(o=this.searchBtn)==null||o.setButtonText("Searching..."),(n=this.submitCallback)==null||n.call(this,{query:this.query,apis:e}))}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:this.title});let i="Search by title",o=new pt.TextComponent(e);o.inputEl.style.width="100%",o.setPlaceholder(i),o.setValue(this.query),o.onChange(n=>this.query=n),o.inputEl.addEventListener("keydown",this.keyPressCallback.bind(this)),e.appendChild(o.inputEl),o.inputEl.focus(),e.createDiv({cls:"media-db-plugin-spacer"}),e.createEl("h3",{text:"APIs to search"});for(let n of this.plugin.apiManager.apis){let a=e.createEl("div",{cls:"media-db-plugin-list-wrapper"}),s=a.createEl("div",{cls:"media-db-plugin-list-text-wrapper"});s.createEl("span",{text:n.apiName,cls:"media-db-plugin-list-text"}),s.createEl("small",{text:n.apiDescription,cls:"media-db-plugin-list-text"});let l=a.createEl("div",{cls:"media-db-plugin-list-toggle"}),d=new pt.ToggleComponent(l);d.setTooltip(n.apiName),d.setValue(this.selectedApis.some(c=>c===n.apiName)),d.onChange(c=>{c?this.selectedApis.push(n.apiName):this.selectedApis=this.selectedApis.filter(u=>u!==n.apiName)}),l.appendChild(d.toggleEl)}e.createDiv({cls:"media-db-plugin-spacer"}),new pt.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(){var i;(i=this.closeCallback)==null||i.call(this);let{contentEl:e}=this;e.empty()}};var ct=require("obsidian");var Ko=class extends ct.Modal{constructor(e,i){var o;i=Object.assign({},Il,i);super(e.app);p(this,"plugin");p(this,"query");p(this,"isBusy");p(this,"title");p(this,"selectedApi");p(this,"searchBtn");p(this,"submitCallback");p(this,"closeCallback");this.plugin=e,this.title=(o=i.modalTitle)!=null?o:"",this.selectedApi=i.preselectedAPI||e.apiManager.apis[0].apiName,this.query="",this.isBusy=!1}setSubmitCallback(e){this.submitCallback=e}setCloseCallback(e){this.closeCallback=e}keyPressCallback(e){e.key==="Enter"&&this.search()}async search(){var e,i,o;if(!this.query){new ct.Notice("MDB | no Id entered");return}if(!this.selectedApi){new ct.Notice("MDB | No API selected");return}this.isBusy||(this.isBusy=!0,(e=this.searchBtn)==null||e.setDisabled(!1),(i=this.searchBtn)==null||i.setButtonText("Searching..."),(o=this.submitCallback)==null||o.call(this,{query:this.query,api:this.selectedApi}))}onOpen(){let{contentEl:e}=this;e.createEl("h2",{text:this.title});let i="Search by id",o=new ct.TextComponent(e);o.inputEl.styl
`}),i.createEl("small",{text:`${e.type.toUpperCase()+(e.subType?` (${e.subType})`:"")} from ${e.dataSource}`})}submit(){var e,i;this.busy||(this.busy=!0,(e=this.submitButton)==null||e.setButtonText("Creating entry..."),(i=this.submitCallback)==null||i.call(this,{selected:this.selectModalElements.filter(o=>o.isActive()).map(o=>o.value)}))}skip(){var e,i;(e=this.skipButton)==null||e.setButtonText("Skipping..."),(i=this.skipCallback)==null||i.call(this)}onClose(){var e;(e=this.closeCallback)==null||e.call(this)}};var Ol={modalTitle:"Media DB Search",preselectedTypes:[],prefilledSearchString:""},Fl={modalTitle:"Media DB Advanced Search",preselectedAPIs:[],prefilledSearchString:""},Il={modalTitle:"Media DB Id Search",preselectedAPI:"",prefilledSearchString:""},Bl={modalTitle:"Media DB Search Results",elements:[],multiSelect:!0,skipButton:!1},Nl={modalTitle:"Media DB Preview",elements:[]},en=class{constructor(r){p(this,"plugin");this.plugin=r}async createSearchModal(r){let e=new zo(this.plugin,r);return{searchModalResult:await new Promise(o=>{e.setSubmitCallback(n=>o({code:"SUCCESS",data:n})),e.setCloseCallback(n=>{n&&o({code:"ERROR",error:n}),o({code:"CLOSE"})}),e.open()}),searchModal:e}}async openSearchModal(r,e){let{searchModalResult:i,searchModal:o}=await this.createSearchModal(r);if(console.debug(`MDB | searchModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new ut.Notice(i.error.toString()),o.close();return}if(i.code!=="CLOSE")try{let n=await e(i.data);return o.close(),n}catch(n){console.warn(n),new ut.Notice(`${n}`),o.close();return}}async createAdvancedSearchModal(r){let e=new Go(this.plugin,r);return{advancedSearchModalResult:await new Promise(o=>{e.setSubmitCallback(n=>o({code:"SUCCESS",data:n})),e.setCloseCallback(n=>{n&&o({code:"ERROR",error:n}),o({code:"CLOSE"})}),e.open()}),advancedSearchModal:e}}async openAdvancedSearchModal(r,e){let{advancedSearchModalResult:i,advancedSearchModal:o}=await this.createAdvancedSearchModal(r);if(console.debug(`MDB | advencedSearchModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new ut.Notice(i.error.toString()),o.close();return}if(i.code!=="CLOSE")try{let n=await e(i.data);return o.close(),n}catch(n){console.warn(n),new ut.Notice(`${n}`),o.close();return}}async createIdSearchModal(r){let e=new Ko(this.plugin,r);return{idSearchModalResult:await new Promise(o=>{e.setSubmitCallback(n=>o({code:"SUCCESS",data:n})),e.setCloseCallback(n=>{n&&o({code:"ERROR",error:n}),o({code:"CLOSE"})}),e.open()}),idSearchModal:e}}async openIdSearchModal(r,e){let{idSearchModalResult:i,idSearchModal:o}=await this.createIdSearchModal(r);if(console.debug(`MDB | idSearchModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new ut.Notice(i.error.toString()),o.close();return}if(i.code!=="CLOSE")try{let n=await e(i.data);return o.close(),n}catch(n){console.warn(n),new ut.Notice(`${n}`),o.close();return}}async createSelectModal(r){let e=new Qo(this.plugin,r);return{selectModalResult:await new Promise(o=>{e.setSubmitCallback(n=>o({code:"SUCCESS",data:n})),e.setSkipCallback(()=>o({code:"SKIP"})),e.setCloseCallback(n=>{n&&o({code:"ERROR",error:n}),o({code:"CLOSE"})}),e.open()}),selectModal:e}}async openSelectModal(r,e){let{selectModalResult:i,selectModal:o}=await this.createSelectModal(r);if(console.debug(`MDB | selectModal closed with code ${i.code}`),i.code==="ERROR"){console.warn(i.error),new ut.Notice(i.error.toString()),o.close();return}if(i.code!=="CLOSE"&&i.code!=="SKIP")try{let n=await e(i.data);return o.close(),n}catch(n){console.warn(n),new ut.Notice(`${n}`),o.close();return}}async createPreviewModal(r){let e=new jo(this.plugin,r);return{previewModalResult:await new Promise(o=>{e.setSubmitCallback(n=>o({code:"SUCCESS",data:n})),e.setCloseCallback(n=>{n&&o({code:"ERROR",error:n}),o({code:"CLOSE"})}),e.open()}),previewModal:e}}async openPreviewModal(r,e){let{previewModalResult:i,previewModal:o}=await this.createPreviewModal(r);if(console.debug(`MDB | previewModal closed with code ${i.code}`),i.code==="ERROR")return console.warn(i.error)
<%* const media = ${JSON.stringify(e)} %>
${(0,oe.stringifyYaml)(n)}---
8 months ago
${a}`:a=`---
3 days ago
${(0,oe.stringifyYaml)(n)}---
${a}`,a}async generateContentWithCustomFrontMatter(e,i,o){var l,d;let n=new RegExp(this.frontMatterRexExpPattern),a=this.getMetaDataFromFileContent(o),s=o.replace(n,"");if(i.attachFile){let c=(d=(l=this.app.metadataCache.getFileCache(i.attachFile))==null?void 0:l.frontmatter)!=null?d:{};s=await this.app.vault.read(i.attachFile),s=s.replace(n,""),s=s.startsWith(`
`)?s.substring(1):s,Object.keys(c).forEach(u=>{let f=c[u];!a[u]&&f&&(a[u]=f)})}return a.id||(a.id=e.id),a.type||(a.type=e.type),a.dataSource||(a.dataSource=e.dataSource),this.settings.enableTemplaterIntegration&&pn(this.app)?s=`---
<%* const media = ${JSON.stringify(e)} %>
${(0,oe.stringifyYaml)(a)}---
8 months ago
${s}`:s=`---
3 days ago
${(0,oe.stringifyYaml)(a)}---
${s}`,s}async attachFile(e,i,o){if(!o)return{fileMetadata:e,fileContent:i};let n=this.getMetadataFromFileCache(o);e=Object.assign(n,e);let a=await this.app.vault.read(o),s=new RegExp(this.frontMatterRexExpPattern);return a=a.replace(s,""),a=a.startsWith(`
`)?a.substring(1):a,i+=a,{fileMetadata:e,fileContent:i}}async attachTemplate(e,i,o){if(!o)return{fileMetadata:e,fileContent:i};let n=this.getMetaDataFromFileContent(o);e=Object.assign(n,e);let a=new RegExp(this.frontMatterRexExpPattern),s=o.replace(a,"");return i+=s,{fileMetadata:e,fileContent:i}}getMetaDataFromFileContent(e){let i,n=new RegExp(this.frontMatterRexExpPattern).exec(e);if(!n)return{};let a=n[0];return a?(a=a.substring(4),a=a.substring(0,a.length-3),i=(0,oe.parseYaml)(a),i||(i={}),console.debug("MDB | metadata read from file content",i),i):{}}getMetadataFromFileCache(e){var o;let i=(o=this.app.metadataCache.getFileCache(e))==null?void 0:o.frontmatter;return structuredClone(i!=null?i:{})}async createNote(e,i,o){var d;let n=(d=o.folder)!=null?d:this.app.vault.getAbstractFileByPath("/");if(!n||!(n instanceof oe.TFolder))throw new Error("MDB | invalid folder");e=Fa(e);let a=`${n.path}/${e}.md`,s=this.app.vault.getAbstractFileByPath(a);s&&await this.app.vault.delete(s);let l=await this.app.vault.create(a,i);if(console.debug(`MDB | created new file at ${a}`),o.openNote){let c=this.app.workspace.getUnpinnedLeaf();if(!c)return console.warn("MDB | no active leaf, not opening newly created note"),l;await c.openFile(l,{state:{mode:"source"}})}return l}async updateActiveNote(e=!1){var l,d,c;let i=(l=this.app.workspace.getActiveFile())!=null?l:void 0;if(!i)throw new Error("MDB | there is no active note");let o=this.getMetadataFromFileCache(i);if(o=this.modelPropertyMapper.convertObjectBack(o),console.debug("MDB | read metadata",o),!(o!=null&&o.type)||!(o!=null&&o.dataSource)||!(o!=null&&o.id))throw new Error("MDB | active note is not a Media DB entry or is missing metadata");let n=o,a=this.mediaTypeManager.createMediaTypeModelFromMediaType(n,n.type),s=await this.apiManager.queryDetailedInfoById(n.id,n.dataSource);s&&(s=Object.assign(a,s.getWithOutUserData()),e?await this.createMediaDbNoteFromModel(s,{attachFile:i,folder:(d=i.parent)!=null?d:void 0,openNote:!0}):await this.createMediaDbNoteFromModel(s,{attachTemplate:!0,folder:(c=i.parent)!=null?c:void 0,openNote:!0}))}async createEntriesFromFolder(e){let i=[],o=!1,{selectedAPI:n,titleFieldName:a,appendContent:s}=await new Promise(l=>{new co(this.app,this,(d,c,u)=>{l({selectedAPI:d,titleFieldName:c,appendContent:u})}).open()});for(let l of e.children)if(l instanceof oe.TFile){let d=l;if(o){i.push({filePath:d.path,error:"user canceled"});continue}let u=this.getMetadataFromFileCache(d)[a];if(!u){i.push({filePath:d.path,error:`metadata field '${a}' not found or empty`});continue}let f=[];try{f=await this.apiManager.query(u,[n])}catch(v){i.push({filePath:d.path,error:`${v}`});continue}if(!f||f.length===0){i.push({filePath:d.path,error:"no search results"});continue}let{selectModalResult:m,selectModal:g}=await this.modalHelper.createSelectModal({elements:f,skipButton:!0,modalTitle:`Results for '${u}'`});if(m.code==="ERROR"){i.push({filePath:d.path,error:m.error.message}),g.close();continue}if(m.code==="CLOSE"){i.push({filePath:d.path,error:"user canceled"}),g.close(),o=!0;continue}if(m.code==="SKIP"){i.push({filePath:d.path,error:"user skipped"}),g.close();continue}if(m.data.selected.length===0){i.push({filePath:d.path,error:"no search results selected"});continue}let h=await this.queryDetails(m.data.selected);await this.createMediaDbNotes(h,s?d:void 0),g.close()}i.length>0&&await this.createErroredFilesReport(i)}async createErroredFilesReport(e){let i=`MDB - bulk import error report ${Ba(new Date)}`,o=`${i}.md`,n=[["file","error"]].concat(e.map(s=>[s.filePath,s.error])),a=`# ${i}
3 days ago
${Ia(n)}`;await this.app.vault.create(o,a)}async loadSettings(){let e=await this.loadData(),i=Rl(this),o=Object.assign({},i,e),n=[];for(let a of i.propertyMappingModels){let s=o.propertyMappingModels.find(l=>l.type===a.type);if(s===void 0)n.push(a);else{let l=[];for(let d of a.properties){let c=s.properties.find(u=>u.property===d.property);c===void 0?l.push(d):l.push(new or(c.property,c.newProperty,c.mapping,d.locked))}n.push(new kr(s.type,l))}}o.propertyMappingModels=n,this.settings=o}async saveSettings(){this.mediaTypeManager.updateTemplates(this.settings),this.mediaTypeManager.updateFolders(this.settings),this.dateFormatter.setFormat(this.settings.customDateFormat),await this.saveData(this.settings)}};
/* nosourcemap */