ngx-emoji
Version:
Components with Emoji for Angular 4+
3 lines (2 loc) • 34.2 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("rxjs/Subject"),require("rxjs/Subscription"),require("ngx-emoji/ngx-emoji.min.css")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common","rxjs/Subject","rxjs/Subscription","ngx-emoji/ngx-emoji.min.css"],t):t(e["ngx-emoji"]={},e.ng.core,e.ng.common,e.Rx,e.Rx)}(this,function(e,t,n,i,o){"use strict";var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}},a=function(){function e(){this.onEmojiPicked=new i.Subject}return e.getEmojis=function(){return null===this.emojis&&(this.emojis=require("ngx-emoji/emojis.json")),this.emojis},e.prototype.setActiveComponent=function(e){this.activeComponent=e},e.prototype.isActiveComponent=function(e){return e===this.activeComponent},e.loadEmoji=function(e){var t=this.getEmojiBundle(e);null===t||this.isCssBundleLoaded(t)||this.loadCssBundle(t)},e.getEmojiBundle=function(t){try{for(var n=r(e.getEmojis()),i=n.next();!i.done;i=n.next()){var o=i.value;if(o.unified==t)return o.bundle}}catch(l){a={error:l}}finally{try{i&&!i.done&&(s=n["return"])&&s.call(n)}finally{if(a)throw a.error}}return null;var a,s},e.loadCssBundle=function(e){if(!this.isCssBundleLoaded(e)){var t="ngx-emoji-bundle-"+e,n=document.getElementsByTagName("head")[0],i=document.createElement("link");i.id=t,i.rel="stylesheet",i.type="text/css",i.href=v.getEmojiBundlesPath()+"ngx-emoji-b"+e+".min.css",i.media="all",n.appendChild(i)}},e.isCssBundleLoaded=function(e){return!!document.getElementById("ngx-emoji-bundle-"+e)},e.prototype.recentPush=function(e){var t=this.getRecent();t.indexOf(e)>-1||(t=[e].concat(t).slice(0,v.getRecentMax()),window.localStorage.setItem("ngx-emoji-recent",t.join(":")))},e.prototype.getRecent=function(){var e=window.localStorage.getItem("ngx-emoji-recent");return e?e.split(":"):[]},e}();a.emojis=null,a.decorators=[{type:t.Injectable}],a.ctorParameters=function(){return[]};var s=function(){function e(){}return e.arrayOfNodeList=function(e){for(var t=[],n=0;n<e.length;n++)t.push(e.item(n));return t},e.isBlockNode=function(e){return e instanceof HTMLElement&&(e instanceof HTMLDivElement||"block"==window.getComputedStyle(e,"").display)},e.replaceAll=function(e,t,n){return t=t.replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),e.replace(new RegExp(t,"g"),n)},e.filterHtml=function(t,n,i){void 0===n&&(n=[]),void 0===i&&(i=!1),n=n.map(function(e){return e.toUpperCase()});var o=document.createElement("div");o.innerHTML=t,t="";var a=function(o){try{for(var s=r(e.arrayOfNodeList(o)),l=s.next();!l.done;l=s.next()){var c=l.value;c.nodeType==c.ELEMENT_NODE?"BR"==c.nodeName&&n.indexOf(c.nodeName)>-1?t+="<br>":n.indexOf(c.nodeName)>-1||i&&c.classList.contains("command")?(c instanceof HTMLAnchorElement?t+="<"+c.nodeName.toLowerCase()+' href="'+c.getAttribute("href")+'">':i&&c.classList.contains("command")?t+="<"+c.nodeName.toLowerCase()+' class="command">':t+="<"+c.nodeName.toLowerCase()+">",a(c.childNodes),t+="</"+c.nodeName.toLowerCase()+">"):a(c.childNodes):t+=c.textContent}}catch(d){u={error:d}}finally{try{l&&!l.done&&(m=s["return"])&&m.call(s)}finally{if(u)throw u.error}}var u,m};return a(o.childNodes),o.remove(),t},e}(),l=function(){function e(){}return e.createEmojiImg=function(e){return a.loadEmoji(e),'<img class="ngx-emoji ngx-emoji-'+e+'" aria-hidden="true" alt="'+this.emojiToSymbol(e)+'" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=">'},e.emojiToSymbol=function(e){if(0==(e=e.trim()).length)return"�";var t=e.split("-").map(function(e){return parseInt("0x"+e,16)});try{e=String.fromCodePoint.apply(String,t)}catch(n){console.warn("Convert emoji "+e+" error: "+n.message),e="�"}return e},e.dumpEmoji=function(e){for(var t=[],n=[],i=0;i<e.length;i++)t.push(e.codePointAt(i).toString(16).toUpperCase()),n.push(e.charCodeAt(i).toString(16).toUpperCase());console.log(e,t,n)},e.emojiFromSymbol=function(e){for(var t=[],n=0;n<e.length;n++)t.push(e.codePointAt(n).toString(16));return(t=t.filter(function(e){var t=parseInt(e,16);return!(t>=55296&&t<=57343)}).map(function(e){return"0000".substring(0,"0000".length-e.length)+e})).join("-").toUpperCase()},e.replaceSymbolsToEmojis=function(t){return t=t.replace(this.getEmojiRegex(),function(t){return e.createEmojiImg(e.emojiFromSymbol(t))}),t=s.replaceAll(t,"️","")},e.isEmojiNode=function(e){return e instanceof HTMLElement&&e.classList.contains("ngx-emoji")},e.emojiFromNode=function(e){if(!this.isEmojiNode(e))return null;for(var t=e.classList,n=null,i=0;i<t.length;i++)if("ngx-emoji-"==t.item(i).substr(0,10)){n=t.item(i).substr(10);break}return n},e.getEmojiRegex=function(){return new RegExp(["(?:\ud83c[\udde6-\uddff]){2}","[#-9]⃣","(?:[\ud83d\ud83c\ud83e][\udc00-\udfff]|[✊-✍☝⛹])\ud83c[\udffb-\udfff]","[\ud83d][\udc66-\udc69][][\ud83d][\udc66-\udc69][][\ud83d][\udc66-\udc67]([][\ud83d][\udc66-\udc67])?","[\ud83d][\udc68-\udc69][][❤][][\ud83d][\udc68-\udc69]","[\ud83d][\udc68-\udc69][][❤][][\ud83d][\udc8b][][\ud83d][\udc68-\udc69]","[\ud83d][\udc68-\udc69][][\ud83c-\ud83e][\udc00-\udfff]","[\ud83c-\ud83e][\udc00-\udfff][️]?[][♀-⚖][️]?","[\ud83d][\udd75][️][][♀][️]","[\ud83d][\udc68-\udc69][][✈]","[\ud83c-\ud83e][\udc68-\udc69][][\ud83c-\ud83e][\udc66][][\ud83c-\ud83e][\udc66]","[⛹][️][][♀-⚖][️]","[\ud83d\ud83c\ud83e][\udc00-\udfff]","[㊗㊙〽⭐⭕⬛➿➡Ⓜ▶◀☀✅↪↩]","[‼⁉™⌨☁☎☝☠☦☪☸☹☺♻♿✂✈]","[↔-↙]","[⬅-⬇]","[⤴-⤵]","[➕-➗]","[✉-❤]","[☢-☣]","[☮-☯]","[⌚-⌛]","[⏩-⏯]","[⏰-⏴]","[⏸-⏺]","[▪-▫]","[◻-◾]","[☂-☘]","[♈-♓]","[♠-♨]","[⚠-⛺]","[⚒-⚜]"].join("|"),"g")},e}(),c=function(){function e(e){this.nativeElement=e,this.onModified=new t.EventEmitter;var n=this.onModified;e.addEventListener("DOMSubtreeModified",function(e){n.emit(e)})}return Object.defineProperty(e.prototype,"contentEditable",{get:function(){return"true"==this.nativeElement.getAttribute("contenteditable")},set:function(e){e!=this.contentEditable&&this.nativeElement.setAttribute("contenteditable",e?"true":"false")},enumerable:!0,configurable:!0}),e.prototype.execCommand=function(e,t){var n=this.contentEditable;this.contentEditable=!0;var i=!1;switch(e){case"code":i=this.execCommandTag("code");break;case"pre":i=this.execCommandTag("pre");break;case"command":i=this.execCommandTag("span",[{name:"class",value:"command"}]);break;default:i=document.execCommand(e,!1,t)}return this.contentEditable=n,i},e.prototype.execCommandTag=function(e,t){void 0===t&&(t=[]),this.execCommand("superscript");var n=document.createElement("div");n.innerHTML=this.nativeElement.innerHTML;var i="",o=function(n){try{for(var a=r(s.arrayOfNodeList(n)),l=a.next();!l.done;l=a.next()){var c=l.value;if(c.nodeType==c.ELEMENT_NODE){var u=c.nodeName.toLowerCase();if("sup"==u){u=e,i+="<"+e;try{for(var m=r(t),d=m.next();!d.done;d=m.next()){var h=d.value;i+=" "+h.name+'="'+h.value+'"'}}catch(y){v={error:y}}finally{try{d&&!d.done&&(C=m["return"])&&C.call(m)}finally{if(v)throw v.error}}i+=">"}else{i+="<"+u;for(var p=0;p<c.attributes.length;p++){h=c.attributes.item(p);i+=" "+h.name+'="'+h.value+'"'}i+=">"}o(c.childNodes),i+="</"+u+">"}else i+=c.textContent}}catch(b){f={error:b}}finally{try{l&&!l.done&&(g=a["return"])&&g.call(a)}finally{if(f)throw f.error}}var f,g,v,C};return o(n.childNodes),n.remove(),this.nativeElement.innerHTML=i,!0},e}(),u=function(){function e(e){this.element=e}return e.prototype.formatText=function(e,t){switch(e){case d.Bold:this.element.execCommand("bold");break;case d.Italic:this.element.execCommand("italic");break;case d.Underline:this.element.execCommand("underline");break;case d.Pre:this.element.execCommand("pre");break;case d.Code:this.element.execCommand("code");break;case d.Strike:this.element.execCommand("strikeThrough");break;case d.Command:this.element.execCommand("command");break;case d.TextLink:case d.Url:this.element.execCommand("createLink",t)}},e.prototype.insertNewLine=function(){this.element.execCommand("insertParagraph")},e.prototype.insertEmoji=function(e){this.element.execCommand("insertHTML",l.createEmojiImg(e))},e}(),m=function(){function e(e,t){this.element=e,this.formatter=t,this.allowedTags=["b","i","u","strong","em","strike","code","pre","a"]}return e.prototype.format=function(e,t){var n=this,i=this.element.nativeElement,o=window.getSelection(),a=o.rangeCount?o.getRangeAt(0):null;Array.isArray(t)||(t=[]),t=t.map(function(e){return{offset:e.offset,length:e.length,type:n.normalizeEntityType(e.type),url:e.url}}).filter(function(e){return null!==e.type}),e=s.filterHtml(e),e=s.replaceAll(e," "," "),e=s.replaceAll(e," "," ");var c=(e=l.replaceSymbolsToEmojis(e)).split("\n");e="";try{for(var u=r(c),m=u.next();!m.done;m=u.next()){var h=m.value;0==h.length&&(h="<br>")," "==h&&(h=" "),e+="<div>"+h+"</div>"}}catch(j){p={error:j}}finally{try{m&&!m.done&&(f=u["return"])&&f.call(u)}finally{if(p)throw p.error}}this.element.nativeElement.innerHTML=e,0==this.element.nativeElement.childNodes.length&&this.element.nativeElement.appendChild(document.createTextNode(""));var p,f,g,v,C=!1,y=function(e){var t=document.createRange(),n=0,r=function(i){for(var o=0;o<i.length;o++){var a=i.item(o);if(l.isEmojiNode(a)){var c=l.emojiToSymbol(l.emojiFromNode(a)).length;n<=e.offset&&n+c>=e.offset&&t.setStartBefore(a),n<=e.offset+e.length&&n+c>=e.offset+e.length&&(t.setEndAfter(a),C=!0),n+=c}else{if(a.hasChildNodes())r(a.childNodes);else if("BR"!=a.nodeName){c=a.textContent.length;n<=e.offset&&n+c>=e.offset&&t.setStart(a,e.offset-n),n<=e.offset+e.length&&n+c>=e.offset+e.length&&(t.setEnd(a,e.offset+e.length-n),C=!0),n+=c}s.isBlockNode(a)&&(n++,e.offset+e.length==n&&(t.setEndAfter(a.lastChild),C=!0))}}};switch(r(i.childNodes),C||t.setEndAfter(i.lastChild),o.removeAllRanges(),o.addRange(t),e.type){case d.TextLink:b.formatter.formatText(d.TextLink,e.url);break;case d.Url:b.formatter.formatText(d.Url,t.cloneContents().textContent);break;default:b.formatter.formatText(e.type)}},b=this;try{for(var E=r(t),x=E.next();!x.done;x=E.next()){y(x.value)}}catch(S){g={error:S}}finally{try{x&&!x.done&&(v=E["return"])&&v.call(E)}finally{if(g)throw g.error}}o.removeAllRanges(),a&&o.addRange(a)},e.prototype.getEntities=function(){var e=[],t=function(n,i){try{for(var o=r(s.arrayOfNodeList(n)),a=o.next();!a.done;a=o.next()){var l=a.value;if(l.textContent.trim().length>0){var c=l.nodeName.toUpperCase();"B"!=c&&"STRONG"!=c||e.push({type:d.Bold,offset:i,length:l.textContent.length}),"I"!=c&&"EM"!=c||e.push({type:d.Italic,offset:i,length:l.textContent.length}),"U"==c&&e.push({type:d.Underline,offset:i,length:l.textContent.length}),"STRIKE"==c&&e.push({type:d.Strike,offset:i,length:l.textContent.length}),"CODE"==c&&e.push({type:d.Code,offset:i,length:l.textContent.length}),"PRE"==c&&e.push({type:d.Pre,offset:i,length:l.textContent.length}),"A"==c&&l instanceof HTMLAnchorElement&&l.getAttribute("href")==l.textContent&&e.push({type:d.Url,offset:i,length:l.textContent.length}),"A"==c&&l instanceof HTMLAnchorElement&&l.getAttribute("href")!=l.textContent&&e.push({type:d.TextLink,offset:i,length:l.textContent.length,url:l.textContent}),l instanceof HTMLElement&&l.classList.contains("command")&&e.push({type:d.Command,offset:i,length:l.textContent.length})}t(l.childNodes,i),i+=l.textContent.length}}catch(h){u={error:h}}finally{try{a&&!a.done&&(m=o["return"])&&m.call(o)}finally{if(u)throw u.error}}var u,m},n=document.createElement("div");return n.innerHTML=this.getMarkupHtml(this.element.nativeElement,!0),t(n.childNodes,0),n.remove(),e=e.map(function(e){return e.type==d.TextLink?e.type="text_link":e.type=d[e.type].toLowerCase(),e})},e.prototype.getText=function(){return s.filterHtml(this.getMarkupHtml())},e.prototype.getFullHtml=function(){var e=document.createElement("div");e.innerHTML=this.element.nativeElement.innerHTML;try{for(var t=r(s.arrayOfNodeList(e.getElementsByTagName("img"))),n=t.next();!n.done;n=t.next()){var i=n.value;if(i.classList.contains("ngx-emoji")){var o=document.createElement("i");o.className=i.className,o.setAttribute("aria-hidden","true"),i.parentElement.insertBefore(o,i),i.remove()}}}catch(u){a={error:u}}finally{try{n&&!n.done&&(l=t["return"])&&l.call(t)}finally{if(a)throw a.error}}var a,l,c=e.innerHTML;return e.remove(),c},e.prototype.getMarkupHtml=function(e,t){void 0===e&&(e=null),void 0===t&&(t=!1),e||(e=this.element.nativeElement);var n="",i=function(t){try{for(var o=r(s.arrayOfNodeList(t)),a=o.next();!a.done;a=o.next()){var c=a.value,u=s.isBlockNode(c);"PRE"==c.nodeName&&(u=!1),l.isEmojiNode(c)?n+=l.emojiToSymbol(l.emojiFromNode(c)):c.hasChildNodes()?(u||(c instanceof HTMLAnchorElement?n+="<"+c.nodeName.toLowerCase()+' href="'+c.getAttribute("href")+'">':c.classList.contains("command")?n+="<"+c.nodeName.toLowerCase()+' class="command">':n+="<"+c.nodeName.toLowerCase()+">"),i(c.childNodes),u||(n+="</"+c.nodeName.toLowerCase()+">")):n+=s.replaceAll(c.textContent,"\n",""),u&&!e.lastChild.isSameNode(c)&&(n+="\n"),"BR"==c.nodeName&&"BR"!=c.parentNode.firstChild.nodeName&&1!=c.parentNode.childNodes.length&&e.lastChild.lastChild&&!e.lastChild.lastChild.isSameNode(c)&&(n+="\n"),!u&&c.previousSibling&&c.previousSibling.textContent.length>0&&c.nextSibling&&s.isBlockNode(c.nextSibling)&&c.parentNode.isSameNode(e)&&(n+="\n"),l.isEmojiNode(c)&&c.nextElementSibling&&s.isBlockNode(c.nextElementSibling)&&0==c.nextSibling.textContent.length&&(n+="\n")}}catch(h){m={error:h}}finally{try{a&&!a.done&&(d=o["return"])&&d.call(o)}finally{if(m)throw m.error}}var m,d};return i(e.childNodes),n=s.replaceAll(n," "," "),n=s.replaceAll(n," "," "),s.filterHtml(n,this.allowedTags,t)},e.prototype.setFullHtml=function(e){this.element.nativeElement.innerHTML=s.filterHtml(e,this.allowedTags)},e.prototype.setMarkupHtml=function(e){e=e.split("\n").map(function(e,t){return t>0?"<div>"+e+"</div>":e}).join(""),this.element.nativeElement.innerHTML=s.filterHtml(e,this.allowedTags.concat("div"))},e.prototype.normalizeEntityType=function(e){switch("string"==typeof e&&(e=e.toLowerCase()),e){case"bold":case d.Bold:return d.Bold;case"italic":case d.Italic:return d.Italic;case"underline":case d.Underline:return d.Underline;case"strike":case d.Strike:return d.Strike;case"code":case d.Code:return d.Code;case"pre":case d.Pre:return d.Pre;case"bot_command":case"command":case d.Command:return d.Command;case"url":case d.Url:return d.Url;case"text_link":case d.TextLink:return d.TextLink;default:return null}},e.prototype.findCommands=function(){var e=window.getSelection();if(e.anchorNode){var t=e.anchorNode;if(t.parentElement.classList.contains("command"))t.textContent.trim().length,t.textContent.length;else for(var n=/(^|\s)(\/[a-z0-9]+)($|\s)/gi,i=void 0;null!==(i=n.exec(t.textContent));){var o=i.index;" "==i[0].charAt(0)&&o++;var r=i[2].length;" "==i[2].charAt(r-1)&&r--,n.lastIndex=n.lastIndex-(i[0].length-i[2].length);var a=document.createTextNode(t.textContent.substr(0,o));t.textContent=t.textContent.substr(o+r),t.parentNode.insertBefore(a,t);var s=document.createElement("span");s.classList.add("command"),s.textContent=i[2].trim(),t.parentNode.insertBefore(s,t)}}},e.prototype.findLinks=function(){},e}(),d={Bold:0,Italic:1,Underline:2,Strike:3,Code:4,Pre:5,Command:6,Url:7,TextLink:8};d[d.Bold]="Bold",d[d.Italic]="Italic",d[d.Underline]="Underline",d[d.Strike]="Strike",d[d.Code]="Code",d[d.Pre]="Pre",d[d.Command]="Command",d[d.Url]="Url",d[d.TextLink]="TextLink";var h=function(){return function(){this.htmlCounter=0,this.htmlValue="",this.fullHtmlCounter=0,this.fullHtmlValue="",this.textCounter=0,this.textValue="",this.entitiesCounter=0,this.entitiesValue=[],this.entitiesStringValue=""}}(),p=function(){function e(e,n){this._contenteditable=!1,this._enterOn={shift:!1,ctrl:!1},this.emojiServiceSubscription=new o.Subscription,this.preventCounter=0,this.preventSet=new h,this.preventGet=new h,this.contenteditableChange=new t.EventEmitter,this.enterOnChange=new t.EventEmitter,this.fullHtmlChange=new t.EventEmitter,this.htmlChange=new t.EventEmitter,this.textChange=new t.EventEmitter,this.entitiesChange=new t.EventEmitter,this.onEnter=new t.EventEmitter,this.onCommand=new t.EventEmitter,this.onLink=new t.EventEmitter;var i=this;n.setActiveComponent(this),this.emojiService=n;var r=this.emojiService.onEmojiPicked.subscribe(function(e){n.isActiveComponent(i)&&i.insertEmoji(e)});this.emojiServiceSubscription.add(r),this.element=new c(e.nativeElement),this.element.nativeElement.appendChild(document.createTextNode("")),this.formatter=new u(this.element),this.handler=new m(this.element,this.formatter);var a=document.createRange();a.setStart(this.element.nativeElement.firstChild,0),this.lastSelectionRange=a,this.element.onModified.subscribe(function(){i.preventCounter++,i.onElementModified()}),document.onselectionchange,undefined}return Object.defineProperty(e.prototype,"placeholder",{set:function(e){this.element.nativeElement.dataset.placeholder=e},enumerable:!0,configurable:!0}),e.prototype.ngOnDestroy=function(){this.emojiServiceSubscription.unsubscribe()},e.prototype.addEmojiService=function(e){e.setActiveComponent(this);var t=this,n=e.onEmojiPicked.subscribe(function(n){e.isActiveComponent(t)&&t.insertEmoji(n)});this.emojiServiceSubscription.add(n)},Object.defineProperty(e.prototype,"inputPicker",{set:function(e){this.emojiServiceSubscription.unsubscribe(),this.emojiServiceSubscription=new o.Subscription;var t=new a;t.setActiveComponent(this),this.emojiService=t,e.setEmojiService(t);var n=this,i=this.emojiService.onEmojiPicked.subscribe(function(e){t.isActiveComponent(n)&&n.insertEmoji(e)});this.emojiServiceSubscription.add(i)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"attrContenteditable",{set:function(e){this.contenteditable=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"contenteditable",{get:function(){return this._contenteditable},set:function(e){this._contenteditable=e,this.element.contentEditable=e,this.contenteditableChange.emit(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enterOn",{get:function(){return this._enterOn},set:function(e){this._enterOn=e,this.enterOnChange.emit(e)},enumerable:!0,configurable:!0}),e.prototype.enterKeyIsEnter=function(){return 0!=this.onEnter.observers.length&&(!this.enterKeyIsShiftEnter()&&!this.enterKeyIsCtrlEnter())},e.prototype.enterKeyIsCtrlEnter=function(){return 0!=this.onEnter.observers.length&&!!this.enterOn.ctrl},e.prototype.enterKeyIsShiftEnter=function(){return 0!=this.onEnter.observers.length&&!!this.enterOn.shift},Object.defineProperty(e.prototype,"fullHtml",{get:function(){return this.preventGet.fullHtmlCounter!=this.preventCounter&&(this.preventGet.fullHtmlValue=this.handler.getFullHtml(),this.preventGet.fullHtmlCounter=this.preventCounter),this.preventGet.fullHtmlValue},set:function(e){this.preventSet.htmlValue==e&&this.preventSet.htmlCounter==this.preventCounter||e==this.html||(this.handler.setFullHtml(e),this.preventSet.fullHtmlValue=e,this.preventSet.fullHtmlCounter=this.preventCounter)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"html",{get:function(){return this.preventGet.htmlCounter!=this.preventCounter&&(this.preventGet.htmlValue=this.handler.getMarkupHtml(),this.preventGet.htmlCounter=this.preventCounter),this.preventGet.htmlValue},set:function(e){this.preventSet.htmlCounter==this.preventCounter&&this.preventSet.htmlValue==e||e==this.html||(this.handler.setMarkupHtml(e),this.preventSet.htmlValue=e,this.preventSet.htmlCounter=this.preventCounter)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"text",{get:function(){return this.preventGet.textCounter!=this.preventCounter&&(this.preventGet.textValue=this.handler.getText(),this.preventGet.textCounter=this.preventCounter),this.preventGet.textValue},set:function(e){if((this.preventSet.textCounter!=this.preventCounter||this.preventSet.textValue!=e)&&e!=this.text){this.handler.format(e,this.entities);for(var t=document.createRange(),n=this.element.nativeElement.lastChild;n.hasChildNodes();)n=n.lastChild;t.setStart(n,n.textContent.length),this.lastSelectionRange=t,this.preventSet.textValue=e,this.preventSet.textCounter=this.preventCounter}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"entities",{get:function(){return this.preventGet.entitiesCounter!=this.preventCounter&&(this.preventGet.entitiesValue=this.handler.getEntities(),this.preventGet.entitiesCounter=this.preventCounter),this.preventGet.entitiesValue},set:function(e){var t=JSON.stringify(e);this.preventSet.entitiesCounter==this.preventCounter&&this.preventSet.entitiesStringValue==t||t==JSON.stringify(this.entities)||(this.handler.format(this.text,e),this.preventSet.entitiesStringValue=JSON.stringify(e),this.preventSet.entitiesCounter=this.preventCounter)},enumerable:!0,configurable:!0}),e.prototype.onKeydownEnter=function(e){this.contenteditable&&(e.preventDefault(),this.enterKeyIsEnter()?this.emitEnter():this.formatter.insertNewLine())},e.prototype.onKeydownControlEnter=function(e){this.contenteditable&&(e.preventDefault(),this.enterKeyIsCtrlEnter()?this.emitEnter():this.formatter.insertNewLine())},e.prototype.onKeydownShiftEnter=function(e){this.contenteditable&&(e.preventDefault(),this.enterKeyIsShiftEnter()?this.emitEnter():this.formatter.insertNewLine())},e.prototype.emitEnter=function(){this.textChange.emit(this.text),this.entitiesChange.emit(this.entities),this.fullHtmlChange.emit(this.fullHtml),this.htmlChange.emit(this.html),this.onEnter.emit()},e.prototype.onKeydown=function(e){e.ctrlKey&&66==e.keyCode&&(e.preventDefault(),this.formatter.formatText(d.Bold)),e.ctrlKey&&73==e.keyCode&&(e.preventDefault(),this.formatter.formatText(d.Italic)),e.ctrlKey&&85==e.keyCode&&(e.preventDefault(),this.formatter.formatText(d.Underline))},e.prototype.onFocus=function(){this.emojiService.setActiveComponent(this)},e.prototype.onFocusout=function(){var e=window.getSelection().getRangeAt(0);this.element.nativeElement.contains(e.startContainer)&&this.element.nativeElement.contains(e.endContainer)&&(this.lastSelectionRange=e)},e.prototype.onSelectionChange=function(){var e=window.getSelection();e.containsNode(this.element.nativeElement,!0)&&(this.lastSelectionRange=e.getRangeAt(0))},e.prototype.onPaste=function(e){e.preventDefault();var t="";e.clipboardData.types.indexOf("text/html")>-1?t=e.clipboardData.getData("text/html"):e.clipboardData.types.indexOf("text/plain")>-1&&(t=e.clipboardData.getData("text/plain")),t=t.split("\n").map(function(e,t){return 0==e.trim().length&&(e="<br>"),t>0?"<div>"+e+"</div>":e}).join("\n"),t=s.filterHtml(t,this.handler.allowedTags.concat(["div","br"])),t=l.replaceSymbolsToEmojis(t),this.element.execCommand("insertHTML",t)},e.prototype.onCopy=function(e){var t=window.getSelection().getRangeAt(0);if(!t.collapsed){e.preventDefault();var n=window.getSelection().getRangeAt(0).cloneContents(),i=document.createElement("div");i.appendChild(n),i.innerHTML=this.handler.getMarkupHtml(i).split("\n").map(function(e){return 0==e.trim().length&&(e="<br>"),"<div>"+e+"</div>"}).join("\n"),document.getElementsByTagName("body")[0].appendChild(i);var o=document.createRange();o.setStartBefore(i.firstChild),o.setEndAfter(i.lastChild);var r=window.getSelection();r.removeAllRanges(),r.addRange(o),this.element.execCommand("copy"),i.remove(),r.removeAllRanges(),r.addRange(t)}},e.prototype.onCut=function(e){this.onCopy(e),this.element.execCommand("delete")},e.prototype.onClick=function(e){if(this.contenteditable&&l.isEmojiNode(e.toElement)){var t=document.createRange();t.setStartBefore(e.toElement);var n=window.getSelection();n.removeAllRanges(),n.addRange(t)}e.toElement.classList.contains("command")&&this.onCommand.emit(e.toElement.textContent),e.toElement instanceof HTMLAnchorElement&&(e.preventDefault(),this.onLink.emit(e.toElement.getAttribute("href")))},e.prototype.onElementModified=function(){this.textChange.observers.length>0&&this.textChange.emit(this.text),this.entitiesChange.observers.length>0&&this.entitiesChange.emit(this.entities),this.fullHtmlChange.observers.length>0&&this.fullHtmlChange.emit(this.fullHtml),this.htmlChange.observers.length>0&&this.htmlChange.emit(this.html)},e.prototype.insertEmoji=function(e){if(this.contenteditable){var t=window.getSelection();t.removeAllRanges(),t.addRange(this.lastSelectionRange),this.formatter.insertEmoji(e),this.emojiService.recentPush(e)}},e}();p.decorators=[{type:t.Component,args:[{selector:"ngx-emoji",template:""}]}],p.ctorParameters=function(){return[{type:t.ElementRef},{type:a}]},p.propDecorators={placeholder:[{type:t.Input,args:["placeholder"]}],inputPicker:[{type:t.Input,args:["picker"]}],attrContenteditable:[{type:t.Input,args:["attr.contenteditable"]}],contenteditable:[{type:t.Input,args:["contenteditable"]}],contenteditableChange:[{type:t.Output,args:["contenteditableChange"]}],enterOn:[{type:t.Input,args:["enterOn"]}],enterOnChange:[{type:t.Output,args:["enterOnChange"]}],fullHtml:[{type:t.Input,args:["fullHtml"]}],fullHtmlChange:[{type:t.Output,args:["fullHtmlChange"]}],html:[{type:t.Input,args:["html"]}],htmlChange:[{type:t.Output,args:["htmlChange"]}],text:[{type:t.Input,args:["text"]}],textChange:[{type:t.Output,args:["textChange"]}],entities:[{type:t.Input,args:["entities"]}],entitiesChange:[{type:t.Output,args:["entitiesChange"]}],onEnter:[{type:t.Output,args:["enter"]}],onKeydownEnter:[{type:t.HostListener,args:["keydown.enter",["$event"]]}],onKeydownControlEnter:[{type:t.HostListener,args:["keydown.control.enter",["$event"]]}],onKeydownShiftEnter:[{type:t.HostListener,args:["keydown.shift.enter",["$event"]]}],onCommand:[{type:t.Output,args:["command"]}],onLink:[{type:t.Output,args:["link"]}],onKeydown:[{type:t.HostListener,args:["keydown",["$event"]]}],onFocus:[{type:t.HostListener,args:["focus"]}],onFocusout:[{type:t.HostListener,args:["focusout"]}],onPaste:[{type:t.HostListener,args:["paste",["$event"]]}],onCopy:[{type:t.HostListener,args:["copy",["$event"]]}],onCut:[{type:t.HostListener,args:["cut",["$event"]]}],onClick:[{type:t.HostListener,args:["click",["$event"]]}]};var f=function(){function e(e,t){this.emojiService=t,this.categories={Recent:[],"Smileys & People":null,"Animals & Nature":null,"Food & Drink":null,Objects:null,"Travel & Places":null,Activities:null,Symbols:null,Flags:null},this.currentCategory="Recent",this.nativeElement=e.nativeElement}return e.prototype.setEmojiService=function(e){this.emojiService=e},Object.defineProperty(e.prototype,"inputFor",{set:function(e){this.emojiService=new a,e.addEmojiService(this.emojiService)},enumerable:!0,configurable:!0}),e.prototype.emojiPicked=function(e){this.emojiService.onEmojiPicked.next(e)},e.prototype.selectCategory=function(e){this.currentCategory=e},e.prototype.loadCategory=function(e){var t,n,i=a.getEmojis().filter(function(t){return t.category==e});try{for(var o=r(i),s=o.next();!s.done;s=o.next()){var l=s.value;a.loadEmoji(l.unified)}}catch(c){t={error:c}}finally{try{s&&!s.done&&(n=o["return"])&&n.call(o)}finally{if(t)throw t.error}}this.categories[e]=i},e.prototype.getEmojis=function(){var e,t,n,i,o=this.currentCategory;if("Recent"==o){var s=[];try{for(var l=r(this.emojiService.getRecent()),c=l.next();!c.done;c=l.next()){var u=c.value;try{for(var m=r(a.getEmojis()),d=m.next();!d.done;d=m.next()){var h=d.value;if(h.unified==u){s.push(h),a.loadEmoji(h.unified);break}}}catch(p){n={error:p}}finally{try{d&&!d.done&&(i=m["return"])&&i.call(m)}finally{if(n)throw n.error}}}}catch(f){e={error:f}}finally{try{c&&!c.done&&(t=l["return"])&&t.call(l)}finally{if(e)throw e.error}}return s}return null==this.categories[o]&&this.loadCategory(o),this.categories[o]},e.prototype.getCategories=function(){return Object.keys(this.categories).map(function(e){return{name:e,"class":"ngx-emoji-cat-"+e.replace("&","").replace(" "," ").replace(" ","-").toLowerCase()}})},e}();f.decorators=[{type:t.Component,args:[{selector:"ngx-emoji-picker",template:'<div>\n <i *ngFor="let emoji of getEmojis()"\n [class]="\'ngx-emoji ngx-emoji-\' + emoji.unified"\n aria-hidden="true"\n unselectable="on"\n onselectstart="return false;"\n (click)="emojiPicked(emoji.unified)"\n ></i>\n</div>\n<hr>\n<i *ngFor="let category of getCategories()"\n [class]="\'ngx-emoji-cat \' + category.class"\n unselectable="on"\n onselectstart="return false;"\n onmousedown="return false;"\n aria-hidden="true"\n (click)="selectCategory(category.name)"\n></i>\n'}]}],f.ctorParameters=function(){return[{type:t.ElementRef},{type:a}]},f.propDecorators={inputFor:[{type:t.Input,args:["for"]}]};var g=function(){function e(e){this.elRef=e,this.showPicker=!1,this.contenteditableChange=new t.EventEmitter,this.enterOnChange=new t.EventEmitter,this.fullHtmlChange=new t.EventEmitter,this.htmlChange=new t.EventEmitter,this.textChange=new t.EventEmitter,this.entitiesChange=new t.EventEmitter,this.onEnter=new t.EventEmitter,this.onCommand=new t.EventEmitter,this.onLink=new t.EventEmitter}return e.prototype.ngOnInit=function(){var e=this;this.emojiComponent.contenteditableChange.subscribe(function(t){return e.contenteditableChange.emit(t)}),this.emojiComponent.enterOnChange.subscribe(function(t){return e.enterOnChange.emit(t)}),this.emojiComponent.fullHtmlChange.subscribe(function(t){return e.fullHtmlChange.emit(t)}),this.emojiComponent.htmlChange.subscribe(function(t){return e.htmlChange.emit(t)}),this.emojiComponent.textChange.subscribe(function(t){return e.textChange.emit(t)}),this.emojiComponent.entitiesChange.subscribe(function(t){return e.entitiesChange.emit(t)}),this.emojiComponent.onEnter.subscribe(function(){return e.onEnter.emit()}),this.emojiComponent.onCommand.subscribe(function(t){return e.onCommand.emit(t)}),this.emojiComponent.onLink.subscribe(function(t){return e.onLink.emit(t)})},e.prototype.togglePicker=function(){this.showPicker=!this.showPicker},Object.defineProperty(e.prototype,"pickerComponent",{set:function(e){if(e){var t=this;e.nativeElement.addEventListener("mouseleave",function(){var n=window.setTimeout(function(){t.showPicker=!1},1e3);e.nativeElement.addEventListener("mouseenter",function(){window.clearTimeout(n)},{once:!0})})}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"placeholder",{set:function(e){this.emojiComponent.placeholder=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"attrContenteditable",{set:function(e){this.contenteditable=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"contenteditable",{get:function(){return this.emojiComponent.contenteditable},set:function(e){this.emojiComponent.contenteditable=e,this.elRef.nativeElement.setAttribute("contenteditable",!1)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enterOn",{get:function(){return this.emojiComponent.enterOn},set:function(e){this.emojiComponent.enterOn=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fullHtml",{get:function(){return this.emojiComponent.fullHtml},set:function(e){this.emojiComponent.fullHtml=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"html",{get:function(){return this.emojiComponent.html},set:function(e){this.emojiComponent.html=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"text",{get:function(){return this.emojiComponent.text},set:function(e){this.emojiComponent.text=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"entities",{get:function(){return this.emojiComponent.entities},set:function(e){this.emojiComponent.entities=e},enumerable:!0,configurable:!0}),e}();g.decorators=[{type:t.Component,args:[{selector:"ngx-emoji-with-picker",template:'<ngx-emoji-picker *ngIf="showPicker" [for]="emoji" #picker></ngx-emoji-picker>\n<ngx-emoji #emoji></ngx-emoji>\n<img *ngIf="emoji.contenteditable"\n aria-hidden="true"\n src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="\n alt="Emoji picker"\n [class]="showPicker ? \'ngx-emoji-cat-smileys-people\' : \'ngx-emoji-cat-smileys-people-inactive\'"\n (click)="togglePicker()">\n'}]}],g.ctorParameters=function(){return[{type:t.ElementRef}]},g.propDecorators={emojiComponent:[{type:t.ViewChild,args:["emoji"]}],pickerComponent:[{type:t.ViewChild,args:["picker"]}],placeholder:[{type:t.Input,args:["placeholder"]}],attrContenteditable:[{type:t.Input,args:["attr.contenteditable"]}],contenteditable:[{type:t.Input,args:["contenteditable"]}],contenteditableChange:[{type:t.Output,args:["contenteditableChange"]}],enterOn:[{type:t.Input,args:["enterOn"]}],enterOnChange:[{type:t.Output,args:["enterOnChange"]}],fullHtml:[{type:t.Input,args:["fullHtml"]}],fullHtmlChange:[{type:t.Output,args:["fullHtmlChange"]}],html:[{type:t.Input,args:["html"]}],htmlChange:[{type:t.Output,args:["htmlChange"]}],text:[{type:t.Input,args:["text"]}],textChange:[{type:t.Output,args:["textChange"]}],entities:[{type:t.Input,args:["entities"]}],entitiesChange:[{type:t.Output,args:["entitiesChange"]}],onEnter:[{type:t.Output,args:["enter"]}],onCommand:[{type:t.Output,args:["command"]}],onLink:[{type:t.Output,args:["link"]}]};var v=function(){function e(){}return e.setEmojiBundlesPath=function(t){e.emojiBundlesPath=t},e.getEmojiBundlesPath=function(){return e.emojiBundlesPath},e.setRecentMax=function(t){e.recentMax=t},e.getRecentMax=function(){return e.recentMax},e}();v.emojiBundlesPath="https://cdn.rawgit.com/arswarog/ngx-emoji/build/ngx-emoji-assets/",v.recentMax=20,v.decorators=[{type:t.NgModule,args:[{imports:[n.CommonModule],declarations:[f,p,g],providers:[a],exports:[f,p,g]}]}],v.ctorParameters=function(){return[]},e.NgxEmojiModule=v,e.NgxEmojiPickerComponent=f,e.NgxEmojiComponent=p,e.NgxEmojiEntityType=d,e.NgxEmojiWithPickerComponent=g,e.NgxEmojiService=a,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-emoji.umd.min.js.map