notations 0.0.48 → 0.0.49
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 +6 -1
- package/lib/cjs/core.js +288 -493
- 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 +124 -1
- package/lib/cjs/grids.js +546 -6
- package/lib/cjs/grids.js.map +1 -1
- 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 +217 -219
- 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 +6 -1
- package/lib/esm/core.js +286 -502
- 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 +124 -1
- package/lib/esm/grids.js +515 -5
- package/lib/esm/grids.js.map +1 -1
- 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 +211 -214
- 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 +2 -1
|
@@ -1,73 +1,39 @@
|
|
|
1
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
-
if (!m) return o;
|
|
4
|
-
var i = m.call(o), r, ar = [], e;
|
|
5
|
-
try {
|
|
6
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
-
}
|
|
8
|
-
catch (error) { e = { error: error }; }
|
|
9
|
-
finally {
|
|
10
|
-
try {
|
|
11
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
-
}
|
|
13
|
-
finally { if (e) throw e.error; }
|
|
14
|
-
}
|
|
15
|
-
return ar;
|
|
16
|
-
};
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
1
|
import * as TSU from "@panyam/tsutils";
|
|
29
2
|
import { LineView } from "./LineView";
|
|
30
|
-
|
|
31
|
-
|
|
3
|
+
import { BeatView } from "./beatviews";
|
|
4
|
+
export class NotationView {
|
|
5
|
+
constructor(rootElement, config) {
|
|
32
6
|
this.rootElement = rootElement;
|
|
33
7
|
this.config = config;
|
|
34
8
|
this.lineViews = [];
|
|
35
|
-
this.beatsByLineRole = new Map();
|
|
36
|
-
this.beatLayouts = new Map();
|
|
37
9
|
this.currentSVGElement = null;
|
|
38
10
|
this.beatViews = new Map();
|
|
39
11
|
this.loadChildViews();
|
|
40
12
|
}
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.beatViews.set(beat.uuid, curr);
|
|
50
|
-
}
|
|
51
|
-
return curr;
|
|
52
|
-
};
|
|
53
|
-
NotationView.prototype.loadChildViews = function () {
|
|
13
|
+
get beatLayout() {
|
|
14
|
+
return this._beatLayout;
|
|
15
|
+
}
|
|
16
|
+
set beatLayout(beatLayout) {
|
|
17
|
+
this._beatLayout = beatLayout;
|
|
18
|
+
beatLayout.gridLayoutGroup.getCellView = (cell) => this.viewForBeat(cell);
|
|
19
|
+
}
|
|
20
|
+
loadChildViews() {
|
|
54
21
|
this.tableElement = TSU.DOM.createNode("table", {
|
|
55
22
|
parent: this.rootElement,
|
|
56
23
|
attrs: {
|
|
57
24
|
class: "notationsContentRootTable",
|
|
58
25
|
},
|
|
59
26
|
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var tr = TSU.DOM.createNode("tr", {
|
|
27
|
+
}
|
|
28
|
+
addNewRow(id, prefix, withAnnotation = true) {
|
|
29
|
+
const tr = TSU.DOM.createNode("tr", {
|
|
64
30
|
parent: this.tableElement,
|
|
65
31
|
attrs: {
|
|
66
32
|
class: prefix + "Row",
|
|
67
33
|
id: prefix + "Row" + id,
|
|
68
34
|
},
|
|
69
35
|
});
|
|
70
|
-
|
|
36
|
+
let td1 = null;
|
|
71
37
|
if (withAnnotation) {
|
|
72
38
|
td1 = TSU.DOM.createNode("td", {
|
|
73
39
|
parent: tr,
|
|
@@ -77,7 +43,7 @@ var NotationView = (function () {
|
|
|
77
43
|
},
|
|
78
44
|
});
|
|
79
45
|
}
|
|
80
|
-
|
|
46
|
+
const td2 = TSU.DOM.createNode("td", {
|
|
81
47
|
parent: tr,
|
|
82
48
|
attrs: {
|
|
83
49
|
class: prefix + "ContentCell",
|
|
@@ -86,9 +52,9 @@ var NotationView = (function () {
|
|
|
86
52
|
},
|
|
87
53
|
});
|
|
88
54
|
return [td1, td2];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
55
|
+
}
|
|
56
|
+
newLineRoot(parent, line) {
|
|
57
|
+
const [td1, td2] = this.addNewRow(line.uuid + "", "line");
|
|
92
58
|
if (line.marginText) {
|
|
93
59
|
td1.innerHTML = line.marginText;
|
|
94
60
|
}
|
|
@@ -99,133 +65,86 @@ var NotationView = (function () {
|
|
|
99
65
|
class: "lineRootSVG",
|
|
100
66
|
},
|
|
101
67
|
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
68
|
+
}
|
|
69
|
+
ensureLineView(line) {
|
|
70
|
+
let lineView = this.getLineView(line);
|
|
105
71
|
if (lineView == null) {
|
|
106
|
-
|
|
107
|
-
|
|
72
|
+
const layoutParams = line.layoutParams || null;
|
|
73
|
+
const svgElem = this.newLineRoot(this.tableElement, line);
|
|
108
74
|
lineView = new LineView(svgElem, line, {
|
|
109
75
|
layoutParams: layoutParams,
|
|
110
76
|
});
|
|
111
77
|
if (!line.isEmpty) {
|
|
112
78
|
TSU.assert(layoutParams != null, "Layout params for a non empty line *should* exist");
|
|
113
|
-
|
|
114
|
-
lineView.beatLayout = beatLayout;
|
|
79
|
+
lineView.gridModel = this.beatLayout.getGridModelForLine(line.uuid);
|
|
115
80
|
}
|
|
116
|
-
lineView.beatsByLineRole = this.beatsByLineRole.get(line.uuid);
|
|
117
81
|
this.lineViews.push(lineView);
|
|
118
82
|
}
|
|
119
83
|
return lineView;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return this.lineViews.find(
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
enumerable: false,
|
|
129
|
-
configurable: true
|
|
130
|
-
});
|
|
131
|
-
NotationView.prototype.clear = function () {
|
|
84
|
+
}
|
|
85
|
+
getLineView(line) {
|
|
86
|
+
return this.lineViews.find((l) => l.line == line) || null;
|
|
87
|
+
}
|
|
88
|
+
get currentLineView() {
|
|
89
|
+
return this.lineViews[this.lineViews.length - 1];
|
|
90
|
+
}
|
|
91
|
+
clear() {
|
|
132
92
|
this.lineViews = [];
|
|
133
|
-
this.beatsByLineRole = new Map();
|
|
134
|
-
this.beatLayouts = new Map();
|
|
135
93
|
this.currentSVGElement = null;
|
|
136
94
|
this.tableElement.innerHTML = "";
|
|
137
95
|
this.beatViews = new Map();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var block = _f.value;
|
|
146
|
-
if (block.type == "RawBlock") {
|
|
147
|
-
this.renderBlock(block);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
lines.push(block);
|
|
151
|
-
var lineView = this.renderLine(block);
|
|
152
|
-
lineViews.push(lineView);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
157
|
-
finally {
|
|
158
|
-
try {
|
|
159
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
160
|
-
}
|
|
161
|
-
finally { if (e_1) throw e_1.error; }
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
for (var _g = __values(this.beatLayouts.values()), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
165
|
-
var bl = _h.value;
|
|
166
|
-
bl.evalColumnSizes(this);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
170
|
-
finally {
|
|
171
|
-
try {
|
|
172
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
173
|
-
}
|
|
174
|
-
finally { if (e_2) throw e_2.error; }
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
for (var _j = __values(this.beatViews.values()), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
178
|
-
var beatView = _k.value;
|
|
179
|
-
beatView.refreshLayout();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
183
|
-
finally {
|
|
184
|
-
try {
|
|
185
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
96
|
+
}
|
|
97
|
+
refreshLayout() {
|
|
98
|
+
const lines = [];
|
|
99
|
+
const lineViews = [];
|
|
100
|
+
for (const block of this.notation.blocks) {
|
|
101
|
+
if (block.type == "RawBlock") {
|
|
102
|
+
this.renderBlock(block);
|
|
186
103
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
var lineView = lineViews_1_1.value;
|
|
192
|
-
lineView.wrapToSize();
|
|
104
|
+
else {
|
|
105
|
+
lines.push(block);
|
|
106
|
+
const lineView = this.ensureLineView(block);
|
|
107
|
+
lineViews.push(lineView);
|
|
193
108
|
}
|
|
194
109
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (lineViews_1_1 && !lineViews_1_1.done && (_d = lineViews_1.return)) _d.call(lineViews_1);
|
|
199
|
-
}
|
|
200
|
-
finally { if (e_4) throw e_4.error; }
|
|
110
|
+
const now = performance.now();
|
|
111
|
+
for (const lineView of lineViews) {
|
|
112
|
+
lineView.gridModel.lastUpdatedAt = now;
|
|
201
113
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (!line.isEmpty) {
|
|
206
|
-
lineView.beatLayout.layoutBeatsForLine(line, lineView.beatsByLineRole, this);
|
|
114
|
+
this.beatLayout.gridLayoutGroup.refreshLayout();
|
|
115
|
+
for (const lineView of lineViews) {
|
|
116
|
+
lineView.wrapToSize();
|
|
207
117
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
var _a = __read(this.addNewRow(raw.uuid + "", "rawBlock", false), 2), td2 = _a[1];
|
|
118
|
+
}
|
|
119
|
+
renderBlock(raw) {
|
|
120
|
+
const [, td2] = this.addNewRow(raw.uuid + "", "rawBlock", false);
|
|
212
121
|
if (raw.contentType == "metadata") {
|
|
213
|
-
|
|
122
|
+
const meta = this.notation.metadata.get(raw.content);
|
|
214
123
|
if (meta) {
|
|
215
124
|
if (meta.key.toLowerCase().indexOf(":") < 0) {
|
|
216
|
-
|
|
217
|
-
|
|
125
|
+
const div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
126
|
+
const html = `<span class = "${meta.key.toLowerCase()}"><strong>${meta.key}</strong>: ${meta.value}</span>`;
|
|
218
127
|
div.innerHTML = html;
|
|
219
128
|
}
|
|
220
129
|
}
|
|
221
130
|
}
|
|
222
131
|
else {
|
|
223
|
-
|
|
132
|
+
const div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
224
133
|
div.innerHTML = this.markdownParser(raw.content.trim());
|
|
225
134
|
}
|
|
226
135
|
this.currentSVGElement = null;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
136
|
+
}
|
|
137
|
+
viewForBeat(cell) {
|
|
138
|
+
const beat = cell.value;
|
|
139
|
+
let curr = this.beatViews.get(beat.uuid) || null;
|
|
140
|
+
if (curr == null) {
|
|
141
|
+
const line = beat.role.line;
|
|
142
|
+
const lineView = this.ensureLineView(line);
|
|
143
|
+
const lp = line.layoutParams;
|
|
144
|
+
curr = new BeatView(cell, beat, lineView.gElem, lp.cycle);
|
|
145
|
+
this.beatViews.set(beat.uuid, curr);
|
|
146
|
+
}
|
|
147
|
+
return curr;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
231
150
|
//# sourceMappingURL=NotationView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotationView.js","sourceRoot":"","sources":["../../../src/carnatic/NotationView.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;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;QAItC,IAAI,CAAC,cAAc,EAAE,CAAC;IACxB,CAAC;IAED,8BAAO,GAAP;QACE,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC/C,CAAC;IAED,kCAAW,GAAX,UAAY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IAED,kCAAW,GAAX,UAAY,GAAa;QACjB,IAAA,KAAA,OAAU,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,IAAA,EAAvD,GAAG,QAAoD,CAAC;QACjE,IAAI,GAAG,CAAC,WAAW,IAAI,UAAU,EAAE;YAEjC,IAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrD,IAAI,IAAI,EAAE;gBAER,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;oBAC3C,IAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;oBACvD,IAAM,IAAI,GAAG,0BAAkB,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,wBAAa,IAAI,CAAC,GAAG,wBAAc,IAAI,CAAC,KAAK,YAAS,CAAC;oBAC5G,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;iBACtB;aACF;SACF;aAAM;YACL,IAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YACvD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;SACzD;QACD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAChC,CAAC;IACH,mBAAC;AAAD,CAAC,AA1LD,IA0LC","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,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,OAAO,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,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU,CAAC,UAA4B;Q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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,QAAQ,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","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"]}
|