var _ = (s) => {
throw TypeError(s);
};
var T = (s, e, t) => e.has(s) || _("Cannot " + t);
var f = (s, e, t) => (T(s, e, "read from private field"), t ? t.call(s) : e.get(s)), c = (s, e, t) => e.has(s) ? _("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t), d = (s, e, t, i) => (T(s, e, "write to private field"), i ? i.call(s, t) : e.set(s, t), t), g = (s, e, t) => (T(s, e, "access private method"), t);
const k = "script[xslt-onload]", v = "xslt-template", w = "xslt-transformed", A = "filter-list", m = "filter-list-list", M = "filter-list-item", y = "filter-list-input", x = "filter-list-searchable", B = "scroll-button", I = "tool-tip", P = "abbrev-tooltips", C = "int-link";
var h, b, E;
class z {
constructor() {
c(this, b);
c(this, h);
d(this, h, /* @__PURE__ */ new Map());
}
setup() {
let e = htmx.findAll(k);
for (let t of e)
g(this, b, E).call(this, t);
}
hookupHTMX() {
htmx.on("htmx:load", (e) => {
this.setup();
});
}
}
h = new WeakMap(), b = new WeakSet(), E = function(e) {
if (e.getAttribute(w) === "true" || !e.hasAttribute(v))
return;
let t = "#" + e.getAttribute(v), i = f(this, h).get(t);
if (!i) {
let l = htmx.find(t);
if (l) {
let S = l.innerHTML ? new DOMParser().parseFromString(l.innerHTML, "application/xml") : l.contentDocument;
i = new XSLTProcessor(), i.importStylesheet(S), f(this, h).set(t, i);
} else
throw new Error("Unknown XSLT template: " + t);
}
let r = new DOMParser().parseFromString(e.innerHTML, "application/xml"), n = i.transformToFragment(r, document), o = new XMLSerializer().serializeToString(n);
e.outerHTML = o;
};
var a, p, L;
class H extends HTMLElement {
constructor() {
super();
c(this, p);
c(this, a, !1);
this._items = [], this._url = "", this._filterstart = !1, this._placeholder = "Liste filtern...", this.render();
}
static get observedAttributes() {
return ["data-url"];
}
set items(t) {
Array.isArray(t) && (this._items = t, this.render());
}
get items() {
return this._items;
}
connectedCallback() {
this._url = this.getAttribute("data-url") || "./", this._filterstart = this.getAttribute("data-filterstart") === "true", this._placeholder = this.getAttribute("data-placeholder") || "Liste filtern...", this._filterstart && d(this, a, !0), this.addEventListener("input", this.onInput.bind(this)), this.addEventListener("keydown", this.onEnter.bind(this)), this.addEventListener("focusin", this.onGainFocus.bind(this)), this.addEventListener("focusout", this.onLoseFocus.bind(this));
}
attributeChangedCallback(t, i, r) {
t === "data-url" && i !== r && (this._url = r, this.render()), t === "data-filterstart" && i !== r && (this._filterstart = r === "true", this.render()), t === "data-placeholder" && i !== r && (this._placeholder = r, this.render());
}
onInput(t) {
t.target && t.target.tagName.toLowerCase() === "input" && (this._filter = t.target.value, this.renderList());
}
onGainFocus(t) {
t.target && t.target.tagName.toLowerCase() === "input" && (d(this, a, !1), this.renderList());
}
onLoseFocus(t) {
let i = this.querySelector("input");
if (t.target && t.target === i) {
if (relatedElement = t.relatedTarget, relatedElement && this.contains(relatedElement))
return;
i.value = "", this._filter = "", this._filterstart && d(this, a, !0), this.renderList();
}
}
onEnter(t) {
if (t.target && t.target.tagName.toLowerCase() === "input" && t.key === "Enter") {
t.preventDefault();
const i = this.querySelector("a");
i && i.click();
}
}
mark() {
if (typeof Mark != "function")
return;
let t = this.querySelector("#" + m);
if (!t)
return;
let i = new Mark(t.querySelectorAll("." + x));
this._filter && i.mark(this._filter, {
separateWordSearch: !0
});
}
// INFO: allows for setting a custom HREF of the list item
// The function takes the item as parameter fn(item) and should return a string.
setHREFFunc(t) {
this.getHREF = t, this.render();
}
// INFO: allows for setting a custom link text of the list item
// The function takes the item as parameter fn(item) and should return a string or
// an HTML template literal.
setLinkTextFunc(t) {
this.getLinkText = t, this.render();
}
// INFO: allows for setting the text that will be filtered for.
// The function takes the item as parameter fn(item) and should return a string.
setSearchTextFunc(t) {
this.getSearchText = t, this.render();
}
getHREF(t) {
if (t) {
if (!t.id)
return "";
} else return "";
return t.id;
}
getSearchText(t) {
if (t) {
if (!t.name)
return "";
} else return "";
return t.name;
}
getLinkText(t) {
let i = this.getSearchText(t);
return i === "" ? "" : `${i}`;
}
renderList() {
let t = this.querySelector("#" + m);
t && (t.outerHTML = this.List()), this.mark();
}
render() {
this.innerHTML = `
`;
}
List() {
let t = this._items;
if (this._filter)
if (this._filterstart)
t = this._items.filter((i) => this.getSearchText(i).toLowerCase().startsWith(this._filter.toLowerCase()));
else {
let i = this._filter.split(" ");
t = this._items.filter((r) => i.every((n) => this.getSearchText(r).toLowerCase().includes(n.toLowerCase())));
}
return `
${o}
`, r += o.length;
} else
i += e[r], r++;
}
return i;
}
findLongestAbbrevAt(e, t, i) {
let r = null, n = 0;
for (const o of Object.keys(i))
e.startsWith(o, t) && o.length > n && (r = o, n = o.length);
return r ? { match: r, meaning: i[r] } : null;
}
isSpaceOrPunct(e) {
return /\s|[.,;:!?]/.test(e);
}
}
class N extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.style.cursor = "pointer", this.addEventListener("click", this.handleClick);
}
disconnectedCallback() {
this.removeEventListener("click", this.handleClick);
}
handleClick(e) {
const t = this.getAttribute("data-jump");
if (t) {
const i = document.querySelector(t);
i ? i.scrollIntoView({ behavior: "smooth" }) : console.warn(`No element found for selector: ${t}`);
}
}
}
customElements.define(C, N);
customElements.define(P, u);
customElements.define(A, H);
customElements.define(B, $);
customElements.define(I, F);
export {
u as AbbreviationTooltips,
H as FilterList,
$ as ScrollButton,
z as XSLTParseProcess
};