Skip to content

Commit c8e5f95

Browse files
committed
Add trailing commas and minor WebGL fixes
Reformat imports and add trailing commas for consistency across function calls and object literals in src/renderers/webgl.js. Also introduce a missing local `closed` constant (elem._closed) used when rendering strokes/points. These are mostly stylistic/formatting changes and a small bugfix to ensure `closed` is available where expected; no major logic changes otherwise.
1 parent 38e63f2 commit c8e5f95

1 file changed

Lines changed: 36 additions & 29 deletions

File tree

src/renderers/webgl.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { Commands } from '../utils/path-commands.js';
22

33
import { root } from '../utils/root.js';
4-
import { getPoT, mod, NumArray, TWO_PI, getEffectiveStrokeWidth } from '../utils/math.js';
4+
import {
5+
getPoT,
6+
mod,
7+
NumArray,
8+
TWO_PI,
9+
getEffectiveStrokeWidth,
10+
} from '../utils/math.js';
511
import { shaders } from '../utils/shaders.js';
612
import { Events } from '../events.js';
713
import { TwoError } from '../utils/error.js';
@@ -98,7 +104,7 @@ const webgl = {
98104
multiplyMatrix(
99105
transformation,
100106
parent._renderer.matrix,
101-
this._renderer.matrix
107+
this._renderer.matrix,
102108
);
103109

104110
if (!(this._renderer.scale instanceof Vector)) {
@@ -134,7 +140,7 @@ const webgl = {
134140
gl.colorMask(false, false, false, false);
135141

136142
const prop = CanvasRenderer.Utils.getRendererType(
137-
this._mask._renderer.type
143+
this._mask._renderer.type,
138144
);
139145
webgl[prop].render.call(this._mask, gl, programs, this);
140146

@@ -200,11 +206,11 @@ const webgl = {
200206

201207
canvas.width = Math.max(
202208
Math.ceil(elem._renderer.rect.width * scale.x),
203-
1
209+
1,
204210
);
205211
canvas.height = Math.max(
206212
Math.ceil(elem._renderer.rect.height * scale.y),
207-
1
213+
1,
208214
);
209215

210216
const centroid = elem._renderer.rect.centroid;
@@ -218,7 +224,7 @@ const webgl = {
218224
ctx.fillStyle = fill;
219225
} else {
220226
const prop = CanvasRenderer.Utils.getRendererType(
221-
fill._renderer.type
227+
fill._renderer.type,
222228
);
223229
webgl[prop].render.call(fill, ctx, elem);
224230
ctx.fillStyle = fill._renderer.effect;
@@ -229,7 +235,7 @@ const webgl = {
229235
ctx.strokeStyle = stroke;
230236
} else {
231237
const prop = CanvasRenderer.Utils.getRendererType(
232-
stroke._renderer.type
238+
stroke._renderer.type,
233239
);
234240
webgl[prop].render.call(stroke, ctx, elem);
235241
ctx.strokeStyle = stroke._renderer.effect;
@@ -297,7 +303,7 @@ const webgl = {
297303
sweepFlag,
298304
xAxisRotation,
299305
x,
300-
y
306+
y,
301307
);
302308
break;
303309

@@ -558,7 +564,7 @@ const webgl = {
558564
multiplyMatrix(
559565
transformation,
560566
parent._renderer.matrix,
561-
this._renderer.matrix
567+
this._renderer.matrix,
562568
);
563569

564570
if (!(this._renderer.scale instanceof Vector)) {
@@ -591,7 +597,7 @@ const webgl = {
591597
gl.colorMask(false, false, false, false);
592598

593599
const prop = CanvasRenderer.Utils.getRendererType(
594-
this._mask._renderer.type
600+
this._mask._renderer.type,
595601
);
596602
webgl[prop].render.call(this._mask, gl, programs, this);
597603

@@ -610,7 +616,7 @@ const webgl = {
610616
webgl.path.getBoundingClientRect(
611617
this._renderer.vertices,
612618
this._linewidth,
613-
this._renderer.rect
619+
this._renderer.rect,
614620
);
615621

616622
webgl.updateTexture.call(webgl, gl, this);
@@ -641,7 +647,7 @@ const webgl = {
641647
gl.uniform2f(
642648
gl.getUniformLocation(program, 'u_resolution'),
643649
programs.resolution.width,
644-
programs.resolution.height
650+
programs.resolution.height,
645651
);
646652
}
647653

@@ -652,7 +658,7 @@ const webgl = {
652658
gl.uniform2f(
653659
gl.getUniformLocation(program, 'u_resolution'),
654660
programs.resolution.width,
655-
programs.resolution.height
661+
programs.resolution.height,
656662
);
657663
}
658664

@@ -693,6 +699,7 @@ const webgl = {
693699
const opacity = elem._renderer.opacity || elem._opacity;
694700
const dashes = elem.dashes;
695701
const size = elem._size * ratio;
702+
const closed = elem._closed;
696703
let dimension = size;
697704

698705
if (!webgl.isHidden.test(stroke)) {
@@ -714,7 +721,7 @@ const webgl = {
714721
ctx.fillStyle = fill;
715722
} else {
716723
const prop = CanvasRenderer.Utils.getRendererType(
717-
fill._renderer.type
724+
fill._renderer.type,
718725
);
719726
webgl[prop].render.call(fill, ctx, elem);
720727
ctx.fillStyle = fill._renderer.effect;
@@ -725,7 +732,7 @@ const webgl = {
725732
ctx.strokeStyle = stroke;
726733
} else {
727734
const prop = CanvasRenderer.Utils.getRendererType(
728-
stroke._renderer.type
735+
stroke._renderer.type,
729736
);
730737
webgl[prop].render.call(stroke, ctx, elem);
731738
ctx.strokeStyle = stroke._renderer.effect;
@@ -866,7 +873,7 @@ const webgl = {
866873
multiplyMatrix(
867874
transformation,
868875
parent._renderer.matrix,
869-
this._renderer.matrix
876+
this._renderer.matrix,
870877
);
871878

872879
if (!(this._renderer.scale instanceof Vector)) {
@@ -935,7 +942,7 @@ const webgl = {
935942
gl.uniform2f(
936943
gl.getUniformLocation(program, 'u_resolution'),
937944
programs.resolution.width,
938-
programs.resolution.height
945+
programs.resolution.height,
939946
);
940947
}
941948
programs.current = program;
@@ -945,7 +952,7 @@ const webgl = {
945952
gl.uniform2f(
946953
gl.getUniformLocation(program, 'u_resolution'),
947954
programs.resolution.width,
948-
programs.resolution.height
955+
programs.resolution.height,
949956
);
950957
}
951958

@@ -983,11 +990,11 @@ const webgl = {
983990

984991
canvas.width = Math.max(
985992
Math.ceil(elem._renderer.rect.width * scale.x),
986-
1
993+
1,
987994
);
988995
canvas.height = Math.max(
989996
Math.ceil(elem._renderer.rect.height * scale.y),
990-
1
997+
1,
991998
);
992999

9931000
const centroid = elem._renderer.rect.centroid;
@@ -1022,7 +1029,7 @@ const webgl = {
10221029
ctx.fillStyle = fill;
10231030
} else {
10241031
const prop = CanvasRenderer.Utils.getRendererType(
1025-
fill._renderer.type
1032+
fill._renderer.type,
10261033
);
10271034
webgl[prop].render.call(fill, ctx, elem);
10281035
ctx.fillStyle = fill._renderer.effect;
@@ -1033,7 +1040,7 @@ const webgl = {
10331040
ctx.strokeStyle = stroke;
10341041
} else {
10351042
const prop = CanvasRenderer.Utils.getRendererType(
1036-
stroke._renderer.type
1043+
stroke._renderer.type,
10371044
);
10381045
webgl[prop].render.call(stroke, ctx, elem);
10391046
ctx.strokeStyle = stroke._renderer.effect;
@@ -1314,7 +1321,7 @@ const webgl = {
13141321
multiplyMatrix(
13151322
transformation,
13161323
parent._renderer.matrix,
1317-
this._renderer.matrix
1324+
this._renderer.matrix,
13181325
);
13191326

13201327
if (!(this._renderer.scale instanceof Vector)) {
@@ -1347,7 +1354,7 @@ const webgl = {
13471354
gl.colorMask(false, false, false, false);
13481355

13491356
const prop = CanvasRenderer.Utils.getRendererType(
1350-
this._mask._renderer.type
1357+
this._mask._renderer.type,
13511358
);
13521359
webgl[prop].render.call(this._mask, gl, programs, this);
13531360

@@ -1393,7 +1400,7 @@ const webgl = {
13931400
gl.uniform2f(
13941401
gl.getUniformLocation(program, 'u_resolution'),
13951402
programs.resolution.width,
1396-
programs.resolution.height
1403+
programs.resolution.height,
13971404
);
13981405
}
13991406

@@ -1404,7 +1411,7 @@ const webgl = {
14041411
gl.uniform2f(
14051412
gl.getUniformLocation(program, 'u_resolution'),
14061413
programs.resolution.width,
1407-
programs.resolution.height
1414+
programs.resolution.height,
14081415
);
14091416
}
14101417

@@ -1521,7 +1528,7 @@ const webgl = {
15211528
0,
15221529
fx,
15231530
fy,
1524-
radius
1531+
radius,
15251532
);
15261533

15271534
for (let i = 0; i < this.stops.length; i++) {
@@ -1636,7 +1643,7 @@ const webgl = {
16361643
gl.RGBA,
16371644
gl.RGBA,
16381645
gl.UNSIGNED_BYTE,
1639-
this.canvas
1646+
this.canvas,
16401647
);
16411648

16421649
// Set the parameters so we can render any size image.
@@ -1772,7 +1779,7 @@ export class Renderer extends Events {
17721779

17731780
if (!this.ctx) {
17741781
throw new TwoError(
1775-
'unable to create a webgl context. Try using another renderer.'
1782+
'unable to create a webgl context. Try using another renderer.',
17761783
);
17771784
}
17781785

0 commit comments

Comments
 (0)