UNPKG

vue-amazing-ui

Version:

An Amazing Vue3 UI Components Library, Using TypeScript.

2 lines (1 loc) 1.49 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),u={class:"highlight-wrap"},p=e.defineComponent({__name:"Highlight",props:{text:{default:void 0},patterns:{default:()=>[]},autoEscape:{type:Boolean,default:!0},caseSensitive:{type:Boolean,default:!1},highlightTag:{default:"mark"},highlightClass:{default:void 0},highlightStyle:{default:()=>({})}},setup(c){const l=c,o=e.computed(()=>{if(l.patterns.length===0||!l.text)return[l.text];{const n=l.patterns.map(t=>l.autoEscape?r(t):t).join("|"),s=new RegExp(`(${n})`,l.caseSensitive?"g":"gi");return h(l.text,s).map(t=>t.isMatch?e.h(l.highlightTag,{class:["highlight-mark",l.highlightClass],style:l.highlightStyle},t.text):t.text)}});function r(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function h(n,s){const a=[];let t=0,i;for(;(i=s.exec(n))!==null&&(i.index>t&&a.push({text:n.slice(t,i.index),isMatch:!1}),a.push({text:i[0],isMatch:!0}),t=s.lastIndex,!!s.global););return t<n.length&&a.push({text:n.slice(t),isMatch:!1}),a}return(n,s)=>(e.openBlock(),e.createElementBlock("span",u,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.value,(a,t)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:t},[typeof a=="string"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(e.toDisplayString(a),1)],64)):(e.openBlock(),e.createBlock(e.resolveDynamicComponent(a),{key:1}))],64))),128))]))}});exports.default=p;