Skip to content

Commit 4f701d3

Browse files
committed
feat: add createParticle jsdoc
1 parent 473f643 commit 4f701d3

File tree

9 files changed

+83
-40
lines changed

9 files changed

+83
-40
lines changed

build/proton.d.ts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -700,21 +700,30 @@ declare class Span {
700700
getValue(isInt?: boolean): number;
701701
}
702702

703+
/**
704+
* Represents an ArraySpan, a subclass of Span that works with arrays.
705+
* @extends Span
706+
*/
703707
declare class ArraySpan extends Span {
704708
/**
705-
* Make sure that the color is an instance of Proton.ArraySpan, if not it makes a new instance
706-
*
707-
* @method setSpanValue
708-
* @memberof Proton#Proton.Color
709-
* @instance
710-
*
711-
* @param {Proton.Particle} particle
712-
* @param {Number} the integrate time 1/ms
713-
* @param {Int} the particle index
709+
* Creates an ArraySpan instance from the given array.
710+
* If the input is already an ArraySpan instance, it returns the input.
711+
* @static
712+
* @param {Array|ArraySpan|any} arr - The array or ArraySpan instance.
713+
* @returns {ArraySpan|null} A new ArraySpan instance or null if the input is falsy.
714+
*/
715+
static createArraySpan(arr: any[] | ArraySpan | any): ArraySpan | null;
716+
/**
717+
* Creates an instance of ArraySpan.
718+
* @param {Array|*|any} arr - The array or value to be converted to an array.
714719
*/
715-
static createArraySpan(arr: any): ArraySpan | null;
716-
constructor(color: any);
720+
constructor(arr: any[] | any | any);
717721
_arr: any;
722+
/**
723+
* Gets a random value from the array.
724+
* If the value is "random" or "Random", it returns a random color.
725+
* @returns {*} A random value from the array or a random color.
726+
*/
718727
getValue(): any;
719728
}
720729

