|
| 1 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 2 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 3 | +}; |
| 4 | +define(["require", "exports", "./Data", "./Util"], function (require, exports, Data_1, Util_1) { |
| 5 | + "use strict"; |
| 6 | + Object.defineProperty(exports, "__esModule", { value: true }); |
| 7 | + exports.TwemojiParser = void 0; |
| 8 | + Data_1 = __importDefault(Data_1); |
| 9 | + Util_1 = __importDefault(Util_1); |
| 10 | + class TwemojiParser { |
| 11 | + constructor(options = {}) { |
| 12 | + this.emojiDataPath = window.WCF_PATH + 'js/Hanashi/Twemoji/twemoji.json'; |
| 13 | + this.emojiSize = 24; |
| 14 | + this.selector = undefined; |
| 15 | + if (options.selector != null) { |
| 16 | + this.selector = options.selector; |
| 17 | + } |
| 18 | + if (options.dataPath != null) { |
| 19 | + this.emojiDataPath = options.dataPath; |
| 20 | + } |
| 21 | + if (options.size != null) { |
| 22 | + this.emojiSize = options.size; |
| 23 | + } |
| 24 | + if (this.selector == null) { |
| 25 | + console.error('no selector configured'); |
| 26 | + } |
| 27 | + const twemojiData = Data_1.default.getTwemojiData(); |
| 28 | + if (twemojiData.emo != null) { |
| 29 | + this.emojis = twemojiData.emo; |
| 30 | + } |
| 31 | + this.parse(); |
| 32 | + } |
| 33 | + parse(selector = undefined) { |
| 34 | + if (this.emojis == null) { |
| 35 | + return; |
| 36 | + } |
| 37 | + if (selector == null) { |
| 38 | + selector = this.selector; |
| 39 | + } |
| 40 | + if (selector == null) { |
| 41 | + console.error('no selector configured'); |
| 42 | + return; |
| 43 | + } |
| 44 | + const nodeList = document.querySelectorAll(selector); |
| 45 | + for (let [_, emoji] of Object.entries(this.emojis)) { |
| 46 | + const native = Util_1.default.getEmojiByUnifier(emoji.u); |
| 47 | + if (!native) { |
| 48 | + continue; |
| 49 | + } |
| 50 | + const x = emoji.c[0] * (this.emojiSize * -1); |
| 51 | + const y = emoji.c[1] * (this.emojiSize * -1); |
| 52 | + const icon = '<span class="haTwemojiIcon' + this.emojiSize + '" style="background-position: ' + x + 'px ' + y + 'px"></span>'; |
| 53 | + nodeList.forEach(node => { |
| 54 | + if (!node.innerHTML.includes(native)) { |
| 55 | + return; |
| 56 | + } |
| 57 | + node.innerHTML = node.innerHTML.replace(new RegExp(native, 'g'), icon); |
| 58 | + }); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + exports.TwemojiParser = TwemojiParser; |
| 63 | + exports.default = TwemojiParser; |
| 64 | +}); |
0 commit comments