Skip to content

Commit c561503

Browse files
committed
rebuild
1 parent 7592d4f commit c561503

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

dist/index.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
"use strict";
2-
var __importDefault = (this && this.__importDefault) || function (mod) {
3-
return (mod && mod.__esModule) ? mod : { "default": mod };
4-
};
5-
var _a;
6-
Object.defineProperty(exports, "__esModule", { value: true });
7-
exports.LiveTranslatorPlugin = void 0;
8-
const throttle_1 = __importDefault(require("lodash/throttle"));
1+
import throttle from 'lodash/throttle';
92
const css = `
103
.live-translator-enable-button {
114
position: fixed !important;
@@ -65,6 +58,12 @@ const css = `
6558
}
6659
`;
6760
class ZeroWidthEncoder {
61+
static START = '\u200B';
62+
static ZERO = '\u200C';
63+
static ONE = '\u200D';
64+
static SPACE = '\u200E';
65+
static END = '\u200F';
66+
static PATTERN = `${this.START}[${this.ZERO}${this.ONE}${this.SPACE}]+${this.END}`;
6867
static encode(text) {
6968
const binary = text
7069
.split('')
@@ -106,14 +105,11 @@ class ZeroWidthEncoder {
106105
return text;
107106
}
108107
}
109-
_a = ZeroWidthEncoder;
110-
ZeroWidthEncoder.START = '\u200B';
111-
ZeroWidthEncoder.ZERO = '\u200C';
112-
ZeroWidthEncoder.ONE = '\u200D';
113-
ZeroWidthEncoder.SPACE = '\u200E';
114-
ZeroWidthEncoder.END = '\u200F';
115-
ZeroWidthEncoder.PATTERN = `${_a.START}[${_a.ZERO}${_a.ONE}${_a.SPACE}]+${_a.END}`;
116108
class LiveTranslatorManager {
109+
_enabled;
110+
_options;
111+
_enableButton;
112+
_indicator;
117113
constructor(options) {
118114
this._enabled = false;
119115
this._options = options;
@@ -147,18 +143,24 @@ class LiveTranslatorManager {
147143
const self = this;
148144
this._options.i18n.formatter = {
149145
interpolate(message, values, path) {
150-
const meta = ZeroWidthEncoder.encode(JSON.stringify({
151-
message,
152-
values,
153-
path,
154-
locale: self._options.i18n.locale,
155-
}));
156146
const original = originalFormatter.interpolate(message, values, path);
157-
return (original && self._enabled) ? [meta, ...original] : original;
147+
let meta = '';
148+
try {
149+
meta = ZeroWidthEncoder.encode(JSON.stringify({
150+
message,
151+
values,
152+
path,
153+
locale: self._options.i18n.locale,
154+
}));
155+
}
156+
catch (exception) {
157+
console.warn(path, exception);
158+
}
159+
return (original && meta && self._enabled) ? [meta, ...original] : original;
158160
},
159161
};
160162
// initialize decode & render
161-
const throttler = (0, throttle_1.default)(() => this.render(), 800);
163+
const throttler = throttle(() => this.render(), 800);
162164
const observer = new MutationObserver(throttler);
163165
observer.observe(document.documentElement, {
164166
subtree: true,
@@ -205,7 +207,7 @@ class LiveTranslatorManager {
205207
const parent = node.parentElement;
206208
if (node instanceof Text) {
207209
const matches = node.textContent.match(re);
208-
for (const match of matches !== null && matches !== void 0 ? matches : []) {
210+
for (const match of matches ?? []) {
209211
const meta = JSON.parse(ZeroWidthEncoder.decode(match));
210212
badges.push(createBadge(meta, this._options));
211213
}
@@ -263,7 +265,7 @@ const createBadge = (meta, options, attribute) => {
263265
});
264266
return badge;
265267
};
266-
exports.LiveTranslatorPlugin = {
268+
export const LiveTranslatorPlugin = {
267269
install(app, options) {
268270
console.log('LiveTranslator is installed');
269271
new LiveTranslatorManager(options);

0 commit comments

Comments
 (0)