@kit-data-manager/pid-component
Version:
The PID-Component is a web component that can be used to evaluate and display FAIR Digital Objects, PIDs, ORCiDs, and possibly other identifiers in a user-friendly way. It is easily extensible to support other identifier types.
18 lines • 85.1 kB
JavaScript
/*!
*
* Copyright 2024 Karlsruhe Institute of Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import{h as t,r as e,H as i,a as r}from"./p-DzUQJMIf.js";import"./json-viewer.entry.esm.js";class o{constructor(t,e){this._isDarkMode=false;this._settings=[];this._items=[];this._actions=[];this._value=t;this._settings=e;this.updateDarkMode()}get settings(){return this._settings}set settings(t){this._settings=t;this.updateDarkMode()}get items(){return this._items}get actions(){return this._actions}get value(){return this._value}get data(){return undefined}renderBody(){return undefined}get isDarkMode(){return this._isDarkMode}updateDarkMode(){var t;const e=(t=this._settings)===null||t===void 0?void 0:t.find((t=>t.name==="darkMode"));if(e){const t=e.value;if(t==="dark"){this._isDarkMode=true}else if(t==="light"){this._isDarkMode=false}else if(t==="system"&&typeof window!=="undefined"&&window.matchMedia){this._isDarkMode=window.matchMedia("(prefers-color-scheme: dark)").matches}}else{this._isDarkMode=false}}}class n extends o{getSettingsKey(){return"DateType"}async hasCorrectFormat(){const t=new RegExp("^([0-9]{4})-([0]?[1-9]|1[0-2])-([0-2][0-9]|3[0-1])(T([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9](.[0-9]*)?(Z|([+|-]([0-1][0-9]|2[0-3]):[0-5][0-9])){1}))$");return t.test(this.value)}init(){this._date=new Date(this.value);return}renderPreview(){return t("span",null,this._date.toLocaleString())}}let s;async function a(){if("caches"in self){s=await caches.open("pid-component")}}async function l(t,e){await a();if(s){const i=await s.match(t);if(i){return i.json()}else{let i;const r=t.split("://");if(r[0]!=="https"){i=await fetch(`https://${r[1]}`,e);if(!i){console.log(`404 for https://${r[1]} - trying http://${r[1]}`);i=await fetch(`http://${r[1]}`,e)}}else{i=await fetch(t,e)}await s.put(t,i.clone());return i.json()}}else{const i=await fetch(t,e);return i.json()}}async function c(){if(s){await s.delete("pid-component")}}class h{constructor(t,e,i,r,o,n,s,a,l,c,h){this._orcid=t;this._familyName=i;this._givenNames=r;this._employments=o;this._preferredLocale=n;this._biography=s;this._emails=a;this._keywords=l;this._researcherUrls=c;this._country=h;this._ORCiDJSON=e}get orcid(){return this._orcid}get familyName(){return this._familyName}get givenNames(){return this._givenNames}get ORCiDJSON(){return this._ORCiDJSON}get employments(){return this._employments}get preferredLocale(){return this._preferredLocale}get biography(){return this._biography}get emails(){return this._emails}get keywords(){return this._keywords}get researcherUrls(){return this._researcherUrls}get country(){return this._country}static isORCiD(t){const e=new RegExp("^(https://orcid.org/)?[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$");return e.test(t)}static async getORCiDInfo(t){if(!h.isORCiD(t))throw new Error("Invalid input");if(t.match("^(https://orcid.org/)?[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$")!==null)t=t.replace("https://orcid.org/","");const e=await l(`https://pub.orcid.org/v3.0/${t}`,{headers:{Accept:"application/json"}});let i="";let r=[];try{i=e["person"]["name"]["family-name"]["value"]}catch(t){console.debug(t)}try{r=e["person"]["name"]["given-names"]["value"]}catch(t){console.debug(t)}const o=e["activities-summary"]["employments"]["affiliation-group"];const n=[];try{for(let t=0;t<o.length;t++){const e=o[t]["summaries"][0]["employment-summary"];const i=new d(new Date,null,"","");if(e["start-date"]!==null)i.startDate=new Date(e["start-date"]["year"]["value"],e["start-date"]["month"]["value"],e["start-date"]["day"]["value"]);if(e["end-date"]!==null)i.endDate=new Date(e["end-date"]["year"]["value"],e["end-date"]["month"]["value"],e["end-date"]["day"]["value"]);i.organization=e["organization"]["name"];i.department=e["department-name"];n.push(i)}}catch(t){console.debug(t)}const s=e["preferences"]["locale"]!==null?e["preferences"]["locale"]:undefined;const a=e["person"]["biography"]!==null?e["person"]["biography"]["content"]:undefined;const c=[];if(e["person"]["emails"]["email"]!==null){for(const t of e["person"]["emails"]["email"]){c.push({email:t["email"],primary:t["primary"],verified:t["verified"]})}}const u=[];if(e["person"]["keywords"]["keyword"]!==null){for(const t of e["person"]["keywords"]["keyword"]){u.push({content:t["content"],index:t["display-index"]})}u.sort(((t,e)=>t.index-e.index))}const p=[];if(e["person"]["researcher-urls"]["researcher-url"]!==null){for(const t of e["person"]["researcher-urls"]["researcher-url"]){p.push({url:t["url"]["value"],name:t["url-name"],index:t["display-index"]})}p.sort(((t,e)=>t.index-e.index))}const f=e["person"]["addresses"]["address"].length>0?e["person"]["addresses"]["address"][0]["country"]["value"]:undefined;return new h(t,e,i,r,n,s,a,c,u,p,f)}static fromJSON(t){const e=JSON.parse(t);const i=e.employments.map((t=>d.fromJSON(t)));return new h(e.orcid,e.ORCiDJSON,e.familyName,e.givenNames,i,e.preferredLocale,e.biography,e.emails,e.keywords,e.researcherUrls,e.country)}getAffiliationsAt(t){const e=[];for(const i of this._employments){if(i.startDate<=t&&i.endDate===null)e.push(i);if(i.startDate<=t&&i.endDate!==null&&i.endDate>=t)e.push(i)}return e}getAffiliationAsString(t,e=true){if(t===undefined||t.organization===null)return undefined;else{if(e&&t.department!==null)return`${t.organization} [${t.department}]`;else return t.organization}}toObject(){return{orcid:this._orcid,ORCiDJSON:this._ORCiDJSON,familyName:this._familyName,givenNames:this._givenNames,employments:this._employments.map((t=>JSON.stringify(t.toObject()))),preferredLocale:this._preferredLocale,biography:this._biography,emails:this._emails,keywords:this._keywords,researcherUrls:this._researcherUrls,country:this._country}}}class d{constructor(t,e,i,r){this.startDate=t;this.endDate=e;this.organization=i;this.department=r}static fromJSON(t){const e=JSON.parse(t);const i=new Date(e.startDate);const r=e.endDate===null?null:new Date(e.endDate);return new d(i,r,e.organization,e.department)}toObject(){return{startDate:this.startDate,endDate:this.endDate,organization:this.organization,department:this.department}}}class u{constructor(t,e,i,r,o,n,s){this._estimatedTypePriority=0;this._priority=t;this._keyTitle=e;this._value=i;this._keyTooltip=r;this._keyLink=o;this._valueRegex=n;this._renderDynamically=s!==undefined?s:true;this._estimatedTypePriority=s?0:0}get priority(){return this._priority}get keyTitle(){return this._keyTitle}get value(){return this._value}get keyTooltip(){return this._keyTooltip}get keyLink(){return this._keyLink}get valueRegex(){return this._valueRegex}get renderDynamically(){return this._renderDynamically}get estimatedTypePriority(){return this._estimatedTypePriority}isValidValue(){return this._valueRegex?this._valueRegex.test(this._value):true}equals(t){return this._keyTitle===t._keyTitle&&this._value===t._value&&this._keyTooltip===t._keyTooltip&&this._keyLink===t._keyLink&&this._renderDynamically===t._renderDynamically}}class p{constructor(t,e,i,r){this._priority=t;this._title=e;this._link=i;this._style=r}get priority(){return this._priority}get title(){return this._title}get link(){return this._link}get style(){return this._style}equals(t){return this._priority===t._priority&&this._title===t._title&&this._link===t._link&&this._style===t._style}}class f extends o{constructor(){super(...arguments);this.affiliationAt=new Date(Date.now());this.showAffiliation=true}get data(){return JSON.stringify(this._orcidInfo.toObject())}async hasCorrectFormat(){return h.isORCiD(this.value)}async init(t){if(t!==undefined){this._orcidInfo=h.fromJSON(t);console.debug("reload ORCIDInfo from data",this._orcidInfo)}else{this._orcidInfo=await h.getORCiDInfo(this.value);console.debug("load ORCIDInfo from API",this._orcidInfo)}if(this.settings){for(const t of this.settings){switch(t["name"]){case"affiliationAt":this.affiliationAt=new Date(t["value"]);break;case"showAffiliation":this.showAffiliation=t["value"]===true||t["value"]==="true"||t["value"]==="1";break}}}this.items.push(new u(0,"ORCiD",this._orcidInfo.orcid,"ORCiD is a free service for researchers to distinguish themselves by creating a unique personal identifier.","https://orcid.org",undefined,false));try{const t=this._orcidInfo.givenNames;if(t){new u(2,"Given Names",this._orcidInfo.givenNames.toString(),"The given names of the person.")}}catch(t){console.log("Failed to obtain given names from ORCiD record.",t)}this.actions.push(new p(0,"Open ORCiD profile",`https://orcid.org/${this._orcidInfo.orcid}`,"primary"));try{const t=this._orcidInfo.getAffiliationsAt(new Date(Date.now()));for(const e of t){const t=this._orcidInfo.getAffiliationAsString(e);if(t!==undefined&&t.length>2)this.items.push(new u(50,"Current Affiliation",t,"The current affiliation of the person.",undefined,undefined,false))}}catch(t){console.log("Failed to obtain affiliations from ORCiD record.",t)}if(this._orcidInfo.getAffiliationsAt(this.affiliationAt)!==this._orcidInfo.getAffiliationsAt(new Date)&&this.affiliationAt.toLocaleDateString("en-US")!==(new Date).toLocaleDateString("en-US")){const t=this._orcidInfo.getAffiliationsAt(this.affiliationAt);for(const e of t){const t=this._orcidInfo.getAffiliationAsString(e);this.items.push(new u(49,"Affiliation at "+this.affiliationAt.toLocaleDateString("en-US",{year:"numeric",month:"numeric",day:"numeric"}),t,"The affiliation of the person at the given date.",undefined,undefined,false))}}if(this._orcidInfo.emails){const t=this._orcidInfo.emails.filter((t=>t.primary))[0];const e=this._orcidInfo.emails.filter((t=>!t.primary));if(t){this.items.push(new u(20,"Primary E-Mail address",t.email,"The primary e-mail address of the person."));this.actions.push(new p(0,"Send E-Mail",`mailto:${t.email}`,"secondary"))}if(e.length>0)this.items.push(new u(70,"Other E-Mail addresses",e.map((t=>t.email)).join(", "),"All other e-mail addresses of the person."));if(this._orcidInfo.preferredLocale)this.items.push(new u(25,"Preferred Language",this._orcidInfo.preferredLocale,"The preferred locale/language of the person."));for(const t of this._orcidInfo.researcherUrls){this.items.push(new u(100,t.name,t.url,"A link to a website specified by the person."))}if(this._orcidInfo.keywords.length>50)this.items.push(new u(60,"Keywords",this._orcidInfo.keywords.map((t=>t.content)).join(", "),"Keywords specified by the person.",undefined,undefined,false));if(this._orcidInfo.biography)this.items.push(new u(200,"Biography",this._orcidInfo.biography,"The biography of the person.",undefined,undefined,false));if(this._orcidInfo.country)this.items.push(new u(30,"Country",this._orcidInfo.country,"The country of the person."))}}isResolvable(){return this._orcidInfo.ORCiDJSON!==undefined}renderPreview(){return t("span",{class:`inline-flex flex-nowrap items-center align-top font-mono ${this.isDarkMode?"text-gray-200":""}`},t("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",class:"mr-1 h-5 flex-none items-center p-0.5"},t("style",{type:"text/css"},`.st0{fill:#A6CE39;}`,`.st1{fill:#FFFFFF;}`),t("path",{class:"st0",d:"M256,128c0,70.7-57.3,128-128,128C57.3,256,0,198.7,0,128C0,57.3,57.3,0,128,0C198.7,0,256,57.3,256,128z"}),t("g",null,t("path",{class:"st1",d:"M86.3,186.2H70.9V79.1h15.4v48.4V186.2z"}),t("path",{class:"st1",d:"M108.9,79.1h41.6c39.6,0,57,28.3,57,53.6c0,27.5-21.5,53.6-56.8,53.6h-41.8V79.1z M124.3,172.4h24.5\n c34.9,0,42.9-26.5,42.9-39.7c0-21.5-13.7-39.7-43.7-39.7h-23.7V172.4z"}),t("path",{class:"st1",d:"M88.7,56.8c0,5.5-4.5,10.1-10.1,10.1c-5.6,0-10.1-4.6-10.1-10.1c0-5.6,4.5-10.1,10.1-10.1\n C84.2,46.7,88.7,51.3,88.7,56.8z"}))),t("span",{class:`flex-none items-center px-1 ${this.isDarkMode?"text-gray-200":""}`},this._orcidInfo.familyName,", ",this._orcidInfo.givenNames," ",this.showAffiliation&&this._orcidInfo.getAffiliationsAt(new Date).length>0?`(${this._orcidInfo.getAffiliationAsString(this._orcidInfo.getAffiliationsAt(new Date)[0],false)}${this._orcidInfo.getAffiliationsAt(this.affiliationAt).length>0&&this.affiliationAt.toLocaleDateString()!==(new Date).toLocaleDateString()&&this._orcidInfo.getAffiliationsAt(this.affiliationAt)[0].organization!==this._orcidInfo.getAffiliationsAt(new Date)[0].organization?`, then: ${this._orcidInfo.getAffiliationsAt(this.affiliationAt)[0].organization}`:""})`:""))}getSettingsKey(){return"ORCIDType"}}class w{constructor(t,e){this._prefix=t;this._suffix=e}get prefix(){return this._prefix}get suffix(){return this._suffix}static isPID(t){return new RegExp("^([0-9A-Za-z])+.([0-9A-Za-z])+/([!-~])+$").test(t)}static getPIDFromString(t){if(!w.isPID(t))throw new Error("Invalid input");const e=t.split("/");return new w(e[0],e[1])}static fromJSON(t){const e=JSON.parse(t);return new w(e.prefix,e.suffix)}toString(){return`${this.prefix}/${this.suffix}`}isResolvable(){return!T.has(this)&&!this.prefix.toUpperCase().match("^(0$|0\\.|HS_|10320$)")}async resolve(){if(T.has(this))return undefined;else if($.has(this))return $.get(this);else{const t=await l(`https://hdl.handle.net/api/handles/${this.prefix}/${this.suffix}#resolve`);console.log(t);const e=t.values.map((async t=>{const e=(async()=>{if(w.isPID(t.type)){const e=w.getPIDFromString(t.type);const i=await m.resolveDataType(e);return i instanceof m?i:e}return t.type})();return{index:t.index,type:await e,data:t.data,ttl:t.ttl,timestamp:Date.parse(t.timestamp)}}));const i=await Promise.all(e);const r=new b(this,i);$.set(this,r);return r}}toObject(){return{prefix:this.prefix,suffix:this.suffix}}}const g=new w("10320","loc");class m{constructor(t,e,i,r,o){this._pid=t;this._name=e;this._description=i;this._regex=o;this._redirectURL=r}get pid(){return this._pid}get name(){return this._name}get description(){return this._description}get redirectURL(){return this._redirectURL}get regex(){return this._regex}static async resolveDataType(t){if(L.has(t))return L.get(t);if(!t.isResolvable()){console.debug(`PID ${t.toString()} has been marked as unresolvable`);return undefined}const e=await t.resolve();if(e===undefined){console.debug(`PID ${t.toString()} could not be resolved via the API`);T.add(t);return undefined}const i={name:"",description:"",redirectURL:"",ePICJSON:{}};for(let t=0;t<e.values.length;t++){const r=e.values[t];if(r.type===g||r.type.toString()===g.toString()){const t=new DOMParser;const e=t.parseFromString(r.data.value,"text/xml");const o=e.getElementsByTagName("location");for(let t=0;t<o.length;t++){const e={href:o[t].getAttribute("href"),weight:undefined,view:undefined,resolvedData:undefined};try{e.weight=parseInt(o[t].getAttribute("weight"))}catch(t){}try{e.view=o[t].getAttribute("view")}catch(t){}try{if(e.view==="json"){e.resolvedData=await l(e.href);i.ePICJSON=e.resolvedData;i.name=e.resolvedData["name"];i.description=e.resolvedData["description"]}else{i.redirectURL=e.href}}catch(t){}}}}try{const e=new m(t,i.name,i.description,i.redirectURL,i.regex);L.set(t,e);return e}catch(t){console.error(t);return undefined}}static fromJSON(t){const e=JSON.parse(t);return new m(w.fromJSON(e.pid),e.name,e.description,e.redirectURL,e.regex)}toObject(){return{pid:JSON.stringify(this._pid.toObject()),name:this._name,description:this._description,redirectURL:this._redirectURL,regex:this._regex}}}class b{constructor(t,e){this._values=[];this._pid=t;this._values=e}get pid(){return this._pid}get values(){return this._values}static fromJSON(t){const e=JSON.parse(t);const i=e.values.map((t=>{const e=JSON.parse(t);const i=JSON.parse(e.type);let r;if(i.pidDataType!==undefined){r=m.fromJSON(i.pidDataType)}else if(i.pid!==undefined){r=w.fromJSON(i.pid)}else{r=i.string}const o=JSON.parse(e.data);return{index:e.index,type:r,data:o,ttl:e.ttl,timestamp:e.timestamp}}));return new b(w.fromJSON(e.pid),i)}toObject(){return{pid:JSON.stringify(this._pid.toObject()),values:this._values.map((t=>JSON.stringify({index:t.index,type:JSON.stringify({pid:t.type instanceof w?JSON.stringify(t.type.toObject()):undefined,pidDataType:t.type instanceof m?JSON.stringify(t.type.toObject()):undefined,string:typeof t.type=="string"?t.type:undefined}),data:JSON.stringify(t.data),ttl:t.ttl,timestamp:t.timestamp})))}}}class v extends o{constructor(){super(...arguments);this._parts=[]}get data(){return JSON.stringify(this._pidRecord.toObject())}async hasCorrectFormat(){return w.isPID(this.value)}async init(t){if(t!==undefined){this._pidRecord=b.fromJSON(t);this._parts=await Promise.all([{text:this._pidRecord.pid.prefix,nextExists:true},{text:this._pidRecord.pid.suffix,nextExists:false}]);console.debug("reload PIDRecord from data",this._pidRecord)}else{const t=w.getPIDFromString(this.value);this._parts=[{text:t.prefix,nextExists:true},{text:t.suffix,nextExists:false}];this._pidRecord=await t.resolve();console.debug("load PIDRecord from API",this._pidRecord)}for(const t of this._pidRecord.values){if(t.type instanceof m){this.items.push(new u(0,t.type.name,t.data.value,t.type.description,t.type.redirectURL,t.type.regex))}}this.actions.push(new p(0,"Open in FAIR-DOscope",`https://kit-data-manager.github.io/fairdoscope/?pid=${this._pidRecord.pid.toString()}`,"primary"));this.actions.push(new p(0,"View in Handle.net registry",`https://hdl.handle.net/${this._pidRecord.pid.toString()}`,"secondary"));return}isResolvable(){return this._pidRecord.values.length>0}renderPreview(){return t("span",{class:"rounded-md bg-inherit font-mono font-bold"},this._parts.map((e=>t("span",{class:"font-mono font-bold"},t("color-highlight",{text:e.text}),t("span",{class:`mx-0.5 font-mono font-bold`},e.nextExists?"/":"")))))}getSettingsKey(){return"HandleType"}}class y extends o{getSettingsKey(){return"EmailType"}async hasCorrectFormat(){const t=/^(([\w\-.]+@([\w-]+\.)+[\w-]{2,})(\s*,\s*)?)*$/gm;return t.test(this.value)}init(){return}renderPreview(){return t("span",{class:`inline-flex items-center gap-2 font-mono text-sm text-blue-500`},this.value.split(new RegExp(/\s*,\s*/)).filter((t=>t.length>0)).map((e=>t("a",{href:"mailto:"+e,rel:"noopener noreferrer",target:"_blank",class:`inline-flex items-center rounded-md border border-slate-500 px-1 py-0.5 font-mono text-sm text-blue-500`},t("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none","aria-hidden":"true",viewBox:"0 0 24 24",stroke:"currentColor","stroke-width":"1",height:"20px",class:"mr-2"},t("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M21.75 6.75v10.5a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25m19.5 0v.243a2.25 2.25 0 0 1-1.07 1.916l-7.5 4.615a2.25 2.25 0 0 1-2.36 0L3.32 8.91a2.25 2.25 0 0 1-1.07-1.916V6.75"})),t("span",{class:`ml-2 text-blue-400 hover:text-blue-500`},e)))))}}class x extends o{getSettingsKey(){return"URLType"}async hasCorrectFormat(){const t=new RegExp("^http(s)?:(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$");return t.test(this.value)}init(){return}renderPreview(){return t("a",{href:this.value,target:"_blank",rel:"noopener noreferrer",class:`font-mono text-sm text-blue-400`},this.value)}}class k extends o{async hasCorrectFormat(){return true}init(){return}renderPreview(){return t("span",null,this.value)}getSettingsKey(){return"FallbackType"}}class C extends o{getSettingsKey(){return"LocaleType"}async hasCorrectFormat(){const t=/^([a-zA-Z]{2})(-[A-Z]{2})?$/;return t.test(this.value)}init(){return}renderPreview(){return t("locale-visualization",{locale:this.value,showFlag:true})}}class D extends o{constructor(){super(...arguments);this._parsedJsonResult=undefined}getParsedJson(){if(this._parsedJsonResult===undefined){try{if(typeof this.value==="object"&&this.value!==null){this._parsedJsonResult={data:this.value};return this._parsedJsonResult}if(typeof this.value!=="string"){throw new Error("Input value is not a string or object")}const t=this.value.trim();if(t===""){this._parsedJsonResult={error:new Error("Empty JSON string")};return this._parsedJsonResult}const e=JSON.parse(t);this._parsedJsonResult={data:e}}catch(t){this._parsedJsonResult={error:t instanceof Error?t:new Error(String(t))}}}return this._parsedJsonResult}getSettingsKey(){return"JSONType"}async hasCorrectFormat(){const{data:t,error:e}=this.getParsedJson();if(e){console.warn("JSONType has incorrect format:",e.message,"for value:",this.value);return false}return typeof t==="object"&&t!==null}init(){this._parsedJsonResult=undefined;return Promise.resolve()}isResolvable(){return false}renderPreview(){const{data:e,error:i}=this.getParsedJson();if(i){return t("span",{class:"text-red-500"},"Invalid JSON")}const r=typeof e==="object"&&e!==null;const o=Array.isArray(e);if(r){const i=Object.keys(e).length;return t("div",{class:"w-full"},t("div",{class:`flex items-center rounded-md font-mono text-xs`},t("span",{class:`mr-1 font-medium`},o?"Array":"Object"),t("span",{class:"text-gray-500"},o?"[":"{"),t("span",{class:`text-xs text-gray-500`},i," ",i===1?"item":"items"),t("span",{class:"text-gray-500"},o?"]":"}")))}return t("div",{class:"w-full"},t("pre",{class:`max-w-full overflow-x-auto rounded-md font-mono text-xs whitespace-pre-wrap`},JSON.stringify(e,null,2)))}renderBody(){var e,i;const{data:r,error:o}=this.getParsedJson();const n=((i=(e=this.settings)===null||e===void 0?void 0:e.find((t=>t.name==="darkMode")))===null||i===void 0?void 0:i.value)||"system";if(o){return t("div",{class:"w-full overflow-y-auto"},t("span",{class:"text-red-500"},"Invalid JSON data: ",o.message))}return t("div",{class:"w-full overflow-y-auto"},t("json-viewer",{data:r,"expand-all":false,"show-line-numbers":true,theme:n},t("span",{class:"text-red-500"},"Could not display JSON data.")))}}class I extends o{constructor(){super(...arguments);this.relationshipTypes={parent:{title:"Parent Organization",tooltip:"Organization that this organization is part of"},child:{title:"Child Organization",tooltip:"Organization that is part of this organization"},related:{title:"Related Organization",tooltip:"Organization that is related to this organization"},predecessor:{title:"Predecessor Organization",tooltip:"Organization that preceded this organization"},successor:{title:"Successor Organization",tooltip:"Organization that succeeded this organization"}};this.contentMappings={active:"🟢 Active",inactive:"⚪️ Inactive",withdrawn:"⚠️ Withdrawn",education:"🏫 Education",funder:"💰 Funder",healthcare:"🏥 Healthcare",company:"🏢 Company",archive:"📚 Archive",nonprofit:"🎗️ Nonprofit",government:"🏛️ Government",facility:"🔬 Facility",other:"Other",unknown:"❓ Unknown"}}getSettingsKey(){return"RORType"}async hasCorrectFormat(){const t=new RegExp("^https?://ror.org/[0-9a-z]{9}$","i");return t.test(this.value)}getRorId(){return this.value.split("/").pop()}getOptimizedContent(t){if(this.contentMappings[t.toLowerCase()]){return this.contentMappings[t.toLowerCase()]}return t}async init(){try{const t=this.getRorId();const e=await fetch(`https://api.ror.org/v2/organizations/${t}`);if(!e.ok){throw new Error(`Failed to fetch ROR data: ${e.status}`)}this.rorData=await e.json();if(!this.rorData)return;if(!this.rorData.names||this.rorData.names.length===0){this.label="Unknown";this.items.push(new u(0,"Name","Unknown","No names available for this organization"));return}else{for(const t of this.rorData.names){const e=t.types||[];if(e.includes("acronym")){this.acronym=t.value;this.items.push(new u(20,"Acronym",t.value,"Short form of the organization name"))}else if(e.includes("ror_display")){this.label=t.value;this.items.push(new u(1,"Display Name",t.value,"Name used for display purposes"))}else if(e.includes("alias")){this.items.push(new u(5,"Alias",t.value,"Alternative name for the organization"))}else if(e.includes("label")){this.items.push(new u(15,"Label",t.value,"Name in another language or script"))}}}this.items.push(new u(20,"ROR ID",this.rorData.id,"Unique identifier for the organization in the ROR registry",null,null,false));this.actions.push(new p(10,"View on ROR",this.rorData.id,"primary"));this.items.push(new u(30,"Status",this.getOptimizedContent(this.rorData.status||"unknown"),"Current status of the organization in the ROR registry"));if(!this.rorData.types||this.rorData.types.length===0){this.items.push(new u(25,"Type",this.getOptimizedContent("unknown"),"Type of organization"))}else{for(const t of this.rorData.types){this.items.push(new u(25,"Type",this.getOptimizedContent(t),"Type of organization"))}}if(this.rorData.links&&this.rorData.links.length>0){for(const t of this.rorData.links){if(t.type){this.items.push(new u(35,`Link to ${t.type}`,t.value,"External link related to the organization"))}else{this.items.push(new u(35,`Link`,t.value,"External link related to the organization"))}}}if(this.rorData.external_ids&&this.rorData.external_ids.length>0){for(const t of this.rorData.external_ids){const e=t.type;const i=t.preferred||t.all[0];this.items.push(new u(40,`External ID: ${e}`,i,`Identifier from another system: ${e}`))}}if(this.rorData.relationships&&this.rorData.relationships.length>0){for(const t of this.rorData.relationships){const e=this.relationshipTypes[t.type]||{title:t.type,tooltip:`${t.type} organization`};this.items.push(new u(90,e.title,t.id,e.tooltip))}}if(this.rorData.locations&&this.rorData.locations.length>0){for(const t of this.rorData.locations){const e=t.geonames_details;if(e.country_code){this.items.push(new u(50,"Country",e.country_code,"Country where the organization is located"))}if(e.lat&&e.lng){this.items.push(new u(55,"Coordinates",`${e.lat}, ${e.lng}`,"Geographic coordinates of the organization"));const t=`https://www.openstreetmap.org/?mlat=${e.lat}&mlon=${e.lng}&zoom=15`;this.actions.push(new p(20,"View on OpenStreetMap",t,"secondary"))}}}}catch(t){console.error("Error fetching ROR data:",t);this.items.push(new u(0,"Error",`Failed to fetch data from ROR API: ${t.message}`))}}renderPreview(){if(!this.rorData){return t("span",{class:`font-mono text-sm`},"Loading ROR: ",this.value,"...")}return t("span",{class:`inline-flex flex-nowrap items-center align-top font-mono`},t("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 164 118",version:"1.1",class:"mr-1 h-5 flex-none items-center p-0.5",style:{fillRule:"evenodd",clipRule:"evenodd",strokeLinejoin:"round",strokeMiterlimit:"2"}},t("g",{transform:"matrix(0.994301,0,0,0.989352,0,0)"},t("rect",{x:"0",y:"0",width:"164.94",height:"119.27",style:{fill:"white"}})),t("g",{transform:"matrix(1,0,0,1,-0.945,-0.815)"},t("path",{d:"M68.65,4.16L56.52,22.74L44.38,4.16L68.65,4.16Z",style:{fill:"rgb(83,186,161)",fillRule:"nonzero"}}),t("path",{d:"M119.41,4.16L107.28,22.74L95.14,4.16L119.41,4.16Z",style:{fill:"rgb(83,186,161)",fillRule:"nonzero"}}),t("path",{d:"M44.38,115.47L56.52,96.88L68.65,115.47L44.38,115.47Z",style:{fill:"rgb(83,186,161)",fillRule:"nonzero"}}),t("path",{d:"M95.14,115.47L107.28,96.88L119.41,115.47L95.14,115.47Z",style:{fill:"rgb(83,186,161)",fillRule:"nonzero"}}),t("path",{d:"M145.53,63.71C149.83,62.91 153.1,61 155.33,57.99C157.57,54.98 158.68,51.32 158.68,47.03C158.68,43.47 158.06,40.51 156.83,38.13C155.6,35.75 153.93,33.86 151.84,32.45C149.75,31.05 147.31,30.04 144.53,29.44C141.75,28.84 138.81,28.54 135.72,28.54L112.16,28.54L112.16,47.37C111.97,46.82 111.77,46.28 111.55,45.74C109.92,41.79 107.64,38.42 104.71,35.64C101.78,32.86 98.32,30.72 94.3,29.23C90.29,27.74 85.9,26.99 81.14,26.99C76.38,26.99 72,27.74 67.98,29.23C63.97,30.72 60.5,32.86 57.57,35.64C54.95,38.13 52.85,41.1 51.27,44.54C51.04,42.07 50.46,39.93 49.53,38.13C48.3,35.75 46.63,33.86 44.54,32.45C42.45,31.05 40.01,30.04 37.23,29.44C34.45,28.84 31.51,28.54 28.42,28.54L4.87,28.54L4.87,89.42L18.28,89.42L18.28,65.08L24.9,65.08L37.63,89.42L53.71,89.42L38.24,63.71C42.54,62.91 45.81,61 48.04,57.99C48.14,57.85 48.23,57.7 48.33,57.56C48.31,58.03 48.3,58.5 48.3,58.98C48.3,63.85 49.12,68.27 50.75,72.22C52.38,76.17 54.66,79.54 57.59,82.32C60.51,85.1 63.98,87.24 68,88.73C72.01,90.22 76.4,90.97 81.16,90.97C85.92,90.97 90.3,90.22 94.32,88.73C98.33,87.24 101.8,85.1 104.73,82.32C107.65,79.54 109.93,76.17 111.57,72.22C111.79,71.69 111.99,71.14 112.18,70.59L112.18,89.42L125.59,89.42L125.59,65.08L132.21,65.08L144.94,89.42L161.02,89.42L145.53,63.71ZM36.39,50.81C35.67,51.73 34.77,52.4 33.68,52.83C32.59,53.26 31.37,53.52 30.03,53.6C28.68,53.69 27.41,53.73 26.2,53.73L18.29,53.73L18.29,39.89L27.06,39.89C28.26,39.89 29.5,39.98 30.76,40.15C32.02,40.32 33.14,40.65 34.11,41.14C35.08,41.63 35.89,42.33 36.52,43.25C37.15,44.17 37.47,45.4 37.47,46.95C37.47,48.6 37.11,49.89 36.39,50.81ZM98.74,66.85C97.85,69.23 96.58,71.29 94.91,73.04C93.25,74.79 91.26,76.15 88.93,77.13C86.61,78.11 84.01,78.59 81.15,78.59C78.28,78.59 75.69,78.1 73.37,77.13C71.05,76.16 69.06,74.79 67.39,73.04C65.73,71.29 64.45,69.23 63.56,66.85C62.67,64.47 62.23,61.85 62.23,58.98C62.23,56.17 62.67,53.56 63.56,51.15C64.45,48.74 65.72,46.67 67.39,44.92C69.05,43.17 71.04,41.81 73.37,40.83C75.69,39.86 78.28,39.37 81.15,39.37C84.02,39.37 86.61,39.86 88.93,40.83C91.25,41.8 93.24,43.17 94.91,44.92C96.57,46.67 97.85,48.75 98.74,51.15C99.63,53.56 100.07,56.17 100.07,58.98C100.07,61.85 99.63,64.47 98.74,66.85ZM143.68,50.81C142.96,51.73 142.06,52.4 140.97,52.83C139.88,53.26 138.66,53.52 137.32,53.6C135.97,53.69 134.7,53.73 133.49,53.73L125.58,53.73L125.58,39.89L134.35,39.89C135.55,39.89 136.79,39.98 138.05,40.15C139.31,40.32 140.43,40.65 141.4,41.14C142.37,41.63 143.18,42.33 143.81,43.25C144.44,44.17 144.76,45.4 144.76,46.95C144.76,48.6 144.4,49.89 143.68,50.81Z",style:{fill:"rgb(32,40,38)",fillRule:"nonzero"}}))),t("span",{class:`flex-none items-center px-1`},this.label,this.acronym?" ("+this.acronym+")":""))}get data(){return this.rorData}}const S=new RegExp("^https?://spdx.org/licenses/[\\w.\\-+]+/?$","i");class O extends o{constructor(){super(...arguments);this.licenseData=null;this.licenseId="";this.corsFallback=true;this.corsProxy="https://corsproxy.io/?";this.spdxBaseUrl="https://spdx.org/licenses";this.fileFormat="json";this.requestTimeout=1e4}getSettingsKey(){return"SPDXType"}async hasCorrectFormat(){const t=S.test(this.value);const e=/^[\w.\-+]+$/;const i=e.test(this.value);if(!t&&!i){return false}let r;if(t){r=this.value.replace(/^https?:\/\/spdx\.org\/licenses\//i,"").replace(/\/$/,"")}else{r=this.value}const o=await this.validateLicense(r);console.log("SPDX License validation result:",{licenseId:r,isValid:o,licenseData:this.licenseData});return o}async validateLicense(t){try{console.log(`Validating SPDX license: ${t}`);this.licenseId=t;const e=this.buildLicenseApiUrl(t);const i=new AbortController;const r=setTimeout((()=>i.abort()),this.requestTimeout);const o=await fetch(e,{signal:i.signal});clearTimeout(r);if(!o.ok){console.log(`License ${t} validation failed with status ${o.status}`);return false}const n=await o.json();console.log(`License API response for ${t}:`,n);if(n&&n.licenseId){this.licenseData=n;console.log(`License data populated for ${t}:`,this.licenseData);return true}console.log(`Invalid license data received for ${t}`);return false}catch(e){console.error(`License validation error for ${t}:`,e);return false}}buildLicenseApiUrl(t){const e=this.corsFallback?`${this.corsProxy}${encodeURIComponent(`${this.spdxBaseUrl}/${t}.${this.fileFormat}`)}`:`${this.spdxBaseUrl}/${t}.${this.fileFormat}`;return e}get data(){return this.licenseData}logLicenseData(){console.log("Current license data:",{licenseId:this.licenseId,licenseData:this.licenseData,hasData:Boolean(this.licenseData&&this.licenseData.licenseId&&this.licenseData.name)})}async init(){try{if(!this.licenseId){this.extractLicenseIdFromInput()}if(!this.licenseData){await this.fetchLicenseData()}else{console.debug(`Using pre-fetched data for license ${this.licenseId}`)}this.populateLicenseData();this.addActionButtons()}catch(t){console.error("Error fetching SPDX data:",t);this.handleInitError(t)}}extractLicenseIdFromInput(){if(!this.value.includes("/")&&!this.value.includes("://")){this.licenseId=this.value.trim()}else{this.licenseId=this.value.replace(/^https?:\/\/spdx\.org\/licenses\//i,"").replace(/\/$/,"").replace(/\.(json|html)$/i,"")}}async fetchLicenseData(){const t=new Promise(((t,e)=>{setTimeout((()=>e(new Error("Request timeout"))),this.requestTimeout)}));try{const e=this.buildApiUrl();console.debug(`Fetching license data from: ${e}`);const i=fetch(e);const r=await Promise.race([i,t]);if(!r.ok){if(this.corsFallback&&e.includes(this.corsProxy)){await this.tryFallbackOptions()}else{throw new Error(`Failed to fetch SPDX data: ${r.status}`)}}else{this.licenseData=await r.json()}if(!this.licenseData){throw new Error("No license data available")}}catch(t){console.warn("Error fetching SPDX license data:",t);throw t}}async tryFallbackOptions(){const t=new Promise(((t,e)=>{setTimeout((()=>e(new Error("Request timeout"))),this.requestTimeout)}));const e=`${this.spdxBaseUrl}/${this.licenseId}.${this.fileFormat}`;const i=fetch(e);const r=await Promise.race([i,t]);if(!r.ok){throw new Error(`Failed to fetch SPDX data: ${r.status}`)}this.licenseData=await r.json()}buildApiUrl(){return this.buildLicenseApiUrl(this.licenseId)}populateLicenseData(){if(!this.licenseData)return;this.items.push(new u(0,"Full Name",this.licenseData.name,"The full legal name of the license",null,null,false));this.items.push(new u(10,"SPDX ID",this.licenseData.licenseId,"The unique SPDX identifier for this license",null,null,false));this.addDeprecationInfo();this.items.push(new u(20,"OSI Approved",this.licenseData.isOsiApproved?"Yes":"No","Whether the license is approved by the Open Source Initiative","https://opensource.org/licenses/",null,false));this.addFsfInfo();this.addRelatedUrls()}addDeprecationInfo(){if(!this.licenseData||!this.licenseData.isDeprecatedLicenseId)return;this.items.push(new u(15,"Deprecated","Yes","This license ID has been deprecated by SPDX",null,null,false));if(this.licenseData.deprecatedVersion){this.items.push(new u(16,"Deprecated Since",this.licenseData.deprecatedVersion,"The SPDX version when this license was deprecated",null,null,false))}}addFsfInfo(){if(!this.licenseData||this.licenseData.isFsfLibre===undefined)return;this.items.push(new u(25,"FSF Free/Libre",this.licenseData.isFsfLibre?"Yes":"No",'Whether the license is considered "Free" by the Free Software Foundation',"https://www.fsf.org/licensing/",null,false))}addRelatedUrls(){if(!this.licenseData||!this.licenseData.seeAlso||this.licenseData.seeAlso.length===0)return;for(let t=0;t<this.licenseData.seeAlso.length;t++){const e=this.licenseData.seeAlso[t];this.items.push(new u(30+t,`Related URL`,e,"A related URL with more information about this license"))}}addActionButtons(){if(!this.licenseData)return;this.actions.push(new p(10,"View on SPDX",`https://spdx.org/licenses/${this.licenseData.licenseId}`,"primary"));if(this.licenseData.isOsiApproved){this.actions.push(new p(20,"View on OSI","https://opensource.org/licenses/","secondary"))}this.addOfficialLicenseLink()}addOfficialLicenseLink(){if(!this.licenseData||!this.licenseData.seeAlso||this.licenseData.seeAlso.length===0)return;const t=this.findOfficialUrl(this.licenseData.seeAlso)||this.licenseData.seeAlso[0];this.actions.push(new p(30,"View Official License",t,"secondary"))}findOfficialUrl(t){const e=["opensource.org","fsf.org","gnu.org","apache.org","creativecommons.org"];return t.find((t=>{try{const i=new URL(t);return e.includes(i.host)}catch(t){return false}}))}handleInitError(t){if(t.message&&t.message.includes("CORS")){this.items.push(new u(0,"Error",`CORS error: Cannot access SPDX API due to cross-origin restrictions. The proxy service may be unavailable.`,"This is a browser security restriction. Try again later or use a different browser."))}else{this.items.push(new u(0,"Error",`Failed to fetch data from SPDX API: ${t.message}`))}this.addBasicErrorInfo();this.addNetworkIssueInfo();this.licenseData={licenseId:this.licenseId,name:this.licenseId}}addBasicErrorInfo(){if(this.licenseId){this.items.push(new u(10,"License ID",this.licenseId,"The license identifier that was detected"));this.actions.push(new p(10,"View on SPDX",`https://spdx.org/licenses/${this.licenseId}`,"primary"))}else{this.licenseId=this.value.replace(/^https?:\/\/spdx\.org\/licenses\//i,"").replace(/\/$/,"");this.items.push(new u(10,"Possible License ID",this.licenseId,"Extracted from the input value"));this.actions.push(new p(10,"Search on SPDX","https://spdx.org/licenses/","primary"))}}addNetworkIssueInfo(){this.items.push(new u(20,"Network Issue","The SPDX API could not be reached. This may be due to network connectivity issues or the SPDX service being unavailable.","Try again when you have internet connectivity"))}renderPreview(){if(!this.licenseData){return t("span",{class:`font-mono text-sm`},"SPDX: ",this.licenseId||this.value)}return t("span",{class:`flex flex-nowrap items-center align-top font-mono`},t("span",{class:"items-center px-1"},t("span",{class:`font-medium`},this.licenseData.name||this.licenseId),this.licenseData.licenseId&&t("span",{class:`ml-1 text-gray-500`},"(",this.licenseData.licenseId,")")))}}const z=[{priority:0,key:"DateType",constructor:n},{priority:1,key:"ORCIDType",constructor:f},{priority:2,key:"HandleType",constructor:v},{priority:3,key:"RORType",constructor:I},{priority:4,key:"SPDXType",constructor:O},{priority:5,key:"EmailType",constructor:y},{priority:6,key:"URLType",constructor:x},{priority:7,key:"LocaleType",constructor:C},{priority:8,key:"JSONType",constructor:D},{priority:99,key:"FallbackType",constructor:k}];const L=new Map;const $=new Map;const T=new Set;class P{static async getEstimatedPriority(t){let e=0;for(let i=0;i<z.length;i++){const r=new z[i].constructor(t);if(await r.hasCorrectFormat()){e=i;break}}return e}static async getBestFit(t,e){var i;let r=new z[z.length-1].constructor(t);for(let e=z.length-1;e>=0;e--){const i=new z[e].constructor(t);if(await i.hasCorrectFormat())r=i}try{const t=r.getSettingsKey();const o=(i=e.find((e=>e.type===t)))===null||i===void 0?void 0:i.values;if(o)r.settings=o}catch(t){console.warn("Error while adding settings to object:",t)}await r.init();return r}}const M=(t,e)=>e.some((e=>t instanceof e));let R;let E;function N(){return R||(R=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function A(){return E||(E=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const F=new WeakMap;const B=new WeakMap;const J=new WeakMap;function j(t){const e=new Promise(((e,i)=>{const r=()=>{t.removeEventListener("success",o);t.removeEventListener("error",n)};const o=()=>{e(q(t.result));r()};const n=()=>{i(t.error);r()};t.addEventListener("success",o);t.addEventListener("error",n)}));J.set(e,t);return e}function U(t){if(F.has(t))return;const e=new Promise(((e,i)=>{const r=()=>{t.removeEventListener("complete",o);t.removeEventListener("error",n);t.removeEventListener("abort",n)};const o=()=>{e();r()};const n=()=>{i(t.error||new DOMException("AbortError","AbortError"));r()};t.addEventListener("complete",o);t.addEventListener("error",n);t.addEventListener("abort",n)}));F.set(t,e)}let X={get(t,e,i){if(t instanceof IDBTransaction){if(e==="done")return F.get(t);if(e==="store"){return i.objectStoreNames[1]?undefined:i.objectStore(i.objectStoreNames[0])}}return q(t[e])},set(t,e,i){t[e]=i;return true},has(t,e){if(t instanceof IDBTransaction&&(e==="done"||e==="store")){return true}return e in t}};function V(t){X=t(X)}function K(t){if(A().includes(t)){return function(...e){t.apply(H(this),e);return q(this.request)}}return function(...e){return q(t.apply(H(this),e))}}function Z(t){if(typeof t==="function")return K(t);if(t instanceof IDBTransaction)U(t);if(M(t,N()))return new Proxy(t,X);return t}function q(t){if(t instanceof IDBRequest)return j(t);if(B.has(t))return B.get(t);const e=Z(t);if(e!==t){B.set(t,e);J.set(e,t)}return e}const H=t=>J.get(t);function W(t,e,{blocked:i,upgrade:r,blocking:o,terminated:n}={}){const s=indexedDB.open(t,e);const a=q(s);if(r){s.addEventListener("upgradeneeded",(t=>{r(q(s.result),t.oldVersion,t.newVersion,q(s.transaction),t)}))}if(i){s.addEventListener("blocked",(t=>i(t.oldVersion,t.newVersion,t)))}a.then((t=>{if(n)t.addEventListener("close",(()=>n()));if(o){t.addEventListener("versionchange",(t=>o(t.oldVersion,t.newVersion,t)))}})).catch((()=>{}));return a}const _=["get","getKey","getAll","getAllKeys","count"];const G=["put","add","delete","clear"];const Y=new Map;function Q(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e==="string")){return}if(Y.get(e))return Y.get(e);const i=e.replace(/FromIndex$/,"");const r=e!==i;const o=G.includes(i);if(!(i in(r?IDBIndex:IDBObjectStore).prototype)||!(o||_.includes(i))){return}const n=async function(t,...e){const n=this.transaction(t,o?"readwrite":"readonly");let s=n.store;if(r)s=s.index(e.shift());return(await Promise.all([s[i](...e),o&&n.done]))[0]};Y.set(e,n);return n}V((t=>({...t,get:(e,i,r)=>Q(e,i)||t.get(e,i,r),has:(e,i)=>!!Q(e,i)||t.has(e,i)})));const tt=["continue","continuePrimaryKey","advance"];const et={};const it=new WeakMap;const rt=new WeakMap;const ot={get(t,e){if(!tt.includes(e))return t[e];let i=et[e];if(!i){i=et[e]=function(...t){it.set(this,rt.get(this)[e](...t))}}return i}};async function*nt(...t){let e=this;if(!(e instanceof IDBCursor)){e=await e.openCursor(...t)}if(!e)return;e=e;const i=new Proxy(e,ot);rt.set(i,e);J.set(i,H(e));while(e){yield i;e=await(it.get(i)||e.continue());it.delete(i)}}function st(t,e){return e===Symbol.asyncIterator&&M(t,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&M(t,[IDBIndex,IDBObjectStore])}V((t=>({...t,get(e,i,r){if(st(e,i))return nt;return t.get(e,i,r)},has(e,i){return st(e,i)||t.has(e,i)}})));const at="pid-component";const lt=undefined;class ct{constructor(){this.dbPromise=W(at,lt,{upgrade(t){const e=t.createObjectStore("entities",{keyPath:"value"});e.createIndex("by-context","context",{unique:false});const i=t.createObjectStore("relations",{autoIncrement:true});i.createIndex("by-start","start",{unique:false});i.createIndex("by-description","description",{unique:false});i.createIndex("by-end","end",{unique:false})}})}async addEntity(t){const e=document.documentURI;const i=await this.dbPromise;const r=this.normalizeKey(t.value);await i.add("entities",{value:r,rendererKey:t.getSettingsKey(),context:e,lastAccess:new Date,lastData:t.data}).catch((t=>{if(t.name==="ConstraintError"){console.debug("Entity already exists",t)}else console.error("Could not add entity",t)}));console.debug("added entity",t);const o=i.transaction("relations","readwrite");const n=[];for(const e of t.items){const i={start:t.value,description:e.keyTitle,end:e.value};const r=o.store.index("by-start");let s=await r.openCursor();while(s){if(s.value.start===i.start&&s.value.end===i.end&&s.value.description===i.description){return}s=await s.continue()}n.push(o.store.add(i))}n.push(o.done);await Promise.all(n);console.debug("added relations",n)}async getEntity(t,e){var i,r;const o=this.normalizeKey(t);try{const r=await this.dbPromise;const n=await r.get("entities",o);if(n!==undefined){console.debug("Found entity for value in db",n,t);const r=(i=e.find((t=>t.type===n.rendererKey)))===null||i===void 0?void 0:i.values;const o=r===null||r===void 0?void 0:r.find((t=>t.name==="ttl"));if(o!=undefined&&o.value!=undefined&&((new Date).getTime()-n.lastAccess.getTime()>o.value||o.value===0)){console.log("TTL expired! Deleting entry in db",o.value,(new Date).getTime()-n.lastAccess.getTime());await this.deleteEntity(t)}else{console.log("TTL not expired or undefined",(new Date).getTime()-n.lastAccess.getTime());const e=new(z.find((t=>t.key===n.rendererKey)).constructor)(t,r);e.settings=r;await e.init(n.lastData);return e}}}catch(t){console.error("Could not get entity from db",t)}console.debug("No valid entity found for value in db",t);const n=await P.getBestFit(t,e);n.settings=(r=e.find((t=>t.type===n.getSettingsKey())))===null||r===void 0?void 0:r.values;await n.init();await this.addEntity(n);console.debug("added entity to db",t,n);return n}async deleteEntity(t){const e=await this.dbPromise;const i=this.normalizeKey(t);await e.delete("entities",i);const r=e.transaction("relations","readwrite");const o=r.store.index("by-start");let n=await o.openCursor();while(n){if(n.value.start===t||n.value.end===t){await r.store.delete(n.primaryKey)}n=await n.continue()}console.log("deleted entity",t);await r.done}normalizeKey(t){let e=t;if(typeof e!=="string"&&typeof e!=="number"){try{e=JSON.stringify(e)}catch(t){e=String(e)}console.warn("Converted entity value to string for IndexedDB key (delete):",e)}return e}async clearEntities(){const t=await this.dbPromise;await t.clear("entities");await t.clear("relations");console.log("cleared entities")}}const ht='/*! tailwindcss v4.1.8 | MIT License | https://tailwindcss.com */@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,::backdrop,:after,:before{--tw-space-y-reverse:0;--tw-leading:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-duration:initial;--tw-ease:initial;--tw-space-x-reverse:0;--tw-outline-style:solid}}}@layer theme{:host,:root{--color-green-200:oklch(92.5% .084 155.995);--color-green-700:oklch(52.7% .154 150.069);--color-slate-500:oklch(55.4% .046 257.417);--color-slate-800:oklch(27.9% .041 260.031);--color-slate-900:oklch(20.8% .042 265.755);--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-700:oklch(50.5% .213 27.518);--color-blue-300:oklch(80.9% .105 251.813);--color-blue-700:oklch(48.8% .243 264.376);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--container-md:28rem;--color-yellow-50:oklch(98.7% .026 102.212);--color-green-50:oklch(98.2% .018 155.826);--color-blue-50:oklch(97% .014 254.604);--color-blue-200:oklch(88.2% .059 254.128);--color-blue-400:oklch(70.7% .165 254.624);--color-purple-50:oklch(97.7% .014 308.299);--color-slate-400:oklch(70.4% .04 256.788);--text-lg:1.125rem;--text-lg--line-height:1.55556;--leading-normal:1.5;--blur-sm:8px;--color-blue-800:oklch(42.4% .199 265.638);--color-blue-900:oklch(37.9% .146 265.522);--color-slate-200:oklch(92.9% .013 255.508);--color-slate-600:oklch(44.6% .043 257.281);--container-3xl:48rem;--radius-sm:.25rem;--radius-lg:.5rem;--color-blue-600:oklch(54.6% .245 262.881);--color-gray-50:oklch(98.5% .002 247.839);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-900:oklch(21% .034 264.665);--font-weight-semibold:600;--color-blue-500:oklch(62.3% .214 259.815);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-700:oklch(37.3% .034 259.733);--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-600:oklch(57.7% .245 27.325);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-600:oklch(44.6% .03 256.802);--color-gray-800:oklch(27.8% .033 256.848);--color-black:#000;--color-white:#fff;--spacing:.25rem;--text-xs:.75rem;--text-xs--line-height:1.33333;--text-sm:.875rem;--text-sm--line-height:1.42857;--font-weight-medium:500;--font-weight-bold:700;--radius-md:.375rem;--ease-in-out:cubic-bezier(.4,0,.2,1);--animate-spin:spin 1s linear infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,::backdrop,:after,:before{border:0 solid;box-sizing:border-box;margin:0;padding:0}::file-selector-button{appearance:button;background-color:#0000;border:0 solid;border-radius:0;box-sizing:border-box;color:inherit;font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;margin:0;margin-inline-end:4px;opacity:1;padding:0}:host,html{-webkit-text-size-adjust:100%;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);tab-size:4;-webkit-tap-highlight-color:transparent;line-height:1.5}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-size:1em;font-variation-settings:var(--default-mono-font-variation-settings,normal)}small{font-size:80%}sub,sup{font-siz