@verbaly/compiler 0.51.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 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 file every page loads went from **46.3 KB to 33.5 KB brotli** with nothing lost on screen.
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
@@ -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 links = own ? globalLinks ? {
2513
+ const merged = own ? globalLinks ? {
2510
2514
  ...globalLinks,
2511
2515
  ...own
2512
2516
  } : own : globalLinks;
2513
- const content = attrs.has(richAttr) ? richToHtml(parseTags(text), richTags, links) : escapeHtml(text);
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);
@@ -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);