1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-09-03 13:23:27 +02:00

view source

This commit is contained in:
Pomax
2020-08-04 15:08:45 -07:00
parent 6ddee66a33
commit 90821b150d

View File

@@ -37,6 +37,7 @@ class GraphicsElement extends CustomElement {
:host canvas:focus { ${
this.getAttribute(`focus-css`) || `border: 1px solid red !important; margin: -1px; `
} }
:host a.view-source { float: left; font-size: 60%; text-decoration: none; }
:host label { display: block; font-style:italic; font-size: 0.9em; text-align: right; }
`;
}
@@ -118,6 +119,7 @@ class GraphicsElement extends CustomElement {
* Transform the graphics source code into global and class code.
*/
processSource(code, rerender = false) {
this.rawCode = code;
if (this.script) {
if (this.script.parentNode) {
this.script.parentNode.removeChild(this.script);
@@ -219,6 +221,13 @@ class GraphicsElement extends CustomElement {
const slotParent = this._slot.parentNode;
if (this.canvas) slotParent.insertBefore(this.canvas, this._slot);
if (this.label) slotParent.insertBefore(this.label, this._slot);
const a = document.createElement('a');
a.classList.add('view-source');
a.textContent = `view source`;
a.href = new URL(`data:text/plain;charset=utf-8,${encodeURIComponent(this.rawCode)}`);
a.target = `_blank`;
if (this.label) slotParent.insertBefore(a, this.label);
}
}