@ugfoundation/swaralipi-js 0.13.1 → 0.14.1

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.
Files changed (39) hide show
  1. package/README.md +25 -0
  2. package/dist/{batch-XVQRHLTN.js → batch-J72GGBG2.js} +4 -4
  3. package/dist/{batch-XVQRHLTN.js.map → batch-J72GGBG2.js.map} +1 -1
  4. package/dist/{chunk-MORX7G6E.js → chunk-4WDAVRET.js} +3 -3
  5. package/dist/{chunk-MORX7G6E.js.map → chunk-4WDAVRET.js.map} +1 -1
  6. package/dist/{chunk-L6YZ3GC6.js → chunk-GIOGYJMM.js} +180 -19
  7. package/dist/chunk-GIOGYJMM.js.map +1 -0
  8. package/dist/{chunk-GKS4WZZ6.js → chunk-KUZSW4FN.js} +3 -3
  9. package/dist/{chunk-GKS4WZZ6.js.map → chunk-KUZSW4FN.js.map} +1 -1
  10. package/dist/cli.cjs +1 -1
  11. package/dist/cli.cjs.map +1 -1
  12. package/dist/cli.js +2 -2
  13. package/dist/convert/index.cjs +1 -1
  14. package/dist/convert/index.cjs.map +1 -1
  15. package/dist/convert/index.js +2 -2
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/{schedule-V-fgepvP.d.cts → instruments-DTIuTlda.d.cts} +174 -140
  20. package/dist/{schedule-ClyON98C.d.ts → instruments-NcUb0ozc.d.ts} +174 -140
  21. package/dist/player/index.cjs +330 -84
  22. package/dist/player/index.cjs.map +1 -1
  23. package/dist/player/index.d.cts +40 -16
  24. package/dist/player/index.d.ts +40 -16
  25. package/dist/player/index.js +150 -69
  26. package/dist/player/index.js.map +1 -1
  27. package/dist/spec/index.cjs +1 -1
  28. package/dist/spec/index.cjs.map +1 -1
  29. package/dist/spec/index.d.cts +1 -1
  30. package/dist/spec/index.d.ts +1 -1
  31. package/dist/spec/index.js +1 -1
  32. package/dist/viewer/index.cjs +189 -31
  33. package/dist/viewer/index.cjs.map +1 -1
  34. package/dist/viewer/index.d.cts +62 -2
  35. package/dist/viewer/index.d.ts +62 -2
  36. package/dist/viewer/index.js +123 -4
  37. package/dist/viewer/index.js.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-L6YZ3GC6.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { O as Octave, a as SvaraLetter, N as Note, M as Meta, S as Swaralipi, T as Taal } from '../schema-DZag9qkF.cjs';
2
2
  import { L as Lay } from '../lay-CXhC-HRO.cjs';
3
- import { D as DrumVoice, S as Schedule, P as PlayEvent } from '../schedule-V-fgepvP.cjs';
3
+ import { D as DrumVoice, S as Schedule, P as PlayEvent } from '../instruments-DTIuTlda.cjs';
4
4
  import 'zod';
5
5
  import 'tone';
6
6
 
@@ -467,6 +467,66 @@ interface PrintOptions extends StaffOptions {
467
467
  * A document's `meta.notationBy` takes precedence when present. */
468
468
  notator?: string;
469
469
  }
