beautiful-backgrounds 0.0.7 → 1.1.0

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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -76
  3. package/build/bb.es.js +2995 -0
  4. package/build/bb.es.js.map +1 -0
  5. package/build/bb.js +8 -0
  6. package/build/bb.js.map +1 -0
  7. package/build/index.d.ts +8 -0
  8. package/build/src/BeautifulBackground.d.ts +25 -0
  9. package/build/src/Particle.d.ts +53 -0
  10. package/build/src/Symbol.d.ts +7 -0
  11. package/build/src/components/ambientRibbon.d.ts +25 -0
  12. package/build/src/components/concentricPulse.d.ts +19 -0
  13. package/{dist/components/DigitalRain.d.ts → build/src/components/digitalRain.d.ts} +13 -11
  14. package/build/src/components/hexagonWave.d.ts +29 -0
  15. package/build/src/components/liquidLines.d.ts +24 -0
  16. package/build/src/components/neonRails.d.ts +31 -0
  17. package/build/src/components/startTrail.d.ts +33 -0
  18. package/build/src/stories/AmbientRibbon.stories.d.ts +16 -0
  19. package/build/src/stories/ConcentricPulse.stories.d.ts +15 -0
  20. package/build/src/stories/DigitalRain.stories.d.ts +13 -0
  21. package/build/src/stories/HexagonWave.stories.d.ts +19 -0
  22. package/build/src/stories/LiquidLines.stories.d.ts +17 -0
  23. package/build/src/stories/NeonRails.stories.d.ts +20 -0
  24. package/build/src/stories/StartTrail.stories.d.ts +20 -0
  25. package/build/src/utils/color.d.ts +2 -0
  26. package/build/src/utils/function.d.ts +1 -0
  27. package/build/src/utils/lit.d.ts +2 -0
  28. package/{dist → build/src}/utils/number.d.ts +0 -1
  29. package/build/vite.svg +1 -0
  30. package/package.json +58 -27
  31. package/dist/beautiful-backgrounds.min.js +0 -1
  32. package/dist/components/BeautifulBackground.d.ts +0 -28
  33. package/dist/components/BeautifulBackground.js +0 -110
  34. package/dist/components/DigitalRain.js +0 -85
  35. package/dist/components/Particle.d.ts +0 -18
  36. package/dist/components/Particle.js +0 -44
  37. package/dist/components/StarTrail.d.ts +0 -30
  38. package/dist/components/StarTrail.js +0 -95
  39. package/dist/components/Symbol.d.ts +0 -7
  40. package/dist/components/Symbol.js +0 -18
  41. package/dist/index.d.ts +0 -2
  42. package/dist/index.js +0 -2
  43. package/dist/utils/color.d.ts +0 -1
  44. package/dist/utils/color.js +0 -7
  45. package/dist/utils/number.js +0 -20
  46. package/dist/utils/object.js +0 -9
  47. /package/{dist → build/src}/utils/object.d.ts +0 -0
