@erikwatson/snowfall 3.0.4 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- window.snowfall=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){const i=n(1),r=document.querySelector("#snow-container"),o=document.createElement("canvas"),a=o.getContext("2d");let d=i.create(0,.7),s=i.create(0,0),l=200,c=[],u="#0d0014",f="#8d90b7",h="#ffffff",y=1,g=.02;function p(t,e){(d=i.fromDegrees(t)).multiplyScalar(e)}function v(t,e){(s=i.fromDegrees(t)).multiplyScalar(e)}function m(){o.width=r.offsetWidth,o.height=r.offsetHeight,c=P(q())}function w(){c.forEach(t=>{b.x=s.x,b.y=s.y,b.multiplyScalar(t.size+t.random),t.pos.add(b),M.x=d.x,M.y=d.y,M.multiplyScalar(t.size+t.random),t.pos.add(M);const e=t.noise;S=i.create(y*Math.sin(g*x+e),0),t.pos.add(S),t.pos.x>o.width&&(t.pos.x=0),t.pos.x<0&&(t.pos.x=o.width),t.pos.y>o.height&&(t.pos.y=0,t.pos.x=Math.random()*o.width),t.pos.y<0&&(t.pos.y=o.height,t.pos.x=Math.random()*o.width)}),x+=1,function(){a.clearRect(0,0,o.width,o.height),u&&(a.fillStyle=u,a.fillRect(0,0,o.width,o.height));const t=c.filter(t=>t.size>=7),e=c.filter(t=>t.size<7);a.fillStyle=f,e.forEach(t=>{a.beginPath(),z(t.pos,t.size),a.fill()}),a.fillStyle=h,t.forEach(t=>{a.beginPath(),z(t.pos,t.size),a.fill()})}(),window.requestAnimationFrame(w)}let x=0;const b=i.create(0,0),M=i.create(0,0);let S=null;function P(t){let e=[];for(;t--;)e.push({pos:i.create(Math.random()*o.width,Math.random()*o.height),size:3+5*Math.random(),noise:10*Math.random(),amplitude:2*Math.random(),frequency:.01*Math.random(),random:Math.random()});return e}function q(){const t=o.width*o.height;return Math.round(l*(t/2073600))}function z(t,e){a.arc(t.x,t.y,e,0,2*Math.PI,!1)}t.exports={setAmplitude:function(t){y=t},setBackground:function(t){u=t},setDensity:function(t){l=t,c=P(q())},setFrequency:function(t){g=t},setGravity:p,setPrimary:function(t){f=t},setSecondary:function(t){h=t},setWind:v,start:function(t={}){void 0!==t.bg&&(u=t.bg),void 0!==t.primary&&(f=t.primary),void 0!==t.secondary&&(h=t.secondary),void 0!==t.density&&(l=t.density),void 0!==t.wave&&(void 0!==t.wave.amplitude&&(y=t.wave.amplitude),void 0!==t.wave.frequency&&(g=t.wave.frequency)),void 0!==t.gravity&&(void 0!==t.gravity.angle&&void 0!==t.gravity.strength&&p(t.gravity.angle,t.gravity.strength),void 0!==t.gravity.angle&&void 0===t.gravity.strength&&p(t.gravity.angle,.6),void 0===t.gravity.angle&&void 0!==t.gravity.strength&&p(90,t.gravity.strength)),void 0!==t.wind&&(void 0!==t.wind.angle&&void 0!==t.wind.strength&&v(t.wind.angle,t.wind.strength),void 0!==t.wind.angle&&void 0===t.wind.strength&&v(t.wind.angle,0),void 0===t.wind.angle&&void 0!==t.wind.strength&&v(0,t.wind.strength)),o.width=r.offsetWidth,o.height=r.offsetHeight,r.appendChild(o),c=P(q()),window.onresize=m,window.requestAnimationFrame(w)}}},function(t,e){function n(t,e){let r=t,o=e;const a=()=>Math.sqrt(r*r+o*o),d=t=>{r*=t,o*=t},s=()=>{let t=a();r/=t,o/=t};return{add:t=>{r+=t.x,o+=t.y},addScalar:t=>{r+=t,o+=t},clone:i,divide:t=>{r/=t.x,o/=t.y},divideScalar:t=>{r/=t,o/=t},dot:t=>r*t.x+o*t.y,getLength:a,getOpposite:t=>n(-t.x,-t.y),getPerp:()=>n(-o,r),isEqualTo:t=>r==t.x&&o==t.y,multiply:t=>{r*=t.x,o*=t.y},multiplyScalar:d,normalise:s,setLength:t=>{s(),d(t)},subtract:t=>{r-=t.x,o-=t.y},subtractScalar:t=>{r-=t,o-=t},set x(t){r=t},get x(){return r},set y(t){o=t},get y(){return o}}}const i=t=>n(t.x,t.y);t.exports={clone:i,create:n,fromDegrees:t=>{const e=t*(Math.PI/180);return n(Math.cos(e),Math.sin(e))}}}]);
1
+ window.snowfall=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){const i=n(1),{lerp:r}=n(2),o=document.querySelector("#snow-container"),a=document.createElement("canvas"),d=a.getContext("2d");let s=i.create(0,.7),l=i.create(0,0),c=200,u=[],f="#0d0014",g="#8d90b7",h="#ffffff",y=1,p=.02,v=!1,m=!1,w=!1;function x(e,t){(s=i.fromDegrees(e)).multiplyScalar(t)}function S(e,t){(l=i.fromDegrees(e)).multiplyScalar(t)}function b(){a.width=o.offsetWidth,a.height=o.offsetHeight,u=q(j())}function M(){w||(u.forEach(e=>{P.x=l.x,P.y=l.y,P.multiplyScalar(e.size+e.random),e.pos.add(P),O.x=s.x,O.y=s.y,O.multiplyScalar(e.size+e.random),e.pos.add(O);const t=e.noise;let n=i.create(y*Math.sin(p*z+t),0);e.pos.add(n),e.pos.x>a.width&&(e.pos.x=0),e.pos.x<0&&(e.pos.x=a.width),e.pos.y>a.height&&(e.pos.y=e.pos.y-a.height,e.pos.x=Math.random()*a.width),e.pos.y<0&&(e.pos.y=a.height-e.pos.y,e.pos.x=Math.random()*a.width),e.renderedSize<e.size&&(e.renderedSize=r(e.renderedSize,e.size,.025))}),previousPageYOffset=window.pageYOffset,z+=1,function(){d.clearRect(0,0,a.width,a.height),f&&(d.fillStyle=f,d.fillRect(0,0,a.width,a.height));const e=u.filter(e=>e.size>=7),t=u.filter(e=>e.size<7);d.fillStyle=g,t.forEach(e=>{d.beginPath(),_(e.pos,e.renderedSize),d.fill()}),d.fillStyle=h,e.forEach(e=>{d.beginPath(),_(e.pos,e.renderedSize),d.fill()})}()),window.requestAnimationFrame(M)}let z=0;const P=i.create(0,0),O=i.create(0,0);function q(e){let t=[];for(;e--;){const e=3+5*Math.random(),n=!0===v?0:e;t.push({pos:i.create(Math.random()*a.width,Math.random()*a.height),size:e,renderedSize:n,noise:10*Math.random(),amplitude:2*Math.random(),frequency:.01*Math.random(),random:Math.random()})}return t}function j(){const e=a.width*a.height;return Math.round(c*(e/2073600))}function _(e,t){d.arc(e.x,e.y,t,0,2*Math.PI,!1)}function E(){u=q(j())}e.exports={setAmplitude:function(e){y=e},setBackground:function(e){f=e},setDensity:function(e){c=e,E()},setFade:function(e){v=e,E()},setScroll:function(e){m=e},setFrequency:function(e){p=e},setGravity:x,setPrimary:function(e){g=e},setSecondary:function(e){h=e},setWind:S,setPaused:function(e){w=e},togglePaused:function(){w=!w},start:function(e={}){void 0!==e.bg&&(f=e.bg),void 0!==e.primary&&(g=e.primary),void 0!==e.secondary&&(h=e.secondary),void 0!==e.density&&(c=e.density),void 0!==e.fadeIn&&(v=e.fadeIn),void 0!==e.scroll&&(m=e.scroll),void 0!==e.wave&&(void 0!==e.wave.amplitude&&(y=e.wave.amplitude),void 0!==e.wave.frequency&&(p=e.wave.frequency)),void 0!==e.gravity&&(void 0!==e.gravity.angle&&void 0!==e.gravity.strength&&x(e.gravity.angle,e.gravity.strength),void 0!==e.gravity.angle&&void 0===e.gravity.strength&&x(e.gravity.angle,.7),void 0===e.gravity.angle&&void 0!==e.gravity.strength&&x(90,e.gravity.strength)),void 0!==e.wind&&(void 0!==e.wind.angle&&void 0!==e.wind.strength&&S(e.wind.angle,e.wind.strength),void 0!==e.wind.angle&&void 0===e.wind.strength&&S(e.wind.angle,0),void 0===e.wind.angle&&void 0!==e.wind.strength&&S(0,e.wind.strength)),a.width=o.offsetWidth,a.height=o.offsetHeight,o.appendChild(a),u=q(j()),window.onresize=b,window.requestAnimationFrame(M)}}},function(e,t){function n(e,t){let r=e,o=t;const a=()=>Math.sqrt(r*r+o*o),d=e=>{r*=e,o*=e},s=()=>{let e=a();r/=e,o/=e};return{add:e=>{r+=e.x,o+=e.y},addScalar:e=>{r+=e,o+=e},clone:i,divide:e=>{r/=e.x,o/=e.y},divideScalar:e=>{r/=e,o/=e},dot:e=>r*e.x+o*e.y,getLength:a,getOpposite:e=>n(-e.x,-e.y),getPerp:()=>n(-o,r),isEqualTo:e=>r==e.x&&o==e.y,multiply:e=>{r*=e.x,o*=e.y},multiplyScalar:d,normalise:s,setLength:e=>{s(),d(e)},subtract:e=>{r-=e.x,o-=e.y},subtractScalar:e=>{r-=e,o-=e},set x(e){r=e},get x(){return r},set y(e){o=e},get y(){return o}}}const i=e=>n(e.x,e.y);e.exports={clone:i,create:n,fromDegrees:e=>{const t=e*(Math.PI/180);return n(Math.cos(t),Math.sin(t))}}},function(e,t){e.exports={lerp:function(e,t,n){return e*(1-n)+t*n}}}]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erikwatson/snowfall",
3
- "version": "3.0.4",
3
+ "version": "3.1.2",
4
4
  "description": "Nice snow in a JS Canvas.",
5
5
  "main": "dist/snowfall.min.js",
6
6
  "repository": "git@github.com:erikwatson/snowfall.js.git",
@@ -16,6 +16,7 @@
16
16
  "build": "yarn webpack --config ./webpack.development.js",
17
17
  "build:production": "yarn webpack --config ./webpack.production.js",
18
18
  "build:all": "yarn build && yarn build:production",
19
+ "build:docs": "yarn jsdoc src/snowfall.js -d ./docs README.md",
19
20
  "watch": "yarn run build --watch",
20
21
  "pub": "yarn build:all && npm publish"
21
22
  },