470
+ /** Diagonal watermark: an SVG data-URI **background** on a fixed, empty `<div>`.
471
+ *
472
+ * Two constraints, and only this shape satisfies both.
473
+ *
474
+ * 1. IT MUST FIT. The box is unknowable from in here — a phone's print page, an A4
475
+ * page, or a 1240×6000 rendered sheet whose `<body>` the consumer additionally
476
+ * `zoom`s. A `vw` font-size answers to the viewport, not to that box, so the old
477
+ * rotated `<span>` ran off the edge and was clipped: "www.gitabitan" with the ".io"
478
+ * shorn off. `preserveAspectRatio` + `background-size: contain` scale the mark into
479
+ * whatever box it lands in, and `textLength` pins the line inside the viewBox — so it
480
+ * fits BY CONSTRUCTION at every size, aspect ratio, zoom, watermark string and font.
481
+ *
482
+ * 2. IT MUST BE ON EVERY PRINTED PAGE. Chrome tiles a `position: fixed` BOX per page, but
483
+ * WebKit — Safari, and every browser on iOS — paints it ONCE, centred on the whole
484
+ * document (WebKit bug 6790), so a printout carries one mark across a page break. A
485
+ * print therefore pins one `.sw-page-mark` box over each page itself (`paginate`); the
486
+ * fixed `.sw-watermark` is left for a single-image render. Both are backgrounds, and
487
+ * `print-color-adjust: exact` carries them past Chrome's "Background graphics"
488
+ * checkbox, which is off by default.
489
+ *
490
+ * The SVG is an isolated document and cannot inherit the page's fonts, hence the inline
491
+ * `sans-serif`. `font-size` then only sets the HEIGHT (textLength fixes the width), so it
492
+ * is estimated from the character count to keep glyph proportions natural (~0.62em average
493
+ * advance for bold sans). Capped, or a short mark like "DRAFT" would be stretched across
494
+ * the whole page — there the natural width is used instead and the line simply centres. */
495
+ declare function watermarkCss(text: string): string;
496
+ /** The page-area height, in CSS px, that a print `widthPx` wide can count on. */
497
+ declare function printPageHeight(widthPx: number, heightMm?: number, ua?: string): number;
498
+ /**
499
+ * Fit every printed page to the paper picked in the print dialog. Pages are laid out (and
500
+ * paginate()d) at one size, `width` × `height`; when printing, Chrome and Firefox resolve vw/vh
501
+ * against the chosen paper's page area, so one zoom of min(area ÷ page) on both axes makes each
502
+ * laid-out page exactly one sheet of any paper at any margins. tan(atan2(a, b)) is a ÷ b as a
503
+ * plain number: Firefox has no typed arithmetic. The page is taken a hair taller than it is, so
504
+ * rounding never pushes its last line onto a sheet of its own. WebKit resolves vw/vh against the
505
+ * window, not the paper, and already shrinks a page to the paper's width, so it is left alone
506
+ * (printPageHeight keeps its pages short enough).
507
+ */
508
+ declare function fitPaperCss(width: string, height: string, ua?: string): string;
509
+ interface PaginateOptions {
510
+ /** The blocks a page may break before, in document order. */
511
+ atoms: string;
512
+ /** Blocks never left last on a page (headings, a song's first line). */
513
+ keep?: string;
514
+ /** Containers whose CSS already starts a page (`break-before: page`), to count. */
515
+ starts?: string;
516
+ /** The page area's height, CSS px (see printPageHeight). */
517
+ pageHeight: number;
518
+ /** Class of an empty box pinned over each page — the watermark (`sw-page-mark`). */
519
+ mark?: string;
520
+ }
521
+ /**
522
+ * Decide every page break here: walk the blocks a page may break before and, wherever the
523
+ * next one would overflow, force the break. Every page then holds less than a page, the
524
+ * printer never breaks anywhere else, and the pages counted are the printed ones — which is
525
+ * what lets a box be pinned over each page (a watermark WebKit cannot repeat) and an index
526
+ * name its pages (Chrome has no target-counter()). Returns each atom's page; the total is
527
+ * left on `body[data-pages]`.
528
+ */
529
+ declare function paginate(doc: Document, o: PaginateOptions): Map<Element, number>;
470
530
  /**
471
531
  * Build a complete, standalone HTML document for printing an akarmatrik
472
532
  * (bn/hi/en) swaralipi sheet, with watermark + notator footer. Usable for a
@@ -568,4 +628,4 @@ type Transliterator = (bengaliText: string) => string;
568
628
  */
569
629
  declare function loadLyricTransliterator(lang: ViewerLang): Promise<Transliterator | undefined>;
570
630
 
