@nodelyra/not-angka 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +38 -2
- package/THIRD_PARTY.md +24 -0
- package/dist/esm/cursor/activeChord.d.ts +12 -0
- package/dist/esm/cursor/activeChord.js +36 -0
- package/dist/esm/cursor/beatDot.d.ts +30 -0
- package/dist/esm/cursor/beatDot.js +49 -0
- package/dist/esm/cursor/drawnTop.d.ts +9 -0
- package/dist/esm/cursor/drawnTop.js +16 -0
- package/dist/esm/cursor/pageBoxes.d.ts +28 -0
- package/dist/esm/cursor/pageBoxes.js +75 -0
- package/dist/esm/cursor/playbackCursor.d.ts +25 -0
- package/dist/esm/cursor/playbackCursor.js +42 -0
- package/dist/esm/cursor/playingStyle.d.ts +16 -0
- package/dist/esm/cursor/playingStyle.js +34 -0
- package/dist/esm/cursor/playingTones.d.ts +8 -0
- package/dist/esm/cursor/playingTones.js +16 -0
- package/dist/esm/cursor/target.d.ts +47 -0
- package/dist/esm/cursor/target.js +63 -0
- package/dist/esm/export/pageText.d.ts +8 -0
- package/dist/esm/export/pageText.js +80 -0
- package/dist/esm/export/svgExport.d.ts +46 -0
- package/dist/esm/export/svgExport.js +88 -0
- package/dist/esm/geometry/metrics.d.ts +42 -0
- package/dist/esm/geometry/metrics.js +52 -0
- package/dist/esm/geometry/pageSetup.d.ts +61 -0
- package/dist/esm/geometry/pageSetup.js +85 -0
- package/dist/esm/geometry/paper.d.ts +16 -0
- package/dist/esm/geometry/paper.js +16 -0
- package/dist/esm/index.d.ts +35 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/layout/LayoutEngine.d.ts +64 -0
- package/dist/esm/layout/LayoutEngine.js +92 -0
- package/dist/esm/layout/arcs.d.ts +20 -0
- package/dist/esm/layout/arcs.js +53 -0
- package/dist/esm/layout/barlineShapes.d.ts +52 -0
- package/dist/esm/layout/barlineShapes.js +71 -0
- package/dist/esm/layout/directions.d.ts +48 -0
- package/dist/esm/layout/directions.js +122 -0
- package/dist/esm/layout/elementBoxes.d.ts +17 -0
- package/dist/esm/layout/elementBoxes.js +72 -0
- package/dist/esm/layout/floating.d.ts +29 -0
- package/dist/esm/layout/floating.js +39 -0
- package/dist/esm/layout/keyMarks.d.ts +26 -0
- package/dist/esm/layout/keyMarks.js +30 -0
- package/dist/esm/layout/lyricAlign.d.ts +6 -0
- package/dist/esm/layout/lyricAlign.js +15 -0
- package/dist/esm/layout/lyricWords.d.ts +13 -0
- package/dist/esm/layout/lyricWords.js +27 -0
- package/dist/esm/layout/lyricsLayout.d.ts +55 -0
- package/dist/esm/layout/lyricsLayout.js +122 -0
- package/dist/esm/layout/markings.d.ts +97 -0
- package/dist/esm/layout/markings.js +150 -0
- package/dist/esm/layout/measurePlan.d.ts +74 -0
- package/dist/esm/layout/measurePlan.js +232 -0
- package/dist/esm/layout/measureSegments.d.ts +24 -0
- package/dist/esm/layout/measureSegments.js +64 -0
- package/dist/esm/layout/notationMetrics.d.ts +110 -0
- package/dist/esm/layout/notationMetrics.js +122 -0
- package/dist/esm/layout/systemBreaking.d.ts +59 -0
- package/dist/esm/layout/systemBreaking.js +137 -0
- package/dist/esm/layout/systemLayout.d.ts +138 -0
- package/dist/esm/layout/systemLayout.js +266 -0
- package/dist/esm/layout/tupletSpacing.d.ts +9 -0
- package/dist/esm/layout/tupletSpacing.js +33 -0
- package/dist/esm/layout/tuplets.d.ts +30 -0
- package/dist/esm/layout/tuplets.js +39 -0
- package/dist/esm/model/hiddenParts.d.ts +23 -0
- package/dist/esm/model/hiddenParts.js +39 -0
- package/dist/esm/model/locate.d.ts +18 -0
- package/dist/esm/model/locate.js +31 -0
- package/dist/esm/model/lowVoices.d.ts +9 -0
- package/dist/esm/model/lowVoices.js +20 -0
- package/dist/esm/model/partColors.d.ts +13 -0
- package/dist/esm/model/partColors.js +10 -0
- package/dist/esm/model/partSpan.d.ts +25 -0
- package/dist/esm/model/partSpan.js +49 -0
- package/dist/esm/model/rowPresence.d.ts +14 -0
- package/dist/esm/model/rowPresence.js +19 -0
- package/dist/esm/model/sharedLyrics.d.ts +23 -0
- package/dist/esm/model/sharedLyrics.js +68 -0
- package/dist/esm/model/textBars.d.ts +12 -0
- package/dist/esm/model/textBars.js +21 -0
- package/dist/esm/model/tickRanges.d.ts +22 -0
- package/dist/esm/model/tickRanges.js +34 -0
- package/dist/esm/model/unisons.d.ts +69 -0
- package/dist/esm/model/unisons.js +181 -0
- package/dist/esm/notation/chords.d.ts +12 -0
- package/dist/esm/notation/chords.js +29 -0
- package/dist/esm/notation/elision.d.ts +24 -0
- package/dist/esm/notation/elision.js +47 -0
- package/dist/esm/notation/keys.d.ts +50 -0
- package/dist/esm/notation/keys.js +59 -0
- package/dist/esm/notation/lyricAlign.d.ts +7 -0
- package/dist/esm/notation/lyricAlign.js +15 -0
- package/dist/esm/notation/navigation.d.ts +3 -0
- package/dist/esm/notation/navigation.js +5 -0
- package/dist/esm/notation/pitch.d.ts +39 -0
- package/dist/esm/notation/pitch.js +74 -0
- package/dist/esm/notation/pitchName.d.ts +2 -0
- package/dist/esm/notation/pitchName.js +3 -0
- package/dist/esm/notation/profile.d.ts +35 -0
- package/dist/esm/notation/profile.js +16 -0
- package/dist/esm/notation/rhythm.d.ts +59 -0
- package/dist/esm/notation/rhythm.js +116 -0
- package/dist/esm/notation/time.d.ts +98 -0
- package/dist/esm/notation/time.js +85 -0
- package/dist/esm/performance/compilePerformance.d.ts +7 -0
- package/dist/esm/performance/compilePerformance.js +8 -0
- package/dist/esm/performance/dynamics.d.ts +6 -0
- package/dist/esm/performance/dynamics.js +78 -0
- package/dist/esm/performance/model.d.ts +56 -0
- package/dist/esm/performance/model.js +1 -0
- package/dist/esm/performance/playOrder.d.ts +16 -0
- package/dist/esm/performance/playOrder.js +64 -0
- package/dist/esm/performance/readScore.d.ts +4 -0
- package/dist/esm/performance/readScore.js +58 -0
- package/dist/esm/performance/timeline.d.ts +10 -0
- package/dist/esm/performance/timeline.js +144 -0
- package/dist/esm/playback/audioOutput.d.ts +46 -0
- package/dist/esm/playback/audioOutput.js +106 -0
- package/dist/esm/playback/clock.d.ts +16 -0
- package/dist/esm/playback/clock.js +44 -0
- package/dist/esm/playback/createPlayerStore.d.ts +79 -0
- package/dist/esm/playback/createPlayerStore.js +135 -0
- package/dist/esm/playback/cues.d.ts +34 -0
- package/dist/esm/playback/cues.js +52 -0
- package/dist/esm/playback/errors.d.ts +6 -0
- package/dist/esm/playback/errors.js +6 -0
- package/dist/esm/playback/metronome.d.ts +13 -0
- package/dist/esm/playback/metronome.js +15 -0
- package/dist/esm/playback/mix.d.ts +9 -0
- package/dist/esm/playback/mix.js +8 -0
- package/dist/esm/playback/pass.d.ts +27 -0
- package/dist/esm/playback/pass.js +36 -0
- package/dist/esm/playback/schedule.d.ts +7 -0
- package/dist/esm/playback/schedule.js +12 -0
- package/dist/esm/playback/session.d.ts +46 -0
- package/dist/esm/playback/session.js +107 -0
- package/dist/esm/playback/source.d.ts +6 -0
- package/dist/esm/playback/source.js +1 -0
- package/dist/esm/playback/start.d.ts +28 -0
- package/dist/esm/playback/start.js +38 -0
- package/dist/esm/playback/timing.d.ts +14 -0
- package/dist/esm/playback/timing.js +11 -0
- package/dist/esm/playback/types.d.ts +60 -0
- package/dist/esm/playback/types.js +1 -0
- package/dist/esm/playback/volume.d.ts +12 -0
- package/dist/esm/playback/volume.js +8 -0
- package/dist/esm/player/ControlBar.d.ts +22 -0
- package/dist/esm/player/ControlBar.js +77 -0
- package/dist/esm/player/CursorPainter.d.ts +17 -0
- package/dist/esm/player/CursorPainter.js +53 -0
- package/dist/esm/player/InfoLine.d.ts +6 -0
- package/dist/esm/player/InfoLine.js +23 -0
- package/dist/esm/player/PageView.d.ts +10 -0
- package/dist/esm/player/PageView.js +16 -0
- package/dist/esm/player/actions.d.ts +24 -0
- package/dist/esm/player/actions.js +26 -0
- package/dist/esm/player/balanceSystems.d.ts +8 -0
- package/dist/esm/player/balanceSystems.js +18 -0
- package/dist/esm/player/createExcerptPlayer.d.ts +33 -0
- package/dist/esm/player/createExcerptPlayer.js +169 -0
- package/dist/esm/player/createScorePlayer.d.ts +24 -0
- package/dist/esm/player/createScorePlayer.js +118 -0
- package/dist/esm/player/dom.d.ts +6 -0
- package/dist/esm/player/dom.js +15 -0
- package/dist/esm/player/embeddedFonts.d.ts +1 -0
- package/dist/esm/player/embeddedFonts.js +3 -0
- package/dist/esm/player/exclusivePlayback.d.ts +10 -0
- package/dist/esm/player/exclusivePlayback.js +13 -0
- package/dist/esm/player/followCursor.d.ts +5 -0
- package/dist/esm/player/followCursor.js +16 -0
- package/dist/esm/player/icons.d.ts +7 -0
- package/dist/esm/player/icons.js +9 -0
- package/dist/esm/player/injectFonts.d.ts +8 -0
- package/dist/esm/player/injectFonts.js +19 -0
- package/dist/esm/player/loadExcerpt.d.ts +21 -0
- package/dist/esm/player/loadExcerpt.js +123 -0
- package/dist/esm/player/loadScore.d.ts +12 -0
- package/dist/esm/player/loadScore.js +12 -0
- package/dist/esm/player/mountExcerpts.d.ts +30 -0
- package/dist/esm/player/mountExcerpts.js +109 -0
- package/dist/esm/player/playhead.d.ts +12 -0
- package/dist/esm/player/playhead.js +14 -0
- package/dist/esm/player/shadowStyles.d.ts +5 -0
- package/dist/esm/player/shadowStyles.js +23 -0
- package/dist/esm/player/staticSvg.d.ts +7 -0
- package/dist/esm/player/staticSvg.js +10 -0
- package/dist/esm/player/styles.d.ts +28 -0
- package/dist/esm/player/styles.js +98 -0
- package/dist/esm/player/theme.d.ts +8 -0
- package/dist/esm/player/theme.js +13 -0
- package/dist/esm/player/types.d.ts +76 -0
- package/dist/esm/player/types.js +12 -0
- package/dist/esm/rendering/SystemRenderer.d.ts +6 -0
- package/dist/esm/rendering/SystemRenderer.js +58 -0
- package/dist/esm/rendering/accidentalRenderer.d.ts +4 -0
- package/dist/esm/rendering/accidentalRenderer.js +41 -0
- package/dist/esm/rendering/arcRenderer.d.ts +9 -0
- package/dist/esm/rendering/arcRenderer.js +32 -0
- package/dist/esm/rendering/barlineRenderer.d.ts +8 -0
- package/dist/esm/rendering/barlineRenderer.js +59 -0
- package/dist/esm/rendering/directionRenderer.d.ts +4 -0
- package/dist/esm/rendering/directionRenderer.js +50 -0
- package/dist/esm/rendering/durationLineRenderer.d.ts +9 -0
- package/dist/esm/rendering/durationLineRenderer.js +27 -0
- package/dist/esm/rendering/dynamicGlyphs.d.ts +25 -0
- package/dist/esm/rendering/dynamicGlyphs.js +56 -0
- package/dist/esm/rendering/frameRenderer.d.ts +17 -0
- package/dist/esm/rendering/frameRenderer.js +252 -0
- package/dist/esm/rendering/keyMarkRenderer.d.ts +8 -0
- package/dist/esm/rendering/keyMarkRenderer.js +57 -0
- package/dist/esm/rendering/lyricsRenderer.d.ts +4 -0
- package/dist/esm/rendering/lyricsRenderer.js +44 -0
- package/dist/esm/rendering/primitives.d.ts +64 -0
- package/dist/esm/rendering/primitives.js +1 -0
- package/dist/esm/rendering/sliceRenderer.d.ts +19 -0
- package/dist/esm/rendering/sliceRenderer.js +79 -0
- package/dist/esm/rendering/textBarRenderer.d.ts +8 -0
- package/dist/esm/rendering/textBarRenderer.js +28 -0
- package/dist/esm/rendering/tupletRenderer.d.ts +7 -0
- package/dist/esm/rendering/tupletRenderer.js +42 -0
- package/dist/esm/schema/normalize.d.ts +14 -0
- package/dist/esm/schema/normalize.js +123 -0
- package/dist/esm/schema/pageMeta.d.ts +11 -0
- package/dist/esm/schema/pageMeta.js +1 -0
- package/dist/esm/schema/scoreJson.d.ts +59 -0
- package/dist/esm/schema/scoreJson.js +1 -0
- package/dist/esm/schema/scoreView.d.ts +16 -0
- package/dist/esm/schema/scoreView.js +24 -0
- package/dist/esm/schema/types.d.ts +339 -0
- package/dist/esm/schema/types.js +1 -0
- package/dist/esm/text/creditLines.d.ts +12 -0
- package/dist/esm/text/creditLines.js +11 -0
- package/dist/esm/text/fonts.d.ts +50 -0
- package/dist/esm/text/fonts.js +98 -0
- package/dist/esm/text/headerFooter.d.ts +13 -0
- package/dist/esm/text/headerFooter.js +21 -0
- package/dist/esm/text/textLines.d.ts +7 -0
- package/dist/esm/text/textLines.js +13 -0
- package/dist/index.cjs +65 -0
- package/dist/index.cjs.map +1 -0
- package/dist/nodelyra-player.global.js +65 -0
- package/dist/nodelyra-player.global.js.map +1 -0
- package/dist/nodelyra-player.lite.global.js +63 -0
- package/dist/nodelyra-player.lite.global.js.map +1 -0
- package/examples/blog-excerpt.html +54 -0
- package/examples/twinkle.html +23 -0
- package/examples/twinkle.json +91 -0
- package/package.json +70 -4
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { INFO_LINE_HEIGHT, SMALL_TITLE_HEIGHT, subtitleLineHeight, titleLineHeight, titleRowsHeight, } from "../geometry/metrics.js";
|
|
2
|
+
import { creditLines } from "../text/creditLines.js";
|
|
3
|
+
import { renderHeaderFooterText } from "../text/headerFooter.js";
|
|
4
|
+
import { textLineCount } from "../text/textLines.js";
|
|
5
|
+
/**
|
|
6
|
+
* The page's words as text primitives, for the SVG export (the editor draws them as HTML, see
|
|
7
|
+
* ADR 0001). Same rows and sizes as the HTML heading, so an exported page matches the screen.
|
|
8
|
+
* Coordinates are page coordinates (px from the sheet's top-left).
|
|
9
|
+
*/
|
|
10
|
+
const text = (x, y, value, size, anchor, options = {}) => ({
|
|
11
|
+
kind: "text",
|
|
12
|
+
role: "page-text",
|
|
13
|
+
x,
|
|
14
|
+
y,
|
|
15
|
+
text: value,
|
|
16
|
+
size,
|
|
17
|
+
anchor,
|
|
18
|
+
font: "text",
|
|
19
|
+
tone: "ink",
|
|
20
|
+
...options,
|
|
21
|
+
});
|
|
22
|
+
const ANCHOR = { left: "start", center: "middle", right: "end" };
|
|
23
|
+
function alignedX(align, m) {
|
|
24
|
+
if (align === "left")
|
|
25
|
+
return m.margin.left;
|
|
26
|
+
if (align === "right")
|
|
27
|
+
return m.width - m.margin.right;
|
|
28
|
+
return m.margin.left + m.contentWidth / 2;
|
|
29
|
+
}
|
|
30
|
+
/** Title, subtitle, info lines (left) and credits (right) at the top of page 1. */
|
|
31
|
+
export function headingText(setup, m, title, subtitle, context) {
|
|
32
|
+
const h = setup.header;
|
|
33
|
+
const fill = (t) => renderHeaderFooterText(t, context);
|
|
34
|
+
const x = alignedX(h.title_align, m);
|
|
35
|
+
const anchor = ANCHOR[h.title_align];
|
|
36
|
+
const top = m.margin.top;
|
|
37
|
+
const titleLine = titleLineHeight(h.title_size);
|
|
38
|
+
const subtitleLine = subtitleLineHeight(h.subtitle_size);
|
|
39
|
+
const titles = title.split("\n").map((line, i) => text(x, top + (i + 0.5) * titleLine, line, h.title_size, anchor, {
|
|
40
|
+
bold: true,
|
|
41
|
+
italic: h.title_italic,
|
|
42
|
+
}));
|
|
43
|
+
const subTop = top + Math.max(1, textLineCount(title)) * titleLine;
|
|
44
|
+
const subtitles = subtitle
|
|
45
|
+
? subtitle.split("\n").map((line, i) => text(x, subTop + (i + 0.5) * subtitleLine, line, h.subtitle_size, anchor, {
|
|
46
|
+
italic: h.subtitle_italic,
|
|
47
|
+
}))
|
|
48
|
+
: [];
|
|
49
|
+
const rowsTop = top +
|
|
50
|
+
titleRowsHeight({ titleLines: textLineCount(title), subtitleLines: textLineCount(subtitle) }, h) +
|
|
51
|
+
4;
|
|
52
|
+
const row = (i) => rowsTop + (i + 0.5) * INFO_LINE_HEIGHT;
|
|
53
|
+
const info = h.info.map((line, i) => text(m.margin.left, row(i), fill(line), 12, "start"));
|
|
54
|
+
const credits = creditLines(h.credits).map((line, i) => text(m.width - m.margin.right, row(i), fill(line), 12, "end", { italic: h.credits_italic }));
|
|
55
|
+
return [...titles, ...subtitles, ...info, ...credits];
|
|
56
|
+
}
|
|
57
|
+
function band(band, y, m, context) {
|
|
58
|
+
const fill = (t) => renderHeaderFooterText(t, context);
|
|
59
|
+
const sides = [
|
|
60
|
+
[band.left, m.margin.left + 20, "start"],
|
|
61
|
+
[band.center, m.width / 2, "middle"],
|
|
62
|
+
[band.right, m.width - m.margin.right - 20, "end"],
|
|
63
|
+
];
|
|
64
|
+
return sides
|
|
65
|
+
.filter(([value]) => value)
|
|
66
|
+
.map(([value, x, anchor]) => text(x, y, fill(value), 10, anchor));
|
|
67
|
+
}
|
|
68
|
+
/** Header and footer text in the margins, and the running title on pages 2+. */
|
|
69
|
+
export function marginText(setup, m, context, firstPage) {
|
|
70
|
+
const running = !firstPage && setup.header.title_block
|
|
71
|
+
? [
|
|
72
|
+
text(m.width - m.margin.right, m.height - m.margin.bottom - SMALL_TITLE_HEIGHT / 2, context.title, 11, "end", { italic: true }),
|
|
73
|
+
]
|
|
74
|
+
: [];
|
|
75
|
+
return [
|
|
76
|
+
...band(setup.header, m.margin.top / 2, m, context),
|
|
77
|
+
...band(setup.footer, m.height - m.margin.bottom / 2, m, context),
|
|
78
|
+
...running,
|
|
79
|
+
];
|
|
80
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ScoreMusic } from "../schema/types.js";
|
|
2
|
+
import type { PageSetup } from "../geometry/pageSetup.js";
|
|
3
|
+
import { type Page } from "../layout/LayoutEngine.js";
|
|
4
|
+
import type { NotationProfile } from "../notation/profile.js";
|
|
5
|
+
import type { FontRole, Primitive, Tone } from "../rendering/primitives.js";
|
|
6
|
+
import type { PageMeta } from "../schema/pageMeta.js";
|
|
7
|
+
/**
|
|
8
|
+
* SVG for a score, from the same layout and renderers as the editor's screen: the SVG export
|
|
9
|
+
* (PRD FR-078, FR-089, AC-019, AC-021) and the player library's pages. The export holds only the
|
|
10
|
+
* score: no selection, hit areas or other editor marks, no app classes, and colors that are
|
|
11
|
+
* explicit (black on white); a viewer can pass its own `style`, ask for `annotate` (every shape
|
|
12
|
+
* says which score element it draws) and for a `cursorLayer` the player paints playback into.
|
|
13
|
+
*/
|
|
14
|
+
export type SvgStyle = {
|
|
15
|
+
ink: string;
|
|
16
|
+
rule: string;
|
|
17
|
+
page: string;
|
|
18
|
+
};
|
|
19
|
+
/** Black on white, as printed. */
|
|
20
|
+
export declare const PRINT_STYLE: SvgStyle;
|
|
21
|
+
export type SvgOptions = {
|
|
22
|
+
/** Colors; black on white by default. */
|
|
23
|
+
style?: SvgStyle;
|
|
24
|
+
/** Add `data-role` and `data-owner` to every shape, so a viewer can find what a shape draws. */
|
|
25
|
+
annotate?: boolean;
|
|
26
|
+
};
|
|
27
|
+
type Fonts = Record<FontRole, string>;
|
|
28
|
+
type Palette = Record<Tone, string>;
|
|
29
|
+
/** What a writer needs besides the shape: the fonts, the colors, and whether to annotate. */
|
|
30
|
+
type Context = {
|
|
31
|
+
fonts: Fonts;
|
|
32
|
+
colors: Palette;
|
|
33
|
+
annotate: boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare const primitiveToSvg: (p: Primitive, context: Context) => string;
|
|
36
|
+
export type SvgExportInput = {
|
|
37
|
+
pages: readonly Page[];
|
|
38
|
+
music: ScoreMusic;
|
|
39
|
+
setup: PageSetup;
|
|
40
|
+
meta: PageMeta;
|
|
41
|
+
profile?: NotationProfile;
|
|
42
|
+
};
|
|
43
|
+
/** One page as a standalone `<svg>` (what a viewer shows), with an empty cursor layer under the notation. */
|
|
44
|
+
export declare function renderPageSvg(input: SvgExportInput, index: number, options?: SvgOptions): string;
|
|
45
|
+
export declare function exportScoreSvg(input: SvgExportInput, options?: SvgOptions): string;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CONTINUATION_TOP_GAP, pageMetrics } from "../geometry/metrics.js";
|
|
2
|
+
import { reservedHeight } from "../layout/LayoutEngine.js";
|
|
3
|
+
import { NOT_ANGKA } from "../notation/profile.js";
|
|
4
|
+
import { renderSystem } from "../rendering/SystemRenderer.js";
|
|
5
|
+
import { resolveFonts } from "../text/fonts.js";
|
|
6
|
+
import { formatTempo } from "../text/headerFooter.js";
|
|
7
|
+
import { singleLine, textLineCount } from "../text/textLines.js";
|
|
8
|
+
import { headingText, marginText } from "./pageText.js";
|
|
9
|
+
/** Black on white, as printed. */
|
|
10
|
+
export const PRINT_STYLE = { ink: "#000", rule: "#555", page: "#fff" };
|
|
11
|
+
const PAGE_GAP = 24;
|
|
12
|
+
const escapeXml = (value) => value.replace(/[<>&"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
13
|
+
const num = (n) => String(Math.round(n * 100) / 100);
|
|
14
|
+
/** Font stacks without the app's CSS variables, which mean nothing outside the app. */
|
|
15
|
+
const standaloneStack = (stack) => escapeXml(stack.replace(/var\([^)]*\),\s*/g, ""));
|
|
16
|
+
/** `data-role` and `data-owner` for a shape, when annotating. */
|
|
17
|
+
const marks = (p, { annotate }) => annotate ? ` data-role="${p.role}"${p.owner ? ` data-owner="${escapeXml(p.owner)}"` : ""}` : "";
|
|
18
|
+
/** One writer per kind of primitive (the string twin of the canvas's `SHAPES`). */
|
|
19
|
+
const SVG_WRITERS = {
|
|
20
|
+
text: (p, c) => `<text${marks(p, c)} x="${num(p.x)}" y="${num(p.y)}" font-size="${p.size}" font-family="${c.fonts[p.font]}" text-anchor="${p.anchor}" dominant-baseline="central"${p.bold ? ' font-weight="bold"' : ""}${p.italic ? ' font-style="italic"' : ""} fill="${c.colors[p.tone]}">${escapeXml(p.text)}</text>`,
|
|
21
|
+
line: (p, c) => `<line${marks(p, c)} x1="${num(p.x1)}" y1="${num(p.y1)}" x2="${num(p.x2)}" y2="${num(p.y2)}" stroke="${c.colors[p.tone]}" stroke-width="${p.width}"/>`,
|
|
22
|
+
circle: (p, c) => `<circle${marks(p, c)} cx="${num(p.cx)}" cy="${num(p.cy)}" r="${p.r}" fill="${c.colors[p.tone]}"/>`,
|
|
23
|
+
path: (p, c) => p.filled
|
|
24
|
+
? `<path${marks(p, c)} d="${p.d}" fill="${c.colors[p.tone]}"/>`
|
|
25
|
+
: `<path${marks(p, c)} d="${p.d}" fill="none" stroke="${c.colors[p.tone]}" stroke-width="${p.width}" stroke-linecap="round" stroke-linejoin="round"/>`,
|
|
26
|
+
};
|
|
27
|
+
export const primitiveToSvg = (p, context) => SVG_WRITERS[p.kind](p, context);
|
|
28
|
+
const contextOf = (setup, { style = PRINT_STYLE, annotate = false }) => {
|
|
29
|
+
const fonts = resolveFonts(setup);
|
|
30
|
+
return {
|
|
31
|
+
fonts: {
|
|
32
|
+
notes: standaloneStack(fonts.notes),
|
|
33
|
+
text: standaloneStack(fonts.text),
|
|
34
|
+
lyrics: standaloneStack(fonts.lyrics),
|
|
35
|
+
volta: standaloneStack(fonts.volta),
|
|
36
|
+
},
|
|
37
|
+
colors: { ink: style.ink, rule: style.rule },
|
|
38
|
+
annotate,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
/** Where the notation starts on a page, in page px: inside the margins, under the heading on page 1. */
|
|
42
|
+
function notationOrigin(input, index) {
|
|
43
|
+
const { setup, meta } = input;
|
|
44
|
+
const m = pageMetrics(setup);
|
|
45
|
+
const lines = { titleLines: textLineCount(meta.title), subtitleLines: textLineCount(meta.subtitle) };
|
|
46
|
+
return { x: m.margin.left, y: m.margin.top + (index === 0 ? reservedHeight(setup, true, lines) : CONTINUATION_TOP_GAP) };
|
|
47
|
+
}
|
|
48
|
+
function pageBody(input, index, context, style, cursorLayer) {
|
|
49
|
+
const { pages, music, setup, meta, profile = NOT_ANGKA } = input;
|
|
50
|
+
const m = pageMetrics(setup);
|
|
51
|
+
const first = index === 0;
|
|
52
|
+
const text = {
|
|
53
|
+
page: index + 1,
|
|
54
|
+
pages: pages.length,
|
|
55
|
+
title: singleLine(meta.title),
|
|
56
|
+
key: meta.key,
|
|
57
|
+
time: meta.time,
|
|
58
|
+
tempo: formatTempo(meta.tempo, meta.tempoMarking),
|
|
59
|
+
};
|
|
60
|
+
const words = [
|
|
61
|
+
...(first && setup.header.title_block ? headingText(setup, m, meta.title, meta.subtitle, text) : []),
|
|
62
|
+
...marginText(setup, m, text, first),
|
|
63
|
+
];
|
|
64
|
+
const origin = notationOrigin(input, index);
|
|
65
|
+
const systems = pages[index].systems.map((system) => `<g transform="translate(${m.margin.left} ${num(origin.y + system.y)}) scale(${num(system.scale)})">${renderSystem(system, music, profile)
|
|
66
|
+
.map((p) => primitiveToSvg(p, context))
|
|
67
|
+
.join("")}</g>`);
|
|
68
|
+
// Under the notation, so what it paints (the playing notes) never covers a digit.
|
|
69
|
+
const cursor = cursorLayer ? `<g data-layer="cursor" transform="translate(${origin.x} ${origin.y})"></g>` : "";
|
|
70
|
+
return `<rect width="${m.width}" height="${m.height}" fill="${style.page}"/>${words.map((p) => primitiveToSvg(p, context)).join("")}${cursor}${systems.join("")}`;
|
|
71
|
+
}
|
|
72
|
+
/** One page as a standalone `<svg>` (what a viewer shows), with an empty cursor layer under the notation. */
|
|
73
|
+
export function renderPageSvg(input, index, options = {}) {
|
|
74
|
+
const m = pageMetrics(input.setup);
|
|
75
|
+
const style = options.style ?? PRINT_STYLE;
|
|
76
|
+
const context = contextOf(input.setup, options);
|
|
77
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${m.width}" height="${m.height}" viewBox="0 0 ${m.width} ${m.height}" data-page="${index + 1}">${pageBody(input, index, context, style, true)}</svg>`;
|
|
78
|
+
}
|
|
79
|
+
export function exportScoreSvg(input, options = {}) {
|
|
80
|
+
const m = pageMetrics(input.setup);
|
|
81
|
+
const style = options.style ?? PRINT_STYLE;
|
|
82
|
+
const context = contextOf(input.setup, options);
|
|
83
|
+
const height = input.pages.length * m.height + (input.pages.length - 1) * PAGE_GAP;
|
|
84
|
+
const body = input.pages
|
|
85
|
+
.map((_, i) => `<g transform="translate(0 ${i * (m.height + PAGE_GAP)})">${pageBody(input, i, context, style, false)}</g>`)
|
|
86
|
+
.join("");
|
|
87
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="${m.width}" height="${height}" viewBox="0 0 ${m.width} ${height}"><title>${escapeXml(singleLine(input.meta.title))}</title>${body}</svg>\n`;
|
|
88
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PageSetup } from "./pageSetup.js";
|
|
2
|
+
import type { PageLayout } from "../schema/types.js";
|
|
3
|
+
/** CSS px per mm at 96 dpi. Screen pages and printed pages share these units. */
|
|
4
|
+
export declare const PX_PER_MM: number;
|
|
5
|
+
/** Notation sizes (rows, digits, spacing) live in layout/notationMetrics.ts. */
|
|
6
|
+
/**
|
|
7
|
+
* Title block rows on page 1 (px). The title takes a line height per line plus some air, the
|
|
8
|
+
* subtitle a line height per line, then come the info / credits lines. Line heights follow the
|
|
9
|
+
* chosen font sizes (21px title -> 28px lines, 12px subtitle -> 20px lines).
|
|
10
|
+
*/
|
|
11
|
+
export declare const titleLineHeight: (size: number) => number;
|
|
12
|
+
export declare const subtitleLineHeight: (size: number) => number;
|
|
13
|
+
export declare const TITLE_ROW_PADDING = 16;
|
|
14
|
+
export declare const INFO_LINE_HEIGHT = 16;
|
|
15
|
+
/** Room between the top margin and the first system on every page after page one (px). */
|
|
16
|
+
export declare const CONTINUATION_TOP_GAP = 40;
|
|
17
|
+
/** The running title at the bottom of pages 2 and later. */
|
|
18
|
+
export declare const SMALL_TITLE_HEIGHT = 20;
|
|
19
|
+
export type PageMetrics = {
|
|
20
|
+
/** Whole page, floored so it never exceeds the physical sheet when printed. */
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
margin: {
|
|
24
|
+
top: number;
|
|
25
|
+
right: number;
|
|
26
|
+
bottom: number;
|
|
27
|
+
left: number;
|
|
28
|
+
};
|
|
29
|
+
contentWidth: number;
|
|
30
|
+
contentHeight: number;
|
|
31
|
+
};
|
|
32
|
+
export declare function pageMetrics(setup: PageSetup): PageMetrics;
|
|
33
|
+
/** How many lines the title and subtitle take (the title always takes at least one). */
|
|
34
|
+
export type TitleLines = {
|
|
35
|
+
titleLines: number;
|
|
36
|
+
subtitleLines: number;
|
|
37
|
+
};
|
|
38
|
+
export type TitleSizes = Pick<PageLayout["header"], "title_size" | "subtitle_size">;
|
|
39
|
+
/** Height of the title and subtitle rows together. */
|
|
40
|
+
export declare function titleRowsHeight({ titleLines, subtitleLines }: TitleLines, sizes: TitleSizes): number;
|
|
41
|
+
/** Height of the page-1 title block; 0 when it is switched off. Grows with every line it holds. */
|
|
42
|
+
export declare function titleBlockHeight(header: PageLayout["header"], lines?: TitleLines): number;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { paperSizeMm } from "./paper.js";
|
|
2
|
+
import { creditLineCount } from "../text/creditLines.js";
|
|
3
|
+
/** CSS px per mm at 96 dpi. Screen pages and printed pages share these units. */
|
|
4
|
+
export const PX_PER_MM = 96 / 25.4;
|
|
5
|
+
/** Notation sizes (rows, digits, spacing) live in layout/notationMetrics.ts. */
|
|
6
|
+
/**
|
|
7
|
+
* Title block rows on page 1 (px). The title takes a line height per line plus some air, the
|
|
8
|
+
* subtitle a line height per line, then come the info / credits lines. Line heights follow the
|
|
9
|
+
* chosen font sizes (21px title -> 28px lines, 12px subtitle -> 20px lines).
|
|
10
|
+
*/
|
|
11
|
+
export const titleLineHeight = (size) => Math.round((size * 4) / 3);
|
|
12
|
+
export const subtitleLineHeight = (size) => Math.round((size * 5) / 3);
|
|
13
|
+
export const TITLE_ROW_PADDING = 16;
|
|
14
|
+
export const INFO_LINE_HEIGHT = 16;
|
|
15
|
+
/** Room between the top margin and the first system on every page after page one (px). */
|
|
16
|
+
export const CONTINUATION_TOP_GAP = 40;
|
|
17
|
+
/** The running title at the bottom of pages 2 and later. */
|
|
18
|
+
export const SMALL_TITLE_HEIGHT = 20;
|
|
19
|
+
export function pageMetrics(setup) {
|
|
20
|
+
const { width, height } = setup.sheet ?? paperSizeMm(setup.paper, setup.orientation);
|
|
21
|
+
const mm = (value) => Math.round(value * PX_PER_MM);
|
|
22
|
+
const { top, right, bottom, left } = setup.margins;
|
|
23
|
+
const pageWidth = Math.floor(width * PX_PER_MM);
|
|
24
|
+
const pageHeight = Math.floor(height * PX_PER_MM);
|
|
25
|
+
return {
|
|
26
|
+
width: pageWidth,
|
|
27
|
+
height: pageHeight,
|
|
28
|
+
margin: {
|
|
29
|
+
top: mm(top),
|
|
30
|
+
right: mm(right),
|
|
31
|
+
bottom: mm(bottom),
|
|
32
|
+
left: mm(left),
|
|
33
|
+
},
|
|
34
|
+
contentWidth: pageWidth - mm(left) - mm(right),
|
|
35
|
+
contentHeight: pageHeight - mm(top) - mm(bottom),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Height of the title and subtitle rows together. */
|
|
39
|
+
export function titleRowsHeight({ titleLines, subtitleLines }, sizes) {
|
|
40
|
+
return (Math.max(1, titleLines) * titleLineHeight(sizes.title_size) +
|
|
41
|
+
TITLE_ROW_PADDING +
|
|
42
|
+
subtitleLines * subtitleLineHeight(sizes.subtitle_size));
|
|
43
|
+
}
|
|
44
|
+
/** Height of the page-1 title block; 0 when it is switched off. Grows with every line it holds. */
|
|
45
|
+
export function titleBlockHeight(header, lines = { titleLines: 1, subtitleLines: 0 }) {
|
|
46
|
+
if (!header.title_block)
|
|
47
|
+
return 0;
|
|
48
|
+
const rows = Math.max(header.info.length, creditLineCount(header.credits));
|
|
49
|
+
return (titleRowsHeight(lines, header) +
|
|
50
|
+
(rows > 0 ? 4 + rows * INFO_LINE_HEIGHT : 0) +
|
|
51
|
+
header.title_gap);
|
|
52
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { PageLayout, PaperSize } from "../schema/types.js";
|
|
2
|
+
import { type SheetMm } from "./paper.js";
|
|
3
|
+
export declare const MARGIN_MAX_MM = 50;
|
|
4
|
+
/** Keep in sync with the backend (`HeaderSerializer`). */
|
|
5
|
+
export declare const MAX_INFO_LINES = 5;
|
|
6
|
+
export declare const MAX_CREDITS = 8;
|
|
7
|
+
export declare const MAX_CREDIT_VALUE_LINES = 4;
|
|
8
|
+
/** Title and subtitle: up to 3 lines, 200 characters in all (the backend limits). */
|
|
9
|
+
export declare const MAX_TITLE_LINES = 3;
|
|
10
|
+
export declare const MAX_TITLE_LENGTH = 200;
|
|
11
|
+
export declare const MAX_TEXT_LENGTH = 120;
|
|
12
|
+
/** Font sizes in px the page setup allows: keep in sync with the backend (`NOTE_SIZE`, ...). */
|
|
13
|
+
export declare const SIZE_LIMITS: {
|
|
14
|
+
readonly note_size: {
|
|
15
|
+
readonly min: 10;
|
|
16
|
+
readonly max: 28;
|
|
17
|
+
};
|
|
18
|
+
readonly lyric_size: {
|
|
19
|
+
readonly min: 8;
|
|
20
|
+
readonly max: 32;
|
|
21
|
+
};
|
|
22
|
+
readonly title_size: {
|
|
23
|
+
readonly min: 12;
|
|
24
|
+
readonly max: 48;
|
|
25
|
+
};
|
|
26
|
+
readonly subtitle_size: {
|
|
27
|
+
readonly min: 8;
|
|
28
|
+
readonly max: 32;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Space between systems the page setup allows: keep in sync with the backend (`SYSTEM_SPACING`). */
|
|
32
|
+
export declare const SYSTEM_SPACING_LIMITS: {
|
|
33
|
+
readonly min: 0;
|
|
34
|
+
readonly max: 120;
|
|
35
|
+
};
|
|
36
|
+
/** Space between the title block and the first system: keep in sync with the backend (`TITLE_GAP`). */
|
|
37
|
+
export declare const TITLE_GAP_LIMITS: {
|
|
38
|
+
readonly min: 0;
|
|
39
|
+
readonly max: 120;
|
|
40
|
+
};
|
|
41
|
+
/** Same defaults as the backend (`PageLayoutSerializer`). */
|
|
42
|
+
export declare const DEFAULT_PAGE_LAYOUT: PageLayout;
|
|
43
|
+
/**
|
|
44
|
+
* Everything that decides how a page looks and how the score is paginated. `sheet` replaces the
|
|
45
|
+
* paper's size for a view that is not printed (the phone's reflowed pages); it is never saved.
|
|
46
|
+
*/
|
|
47
|
+
export type PageSetup = {
|
|
48
|
+
paper: PaperSize;
|
|
49
|
+
sheet?: SheetMm;
|
|
50
|
+
} & PageLayout;
|
|
51
|
+
export declare const pageSetup: (paper?: PaperSize, layout?: PageLayout) => PageSetup;
|
|
52
|
+
/** Every font the page setup chooses: the score font and the one for each kind of text. */
|
|
53
|
+
export type PageFonts = Pick<PageLayout, "font" | "title_font" | "subtitle_font" | "info_font" | "credits_font" | "notes_font" | "lyrics_font">;
|
|
54
|
+
export declare const pageFontsOf: (layout: PageLayout) => PageFonts;
|
|
55
|
+
/** The page setup's font sizes in one place: notes and lyrics, title and subtitle (px). */
|
|
56
|
+
export type FontSizes = {
|
|
57
|
+
[K in keyof typeof SIZE_LIMITS]: number;
|
|
58
|
+
};
|
|
59
|
+
export declare const fontSizesOf: (layout: PageLayout) => FontSizes;
|
|
60
|
+
/** The layout change for new font sizes: the title sizes live in the header, the rest on the page. */
|
|
61
|
+
export declare function withFontSizes(layout: PageLayout, { title_size, subtitle_size, ...page }: Partial<FontSizes>): Partial<PageLayout>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { DEFAULT_PAPER } from "./paper.js";
|
|
2
|
+
export const MARGIN_MAX_MM = 50;
|
|
3
|
+
/** Keep in sync with the backend (`HeaderSerializer`). */
|
|
4
|
+
export const MAX_INFO_LINES = 5;
|
|
5
|
+
export const MAX_CREDITS = 8;
|
|
6
|
+
export const MAX_CREDIT_VALUE_LINES = 4;
|
|
7
|
+
/** Title and subtitle: up to 3 lines, 200 characters in all (the backend limits). */
|
|
8
|
+
export const MAX_TITLE_LINES = 3;
|
|
9
|
+
export const MAX_TITLE_LENGTH = 200;
|
|
10
|
+
export const MAX_TEXT_LENGTH = 120;
|
|
11
|
+
/** Font sizes in px the page setup allows: keep in sync with the backend (`NOTE_SIZE`, ...). */
|
|
12
|
+
export const SIZE_LIMITS = {
|
|
13
|
+
note_size: { min: 10, max: 28 },
|
|
14
|
+
lyric_size: { min: 8, max: 32 },
|
|
15
|
+
title_size: { min: 12, max: 48 },
|
|
16
|
+
subtitle_size: { min: 8, max: 32 },
|
|
17
|
+
};
|
|
18
|
+
/** Space between systems the page setup allows: keep in sync with the backend (`SYSTEM_SPACING`). */
|
|
19
|
+
export const SYSTEM_SPACING_LIMITS = { min: 0, max: 120 };
|
|
20
|
+
/** Space between the title block and the first system: keep in sync with the backend (`TITLE_GAP`). */
|
|
21
|
+
export const TITLE_GAP_LIMITS = { min: 0, max: 120 };
|
|
22
|
+
/** Same defaults as the backend (`PageLayoutSerializer`). */
|
|
23
|
+
export const DEFAULT_PAGE_LAYOUT = {
|
|
24
|
+
orientation: "portrait",
|
|
25
|
+
font: "default",
|
|
26
|
+
title_font: "inherit",
|
|
27
|
+
subtitle_font: "inherit",
|
|
28
|
+
info_font: "inherit",
|
|
29
|
+
credits_font: "inherit",
|
|
30
|
+
notes_font: "inherit",
|
|
31
|
+
lyrics_font: "sofia_sans_extra_condensed",
|
|
32
|
+
note_size: 15,
|
|
33
|
+
lyric_size: 18,
|
|
34
|
+
system_spacing: 18, // the gap used before it could be changed
|
|
35
|
+
system_bracket: true, // always drawn before it could be hidden
|
|
36
|
+
low_voices_octave_up: true,
|
|
37
|
+
margins: { top: 18, right: 20, bottom: 18, left: 20 },
|
|
38
|
+
header: {
|
|
39
|
+
title_block: true,
|
|
40
|
+
title_align: "left",
|
|
41
|
+
title_italic: false,
|
|
42
|
+
subtitle_italic: false,
|
|
43
|
+
title_size: 21,
|
|
44
|
+
subtitle_size: 12,
|
|
45
|
+
title_gap: 28,
|
|
46
|
+
info: ["do = {key} · {time} · ♩ = {tempo}"],
|
|
47
|
+
credits: [],
|
|
48
|
+
credits_align: "right",
|
|
49
|
+
credits_italic: true, // credits were always italic
|
|
50
|
+
left: "",
|
|
51
|
+
center: "",
|
|
52
|
+
right: "",
|
|
53
|
+
},
|
|
54
|
+
footer: { left: "", center: "{page} / {pages}", right: "" },
|
|
55
|
+
};
|
|
56
|
+
export const pageSetup = (paper = DEFAULT_PAPER, layout = DEFAULT_PAGE_LAYOUT) => ({
|
|
57
|
+
paper,
|
|
58
|
+
...layout,
|
|
59
|
+
});
|
|
60
|
+
export const pageFontsOf = (layout) => ({
|
|
61
|
+
font: layout.font,
|
|
62
|
+
title_font: layout.title_font,
|
|
63
|
+
subtitle_font: layout.subtitle_font,
|
|
64
|
+
info_font: layout.info_font,
|
|
65
|
+
credits_font: layout.credits_font,
|
|
66
|
+
notes_font: layout.notes_font,
|
|
67
|
+
lyrics_font: layout.lyrics_font,
|
|
68
|
+
});
|
|
69
|
+
export const fontSizesOf = (layout) => ({
|
|
70
|
+
note_size: layout.note_size,
|
|
71
|
+
lyric_size: layout.lyric_size,
|
|
72
|
+
title_size: layout.header.title_size,
|
|
73
|
+
subtitle_size: layout.header.subtitle_size,
|
|
74
|
+
});
|
|
75
|
+
/** The layout change for new font sizes: the title sizes live in the header, the rest on the page. */
|
|
76
|
+
export function withFontSizes(layout, { title_size, subtitle_size, ...page }) {
|
|
77
|
+
return {
|
|
78
|
+
...page,
|
|
79
|
+
header: {
|
|
80
|
+
...layout.header,
|
|
81
|
+
...(title_size !== undefined && { title_size }),
|
|
82
|
+
...(subtitle_size !== undefined && { subtitle_size }),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Orientation, PaperSize } from "../schema/types.js";
|
|
2
|
+
export declare const DEFAULT_PAPER: PaperSize;
|
|
3
|
+
/** Portrait page sizes in millimetres. Labels follow the Indonesian names. */
|
|
4
|
+
export declare const PAPER_SIZES: Record<PaperSize, {
|
|
5
|
+
label: string;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const PAPER_OPTIONS: PaperSize[];
|
|
10
|
+
/** A sheet's size in millimetres. */
|
|
11
|
+
export type SheetMm = {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
};
|
|
15
|
+
/** Sheet size in millimetres for the given orientation. */
|
|
16
|
+
export declare function paperSizeMm(paper: PaperSize, orientation: Orientation): SheetMm;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const DEFAULT_PAPER = "a4";
|
|
2
|
+
/** Portrait page sizes in millimetres. Labels follow the Indonesian names. */
|
|
3
|
+
export const PAPER_SIZES = {
|
|
4
|
+
a4: { label: "A4 (Standard)", width: 210, height: 297 },
|
|
5
|
+
letter: { label: "Letter (Kuarto)", width: 215.9, height: 279.4 },
|
|
6
|
+
f4: { label: "F4 (Folio)", width: 215, height: 330 },
|
|
7
|
+
legal: { label: "Legal", width: 215.9, height: 355.6 },
|
|
8
|
+
};
|
|
9
|
+
export const PAPER_OPTIONS = Object.keys(PAPER_SIZES);
|
|
10
|
+
/** Sheet size in millimetres for the given orientation. */
|
|
11
|
+
export function paperSizeMm(paper, orientation) {
|
|
12
|
+
const { width, height } = PAPER_SIZES[paper];
|
|
13
|
+
return orientation === "landscape"
|
|
14
|
+
? { width: height, height: width }
|
|
15
|
+
: { width, height };
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nodelyra/not-angka: render numbered music notation (Not Angka, Jianpu) from JSON, and play it.
|
|
3
|
+
*
|
|
4
|
+
* import { createScorePlayer } from "@nodelyra/not-angka";
|
|
5
|
+
* createScorePlayer(document.getElementById("score")!, scoreJson);
|
|
6
|
+
*/
|
|
7
|
+
export { createScorePlayer } from "./player/createScorePlayer.js";
|
|
8
|
+
export type { PlayerEnvironment } from "./player/createScorePlayer.js";
|
|
9
|
+
export { createExcerptPlayer } from "./player/createExcerptPlayer.js";
|
|
10
|
+
export type { ExcerptEnvironment, ExcerptOptions, ExcerptPlayer } from "./player/createExcerptPlayer.js";
|
|
11
|
+
export { mountExcerpts } from "./player/mountExcerpts.js";
|
|
12
|
+
export type { ExcerptMounts, MountEnvironment, MountOptions } from "./player/mountExcerpts.js";
|
|
13
|
+
export { renderScoreToSvg } from "./player/staticSvg.js";
|
|
14
|
+
export { loadScore } from "./player/loadScore.js";
|
|
15
|
+
export type { LoadedScore } from "./player/loadScore.js";
|
|
16
|
+
export { DEFAULT_LABELS } from "./player/types.js";
|
|
17
|
+
export type { PlayerControls, PlayerLabels, PlayerOptions, PlayerSnapshot, ScorePlayer } from "./player/types.js";
|
|
18
|
+
export type { Theme } from "./player/theme.js";
|
|
19
|
+
export { compilePerformance, localPerformanceSource } from "./performance/compilePerformance.js";
|
|
20
|
+
export type { Performance } from "./playback/types.js";
|
|
21
|
+
export { normalizeScore, ScoreFormatError } from "./schema/normalize.js";
|
|
22
|
+
export type { ChordJson, EventJson, LyricJson, MeasureJson, NoteJson, PartJson, RestJson, ScoreJson, SettingsJson } from "./schema/scoreJson.js";
|
|
23
|
+
export type { ScoreInput as Score } from "./schema/types.js";
|
|
24
|
+
export type { SvgOptions, SvgStyle } from "./export/svgExport.js";
|
|
25
|
+
export { scoreViewOf } from "./schema/scoreView.js";
|
|
26
|
+
export type { ScoreView } from "./schema/scoreView.js";
|
|
27
|
+
export { DEFAULT_PAGE_LAYOUT } from "./geometry/pageSetup.js";
|
|
28
|
+
export type { PageSetup } from "./geometry/pageSetup.js";
|
|
29
|
+
export { pageMetrics } from "./geometry/metrics.js";
|
|
30
|
+
export { createPlayerStore } from "./playback/createPlayerStore.js";
|
|
31
|
+
export type { PlayerDeps, PlayerStatus, PlayerStore } from "./playback/createPlayerStore.js";
|
|
32
|
+
export { createWebAudioOutput } from "./playback/audioOutput.js";
|
|
33
|
+
export type { AudioOutput } from "./playback/audioOutput.js";
|
|
34
|
+
export { clampPlayTempo } from "./playback/timing.js";
|
|
35
|
+
export { formatTempo } from "./text/headerFooter.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nodelyra/not-angka: render numbered music notation (Not Angka, Jianpu) from JSON, and play it.
|
|
3
|
+
*
|
|
4
|
+
* import { createScorePlayer } from "@nodelyra/not-angka";
|
|
5
|
+
* createScorePlayer(document.getElementById("score")!, scoreJson);
|
|
6
|
+
*/
|
|
7
|
+
export { createScorePlayer } from "./player/createScorePlayer.js";
|
|
8
|
+
export { createExcerptPlayer } from "./player/createExcerptPlayer.js";
|
|
9
|
+
export { mountExcerpts } from "./player/mountExcerpts.js";
|
|
10
|
+
export { renderScoreToSvg } from "./player/staticSvg.js";
|
|
11
|
+
export { loadScore } from "./player/loadScore.js";
|
|
12
|
+
export { DEFAULT_LABELS } from "./player/types.js";
|
|
13
|
+
export { compilePerformance, localPerformanceSource } from "./performance/compilePerformance.js";
|
|
14
|
+
export { normalizeScore, ScoreFormatError } from "./schema/normalize.js";
|
|
15
|
+
// What a host page builds its own player around (the Nodelyra player and embed pages do): the score
|
|
16
|
+
// as pages, the playback store and its sound device, and the few helpers they share.
|
|
17
|
+
export { scoreViewOf } from "./schema/scoreView.js";
|
|
18
|
+
export { DEFAULT_PAGE_LAYOUT } from "./geometry/pageSetup.js";
|
|
19
|
+
export { pageMetrics } from "./geometry/metrics.js";
|
|
20
|
+
export { createPlayerStore } from "./playback/createPlayerStore.js";
|
|
21
|
+
export { createWebAudioOutput } from "./playback/audioOutput.js";
|
|
22
|
+
export { clampPlayTempo } from "./playback/timing.js";
|
|
23
|
+
export { formatTempo } from "./text/headerFooter.js";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ScoreMusic } from "../schema/types.js";
|
|
2
|
+
import type { PageSetup } from "../geometry/pageSetup.js";
|
|
3
|
+
import { type TitleLines } from "../geometry/metrics.js";
|
|
4
|
+
import { type Arc } from "./arcs.js";
|
|
5
|
+
import { type SystemDirections } from "./directions.js";
|
|
6
|
+
import { type ElementBox } from "./elementBoxes.js";
|
|
7
|
+
import { type SystemLyrics } from "./lyricsLayout.js";
|
|
8
|
+
import { type SystemMarkings } from "./markings.js";
|
|
9
|
+
import { type LyricStyle } from "./notationMetrics.js";
|
|
10
|
+
import { type SystemPlan } from "./systemBreaking.js";
|
|
11
|
+
import { type SystemLayout } from "./systemLayout.js";
|
|
12
|
+
/** A fully laid-out system: everything the renderers draw and the editor hit-tests. */
|
|
13
|
+
export type PlacedSystem = SystemLayout & {
|
|
14
|
+
/** Top of the system on its page, from the top of the notation area (px). */
|
|
15
|
+
y: number;
|
|
16
|
+
/**
|
|
17
|
+
* Page px per layout unit: the system is laid out at the base note size and drawn scaled, so
|
|
18
|
+
* the note size scales the whole notation. Everything else in the system is in layout units.
|
|
19
|
+
*/
|
|
20
|
+
scale: number;
|
|
21
|
+
/** False hides the bracket joining its parts (page setup `system_bracket`); shown by default. */
|
|
22
|
+
bracket?: boolean;
|
|
23
|
+
/** True draws the low voices one octave up (page setup `low_voices_octave_up`); on by default. */
|
|
24
|
+
lowVoicesUp?: boolean;
|
|
25
|
+
arcs: Arc[];
|
|
26
|
+
/** Dynamics, hairpins and expression text above it (ADR 0011). */
|
|
27
|
+
directions: SystemDirections;
|
|
28
|
+
lyrics: SystemLyrics;
|
|
29
|
+
markings: SystemMarkings;
|
|
30
|
+
boxes: ElementBox[];
|
|
31
|
+
};
|
|
32
|
+
export type Page = {
|
|
33
|
+
systems: PlacedSystem[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* What the layout needs: the music, the score's time signature, pickup (ticks; 0 = none) and key
|
|
37
|
+
* (the "1 =" the score starts in; C when left out), and how lyrics are set.
|
|
38
|
+
*/
|
|
39
|
+
export type LayoutInput = {
|
|
40
|
+
music: ScoreMusic;
|
|
41
|
+
time: string;
|
|
42
|
+
pickup?: number;
|
|
43
|
+
lyrics?: LyricStyle;
|
|
44
|
+
key?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Room on a page that is not for notation: page 1 holds the page heading (title, info and
|
|
48
|
+
* credits); every later page holds the small running title and keeps `CONTINUATION_TOP_GAP` free
|
|
49
|
+
* under the top margin. The heading and the running title need the title block; the gap does not.
|
|
50
|
+
*/
|
|
51
|
+
export declare function reservedHeight(setup: PageSetup, firstPage: boolean, lines: TitleLines): number;
|
|
52
|
+
/** Systems of the score at a given width, before they are put on pages (PRD FR-064). */
|
|
53
|
+
export declare function layoutSystems({ music, time, pickup, lyrics: style, key }: LayoutInput, width: number): {
|
|
54
|
+
systems: (Omit<PlacedSystem, "y" | "scale">)[];
|
|
55
|
+
plans: SystemPlan[];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Lay the score out on pages (PRD FR-065): a pure function of the music and the page setup, so
|
|
59
|
+
* the editor canvas, the printed PDF and the SVG export break at the same places. Pages break
|
|
60
|
+
* between systems, or where a measure asks for a page break. An empty score still has one page.
|
|
61
|
+
*/
|
|
62
|
+
export declare function paginate(input: LayoutInput, setup: PageSetup, options?: Partial<TitleLines>): Page[];
|
|
63
|
+
/** Height of a page's notation (its last system's bottom), in page px. */
|
|
64
|
+
export declare const notationHeight: (page: Page) => number;
|