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.
Files changed (63) hide show
  1. package/dist/notations.umd.js +17409 -23615
  2. package/dist/notations.umd.min.js +8 -3
  3. package/dist/notations.umd.min.js.LICENSE.txt +0 -14
  4. package/dist/notations.umd.min.js.map +1 -1
  5. package/lib/cjs/beats.d.ts +4 -0
  6. package/lib/cjs/beats.js +19 -2
  7. package/lib/cjs/beats.js.map +1 -1
  8. package/lib/cjs/block.d.ts +73 -0
  9. package/lib/cjs/block.js +247 -0
  10. package/lib/cjs/block.js.map +1 -0
  11. package/lib/cjs/carnatic/NotationView.d.ts +11 -4
  12. package/lib/cjs/carnatic/NotationView.js +26 -11
  13. package/lib/cjs/carnatic/NotationView.js.map +1 -1
  14. package/lib/cjs/commands.d.ts +25 -11
  15. package/lib/cjs/commands.js +87 -34
  16. package/lib/cjs/commands.js.map +1 -1
  17. package/lib/cjs/entity.d.ts +3 -7
  18. package/lib/cjs/entity.js +7 -37
  19. package/lib/cjs/entity.js.map +1 -1
  20. package/lib/cjs/grids.d.ts +32 -3
  21. package/lib/cjs/grids.js +96 -9
  22. package/lib/cjs/grids.js.map +1 -1
  23. package/lib/cjs/index.d.ts +1 -0
  24. package/lib/cjs/index.js +1 -0
  25. package/lib/cjs/index.js.map +1 -1
  26. package/lib/cjs/loader.js +1 -41
  27. package/lib/cjs/loader.js.map +1 -1
  28. package/lib/cjs/notation.d.ts +28 -33
  29. package/lib/cjs/notation.js +144 -122
  30. package/lib/cjs/notation.js.map +1 -1
  31. package/lib/cjs/parser.d.ts +21 -6
  32. package/lib/cjs/parser.js +122 -23
  33. package/lib/cjs/parser.js.map +1 -1
  34. package/lib/esm/beats.d.ts +4 -0
  35. package/lib/esm/beats.js +19 -2
  36. package/lib/esm/beats.js.map +1 -1
  37. package/lib/esm/block.d.ts +73 -0
  38. package/lib/esm/block.js +230 -0
  39. package/lib/esm/block.js.map +1 -0
  40. package/lib/esm/carnatic/NotationView.d.ts +11 -4
  41. package/lib/esm/carnatic/NotationView.js +26 -11
  42. package/lib/esm/carnatic/NotationView.js.map +1 -1
  43. package/lib/esm/commands.d.ts +25 -11
  44. package/lib/esm/commands.js +84 -34
  45. package/lib/esm/commands.js.map +1 -1
  46. package/lib/esm/entity.d.ts +3 -7
  47. package/lib/esm/entity.js +7 -37
  48. package/lib/esm/entity.js.map +1 -1
  49. package/lib/esm/grids.d.ts +32 -3
  50. package/lib/esm/grids.js +96 -9
  51. package/lib/esm/grids.js.map +1 -1
  52. package/lib/esm/index.d.ts +1 -0
  53. package/lib/esm/index.js +1 -0
  54. package/lib/esm/index.js.map +1 -1
  55. package/lib/esm/loader.js +1 -8
  56. package/lib/esm/loader.js.map +1 -1
  57. package/lib/esm/notation.d.ts +28 -33
  58. package/lib/esm/notation.js +129 -118
  59. package/lib/esm/notation.js.map +1 -1
  60. package/lib/esm/parser.d.ts +21 -6
  61. package/lib/esm/parser.js +122 -24
  62. package/lib/esm/parser.js.map +1 -1
  63. package/package.json +3 -2
@@ -3,11 +3,8 @@ import { Entity } from "./entity";
3
3
  import { Cycle } from "./cycle";
4
4
  import { Line } from "./core";
5
5
  import { LayoutParams } from "./layouts";