571
- export { type AbcMeter, type Arc, type Cell, type Cluster, type ComposeOptions, DEFAULT_NOTATOR, DEFAULT_WATERMARK, DIGITS, FREE_TAAL_LABELS, type GridLang, LABELS, LAY_LABELS, type Layout, MARKS, MAX_ZOOM, MIN_ZOOM, NOTATION_FONT_URLS, PRACTICE_LABELS, type PrintOptions, type RenderOptions, SWARALIPI_CSS, SWARALIPI_PRINT_CSS, SWARALIPI_STAFF_CSS, type StaffOptions, type SwaralipiSheetElement, type TaalStaffOptions, type Transliterator, type ViewerLang, ZOOM_STEP, abcDuration, abcToSvg, alignRows, buildAbc, buildTaalAbc, cellMatra, composeCluster, defineSwaralipiSheet, docToAbc, fitSwaralipi, groupRowIntoCells, loadLyricTransliterator, localizeDigits, midiToAbc, printSwaralipi, renderMetaHeader, renderPrintDocument, renderStaffHtml, renderStaffPrintDocument, renderTaalStaffHtml, renderToHtml, resolveArcs };
631
+ export { type AbcMeter, type Arc, type Cell, type Cluster, type ComposeOptions, DEFAULT_NOTATOR, DEFAULT_WATERMARK, DIGITS, FREE_TAAL_LABELS, type GridLang, LABELS, LAY_LABELS, type Layout, MARKS, MAX_ZOOM, MIN_ZOOM, NOTATION_FONT_URLS, PRACTICE_LABELS, type PaginateOptions, type PrintOptions, type RenderOptions, SWARALIPI_CSS, SWARALIPI_PRINT_CSS, SWARALIPI_STAFF_CSS, type StaffOptions, type SwaralipiSheetElement, type TaalStaffOptions, type Transliterator, type ViewerLang, ZOOM_STEP, abcDuration, abcToSvg, alignRows, buildAbc, buildTaalAbc, cellMatra, composeCluster, defineSwaralipiSheet, docToAbc, fitPaperCss, fitSwaralipi, groupRowIntoCells, loadLyricTransliterator, localizeDigits, midiToAbc, paginate, printPageHeight, printSwaralipi, renderMetaHeader, renderPrintDocument, renderStaffHtml, renderStaffPrintDocument, renderTaalStaffHtml, renderToHtml, resolveArcs, watermarkCss };
@@ -1,6 +1,6 @@
1
1
  import { O as Octave, a as SvaraLetter, N as Note, M as Meta, S as Swaralipi, T as Taal } from '../schema-DZag9qkF.js';
2
2
  import { L as Lay } from '../lay-CWlEhImP.js';
3
- import { D as DrumVoice, S as Schedule, P as PlayEvent } from '../schedule-ClyON98C.js';
3
+ import { D as DrumVoice, S as Schedule, P as PlayEvent } from '../instruments-NcUb0ozc.js';
4
4
  import 'zod';
5
5
  import 'tone';
6
6
 
@@ -467,6 +467,66 @@ interface PrintOptions extends StaffOptions {
467
467
  * A document's `meta.notationBy` takes precedence when present. */
468
468
  notator?: string;
469
469
  }
