Skip to content

Commit

Permalink
🌀
Browse files Browse the repository at this point in the history
  • Loading branch information
hcodes committed Oct 26, 2024
1 parent 4adc519 commit 82a13c0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 47 deletions.
4 changes: 0 additions & 4 deletions dist/helpers/dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export declare function injectStyle(style: string, styleNode?: HTMLStyleElement)
* Remove DOM node.
*/
export declare function removeNode(node?: HTMLElement): void;
/**
* A DOM node is body.
*/
export declare function isBody(node: HTMLElement): boolean;
/**
* Add className for a node.
*/
Expand Down
5 changes: 3 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { SnowflakesParams } from './types';
import { SnowflakesInnerParams, SnowflakesParams } from './types';
export { SnowflakesParams } from './types';
export default class Snowflakes {
private container;
private destroyed;
private flakes;
private isBody;
private params;
private animationStyleNode?;
private imagesStyleNode?;
Expand All @@ -14,6 +13,7 @@ export default class Snowflakes {
static gid: number;
static instanceCounter: number;
static hasSupport(): boolean;
static defaultParams: SnowflakesInnerParams;
constructor(params?: SnowflakesParams);
/**
* Start CSS animation.
Expand All @@ -39,6 +39,7 @@ export default class Snowflakes {
* Destroy instance.
*/
destroy(): void;
private isBody;
private handleResize;
private handleOrientationChange;
private appendContainer;
Expand Down
22 changes: 9 additions & 13 deletions dist/snowflakes.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ function removeNode(node) {
node.parentNode.removeChild(node);
}
}
/**
* A DOM node is body.
*/
function isBody(node) {
return node === document.body;
}
function isNotEmptyString(value) {
return typeof value === 'string' && value !== '';
}
Expand Down Expand Up @@ -219,7 +213,6 @@ class Snowflakes {
constructor(params) {
this.destroyed = false;
this.flakes = [];
this.isBody = false;
this.handleResize = () => {
if (this.params.autoResize) {
this.resize();
Expand All @@ -229,7 +222,6 @@ class Snowflakes {
this.resize();
};
this.params = this.setParams(params);
this.isBody = isBody(this.params.container);
Snowflakes.gid++;
this.gid = Snowflakes.gid;
this.container = this.appendContainer();
Expand Down Expand Up @@ -284,7 +276,7 @@ class Snowflakes {
this.containerSize.height = newHeight;
const flakeParams = this.getFlakeParams();
this.flakes.forEach(flake => flake.resize(flakeParams));
if (this.isBody) {
if (this.isBody()) {
return;
}
hideElement(this.container);
Expand All @@ -311,9 +303,12 @@ class Snowflakes {
screen.orientation.removeEventListener('change', this.handleOrientationChange, false);
}
}
isBody() {
return this.params.container === document.body;
}
appendContainer() {
const container = document.createElement('div');
addClass(container, 'snowflakes', `snowflakes_gid_${this.gid}`, this.isBody ? 'snowflakes_body' : '');
addClass(container, 'snowflakes', `snowflakes_gid_${this.gid}`, this.isBody() ? 'snowflakes_body' : '');
setStyle(container, { zIndex: String(this.params.zIndex) });
this.params.container.appendChild(container);
return container;
Expand Down Expand Up @@ -371,7 +366,7 @@ class Snowflakes {
getAnimationStyle() {
const fromY = '0px';
const maxSize = Math.ceil(this.params.maxSize * Math.sqrt(2));
const toY = this.isBody ? `calc(100vh + ${maxSize}px)` : `${this.height() + maxSize}px`;
const toY = this.isBody() ? `calc(100vh + ${maxSize}px)` : `${this.height() + maxSize}px`;
const gid = this.gid;
const cssText = [`@keyframes snowflake_gid_${gid}_y{from{transform:translateY(${fromY})}to{transform:translateY(${toY})}}`];
for (let i = 0; i <= maxInnerSize; i++) {
Expand All @@ -395,14 +390,15 @@ class Snowflakes {
}
width() {
return this.params.width ||
(this.isBody ? window.innerWidth : this.params.container.offsetWidth);
(this.isBody() ? window.innerWidth : this.params.container.offsetWidth);
}
height() {
return this.params.height ||
(this.isBody ? window.innerHeight : this.params.container.offsetHeight + this.params.maxSize);
(this.isBody() ? window.innerHeight : this.params.container.offsetHeight + this.params.maxSize);
}
}
Snowflakes.gid = 0;
Snowflakes.instanceCounter = 0;
Snowflakes.defaultParams = defaultParams;

export { Snowflakes as default };
22 changes: 9 additions & 13 deletions dist/snowflakes.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@
node.parentNode.removeChild(node);
}
}
/**
* A DOM node is body.
*/
function isBody(node) {
return node === document.body;
}
function isNotEmptyString(value) {
return typeof value === 'string' && value !== '';
}
Expand Down Expand Up @@ -235,7 +229,6 @@
var _this = this;
this.destroyed = false;
this.flakes = [];
this.isBody = false;
this.handleResize = function () {
if (_this.params.autoResize) {
_this.resize();
Expand All @@ -245,7 +238,6 @@
_this.resize();
};
this.params = this.setParams(params);
this.isBody = isBody(this.params.container);
Snowflakes.gid++;
this.gid = Snowflakes.gid;
this.container = this.appendContainer();
Expand Down Expand Up @@ -303,7 +295,7 @@
this.containerSize.height = newHeight;
var flakeParams = this.getFlakeParams();
this.flakes.forEach(function (flake) { return flake.resize(flakeParams); });
if (this.isBody) {
if (this.isBody()) {
return;
}
hideElement(this.container);
Expand All @@ -330,9 +322,12 @@
screen.orientation.removeEventListener('change', this.handleOrientationChange, false);
}
};
Snowflakes.prototype.isBody = function () {
return this.params.container === document.body;
};
Snowflakes.prototype.appendContainer = function () {
var container = document.createElement('div');
addClass(container, 'snowflakes', "snowflakes_gid_".concat(this.gid), this.isBody ? 'snowflakes_body' : '');
addClass(container, 'snowflakes', "snowflakes_gid_".concat(this.gid), this.isBody() ? 'snowflakes_body' : '');
setStyle(container, { zIndex: String(this.params.zIndex) });
this.params.container.appendChild(container);
return container;
Expand Down Expand Up @@ -391,7 +386,7 @@
Snowflakes.prototype.getAnimationStyle = function () {
var fromY = '0px';
var maxSize = Math.ceil(this.params.maxSize * Math.sqrt(2));
var toY = this.isBody ? "calc(100vh + ".concat(maxSize, "px)") : "".concat(this.height() + maxSize, "px");
var toY = this.isBody() ? "calc(100vh + ".concat(maxSize, "px)") : "".concat(this.height() + maxSize, "px");
var gid = this.gid;
var cssText = ["@keyframes snowflake_gid_".concat(gid, "_y{from{transform:translateY(").concat(fromY, ")}to{transform:translateY(").concat(toY, ")}}")];
for (var i = 0; i <= maxInnerSize; i++) {
Expand All @@ -415,14 +410,15 @@
};
Snowflakes.prototype.width = function () {
return this.params.width ||
(this.isBody ? window.innerWidth : this.params.container.offsetWidth);
(this.isBody() ? window.innerWidth : this.params.container.offsetWidth);
};
Snowflakes.prototype.height = function () {
return this.params.height ||
(this.isBody ? window.innerHeight : this.params.container.offsetHeight + this.params.maxSize);
(this.isBody() ? window.innerHeight : this.params.container.offsetHeight + this.params.maxSize);
};
Snowflakes.gid = 0;
Snowflakes.instanceCounter = 0;
Snowflakes.defaultParams = defaultParams;
return Snowflakes;
}());

Expand Down
22 changes: 9 additions & 13 deletions dist/snowflakes.light.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@
node.parentNode.removeChild(node);
}
}
/**
* A DOM node is body.
*/
function isBody(node) {
return node === document.body;
}
function isNotEmptyString(value) {
return typeof value === 'string' && value !== '';
}
Expand Down Expand Up @@ -235,7 +229,6 @@
var _this = this;
this.destroyed = false;
this.flakes = [];
this.isBody = false;
this.handleResize = function () {
if (_this.params.autoResize) {
_this.resize();
Expand All @@ -245,7 +238,6 @@
_this.resize();
};
this.params = this.setParams(params);
this.isBody = isBody(this.params.container);
Snowflakes.gid++;
this.gid = Snowflakes.gid;
this.container = this.appendContainer();
Expand Down Expand Up @@ -303,7 +295,7 @@
this.containerSize.height = newHeight;
var flakeParams = this.getFlakeParams();
this.flakes.forEach(function (flake) { return flake.resize(flakeParams); });
if (this.isBody) {
if (this.isBody()) {
return;
}
hideElement(this.container);
Expand All @@ -330,9 +322,12 @@
screen.orientation.removeEventListener('change', this.handleOrientationChange, false);
}
};
Snowflakes.prototype.isBody = function () {
return this.params.container === document.body;
};
Snowflakes.prototype.appendContainer = function () {
var container = document.createElement('div');
addClass(container, 'snowflakes', "snowflakes_gid_".concat(this.gid), this.isBody ? 'snowflakes_body' : '');
addClass(container, 'snowflakes', "snowflakes_gid_".concat(this.gid), this.isBody() ? 'snowflakes_body' : '');
setStyle(container, { zIndex: String(this.params.zIndex) });
this.params.container.appendChild(container);
return container;
Expand Down Expand Up @@ -391,7 +386,7 @@
Snowflakes.prototype.getAnimationStyle = function () {
var fromY = '0px';
var maxSize = Math.ceil(this.params.maxSize * Math.sqrt(2));
var toY = this.isBody ? "calc(100vh + ".concat(maxSize, "px)") : "".concat(this.height() + maxSize, "px");
var toY = this.isBody() ? "calc(100vh + ".concat(maxSize, "px)") : "".concat(this.height() + maxSize, "px");
var gid = this.gid;
var cssText = ["@keyframes snowflake_gid_".concat(gid, "_y{from{transform:translateY(").concat(fromY, ")}to{transform:translateY(").concat(toY, ")}}")];
for (var i = 0; i <= maxInnerSize; i++) {
Expand All @@ -415,14 +410,15 @@
};
Snowflakes.prototype.width = function () {
return this.params.width ||
(this.isBody ? window.innerWidth : this.params.container.offsetWidth);
(this.isBody() ? window.innerWidth : this.params.container.offsetWidth);
};
Snowflakes.prototype.height = function () {
return this.params.height ||
(this.isBody ? window.innerHeight : this.params.container.offsetHeight + this.params.maxSize);
(this.isBody() ? window.innerHeight : this.params.container.offsetHeight + this.params.maxSize);
};
Snowflakes.gid = 0;
Snowflakes.instanceCounter = 0;
Snowflakes.defaultParams = defaultParams;
return Snowflakes;
}());

Expand Down
Loading

0 comments on commit 82a13c0

Please sign in to comment.