UNPKG

chatarea

Version:

纯JS封装的聊天框,交互功能对标钉钉微信聊天框,适用于JQuery/React/Vue等各大框架,兼容PC与H5的使用

87 lines 117 kB
var j=Object.defineProperty;var X=(m,t,e)=>t in m?j(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e;var T=(m,t,e)=>(X(m,typeof t!="symbol"?t+"":t,e),e);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&s(a)}).observe(document,{childList:!0,subtree:!0});function e(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(n){if(n.ep)return;n.ep=!0;const i=e(n);fetch(n.href,i)}})();function Z(){const m=navigator.userAgent,t=/(?:Windows Phone)/.test(m),e=/(?:SymbianOS)/.test(m)||t,s=/(?:Android)/.test(m),n=/(?:Firefox)/.test(m),i=/(?:iPad|PlayBook)/.test(m)||s&&!/(?:Mobile)/.test(m)||n&&/(?:Tablet)/.test(m),a=/(?:iPhone)/.test(m)&&!i;return{isTablet:i,isPhone:a,isAndroid:s,isPc:!a&&!s&&!e}}function x(m,t=!1,e="block"){m&&(m.className=m.className.replace(/ chat-view-show| chat-view-hidden/g,""),t?(m.style.display=e,m.className+=" chat-view-show"):(m.className+=" chat-view-hidden",m.style.display="none"))}function O(m){return m.classList.contains("chat-view-show")}function y(m,t,e){m.classList[e?"add":"remove"](t)}const _=(m=50)=>new Promise(t=>{setTimeout(t,m)}),U=m=>String(m)!=="false"&&String(m)!=="null"&&String(m)!=="0",R=(m,t,e=!1)=>{let s;return function(...n){const i=this,a=()=>{s=null,e||m.apply(i,n)},l=e&&!s;clearTimeout(s),s=setTimeout(a,t),l&&m.apply(i,n)}},V=(m,t)=>{let e;return function(...s){const n=this;e||(m.apply(n,s),e=!0,setTimeout(function(){e=!1},t))}},$=(m,t,e)=>(m=m.toLowerCase(),t=t.toLowerCase(),e=e.toLowerCase(),e=e.replace(/\s/g,""),!/[\p{P}\p{S}]/u.test(e)&&J(m,t||m,e)),J=(m,t,e)=>{if(!e)return!1;const{chinesePart:s,pinyinPart:n,numberPart:i}=Q(e);if(s&&!m.startsWith(s)||i&&!m.includes(i))return!1;const a=t.replace(/\s+/g,"").toLowerCase();return!(n&&!et(n,a))},Q=m=>{let t="",e="",s="",n=null;for(const i of m)tt(i)?(n="chinese",t+=i):/[a-zA-Z]/.test(i)?(n="pinyin",e+=i.toLowerCase()):/\d/.test(i)?(n="number",s+=i):n=null;return{chinesePart:t,pinyinPart:e,numberPart:s,currentType:n}},tt=m=>{const t=m.charCodeAt(0);return t>=19968&&t<=40959||t>=13312&&t<=19903||t>=131072&&t<=173791},et=(m,t)=>{let e=0;for(const s of t){if(e>=m.length)break;s===m[e]&&e++}return e===m.length},z=(m,t)=>{const e=m.getAttribute("data-set-richType");return e==="richBox"?null:e==="richMark"||e==="chatTag"?m:m.parentElement&&t>0?z(m.parentElement,t-1):null},K=(m,t,e)=>m&&m[t]?m[t]:e,it='<svg class="check-empty-svg" viewBox="0 0 64 41" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 1)" fill="none" fill-rule="evenodd"><ellipse fill="#f5f5f5" cx="32" cy="33" rx="32" ry="7"></ellipse><g fill-rule="nonzero" stroke="#d9d9d9"><path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path><path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#fafafa"></path></g></g></svg>',st='<svg class="empty-svg" viewBox="0 0 64 41" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 1)" fill="none" fill-rule="evenodd"><ellipse fill="#f5f5f5" cx="32" cy="33" rx="32" ry="7"></ellipse><g fill-rule="nonzero" stroke="#d9d9d9"><path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path><path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#fafafa"></path></g></g></svg>',nt='<svg class="icon-search" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M684.8 223.530667a326.272 326.272 0 0 1 24.96 433.621333c2.645333 2.133333 5.290667 4.48 7.850667 7.04L870.4 817.066667c24.789333 24.746667 32.896 56.832 18.133333 71.594666-14.762667 14.805333-46.848 6.656-71.637333-18.090666l-152.789333-152.832a106.282667 106.282667 0 0 1-7.210667-7.936 326.101333 326.101333 0 0 1-433.109333-25.173334c-127.445333-127.445333-127.573333-333.952-0.256-461.269333 127.36-127.36 333.866667-127.232 461.269333 0.213333zM275.328 275.114667a252.885333 252.885333 0 0 0 0.256 357.632 252.885333 252.885333 0 0 0 357.632 0.256 252.885333 252.885333 0 0 0-0.256-357.632 252.885333 252.885333 0 0 0-357.632-0.256z" fill="#9B9B9B"></path></svg>',F='<div class="ant-spin ant-spin-spinning" aria-live="polite" aria-busy="true"><span class="ant-spin-dot ant-spin-dot-spin"><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i></span></div>',at='<svg class="match-empty-svg" viewBox="0 0 64 41" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 1)" fill="none" fill-rule="evenodd"><ellipse fill="#f5f5f5" cx="32" cy="33" rx="32" ry="7"></ellipse><g fill-rule="nonzero" stroke="#d9d9d9"><path d="M55 12.76L44.854 1.258C44.367.474 43.656 0 42.907 0H21.093c-.749 0-1.46.474-1.947 1.257L9 12.761V22h46v-9.24z"></path><path d="M41.613 15.931c0-1.605.994-2.93 2.227-2.931H55v18.137C55 33.26 53.68 35 52.05 35h-40.1C10.32 35 9 33.259 9 31.137V13h11.16c1.233 0 2.227 1.323 2.227 2.928v.022c0 1.605 1.005 2.901 2.237 2.901h14.752c1.232 0 2.237-1.308 2.237-2.913v-.007z" fill="#fafafa"></path></g></g></svg>',lt='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="none" viewBox="0 0 24 24"><path fill="currentColor" d="M9.218 17.41 19.83 6.796a.99.99 0 1 1 1.389 1.415c-3.545 3.425-4.251 4.105-11.419 11.074a.997.997 0 0 1-1.375.018c-1.924-1.801-3.709-3.568-5.573-5.43a.999.999 0 0 1 1.414-1.413z"></path></svg>',Y='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="none" viewBox="0 0 24 24"><path fill="currentColor" d="m20.23 8.653-7.795 9.685a1.2 1.2 0 0 1-1.87 0L2.771 8.652C2.14 7.867 2.698 6.7 3.706 6.7h15.588c1.008 0 1.567 1.167.935 1.952"></path></svg>',ot='<svg focusable="false" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" fill-rule="evenodd" viewBox="64 64 896 896"><path d="M512 64c247.4 0 448 200.6 448 448S759.4 960 512 960 64 759.4 64 512 264.6 64 512 64zm127.98 274.82h-.04l-.08.06L512 466.75 384.14 338.88c-.04-.05-.06-.06-.08-.06a.12.12 0 00-.07 0c-.03 0-.05.01-.09.05l-45.02 45.02a.2.2 0 00-.05.09.12.12 0 000 .07v.02a.27.27 0 00.06.06L466.75 512 338.88 639.86c-.05.04-.06.06-.06.08a.12.12 0 000 .07c0 .03.01.05.05.09l45.02 45.02a.2.2 0 00.09.05.12.12 0 00.07 0c.02 0 .04-.01.08-.05L512 557.25l127.86 127.87c.04.04.06.05.08.05a.12.12 0 00.07 0c.03 0 .05-.01.09-.05l45.02-45.02a.2.2 0 00.05-.09.12.12 0 000-.07v-.02a.27.27 0 00-.05-.06L557.25 512l127.87-127.86c.04-.04.05-.06.05-.08a.12.12 0 000-.07c0-.03-.01-.05-.05-.09l-45.02-45.02a.2.2 0 00-.09-.05.12.12 0 00-.07 0z"></path></svg>';class rt{constructor(t){T(this,"target");T(this,"richText",document.createElement("div"));T(this,"placeholderElm",document.createElement("div"));T(this,"tipElm",null);T(this,"isExternalCallPopup",!1);T(this,"isPointSearchMode",!1);T(this,"checkboxRows",[]);T(this,"customTags",{});T(this,"selectTags",{});T(this,"rects",{});T(this,"pcElms",{containerDialogElm:null,pointDialogElm:null,pointDialogCheckElm:null,pointDialogMainElm:null,pointDialogUsersElm:[],pointDialogActiveElm:null,pointDialogLoadingElm:null,pointDialogEmptyElm:null,checkDialogElm:null,checkDialogSearchResultElm:null,checkDialogUsersElm:null,checkDialogSearchInputElm:null,checkDialogTagsElm:null,customTagDialogElms:{},customTagDialogTagKey:"",customTagDialogActiveElm:null,selectDialogElms:{},selectDialogKey:"",selectDialogAim:null,tipPopoverElm:null});T(this,"h5Elms",{dialogElm:null,dialogMainElm:null,dialogCheckElm:null,dialogShowElm:null,dialogSearchElm:null,dialogEmptyElm:null,dialogLoadingElm:null});this.target=t,this.createRichText(),this.createPlaceholder(),t.deviceInfo.isPc?this.createPCDialog():this.createH5Dialog()}createRichText(){const{options:t,deviceInfo:e}=this.target,{elm:s}=t;y(s,`chat-area-${e.isPc?"pc":"h5"}`,!0),y(this.richText,"chat-rich-text",!0),this.richText.setAttribute("data-set-richType","richAllBox"),this.richText.setAttribute("contenteditable","true"),s.appendChild(this.richText)}createPlaceholder(){const{options:t}=this.target,{elm:e}=t;y(this.placeholderElm,"chat-placeholder-wrap",!0),x(this.placeholderElm,!0),e.appendChild(this.placeholderElm),this.rects.plaRect=this.placeholderElm.getBoundingClientRect()}createPCDialog(){const{options:t}=this.target,{needDialog:e,elm:s,asyncMatch:n}=t;if(!e)return;const{pcElms:i}=this;if(i.containerDialogElm=document.createElement("div"),y(this.pcElms.containerDialogElm,"chat-dialog",!0),s.parentElement)s.nextElementSibling?s.parentElement.insertBefore(i.containerDialogElm,s.nextElementSibling):s.parentElement.appendChild(i.containerDialogElm);else throw new Error('配置项:"elm" 需要存在一个父级元素,请检查后重新配置!');n||this.createPCCheckDialog(),this.createPCPointDialog()}createPCCheckDialog(){const{options:t}=this.target,e=this.target.options.dialogLabels.pcPCheckDialog,{pcElms:s}=this;s.checkDialogElm=document.createElement("div"),y(s.checkDialogElm,"checkbox-dialog",!0),x(s.checkDialogElm),s.checkDialogElm.innerHTML=` <div class="checkbox-dialog-container"> <div class="checkbox-dialog-container-header"> <span>${e.title}</span> <span class="checkbox-dialog-container-header-close">⛌</span> </div> <div class="checkbox-dialog-container-body"> <div class="checkbox-dialog-left-box"> <div class="checkbox-dialog-search"> <input class="checkbox-dialog-search-input" placeholder="${e.searchPlaceholder}" type="text"> <div class="checkbox-dialog-search-group"></div> </div> <div class="checkbox-dialog-tags"></div> <div class="checkbox-dialog-option"> <button class="checkbox-dialog-option-btn btn-submit disabled">${e.confirmLabel}</button> <button class="checkbox-dialog-option-btn btn-close">${e.cancelLabel}</button> </div> </div> <div class="checkbox-dialog-right-box"> <div class="checkbox-dialog-right-box-title">${e.userTagTitle}</div> <div class="checkbox-dialog-check-group"></div> </div> </div> </div> `,s.containerDialogElm.appendChild(s.checkDialogElm),s.checkDialogUsersElm=s.checkDialogElm.querySelector(".checkbox-dialog-check-group"),s.checkDialogSearchResultElm=s.checkDialogElm.querySelector(".checkbox-dialog-search-group"),s.checkDialogSearchInputElm=s.checkDialogElm.querySelector(".checkbox-dialog-search-input"),s.checkDialogTagsElm=s.checkDialogElm.querySelector(".checkbox-dialog-tags");const n=()=>{x(s.checkDialogElm),y(document.body,"disable-scroll")};s.checkDialogElm.querySelector(".checkbox-dialog-container-header-close").onclick=n,s.checkDialogElm.querySelector(".btn-close").onclick=n;const i=s.checkDialogElm.querySelector(".btn-submit");i.onclick=async()=>{if(i.classList.contains("disabled"))return;const l=this.checkboxRows.map(o=>{const c=Object.create(null);return c[t.userProps.id]=o.id,c[t.userProps.name]=o.name,c});await this.target.batchSetTag(l),n()},x(s.checkDialogSearchResultElm),s.checkDialogSearchResultElm.onclick=l=>{l.stopPropagation()},s.checkDialogSearchInputElm.onclick=l=>{l.stopPropagation()};const a=R(l=>{const o=String(l.target.value||"").replace(/'/g,"").trim();if(!o){x(s.checkDialogSearchResultElm);return}const c=this.target.searchUserList(o).map(h=>h.id);Array.from(s.checkDialogSearchResultElm.children,(h,r)=>{if(r===s.checkDialogSearchResultElm.children.length-1)x(h,c.length===0);else{const g=h.getAttribute("data-set-id");x(h,c.indexOf(g)!==-1,"flex")}}),x(s.checkDialogSearchResultElm,!0)},200);s.checkDialogSearchInputElm.oninput=a,s.checkDialogSearchInputElm.onfocus=a}createPCPointDialog(){const{pcElms:t,target:e}=this;t.pointDialogElm=document.createElement("div"),y(t.pointDialogElm,"call-user-dialog",!0),x(t.pointDialogElm);const s=document.createElement("div");y(s,"call-user-dialog-header",!0),s.innerHTML=`<span class="call-user-dialog-header-title">${e.options.dialogLabels.pcPointDialog.title}</span>`,t.pointDialogCheckElm=document.createElement("span"),y(t.pointDialogCheckElm,"call-user-dialog-header-check",!0),t.pointDialogCheckElm.innerText=e.options.dialogLabels.pcPointDialog.checkLabel,t.pointDialogCheckElm.onclick=()=>{this.target.showPCCheckDialog(),this.isExternalCallPopup=!1},s.appendChild(t.pointDialogCheckElm),t.pointDialogElm.appendChild(s),t.pointDialogMainElm=document.createElement("div"),y(t.pointDialogMainElm,"call-user-dialog-main",!0),t.pointDialogElm.appendChild(t.pointDialogMainElm),e.options.asyncMatch&&(t.pointDialogLoadingElm=document.createElement("div"),y(t.pointDialogLoadingElm,"call-user-dialog-loading",!0),t.pointDialogLoadingElm.innerHTML=F,t.pointDialogElm.appendChild(t.pointDialogLoadingElm),x(t.pointDialogLoadingElm),t.pointDialogEmptyElm=document.createElement("div"),y(t.pointDialogEmptyElm,"call-user-dialog-empty",!0),t.pointDialogEmptyElm.innerHTML=` ${at} <span class="empty-label">${e.options.dialogLabels.pcPointDialog.emptyLabel}</span> `,t.pointDialogElm.appendChild(t.pointDialogEmptyElm),x(t.pointDialogEmptyElm)),t.containerDialogElm.appendChild(t.pointDialogElm)}createH5Dialog(){const{options:t,chatEvent:e}=this.target,{needDialog:s,dialogLabels:n}=t;if(!s)return;const{h5Elms:i}=this;i.dialogElm=document.createElement("div"),y(i.dialogElm,"call-user-popup",!0),i.dialogElm.innerHTML=` <div class="call-user-popup-main"> <div class="call-user-popup-header"> <span class="popup-show">${n.h5Dialog.cancelLabel}</span> <span class="popup-title">${n.h5Dialog.title}</span> <span class="popup-check">${n.h5Dialog.confirmLabel}</span> </div> <div class="call-user-popup-search"> ${nt} <input class="call-user-popup-search-input" placeholder="${n.h5Dialog.searchPlaceholder}" type="text"> </div> <div class="call-user-popup-body"></div> </div> `;const a=async()=>{i.dialogElm.className=i.dialogElm.className.replace(/ chat-view-show/g," chat-view-hidden"),i.dialogSearchElm.value="",await _(260),x(i.dialogElm),y(document.body,"disable-scroll"),t.asyncMatch&&this.target.updateUserList([]),this.target.chatInput.restCursorPos(this.target.chatInput.vnode,this.target.chatInput.cursorIndex),this.target.chatInput.viewIntoPoint()};i.dialogElm.onclick=a;const l=i.dialogElm.querySelector(".call-user-popup-main");l.onclick=o=>{o.stopPropagation()},i.dialogShowElm=i.dialogElm.querySelector(".popup-show"),i.dialogShowElm.onclick=a,i.dialogCheckElm=i.dialogElm.querySelector(".popup-check"),i.dialogCheckElm.onclick=async()=>{if(i.dialogCheckElm.classList.contains("disabled"))return;const o=i.dialogElm.querySelectorAll(".user-popup-check-item-check")||[];if(o.length===0){await a();return}if(Array.prototype.some.call(o,r=>r.getAttribute("data-set-id")==="isALL")){await this.target.onceSetTag({[t.userProps.id]:"isALL",[t.userProps.name]:t.dialogLabels.h5Dialog.callEveryLabel}),await a();return}const c=Array.from(o,r=>r.getAttribute("data-set-id")),h=t.userList.filter(r=>c.indexOf(String(r[t.userProps.id]))!==-1);await this.target.batchSetTag(h),await a()},i.dialogMainElm=i.dialogElm.querySelector(".call-user-popup-body"),i.dialogEmptyElm=document.createElement("div"),y(i.dialogEmptyElm,"call-user-popup-empty",!0),this.h5Elms.dialogEmptyElm.innerHTML=` ${st} <span class="empty-label">${t.dialogLabels.h5Dialog.searchEmptyLabel}</span> `,x(i.dialogEmptyElm),l.appendChild(i.dialogEmptyElm),t.asyncMatch&&(i.dialogLoadingElm=document.createElement("div"),y(i.dialogLoadingElm,"call-user-popup-loading",!0),i.dialogLoadingElm.innerHTML=F,x(i.dialogLoadingElm),l.appendChild(i.dialogLoadingElm)),i.dialogSearchElm=i.dialogElm.querySelector(".call-user-popup-search-input"),i.dialogSearchElm.oninput=R(o=>{const c=String(o.target.value||"").replace(/'/g,"").trim();if(t.asyncMatch){e.matchKey++;const r=e.matchKey;this.target.updateUserList([]),x(i.dialogLoadingElm,!0),x(i.dialogEmptyElm);const p=e.triggerChatEvent("atMatch",c).find(d=>d&&d instanceof Promise);p&&p.then(d=>{if(r===e.matchKey){if(x(i.dialogLoadingElm),!d||d.length<=0){x(i.dialogEmptyElm,!0,"flex");return}this.target.updateUserList(d)}});return}const h=[];Array.from(this.h5Elms.dialogMainElm.children,r=>{if(!c){x(r,!0,"flex"),h.push(r);return}const g=r.getAttribute("data-set-name")||"",p=r.getAttribute("data-set-pinyin")||"";$(g,p,c)?(x(r,!0,"flex"),h.push(r)):x(r)}),x(this.h5Elms.dialogEmptyElm,!h.length,"flex")},200),x(i.dialogElm),document.body.appendChild(i.dialogElm)}updatePCUser(){const{pcElms:t,target:e}=this;t.pointDialogMainElm.innerHTML="",t.pointDialogActiveElm=void 0;const s=document.createDocumentFragment();if(this.target.options.needCallEvery){const l=document.createElement("div");y(l,"call-user-dialog-item",!0),l.setAttribute("data-set-id","isALL"),this.userSelectStyleAndEvent(l,{id:"isALL",name:e.options.dialogLabels.pcPointDialog.callEveryLabel}),l.innerHTML=` <span class="call-user-dialog-item-sculpture"> <span style="transform: scale(0.75)">@</span> </span> <span class="call-user-dialog-item-name">${e.options.dialogLabels.pcPointDialog.callEveryLabel}(${e.options.reformList.length})</span> `,s.appendChild(l)}if(e.options.reformList.forEach(l=>{const o=document.createElement("div");y(o,"call-user-dialog-item",!0),o.setAttribute("data-set-id",l.id),this.userSelectStyleAndEvent(o,l),this.getUserHtmlTemplate(o,l),s.appendChild(o)}),t.pointDialogMainElm.appendChild(s),t.pointDialogUsersElm=[],Array.from(t.pointDialogMainElm.children||[],(l,o)=>{t.pointDialogUsersElm.push({index:o,elm:l})}),e.options.asyncMatch)return;t.checkDialogUsersElm.innerHTML=` <div class="checkbox-dialog-check-item" data-set-value="ALL"> <input type="checkbox" value> <span class="checkbox-dialog-check-item-inner"></span> <div class="checkbox-dialog-check-item-label">${e.options.dialogLabels.pcPCheckDialog.checkAllLabel}</div> </div> `;const n=document.createDocumentFragment();e.options.reformList.forEach(l=>{const o=document.createElement("div");y(o,"checkbox-dialog-check-item",!0),o.setAttribute("data-set-value",l.id),o.innerHTML=` <input type="checkbox" value> <span class="checkbox-dialog-check-item-inner"></span> `,this.getUserHtmlTemplate(o,l),n.appendChild(o)}),t.checkDialogUsersElm.appendChild(n),t.checkDialogUsersElm&&t.checkDialogUsersElm.children.length&&Array.from(t.checkDialogUsersElm.children,l=>{l.onclick=()=>{const o=l.getAttribute("data-set-value")||"",c=e.options.reformList.find(r=>r.id===o),h=l.className.indexOf("checkbox-dialog-check-item-check")===-1;o==="ALL"?this.checkboxRows=h?e.options.reformList.map(r=>r):[]:h?this.checkboxRows.push(c):this.checkboxRows=this.checkboxRows.filter(r=>r.id!==o),this.updateCheckDialogTags()}});const i=document.createDocumentFragment();e.options.reformList.forEach(l=>{const o=document.createElement("div");y(o,"checkbox-dialog-check-item",!0),o.setAttribute("data-set-id",l.id);const c=document.createElement("div");y(c,"checkbox-dialog-check-item-label",!0),this.getUserHtmlTemplate(c,l),o.appendChild(c),o.onclick=()=>{x(this.pcElms.checkDialogSearchResultElm);const h=o.getAttribute("data-set-id")||"";if(this.pcElms.checkDialogSearchInputElm.value="",this.pcElms.checkDialogSearchInputElm.focus(),this.checkboxRows.some(g=>g.id===h))return;const r=e.options.reformList.find(g=>g.id===h);r&&this.checkboxRows.push(r),this.updateCheckDialogTags()},i.appendChild(o)});const a=document.createElement("div");y(a,"checkbox-dialog-search-empty",!0),a.innerText=e.options.dialogLabels.pcPCheckDialog.searchEmptyLabel,i.appendChild(a),t.checkDialogSearchResultElm.appendChild(i)}updateH5User(){const{h5Elms:t,target:e}=this;t.dialogMainElm.innerHTML="";const s=e.options.reformList&&e.options.reformList.length>0,n=document.createDocumentFragment(),i=document.createElement("span");if(i.innerHTML=` <input type="checkbox" value> <span class="user-popup-check-item-inner"></span> `,s){const a=document.createElement("div");e.options.needCallEvery&&(y(a,"call-user-popup-item",!0),a.setAttribute("data-set-id","isALL"),a.innerHTML=` <span class="call-user-dialog-item-sculpture"> <span style="transform: scale(0.75)">@</span> </span> <span class="call-user-dialog-item-name">${e.options.dialogLabels.h5Dialog.callEveryLabel}(${e.options.reformList.length})</span> `,a.appendChild(i.cloneNode(!0)),a.onclick=()=>{const l=!a.classList.contains("user-popup-check-item-check");Array.from(this.h5Elms.dialogMainElm.children,o=>{y(o,"user-popup-check-item-check",l)}),y(this.h5Elms.dialogCheckElm,"disabled",!l)},n.appendChild(a)),e.options.reformList.forEach((l,o)=>{const c=document.createElement("div");y(c,"call-user-popup-item",!0),c.setAttribute("data-set-id",l.id),c.setAttribute("data-set-name",l.name),c.setAttribute("data-set-pinyin",l.pinyin||""),this.getUserHtmlTemplate(c,l),c.appendChild(i.cloneNode(!0)),n.appendChild(c),c.onclick=h=>{const r=!c.classList.contains("user-popup-check-item-check");y(c,"user-popup-check-item-check",r);const g=Array.prototype.every.call(this.h5Elms.dialogMainElm.children,d=>d.classList.contains("user-popup-check-item-check")||d.getAttribute("data-set-id")==="isALL");y(a,"user-popup-check-item-check",g);const p=Array.prototype.some.call(this.h5Elms.dialogMainElm.children,d=>d.classList.contains("user-popup-check-item-check"));y(this.h5Elms.dialogCheckElm,"disabled",!p)}})}t.dialogMainElm.appendChild(n)}updateCheckDialogTags(){const t=this.checkboxRows.map(o=>o.id),e=[],s=[],n=document.createElement("div");n.className="check-empty",n.innerHTML=` ${it} <span class="check-empty-label">${this.target.options.dialogLabels.pcPCheckDialog.checkEmptyLabel}</span> `,Array.from(this.pcElms.checkDialogTagsElm.children,o=>{const c=o.getAttribute("data-set-value");t.indexOf(c)===-1?s.push(o):e.push(c)}),Array.from(this.pcElms.checkDialogUsersElm.children,(o,c)=>{if(c===0){y(o,"checkbox-dialog-check-item-check",t.length===this.target.options.reformList.length);return}const h=o.getAttribute("data-set-value");y(o,"checkbox-dialog-check-item-check",t.indexOf(h)!==-1)}),s.forEach(o=>{this.pcElms.checkDialogTagsElm.removeChild(o)});const i=this.pcElms.checkDialogElm.querySelector(".btn-submit");y(i,"disabled",t.length<=0),t.length||this.pcElms.checkDialogTagsElm.appendChild(n);const a=this.checkboxRows.filter(o=>e.indexOf(o.id)===-1);if(!a.length)return;const l=document.createDocumentFragment();a.forEach(o=>{const c=document.createElement("div");c.setAttribute("class","checkbox-dialog-tag-item"),c.setAttribute("data-set-value",o.id),c.innerHTML=` <span>${o.name}</span> `;const h=document.createElement("span");h.setAttribute("class","checkbox-dialog-tag-item-close"),h.innerHTML="⛌",h.onclick=()=>{const r=c.getAttribute("data-set-value");this.checkboxRows=this.checkboxRows.filter(g=>g.id!==r),this.updateCheckDialogTags()},c.appendChild(h),l.appendChild(c)}),this.pcElms.checkDialogTagsElm.appendChild(l)}userSelectStyleAndEvent(t,e){t.addEventListener("click",async s=>{const{options:n}=this.target;if(s.stopPropagation(),this.updatePointActiveUserElm(t),this.isPointSearchMode||n.asyncMatch)await this.target.matchSetTag(e);else{const i=n.userList.find(a=>String(a[n.userProps.id])===e.id);await this.target.onceSetTag(i)}this.exitPointDialog()})}bindCustomTrigger(){Object.values(this.pcElms.customTagDialogElms).forEach(e=>{this.pcElms.containerDialogElm.removeChild(e)}),this.pcElms.customTagDialogElms={},this.customTags={},this.target.options.customTrigger.forEach(e=>{e.tagList&&e.tagList.length>0&&(this.customTags[e.prefix]=e.tagList.map(s=>({id:String(s.id),name:String(s.name),pinyin:String(s.pinyin||"")})),this.createCustomTagDialog(e))})}createCustomTagDialog(t){const e=document.createElement("div");e.setAttribute("class","call-tag-dialog"),x(e);const s=document.createElement("div");s.setAttribute("class","call-tag-dialog-header"),s.innerHTML=`<span class="call-tag-dialog-header-title">${t.dialogTitle||t.prefix}</span>`,e.appendChild(s);const n=document.createElement("div");n.setAttribute("class","call-tag-dialog-main"),t.tagList.forEach(i=>{const a=document.createElement("div");a.setAttribute("class","call-tag-dialog-item"),a.setAttribute("data-set-id",i.id);const l=document.createElement("span");l.setAttribute("class","call-tag-dialog-item-name"),l.innerHTML=i.name,a.appendChild(l),a.addEventListener("click",async o=>{o.stopPropagation(),this.updateActiveCustomTagElm(a),this.isPointSearchMode?await this.target.matchSetCustomTag(i):await this.target.onceSetCustomTag(i),this.exitCustomTagDialog()}),n.appendChild(a)}),e.appendChild(n),this.pcElms.containerDialogElm.appendChild(e),this.pcElms.customTagDialogElms[t.prefix]=e}getUserHtmlTemplate(t,e){const s=document.createElement("span");if(s.setAttribute("class",`call-user-dialog-item-sculpture ${e.avatar?"is-avatar":""}`),e.avatar){const i=new Image;i.alt="",i.src=String(e.avatar),s.appendChild(i)}else s.innerHTML=`<span style="transform: scale(0.75)">${e.name.slice(-2)}</span>`;t.appendChild(s);const n=document.createElement("span");n.setAttribute("class","call-user-dialog-item-name"),n.innerHTML=e.name,t.appendChild(n)}updatePointActiveUserElm(t,e=!1){if(this.pcElms.pointDialogActiveElm&&y(this.pcElms.pointDialogActiveElm,"call-user-dialog-item-active"),this.pcElms.pointDialogActiveElm=t,t&&(y(t,"call-user-dialog-item-active",!0),e)){const s=Array.prototype.filter.call(this.pcElms.pointDialogMainElm.children,o=>o.className.indexOf("user-no-match")===-1),n=t.clientHeight,i=Array.prototype.indexOf.call(s,t),a=Math.ceil(Math.floor(this.pcElms.pointDialogMainElm.clientHeight/n)/2),l=i+1-a;l>0?this.pcElms.pointDialogMainElm.scrollTop=l*n:this.pcElms.pointDialogMainElm.scrollTop=0}}updateActiveCustomTagElm(t,e=!1){if(this.pcElms.customTagDialogActiveElm&&y(this.pcElms.customTagDialogActiveElm,"call-tag-dialog-item-active"),this.pcElms.customTagDialogActiveElm=t,t&&(y(t,"call-tag-dialog-item-active",!0),e)){const s=this.pcElms.customTagDialogElms[this.pcElms.customTagDialogTagKey].children[1],n=Array.prototype.filter.call(s.children,c=>c.className.indexOf("tag-no-match")===-1),i=t.clientHeight,a=Array.prototype.indexOf.call(n,t),l=Math.ceil(Math.floor(s.clientHeight/i)/2),o=a+1-l;o>0?s.scrollTop=o*i:s.scrollTop=0}}showPointDialog(t){this.exitSelectDialog(),this.exitCustomTagDialog(),this.exitPointDialog(),this.isPointSearchMode=!!t;let e=null;this.pcElms.pointDialogUsersElm.forEach(s=>{const n=s.elm,i=n.getAttribute("data-set-id"),a=t&&t.every(l=>l.id!==i);!e&&!a&&(e=n),y(n,"user-no-match",a)}),e!==null&&this.updatePointActiveUserElm(e),x(this.pcElms.pointDialogCheckElm,!this.target.options.asyncMatch&&!this.isPointSearchMode),x(this.pcElms.pointDialogElm,!0),this.target.chatEvent.debounceEvents.dialogMoveToRange(this.pcElms.pointDialogElm),this.pcElms.pointDialogMainElm.scrollTop=0}showCustomTagDialog(t,e){this.exitSelectDialog(),this.exitCustomTagDialog(),this.exitPointDialog(),this.isPointSearchMode=!!e,this.pcElms.customTagDialogTagKey=t;const s=this.pcElms.customTagDialogElms[t],n=s.children[1];let i=null;Array.from(n.children,a=>{const l=a.getAttribute("data-set-id"),o=e&&e.every(c=>c.id!==l);!i&&!o&&(i=a),y(a,"tag-no-match",o)}),i!==null&&this.updateActiveCustomTagElm(i),x(s,!0),this.target.chatEvent.debounceEvents.dialogMoveToRange(s),s.children[1].scrollTop=0}exitPointDialog(){this.updatePointActiveUserElm(),this.target.options.asyncMatch&&this.target.updateUserList([]),x(this.pcElms.pointDialogElm)}exitCustomTagDialog(){this.updateActiveCustomTagElm();for(const t in this.pcElms.customTagDialogElms)x(this.pcElms.customTagDialogElms[t])}ruleShowPointDialog(){const{options:t,chatInput:e}=this.target;t.needDialog&&t.reformList.length>0&&e.showAt()&&(this.isExternalCallPopup=!1,this.showPointDialog())}showPlaceholder(){x(this.placeholderElm,this.target.isEmpty()),this.offsetViewElm()}bindSelectList(){Object.values(this.pcElms.selectDialogElms).forEach(e=>{this.pcElms.containerDialogElm.removeChild(e)}),this.pcElms.selectDialogElms={},this.selectTags={},this.target.options.selectList.forEach(e=>{e.options&&e.options.length>0&&(this.selectTags[e.key]=e.options.map(s=>({id:String(s.id),name:String(s.name),preview:String(s.preview||"")})),this.createSelectDialog(e))})}createSelectDialog(t){const e=document.createElement("div");e.setAttribute("class","chat-select-dialog"),x(e);const s=document.createElement("div");s.setAttribute("class","chat-select-dialog-header"),s.innerHTML=`<span class="chat-select-dialog-header-title">${t.dialogTitle||t.key}</span>`,e.appendChild(s);const n=document.createElement("div");n.setAttribute("class","chat-select-dialog-main"),t.options.forEach(a=>{const l=document.createElement("div");if(l.setAttribute("class","chat-select-dialog-item"),l.setAttribute("data-set-id",a.id),a.preview){const h=document.createElement("img");h.setAttribute("class","chat-select-dialog-preview"),h.src=String(a.preview),l.appendChild(h)}const o=document.createElement("span");o.setAttribute("class","chat-select-dialog-name"),o.textContent=a.name;const c=document.createElement("span");c.setAttribute("class","chat-select-dialog-check"),c.innerHTML=lt,x(c),o.appendChild(c),l.appendChild(o),l.onclick=async()=>{await this.target.setSelectTag(a)},n.appendChild(l)}),e.appendChild(n);const i=document.createElement("div");i.setAttribute("class","chat-select-arrow"),e.appendChild(i),this.pcElms.containerDialogElm.appendChild(e),this.pcElms.selectDialogElms[t.key]=e}exitSelectDialog(){for(const t in this.pcElms.selectDialogElms)x(this.pcElms.selectDialogElms[t]);this.pcElms.selectDialogKey="",this.pcElms.selectDialogAim&&(y(this.pcElms.selectDialogAim,"aim"),this.pcElms.selectDialogAim=null)}createTipElm(t){this.tipElm||(this.tipElm=document.createElement("div")),y(this.tipElm,"chat-tip-wrap",!0),this.tipElm.innerHTML=` <div class="chat-tip-tag"> <span class="chat-tip-tag-txt">${t.tagLabel||"--"}</span> <span class="chat-tip-tag-close"> ${ot} </span> </div> `,this.target.options.elm.appendChild(this.tipElm);const e=this.tipElm.children[0],s=(e.clientHeight-this.target.chatInput.NODE_HEIGHT)/2;this.tipElm.style.top=`-${s}px`,e.onclick=()=>{this.target.closeTipTag()},e.onmouseenter=()=>{if(this.pcElms.tipPopoverElm){x(this.pcElms.tipPopoverElm,!0);const l=this.pcElms.containerDialogElm.getBoundingClientRect();this.rects.tipRect=this.tipElm.getBoundingClientRect();const o=(this.pcElms.tipPopoverElm.clientWidth-(this.tipElm.clientWidth+(this.tipElm.clientWidth-e.clientWidth)))/2;this.pcElms.tipPopoverElm.style.left=-o+"px",this.pcElms.tipPopoverElm.style.bottom=l.y-this.rects.tipRect.y+"px",this.pcElms.tipPopoverElm.style.transform=e.style.transform}},e.onmouseleave=()=>{this.pcElms.tipPopoverElm&&x(this.pcElms.tipPopoverElm)};const i=this.richText.children[0].children[0];this.rects.tipRect=this.tipElm.getBoundingClientRect();const a=this.rects.tipRect;this.placeholderElm.style.paddingLeft=a.width+"px",i.style.paddingLeft=a.width-i.offsetLeft+"px",e.style.transform=`translateY(${i.offsetTop-this.target.chatInput.NODE_PADDING_DIFF}px)`,this.target.deviceInfo.isPc&&(this.pcElms.tipPopoverElm||(this.pcElms.tipPopoverElm=document.createElement("div")),y(this.pcElms.tipPopoverElm,"chat-tip-popover",!0),this.pcElms.tipPopoverElm.innerHTML=` <div class="chat-tip-popover-main"> <span class="chat-tip-popover-txt">${t.popoverLabel||"--"}</span> <span class="chat-tip-popover-code ${t.codeLabel?"":"chat-view-show"}">${t.codeLabel||"--"}</span> </div> <div class="chat-tip-popover-arrow"></div> `,this.pcElms.containerDialogElm.appendChild(this.pcElms.tipPopoverElm),x(this.pcElms.tipPopoverElm))}offsetViewElm(){if(this.tipElm){const t=this.richText.children[0].children[0];t.style.paddingLeft=this.rects.tipRect.width-t.offsetLeft+"px",this.target.chatEvent.debounceEvents.offsetTipTag()}}removeTipElm(){this.tipElm&&(this.target.options.elm.removeChild(this.tipElm),this.tipElm=null),this.pcElms.tipPopoverElm&&(this.pcElms.containerDialogElm.removeChild(this.pcElms.tipPopoverElm),this.pcElms.tipPopoverElm=null);const e=this.richText.children[0].children[0];this.placeholderElm.style.removeProperty("padding-left"),e.style.removeProperty("padding-left"),this.target.chatInput.setRangeLastText()}}class ct{constructor(t){T(this,"target");T(this,"richText");T(this,"vnode");T(this,"cursorIndex");T(this,"cursorLeft");T(this,"needCallSpace",!1);T(this,"inputTagWatcher",null);T(this,"VOID_KEY","\uFEFF");T(this,"ZERO_WIDTH_KEY","​");T(this,"INPUT_TAG_WRAP_KEY",`​ ​`);T(this,"NODE_HEIGHT",24);T(this,"NODE_PADDING_DIFF",10);T(this,"IME_RECORD",{MARK:void 0,GRID:void 0,TAG:void 0,NODE:void 0,INDEX:void 0});this.target=t,this.richText=t.chatElement.richText,this.initEditor()}initEditor(t=!1,e){if(t||this.getNodeEmpty(this.richText)){this.richText.innerHTML="";const s=this.getGridElm();this.richText.appendChild(s);const n=s.children[0].children[0];e&&(n.textContent=e,n.setAttribute("data-set-empty","false"));const i=n.childNodes[0];t||this.target.options.autoFocus?this.restCursorPos(i,i.textContent===this.VOID_KEY?1:i.textContent.length):(this.vnode=i,this.cursorIndex=i.textContent===this.VOID_KEY?1:i.textContent.length);const a=s.getBoundingClientRect();this.NODE_HEIGHT=a.height,this.NODE_PADDING_DIFF=a.top-this.richText.parentElement.getBoundingClientRect().top}}onceCall(t){return new Promise(e=>{const s=this.createChatTagElm(t,"@","at-user","user-id");this.replaceRegContent(s),e()})}onceSearchCall(t,e){return new Promise(s=>{const n=this.createChatTagElm(t,"@","at-user","user-id");this.replaceRegContent(n,e),s()})}onceCustomCall(t,e,s){return new Promise(n=>{const i=this.createChatTagElm(t,s,"at-tag","tag-id");i.children[0].setAttribute("data-set-prefix",s),this.replaceRegContent(i,e),n()})}upDataNodeOrIndex(){var a,l,o;const{focusNode:t,focusOffset:e,anchorOffset:s}=window.getSelection(),n=(t==null?void 0:t.parentNode)||void 0;!n||!n.getAttribute||n.getAttribute("data-set-richType")!=="richInput"||((o=(l=(a=t==null?void 0:t.parentNode)==null?void 0:a.parentNode)==null?void 0:l.parentNode)==null?void 0:o.parentNode)!==this.richText||(this.vnode=t,this.cursorIndex=e,this.cursorLeft=s<e?s:e)}showAt(){if(this.upDataNodeOrIndex(),!this.vnode||this.vnode.nodeType!==Node.TEXT_NODE)return!1;const t=this.vnode.textContent||"",e=/@([^@\s]*)$/,s=t.slice(0,this.cursorIndex),n=e.exec(s);return n&&n.length===2&&s[s.length-1]==="@"}getRangeRect(){let t=0,e=0;const s=window.getSelection();if(s.focusNode.nodeType!==Node.TEXT_NODE)return null;const n=s.getRangeAt(0).getClientRects()[0];return n&&(t=n.x,e=n.y),{x:t,y:e}}createChatTagElm(t,e,s,n){const i=document.createElement("span");return i.className=s,i.setAttribute(`data-${n}`,String(t.id)),i.textContent=`${e}${t.name}${this.needCallSpace?" ":""}`,this.createNewDom(i)}createNewDom(t){const e=document.createElement("span");return e.className="chat-tag",e.setAttribute("contenteditable","false"),e.setAttribute("data-set-richType","chatTag"),e.appendChild(t),e}restCursorPos(t,e){e==null?e=t.textContent===this.VOID_KEY?1:0:e>t.textContent.length&&(e=t.textContent.length);const s=new Range;s.setStart(t,e),s.setEnd(t,e);const n=window.getSelection();n&&(this.vnode=t,this.cursorIndex=e,this.cursorLeft=e,n.removeAllRanges(),n.addRange(s))}replaceRegContent(t,e=!0){const s=this.vnode.textContent;let n;typeof e=="boolean"?n=s.slice(0,e?this.cursorIndex-1:this.cursorIndex):n=s.slice(0,e-1),n.length===0?(this.vnode.parentElement.setAttribute("data-set-empty",!0),this.vnode.textContent=this.VOID_KEY):this.vnode.textContent=n;let i=s.slice(this.cursorIndex);const a=this.vnode.parentNode.parentNode,l=a.nextSibling;l?a.parentNode.insertBefore(t,l):a.parentNode.appendChild(t);const c=t.previousSibling.childNodes[0],h=c.childNodes[1];h&&c.removeChild(h);const r=this.getGridElm(!0),g=r.childNodes[0];i&&i!==this.VOID_KEY&&(g.setAttribute("data-set-empty","false"),g.innerHTML=i);const p=g.childNodes[1];t.nextSibling?(p&&g.removeChild(p),a.parentNode.insertBefore(r,t.nextSibling)):a.parentNode.appendChild(r),this.restCursorPos(g.childNodes[0])}batchReplaceRegContent(t=[],e=!0){return new Promise(s=>{let n=`<span data-set-richType="richMark"><span class="chat-grid-input" data-set-richType="richInput" data-set-empty="true">${this.VOID_KEY}</span></span>`;t.forEach(a=>{n+=`<span class="chat-tag" contenteditable="false" data-set-richType="chatTag"><span class="at-user" data-user-id="${a.id}" contentEditable="false">@${a.name}${this.needCallSpace?" ":""}</span></span><span data-set-richType="richMark"><span class="chat-grid-input" data-set-richType="richInput" data-set-empty="true">${this.VOID_KEY}</span></span>`});const i=document.createElement("div");i.innerHTML=n,this.insetRangeGrid(i,e?1:0),s()})}switchRange(t){var l,o;let{focusNode:e,focusOffset:s}=window.getSelection();e.getAttribute&&e.getAttribute("data-set-richType")==="richInput"&&(e=e.childNodes[0]);let n,i,a=!1;if(e.nodeType===Node.TEXT_NODE){const c=e.textContent.length,h=e.parentNode.parentNode;switch(t){case"ArrowLeft":if(s>0&&e.textContent!==this.VOID_KEY){i=s-1,n=e;break}const r=h.previousSibling;if(r&&r.children[0].classList.contains("at-input")){n=r.children[0].children[0].childNodes[0],i=n.textContent===this.VOID_KEY?1:n.textContent.length,a=!0;break}const g=(l=h==null?void 0:h.previousSibling)==null?void 0:l.previousSibling;if(g)n=g.childNodes[0].childNodes[0],i=n.textContent.length;else{const u=h.parentNode.previousSibling;u&&(n=u.lastChild.childNodes[0].childNodes[0],i=n.textContent.length)}break;case"ArrowRight":if(s<c&&e.textContent!==this.VOID_KEY){i=s+1,n=e;break}const p=h.nextSibling;if(p&&p.children[0].classList.contains("at-input")){n=p.children[0].children[0].childNodes[0],i=n.textContent===this.VOID_KEY?1:0,a=!0;break}const d=(o=h==null?void 0:h.nextSibling)==null?void 0:o.nextSibling;if(d)n=d.childNodes[0].childNodes[0],i=n.textContent===this.VOID_KEY?1:0;else{const u=h.parentNode.nextSibling;u&&(n=u.childNodes[0].childNodes[0].childNodes[0],i=n.textContent===this.VOID_KEY?1:0)}break}}(i||i===0)&&(a?this.setInputTagRange(n,i):this.restCursorPos(n,i))}getGridElm(t=!1){const e=document.createElement("span");if(e.setAttribute("data-set-richType","richMark"),e.innerHTML=`<span class="chat-grid-input" data-set-richType="richInput" data-set-empty="true">${this.VOID_KEY}<br></span>`,t)return e;const s=document.createElement("p");return s.className="chat-grid-wrap",s.setAttribute("data-set-richType","richBox"),s.appendChild(e),s}updateGrid(){const t=window.getSelection(),e=t.focusNode;if(!e)return;const s=e.parentNode,n=s.getAttribute("data-set-richType");let i,a,l,o;switch(n){case"richAllBox":if(i=e.childNodes[t.focusOffset],!i||i.getAttribute("data-set-richType")==="chatTag"){const d=this.getGridElm(!0),u=d.children[0];i?(u.removeChild(u.childNodes[1]),e.insertBefore(d,i)):e.appendChild(d),this.restCursorPos(u.childNodes[0]);break}if(i.tagName==="BR"){const d=this.getGridElm(!0),u=d.children[0];e.insertBefore(d,i),e.removeChild(i),this.restCursorPos(u.childNodes[0],u.childNodes[0].textContent.length)}break;case"richMark":const c=s.parentNode,h=Array.prototype.indexOf.call(c.childNodes,s);if(h===-1)break;if(h===0){const d=t.focusNode;d.setAttribute("data-set-empty","true"),d.innerHTML=`${this.VOID_KEY}<br>`,i=d.childNodes[0],this.restCursorPos(i,i.textContent.length);break}let r=s.previousSibling,g;r.getAttribute("data-set-richType")==="chatTag"?(g=r.previousSibling,c.removeChild(r),c.removeChild(s)):(g=s.previousSibling,c.removeChild(s)),i=g.childNodes[0].childNodes[0],i.textContent===this.VOID_KEY&&i.parentNode.appendChild(document.createElement("br")),this.restCursorPos(i,i.textContent.length);break;case"richInput":if(o=s.parentNode,l=o.parentNode,this.getNodeEmpty(s)){s.setAttribute("data-set-empty","true"),l.childNodes[l.childNodes.length-1]===o&&(s.innerHTML=`${this.VOID_KEY}<br>`),i=s.childNodes[0],this.restCursorPos(i,i.textContent.length);break}if(String(s.getAttribute("data-set-empty"))==="true"){s.setAttribute("data-set-empty","false"),i=s.childNodes[0],this.target.chatEvent.isIMEModel?(s.childNodes[1]&&s.removeChild(s.childNodes[1]),i.textContent===this.VOID_KEY&&s.setAttribute("data-set-empty","true")):s.textContent=i.textContent.replace(new RegExp(this.VOID_KEY,"g"),"");const d=s.childNodes[0];this.restCursorPos(d,d.textContent.length)}if(a=s.parentNode.nextSibling,a&&a.nodeType===Node.TEXT_NODE){let d=a.textContent,u=this.getGridElm(!0);u.childNodes[0].textContent=d,u.childNodes[0].setAttribute("data-set-empty","false"),a.parentNode.insertBefore(u,a),a.parentNode.removeChild(a),a=u}a&&a.getAttribute("data-set-richType")==="richMark"&&this.markMerge(s.parentNode,a);break}}getNodeEmpty(t){const e=new RegExp(`^(${this.ZERO_WIDTH_KEY}|<br>|${this.VOID_KEY})+$`);return!t.innerHTML||e.test(t.innerHTML)}setWrap(t=!0){const e=window.getSelection();let{focusNode:s,focusOffset:n}=e;if(s.nodeType!==Node.TEXT_NODE){if(!s.getAttribute||s.getAttribute("data-set-richType")!=="richInput")return;s=s.childNodes[0]}const i=s.textContent.slice(n),a=s.parentNode.parentNode,l=a.parentNode,o=Array.prototype.indexOf.call(l.childNodes,a),c=Array.prototype.slice.call(l.childNodes,o+1),h=this.getGridElm();let r=h.children[0].children[0].childNodes[0];(i||c.length>0)&&r.parentNode.removeChild(r.parentNode.childNodes[1]),i&&i!==this.VOID_KEY&&(s.textContent=s.textContent.slice(0,n),r.textContent=i,r.parentElement.setAttribute("data-set-empty","false")),c.forEach(d=>{l.removeChild(d),h.appendChild(d)});const g=l.lastChild.childNodes[0],p=h.lastChild.childNodes[0];if(g.childNodes.length<=1){const d=g.childNodes[0];(!d.textContent||d.textContent===this.VOID_KEY)&&(g.innerHTML=`${this.VOID_KEY}<br>`,g.setAttribute("data-set-empty","true"))}if(p.parentElement.getAttribute("data-set-richType")!=="richMark")h.appendChild(this.getGridElm(!0));else if(p.childNodes.length<=1){const d=p.childNodes[0];(!d.textContent||d.textContent===this.VOID_KEY)&&(p.innerHTML=`${this.VOID_KEY}<br>`,p.setAttribute("data-set-empty","true"),r=h.children[0].children[0].childNodes[0])}l.nextSibling?this.richText.insertBefore(h,l.nextSibling):this.richText.appendChild(h),t&&this.restCursorPos(r,r.textContent===this.VOID_KEY?1:0)}selectRegionMerge(){const t=window.getSelection();if(t.isCollapsed||t.rangeCount<=0)return;const e=t.getRangeAt(0);if(e.startContainer.nodeType===Node.TEXT_NODE&&e.startContainer===e.endContainer){const s=e.startContainer;if(s.length===e.endOffset-e.startOffset){const n=s.parentNode,i=n.parentNode===n.parentNode.parentNode.lastChild;n.setAttribute("data-set-empty","true"),n.innerHTML=`\uFEFF${i?"<br>":""}`,this.restCursorPos(n.childNodes[0])}else e.deleteContents()}else if(e.commonAncestorContainer&&e.commonAncestorContainer.getAttribute("data-set-richType")==="richBox"){const s=e.startContainer.nodeType===Node.TEXT_NODE?e.startContainer.parentNode.parentNode:e.startContainer,n=e.endContainer.nodeType===Node.TEXT_NODE?e.endContainer.parentNode.parentNode:e.endContainer;e.deleteContents(),s.getAttribute("data-set-richType")===n.getAttribute("data-set-richType")&&this.markMerge(s,n)}else if(e.commonAncestorContainer===e.startContainer&&e.startContainer===e.endContainer)this.initEditor(!0);else{const s=a=>{if(a.nodeType===Node.TEXT_NODE)return a.parentNode.parentNode.parentNode;switch(a.getAttribute("data-set-richType")){case"richInput":return a.parentNode.parentNode;case"richMark":return a.parentNode;case"richBox":return a;default:return null}},n=s(e.startContainer),i=s(e.endContainer);if(!n||!i)return;e.deleteContents(),this.gridMerge(n,i)}return!0}gridElmMerge(){const t=window.getSelection(),{focusNode:e,focusOffset:s,isCollapsed:n}=t;if(!e)return this.restCursorPos(this.vnode,this.cursorIndex),!1;if(s>1||!n)return!1;const i=(o,c)=>o.parentNode!==this.richText&&o!==o.parentNode.childNodes[0]?!1:Array.prototype.indexOf.call(this.richText.childNodes,o)!==-1?o:c>=6?!1:i(o.parentNode,c+1),a=i(e,0);if(!a||a===this.richText.childNodes[0]||s===1&&a.children[0].children[0].getAttribute("data-set-empty")==="false")return!1;const l=a.previousSibling;return this.gridMerge(l,a),!0}delMarkRule(){const t=window.getSelection(),e=t.focusNode;if(!e)return this.restCursorPos(this.vnode,this.cursorIndex),!1;const s=e.textContent,n=e.parentNode,i=n.parentNode,a=i.parentNode;if(!t.isCollapsed||n.getAttribute("data-set-richType")!=="richInput")return!1;if(s&&s.length===1&&i!==a.childNodes[0]&&(t.focusOffset!==0||s===this.VOID_KEY)){if(s===this.VOID_KEY){const l=i.previousSibling;if(l.children[0].classList.contains("at-input")&&l.children[0].children[0].textContent!==this.VOID_KEY)return this.rangeToInputTag(l.children[0]),!0;const o=l.previousSibling;a.removeChild(l),a.removeChild(i);const c=o.childNodes[0],h=c.childNodes[0];h.textContent===this.VOID_KEY&&o===a.lastChild&&c.appendChild(document.createElement("br")),this.restCursorPos(h,h.textContent.length)}else{n.innerHTML=i===a.lastChild?`${this.VOID_KEY}<br>`:this.VOID_KEY,n.setAttribute("data-set-empty","true");const l=n.childNodes[0];this.restCursorPos(l,1)}return!0}else if(t.focusOffset===0){const l=n.parentNode,o=l==null?void 0:l.previousSibling;return!o||o.getAttribute("data-set-richType")!=="chatTag"?!1:o.children[0].classList.contains("at-input")&&o.children[0].children[0].textContent!==this.VOID_KEY?(this.rangeToInputTag(o.children[0]),!0):(this.delTag(o),!0)}}delTag(t){const e=t.previousSibling,s=t.nextSibling;t.parentNode.removeChild(t),this.markMerge(e,s)}gridMerge(t,e,s=!0){t.lastChild.getAttribute("data-set-richType")!=="richMark"&&t.appendChild(this.getGridElm(!0)),e.childNodes[0].getAttribute("data-set-richType")!=="richMark"&&e.insertBefore(this.getGridElm(!0),e.childNodes[0]);const n=t.lastChild.childNodes[0],i=n.childNodes[0];let a=i.textContent.length;Array.from(e.childNodes,o=>{t.appendChild(o.cloneNode(!0))}),e.childNodes.length>1&&n.childNodes[1]&&n.removeChild(n.childNodes[1]);const l=n.parentNode.nextSibling;if(l){const c=l.children[0].childNodes[0];c&&c.textContent!==this.VOID_KEY&&(n.childNodes[1]&&n.removeChild(n.childNodes[1]),i.textContent=(i.textContent+c.textContent).replace(new RegExp(this.VOID_KEY,"g"),()=>(a--,"")),i.parentElement.setAttribute("data-set-empty","false")),t.removeChild(l)}i.textContent===""&&(i.textContent=this.VOID_KEY,i.parentNode.setAttribute("data-set-empty","true"),a=1),this.richText.removeChild(e),s&&this.restCursorPos(i,a)}markMerge(t,e){const n=t.children[0].childNodes[0];let i=n.textContent.length;if(e){const o=e.children[0].childNodes[0];o&&o.textContent!==this.VOID_KEY&&(n.textContent=(n.textContent+o.textContent).replace(new RegExp(this.VOID_KEY,"g"),()=>(i--,"")),n.parentElement.setAttribute("data-set-empty","false")),e.parentNode.removeChild(e)}n.textContent===""&&(n.textContent=this.VOID_KEY,n.parentNode.setAttribute("data-set-empty","true"),i=1);const a=t.parentNode;n.textContent===this.VOID_KEY&&t===a.lastChild&&(n.parentNode.appendChild(document.createElement("br")),n.parentNode.setAttribute("data-set-empty","true"),i=1),this.restCursorPos(n,i)}setCallSpace(t){this.needCallSpace=t}getWrapNode(t,e=!1){if(t.nodeType===Node.TEXT_NODE)return t.parentNode.parentNode.parentNode;const s=t.getAttribute("data-set-richType");if(e&&s==="chatTag")return t.parentNode;switch(s){case"richInput":return t.parentNode.parentNode;case"richMark":return t.parentNode;case"richBox":return t}}getMarkNode(t,e=!1){if(t.nodeType===Node.TEXT_NODE)return t.parentNode?t.parentNode.parentNode:null;const s=t.getAttribute("data-set-richType");if(e&&s==="chatTag")return t;switch(s){case"richInput":return t.parentNode;case"richMark":return t}}getRichTextNodeIndex(t){const e=this.getMarkNode(t),s=e?e.parentNode:null;return!e||!s?{gridIndex:null,markIndex:null}:{gridIndex:Array.prototype.indexOf.call(this.richText.childNodes,s),markIndex:Array.prototype.indexOf.call(s.childNodes,e)}}setWrapNodeByMark(t){const e=document.createElement("p");return e.className="chat-grid-wrap",e.setAttribute("data-set-richType","richBox"),Array.from(t,s=>{e.appendChild(s)}),e}setRangeLastText(){const t=this.richText.childNodes[this.richText.childNodes.length-1],n=t.childNodes[t.childNodes.length-1].children[0].childNodes[0];this.restCursorPos(n,n.textContent===this.VOID_KEY?1:n.textContent.length),this.viewIntoPoint()}viewIntoPoint(){let t,e;const s=window.getSelection(),{focusNode:n,focusOffset:i}=s;