470
+ /** Diagonal watermark: an SVG data-URI **background** on a fixed, empty `<div>`.
471
+ *
472
+ * Two constraints, and only this shape satisfies both.
473
+ *
474
+ * 1. IT MUST FIT. The box is unknowable from in here — a phone's print page, an A4
475
+ * page, or a 1240×6000 rendered sheet whose `<body>` the consumer additionally
476
+ * `zoom`s. A `vw` font-size answers to the viewport, not to that box, so the old
477
+ * rotated `<span>` ran off the edge and was clipped: "www.gitabitan" with the ".io"
478
+ * shorn off. `preserveAspectRatio` + `background-size: contain` scale the mark into
479
+ * whatever box it lands in, and `textLength` pins the line inside the viewBox — so it
480
+ * fits BY CONSTRUCTION at every size, aspect ratio, zoom, watermark string and font.
481
+ *
482
+ * 2. IT MUST BE ON EVERY PRINTED PAGE. Chrome tiles a `position: fixed` BOX per page, but
483
+ * WebKit — Safari, and every browser on iOS — paints it ONCE, centred on the whole
484
+ * document (WebKit bug 6790), so a printout carries one mark across a page break. A
485
+ * print therefore pins one `.sw-page-mark` box over each page itself (`paginate`); the
486
+ * fixed `.sw-watermark` is left for a single-image render. Both are backgrounds, and
487
+ * `print-color-adjust: exact` carries them past Chrome's "Background graphics"
488
+ * checkbox, which is off by default.
489
+ *
490
+ * The SVG is an isolated document and cannot inherit the page's fonts, hence the inline
491
+ * `sans-serif`. `font-size` then only sets the HEIGHT (textLength fixes the width), so it
492
+ * is estimated from the character count to keep glyph proportions natural (~0.62em average
493
+ * advance for bold sans). Capped, or a short mark like "DRAFT" would be stretched across
494
+ * the whole page — there the natural width is used instead and the line simply centres. */
495
+ declare function watermarkCss(text: string): string;
496
+ /** The page-area height, in CSS px, that a print `widthPx` wide can count on. */
497
+ declare function printPageHeight(widthPx: number, heightMm?: number, ua?: string): number;
498
+ /**
499
+ * Fit every printed page to the paper picked in the print dialog. Pages are laid out (and
500
+ * paginate()d) at one size, `width` × `height`; when printing, Chrome and Firefox resolve vw/vh
501
+ * against the chosen paper's page area, so one zoom of min(area ÷ page) on both axes makes each
502
+ * laid-out page exactly one sheet of any paper at any margins. tan(atan2(a, b)) is a ÷ b as a
503
+ * plain number: Firefox has no typed arithmetic. The page is taken a hair taller than it is, so
504
+ * rounding never pushes its last line onto a sheet of its own. WebKit resolves vw/vh against the
505
+ * window, not the paper, and already shrinks a page to the paper's width, so it is left alone
506
+ * (printPageHeight keeps its pages short enough).
507
+ */
508
+ declare function fitPaperCss(width: string, height: string, ua?: string): string;
509
+ interface PaginateOptions {
510
+ /** The blocks a page may break before, in document order. */
511
+ atoms: string;
512
+ /** Blocks never left last on a page (headings, a song's first line). */
513
+ keep?: string;
514
+ /** Containers whose CSS already starts a page (`break-before: page`), to count. */
515
+ starts?: string;
516
+ /** The page area's height, CSS px (see printPageHeight). */
517
+ pageHeight: number;
518
+ /** Class of an empty box pinned over each page — the watermark (`sw-page-mark`). */
519
+ mark?: string;
520
+ }
521
+ /**
522
+ * Decide every page break here: walk the blocks a page may break before and, wherever the
523
+ * next one would overflow, force the break. Every page then holds less than a page, the
524
+ * printer never breaks anywhere else, and the pages counted are the printed ones — which is
525
+ * what lets a box be pinned over each page (a watermark WebKit cannot repeat) and an index
526
+ * name its pages (Chrome has no target-counter()). Returns each atom's page; the total is
527
+ * left on `body[data-pages]`.
528
+ */
529
+ declare function paginate(doc: Document, o: PaginateOptions): Map<Element, number>;
470
530
  /**
471
531
  * Build a complete, standalone HTML document for printing an akarmatrik
472
532
  * (bn/hi/en) swaralipi sheet, with watermark + notator footer. Usable for a
@@ -568,4 +628,4 @@ type Transliterator = (bengaliText: string) => string;
568
628
  */
569
629
  declare function loadLyricTransliterator(lang: ViewerLang): Promise<Transliterator | undefined>;
570
630
 
571
- export { type AbcMeter, type Arc, type Cell, type Cluster, type ComposeOptions, DEFAULT_NOTATOR, DEFAULT_WATERMARK, DIGITS, FREE_TAAL_LABELS, type GridLang, LABELS, LAY_LABELS, type Layout, MARKS, MAX_ZOOM, MIN_ZOOM, NOTATION_FONT_URLS, PRACTICE_LABELS, type PrintOptions, type RenderOptions, SWARALIPI_CSS, SWARALIPI_PRINT_CSS, SWARALIPI_STAFF_CSS, type StaffOptions, type SwaralipiSheetElement, type TaalStaffOptions, type Transliterator, type ViewerLang, ZOOM_STEP, abcDuration, abcToSvg, alignRows, buildAbc, buildTaalAbc, cellMatra, composeCluster, defineSwaralipiSheet, docToAbc, fitSwaralipi, groupRowIntoCells, loadLyricTransliterator, localizeDigits, midiToAbc, printSwaralipi, renderMetaHeader, renderPrintDocument, renderStaffHtml, renderStaffPrintDocument, renderTaalStaffHtml, renderToHtml, resolveArcs };
631
+ export { type AbcMeter, type Arc, type Cell, type Cluster, type ComposeOptions, DEFAULT_NOTATOR, DEFAULT_WATERMARK, DIGITS, FREE_TAAL_LABELS, type GridLang, LABELS, LAY_LABELS, type Layout, MARKS, MAX_ZOOM, MIN_ZOOM, NOTATION_FONT_URLS, PRACTICE_LABELS, type PaginateOptions, type PrintOptions, type RenderOptions, SWARALIPI_CSS, SWARALIPI_PRINT_CSS, SWARALIPI_STAFF_CSS, type StaffOptions, type SwaralipiSheetElement, type TaalStaffOptions, type Transliterator, type ViewerLang, ZOOM_STEP, abcDuration, abcToSvg, alignRows, buildAbc, buildTaalAbc, cellMatra, composeCluster, defineSwaralipiSheet, docToAbc, fitPaperCss, fitSwaralipi, groupRowIntoCells, loadLyricTransliterator, localizeDigits, midiToAbc, paginate, printPageHeight, printSwaralipi, renderMetaHeader, renderPrintDocument, renderStaffHtml, renderStaffPrintDocument, renderTaalStaffHtml, renderToHtml, resolveArcs, watermarkCss };
@@ -1,4 +1,4 @@
1
- import { isArcRaw, glideTargets, buildSchedule, drumPattern } from '../chunk-L6YZ3GC6.js';
1
+ import { isArcRaw, glideTargets, buildSchedule, drumPattern } from '../chunk-GIOGYJMM.js';
2
2
  import '../chunk-BSZ3WQUP.js';