6
- export declare class RoleDef {
7
- name: string;
8
- notesOnly: boolean;
9
- index: number;
10
- }
6
+ import { RoleDef, RawBlock, BlockItem, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock } from "./block";
7
+ export { RoleDef, RawBlock, BlockItem, Block, SectionBlock, RepeatBlock, CycleBlock, BeatDurationBlock, BreaksBlock, RoleBlock, GroupBlock, isBlock, isLine, isRawBlock, findContainingBlock, };
11
8
  export type CmdParam = {
12
9
  key: TSU.Nullable<string>;
13
10
  value: any;
@@ -24,14 +21,8 @@ export declare abstract class Command extends Entity {
24
21
  debugValue(): any;
25
22
  getParam(name: string): any;
26
23
  getParamAt(index: number): any;
27
- abstract applyToNotation(notebook: Notation): void;
28
- }
29
- export declare class RawBlock extends Entity {
30
- content: string;
31
- contentType: string;
32
- readonly TYPE: string;
33
- constructor(content: string, contentType?: string);
34
- debugValue(): any;
24
+ abstract applyToBlock(container: Block): void;
25
+ applyToNotation(notation: Notation): void;
35
26
  }
36
27
  export declare class MetaData {
37
28
  readonly key: string;
@@ -39,37 +30,41 @@ export declare class MetaData {
39
30
  readonly params?: any | undefined;
40
31
  constructor(key: string, value: string, params?: any | undefined);
41
32
  }
42
- export declare class Notation extends Entity {
33
+ export declare class Notation extends Block {
43
34
  readonly TYPE = "Notation";
44
- private _unnamedLayoutParams;
45
- private _namedLayoutParams;
46
- private _currRoleDef;
47
- roles: RoleDef[];
48
- blocks: (Line | RawBlock)[];
49
- currentAPB: number;
50
- currentCycle: Cycle;
51
- currentBreaks: number[];
52
35
  metadata: Map<string, MetaData>;
53
36
  onMissingRole: (name: string) => RoleDef | null;
37
+ private _unnamedLayoutParams;
38
+ private _namedLayoutParams;
39
+ private _layoutParams;
40
+ constructor();
41
+ get blocks(): BlockItem[];
42
+ get currentAPB(): number;
43
+ set currentAPB(value: number);
44
+ get currentCycle(): Cycle;
45
+ set currentCycle(value: Cycle);
46
+ get currentBreaks(): number[];
47
+ set currentBreaks(value: number[]);
48
+ get roles(): RoleDef[];
54
49
  get unnamedLayoutParams(): ReadonlyArray<LayoutParams>;
55
50
  get namedLayoutParams(): ReadonlyMap<string, LayoutParams>;
51
+ get layoutParams(): LayoutParams;
52
+ resetLayoutParams(): void;
53
+ ensureNamedLayoutParams(name: string): LayoutParams;
54
+ protected snapshotLayoutParams(): LayoutParams;
55
+ protected findUnnamedLayoutParams(): LayoutParams | null;
56
+ setCurrRole(name: string): void;
57
+ getRoleDef(name: string): TSU.Nullable<RoleDef>;
58
+ newRoleDef(name: string, notesOnly?: boolean): RoleDef;
56
59
  addLine(line: Line): void;
57
60
  removeLine(line: Line): number;
58
61
  addRawBlock(raw: RawBlock): void;
59
62
  addMetaData(meta: MetaData, addBlock?: boolean): void;
63
+ resetLine(): void;
60
64
  debugValue(): any;
61
- getRoleDef(name: string): TSU.Nullable<RoleDef>;
62
- newRoleDef(name: string, notesOnly?: boolean): RoleDef;
65
+ protected _currRoleDef: TSU.Nullable<RoleDef>;
63
66
  get currRoleDef(): RoleDef | null;
64
- setCurrRole(name: string): void;
65
- private _currentLine;
67
+ protected _currentLine: Line | null;
66
68
  get currentLine(): Line;
67
- resetLine(): void;
68
69
  newLine(): Line;
69
- private _layoutParams;
70
- resetLayoutParams(): void;
71
- get layoutParams(): LayoutParams;
72
- ensureNamedLayoutParams(name: string): LayoutParams;
73
- protected snapshotLayoutParams(): LayoutParams;
74
- protected findUnnamedLayoutParams(): LayoutParams | null;
75
70
  }
@@ -1,18 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Notation = exports.MetaData = exports.RawBlock = exports.Command = exports.RoleDef = void 0;
3
+ exports.Notation = exports.MetaData = exports.Command = exports.findContainingBlock = exports.isRawBlock = exports.isLine = exports.isBlock = exports.GroupBlock = exports.RoleBlock = exports.BreaksBlock = exports.BeatDurationBlock = exports.CycleBlock = exports.RepeatBlock = exports.SectionBlock = exports.Block = exports.RawBlock = exports.RoleDef = void 0;
4
4
  const entity_1 = require("./entity");
5
5
  const cycle_1 = require("./cycle");
6
6
  const core_1 = require("./core");
7
7
  const layouts_1 = require("./layouts");
8
- class RoleDef {
9
- constructor() {
10
- this.name = "";
11
- this.notesOnly = false;
12
- this.index = 0;
13
- }
14
- }
15
- exports.RoleDef = RoleDef;
8
+ const block_1 = require("./block");
9
+ Object.defineProperty(exports, "RoleDef", { enumerable: true, get: function () { return block_1.RoleDef; } });
10
+ Object.defineProperty(exports, "RawBlock", { enumerable: true, get: function () { return block_1.RawBlock; } });
11
+ Object.defineProperty(exports, "Block", { enumerable: true, get: function () { return block_1.Block; } });
12
+ Object.defineProperty(exports, "SectionBlock", { enumerable: true, get: function () { return block_1.SectionBlock; } });
13
+ Object.defineProperty(exports, "RepeatBlock", { enumerable: true, get: function () { return block_1.RepeatBlock; } });
14
+ Object.defineProperty(exports, "CycleBlock", { enumerable: true, get: function () { return block_1.CycleBlock; } });
15
+ Object.defineProperty(exports, "BeatDurationBlock", { enumerable: true, get: function () { return block_1.BeatDurationBlock; } });
16
+ Object.defineProperty(exports, "BreaksBlock", { enumerable: true, get: function () { return block_1.BreaksBlock; } });
17
+ Object.defineProperty(exports, "RoleBlock", { enumerable: true, get: function () { return block_1.RoleBlock; } });
18
+ Object.defineProperty(exports, "GroupBlock", { enumerable: true, get: function () { return block_1.GroupBlock; } });
19
+ Object.defineProperty(exports, "isBlock", { enumerable: true, get: function () { return block_1.isBlock; } });
20
+ Object.defineProperty(exports, "isLine", { enumerable: true, get: function () { return block_1.isLine; } });
21
+ Object.defineProperty(exports, "isRawBlock", { enumerable: true, get: function () { return block_1.isRawBlock; } });
22
+ Object.defineProperty(exports, "findContainingBlock", { enumerable: true, get: function () { return block_1.findContainingBlock; } });
16
23
  class Command extends entity_1.Entity {
17
24
  constructor(params = []) {
18
25
  super();
@@ -41,20 +48,11 @@ class Command extends entity_1.Entity {
41
48
  getParamAt(index) {
42
49
  return index < this.params.length ? this.params[index].value : null;
43
50
  }
44
- }
45
- exports.Command = Command;
46
- class RawBlock extends entity_1.Entity {
47
- constructor(content, contentType = "md") {
48
- super();
49
- this.content = content;
50
- this.contentType = contentType;
51
- this.TYPE = "RawBlock";
52
- }
53
- debugValue() {
54
- return Object.assign(Object.assign({}, super.debugValue()), { content: this.content, contentType: this.contentType });
51
+ applyToNotation(notation) {
52
+ this.applyToBlock(notation);
55
53
  }
56
54
  }
57
- exports.RawBlock = RawBlock;
55
+ exports.Command = Command;
58
56
  class MetaData {
59
57
  constructor(key, value, params) {
60
58
  this.key = key;
@@ -64,124 +62,53 @@ class MetaData {
64
62
  }
65
63
  }
66
64
  exports.MetaData = MetaData;
67
- class Notation extends entity_1.Entity {
65
+ class Notation extends block_1.Block {
68
66
  constructor() {
69
- super(...arguments);
67
+ super("notation", null);
70
68
  this.TYPE = "Notation";
69
+ this.metadata = new Map();
70
+ this.onMissingRole = (name) => this.newRoleDef(name, name == "sw");
71
71
  this._unnamedLayoutParams = [];
72
72
  this._namedLayoutParams = new Map();
73
+ this._layoutParams = null;
73
74
  this._currRoleDef = null;
74
- this.roles = [];
75
- this.blocks = [];
76
- this.currentAPB = 1;
77
- this.currentCycle = cycle_1.Cycle.DEFAULT;
78
- this.currentBreaks = [];
79
- this.metadata = new Map();
80
- this.onMissingRole = (name) => this.newRoleDef(name, name == "sw");
81
75
  this._currentLine = null;
82
- this._layoutParams = null;
83
- }
84
- get unnamedLayoutParams() {
85
- return this._unnamedLayoutParams;
86
- }
87
- get namedLayoutParams() {
88
- return this._namedLayoutParams;
89
- }
90
- addLine(line) {
91
- this.blocks.push(line);
92
- }
93
- removeLine(line) {
94
- const index = this.blocks.findIndex((l) => l == line);
95
- if (index >= 0) {
96
- this.blocks.splice(index, 1);
97
- }
98
- return index;
99
- }
100
- addRawBlock(raw) {
101
- this.blocks.push(raw);
102
- this.resetLine();
76
+ this.localCycle = cycle_1.Cycle.DEFAULT;
77
+ this.localAtomsPerBeat = 1;
78
+ this.localBreaks = [];
103
79
  }
104
- addMetaData(meta, addBlock = true) {
105
- if (addBlock && !this.metadata.has(meta.key)) {
106
- const raw = new RawBlock(meta.key, "metadata");
107
- this.addRawBlock(raw);
108
- }
109
- this.metadata.set(meta.key, meta);
80
+ get blocks() {
81
+ return this.blockItems;
110
82
  }
111
- debugValue() {
83
+ get currentAPB() {
112
84
  var _a;
113
- return Object.assign(Object.assign({}, super.debugValue), { roles: this.roles, blocks: this.blocks.map((b) => b.debugValue()), currentAPB: this.currentAPB, currentCycle: (_a = this.currentCycle) === null || _a === void 0 ? void 0 : _a.uuid, currentBreaks: this.currentBreaks });
85
+ return (_a = this.localAtomsPerBeat) !== null && _a !== void 0 ? _a : 1;
114
86
  }
115
- getRoleDef(name) {
116
- name = name.trim().toLowerCase();
117
- if (name == "") {
118
- return this.roles[this.roles.length - 1] || null;
119
- }
120
- for (let i = 0; i < this.roles.length; i++) {
121
- const rd = this.roles[i];
122
- if (name == rd.name)
123
- return rd;
124
- }
125
- return null;
87
+ set currentAPB(value) {
88
+ this.localAtomsPerBeat = value;
126
89
  }
127
- newRoleDef(name, notesOnly = false) {
128
- name = name.trim().toLowerCase();
129
- if (name.trim() == "") {
130
- throw new Error("Role name cannot be empty");
131
- }
132
- const roleDef = this.getRoleDef(name);
133
- if (roleDef != null) {
134
- throw new Error("Role already exists");
135
- }
136
- const rd = new RoleDef();
137
- rd.name = name;
138
- rd.notesOnly = notesOnly;
139
- rd.index = this.roles.length;
140
- this.roles.push(rd);
141
- return rd;
90
+ get currentCycle() {
91
+ var _a;
92
+ return (_a = this.localCycle) !== null && _a !== void 0 ? _a : cycle_1.Cycle.DEFAULT;
142
93
  }
143
- get currRoleDef() {
144
- if (this._currRoleDef == null) {
145
- if (this.roles.length == 0) {
146
- return null;
147
- }
148
- else {
149
- this._currRoleDef = this.roles[this.roles.length - 1];
150
- }
151
- }
152
- return this._currRoleDef;
94
+ set currentCycle(value) {
95
+ this.localCycle = value;
153
96
  }
154
- setCurrRole(name) {
155
- name = name.trim().toLowerCase();
156
- if (name.trim() == "") {
157
- throw new Error("Role name cannot be empty");
158
- }
159
- const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);
160
- if (roleDef == null) {
161
- throw new Error("Role not found: " + name);
162
- }
163
- this._currRoleDef = roleDef;
97
+ get currentBreaks() {
98
+ var _a;
99
+ return (_a = this.localBreaks) !== null && _a !== void 0 ? _a : [];
164
100
  }
165
- get currentLine() {
166
- if (this._currentLine == null) {
167
- return this.newLine();
168
- }
169
- return this._currentLine;
101
+ set currentBreaks(value) {
102
+ this.localBreaks = value;
170
103
  }
171
- resetLine() {
172
- this._currentLine = null;
104
+ get roles() {
105
+ return Array.from(this.localRoles.values());
173
106
  }
174
- newLine() {
175
- if (this._currentLine && this._currentLine.isEmpty) {
176
- this.removeLine(this._currentLine);
177
- }
178
- this._currentLine = new core_1.Line();
179
- this.addLine(this._currentLine);
180
- return this._currentLine;
107
+ get unnamedLayoutParams() {
108
+ return this._unnamedLayoutParams;
181
109
  }
182
- resetLayoutParams() {
183
- this._layoutParams = null;
184
- this.resetLine();
110
+ get namedLayoutParams() {
111
+ return this._namedLayoutParams;
185
112
  }
186
113
  get layoutParams() {
187
114
  if (this._layoutParams == null) {
@@ -193,6 +120,10 @@ class Notation extends entity_1.Entity {
193
120
  }
194
121
  return this._layoutParams;
195
122
  }
123
+ resetLayoutParams() {
124
+ this._layoutParams = null;
125
+ this.resetLine();
126
+ }
196
127
  ensureNamedLayoutParams(name) {
197
128
  let lp = this._namedLayoutParams.get(name) || null;
198
129
  if (lp == null || this._layoutParams != lp) {
@@ -224,6 +155,97 @@ class Notation extends entity_1.Entity {
224
155
  lp.lineBreaksEqual(this.currentBreaks));
225
156
  }) || null);
226
157
  }
158
+ setCurrRole(name) {
159
+ name = name.trim().toLowerCase();
160
+ if (name.trim() == "") {
161
+ throw new Error("Role name cannot be empty");
162
+ }
163
+ const roleDef = this.getRole(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);
164
+ if (roleDef == null) {
165
+ throw new Error("Role not found: " + name);
166
+ }
167
+ this._currRoleDef = roleDef;
168
+ }
169
+ getRoleDef(name) {
170
+ var _a;
171
+ name = name.trim().toLowerCase();
172
+ if (name === "") {
173
+ const roles = Array.from(this.localRoles.values());
174
+ return roles[roles.length - 1] || null;
175
+ }
176
+ return (_a = this.localRoles.get(name)) !== null && _a !== void 0 ? _a : null;
177
+ }
178
+ newRoleDef(name, notesOnly = false) {
179
+ name = name.trim().toLowerCase();
180
+ if (name === "") {
181
+ throw new Error("Role name cannot be empty");
182
+ }
183
+ if (this.localRoles.has(name)) {
184
+ throw new Error("Role already exists: " + name);
185
+ }
186
+ const rd = new block_1.RoleDef();
187
+ rd.name = name;
188
+ rd.notesOnly = notesOnly;
189
+ rd.index = this.localRoles.size;
190
+ this.localRoles.set(name, rd);
191
+ return rd;
192
+ }
193
+ addLine(line) {
194
+ this.addBlockItem(line);
195
+ }
196
+ removeLine(line) {
197
+ return this.removeBlockItem(line);
198
+ }
199
+ addRawBlock(raw) {
200
+ this.addBlockItem(raw);
201
+ this.resetLine();
202
+ }
203
+ addMetaData(meta, addBlock = true) {
204
+ if (addBlock && !this.metadata.has(meta.key)) {
205
+ const raw = new block_1.RawBlock(meta.key, "metadata");
206
+ this.addRawBlock(raw);
207
+ }
208
+ this.metadata.set(meta.key, meta);
209
+ }
210
+ resetLine() {
211
+ this._currentLine = null;
212
+ }
213
+ debugValue() {
214
+ var _a;
215
+ return {
216
+ blocks: this.blocks.map((b) => b.debugValue()),
217
+ currentAPB: this.currentAPB,
218
+ currentBreaks: this.currentBreaks,
219
+ currentCycle: (_a = this.currentCycle) === null || _a === void 0 ? void 0 : _a.uuid,
220
+ roles: this.roles,
221
+ };
222
+ }
223
+ get currRoleDef() {
224
+ if (this._currRoleDef == null) {
225
+ const roles = Array.from(this.localRoles.values());
226
+ if (roles.length === 0) {
227
+ return null;
228
+ }
229
+ else {
230
+ this._currRoleDef = roles[roles.length - 1];
231
+ }
232
+ }
233
+ return this._currRoleDef;
234
+ }
235
+ get currentLine() {
236
+ if (this._currentLine == null) {
237
+ return this.newLine();
238
+ }
239
+ return this._currentLine;
240
+ }
241
+ newLine() {
242
+ if (this._currentLine && this._currentLine.isEmpty) {
243
+ this.removeLine(this._currentLine);
244
+ }
245
+ this._currentLine = new core_1.Line();
246
+ this.addLine(this._currentLine);
247
+ return this._currentLine;
248
+ }
227
249
  }
228
250
  exports.Notation = Notation;
229
251
  //# sourceMappingURL=notation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAClC,mCAAgC;AAChC,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,CAAC;iBAAM,CAAC;gBAEN,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC,KAAK,CAAC;gBAC7B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC;gBAClC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC,UAAU,CAAC;YACrC,CAAC;YACD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;YACxB,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,CAAC;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAMS,oBAAoB;QAC5B,OAAO,IAAI,sBAAY,CAAC;YACtB,KAAK,EAAE,IAAI,CAAC,YAAY;YACxB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,MAAM,EAAE,IAAI,CAAC,aAAa;SAC3B,CAAC,CAAC;IACL,CAAC;IAMS,uBAAuB;QAC/B,OAAO,CACL,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;YACpC,OAAO,CACL,EAAE,CAAC,YAAY,IAAI,IAAI,CAAC,UAAU;gBAClC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC;gBAClC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CACvC,CAAC;QACJ,CAAC,CAAC,IAAI,IAAI,CACX,CAAC;IACJ,CAAC;CACF;AArSD,4BAqSC","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 the notation.\n * A role represents a specific voice or part in the music notation.\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 * Type representing a command parameter with optional key and value.\n */\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\n\n/**\n * Base class for commands in the notation.\n * Commands modify the notation in various ways, such as adding content,\n * changing layout, setting roles, etc.\n */\nexport abstract class Command extends Entity {\n /** Whether this command was auto-generated */\n autoGenerated = false;\n\n /** Previous command in the sequence */\n prevSibling: null | Command = null;\n\n /** Next command in the sequence */\n nextSibling: null | Command = null;\n\n /** Parameters for this command */\n params: CmdParam[];\n\n /** Index of this command in the sequence */\n index: number;\n\n /**\n * Creates a new Command.\n * @param params Optional parameters for the command\n */\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n //\n }\n\n /**\n * Gets the name of this command.\n */\n get name(): string {\n return this.constructor.name;\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 { name: this.name, index: this.index, params: this.params };\n }\n\n /**\n * Gets a parameter value by name.\n * @param name The name of the parameter\n * @returns The parameter value, or null if not found\n */\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n /**\n * Gets a parameter value by index.\n * @param index The index of the parameter\n * @returns The parameter value, or null if not found\n */\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n\n /**\n * Applies this command to a notation.\n * @param notation The notation to apply this command to\n */\n abstract applyToNotation(notebook: Notation): void;\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 * Represents metadata for the notation.\n */\nexport class MetaData {\n /**\n * Creates a new MetaData.\n * @param key The key for this metadata\n * @param value The value of this metadata\n * @param params Optional additional parameters\n */\n constructor(\n public readonly key: string,\n public readonly value: string,\n public readonly params?: any,\n ) {\n params = params || {};\n }\n}\n\n/**\n * The main class representing a complete notation.\n * Notation contains all the elements, settings, and layout information for a piece of music.\n */\nexport class Notation extends Entity {\n readonly TYPE = \"Notation\";\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _currRoleDef: TSU.Nullable<RoleDef> = null;\n\n /** Roles defined in this notation */\n roles: RoleDef[] = [];\n\n /** Blocks (lines or raw blocks) in this notation */\n blocks: (Line | RawBlock)[] = [];\n\n /** Current beat duration multiplier */\n currentAPB = 1;\n\n /** Current cycle pattern */\n currentCycle: Cycle = Cycle.DEFAULT;\n\n /** Current line breaks pattern */\n currentBreaks: number[] = [];\n\n /** Metadata associated with this notation */\n metadata = new Map<string, MetaData>();\n\n /** Handler for missing roles */\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n /**\n * Gets the unnamed layout parameters.\n */\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n /**\n * Gets the named layout parameters.\n */\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n /**\n * Adds a line to this notation.\n * @param line The line to add\n */\n addLine(line: Line): void {\n this.blocks.push(line);\n }\n\n /**\n * Removes a line from this notation.\n * @param line The line to remove\n * @returns The index of the removed line, or -1 if not found\n */\n removeLine(line: Line): number {\n const index = this.blocks.findIndex((l) => l == line);\n if (index >= 0) {\n this.blocks.splice(index, 1);\n }\n return index;\n }\n\n /**\n * Adds a raw block to this notation.\n * @param raw The raw block to add\n */\n addRawBlock(raw: RawBlock): void {\n this.blocks.push(raw);\n this.resetLine();\n }\n\n /**\n * Adds metadata to this notation.\n * @param meta The metadata to add\n * @param addBlock Whether to add a corresponding raw block, defaults to true\n */\n addMetaData(meta: MetaData, addBlock = true): void {\n if (addBlock && !this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n /**\n * Returns a debug-friendly representation of this notation.\n * @returns An object containing debug information\n */\n debugValue(): any {\n return {\n ...super.debugValue,\n roles: this.roles,\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentCycle: this.currentCycle?.uuid,\n currentBreaks: this.currentBreaks,\n };\n }\n\n /**\n * Gets a role definition by name.\n * @param name The name of the role\n * @returns The role definition, or null if not found\n */\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name == \"\") {\n return this.roles[this.roles.length - 1] || null;\n }\n for (let i = 0; i < this.roles.length; i++) {\n const rd = this.roles[i];\n if (name == rd.name) return rd;\n }\n return null;\n }\n\n /**\n * Creates a new role definition.\n * @param name The name of the role\n * @param notesOnly Whether the role contains only notes, defaults to false\n * @returns The created role definition\n * @throws Error if the name is empty or the role already exists\n */\n newRoleDef(name: string, notesOnly = false): RoleDef {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name);\n if (roleDef != null) {\n throw new Error(\"Role already exists\");\n // roleDef.notesOnly = notesOnly;\n // return roleDef;\n }\n // create new and add\n const rd = new RoleDef();\n rd.name = name;\n rd.notesOnly = notesOnly;\n rd.index = this.roles.length;\n this.roles.push(rd);\n\n return rd;\n }\n\n /**\n * Gets the current role definition.\n */\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n if (this.roles.length == 0) {\n return null;\n } else {\n this._currRoleDef = this.roles[this.roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n /**\n * Sets the current role by name.\n * @param name The name of the role to set as current\n * @throws Error if the name is empty or the role is not found\n */\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRoleDef(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n // Gets the current line, creating it if needed\n private _currentLine: Line | null = null;\n\n /**\n * Gets the current line, creating it 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 * Resets the current line pointer to null.\n */\n resetLine(): void {\n this._currentLine = null;\n }\n\n /**\n * Creates a new line and makes it the current line.\n * @returns The newly created line\n */\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n\n private _layoutParams: LayoutParams | null = null;\n\n /**\n * Resets the current layout parameters to null.\n */\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n /**\n * Gets the current layout parameters, creating or finding an appropriate one if needed.\n */\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\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 * Ensures that named layout parameters with the given name exist.\n * Creates them if they don't exist, or updates current layout parameters to match.\n *\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 // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n /**\n * Creates a snapshot of the current layout parameters.\n * @returns A new LayoutParams object with the current settings\n */\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Finds an unnamed layout parameters object that matches the current settings.\n * @returns Matching layout parameters, or null if none found\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n}\n"]}
1
+ {"version":3,"file":"notation.js","sourceRoot":"","sources":["../../src/notation.ts"],"names":[],"mappings":";;;AACA,qCAAkC;AAClC,mCAAgC;AAChC,iCAA8B;AAC9B,uCAAyC;AACzC,mCAgBiB;AAIf,wFAnBA,eAAO,OAmBA;AACP,yFAnBA,gBAAQ,OAmBA;AAER,sFAnBA,aAAK,OAmBA;AACL,6FAnBA,oBAAY,OAmBA;AACZ,4FAnBA,mBAAW,OAmBA;AACX,2FAnBA,kBAAU,OAmBA;AACV,kGAnBA,yBAAiB,OAmBA;AACjB,4FAnBA,mBAAW,OAmBA;AACX,0FAnBA,iBAAS,OAmBA;AACT,2FAnBA,kBAAU,OAmBA;AACV,wFAnBA,eAAO,OAmBA;AACP,uFAnBA,cAAM,OAmBA;AACN,2FAnBA,kBAAU,OAmBA;AACV,oGAnBA,2BAAmB,OAmBA;AAarB,MAAsB,OAAQ,SAAQ,eAAM;IAoB1C,YAAY,SAAqB,EAAE;QACjC,KAAK,EAAE,CAAC;QAnBV,kBAAa,GAAG,KAAK,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ACvB,OAAO,IAAI,CAAC;YACd,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAQD,IAAI,WAAW;QACb,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAMD,OAAO;QACL,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;YAGnD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,IAAI,WAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF;AAzWD,4BAyWC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Entity } from \"./entity\";\nimport { Cycle } from \"./cycle\";\nimport { Line } from \"./core\";\nimport { LayoutParams } from \"./layouts\";\nimport {\n RoleDef,\n RawBlock,\n BlockItem,\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n isBlock,\n isLine,\n isRawBlock,\n findContainingBlock,\n} from \"./block\";\n\n// Re-export for backward compatibility\nexport {\n RoleDef,\n RawBlock,\n BlockItem,\n Block,\n SectionBlock,\n RepeatBlock,\n CycleBlock,\n BeatDurationBlock,\n BreaksBlock,\n RoleBlock,\n GroupBlock,\n isBlock,\n isLine,\n isRawBlock,\n findContainingBlock,\n};\n\n/**\n * Type representing a command parameter with optional key and value.\n */\nexport type CmdParam = { key: TSU.Nullable<string>; value: any };\n\n/**\n * Base class for commands in the notation.\n * Commands modify the notation in various ways, such as adding content,\n * changing layout, setting roles, etc.\n */\nexport abstract class Command extends Entity {\n /** Whether this command was auto-generated */\n autoGenerated = false;\n\n /** Previous command in the sequence */\n prevSibling: null | Command = null;\n\n /** Next command in the sequence */\n nextSibling: null | Command = null;\n\n /** Parameters for this command */\n params: CmdParam[];\n\n /** Index of this command in the sequence */\n index: number;\n\n /**\n * Creates a new Command.\n * @param params Optional parameters for the command\n */\n constructor(params: CmdParam[] = []) {\n super();\n this.params = params;\n this.index = 0;\n this.validateParams();\n }\n\n /**\n * Validates the parameters for this command.\n * @throws Error if parameters are invalid\n */\n validateParams(): void {\n //\n }\n\n /**\n * Gets the name of this command.\n */\n get name(): string {\n return this.constructor.name;\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 { name: this.name, index: this.index, params: this.params };\n }\n\n /**\n * Gets a parameter value by name.\n * @param name The name of the parameter\n * @returns The parameter value, or null if not found\n */\n getParam(name: string): any {\n for (const param of this.params) {\n if (param.key == name) return param.value;\n }\n return null;\n }\n\n /**\n * Gets a parameter value by index.\n * @param index The index of the parameter\n * @returns The parameter value, or null if not found\n */\n getParamAt(index: number): any {\n return index < this.params.length ? this.params[index].value : null;\n }\n\n /**\n * Applies this command to a block (the primary method).\n * Since Notation extends Block, this works for both.\n * @param container The block to apply this command to\n */\n abstract applyToBlock(container: Block): void;\n\n /**\n * @deprecated Use applyToBlock instead\n * Applies this command to a notation.\n * Default implementation delegates to applyToBlock.\n * @param notation The notation to apply this command to\n */\n applyToNotation(notation: Notation): void {\n this.applyToBlock(notation);\n }\n}\n\n/**\n * Represents metadata for the notation.\n */\nexport class MetaData {\n /**\n * Creates a new MetaData.\n * @param key The key for this metadata\n * @param value The value of this metadata\n * @param params Optional additional parameters\n */\n constructor(\n public readonly key: string,\n public readonly value: string,\n public readonly params?: any,\n ) {\n params = params || {};\n }\n}\n\n/**\n * The main class representing a complete notation.\n * Notation is the root Block of the notation hierarchy.\n * It contains all the elements, settings, and layout information for a piece of music.\n */\nexport class Notation extends Block {\n readonly TYPE = \"Notation\";\n\n // ============================================\n // Notation-specific properties\n // ============================================\n\n /** Metadata associated with this notation */\n metadata = new Map<string, MetaData>();\n\n /** Handler for missing roles */\n onMissingRole: (name: string) => RoleDef | null = (name) => this.newRoleDef(name, name == \"sw\");\n\n /** Layout parameters management */\n private _unnamedLayoutParams: LayoutParams[] = [];\n private _namedLayoutParams = new Map<string, LayoutParams>();\n private _layoutParams: LayoutParams | null = null;\n\n /**\n * Creates a new Notation.\n */\n constructor() {\n super(\"notation\", null);\n // Set default values for root notation\n this.localCycle = Cycle.DEFAULT;\n this.localAtomsPerBeat = 1;\n this.localBreaks = [];\n }\n\n // ============================================\n // Backward compatibility aliases\n // ============================================\n\n /**\n * @deprecated Use blockItems instead\n * Legacy accessor for blocks array.\n */\n get blocks(): BlockItem[] {\n return this.blockItems;\n }\n\n /**\n * @deprecated Use localAtomsPerBeat instead\n * Legacy accessor for current atoms per beat.\n */\n get currentAPB(): number {\n return this.localAtomsPerBeat ?? 1;\n }\n\n set currentAPB(value: number) {\n this.localAtomsPerBeat = value;\n }\n\n /**\n * @deprecated Use localCycle instead\n * Legacy accessor for current cycle.\n */\n get currentCycle(): Cycle {\n return this.localCycle ?? Cycle.DEFAULT;\n }\n\n set currentCycle(value: Cycle) {\n this.localCycle = value;\n }\n\n /**\n * @deprecated Use localBreaks instead\n * Legacy accessor for current breaks.\n */\n get currentBreaks(): number[] {\n return this.localBreaks ?? [];\n }\n\n set currentBreaks(value: number[]) {\n this.localBreaks = value;\n }\n\n /**\n * @deprecated Use localRoles instead\n * Legacy accessor for roles array.\n */\n get roles(): RoleDef[] {\n return Array.from(this.localRoles.values());\n }\n\n // ============================================\n // Layout parameters management\n // ============================================\n\n /**\n * Gets the unnamed layout parameters.\n */\n get unnamedLayoutParams(): ReadonlyArray<LayoutParams> {\n return this._unnamedLayoutParams;\n }\n\n /**\n * Gets the named layout parameters.\n */\n get namedLayoutParams(): ReadonlyMap<string, LayoutParams> {\n return this._namedLayoutParams;\n }\n\n /**\n * Gets the current layout parameters, creating or finding an appropriate one if needed.\n */\n get layoutParams(): LayoutParams {\n if (this._layoutParams == null) {\n // create it or find one that matches current params\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 */\n resetLayoutParams(): void {\n this._layoutParams = null;\n this.resetLine();\n }\n\n /**\n * Ensures that named layout parameters with the given name exist.\n * Creates them if they don't exist, or updates current layout parameters to match.\n *\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 // no change so go ahead\n if (lp == null) {\n // does not exist so create one by re-snapshotting it\n // and saving it\n lp = this.snapshotLayoutParams();\n this._namedLayoutParams.set(name, lp);\n } else {\n // copy named LPs attributes into our locals\n this.currentCycle = lp.cycle;\n this.currentAPB = lp.beatDuration;\n this.currentBreaks = lp.lineBreaks;\n }\n this._layoutParams = lp;\n this.resetLine(); // since layout params have changed\n }\n return this._layoutParams;\n }\n\n /**\n * Creates a snapshot of the current layout parameters.\n * @returns A new LayoutParams object with the current settings\n */\n protected snapshotLayoutParams(): LayoutParams {\n return new LayoutParams({\n cycle: this.currentCycle,\n beatDuration: this.currentAPB,\n layout: this.currentBreaks,\n });\n }\n\n /**\n * Finds an unnamed layout parameters object that matches the current settings.\n * @returns Matching layout parameters, or null if none found\n */\n protected findUnnamedLayoutParams(): LayoutParams | null {\n return (\n this._unnamedLayoutParams.find((lp) => {\n return (\n lp.beatDuration == this.currentAPB &&\n this.currentCycle.equals(lp.cycle) &&\n lp.lineBreaksEqual(this.currentBreaks)\n );\n }) || null\n );\n }\n\n // ============================================\n // Overridden methods\n // ============================================\n\n /**\n * Sets the current role by name.\n * Uses onMissingRole callback for auto-creation of missing roles.\n * @param name The name of the role to set as current\n * @throws Error if the name is empty or the role is not found\n */\n setCurrRole(name: string): void {\n name = name.trim().toLowerCase();\n if (name.trim() == \"\") {\n throw new Error(\"Role name cannot be empty\");\n }\n const roleDef = this.getRole(name) || (this.onMissingRole ? this.onMissingRole(name) || null : null);\n if (roleDef == null) {\n throw new Error(\"Role not found: \" + name);\n }\n this._currRoleDef = roleDef;\n }\n\n /**\n * Gets a role definition by name.\n * Handles empty name by returning the last added role.\n * @param name The name of the role\n * @returns The role definition, or null if not found\n */\n getRoleDef(name: string): TSU.Nullable<RoleDef> {\n name = name.trim().toLowerCase();\n if (name === \"\") {\n // Return the last added role if name is empty\n const roles = Array.from(this.localRoles.values());\n return roles[roles.length - 1] || null;\n }\n return this.localRoles.get(name) ?? null;\n }\n\n /**\n * Creates a new role definition.\n * @param name The name of the role\n * @param notesOnly Whether the role contains only notes, defaults to false\n * @returns The created role definition\n * @throws Error if the name is empty or the role already exists\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 already exists: \" + name);\n }\n // create new and add\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\n return rd;\n }\n\n // ============================================\n // Additional methods\n // ============================================\n\n /**\n * Adds a line to this notation.\n * @param line The line to add\n */\n addLine(line: Line): void {\n this.addBlockItem(line);\n }\n\n /**\n * Removes a line from this notation.\n * @param line The line to remove\n * @returns The index of the removed line, or -1 if not found\n */\n removeLine(line: Line): number {\n return this.removeBlockItem(line);\n }\n\n /**\n * Adds a raw block to this notation.\n * @param raw The raw block to add\n */\n addRawBlock(raw: RawBlock): void {\n this.addBlockItem(raw);\n this.resetLine();\n }\n\n /**\n * Adds metadata to this notation.\n * @param meta The metadata to add\n * @param addBlock Whether to add a corresponding raw block, defaults to true\n */\n addMetaData(meta: MetaData, addBlock = true): void {\n if (addBlock && !this.metadata.has(meta.key)) {\n // Add a new raw block here\n // set this by key so even if metadata changes we can\n // get latest value of it\n const raw = new RawBlock(meta.key, \"metadata\");\n this.addRawBlock(raw);\n }\n this.metadata.set(meta.key, meta);\n }\n\n /**\n * Resets the current line pointer to null.\n */\n resetLine(): void {\n this._currentLine = null;\n }\n\n /**\n * Returns a debug-friendly representation of this notation.\n * Uses Notation-specific property names for backward compatibility.\n * @returns An object containing debug information\n */\n debugValue(): any {\n // Use Notation-specific names (blocks, currentCycle, etc.)\n // instead of Block names (blockItems, localCycle, etc.)\n // to maintain backward compatibility with existing tests\n return {\n blocks: this.blocks.map((b) => b.debugValue()),\n currentAPB: this.currentAPB,\n currentBreaks: this.currentBreaks,\n currentCycle: this.currentCycle?.uuid,\n roles: this.roles,\n };\n }\n\n // Need protected access to _currRoleDef for setCurrRole override\n protected _currRoleDef: TSU.Nullable<RoleDef> = null;\n\n /**\n * Gets the current role definition.\n */\n get currRoleDef(): RoleDef | null {\n if (this._currRoleDef == null) {\n const roles = Array.from(this.localRoles.values());\n if (roles.length === 0) {\n return null;\n } else {\n this._currRoleDef = roles[roles.length - 1];\n }\n }\n return this._currRoleDef;\n }\n\n // Need protected access to _currentLine for resetLine\n protected _currentLine: Line | null = null;\n\n /**\n * Gets the current line, creating it 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 and makes it the current line.\n * @returns The newly created line\n */\n newLine(): Line {\n if (this._currentLine && this._currentLine.isEmpty) {\n // then remove it first instead of adding another\n // so we dont have a string of empty lines\n this.removeLine(this._currentLine);\n }\n this._currentLine = new Line();\n this.addLine(this._currentLine);\n return this._currentLine;\n }\n}\n"]}
@@ -3,10 +3,22 @@ import * as G from "galore";
3
3
  import * as TLEX from "tlex";
4
4
  import { Literal, Note, Atom, Rest, Space, Group } from "./core";
5
5
  import { Notation, Command, CmdParam } from "./notation";
6
+ import { Block } from "./block";
7
+ export declare class BlockCommand extends Command {
8
+ readonly innerCommand: Command;
9
+ readonly blockCommands: Command[];
10
+ constructor(innerCommand: Command, blockCommands: Command[]);
11
+ get name(): string;
12
+ private createBlock;
13
+ debugValue(): any;
14
+ applyToNotation(notation: Notation): void;
15
+ applyToBlock(container: Block): void;
16
+ }
6
17
  export declare class Parser {
7
18
  errors: (TLEX.TokenizerError | G.ParseError)[];
8
19
  metadata: any;
9
20
  readonly commands: Command[];
21
+ private blockStartStack;
10
22
  protected ruleHandlers: {
11
23
  newFraction: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => TSU.Num.Fraction;
12
24
  newGroup: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Group;
@@ -14,10 +26,10 @@ export declare class Parser {
14
26
  litWithPreEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Literal;
15
27
  litWithPostEmb: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Literal;
16
28
  litToAtom: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
17
- newSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
18
- newRest: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Rest;
19
- newDoubleSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
20
- newSilentSpace: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Space;
29
+ newSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
30
+ newRest: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Rest;
31
+ newDoubleSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
32
+ newSilentSpace: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Space;
21
33
  applyPreMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
22
34
  applyPostMarker: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
23
35
  applyDuration: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Atom;
@@ -29,14 +41,17 @@ export declare class Parser {
29
41
  };
30
42
  newParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any[];
31
43
  concatParamList: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
32
- newCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Command;
44
+ beginBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => null;
45
+ endBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => Command[];
46
+ nullBlock: (_rule: G.Rule, _parent: G.PTNode, ..._children: G.PTNode[]) => null;
47
+ newCommandWithBlock: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => Command;
33
48
  appendAtoms: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
34
49
  prependFrontMatter: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => any;
35
50
  appendCommand: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
36
51
  appendRoleSelector: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
37
52
  insertEmbedding: (rule: G.Rule, parent: G.PTNode, ...children: G.PTNode[]) => null;
38
53
  };
39
- constructor(config?: any);
54
+ constructor(_config?: any);
40
55
  createCommand(name: string, params: CmdParam[]): Command;
41
56
  addCommand(cmd: Command): void;
42
57
  parse(input: string): any;