@@ -1,110 +0,0 @@
1
- import { has } from '../utils/object';
2
- export default class BeautifulBackground extends HTMLElement {
3
- constructor() {
4
- super();
5
- this.interpolationDuration = 1000;
6
- this.interpolationStep = 100;
7
- this.fullyInitialized = false;
8
- this.shadowR = this.attachShadow({ mode: 'open' });
9
- this.shadowR.innerHTML = `
10
- <style>
11
- :host {
12
- display: flex;
13
- }
14
- </style>
15
- `;
16
- this.lastTime = 0;
17
- this.fps = 30;
18
- this.timer = 0;
19
- this.resizeDebounceTimer = null;
20
- this.canvas = document.createElement('canvas');
21
- this.ctx = this.canvas.getContext('2d');
22
- this.backgroundColor = '0, 0, 0';
23
- }
24
- debouncedResizeCanvas() {
25
- clearTimeout(this.resizeDebounceTimer);
26
- this.resizeDebounceTimer = setTimeout(() => {
27
- this.resizeCanvas();
28
- }, 1000);
29
- }
30
- startAnimation(fn) {
31
- const animate = (timeStamp) => {
32
- const deltaTime = timeStamp - this.lastTime;
33
- this.lastTime = timeStamp;
34
- if (this.timer > 1000 / this.fps) {
35
- fn();
36
- this.timer = 0;
37
- }
38
- else {
39
- this.timer += deltaTime;
40
- }
41
- this.animationFrameId = requestAnimationFrame(animate);
42
- };
43
- this.animationFrameId = requestAnimationFrame(animate);
44
- }
45
- interpolateWithThrottle(startValue, newValue, durationMs, throttleMs, onInterpolate) {
46
- const numSteps = Math.ceil(durationMs / throttleMs);
47
- const stepValue = (newValue - startValue) / numSteps;
48
- let currentValue = startValue;
49
- let currentTime = 0;
50
- let isInterpolating = true;
51
- let timeoutID = null;
52
- function interpolateStep() {
53
- if (currentTime < durationMs && isInterpolating) {
54
- onInterpolate(currentValue, false);
55
- currentValue += stepValue;
56
- currentTime += throttleMs;
57
- timeoutID = window.setTimeout(interpolateStep, throttleMs);
58
- }
59
- else if (isInterpolating) {
60
- onInterpolate(newValue, true);
61
- isInterpolating = false;
62
- if (timeoutID) {
63
- window.clearTimeout(timeoutID);
64
- }
65
- }
66
- }
67
- interpolateStep();
68
- }
69
- triggerInterpolation(name, oldValue, newValue) {
70
- const old = Number(oldValue);
71
- const target = Number(newValue);
72
- const prop = this.getPropNameCamelCased(name);
73
- if (old !== target && this.fullyInitialized) {
74
- if (has(this, prop)) {
75
- this.interpolateWithThrottle(oldValue ? old : this[prop], target, this.interpolationDuration, this.interpolationStep, (i) => {
76
- this[prop] = i;
77
- });
78
- }
79
- }
80
- else {
81
- this[prop] = target;
82
- }
83
- }
84
- setValues(ignoredProps, name, oldValue, newValue) {
85
- if (ignoredProps.includes(name)) {
86
- const propName = this.getPropNameCamelCased(name);
87
- this[propName] = newValue;
88
- }
89
- if (!ignoredProps.includes(name)) {
90
- this.triggerInterpolation(name, oldValue, newValue);
91
- }
92
- }
93
- getPropNameCamelCased(dashCased) {
94
- return dashCased
95
- .substring(5)
96
- .replace(/-(.)/g, (_, char) => char.toUpperCase());
97
- }
98
- resizeCanvas() {
99
- const newWidth = Number.parseInt(this.getAttribute('data-width')) || this.parentElement.clientWidth;
100
- const newHeight = Number.parseInt(this.getAttribute('data-height')) || this.parentElement.clientHeight;
101
- if (newWidth !== this.width || newHeight !== this.height) {
102
- this.width = newWidth;
103
- this.height = newHeight;
104
- this.canvas.width = newWidth;
105
- this.canvas.height = newHeight;
106
- this.canvas.style.backgroundColor = `rgb(${this.backgroundColor})`;
107
- }
108
- this.fullyInitialized = true;
109
- }
110
- }
@@ -1,85 +0,0 @@
1
- import BB from './BeautifulBackground';
2
- import { randomColor } from '../utils/color';
3
- import Symbol from './Symbol';
4
- import { getRandomInt } from '../utils/number';
5
- export class BbDigitalRain extends BB {
6
- constructor() {
7
- super();
8
- this.ignoredProps = ['data-characters', 'data-background-color'];
9
- this.fontSize = 24;
10
- this.fontColorHueStart = 60;
11
- this.fontColorHueEnd = this.fontColorHueStart + 90;
12
- this.fontColorSaturationStart = 90;
13
- this.fontColorSaturationEnd = 100;
14
- this.fontColorLightnessStart = 50;
15
- this.fontColorLightnessEnd = 50;
16
- this.randomness = 0.975;
17
- this.trailOpacity = 0.1;
18
- this.characters = 'ヲアウエオカキケコサシスセソタツテナニヌネハヒホマミムメモヤユラリワ13579ヲイクコソチトノフヤヨルレロンZ:."¦=*+-<>|リçδ╘';
19
- }
20
- connectedCallback() {
21
- this.shadowR.appendChild(this.canvas);
22
- this.resizeCanvas();
23
- this.initialize();
24
- this.startAnimation(this.animation.bind(this));
25
- window.addEventListener('resize', this.debouncedResizeCanvas.bind(this));
26
- }
27
- disconnectedCallback() {
28
- window.removeEventListener('resize', this.debouncedResizeCanvas.bind(this));
29
- if (this.animationFrameId !== null) {
30
- window.cancelAnimationFrame(this.animationFrameId);
31
- }
32
- }
33
- initialize() {
34
- this.symbols = [];
35
- this.createSymbols();
36
- }
37
- createSymbols() {
38
- this.columns = Math.floor(this.width / this.fontSize);
39
- for (let i = 0; i < this.columns; i++) {
40
- this.symbols[i] = this.createSymbol(i);
41
- }
42
- }
43
- updateSymbols() {
44
- const currentColumns = Math.floor(this.width / this.fontSize);
45
- for (let i = this.symbols.length; i < currentColumns; i++) {
46
- this.symbols[i] = this.createSymbol(i);
47
- }
48
- if (this.symbols.length > currentColumns) {
49
- this.symbols.length = currentColumns;
50
- }
51
- }
52
- animation() {
53
- this.updateSymbols();
54
- this.ctx.fillStyle = `rgba(${this.backgroundColor}, ${this.trailOpacity})`;
55
- this.ctx.fillRect(0, 0, this.width, this.height);
56
- this.ctx.textAlign = 'center';
57
- this.ctx.font = `${this.fontSize}px monospace`;
58
- this.symbols.forEach((symbol) => {
59
- symbol.draw(this.ctx, this.characters.charAt(Math.floor(Math.random() * this.characters.length)), randomColor([this.fontColorHueStart, this.fontColorHueEnd], [this.fontColorSaturationStart, this.fontColorSaturationEnd], [this.fontColorLightnessStart, this.fontColorLightnessEnd]), this.fontSize);
60
- symbol.update(this.height, this.randomness, this.fontSize);
61
- });
62
- }
63
- createSymbol(index) {
64
- return new Symbol(index, getRandomInt(0, -this.height / this.fontSize));
65
- }
66
- attributeChangedCallback(name, oldValue, newValue) {
67
- this.setValues(this.ignoredProps, name, oldValue, newValue);
68
- }
69
- }
70
- BbDigitalRain.observedAttributes = [
71
- 'data-fps',
72
- 'data-characters',
73
- 'data-randomness',
74
- 'data-font-size',
75
- 'data-font-color-hue-start',
76
- 'data-font-color-hue-end',
77
- 'data-font-color-saturation-start',
78
- 'data-font-color-saturation-end',
79
- 'data-font-color-lightness-start',
80
- 'data-font-color-lightness-end',
81
- 'data-background-color'
82
- ];
83
- if (!window.customElements.get('bb-digital-rain')) {
84
- window.customElements.define('bb-digital-rain', BbDigitalRain);
85
- }
@@ -1,18 +0,0 @@
1
- export default class Particle {
2
- private size;
3
- private speed;
4
- private color;
5
- private radius;
6
- private angle;
7
- private lifespan;
8
- private x;
9
- private y;
10
- private born;
11
- private fadeInDuration;
12
- private fadeOutDuration;
13
- constructor(size: number, speed: number, color: string, radius: number, angle: number, lifespan: number);
14
- update(centerX: number, centerY: number): void;
15
- draw(ctx: CanvasRenderingContext2D): void;
16
- isDead(): boolean;
17
- private calculateOpacity;
18
- }
@@ -1,44 +0,0 @@
1
- export default class Particle {
2
- constructor(size, speed, color, radius, angle, lifespan) {
3
- this.size = size;
4
- this.speed = speed;
5
- this.color = color;
6
- this.radius = radius;
7
- this.angle = angle;
8
- this.lifespan = lifespan;
9
- this.x = 0;
10
- this.y = 0;
11
- this.born = Date.now();
12
- this.fadeInDuration = this.lifespan * 0.25;
13
- this.fadeOutDuration = this.lifespan * 0.5;
14
- }
15
- update(centerX, centerY) {
16
- this.angle += this.speed;
17
- this.x = centerX + Math.cos(this.angle) * this.radius;
18
- this.y = centerY + Math.sin(this.angle) * this.radius;
19
- }
20
- draw(ctx) {
21
- ctx.beginPath();
22
- ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false);
23
- ctx.fillStyle = this.color;
24
- ctx.globalAlpha = this.calculateOpacity();
25
- ctx.shadowBlur = 10;
26
- ctx.shadowColor = this.color;
27
- ctx.fill();
28
- ctx.globalAlpha = 1;
29
- ctx.shadowBlur = 0;
30
- }
31
- isDead() {
32
- return Date.now() - this.born > this.lifespan;
33
- }
34
- calculateOpacity() {
35
- const age = Date.now() - this.born;
36
- if (age < this.fadeInDuration) {
37
- return age / this.fadeInDuration;
38
- }
39
- if (age > this.lifespan - this.fadeOutDuration) {
40
- return (this.lifespan - age) / this.fadeOutDuration;
41
- }
42
- return 1;
43
- }
44
- }
@@ -1,30 +0,0 @@
1
- import BB from './BeautifulBackground';
2
- import Particle from './Particle';
3
- export declare class BbStarTrail extends BB {
4
- backgroundColor: string;
5
- starSizeMin: number;
6
- starSizeMax: number;
7
- starSpeedMin: number;
8
- starSpeedMax: number;
9
- starColorHueStart: number;
10
- starColorHueEnd: number;
11
- starColorSaturationStart: number;
12
- starColorSaturationEnd: number;
13
- starColorLightnessStart: number;
14
- starColorLightnessEnd: number;
15
- starRadiusMin: number;
16
- starRadiusMax: number;
17
- starLifespanMin: number;
18
- starLifespanMax: number;
19
- numStars: number;
20
- private stars;
21
- static observedAttributes: string[];
22
- private ignoredProps;
23
- constructor();
24
- protected connectedCallback(): void;
25
- protected disconnectedCallback(): void;
26
- protected initialize(): void;
27
- protected animation(): void;
28
- protected createStar(): Particle;
29
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
30
- }
@@ -1,95 +0,0 @@
1
- import BB from './BeautifulBackground';
2
- import Particle from './Particle';
3
- import { getRandomFloat, interpolateLinear } from '../utils/number';
4
- import { randomColor } from '../utils/color';
5
- export class BbStarTrail extends BB {
6
- constructor() {
7
- super();
8
- this.ignoredProps = ['data-characters', 'data-background-color'];
9
- this.backgroundColor = '0, 0, 0';
10
- this.starSizeMin = 0.5;
11
- this.starSizeMax = 1.5;
12
- this.starSpeedMin = 0.025;
13
- this.starSpeedMax = 0.05;
14
- this.starColorHueStart = 30;
15
- this.starColorHueEnd = 75;
16
- this.starColorSaturationStart = 100;
17
- this.starColorSaturationEnd = 100;
18
- this.starColorLightnessStart = 50;
19
- this.starColorLightnessEnd = 50;
20
- this.starRadiusMin = 1;
21
- this.starRadiusMax = 100;
22
- this.starLifespanMin = 1000;
23
- this.starLifespanMax = 10000;
24
- this.numStars = 1000;
25
- this.trailOpacity = 0.1;
26
- }
27
- connectedCallback() {
28
- this.shadowR.appendChild(this.canvas);
29
- this.resizeCanvas();
30
- this.initialize();
31
- this.startAnimation(this.animation.bind(this));
32
- window.addEventListener('resize', this.debouncedResizeCanvas.bind(this));
33
- }
34
- disconnectedCallback() {
35
- window.removeEventListener('resize', this.debouncedResizeCanvas.bind(this));
36
- if (this.animationFrameId !== null) {
37
- window.cancelAnimationFrame(this.animationFrameId);
38
- }
39
- }
40
- initialize() {
41
- this.stars = [];
42
- this.starRadiusMax = Math.max(this.width, this.height) / 2;
43
- this.animationFrameId = null;
44
- for (let i = 0; i < this.numStars; i++) {
45
- this.stars.push(this.createStar());
46
- }
47
- }
48
- animation() {
49
- this.ctx.fillStyle = `rgba(${this.backgroundColor}, ${this.trailOpacity})`;
50
- this.ctx.fillRect(0, 0, this.width, this.height);
51
- this.stars = this.stars.filter((star) => !star.isDead());
52
- while (this.stars.length < this.numStars) {
53
- this.stars.push(this.createStar());
54
- }
55
- this.stars.forEach((star) => {
56
- star.update(this.width / 2, this.height / 2);
57
- star.draw(this.ctx);
58
- });
59
- }
60
- createStar() {
61
- const size = getRandomFloat(this.starSizeMin, this.starSizeMax);
62
- const speed = getRandomFloat(interpolateLinear(this.starSpeedMin, -1, 1, -0.04, 0.04), interpolateLinear(this.starSpeedMax, -1, 1, -0.04, 0.04));
63
- const lifespan = getRandomFloat(this.starLifespanMin, this.starLifespanMax);
64
- const color = randomColor([this.starColorHueStart, this.starColorHueEnd], [this.starColorSaturationStart, this.starColorSaturationEnd], [this.starColorLightnessStart, this.starColorLightnessEnd]);
65
- const angle = getRandomFloat(0, Math.PI * 2);
66
- const radiusRange = this.starRadiusMax - this.starRadiusMin;
67
- const radius = Math.sqrt(Math.random()) * radiusRange + this.starRadiusMin;
68
- return new Particle(size, speed, color, radius, angle, lifespan);
69
- }
70
- attributeChangedCallback(name, oldValue, newValue) {
71
- this.setValues(this.ignoredProps, name, oldValue, newValue);
72
- }
73
- }
74
- BbStarTrail.observedAttributes = [
75
- 'data-fps',
76
- 'data-background-color',
77
- 'data-star-size-min',
78
- 'data-star-size-max',
79
- 'data-star-speed-min',
80
- 'data-star-speed-max',
81
- 'data-star-color-hue-start',
82
- 'data-star-color-hue-end',
83
- 'data-star-color-saturation-start',
84
- 'data-star-color-saturation-end',
85
- 'data-star-color-lightness-start',
86
- 'data-star-color-lightness-end',
87
- 'data-star-radius-min',
88
- 'data-star-radius-max',
89
- 'data-star-lifespan-min',
90
- 'data-star-lifespan-max',
91
- 'data-num-stars'
92
- ];
93
- if (!window.customElements.get('bb-star-trail')) {
94
- window.customElements.define('bb-star-trail', BbStarTrail);
95
- }
@@ -1,7 +0,0 @@
1
- export default class Symbol {
2
- protected x: number;
3
- protected y: number;
4
- constructor(x: number, y: number);
5
- update(height: number, randomness: number, fontSize: number): void;
6
- draw(ctx: CanvasRenderingContext2D, text: string, color: string, fontSize: number): void;
7
- }
@@ -1,18 +0,0 @@
1
- export default class Symbol {
2
- constructor(x, y) {
3
- this.x = x;
4
- this.y = y;
5
- }
6
- update(height, randomness, fontSize) {
7
- if (this.y * fontSize > height && Math.random() > randomness) {
8
- this.y = 0;
9
- }
10
- else {
11
- this.y += 1;
12
- }
13
- }
14
- draw(ctx, text, color, fontSize) {
15
- ctx.fillStyle = color;
16
- ctx.fillText(text, this.x * fontSize, this.y * fontSize);
17
- }
18
- }
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { BbStarTrail } from './components/StarTrail';
2
- export { BbDigitalRain } from './components/DigitalRain';
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { BbStarTrail } from './components/StarTrail';
2
- export { BbDigitalRain } from './components/DigitalRain';
@@ -1 +0,0 @@
1
- export declare function randomColor(hRange?: number[], sRange?: number[], lRange?: number[]): string;
@@ -1,7 +0,0 @@
1
- import { getRandomInt } from './number';
2
- export function randomColor(hRange = [0, 360], sRange = [0, 100], lRange = [40, 60]) {
3
- const h = getRandomInt(hRange[0], hRange[1]);
4
- const s = getRandomInt(sRange[0], sRange[1]);
5
- const l = getRandomInt(lRange[0], lRange[1]);
6
- return `hsl(${h}, ${s}%, ${l}%)`;
7
- }
@@ -1,20 +0,0 @@
1
- export function getRandomFloat(min, max) {
2
- return Math.random() * (max - min) + min;
3
- }
4
- export function getRandomInt(min, max) {
5
- min = Math.ceil(min);
6
- max = Math.floor(max);
7
- return Math.floor(Math.random() * (max - min + 1) + min);
8
- }
9
- export function interpolateLinear(value, domainStart, domainEnd, rangeStart, rangeEnd) {
10
- // Ensure the value is within the domain
11
- if (value < domainStart)
12
- value = domainStart;
13
- if (value > domainEnd)
14
- value = domainEnd;
15
- // Normalize the value within the domain
16
- const normalized = (value - domainStart) / (domainEnd - domainStart);
17
- // Scale the normalized value to the range and return it
18
- // The output is always between rangeStart and rangeEnd,
19
- return normalized * (rangeEnd - rangeStart) + rangeStart;
20
- }
@@ -1,9 +0,0 @@
1
- export function has(object, key) {
2
- return Object.prototype.hasOwnProperty.call(object, key);
3
- }
4
- export function isObject(object) {
5
- return (typeof object === 'object' && Object.prototype.toString.call(object) === '[object Object]');
6
- }
7
- export function isEmpty(object) {
8
- return isObject(object) && Object.keys(object).length === 0;
9
- }
File without changes