guidex 0.5.0 → 0.6.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +215 -0
  2. package/README.md +62 -16
  3. package/dist/lib/app/App.d.ts +1 -0
  4. package/dist/lib/app/AretinoControls.d.ts +35 -0
  5. package/dist/lib/app/CaretBand.d.ts +28 -0
  6. package/dist/lib/app/Developers.d.ts +13 -0
  7. package/dist/lib/app/EditorContext.d.ts +15 -0
  8. package/dist/lib/app/EditorTextarea.d.ts +18 -1
  9. package/dist/lib/app/EditorToolbar.d.ts +13 -0
  10. package/dist/lib/app/ExportSettings.d.ts +20 -1
  11. package/dist/lib/app/Footer.d.ts +1 -0
  12. package/dist/lib/app/GlyphChooser.d.ts +31 -0
  13. package/dist/lib/app/Inspector.d.ts +26 -0
  14. package/dist/lib/app/LiveScore.d.ts +31 -0
  15. package/dist/lib/app/Opening.d.ts +3 -0
  16. package/dist/lib/app/Reference.d.ts +28 -0
  17. package/dist/lib/app/RenderSettings.d.ts +2 -1
  18. package/dist/lib/app/ScriptViews.d.ts +8 -0
  19. package/dist/lib/app/SectionSize.d.ts +33 -0
  20. package/dist/lib/app/StaffSettings.d.ts +4 -0
  21. package/dist/lib/app/StaffedGlyph.d.ts +8 -0
  22. package/dist/lib/app/Tabs.d.ts +15 -0
  23. package/dist/lib/app/TakeItOut.d.ts +1 -0
  24. package/dist/lib/app/ThemeSwitch.d.ts +1 -0
  25. package/dist/lib/app/TopBar.d.ts +6 -0
  26. package/dist/lib/app/WidthControls.d.ts +21 -0
  27. package/dist/lib/app/aretinoCaret.d.ts +47 -0
  28. package/dist/lib/app/aretinoSource.d.ts +46 -0
  29. package/dist/lib/app/caretSync.d.ts +48 -0
  30. package/dist/lib/app/chantLibrary.d.ts +8 -4
  31. package/dist/lib/app/editorSnapshot.d.ts +11 -0
  32. package/dist/lib/app/editorState.d.ts +38 -5
  33. package/dist/lib/app/expandLink.d.ts +19 -0
  34. package/dist/lib/app/glyphData.d.ts +37 -0
  35. package/dist/lib/app/inCode.d.ts +4 -0
  36. package/dist/lib/app/insertAtCaret.d.ts +12 -0
  37. package/dist/lib/app/learn/Learn.d.ts +1 -0
  38. package/dist/lib/app/learn/LessonCard.d.ts +12 -0
  39. package/dist/lib/app/learn/lessons.d.ts +64 -0
  40. package/dist/lib/app/learn/narrowing.d.ts +24 -0
  41. package/dist/lib/app/learn/progress.d.ts +14 -0
  42. package/dist/lib/app/pageEvents.d.ts +14 -0
  43. package/dist/lib/app/previewHighlight.d.ts +44 -0
  44. package/dist/lib/app/samples.d.ts +9 -1
  45. package/dist/lib/app/scriptParts.d.ts +31 -0
  46. package/dist/lib/app/shareLink.d.ts +12 -2
  47. package/dist/lib/app/showcases/Showcases.d.ts +17 -0
  48. package/dist/lib/app/wordCopy.d.ts +4 -0
  49. package/dist/lib/aretino/fromAretino.d.ts +99 -0
  50. package/dist/lib/aretino/index.d.ts +38 -0
  51. package/dist/lib/aretino/index.js +1870 -0
  52. package/dist/lib/aretino/toAretino.d.ts +27 -0
  53. package/dist/lib/chantLayout-BRQ6FYND.js +1345 -0
  54. package/dist/lib/chantLayout.d.ts +101 -6
  55. package/dist/lib/chantMarkup-DX4K86Rv.js +993 -0
  56. package/dist/lib/drawnStaff.d.ts +39 -5
  57. package/dist/lib/editorStorage.d.ts +48 -6
  58. package/dist/lib/embed/core.d.ts +15 -1
  59. package/dist/lib/embed/index.js +1 -1
  60. package/dist/lib/embed/manual.d.ts +5 -4
  61. package/dist/lib/embed/manual.js +6 -4
  62. package/dist/lib/fonts/guidohu-staffless.woff2 +0 -0
  63. package/dist/lib/fonts/guidohu.ttf +0 -0
  64. package/dist/lib/glyphFamilies.d.ts +5 -1
  65. package/dist/lib/guidoRender.d.ts +30 -1
  66. package/dist/lib/guidoScriptTransforms.d.ts +2 -2
  67. package/dist/lib/guidoStyles-CvnACCsk.js +1466 -0
  68. package/dist/lib/guidoStyles.d.ts +23 -2
  69. package/dist/lib/react/GuidexScore.d.ts +10 -2
  70. package/dist/lib/react/index.js +14 -4
  71. package/dist/lib/{scoreImage-B2SGdROL.js → scoreImage-CKsQxHg5.js} +282 -1026
  72. package/dist/lib/theme.d.ts +13 -0
  73. package/dist/lib/word/index.d.ts +1 -1
  74. package/dist/lib/word/index.js +1 -1
  75. package/dist/lib/{wordChecker-CjYl2yof.js → wordChecker-BN_9dKAx.js} +133 -20
  76. package/dist/lib/wordChecker.d.ts +18 -1
  77. package/dist/lib/wordExport.d.ts +51 -3
  78. package/dist-embed/demo.html +2 -2
  79. package/dist-embed/fonts/guidohu-staffless.woff2 +0 -0
  80. package/dist-embed/fonts/guidohu.ttf +0 -0
  81. package/dist-embed/guidex-embed.min.js +1 -1
  82. package/package.json +10 -1
  83. package/dist/lib/app/ControlsRow.d.ts +0 -1
  84. package/dist/lib/app/SettingsMenu.d.ts +0 -1
  85. package/dist/lib/app/SettingsPanel.d.ts +0 -1
  86. package/dist/lib/chantLayout-BrCQUOhp.js +0 -2616
