@ugfoundation/swaralipi-js 0.7.1 → 0.7.2

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.
@@ -197,7 +197,9 @@ declare function renderToHtml(doc: Swaralipi, opts?: RenderOptions): string;
197
197
  * `transform` would scale it too, but would also break print
198
198
  * pagination). This is what actually makes the glyphs smaller, so it
199
199
  * runs second and stops at `minSize` px — past that the block scrolls
200
- * inside `.sw-scroll` rather than becoming unreadable.
200
+ * inside `.sw-scroll` rather than becoming unreadable. It also runs the
201
+ * other way: a sheet narrower than its container grows (to 2x) rather
202
+ * than leaving dead space to the right of every row.
201
203
  *
202
204
  * `zoom` (default 1) multiplies the fit scale so callers can zoom in past
203
205
  * fit-to-width, or below the readability floor deliberately; past that point
@@ -197,7 +197,9 @@ declare function renderToHtml(doc: Swaralipi, opts?: RenderOptions): string;
197
197
  * `transform` would scale it too, but would also break print
198
198
  * pagination). This is what actually makes the glyphs smaller, so it
199
199
  * runs second and stops at `minSize` px — past that the block scrolls
200
- * inside `.sw-scroll` rather than becoming unreadable.
200
+ * inside `.sw-scroll` rather than becoming unreadable. It also runs the
201
+ * other way: a sheet narrower than its container grows (to 2x) rather
202
+ * than leaving dead space to the right of every row.
201
203
  *
202
204
  * `zoom` (default 1) multiplies the fit scale so callers can zoom in past
203
205
  * fit-to-width, or below the readability floor deliberately; past that point
@@ -492,14 +492,22 @@ function fitSwaralipi(root, minScale = 0, zoom = 1, minSpacing = 0.35, minSize =
492
492
  const available = scroll.clientWidth;
493
493
  let natural = block.scrollWidth;
494
494
  if (available === 0 || natural === 0) continue;
495
- for (const step of [0.75, 0.5, 0.25, 0]) {
496
- if (natural <= available || minSpacing >= 1) break;
497
- sheet.style.setProperty("--sw-tight", String(minSpacing + (1 - minSpacing) * step));
495
+ if (natural > available && minSpacing < 1) {
496
+ let loose = minSpacing;
497
+ let tight = 1;
498
+ for (let i = 0; i < 6; i++) {
499
+ const mid = (loose + tight) / 2;
500
+ sheet.style.setProperty("--sw-tight", String(mid));
501
+ if (block.scrollWidth <= available) loose = mid;
502
+ else tight = mid;
503
+ }
504
+ sheet.style.setProperty("--sw-tight", String(loose));
498
505
  natural = block.scrollWidth;
499
506
  }
500
507
  const base = parseFloat(getComputedStyle(sheet).fontSize);
501
- let fit = natural > available ? Math.max(minScale, available / natural) : 1;
502
- if (base > 0 && minSize > 0) fit = Math.max(fit, Math.min(1, minSize / base));
508
+ if (!(base > 0)) continue;
509
+ let fit = Math.max(minScale, Math.min((available - 1) / natural, 2));
510
+ if (minSize > 0) fit = Math.max(fit, Math.min(1, minSize / base));
503
511
  const scale = fit * zoom;
504
512
  if (scale === 1) continue;
505
513
  sheet.style.setProperty("--sw-size", `${(base * scale).toFixed(3)}px`);
@@ -1308,6 +1316,9 @@ function createElementClass() {
1308
1316
  });
1309
1317
  this.#root.innerHTML = this.#styleFallback() + html;
1310
1318
  this.#fit();
1319
+ void document.fonts?.ready.then(() => {
1320
+ if (seq === this.#renderSeq) this.fit();
1321
+ });
1311
1322
  }
1312
1323
  #renderError(message) {
1313
1324
  const div = document.createElement("div");