Skip to content

Commit cae2897

Browse files
committed
jsdoc追加。
1 parent b59f2f5 commit cae2897

11 files changed

Lines changed: 598 additions & 567 deletions

File tree

chickenpaint/js/chickenpaint.js

Lines changed: 266 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chickenpaint/js/chickenpaint.min.js

Lines changed: 266 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/engine/CPArtwork.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,6 +3139,10 @@ export default class CPArtwork extends EventEmitter {
31393139
}
31403140
}
31413141

3142+
/**
3143+
* @class
3144+
* @extends {CPUndo}
3145+
*/
31423146
class CPActionTransformSelection extends CPUndo {
31433147
constructor() {
31443148
super();
@@ -3187,8 +3191,8 @@ export default class CPArtwork extends EventEmitter {
31873191
*
31883192
* We either have these full undos which cover the whole layer area:
31893193
*
3190-
* @property {?CPColorBmp} imageUndo
3191-
* @property {?CPGreyBmp} maskUndo
3194+
* @property {?CPColorBmp} [imageUndo]
3195+
* @property {?CPGreyBmp} [maskUndo]
31923196
*
31933197
* Or else we have this map from rectangles to images which cover the dirtied areas only.
31943198
*

js/engine/CPChiAutosaveDB.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function performAction(mode, callback) {
6161
/**
6262
* データ消失防止のためDBに保存 (Save)
6363
* 画像データとパレットデータを保存する
64-
* @param {Uint8Array} bytes - .chi形式のバイナリ
64+
* @param {Blob} bytes - .chi形式のBlobデータ
6565
* @param {Blob|null} swatchesBlob - パレットのBlobデータ
6666
*/
6767
export async function CPPutChiAutosaveToDB(bytes, swatchesBlob) {

js/engine/CPChibiFile.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,15 @@ class ChibiLayerDecoder {
138138

139139
this.colorDecoder = null;
140140
this.maskDecoder = null;
141+
/** @type {boolean} */
142+
this.clip = false;
141143
}
142144

145+
/**
146+
* @returns {CPImageLayer|void}
147+
*/
148+
createLayer() {}
149+
143150
readFixedHeader(stream) {
144151
this.payloadOffset = stream.readU32BE();
145152

@@ -754,12 +761,6 @@ function hasChibiMagicMarker(array) {
754761
return true;
755762
}
756763

757-
/**
758-
* @typedef {Object} SerializeResult
759-
* @property {(Blob|Uint8Array)} SerializeResult.bytes - A Blob when called in the browser, or a Uint8Array in Node.
760-
* @property {String} SerializeResult.version - Version string of created artwork, "ChibiPaint v0.0" or "ChickenPaint v0.10"
761-
*/
762-
763764
// ループの合間に「ブラウザに息をつかせる」関数
764765
const yieldToMain = () => {
765766
return new Promise((resolve) => {
@@ -768,11 +769,16 @@ const yieldToMain = () => {
768769
channel.port2.postMessage(undefined);
769770
});
770771
};
772+
771773
/**
772774
* Serialize the given artwork to Chibifile format.
775+
* @typedef {Object} SerializeResult
776+
* @property {(Blob)} SerializeResult.bytes - A Blob when called in the browser, or a Uint8Array in Node.
777+
* @property {String} SerializeResult.version - Version string of created artwork, "ChibiPaint v0.0" or "ChickenPaint v0.10"
773778
*
774779
* @param {CPArtwork} artwork
775780
* @param {?Object} options
781+
* @param {Object} [options] -
776782
* @param {boolean} options.forceOldVersion - Mark this as a version 0.0 (ChibiPaint) drawing even if it uses new features
777783
*
778784
* @returns {Promise.<SerializeResult>}

js/engine/CPColorBmp.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,22 +485,32 @@ CPColorBmp.prototype.createThumbnailFrom = function (that) {
485485
* - expandBy: 塗りつぶし範囲を拡張するピクセル数
486486
* - alpha255: 不透明度 (1-255)
487487
* - mergedData: 判定用に渡す全レイヤー合成結果 (Uint8ClampedArray)
488-
* null の場合は現在のレイヤーを基準にする
488+
* 空のオブジェクトの場合は現在のレイヤーを基準にする
489+
*
490+
* @param {number} x - 塗りつぶしを開始するX座標
491+
* @param {number} y - 塗りつぶしを開始するY座標
492+
* @param {number} fillColor - 塗りつぶす色(0xRRGGBB 形式の数値)
493+
* @param {number} [expandBy=2] - 塗りつぶした領域を外側に拡張するピクセル数(縁取りの太さ)
494+
* @param {number} [alpha255=255] - 塗りつぶす色の不透明度(0〜255)
495+
* @param {Object} [fusion={}] - 統合画像の情報を含むオブジェクト
496+
* @param {Uint8Array|Uint8ClampedArray} [fusion.data] - 塗りつぶし対象の判定元として使用する画像データ。未指定の場合は自身の `data` を参照。
497+
* @returns {void}
489498
*/
499+
490500
CPColorBmp.prototype.floodFillWithBorder = function (
491501
x,
492502
y,
493503
fillColor,
494504
expandBy = 2,
495505
alpha255 = 255,
496-
fusion = null,
506+
fusion = {},
497507
) {
498508
if (!this.isInside(x, y)) return;
499509

500510
const w = this.width;
501511
const h = this.height;
502512
const data = this.data; // 書き込み先
503-
const srcData = fusion ? fusion.data : data; // 判定元
513+
const srcData = fusion && fusion.data ? fusion.data : data; // 判定元
504514
const BYTES = CPColorBmp.BYTES_PER_PIXEL;
505515

506516
const fillR = (fillColor >> 16) & 0xff;
@@ -539,7 +549,9 @@ CPColorBmp.prototype.floodFillWithBorder = function (
539549

540550
// flood fill 本体
541551
while (stack.length) {
542-
const { x: px, y: py } = stack.pop();
552+
const { x: px, y: py } = /** @type {{x: number, y: number}} */ (
553+
stack.pop()
554+
);
543555
if (!comparePixel(px, py)) continue;
544556

545557
Processed[py * w + px] = 1;
@@ -2087,8 +2099,9 @@ CPColorBmp.prototype.getNonTransparentBounds = function (initialBounds) {
20872099
/**
20882100
* Returns a new canvas with a rotated version of the given canvas.
20892101
*
2090-
* @param {HTMLCanvasElement} canvas
2102+
* @param {any} canvas
20912103
* @param {number} rotation - [0..3], selects a multiple of 90 degrees of clockwise rotation to be applied.
2104+
* @return {any}
20922105
*/
20932106
export function getRotatedCanvas(canvas, rotation) {
20942107
rotation = rotation % 4;
@@ -2165,7 +2178,7 @@ CPColorBmp.prototype.getAsCanvas = function (rotation) {
21652178
* Rotation is [0..3] and selects a multiple of 90 degrees of clockwise rotation to be applied, or 0 to leave
21662179
* unrotated.
21672180
*
2168-
* @returns {string} - "Binary string" representation of the PNG file
2181+
* @returns {string|false} - "Binary string" representation of the PNG file
21692182
*/
21702183
CPColorBmp.prototype.getAsPNG = function (rotation) {
21712184
let canvas = this.getAsCanvas(rotation);
@@ -2182,6 +2195,7 @@ CPColorBmp.prototype.getAsPNG = function (rotation) {
21822195
* @returns {Buffer}
21832196
*/
21842197
CPColorBmp.prototype.getAsPNGBuffer = function (rotation) {
2198+
/** @type {any} */
21852199
let canvas = this.getAsCanvas(rotation);
21862200

21872201
// API provided by node-canvas for running on Node (browsers don't support this)
@@ -2233,7 +2247,7 @@ CPColorBmp.prototype.hasAlpha = function () {
22332247
/**
22342248
* Create from a loaded HTML Image object
22352249
*
2236-
* @param {HTMLImageElement} image
2250+
* @param {any} image
22372251
*/
22382252
CPColorBmp.createFromImage = function (image) {
22392253
var imageCanvas = createCanvas(image.width, image.height),

js/engine/CPGreyBmp.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ CPGreyBmp.prototype.floodFillWithBorder = function (
204204
const stack = [{ x, y }];
205205

206206
while (stack.length) {
207-
const { x: px, y: py } = stack.pop();
207+
const { x: px, y: py } = /** @type {{x: number, y: number}} */ (
208+
stack.pop()
209+
);
208210
if (px < 0 || py < 0 || px >= w || py >= h) continue;
209211
const idx = py * w + px;
210212
if (Processed[idx]) continue;
@@ -380,7 +382,7 @@ CPGreyBmp.prototype.getAsCanvas = function (imageRotation) {
380382
* @param {number} width
381383
* @param {number} height
382384
*
383-
* @returns {ImageData}
385+
* @returns {any}
384386
*/
385387
CPGreyBmp.prototype.getImageData = function (x, y, width, height) {
386388
let imageData = createImageData(width, height),
@@ -615,7 +617,7 @@ function boxBlurLine(src, dst, len, radius) {
615617
* @param {number} x X-coordinate of column
616618
* @param {number} y Y-coordinate of top of column to copy
617619
* @param {number} len Number of pixels to copy
618-
* @param {TypedArray} buffer Pixel array
620+
* @param {Uint8Array|Uint8ClampedArray} buffer Pixel array
619621
*/
620622
CPGreyBmp.prototype.copyPixelColumnToArray = function (x, y, len, buffer) {
621623
var yJump = this.width,
@@ -636,7 +638,7 @@ CPGreyBmp.prototype.copyPixelColumnToArray = function (x, y, len, buffer) {
636638
* @param {number} x X-coordinate of column
637639
* @param {number} y Y-coordinate of top of column to copy
638640
* @param {number} len Number of pixels to copy
639-
* @param {TypedArray} buffer Pixel array to copy from
641+
* @param {Uint8Array|Uint8ClampedArray} buffer Pixel array to copy from
640642
*/
641643
CPGreyBmp.prototype.copyArrayToPixelColumn = function (x, y, len, buffer) {
642644
var yJump = this.width,
@@ -760,7 +762,6 @@ CPGreyBmp.prototype.monoHalftone = function (
760762

761763
const w = this.width;
762764
const h = this.height;
763-
const B = CPGreyBmp.BYTES_PER_PIXEL; // = 1
764765

765766
const src = new Uint8ClampedArray(this.data);
766767
const dst = new Uint8ClampedArray(this.data.length);

js/engine/CPImageLayer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ import CPRect from "../util/CPRect.js";
4242
*
4343
* @constructor
4444
* @extends CPLayer
45-
* @this{typeof CPImageLayer
46-
* & Record<string, any>}
45+
* @this {any}
4746
*/
4847
export default class CPImageLayer extends CPLayer {
4948
constructor(width, height, name) {

js/engine/CPLayer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ CPLayer.prototype.copyFrom = function (layer) {
159159
}
160160
};
161161

162+
/**
163+
* @memberof CPLayer
164+
* @param {CPGreyBmp|null} mask
165+
*/
162166
CPLayer.prototype.setMask = function (mask) {
163167
this.mask = mask;
164168
if (!mask) {

js/engine/CPResourceSaver.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,17 @@ export default class CPResourceSaver extends EventEmitter {
248248
const savedb = save_options.savedb ?? false;
249249
const savedbFromMenu = save_options.savedbFromMenu ?? false;
250250

251-
var flat, flatBlob, swatchesBlob;
252-
253-
flat = !savedb
254-
? binaryStringToByteArray(options.artwork.getFlatPNG(options.rotation))
255-
: null;
256-
flatBlob = !savedb ? new Blob([flat], { type: "image/png" }) : null;
257-
flat = null; // Don't need this any more
258-
251+
let flat = null;
252+
let flatBlob = null;
253+
let swatchesBlob;
259254
if (!savedb) {
255+
flat = binaryStringToByteArray(
256+
options.artwork.getFlatPNG(options.rotation),
257+
);
258+
flatBlob = new Blob([flat], { type: "image/png" });
260259
reportProgress(0.3); // 開始
261260
}
261+
flat = null; // Don't need this any more
262262

263263
var serializeLayers;
264264

@@ -280,9 +280,12 @@ export default class CPResourceSaver extends EventEmitter {
280280
if (options.swatches) {
281281
var aco = new AdobeColorTable();
282282

283-
swatchesBlob = new Blob([aco.write(options.swatches)], {
284-
type: "application/octet-stream",
285-
});
283+
swatchesBlob = new Blob(
284+
[/** @type {any} */ (aco.write(options.swatches))],
285+
{
286+
type: "application/octet-stream",
287+
},
288+
);
286289
} else {
287290
swatchesBlob = null;
288291
}
@@ -300,7 +303,6 @@ export default class CPResourceSaver extends EventEmitter {
300303

301304
if (chibiResult) {
302305
formData.append("chibifileFormat", chibiResult.version);
303-
304306
formData.append("chibifile", chibiResult.bytes);
305307
chibiResult = null;
306308

0 commit comments

Comments
 (0)