chordsheetjs 14.6.1 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -3
- package/lib/bundle.js +25728 -66671
- package/lib/bundle.min.js +148 -7118
- package/lib/index.js +1 -7770
- package/lib/index.js.map +1 -1
- package/lib/main.d.ts +2 -131
- package/lib/main.d.ts.map +1 -1
- package/lib/module.js +2 -7769
- package/lib/module.js.map +1 -1
- package/lib/pdf/chord.d.ts +219 -0
- package/lib/pdf/chord_definition/chord_definition.d.ts +66 -0
- package/lib/pdf/chord_definition/chord_definition_set.d.ts +12 -0
- package/lib/pdf/chord_diagram/chord_diagram.d.ts +131 -0
- package/lib/pdf/chord_diagram/js_pdf_renderer.d.ts +40 -0
- package/lib/pdf/chord_diagram/renderer.d.ts +43 -0
- package/lib/pdf/chord_parsing_error.d.ts +2 -0
- package/lib/pdf/chord_sheet/ast_component.d.ts +11 -0
- package/lib/pdf/chord_sheet/ast_type.d.ts +9 -0
- package/lib/pdf/chord_sheet/chord_lyrics_pair.d.ts +60 -0
- package/lib/pdf/chord_sheet/chord_pro/composite.d.ts +11 -0
- package/lib/pdf/chord_sheet/chord_pro/evaluatable.d.ts +7 -0
- package/lib/pdf/chord_sheet/chord_pro/evaluation_error.d.ts +7 -0
- package/lib/pdf/chord_sheet/chord_pro/literal.d.ts +9 -0
- package/lib/pdf/chord_sheet/chord_pro/ternary.d.ts +29 -0
- package/lib/pdf/chord_sheet/comment.d.ts +21 -0
- package/lib/pdf/chord_sheet/font.d.ts +47 -0
- package/lib/pdf/chord_sheet/font_size.d.ts +33 -0
- package/lib/pdf/chord_sheet/font_stack.d.ts +13 -0
- package/lib/pdf/chord_sheet/item.d.ts +7 -0
- package/lib/pdf/chord_sheet/line.d.ts +130 -0
- package/lib/pdf/chord_sheet/line_expander.d.ts +12 -0
- package/lib/pdf/chord_sheet/metadata.d.ts +71 -0
- package/lib/pdf/chord_sheet/metadata_accessors.d.ts +18 -0
- package/lib/pdf/chord_sheet/paragraph.d.ts +48 -0
- package/lib/pdf/chord_sheet/soft_line_break.d.ts +15 -0
- package/lib/pdf/chord_sheet/song.d.ts +253 -0
- package/lib/pdf/chord_sheet/song_mapper.d.ts +15 -0
- package/lib/pdf/chord_sheet/standard_metadata_providers.d.ts +5 -0
- package/lib/pdf/chord_sheet/tag.d.ts +104 -0
- package/lib/pdf/chord_sheet/tag_interpreter.d.ts +14 -0
- package/lib/pdf/chord_sheet/tags.d.ts +259 -0
- package/lib/pdf/chord_sheet/trace_info.d.ts +6 -0
- package/lib/pdf/chord_sheet_serializer.d.ts +49 -0
- package/lib/pdf/constants.d.ts +117 -0
- package/lib/pdf/formatter/chord_pro_formatter.d.ts +39 -0
- package/lib/pdf/formatter/chord_renderer.d.ts +30 -0
- package/lib/pdf/formatter/chords_over_words_formatter.d.ts +33 -0
- package/lib/pdf/formatter/configuration/base_configuration.d.ts +58 -0
- package/lib/pdf/formatter/configuration/default_config_manager.d.ts +31 -0
- package/lib/pdf/formatter/configuration/html_configuration.d.ts +37 -0
- package/lib/pdf/formatter/configuration/index.d.ts +13 -0
- package/lib/pdf/formatter/configuration/measured_html_configuration.d.ts +38 -0
- package/lib/pdf/formatter/configuration/measurement_based_configuration.d.ts +204 -0
- package/lib/pdf/formatter/configuration/pdf_configuration.d.ts +16 -0
- package/lib/pdf/formatter/formatter.d.ts +38 -0
- package/lib/pdf/formatter/formatting_context.d.ts +7 -0
- package/lib/pdf/formatter/html_div_formatter.d.ts +9 -0
- package/lib/pdf/formatter/html_formatter.d.ts +60 -0
- package/lib/pdf/formatter/html_table_formatter.d.ts +10 -0
- package/lib/pdf/formatter/measured_html_formatter.d.ts +43 -0
- package/lib/pdf/formatter/measurement_based_formatter.d.ts +19 -0
- package/lib/pdf/formatter/pdf_formatter/doc_wrapper.d.ts +53 -0
- package/lib/pdf/formatter/pdf_formatter/fonts/NimbusSansLFonts.base64.d.ts +4 -0
- package/lib/pdf/formatter/pdf_formatter/types.d.ts +34 -0
- package/lib/pdf/formatter/pdf_formatter.d.ts +40 -0
- package/lib/pdf/formatter/templates/html_div_formatter.d.ts +3 -0
- package/lib/pdf/formatter/templates/html_table_formatter.d.ts +3 -0
- package/lib/pdf/formatter/text_formatter.d.ts +35 -0
- package/lib/pdf/helpers.d.ts +42 -0
- package/lib/pdf/index.d.ts +126 -0
- package/lib/pdf/index.js +24369 -0
- package/lib/pdf/key.d.ts +124 -0
- package/lib/pdf/key_config.d.ts +3 -0
- package/lib/pdf/layout/engine/condition.d.ts +25 -0
- package/lib/pdf/layout/engine/dimensions.d.ts +33 -0
- package/lib/pdf/layout/engine/index.d.ts +7 -0
- package/lib/pdf/layout/engine/item_processor.d.ts +70 -0
- package/lib/pdf/layout/engine/layout_engine.d.ts +67 -0
- package/lib/pdf/layout/engine/layout_factory.d.ts +22 -0
- package/lib/pdf/layout/engine/layout_helpers.d.ts +35 -0
- package/lib/pdf/layout/engine/line_breaker.d.ts +54 -0
- package/lib/pdf/layout/engine/paragraph_splitter/index.d.ts +5 -0
- package/lib/pdf/layout/engine/paragraph_splitter/paragraph_splitter.d.ts +5 -0
- package/lib/pdf/layout/engine/paragraph_splitter/strategies/five_or_more_lines_paragraph_split_strategy.d.ts +14 -0
- package/lib/pdf/layout/engine/paragraph_splitter/strategies/four_lines_paragraph_split_strategy.d.ts +8 -0
- package/lib/pdf/layout/engine/paragraph_splitter/strategies/three_or_less_lines_paragraph_split_strategy.d.ts +4 -0
- package/lib/pdf/layout/engine/title_separator_tag.d.ts +8 -0
- package/lib/pdf/layout/engine/types.d.ts +98 -0
- package/lib/pdf/layout/measurement/canvas_measurer.d.ts +18 -0
- package/lib/pdf/layout/measurement/dom_measurer.d.ts +21 -0
- package/lib/pdf/layout/measurement/index.d.ts +4 -0
- package/lib/pdf/layout/measurement/js_pdf_measurer.d.ts +12 -0
- package/lib/pdf/layout/measurement/measurer.d.ts +52 -0
- package/lib/pdf/module.js +24336 -0
- package/lib/pdf/normalize_mappings/enharmonic-normalize.d.ts +2 -0
- package/lib/pdf/normalize_mappings/suffix-normalize-mapping.d.ts +2 -0
- package/lib/pdf/pango/pango_helpers.d.ts +6 -0
- package/lib/pdf/parser/chord/peg_parser.d.ts +55 -0
- package/lib/pdf/parser/chord_definition/peg_parser.d.ts +55 -0
- package/lib/pdf/parser/chord_pro/helpers.d.ts +15 -0
- package/lib/pdf/parser/chord_pro/peg_parser.d.ts +55 -0
- package/lib/pdf/parser/chord_pro_parser.d.ts +32 -0
- package/lib/pdf/parser/chord_sheet_parser.d.ts +57 -0
- package/lib/pdf/parser/chords_over_words/helpers.d.ts +33 -0
- package/lib/pdf/parser/chords_over_words/peg_parser.d.ts +55 -0
- package/lib/pdf/parser/chords_over_words_parser.d.ts +67 -0
- package/lib/pdf/parser/null_tracer.d.ts +4 -0
- package/lib/pdf/parser/parser_helpers.d.ts +3 -0
- package/lib/pdf/parser/parser_warning.d.ts +33 -0
- package/lib/pdf/parser/ultimate_guitar_parser.d.ts +46 -0
- package/lib/pdf/pdf.d.ts +2 -0
- package/lib/pdf/rendering/html/html_doc_wrapper.d.ts +82 -0
- package/lib/pdf/rendering/html/html_element_styler.d.ts +58 -0
- package/lib/pdf/rendering/html/positioned_html_renderer.d.ts +85 -0
- package/lib/pdf/rendering/pdf/js_pdf_renderer.d.ts +46 -0
- package/lib/pdf/rendering/pdf/pdf_chord_diagram_renderer.d.ts +118 -0
- package/lib/pdf/rendering/renderer.d.ts +273 -0
- package/lib/pdf/rendering/shared/layout_section_renderer.d.ts +93 -0
- package/lib/pdf/scales.d.ts +3 -0
- package/lib/pdf/serialized_types.d.ts +76 -0
- package/lib/pdf/song_builder.d.ts +38 -0
- package/lib/pdf/template_helpers/metadata_processor.d.ts +14 -0
- package/lib/pdf/template_helpers/when.d.ts +13 -0
- package/lib/pdf/template_helpers/when_callback.d.ts +2 -0
- package/lib/pdf/template_helpers/when_clause.d.ts +8 -0
- package/lib/pdf/template_helpers.d.ts +64 -0
- package/lib/pdf/utilities.d.ts +35 -0
- package/lib/pdf/version.d.ts +2 -0
- package/package.json +20 -2
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Dimensions from '../../layout/engine/dimensions';
|
|
2
|
+
import HtmlDocWrapper from './html_doc_wrapper';
|
|
3
|
+
import Song from '../../chord_sheet/song';
|
|
4
|
+
import { LineLayout, MeasuredItem } from '../../layout/engine';
|
|
5
|
+
import Renderer, { ParagraphLayout } from '../renderer';
|
|
6
|
+
import { FontConfiguration, MeasuredHtmlFormatterConfiguration } from '../../formatter/configuration';
|
|
7
|
+
/**
|
|
8
|
+
* HtmlRenderer renders a song as HTML with absolute positioning
|
|
9
|
+
*/
|
|
10
|
+
declare class PositionedHtmlRenderer extends Renderer {
|
|
11
|
+
private configuration;
|
|
12
|
+
private currentLayoutFontStyle;
|
|
13
|
+
private currentLayoutSection;
|
|
14
|
+
private currentLayoutTextItem;
|
|
15
|
+
private currentLineStyle;
|
|
16
|
+
private _dimensions;
|
|
17
|
+
private _dimensionCacheKey;
|
|
18
|
+
private styler;
|
|
19
|
+
container: HTMLElement;
|
|
20
|
+
doc: HtmlDocWrapper;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new HtmlRenderer
|
|
23
|
+
*/
|
|
24
|
+
constructor(song: Song, container: HTMLElement, configuration: MeasuredHtmlFormatterConfiguration);
|
|
25
|
+
getFontConfiguration(objectType: string): FontConfiguration;
|
|
26
|
+
getDocumentMetadata(): Record<string, any>;
|
|
27
|
+
getDoc(): HtmlDocWrapper;
|
|
28
|
+
getHTML(): HTMLElement;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
protected initializeBackend(): void;
|
|
31
|
+
protected createNewPage(): void;
|
|
32
|
+
protected renderChordDiagrams(): void;
|
|
33
|
+
protected renderHeadersAndFooters(): void;
|
|
34
|
+
private renderLayoutForEachPage;
|
|
35
|
+
private resetLayoutRenderingState;
|
|
36
|
+
private createLayoutRenderer;
|
|
37
|
+
private createLayoutBackend;
|
|
38
|
+
private renderHtmlText;
|
|
39
|
+
private applyLayoutTextClasses;
|
|
40
|
+
private applyLayoutTextStyles;
|
|
41
|
+
private renderHtmlImage;
|
|
42
|
+
private renderHtmlLine;
|
|
43
|
+
protected renderParagraphs(paragraphLayouts: ParagraphLayout[]): void;
|
|
44
|
+
private renderParagraph;
|
|
45
|
+
private groupElementsByPageAndColumn;
|
|
46
|
+
protected renderLineItems(lines: LineLayout[]): void;
|
|
47
|
+
private renderSingleLine;
|
|
48
|
+
private getCurrentContext;
|
|
49
|
+
private handleColumnOverflow;
|
|
50
|
+
private renderLineContent;
|
|
51
|
+
private renderMeasuredItem;
|
|
52
|
+
private renderChordLyricsPairItem;
|
|
53
|
+
private renderTagItem;
|
|
54
|
+
private updatePosition;
|
|
55
|
+
protected addSectionLabel(label: string, x: number, y: number, options?: {
|
|
56
|
+
noUnderline?: boolean;
|
|
57
|
+
}): void;
|
|
58
|
+
protected addComment(comment: string, x: number, y: number, options?: {
|
|
59
|
+
noUnderline?: boolean;
|
|
60
|
+
}): void;
|
|
61
|
+
private addTextElementWithOptions;
|
|
62
|
+
protected measureText(text: string, font: FontConfiguration): {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
};
|
|
66
|
+
protected calculateChordBaseline(yOffset: number, items: MeasuredItem[], chordText: string): number;
|
|
67
|
+
protected finalizeRendering(): void;
|
|
68
|
+
protected getConfiguration(): MeasuredHtmlFormatterConfiguration;
|
|
69
|
+
get dimensions(): Dimensions;
|
|
70
|
+
protected getDocPageSize(): {
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
};
|
|
74
|
+
private calculateBounds;
|
|
75
|
+
private createParagraphDiv;
|
|
76
|
+
private createElementGroupDiv;
|
|
77
|
+
private renderElementGroup;
|
|
78
|
+
private renderElement;
|
|
79
|
+
private drawElement;
|
|
80
|
+
private drawTextElement;
|
|
81
|
+
private buildDimensions;
|
|
82
|
+
private generateDimensionCacheKey;
|
|
83
|
+
protected getExtraMetadata(page: number, totalPages: number): Record<string, string | string[]>;
|
|
84
|
+
}
|
|
85
|
+
export default PositionedHtmlRenderer;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Blob } from 'buffer';
|
|
2
|
+
import Dimensions from '../../layout/engine/dimensions';
|
|
3
|
+
import DocWrapper from '../../formatter/pdf_formatter/doc_wrapper';
|
|
4
|
+
import Song from '../../chord_sheet/song';
|
|
5
|
+
import { MeasuredItem } from '../../layout/engine';
|
|
6
|
+
import { PdfConstructor } from '../../formatter/pdf_formatter/types';
|
|
7
|
+
import Renderer from '../renderer';
|
|
8
|
+
import { FontConfiguration, PDFFormatterConfiguration } from '../../formatter/configuration';
|
|
9
|
+
declare class JsPdfRenderer extends Renderer {
|
|
10
|
+
private configuration;
|
|
11
|
+
private _dimensions;
|
|
12
|
+
private _dimensionCacheKey;
|
|
13
|
+
doc: DocWrapper;
|
|
14
|
+
constructor(song: Song, docConstructor: PdfConstructor, configuration: PDFFormatterConfiguration);
|
|
15
|
+
getFontConfiguration(objectType: string): FontConfiguration;
|
|
16
|
+
getDocumentMetadata(): Record<string, any>;
|
|
17
|
+
save(filename: string): void;
|
|
18
|
+
generatePDF(): Promise<Blob>;
|
|
19
|
+
getDoc(): DocWrapper;
|
|
20
|
+
protected initializeBackend(): void;
|
|
21
|
+
protected createNewPage(): void;
|
|
22
|
+
protected renderChordDiagrams(): void;
|
|
23
|
+
private createDiagramContext;
|
|
24
|
+
private createDiagramConfig;
|
|
25
|
+
protected renderHeadersAndFooters(): void;
|
|
26
|
+
private createLayoutRenderer;
|
|
27
|
+
private createLayoutBackend;
|
|
28
|
+
protected measureText(text: string, font: FontConfiguration): {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
};
|
|
32
|
+
protected calculateChordBaseline(yOffset: number, items: MeasuredItem[], chordText: string): number;
|
|
33
|
+
protected finalizeRendering(): void;
|
|
34
|
+
protected getConfiguration(): PDFFormatterConfiguration;
|
|
35
|
+
protected get dimensions(): Dimensions;
|
|
36
|
+
protected getDocPageSize(): {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
};
|
|
40
|
+
private drawElement;
|
|
41
|
+
private drawUnderlineIfNeeded;
|
|
42
|
+
private buildDimensions;
|
|
43
|
+
private generateDimensionCacheKey;
|
|
44
|
+
protected getExtraMetadata(page: number, totalPages: number): Record<string, string | string[]>;
|
|
45
|
+
}
|
|
46
|
+
export default JsPdfRenderer;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import DocWrapper from '../../formatter/pdf_formatter/doc_wrapper';
|
|
2
|
+
import Song from '../../chord_sheet/song';
|
|
3
|
+
import { ChordDiagramRenderingConfig } from '../../chord_diagram/chord_diagram';
|
|
4
|
+
import { ChordDiagramFontConfigurations } from '../../formatter/configuration';
|
|
5
|
+
/**
|
|
6
|
+
* Context for chord diagram rendering
|
|
7
|
+
*/
|
|
8
|
+
export interface ChordDiagramRenderingContext {
|
|
9
|
+
song: Song;
|
|
10
|
+
doc: DocWrapper;
|
|
11
|
+
getMinY: () => number;
|
|
12
|
+
getColumnStartX: () => number;
|
|
13
|
+
getColumnBottomY: () => number;
|
|
14
|
+
moveToNextColumn: () => void;
|
|
15
|
+
dimensions: {
|
|
16
|
+
columnWidth: number;
|
|
17
|
+
};
|
|
18
|
+
getX: () => number;
|
|
19
|
+
getY: () => number;
|
|
20
|
+
getCurrentColumn: () => number;
|
|
21
|
+
getCurrentPage: () => number;
|
|
22
|
+
setPosition: (x: number, y: number, column: number, page: number) => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for chord diagram rendering
|
|
26
|
+
*/
|
|
27
|
+
export interface ChordDiagramConfig {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
renderingConfig?: ChordDiagramRenderingConfig;
|
|
30
|
+
fonts: ChordDiagramFontConfigurations;
|
|
31
|
+
overrides?: {
|
|
32
|
+
global?: Record<string, {
|
|
33
|
+
hide?: boolean;
|
|
34
|
+
definition?: string;
|
|
35
|
+
}>;
|
|
36
|
+
byKey?: Record<string, Record<string, {
|
|
37
|
+
hide?: boolean;
|
|
38
|
+
definition?: string;
|
|
39
|
+
}>>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Handles chord diagram rendering for PDF output.
|
|
44
|
+
* Extracted from JsPdfRenderer to improve modularity.
|
|
45
|
+
*/
|
|
46
|
+
export declare class ChordDiagramRenderer {
|
|
47
|
+
private context;
|
|
48
|
+
private config;
|
|
49
|
+
constructor(context: ChordDiagramRenderingContext, config: ChordDiagramConfig);
|
|
50
|
+
/**
|
|
51
|
+
* Renders all chord diagrams for the song
|
|
52
|
+
*/
|
|
53
|
+
render(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Calculates layout dimensions for chord diagrams
|
|
56
|
+
*/
|
|
57
|
+
private calculateDiagramLayout;
|
|
58
|
+
/**
|
|
59
|
+
* Initializes position for diagram rendering
|
|
60
|
+
*/
|
|
61
|
+
private initializeDiagramPosition;
|
|
62
|
+
/**
|
|
63
|
+
* Renders a single chord diagram
|
|
64
|
+
*/
|
|
65
|
+
private renderSingleChordDiagram;
|
|
66
|
+
/**
|
|
67
|
+
* Positions for the next diagram, handling row and column breaks
|
|
68
|
+
*/
|
|
69
|
+
private positionForNextDiagram;
|
|
70
|
+
private getInitialPosition;
|
|
71
|
+
private handleRowBreak;
|
|
72
|
+
private handleColumnBreak;
|
|
73
|
+
/**
|
|
74
|
+
* Draws a single chord diagram
|
|
75
|
+
*/
|
|
76
|
+
private drawChordDiagram;
|
|
77
|
+
/**
|
|
78
|
+
* Processes chord overrides from configuration
|
|
79
|
+
*/
|
|
80
|
+
private processChordOverrides;
|
|
81
|
+
/**
|
|
82
|
+
* Extracts override values from configuration
|
|
83
|
+
*/
|
|
84
|
+
private extractOverrideValues;
|
|
85
|
+
/**
|
|
86
|
+
* Gets chord definitions from the song
|
|
87
|
+
*/
|
|
88
|
+
private getChordDefinitions;
|
|
89
|
+
/**
|
|
90
|
+
* Builds a chord diagram from a chord definition
|
|
91
|
+
*/
|
|
92
|
+
private buildChordDiagram;
|
|
93
|
+
/**
|
|
94
|
+
* Processes fingering information and identifies barres
|
|
95
|
+
*/
|
|
96
|
+
private processFingeringAndBarres;
|
|
97
|
+
/**
|
|
98
|
+
* Adds markers without fingering information
|
|
99
|
+
*/
|
|
100
|
+
private addMarkersWithoutFingering;
|
|
101
|
+
/**
|
|
102
|
+
* Groups frets by finger for barre detection
|
|
103
|
+
*/
|
|
104
|
+
private groupFretsByFinger;
|
|
105
|
+
/**
|
|
106
|
+
* Processes grouped frets/fingers into markers and barres
|
|
107
|
+
*/
|
|
108
|
+
private processFretFingerGroups;
|
|
109
|
+
/**
|
|
110
|
+
* Processes a single finger group into either a marker or barre
|
|
111
|
+
*/
|
|
112
|
+
private processFingerGroup;
|
|
113
|
+
/**
|
|
114
|
+
* Adds a barre if string positions are valid
|
|
115
|
+
*/
|
|
116
|
+
private addBarreIfValid;
|
|
117
|
+
}
|
|
118
|
+
export default ChordDiagramRenderer;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import Dimensions from '../layout/engine/dimensions';
|
|
2
|
+
import Line from '../chord_sheet/line';
|
|
3
|
+
import Song from '../chord_sheet/song';
|
|
4
|
+
import { LineLayout, MeasuredItem } from '../layout/engine';
|
|
5
|
+
import { FontConfiguration, LayoutItem, MeasurementBasedFormatterConfiguration } from '../formatter/configuration';
|
|
6
|
+
/**
|
|
7
|
+
* Interface representing paragraph layouts from the layout engine
|
|
8
|
+
*/
|
|
9
|
+
export interface ParagraphLayout {
|
|
10
|
+
units: LineLayout[][];
|
|
11
|
+
addSpacing: boolean;
|
|
12
|
+
sectionType: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* PositionedElement represents an element with absolute positioning
|
|
16
|
+
*/
|
|
17
|
+
export interface PositionedElement {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
width: number;
|
|
21
|
+
height: number;
|
|
22
|
+
content: any;
|
|
23
|
+
type: string;
|
|
24
|
+
style?: any;
|
|
25
|
+
page: number;
|
|
26
|
+
column: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Abstract renderer class for absolute-positioned rendering
|
|
30
|
+
*/
|
|
31
|
+
declare abstract class Renderer {
|
|
32
|
+
protected song: Song;
|
|
33
|
+
protected startTime: number;
|
|
34
|
+
protected renderTime: number;
|
|
35
|
+
protected x: number;
|
|
36
|
+
protected y: number;
|
|
37
|
+
protected currentColumn: number;
|
|
38
|
+
protected elements: PositionedElement[];
|
|
39
|
+
protected currentPage: number;
|
|
40
|
+
constructor(song: Song);
|
|
41
|
+
/**
|
|
42
|
+
* Initialize the renderer with the song
|
|
43
|
+
*/
|
|
44
|
+
initialize(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Main render method - the only method that formatters should call
|
|
47
|
+
* @param paragraphLayouts The layouts to render
|
|
48
|
+
* @param config Additional configuration options
|
|
49
|
+
*/
|
|
50
|
+
render(paragraphLayouts: ParagraphLayout[], _config?: any): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get the bottom Y position available for content
|
|
53
|
+
*/
|
|
54
|
+
getContentBottomY(): number;
|
|
55
|
+
/**
|
|
56
|
+
* Get metadata about the rendered document
|
|
57
|
+
*/
|
|
58
|
+
abstract getDocumentMetadata(): Record<string, any>;
|
|
59
|
+
/**
|
|
60
|
+
* Get the font configuration for a specific object type
|
|
61
|
+
*/
|
|
62
|
+
abstract getFontConfiguration(objectType: string): FontConfiguration;
|
|
63
|
+
/**
|
|
64
|
+
* Get the current rendering time in seconds
|
|
65
|
+
*/
|
|
66
|
+
getRenderTime(): number;
|
|
67
|
+
/**
|
|
68
|
+
* Renders all paragraph layouts
|
|
69
|
+
*/
|
|
70
|
+
protected renderParagraphs(paragraphLayouts: ParagraphLayout[]): void;
|
|
71
|
+
/**
|
|
72
|
+
* Render lines of content with chords, lyrics, and other elements
|
|
73
|
+
*/
|
|
74
|
+
protected renderLines(lines: LineLayout[]): void;
|
|
75
|
+
private renderLineLayout;
|
|
76
|
+
protected hasColumnBreak(lineLayout: LineLayout): boolean;
|
|
77
|
+
private renderItem;
|
|
78
|
+
private renderChordLyricsPair;
|
|
79
|
+
/**
|
|
80
|
+
* Move to the next column or page
|
|
81
|
+
*/
|
|
82
|
+
protected moveToNextColumn(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Start a new page
|
|
85
|
+
*/
|
|
86
|
+
protected startNewPage(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Calculate chord and lyrics Y offsets based on the line content
|
|
89
|
+
*/
|
|
90
|
+
protected calculateChordLyricYOffsets(items: MeasuredItem[], yOffset: number): {
|
|
91
|
+
chordsYOffset: number;
|
|
92
|
+
lyricsYOffset: number;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Get the maximum chord height for a line
|
|
96
|
+
*/
|
|
97
|
+
protected getMaxChordHeight(items: MeasuredItem[]): number;
|
|
98
|
+
/**
|
|
99
|
+
* Process chords for display (handle modifiers, normalization)
|
|
100
|
+
*/
|
|
101
|
+
protected processChords(chords: string, line: Line): string;
|
|
102
|
+
/**
|
|
103
|
+
* Add a text element to the elements array
|
|
104
|
+
*/
|
|
105
|
+
protected addTextElement(text: string, x: number, y: number, type: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Add a section label element
|
|
108
|
+
*/
|
|
109
|
+
protected addSectionLabel(label: string, x: number, y: number): void;
|
|
110
|
+
/**
|
|
111
|
+
* Add a comment element
|
|
112
|
+
*/
|
|
113
|
+
protected addComment(comment: string, x: number, y: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Get the font configuration for a specific element type
|
|
116
|
+
*/
|
|
117
|
+
protected getFontForType(type: string): FontConfiguration;
|
|
118
|
+
/**
|
|
119
|
+
* Get the total number of pages in the document
|
|
120
|
+
*/
|
|
121
|
+
protected getTotalPages(): number;
|
|
122
|
+
/**
|
|
123
|
+
* Get the starting X position for the current column
|
|
124
|
+
*/
|
|
125
|
+
protected getColumnStartX(): number;
|
|
126
|
+
/**
|
|
127
|
+
* Get the bottom Y position for the current column
|
|
128
|
+
*/
|
|
129
|
+
protected getColumnBottomY(): number;
|
|
130
|
+
/**
|
|
131
|
+
* Get the width of a column
|
|
132
|
+
*/
|
|
133
|
+
protected getColumnWidth(): number;
|
|
134
|
+
/**
|
|
135
|
+
* Get the minimum X coordinate (left margin)
|
|
136
|
+
*/
|
|
137
|
+
protected getMinX(): number;
|
|
138
|
+
/**
|
|
139
|
+
* Get the minimum Y coordinate (top margin + header)
|
|
140
|
+
*/
|
|
141
|
+
protected getMinY(): number;
|
|
142
|
+
/**
|
|
143
|
+
* Record the rendering time
|
|
144
|
+
*/
|
|
145
|
+
protected recordRenderingTime(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Get the elements for a specific page
|
|
148
|
+
*/
|
|
149
|
+
protected getElementsForPage(page: number): PositionedElement[];
|
|
150
|
+
/**
|
|
151
|
+
* Initialize the backend rendering system
|
|
152
|
+
*/
|
|
153
|
+
protected abstract initializeBackend(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Create a new page in the backend
|
|
156
|
+
*/
|
|
157
|
+
protected abstract createNewPage(): void;
|
|
158
|
+
/**
|
|
159
|
+
* Render chord diagrams
|
|
160
|
+
*/
|
|
161
|
+
protected abstract renderChordDiagrams(): void;
|
|
162
|
+
/**
|
|
163
|
+
* Render headers and footers
|
|
164
|
+
*/
|
|
165
|
+
protected abstract renderHeadersAndFooters(): void;
|
|
166
|
+
/**
|
|
167
|
+
* Measure text with the given font
|
|
168
|
+
*/
|
|
169
|
+
protected abstract measureText(text: string, font: FontConfiguration): {
|
|
170
|
+
width: number;
|
|
171
|
+
height: number;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Calculate chord baseline position
|
|
175
|
+
*/
|
|
176
|
+
protected abstract calculateChordBaseline(yOffset: number, items: MeasuredItem[], chordText: string): number;
|
|
177
|
+
/**
|
|
178
|
+
* Finalize the rendering process
|
|
179
|
+
*/
|
|
180
|
+
protected abstract finalizeRendering(): void;
|
|
181
|
+
/**
|
|
182
|
+
* Get the renderer configuration
|
|
183
|
+
*/
|
|
184
|
+
protected abstract getConfiguration(): MeasurementBasedFormatterConfiguration | any;
|
|
185
|
+
/**
|
|
186
|
+
* Get the dimensions object for layout calculations
|
|
187
|
+
*/
|
|
188
|
+
protected abstract get dimensions(): Dimensions;
|
|
189
|
+
/**
|
|
190
|
+
* Get the page size from the document wrapper
|
|
191
|
+
*/
|
|
192
|
+
protected abstract getDocPageSize(): {
|
|
193
|
+
width: number;
|
|
194
|
+
height: number;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Get the layout configuration
|
|
198
|
+
*/
|
|
199
|
+
protected getLayout(): MeasurementBasedFormatterConfiguration['layout'];
|
|
200
|
+
/**
|
|
201
|
+
* Get the header configuration
|
|
202
|
+
*/
|
|
203
|
+
protected getHeaderConfig(): LayoutItem | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Get the footer configuration
|
|
206
|
+
*/
|
|
207
|
+
protected getFooterConfig(): LayoutItem | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Get the page width
|
|
210
|
+
*/
|
|
211
|
+
protected getPageWidth(): number;
|
|
212
|
+
/**
|
|
213
|
+
* Get the page height
|
|
214
|
+
*/
|
|
215
|
+
protected getPageHeight(): number;
|
|
216
|
+
/**
|
|
217
|
+
* Get the left margin
|
|
218
|
+
*/
|
|
219
|
+
protected getLeftMargin(): number;
|
|
220
|
+
/**
|
|
221
|
+
* Get the right margin
|
|
222
|
+
*/
|
|
223
|
+
protected getRightMargin(): number;
|
|
224
|
+
/**
|
|
225
|
+
* Get the top margin
|
|
226
|
+
*/
|
|
227
|
+
protected getTopMargin(): number;
|
|
228
|
+
/**
|
|
229
|
+
* Get the bottom margin
|
|
230
|
+
*/
|
|
231
|
+
protected getBottomMargin(): number;
|
|
232
|
+
/**
|
|
233
|
+
* Get the header height
|
|
234
|
+
*/
|
|
235
|
+
protected getHeaderHeight(): number;
|
|
236
|
+
/**
|
|
237
|
+
* Get the footer height
|
|
238
|
+
*/
|
|
239
|
+
protected getFooterHeight(): number;
|
|
240
|
+
/**
|
|
241
|
+
* Get the column count
|
|
242
|
+
*/
|
|
243
|
+
protected getColumnCount(): number;
|
|
244
|
+
/**
|
|
245
|
+
* Get the sections configuration with defaults
|
|
246
|
+
*/
|
|
247
|
+
protected getSectionsConfig(): import("../formatter/configuration").SectionsConfig;
|
|
248
|
+
/**
|
|
249
|
+
* Get the column spacing
|
|
250
|
+
*/
|
|
251
|
+
protected getColumnSpacing(): number;
|
|
252
|
+
/**
|
|
253
|
+
* Get the chord-to-lyrics spacing
|
|
254
|
+
*/
|
|
255
|
+
protected getChordLyricSpacing(): number;
|
|
256
|
+
/**
|
|
257
|
+
* Get the paragraph spacing
|
|
258
|
+
*/
|
|
259
|
+
protected getParagraphSpacing(): number;
|
|
260
|
+
/**
|
|
261
|
+
* Whether to use Unicode modifiers for chord rendering
|
|
262
|
+
*/
|
|
263
|
+
protected useUnicodeModifiers(): boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Whether to normalize chords
|
|
266
|
+
*/
|
|
267
|
+
protected normalizeChords(): boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Whether to render lyrics only (no chords)
|
|
270
|
+
*/
|
|
271
|
+
protected isLyricsOnly(): boolean;
|
|
272
|
+
}
|
|
273
|
+
export default Renderer;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ImageCompression } from 'jspdf';
|
|
2
|
+
import Metadata from '../../chord_sheet/metadata';
|
|
3
|
+
import { Alignment, FontConfiguration, LayoutContentItemWithText, LayoutItem, LayoutSection, Margins } from '../../formatter/configuration';
|
|
4
|
+
/**
|
|
5
|
+
* Backend abstraction for layout rendering operations.
|
|
6
|
+
* Both PDF and HTML renderers implement this interface.
|
|
7
|
+
*/
|
|
8
|
+
export interface LayoutRenderingBackend {
|
|
9
|
+
pageSize: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
currentPage: number;
|
|
14
|
+
totalPages: number;
|
|
15
|
+
text(content: string, x: number, y: number): void;
|
|
16
|
+
getTextWidth(text: string, font?: FontConfiguration): number;
|
|
17
|
+
splitTextToSize(text: string, maxWidth: number, font?: FontConfiguration): string[];
|
|
18
|
+
setFontStyle(style: FontConfiguration): void;
|
|
19
|
+
setTextItem?(item: LayoutContentItemWithText): void;
|
|
20
|
+
addElement?(element: any, x: number, y: number): void;
|
|
21
|
+
addImage(src: string, format: string, x: number, y: number, width: number, height: number, alias?: string, compression?: ImageCompression, rotation?: number): void;
|
|
22
|
+
line(x1: number, y1: number, x2: number, y2: number): void;
|
|
23
|
+
setLineStyle(style: any): void;
|
|
24
|
+
resetDash(): void;
|
|
25
|
+
setDrawColor?(color: number): void;
|
|
26
|
+
setLineWidth?(width: number): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Context for rendering layout sections (headers/footers)
|
|
30
|
+
*/
|
|
31
|
+
export interface LayoutRenderingContext {
|
|
32
|
+
metadata: Metadata;
|
|
33
|
+
margins: Margins;
|
|
34
|
+
extraMetadata: Record<string, string | string[]>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Renders layout sections (headers and footers) for both PDF and HTML backends.
|
|
38
|
+
* This extracts the common layout rendering logic that was duplicated across renderers.
|
|
39
|
+
*/
|
|
40
|
+
export declare class LayoutSectionRenderer {
|
|
41
|
+
private backend;
|
|
42
|
+
private context;
|
|
43
|
+
constructor(backend: LayoutRenderingBackend, context: LayoutRenderingContext);
|
|
44
|
+
/**
|
|
45
|
+
* Renders a layout section (header or footer)
|
|
46
|
+
*/
|
|
47
|
+
renderLayout(layoutConfig: LayoutItem, section: LayoutSection): void;
|
|
48
|
+
/**
|
|
49
|
+
* Determines if a content item should be rendered based on conditions
|
|
50
|
+
*/
|
|
51
|
+
private shouldRenderContent;
|
|
52
|
+
/**
|
|
53
|
+
* Renders a text item
|
|
54
|
+
*/
|
|
55
|
+
private renderTextItem;
|
|
56
|
+
/**
|
|
57
|
+
* Renders clipped text with optional ellipsis
|
|
58
|
+
*/
|
|
59
|
+
private renderClippedText;
|
|
60
|
+
/**
|
|
61
|
+
* Clips text with ellipsis if it exceeds the maximum width
|
|
62
|
+
*/
|
|
63
|
+
private clipTextWithEllipsis;
|
|
64
|
+
/**
|
|
65
|
+
* Clips text to fit within the maximum width
|
|
66
|
+
*/
|
|
67
|
+
clipText(text: string, maxWidth: number, style?: FontConfiguration): string;
|
|
68
|
+
/**
|
|
69
|
+
* Renders multiline text
|
|
70
|
+
*/
|
|
71
|
+
private renderMultilineText;
|
|
72
|
+
/**
|
|
73
|
+
* Renders an image
|
|
74
|
+
*/
|
|
75
|
+
private renderImage;
|
|
76
|
+
/**
|
|
77
|
+
* Renders a line
|
|
78
|
+
*/
|
|
79
|
+
private renderLine;
|
|
80
|
+
/**
|
|
81
|
+
* Evaluates a template with metadata
|
|
82
|
+
*/
|
|
83
|
+
private evaluateTemplate;
|
|
84
|
+
/**
|
|
85
|
+
* Calculates the X position based on alignment
|
|
86
|
+
*/
|
|
87
|
+
calculateX(alignment: Alignment | number, width?: number, offsetX?: number): number;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the available width for content
|
|
90
|
+
*/
|
|
91
|
+
private getAvailableWidth;
|
|
92
|
+
}
|
|
93
|
+
export default LayoutSectionRenderer;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ChordType, Mode, ModifierMaybe } from './constants';
|
|
2
|
+
export declare const KEY_TO_GRADE: Record<ChordType, Record<Mode, Record<ModifierMaybe, Record<string, number>>>>;
|
|
3
|
+
export declare const GRADE_TO_KEY: Record<ChordType, Record<Mode, Record<ModifierMaybe, Record<number, string>>>>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Accidental, ChordType, Fret } from './constants';
|
|
2
|
+
export interface SerializedTraceInfo {
|
|
3
|
+
location?: {
|
|
4
|
+
offset: number | null;
|
|
5
|
+
line: number | null;
|
|
6
|
+
column: number | null;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface SerializedChord {
|
|
10
|
+
type: 'chord';
|
|
11
|
+
base: string;
|
|
12
|
+
accidental: Accidental | null;
|
|
13
|
+
suffix: string | null;
|
|
14
|
+
bassBase: string | null;
|
|
15
|
+
bassAccidental: Accidental | null;
|
|
16
|
+
chordType: ChordType;
|
|
17
|
+
optional?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface SerializedChordLyricsPair {
|
|
20
|
+
type: 'chordLyricsPair';
|
|
21
|
+
chord?: SerializedChord | null;
|
|
22
|
+
chords: string;
|
|
23
|
+
lyrics: string | null;
|
|
24
|
+
annotation?: string | null;
|
|
25
|
+
isRhythmSymbol?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface SerializedChordDefinition {
|
|
28
|
+
name: string;
|
|
29
|
+
baseFret: number;
|
|
30
|
+
frets: Fret[];
|
|
31
|
+
fingers?: number[];
|
|
32
|
+
}
|
|
33
|
+
export type SerializedTag = SerializedTraceInfo & {
|
|
34
|
+
type: 'tag';
|
|
35
|
+
name: string;
|
|
36
|
+
value: string;
|
|
37
|
+
chordDefinition?: SerializedChordDefinition;
|
|
38
|
+
attributes?: Record<string, string>;
|
|
39
|
+
selector?: string | null;
|
|
40
|
+
isNegated?: boolean;
|
|
41
|
+
};
|
|
42
|
+
export interface SerializedComment {
|
|
43
|
+
type: 'comment';
|
|
44
|
+
comment: string;
|
|
45
|
+
}
|
|
46
|
+
export type ContentType = 'tab' | 'abc' | 'ly' | 'svg' | 'grid' | 'textblock';
|
|
47
|
+
export type PartTypes = 'part' | 'intro' | 'instrumental' | 'tag' | 'end';
|
|
48
|
+
export interface SerializedSection {
|
|
49
|
+
type: 'section';
|
|
50
|
+
sectionType: ContentType;
|
|
51
|
+
content: string[];
|
|
52
|
+
startTag: SerializedTag;
|
|
53
|
+
endTag: SerializedTag;
|
|
54
|
+
}
|
|
55
|
+
export type SerializedLiteral = string;
|
|
56
|
+
export interface SerializedTernary extends SerializedTraceInfo {
|
|
57
|
+
type: 'ternary';
|
|
58
|
+
variable: string | null;
|
|
59
|
+
valueTest: string | null;
|
|
60
|
+
trueExpression: (SerializedLiteral | SerializedTernary)[];
|
|
61
|
+
falseExpression: (SerializedLiteral | SerializedTernary)[];
|
|
62
|
+
}
|
|
63
|
+
export type SerializedComposite = (SerializedLiteral | SerializedTernary)[];
|
|
64
|
+
export interface SerializedSoftLineBreak {
|
|
65
|
+
type: 'softLineBreak';
|
|
66
|
+
}
|
|
67
|
+
export type SerializedItem = SerializedChordLyricsPair | SerializedComment | SerializedLiteral | SerializedSoftLineBreak | SerializedTag | SerializedTernary;
|
|
68
|
+
export interface SerializedLine {
|
|
69
|
+
type: 'line';
|
|
70
|
+
items: SerializedItem[];
|
|
71
|
+
}
|
|
72
|
+
export interface SerializedSong {
|
|
73
|
+
type: 'chordSheet';
|
|
74
|
+
lines: SerializedLine[];
|
|
75
|
+
}
|
|
76
|
+
export type SerializedComponent = SerializedLine | SerializedSong | SerializedChordLyricsPair | SerializedTag | SerializedComment | SerializedTernary | SerializedLiteral | SerializedSection | SerializedSoftLineBreak;
|