Skip to content

Commit e871825

Browse files
committed
Updated JSDoc.
1 parent d7e72d6 commit e871825

File tree

13 files changed

+82
-138
lines changed

13 files changed

+82
-138
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
/**
3131
* Creates a new canvas.
3232
* @param {number} width Width of the canvas in pixels.
33-
* @param {number} heigt Height of the canvas in pixels.
33+
* @param {number} heigth Height of the canvas in pixels.
3434
* @returns {Canvas}
3535
*/
3636
createCanvas: function (width, height) {

lib/canvas.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2424
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2525
*/
26-
27-
"use strict";
26+
27+
"use strict";
2828

2929
const EdgeTable = require("./rasterization/edgeTable");
3030
const rasterizer = require("./rasterization/rasterizer");
@@ -38,7 +38,6 @@ const colorUtils = require("./colorUtils");
3838
* @param {number} width Canvas width in pixels.
3939
* @param {number} height Canvas height in pixels.
4040
* @constructor
41-
* @public
4241
*/
4342
function Canvas(width, height) {
4443
this.width = width;
@@ -49,42 +48,51 @@ function Canvas(width, height) {
4948
/**
5049
* The width of the canvas in pixels.
5150
* @type {number}
52-
* @public
5351
*/
5452
Canvas.prototype.width = 0;
5553

5654
/**
5755
* The height of the canvas in pixels.
5856
* @type {number}
59-
* @public
6057
*/
6158
Canvas.prototype.height = 0;
6259

6360
/**
64-
* Specifies the background color. Allowed values are:
65-
* - 32 bit integers on the format 0xRRGGBBAA
66-
* - strings on the format #RGB
67-
* - strings on the format #RRGGBB
68-
* - strings on the format #RRGGBBAA
69-
* @type {number}
70-
* @public
61+
* Specifies the background color. Default is fully transparent. Allowed values are:
62+
* - 32 bit integers on the format `0xRRGGBBAA`
63+
* - strings on the format `"#RGB"`
64+
* - strings on the format `"#RGBA"`
65+
* - strings on the format `"#RRGGBB"`
66+
* - strings on the format `"#RRGGBBAA"`
67+
* - strings on the format `"rgb(255, 255, 255)"`
68+
* - strings on the format `"rgb(255, 255, 255, 0.5)"`
69+
* - strings on the format `"rgb(255, 255, 255, 50%)"`
70+
* - strings on the format `"rgba(255, 255, 255, 0.5)"`
71+
* - strings on the format `"rgba(255, 255, 255, 50%)"`
72+
* - strings on the format `"hsl(134, 50%, 50%)"`
73+
* - strings on the format `"hsl(134, 50%, 50%, 0.5)"`
74+
* - strings on the format `"hsl(134, 50%, 50%, 50%)"`
75+
* - strings on the format `"hsla(134, 50%, 50%, 0.5)"`
76+
* - strings on the format `"hsla(134, 50%, 50%, 50%)"`
77+
* - strings on the format `"hwb(134, 50%, 50%)"`
78+
* - strings on the format `"hwb(134, 50%, 50%, 0.5)"`
79+
* - strings on the format `"hwb(134, 50%, 50%, 50%)"`
80+
* @type {string|number}
7181
*/
7282
Canvas.prototype.backColor = 0x00000000;
7383

7484
/**
7585
* Gets a context used to draw polygons on this canvas.
7686
* @returns {CanvasContext}
77-
* @public
7887
*/
7988
Canvas.prototype.getContext = function Canvas_getContext() {
8089
return new CanvasContext(this);
8190
};
8291

8392
/**
8493
* Renders the canvas as a PNG data stream.
85-
* @param {Object} keywords Keywords to be written to the PNG stream. See https://www.w3.org/TR/PNG/#11keywords.
94+
* @param {Object} [keywords] Keywords to be written to the PNG stream. See https://www.w3.org/TR/PNG/#11keywords.
8695
* @returns {Buffer}
87-
* @public
8896
*/
8997
Canvas.prototype.toPng = function Canvas_toPng(keywords) {
9098
var backColor = colorUtils.parse(this.backColor);
@@ -119,9 +127,8 @@ Canvas.prototype.toPng = function Canvas_toPng(keywords) {
119127
};
120128

121129
/**
122-
* Renders the canvas as a data URI. Only type 'image/png' is supported.
130+
* Renders the canvas as a data URI. Only type `"image/png"` is supported.
123131
* @returns {string}
124-
* @public
125132
*/
126133
Canvas.prototype.toDataURL = function Canvas_toDataURL() {
127134
if (this.width <= 0 || this.height <= 0) {

lib/canvasContext.js

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const canvasState = require("./canvasState");
3333

3434
/**
3535
* Creates a new canvas with the specified dimensions given in pixels.
36-
* @public
3736
*/
3837
function CanvasContext(canvas) {
3938
this.canvas = canvas;
@@ -48,39 +47,41 @@ function CanvasContext(canvas) {
4847

4948
/**
5049
* Specifies the fill color that is used when the fill method is called. Allowed values are:
51-
* - 32 bit integers on the format 0xRRGGBBAA
52-
* - strings on the format #RGB
53-
* - strings on the format #RGBA
54-
* - strings on the format #RRGGBB
55-
* - strings on the format #RRGGBBAA
56-
* - strings on the format rgb(255, 255, 255)
57-
* - strings on the format rgb(255, 255, 255, 0.5)
58-
* - strings on the format rgb(255, 255, 255, 50%)
59-
* - strings on the format rgba(255, 255, 255, 0.5)
60-
* - strings on the format rgba(255, 255, 255, 50%)
61-
* - strings on the format hsl(134, 50%, 50%)
62-
* - strings on the format hsl(134, 50%, 50%, 0.5)
63-
* - strings on the format hsl(134, 50%, 50%, 50%)
64-
* - strings on the format hsla(134, 50%, 50%, 0.5)
65-
* - strings on the format hsla(134, 50%, 50%, 50%)
66-
* - strings on the format hwb(134, 50%, 50%)
67-
* - strings on the format hwb(134, 50%, 50%, 0.5)
68-
* - strings on the format hwb(134, 50%, 50%, 50%)
69-
* @public
50+
* - 32 bit integers on the format `0xRRGGBBAA`
51+
* - strings on the format `"#RGB"`
52+
* - strings on the format `"#RGBA"`
53+
* - strings on the format `"#RRGGBB"`
54+
* - strings on the format `"#RRGGBBAA"`
55+
* - strings on the format `"rgb(255, 255, 255)"`
56+
* - strings on the format `"rgb(255, 255, 255, 0.5)"`
57+
* - strings on the format `"rgb(255, 255, 255, 50%)"`
58+
* - strings on the format `"rgba(255, 255, 255, 0.5)"`
59+
* - strings on the format `"rgba(255, 255, 255, 50%)"`
60+
* - strings on the format `"hsl(134, 50%, 50%)"`
61+
* - strings on the format `"hsl(134, 50%, 50%, 0.5)"`
62+
* - strings on the format `"hsl(134, 50%, 50%, 50%)"`
63+
* - strings on the format `"hsla(134, 50%, 50%, 0.5)"`
64+
* - strings on the format `"hsla(134, 50%, 50%, 50%)"`
65+
* - strings on the format `"hwb(134, 50%, 50%)"`
66+
* - strings on the format `"hwb(134, 50%, 50%, 0.5)"`
67+
* - strings on the format `"hwb(134, 50%, 50%, 50%)"`
68+
* @type {string|number}
7069
*/
7170
CanvasContext.prototype.fillStyle = 0x000000ff;
7271

7372
/**
74-
* Saves the current state to the state stack.
75-
* @public
73+
* Saves the current drawing state to a stack. The state can later be restored by calling `CanvasContext.restore()`.
74+
*
75+
* The following state is included when being saved to the stack:
76+
* - Current transformation matrix
77+
* - Current fill style
7678
*/
7779
CanvasContext.prototype.save = function CanvasContext_save() {
7880
this._savedStates.push(canvasState.capture(this));
7981
};
8082

8183
/**
82-
* Restores the last saved state of the CanvasContext.
83-
* @public
84+
* Restores the last drawing state that was saved with `CanvasContext.save()`, and then removes it from the state stack.
8485
*/
8586
CanvasContext.prototype.restore = function CanvasContext_restore() {
8687
if (this._savedStates.length) {
@@ -89,16 +90,14 @@ CanvasContext.prototype.restore = function CanvasContext_restore() {
8990
};
9091

9192
/**
92-
* Resets the internal path buffer and begins a new path.
93-
* @public
93+
* Restores the current transformation to the identity matrix.
9494
*/
9595
CanvasContext.prototype.resetTransform = function CanvasContext_resetTransform() {
9696
this._transform = new Matrix(1, 0, 0, 1, 0, 0);
9797
};
9898

9999
/**
100100
* Multiplies the current transformation matrix with the specified values.
101-
* @public
102101
*/
103102
CanvasContext.prototype.transform = function CanvasContext_transform(a, b, c, d, e, f) {
104103
if (!Number.isFinite(a) ||
@@ -115,7 +114,6 @@ CanvasContext.prototype.transform = function CanvasContext_transform(a, b, c, d,
115114

116115
/**
117116
* Sets the transformation matrix to the specified matrix.
118-
* @public
119117
*/
120118
CanvasContext.prototype.setTransform = function CanvasContext_transform(a, b, c, d, e, f) {
121119
if (!Number.isFinite(a) ||
@@ -131,10 +129,9 @@ CanvasContext.prototype.setTransform = function CanvasContext_transform(a, b, c,
131129
};
132130

133131
/**
134-
* Applies a translation transformation to the CanvasContext.
132+
* Applies a translation transformation on top of the current transform.
135133
* @param {number} x Distance to move in the horizontal direction in pixels.
136134
* @param {number} y Distance to move in the vertical direction in pixels.
137-
* @public
138135
*/
139136
CanvasContext.prototype.translate = function CanvasContext_translate(x, y) {
140137
if (!Number.isFinite(x) || !Number.isFinite(y)) {
@@ -145,10 +142,9 @@ CanvasContext.prototype.translate = function CanvasContext_translate(x, y) {
145142
};
146143

147144
/**
148-
* Applies a scale transformation to the CanvasContext.
149-
* @param {number} x Scale in the horizontal direction. 1 means no scale.
150-
* @param {number} y Scale in the vertical direction. 1 means no scale.
151-
* @public
145+
* Applies a scale transformation on top of the current transform.
146+
* @param {number} x Scale in the horizontal direction. `1` means no horizontal scaling.
147+
* @param {number} y Scale in the vertical direction. `1` means no vertical scaling.
152148
*/
153149
CanvasContext.prototype.scale = function CanvasContext_scale(x, y) {
154150
if (!Number.isFinite(x) || !Number.isFinite(y)) {
@@ -159,9 +155,8 @@ CanvasContext.prototype.scale = function CanvasContext_scale(x, y) {
159155
};
160156

161157
/**
162-
* Applies a rotation transformation to the canvas around its current origo.
158+
* Applies a rotation transformation on top of the current transform around the current canvas origo.
163159
* @param {number} angle Angle in radians measured clockwise from the positive x axis.
164-
* @public
165160
*/
166161
CanvasContext.prototype.rotate = function CanvasContext_rotate(angle) {
167162
if (!Number.isFinite(angle)) {
@@ -173,15 +168,13 @@ CanvasContext.prototype.rotate = function CanvasContext_rotate(angle) {
173168

174169
/**
175170
* Removes all existing subpaths and begins a new path.
176-
* @public
177171
*/
178172
CanvasContext.prototype.beginPath = function CanvasContext_beginPath() {
179173
this._paths = [];
180174
};
181175

182176
/**
183177
* Starts a new subpath that begins in the same point as the start and end point of the previous one.
184-
* @public
185178
*/
186179
CanvasContext.prototype.closePath = function CanvasContext_closePath() {
187180
if (this._paths.length) {
@@ -204,7 +197,6 @@ CanvasContext.prototype.closePath = function CanvasContext_closePath() {
204197
* Begins a new subpath by moving the cursor to the specified position.
205198
* @param {number} x X coordinate.
206199
* @param {number} y Y coordinate.
207-
* @public
208200
*/
209201
CanvasContext.prototype.moveTo = function CanvasContext_moveTo(x, y) {
210202
if (!Number.isFinite(x) || !Number.isFinite(y)) {
@@ -219,7 +211,6 @@ CanvasContext.prototype.moveTo = function CanvasContext_moveTo(x, y) {
219211
* Inserts an edge between the last and specified position.
220212
* @param {number} x Target X coordinate.
221213
* @param {number} y Target Y coordinate.
222-
* @public
223214
*/
224215
CanvasContext.prototype.lineTo = function CanvasContext_lineTo(x, y) {
225216
if (!Number.isFinite(x) || !Number.isFinite(y)) {
@@ -243,7 +234,7 @@ CanvasContext.prototype.lineTo = function CanvasContext_lineTo(x, y) {
243234
* @param {number} radius Radius of the arc.
244235
* @param {number} startAngle The angle in radians at which the arc starts, measured clockwise from the positive x axis.
245236
* @param {number} endAngle The angle in radians at which the arc end, measured clockwise from the positive x axis.
246-
* @param {Boolean} anticlockwise Specifies whether the arc will be drawn counter clockwise. Default is clockwise.
237+
* @param {boolean} [anticlockwise] Specifies whether the arc will be drawn counter clockwise. Default is clockwise.
247238
*/
248239
CanvasContext.prototype.arc = function CanvasContext_arc(x, y, radius, startAngle, endAngle, anticlockwise) {
249240
if (!Number.isFinite(x) || !Number.isFinite(y) ||
@@ -304,12 +295,11 @@ CanvasContext.prototype.arc = function CanvasContext_arc(x, y, radius, startAngl
304295
};
305296

306297
/**
307-
* Fills the specified rectangle with fully transparent black without affecting the current paths.
298+
* Fills a specified rectangle with fully transparent black without blending with the background or affecting the current paths.
308299
* @param {number} x X coordinate of the left side of the rectangle.
309300
* @param {number} y Y coordinate of the top of the rectangle.
310301
* @param {number} width Width of the rectangle.
311302
* @param {number} height Height of the rectangle.
312-
* @public
313303
*/
314304
CanvasContext.prototype.clearRect = function CanvasContext_clearRect(x, y, width, height) {
315305
var fullCanvas = false;
@@ -336,12 +326,11 @@ CanvasContext.prototype.clearRect = function CanvasContext_clearRect(x, y, width
336326
};
337327

338328
/**
339-
* Fills the specified rectangle without affecting the current paths.
329+
* Fills a specified rectangle without affecting the current paths.
340330
* @param {number} x X coordinate of the left side of the rectangle.
341331
* @param {number} y Y coordinate of the top of the rectangle.
342332
* @param {number} width Width of the rectangle.
343333
* @param {number} height Height of the rectangle.
344-
* @public
345334
*/
346335
CanvasContext.prototype.fillRect = function CanvasContext_fillRect(x, y, width, height) {
347336
var fillColor = colorUtils.parse(this.fillStyle);
@@ -379,9 +368,8 @@ CanvasContext.prototype._fillRect = function CanvasContext__fillRect(fillColor,
379368
/**
380369
* Fills the defined paths.
381370
* @param {string} [windingRule] The winding rule to be used for determining
382-
* which areas are covered by the current path. Valid values are "evenodd" and
383-
* "nonzero". Default is "nonzero".
384-
* @public
371+
* which areas are covered by the current path. Valid values are "evenodd" and
372+
* "nonzero". Default is `"nonzero"`.
385373
*/
386374
CanvasContext.prototype.fill = function CanvasContext_fill(windingRule) {
387375
var id = this._edges.nextId++;

lib/canvasState.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
/**
3030
* Captures the current state of a specified canvas context.
3131
* @param {CanvasContext} ctx Canvas context whose state will be captured.
32-
* @public
3332
*/
3433
function canvasState_capture(ctx) {
3534
return {
@@ -42,7 +41,6 @@ function canvasState_capture(ctx) {
4241
* Restores the specified canvas state.
4342
* @param {CanvasContext} ctx Canvas context whose state will be restored.
4443
* @param {CanvasState} state State to restore.
45-
* @public
4644
*/
4745
function canvasState_restore(ctx, state) {
4846
ctx.fillStyle = state.fillStyle;

0 commit comments

Comments
 (0)