ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
78 lines (77 loc) • 2.45 kB
JavaScript
import { t as i } from "./events-Cqz3ramM.js";
import "./builder-EH76YCFS.js";
import { i as s, n, o as a, t as o } from "./utils-U-9uH7EX.js";
import { a as h, n as l } from "./ssr-BzykYefm.js";
import { useRouter as c } from "./utils/router.js";
var f = ":host{display:inline}a{color:var(--ran-color-link, #006bff);text-decoration:none;cursor:pointer;font-family:inherit;font-size:inherit;border-radius:var(--ran-radius-sm, 6px)}a:hover{text-decoration:underline;opacity:.85}a:focus-visible{outline:var(--ran-link-focus-outline, 2px solid var(--ran-color-primary, #006bff));outline-offset:var(--ran-link-focus-outline-offset, 2px)}:host([active]) a{font-weight:var(--ran-link-active-font-weight, 600);text-decoration:underline}", u = class extends l {
static get observedAttributes() {
return [
"href",
"replace",
"sheet"
];
}
_events = new i();
_shadowDom;
_anchor;
constructor() {
super(), this._shadowDom = o(this, f);
const t = document.createElement("a");
t.appendChild(document.createElement("slot"));
const e = t;
this._shadowDom.appendChild(e), this._anchor = e;
}
get href() {
return n(this, "href");
}
set href(t) {
s(this, "href", t);
}
get replace() {
return this.hasAttribute("replace");
}
get sheet() {
return n(this, "sheet");
}
set sheet(t) {
s(this, "sheet", t);
}
handlerExternalCss = () => {
a(this, this._shadowDom, "sheet", null, this.sheet);
};
_handleClick = (t) => {
if (t.defaultPrevented || t.button !== 0 || t.metaKey || t.ctrlKey || t.shiftKey || t.altKey) return;
const e = this.href;
if (!e || /^(https?:\/\/|\/\/|mailto:|tel:)/.test(e)) return;
t.preventDefault();
const r = c();
if (r) {
this.replace ? r.replace(e) : r.push(e);
return;
}
this.dispatchEvent(new CustomEvent("ran-navigate", {
detail: {
path: e,
replace: this.replace
},
bubbles: !0,
composed: !0
}));
};
_syncHref() {
this._anchor && (this._anchor.href = this.href);
}
connectedCallback() {
this.handlerExternalCss(), this._syncHref(), this._events.on(this._anchor, "click", this._handleClick);
}
disconnectedCallback() {
this._events.abort();
}
attributeChangedCallback(t, e, r) {
e !== r && (t === "href" && this._syncHref(), t === "sheet" && this.handlerExternalCss());
}
};
h("r-link", u);
export {
u as t
};