diff --git a/CHANGES.MD b/CHANGES.MD index a26e510..b89b2a2 100644 --- a/CHANGES.MD +++ b/CHANGES.MD @@ -1,11 +1,16 @@ +## 2.3.1 + +Fix busted build with evergreen browsers (oops!). + ## 2.3.0 Update build to use rollup, there are now 3 supported bunldes: -- fireworks.js - cjs module +- fireworks.node.js - cjs module - fireworks.mjs - es6 module -- fireworks.umd.js - browser umd bundle +- fireworks.js - browser umd bundle +- fireworks.min.js - browser umd bundle (minified) The browser bundle now has a target of `es3` so it should support older browsers. diff --git a/README.MD b/README.MD index df6d831..9e6b8af 100644 --- a/README.MD +++ b/README.MD @@ -17,7 +17,7 @@ import * as Fireworks from 'fireworks-canvas' // mjs const Fireworks = require('fireworks-canvas') // cjs -define(['fireworks'], (Fireworks) => {}) // amd +requirejs(['Fireworks'], (Fireworks) => {}) // amd const Fireworks = window.Fireworks // browser global diff --git a/fireworks.js b/fireworks.js index bb8dde0..a1195f6 100644 --- a/fireworks.js +++ b/fireworks.js @@ -18,20 +18,6 @@ See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ - /* global Reflect, Promise */ - - var extendStatics = function(d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - - function __extends(d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; @@ -141,18 +127,31 @@ return Particle; }()); - var Things = (function (_super) { - __extends(Things, _super); + var Things = (function () { function Things(_a) { var maxRockets = _a.maxRockets, numParticles = _a.numParticles, cw = _a.cw, ch = _a.ch; - var _this = _super.call(this) || this; - _this.rockets = 0; - _this.maxRockets = maxRockets; - _this.numParticles = numParticles; - _this.cw = cw; - _this.ch = ch; - return _this; + this._set = new Set(); + this.rockets = 0; + this.maxRockets = maxRockets; + this.numParticles = numParticles; + this.cw = cw; + this.ch = ch; } + Things.prototype.size = function () { + return this._set.size; + }; + Things.prototype.entries = function () { + return this._set; + }; + Things.prototype.clear = function () { + this._set.clear(); + }; + Things.prototype["delete"] = function (thing) { + this._set["delete"](thing); + }; + Things.prototype.add = function (thing) { + this._set.add(thing); + }; Things.prototype.explode = function (particle) { this.rockets--; for (var i = 0; i < this.numParticles; i += 1) { @@ -176,7 +175,7 @@ } }; return Things; - }(Set)); + }()); var Fireworks = (function () { function Fireworks(container, _a) { @@ -208,7 +207,7 @@ Fireworks.prototype.start = function () { var _this = this; if (this.maxRockets > 0) { - this.interval = setInterval(function () { return _this.things.spawnRockets(); }, this.rocketSpawnInterval); + this.interval = window.setInterval(function () { return _this.things.spawnRockets(); }, this.rocketSpawnInterval); this.rafInterval = window.requestAnimationFrame(function () { return _this.update(); }); } return function () { return _this.stop(); }; @@ -243,7 +242,7 @@ var e_1, _a; this._clear(); try { - for (var _b = __values(this.things), _c = _b.next(); !_c.done; _c = _b.next()) { + for (var _b = __values(this.things.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { var particle = _c.value; particle.draw(this.ctx); particle.update(); @@ -262,7 +261,7 @@ } finally { if (e_1) throw e_1.error; } } - if (this.interval || this.things.size > 0) { + if (this.interval || this.things.size() > 0) { this.rafInterval = window.requestAnimationFrame(function () { return _this.update(); }); } else { diff --git a/fireworks.min.js b/fireworks.min.js index 3b69f70..b53c830 100644 --- a/fireworks.min.js +++ b/fireworks.min.js @@ -1 +1 @@ -!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define("Fireworks",i):t.Fireworks=i()}(this,function(){"use strict";var t=function(i,s){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var s in i)i.hasOwnProperty(s)&&(t[s]=i[s])})(i,s)};function i(t,i){return Math.random()*(i-t)+t}var s=2*Math.PI,o=function(){function t(t){var o=t.isRocket,n=void 0!==o&&o,e=t.hue,h=void 0===e?i(1,360):e,r=t.brightness,a=void 0===r?i(50,60):r,c=t.position;if(this.isRocket=n,this.position=c,this.positions=[this.position,this.position,this.position],this.isRocket)this.velocity={x:i(-3,3),y:i(-7,-3)},this.shrink=.999,this.resistance=1;else{var p=i(0,s),l=15*Math.cos(i(0,s));this.velocity={x:Math.cos(p)*l,y:Math.sin(p)*l},this.shrink=i(0,.05)+.93,this.resistance=.92}this.gravity=.01,this.size=3,this.alpha=1,this.fade=0,this.hue=h,this.brightness=a}return t.prototype.clone=function(){return new t({position:{x:this.position.x,y:this.position.y},hue:this.hue,brightness:this.brightness})},t.prototype.shouldRemove=function(t,i){return this.alpha<=.1||this.size<=1||(this.position.x>t||this.position.x<0||(this.position.y>i||this.position.y<0))},t.prototype.shouldExplode=function(t,s,o){return!!this.isRocket&&(this.position.y<=t||!(this.position.y>=s)&&i(0,1)<=o)},t.prototype.update=function(){this.positions.pop(),this.positions.unshift({x:this.position.x,y:this.position.y}),this.velocity.x*=this.resistance,this.velocity.y*=this.resistance,this.velocity.y+=this.gravity,this.position.x+=this.velocity.x,this.position.y+=this.velocity.y,this.size*=this.shrink,this.alpha-=this.fade},t.prototype.draw=function(t){var i=this.positions[this.positions.length-1];t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(this.position.x,this.position.y),t.lineWidth=this.size,t.strokeStyle="hsla("+this.hue+", 100%, "+this.brightness+"%, "+this.alpha+")",t.stroke()},t}(),n=function(s){function n(t){var i=t.maxRockets,o=t.numParticles,n=t.cw,e=t.ch,h=s.call(this)||this;return h.rockets=0,h.maxRockets=i,h.numParticles=o,h.cw=n,h.ch=e,h}return function(i,s){function o(){this.constructor=i}t(i,s),i.prototype=null===s?Object.create(s):(o.prototype=s.prototype,new o)}(n,s),n.prototype.explode=function(t){this.rockets--;for(var i=0;i0&&(this.interval=setInterval(function(){return t.things.spawnRockets()},this.rocketSpawnInterval),this.rafInterval=window.requestAnimationFrame(function(){return t.update()})),function(){return t.stop()}},t.prototype.stop=function(){window.clearInterval(this.interval),this.interval=null},t.prototype.kill=function(){this.things.clear(),this.stop(),window.cancelAnimationFrame(this.rafInterval),this.rafInterval=null,this._clear(!0)},t.prototype.fire=function(){var t=this;this.things.spawnRocket(),this.rafInterval||(this.rafInterval=window.requestAnimationFrame(function(){return t.update()}))},t.prototype._clear=function(t){void 0===t&&(t=!1),this.ctx.globalCompositeOperation="destination-out",this.ctx.fillStyle="rgba(0, 0, 0 "+(t?"":", 0.5")+")",this.ctx.fillRect(0,0,this.cw,this.ch),this.ctx.globalCompositeOperation="lighter"},t.prototype.update=function(){var t,i,s=this;this._clear();try{for(var o=function(t){var i="function"==typeof Symbol&&t[Symbol.iterator],s=0;return i?i.call(t):{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}}}(this.things),n=o.next();!n.done;n=o.next()){var e=n.value;e.draw(this.ctx),e.update(),e.shouldRemove(this.cw,this.ch)?this.things.delete(e):e.shouldExplode(this.max_h,this.min_h,this.chance)&&this.things.explode(e)}}catch(i){t={error:i}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}this.interval||this.things.size>0?this.rafInterval=window.requestAnimationFrame(function(){return s.update()}):(this._clear(!0),this.rafInterval=null)},t}()}); +!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define("Fireworks",i):t.Fireworks=i()}(this,function(){"use strict";function t(t,i){return Math.random()*(i-t)+t}var i=2*Math.PI,s=function(){function s(s){var e=s.isRocket,n=void 0!==e&&e,o=s.hue,h=void 0===o?t(1,360):o,r=s.brightness,a=void 0===r?t(50,60):r,c=s.position;if(this.isRocket=n,this.position=c,this.positions=[this.position,this.position,this.position],this.isRocket)this.velocity={x:t(-3,3),y:t(-7,-3)},this.shrink=.999,this.resistance=1;else{var p=t(0,i),l=15*Math.cos(t(0,i));this.velocity={x:Math.cos(p)*l,y:Math.sin(p)*l},this.shrink=t(0,.05)+.93,this.resistance=.92}this.gravity=.01,this.size=3,this.alpha=1,this.fade=0,this.hue=h,this.brightness=a}return s.prototype.clone=function(){return new s({position:{x:this.position.x,y:this.position.y},hue:this.hue,brightness:this.brightness})},s.prototype.shouldRemove=function(t,i){return this.alpha<=.1||this.size<=1||(this.position.x>t||this.position.x<0||(this.position.y>i||this.position.y<0))},s.prototype.shouldExplode=function(i,s,e){return!!this.isRocket&&(this.position.y<=i||!(this.position.y>=s)&&t(0,1)<=e)},s.prototype.update=function(){this.positions.pop(),this.positions.unshift({x:this.position.x,y:this.position.y}),this.velocity.x*=this.resistance,this.velocity.y*=this.resistance,this.velocity.y+=this.gravity,this.position.x+=this.velocity.x,this.position.y+=this.velocity.y,this.size*=this.shrink,this.alpha-=this.fade},s.prototype.draw=function(t){var i=this.positions[this.positions.length-1];t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(this.position.x,this.position.y),t.lineWidth=this.size,t.strokeStyle="hsla("+this.hue+", 100%, "+this.brightness+"%, "+this.alpha+")",t.stroke()},s}(),e=function(){function i(t){var i=t.maxRockets,s=t.numParticles,e=t.cw,n=t.ch;this._set=new Set,this.rockets=0,this.maxRockets=i,this.numParticles=s,this.cw=e,this.ch=n}return i.prototype.size=function(){return this._set.size},i.prototype.entries=function(){return this._set},i.prototype.clear=function(){this._set.clear()},i.prototype.delete=function(t){this._set.delete(t)},i.prototype.add=function(t){this._set.add(t)},i.prototype.explode=function(t){this.rockets--;for(var i=0;i0&&(this.interval=window.setInterval(function(){return t.things.spawnRockets()},this.rocketSpawnInterval),this.rafInterval=window.requestAnimationFrame(function(){return t.update()})),function(){return t.stop()}},t.prototype.stop=function(){window.clearInterval(this.interval),this.interval=null},t.prototype.kill=function(){this.things.clear(),this.stop(),window.cancelAnimationFrame(this.rafInterval),this.rafInterval=null,this._clear(!0)},t.prototype.fire=function(){var t=this;this.things.spawnRocket(),this.rafInterval||(this.rafInterval=window.requestAnimationFrame(function(){return t.update()}))},t.prototype._clear=function(t){void 0===t&&(t=!1),this.ctx.globalCompositeOperation="destination-out",this.ctx.fillStyle="rgba(0, 0, 0 "+(t?"":", 0.5")+")",this.ctx.fillRect(0,0,this.cw,this.ch),this.ctx.globalCompositeOperation="lighter"},t.prototype.update=function(){var t,i,s=this;this._clear();try{for(var e=function(t){var i="function"==typeof Symbol&&t[Symbol.iterator],s=0;return i?i.call(t):{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}}}(this.things.entries()),n=e.next();!n.done;n=e.next()){var o=n.value;o.draw(this.ctx),o.update(),o.shouldRemove(this.cw,this.ch)?this.things.delete(o):o.shouldExplode(this.max_h,this.min_h,this.chance)&&this.things.explode(o)}}catch(i){t={error:i}}finally{try{n&&!n.done&&(i=e.return)&&i.call(e)}finally{if(t)throw t.error}}this.interval||this.things.size()>0?this.rafInterval=window.requestAnimationFrame(function(){return s.update()}):(this._clear(!0),this.rafInterval=null)},t}()}); diff --git a/fireworks.mjs b/fireworks.mjs index f2501f6..0c7ce80 100644 --- a/fireworks.mjs +++ b/fireworks.mjs @@ -93,15 +93,30 @@ class Particle { } } -class Things extends Set { +class Things { constructor({ maxRockets, numParticles, cw, ch }) { - super(); + this._set = new Set(); this.rockets = 0; this.maxRockets = maxRockets; this.numParticles = numParticles; this.cw = cw; this.ch = ch; } + size() { + return this._set.size; + } + entries() { + return this._set; + } + clear() { + this._set.clear(); + } + delete(thing) { + this._set.delete(thing); + } + add(thing) { + this._set.add(thing); + } explode(particle) { this.rockets--; for (let i = 0; i < this.numParticles; i += 1) { @@ -154,7 +169,7 @@ class Fireworks { } start() { if (this.maxRockets > 0) { - this.interval = setInterval(() => this.things.spawnRockets(), this.rocketSpawnInterval); + this.interval = window.setInterval(() => this.things.spawnRockets(), this.rocketSpawnInterval); this.rafInterval = window.requestAnimationFrame(() => this.update()); } return () => this.stop(); @@ -184,7 +199,7 @@ class Fireworks { } update() { this._clear(); - for (const particle of this.things) { + for (const particle of this.things.entries()) { particle.draw(this.ctx); particle.update(); if (particle.shouldRemove(this.cw, this.ch)) { @@ -194,7 +209,7 @@ class Fireworks { this.things.explode(particle); } } - if (this.interval || this.things.size > 0) { + if (this.interval || this.things.size() > 0) { this.rafInterval = window.requestAnimationFrame(() => this.update()); } else { diff --git a/fireworks.node.js b/fireworks.node.js index 4fe29f9..5e76472 100644 --- a/fireworks.node.js +++ b/fireworks.node.js @@ -95,15 +95,30 @@ class Particle { } } -class Things extends Set { +class Things { constructor({ maxRockets, numParticles, cw, ch }) { - super(); + this._set = new Set(); this.rockets = 0; this.maxRockets = maxRockets; this.numParticles = numParticles; this.cw = cw; this.ch = ch; } + size() { + return this._set.size; + } + entries() { + return this._set; + } + clear() { + this._set.clear(); + } + delete(thing) { + this._set.delete(thing); + } + add(thing) { + this._set.add(thing); + } explode(particle) { this.rockets--; for (let i = 0; i < this.numParticles; i += 1) { @@ -156,7 +171,7 @@ class Fireworks { } start() { if (this.maxRockets > 0) { - this.interval = setInterval(() => this.things.spawnRockets(), this.rocketSpawnInterval); + this.interval = window.setInterval(() => this.things.spawnRockets(), this.rocketSpawnInterval); this.rafInterval = window.requestAnimationFrame(() => this.update()); } return () => this.stop(); @@ -186,7 +201,7 @@ class Fireworks { } update() { this._clear(); - for (const particle of this.things) { + for (const particle of this.things.entries()) { particle.draw(this.ctx); particle.update(); if (particle.shouldRemove(this.cw, this.ch)) { @@ -196,7 +211,7 @@ class Fireworks { this.things.explode(particle); } } - if (this.interval || this.things.size > 0) { + if (this.interval || this.things.size() > 0) { this.rafInterval = window.requestAnimationFrame(() => this.update()); } else { diff --git a/package.json b/package.json index 7c1bb5d..1723b49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fireworks-canvas", - "version": "2.3.0", + "version": "2.3.1", "description": "fireworks example", "browser": "./fireworks.min.js", "main": "./fireworks.node.js",