Skip to content

Commit 5da592d

Browse files
committed
Changelog for #133. Improved "canvas coommon" test coverage.
1 parent 2fd5697 commit 5da592d

File tree

5 files changed

+73
-27
lines changed

5 files changed

+73
-27
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
#### :boom: Breaking Change
1515

1616
- Corrected return type of `getPropertyValue` for CSS style attributes (it's nullable and now returns an option).
17-
- Corrected signature of `toggleForced` (for `Dom.domTokenList`) to accept a bool denoting whether to toggle the class on or off. https://github.com/TheSpyder/rescript-webapi/pull/136
17+
- Corrected signature of `DomTokenList.toggleForced` to accept a boolean, denoting whether to toggle the class on or off. https://github.com/TheSpyder/rescript-webapi/pull/136
18+
- Corrected argument names of Canvas2d and Path2d bindings https://github.com/TheSpyder/rescript-webapi/pull/133
19+
20+
#### :rocket: New Feature
21+
22+
- `VisualViewport` bindings. https://github.com/TheSpyder/rescript-webapi/pull/137
23+
- `Path2d` is now a separate module from `Canvas2d`, with more complete bindings https://github.com/TheSpyder/rescript-webapi/pull/133
1824

1925
#### :bug: Bug Fix
2026

lib/js/tests/Webapi/Canvas/Webapi__Canvas__Canvas2d__test.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,8 @@ ctx.shadowBlur = 1;
7070

7171
ctx.shadowColor = "red";
7272

73-
ctx.beginPath();
74-
7573
ctx.closePath();
7674

77-
ctx.fill();
78-
79-
ctx.stroke();
80-
81-
ctx.clip();
82-
8375
ctx.moveTo(1, 1);
8476

8577
ctx.lineTo(1, 2);
@@ -88,14 +80,24 @@ ctx.quadraticCurveTo(1, 1, 1, 1);
8880

8981
ctx.bezierCurveTo(1, 1, 2, 2, 4, 4);
9082

91-
ctx.arcTo(1, 1, 2, 2, 4);
92-
9383
ctx.arc(1, 1, 4, 1, 3, true);
9484

85+
ctx.arcTo(1, 1, 2, 2, 4);
86+
9587
ctx.ellipse(1, 1, 4, 8, 4, 1, 3, true);
9688

9789
ctx.rect(0, 0, 10, 10);
9890

91+
ctx.roundRect(0, 0, 10, 10, 10);
92+
93+
ctx.beginPath();
94+
95+
ctx.stroke();
96+
97+
ctx.clip();
98+
99+
ctx.fill();
100+
99101
var pointInPath = ctx.isPointInPath(0, 0);
100102

101103
var linearGradient = ctx.createLinearGradient(0.0, 0.0, 0.0, 0.0);

lib/js/tests/Webapi/Canvas/Webapi__Canvas__Path2d__test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,34 @@
33

44
var path = new Path2D("M24.85,10.126c2.018-4.783,6.628-8.125,11.99-8.125c7.223,0,12.425,6.179,13.079,13.543 c0,0,0.353,1.828-0.424,5.119c-1.058,4.482-3.545,8.464-6.898,11.503L24.85,48L7.402,32.165c-3.353-3.038-5.84-7.021-6.898-11.503 c-0.777-3.291-0.424-5.119-0.424-5.119C0.734,8.179,5.936,2,13.159,2C18.522,2,22.832,5.343,24.85,10.126z");
55

6+
path.closePath();
7+
68
path.moveTo(1, 1);
79

810
path.lineTo(1, 2);
911

10-
path.rect(1, 2, 10, 10);
12+
path.quadraticCurveTo(1, 1, 1, 1);
13+
14+
path.bezierCurveTo(1, 1, 2, 2, 4, 4);
15+
16+
path.arc(1, 1, 4, 1, 3, true);
17+
18+
path.arcTo(1, 1, 2, 2, 4);
1119

12-
path.bezierCurveTo(1, 2, 2, 2, 4, 4);
20+
path.ellipse(1, 1, 4, 8, 4, 1, 3, true);
21+
22+
path.rect(0, 0, 10, 10);
23+
24+
path.roundRect(0, 0, 10, 10, 10);
1325

1426
var canvasEl = document.createElement("canvas");
1527

1628
var ctx = canvasEl.getContext("2d");
1729

1830
ctx.fill(path);
1931

32+
ctx.stroke(path);
33+
2034
exports.path = path;
2135
exports.canvasEl = canvasEl;
2236
exports.ctx = ctx;

tests/Webapi/Canvas/Webapi__Canvas__Canvas2d__test.res

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,14 @@ shadowOffsetY(ctx, 1.)
4141
shadowBlur(ctx, 1.)
4242
shadowColor(ctx, "red")
4343

44-
ctx->beginPath
44+
// common things
4545
ctx->closePath
46-
ctx->fill
47-
ctx->stroke
48-
ctx->clip
4946
ctx->moveTo(~x=1., ~y=1.)
5047
ctx->lineTo(~x=1., ~y=2.)
5148
ctx->quadraticCurveTo(~cpx=1., ~cpy=1., ~x=1., ~y=1.)
5249
ctx->bezierCurveTo(~cp1x=1., ~cp1y=1., ~cp2x=2., ~cp2y=2., ~x=4., ~y=4.)
53-
ctx->arcTo(~x1=1., ~y1=1., ~x2=2., ~y2=2., ~r=4.)
5450
ctx->arc(~x=1., ~y=1., ~r=4., ~startAngle=1., ~endAngle=3., ~counterClockWise=true, ())
51+
ctx->arcTo(~x1=1., ~y1=1., ~x2=2., ~y2=2., ~r=4.)
5552
ctx->ellipse(
5653
~x=1.,
5754
~y=1.,
@@ -64,8 +61,17 @@ ctx->ellipse(
6461
(),
6562
)
6663
ctx->rect(~x=0., ~y=0., ~w=10., ~h=10.)
64+
ctx->roundRect(~x=0., ~y=0., ~w=10., ~h=10., ~r=10.)
65+
// end common things
66+
67+
ctx->beginPath
68+
ctx->stroke
69+
ctx->clip
70+
ctx->fill
6771
let pointInPath: bool = ctx->isPointInPath(~x=0., ~y=0.)
6872

73+
// fillPath2d and strokePath2d are in the Path2d module test
74+
6975
let linearGradient: gradient = ctx->createLinearGradient(~x0=0.0, ~y0=0.0, ~x1=0.0, ~y1=0.0)
7076
setStrokeStyle(ctx, Gradient, linearGradient)
7177
let radialGradient: gradient =
@@ -122,4 +128,4 @@ ctx->strokeText("hi", ~x=1., ~y=0., ())
122128

123129
ctx->fillRect(~x=1., ~y=0., ~w=10., ~h=10.)
124130
ctx->strokeRect(~x=1., ~y=0., ~w=10., ~h=10.)
125-
ctx->clearRect(~x=1., ~y=0., ~w=10., ~h=10.)
131+
ctx->clearRect(~x=1., ~y=0., ~w=10., ~h=10.)
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
open Webapi.Canvas
2-
open Webapi.Canvas.Canvas2d
32
open Webapi.Dom
3+
open Path2d
44

5-
let path = Path2d.make(
5+
let path = make(
66
~d="M24.85,10.126c2.018-4.783,6.628-8.125,11.99-8.125c7.223" ++
77
",0,12.425,6.179,13.079,13.543 c0,0,0.353,1.828-0.424,5.119c-1.058,4.482" ++
88
"-3.545,8.464-6.898,11.503L24.85,48L7.402,32.165c-3.353-3.038-5.84-7.021" ++
99
"-6.898-11.503 c-0.777-3.291-0.424-5.119-0.424-5.119C0.734,8.179,5.936,2" ++ ",13.159,2C18.522,2,22.832,5.343,24.85,10.126z",
1010
(),
1111
)
1212

13-
path->Path2d.moveTo(~x=1., ~y=1.)
14-
path->Path2d.lineTo(~x=1., ~y=2.)
15-
path->Path2d.rect(~x=1., ~y=2., ~w=10., ~h=10.)
16-
path->Path2d.bezierCurveTo(~cp1x=1., ~cp1y=2., ~cp2x=2., ~cp2y=2., ~x=4., ~y=4.)
17-
13+
// common things
14+
path->closePath
15+
path->moveTo(~x=1., ~y=1.)
16+
path->lineTo(~x=1., ~y=2.)
17+
path->quadraticCurveTo(~cpx=1., ~cpy=1., ~x=1., ~y=1.)
18+
path->bezierCurveTo(~cp1x=1., ~cp1y=1., ~cp2x=2., ~cp2y=2., ~x=4., ~y=4.)
19+
path->arc(~x=1., ~y=1., ~r=4., ~startAngle=1., ~endAngle=3., ~counterClockWise=true, ())
20+
path->arcTo(~x1=1., ~y1=1., ~x2=2., ~y2=2., ~r=4.)
21+
path->ellipse(
22+
~x=1.,
23+
~y=1.,
24+
~rx=4.,
25+
~ry=8.,
26+
~rtn=4.,
27+
~startAngle=1.,
28+
~endAngle=3.,
29+
~counterClockWise=true,
30+
(),
31+
)
32+
path->rect(~x=0., ~y=0., ~w=10., ~h=10.)
33+
path->roundRect(~x=0., ~y=0., ~w=10., ~h=10., ~r=10.)
34+
// end common things
1835

1936
let canvasEl: Dom.element = document->Document.createElement("canvas")
2037
let ctx = canvasEl->CanvasElement.getContext2d
2138

22-
ctx->fillPath2d(path)
39+
ctx->Canvas2d.fillPath2d(path)
40+
ctx->Canvas2d.strokePath2d(path)

0 commit comments

Comments
 (0)