Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
expanse committed Jul 18, 2023
1 parent 4b27583 commit 18f1080
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tgui/packages/tgui/interfaces/CanvasLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ export class CanvasLayer extends Component {
constructor(props) {
super(props);
this.canvasRef = createRef();

// color selection
// using this.state prevents unpredictable behavior
this.state = {
selection: this.props.selection,
};

// needs to be of type png of jpg
this.img = null;
this.imageSrc = this.props.imageSrc;

// stores the stacked lines
this.lineStack = [];

// stores the individual line drawn
this.currentLine = [];

Expand Down Expand Up @@ -77,7 +77,7 @@ export class CanvasLayer extends Component {
return;
}

// defaults to black sometimes, it's a bug I think maybe.
// defaults to black sometimes, it's a bug I think maybe.
this.ctx.strokeStyle = this.state.selection;

const rect = this.canvasRef.current.getBoundingClientRect();
Expand Down Expand Up @@ -136,7 +136,7 @@ export class CanvasLayer extends Component {
}
const line = this.lineStack[this.lineStack.length - 1];

// selects last color before line is yeeted, this is buggy sometimes.
// selects last color before line is yeeted, this is buggy sometimes.
const prevColor = line[0][4];
this.lineStack.pop();

Expand Down Expand Up @@ -169,11 +169,11 @@ export class CanvasLayer extends Component {
return;
}

if (selection === 'export') {
const svgData = this.convertToSVG();
this.props.onImageExport(svgData);
return;
}
if (selection === 'export') {
const svgData = this.convertToSVG();
this.props.onImageExport(svgData);
return;
}

this.setState({ selection: selection });
};
Expand All @@ -186,7 +186,7 @@ export class CanvasLayer extends Component {

drawCanvas() {
this.img.onload = () => {
// this onload may or may not be causing problems.
// this onload may or may not be causing problems.
this.ctx.drawImage(
this.img,
0,
Expand All @@ -198,11 +198,11 @@ export class CanvasLayer extends Component {
}

convertToSVG() {
const svgNS = "http://www.w3.org/2000/svg";
const svgNS = 'http://www.w3.org/2000/svg';
const svg = document.createElementNS(svgNS, 'svg');
svg.setAttributeNS(null, 'width', this.canvasRef.current.width);
svg.setAttributeNS(null, 'height', this.canvasRef.current.height);

const lines = this.lineStack.flat();
lines.forEach(([lastX, lastY, x, y, colorSelection]) => {
const line = document.createElementNS(svgNS, 'line');
Expand All @@ -215,12 +215,12 @@ export class CanvasLayer extends Component {
line.setAttributeNS(null, 'stroke-linecap', 'round');
svg.appendChild(line);
});

const serializer = new XMLSerializer();
const serializedSvg = serializer.serializeToString(svg);
const base64Svg = btoa(serializedSvg);
const dataUrl = `data:image/svg+xml;base64,${base64Svg}`;

return dataUrl;
}

Expand Down

0 comments on commit 18f1080

Please sign in to comment.