notations 0.0.33 → 0.0.34
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/carnatic/atomviews.js +0 -2
- package/lib/cjs/carnatic/atomviews.js.map +1 -1
- package/lib/cjs/shapes.d.ts +4 -0
- package/lib/cjs/shapes.js +33 -5
- package/lib/cjs/shapes.js.map +1 -1
- package/lib/esm/carnatic/atomviews.js +0 -2
- package/lib/esm/carnatic/atomviews.js.map +1 -1
- package/lib/esm/shapes.d.ts +4 -0
- package/lib/esm/shapes.js +33 -5
- package/lib/esm/shapes.js.map +1 -1
- package/package.json +1 -1
|
@@ -82,8 +82,6 @@ var LeafAtomView = (function (_super) {
|
|
|
82
82
|
this.bottomSlot.reduce(function (a, b) { return a + b.minSize.height; }, 0);
|
|
83
83
|
out.width += totalWidth;
|
|
84
84
|
out.height += totalHeight;
|
|
85
|
-
if (this.postSpacingSpan)
|
|
86
|
-
out.width += this.postSpacingSpan.getBBox().width;
|
|
87
85
|
return out;
|
|
88
86
|
};
|
|
89
87
|
LeafAtomView.prototype.updateBounds = function (x, y, w, h) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomviews.js","sourceRoot":"","sources":["../../../src/carnatic/atomviews.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,gCAAmE;AACnE,oCAAiE;AAEjE,iDAYyB;AACzB,qCAAuC;AAEvC;IAA2C,gCAAQ;IAAnD;QAAA,qEA+NC;QA9NC,cAAQ,GAAmB,EAAE,CAAC;QAC9B,aAAO,GAAmB,EAAE,CAAC;QAC7B,eAAS,GAAmB,EAAE,CAAC;QAC/B,gBAAU,GAAmB,EAAE,CAAC;;IA2NlC,CAAC;IAjNW,qCAAc,GAAxB;QACE,IAAM,GAAG,gBAAQ,CAAC,IAAI,CAAC,SAAS,IAAI,IAA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AAI,CAAC,KAAK,CAAC,GAAG,GAAG;aAC9D,CAAC,CAAC;SACJ;IACH,CAAC;IAES,kCAAe,GAAzB;QACE,iBAAM,eAAe,WAAE,CAAC;QACxB,IAAI,IAAI,CAAC,YAAY,EAAE;YACrB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACvD;IACH,CAAC;IAED,qCAAkB,GAAlB;QACE,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAEvB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,+BAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;SACpD;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,+BAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;SACvD;QACD,iBAAM,kBAAkB,WAAE,CAAC;IAC7B,CAAC;IAED,sBAAI,0BAAI;aAAR;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAY,CAAC;QACpC,CAAC;;;OAAA;IACH,eAAC;AAAD,CAAC,AAhDD,CAAuB,YAAY,GAgDlC;AAED;IAA2B,gCAAY;IAAvC;;IAQA,CAAC;IAPC,sBAAI,oCAAU;aAAd;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC7B,CAAC;;;OAAA;IAED,sBAAI,kCAAQ;aAAZ;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAgB,CAAC;QACxC,CAAC;;;OAAA;IACH,mBAAC;AAAD,CAAC,AARD,CAA2B,YAAY,GAQtC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Literal, AtomType, Note, Space, Syllable } from \"../core\";\nimport { AtomView, Embelishment, ElementShape } from \"../shapes\";\nimport { FlatAtom } from \"../iterators\";\nimport {\n OctaveIndicator,\n Kampitham,\n Nokku,\n Spuritham,\n Prathyagatham,\n Orikkai,\n Odukkal,\n Raavi,\n Kandippu,\n Vaali,\n Jaaru,\n} from \"./embelishments\";\nimport { GamakaType } from \"./gamakas\";\n\nexport abstract class LeafAtomView extends AtomView {\n leftSlot: Embelishment[] = [];\n topSlot: Embelishment[] = [];\n rightSlot: Embelishment[] = [];\n bottomSlot: Embelishment[] = [];\n\n // Spaces required before and after to accomodate for left and right slots\n protected postSpacingSpan: SVGTSpanElement;\n // Sometimes this.element may not be the root element if we need spacings\n // the rootElement is the top of the chain\n protected rootShape: ElementShape;\n\n abstract get glyphLabel(): string;\n\n protected refreshMinSize(): TSU.Geom.Size {\n const out = { ...(this.rootShape || this.glyph).minSize };\n const totalWidth =\n this.leftSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.rightSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.leftSlot.length + // Padding of 1\n this.rightSlot.length; // Padding of 1\n const totalHeight =\n this.topSlot.reduce((a, b) => a + b.minSize.height, 0) +\n this.bottomSlot.reduce((a, b) => a + b.minSize.height, 0);\n out.width += totalWidth;\n out.height += totalHeight;\n if (this.postSpacingSpan) out.width += this.postSpacingSpan.getBBox().width;\n return out;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, NaN, NaN];\n }\n\n refreshLayout(): void {\n // TODO - move this code out to refreshLayout?\n // set the glyphs Y first so we can layout others\n const x = this.x;\n const y = this.y;\n this.glyph.setBounds(null, y, null, null, true);\n\n // now layout leftSlots\n let currX = x;\n let currY = y;\n if (currX != null) {\n // place left embelishments\n for (const emb of this.leftSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now place the glyph\n const glyphRoot = this.rootShape || this.glyph;\n console.log(\"Glyph Root: \", glyphRoot);\n glyphRoot.x = currX;\n glyphRoot.refreshLayout();\n currX += glyphRoot.minSize.width;\n\n // And right embelishments\n for (const emb of this.rightSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now the spacing span\n // if (this.postSpacingSpan) { this.postSpacingSpan.setAttribute(\"x\", \"\" + x); }\n }\n\n // layout top and bottom if x or y has changed\n if (currX != null || currY != null) {\n const gminSize = this.glyph.minSize;\n\n // top embelishments\n const glyphX = this.glyph.x;\n const glyphY = this.glyph.y;\n currY = glyphY - 1;\n for (const emb of this.topSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY - bb.height, null, null, true);\n currY = emb.y;\n }\n\n // bottom embelishments\n currY = glyphY + gminSize.height + 2;\n for (const emb of this.bottomSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY, null, null, true);\n currY = emb.y + bb.height;\n }\n }\n }\n\n protected addEmbelishment(slot: Embelishment[], emb: Embelishment): void {\n slot.push(emb);\n this.addShape(emb);\n }\n\n /**\n * Orders embelishments and creates their views.\n */\n orderEmbelishments(): void {\n const atom = this.flatAtom.atom;\n if (atom.type != AtomType.SYLLABLE && atom.type != AtomType.NOTE) {\n return;\n }\n const lit = atom as Literal;\n if (lit.embelishments.length == 0) return;\n for (const emb of lit.embelishments) {\n switch (emb.type) {\n case GamakaType.Kampitham:\n this.addEmbelishment(this.topSlot, new Kampitham(this));\n break;\n case GamakaType.Nokku:\n this.addEmbelishment(this.topSlot, new Nokku(this));\n break;\n case GamakaType.Spuritham:\n this.addEmbelishment(this.topSlot, new Spuritham(this));\n break;\n case GamakaType.Prathyagatham:\n this.addEmbelishment(this.topSlot, new Prathyagatham(this));\n break;\n case GamakaType.Orikkai:\n this.addEmbelishment(this.topSlot, new Orikkai(this));\n break;\n case GamakaType.Odukkal:\n this.addEmbelishment(this.topSlot, new Odukkal(this));\n break;\n case GamakaType.Aahaatam_Raavi:\n this.addEmbelishment(this.topSlot, new Raavi(this));\n break;\n case GamakaType.Aahaatam_Kandippu:\n this.addEmbelishment(this.topSlot, new Kandippu(this));\n break;\n case GamakaType.Vaali:\n this.addEmbelishment(this.topSlot, new Vaali(this));\n break;\n case GamakaType.Jaaru_Eetra:\n case GamakaType.Jaaru_Irakka:\n this.addEmbelishment(this.leftSlot, new Jaaru(emb, this));\n break;\n }\n }\n }\n\n needsRootElement(): boolean {\n return this.rightSlot.length > 0 || this.flatAtom.atom.beforeRest;\n }\n\n createElements(parent: SVGGraphicsElement): void {\n // Create the glyph element first before anything\n // this allows embelishments to get early access to this element\n if (this.needsRootElement()) {\n this.createGlyphRoot(parent);\n }\n this.createGlyphElement(this.rootShape?.element || parent);\n\n // Order embelishments (without creating any views)\n this.orderEmbelishments();\n if (this.needsRootElement()) {\n // create as 2 sub span elements\n if (!this.rootShape) {\n this.createGlyphRoot(parent);\n // move the element into the parent\n this.moveGlyphToRoot();\n }\n\n this.createPostSpacingElement();\n }\n }\n\n protected createGlyphRoot(parent: SVGGraphicsElement): void {\n this.rootShape = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"atomViewRoot\" + this.flatAtom.atom.uuid,\n },\n }),\n );\n }\n\n protected createPostSpacingElement(): void {\n this.postSpacingSpan = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"postSpacing\" + this.flatAtom.atom.uuid,\n },\n text: this.flatAtom.atom.beforeRest ? \" - \" : \" \",\n });\n }\n\n protected moveGlyphToRoot(): void {\n this.rootShape.element.appendChild(this.glyph.element);\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n const atom = this.flatAtom.atom;\n this.glyph = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: atom.uuid,\n id: \"atom\" + atom.uuid,\n },\n text: this.glyphLabel, // + (note.beforeRest ? \" - \" : \" \"),\n }),\n );\n }\n}\n\nexport function createAtomView(parent: SVGGraphicsElement, atom: FlatAtom): AtomView {\n let out: AtomView;\n switch (atom.atom.type) {\n // Dealing with leaf atoms\n case AtomType.SPACE:\n out = new SpaceView(atom);\n break;\n case AtomType.SYLLABLE:\n out = new SyllableView(atom);\n break;\n case AtomType.NOTE:\n out = new NoteView(atom);\n break;\n default:\n // We should never get a group as we are iterating\n // at leaf atom levels\n throw new Error(\"Invalid atom type: \" + atom.atom.type);\n }\n out.createElements(parent);\n return out;\n}\n\nclass SpaceView extends LeafAtomView {\n get glyphLabel(): string {\n return this.space.isSilent ? \" \" : \",\";\n }\n\n get space(): Space {\n return this.flatAtom.atom as Space;\n }\n}\n\nclass NoteView extends LeafAtomView {\n protected shiftElement: SVGTSpanElement;\n get glyphLabel(): string {\n return this.note.value;\n }\n\n needsRootElement(): boolean {\n return this.note.shift == true || this.note.shift != 0 || super.needsRootElement();\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n super.createGlyphElement(parent);\n if (this.note.shift == true || this.note.shift != 0) {\n this.shiftElement = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.note.uuid,\n id: \"noteShift\" + this.note.uuid,\n \"baseline-shift\": \"sub\",\n },\n text: (this.note.shift == true ? \"*\" : this.note.shift) + \" \",\n });\n }\n }\n\n protected moveGlyphToRoot(): void {\n super.moveGlyphToRoot();\n if (this.shiftElement) {\n this.rootShape.element.appendChild(this.shiftElement);\n }\n }\n\n orderEmbelishments(): void {\n const note = this.note;\n // create the embelishments if needed\n if (note.octave > 0) {\n this.topSlot.push(new OctaveIndicator(this, note));\n } else if (this.note.octave < 0) {\n this.bottomSlot.push(new OctaveIndicator(this, note));\n }\n super.orderEmbelishments();\n }\n\n get note(): Note {\n return this.flatAtom.atom as Note;\n }\n}\n\nclass SyllableView extends LeafAtomView {\n get glyphLabel(): string {\n return this.syllable.value;\n }\n\n get syllable(): Syllable {\n return this.flatAtom.atom as Syllable;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"atomviews.js","sourceRoot":"","sources":["../../../src/carnatic/atomviews.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AACvC,gCAAmE;AACnE,oCAAiE;AAEjE,iDAYyB;AACzB,qCAAuC;AAEvC;IAA2C,gCAAQ;IAAnD;QAAA,qEA+NC;QA9NC,cAAQ,GAAmB,EAAE,CAAC;QAC9B,aAAO,GAAmB,EAAE,CAAC;QAC7B,eAAS,GAAmB,EAAE,CAAC;QAC/B,gBAAU,GAAmB,EAAE,CAAC;;IA2NlC,CAAC;IAjNW,qCAAc,GAAxB;QACE,IAAM,GAAG,gBAAQ,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAE,CAAC;QAC1D,IAAM,UAAU,GACd,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAnB,CAAmB,EAAE,CAAC,CAAC;YACtD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAnB,CAAmB,EAAE,CAAC,CAAC;YACvD,IAAI,CAAC,QAAQ,CAAC,MAAM;YACpB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;QACxB,IAAM,WAAW,GACf,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,C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C;IAC7B,CAAC;IAED,sBAAI,0BAAI;aAAR;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAY,CAAC;QACpC,CAAC;;;OAAA;IACH,eAAC;AAAD,CAAC,AAhDD,CAAuB,YAAY,GAgDlC;AAED;IAA2B,gCAAY;IAAvC;;IAQA,CAAC;IAPC,sBAAI,oCAAU;aAAd;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC7B,CAAC;;;OAAA;IAED,sBAAI,kCAAQ;aAAZ;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAgB,CAAC;QACxC,CAAC;;;OAAA;IACH,mBAAC;AAAD,CAAC,AARD,CAA2B,YAAY,GAQtC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Literal, AtomType, Note, Space, Syllable } from \"../core\";\nimport { AtomView, Embelishment, ElementShape } from \"../shapes\";\nimport { FlatAtom } from \"../iterators\";\nimport {\n OctaveIndicator,\n Kampitham,\n Nokku,\n Spuritham,\n Prathyagatham,\n Orikkai,\n Odukkal,\n Raavi,\n Kandippu,\n Vaali,\n Jaaru,\n} from \"./embelishments\";\nimport { GamakaType } from \"./gamakas\";\n\nexport abstract class LeafAtomView extends AtomView {\n leftSlot: Embelishment[] = [];\n topSlot: Embelishment[] = [];\n rightSlot: Embelishment[] = [];\n bottomSlot: Embelishment[] = [];\n\n // Spaces required before and after to accomodate for left and right slots\n protected postSpacingSpan: SVGTSpanElement;\n // Sometimes this.element may not be the root element if we need spacings\n // the rootElement is the top of the chain\n protected rootShape: ElementShape;\n\n abstract get glyphLabel(): string;\n\n protected refreshMinSize(): TSU.Geom.Size {\n const out = { ...(this.rootShape || this.glyph).minSize };\n const totalWidth =\n this.leftSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.rightSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.leftSlot.length + // Padding of 1\n this.rightSlot.length; // Padding of 1\n const totalHeight =\n this.topSlot.reduce((a, b) => a + b.minSize.height, 0) +\n this.bottomSlot.reduce((a, b) => a + b.minSize.height, 0);\n out.width += totalWidth;\n out.height += totalHeight;\n // if (this.postSpacingSpan) out.width += this.postSpacingSpan.getBBox().width;\n return out;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, NaN, NaN];\n }\n\n refreshLayout(): void {\n // TODO - move this code out to refreshLayout?\n // set the glyphs Y first so we can layout others\n const x = this.x;\n const y = this.y;\n this.glyph.setBounds(null, y, null, null, true);\n\n // now layout leftSlots\n let currX = x;\n let currY = y;\n if (currX != null) {\n // place left embelishments\n for (const emb of this.leftSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now place the glyph\n const glyphRoot = this.rootShape || this.glyph;\n console.log(\"Glyph Root: \", glyphRoot);\n glyphRoot.x = currX;\n glyphRoot.refreshLayout();\n currX += glyphRoot.minSize.width;\n\n // And right embelishments\n for (const emb of this.rightSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now the spacing span\n // if (this.postSpacingSpan) { this.postSpacingSpan.setAttribute(\"x\", \"\" + x); }\n }\n\n // layout top and bottom if x or y has changed\n if (currX != null || currY != null) {\n const gminSize = this.glyph.minSize;\n\n // top embelishments\n const glyphX = this.glyph.x;\n const glyphY = this.glyph.y;\n currY = glyphY - 1;\n for (const emb of this.topSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY - bb.height, null, null, true);\n currY = emb.y;\n }\n\n // bottom embelishments\n currY = glyphY + gminSize.height + 2;\n for (const emb of this.bottomSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY, null, null, true);\n currY = emb.y + bb.height;\n }\n }\n }\n\n protected addEmbelishment(slot: Embelishment[], emb: Embelishment): void {\n slot.push(emb);\n this.addShape(emb);\n }\n\n /**\n * Orders embelishments and creates their views.\n */\n orderEmbelishments(): void {\n const atom = this.flatAtom.atom;\n if (atom.type != AtomType.SYLLABLE && atom.type != AtomType.NOTE) {\n return;\n }\n const lit = atom as Literal;\n if (lit.embelishments.length == 0) return;\n for (const emb of lit.embelishments) {\n switch (emb.type) {\n case GamakaType.Kampitham:\n this.addEmbelishment(this.topSlot, new Kampitham(this));\n break;\n case GamakaType.Nokku:\n this.addEmbelishment(this.topSlot, new Nokku(this));\n break;\n case GamakaType.Spuritham:\n this.addEmbelishment(this.topSlot, new Spuritham(this));\n break;\n case GamakaType.Prathyagatham:\n this.addEmbelishment(this.topSlot, new Prathyagatham(this));\n break;\n case GamakaType.Orikkai:\n this.addEmbelishment(this.topSlot, new Orikkai(this));\n break;\n case GamakaType.Odukkal:\n this.addEmbelishment(this.topSlot, new Odukkal(this));\n break;\n case GamakaType.Aahaatam_Raavi:\n this.addEmbelishment(this.topSlot, new Raavi(this));\n break;\n case GamakaType.Aahaatam_Kandippu:\n this.addEmbelishment(this.topSlot, new Kandippu(this));\n break;\n case GamakaType.Vaali:\n this.addEmbelishment(this.topSlot, new Vaali(this));\n break;\n case GamakaType.Jaaru_Eetra:\n case GamakaType.Jaaru_Irakka:\n this.addEmbelishment(this.leftSlot, new Jaaru(emb, this));\n break;\n }\n }\n }\n\n needsRootElement(): boolean {\n return this.rightSlot.length > 0 || this.flatAtom.atom.beforeRest;\n }\n\n createElements(parent: SVGGraphicsElement): void {\n // Create the glyph element first before anything\n // this allows embelishments to get early access to this element\n if (this.needsRootElement()) {\n this.createGlyphRoot(parent);\n }\n this.createGlyphElement(this.rootShape?.element || parent);\n\n // Order embelishments (without creating any views)\n this.orderEmbelishments();\n if (this.needsRootElement()) {\n // create as 2 sub span elements\n if (!this.rootShape) {\n this.createGlyphRoot(parent);\n // move the element into the parent\n this.moveGlyphToRoot();\n }\n\n this.createPostSpacingElement();\n }\n }\n\n protected createGlyphRoot(parent: SVGGraphicsElement): void {\n this.rootShape = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"atomViewRoot\" + this.flatAtom.atom.uuid,\n },\n }),\n );\n }\n\n protected createPostSpacingElement(): void {\n this.postSpacingSpan = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"postSpacing\" + this.flatAtom.atom.uuid,\n },\n text: this.flatAtom.atom.beforeRest ? \" - \" : \" \",\n });\n }\n\n protected moveGlyphToRoot(): void {\n this.rootShape.element.appendChild(this.glyph.element);\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n const atom = this.flatAtom.atom;\n this.glyph = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: atom.uuid,\n id: \"atom\" + atom.uuid,\n },\n text: this.glyphLabel, // + (note.beforeRest ? \" - \" : \" \"),\n }),\n );\n }\n}\n\nexport function createAtomView(parent: SVGGraphicsElement, atom: FlatAtom): AtomView {\n let out: AtomView;\n switch (atom.atom.type) {\n // Dealing with leaf atoms\n case AtomType.SPACE:\n out = new SpaceView(atom);\n break;\n case AtomType.SYLLABLE:\n out = new SyllableView(atom);\n break;\n case AtomType.NOTE:\n out = new NoteView(atom);\n break;\n default:\n // We should never get a group as we are iterating\n // at leaf atom levels\n throw new Error(\"Invalid atom type: \" + atom.atom.type);\n }\n out.createElements(parent);\n return out;\n}\n\nclass SpaceView extends LeafAtomView {\n get glyphLabel(): string {\n return this.space.isSilent ? \" \" : \",\";\n }\n\n get space(): Space {\n return this.flatAtom.atom as Space;\n }\n}\n\nclass NoteView extends LeafAtomView {\n protected shiftElement: SVGTSpanElement;\n get glyphLabel(): string {\n return this.note.value;\n }\n\n needsRootElement(): boolean {\n return this.note.shift == true || this.note.shift != 0 || super.needsRootElement();\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n super.createGlyphElement(parent);\n if (this.note.shift == true || this.note.shift != 0) {\n this.shiftElement = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.note.uuid,\n id: \"noteShift\" + this.note.uuid,\n \"baseline-shift\": \"sub\",\n },\n text: (this.note.shift == true ? \"*\" : this.note.shift) + \" \",\n });\n }\n }\n\n protected moveGlyphToRoot(): void {\n super.moveGlyphToRoot();\n if (this.shiftElement) {\n this.rootShape.element.appendChild(this.shiftElement);\n }\n }\n\n orderEmbelishments(): void {\n const note = this.note;\n // create the embelishments if needed\n if (note.octave > 0) {\n this.topSlot.push(new OctaveIndicator(this, note));\n } else if (this.note.octave < 0) {\n this.bottomSlot.push(new OctaveIndicator(this, note));\n }\n super.orderEmbelishments();\n }\n\n get note(): Note {\n return this.flatAtom.atom as Note;\n }\n}\n\nclass SyllableView extends LeafAtomView {\n get glyphLabel(): string {\n return this.syllable.value;\n }\n\n get syllable(): Syllable {\n return this.flatAtom.atom as Syllable;\n }\n}\n"]}
|
package/lib/cjs/shapes.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export declare abstract class Shape {
|
|
|
18
18
|
protected abstract updateBounds(x: null | number, y: null | number, w: null | number, h: null | number): [number | null, number | null, number | null, number | null];
|
|
19
19
|
resetMinSize(): void;
|
|
20
20
|
setBounds(x: number | null, y: number | null, w: number | null, h: number | null, applyLayout?: boolean): [number | null, number | null, number | null, number | null];
|
|
21
|
+
get hasX(): boolean;
|
|
22
|
+
get hasY(): boolean;
|
|
23
|
+
get hasWidth(): boolean;
|
|
24
|
+
get hasHeight(): boolean;
|
|
21
25
|
get x(): number;
|
|
22
26
|
set x(x: number | null);
|
|
23
27
|
get y(): number;
|
package/lib/cjs/shapes.js
CHANGED
|
@@ -169,11 +169,37 @@ var Shape = (function () {
|
|
|
169
169
|
this.refreshLayout();
|
|
170
170
|
return [nx, ny, nw, nh];
|
|
171
171
|
};
|
|
172
|
+
Object.defineProperty(Shape.prototype, "hasX", {
|
|
173
|
+
get: function () {
|
|
174
|
+
return this._x != null && !isNaN(this._x);
|
|
175
|
+
},
|
|
176
|
+
enumerable: false,
|
|
177
|
+
configurable: true
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(Shape.prototype, "hasY", {
|
|
180
|
+
get: function () {
|
|
181
|
+
return this._y != null && !isNaN(this._y);
|
|
182
|
+
},
|
|
183
|
+
enumerable: false,
|
|
184
|
+
configurable: true
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(Shape.prototype, "hasWidth", {
|
|
187
|
+
get: function () {
|
|
188
|
+
return this._width != null && !isNaN(this._width);
|
|
189
|
+
},
|
|
190
|
+
enumerable: false,
|
|
191
|
+
configurable: true
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(Shape.prototype, "hasHeight", {
|
|
194
|
+
get: function () {
|
|
195
|
+
return this._height != null && !isNaN(this._height);
|
|
196
|
+
},
|
|
197
|
+
enumerable: false,
|
|
198
|
+
configurable: true
|
|
199
|
+
});
|
|
172
200
|
Object.defineProperty(Shape.prototype, "x", {
|
|
173
201
|
get: function () {
|
|
174
|
-
|
|
175
|
-
return this._x;
|
|
176
|
-
return 0;
|
|
202
|
+
return this._x || 0;
|
|
177
203
|
},
|
|
178
204
|
set: function (x) {
|
|
179
205
|
this.setBounds(x == null ? NaN : x, null, null, null);
|
|
@@ -245,8 +271,10 @@ var ElementShape = (function (_super) {
|
|
|
245
271
|
return [x, y, w, h];
|
|
246
272
|
};
|
|
247
273
|
ElementShape.prototype.refreshLayout = function () {
|
|
248
|
-
|
|
249
|
-
|
|
274
|
+
if (this.hasX)
|
|
275
|
+
this.element.setAttribute("x", "" + this._x);
|
|
276
|
+
if (this.hasY)
|
|
277
|
+
this.element.setAttribute("y", "" + this._y);
|
|
250
278
|
};
|
|
251
279
|
return ElementShape;
|
|
252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;QAC5B,CAAC;;;OAAA;IAED,0BAAO,GAAP;QACE,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAA0C,CAAC;QAC7E,OAAO,QAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,OAAO,IAAI,QAAQ,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE;YAC9E,QAAQ,GAAG,QAAQ,CAAC,aAA0C,CAAC;SAChE;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,eAAC;AAAD,CAAC,AAlDD,CAAuC,KAAK,GAkD3C;AAlDqB,4BAAQ","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { FlatAtom } from \"./iterators\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the top left corner\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n // protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._minSize;\n }\n\n /**\n * Add a child shape.\n */\n addShape(child: Shape, index = -1): void {\n // Orphan it first\n child.removeFromParent();\n\n // Then add it\n if (index >= 0) {\n this.children.splice(index, 0, child);\n } else {\n this.children.push(child);\n }\n child.parentShape = this;\n }\n\n /**\n * Remove a child from our children list if it exists.\n */\n removeShape(child: Shape): void {\n const index = this.children.indexOf(child);\n if (index >= 0) {\n this.children.splice(index, 1);\n }\n child.parentShape = null;\n }\n\n /**\n * Remove ourselves from our parent.\n */\n removeFromParent(): void {\n if (this.parentShape) {\n this.parentShape.removeShape(this);\n }\n }\n\n /**\n * Returns the unioned bounding box of all child shapes.\n */\n /*\n protected childrenBBox(): TSU.Geom.Rect | null {\n let bbox: TSU.Geom.Rect | null = null;\n for (let i = this.children.length - 1; i >= 0; i--) {\n if (bbox == null) bbox = TSU.Geom.Rect.from(this.children[i].bbox);\n else bbox = bbox.union(this.children[i].bbox);\n }\n return bbox;\n }\n */\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n // protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n resetMinSize(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n }\n /*\n resetBBox(): void {\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n */\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n /**\n * Gets the bounding box of this shape in the coordinate system within\n * the parent.\n */\n /*\n protected get bbox2(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox().union(this.childrenBBox());\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._bbox;\n }\n */\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n if (this._x != null) return this._x;\n return 0; // this.bbox.x;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape extends Shape {\n constructor(public readonly element: SVGGraphicsElement) {\n super();\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n this.element.setAttribute(\"x\", \"\" + this.x);\n this.element.setAttribute(\"y\", \"\" + this.y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n glyph: ElementShape;\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n constructor(public flatAtom: FlatAtom) {\n super();\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n abstract refreshLayout(): void;\n\n /**\n * By default the glyph's bbox is our bbox.\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return this.glyph.minSize;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return this.glyph.setBounds(x, y, w, h);\n }\n\n get viewId(): number {\n return this.flatAtom.uuid;\n }\n\n embRoot(): SVGGraphicsElement {\n let rootElem = this.glyph.element.parentElement as any as SVGGraphicsElement;\n while (rootElem && (rootElem.tagName == \"tspan\" || rootElem.tagName == \"text\")) {\n rootElem = rootElem.parentElement as any as SVGGraphicsElement;\n }\n return rootElem;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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S,GAAG,CAAC,CAAC;;IAYd,CAAC;IAWS,iCAAc,GAAxB;QACE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;IAES,+BAAY,GAAtB,UACE,CAAgB,EAChB,CAAgB,EAChB,CAAgB,EAChB,CAAgB;QAEhB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,sBAAI,4BAAM;aAAV;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC5B,CAAC;;;OAAA;IAED,0BAAO,GAAP;QACE,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAA0C,CAAC;QAC7E,OAAO,QAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,OAAO,IAAI,QAAQ,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE;YAC9E,QAAQ,GAAG,QAAQ,CAAC,aAA0C,CAAC;SAChE;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,eAAC;AAAD,CAAC,AAlDD,CAAuC,KAAK,GAkD3C;AAlDqB,4BAAQ","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { FlatAtom } from \"./iterators\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the top left corner\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n // protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._minSize;\n }\n\n /**\n * Add a child shape.\n */\n addShape(child: Shape, index = -1): void {\n // Orphan it first\n child.removeFromParent();\n\n // Then add it\n if (index >= 0) {\n this.children.splice(index, 0, child);\n } else {\n this.children.push(child);\n }\n child.parentShape = this;\n }\n\n /**\n * Remove a child from our children list if it exists.\n */\n removeShape(child: Shape): void {\n const index = this.children.indexOf(child);\n if (index >= 0) {\n this.children.splice(index, 1);\n }\n child.parentShape = null;\n }\n\n /**\n * Remove ourselves from our parent.\n */\n removeFromParent(): void {\n if (this.parentShape) {\n this.parentShape.removeShape(this);\n }\n }\n\n /**\n * Returns the unioned bounding box of all child shapes.\n */\n /*\n protected childrenBBox(): TSU.Geom.Rect | null {\n let bbox: TSU.Geom.Rect | null = null;\n for (let i = this.children.length - 1; i >= 0; i--) {\n if (bbox == null) bbox = TSU.Geom.Rect.from(this.children[i].bbox);\n else bbox = bbox.union(this.children[i].bbox);\n }\n return bbox;\n }\n */\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n // protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n resetMinSize(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n }\n /*\n resetBBox(): void {\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n */\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n /**\n * Gets the bounding box of this shape in the coordinate system within\n * the parent.\n */\n /*\n protected get bbox2(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox().union(this.childrenBBox());\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._bbox;\n }\n */\n\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape extends Shape {\n constructor(public readonly element: SVGGraphicsElement) {\n super();\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n glyph: ElementShape;\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n constructor(public flatAtom: FlatAtom) {\n super();\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n abstract refreshLayout(): void;\n\n /**\n * By default the glyph's bbox is our bbox.\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return this.glyph.minSize;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return this.glyph.setBounds(x, y, w, h);\n }\n\n get viewId(): number {\n return this.flatAtom.uuid;\n }\n\n embRoot(): SVGGraphicsElement {\n let rootElem = this.glyph.element.parentElement as any as SVGGraphicsElement;\n while (rootElem && (rootElem.tagName == \"tspan\" || rootElem.tagName == \"text\")) {\n rootElem = rootElem.parentElement as any as SVGGraphicsElement;\n }\n return rootElem;\n }\n}\n"]}
|
|
@@ -60,8 +60,6 @@ var LeafAtomView = (function (_super) {
|
|
|
60
60
|
this.bottomSlot.reduce(function (a, b) { return a + b.minSize.height; }, 0);
|
|
61
61
|
out.width += totalWidth;
|
|
62
62
|
out.height += totalHeight;
|
|
63
|
-
if (this.postSpacingSpan)
|
|
64
|
-
out.width += this.postSpacingSpan.getBBox().width;
|
|
65
63
|
return out;
|
|
66
64
|
};
|
|
67
65
|
LeafAtomView.prototype.updateBounds = function (x, y, w, h) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomviews.js","sourceRoot":"","sources":["../../../src/carnatic/atomviews.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAW,QAAQ,EAAyB,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAgB,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EACL,eAAe,EACf,SAAS,EACT,KAAK,EACL,SAAS,EACT,aAAa,EACb,OAAO,EACP,OAAO,EACP,KAAK,EACL,QAAQ,EACR,KAAK,EACL,KAAK,GACN,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;I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,CAAC,IAAgB,CAAC;QACxC,CAAC;;;OAAA;IACH,mBAAC;AAAD,CAAC,AARD,CAA2B,YAAY,GAQtC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Literal, AtomType, Note, Space, Syllable } from \"../core\";\nimport { AtomView, Embelishment, ElementShape } from \"../shapes\";\nimport { FlatAtom } from \"../iterators\";\nimport {\n OctaveIndicator,\n Kampitham,\n Nokku,\n Spuritham,\n Prathyagatham,\n Orikkai,\n Odukkal,\n Raavi,\n Kandippu,\n Vaali,\n Jaaru,\n} from \"./embelishments\";\nimport { GamakaType } from \"./gamakas\";\n\nexport abstract class LeafAtomView extends AtomView {\n leftSlot: Embelishment[] = [];\n topSlot: Embelishment[] = [];\n rightSlot: Embelishment[] = [];\n bottomSlot: Embelishment[] = [];\n\n // Spaces required before and after to accomodate for left and right slots\n protected postSpacingSpan: SVGTSpanElement;\n // Sometimes this.element may not be the root element if we need spacings\n // the rootElement is the top of the chain\n protected rootShape: ElementShape;\n\n abstract get glyphLabel(): string;\n\n protected refreshMinSize(): TSU.Geom.Size {\n const out = { ...(this.rootShape || this.glyph).minSize };\n const totalWidth =\n this.leftSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.rightSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.leftSlot.length + // Padding of 1\n this.rightSlot.length; // Padding of 1\n const totalHeight =\n this.topSlot.reduce((a, b) => a + b.minSize.height, 0) +\n this.bottomSlot.reduce((a, b) => a + b.minSize.height, 0);\n out.width += totalWidth;\n out.height += totalHeight;\n if (this.postSpacingSpan) out.width += this.postSpacingSpan.getBBox().width;\n return out;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, NaN, NaN];\n }\n\n refreshLayout(): void {\n // TODO - move this code out to refreshLayout?\n // set the glyphs Y first so we can layout others\n const x = this.x;\n const y = this.y;\n this.glyph.setBounds(null, y, null, null, true);\n\n // now layout leftSlots\n let currX = x;\n let currY = y;\n if (currX != null) {\n // place left embelishments\n for (const emb of this.leftSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now place the glyph\n const glyphRoot = this.rootShape || this.glyph;\n console.log(\"Glyph Root: \", glyphRoot);\n glyphRoot.x = currX;\n glyphRoot.refreshLayout();\n currX += glyphRoot.minSize.width;\n\n // And right embelishments\n for (const emb of this.rightSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now the spacing span\n // if (this.postSpacingSpan) { this.postSpacingSpan.setAttribute(\"x\", \"\" + x); }\n }\n\n // layout top and bottom if x or y has changed\n if (currX != null || currY != null) {\n const gminSize = this.glyph.minSize;\n\n // top embelishments\n const glyphX = this.glyph.x;\n const glyphY = this.glyph.y;\n currY = glyphY - 1;\n for (const emb of this.topSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY - bb.height, null, null, true);\n currY = emb.y;\n }\n\n // bottom embelishments\n currY = glyphY + gminSize.height + 2;\n for (const emb of this.bottomSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY, null, null, true);\n currY = emb.y + bb.height;\n }\n }\n }\n\n protected addEmbelishment(slot: Embelishment[], emb: Embelishment): void {\n slot.push(emb);\n this.addShape(emb);\n }\n\n /**\n * Orders embelishments and creates their views.\n */\n orderEmbelishments(): void {\n const atom = this.flatAtom.atom;\n if (atom.type != AtomType.SYLLABLE && atom.type != AtomType.NOTE) {\n return;\n }\n const lit = atom as Literal;\n if (lit.embelishments.length == 0) return;\n for (const emb of lit.embelishments) {\n switch (emb.type) {\n case GamakaType.Kampitham:\n this.addEmbelishment(this.topSlot, new Kampitham(this));\n break;\n case GamakaType.Nokku:\n this.addEmbelishment(this.topSlot, new Nokku(this));\n break;\n case GamakaType.Spuritham:\n this.addEmbelishment(this.topSlot, new Spuritham(this));\n break;\n case GamakaType.Prathyagatham:\n this.addEmbelishment(this.topSlot, new Prathyagatham(this));\n break;\n case GamakaType.Orikkai:\n this.addEmbelishment(this.topSlot, new Orikkai(this));\n break;\n case GamakaType.Odukkal:\n this.addEmbelishment(this.topSlot, new Odukkal(this));\n break;\n case GamakaType.Aahaatam_Raavi:\n this.addEmbelishment(this.topSlot, new Raavi(this));\n break;\n case GamakaType.Aahaatam_Kandippu:\n this.addEmbelishment(this.topSlot, new Kandippu(this));\n break;\n case GamakaType.Vaali:\n this.addEmbelishment(this.topSlot, new Vaali(this));\n break;\n case GamakaType.Jaaru_Eetra:\n case GamakaType.Jaaru_Irakka:\n this.addEmbelishment(this.leftSlot, new Jaaru(emb, this));\n break;\n }\n }\n }\n\n needsRootElement(): boolean {\n return this.rightSlot.length > 0 || this.flatAtom.atom.beforeRest;\n }\n\n createElements(parent: SVGGraphicsElement): void {\n // Create the glyph element first before anything\n // this allows embelishments to get early access to this element\n if (this.needsRootElement()) {\n this.createGlyphRoot(parent);\n }\n this.createGlyphElement(this.rootShape?.element || parent);\n\n // Order embelishments (without creating any views)\n this.orderEmbelishments();\n if (this.needsRootElement()) {\n // create as 2 sub span elements\n if (!this.rootShape) {\n this.createGlyphRoot(parent);\n // move the element into the parent\n this.moveGlyphToRoot();\n }\n\n this.createPostSpacingElement();\n }\n }\n\n protected createGlyphRoot(parent: SVGGraphicsElement): void {\n this.rootShape = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"atomViewRoot\" + this.flatAtom.atom.uuid,\n },\n }),\n );\n }\n\n protected createPostSpacingElement(): void {\n this.postSpacingSpan = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"postSpacing\" + this.flatAtom.atom.uuid,\n },\n text: this.flatAtom.atom.beforeRest ? \" - \" : \" \",\n });\n }\n\n protected moveGlyphToRoot(): void {\n this.rootShape.element.appendChild(this.glyph.element);\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n const atom = this.flatAtom.atom;\n this.glyph = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: atom.uuid,\n id: \"atom\" + atom.uuid,\n },\n text: this.glyphLabel, // + (note.beforeRest ? \" - \" : \" \"),\n }),\n );\n }\n}\n\nexport function createAtomView(parent: SVGGraphicsElement, atom: FlatAtom): AtomView {\n let out: AtomView;\n switch (atom.atom.type) {\n // Dealing with leaf atoms\n case AtomType.SPACE:\n out = new SpaceView(atom);\n break;\n case AtomType.SYLLABLE:\n out = new SyllableView(atom);\n break;\n case AtomType.NOTE:\n out = new NoteView(atom);\n break;\n default:\n // We should never get a group as we are iterating\n // at leaf atom levels\n throw new Error(\"Invalid atom type: \" + atom.atom.type);\n }\n out.createElements(parent);\n return out;\n}\n\nclass SpaceView extends LeafAtomView {\n get glyphLabel(): string {\n return this.space.isSilent ? \" \" : \",\";\n }\n\n get space(): Space {\n return this.flatAtom.atom as Space;\n }\n}\n\nclass NoteView extends LeafAtomView {\n protected shiftElement: SVGTSpanElement;\n get glyphLabel(): string {\n return this.note.value;\n }\n\n needsRootElement(): boolean {\n return this.note.shift == true || this.note.shift != 0 || super.needsRootElement();\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n super.createGlyphElement(parent);\n if (this.note.shift == true || this.note.shift != 0) {\n this.shiftElement = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.note.uuid,\n id: \"noteShift\" + this.note.uuid,\n \"baseline-shift\": \"sub\",\n },\n text: (this.note.shift == true ? \"*\" : this.note.shift) + \" \",\n });\n }\n }\n\n protected moveGlyphToRoot(): void {\n super.moveGlyphToRoot();\n if (this.shiftElement) {\n this.rootShape.element.appendChild(this.shiftElement);\n }\n }\n\n orderEmbelishments(): void {\n const note = this.note;\n // create the embelishments if needed\n if (note.octave > 0) {\n this.topSlot.push(new OctaveIndicator(this, note));\n } else if (this.note.octave < 0) {\n this.bottomSlot.push(new OctaveIndicator(this, note));\n }\n super.orderEmbelishments();\n }\n\n get note(): Note {\n return this.flatAtom.atom as Note;\n }\n}\n\nclass SyllableView extends LeafAtomView {\n get glyphLabel(): string {\n return this.syllable.value;\n }\n\n get syllable(): Syllable {\n return this.flatAtom.atom as Syllable;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"atomviews.js","sourceRoot":"","sources":["../../../src/carnatic/atomviews.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAW,QAAQ,EAAyB,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAgB,YAAY,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EACL,eAAe,EACf,SAAS,EACT,KAAK,EACL,SAAS,EACT,aAAa,EACb,OAAO,EACP,OAAO,EACP,KAAK,EACL,QAAQ,EACR,KAAK,EACL,KAAK,GACN,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;IAA2C,gCAAQ;IAAnD;QAAA,qEA+NC;QA9NC,cAAQ,GAAmB,EAAE,CAAC;QAC9B,aAAO,GAAmB,EAAE,CAAC;QAC7B,eAAS,GAAmB,EAAE,CAAC;QAC/B,gBAAU,GAAmB,EAAE,CAAC;;IA2NlC,CAAC;IAjNW,qCAAc,GAAxB;QACE,IAAM,GAAG,gBAAQ,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAE,CAAC;QAC1D,IAAM,UAAU,GACd,IAAI,CAAC,QAAQ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AED,qCAAkB,GAAlB;QACE,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QAEvB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACnB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;SACpD;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;SACvD;QACD,iBAAM,kBAAkB,WAAE,CAAC;IAC7B,CAAC;IAED,sBAAI,0BAAI;aAAR;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAY,CAAC;QACpC,CAAC;;;OAAA;IACH,eAAC;AAAD,CAAC,AAhDD,CAAuB,YAAY,GAgDlC;AAED;IAA2B,gCAAY;IAAvC;;IAQA,CAAC;IAPC,sBAAI,oCAAU;aAAd;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC7B,CAAC;;;OAAA;IAED,sBAAI,kCAAQ;aAAZ;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAgB,CAAC;QACxC,CAAC;;;OAAA;IACH,mBAAC;AAAD,CAAC,AARD,CAA2B,YAAY,GAQtC","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { Literal, AtomType, Note, Space, Syllable } from \"../core\";\nimport { AtomView, Embelishment, ElementShape } from \"../shapes\";\nimport { FlatAtom } from \"../iterators\";\nimport {\n OctaveIndicator,\n Kampitham,\n Nokku,\n Spuritham,\n Prathyagatham,\n Orikkai,\n Odukkal,\n Raavi,\n Kandippu,\n Vaali,\n Jaaru,\n} from \"./embelishments\";\nimport { GamakaType } from \"./gamakas\";\n\nexport abstract class LeafAtomView extends AtomView {\n leftSlot: Embelishment[] = [];\n topSlot: Embelishment[] = [];\n rightSlot: Embelishment[] = [];\n bottomSlot: Embelishment[] = [];\n\n // Spaces required before and after to accomodate for left and right slots\n protected postSpacingSpan: SVGTSpanElement;\n // Sometimes this.element may not be the root element if we need spacings\n // the rootElement is the top of the chain\n protected rootShape: ElementShape;\n\n abstract get glyphLabel(): string;\n\n protected refreshMinSize(): TSU.Geom.Size {\n const out = { ...(this.rootShape || this.glyph).minSize };\n const totalWidth =\n this.leftSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.rightSlot.reduce((a, b) => a + b.minSize.width, 0) +\n this.leftSlot.length + // Padding of 1\n this.rightSlot.length; // Padding of 1\n const totalHeight =\n this.topSlot.reduce((a, b) => a + b.minSize.height, 0) +\n this.bottomSlot.reduce((a, b) => a + b.minSize.height, 0);\n out.width += totalWidth;\n out.height += totalHeight;\n // if (this.postSpacingSpan) out.width += this.postSpacingSpan.getBBox().width;\n return out;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, NaN, NaN];\n }\n\n refreshLayout(): void {\n // TODO - move this code out to refreshLayout?\n // set the glyphs Y first so we can layout others\n const x = this.x;\n const y = this.y;\n this.glyph.setBounds(null, y, null, null, true);\n\n // now layout leftSlots\n let currX = x;\n let currY = y;\n if (currX != null) {\n // place left embelishments\n for (const emb of this.leftSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now place the glyph\n const glyphRoot = this.rootShape || this.glyph;\n console.log(\"Glyph Root: \", glyphRoot);\n glyphRoot.x = currX;\n glyphRoot.refreshLayout();\n currX += glyphRoot.minSize.width;\n\n // And right embelishments\n for (const emb of this.rightSlot) {\n emb.x = currX;\n emb.refreshLayout();\n currX += emb.minSize.width + 1;\n }\n\n // now the spacing span\n // if (this.postSpacingSpan) { this.postSpacingSpan.setAttribute(\"x\", \"\" + x); }\n }\n\n // layout top and bottom if x or y has changed\n if (currX != null || currY != null) {\n const gminSize = this.glyph.minSize;\n\n // top embelishments\n const glyphX = this.glyph.x;\n const glyphY = this.glyph.y;\n currY = glyphY - 1;\n for (const emb of this.topSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY - bb.height, null, null, true);\n currY = emb.y;\n }\n\n // bottom embelishments\n currY = glyphY + gminSize.height + 2;\n for (const emb of this.bottomSlot) {\n const bb = emb.minSize;\n emb.setBounds(glyphX + (gminSize.width - bb.width) / 2, currY, null, null, true);\n currY = emb.y + bb.height;\n }\n }\n }\n\n protected addEmbelishment(slot: Embelishment[], emb: Embelishment): void {\n slot.push(emb);\n this.addShape(emb);\n }\n\n /**\n * Orders embelishments and creates their views.\n */\n orderEmbelishments(): void {\n const atom = this.flatAtom.atom;\n if (atom.type != AtomType.SYLLABLE && atom.type != AtomType.NOTE) {\n return;\n }\n const lit = atom as Literal;\n if (lit.embelishments.length == 0) return;\n for (const emb of lit.embelishments) {\n switch (emb.type) {\n case GamakaType.Kampitham:\n this.addEmbelishment(this.topSlot, new Kampitham(this));\n break;\n case GamakaType.Nokku:\n this.addEmbelishment(this.topSlot, new Nokku(this));\n break;\n case GamakaType.Spuritham:\n this.addEmbelishment(this.topSlot, new Spuritham(this));\n break;\n case GamakaType.Prathyagatham:\n this.addEmbelishment(this.topSlot, new Prathyagatham(this));\n break;\n case GamakaType.Orikkai:\n this.addEmbelishment(this.topSlot, new Orikkai(this));\n break;\n case GamakaType.Odukkal:\n this.addEmbelishment(this.topSlot, new Odukkal(this));\n break;\n case GamakaType.Aahaatam_Raavi:\n this.addEmbelishment(this.topSlot, new Raavi(this));\n break;\n case GamakaType.Aahaatam_Kandippu:\n this.addEmbelishment(this.topSlot, new Kandippu(this));\n break;\n case GamakaType.Vaali:\n this.addEmbelishment(this.topSlot, new Vaali(this));\n break;\n case GamakaType.Jaaru_Eetra:\n case GamakaType.Jaaru_Irakka:\n this.addEmbelishment(this.leftSlot, new Jaaru(emb, this));\n break;\n }\n }\n }\n\n needsRootElement(): boolean {\n return this.rightSlot.length > 0 || this.flatAtom.atom.beforeRest;\n }\n\n createElements(parent: SVGGraphicsElement): void {\n // Create the glyph element first before anything\n // this allows embelishments to get early access to this element\n if (this.needsRootElement()) {\n this.createGlyphRoot(parent);\n }\n this.createGlyphElement(this.rootShape?.element || parent);\n\n // Order embelishments (without creating any views)\n this.orderEmbelishments();\n if (this.needsRootElement()) {\n // create as 2 sub span elements\n if (!this.rootShape) {\n this.createGlyphRoot(parent);\n // move the element into the parent\n this.moveGlyphToRoot();\n }\n\n this.createPostSpacingElement();\n }\n }\n\n protected createGlyphRoot(parent: SVGGraphicsElement): void {\n this.rootShape = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"atomViewRoot\" + this.flatAtom.atom.uuid,\n },\n }),\n );\n }\n\n protected createPostSpacingElement(): void {\n this.postSpacingSpan = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.flatAtom.atom.uuid,\n id: \"postSpacing\" + this.flatAtom.atom.uuid,\n },\n text: this.flatAtom.atom.beforeRest ? \" - \" : \" \",\n });\n }\n\n protected moveGlyphToRoot(): void {\n this.rootShape.element.appendChild(this.glyph.element);\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n const atom = this.flatAtom.atom;\n this.glyph = new ElementShape(\n TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: parent,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: atom.uuid,\n id: \"atom\" + atom.uuid,\n },\n text: this.glyphLabel, // + (note.beforeRest ? \" - \" : \" \"),\n }),\n );\n }\n}\n\nexport function createAtomView(parent: SVGGraphicsElement, atom: FlatAtom): AtomView {\n let out: AtomView;\n switch (atom.atom.type) {\n // Dealing with leaf atoms\n case AtomType.SPACE:\n out = new SpaceView(atom);\n break;\n case AtomType.SYLLABLE:\n out = new SyllableView(atom);\n break;\n case AtomType.NOTE:\n out = new NoteView(atom);\n break;\n default:\n // We should never get a group as we are iterating\n // at leaf atom levels\n throw new Error(\"Invalid atom type: \" + atom.atom.type);\n }\n out.createElements(parent);\n return out;\n}\n\nclass SpaceView extends LeafAtomView {\n get glyphLabel(): string {\n return this.space.isSilent ? \" \" : \",\";\n }\n\n get space(): Space {\n return this.flatAtom.atom as Space;\n }\n}\n\nclass NoteView extends LeafAtomView {\n protected shiftElement: SVGTSpanElement;\n get glyphLabel(): string {\n return this.note.value;\n }\n\n needsRootElement(): boolean {\n return this.note.shift == true || this.note.shift != 0 || super.needsRootElement();\n }\n\n protected createGlyphElement(parent: SVGGraphicsElement): void {\n super.createGlyphElement(parent);\n if (this.note.shift == true || this.note.shift != 0) {\n this.shiftElement = TSU.DOM.createSVGNode(\"tspan\", {\n doc: document,\n parent: this.rootShape.element,\n attrs: {\n depth: this.flatAtom.depth || 0,\n atomid: this.note.uuid,\n id: \"noteShift\" + this.note.uuid,\n \"baseline-shift\": \"sub\",\n },\n text: (this.note.shift == true ? \"*\" : this.note.shift) + \" \",\n });\n }\n }\n\n protected moveGlyphToRoot(): void {\n super.moveGlyphToRoot();\n if (this.shiftElement) {\n this.rootShape.element.appendChild(this.shiftElement);\n }\n }\n\n orderEmbelishments(): void {\n const note = this.note;\n // create the embelishments if needed\n if (note.octave > 0) {\n this.topSlot.push(new OctaveIndicator(this, note));\n } else if (this.note.octave < 0) {\n this.bottomSlot.push(new OctaveIndicator(this, note));\n }\n super.orderEmbelishments();\n }\n\n get note(): Note {\n return this.flatAtom.atom as Note;\n }\n}\n\nclass SyllableView extends LeafAtomView {\n get glyphLabel(): string {\n return this.syllable.value;\n }\n\n get syllable(): Syllable {\n return this.flatAtom.atom as Syllable;\n }\n}\n"]}
|
package/lib/esm/shapes.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ export declare abstract class Shape {
|
|
|
18
18
|
protected abstract updateBounds(x: null | number, y: null | number, w: null | number, h: null | number): [number | null, number | null, number | null, number | null];
|
|
19
19
|
resetMinSize(): void;
|
|
20
20
|
setBounds(x: number | null, y: number | null, w: number | null, h: number | null, applyLayout?: boolean): [number | null, number | null, number | null, number | null];
|
|
21
|
+
get hasX(): boolean;
|
|
22
|
+
get hasY(): boolean;
|
|
23
|
+
get hasWidth(): boolean;
|
|
24
|
+
get hasHeight(): boolean;
|
|
21
25
|
get x(): number;
|
|
22
26
|
set x(x: number | null);
|
|
23
27
|
get y(): number;
|
package/lib/esm/shapes.js
CHANGED
|
@@ -147,11 +147,37 @@ var Shape = (function () {
|
|
|
147
147
|
this.refreshLayout();
|
|
148
148
|
return [nx, ny, nw, nh];
|
|
149
149
|
};
|
|
150
|
+
Object.defineProperty(Shape.prototype, "hasX", {
|
|
151
|
+
get: function () {
|
|
152
|
+
return this._x != null && !isNaN(this._x);
|
|
153
|
+
},
|
|
154
|
+
enumerable: false,
|
|
155
|
+
configurable: true
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(Shape.prototype, "hasY", {
|
|
158
|
+
get: function () {
|
|
159
|
+
return this._y != null && !isNaN(this._y);
|
|
160
|
+
},
|
|
161
|
+
enumerable: false,
|
|
162
|
+
configurable: true
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(Shape.prototype, "hasWidth", {
|
|
165
|
+
get: function () {
|
|
166
|
+
return this._width != null && !isNaN(this._width);
|
|
167
|
+
},
|
|
168
|
+
enumerable: false,
|
|
169
|
+
configurable: true
|
|
170
|
+
});
|
|
171
|
+
Object.defineProperty(Shape.prototype, "hasHeight", {
|
|
172
|
+
get: function () {
|
|
173
|
+
return this._height != null && !isNaN(this._height);
|
|
174
|
+
},
|
|
175
|
+
enumerable: false,
|
|
176
|
+
configurable: true
|
|
177
|
+
});
|
|
150
178
|
Object.defineProperty(Shape.prototype, "x", {
|
|
151
179
|
get: function () {
|
|
152
|
-
|
|
153
|
-
return this._x;
|
|
154
|
-
return 0;
|
|
180
|
+
return this._x || 0;
|
|
155
181
|
},
|
|
156
182
|
set: function (x) {
|
|
157
183
|
this.setBounds(x == null ? NaN : x, null, null, null);
|
|
@@ -223,8 +249,10 @@ var ElementShape = (function (_super) {
|
|
|
223
249
|
return [x, y, w, h];
|
|
224
250
|
};
|
|
225
251
|
ElementShape.prototype.refreshLayout = function () {
|
|
226
|
-
|
|
227
|
-
|
|
252
|
+
if (this.hasX)
|
|
253
|
+
this.element.setAttribute("x", "" + this._x);
|
|
254
|
+
if (this.hasY)
|
|
255
|
+
this.element.setAttribute("y", "" + this._y);
|
|
228
256
|
};
|
|
229
257
|
return ElementShape;
|
|
230
258
|
}(Shape));
|
package/lib/esm/shapes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAQvC;IAAA;QAEW,YAAO,GAAW,KAAK,CAAC,SAAS,EAAE,CAAC;QAMnC,OAAE,GAAkB,IAAI,CAAC;QACzB,OAAE,GAAkB,IAAI,CAAC;QACzB,WAAM,GAAkB,IAAI,CAAC;QAC7B,YAAO,GAAkB,IAAI,CAAC;QAG9B,gBAAW,GAAiB,IAAI,CAAC;QAC3C,aAAQ,GAAY,EAAE,CAAC;IA8OzB,CAAC;IAxOC,sBAAI,0BAAO;aAAX;YACE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;aAEvC;YACD,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;;;OAAA;IAKD,wBAAQ,GAAR,UAAS,KAAY,EAAE,KAAU;QAAV,sBAAA,EAAA,SAAS,CAAC;QAE/B,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAGzB,IAAI,KAAK,IAAI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ACV,eAAS,GAAG,CAAC,CAAC;;IAYd,CAAC;IAWS,iCAAc,GAAxB;QACE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;IAES,+BAAY,GAAtB,UACE,CAAgB,EAChB,CAAgB,EAChB,CAAgB,EAChB,CAAgB;QAEhB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,sBAAI,4BAAM;aAAV;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC5B,CAAC;;;OAAA;IAED,0BAAO,GAAP;QACE,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAA0C,CAAC;QAC7E,OAAO,QAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,OAAO,IAAI,QAAQ,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE;YAC9E,QAAQ,GAAG,QAAQ,CAAC,aAA0C,CAAC;SAChE;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,eAAC;AAAD,CAAC,AAlDD,CAAuC,KAAK,GAkD3C","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { FlatAtom } from \"./iterators\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the top left corner\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n // protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._minSize;\n }\n\n /**\n * Add a child shape.\n */\n addShape(child: Shape, index = -1): void {\n // Orphan it first\n child.removeFromParent();\n\n // Then add it\n if (index >= 0) {\n this.children.splice(index, 0, child);\n } else {\n this.children.push(child);\n }\n child.parentShape = this;\n }\n\n /**\n * Remove a child from our children list if it exists.\n */\n removeShape(child: Shape): void {\n const index = this.children.indexOf(child);\n if (index >= 0) {\n this.children.splice(index, 1);\n }\n child.parentShape = null;\n }\n\n /**\n * Remove ourselves from our parent.\n */\n removeFromParent(): void {\n if (this.parentShape) {\n this.parentShape.removeShape(this);\n }\n }\n\n /**\n * Returns the unioned bounding box of all child shapes.\n */\n /*\n protected childrenBBox(): TSU.Geom.Rect | null {\n let bbox: TSU.Geom.Rect | null = null;\n for (let i = this.children.length - 1; i >= 0; i--) {\n if (bbox == null) bbox = TSU.Geom.Rect.from(this.children[i].bbox);\n else bbox = bbox.union(this.children[i].bbox);\n }\n return bbox;\n }\n */\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n // protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n resetMinSize(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n }\n /*\n resetBBox(): void {\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n */\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n /**\n * Gets the bounding box of this shape in the coordinate system within\n * the parent.\n */\n /*\n protected get bbox2(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox().union(this.childrenBBox());\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._bbox;\n }\n */\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n if (this._x != null) return this._x;\n return 0; // this.bbox.x;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape extends Shape {\n constructor(public readonly element: SVGGraphicsElement) {\n super();\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n this.element.setAttribute(\"x\", \"\" + this.x);\n this.element.setAttribute(\"y\", \"\" + this.y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n glyph: ElementShape;\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n constructor(public flatAtom: FlatAtom) {\n super();\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n abstract refreshLayout(): void;\n\n /**\n * By default the glyph's bbox is our bbox.\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return this.glyph.minSize;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return this.glyph.setBounds(x, y, w, h);\n }\n\n get viewId(): number {\n return this.flatAtom.uuid;\n }\n\n embRoot(): SVGGraphicsElement {\n let rootElem = this.glyph.element.parentElement as any as SVGGraphicsElement;\n while (rootElem && (rootElem.tagName == \"tspan\" || rootElem.tagName == \"text\")) {\n rootElem = rootElem.parentElement as any as SVGGraphicsElement;\n }\n return rootElem;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../src/shapes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,iBAAiB,CAAC;AAQvC;IAAA;QAEW,YAAO,GAAW,KAAK,CAAC,SAAS,EAAE,CAAC;QAMnC,OAAE,GAAkB,IAAI,CAAC;QACzB,OAAE,GAAkB,IAAI,CAAC;QACzB,WAAM,GAAkB,IAAI,CAAC;QAC7B,YAAO,GAAkB,IAAI,CAAC;QAG9B,gBAAW,GAAiB,IAAI,CAAC;QAC3C,aAAQ,GAAY,EAAE,CAAC;IA6PzB,CAAC;IAvPC,sBAAI,0BAAO;aAAX;YACE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;aAEvC;YACD,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;;;OAAA;IAKD,wBAAQ,GAAR,UAAS,KAAY,EAAE,KAAU;QAAV,sBAAA,EAAA,SAAS,CAAC;QAE/B,KAAK,CAAC,gBAAgB,EAAE,CAAC;QAGzB,IAAI,KAAK,IAAI,CAAC,EAAE;YACd,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;SACvC;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAC3B;QACD,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;IAC3B,CAAC;IAKD,2BAAW,GA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AAC;QAC5D,IAAI,IAAI,CAAC,IAAI;YAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9D,CAAC;IACH,mBAAC;AAAD,CAAC,AAtBD,CAAkC,KAAK,GAsBtC;;AAED;IAAuC,4BAAK;IAa1C,kBAAmB,QAAkB;QAArC,YACE,iBAAO,SACR;QAFkB,cAAQ,GAAR,QAAQ,CAAU;QAXrC,WAAK,GAAG,CAAC,CAAC;QACV,eAAS,GAAG,CAAC,CAAC;;IAYd,CAAC;IAWS,iCAAc,GAAxB;QACE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;IAES,+BAAY,GAAtB,UACE,CAAgB,EAChB,CAAgB,EAChB,CAAgB,EAChB,CAAgB;QAEhB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,sBAAI,4BAAM;aAAV;YACE,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAC5B,CAAC;;;OAAA;IAED,0BAAO,GAAP;QACE,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAA0C,CAAC;QAC7E,OAAO,QAAQ,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,OAAO,IAAI,QAAQ,CAAC,OAAO,IAAI,MAAM,CAAC,EAAE;YAC9E,QAAQ,GAAG,QAAQ,CAAC,aAA0C,CAAC;SAChE;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,eAAC;AAAD,CAAC,AAlDD,CAAuC,KAAK,GAkD3C","sourcesContent":["import * as TSU from \"@panyam/tsutils\";\nimport { FlatAtom } from \"./iterators\";\n\n/**\n * Base class of all renderable objects for caching things like bounding boxes etc.\n * We do this since a lot of the property setters dont change bounding boxes but\n * bounding box reads are a bit slow in general.\n */\nexport abstract class Shape {\n private static idCounter = 0;\n readonly shapeId: number = Shape.idCounter++;\n /**\n * Note that x and y coordinates are not always the x and y coordinates of the bounding box.\n * Eg a circle's x and y coordinates are its center point and not the top left corner\n * These \"main\" coordinates are referred as control coordinates.\n */\n protected _x: number | null = null;\n protected _y: number | null = null;\n protected _width: number | null = null;\n protected _height: number | null = null;\n // protected _bbox: TSU.Geom.Rect;\n protected _minSize: TSU.Geom.Size;\n protected parentShape: Shape | null = null;\n children: Shape[] = [];\n\n /**\n * Sizes can have a minimum size.\n * This is usually the size of the bounding box.\n */\n get minSize(): TSU.Geom.Size {\n if (!this._minSize) {\n this._minSize = this.refreshMinSize();\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._minSize;\n }\n\n /**\n * Add a child shape.\n */\n addShape(child: Shape, index = -1): void {\n // Orphan it first\n child.removeFromParent();\n\n // Then add it\n if (index >= 0) {\n this.children.splice(index, 0, child);\n } else {\n this.children.push(child);\n }\n child.parentShape = this;\n }\n\n /**\n * Remove a child from our children list if it exists.\n */\n removeShape(child: Shape): void {\n const index = this.children.indexOf(child);\n if (index >= 0) {\n this.children.splice(index, 1);\n }\n child.parentShape = null;\n }\n\n /**\n * Remove ourselves from our parent.\n */\n removeFromParent(): void {\n if (this.parentShape) {\n this.parentShape.removeShape(this);\n }\n }\n\n /**\n * Returns the unioned bounding box of all child shapes.\n */\n /*\n protected childrenBBox(): TSU.Geom.Rect | null {\n let bbox: TSU.Geom.Rect | null = null;\n for (let i = this.children.length - 1; i >= 0; i--) {\n if (bbox == null) bbox = TSU.Geom.Rect.from(this.children[i].bbox);\n else bbox = bbox.union(this.children[i].bbox);\n }\n return bbox;\n }\n */\n\n /**\n * refreshBBox is called by the Shape when it knows the bbox it is tracking\n * cannot be trusted and has to be refreshed by calling native methods.\n */\n protected abstract refreshMinSize(): TSU.Geom.Size;\n // protected abstract refreshBBox(): TSU.Geom.Rect;\n protected abstract updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null];\n\n resetMinSize(): void {\n this._minSize = null as unknown as TSU.Geom.Size;\n }\n /*\n resetBBox(): void {\n this._bbox = null as unknown as TSU.Geom.Rect;\n }\n */\n\n /**\n * Sets the x or y coordinate of this shape in coordinate system within its\n * parent.\n *\n * Note that null and NaN are valid values and mean the following:\n * null - Dont change the value. Passed to \"ignore\" effects.\n * NaN - Ensure the value is set to null so that the bounding box specific coord is used going forward.\n */\n setBounds(\n x: number | null,\n y: number | null,\n w: number | null,\n h: number | null,\n applyLayout = false,\n ): [number | null, number | null, number | null, number | null] {\n if (x != null) {\n if (isNaN(x)) {\n this._x = null;\n } else {\n this._x = x;\n }\n }\n if (y != null) {\n if (isNaN(y)) {\n this._y = null;\n } else {\n this._y = y;\n }\n }\n if (w != null) {\n if (isNaN(w)) {\n this._width = null;\n } else {\n this._width = w;\n }\n }\n if (h != null) {\n if (isNaN(h)) {\n this._height = null;\n } else {\n this._height = h;\n }\n }\n const [nx, ny, nw, nh] = this.updateBounds(x, y, w, h);\n if (nx != null) {\n if (isNaN(nx)) {\n this._x = null;\n } else {\n this._x = nx;\n }\n }\n if (ny != null) {\n if (isNaN(ny)) {\n this._y = null;\n } else {\n this._y = ny;\n }\n }\n if (nw != null) {\n if (isNaN(nw)) {\n this._width = null;\n } else {\n this._width = nw;\n }\n }\n if (nh != null) {\n if (isNaN(nh)) {\n this._height = null;\n } else {\n this._height = nh;\n }\n }\n if (applyLayout) this.refreshLayout();\n // this.resetBBox();\n return [nx, ny, nw, nh];\n }\n\n /**\n * Gets the bounding box of this shape in the coordinate system within\n * the parent.\n */\n /*\n protected get bbox2(): TSU.Geom.Rect {\n if (!this._bbox) {\n this._bbox = this.refreshBBox().union(this.childrenBBox());\n // this.xChanged = this.yChanged = this.widthChanged = this.heightChanged = false;\n }\n return this._bbox;\n }\n */\n\n get hasX(): boolean {\n return this._x != null && !isNaN(this._x);\n }\n\n get hasY(): boolean {\n return this._y != null && !isNaN(this._y);\n }\n\n get hasWidth(): boolean {\n return this._width != null && !isNaN(this._width);\n }\n\n get hasHeight(): boolean {\n return this._height != null && !isNaN(this._height);\n }\n\n /**\n * Gets the x coordinate within the parent's coordinate system.\n */\n get x(): number {\n return this._x || 0;\n }\n\n /**\n * Sets the x coordinate within the parent's coordinate system.\n */\n set x(x: number | null) {\n // Here a manual x is being set - how does this interfere with the bounding box?\n // We should _x to the new value to indicate a manual value was set.\n // and reset bbox so that based on this x a new bbox may need to be calculated\n this.setBounds(x == null ? NaN : x, null, null, null);\n }\n\n /**\n * Gets the y coordinate within the parent's coordinate system.\n */\n get y(): number {\n if (this._y != null) return this._y;\n return 0; // this.bbox.y;\n }\n\n /**\n * Sets the y coordinate within the parent's coordinate system.\n */\n set y(y: number | null) {\n this.setBounds(null, y == null ? NaN : y, null, null);\n }\n\n get width(): number {\n if (this._width != null) return this._width;\n return 0; // this.bbox.width;\n }\n\n set width(w: number | null) {\n this.setBounds(null, null, w == null ? NaN : w, null);\n }\n\n get height(): number {\n if (this._height != null) return this._height;\n return 0; // this.bbox.height;\n }\n\n set height(h: number | null) {\n this.setBounds(null, null, null, h == null ? NaN : h);\n }\n\n /**\n * This is called when bounds or other properties of a shape have changed to\n * give the shape an opportunity to layout the children. For shapes\n * with no children this is a no-op. It is expected the Shape will keep track\n * of all changes so it can apply them all in in one go in this method - A\n * form of \"commit\"ing the layout transaction.\n */\n refreshLayout(): void {\n // throw new Error(\"Implement this\");\n }\n}\n\nexport abstract class Embelishment extends Shape {}\n\nexport class ElementShape extends Shape {\n constructor(public readonly element: SVGGraphicsElement) {\n super();\n }\n\n protected refreshMinSize(): TSU.Geom.Size {\n return TSU.DOM.svgBBox(this.element);\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return [x, y, w, h];\n }\n\n refreshLayout(): void {\n if (this.hasX) this.element.setAttribute(\"x\", \"\" + this._x);\n if (this.hasY) this.element.setAttribute(\"y\", \"\" + this._y);\n }\n}\n\nexport abstract class AtomView extends Shape {\n glyph: ElementShape;\n depth = 0;\n roleIndex = 0;\n\n // LayoutMetrics for the AtomView so all atomviews laid out on the\n // same baseline will show up aligned vertically\n baseline: number;\n ascent: number;\n descent: number;\n capHeight: number;\n leading: number;\n\n constructor(public flatAtom: FlatAtom) {\n super();\n }\n\n /**\n * Creates views needed for this AtomView.\n */\n abstract createElements(parent: SVGGraphicsElement): void;\n abstract refreshLayout(): void;\n\n /**\n * By default the glyph's bbox is our bbox.\n */\n protected refreshMinSize(): TSU.Geom.Size {\n return this.glyph.minSize;\n }\n\n protected updateBounds(\n x: null | number,\n y: null | number,\n w: null | number,\n h: null | number,\n ): [number | null, number | null, number | null, number | null] {\n return this.glyph.setBounds(x, y, w, h);\n }\n\n get viewId(): number {\n return this.flatAtom.uuid;\n }\n\n embRoot(): SVGGraphicsElement {\n let rootElem = this.glyph.element.parentElement as any as SVGGraphicsElement;\n while (rootElem && (rootElem.tagName == \"tspan\" || rootElem.tagName == \"text\")) {\n rootElem = rootElem.parentElement as any as SVGGraphicsElement;\n }\n return rootElem;\n }\n}\n"]}
|
package/package.json
CHANGED