mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-12-24 14:07:03 +01:00
21 lines
111 KiB
JavaScript
21 lines
111 KiB
JavaScript
|
"use strict";;(function(){var root=this;var previous_emoji=root.EmojiConvertor;var emoji=function(){var self=this;self.img_set='apple';self.img_sets={'apple':{'path':'/emoji-data/img-apple-64/','sheet':'/emoji-data/sheet_apple_64.png','mask':1},'google':{'path':'/emoji-data/img-google-64/','sheet':'/emoji-data/sheet_google_64.png','mask':2},'twitter':{'path':'/emoji-data/img-twitter-64/','sheet':'/emoji-data/sheet_twitter_64.png','mask':4},'emojione':{'path':'/emoji-data/img-emojione-64/','sheet':'/emoji-data/sheet_emojione_64.png','mask':8},'facebook':{'path':'/emoji-data/img-facebook-64/','sheet':'/emoji-data/sheet_facebook_64.png','mask':16},'messenger':{'path':'/emoji-data/img-messenger-64/','sheet':'/emoji-data/sheet_messenger_64.png','mask':32},};self.use_css_imgs=false;self.colons_mode=false;self.text_mode=false;self.include_title=false;self.include_text=false;self.allow_native=true;self.use_sheet=false;self.avoid_ms_emoji=true;self.allow_caps=false;self.img_suffix='';self.inits={};self.map={};self.init_env();return self;}
|
||
|
emoji.prototype.noConflict=function(){root.EmojiConvertor=previous_emoji;return emoji;}
|
||
|
emoji.prototype.replace_emoticons=function(str){var self=this;var colonized=self.replace_emoticons_with_colons(str);return self.replace_colons(colonized);};emoji.prototype.replace_emoticons_with_colons=function(str){var self=this;self.init_emoticons();var _prev_offset=0;var emoticons_with_parens=[];var str_replaced=str.replace(self.rx_emoticons,function(m,$1,emoticon,offset){var prev_offset=_prev_offset;_prev_offset=offset+m.length;var has_open_paren=emoticon.indexOf('(')!==-1;var has_close_paren=emoticon.indexOf(')')!==-1;if((has_open_paren||has_close_paren)&&emoticons_with_parens.indexOf(emoticon)==-1){emoticons_with_parens.push(emoticon);}
|
||
|
if(has_close_paren&&!has_open_paren){var piece=str.substring(prev_offset,offset);if(piece.indexOf('(')!==-1&&piece.indexOf(')')===-1)return m;}
|
||
|
if(m==='\n8)'){var before_match=str.substring(0,offset);if(/\n?(6\)|7\))/.test(before_match))return m;}
|
||
|
var val=self.data[self.map.emoticons[emoticon]][3][0];return val?$1+':'+val+':':m;});if(emoticons_with_parens.length){var escaped_emoticons=emoticons_with_parens.map(self.escape_rx);var parenthetical_rx=new RegExp('(\\(.+)('+escaped_emoticons.join('|')+')(.+\\))','g');str_replaced=str_replaced.replace(parenthetical_rx,function(m,$1,emoticon,$2){var val=self.data[self.map.emoticons[emoticon]][3][0];return val?$1+':'+val+':'+$2:m;});}
|
||
|
return str_replaced;};emoji.prototype.replace_colons=function(str,custom,custom_url){var self=this;self.init_colons();return str.replace(self.rx_colons,function(m){var idx=m.substr(1,m.length-2);if(self.allow_caps)idx=idx.toLowerCase();if(idx.indexOf('::skin-tone-')>-1){var skin_tone=idx.substr(-1,1);var skin_idx='skin-tone-'+skin_tone;var skin_val=self.map.colons[skin_idx];idx=idx.substr(0,idx.length-13);var val=self.map.colons[idx];if(val){return self.replacement(val,idx,':',{'idx':skin_val,'actual':skin_idx,'wrapper':':'});}else{return':'+idx+':'+self.replacement(skin_val,skin_idx,':');}}else if(custom){var style='background: url('+custom_url+'); background-size: contain; background-repeat: no-repeat; background-position: center;';return'<span class="emoji-outer emoji-sizer"><span class="emoji-inner" style="'+style+'">';}else{var val=self.map.colons[idx];return val?self.replacement(val,idx,':'):m;}});};emoji.prototype.replace_unified=function(str){var self=this;self.init_unified();return str.replace(self.rx_unified,function(m,p1,p2){var val=self.map.unified[p1];if(!val)return m;var idx=null;if(p2=='\uD83C\uDFFB')idx='1f3fb';if(p2=='\uD83C\uDFFC')idx='1f3fc';if(p2=='\uD83C\uDFFD')idx='1f3fd';if(p2=='\uD83C\uDFFE')idx='1f3fe';if(p2=='\uD83C\uDFFF')idx='1f3ff';if(idx){return self.replacement(val,null,null,{idx:idx,actual:p2,wrapper:''});}
|
||
|
return self.replacement(val);});};emoji.prototype.addAliases=function(map){var self=this;self.init_colons();for(var i in map){self.map.colons[i]=map[i];}};emoji.prototype.removeAliases=function(list){var self=this;for(var i=0;i<list.length;i++){var alias=list[i];delete self.map.colons[alias];finder_block:{for(var j in self.data){for(var k=0;k<self.data[j][3].length;k++){if(alias==self.data[j][3][k]){self.map.colons[alias]=j;break finder_block;}}}}}};emoji.prototype.replacement=function(idx,actual,wrapper,variation){var self=this;var full_idx=idx;var extra='';var variation_idx=0;if(typeof variation==='object'){extra=self.replacement(variation.idx,variation.actual,variation.wrapper);variation_idx=idx+'-'+variation.idx;}
|
||
|
var img_set=self.img_set;if((!self.use_sheet||!self.supports_css)&&!(self.data[idx][6]&self.img_sets[self.img_set].mask)){img_set='apple';}
|
||
|
wrapper=wrapper||'';if(self.colons_mode)return':'+self.data[idx][3][0]+':'+extra;var text_name=(actual)?wrapper+actual+wrapper:self.data[idx][8]||wrapper+self.data[idx][3][0]+wrapper;if(self.text_mode)return text_name+extra;self.init_env();if(self.replace_mode=='unified'&&self.allow_native&&self.data[idx][0][0])return self.data[idx][0][0]+extra;if(self.replace_mode=='softbank'&&self.allow_native&&self.data[idx][1])return self.data[idx][1]+extra;if(self.replace_mode=='google'&&self.allow_native&&self.data[idx][2])return self.data[idx][2]+extra;var img=self.data[idx][7]||self.img_sets[img_set].path+idx+'.png'+self.img_suffix;var title=self.include_title?' title="'+(actual||self.data[idx][3][0])+'"':'';var text=self.include_text?wrapper+(actual||self.data[idx][3][0])+wrapper:'';var px=self.data[idx][4];var py=self.data[idx][5];if(variation_idx&&self.variations_data[variation_idx]&&self.variations_data[variation_idx][2]&&!self.data[idx][7]){if(self.variations_data[variation_idx][2]&self.img_sets[self.img_set].mask){img=self.img_sets[self.img_set].path+variation_idx+'.png';px=self.variations_data[variation_idx][0];py=self.variations_data[variation_idx][1];extra='';full_idx=variation_idx;if(self.include_text&&variation&&variation.actual&&variation.wrapper){text+=variation.wrapper+variation.actual+variation.wrapper;}}}
|
||
|
if(self.supports_css){if(self.use_sheet&&px!=null&&py!=null){var mul=100 /(self.sheet_size-1);var style='background: url('+self.img_sets[img_set].sheet+');background-position:'+(mul*px)+'% '+(mul*py)+'%;background-size:'+self.sheet_size+'00%';return'<span class="emoji-outer emoji-sizer"><span class="emoji-inner" style="'+style+'"'+title+' data-codepoints="'+full_idx+'">'+text+'</span></span>'+extra;}else if(self.use_css_imgs){return'<span class="emoji emoji-'+idx+'"'+title+' data-codepoints="'+full_idx+'">'+text+'</span>'+extra;}else{return'<span class="emoji emoji-sizer" style="background-image:url('+img+')"'+title+' data-codepoints="'+full_idx+'">'+text+'</span>'+extra;}}
|
||
|
return'<img src="'+img+'" class="emoji" data-codepoints="'+full_idx+'" '+title+'/>'+extra;};emoji.prototype.init_emoticons=function(){var self=this;if(self.inits.emoticons)return;self.init_colons();self.inits.emoticons=1;var a=[];self.map.emoticons={};for(var i in self.emoticons_data){var emoticon=i.replace(/\&/g,'&').replace(/\</g,'<').replace(/\>/g,'>');if(!self.map.colons[self.emoticons_data[i]])continue;self.map.emoticons[emoticon]=self.map.colons[self.emoticons_data[i]];a.push(self.escape_rx(emoticon));}
|
||
|
self.rx_emoticons=new RegExp(('(^|\\s)('+a.join('|')+')(?=$|[\\s|\\?\\.,!])'),'g');};emoji.prototype.init_colons=function(){var self=this;if(self.inits.colons)return;self.inits.colons=1;self.rx_colons=new RegExp('\:[a-zA-Z0-9-_+]+\:(\:skin-tone-[2-6]\:)?','g');self.map.colons={};for(var i in self.data){for(var j=0;j<self.data[i][3].length;j++){self.map.colons[self.data[i][3][j]]=i;}}};emoji.prototype.init_unified=function(){var self=this;if(self.inits.unified)return;self.inits.unified=1;var a=[];self.map.unified={};for(var i in self.data){for(var j=0;j<self.data[i][0].length;j++){a.push(self.data[i][0][j].replace('*','\\*'));self.map.unified[self.data[i][0][j]]=i;}}
|
||
|
a=a.sort(function(a,b){return b.length-a.length;});self.rx_unified=new RegExp('('+a.join('|')+')(\uD83C[\uDFFB-\uDFFF])?',"g");};emoji.prototype.init_env=function(){var self=this;if(self.inits.env)return;self.inits.env=1;self.replace_mode='img';self.supports_css=false;if(typeof(navigator)!=='undefined'){var ua=navigator.userAgent;if(window.getComputedStyle){try{var st=window.getComputedStyle(document.body);if(st['background-size']||st['backgroundSize']){self.supports_css=true;}}catch(e){if(ua.match(/Firefox/i)){self.supports_css=true;}}}
|
||
|
if(ua.match(/(iPhone|iPod|iPad|iPhone\s+Simulator)/i)){if(ua.match(/OS\s+[12345]/i)){self.replace_mode='softbank';return;}
|
||
|
if(ua.match(/OS\s+[6789]/i)){self.replace_mode='unified';return;}}
|
||
|
if(ua.match(/Mac OS X 10[._ ](?:[789]|1\d)/i)){self.replace_mode='unified';return;}
|
||
|
if(!self.avoid_ms_emoji){if(ua.match(/Windows NT 6.[1-9]/i)||ua.match(/Windows NT 10.[0-9]/i)){if(!ua.match(/Chrome/i)&&!ua.match(/MSIE 8/i)){self.replace_mode='unified';return;}}}}
|
||
|
if(false&&ua.match(/Android/i)){self.replace_mode='google';return;}
|
||
|
if(self.supports_css){self.replace_mode='css';}};emoji.prototype.escape_rx=function(text){return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");};emoji.prototype.sheet_size=41;emoji.prototype.data={"00a9":[["\u00A9\uFE0F","\u00A9"],"\uE24E","\uDBBA\uDF29",["copyright"],0,0,11,0],"00ae":[["\u00AE\uFE0F","\u00AE"],"\uE24F","\uDBBA\uDF2D",["registered"],0,1,11,0],"203c":[["\u203C\uFE0F","\u203C"],"","\uDBBA\uDF06",["bangbang"],0,2,15,0],"2049":[["\u2049\uFE0F","\u2049"],"","\uDBBA\uDF05",["interrobang"],0,3,15,0],"2122":[["\u2122\uFE0F","\u2122"],"\uE537","\uDBBA\uDF2A",["tm"],0,4,11,0],"2139":[["\u2139\uFE0F","\u2139"],"","\uDBBA\uDF47",["information_source"],0,5,15,0],"2194":[["\u2194\uFE0F","\u2194"],"","\uDBBA\uDEF6",["left_right_arrow"],0,6,15,0],"2195":[["\u2195\uFE0F","\u2195"],"","\uDBBA\uDEF7",["arrow_up_down"],0,7,15,0],"2196":[["\u2196\uFE0F","\u2196"],"\uE237","\uDBBA\uDEF2",["arrow_upper_left"],0,8,15,0],"2197":[["\u2197\uFE0F","\u2197"],"\uE236","\uDBBA\uDEF0",["arrow_upper_right"],0,9,15,0],"2198":[["\u2198\uFE0F","\u2198"],"\uE238","\uDBBA\uDEF1",["arrow_lower_right"],0,10,15,0],"2199":[["\u2199\uFE0F","\u2199"],"\uE239","\uDBBA\uDEF3",["arrow_lower_left"],0,11,15,0],"21a9":[["\u21A9\uFE0F","\u21A9"],"","\uDBBA\uDF83",["leftwards_arrow_with_hook"],0,12,15,0],"21aa":[["\u21AA\uFE0F","\u21AA"],"","\uDBBA\uDF88",["arrow_right_hook"],0,13,15,0],"231a":[["\u231A\uFE0F","\u231A"],"","\uDBB8\uDC1D",["watch"],0,14,15,0],"231b":[["\u231B\uFE0F","\u231B"],"","\uDBB8\uDC1C",["hourglass"],0,15,15,0],"2328":[["\u2328\uFE0F","\u2328"],"","",["keyboard"],0,16,15,0],"23cf":[["\u23CF"],"","",["eject"],0,17,2,0],"23e9":[["\u23E9"],"\uE23C","\uDBBA\uDEFE",["fast_forward"],0,18,15,0],"23ea":[["\u23EA"],"\uE23D","\uDBBA\uDEFF",["rewind"],0,19,15,0],"23eb":[["\u23EB"],"","\uDBBA\uDF03",["arrow_double_up"],0,20,15,0],"23ec":[["\u23EC"],"","\uDBBA\uDF02",["arrow_double_down"],0,21,15,0],"23ed":[["\u23ED"],"","",["black_right_pointing_double_triangle_with_vertical_bar"],0,22,15,0],"23ee":[["\u23EE"],"","",["black_left_pointing_double_triangle_with_vertical_bar"],0,23,15,0],"23ef":[["\u23EF"],"","",["black_right_pointing_triangle_with_double_vertical_bar"],0,24,15,0],"23f0":[["\u23F0"],"\uE02D","\uDBB8\uDC2A",["alarm_clock"],0,25,15,0],"23f1":[["\u23F1"],"","",["stopwatch"],0,26,15,0],"23f2":[["\u23F2"],"","",["timer_clock"],0,27,15,0],"23f3":[["\u23F3"],"","\uDBB8\uDC1B",["hourglass_flowing_sand"],0,28,15,0],"23f8":[["\u23F8"],"","",["double_vertical_bar"],0,29,15,0],"23f9":[["\u23F9"],"","",["black_square_for_stop"],0,30,15,0],"23fa":[["\u23FA"],"","",["black_circle_for_record"],0,31,15,0],"24c2":[["\u24C2\uFE0F","\u24C2"],"\uE434","\uDBB9\uDFE1",["m"],0,32,15,0],"25aa":[["\u25AA\uFE0F","\u25AA"],"\uE21A","\uDBBA\uDF6E",["black_small_square"],0,33,15,0],"25ab":[["\u25AB\uFE0F","\u25AB"],"\uE21B","\uDBBA\uDF6D",["white_small_square"],0,34,15,0],"25b6":[["\u25B6\uFE0F","\u25B6"],"\uE23A","\uDBBA\uDEFC",["arrow_forward"],0,35,15,0],"25c0":[["\u25C0\uFE0F","\u25C0"],"\uE23B","\uDBBA\uDEFD",["arrow_backward"],0,36,15,0],"25fb":[["\u25FB\uFE0F","\u25FB"],"\uE21B","\uDBBA\uDF71",["white_medium_square"],0,37,15,0],"25fc":[["\u25FC\uFE0F","\u25FC"],"\uE21A","\uDBBA\uDF72",["black_medium_square"],0,38,15,0],"25fd":[["\u25FD\uFE0F","\u25FD"],"\uE21B","\uDBBA\uDF6F",["white_medium_small_square"],0,39,15,0],"25fe":[["\u25FE\uFE0F","\u25FE"],"\uE21A","\uDBBA\uDF70",["black_medium_small_square"],0,40,15,0],"2600":[["\u2600\uFE0F","\u2600"],"\uE04A","\uDBB8\uDC00",["sunny"],1,0,15,0],"2601":[["\u2601\uFE0F","\u2601"],"\uE049","\uDBB8\uDC01",["cloud"],1,1,15,0],"2602":[["\u2602\uFE0F","\u2602"],"","",["umbrella"],1,2,15,0],"2603":[["\u2603\uFE0F","\u2603"],"","",["snowman"],1,3,15,0],"2604":[["\u2604\uFE0F","\u2604"],"","",["comet"],1,4,15,0],"260e":[["\u260E\uFE0F","\u260E"],"\uE009","\uDBB9\uDD23",["phone","telephone"],1,5,15,0],"2611":[["\u2611\uFE0F","\u2611"],"","\uDBBA\uDF8B",["ballot_box_with_check"],1,6,15,0],"2614":[["\u2614\uFE0F","\u2614"],"\uE04B","\uDBB8\uDC02",["umbrella_with_rain_drops"],1,7,15,0],"2615":[["\u2615\uFE0F","\u2615"],
|
||
|
exports.EmojiConvertor=emoji;}else if(typeof define==='function'&&define.amd){define(function(){return emoji;})}else{root.EmojiConvertor=emoji;}}).call(function(){return this||(typeof window!=='undefined'?window:global);}());
|