UNPKG

@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.

19 lines 3.28 kB
/*! * * Copyright 2024-2026 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{p as e,H as t,h as o,c as i,t as s}from"./p-Bw7bVt6t.js";const n=e(class e extends t{constructor(e){super();if(e!==false){this.__registerHost()}this.copied=false;this.darkMode="light";this.copyValue=e=>{e.stopPropagation();e.preventDefault();const t=document.createElement("textarea");t.value=this.value;t.setAttribute("aria-hidden","true");t.setAttribute("readonly","readonly");t.style.cssText="position:fixed;top:0;left:0;width:2em;height:2em;padding:0;border:none;outline:none;box-shadow:none;opacity:0;";document.body.appendChild(t);t.focus();t.select();t.setSelectionRange(0,t.value.length);let o=false;try{o=document.execCommand("copy")}catch(e){}document.body.removeChild(t);if(o){this.showSuccess();return}if("clipboard"in navigator){navigator.clipboard.writeText(this.value).then((()=>this.showSuccess()),(()=>{}))}}}getIsDarkMode(){if(this.darkMode==="dark"){return true}if(this.darkMode==="light"){return false}const e=this.el.closest("pid-component");if(e===null||e===void 0?void 0:e.classList.contains("bg-gray-800")){return true}if(this.darkMode==="system"){return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches}return false}render(){const e=this.copied?"✓ Copied!":"Copy";const t=this.getAriaLabel();const s=this.getIsDarkMode();return o(i,{key:"c5c3499428ec7ab4b306458dc25af78c26e1b91d",class:"inline-block align-baseline text-xs"},this.copied&&o("span",{key:"eab38ff718680f01488fb1a3fe0cf36547a09daa",class:"sr-only","aria-live":"assertive"},"Content copied to clipboard"),o("button",{key:"ac8d35bc7e2cb5038846adc8134b20ca31ac09e0",class:`${this.copied?s?"bg-green-700":"bg-green-200":s?"bg-gray-700 hover:bg-gray-600":"bg-white hover:bg-blue-200"} relative z-30 max-h-min flex-none items-center rounded-md border ${s?"border-gray-600 text-gray-200 hover:text-white":"border-slate-500 text-slate-800 hover:text-slate-900"} px-2 py-0.5 font-mono font-medium transition-colors duration-200 focus:ring-2 focus:ring-blue-500 focus:ring-offset-1 focus:outline-hidden`,onClick:e=>this.copyValue(e),"aria-label":t,title:t,type:"button"},e))}showSuccess(){this.copied=true;setTimeout((()=>{this.copied=false}),1500)}getAriaLabel(){const e=this.label||"content";return this.copied?`${e} copied to clipboard`:`Copy ${e} to clipboard`}get el(){return this}},[0,"copy-button",{value:[1],label:[1],darkMode:[1,"dark-mode"],copied:[32]}]);function r(){if(typeof customElements==="undefined"){return}const e=["copy-button"];e.forEach((e=>{switch(e){case"copy-button":if(!customElements.get(s(e))){customElements.define(s(e),n)}break}}))}export{n as C,r as d}; //# sourceMappingURL=p-ClvEqYNC.js.map