3
3
  import { hasKomal, isTaalFerta, sameTaal, TAALS, graceNotes } from '../chunk-KOHSKHXI.js';
4
4
 
@@ -1233,14 +1233,123 @@ function watermarkCss(text) {
1233
1233
  const len = Math.min(span, 0.62 * text.length * size);
1234
1234
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet"><text x="50" y="50" dy=".35em" text-anchor="middle" font-family="sans-serif" font-weight="700" fill="rgba(0,0,0,0.07)" font-size="${size.toFixed(2)}" textLength="${len.toFixed(2)}" lengthAdjust="spacingAndGlyphs" transform="rotate(-35 50 50)">${escapeHtml2(text)}</text></svg>`;
1235
1235
  return `
1236
- .sw-watermark {
1237
- position: fixed; inset: 0; z-index: 0; pointer-events: none;
1236
+ .sw-watermark, .sw-page-mark {
1237
+ pointer-events: none;
1238
1238
  background: url("data:image/svg+xml,${encodeURIComponent(svg)}") center / contain no-repeat;
1239
1239
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
1240
1240
  }
1241
+ .sw-watermark { position: fixed; inset: 0; z-index: 0; }
1242
+ .sw-page-mark { position: absolute; z-index: -1; }
1241
1243
  body > .sw-sheet, body > .sw-footer { position: relative; z-index: 1; }
1242
1244
  `;
1243
1245
  }