@@ -2,14 +2,21 @@
2
2
  * User-set dark mode (issue #16): the theme choice lives in a cookie and is
3
3
  * applied as a class on <html> that style.css reacts to.
4
4
  *
5
+ * Three choices (the top bar's Auto / Light / Dark switch): Light and Dark
6
+ * write the cookie; Auto clears it and follows the system preference, which
7
+ * is also what a visitor without a cookie gets.
8
+ *
5
9
  * The same resolve logic is duplicated as a tiny inline script in
6
10
  * index.html's <head> — it must run before the CSS body renders to avoid a
7
11
  * theme flash, long before this module loads.
8
12
  */
9
13
  export declare const THEME_COOKIE = "theme";
10
14
  export type Theme = 'light' | 'dark';
15
+ /** What the visitor picked: a fixed theme, or `auto` (follow the system). */
16
+ export type ThemePreference = 'auto' | Theme;
11
17
  export declare function readThemeCookie(cookie: string): Theme | null;
12
18
  export declare function writeThemeCookie(theme: Theme): void;
19
+ export declare function clearThemeCookie(): void;
13
20
  /** Applies a theme as the `dark`/`light` class on <html>. */
14
21
  export declare function applyTheme(theme: Theme): void;
15
22
  /**
@@ -17,3 +24,9 @@ export declare function applyTheme(theme: Theme): void;
17
24
  * preference decides (and nothing is persisted).
18
25
  */
19
26
  export declare function resolveTheme(cookie: string, systemDark: boolean): Theme;
27
+ /** The visitor's pick: the cookie's theme, or `auto` without one. */
28
+ export declare function readThemePreference(cookie: string): ThemePreference;
29
+ /** jsdom (and old browsers) may lack matchMedia; no media query means light. */
30
+ export declare function systemPrefersDark(): boolean;
31
+ /** Saves a pick and applies the theme it resolves to. */
32
+ export declare function setThemePreference(preference: ThemePreference, systemDark?: boolean): void;
@@ -13,5 +13,5 @@
13
13
  */
14
14
  export { DEFAULT_SPACER, DEFAULT_TAB_INTERVAL_PT, SpacerMeter, layoutForWord, toWordHtml, toWordText, wordLayoutText, type SpacerChar, type SpacerConfig, type SpacerWidth, type WordExportOptions, type WordLayout, type WordLine, type WordRun, type WordStyleNames, type WordTextPiece, } from '../wordExport';
15
15
  export { copyWordHtml, copyWordPlainText, type CopyResult } from '../wordClipboard';
16
- export { checkWordHtml, type WordCheckIssue, type WordCheckReport, type WordGapClass, type WordGapMechanism, type WordGapStat, type WordParagraphDiag, } from '../wordChecker';
16
+ export { checkWordHtml, type WordCheckIssue, type WordCheckOptions, type WordCheckReport, type WordGapClass, type WordGapMechanism, type WordGapStat, type WordParagraphDiag, } from '../wordChecker';
17
17
  export type { StyleSetName, ChantRunKind } from '../guidoStyles';
@@ -1,2 +1,2 @@
1
- import { a as DEFAULT_TAB_INTERVAL_PT, c as toWordHtml, i as DEFAULT_SPACER, l as toWordText, n as copyWordHtml, o as SpacerMeter, r as copyWordPlainText, s as layoutForWord, t as checkWordHtml, u as wordLayoutText } from "../wordChecker-CjYl2yof.js";
1
+ import { a as DEFAULT_TAB_INTERVAL_PT, c as toWordHtml, i as DEFAULT_SPACER, l as toWordText, n as copyWordHtml, o as SpacerMeter, r as copyWordPlainText, s as layoutForWord, t as checkWordHtml, u as wordLayoutText } from "../wordChecker-BN_9dKAx.js";
2
2
  export { DEFAULT_SPACER, DEFAULT_TAB_INTERVAL_PT, SpacerMeter, checkWordHtml, copyWordHtml, copyWordPlainText, layoutForWord, toWordHtml, toWordText, wordLayoutText };
@@ -1,4 +1,5 @@
1
- import { A as CLEF_GLYPHS, O as SCORE_MARKERS, d as measurementFont, i as measure, n as SPECIAL_NOTES, o as SMALL_CAP_SCALE, r as layoutScore, t as NOTE_MODIFIERS } from "./chantLayout-BrCQUOhp.js";
1
+ import { j as CLEF_GLYPHS, k as SCORE_MARKERS, n as SMALL_CAP_SCALE, u as measurementFont } from "./guidoStyles-CvnACCsk.js";
2
+ import { a as measure, i as layoutScore, n as SPECIAL_NOTES, t as NOTE_MODIFIERS } from "./chantLayout-BRQ6FYND.js";
2
3
  //#region src/wordExport.ts
3
4
  /**
4
5
  * Word-compatible export: turns the shared layout (chantLayout.ts) into
@@ -64,6 +65,10 @@ var CSS_VAR_COLORS = { "--red": "#d40000" };
64
65
  * installed fonts by name, not by the browser stylesheets' @font-face
65
66
  * alias. */
66
67
  var NOTES_FONT_FAMILY = "Guido HU";
68
+ /** A pt length as Word writes it: `-.1pt`, `0pt` */
69
+ function wordPt(pt) {
70
+ return `${fmtPt(pt).replace(/^(-?)0\./, "$1.")}pt`;
71
+ }
67
72
  /** 0.5 mm, the issue's example of a fixed small tab unit. */
68
73
  var DEFAULT_TAB_INTERVAL_PT = 36 / 25.4;
69
74
  /** The default spacer: a no-break space at its natural advance. The
@@ -156,6 +161,28 @@ var SpacerMeter = class {
156
161
  emittedPx: emittedPx + count * this.unitPx
157
162
  };
158
163
  }
164
+ /** A same-word connector: spacers to the dash, the dash, spacers to
165
+ * the next syllable, rounded as a pair (issue #124). Rounding each
166
+ * side alone can leave spacers before the dash and none after, gluing
167
+ * the hyphen to the next syllable (`ec -ce`); then one unit moves
168
+ * after the dash (`ec- ce`). The far side still targets `nextPx`, so
169
+ * no error accumulates. */
170
+ connector(dashStartPx, dashWidthPx, nextPx, emittedPx) {
171
+ const place = (before) => {
172
+ const dashAtPx = this.grid ? before > 0 ? (Math.floor(emittedPx / this.unitPx) + before) * this.unitPx : emittedPx : emittedPx + before * this.unitPx;
173
+ const tail = this.advance(nextPx, dashAtPx + dashWidthPx);
174
+ return {
175
+ before,
176
+ dashAtPx,
177
+ after: tail.count,
178
+ emittedPx: tail.emittedPx
179
+ };
180
+ };
181
+ const first = place(this.advance(dashStartPx, emittedPx).count);
182
+ if (first.after > 0 || first.before === 0) return first;
183
+ const moved = place(first.before - 1);
184
+ return moved.after > 0 ? moved : first;
185
+ }
159
186
  };
160
187
  function escapeHtml(text) {
161
188
  return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
@@ -206,8 +233,8 @@ function fmtPt(pt) {
206
233
  function wordScale(style) {
207
234
  return style.smallCaps ? (style.scale ?? 1) / SMALL_CAP_SCALE : style.scale;
208
235
  }
209
- /** One syllable run as Word HTML: a `<b>` wrapper for weight, inline
210
- * styles for family, size, color, and raise. Characters with no glyph in
236
+ /** One syllable run as Word HTML: `<b>` and `<u>` wrappers for weight
237
+ * and underline, inline styles for family, size, color, and raise. Characters with no glyph in
211
238
  * the destination fonts (the `**` star) ride the Symbol font as their
212
239
  * Word-safe stand-ins instead. */
213
240
  function partHtml(part, textPx) {
@@ -232,7 +259,8 @@ function partHtml(part, textPx) {
232
259
  ...css.slice(style.fontFamily ? 1 : 0).filter((c) => !c.startsWith("vertical-align:"))
233
260
  ].join(";")}">${standIn}</span>`;
234
261
  }).join("") : css.length ? `<span style="${css.join(";")}">${escapeHtml(part.text)}</span>` : escapeHtml(part.text);
235
- return style.weight === "700" ? `<b>${inner}</b>` : inner;
262
+ const underlined = style.underline ? `<u>${inner}</u>` : inner;
263
+ return style.weight === "700" ? `<b>${underlined}</b>` : underlined;
236
264
  }
