@aplus-frontend/ui
Version:
50 lines (49 loc) • 1.65 kB
JavaScript
import { defineComponent as v, computed as c, createElementBlock as s, openBlock as n, normalizeClass as p, unref as i, Fragment as u, renderList as C, renderSlot as d, createTextVNode as m, toDisplayString as y } from "vue";
import "../config-provider/index.mjs";
import S from "./style/index.mjs";
import { useNamespace as $ } from "../config-provider/hooks/use-namespace.mjs";
const B = { key: 1 }, N = /* @__PURE__ */ v({
name: "Highlight",
__name: "index",
props: {
content: {},
keywords: {},
ignoreCase: { type: Boolean }
},
setup(g) {
const o = g, { b: h, e: k } = $("highlight"), f = S("highlight"), l = c(() => {
const e = o.keywords;
if (!e)
return null;
let t = Array.isArray(e) ? e : [e];
return t = t.sort((r, a) => a.length - r.length), new RegExp(
`(${t.join("|")})`,
`${o.ignoreCase ? "i" : ""}g`
);
}), w = c(() => {
const e = o.content;
return !l.value || !e ? [{ keywords: !1, text: e }] : e.split(l.value).map((t) => ({ keywords: l.value.test(t), text: t }));
});
return (e, t) => (n(), s("div", {
class: p([i(h)(), i(f)])
}, [
(n(!0), s(u, null, C(w.value, ({ text: r, keywords: a }, _) => (n(), s(u, { key: _ }, [
a ? (n(), s("span", {
key: 0,
class: p(i(k)("keywords"))
}, [
d(e.$slots, "keywords", { text: r }, () => [
m(y(r), 1)
])
], 2)) : (n(), s("span", B, [
d(e.$slots, "default", { text: r }, () => [
m(y(r), 1)
])
]))
], 64))), 128))
], 2));
}
});
export {
N as default
};