notations 0.0.46 → 0.0.47
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.
|
@@ -235,15 +235,18 @@ var NotationView = (function () {
|
|
|
235
235
|
};
|
|
236
236
|
NotationView.prototype.renderBlock = function (raw) {
|
|
237
237
|
var _a = __read(this.addNewRow(raw.uuid + "", "rawBlock", false), 2), td2 = _a[1];
|
|
238
|
-
var div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
239
238
|
if (raw.contentType == "metadata") {
|
|
240
239
|
var meta = this.notation.metadata.get(raw.content);
|
|
241
240
|
if (meta) {
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
if (meta.key.toLowerCase().indexOf(":") < 0) {
|
|
242
|
+
var div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
243
|
+
var html = "<span class = \"".concat(meta.key.toLowerCase(), "\"><strong>").concat(meta.key, "</strong>: ").concat(meta.value, "</span>");
|
|
244
|
+
div.innerHTML = html;
|
|
245
|
+
}
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
else {
|
|
249
|
+
var div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
247
250
|
div.innerHTML = this.markdownParser(raw.content.trim());
|
|
248
251
|
}
|
|
249
252
|
this.currentSVGElement = null;
|
|
@@ -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,CA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AQ,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAG3C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,QAAQ,CAAC,UAAU,CAAC,kBAAkB,CAAC,IAAI,EAAE,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;SAC9E;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;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,IAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QACvD,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;gBACR,IAAM,IAAI,GAAG,0BAAkB,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,wBAAa,IAAI,CAAC,GAAG,wBAAc,IAAI,CAAC,KAAK,YAAS,CAAC;gBAC5G,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;aACtB;SACF;aAAM;YACL,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,AAtLD,IAsLC;AAtLY,oCAAY","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 const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n } else {\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,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;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,IAAU;QACpB,IAAI,IAAI,GAAG,I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ACjB,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;AA1LY,oCAAY","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"]}
|
|
@@ -209,15 +209,18 @@ var NotationView = (function () {
|
|
|
209
209
|
};
|
|
210
210
|
NotationView.prototype.renderBlock = function (raw) {
|
|
211
211
|
var _a = __read(this.addNewRow(raw.uuid + "", "rawBlock", false), 2), td2 = _a[1];
|
|
212
|
-
var div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
213
212
|
if (raw.contentType == "metadata") {
|
|
214
213
|
var meta = this.notation.metadata.get(raw.content);
|
|
215
214
|
if (meta) {
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
if (meta.key.toLowerCase().indexOf(":") < 0) {
|
|
216
|
+
var div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
217
|
+
var html = "<span class = \"".concat(meta.key.toLowerCase(), "\"><strong>").concat(meta.key, "</strong>: ").concat(meta.value, "</span>");
|
|
218
|
+
div.innerHTML = html;
|
|
219
|
+
}
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
else {
|
|
223
|
+
var div = td2.appendChild(TSU.DOM.createNode("div"));
|
|
221
224
|
div.innerHTML = this.markdownParser(raw.content.trim());
|
|
222
225
|
}
|
|
223
226
|
this.currentSVGElement = null;
|
|
@@ -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,IAAU;QACpB,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;QACjD,IAAI,IAAI,IAAI,IAAI,EAAE;YAEhB,IAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAClC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACrC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qCAAc,GAAd;QACE,IAAI,CAAC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gBACR,IAAM,IAAI,GAAG,0BAAkB,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,wBAAa,IAAI,CAAC,GAAG,wBAAc,IAAI,CAAC,KAAK,YAAS,CAAC;gBAC5G,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;aACtB;SACF;aAAM;YACL,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,AAtLD,IAsLC","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 const div = td2.appendChild(TSU.DOM.createNode(\"div\"));\n if (raw.contentType == \"metadata\") {\n // we have a metadata block\n const meta = this.notation.metadata.get(raw.content);\n if (meta) {\n const html = `<span class = \"${meta.key.toLowerCase()}\"><strong>${meta.key}</strong>: ${meta.value}</span>`;\n div.innerHTML = html;\n }\n } else {\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,iBAAi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AS,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"]}
|
package/package.json
CHANGED