237
265
  function sylHtml(seg, textPx) {
238
266
  return seg.parts.map((p) => partHtml(p, textPx)).join("");
@@ -254,16 +282,23 @@ function walkTextLine(line, meter, pieces) {
254
282
  case "gap":
255
283
  spacerTo(seg.endPx);
256
284
  break;
257
- case "connector":
258
- spacerTo(seg.dashStartPx);
285
+ case "connector": {
286
+ const c = meter.connector(seg.dashStartPx, seg.dashWidth, seg.nextAnchorPx, emitted);
287
+ if (c.before > 0) out += pieces.spacer(c.before);
259
288
  out += pieces.dash(seg.parts);
260
- emitted += seg.dashWidth;
261
- spacerTo(seg.nextAnchorPx);
289
+ if (c.after > 0) out += pieces.spacer(c.after);
290
+ emitted = c.emittedPx;
262
291
  break;
292
+ }
263
293
  case "syl":
264
294
  out += pieces.syl(seg);
265
295
  emitted += seg.textWidth;
266
296
  break;
297
+ case "mark":
298
+ spacerTo(seg.textStart);
299
+ out += pieces.syl(seg);
300
+ emitted += seg.textWidth;
301
+ break;
267
302
  case "word-space":
268
303
  out += " ";
269
304
  emitted += seg.width;
@@ -288,7 +323,7 @@ function tabDisplayPadding(meter, spacePx) {
288
323
  return " ".repeat(Math.max(1, Math.round(meter.unitPx / spacePx)));
289
324
  }
290
325
  function buildMeter(layout, config) {
291
- return new SpacerMeter(config, measurementFont({ weight: layout.bold ? "700" : "400" }, layout.textPx, layout.styleSet.textFontStack));
326
+ return new SpacerMeter(config, measurementFont({ weight: layout.bold ? "700" : "400" }, layout.textPx, layout.textFontStack));
292
327
  }
293
328
  function resolveStyleNames(layout, option) {
294
329
  const defaults = defaultStyleNames(layout.styleName);
@@ -298,6 +333,11 @@ function resolveStyleNames(layout, option) {
298
333
  textusChar: option?.textusChar ?? defaults.textusChar
299
334
  };
300
335
  }
336
+ function notesSpacing(options) {
337
+ const pt = options.notesLetterSpacingPt ?? 0;
338
+ if (!Number.isFinite(pt)) throw new Error(`notesLetterSpacingPt must be a number: ${pt}`);
339
+ return pt;
340
+ }
301
341
  /** Resolves the layout sizes: the destination-document pt options take
302
342
  * precedence over their px counterparts (px = pt × 4/3, so the layout
303
343
  * runs at the size Word will render); with textPt given the notes default
@@ -315,8 +355,13 @@ function resolveSizing(options) {
315
355
  marks: options.marks,
316
356
  staffFill: options.staffFill,
317
357
  staffFillSnapPx: options.staffFillSnapPx,
358
+ paddingPx: options.paddingPx,
359
+ textFont: options.textFont,
360
+ notesLetterSpacingPx: notesSpacing(options) * PX_PER_PT,
318
361
  twoSyllableRecitationsToPlain: options.twoSyllableRecitationsToPlain,
319
- plainRunsToRecitation: options.plainRunsToRecitation
362
+ plainRunsToRecitation: options.plainRunsToRecitation,
363
+ starUnderBar: options.starUnderBar,
364
+ cutEmptySlots: options.cutEmptySlots
320
365
  };
321
366
  }
322
367
  /** A broken line's break marker stop, in px: its right edge. Most lines
@@ -344,11 +389,12 @@ async function toWordHtml(source, options = {}) {
344
389
  const charClass = styleClass(names.textusChar);
345
390
  const notesPt = layout.notesPx * PT_PER_PX;
346
391
  const textPt = layout.textPx * PT_PER_PX;
347
- const textFamily = firstFontFamily(layout.styleSet.textFontStack);
348
- const spacePx = measure(" ", measurementFont({ weight: layout.bold ? "700" : "400" }, layout.textPx, layout.styleSet.textFontStack));
392
+ const textFamily = firstFontFamily(layout.textFontStack);
393
+ const notesSpacingPt = notesSpacing(options);
394
+ const spacePx = measure(" ", measurementFont({ weight: layout.bold ? "700" : "400" }, layout.textPx, layout.textFontStack));
349
395
  const tabInterval = spacerConfig.character === "tab" ? spacerConfig.width?.kind === "tabInterval" ? spacerConfig.width.pt : DEFAULT_TAB_INTERVAL_PT : null;
350
396
  const styleBlock = [
351
- `p.${notaClass} {mso-style-name:"${safeStyleName(names.nota)}";margin:0cm;mso-pagination:none;mso-line-height-rule:exactly;line-height:${fmtPt(notesPt * LINE_HEIGHT_RATIO)}pt;font-size:${fmtPt(notesPt)}pt;font-family:"${NOTES_FONT_FAMILY}";letter-spacing:-.1pt;` + (layout.maxWidthPx !== Infinity ? `tab-stops:right ${fmtPt(layout.starTarget * PT_PER_PX)}pt;` : "") + "}",
397
+ `p.${notaClass} {mso-style-name:"${safeStyleName(names.nota)}";margin:6pt 0cm;mso-pagination:none;mso-line-height-rule:exactly;line-height:${fmtPt(notesPt * LINE_HEIGHT_RATIO)}pt;font-size:${fmtPt(notesPt)}pt;font-family:"${NOTES_FONT_FAMILY}";letter-spacing:${wordPt(notesSpacingPt)};` + (layout.maxWidthPx !== Infinity ? `tab-stops:right ${fmtPt(layout.starTarget * PT_PER_PX)}pt;` : "") + "}",
352
398
  `p.${textusClass} {mso-style-name:"${safeStyleName(names.textus)}";mso-style-link:"${safeStyleName(names.textusChar)}";margin:0cm;mso-pagination:none;mso-line-height-rule:exactly;line-height:${fmtPt(textPt * LINE_HEIGHT_RATIO)}pt;font-size:${fmtPt(textPt)}pt;` + (layout.bold ? "font-weight:bold;" : "") + `font-family:"${textFamily}";mso-ansi-language:HU;}`,
353
399
  `span.${charClass} {mso-style-name:"${safeStyleName(names.textusChar)}";mso-ansi-language:HU;}`
354
400
  ].join("\n");
@@ -367,7 +413,7 @@ async function toWordHtml(source, options = {}) {
367
413
  const stopPx = line.breakMarkerLeftPx !== void 0 ? markerStopPx(layout, line) : layout.starTarget;
368
414
  const markerStop = stopPx !== layout.starTarget ? ` style="tab-stops:right ${fmtPt(stopPx * PT_PER_PX)}pt"` : "";
369
415
  const marker = line.breakMarkerLeftPx !== void 0 ? `<span style="mso-tab-count:1">${" ".repeat(Math.max(1, Math.round((line.breakMarkerLeftPx + layout.starWidth) / spacePx)))}</span>*` : "";
370
- paragraphs.push(`<p class="${notaClass}"${markerStop}><span style="letter-spacing:-.1pt">${escapeHtml(notesText(line))}</span>${marker}</p>`);
416
+ paragraphs.push(`<p class="${notaClass}"${markerStop}><span style="letter-spacing:${wordPt(notesSpacingPt)}">${escapeHtml(notesText(line))}</span>${marker}</p>`);
371
417
  for (const text of line.texts) paragraphs.push(`<p class="${textusClass}">` + walkTextLine(text, meter, {
372
418
  spacer: spacerHtml,
373
419
  dash: (parts) => parts ? partHtml(parts[0], layout.textPx) : "-",
@@ -421,6 +467,7 @@ function wordRuns(part, textPx) {
421
467
  else if (style.uppercase) base.allCaps = true;
422
468
  const color = resolveColor(style.color);
423
469
  if (color) base.color = color;
470
+ if (style.underline) base.underline = true;
424
471
  if (style.raise) base.raisePt = textPx * style.raise * PT_PER_PX;
425
472
  if (part.kind) base.kind = part.kind;
426
473
  if (style.initial) base.initial = true;
@@ -486,7 +533,25 @@ async function layoutForWord(source, options = {}) {
486
533
  case "gap":
487
534
  spacerTo(seg.endPx);
488
535
  break;
489
- case "connector":
536
+ case "connector": {
537
+ const c = meter.connector(seg.dashStartPx, seg.dashWidth, seg.nextAnchorPx, emitted);
538
+ if (c.before > 0) text.push({
539
+ type: "spacer",
540
+ count: c.before,
541
+ endPt: c.dashAtPx * PT_PER_PX
542
+ });
543
+ text.push(seg.parts ? {
544
+ type: "dash",
545
+ run: wordRuns(seg.parts[0], layout.textPx)[0]
546
+ } : { type: "dash" });
547
+ if (c.after > 0) text.push({
548
+ type: "spacer",
549
+ count: c.after,
550
+ endPt: c.emittedPx * PT_PER_PX
551
+ });
552
+ emitted = c.emittedPx;
553
+ break;
554
+ }
490
555
  case "line-end-dash":
491
556
  spacerTo(seg.dashStartPx);
492
557
  text.push(seg.parts ? {
@@ -494,7 +559,7 @@ async function layoutForWord(source, options = {}) {
494
559
  run: wordRuns(seg.parts[0], layout.textPx)[0]
495
560
  } : { type: "dash" });
496
561
  emitted += seg.dashWidth;
497
- spacerTo(seg.kind === "connector" ? seg.nextAnchorPx : seg.trailEndPx);
562
+ spacerTo(seg.trailEndPx);
498
563
  break;
499
564
  case "syl":
500
565
  for (const part of seg.parts) for (const run of wordRuns(part, layout.textPx)) text.push({
@@ -503,6 +568,14 @@ async function layoutForWord(source, options = {}) {
503
568
  });
504
569
  emitted += seg.textWidth;
505
570
  break;
571
+ case "mark":
572
+ spacerTo(seg.textStart);
573
+ for (const part of seg.parts) for (const run of wordRuns(part, layout.textPx)) text.push({
574
+ type: "run",
575
+ run
576
+ });
577
+ emitted += seg.textWidth;
578
+ break;
506
579
  case "word-space":
507
580
  text.push({ type: "space" });
508
581
  emitted += seg.width;
@@ -528,8 +601,9 @@ async function layoutForWord(source, options = {}) {
528
601
  notesPt,
529
602
  notesLineHeightPt: notesPt * LINE_HEIGHT_RATIO,
530
603
  textLineHeightPt: textPt * LINE_HEIGHT_RATIO,
531
- textFontFamily: firstFontFamily(layout.styleSet.textFontStack),
604
+ textFontFamily: firstFontFamily(layout.textFontStack),
532
605
  notesFontFamily: NOTES_FONT_FAMILY,
606
+ notesLetterSpacingPt: notesSpacing(options),
533
607
  maxWidthPt: layout.maxWidthPx * PT_PER_PX,
534
608
  breakTabStopPt: finite ? layout.starTarget * PT_PER_PX : null,
535
609
  spacer: {
@@ -836,6 +910,27 @@ function collectTokens(el) {
836
910
  }
837
911
  return mergeAdjacentSpacers(split);
838
912
  }
913
+ /** The distinct letter-spacings Word applies to a notes paragraph's
914
+ * characters, pt: each text node takes the nearest letter-spacing in a
915
+ * style attribute up to the paragraph, else the paragraph style's. The
916
+ * break marker's tab and star are left out. */
917
+ function notesLetterSpacings(p, styleSpacing) {
918
+ const found = /* @__PURE__ */ new Set();
919
+ const walker = p.ownerDocument.createTreeWalker(p, 4);
920
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
921
+ if (!(node.textContent ?? "").replace(/[\s\u00A0*]/g, "")) continue;
922
+ let spacing = styleSpacing;
923
+ for (let el = node.parentElement; el; el = el === p ? null : el.parentElement) {
924
+ const style = el.getAttribute("style") ?? "";
925
+ if (/letter-spacing:/.test(style)) {
926
+ spacing = letterSpacingOf(style);
927
+ break;
928
+ }
929
+ }
930
+ found.add(spacing);
931
+ }
932
+ return [...found];
933
+ }
839
934
  function letterSpacingOf(style) {
840
935
  const m = /letter-spacing:\s*(-?[\d.]+)pt/.exec(style);
841
936
  return m ? parseFloat(m[1]) : 0;
@@ -937,13 +1032,19 @@ function pickTextusFont(styleText) {
937
1032
  }
938
1033
  return "12px serif";
939
1034
  }
1035
+ var PT_PER_CM = 72 / 2.54;
1036
+ /** A tab interval as Word's dialog takes it: cm to two decimals, and the
1037
+ * exact pt — "0.05 cm (1.42 pt)". */
1038
+ function describeTabInterval(pt) {
1039
+ return `${(Math.round(pt / PT_PER_CM * 100) / 100).toFixed(2)} cm (${(Math.round(pt * 100) / 100).toString()} pt)`;
1040
+ }
940
1041
  /**
941
1042
  * Checks a pasted Word HTML document (the text/html clipboard flavour).
942
1043
  * Returns the positioned issues, the paragraph structure, the style names
943
1044
  * in use, and the gap census. `ok` is false when any error-level issue
944
1045
  * was found; warnings alone keep it true.
945
1046
  */
946
- function checkWordHtml(html) {
1047
+ function checkWordHtml(html, options = {}) {
947
1048
  const issues = [];
948
1049
  const error = (message, paragraph, offset) => issues.push({
949
1050
  severity: "error",
@@ -962,9 +1063,11 @@ function checkWordHtml(html) {
962
1063
  const styleNames = /* @__PURE__ */ new Set();
963
1064
  for (const m of styleText.matchAll(/mso-style-name:\s*"([^"]+)"/g)) styleNames.add(m[1]);
964
1065
  const classToName = /* @__PURE__ */ new Map();
1066
+ const classLetterSpacing = /* @__PURE__ */ new Map();
965
1067
  for (const m of styleText.matchAll(/p\.([A-Za-z0-9_-]+)\s*\{([^}]*)\}/g)) {
966
1068
  const name = /mso-style-name:\s*"([^"]+)"/.exec(m[2])?.[1];
967
1069
  if (name) classToName.set(m[1], name);
1070
+ if (/letter-spacing:/.test(m[2])) classLetterSpacing.set(m[1], letterSpacingOf(m[2]));
968
1071
  }
969
1072
  const bodyStyle = doc.body?.getAttribute("style") ?? "";
970
1073
  const unitPt = /tab-interval:\s*([\d.]+)pt/.exec(bodyStyle)?.[1] ? parseFloat(/tab-interval:\s*([\d.]+)pt/.exec(bodyStyle)[1]) : null;
@@ -1007,8 +1110,15 @@ function checkWordHtml(html) {
1007
1110
  if (next === void 0 || next.kind !== "textus") error(`Paragraph ${i + 1} is a notes line without a text line after it — every notes line pairs with a text line`, i);
1008
1111
  });
1009
1112
  const lastNota = paragraphs.findLast((para) => para.kind === "nota");
1010
- for (const para of paragraphs) if (para.kind === "nota") checkNotesParagraph(para, para === lastNota, error, warn);
1011
- else if (para.kind === "textus") checkTextParagraph(para, error, warn);
1113
+ const expectedSpacing = options.notesLetterSpacingPt ?? 0;
1114
+ for (const para of paragraphs) if (para.kind === "nota") {
1115
+ checkNotesParagraph(para, para === lastNota, error, warn);
1116
+ const spacings = notesLetterSpacings(para.el, classLetterSpacing.get(para.el.getAttribute("class") ?? "") ?? 0).filter((pt) => Math.abs(pt - expectedSpacing) > .005);
1117
+ if (spacings.length > 0) {
1118
+ const found = spacings.map((pt) => `${pt}pt`).join(", ");
1119
+ warn(`Paragraph ${para.index + 1}: the notes have letter-spacing ${found}, but the score was laid out with ${expectedSpacing}pt — the text drifts off its notes by the difference after every notes character. Set the notes' character spacing back (Format › Font › Advanced › Spacing).`, para.index);
1120
+ }
1121
+ } else if (para.kind === "textus") checkTextParagraph(para, error, warn);
1012
1122
  const gapMap = /* @__PURE__ */ new Map();
1013
1123
  let letterSpacingPt = null;
1014
1124
  for (const para of paragraphs) {
@@ -1040,6 +1150,9 @@ function checkWordHtml(html) {
1040
1150
  };
1041
1151
  });
1042
1152
  const mechanisms = new Set(gaps.map((g) => g.mechanism));
1153
+ const expected = options.expectedTabIntervalPt;
1154
+ const tabSpacers = gaps.some((g) => g.mechanism === "tab" && g.gapClass !== "line-end");
1155
+ if (expected !== void 0 && tabSpacers && unitPt !== null && Math.abs(unitPt - expected) > .05) error(`Default tab stops don’t match: the document’s are ${describeTabInterval(unitPt)}, the copy expects ${describeTabInterval(expected)}. Word keeps the document’s own Default tab stops when you paste, so the tab spacers land in the wrong places. Set them to ${describeTabInterval(expected)} and paste again. Windows: Home › Paragraph dialog launcher › Tabs… › Default tab stops. Mac: Format › Tabs… › Default tab stops.`);
1043
1156
  return {
1044
1157
  ok: !issues.some((i) => i.severity === "error"),
1045
1158
  issues,
@@ -57,10 +57,27 @@ export interface WordCheckReport {
57
57
  * and to a default serif when nothing identifiable remains.
58
58
  */
59
59
  export declare function pickTextusFont(styleText: string): string;
60
+ /** Where Word's Default tab stops live — the document-wide setting a tab
61
+ * spacer depends on. */
62
+ export declare const WORD_DEFAULT_TAB_STOPS_WHERE = "Windows: Home \u203A Paragraph dialog launcher \u203A Tabs\u2026 \u203A Default tab stops. Mac: Format \u203A Tabs\u2026 \u203A Default tab stops.";
63
+ /** A tab interval as Word's dialog takes it: cm to two decimals, and the
64
+ * exact pt — "0.05 cm (1.42 pt)". */
65
+ export declare function describeTabInterval(pt: number): string;
66
+ export interface WordCheckOptions {
67
+ /** The tab interval the copy was made with, pt (the tab spacer's
68
+ * width). When the pasted text uses tab spacers and the document's
69
+ * Default tab stops differ, the report says so: Word keeps the
70
+ * destination document's own interval on paste, and every tab
71
+ * spacer then lands on the wrong grid. */
72
+ expectedTabIntervalPt?: number;
73
+ /** The notes letter-spacing the score was copied with, pt (default:
74
+ * the export's, 0) */
75
+ notesLetterSpacingPt?: number;
76
+ }
60
77
  /**
61
78
  * Checks a pasted Word HTML document (the text/html clipboard flavour).
62
79
  * Returns the positioned issues, the paragraph structure, the style names
63
80
  * in use, and the gap census. `ok` is false when any error-level issue
64
81
  * was found; warnings alone keep it true.
65
82
  */
66
- export declare function checkWordHtml(html: string): WordCheckReport;
83
+ export declare function checkWordHtml(html: string, options?: WordCheckOptions): WordCheckReport;
@@ -1,5 +1,13 @@
1
1
  import { ChantRunKind, MarkDefinitions, StyleSetName } from './guidoStyles';
2
2
  import { LayoutSource, StaffFill } from './chantLayout';
3
+ /** The notes' letter-spacing in Word, pt. Word adds it after every notes
4
+ * character, so the layout measures with the same value: the export once
5
+ * condensed the notes by 0.1pt without measuring it, which pulled each
6
+ * note 0.1pt further left per character than the text's spacers expected
7
+ * (several points by a line's end, whatever the spacer width). Written
8
+ * explicitly on every notes run, so a destination style that condenses
9
+ * its notes cannot move them either. */
10
+ export declare const NOTES_LETTER_SPACING_PT = 0;
3
11
  /** The spacer character faking every horizontal gap. A custom character
4
12
  * (any non-empty string) is emitted verbatim. */
5
13
  export type SpacerChar = 'tab' | 'en' | 'em' | 'nbsp' | 'space' | (string & {});
@@ -69,12 +77,29 @@ export interface WordExportOptions {
69
77
  /** With `staffFill: 'longest'`: the distance from the available width
70
78
  * within which every line runs to it instead (default 0) */
71
79
  staffFillSnapPx?: number;
80
+ /** The gap between a broken line's notes and its break star, px at the
81
+ * layout's size (with the pt options, Word's px: pt × 4/3); default:
82
+ * the style set's padding, 12. With `maxWidthPt` the notes break this
83
+ * far short of the column. */
84
+ paddingPx?: number;
85
+ /** The syllable text's font, an installed font by name (default: the
86
+ * style set's). The copy names it in the BNS-textus style, so Word
87
+ * needs it installed too. */
88
+ textFont?: string;
72
89
  /** Render a recitation that covers exactly 2 syllables on a line as
73
90
  * plain notes of the same pitch (default true, issue #21) */
74
91
  twoSyllableRecitationsToPlain?: boolean;
75
92
  /** Render 3 or more syllables on one plain note with a reciting glyph
76
93
  * (`1`–`9`, `ö`, `ü`) on a line as a recitation (default false) */
77
94
  plainRunsToRecitation?: boolean;
95
+ /** Draw a `**()` star right after a group closing with a bar centred
96
+ * under the bar, moving nothing (default true); `false` sets it between
97
+ * the syllables */
98
+ starUnderBar?: boolean;
99
+ /** Cut an empty slot (`~(…)`) that does not fit at a line end at its
100
+ * dashes, like a sung group (default true); `false` moves it whole to
101
+ * a fresh line first, as held groups do */
102
+ cutEmptySlots?: boolean;
78
103
  /** Text line size in pt at the DESTINATION document (default: none —
79
104
  * textPx governs). Takes precedence over textPx; notes default to
80
105
  * twice the text size (the established BNS ratio). Laying out at the
@@ -86,10 +111,16 @@ export interface WordExportOptions {
86
111
  /** Notes line size in pt at the destination document (default:
87
112
  * textPt × 2, or notesPx). Takes precedence over notesPx. */
88
113
  notesPt?: number;
89
- /** Maximum notes-line width before a staff break, in pt at the
90
- * destination document (default: maxWidthPx). Takes precedence over
91
- * maxWidthPx. */
114
+ /** The destination document's column, pt: the break stars' right
115
+ * edge lands on it, and the notes break the style set's padding short
116
+ * of it (default: maxWidthPx, which is the notes width, with the stars
117
+ * the padding past it). Takes precedence over maxWidthPx. */
92
118
  maxWidthPt?: number;
119
+ /** The notes' letter-spacing in Word, pt (default 0; -0.1 condenses
120
+ * the notes as some BNS documents do). The notes runs carry it and the
121
+ * layout measures with it, so the text stays under the notes Word
122
+ * draws. */
123
+ notesLetterSpacingPt?: number;
93
124
  /** The spacer mechanism faking every gap (default: a no-break space
94
125
  * at its natural advance) */
95
126
  spacer?: SpacerConfig;
@@ -127,6 +158,18 @@ export declare class SpacerMeter {
127
158
  count: number;
128
159
  emittedPx: number;
129
160
  };
161
+ /** A same-word connector: spacers to the dash, the dash, spacers to
162
+ * the next syllable, rounded as a pair (issue #124). Rounding each
163
+ * side alone can leave spacers before the dash and none after, gluing
164
+ * the hyphen to the next syllable (`ec -ce`); then one unit moves
165
+ * after the dash (`ec- ce`). The far side still targets `nextPx`, so
166
+ * no error accumulates. */
167
+ connector(dashStartPx: number, dashWidthPx: number, nextPx: number, emittedPx: number): {
168
+ before: number;
169
+ dashAtPx: number;
170
+ after: number;
171
+ emittedPx: number;
172
+ };
130
173
  }
131
174
  /**
132
175
  * Renders the score as Word-flavoured HTML: one `nota` paragraph (notes)
@@ -155,6 +198,8 @@ export interface WordRun {
155
198
  allCaps?: boolean;
156
199
  /** Word's Small Caps: the text stays as written */
157
200
  smallCaps?: boolean;
201
+ /** Underlined (the `u` mark) */
202
+ underline?: boolean;
158
203
  /** Raise above the baseline, pt */
159
204
  raisePt?: number;
160
205
  /** Set when the text has no glyph in the destination fonts: emit
@@ -229,6 +274,9 @@ export interface WordLayout {
229
274
  textFontFamily: string;
230
275
  /** The notes paragraph's font family, Word's real name ("Guido HU") */
231
276
  notesFontFamily: string;
277
+ /** The notes' letter-spacing (Word's condensed spacing), pt: the
278
+ * layout assumes it, so the notes runs must carry it */
279
+ notesLetterSpacingPt: number;
232
280
  /** The width the lines were broken at, pt (Infinity: unbroken) */
233
281
  maxWidthPt: number;
234
282
  /** The nota style's right tab stop for break markers, pt — null at
@@ -18,7 +18,7 @@
18
18
 
19
19
  <div class="demo-box">
20
20
  <h2>Default: auto width, BNS style</h2>
21
- <div class="guido-script">(MX)Ki(3)rály(3)ként(5) tró(7i)nol(7-:) **() az(7i) Úr(5-/) mind(5)ö(4t)rök(3)ké.(3-.)</div>
21
+ <div class="guido-script">(MX)Ki(3)rály(3)ként(5) tró(7i)nol(7-:) **() az(7i) Úr(5-/) mind(5)ö(4t)rök(3)re.(3-.)</div>
22
22
  </div>
23
23
 
24
24
  <div class="demo-box" style="width: 420px">
@@ -28,7 +28,7 @@
28
28
 
29
29
  <div class="demo-box">
30
30
  <h2>data-style="Vesperale" data-transpose="2"</h2>
31
- <div class="guido-script" data-style="Vesperale" data-transpose="2">(MX)Ki(3)rály(3)ként(5) tró(7i)nol(7-:) **() az(7i) Úr(5-/) mind(5)ö(4t)rök(3)ké.(3-.)</div>
31
+ <div class="guido-script" data-style="Vesperale" data-transpose="2">(MX)Ki(3)rály(3)ként(5) tró(7i)nol(7-:) **() az(7i) Úr(5-/) mind(5)ö(4t)rök(3)re.(3-.)</div>
32
32
  </div>
33
33
  </body>
34
34
  </html>
Binary file