searchmate-js
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -1,14 +0,17 @@ | ||
const R = "https://search-worker.searchmateapp.workers.dev/v1", q = "heading", x = ".searchmate-result-part", g = "searchmate-result-selected", B = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" class="searchmate-search-icon"> | ||
var N = Object.defineProperty; | ||
var z = (t, e, n) => e in t ? N(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; | ||
var C = (t, e, n) => (z(t, typeof e != "symbol" ? e + "" : e, n), n); | ||
const X = "https://search-worker.searchmateapp.workers.dev/v1", O = "heading", k = ".searchmate-result-part", w = "searchmate-result-selected", G = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" class="searchmate-search-icon"> | ||
<path strokeLinecap="round" class strokeLinejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" /> | ||
</svg> | ||
`, D = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-path-icon"> | ||
`, Q = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-path-icon"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244" /> | ||
</svg> | ||
`, F = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="searchmate-hash-icon"> | ||
`, V = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="searchmate-hash-icon"> | ||
<path fill-rule="evenodd" d="M9.493 2.853a.75.75 0 00-1.486-.205L7.545 6H4.198a.75.75 0 000 1.5h3.14l-.69 5H3.302a.75.75 0 000 1.5h3.14l-.435 3.148a.75.75 0 001.486.205L7.955 14h2.986l-.434 3.148a.75.75 0 001.486.205L12.456 14h3.346a.75.75 0 000-1.5h-3.14l.69-5h3.346a.75.75 0 000-1.5h-3.14l.435-3.147a.75.75 0 00-1.486-.205L12.045 6H9.059l.434-3.147zM8.852 7.5l-.69 5h2.986l.69-5H8.852z" clip-rule="evenodd" /> | ||
</svg> | ||
`, U = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-x-notfound-circle"> | ||
`, Z = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-x-notfound-circle"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /> | ||
</svg> | ||
`, P = `<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg" class="searchmate-logo"> | ||
`, J = `<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg" class="searchmate-logo"> | ||
<g clip-path="url(#clip0_102_15)"> | ||
@@ -25,59 +28,59 @@ <rect width="40" height="40" rx="4" fill="#EF4444"/> | ||
`; | ||
function k(n, t, r) { | ||
const e = document.createElement(n); | ||
return r.forEach((o) => e.classList.add(o)), t.appendChild(e), e; | ||
function x(t, e, n) { | ||
const s = document.createElement(t); | ||
return n.forEach((i) => s.classList.add(i)), e.appendChild(s), s; | ||
} | ||
function d(n, t) { | ||
const r = document.createElement(n); | ||
return t && t.forEach((e) => r.classList.add(e)), r; | ||
function u(t, e) { | ||
const n = document.createElement(t); | ||
return e && e.forEach((s) => n.classList.add(s)), n; | ||
} | ||
function K(n, t) { | ||
const r = d("a", [ | ||
function ee(t, e) { | ||
const n = u("a", [ | ||
"searchmate-result-part", | ||
"searchmate-result-path" | ||
]), e = d("p", ["searchmate-result-path-header"]); | ||
e.innerHTML += D; | ||
const o = d("span"); | ||
o.textContent = `/${n}`, e.appendChild(o), r.appendChild(e); | ||
const i = t ? `${t}/${n}` : `/${n}`; | ||
return r.setAttribute("href", i), r; | ||
]), s = u("p", ["searchmate-result-path-header"]); | ||
s.innerHTML += Q; | ||
const i = u("span"); | ||
i.textContent = `/${t}`, s.appendChild(i), n.appendChild(s); | ||
const l = e ? `${e}/${t}` : `/${t}`; | ||
return n.setAttribute("href", l), n; | ||
} | ||
function Y(n, t, r, e) { | ||
const o = d("a", [ | ||
function te(t, e, n, s) { | ||
const i = u("a", [ | ||
"searchmate-result-part", | ||
"searchmate-result-heading" | ||
]); | ||
o.innerHTML += F, o.innerHTML += n; | ||
const i = e ? `${e}/${t}` : `/${t}`; | ||
return o.setAttribute("href", `${i}#${r}`), o; | ||
i.innerHTML += V, i.innerHTML += t; | ||
const l = s ? `${s}/${e}` : `/${e}`; | ||
return i.setAttribute("href", `${l}#${n}`), i; | ||
} | ||
function j(n) { | ||
const t = d("div", [ | ||
function ne(t) { | ||
const e = u("div", [ | ||
"searchmate-result-other", | ||
"markdown-body" | ||
]); | ||
return t.innerHTML += n, t; | ||
return e.innerHTML += t, e; | ||
} | ||
function W(n, t) { | ||
const r = d("div", ["searchmate-result"]), e = K(n.path, t); | ||
return r.appendChild(e), n.content.forEach((i) => { | ||
if (i.type === q) { | ||
const c = Y( | ||
i.content, | ||
n.path, | ||
i.headingId, | ||
t | ||
function se(t, e) { | ||
const n = u("div", ["searchmate-result"]), s = ee(t.path, e); | ||
return n.appendChild(s), t.content.forEach((l) => { | ||
if (l.type === O) { | ||
const o = te( | ||
l.content, | ||
t.path, | ||
l.headingId, | ||
e | ||
); | ||
r.appendChild(c); | ||
n.appendChild(o); | ||
} else { | ||
if (i.type === "yaml") | ||
if (l.type === "yaml") | ||
return; | ||
const c = j(i.content); | ||
e.appendChild(c); | ||
const o = ne(l.content); | ||
s.appendChild(o); | ||
} | ||
}), r; | ||
}), n; | ||
} | ||
function S(n, t) { | ||
const e = t.querySelectorAll(x)[n]; | ||
return e ? (e.classList.add(g), e.scrollIntoView({ | ||
function I(t, e) { | ||
const s = e.querySelectorAll(k)[t]; | ||
return s ? (s.classList.add(w), s.scrollIntoView({ | ||
behavior: "smooth", | ||
@@ -87,197 +90,372 @@ block: "center" | ||
} | ||
function A(n, t) { | ||
const e = t.querySelectorAll(x)[n]; | ||
e && e.classList.remove(g); | ||
function D(t, e) { | ||
const s = e.querySelectorAll(k)[t]; | ||
s && s.classList.remove(w); | ||
} | ||
function z(n, t) { | ||
const r = n.clientX, e = n.clientY, o = t.querySelectorAll(x); | ||
let i = -1; | ||
for (let c = 0; c < o.length; c++) { | ||
const h = o[c], { top: u, bottom: f, left: s, right: w } = h.getBoundingClientRect(); | ||
e >= u && e <= f && r >= s && r <= w ? (i = c, h.classList.add(g)) : o[c].classList.remove(g); | ||
function ie(t, e) { | ||
const n = t.clientX, s = t.clientY, i = e.querySelectorAll(k); | ||
let l = -1; | ||
for (let o = 0; o < i.length; o++) { | ||
const h = i[o], { top: f, bottom: g, left: m, right: a } = h.getBoundingClientRect(); | ||
s >= f && s <= g && n >= m && n <= a ? (l = o, h.classList.add(w)) : i[o].classList.remove(w); | ||
} | ||
return i; | ||
return l; | ||
} | ||
function X(n, t) { | ||
const r = n.touches[0].clientX, e = n.touches[0].clientY, o = t.querySelectorAll(x); | ||
let i = -1; | ||
for (let c = 0; c < o.length; c++) { | ||
const h = o[c], { top: u, bottom: f, left: s, right: w } = h.getBoundingClientRect(); | ||
e >= u && e <= f && r >= s && r <= w ? (i = c, h.classList.add(g)) : o[c].classList.remove(g); | ||
function re(t, e) { | ||
const n = t.touches[0].clientX, s = t.touches[0].clientY, i = e.querySelectorAll(k); | ||
let l = -1; | ||
for (let o = 0; o < i.length; o++) { | ||
const h = i[o], { top: f, bottom: g, left: m, right: a } = h.getBoundingClientRect(); | ||
s >= f && s <= g && n >= m && n <= a ? (l = o, h.classList.add(w)) : i[o].classList.remove(w); | ||
} | ||
return i; | ||
return l; | ||
} | ||
function G(n) { | ||
const t = d("div", ["searchmate-not-found"]); | ||
t.innerHTML += U; | ||
const r = d("p", ["searchmate-not-found-text"]); | ||
r.textContent = "No results found for "; | ||
const e = d("span", ["searchmate-not-found-query"]); | ||
return e.textContent = `"${n}"`, r.appendChild(e), t.appendChild(r), t; | ||
function oe(t) { | ||
const e = u("div", ["searchmate-not-found"]); | ||
e.innerHTML += Z; | ||
const n = u("p", ["searchmate-not-found-text"]); | ||
n.textContent = "No results found for "; | ||
const s = u("span", ["searchmate-not-found-query"]); | ||
return s.textContent = `"${t}"`, n.appendChild(s), e.appendChild(n), e; | ||
} | ||
function O() { | ||
const n = d("div", ["searchmate-initial-content"]), t = d("p", [ | ||
function ae() { | ||
const t = u("div", ["searchmate-initial-content"]), e = u("p", [ | ||
"searchmate-initial-content-text" | ||
]); | ||
return t.textContent = "What are you looking for?", n.appendChild(t), n; | ||
return e.textContent = "What are you looking for?", t.appendChild(e), t; | ||
} | ||
function Q() { | ||
const n = d("div", ["searchmate-footer"]), t = d("p", ["searchmate-footer-text"]); | ||
t.textContent = "Powered by "; | ||
const r = d("a", ["searchmate-footer-link"]); | ||
return r.textContent = "Search Mate", r.setAttribute("href", "https://searchmate.app"), t.appendChild(r), n.appendChild(t), n.innerHTML += P, n; | ||
function ce() { | ||
const t = u("div", ["searchmate-footer"]), e = u("p", ["searchmate-footer-text"]); | ||
e.textContent = "Powered by "; | ||
const n = u("a", ["searchmate-footer-link"]); | ||
return n.textContent = "Search Mate", n.setAttribute("href", "https://searchmate.app"), e.appendChild(n), t.appendChild(e), t.innerHTML += J, t; | ||
} | ||
var V = Z; | ||
function Z(n, t, r) { | ||
var e = null, o = null, i = function() { | ||
e && (clearTimeout(e), o = null, e = null); | ||
}, c = function() { | ||
var u = o; | ||
i(), u && u(); | ||
const r = { | ||
inert: ":not([inert]):not([inert] *)", | ||
negTabIndex: ':not([tabindex^="-"])', | ||
disabled: ":not(:disabled)" | ||
}; | ||
var le = [ | ||
`a[href]${r.inert}${r.negTabIndex}`, | ||
`area[href]${r.inert}${r.negTabIndex}`, | ||
`input:not([type="hidden"]):not([type="radio"])${r.inert}${r.negTabIndex}${r.disabled}`, | ||
`input[type="radio"]${r.inert}${r.negTabIndex}${r.disabled}`, | ||
`select${r.inert}${r.negTabIndex}${r.disabled}`, | ||
`textarea${r.inert}${r.negTabIndex}${r.disabled}`, | ||
`button${r.inert}${r.negTabIndex}${r.disabled}`, | ||
`details${r.inert} > summary:first-of-type${r.negTabIndex}`, | ||
// Discard until Firefox supports `:has()` | ||
// See: https://github.com/KittyGiraudel/focusable-selectors/issues/12 | ||
// `details:not(:has(> summary))${not.inert}${not.negTabIndex}`, | ||
`iframe${r.inert}${r.negTabIndex}`, | ||
`audio[controls]${r.inert}${r.negTabIndex}`, | ||
`video[controls]${r.inert}${r.negTabIndex}`, | ||
`[contenteditable]${r.inert}${r.negTabIndex}`, | ||
`[tabindex]${r.inert}${r.negTabIndex}` | ||
]; | ||
function R(t) { | ||
(t.querySelector("[autofocus]") || t).focus(); | ||
} | ||
function de(t) { | ||
const e = L(t, !0), n = e ? L(t, !1) || e : null; | ||
return [e, n]; | ||
} | ||
function L(t, e) { | ||
if (e && q(t)) | ||
return t; | ||
if (he(t)) | ||
if (t.shadowRoot) { | ||
let n = K(t.shadowRoot, e); | ||
for (; n; ) { | ||
const s = L(n, e); | ||
if (s) | ||
return s; | ||
n = _(n, e); | ||
} | ||
} else if (t.localName === "slot") { | ||
const n = t.assignedElements({ | ||
flatten: !0 | ||
}); | ||
e || n.reverse(); | ||
for (const s of n) { | ||
const i = L(s, e); | ||
if (i) | ||
return i; | ||
} | ||
} else { | ||
let n = K(t, e); | ||
for (; n; ) { | ||
const s = L(n, e); | ||
if (s) | ||
return s; | ||
n = _(n, e); | ||
} | ||
} | ||
return !e && q(t) ? t : null; | ||
} | ||
function K(t, e) { | ||
return e ? t.firstElementChild : t.lastElementChild; | ||
} | ||
function _(t, e) { | ||
return e ? t.nextElementSibling : t.previousElementSibling; | ||
} | ||
const ue = (t) => t.matches("details:not([open]) *") && !t.matches("details>summary:first-of-type") ? !0 : !(t.offsetWidth || t.offsetHeight || t.getClientRects().length), q = (t) => { | ||
var e; | ||
return (e = t.shadowRoot) != null && e.delegatesFocus ? !1 : t.matches(le.join(",")) && !ue(t); | ||
}; | ||
function he(t) { | ||
return t.shadowRoot && t.getAttribute("tabindex") === "-1" ? !1 : !t.matches(":disabled,[hidden],[inert]"); | ||
} | ||
function A(t = document) { | ||
const e = t.activeElement; | ||
return e ? e.shadowRoot ? A(e.shadowRoot) || document.activeElement : e : null; | ||
} | ||
function fe(t, e) { | ||
const [n, s] = de(t); | ||
if (!n) | ||
return e.preventDefault(); | ||
const i = A(); | ||
e.shiftKey && i === n ? (s.focus(), e.preventDefault()) : !e.shiftKey && i === s && (n.focus(), e.preventDefault()); | ||
} | ||
class U { | ||
constructor(e) { | ||
C(this, "$el"); | ||
C(this, "id"); | ||
C(this, "previouslyFocused"); | ||
C(this, "shown"); | ||
this.$el = e, this.id = this.$el.getAttribute("data-a11y-dialog") || this.$el.id, this.previouslyFocused = null, this.shown = !1, this.maintainFocus = this.maintainFocus.bind(this), this.bindKeypress = this.bindKeypress.bind(this), this.handleTriggerClicks = this.handleTriggerClicks.bind(this), this.show = this.show.bind(this), this.hide = this.hide.bind(this), this.$el.setAttribute("aria-hidden", "true"), this.$el.setAttribute("aria-modal", "true"), this.$el.setAttribute("tabindex", "-1"), this.$el.hasAttribute("role") || this.$el.setAttribute("role", "dialog"), document.addEventListener("click", this.handleTriggerClicks, !0); | ||
} | ||
/** | ||
* Destroy the current instance (after making sure the dialog has been hidden) | ||
* and remove all associated listeners from dialog openers and closers | ||
*/ | ||
destroy() { | ||
return this.hide(), document.removeEventListener("click", this.handleTriggerClicks, !0), this.$el.replaceWith(this.$el.cloneNode(!0)), this.fire("destroy"), this; | ||
} | ||
/** | ||
* Show the dialog element, trap the current focus within it, listen for some | ||
* specific key presses and fire all registered callbacks for `show` event | ||
*/ | ||
show(e) { | ||
var n; | ||
return this.shown ? this : (this.shown = !0, this.$el.removeAttribute("aria-hidden"), this.previouslyFocused = A(), ((n = this.previouslyFocused) == null ? void 0 : n.tagName) === "BODY" && (e != null && e.target) && (this.previouslyFocused = e.target), R(this.$el), document.body.addEventListener("focus", this.maintainFocus, !0), this.$el.addEventListener("keydown", this.bindKeypress, !0), this.fire("show", e), this); | ||
} | ||
/** | ||
* Hide the dialog element, restore the focus to the previously active | ||
* element, stop listening for some specific key presses and fire all | ||
* registered callbacks for `hide` event | ||
*/ | ||
hide(e) { | ||
var n, s; | ||
return this.shown ? (this.shown = !1, this.$el.setAttribute("aria-hidden", "true"), (s = (n = this.previouslyFocused) == null ? void 0 : n.focus) == null || s.call(n), document.body.removeEventListener("focus", this.maintainFocus, !0), this.$el.removeEventListener("keydown", this.bindKeypress, !0), this.fire("hide", e), this) : this; | ||
} | ||
/** | ||
* Register a new callback for the given event type | ||
*/ | ||
on(e, n, s) { | ||
return this.$el.addEventListener(e, n, s), this; | ||
} | ||
/** | ||
* Unregister an existing callback for the given event type | ||
*/ | ||
off(e, n, s) { | ||
return this.$el.removeEventListener(e, n, s), this; | ||
} | ||
/** | ||
* Dispatch a custom event from the DOM element associated with this dialog. | ||
* This allows authors to listen for and respond to the events in their own | ||
* code | ||
*/ | ||
fire(e, n) { | ||
this.$el.dispatchEvent(new CustomEvent(e, { | ||
detail: n, | ||
cancelable: !0 | ||
})); | ||
} | ||
/** | ||
* Add a delegated event listener for when elememts that open or close the | ||
* dialog are clicked, and call `show` or `hide`, respectively | ||
*/ | ||
handleTriggerClicks(e) { | ||
const n = e.target; | ||
n.closest(`[data-a11y-dialog-show="${this.id}"]`) && this.show(e), (n.closest(`[data-a11y-dialog-hide="${this.id}"]`) || n.closest("[data-a11y-dialog-hide]") && n.closest('[aria-modal="true"]') === this.$el) && this.hide(e); | ||
} | ||
/** | ||
* Private event handler used when listening to some specific key presses | ||
* (namely ESC and TAB) | ||
*/ | ||
bindKeypress(e) { | ||
var n; | ||
((n = document.activeElement) == null ? void 0 : n.closest('[aria-modal="true"]')) === this.$el && (e.key === "Escape" && this.$el.getAttribute("role") !== "alertdialog" && (e.preventDefault(), this.hide(e)), e.key === "Tab" && fe(this.$el, e)); | ||
} | ||
/** | ||
* If the dialog is shown and the focus is not within a dialog element (either | ||
* this one or another one in case of nested dialogs) or attribute, move it | ||
* back to the dialog container | ||
* See: https://github.com/KittyGiraudel/a11y-dialog/issues/177 | ||
*/ | ||
maintainFocus(e) { | ||
e.target.closest('[aria-modal="true"], [data-a11y-dialog-ignore-focus-trap]') || R(this.$el); | ||
} | ||
} | ||
function B() { | ||
for (const t of document.querySelectorAll("[data-a11y-dialog]")) | ||
new U(t); | ||
} | ||
typeof document < "u" && (document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", B) : B()); | ||
var me = pe; | ||
function pe(t, e, n) { | ||
var s = null, i = null, l = function() { | ||
s && (clearTimeout(s), i = null, s = null); | ||
}, o = function() { | ||
var f = i; | ||
l(), f && f(); | ||
}, h = function() { | ||
if (!t) | ||
return n.apply(this, arguments); | ||
var u = this, f = arguments, s = r && !e; | ||
if (i(), o = function() { | ||
n.apply(u, f); | ||
}, e = setTimeout(function() { | ||
if (e = null, !s) { | ||
var w = o; | ||
return o = null, w(); | ||
if (!e) | ||
return t.apply(this, arguments); | ||
var f = this, g = arguments, m = n && !s; | ||
if (l(), i = function() { | ||
t.apply(f, g); | ||
}, s = setTimeout(function() { | ||
if (s = null, !m) { | ||
var a = i; | ||
return i = null, a(); | ||
} | ||
}, t), s) | ||
return o(); | ||
}, e), m) | ||
return i(); | ||
}; | ||
return h.cancel = i, h.flush = c, h; | ||
return h.cancel = l, h.flush = o, h; | ||
} | ||
function J({ | ||
appId: n, | ||
urlPrefix: t = void 0, | ||
onClose: r = void 0, | ||
overrideNavigateToResult: e = void 0 | ||
function ve({ | ||
appId: t, | ||
urlPrefix: e = void 0, | ||
onClose: n = void 0, | ||
overrideNavigateToResult: s = void 0 | ||
}) { | ||
const o = document.body; | ||
if (o.querySelector("#searchmate-docs-search")) | ||
const i = document.body; | ||
if (i.querySelector("#searchmate-docs-search")) | ||
return; | ||
const c = k("div", o, [ | ||
const o = x("div", i, [ | ||
"searchmate-container" | ||
]); | ||
c.id = "searchmate-docs-search"; | ||
const h = k("div", c, [ | ||
o.id = "searchmate-docs-search"; | ||
const h = new U(o); | ||
h.show(); | ||
const f = x("div", o, [ | ||
"searchmate-search-container" | ||
]), u = k("div", h, [ | ||
]), g = x("div", f, [ | ||
"searchmate-input-container" | ||
]); | ||
u.innerHTML += B; | ||
const f = k("input", u, [ | ||
g.innerHTML += G; | ||
const m = x("input", g, [ | ||
"searchmate-search-input" | ||
]); | ||
f.setAttribute("placeholder", "Type to search..."); | ||
const s = k("div", h, [ | ||
m.setAttribute("placeholder", "Type to search..."); | ||
const a = x("div", f, [ | ||
"searchmate-results-container" | ||
]), w = Q(); | ||
h.appendChild(w); | ||
const H = O(); | ||
s.appendChild(H); | ||
]), P = ce(); | ||
f.appendChild(P); | ||
const W = ae(); | ||
a.appendChild(W); | ||
let p = 0; | ||
function _({ query: a, appId: l }) { | ||
if (a.length <= 0) | ||
function Y({ query: c, appId: d }) { | ||
if (c.length <= 0) | ||
return; | ||
const y = new URL(R); | ||
y.searchParams.set("query", a), y.searchParams.set("appId", l), fetch(y).then(async (C) => { | ||
const L = await C.json(); | ||
if (!C.ok) | ||
throw new Error(L.error); | ||
return L; | ||
}).then((C) => { | ||
s.innerHTML = "", p = 0; | ||
const L = C.results; | ||
if (L.length <= 0) { | ||
const v = G(a); | ||
s.appendChild(v); | ||
const T = new URL(X); | ||
T.searchParams.set("query", c), T.searchParams.set("appId", d), fetch(T).then(async (E) => { | ||
const y = await E.json(); | ||
if (!E.ok) | ||
throw new Error(y.error); | ||
return y; | ||
}).then((E) => { | ||
a.innerHTML = "", p = 0; | ||
const y = E.results; | ||
if (y.length <= 0) { | ||
const b = oe(c); | ||
a.appendChild(b); | ||
return; | ||
} | ||
L.forEach((v) => { | ||
const E = W(v, t); | ||
s.appendChild(E); | ||
}), S(p, s), s.querySelectorAll("a").forEach((v) => { | ||
v.addEventListener("click", (E) => { | ||
if (E.preventDefault(), e) | ||
e(v.href, E.ctrlKey), m(); | ||
y.forEach((b) => { | ||
const $ = se(b, e); | ||
a.appendChild($); | ||
}), I(p, a), a.querySelectorAll("a").forEach((b) => { | ||
b.addEventListener("click", ($) => { | ||
if ($.preventDefault(), s) | ||
s(b.href, $.ctrlKey), v(); | ||
else { | ||
if (E.ctrlKey) { | ||
window.open(v.href, "_blank"), m(); | ||
if ($.ctrlKey) { | ||
window.open(b.href, "_blank"), v(); | ||
return; | ||
} | ||
location.href = v.href, m(); | ||
location.href = b.href, v(); | ||
} | ||
}); | ||
}); | ||
}).catch((C) => { | ||
}).catch((E) => { | ||
}); | ||
} | ||
const $ = V(_, 300); | ||
f.addEventListener("input", (a) => { | ||
const l = a.target; | ||
$({ appId: n, query: l.value }); | ||
const j = me(Y, 300); | ||
m.addEventListener("input", (c) => { | ||
const d = c.target; | ||
j({ appId: t, query: d.value }); | ||
}); | ||
function M(a) { | ||
if (a.key === "ArrowDown") { | ||
a.preventDefault(); | ||
const { end: l } = S( | ||
function S(c) { | ||
if (c.key === "ArrowDown") { | ||
c.preventDefault(); | ||
const { end: d } = I( | ||
p + 1, | ||
s | ||
a | ||
); | ||
l || (A(p, s), p += 1); | ||
d || (D(p, a), p += 1); | ||
} | ||
if (a.key === "ArrowUp") { | ||
if (a.preventDefault(), p <= 0) | ||
if (c.key === "ArrowUp") { | ||
if (c.preventDefault(), p <= 0) | ||
return; | ||
A(p, s), p -= 1, S(p, s); | ||
D(p, a), p -= 1, I(p, a); | ||
} | ||
if (a.key === "Enter") { | ||
a.preventDefault(); | ||
const l = s.querySelector( | ||
`.${g}` | ||
if (c.key === "Enter") { | ||
c.preventDefault(); | ||
const d = a.querySelector( | ||
`.${w}` | ||
); | ||
if (!l) | ||
if (!d) | ||
return; | ||
if (e) | ||
e(l.href, a.ctrlKey), m(); | ||
if (s) | ||
s(d.href, c.ctrlKey), v(); | ||
else { | ||
if (a.ctrlKey) { | ||
window.open(l.href, "_blank"), m(); | ||
if (c.ctrlKey) { | ||
window.open(d.href, "_blank"), v(); | ||
return; | ||
} | ||
l.click(), m(); | ||
d.click(), v(); | ||
} | ||
} | ||
} | ||
f.addEventListener("focus", () => { | ||
document.addEventListener("keydown", M); | ||
}), f.addEventListener("blur", () => { | ||
document.removeEventListener("keydown", M); | ||
m.addEventListener("focus", () => { | ||
document.addEventListener("keydown", S); | ||
}), m.addEventListener("blur", () => { | ||
document.removeEventListener("keydown", S); | ||
}); | ||
function b(a) { | ||
const l = z(a, s); | ||
l >= 0 && (p = l); | ||
function F(c) { | ||
const d = ie(c, a); | ||
d >= 0 && (p = d); | ||
} | ||
s.addEventListener("mousemove", b); | ||
function I(a) { | ||
const l = X(a, s); | ||
l >= 0 && (p = l); | ||
a.addEventListener("mousemove", F); | ||
function M(c) { | ||
const d = re(c, a); | ||
d >= 0 && (p = d); | ||
} | ||
"ontouchstart" in window && s.addEventListener("touchstart", I); | ||
function m() { | ||
s.removeEventListener("mousemove", b), "ontouchstart" in window && s.removeEventListener("touchstart", I), c.remove(), r && r(); | ||
"ontouchstart" in window && a.addEventListener("touchstart", M); | ||
function v() { | ||
a.removeEventListener("mousemove", F), "ontouchstart" in window && a.removeEventListener("touchstart", M), o.remove(), h.destroy(), n && n(); | ||
} | ||
const T = (a) => { | ||
a.key === "Escape" && (m(), document.removeEventListener("keydown", T)); | ||
const H = (c) => { | ||
c.key === "Escape" && (v(), document.removeEventListener("keydown", H)); | ||
}; | ||
document.addEventListener("keydown", T), c.addEventListener("click", (a) => { | ||
a.target === c && m(); | ||
}), f.focus(); | ||
document.addEventListener("keydown", H), o.addEventListener("click", (c) => { | ||
c.target === o && v(); | ||
}), m.focus(); | ||
} | ||
export { | ||
J as searchmate | ||
ve as searchmate | ||
}; |
{ | ||
"name": "searchmate-js", | ||
"private": false, | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"type": "module", | ||
@@ -25,8 +25,9 @@ "files": [ | ||
"@types/node": "^18.16.3", | ||
"rome": "12.0.0", | ||
"typescript": "^5.0.2", | ||
"vite": "^4.3.2", | ||
"vite-plugin-dts": "^2.3.0", | ||
"rome": "12.0.0" | ||
"vite-plugin-dts": "^2.3.0" | ||
}, | ||
"dependencies": { | ||
"a11y-dialog": "^8.0.0", | ||
"just-debounce-it": "^3.2.0", | ||
@@ -33,0 +34,0 @@ "postcss-nesting": "^11.2.2" |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
56888
617
3
2
+ Addeda11y-dialog@^8.0.0
+ Addeda11y-dialog@8.1.1(transitive)
+ Addedfocusable-selectors@0.8.4(transitive)