1246
+ var A4_MM = 297 - 2 * 16;
1247
+ var WEBKIT_PAGE_ASPECT = 1.2;
1248
+ var isWebKit = (ua) => /AppleWebKit/.test(ua) && !/Chrome\//.test(ua);
1249
+ function printPageHeight(widthPx, heightMm = A4_MM, ua = navigator.userAgent) {
1250
+ const px = heightMm * 96 / 25.4;
1251
+ return isWebKit(ua) ? Math.min(px, widthPx * WEBKIT_PAGE_ASPECT) : px;
1252
+ }
1253
+ function fitPaperCss(width, height, ua = globalThis.navigator?.userAgent ?? "") {
1254
+ if (isWebKit(ua)) return "";
1255
+ return `@media print { html { zoom: min(tan(atan2(100vw, ${width})), tan(atan2(100vh, calc(${height} + 2px)))); } }`;
1256
+ }
1257
+ function paginate(doc, o) {
1258
+ const atoms = [...doc.querySelectorAll(o.atoms)];
1259
+ const pages = /* @__PURE__ */ new Map();
1260
+ if (atoms.length === 0) return pages;
1261
+ const view = doc.defaultView;
1262
+ const forced = new Set(o.starts ? [...doc.querySelectorAll(o.starts)].map((c) => c.matches(o.atoms) ? c : c.querySelector(o.atoms)) : []);
1263
+ const keep = (el) => !!o.keep && el.matches(o.keep);
1264
+ const start = (el) => {
1265
+ let y = Infinity;
1266
+ for (let e = el; e && e !== doc.body; e = e.parentElement) {
1267
+ if (e.getClientRects().length) y = Math.min(y, e.getBoundingClientRect().top - parseFloat(view.getComputedStyle(e).marginTop));
1268
+ if (e.previousElementSibling) break;
1269
+ }
1270
+ return y;
1271
+ };
1272
+ let page = 1;
1273
+ let first = 0;
1274
+ let top = start(atoms[0]);
1275
+ const heads = [atoms[0]];
1276
+ atoms.forEach((el, i) => {
1277
+ let at = -1;
1278
+ if (i > first && forced.has(el)) at = i;
1279
+ else if (i > first && el.getBoundingClientRect().bottom - top > o.pageHeight) {
1280
+ at = i;
1281
+ while (at - 1 > first && keep(atoms[at - 1])) at--;
1282
+ }
1283
+ if (at >= 0) {
1284
+ page++;
1285
+ first = at;
1286
+ top = start(atoms[at]);
1287
+ heads.push(atoms[at]);
1288
+ for (let k = at; k < i; k++) pages.set(atoms[k], page);
1289
+ }
1290
+ while (el.getBoundingClientRect().bottom - top > o.pageHeight) {
1291
+ page++;
1292
+ top += o.pageHeight;
1293
+ }
1294
+ pages.set(el, page);
1295
+ });
1296
+ const grids = /* @__PURE__ */ new Map();
1297
+ for (const el of heads) {
1298
+ for (let a = el.parentElement; a && a !== doc.body; a = a.parentElement) {
1299
+ const css = view.getComputedStyle(a);
1300
+ if (!grids.has(a) && css.display.endsWith("grid")) grids.set(a, css.gridTemplateColumns);
1301
+ }
1302
+ }
1303
+ for (const [g, cols] of grids) g.style.gridTemplateColumns = cols;
1304
+ const hosts = heads.map((el, i) => i === 0 ? topOf(el) : splitBefore(el));
1305
+ if (o.mark) {
1306
+ const body = doc.body.getBoundingClientRect();
1307
+ const side = Math.min(body.width, o.pageHeight);
1308
+ const at = heads.map((el, i) => ({ top: start(el), box: hosts[i].getBoundingClientRect(), fixed: view.getComputedStyle(hosts[i]).position !== "static" }));
1309
+ hosts.forEach((host, i) => {
1310
+ const { top: top2, box, fixed } = at[i];
1311
+ if (!fixed) host.style.position = "relative";
1312
+ host.style.isolation = "isolate";
1313
+ const mark = doc.createElement("div");
1314
+ mark.className = o.mark;
1315
+ mark.setAttribute("aria-hidden", "true");
1316
+ mark.style.cssText = `top:${top2 - box.top + (o.pageHeight - side) / 2}px; left:${body.left - box.left}px; width:${body.width}px; height:${side}px;`;
1317
+ host.append(mark);
1318
+ });
1319
+ }
1320
+ doc.body.dataset.pages = String(page);
1321
+ return pages;
1322
+ }
1323
+ function topOf(el) {
1324
+ let top = el;
1325
+ while (top.parentElement !== top.ownerDocument.body) top = top.parentElement;
1326
+ return top;
1327
+ }
1328
+ function splitBefore(el) {
1329
+ const top = topOf(el);
1330
+ let from = el;
1331
+ while (from !== top && !from.previousElementSibling) from = from.parentElement;
1332
+ if (from === top) {
1333
+ top.style.breakBefore = "page";
1334
+ return top;
1335
+ }
1336
+ const cut = [];
1337
+ for (let a = from.parentElement; a !== top.parentElement; a = a.parentElement) cut.push(a);
1338
+ const range = el.ownerDocument.createRange();
1339
+ range.setStartBefore(from);
1340
+ range.setEndAfter(top.lastChild);
1341
+ const rest = top.cloneNode(false);
1342
+ rest.append(range.extractContents());
1343
+ top.after(rest);
1344
+ for (const a of cut) Object.assign(a.style, { marginBottom: "0", paddingBottom: "0", borderBottomWidth: "0" });
1345
+ for (let a = from.parentElement; a !== rest.parentElement; a = a.parentElement) {
1346
+ Object.assign(a.style, { marginTop: "0", paddingTop: "0", borderTopWidth: "0" });
1347
+ }
1348
+ rest.style.breakBefore = "page";
1349
+ return rest;
1350
+ }
1351
+ var SHEET_ATOMS = ".sw-header, .sw-part-name, .sw-change, .sw-row, .sw-staff-meta, .sw-staff-lines > div, body > .sw-footer";
1352
+ var SHEET_KEEP = ".sw-header, .sw-part-name, .sw-change, .sw-staff-meta";
1244
1353
  function chrome(text, notator) {
1245
1354
  const top = text ? '<div class="sw-watermark" aria-hidden="true"></div>' : "";
1246
1355
  const bottom = notator ? `<footer class="sw-footer">${escapeHtml2(notator)}</footer>` : "";
@@ -1264,6 +1373,9 @@ ${SWARALIPI_CSS}
1264
1373
  ${SWARALIPI_STAFF_CSS}
1265
1374
  ${SWARALIPI_PRINT_CSS}
1266
1375
  ${watermarkCss(watermark)}
1376
+ /* Laid out as A4 \u2014 the page paginate() fills \u2014 and fitted to whatever paper is picked. */
1377
+ @page { margin: 16mm; }
1378
+ ${fitPaperCss("178mm", `${A4_MM}mm`)}
1267
1379
  html, body { margin: 0; }
1268
1380
  /* The printable width of A4 at the @page margin above. The sheet is one grid
1269
1381
  with one natural width, so the fit script needs a real page-sized box to
@@ -1319,6 +1431,13 @@ function printHtmlInIframe(html) {
1319
1431
  printed = true;
1320
1432
  try {
1321
1433
  win.__swFit?.();
1434
+ const doc = iframe.contentDocument;
1435
+ const fixed = doc.querySelector(".sw-watermark");
1436
+ if (fixed) {
1437
+ fixed.remove();
1438
+ const pageHeight = printPageHeight(doc.body.clientWidth);
1439
+ paginate(doc, { atoms: SHEET_ATOMS, keep: SHEET_KEEP, pageHeight, mark: "sw-page-mark" });
1440
+ }
1322
1441
  win.focus();
1323
1442
  win.print();
1324
1443
  } catch {
@@ -1675,6 +1794,6 @@ function defineSwaralipiSheet(tagName = "swaralipi-sheet") {
1675
1794
  return ctor;
1676
1795
  }
1677
1796
 
1678
- export { DEFAULT_NOTATOR, DEFAULT_WATERMARK, DIGITS, FREE_TAAL_LABELS, LABELS, LAY_LABELS, MARKS, MAX_ZOOM, MIN_ZOOM, NOTATION_FONT_URLS, PRACTICE_LABELS, SWARALIPI_CSS, SWARALIPI_PRINT_CSS, SWARALIPI_STAFF_CSS, ZOOM_STEP, abcDuration, abcToSvg, alignRows, buildAbc, buildTaalAbc, cellMatra, composeCluster, defineSwaralipiSheet, docToAbc, fitSwaralipi, groupRowIntoCells, loadLyricTransliterator, localizeDigits, midiToAbc, printSwaralipi, renderMetaHeader, renderPrintDocument, renderStaffHtml, renderStaffPrintDocument, renderTaalStaffHtml, renderToHtml, resolveArcs };
1797
+ export { DEFAULT_NOTATOR, DEFAULT_WATERMARK, DIGITS, FREE_TAAL_LABELS, LABELS, LAY_LABELS, MARKS, MAX_ZOOM, MIN_ZOOM, NOTATION_FONT_URLS, PRACTICE_LABELS, SWARALIPI_CSS, SWARALIPI_PRINT_CSS, SWARALIPI_STAFF_CSS, ZOOM_STEP, abcDuration, abcToSvg, alignRows, buildAbc, buildTaalAbc, cellMatra, composeCluster, defineSwaralipiSheet, docToAbc, fitPaperCss, fitSwaralipi, groupRowIntoCells, loadLyricTransliterator, localizeDigits, midiToAbc, paginate, printPageHeight, printSwaralipi, renderMetaHeader, renderPrintDocument, renderStaffHtml, renderStaffPrintDocument, renderTaalStaffHtml, renderToHtml, resolveArcs, watermarkCss };
1679
1798
  //# sourceMappingURL=index.js.map
1680
1799
  //# sourceMappingURL=index.js.map