ИЛИ НЕ АНГУЛЯРОМ ЕДИНЫМ
ОС | Mac OS | >= Windows 8 | <= Windows 7 | Linux |
---|---|---|---|---|
Chrome | 😀 | 😀 | 😡 | ¯\_(ツ)_/¯ |
Firefox | 😀 | 😀 | 😀!!! | 😀!!! |
Edge | 😀 | |||
IE | 😀 | 😡 |
Twem❤️ji
Twem
<img src="https://.../2/72x72/2764.png" alt="❤️">
ji
@Directive({selector: '[emojiText]'})
class EmojiTextDirective {
constructor(ref: ElementRef) {}
@Input() set emojiText(input: string) {
const text = twemoji(input)
this.ref.nativeElement.innerHTML = text
}
}
<message-header [emojiText]="header"></message-header>
<message [emojiText]="text"></message>
ОС | Mac OS | >= Windows 8 | <= Windows 7 | Linux |
---|---|---|---|---|
Chrome | 😀 | 😀 | 😡 | ¯\_(ツ)_/¯ |
Firefox | 😀 | 😀 | 😀!!! | 😀!!! |
Edge | 😀 | |||
IE | 😀 | 😡 |
const ctx = canvas.getContext('2d');
// smile - red circle
const smile = '🔴';
// font-color - green
const greenRGB = '0,255,0';
ctx.textBaseline = 'top';
ctx.fillStyle = `rgb(${greenRGB})`;
ctx.font = '32px Arial';
ctx.fillText(smile, 0, 0);
const {data} = ctx.getImageData(16, 16, 1, 1);
const rgb = data.slice(0, 3)
const isGreen = rgb.toString() === greenRGB
const isTransparent = data[3] === 0
return !(isGreen || isTransparent);
const ctx = document.createElement('canvas').getContext('2d');
// smile - red circle
const smile = '🔴';
// font-color - green
const greenRGB = '0,255,0';
ctx.textBaseline = 'top';
ctx.fillStyle = `rgb(${greenRGB})`;
ctx.font = '32px Arial';
ctx.fillText(smile, 0, 0);
const {data} = ctx.getImageData(16, 16, 1, 1);
return !(data.slice(0, 3).toString() === greenRGB || data[3] === 0);
<span class="icon icon-🐹">🐹</span>
.icon {
background: url(sprite.png)
}
.icon-🐹 {
background-position-y: -240px
}
<div [emojiText]="Всем привет 😀!"></div>
<div>
Всем привет<span class="icon icon-😀">😀</span>!
</div>
@Directive({selector: '[emojiText]'})
class EmojiTextDirective {
@Input() set emojiText(input: string) {
const text = isColorEmojiSupports()
? emojiText
: emojiText.replace(EMOJI_REGEXP, ...);
}
}
/[\u2139-\u303d\uD83C-\uDBFF\uDC00-\uDFFF]/gu
U – значит Unicode
<div contenteditable>
Всем привет <img src="...">! А что вы тут ...
</div>
<textarea [(emojiTextArea)]="text"></textarea>
@Input() emojiTextArea: string
@Output() emojiTextAreaChange: EventEmitter<string>
@Directive({selector: 'textarea[emojiTextArea]'})
export class EmojiTextAreaDirective {
// при смене значения извне – обновляем textarea
@Input() set emojiTextArea(value: string) {
this.updateInput(value)
}
@Output() emojiTextAreaChange
= new EventEmitter<string>()
// получаем textarea
constructor(private ref: ElementRef) {}
// реакция на событие ввода
@HostListener('input')
onInput() {
const {value} = this.ref.nativeElement;
this.updateInput(value);
this.updateOutput(value);
}
// обновление textarea
private updateInput(value: string) {
this.ref.nativeElement.value
// 'Привет 😀!' -> 'Привет :smile:!'
= this.getCodesValue(value);
}
// обновление output
private updateOutput(value: string) {
this.emojiTextAreaChange.emit(
// 'Привет :smile:!' -> 'Привет 😀!'
this.getEmojiValue(value)
);
}
}