notations 0.0.69 → 0.0.70
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/notations.umd.js +17409 -23615
- 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 +73 -0
- package/lib/cjs/block.js +247 -0
- package/lib/cjs/block.js.map +1 -0
- package/lib/cjs/carnatic/NotationView.d.ts +11 -4
- package/lib/cjs/carnatic/NotationView.js +26 -11
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/commands.d.ts +25 -11
- package/lib/cjs/commands.js +87 -34
- 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 +28 -33
- package/lib/cjs/notation.js +144 -122
- 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 +73 -0
- package/lib/esm/block.js +230 -0
- package/lib/esm/block.js.map +1 -0
- package/lib/esm/carnatic/NotationView.d.ts +11 -4
- package/lib/esm/carnatic/NotationView.js +26 -11
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/commands.d.ts +25 -11
- package/lib/esm/commands.js +84 -34
- 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 +28 -33
- package/lib/esm/notation.js +129 -118
- 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
|
@@ -36,6 +36,7 @@ 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,9 +44,13 @@ class NotationView {
|
|
|
43
44
|
this.config = config;
|
|
44
45
|
this.lineViews = [];
|
|
45
46
|
this.currentSVGElement = null;
|
|
47
|
+
this.layoutChangeUnsubscribe = null;
|
|
46
48
|
this.beatViews = new Map();
|
|
47
49
|
this.markerViews = new Map();
|
|
48
50
|
this.loadChildViews();
|
|
51
|
+
if (config === null || config === void 0 ? void 0 : config.markdownParser) {
|
|
52
|
+
this.markdownParser = config.markdownParser;
|
|
53
|
+
}
|
|
49
54
|
}
|
|
50
55
|
get beatLayout() {
|
|
51
56
|
return this._beatLayout;
|
|
@@ -140,18 +145,8 @@ class NotationView {
|
|
|
140
145
|
this.beatViews = new Map();
|
|
141
146
|
}
|
|
142
147
|
refreshLayout() {
|
|
143
|
-
const lines = [];
|
|
144
148
|
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
|
-
}
|
|
149
|
+
this.processBlock(this.notation, lineViews);
|
|
155
150
|
const now = performance.now();
|
|
156
151
|
for (const lineView of lineViews) {
|
|
157
152
|
lineView.gridModel.lastUpdatedAt = now;
|
|
@@ -161,6 +156,26 @@ class NotationView {
|
|
|
161
156
|
lineView.wrapToSize();
|
|
162
157
|
}
|
|
163
158
|
}
|
|
159
|
+
processBlock(block, lineViews) {
|
|
160
|
+
for (const child of block.children()) {
|
|
161
|
+
this.processBlockItem(child, lineViews);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
processBlockItem(item, lineViews) {
|
|
165
|
+
if ((0, notation_1.isRawBlock)(item)) {
|
|
166
|
+
this.renderBlock(item);
|
|
167
|
+
}
|
|
168
|
+
else if ((0, notation_1.isLine)(item)) {
|
|
169
|
+
const line = item;
|
|
170
|
+
if (!line.isEmpty) {
|
|
171
|
+
const lineView = this.ensureLineView(line);
|
|
172
|
+
lineViews.push(lineView);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if ((0, notation_1.isBlock)(item)) {
|
|
176
|
+
this.processBlock(item, lineViews);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
164
179
|
renderBlock(raw) {
|
|
165
180
|
const [, td2] = this.addNewRow(raw.uuid + "", "rawBlock", false);
|
|
166
181
|
if (raw.contentType == "metadata") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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gBAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;gBAC7B,IAAI,GAAG,IAAI,oBAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;gBAC1D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACtC,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YAEN,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,MAAM,IAAI,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;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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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C5B,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;AA9OD,oCA8OC","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 if (config?.markdownParser) {\n this.markdownParser = config.markdownParser;\n }\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,17 @@ 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
47
|
}
|
|
48
48
|
}
|
|
49
49
|
exports.RawEmbedding = RawEmbedding;
|
|
50
50
|
class MetaData extends notation_1.Command {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
applyToBlock(container) {
|
|
52
|
+
if (container instanceof notation_1.Notation) {
|
|
53
|
+
container.addMetaData(this.meta);
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
get meta() {
|
|
55
57
|
const out = new notation_1.MetaData(this.key, this.value);
|
|
@@ -64,8 +66,8 @@ class MetaData extends notation_1.Command {
|
|
|
64
66
|
}
|
|
65
67
|
exports.MetaData = MetaData;
|
|
66
68
|
class ActivateRole extends notation_1.Command {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
applyToBlock(container) {
|
|
70
|
+
container.setCurrRole(this.roleName);
|
|
69
71
|
}
|
|
70
72
|
get roleName() {
|
|
71
73
|
return this.getParamAt(0);
|
|
@@ -85,26 +87,28 @@ class AddAtoms extends notation_1.Command {
|
|
|
85
87
|
atoms: this.atoms.map((a) => a.debugValue()),
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
|
-
|
|
89
|
-
let roleDef =
|
|
90
|
+
applyToBlock(container) {
|
|
91
|
+
let roleDef = container.currRoleDef;
|
|
90
92
|
if (roleDef == null) {
|
|
91
|
-
roleDef =
|
|
92
|
-
}
|
|
93
|
-
const lpForLine = notation.currentLine.layoutParams;
|
|
94
|
-
if (lpForLine == null) {
|
|
95
|
-
notation.currentLine.layoutParams = notation.layoutParams;
|
|
93
|
+
roleDef = container.newRoleDef("Sw", true);
|
|
96
94
|
}
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
const line = container.currentLine;
|
|
96
|
+
if (container instanceof notation_1.Notation) {
|
|
97
|
+
const lpForLine = line.layoutParams;
|
|
98
|
+
if (lpForLine == null) {
|
|
99
|
+
line.layoutParams = container.layoutParams;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
TSU.assert(lpForLine == container.layoutParams, "Layout parameters have changed so a new line should have been started");
|
|
103
|
+
}
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
notation.currentLine.addAtoms(roleDef.name, roleDef.notesOnly, ...finalised);
|
|
105
|
+
line.addAtoms(roleDef.name, roleDef.notesOnly, ...this.atoms);
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
exports.AddAtoms = AddAtoms;
|
|
105
109
|
class CreateLine extends notation_1.Command {
|
|
106
|
-
|
|
107
|
-
const line =
|
|
110
|
+
applyToBlock(container) {
|
|
111
|
+
const line = container.newLine();
|
|
108
112
|
line.offset = this.offset;
|
|
109
113
|
line.marginText = this.marginText;
|
|
110
114
|
}
|
|
@@ -125,9 +129,9 @@ class CreateLine extends notation_1.Command {
|
|
|
125
129
|
}
|
|
126
130
|
exports.CreateLine = CreateLine;
|
|
127
131
|
class CreateRole extends notation_1.Command {
|
|
128
|
-
|
|
132
|
+
applyToBlock(container) {
|
|
129
133
|
const name = this.getParamAt(0);
|
|
130
|
-
|
|
134
|
+
container.newRoleDef(name, this.notesOnly);
|
|
131
135
|
}
|
|
132
136
|
get notesOnly() {
|
|
133
137
|
const notesOnly = this.getParam("notes");
|
|
@@ -144,9 +148,11 @@ class ApplyLayout extends notation_1.Command {
|
|
|
144
148
|
throw new Error("layout command must contain one string argument");
|
|
145
149
|
}
|
|
146
150
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
151
|
+
applyToBlock(container) {
|
|
152
|
+
if (container instanceof notation_1.Notation) {
|
|
153
|
+
const value = this.params[0].value;
|
|
154
|
+
container.ensureNamedLayoutParams(value);
|
|
155
|
+
}
|
|
150
156
|
}
|
|
151
157
|
}
|
|
152
158
|
exports.ApplyLayout = ApplyLayout;
|
|
@@ -164,18 +170,22 @@ class SetBreaks extends LayoutParamCommand {
|
|
|
164
170
|
}
|
|
165
171
|
}
|
|
166
172
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
applyToBlock(container) {
|
|
174
|
+
container.localBreaks = this.pattern;
|
|
175
|
+
if (container instanceof notation_1.Notation) {
|
|
176
|
+
container.resetLayoutParams();
|
|
177
|
+
}
|
|
170
178
|
}
|
|
171
179
|
}
|
|
172
180
|
exports.SetBreaks = SetBreaks;
|
|
173
181
|
class SetCycle extends LayoutParamCommand {
|
|
174
|
-
|
|
182
|
+
applyToBlock(container) {
|
|
175
183
|
const value = this.params[0].value;
|
|
176
184
|
const cycle = (0, utils_1.parseCycle)(value);
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
container.localCycle = cycle;
|
|
186
|
+
if (container instanceof notation_1.Notation) {
|
|
187
|
+
container.resetLayoutParams();
|
|
188
|
+
}
|
|
179
189
|
}
|
|
180
190
|
}
|
|
181
191
|
exports.SetCycle = SetCycle;
|
|
@@ -188,10 +198,53 @@ class SetBeatDuration extends LayoutParamCommand {
|
|
|
188
198
|
get beatDuration() {
|
|
189
199
|
return this.params[0].value;
|
|
190
200
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
201
|
+
applyToBlock(container) {
|
|
202
|
+
container.localAtomsPerBeat = this.beatDuration;
|
|
203
|
+
if (container instanceof notation_1.Notation) {
|
|
204
|
+
container.resetLayoutParams();
|
|
205
|
+
}
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
208
|
exports.SetBeatDuration = SetBeatDuration;
|
|
209
|
+
class Section extends notation_1.Command {
|
|
210
|
+
get sectionName() {
|
|
211
|
+
return this.getParamAt(0) || "";
|
|
212
|
+
}
|
|
213
|
+
validateParams() {
|
|
214
|
+
if (this.params.length < 1 || typeof this.params[0].value !== "string") {
|
|
215
|
+
throw new Error("section command must contain a string name");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
applyToBlock(_container) {
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.Section = Section;
|
|
222
|
+
class ScopedGroup extends notation_1.Command {
|
|
223
|
+
get groupName() {
|
|
224
|
+
return this.getParamAt(0) || "";
|
|
225
|
+
}
|
|
226
|
+
applyToBlock(_container) {
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.ScopedGroup = ScopedGroup;
|
|
230
|
+
class Repeat extends notation_1.Command {
|
|
231
|
+
get count() {
|
|
232
|
+
const count = this.getParamAt(0);
|
|
233
|
+
if (typeof count === "number") {
|
|
234
|
+
return count;
|
|
235
|
+
}
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
validateParams() {
|
|
239
|
+
if (this.params.length > 0) {
|
|
240
|
+
const count = this.params[0].value;
|
|
241
|
+
if (typeof count !== "number" || count < 0) {
|
|
242
|
+
throw new Error("repeat command count must be a non-negative number");
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
applyToBlock(_container) {
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
exports.Repeat = Repeat;
|
|
197
250
|
//# 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,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAMD,eAAe,CAAC,QAAkB;QAChC,MAAM,GAAG,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QA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AAC,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;IAMD,YAAY,CAAC,SAAgB;QAC3B,MAAM,GAAG,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3C,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF;AAhBD,oCAgBC;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;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAKD,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;CACF;AAjCD,4BAiCC;AAKD,MAAa,YAAa,S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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.\n */\n applyToBlock(container: Block): void {\n const raw = new RawBlock(this.rawContents);\n container.addBlockItem(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 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 // For Notation, also handle layoutParams\n if (container instanceof 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 }\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;
|
package/lib/cjs/entity.js
CHANGED
|
@@ -5,49 +5,19 @@ class Entity {
|
|
|
5
5
|
constructor(config = null) {
|
|
6
6
|
this.TYPE = "Entity";
|
|
7
7
|
this.uuid = Entity.counter++;
|
|
8
|
+
this._parent = null;
|
|
8
9
|
config = config || {};
|
|
9
10
|
if (config.metadata)
|
|
10
11
|
throw new Error("See where metadata is being passed");
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
children() {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
get childCount() {
|
|
19
|
-
return this.children().length;
|
|
20
|
-
}
|
|
21
|
-
addChild(child, index = -1) {
|
|
22
|
-
if (index < 0) {
|
|
23
|
-
this.children().push(child);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
this.children().splice(index, 0, child);
|
|
27
|
-
}
|
|
28
|
-
return this;
|
|
13
|
+
get parent() {
|
|
14
|
+
return this._parent;
|
|
29
15
|
}
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
setParent(parent) {
|
|
17
|
+
this._parent = parent;
|
|
32
18
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
for (const child of this.children()) {
|
|
36
|
-
if (child == entity)
|
|
37
|
-
return i;
|
|
38
|
-
i++;
|
|
39
|
-
}
|
|
40
|
-
return -1;
|
|
41
|
-
}
|
|
42
|
-
removeChildAt(index) {
|
|
43
|
-
const children = this.children();
|
|
44
|
-
const out = children[index];
|
|
45
|
-
children.splice(index, 1);
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
48
|
-
setChildAt(index, entity) {
|
|
49
|
-
this.children()[index] = entity;
|
|
50
|
-
return this;
|
|
19
|
+
debugValue() {
|
|
20
|
+
return { type: this.TYPE };
|
|
51
21
|
}
|
|
52
22
|
toString() {
|
|
53
23
|
return `Entity(id = ${this.uuid})`;
|
package/lib/cjs/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity.ts"],"names":[],"mappings":";;;AAWA,MAAa,MAAM;IAajB,YAAY,SAAc,IAAI;QAZrB,SAAI,GAAW,QAAQ,CAAC;QAIxB,SAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAEvB,YAAO,GAAyB,IAAI,CAAC;QAO7C,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC7E,CAAC;IAKD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAMD,SAAS,CAAC,MAA4B;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAOD,UAAU;QACR,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAMD,QAAQ;QACN,OAAO,eAAe,IAAI,CAAC,IAAI,GAAG,CAAC;IACrC,CAAC;IAQD,MAAM,CAAC,OAAa,EAAE,MAAM,GAAG,KAAK;QAClC,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI;YAAE,OAAO,KAAK,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IAUD,KAAK;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjB,OAAO,GAAG,CAAC;IACb,CAAC;IAMD,MAAM,CAAC,OAAa;IAEpB,CAAC;IAMS,WAAW;QACnB,OAAO,IAAK,IAAI,CAAC,WAAmB,EAAE,CAAC;IACzC,CAAC;;AAzFH,wBA0FC;AAvFgB,cAAO,GAAG,CAAC,AAAJ,CAAK;AA6F7B,MAAsB,WAAY,SAAQ,MAAM;IAAhD;;QACW,SAAI,GAAW,aAAa,CAAC;IAgBxC,CAAC;IAHC,MAAM,CAAC,OAAa;QAClB,OAAO,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzE,CAAC;CACF;AAjBD,kCAiBC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\n\n/**\n * A common Entity base class with support for unique IDs, parent references,\n * copying, and debug info. This serves as the foundation for all entities\n * in the notation system.\n *\n * Note: Child management is intentionally NOT included here. Each container type\n * (BlockContainer, Line, Group, etc.) defines its own child management with\n * appropriate types.\n */\nexport class Entity {\n readonly TYPE: string = \"Entity\";\n\n private static counter = 0;\n /** Unique identifier for this entity */\n readonly uuid = Entity.counter++;\n /** Parent entity in the tree hierarchy */\n protected _parent: TSU.Nullable<Entity> = null;\n\n /**\n * Creates a new Entity.\n * @param config Optional configuration object\n */\n constructor(config: any = null) {\n config = config || {};\n if (config.metadata) throw new Error(\"See where metadata is being passed\");\n }\n\n /**\n * Gets the parent entity.\n */\n get parent(): TSU.Nullable<Entity> {\n return this._parent;\n }\n\n /**\n * Sets the parent entity.\n * @param parent The parent entity to set\n */\n setParent(parent: TSU.Nullable<Entity>): void {\n this._parent = parent;\n }\n\n /**\n * Returns a debug-friendly representation of this entity.\n * Usually overridden by children to add more debug info.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return { type: this.TYPE };\n }\n\n /**\n * Returns a simple string representation of this Entity.\n * @returns A string representation\n */\n toString(): string {\n return `Entity(id = ${this.uuid})`;\n }\n\n /**\n * Checks if this Entity is equal to another Entity.\n * @param another The Entity to compare with\n * @param expect Optional parameter\n * @returns True if the Entities are equal, false otherwise\n */\n equals(another: this, expect = false): boolean {\n if (this.TYPE != another.TYPE) return false;\n return true;\n }\n\n /**\n * Creates a clone of this entity.\n * Cloning is a two-part process:\n * 1. Creation of a new instance via this.newInstance()\n * 2. Copying of data into the new instance via this.copyTo()\n *\n * @returns A new instance of the same type with the same properties\n */\n clone(): this {\n const out = this.newInstance();\n this.copyTo(out);\n return out;\n }\n\n /**\n * Copies information about this instance into another instance of the same type.\n * @param another The target instance to copy properties to\n */\n copyTo(another: this): void {\n // Subclasses override to copy their specific properties\n }\n\n /**\n * First part of the cloning process where the instance is created.\n * @returns A new instance of the same type\n */\n protected newInstance(): this {\n return new (this.constructor as any)();\n }\n}\n\n/**\n * Music is all about timing! TimedEntities are base of all entities that\n * have a duration. This is an abstract class that all timed entities inherit from.\n */\nexport abstract class TimedEntity extends Entity {\n readonly TYPE: string = \"TimedEntity\";\n\n /**\n * Gets the duration of this entity in terms of beats.\n * By default, entity durations are readonly.\n */\n abstract get duration(): TSU.Num.Fraction;\n\n /**\n * Checks if this TimedEntity is equal to another TimedEntity.\n * @param another The TimedEntity to compare with\n * @returns True if the TimedEntities are equal, false otherwise\n */\n equals(another: this): boolean {\n return super.equals(another) && this.duration.equals(another.duration);\n }\n}\n"]}
|