@dabalabs/lang 0.0.4-beta → 0.0.6-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 +18 -11
- package/dist/dabalang.cjs.map +1 -1
- package/dist/dabalang.js +18 -11
- 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 +1 -1
package/dist/dabalang.js
CHANGED
|
@@ -237,8 +237,20 @@ var TranslationApplier = class {
|
|
|
237
237
|
/** Re-crawls the current DOM — call after content is known to have
|
|
238
238
|
* changed (e.g. after a route change in an SPA). Not called
|
|
239
239
|
* automatically; dabalang does one crawl per page load. */
|
|
240
|
+
/** Re-crawls, returning how many text nodes were seen for the first
|
|
241
|
+
* time.
|
|
242
|
+
*
|
|
243
|
+
* That count is the signal a caller needs to decide whether anything
|
|
244
|
+
* actually arrived. Applying a language writes to the DOM, which any
|
|
245
|
+
* MutationObserver watching will see as a change — so "did the DOM
|
|
246
|
+
* mutate" cannot distinguish new content from our own echo, and acting
|
|
247
|
+
* on it would loop. "Did previously-unseen text appear" can: our own
|
|
248
|
+
* writes land on nodes already in sourceByNode, so they count zero. */
|
|
240
249
|
recrawl() {
|
|
241
|
-
|
|
250
|
+
const crawled = crawlVisibleText(this.root);
|
|
251
|
+
const fresh = crawled.reduce((n, { node }) => this.sourceByNode.has(node) ? n : n + 1, 0);
|
|
252
|
+
this.groups = this.absorb(crawled);
|
|
253
|
+
return fresh;
|
|
242
254
|
}
|
|
243
255
|
currentLanguage() {
|
|
244
256
|
return this.activeLang;
|
|
@@ -508,13 +520,7 @@ var NavigationWatcher = class {
|
|
|
508
520
|
const onPop = () => this.onRouteMaybeChanged();
|
|
509
521
|
window.addEventListener("popstate", onPop);
|
|
510
522
|
this.restorers.push(() => window.removeEventListener("popstate", onPop));
|
|
511
|
-
this.observer = new MutationObserver(() =>
|
|
512
|
-
if (this.currentPath() !== this.lastPath) {
|
|
513
|
-
this.schedule();
|
|
514
|
-
} else if (this.passesLeft > 0) {
|
|
515
|
-
this.schedule();
|
|
516
|
-
}
|
|
517
|
-
});
|
|
523
|
+
this.observer = new MutationObserver(() => this.schedule());
|
|
518
524
|
this.observer.observe(document.body, { childList: true, subtree: true });
|
|
519
525
|
}
|
|
520
526
|
currentPath() {
|
|
@@ -534,11 +540,10 @@ var NavigationWatcher = class {
|
|
|
534
540
|
if (path !== this.lastPath) {
|
|
535
541
|
this.lastPath = path;
|
|
536
542
|
this.passesLeft = FOLLOW_UP_PASSES;
|
|
537
|
-
this.onNavigated();
|
|
538
543
|
} else if (this.passesLeft > 0) {
|
|
539
544
|
this.passesLeft -= 1;
|
|
540
|
-
this.onNavigated();
|
|
541
545
|
}
|
|
546
|
+
this.onNavigated();
|
|
542
547
|
}, SETTLE_MS);
|
|
543
548
|
}
|
|
544
549
|
stop() {
|
|
@@ -1121,6 +1126,7 @@ function renderLanguageSwitcher(container, targetLanguages, sourceLang, onSelect
|
|
|
1121
1126
|
let closing = false;
|
|
1122
1127
|
const root = document.createElement("div");
|
|
1123
1128
|
root.className = "dabalang-switcher-root";
|
|
1129
|
+
root.setAttribute(IGNORE_ATTR, "");
|
|
1124
1130
|
const trigger = document.createElement("button");
|
|
1125
1131
|
trigger.type = "button";
|
|
1126
1132
|
trigger.className = "dabalang-trigger";
|
|
@@ -1178,6 +1184,7 @@ function renderLanguageSwitcher(container, targetLanguages, sourceLang, onSelect
|
|
|
1178
1184
|
if (backdrop) return;
|
|
1179
1185
|
const overlay = document.createElement("div");
|
|
1180
1186
|
overlay.className = "dabalang-backdrop";
|
|
1187
|
+
overlay.setAttribute(IGNORE_ATTR, "");
|
|
1181
1188
|
overlay.addEventListener("mousedown", (e) => {
|
|
1182
1189
|
if (e.target === overlay) closeModal();
|
|
1183
1190
|
});
|
|
@@ -1454,7 +1461,7 @@ var DabaLang = class {
|
|
|
1454
1461
|
if (this.isSiteTranslated(this.activeLang)) return;
|
|
1455
1462
|
this.retranslating = this.retranslating.catch(() => void 0).then(async () => {
|
|
1456
1463
|
if (!this.applier || this.activeLang === null) return;
|
|
1457
|
-
this.applier.recrawl();
|
|
1464
|
+
if (this.applier.recrawl() === 0) return;
|
|
1458
1465
|
try {
|
|
1459
1466
|
await this.applier.applyLanguage(this.activeLang);
|
|
1460
1467
|
} catch (err) {
|