notations 0.0.69 → 1.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/dist/NotationView.css +20 -0
- package/dist/NotationView.css.map +1 -1
- package/dist/NotationView.min.css +1 -1
- package/dist/NotationView.min.css.map +1 -1
- package/dist/notations.umd.js +17425 -23624
- package/dist/notations.umd.min.js +8 -3
- package/dist/notations.umd.min.js.LICENSE.txt +0 -14
- package/dist/notations.umd.min.js.map +1 -1
- package/lib/cjs/beats.d.ts +4 -0
- package/lib/cjs/beats.js +19 -2
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/block.d.ts +85 -0
- package/lib/cjs/block.js +310 -0
- package/lib/cjs/block.js.map +1 -0
- package/lib/cjs/carnatic/NotationView.d.ts +11 -4
- package/lib/cjs/carnatic/NotationView.js +25 -11
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/commands.d.ts +25 -11
- package/lib/cjs/commands.js +83 -31
- package/lib/cjs/commands.js.map +1 -1
- package/lib/cjs/entity.d.ts +3 -7
- package/lib/cjs/entity.js +7 -37
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/grids.d.ts +32 -3
- package/lib/cjs/grids.js +96 -9
- package/lib/cjs/grids.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/loader.js +1 -41
- package/lib/cjs/loader.js.map +1 -1
- package/lib/cjs/notation.d.ts +20 -36
- package/lib/cjs/notation.js +100 -133
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.d.ts +21 -6
- package/lib/cjs/parser.js +122 -23
- package/lib/cjs/parser.js.map +1 -1
- package/lib/esm/beats.d.ts +4 -0
- package/lib/esm/beats.js +19 -2
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/block.d.ts +85 -0
- package/lib/esm/block.js +293 -0
- package/lib/esm/block.js.map +1 -0
- package/lib/esm/carnatic/NotationView.d.ts +11 -4
- package/lib/esm/carnatic/NotationView.js +25 -11
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/commands.d.ts +25 -11
- package/lib/esm/commands.js +80 -31
- package/lib/esm/commands.js.map +1 -1
- package/lib/esm/entity.d.ts +3 -7
- package/lib/esm/entity.js +7 -37
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/grids.d.ts +32 -3
- package/lib/esm/grids.js +96 -9
- package/lib/esm/grids.js.map +1 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/loader.js +1 -8
- package/lib/esm/loader.js.map +1 -1
- package/lib/esm/notation.d.ts +20 -36
- package/lib/esm/notation.js +84 -128
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.d.ts +21 -6
- package/lib/esm/parser.js +122 -24
- package/lib/esm/parser.js.map +1 -1
- package/package.json +3 -2
- package/styles/NotationView.scss +22 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/block.ts"],"names":[],"mappings":";;;AAyDA,0BAEC;AAKD,wBAEC;AAKD,gCAEC;AAwXD,kDASC;AAzcD,qCAAkC;AAElC,iCAA8B;AAC9B,uCAAyC;AAMzC,MAAa,OAAO;IAApB;QAEE,SAAI,GAAG,EAAE,CAAC;QAGV,cAAS,GAAG,KAAK,CAAC;QAGlB,UAAK,GAAG,CAAC,CAAC;IACZ,CAAC;CAAA;AATD,0BASC;AAMD,MAAa,QAAS,SAAQ,eAAM;IAQlC,YACS,OAAe,EACf,cAAsB,IAAI;QAEjC,KAAK,EAAE,CAAC;QAHD,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAe;QAT1B,SAAI,GAAW,UAAU,CAAC;IAYnC,CAAC;IAMD,UAAU;QACR,uCAAY,KAAK,CAAC,UAAU,EAAE,KAAE,OAAO,EAAE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;AAND,8BAMC;AAOD,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,SAAwB,EAAE,SAA8B,IAAI;QACtE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;CACF;AAJD,gCAIC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\n\n/**\n * Definition of a role in a block context.\n * This is used for block-scoped role definitions.\n */\nexport class RoleDef {\n /** Name of the role */\n name = \"\";\n\n /** Whether this role contains only notes (true) or can also contain syllables/text (false) */\n notesOnly = false;\n\n /** Index of this role in the notation */\n index = 0;\n}\n\n/**\n * Represents a raw block of content in the notation.\n * Raw blocks can contain arbitrary content like markdown, HTML, etc.\n */\nexport class RawBlock extends Entity {\n readonly TYPE: string = \"RawBlock\";\n\n /**\n * Creates a new RawBlock.\n * @param content The content of the block\n * @param contentType The type of content (e.g., \"md\" for markdown)\n */\n constructor(\n public content: string,\n public contentType: string = \"md\",\n ) {\n super();\n }\n\n /**\n * Returns a debug-friendly representation of this raw block.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { ...super.debugValue(), content: this.content, contentType: this.contentType };\n }\n}\n\n/**\n * Union type for items that can appear in a block.\n */\nexport type BlockItem = Block | Line | RawBlock;\n\n/**\n * Type guard to check if an entity is a Block.\n */\nexport function isBlock(item: BlockItem): item is Block {\n return item.TYPE === \"Block\";\n}\n\n/**\n * Type guard to check if an entity is a Line.\n */\nexport function isLine(item: BlockItem): item is Line {\n return item.TYPE === \"Line\";\n}\n\n/**\n * Type guard to check if an entity is a RawBlock.\n */\nexport function isRawBlock(item: BlockItem): item is RawBlock {\n return item.TYPE === \"RawBlock\";\n}\n\n/**\n * Represents a scoped block created by a command with braces.\n * For example: \\section(\"Pallavi\") { ... }\n *\n * Blocks inherit properties from their parent Block and can override them locally.\n * Properties are resolved lazily by walking up the tree.\n *\n * Block = Command + Children (unified model)\n */\nexport class Block extends Entity {\n readonly TYPE: string = \"Block\";\n\n /** The type of block (e.g., \"section\", \"repeat\", \"cycle\") */\n readonly blockType: string;\n\n /** Optional name for the block (e.g., section name) */\n readonly name: TSU.Nullable<string>;\n\n /** Child items (before expansion by subclasses) */\n readonly blockItems: BlockItem[] = [];\n\n // Local properties\n localCycle: TSU.Nullable<Cycle> = null;\n localAtomsPerBeat: TSU.Nullable<number> = null;\n localBreaks: TSU.Nullable<number[]> = null;\n readonly localRoles = new Map<string, RoleDef>();\n\n // Store parent reference (Block or null for root)\n private _parentBlock: TSU.Nullable<Block> = null;\n\n // State tracking for command application (protected for Notation override)\n protected _currRoleDef: TSU.Nullable<RoleDef> = null;\n protected _currentLine: TSU.Nullable<Line> = null;\n\n /**\n * Creates a new Block.\n * @param blockType The type of block (e.g., \"section\", \"group\")\n * @param parent The parent block (null for root)\n * @param name Optional name for the block\n */\n constructor(blockType: string, parent: TSU.Nullable<Block> = null, name: TSU.Nullable<string> = null) {\n super();\n this.blockType = blockType;\n this.name = name;\n this._parentBlock = parent;\n // Also set Entity's parent for tree traversal\n if (parent) {\n this.setParent(parent);\n }\n }\n\n /**\n * Returns the expanded children for layout iteration.\n * Subclasses can override this to transform children (e.g., Repeat, Section).\n */\n children(): BlockItem[] {\n return this.blockItems;\n }\n\n /**\n * Gets the parent block.\n */\n get parentBlock(): TSU.Nullable<Block> {\n return this._parentBlock;\n }\n\n // ============================================\n // Property inheritance via tree walking\n // ============================================\n\n /**\n * Gets the effective cycle by walking up the tree.\n */\n get cycle(): TSU.Nullable<Cycle> {\n if (this.localCycle !== null) {\n return this.localCycle;\n }\n return this.parentBlock?.cycle ?? null;\n }\n\n /**\n * Gets the effective atoms per beat by walking up the tree.\n * Defaults to 1 if not set anywhere in the tree.\n */\n get atomsPerBeat(): number {\n if (this.localAtomsPerBeat !== null) {\n return this.localAtomsPerBeat;\n }\n return this.parentBlock?.atomsPerBeat ?? 1;\n }\n\n /**\n * Gets the effective line breaks by walking up the tree.\n * Defaults to empty array if not set anywhere.\n */\n get breaks(): number[] {\n if (this.localBreaks !== null) {\n return this.localBreaks;\n }\n return this.parentBlock?.breaks ?? [];\n }\n\n // ============================================\n // Layout parameters management\n // ============================================\n\n /** Layout parameters caching for this block scope */\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _layoutParams: LayoutParams | null = null;\n\n /**\n * Gets the unnamed layout parameters for this block.\n */\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n /**\n * Gets the named layout parameters for this block.\n */\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n /**\n * Gets the current layout parameters for this block scope.\n * Uses the effective cycle, atomsPerBeat, and breaks from tree walking.\n * Creates or finds a matching LayoutParams if needed.\n */\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // Find or create layout params matching current effective values\n this._layoutParams = this.findUnnamedLayoutParams();\n if (this._layoutParams == null) {\n this._layoutParams = this.snapshotLayoutParams();\n this._unnamedLayoutParams.push(this._layoutParams);\n }\n }\n return this._layoutParams;\n }\n\n /**\n * Resets the current layout parameters to null.\n * Called when layout-affecting properties change.\n */\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n /**\n * Creates a snapshot of the current layout parameters.\n * @returns A new LayoutParams object with the current effective settings\n */\n protected snapshotLayoutParams(): LayoutParams {\n const effectiveCycle = this.cycle;\n if (effectiveCycle == null) {\n throw new Error(\"Cannot create layout params: no cycle defined\");\n }\n return new LayoutParams({\n cycle: effectiveCycle,\n beatDuration: this.atomsPerBeat,\n layout: this.breaks,\n });\n }\n\n /**\n * Finds an unnamed layout parameters object that matches the current effective settings.\n * @returns Matching layout parameters, or null if none found\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n const effectiveCycle = this.cycle;\n if (effectiveCycle == null) return null;\n\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.atomsPerBeat && effectiveCycle.equals(lp.cycle) && lp.lineBreaksEqual(this.breaks)\n );\n }) || null\n );\n }\n\n /**\n * Ensures that named layout parameters with the given name exist.\n * @param name The name of the layout parameters\n * @returns The layout parameters\n */\n ensureNamedLayoutParams(name: string): LayoutParams {\n let lp = this._namedLayoutParams.get(name) || null;\n if (lp == null || this._layoutParams != lp) {\n if (lp == null) {\n // Create new named layout params\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // Copy named LPs attributes into our locals\n this.localCycle = lp.cycle;\n this.localAtomsPerBeat = lp.beatDuration;\n this.localBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine();\n }\n return this._layoutParams!;\n }\n\n /**\n * Gets a role definition by name, walking up the tree if not found locally.\n * @param name The name of the role\n */\n getRole(name: string): TSU.Nullable<RoleDef> {\n const local = this.localRoles.get(name.toLowerCase());\n if (local) {\n return local;\n }\n return this.parentBlock?.getRole(name) ?? null;\n }\n\n // ============================================\n // State tracking for command application\n // ============================================\n\n /**\n * Gets the current role definition.\n * Falls back to parent's current role or the last defined role.\n */\n get currRoleDef(): TSU.Nullable<RoleDef> {\n if (this._currRoleDef !== null) {\n return this._currRoleDef;\n }\n // Fall back to parent's current role\n if (this.parentBlock) {\n return this.parentBlock.currRoleDef;\n }\n // Or use the last locally defined role\n const roles = Array.from(this.localRoles.values());\n return roles.length > 0 ? roles[roles.length - 1] : null;\n }\n\n /**\n * Sets the current role by name.\n * If the role doesn't exist, tries to create it via the root container's onMissingRole.\n * @param name The name of the role to activate\n * @throws Error if the role is not found and cannot be created\n */\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name === \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n let roleDef = this.getRole(name);\n // If role not found, try auto-creation\n if (roleDef == null) {\n // Create the role locally in this block\n // Default: \"sw\" is notes-only, others are not\n roleDef = this.newRoleDef(name, name === \"sw\");\n }\n this._currRoleDef = roleDef;\n }\n\n /**\n * Gets the current line, creating one if needed.\n */\n get currentLine(): Line {\n if (this._currentLine === null) {\n return this.newLine();\n }\n return this._currentLine;\n }\n\n /**\n * Creates a new line in this block.\n */\n newLine(): Line {\n if (this._currentLine !== null && this._currentLine.isEmpty) {\n // Remove empty line before creating new one\n this.removeBlockItem(this._currentLine);\n }\n this._currentLine = new Line();\n this.addBlockItem(this._currentLine);\n return this._currentLine;\n }\n\n /**\n * Resets the current line pointer to null.\n * Called when layout parameters change to force a new line.\n */\n resetLine(): void {\n this._currentLine = null;\n }\n\n /**\n * Creates a new role definition local to this block.\n * @param name The name of the role\n * @param notesOnly Whether this role contains only notes\n */\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name === \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n if (this.localRoles.has(name)) {\n throw new Error(`Role '${name}' already exists in this block`);\n }\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.localRoles.size;\n this.localRoles.set(name, rd);\n return rd;\n }\n\n // ============================================\n // Child management\n // ============================================\n\n /**\n * Adds a child item to this block.\n * @param item The item to add\n */\n addBlockItem(item: BlockItem): void {\n item.setParent(this);\n this.blockItems.push(item);\n }\n\n /**\n * Removes a child item from this block.\n * @param item The item to remove\n * @returns The index of the removed item, or -1 if not found\n */\n removeBlockItem(item: BlockItem): number {\n const index = this.blockItems.indexOf(item);\n if (index >= 0) {\n this.blockItems.splice(index, 1);\n item.setParent(null);\n }\n return index;\n }\n\n /**\n * Returns a debug-friendly representation of this block.\n */\n debugValue(): any {\n const out: any = {\n ...super.debugValue(),\n blockType: this.blockType,\n blockItems: this.blockItems.map((c) => c.debugValue()),\n };\n if (this.name) {\n out.name = this.name;\n }\n if (this.localCycle) {\n out.localCycle = this.localCycle.uuid;\n }\n if (this.localAtomsPerBeat !== null) {\n out.localAtomsPerBeat = this.localAtomsPerBeat;\n }\n if (this.localBreaks !== null) {\n out.localBreaks = this.localBreaks;\n }\n if (this.localRoles.size > 0) {\n out.localRoles = Array.from(this.localRoles.keys());\n }\n return out;\n }\n}\n\n/**\n * Helper function to find the containing block of an entity by walking up the tree.\n * @param entity The entity to start from\n * @returns The containing Block, or null if not found\n */\nexport function findContainingBlock(entity: Entity): TSU.Nullable<Block> {\n let current: TSU.Nullable<Entity> = entity.parent;\n while (current !== null) {\n if (current instanceof Block) {\n return current;\n }\n current = current.parent;\n }\n return null;\n}\n\n// ============================================\n// Block Subclasses\n// ============================================\n\n/**\n * A section block with a heading.\n * Expands children to include a heading RawBlock followed by the content.\n *\n * Usage: \\section(\"Pallavi\") { ... }\n */\nexport class SectionBlock extends Block {\n constructor(sectionName: string, parent: TSU.Nullable<Block> = null) {\n super(\"section\", parent, sectionName);\n }\n\n /**\n * Expands children to include a heading RawBlock.\n */\n children(): BlockItem[] {\n const heading = new RawBlock(`# ${this.name}`, \"md\");\n return [heading, ...this.blockItems];\n }\n}\n\n/**\n * A repeat block that expands its children N times.\n *\n * Usage: \\repeat(2) { ... }\n */\nexport class RepeatBlock extends Block {\n /** Number of times to repeat (0 = visual markers only) */\n readonly repeatCount: number;\n\n constructor(repeatCount: number, parent: TSU.Nullable<Block> = null) {\n super(\"repeat\", parent);\n this.repeatCount = repeatCount;\n }\n\n /**\n * Expands children by repeating them N times.\n * If count is 0, returns children as-is (visual repeat markers only).\n */\n children(): BlockItem[] {\n if (this.repeatCount <= 0) {\n return this.blockItems;\n }\n const expanded: BlockItem[] = [];\n for (let i = 0; i < this.repeatCount; i++) {\n expanded.push(...this.blockItems);\n }\n return expanded;\n }\n}\n\n/**\n * A cycle block that sets localCycle for scoped notation.\n *\n * Usage: \\cycle(\"|4|4|\") { ... }\n */\nexport class CycleBlock extends Block {\n constructor(cycle: Cycle, parent: TSU.Nullable<Block> = null) {\n super(\"cycle\", parent);\n this.localCycle = cycle;\n }\n}\n\n/**\n * A beat duration block that sets localAtomsPerBeat for scoped notation.\n *\n * Usage: \\beatDuration(2) { ... }\n */\nexport class BeatDurationBlock extends Block {\n constructor(atomsPerBeat: number, parent: TSU.Nullable<Block> = null) {\n super(\"beatduration\", parent);\n this.localAtomsPerBeat = atomsPerBeat;\n }\n}\n\n/**\n * A breaks block that sets localBreaks for scoped notation.\n *\n * Usage: \\breaks(4, 2, 2) { ... }\n */\nexport class BreaksBlock extends Block {\n constructor(breaks: number[], parent: TSU.Nullable<Block> = null) {\n super(\"breaks\", parent);\n this.localBreaks = breaks;\n }\n}\n\n/**\n * A role block that creates a local role definition.\n *\n * Usage: \\role(\"Vocals\", notes=false) { ... }\n */\nexport class RoleBlock extends Block {\n constructor(roleName: string, notesOnly: boolean, parent: TSU.Nullable<Block> = null) {\n super(\"role\", parent);\n // Create the role locally\n this.newRoleDef(roleName, notesOnly);\n }\n}\n\n/**\n * A group block for organizing notation without special semantics.\n *\n * Usage: \\group(\"optional-name\") { ... }\n */\nexport class GroupBlock extends Block {\n constructor(groupName: string | null, parent: TSU.Nullable<Block> = null) {\n super(\"group\", parent, groupName);\n }\n}\n"]}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
2
|
import { LineView } from "./LineView";
|
|
3
|
-
import { Notation, RawBlock } from "../notation";
|
|
3
|
+
import { Notation, RawBlock, Block, BlockItem } from "../notation";
|
|
4
4
|
import { GlobalBeatLayout } from "../beats";
|
|
5
|
-
import { GridCell, GridCellView } from "../grids";
|
|
5
|
+
import { GridCell, GridCellView, GridLayoutGroup } from "../grids";
|
|
6
6
|
import { Line } from "../core";
|
|
7
7
|
import { BeatView, MarkerView } from "./beatviews";
|
|
8
|
+
export interface NotationViewConfig {
|
|
9
|
+
sharedGridLayoutGroup?: GridLayoutGroup;
|
|
10
|
+
markdownParser?: (contents: string) => string;
|
|
11
|
+
}
|
|
8
12
|
export declare class NotationView {
|
|
9
13
|
readonly rootElement: HTMLElement;
|
|
10
|
-
readonly config?:
|
|
14
|
+
readonly config?: NotationViewConfig | undefined;
|
|
11
15
|
headerElement: HTMLDivElement;
|
|
12
16
|
notation: Notation;
|
|
13
17
|
lineViews: LineView[];
|
|
@@ -15,7 +19,8 @@ export declare class NotationView {
|
|
|
15
19
|
tableElement: HTMLTableElement;
|
|
16
20
|
markdownParser: (contents: string) => string;
|
|
17
21
|
_beatLayout: GlobalBeatLayout;
|
|
18
|
-
|
|
22
|
+
private layoutChangeUnsubscribe;
|
|
23
|
+
constructor(rootElement: HTMLElement, config?: NotationViewConfig | undefined);
|
|
19
24
|
get beatLayout(): GlobalBeatLayout;
|
|
20
25
|
set beatLayout(beatLayout: GlobalBeatLayout);
|
|
21
26
|
loadChildViews(): void;
|
|
@@ -27,6 +32,8 @@ export declare class NotationView {
|
|
|
27
32
|
get currentLineView(): LineView;
|
|
28
33
|
clear(): void;
|
|
29
34
|
refreshLayout(): void;
|
|
35
|
+
protected processBlock(block: Block, lineViews: LineView[]): void;
|
|
36
|
+
protected processBlockItem(item: BlockItem, lineViews: LineView[]): void;
|
|
30
37
|
renderBlock(raw: RawBlock): void;
|
|
31
38
|
beatViews: Map<number, BeatView>;
|
|
32
39
|
markerViews: Map<string, MarkerView>;
|
|
@@ -36,16 +36,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.NotationView = void 0;
|
|
37
37
|
const TSU = __importStar(require("@panyam/tsutils"));
|
|
38
38
|
const LineView_1 = require("./LineView");
|
|
39
|
+
const notation_1 = require("../notation");
|
|
39
40
|
const beatviews_1 = require("./beatviews");
|
|
40
41
|
class NotationView {
|
|
41
42
|
constructor(rootElement, config) {
|
|
43
|
+
var _a;
|
|
42
44
|
this.rootElement = rootElement;
|
|
43
45
|
this.config = config;
|
|
44
46
|
this.lineViews = [];
|
|
45
47
|
this.currentSVGElement = null;
|
|
48
|
+
this.layoutChangeUnsubscribe = null;
|
|
46
49
|
this.beatViews = new Map();
|
|
47
50
|
this.markerViews = new Map();
|
|
48
51
|
this.loadChildViews();
|
|
52
|
+
this.markdownParser = (_a = config === null || config === void 0 ? void 0 : config.markdownParser) !== null && _a !== void 0 ? _a : ((content) => content);
|
|
49
53
|
}
|
|
50
54
|
get beatLayout() {
|
|
51
55
|
return this._beatLayout;
|
|
@@ -140,18 +144,8 @@ class NotationView {
|
|
|
140
144
|
this.beatViews = new Map();
|
|
141
145
|
}
|
|
142
146
|
refreshLayout() {
|
|
143
|
-
const lines = [];
|
|
144
147
|
const lineViews = [];
|
|
145
|
-
|
|
146
|
-
if (block.TYPE == "RawBlock") {
|
|
147
|
-
this.renderBlock(block);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
lines.push(block);
|
|
151
|
-
const lineView = this.ensureLineView(block);
|
|
152
|
-
lineViews.push(lineView);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
148
|
+
this.processBlock(this.notation, lineViews);
|
|
155
149
|
const now = performance.now();
|
|
156
150
|
for (const lineView of lineViews) {
|
|
157
151
|
lineView.gridModel.lastUpdatedAt = now;
|
|
@@ -161,6 +155,26 @@ class NotationView {
|
|
|
161
155
|
lineView.wrapToSize();
|
|
162
156
|
}
|
|
163
157
|
}
|
|
158
|
+
processBlock(block, lineViews) {
|
|
159
|
+
for (const child of block.children()) {
|
|
160
|
+
this.processBlockItem(child, lineViews);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
processBlockItem(item, lineViews) {
|
|
164
|
+
if ((0, notation_1.isRawBlock)(item)) {
|
|
165
|
+
this.renderBlock(item);
|
|
166
|
+
}
|
|
167
|
+
else if ((0, notation_1.isLine)(item)) {
|
|
168
|
+
const line = item;
|
|
169
|
+
if (!line.isEmpty) {
|
|
170
|
+
const lineView = this.ensureLineView(line);
|
|
171
|
+
lineViews.push(lineView);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if ((0, notation_1.isBlock)(item)) {
|
|
175
|
+
this.processBlock(item, lineViews);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
164
178
|
renderBlock(raw) {
|
|
165
179
|
const [, td2] = this.addNewRow(raw.uuid + "", "rawBlock", false);
|
|
166
180
|
if (raw.contentType == "metadata") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,yCAAsC;AAKtC,2CAAmD;AAEnD,MAAa,YAAY;IAUvB,YACkB,WAAwB,EACxB,MAAY;QADZ,gBAAW,GAAX,WAAW,CAAa;QACxB,WAAM,GAAN,MAAM,CAAM;QAT9B,cAAS,GAAe,EAAE,CAAC;QAE3B,sBAAiB,GAAyB,IAAI,CAAC;QA2K/C,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QACxC,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QAnK1C,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU,CAAC,UAA4B;QACzC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,UAAU,CAAC,eAAe,CAAC,WAAW,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE;YAC9C,MAAM,EAAE,IAAI,CAAC,WAAW;YACxB,KAAK,EAAE;gBACL,KAAK,EAAE,2BAA2B;aACnC;SACF,CAAqB,CAAC;IACzB,CAAC;IAED,cAAc,CAAC,QAAkB,EAAE,UAA4B;QAC7D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,MAAM,SAAS,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AC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAhND,oCAgNC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock } from \"../notation\";\nimport { Beat, GlobalBeatLayout } from \"../beats\";\nimport { GridCell, GridCellView } from \"../grids\";\nimport { Line } from \"../core\";\nimport { BeatView, MarkerView } from \"./beatviews\";\n\nexport class NotationView {\n headerElement: HTMLDivElement;\n notation: Notation;\n lineViews: LineView[] = [];\n // Mapping from line id -> list of beats in each of its roles\n currentSVGElement: SVGSVGElement | null = null;\n tableElement: HTMLTableElement;\n markdownParser: (contents: string) => string;\n _beatLayout: GlobalBeatLayout;\n\n constructor(\n public readonly rootElement: HTMLElement,\n public readonly config?: any,\n ) {\n this.loadChildViews();\n }\n\n get beatLayout(): GlobalBeatLayout {\n return this._beatLayout;\n }\n\n set beatLayout(beatLayout: GlobalBeatLayout) {\n this._beatLayout = beatLayout;\n beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);\n }\n\n loadChildViews(): void {\n this.tableElement = TSU.DOM.createNode(\"table\", {\n parent: this.rootElement,\n attrs: {\n class: \"notationsContentRootTable\",\n },\n }) as HTMLTableElement;\n }\n\n renderNotation(notation: Notation, beatLayout: GlobalBeatLayout): void {\n this.notation = notation;\n this.beatLayout = beatLayout;\n const startTime = performance.now();\n this.refreshLayout();\n const layoutTime = performance.now();\n console.log(`V4 Document, Layout Time: ${layoutTime - startTime}ms`);\n }\n\n public addNewRow(id: string, prefix: string, withAnnotation = true): [HTMLElement, HTMLElement] {\n const tr = TSU.DOM.createNode(\"tr\", {\n parent: this.tableElement, // parent,\n attrs: {\n class: prefix + \"Row\",\n id: prefix + \"Row\" + id,\n },\n });\n let td1: HTMLElement | null = null;\n if (withAnnotation) {\n td1 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"AnnotationCell\",\n id: prefix + \"Annotation\" + id,\n },\n }) as HTMLElement;\n }\n const td2 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"ContentCell\",\n id: prefix + \"Content\" + id,\n colspan: withAnnotation ? 1 : 2,\n },\n }) as HTMLElement;\n return [td1!, td2];\n }\n\n public newLineRoot(parent: Element, line: Line): SVGSVGElement {\n const [td1, td2] = this.addNewRow(line.uuid + \"\", \"line\");\n // Hacky solution to \"line headings\"\n if (line.marginText) {\n td1.innerHTML = line.marginText;\n }\n return TSU.DOM.createSVGNode(\"svg\", {\n parent: td2, // parent\n attrs: {\n style: \"margin-bottom: 10px\",\n class: \"lineRootSVG\",\n },\n }) as SVGSVGElement;\n }\n\n ensureLineView(line: Line): LineView {\n let lineView = this.getLineView(line);\n if (lineView == null) {\n const layoutParams = line.layoutParams || null;\n const svgElem = this.newLineRoot(this.tableElement, line);\n lineView = new LineView(svgElem, line, {\n layoutParams: layoutParams,\n } as any);\n if (!line.isEmpty) {\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(layoutParams != null, \"Layout params for a non empty line *should* exist\");\n lineView.gridModel = this.beatLayout!.getGridModelForLine(line.uuid);\n }\n this.lineViews.push(lineView);\n }\n return lineView;\n }\n\n getLineView(line: Line): TSU.Nullable<LineView> {\n return this.lineViews.find((l) => l.line == line) || null;\n }\n\n get currentLineView(): LineView {\n return this.lineViews[this.lineViews.length - 1];\n }\n\n clear(): void {\n this.lineViews = [];\n // Mapping from line id -> list of beats in each of its roles\n this.currentSVGElement = null;\n this.tableElement.innerHTML = \"\";\n this.beatViews = new Map<number, BeatView>();\n }\n\n /**\n * Layout all the blocks in the Notation along with their corresponding blocks.\n * Key thing is here is an opportunity to perform any batch rendering as needed.\n */\n refreshLayout(): void {\n const lines = [] as Line[];\n const lineViews = [] as LineView[];\n for (const block of this.notation.blocks) {\n if (block.TYPE == \"RawBlock\") {\n // Add the markdown here\n this.renderBlock(block as RawBlock);\n } else {\n lines.push(block as Line);\n const lineView = this.ensureLineView(block as Line);\n lineViews.push(lineView);\n }\n }\n\n const now = performance.now();\n for (const lineView of lineViews) {\n lineView.gridModel.lastUpdatedAt = now;\n }\n\n this.beatLayout.gridLayoutGroup.refreshLayout();\n\n for (const lineView of lineViews) {\n lineView.wrapToSize();\n }\n\n // now that all spacing has been calculated\n // go through all\n // for (const beatView of this.beatViews.values()) { beatView.refreshLayout(); }\n }\n\n renderBlock(raw: RawBlock): void {\n const [, td2] = this.addNewRow(raw.uuid + \"\", \"rawBlock\", false);\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n // For now ignore metadata with \":\" in the key\n if (meta.key.toLowerCase().indexOf(\":\") < 0) {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n }\n } else {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n div.innerHTML = this.markdownParser(raw.content.trim());\n }\n this.currentSVGElement = null;\n }\n\n beatViews = new Map<number, BeatView>();\n markerViews = new Map<string, MarkerView>();\n viewForBeat(cell: GridCell): GridCellView {\n if (cell.colIndex % 3 == 1) {\n // beat view needed\n const beat = cell.value;\n let curr = this.beatViews.get(beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n // how to get the bar and beat index for a given beat in a given row?\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);\n this.beatViews.set(beat.uuid, curr);\n }\n return curr;\n } else {\n // markers view\n const marker = cell.value;\n const beat = marker.beat as Beat;\n let curr = this.markerViews.get(\"pre:\" + beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n const isPreMarker = cell.colIndex % 3 == 0;\n curr = new MarkerView(cell, beat, marker.markers, isPreMarker, lineView.gElem);\n this.markerViews.set(\"pre:\" + beat.uuid, curr);\n }\n return curr;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,yCAAsC;AACtC,0CAAgG;AAIhG,2CAAmD;AAkBnD,MAAa,YAAY;IAavB,YACkB,WAAwB,EACxB,MAA2B;;QAD3B,gBAAW,GAAX,WAAW,CAAa;QACxB,WAAM,GAAN,MAAM,CAAqB;QAZ7C,cAAS,GAAe,EAAE,CAAC;QAE3B,sBAAiB,GAAyB,IAAI,CAAC;QAMvC,4BAAuB,GAAwB,IAAI,CAAC;QAkM5D,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QACxC,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QA7L1C,IAAI,CAAC,cAAc,EAAE,CAAC;QAEtB,IAAI,CAAC,cAAc,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,mCAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU,CAAC,UAA4B;QACzC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,UAAU,CAAC,eAAe,CAAC,WAAW,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE;YAC9C,MAAM,EAAE,IAAI,CAAC,WAAW;YACxB,KAAK,EAAE;gBACL,KAAK,EAAE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GAAG,MAAM,CAAC,IAAY,CAAC;YACjC,IAAI,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;YAC5D,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;gBACjB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;gBAC7B,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC3C,IAAI,GAAG,IAAI,sBAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAC/E,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACjD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA7OD,oCA6OC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock, Block, BlockItem, isLine, isBlock, isRawBlock } from \"../notation\";\nimport { Beat, GlobalBeatLayout } from \"../beats\";\nimport { GridCell, GridCellView, GridLayoutGroup, LayoutChangeEvent } from \"../grids\";\nimport { Line } from \"../core\";\nimport { BeatView, MarkerView } from \"./beatviews\";\n\n/**\n * Configuration options for NotationView.\n */\nexport interface NotationViewConfig {\n /**\n * Optional shared GridLayoutGroup for column alignment across multiple NotationViews.\n * When provided, this view will share column widths with other views using the same group.\n */\n sharedGridLayoutGroup?: GridLayoutGroup;\n\n /**\n * Optional markdown parser for RawBlock content.\n */\n markdownParser?: (contents: string) => string;\n}\n\nexport class NotationView {\n headerElement: HTMLDivElement;\n notation: Notation;\n lineViews: LineView[] = [];\n // Mapping from line id -> list of beats in each of its roles\n currentSVGElement: SVGSVGElement | null = null;\n tableElement: HTMLTableElement;\n markdownParser: (contents: string) => string;\n _beatLayout: GlobalBeatLayout;\n\n /** Unsubscribe function for layout change listener */\n private layoutChangeUnsubscribe: (() => void) | null = null;\n\n constructor(\n public readonly rootElement: HTMLElement,\n public readonly config?: NotationViewConfig,\n ) {\n this.loadChildViews();\n // Default to identity function if no markdown parser provided\n this.markdownParser = config?.markdownParser ?? ((content) => content);\n }\n\n get beatLayout(): GlobalBeatLayout {\n return this._beatLayout;\n }\n\n set beatLayout(beatLayout: GlobalBeatLayout) {\n this._beatLayout = beatLayout;\n beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);\n }\n\n loadChildViews(): void {\n this.tableElement = TSU.DOM.createNode(\"table\", {\n parent: this.rootElement,\n attrs: {\n class: \"notationsContentRootTable\",\n },\n }) as HTMLTableElement;\n }\n\n renderNotation(notation: Notation, beatLayout: GlobalBeatLayout): void {\n this.notation = notation;\n this.beatLayout = beatLayout;\n const startTime = performance.now();\n this.refreshLayout();\n const layoutTime = performance.now();\n console.log(`V4 Document, Layout Time: ${layoutTime - startTime}ms`);\n }\n\n public addNewRow(id: string, prefix: string, withAnnotation = true): [HTMLElement, HTMLElement] {\n const tr = TSU.DOM.createNode(\"tr\", {\n parent: this.tableElement, // parent,\n attrs: {\n class: prefix + \"Row\",\n id: prefix + \"Row\" + id,\n },\n });\n let td1: HTMLElement | null = null;\n if (withAnnotation) {\n td1 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"AnnotationCell\",\n id: prefix + \"Annotation\" + id,\n },\n }) as HTMLElement;\n }\n const td2 = TSU.DOM.createNode(\"td\", {\n parent: tr,\n attrs: {\n class: prefix + \"ContentCell\",\n id: prefix + \"Content\" + id,\n colspan: withAnnotation ? 1 : 2,\n },\n }) as HTMLElement;\n return [td1!, td2];\n }\n\n public newLineRoot(parent: Element, line: Line): SVGSVGElement {\n const [td1, td2] = this.addNewRow(line.uuid + \"\", \"line\");\n // Hacky solution to \"line headings\"\n if (line.marginText) {\n td1.innerHTML = line.marginText;\n }\n return TSU.DOM.createSVGNode(\"svg\", {\n parent: td2, // parent\n attrs: {\n style: \"margin-bottom: 10px\",\n class: \"lineRootSVG\",\n },\n }) as SVGSVGElement;\n }\n\n ensureLineView(line: Line): LineView {\n let lineView = this.getLineView(line);\n if (lineView == null) {\n const layoutParams = line.layoutParams || null;\n const svgElem = this.newLineRoot(this.tableElement, line);\n lineView = new LineView(svgElem, line, {\n layoutParams: layoutParams,\n } as any);\n if (!line.isEmpty) {\n // Probably because this is an empty line and AddAtoms was not called\n TSU.assert(layoutParams != null, \"Layout params for a non empty line *should* exist\");\n lineView.gridModel = this.beatLayout!.getGridModelForLine(line.uuid);\n }\n this.lineViews.push(lineView);\n }\n return lineView;\n }\n\n getLineView(line: Line): TSU.Nullable<LineView> {\n return this.lineViews.find((l) => l.line == line) || null;\n }\n\n get currentLineView(): LineView {\n return this.lineViews[this.lineViews.length - 1];\n }\n\n clear(): void {\n this.lineViews = [];\n // Mapping from line id -> list of beats in each of its roles\n this.currentSVGElement = null;\n this.tableElement.innerHTML = \"\";\n this.beatViews = new Map<number, BeatView>();\n }\n\n /**\n * Layout all the blocks in the Notation along with their corresponding blocks.\n * Key thing is here is an opportunity to perform any batch rendering as needed.\n */\n refreshLayout(): void {\n const lineViews = [] as LineView[];\n\n // Recursively process the notation (which is a Block) and collect LineViews\n this.processBlock(this.notation, lineViews);\n\n const now = performance.now();\n for (const lineView of lineViews) {\n lineView.gridModel.lastUpdatedAt = now;\n }\n\n this.beatLayout.gridLayoutGroup.refreshLayout();\n\n for (const lineView of lineViews) {\n lineView.wrapToSize();\n }\n }\n\n /**\n * Recursively processes a block and its children for rendering.\n * Uses block.children() to get expanded children (e.g., RepeatBlock expands to N copies).\n *\n * @param block The block to process\n * @param lineViews Array to collect LineViews for batch layout\n */\n protected processBlock(block: Block, lineViews: LineView[]): void {\n for (const child of block.children()) {\n this.processBlockItem(child, lineViews);\n }\n }\n\n /**\n * Processes a single block item (Block, Line, or RawBlock) for rendering.\n *\n * @param item The item to process\n * @param lineViews Array to collect LineViews for batch layout\n */\n protected processBlockItem(item: BlockItem, lineViews: LineView[]): void {\n if (isRawBlock(item)) {\n // Render raw content (markdown, metadata)\n this.renderBlock(item as RawBlock);\n } else if (isLine(item)) {\n // Render line\n const line = item as Line;\n if (!line.isEmpty) {\n const lineView = this.ensureLineView(line);\n lineViews.push(lineView);\n }\n } else if (isBlock(item)) {\n // Recursively process nested block\n this.processBlock(item as Block, lineViews);\n }\n }\n\n renderBlock(raw: RawBlock): void {\n const [, td2] = this.addNewRow(raw.uuid + \"\", \"rawBlock\", false);\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n // For now ignore metadata with \":\" in the key\n if (meta.key.toLowerCase().indexOf(\":\") < 0) {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n }\n } else {\n const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n div.innerHTML = this.markdownParser(raw.content.trim());\n }\n this.currentSVGElement = null;\n }\n\n beatViews = new Map<number, BeatView>();\n markerViews = new Map<string, MarkerView>();\n viewForBeat(cell: GridCell): GridCellView {\n if (cell.colIndex % 3 == 1) {\n // beat view needed\n const beat = cell.value;\n let curr = this.beatViews.get(beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n // how to get the bar and beat index for a given beat in a given row?\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);\n this.beatViews.set(beat.uuid, curr);\n }\n return curr;\n } else {\n // markers view\n const marker = cell.value;\n const beat = marker.beat as Beat;\n let curr = this.markerViews.get(\"pre:\" + beat.uuid) || null;\n if (curr == null) {\n const line = beat.role.line;\n const lineView = this.ensureLineView(line);\n const lp = line.layoutParams;\n const isPreMarker = cell.colIndex % 3 == 0;\n curr = new MarkerView(cell, beat, marker.markers, isPreMarker, lineView.gElem);\n this.markerViews.set(\"pre:\" + beat.uuid, curr);\n }\n return curr;\n }\n }\n}\n"]}
|
package/lib/cjs/commands.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as TSU from "@panyam/tsutils";
|
|
2
2
|
import { Atom } from "./core";
|
|
3
|
-
import { Command,
|
|
3
|
+
import { Command, MetaData as Meta, Block } from "./notation";
|
|
4
4
|
export declare class RawEmbedding extends Command {
|
|
5
5
|
get rawContents(): string;
|
|
6
|
-
|
|
6
|
+
applyToBlock(container: Block): void;
|
|
7
7
|
}
|
|
8
8
|
export declare class MetaData extends Command {
|
|
9
|
-
|
|
9
|
+
applyToBlock(container: Block): void;
|
|
10
10
|
get meta(): Meta;
|
|
11
11
|
get key(): string;
|
|
12
12
|
get value(): string;
|
|
13
13
|
}
|
|
14
14
|
export declare class ActivateRole extends Command {
|
|
15
|
-
|
|
15
|
+
applyToBlock(container: Block): void;
|
|
16
16
|
get roleName(): string;
|
|
17
17
|
}
|
|
18
18
|
export declare class AddAtoms extends Command {
|
|
@@ -20,33 +20,47 @@ export declare class AddAtoms extends Command {
|
|
|
20
20
|
atoms: Atom[];
|
|
21
21
|
constructor(...atoms: Atom[]);
|
|
22
22
|
debugValue(): any;
|
|
23
|
-
|
|
23
|
+
applyToBlock(container: Block): void;
|
|
24
24
|
}
|
|
25
25
|
export declare class CreateLine extends Command {
|
|
26
|
-
|
|
26
|
+
applyToBlock(container: Block): void;
|
|
27
27
|
get offset(): TSU.Num.Fraction;
|
|
28
28
|
get marginText(): string;
|
|
29
29
|
}
|
|
30
30
|
export declare class CreateRole extends Command {
|
|
31
|
-
|
|
31
|
+
applyToBlock(container: Block): void;
|
|
32
32
|
get notesOnly(): boolean;
|
|
33
33
|
}
|
|
34
34
|
export declare abstract class LayoutParamCommand extends Command {
|
|
35
35
|
}
|
|
36
36
|
export declare class ApplyLayout extends Command {
|
|
37
37
|
validateParams(): void;
|
|
38
|
-
|
|
38
|
+
applyToBlock(container: Block): void;
|
|
39
39
|
}
|
|
40
40
|
export declare class SetBreaks extends LayoutParamCommand {
|
|
41
41
|
get pattern(): number[];
|
|
42
42
|
validateParams(): void;
|
|
43
|
-
|
|
43
|
+
applyToBlock(container: Block): void;
|
|
44
44
|
}
|
|
45
45
|
export declare class SetCycle extends LayoutParamCommand {
|
|
46
|
-
|
|
46
|
+
applyToBlock(container: Block): void;
|
|
47
47
|
}
|
|
48
48
|
export declare class SetBeatDuration extends LayoutParamCommand {
|
|
49
49
|
validateParams(): void;
|
|
50
50
|
get beatDuration(): number;
|
|
51
|
-
|
|
51
|
+
applyToBlock(container: Block): void;
|
|
52
|
+
}
|
|
53
|
+
export declare class Section extends Command {
|
|
54
|
+
get sectionName(): string;
|
|
55
|
+
validateParams(): void;
|
|
56
|
+
applyToBlock(_container: Block): void;
|
|
57
|
+
}
|
|
58
|
+
export declare class ScopedGroup extends Command {
|
|
59
|
+
get groupName(): string;
|
|
60
|
+
applyToBlock(_container: Block): void;
|
|
61
|
+
}
|
|
62
|
+
export declare class Repeat extends Command {
|
|
63
|
+
get count(): number;
|
|
64
|
+
validateParams(): void;
|
|
65
|
+
applyToBlock(_container: Block): void;
|
|
52
66
|
}
|
package/lib/cjs/commands.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SetBeatDuration = exports.SetCycle = exports.SetBreaks = exports.ApplyLayout = exports.LayoutParamCommand = exports.CreateRole = exports.CreateLine = exports.AddAtoms = exports.ActivateRole = exports.MetaData = exports.RawEmbedding = void 0;
|
|
36
|
+
exports.Repeat = exports.ScopedGroup = exports.Section = exports.SetBeatDuration = exports.SetCycle = exports.SetBreaks = exports.ApplyLayout = exports.LayoutParamCommand = exports.CreateRole = exports.CreateLine = exports.AddAtoms = exports.ActivateRole = exports.MetaData = exports.RawEmbedding = void 0;
|
|
37
37
|
const TSU = __importStar(require("@panyam/tsutils"));
|
|
38
38
|
const utils_1 = require("./utils");
|
|
39
39
|
const notation_1 = require("./notation");
|
|
@@ -41,15 +41,18 @@ class RawEmbedding extends notation_1.Command {
|
|
|
41
41
|
get rawContents() {
|
|
42
42
|
return this.getParamAt(0);
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
applyToBlock(container) {
|
|
45
45
|
const raw = new notation_1.RawBlock(this.rawContents);
|
|
46
|
-
|
|
46
|
+
container.addBlockItem(raw);
|
|
47
|
+
container.resetLine();
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
exports.RawEmbedding = RawEmbedding;
|
|
50
51
|
class MetaData extends notation_1.Command {
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
applyToBlock(container) {
|
|
53
|
+
if (container instanceof notation_1.Notation) {
|
|
54
|
+
container.addMetaData(this.meta);
|
|
55
|
+
}
|
|
53
56
|
}
|
|
54
57
|
get meta() {
|
|
55
58
|
const out = new notation_1.MetaData(this.key, this.value);
|
|
@@ -64,8 +67,8 @@ class MetaData extends notation_1.Command {
|
|
|
64
67
|
}
|
|
65
68
|
exports.MetaData = MetaData;
|
|
66
69
|
class ActivateRole extends notation_1.Command {
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
applyToBlock(container) {
|
|
71
|
+
container.setCurrRole(this.roleName);
|
|
69
72
|
}
|
|
70
73
|
get roleName() {
|
|
71
74
|
return this.getParamAt(0);
|
|
@@ -85,26 +88,26 @@ class AddAtoms extends notation_1.Command {
|
|
|
85
88
|
atoms: this.atoms.map((a) => a.debugValue()),
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
|
-
|
|
89
|
-
let roleDef =
|
|
91
|
+
applyToBlock(container) {
|
|
92
|
+
let roleDef = container.currRoleDef;
|
|
90
93
|
if (roleDef == null) {
|
|
91
|
-
roleDef =
|
|
94
|
+
roleDef = container.newRoleDef("Sw", true);
|
|
92
95
|
}
|
|
93
|
-
const
|
|
96
|
+
const line = container.currentLine;
|
|
97
|
+
const lpForLine = line.layoutParams;
|
|
94
98
|
if (lpForLine == null) {
|
|
95
|
-
|
|
99
|
+
line.layoutParams = container.layoutParams;
|
|
96
100
|
}
|
|
97
101
|
else {
|
|
98
|
-
TSU.assert(lpForLine ==
|
|
102
|
+
TSU.assert(lpForLine == container.layoutParams, "Layout parameters have changed so a new line should have been started");
|
|
99
103
|
}
|
|
100
|
-
|
|
101
|
-
notation.currentLine.addAtoms(roleDef.name, roleDef.notesOnly, ...finalised);
|
|
104
|
+
line.addAtoms(roleDef.name, roleDef.notesOnly, ...this.atoms);
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
exports.AddAtoms = AddAtoms;
|
|
105
108
|
class CreateLine extends notation_1.Command {
|
|
106
|
-
|
|
107
|
-
const line =
|
|
109
|
+
applyToBlock(container) {
|
|
110
|
+
const line = container.newLine();
|
|
108
111
|
line.offset = this.offset;
|
|
109
112
|
line.marginText = this.marginText;
|
|
110
113
|
}
|
|
@@ -125,9 +128,9 @@ class CreateLine extends notation_1.Command {
|
|
|
125
128
|
}
|
|
126
129
|
exports.CreateLine = CreateLine;
|
|
127
130
|
class CreateRole extends notation_1.Command {
|
|
128
|
-
|
|
131
|
+
applyToBlock(container) {
|
|
129
132
|
const name = this.getParamAt(0);
|
|
130
|
-
|
|
133
|
+
container.newRoleDef(name, this.notesOnly);
|
|
131
134
|
}
|
|
132
135
|
get notesOnly() {
|
|
133
136
|
const notesOnly = this.getParam("notes");
|
|
@@ -144,9 +147,11 @@ class ApplyLayout extends notation_1.Command {
|
|
|
144
147
|
throw new Error("layout command must contain one string argument");
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
applyToBlock(container) {
|
|
151
|
+
if (container instanceof notation_1.Notation) {
|
|
152
|
+
const value = this.params[0].value;
|
|
153
|
+
container.ensureNamedLayoutParams(value);
|
|
154
|
+
}
|
|
150
155
|
}
|
|
151
156
|
}
|
|
152
157
|
exports.ApplyLayout = ApplyLayout;
|
|
@@ -164,18 +169,22 @@ class SetBreaks extends LayoutParamCommand {
|
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
applyToBlock(container) {
|
|
173
|
+
container.localBreaks = this.pattern;
|
|
174
|
+
if (container instanceof notation_1.Notation) {
|
|
175
|
+
container.resetLayoutParams();
|
|
176
|
+
}
|
|
170
177
|
}
|
|
171
178
|
}
|
|
172
179
|
exports.SetBreaks = SetBreaks;
|
|
173
180
|
class SetCycle extends LayoutParamCommand {
|
|
174
|
-
|
|
181
|
+
applyToBlock(container) {
|
|
175
182
|
const value = this.params[0].value;
|
|
176
183
|
const cycle = (0, utils_1.parseCycle)(value);
|
|
177
|
-
|
|
178
|
-
|
|
184
|
+
container.localCycle = cycle;
|
|
185
|
+
if (container instanceof notation_1.Notation) {
|
|
186
|
+
container.resetLayoutParams();
|
|
187
|
+
}
|
|
179
188
|
}
|
|
180
189
|
}
|
|
181
190
|
exports.SetCycle = SetCycle;
|
|
@@ -188,10 +197,53 @@ class SetBeatDuration extends LayoutParamCommand {
|
|
|
188
197
|
get beatDuration() {
|
|
189
198
|
return this.params[0].value;
|
|
190
199
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
200
|
+
applyToBlock(container) {
|
|
201
|
+
container.localAtomsPerBeat = this.beatDuration;
|
|
202
|
+
if (container instanceof notation_1.Notation) {
|
|
203
|
+
container.resetLayoutParams();
|
|
204
|
+
}
|
|
194
205
|
}
|
|
195
206
|
}
|
|
196
207
|
exports.SetBeatDuration = SetBeatDuration;
|
|
208
|
+
class Section extends notation_1.Command {
|
|
209
|
+
get sectionName() {
|
|
210
|
+
return this.getParamAt(0) || "";
|
|
211
|
+
}
|
|
212
|
+
validateParams() {
|
|
213
|
+
if (this.params.length < 1 || typeof this.params[0].value !== "string") {
|
|
214
|
+
throw new Error("section command must contain a string name");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
applyToBlock(_container) {
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.Section = Section;
|
|
221
|
+
class ScopedGroup extends notation_1.Command {
|
|
222
|
+
get groupName() {
|
|
223
|
+
return this.getParamAt(0) || "";
|
|
224
|
+
}
|
|
225
|
+
applyToBlock(_container) {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.ScopedGroup = ScopedGroup;
|
|
229
|
+
class Repeat extends notation_1.Command {
|
|
230
|
+
get count() {
|
|
231
|
+
const count = this.getParamAt(0);
|
|
232
|
+
if (typeof count === "number") {
|
|
233
|
+
return count;
|
|
234
|
+
}
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
237
|
+
validateParams() {
|
|
238
|
+
if (this.params.length > 0) {
|
|
239
|
+
const count = this.params[0].value;
|
|
240
|
+
if (typeof count !== "number" || count < 0) {
|
|
241
|
+
throw new Error("repeat command count must be a non-negative number");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
applyToBlock(_container) {
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.Repeat = Repeat;
|
|
197
249
|
//# sourceMappingURL=commands.js.map
|
package/lib/cjs/commands.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/commands.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAEvC,mCAAqC;AACrC,yCAA2E;AAM3E,MAAa,YAAa,SAAQ,kBAAO;IAIvC,IAAI,WAAW;QACb,OAAO,IAAI,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BAYC;AAKD,MAAa,eAAgB,SAAQ,kBAAkB;IAKrD,cAAc;QACZ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAKD,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9B,CAAC;IAMD,eAAe,CAAC,QAAkB;QAChC,QAAQ,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC;QACxC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;IAC/B,CAAC;CACF;AA1BD,0CA0BC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Atom } from \"./core\";\nimport { parseCycle } from \"./utils\";\nimport { Command, RawBlock, Notation, MetaData as Meta } from \"./notation\";\n\n/**\n * Command for embedding raw content in the notation.\n * This allows including arbitrary raw text blocks (like markdown or HTML) within the notation.\n */\nexport class RawEmbedding extends Command {\n /**\n * Gets the raw content of this embedding.\n */\n get rawContents(): string {\n return this.getParamAt(0);\n }\n\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n const raw = new RawBlock(this.rawContents);\n notation.addRawBlock(raw);\n }\n}\n\n/**\n * Command for adding metadata to the notation.\n */\nexport class MetaData extends Command {\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n // Create the role - ensure that we have a role\n notation.addMetaData(this.meta);\n }\n\n /**\n * Gets the metadata object for this command.\n */\n get meta(): Meta {\n const out = new Meta(this.key, this.value);\n return out;\n }\n\n /**\n * Gets the key for this metadata.\n */\n get key(): string {\n return this.getParamAt(0);\n }\n\n /**\n * Gets the value for this metadata.\n */\n get value(): string {\n return this.getParamAt(1);\n }\n}\n\n/**\n * Command for activating (selecting) a specific role.\n */\nexport class ActivateRole extends Command {\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n // Create the role - ensure that we have a role\n notation.setCurrRole(this.roleName);\n // const line = notation.ensureLine();\n }\n\n /**\n * Gets the name of the role to activate.\n */\n get roleName(): string {\n return this.getParamAt(0);\n }\n}\n\n/**\n * Command for adding atoms to the current role.\n */\nexport class AddAtoms extends Command {\n /** Index of this command in the sequence */\n index: number;\n /** Atoms to add */\n atoms: Atom[];\n\n /**\n * Creates a new AddAtoms command.\n * @param atoms Atoms to add\n */\n constructor(...atoms: Atom[]) {\n super();\n this.atoms = atoms;\n this.index = 0;\n }\n\n /**\n * Returns a debug-friendly representation of this command.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n name: this.name,\n index: this.index,\n atoms: this.atoms.map((a) => a.debugValue()),\n };\n }\n\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n let roleDef = notation.currRoleDef;\n if (roleDef == null) {\n // By default create a role for swaras\n roleDef = notation.newRoleDef(\"Sw\", true);\n // throw new Error(\"Current role is invalid\");\n }\n // Ensure a line exists\n const lpForLine = notation.currentLine.layoutParams;\n if (lpForLine == null) {\n notation.currentLine.layoutParams = notation.layoutParams;\n } else {\n TSU.assert(\n lpForLine == notation.layoutParams,\n \"Layout parameters have changed so a new line should have been started\",\n );\n }\n const finalised = this.atoms;\n notation.currentLine.addAtoms(roleDef.name, roleDef.notesOnly, ...finalised);\n }\n}\n\n/**\n * Command for creating a new line in the notation.\n */\nexport class CreateLine extends Command {\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n // We are not calling a newLine here just to avoid\n // a series of \\line commands creating wasteful empty lines\n // TODO - how do we consider offsets in line create\n const line = notation.newLine();\n line.offset = this.offset;\n line.marginText = this.marginText;\n }\n\n /**\n * Gets the offset for the new line.\n */\n get offset(): TSU.Num.Fraction {\n let offset = this.getParam(\"offset\") || TSU.Num.Fraction.ZERO;\n if (typeof offset === \"number\") offset = new TSU.Num.Fraction(offset);\n return offset;\n }\n\n /**\n * Gets the margin text for the new line.\n */\n get marginText(): string {\n if (this.params.length > 0) {\n if (this.params[0].key == null && typeof this.params[0].value === \"string\") {\n return this.params[0].value.trim();\n }\n }\n return this.getParam(\"marginText\") || \"\";\n }\n}\n\n/**\n * Command for creating a new role in the notation.\n */\nexport class CreateRole extends Command {\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n // Create the role\n const name = this.getParamAt(0);\n notation.newRoleDef(name, this.notesOnly);\n }\n\n /**\n * Gets whether this role should contain only notes (true) or also syllables/text (false).\n */\n get notesOnly(): boolean {\n const notesOnly = this.getParam(\"notes\");\n return notesOnly == \"true\" || notesOnly == \"yes\" || notesOnly == true;\n }\n}\n\n/**\n * Base class for commands that modify layout parameters.\n */\nexport abstract class LayoutParamCommand extends Command {}\n\n/**\n * Command for applying a named layout to the notation.\n *\n * Saves the current layout with the given name.\n * Typically users can change layout params (currently cycle, APB and line layout)\n * with the \\cycle, \\layout and \\beatDuration commands. Each time these are\n * changed, the current layout params is set to null. So the next time layout\n * params are needed we look at saved layout params and search by the unique\n * combination of cycle, apb and line layout. This prevents users from creating\n * too many layouts with the same config. Each layout is associated with an\n * AtomLayout instance.\n *\n * For example consider this:\n *\n * \\apb(4)\n * \\breaks(4)\n * \\cycle(\"|4|2|2|\")\n * \\apb(5)\n * \\breaks(3)\n *\n * In all these cases LayoutParams are *not* created. Instead they are reset to null.\n *\n *\n * When we do an AddAtoms command, this is where a LineView is created and along with this\n * a layoutParams is created taking the latest state of the layout params resulting an\n * LP (instance id = 1) of (layout = 3, cycle = \"4|2|2\", apb = 5)\n *\n * Now after this say we had the following commands:\n *\n * \\cycle(x)\n * \\cycle(|4|2|2)\n * \\apb(10)\n * \\apb(5)\n *\n * Sw: a b c\n *\n * Here again since the LP was set to null, \"creating\" layout params results in returning\n * the LP created previously (at the end of these commands the cycle, apb and layout params\n * are the same).\n *\n * eg doing\n *\n * \\layout(\"layout1\")\n *\n * This ensures that a *new* LP instance is created (even if another one exists with the same\n * apb, cycle, layout combo). This allows us to group different sectiosn that are identical\n * in layout but to be processed by different atom layouts.\n *\n * To use a saved layout simply do:\n *\n * \\layout(\"layout\")\n *\n * Note the use and saving commands are same - as we cannot override existing\n * layouts so referring to it the first time creates and saves it too\n */\nexport class ApplyLayout extends Command {\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n if (this.params.length != 1 || typeof this.params[0].value !== \"string\") {\n throw new Error(\"layout command must contain one string argument\");\n }\n }\n\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n const value = this.params[0].value;\n notation.ensureNamedLayoutParams(value);\n }\n}\n\n/**\n * Command for setting line breaks in the layout.\n */\nexport class SetBreaks extends LayoutParamCommand {\n /**\n * Gets the line breaks pattern.\n */\n get pattern(): number[] {\n return this.params.map((cmd) => cmd.value as number);\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n for (const param of this.params) {\n if (param.key != null) {\n throw new Error(\"Breaks command cannot have keyword params\");\n }\n if (typeof param.value !== \"number\") {\n throw new Error(\"Breaks command must be a list of integers\");\n }\n }\n }\n\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n notation.currentBreaks = this.pattern;\n notation.resetLayoutParams();\n }\n}\n\n/**\n * Command for setting the cycle pattern in the layout.\n */\nexport class SetCycle extends LayoutParamCommand {\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n const value = this.params[0].value;\n // TODO - move the parsing to validation\n const cycle = parseCycle(value);\n notation.currentCycle = cycle;\n notation.resetLayoutParams();\n }\n}\n\n/**\n * Command for setting the beat duration in the layout.\n */\nexport class SetBeatDuration extends LayoutParamCommand {\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n if (this.params.length != 1 || typeof this.params[0].value !== \"number\") {\n throw new Error(\"beatDuration command must contain one number\");\n }\n }\n\n /**\n * Gets the beat duration value.\n */\n get beatDuration(): number {\n return this.params[0].value;\n }\n\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n notation.currentAPB = this.beatDuration;\n notation.resetLayoutParams();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/commands.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAEvC,mCAAqC;AACrC,yCAA6F;AAM7F,MAAa,YAAa,SAAQ,kBAAO;IAIvC,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAOD,YAAY,CAAC,SAAgB;QAC3B,MAAM,GAAG,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3C,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAE5B,SAAS,CAAC,SAAS,EAAE,CAAC;IACxB,CAAC;CACF;AAnBD,oCAmBC;AAKD,MAAa,QAAS,SAAQ,kBAAO;IAKnC,YAAY,CAAC,SAAgB;QAC3B,IAAI,SAAS,YAAY,mBAAQ,EAAE,CAAC;YAClC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;IAEH,CAAC;IAKD,IAAI,IAAI;QACN,MAAM,GAAG,GAAG,IAAI,mBAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,GAAG,CAAC;IACb,CAAC;IAKD,IAAI,GAAG;QAC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AAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;IACH,CAAC;IAMD,YAAY,CAAC,UAAiB;IAE9B,CAAC;CACF;AAjCD,wBAiCC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Atom } from \"./core\";\nimport { parseCycle } from \"./utils\";\nimport { Command, RawBlock, Notation, MetaData as Meta, BlockItem, Block } from \"./notation\";\n\n/**\n * Command for embedding raw content in the notation.\n * This allows including arbitrary raw text blocks (like markdown or HTML) within the notation.\n */\nexport class RawEmbedding extends Command {\n /**\n * Gets the raw content of this embedding.\n */\n get rawContents(): string {\n return this.getParamAt(0);\n }\n\n /**\n * Applies this command to a block.\n * Adds a raw block to the container and resets the current line\n * so subsequent notation starts a new line.\n */\n applyToBlock(container: Block): void {\n const raw = new RawBlock(this.rawContents);\n container.addBlockItem(raw);\n // Reset the current line so subsequent notation starts fresh\n container.resetLine();\n }\n}\n\n/**\n * Command for adding metadata to the notation.\n */\nexport class MetaData extends Command {\n /**\n * Applies this command to a block.\n * Only works on Notation (metadata is a Notation-specific feature).\n */\n applyToBlock(container: Block): void {\n if (container instanceof Notation) {\n container.addMetaData(this.meta);\n }\n // No-op for non-Notation blocks\n }\n\n /**\n * Gets the metadata object for this command.\n */\n get meta(): Meta {\n const out = new Meta(this.key, this.value);\n return out;\n }\n\n /**\n * Gets the key for this metadata.\n */\n get key(): string {\n return this.getParamAt(0);\n }\n\n /**\n * Gets the value for this metadata.\n */\n get value(): string {\n return this.getParamAt(1);\n }\n}\n\n/**\n * Command for activating (selecting) a specific role.\n */\nexport class ActivateRole extends Command {\n /**\n * Applies this command to a block.\n * Sets the current role in the container.\n */\n applyToBlock(container: Block): void {\n container.setCurrRole(this.roleName);\n }\n\n /**\n * Gets the name of the role to activate.\n */\n get roleName(): string {\n return this.getParamAt(0);\n }\n}\n\n/**\n * Command for adding atoms to the current role.\n */\nexport class AddAtoms extends Command {\n /** Index of this command in the sequence */\n index: number;\n /** Atoms to add */\n atoms: Atom[];\n\n /**\n * Creates a new AddAtoms command.\n * @param atoms Atoms to add\n */\n constructor(...atoms: Atom[]) {\n super();\n this.atoms = atoms;\n this.index = 0;\n }\n\n /**\n * Returns a debug-friendly representation of this command.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n name: this.name,\n index: this.index,\n atoms: this.atoms.map((a) => a.debugValue()),\n };\n }\n\n /**\n * Applies this command to a block.\n * Adds atoms to the current line in the container.\n */\n applyToBlock(container: Block): void {\n let roleDef = container.currRoleDef;\n if (roleDef == null) {\n // By default create a role for swaras\n roleDef = container.newRoleDef(\"Sw\", true);\n }\n // Get or create the current line\n const line = container.currentLine;\n // Set layoutParams from the container's scope (Block or Notation)\n const lpForLine = line.layoutParams;\n if (lpForLine == null) {\n line.layoutParams = container.layoutParams;\n } else {\n TSU.assert(\n lpForLine == container.layoutParams,\n \"Layout parameters have changed so a new line should have been started\",\n );\n }\n // Add atoms to the line\n line.addAtoms(roleDef.name, roleDef.notesOnly, ...this.atoms);\n }\n}\n\n/**\n * Command for creating a new line in the notation.\n */\nexport class CreateLine extends Command {\n /**\n * Applies this command to a block.\n * Creates a new line in the container.\n */\n applyToBlock(container: Block): void {\n const line = container.newLine();\n line.offset = this.offset;\n line.marginText = this.marginText;\n }\n\n /**\n * Gets the offset for the new line.\n */\n get offset(): TSU.Num.Fraction {\n let offset = this.getParam(\"offset\") || TSU.Num.Fraction.ZERO;\n if (typeof offset === \"number\") offset = new TSU.Num.Fraction(offset);\n return offset;\n }\n\n /**\n * Gets the margin text for the new line.\n */\n get marginText(): string {\n if (this.params.length > 0) {\n if (this.params[0].key == null && typeof this.params[0].value === \"string\") {\n return this.params[0].value.trim();\n }\n }\n return this.getParam(\"marginText\") || \"\";\n }\n}\n\n/**\n * Command for creating a new role in the notation.\n */\nexport class CreateRole extends Command {\n /**\n * Applies this command to a block.\n * Creates a role definition local to the container.\n */\n applyToBlock(container: Block): void {\n const name = this.getParamAt(0);\n container.newRoleDef(name, this.notesOnly);\n }\n\n /**\n * Gets whether this role should contain only notes (true) or also syllables/text (false).\n */\n get notesOnly(): boolean {\n const notesOnly = this.getParam(\"notes\");\n return notesOnly == \"true\" || notesOnly == \"yes\" || notesOnly == true;\n }\n}\n\n/**\n * Base class for commands that modify layout parameters.\n */\nexport abstract class LayoutParamCommand extends Command {}\n\n/**\n * Command for applying a named layout to the notation.\n *\n * Saves the current layout with the given name.\n * Typically users can change layout params (currently cycle, APB and line layout)\n * with the \\cycle, \\layout and \\beatDuration commands. Each time these are\n * changed, the current layout params is set to null. So the next time layout\n * params are needed we look at saved layout params and search by the unique\n * combination of cycle, apb and line layout. This prevents users from creating\n * too many layouts with the same config. Each layout is associated with an\n * AtomLayout instance.\n *\n * For example consider this:\n *\n * \\apb(4)\n * \\breaks(4)\n * \\cycle(\"|4|2|2|\")\n * \\apb(5)\n * \\breaks(3)\n *\n * In all these cases LayoutParams are *not* created. Instead they are reset to null.\n *\n *\n * When we do an AddAtoms command, this is where a LineView is created and along with this\n * a layoutParams is created taking the latest state of the layout params resulting an\n * LP (instance id = 1) of (layout = 3, cycle = \"4|2|2\", apb = 5)\n *\n * Now after this say we had the following commands:\n *\n * \\cycle(x)\n * \\cycle(|4|2|2)\n * \\apb(10)\n * \\apb(5)\n *\n * Sw: a b c\n *\n * Here again since the LP was set to null, \"creating\" layout params results in returning\n * the LP created previously (at the end of these commands the cycle, apb and layout params\n * are the same).\n *\n * eg doing\n *\n * \\layout(\"layout1\")\n *\n * This ensures that a *new* LP instance is created (even if another one exists with the same\n * apb, cycle, layout combo). This allows us to group different sectiosn that are identical\n * in layout but to be processed by different atom layouts.\n *\n * To use a saved layout simply do:\n *\n * \\layout(\"layout\")\n *\n * Note the use and saving commands are same - as we cannot override existing\n * layouts so referring to it the first time creates and saves it too\n */\nexport class ApplyLayout extends Command {\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n if (this.params.length != 1 || typeof this.params[0].value !== \"string\") {\n throw new Error(\"layout command must contain one string argument\");\n }\n }\n\n /**\n * Applies this command to a block.\n * Named layouts are Notation-specific; no-op for other blocks.\n */\n applyToBlock(container: Block): void {\n if (container instanceof Notation) {\n const value = this.params[0].value;\n container.ensureNamedLayoutParams(value);\n }\n // No-op for non-Notation blocks (named layouts are Notation-specific)\n }\n}\n\n/**\n * Command for setting line breaks in the layout.\n */\nexport class SetBreaks extends LayoutParamCommand {\n /**\n * Gets the line breaks pattern.\n */\n get pattern(): number[] {\n return this.params.map((cmd) => cmd.value as number);\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n for (const param of this.params) {\n if (param.key != null) {\n throw new Error(\"Breaks command cannot have keyword params\");\n }\n if (typeof param.value !== \"number\") {\n throw new Error(\"Breaks command must be a list of integers\");\n }\n }\n }\n\n /**\n * Applies this command to a block.\n * Sets the local breaks on the container.\n */\n applyToBlock(container: Block): void {\n container.localBreaks = this.pattern;\n if (container instanceof Notation) {\n container.resetLayoutParams();\n }\n }\n}\n\n/**\n * Command for setting the cycle pattern in the layout.\n */\nexport class SetCycle extends LayoutParamCommand {\n /**\n * Applies this command to a block.\n * Sets the local cycle on the container.\n */\n applyToBlock(container: Block): void {\n const value = this.params[0].value;\n // TODO - move the parsing to validation\n const cycle = parseCycle(value);\n container.localCycle = cycle;\n if (container instanceof Notation) {\n container.resetLayoutParams();\n }\n }\n}\n\n/**\n * Command for setting the beat duration in the layout.\n */\nexport class SetBeatDuration extends LayoutParamCommand {\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n if (this.params.length != 1 || typeof this.params[0].value !== \"number\") {\n throw new Error(\"beatDuration command must contain one number\");\n }\n }\n\n /**\n * Gets the beat duration value.\n */\n get beatDuration(): number {\n return this.params[0].value;\n }\n\n /**\n * Applies this command to a block.\n * Sets the local atoms per beat on the container.\n */\n applyToBlock(container: Block): void {\n container.localAtomsPerBeat = this.beatDuration;\n if (container instanceof Notation) {\n container.resetLayoutParams();\n }\n }\n}\n\n/**\n * Command for creating a named section in the notation.\n * Sections are organizational blocks with a name that can be displayed as headers.\n *\n * Usage: \\section(\"Pallavi\") { ... }\n */\nexport class Section extends Command {\n /**\n * Gets the name of the section.\n */\n get sectionName(): string {\n return this.getParamAt(0) || \"\";\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n if (this.params.length < 1 || typeof this.params[0].value !== \"string\") {\n throw new Error(\"section command must contain a string name\");\n }\n }\n\n /**\n * Applies this command to a block.\n * No-op: SectionBlock handles the section behavior.\n */\n applyToBlock(_container: Block): void {\n // SectionBlock handles section semantics\n }\n}\n\n/**\n * Command for creating a grouping/scope block without specific semantics.\n * Groups are useful for visually organizing notation or applying shared properties.\n *\n * Usage: \\group(\"optional-name\") { ... }\n */\nexport class ScopedGroup extends Command {\n /**\n * Gets the optional name of the group.\n */\n get groupName(): string {\n return this.getParamAt(0) || \"\";\n }\n\n /**\n * Applies this command to a block.\n * No additional properties to set for basic groups.\n */\n applyToBlock(_container: Block): void {\n // No additional properties\n }\n}\n\n/**\n * Command for creating a repeated section in the notation.\n * Repeats can specify a count for how many times the content should repeat.\n *\n * Usage: \\repeat(2) { ... } or \\repeat() { ... } for visual repeat markers\n */\nexport class Repeat extends Command {\n /**\n * Gets the number of times to repeat.\n * Returns 0 if not specified (meaning visual repeat markers only).\n */\n get count(): number {\n const count = this.getParamAt(0);\n if (typeof count === \"number\") {\n return count;\n }\n return 0;\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n if (this.params.length > 0) {\n const count = this.params[0].value;\n if (typeof count !== \"number\" || count < 0) {\n throw new Error(\"repeat command count must be a non-negative number\");\n }\n }\n }\n\n /**\n * Applies this command to a block.\n * No-op: RepeatBlock handles the repeat behavior.\n */\n applyToBlock(_container: Block): void {\n // RepeatBlock handles repeat semantics\n }\n}\n"]}
|
package/lib/cjs/entity.d.ts
CHANGED
|
@@ -3,15 +3,11 @@ export declare class Entity {
|
|
|
3
3
|
readonly TYPE: string;
|
|
4
4
|
private static counter;
|
|
5
5
|
readonly uuid: number;
|
|
6
|
+
protected _parent: TSU.Nullable<Entity>;
|
|
6
7
|
constructor(config?: any);
|
|
8
|
+
get parent(): TSU.Nullable<Entity>;
|
|
9
|
+
setParent(parent: TSU.Nullable<Entity>): void;
|
|
7
10
|
debugValue(): any;
|
|
8
|
-
children(): Entity[];
|
|
9
|
-
get childCount(): number;
|
|
10
|
-
addChild(child: Entity, index?: number): this;
|
|
11
|
-
childAt(index: number): Entity;
|
|
12
|
-
indexOfChild(entity: Entity): number;
|
|
13
|
-
removeChildAt(index: number): Entity;
|
|
14
|
-
setChildAt(index: number, entity: Entity): this;
|
|
15
11
|
toString(): string;
|
|
16
12
|
equals(another: this, expect?: boolean): boolean;
|
|
17
13
|
clone(): this;
|