@dabalabs/lang 0.0.3-beta → 0.0.5-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dabalang.cjs +19 -14
- package/dist/dabalang.cjs.map +1 -1
- package/dist/dabalang.js +19 -14
- package/dist/dabalang.js.map +1 -1
- package/dist/dabalang.min.js +2 -2
- package/dist/dabalang.min.js.map +1 -1
- package/package.json +2 -2
package/dist/dabalang.cjs
CHANGED
|
@@ -239,8 +239,20 @@ var TranslationApplier = class {
|
|
|
239
239
|
/** Re-crawls the current DOM — call after content is known to have
|
|
240
240
|
* changed (e.g. after a route change in an SPA). Not called
|
|
241
241
|
* automatically; dabalang does one crawl per page load. */
|
|
242
|
+
/** Re-crawls, returning how many text nodes were seen for the first
|
|
243
|
+
* time.
|
|
244
|
+
*
|
|
245
|
+
* That count is the signal a caller needs to decide whether anything
|
|
246
|
+
* actually arrived. Applying a language writes to the DOM, which any
|
|
247
|
+
* MutationObserver watching will see as a change — so "did the DOM
|
|
248
|
+
* mutate" cannot distinguish new content from our own echo, and acting
|
|
249
|
+
* on it would loop. "Did previously-unseen text appear" can: our own
|
|
250
|
+
* writes land on nodes already in sourceByNode, so they count zero. */
|
|
242
251
|
recrawl() {
|
|
243
|
-
|
|
252
|
+
const crawled = crawlVisibleText(this.root);
|
|
253
|
+
const fresh = crawled.reduce((n, { node }) => this.sourceByNode.has(node) ? n : n + 1, 0);
|
|
254
|
+
this.groups = this.absorb(crawled);
|
|
255
|
+
return fresh;
|
|
244
256
|
}
|
|
245
257
|
currentLanguage() {
|
|
246
258
|
return this.activeLang;
|
|
@@ -510,13 +522,7 @@ var NavigationWatcher = class {
|
|
|
510
522
|
const onPop = () => this.onRouteMaybeChanged();
|
|
511
523
|
window.addEventListener("popstate", onPop);
|
|
512
524
|
this.restorers.push(() => window.removeEventListener("popstate", onPop));
|
|
513
|
-
this.observer = new MutationObserver(() =>
|
|
514
|
-
if (this.currentPath() !== this.lastPath) {
|
|
515
|
-
this.schedule();
|
|
516
|
-
} else if (this.passesLeft > 0) {
|
|
517
|
-
this.schedule();
|
|
518
|
-
}
|
|
519
|
-
});
|
|
525
|
+
this.observer = new MutationObserver(() => this.schedule());
|
|
520
526
|
this.observer.observe(document.body, { childList: true, subtree: true });
|
|
521
527
|
}
|
|
522
528
|
currentPath() {
|
|
@@ -536,11 +542,10 @@ var NavigationWatcher = class {
|
|
|
536
542
|
if (path !== this.lastPath) {
|
|
537
543
|
this.lastPath = path;
|
|
538
544
|
this.passesLeft = FOLLOW_UP_PASSES;
|
|
539
|
-
this.onNavigated();
|
|
540
545
|
} else if (this.passesLeft > 0) {
|
|
541
546
|
this.passesLeft -= 1;
|
|
542
|
-
this.onNavigated();
|
|
543
547
|
}
|
|
548
|
+
this.onNavigated();
|
|
544
549
|
}, SETTLE_MS);
|
|
545
550
|
}
|
|
546
551
|
stop() {
|
|
@@ -670,15 +675,15 @@ var FLAG_IMAGES = {
|
|
|
670
675
|
var STYLE_ID = "dabalang-switcher-styles";
|
|
671
676
|
var LANGUAGE_LABELS = {
|
|
672
677
|
en: "English",
|
|
673
|
-
es: "Espa\
|
|
678
|
+
es: "Espa\xF1ol",
|
|
674
679
|
fr: "Fran\xE7ais",
|
|
675
|
-
de: "
|
|
680
|
+
de: "Deutsch",
|
|
676
681
|
pt: "Portugu\xEAs",
|
|
677
682
|
it: "Italiano",
|
|
678
683
|
ja: "\u65E5\u672C\u8A9E",
|
|
679
684
|
ko: "\uD55C\uAD6D\uC5B4",
|
|
680
685
|
zh: "\u4E2D\u6587",
|
|
681
|
-
ar: "\u0639\u0631\u0628\u064A",
|
|
686
|
+
ar: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629",
|
|
682
687
|
hi: "\u0939\u093F\u0928\u094D\u0926\u0940",
|
|
683
688
|
ru: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
|
|
684
689
|
nl: "Nederlands",
|
|
@@ -1456,7 +1461,7 @@ var DabaLang = class {
|
|
|
1456
1461
|
if (this.isSiteTranslated(this.activeLang)) return;
|
|
1457
1462
|
this.retranslating = this.retranslating.catch(() => void 0).then(async () => {
|
|
1458
1463
|
if (!this.applier || this.activeLang === null) return;
|
|
1459
|
-
this.applier.recrawl();
|
|
1464
|
+
if (this.applier.recrawl() === 0) return;
|
|
1460
1465
|
try {
|
|
1461
1466
|
await this.applier.applyLanguage(this.activeLang);
|
|
1462
1467
|
} catch (err) {
|