import type { MaybeRefOrGetter } from '@vueuse/core' import { toRef } from '@vueuse/core' // eslint-disable-next-line vue/prefer-import-from-vue import { escapeHtml } from '@vue/shared' export function useNinjaMark( _text?: MaybeRefOrGetter, _search?: MaybeRefOrGetter, _classes?: MaybeRefOrGetter, ) { const text = toRef(_text) const classes = toRef(_classes) const search = toRef(_search) return computed(() => { const txt = unref(text) const srch = unref(search) if (!txt) { return '' } if (!srch) { return escapeHtml(txt) } const regex = new RegExp(srch, 'gi') return txt.replace(regex, (part) => { return `${escapeHtml(part)}` }) }) }