@verbaly/compiler 0.50.0 → 0.52.0
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/README.md +3 -1
- package/dist/cli.js +42 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +63 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -215,7 +215,9 @@ export default {
|
|
|
215
215
|
};
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
`render` keeps reading the full catalogs, so those pages still publish translated; the browser just stops fetching that text. Entries are key prefixes matched whole segment by whole segment, so `nav` never takes `navbar` with it, and `changelog.v1` excludes one version instead of the group. Measured on this project's own docs site: the
|
|
218
|
+
`render` keeps reading the full catalogs, so those pages still publish translated; the browser just stops fetching that text. Entries are key prefixes matched whole segment by whole segment, so `nav` never takes `navbar` with it, and `changelog.v1` excludes one version instead of the group. Measured on this project's own docs site: the locale chunk goes from **55.6 KB to 39.3 KB brotli** with nothing lost on screen.
|
|
219
|
+
|
|
220
|
+
**It composes with `render.inlineCatalog`, it is not replaced by it.** With both on, a mirrored page ships only the messages it renders (**2.86 KB brotli** on that site's home) and fetches no chunk at all, while the exclusion caps what a visitor would download on the day something does need the catalog.
|
|
219
221
|
|
|
220
222
|
**Use it for text `render` covers.** A key that is excluded and then asked for at runtime resolves to itself, like any absent key, and `bindDom` leaves the pre-rendered text alone rather than painting the key over it. The build says so when a prefix matches nothing, and when your code reads an excluded key through `t()`. To use an excluded group at runtime anyway, load it yourself:
|
|
221
223
|
|
package/dist/cli.js
CHANGED
|
@@ -793,7 +793,7 @@ function renderParamType(types) {
|
|
|
793
793
|
]) members.add(m);
|
|
794
794
|
return [...members].join(" | ");
|
|
795
795
|
}
|
|
796
|
-
function generateDts(catalog) {
|
|
796
|
+
function generateDts(catalog, options = {}) {
|
|
797
797
|
const lines = [];
|
|
798
798
|
for (const [key, message] of Object.entries(catalog).sort(([a], [b]) => a.localeCompare(b))) {
|
|
799
799
|
const params = collectParams(message);
|
|
@@ -826,7 +826,7 @@ ${lines.join("\n")}
|
|
|
826
826
|
path?: string;
|
|
827
827
|
base?: string;
|
|
828
828
|
}): string | undefined;
|
|
829
|
-
export function loadMessages(locale: string): Promise<Record<string, string
|
|
829
|
+
export function loadMessages(locale: string): Promise<Record<string, string>>;${options.inlineCatalog ? "\n export function adoptPage(options?: {\n root?: ParentNode;\n path?: string;\n }): string | undefined;" : ""}
|
|
830
830
|
export function createInstance(
|
|
831
831
|
options?: import('verbaly').VerbalyOptions<VerbalyKey>,
|
|
832
832
|
): import('verbaly').Verbaly<VerbalyKey>;
|
|
@@ -865,7 +865,7 @@ declare module 'virtual:verbaly/locale/*' {
|
|
|
865
865
|
}
|
|
866
866
|
function writeDts(cfg, catalog, file) {
|
|
867
867
|
file ??= join(cfg.root, "verbaly.d.ts");
|
|
868
|
-
const content = generateDts(catalog);
|
|
868
|
+
const content = generateDts(catalog, { inlineCatalog: cfg.render.inlineCatalog === true });
|
|
869
869
|
try {
|
|
870
870
|
if (readFileSync(file, "utf8") === content) return;
|
|
871
871
|
} catch {}
|
|
@@ -1584,7 +1584,7 @@ async function doctor(cfg) {
|
|
|
1584
1584
|
if (source && scanning && cfg.dts !== false) {
|
|
1585
1585
|
const dtsPath = cfg.dts ?? join(cfg.root, "verbaly.d.ts");
|
|
1586
1586
|
if (!existsSync(dtsPath)) warn("types", "verbaly.d.ts has not been generated", "run `npx verbaly extract`");
|
|
1587
|
-
else if (readFileSync(dtsPath, "utf8") !== generateDts(source)) warn("types", "verbaly.d.ts is stale", "run `npx verbaly extract`");
|
|
1587
|
+
else if (readFileSync(dtsPath, "utf8") !== generateDts(source, { inlineCatalog: cfg.render.inlineCatalog === true })) warn("types", "verbaly.d.ts is stale", "run `npx verbaly extract`");
|
|
1588
1588
|
else ok("types", "verbaly.d.ts is up to date");
|
|
1589
1589
|
}
|
|
1590
1590
|
const registry = await extractProject(cfg);
|
|
@@ -2487,6 +2487,10 @@ function renderHtml(html, options) {
|
|
|
2487
2487
|
if (tagName === "a" || tagName === "area") {
|
|
2488
2488
|
const inside = mirroredHref(attrs.get("href"), mirror);
|
|
2489
2489
|
if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, "href", inside);
|
|
2490
|
+
} else if (tagName === "form" || tagName === "button" || tagName === "input") {
|
|
2491
|
+
const name = tagName === "form" ? "action" : "formaction";
|
|
2492
|
+
const inside = mirroredHref(attrs.get(name), mirror);
|
|
2493
|
+
if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, name, inside);
|
|
2490
2494
|
} else if (tagName === "meta" && attrs.get("http-equiv")?.toLowerCase() === "refresh") {
|
|
2491
2495
|
const content = attrs.get("content") ?? "";
|
|
2492
2496
|
const url = /^([^;]*;\s*url\s*=\s*)(.*)$/i.exec(decodeEntities(content));
|
|
@@ -2506,11 +2510,17 @@ function renderHtml(html, options) {
|
|
|
2506
2510
|
if (close) {
|
|
2507
2511
|
const text = t(key, args);
|
|
2508
2512
|
const own = parseArgs$1(attrs.get(linksAttr));
|
|
2509
|
-
const
|
|
2513
|
+
const merged = own ? globalLinks ? {
|
|
2510
2514
|
...globalLinks,
|
|
2511
2515
|
...own
|
|
2512
2516
|
} : own : globalLinks;
|
|
2513
|
-
const
|
|
2517
|
+
const links = mirror ? mirroredLinks(merged, mirror) : merged;
|
|
2518
|
+
const nodes = attrs.has(richAttr) ? parseTags(text) : [];
|
|
2519
|
+
if (mirror && links) {
|
|
2520
|
+
const carried = usedLinks(nodes, links);
|
|
2521
|
+
if (carried && JSON.stringify(carried) !== JSON.stringify(own)) setAttribute(ms, html, chunkStart, openEnd, attrChunk, linksAttr, JSON.stringify(carried));
|
|
2522
|
+
}
|
|
2523
|
+
const content = attrs.has(richAttr) ? richToHtml(nodes, richTags, links) : escapeHtml(text);
|
|
2514
2524
|
if (html.slice(openEnd, close.contentEnd) !== content) {
|
|
2515
2525
|
if (openEnd === close.contentEnd) ms.appendLeft(openEnd, content);
|
|
2516
2526
|
else ms.overwrite(openEnd, close.contentEnd, content);
|
|
@@ -2549,7 +2559,7 @@ function pageSlice(v, locale, used) {
|
|
|
2549
2559
|
const slice = {};
|
|
2550
2560
|
for (const key of used) {
|
|
2551
2561
|
const found = v.inspect(key);
|
|
2552
|
-
|
|
2562
|
+
slice[key] = found?.from === locale ? found.source : "";
|
|
2553
2563
|
}
|
|
2554
2564
|
return slice;
|
|
2555
2565
|
}
|
|
@@ -2557,6 +2567,31 @@ function publicPath(rel) {
|
|
|
2557
2567
|
const path = `/${rel.replace(/(^|\/)index\.html$/, "$1")}`;
|
|
2558
2568
|
return path.length > 1 ? path.replace(/\/+$/, "") : path;
|
|
2559
2569
|
}
|
|
2570
|
+
function usedLinks(nodes, links) {
|
|
2571
|
+
const out = {};
|
|
2572
|
+
const walk = (list) => {
|
|
2573
|
+
for (const node of list) {
|
|
2574
|
+
if (typeof node === "string") continue;
|
|
2575
|
+
if (links[node.name] !== void 0) out[node.name] = links[node.name];
|
|
2576
|
+
walk(node.children);
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
walk(nodes);
|
|
2580
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
2581
|
+
}
|
|
2582
|
+
function mirroredLinks(links, mirror) {
|
|
2583
|
+
if (!links) return links;
|
|
2584
|
+
const out = {};
|
|
2585
|
+
for (const [name, link] of Object.entries(links)) {
|
|
2586
|
+
const inside = mirroredHref(typeof link === "string" ? link : link.href, mirror);
|
|
2587
|
+
if (inside === void 0) out[name] = link;
|
|
2588
|
+
else out[name] = typeof link === "string" ? inside : {
|
|
2589
|
+
...link,
|
|
2590
|
+
href: inside
|
|
2591
|
+
};
|
|
2592
|
+
}
|
|
2593
|
+
return out;
|
|
2594
|
+
}
|
|
2560
2595
|
function mirroredHref(raw, mirror) {
|
|
2561
2596
|
if (raw === void 0) return void 0;
|
|
2562
2597
|
const href = decodeEntities(raw);
|