notations 0.0.47 → 0.0.50
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/lib/cjs/beats.d.ts +34 -69
- package/lib/cjs/beats.js +178 -439
- package/lib/cjs/beats.js.map +1 -1
- package/lib/cjs/beatutils.d.ts +3 -0
- package/lib/cjs/beatutils.js +64 -0
- package/lib/cjs/beatutils.js.map +1 -0
- package/lib/cjs/beatview.d.ts +18 -0
- package/lib/cjs/beatview.js +62 -0
- package/lib/cjs/beatview.js.map +1 -0
- package/lib/cjs/carnatic/LineView.d.ts +2 -7
- package/lib/cjs/carnatic/LineView.js +13 -31
- package/lib/cjs/carnatic/LineView.js.map +1 -1
- package/lib/cjs/carnatic/NotationView.d.ts +8 -7
- package/lib/cjs/carnatic/NotationView.js +73 -153
- package/lib/cjs/carnatic/NotationView.js.map +1 -1
- package/lib/cjs/carnatic/atomviews.js +149 -287
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/carnatic/beatviews.d.ts +4 -13
- package/lib/cjs/carnatic/beatviews.js +23 -118
- package/lib/cjs/carnatic/beatviews.js.map +1 -1
- package/lib/cjs/carnatic/embelishments.d.ts +1 -1
- package/lib/cjs/carnatic/embelishments.js +189 -283
- package/lib/cjs/carnatic/embelishments.js.map +1 -1
- package/lib/cjs/carnatic/gamakas.js +15 -47
- package/lib/cjs/carnatic/gamakas.js.map +1 -1
- package/lib/cjs/commands.js +111 -271
- package/lib/cjs/commands.js.map +1 -1
- package/lib/cjs/core.d.ts +14 -1
- package/lib/cjs/core.js +291 -477
- package/lib/cjs/core.js.map +1 -1
- package/lib/cjs/cycle.js +175 -367
- package/lib/cjs/cycle.js.map +1 -1
- package/lib/cjs/entity.js +48 -102
- package/lib/cjs/entity.js.map +1 -1
- package/lib/cjs/grids.d.ts +125 -0
- package/lib/cjs/grids.js +550 -0
- package/lib/cjs/grids.js.map +1 -0
- package/lib/cjs/iterators.js +96 -234
- package/lib/cjs/iterators.js.map +1 -1
- package/lib/cjs/layouts.d.ts +1 -1
- package/lib/cjs/layouts.js +62 -98
- package/lib/cjs/layouts.js.map +1 -1
- package/lib/cjs/loader.d.ts +2 -2
- package/lib/cjs/loader.js +23 -123
- package/lib/cjs/loader.js.map +1 -1
- package/lib/cjs/notation.d.ts +0 -3
- package/lib/cjs/notation.js +139 -241
- package/lib/cjs/notation.js.map +1 -1
- package/lib/cjs/parser.d.ts +2 -0
- package/lib/cjs/parser.js +230 -214
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/shapes.js +149 -283
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/cjs/utils.d.ts +8 -0
- package/lib/cjs/utils.js +60 -55
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/beats.d.ts +34 -69
- package/lib/esm/beats.js +172 -438
- package/lib/esm/beats.js.map +1 -1
- package/lib/esm/beatutils.d.ts +3 -0
- package/lib/esm/beatutils.js +37 -0
- package/lib/esm/beatutils.js.map +1 -0
- package/lib/esm/beatview.d.ts +18 -0
- package/lib/esm/beatview.js +35 -0
- package/lib/esm/beatview.js.map +1 -0
- package/lib/esm/carnatic/LineView.d.ts +2 -7
- package/lib/esm/carnatic/LineView.js +12 -31
- package/lib/esm/carnatic/LineView.js.map +1 -1
- package/lib/esm/carnatic/NotationView.d.ts +8 -7
- package/lib/esm/carnatic/NotationView.js +71 -152
- package/lib/esm/carnatic/NotationView.js.map +1 -1
- package/lib/esm/carnatic/atomviews.js +144 -284
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/carnatic/beatviews.d.ts +4 -13
- package/lib/esm/carnatic/beatviews.js +21 -94
- package/lib/esm/carnatic/beatviews.js.map +1 -1
- package/lib/esm/carnatic/embelishments.d.ts +1 -1
- package/lib/esm/carnatic/embelishments.js +187 -296
- package/lib/esm/carnatic/embelishments.js.map +1 -1
- package/lib/esm/carnatic/gamakas.js +14 -48
- package/lib/esm/carnatic/gamakas.js.map +1 -1
- package/lib/esm/commands.js +100 -271
- package/lib/esm/commands.js.map +1 -1
- package/lib/esm/core.d.ts +14 -1
- package/lib/esm/core.js +287 -484
- package/lib/esm/core.js.map +1 -1
- package/lib/esm/cycle.js +172 -367
- package/lib/esm/cycle.js.map +1 -1
- package/lib/esm/entity.js +48 -104
- package/lib/esm/entity.js.map +1 -1
- package/lib/esm/grids.d.ts +125 -0
- package/lib/esm/grids.js +517 -0
- package/lib/esm/grids.js.map +1 -0
- package/lib/esm/iterators.js +93 -235
- package/lib/esm/iterators.js.map +1 -1
- package/lib/esm/layouts.d.ts +1 -1
- package/lib/esm/layouts.js +60 -97
- package/lib/esm/layouts.js.map +1 -1
- package/lib/esm/loader.d.ts +2 -2
- package/lib/esm/loader.js +20 -120
- package/lib/esm/loader.js.map +1 -1
- package/lib/esm/notation.d.ts +0 -3
- package/lib/esm/notation.js +135 -242
- package/lib/esm/notation.js.map +1 -1
- package/lib/esm/parser.d.ts +2 -0
- package/lib/esm/parser.js +225 -210
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/shapes.js +148 -288
- package/lib/esm/shapes.js.map +1 -1
- package/lib/esm/utils.d.ts +8 -0
- package/lib/esm/utils.js +55 -51
- package/lib/esm/utils.js.map +1 -1
- package/package.json +18 -17
|
@@ -22,78 +22,44 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
-
if (!m) return o;
|
|
28
|
-
var i = m.call(o), r, ar = [], e;
|
|
29
|
-
try {
|
|
30
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
-
}
|
|
32
|
-
catch (error) { e = { error: error }; }
|
|
33
|
-
finally {
|
|
34
|
-
try {
|
|
35
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
-
}
|
|
37
|
-
finally { if (e) throw e.error; }
|
|
38
|
-
}
|
|
39
|
-
return ar;
|
|
40
|
-
};
|
|
41
|
-
var __values = (this && this.__values) || function(o) {
|
|
42
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
43
|
-
if (m) return m.call(o);
|
|
44
|
-
if (o && typeof o.length === "number") return {
|
|
45
|
-
next: function () {
|
|
46
|
-
if (o && i >= o.length) o = void 0;
|
|
47
|
-
return { value: o && o[i++], done: !o };
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
51
|
-
};
|
|
52
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
26
|
exports.NotationView = void 0;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
27
|
+
const TSU = __importStar(require("@panyam/tsutils"));
|
|
28
|
+
const LineView_1 = require("./LineView");
|
|
29
|
+
const beatviews_1 = require("./beatviews");
|
|
30
|
+
class NotationView {
|
|
31
|
+
constructor(rootElement, config) {
|
|
58
32
|
this.rootElement = rootElement;
|
|
59
33
|
this.config = config;
|
|
60
34
|
this.lineViews = [];
|
|
61
|
-
this.beatsByLineRole = new Map();
|
|
62
|
-
this.beatLayouts = new Map();
|
|
63
35
|
this.currentSVGElement = null;
|
|
64
36
|
this.beatViews = new Map();
|
|
65
37
|
this.loadChildViews();
|
|
66
38
|
}
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.beatViews.set(beat.uuid, curr);
|
|
76
|
-
}
|
|
77
|
-
return curr;
|
|
78
|
-
};
|
|
79
|
-
NotationView.prototype.loadChildViews = function () {
|
|
39
|
+
get beatLayout() {
|
|
40
|
+
return this._beatLayout;
|
|
41
|
+
}
|
|
42
|
+
set beatLayout(beatLayout) {
|
|
43
|
+
this._beatLayout = beatLayout;
|
|
44
|
+
beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);
|
|
45
|
+
}
|
|
46
|
+
loadChildViews() {
|
|
80
47
|
this.tableElement = TSU.DOM.createNode("table", {
|
|
81
48
|
parent: this.rootElement,
|
|
82
49
|
attrs: {
|
|
83
50
|
class: "notationsContentRootTable",
|
|
84
51
|
},
|
|
85
52
|
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var tr = TSU.DOM.createNode("tr", {
|
|
53
|
+
}
|
|
54
|
+
addNewRow(id, prefix, withAnnotation = true) {
|
|
55
|
+
const tr = TSU.DOM.createNode("tr", {
|
|
90
56
|
parent: this.tableElement,
|
|
91
57
|
attrs: {
|
|
92
58
|
class: prefix + "Row",
|
|
93
59
|
id: prefix + "Row" + id,
|
|
94
60
|
},
|
|
95
61
|
});
|
|
96
|
-
|
|
62
|
+
let td1 = null;
|
|
97
63
|
if (withAnnotation) {
|
|
98
64
|
td1 = TSU.DOM.createNode("td", {
|
|
99
65
|
parent: tr,
|
|
@@ -103,7 +69,7 @@ var NotationView = (function () {
|
|
|
103
69
|
},
|
|
104
70
|
});
|
|
105
71
|
}
|
|
106
|
-
|
|
72
|
+
const td2 = TSU.DOM.createNode("td", {
|
|
107
73
|
parent: tr,
|
|
108
74
|
attrs: {
|
|
109
75
|
class: prefix + "ContentCell",
|
|
@@ -112,9 +78,9 @@ var NotationView = (function () {
|
|
|
112
78
|
},
|
|
113
79
|
});
|
|
114
80
|
return [td1, td2];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
81
|
+
}
|
|
82
|
+
newLineRoot(parent, line) {
|
|
83
|
+
const [td1, td2] = this.addNewRow(line.uuid + "", "line");
|
|
118
84
|
if (line.marginText) {
|
|
119
85
|
td1.innerHTML = line.marginText;
|
|
120
86
|
}
|
|
@@ -125,133 +91,87 @@ var NotationView = (function () {
|
|
|
125
91
|
class: "lineRootSVG",
|
|
126
92
|
},
|
|
127
93
|
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
94
|
+
}
|
|
95
|
+
ensureLineView(line) {
|
|
96
|
+
let lineView = this.getLineView(line);
|
|
131
97
|
if (lineView == null) {
|
|
132
|
-
|
|
133
|
-
|
|
98
|
+
const layoutParams = line.layoutParams || null;
|
|
99
|
+
const svgElem = this.newLineRoot(this.tableElement, line);
|
|
134
100
|
lineView = new LineView_1.LineView(svgElem, line, {
|
|
135
101
|
layoutParams: layoutParams,
|
|
136
102
|
});
|
|
137
103
|
if (!line.isEmpty) {
|
|
138
104
|
TSU.assert(layoutParams != null, "Layout params for a non empty line *should* exist");
|
|
139
|
-
|
|
140
|
-
lineView.beatLayout = beatLayout;
|
|
105
|
+
lineView.gridModel = this.beatLayout.getGridModelForLine(line.uuid);
|
|
141
106
|
}
|
|
142
|
-
lineView.beatsByLineRole = this.beatsByLineRole.get(line.uuid);
|
|
143
107
|
this.lineViews.push(lineView);
|
|
144
108
|
}
|
|
145
109
|
return lineView;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return this.lineViews.find(
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
enumerable: false,
|
|
155
|
-
configurable: true
|
|
156
|
-
});
|
|
157
|
-
NotationView.prototype.clear = function () {
|
|
110
|
+
}
|
|
111
|
+
getLineView(line) {
|
|
112
|
+
return this.lineViews.find((l) => l.line == line) || null;
|
|
113
|
+
}
|
|
114
|
+
get currentLineView() {
|
|
115
|
+
return this.lineViews[this.lineViews.length - 1];
|
|
116
|
+
}
|
|
117
|
+
clear() {
|
|
158
118
|
this.lineViews = [];
|
|
159
|
-
this.beatsByLineRole = new Map();
|
|
160
|
-
this.beatLayouts = new Map();
|
|
161
119
|
this.currentSVGElement = null;
|
|
162
120
|
this.tableElement.innerHTML = "";
|
|
163
121
|
this.beatViews = new Map();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var block = _f.value;
|
|
172
|
-
if (block.type == "RawBlock") {
|
|
173
|
-
this.renderBlock(block);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
lines.push(block);
|
|
177
|
-
var lineView = this.renderLine(block);
|
|
178
|
-
lineViews.push(lineView);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
183
|
-
finally {
|
|
184
|
-
try {
|
|
185
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
186
|
-
}
|
|
187
|
-
finally { if (e_1) throw e_1.error; }
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
for (var _g = __values(this.beatLayouts.values()), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
191
|
-
var bl = _h.value;
|
|
192
|
-
bl.evalColumnSizes(this);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
196
|
-
finally {
|
|
197
|
-
try {
|
|
198
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
122
|
+
}
|
|
123
|
+
refreshLayout() {
|
|
124
|
+
const lines = [];
|
|
125
|
+
const lineViews = [];
|
|
126
|
+
for (const block of this.notation.blocks) {
|
|
127
|
+
if (block.type == "RawBlock") {
|
|
128
|
+
this.renderBlock(block);
|
|
199
129
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var beatView = _k.value;
|
|
205
|
-
beatView.refreshLayout();
|
|
130
|
+
else {
|
|
131
|
+
lines.push(block);
|
|
132
|
+
const lineView = this.ensureLineView(block);
|
|
133
|
+
lineViews.push(lineView);
|
|
206
134
|
}
|
|
207
135
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
212
|
-
}
|
|
213
|
-
finally { if (e_3) throw e_3.error; }
|
|
136
|
+
const now = performance.now();
|
|
137
|
+
for (const lineView of lineViews) {
|
|
138
|
+
lineView.gridModel.lastUpdatedAt = now;
|
|
214
139
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
lineView.wrapToSize();
|
|
219
|
-
}
|
|
140
|
+
this.beatLayout.gridLayoutGroup.refreshLayout();
|
|
141
|
+
for (const lineView of lineViews) {
|
|
142
|
+
lineView.wrapToSize();
|
|
220
143
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (lineViews_1_1 && !lineViews_1_1.done && (_d = lineViews_1.return)) _d.call(lineViews_1);
|
|
225
|
-
}
|
|
226
|
-
finally { if (e_4) throw e_4.error; }
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
NotationView.prototype.renderLine = function (line) {
|
|
230
|
-
var lineView = this.ensureLineView(line);
|
|
231
|
-
if (!line.isEmpty) {
|
|
232
|
-
lineView.beatLayout.layoutBeatsForLine(line, lineView.beatsByLineRole, this);
|
|
233
|
-
}
|
|
234
|
-
return lineView;
|
|
235
|
-
};
|
|
236
|
-
NotationView.prototype.renderBlock = function (raw) {
|
|
237
|
-
var _a = __read(this.addNewRow(raw.uuid + "", "rawBlock", false), 2), td2 = _a[1];
|
|
144
|
+
}
|
|
145
|
+
renderBlock(raw) {
|
|
146
|
+
const [, td2] = this.addNewRow(raw.uuid + "", "rawBlock", false);
|
|
238
147
|
if (raw.contentType == "metadata") {
|
|
239
|
-
|
|
148
|
+
const meta = this.notation.metadata.get(raw.content);
|
|
240
149
|
if (meta) {
|
|
241
150
|
if (meta.key.toLowerCase().indexOf(":") < 0) {
|
|
242
|
-
|
|
243
|
-
|
|
151
|
+
const div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
152
|
+
const html = `<span class = "${meta.key.toLowerCase()}"><strong>${meta.key}</strong>: ${meta.value}</span>`;
|
|
244
153
|
div.innerHTML = html;
|
|
245
154
|
}
|
|
246
155
|
}
|
|
247
156
|
}
|
|
248
157
|
else {
|
|
249
|
-
|
|
158
|
+
const div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
250
159
|
div.innerHTML = this.markdownParser(raw.content.trim());
|
|
251
160
|
}
|
|
252
161
|
this.currentSVGElement = null;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
162
|
+
}
|
|
163
|
+
viewForBeat(cell) {
|
|
164
|
+
const beat = cell.value;
|
|
165
|
+
let curr = this.beatViews.get(beat.uuid) || null;
|
|
166
|
+
if (curr == null) {
|
|
167
|
+
const line = beat.role.line;
|
|
168
|
+
const lineView = this.ensureLineView(line);
|
|
169
|
+
const lp = line.layoutParams;
|
|
170
|
+
curr = new beatviews_1.BeatView(cell, beat, lineView.gElem, lp.cycle);
|
|
171
|
+
this.beatViews.set(beat.uuid, curr);
|
|
172
|
+
}
|
|
173
|
+
return curr;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
256
176
|
exports.NotationView = NotationView;
|
|
257
177
|
//# sourceMappingURL=NotationView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,uCAAsC;AAKtC;IAYE,sBAA4B,WAAwB,EAAkB,MAAY;QAAtD,gBAAW,GAAX,WAAW,CAAa;QAAkB,WAAM,GAAN,MAAM,CAAM;QATlF,cAAS,GAAe,EAAE,CAAC;QAE3B,oBAAe,GAAG,IAAI,GAAG,EAAoB,CAAC;QAC9C,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC5C,sBAAiB,GAAyB,IAAI,CAAC;QAE/C,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QA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Y","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock } from \"../notation\";\nimport { Beat, BeatLayout, BeatView } from \"../beats\";\nimport { Line } from \"../core\";\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 beatsByLineRole = new Map<number, Beat[][]>();\n beatLayouts = new Map<number, BeatLayout>();\n currentSVGElement: SVGSVGElement | null = null;\n tableElement: HTMLTableElement;\n beatViews = new Map<number, BeatView>();\n markdownParser: (contents: string) => string;\n\n constructor(public readonly rootElement: HTMLElement, public readonly config?: any) {\n this.loadChildViews();\n }\n\n refresh(): void {\n this.beatViews = new Map<number, BeatView>();\n }\n\n viewForBeat(beat: Beat): BeatView {\n let curr = this.beatViews.get(beat.uuid) || null;\n if (curr == null) {\n // how to get the bar and beat index for a given beat in a given row?\n const lineView = this.ensureLineView(beat.role.line);\n curr = lineView.viewForBeat(beat);\n this.beatViews.set(beat.uuid, curr);\n }\n return curr;\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 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 = this.notation.layoutParamsForLine(line) || 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 const beatLayout = this.beatLayouts.get(layoutParams.uuid)!;\n lineView.beatLayout = beatLayout;\n }\n lineView.beatsByLineRole = this.beatsByLineRole.get(line.uuid)!;\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.beatsByLineRole = new Map<number, Beat[][]>();\n this.beatLayouts = new Map<number, BeatLayout>();\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.renderLine(block as Line);\n lineViews.push(lineView);\n }\n }\n\n // Eval column sizes all beat layouts\n for (const bl of this.beatLayouts.values()) {\n bl.evalColumnSizes(this);\n }\n\n // now that all spacing has been calculated\n // go through all\n for (const beatView of this.beatViews.values()) {\n beatView.refreshLayout();\n }\n\n // Set line view preferred sizes\n for (const lineView of lineViews) {\n lineView.wrapToSize();\n }\n }\n\n renderLine(line: Line): LineView {\n const lineView = this.ensureLineView(line);\n // Layout the \"rows\" for this line - x has already been set by the\n // previous column spacing step\n if (!line.isEmpty) {\n lineView.beatLayout.layoutBeatsForLine(line, lineView.beatsByLineRole, this);\n }\n return lineView;\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"]}
|
|
1
|
+
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AACvC,yCAAsC;AAKtC,2CAAuC;AAEvC,MAAa,YAAY;IAUvB,YAA4B,WAAwB,EAAkB,MAAY;QAAtD,gBAAW,GAAX,WAAW,CAAa;QAAkB,WAAM,GAAN,MAAM,CAAM;QAPlF,cAAS,GAAe,EAAE,CAAC;QAE3B,sBAAiB,GAAyB,IAAI,CAAC;QA+J/C,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;QAzJtC,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED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AAC;QACxB,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;QACjD,IAAI,IAAI,IAAI,IAAI,EAAE;YAChB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAE5B,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;YAC7B,IAAI,GAAG,IAAI,oBAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;YAC1D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlLD,oCAkLC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { LineView } from \"./LineView\";\nimport { Notation, RawBlock } from \"../notation\";\nimport { GlobalBeatLayout } from \"../beats\";\nimport { GridCell } from \"../grids\";\nimport { Line } from \"../core\";\nimport { BeatView } 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(public readonly rootElement: HTMLElement, public readonly config?: any) {\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 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 viewForBeat(cell: GridCell): BeatView {\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 }\n}\n"]}
|