@@ -1035,11 +1044,11 @@ declare class Radius extends Initialize {
10351044
declare class Body extends Initialize {
10361045
/**
10371046
* Creates a new Body instance.
1038-
* @param {string|object|ArraySpan} image - The image source or object to use for the particle body.
1047+
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to use for the particle body.
10391048
* @param {number} [w=20] - The width of the particle body.
10401049
* @param {number} [h] - The height of the particle body. Defaults to the width if not provided.
10411050
*/
1042-
constructor(image: string | object | ArraySpan, w?: number, h?: number);
1051+
constructor(image: string | object | (new (width?: number, height?: number) => HTMLImageElement) | HTMLImageElement | ArraySpan, w?: number, h?: number);
10431052
/**
10441053
* @type {ArraySpan}
10451054
* @private
@@ -1058,7 +1067,7 @@ declare class Body extends Initialize {
10581067
initialize(particle: object): void;
10591068
/**
10601069
* Sets the span value for the image.
1061-
* @param {string|object|ArraySpan} image - The image source or object to set as span value.
1070+
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to set as span value.
10621071
* @returns {ArraySpan} The ArraySpan instance.
10631072
* @private
10641073
*/
@@ -1840,13 +1849,25 @@ declare class Emitter$1 extends Particle$1 {
18401849
dispatch(event: any, target: any): void;
18411850
emitting(time: any): void;
18421851
/**
1843-
* create single particle;
1852+
* Creates a single particle.
18441853
*
1845-
* can use emit({x:10},new Gravity(10),{'particleUpdate',fun}) or emit([{x:10},new Initialize],new Gravity(10),{'particleUpdate',fun})
1846-
* @method removeAllParticles
1854+
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
1855+
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
1856+
* @returns {Particle} The created particle.
1857+
*
1858+
*/
1859+
createParticle(initialize?: Object | any[], behaviour?: Object | any[]): Particle$1;
1860+
/**
1861+
* Sets up a particle with initialization and behavior.
1862+
*
1863+
* @param {Particle} particle - The particle to set up.
1864+
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
1865+
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
1866+
*/
1867+
setupParticle(particle: Particle$1, initialize?: Object | any[], behaviour?: Object | any[]): void;
1868+
/**
1869+
* Removes all particles and stops the emitter.
18471870
*/
1848-
createParticle(initialize: any, behaviour: any): any;
1849-
setupParticle(particle: any, initialize: any, behaviour: any): void;
18501871
remove(): void;
18511872
}
18521873

build/proton.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/proton.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/proton.web.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/proton.web.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "proton-engine",
3-
"version": "7.1.1",
3+
"version": "7.1.3",
44
"description": "Proton is a simple and powerful javascript particle animation engine.",
55
"keywords": [
66
"particle",

src/emitter/Emitter.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ export default class Emitter extends Particle {
268268
}
269269

270270
/**
271-
* create single particle;
271+
* Creates a single particle.
272+
*
273+
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
274+
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
275+
* @returns {Particle} The created particle.
272276
*
273-
* can use emit({x:10},new Gravity(10),{'particleUpdate',fun}) or emit([{x:10},new Initialize],new Gravity(10),{'particleUpdate',fun})
274-
* @method removeAllParticles
275277
*/
276278
createParticle(initialize, behaviour) {
277279
const particle = this.parent.pool.get(Particle);
@@ -281,6 +283,13 @@ export default class Emitter extends Particle {
281283
return particle;
282284
}
283285

286+
/**
287+
* Sets up a particle with initialization and behavior.
288+
*
289+
* @param {Particle} particle - The particle to set up.
290+
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
291+
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
292+
*/
284293
setupParticle(particle, initialize, behaviour) {
285294
let initializes = this.initializes;
286295
let behaviours = this.behaviours;
@@ -296,6 +305,9 @@ export default class Emitter extends Particle {
296305
this.particles.push(particle);
297306
}
298307

308+
/**
309+
* Removes all particles and stops the emitter.
310+
*/
299311
remove() {
300312
this.stop();
301313
Util.destroyAll(this.particles);

src/initialize/Body.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class Body extends Initialize {
2020

2121
/**
2222
* Creates a new Body instance.
23-
* @param {string|object|ArraySpan} image - The image source or object to use for the particle body.
23+
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to use for the particle body.
2424
* @param {number} [w=20] - The width of the particle body.
2525
* @param {number} [h] - The height of the particle body. Defaults to the width if not provided.
2626
*/
@@ -55,7 +55,7 @@ export default class Body extends Initialize {
5555

5656
/**
5757
* Sets the span value for the image.
58-
* @param {string|object|ArraySpan} image - The image source or object to set as span value.
58+
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to set as span value.
5959
* @returns {ArraySpan} The ArraySpan instance.
6060
* @private
6161
*/

src/math/ArraySpan.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,36 @@ import Span from "./Span";
22
import Util from "../utils/Util";
33
import MathUtil from "./MathUtil";
44

5+
/**
6+
* Represents an ArraySpan, a subclass of Span that works with arrays.
7+
* @extends Span
8+
*/
59
export default class ArraySpan extends Span {
6-
constructor(color) {
10+
/**
11+
* Creates an instance of ArraySpan.
12+
* @param {Array|*|any} arr - The array or value to be converted to an array.
13+
*/
14+
constructor(arr) {
715
super();
8-
this._arr = Util.toArray(color);
16+
this._arr = Util.toArray(arr);
917
}
1018

19+
/**
20+
* Gets a random value from the array.
21+
* If the value is "random" or "Random", it returns a random color.
22+
* @returns {*} A random value from the array or a random color.
23+
*/
1124
getValue() {
1225
const val = Util.getRandFromArray(this._arr);
1326
return val === "random" || val === "Random" ? MathUtil.randomColor() : val;
1427
}
1528

1629
/**
17-
* Make sure that the color is an instance of Proton.ArraySpan, if not it makes a new instance
18-
*
19-
* @method setSpanValue
20-
* @memberof Proton#Proton.Color
21-
* @instance
22-
*
23-
* @param {Proton.Particle} particle
24-
* @param {Number} the integrate time 1/ms
25-
* @param {Int} the particle index
30+
* Creates an ArraySpan instance from the given array.
31+
* If the input is already an ArraySpan instance, it returns the input.
32+
* @static
33+
* @param {Array|ArraySpan|any} arr - The array or ArraySpan instance.
34+
* @returns {ArraySpan|null} A new ArraySpan instance or null if the input is falsy.
2635
*/
2736
static createArraySpan(arr) {
2837
if (!arr) return null;
@@ -31,3 +40,4 @@ export default class ArraySpan extends Span {
3140
else return new ArraySpan(arr);
3241
}
3342
}
43+

0 commit comments

Comments
 (0)