@designbasekorea/ui-wc 0.5.3 → 0.5.6
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.
- package/dist/chunks/lottie-e273b936.js +17032 -0
- package/dist/esm/components/animation-background/canvas-controller.js +121 -1
- package/dist/esm/components/animation-background/controls.js +180 -1
- package/dist/esm/components/animation-background/graphite-controller.js +196 -1
- package/dist/esm/components/animation-background/graphite-presets.js +42 -1
- package/dist/esm/components/animation-background/graphite-shader.js +111 -1
- package/dist/esm/components/animation-background/layers.js +369 -1
- package/dist/esm/components/animation-background/lumina-presets.js +53 -1
- package/dist/esm/components/animation-background/lumina-shaders.js +181 -1
- package/dist/esm/components/animation-background/lumina-utils.js +60 -1
- package/dist/esm/components/animation-background/particle-defaults.js +36 -1
- package/dist/esm/components/animation-background/renderers.js +167 -1
- package/dist/esm/components/animation-background/shader-controller.js +154 -1
- package/dist/esm/components/color-picker-utils.js +134 -1
- package/dist/esm/components/date-picker-utils.js +140 -1
- package/dist/esm/components/db-accordion.js +304 -1
- package/dist/esm/components/db-ad-banner.js +455 -1
- package/dist/esm/components/db-alert.js +149 -1
- package/dist/esm/components/db-animation-background.js +486 -1
- package/dist/esm/components/db-animation-text.js +601 -1
- package/dist/esm/components/db-app-badge.js +88 -1
- package/dist/esm/components/db-audio-player.js +752 -1
- package/dist/esm/components/db-avatar.js +188 -1
- package/dist/esm/components/db-backdrop.js +139 -1
- package/dist/esm/components/db-badge.js +91 -1
- package/dist/esm/components/db-banner.js +188 -1
- package/dist/esm/components/db-bottom-navigation.js +146 -1
- package/dist/esm/components/db-bottom-sheet.js +481 -1
- package/dist/esm/components/db-breadcrumbs.js +329 -1
- package/dist/esm/components/db-button.js +316 -1
- package/dist/esm/components/db-calendar.js +675 -1
- package/dist/esm/components/db-card.js +265 -1
- package/dist/esm/components/db-carousel.js +264 -1
- package/dist/esm/components/db-checkbox.js +202 -1
- package/dist/esm/components/db-chip.js +104 -1
- package/dist/esm/components/db-code-block.js +304 -1
- package/dist/esm/components/db-color-picker.js +746 -1
- package/dist/esm/components/db-confirm.js +191 -1
- package/dist/esm/components/db-container.js +39 -1
- package/dist/esm/components/db-context-menu.js +265 -1
- package/dist/esm/components/db-countdown.js +146 -1
- package/dist/esm/components/db-cursor-follower.js +173 -1
- package/dist/esm/components/db-date-picker.js +837 -1
- package/dist/esm/components/db-divider.js +66 -1
- package/dist/esm/components/db-drawer.js +245 -1
- package/dist/esm/components/db-dropdown.js +493 -1
- package/dist/esm/components/db-dropzone.js +266 -1
- package/dist/esm/components/db-empty-state.js +97 -1
- package/dist/esm/components/db-file-uploader.js +256 -1
- package/dist/esm/components/db-floating-action-button.js +139 -1
- package/dist/esm/components/db-footer.js +385 -1
- package/dist/esm/components/db-form.js +566 -1
- package/dist/esm/components/db-gantt.js +882 -1
- package/dist/esm/components/db-gradient.js +133 -1
- package/dist/esm/components/db-grid-background.js +909 -1
- package/dist/esm/components/db-grid.js +73 -1
- package/dist/esm/components/db-icons.js +82 -1
- package/dist/esm/components/db-image-list.js +214 -1
- package/dist/esm/components/db-image-placeholder.js +96 -1
- package/dist/esm/components/db-image.js +289 -1
- package/dist/esm/components/db-indicator.js +517 -1
- package/dist/esm/components/db-input.js +420 -1
- package/dist/esm/components/db-kanban.js +538 -1
- package/dist/esm/components/db-label.js +66 -1
- package/dist/esm/components/db-lightbox.js +372 -1
- package/dist/esm/components/db-list.js +340 -1
- package/dist/esm/components/db-logo-svg.js +72 -1
- package/dist/esm/components/db-logo.js +106 -1
- package/dist/esm/components/db-lottie.js +109 -1
- package/dist/esm/components/db-markdown-editor.js +458 -1
- package/dist/esm/components/db-marquee.js +402 -1
- package/dist/esm/components/db-masonry.js +94 -1
- package/dist/esm/components/db-menu-item.js +211 -1
- package/dist/esm/components/db-modal.js +522 -1
- package/dist/esm/components/db-navbar.js +680 -1
- package/dist/esm/components/db-onboarding-modal.js +322 -1
- package/dist/esm/components/db-page-header.js +312 -1
- package/dist/esm/components/db-pagination.js +271 -1
- package/dist/esm/components/db-popover.js +580 -1
- package/dist/esm/components/db-progress-step.js +166 -1
- package/dist/esm/components/db-progress.js +171 -1
- package/dist/esm/components/db-progressbar.js +72 -1
- package/dist/esm/components/db-radio.js +172 -1
- package/dist/esm/components/db-random-gradient.js +121 -1
- package/dist/esm/components/db-range-slider.js +811 -1
- package/dist/esm/components/db-rating.js +325 -1
- package/dist/esm/components/db-reorder.js +286 -1
- package/dist/esm/components/db-resizable-panels.js +282 -1
- package/dist/esm/components/db-scroll-area.js +126 -1
- package/dist/esm/components/db-search-bar.js +668 -1
- package/dist/esm/components/db-section-app-download.js +101 -1
- package/dist/esm/components/db-section-contact.js +102 -1
- package/dist/esm/components/db-section-cta.js +150 -1
- package/dist/esm/components/db-section-faq.js +120 -1
- package/dist/esm/components/db-section-feature-grid.js +137 -1
- package/dist/esm/components/db-section-feature.js +179 -1
- package/dist/esm/components/db-section-hero.js +243 -1
- package/dist/esm/components/db-section-logo-cloud.js +138 -1
- package/dist/esm/components/db-section-pricing.js +166 -1
- package/dist/esm/components/db-section-stats.js +129 -1
- package/dist/esm/components/db-section-testimonials.js +252 -1
- package/dist/esm/components/db-section.js +385 -1
- package/dist/esm/components/db-segment-control.js +231 -1
- package/dist/esm/components/db-select.js +571 -1
- package/dist/esm/components/db-share-icons.js +40 -1
- package/dist/esm/components/db-share.js +489 -1
- package/dist/esm/components/db-sidebar.js +1068 -1
- package/dist/esm/components/db-skeleton.js +94 -1
- package/dist/esm/components/db-spinner.js +102 -1
- package/dist/esm/components/db-split-view.js +297 -1
- package/dist/esm/components/db-stack.js +46 -1
- package/dist/esm/components/db-stat.js +218 -1
- package/dist/esm/components/db-stepper.js +398 -1
- package/dist/esm/components/db-table.js +412 -1
- package/dist/esm/components/db-tabs.js +335 -1
- package/dist/esm/components/db-testimonial.js +162 -1
- package/dist/esm/components/db-textarea.js +233 -1
- package/dist/esm/components/db-time-picker.js +523 -1
- package/dist/esm/components/db-timeline.js +174 -1
- package/dist/esm/components/db-toast.js +158 -1
- package/dist/esm/components/db-toggle.js +162 -1
- package/dist/esm/components/db-toolbar.js +94 -1
- package/dist/esm/components/db-tooltip.js +440 -1
- package/dist/esm/components/db-top-banner.js +121 -1
- package/dist/esm/components/db-tutorial.js +324 -1
- package/dist/esm/components/db-video-player.js +503 -1
- package/dist/esm/components/db-youtube-player.js +194 -1
- package/dist/esm/components/highlight-code.js +65 -1
- package/dist/esm/components/input-validation.js +50 -1
- package/dist/esm/components/marketing-block-host-utils.js +9 -1
- package/dist/esm/components/number-scrub.js +117 -1
- package/dist/esm/components/random-gradient-palettes.js +67 -1
- package/dist/esm/components/section-block-header-utils.js +48 -1
- package/dist/esm/helpers/confirm.js +52 -1
- package/dist/esm/helpers/toast.js +73 -1
- package/dist/esm/index.js +111 -1
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +235 -1
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +31 -1
- package/dist/esm/node_modules/prismjs/components/prism-css.js +64 -1
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +172 -1
- package/dist/esm/node_modules/prismjs/components/prism-json.js +27 -1
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +143 -1
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +186 -1
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +81 -1
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +15 -1
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +60 -1
- package/dist/index.cjs +55414 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +38284 -1
- package/dist/react/chunks/lottie-72a4c6d4.js +17032 -0
- package/dist/react/index.cjs +56503 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.esm.js +39373 -1
- package/package.json +1 -1
- package/dist/chunks/lottie-2d1f6278.js +0 -1
- package/dist/react/chunks/lottie-14e7addb.js +0 -1
|
@@ -1 +1,121 @@
|
|
|
1
|
-
import{drawFallingParticles
|
|
1
|
+
import { drawFallingParticles, drawStars, drawParticles } from './renderers.js';
|
|
2
|
+
import { toSpeedRate } from './lumina-utils.js';
|
|
3
|
+
|
|
4
|
+
const CLASS = 'designbase-wc-animation-background';
|
|
5
|
+
const FALLING_TYPES = ['snow', 'flowers', 'confetti'];
|
|
6
|
+
function isFallingType(type) {
|
|
7
|
+
return FALLING_TYPES.includes(type);
|
|
8
|
+
}
|
|
9
|
+
class CanvasAnimationController {
|
|
10
|
+
constructor(container, options) {
|
|
11
|
+
this.raf = 0;
|
|
12
|
+
this.frameCount = 0;
|
|
13
|
+
this.mouse = { x: -9999, y: -9999 };
|
|
14
|
+
this.particlesRef = { current: [] };
|
|
15
|
+
this.starsRef = { current: [] };
|
|
16
|
+
this.fallingRef = { current: [] };
|
|
17
|
+
this.tick = () => {
|
|
18
|
+
const ctx = this.canvas.getContext('2d');
|
|
19
|
+
if (!ctx) {
|
|
20
|
+
this.raf = requestAnimationFrame(this.tick);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const dpr = window.devicePixelRatio || 1;
|
|
24
|
+
const width = this.canvas.width / dpr;
|
|
25
|
+
const height = this.canvas.height / dpr;
|
|
26
|
+
const { type, colors, speed, particleCount, particleSize, starCount, starSize, clickable, wind, layerOpacity, } = this.options;
|
|
27
|
+
ctx.clearRect(0, 0, width, height);
|
|
28
|
+
const speedRate = toSpeedRate(speed);
|
|
29
|
+
const time = this.frameCount * speedRate;
|
|
30
|
+
this.frameCount += 1;
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 'particles':
|
|
33
|
+
drawParticles(ctx, width, height, this.particlesRef, {
|
|
34
|
+
count: particleCount,
|
|
35
|
+
colors,
|
|
36
|
+
size: particleSize,
|
|
37
|
+
speed,
|
|
38
|
+
mouse: this.mouse,
|
|
39
|
+
clickable,
|
|
40
|
+
layerOpacity,
|
|
41
|
+
});
|
|
42
|
+
break;
|
|
43
|
+
case 'stars':
|
|
44
|
+
drawStars(ctx, width, height, this.starsRef, {
|
|
45
|
+
count: starCount,
|
|
46
|
+
colors,
|
|
47
|
+
size: starSize,
|
|
48
|
+
time,
|
|
49
|
+
layerOpacity,
|
|
50
|
+
speedRate,
|
|
51
|
+
});
|
|
52
|
+
break;
|
|
53
|
+
case 'snow':
|
|
54
|
+
case 'flowers':
|
|
55
|
+
case 'confetti':
|
|
56
|
+
if (isFallingType(type)) {
|
|
57
|
+
drawFallingParticles(ctx, width, height, this.fallingRef, type, {
|
|
58
|
+
count: particleCount,
|
|
59
|
+
colors,
|
|
60
|
+
size: particleSize,
|
|
61
|
+
speed,
|
|
62
|
+
wind,
|
|
63
|
+
layerOpacity,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
this.raf = requestAnimationFrame(this.tick);
|
|
69
|
+
};
|
|
70
|
+
this.container = container;
|
|
71
|
+
this.options = options;
|
|
72
|
+
this.canvas = document.createElement('canvas');
|
|
73
|
+
this.canvas.className = `${CLASS}__canvas`;
|
|
74
|
+
container.appendChild(this.canvas);
|
|
75
|
+
this.onResize = () => this.resize();
|
|
76
|
+
this.onMouseMove = (event) => {
|
|
77
|
+
if (this.options.type !== 'particles')
|
|
78
|
+
return;
|
|
79
|
+
const rect = this.container.getBoundingClientRect();
|
|
80
|
+
this.mouse = {
|
|
81
|
+
x: event.clientX - rect.left,
|
|
82
|
+
y: event.clientY - rect.top,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
this.onMouseLeave = () => {
|
|
86
|
+
this.mouse = { x: -9999, y: -9999 };
|
|
87
|
+
};
|
|
88
|
+
container.addEventListener('mousemove', this.onMouseMove);
|
|
89
|
+
container.addEventListener('mouseleave', this.onMouseLeave);
|
|
90
|
+
window.addEventListener('resize', this.onResize);
|
|
91
|
+
this.particlesRef.current = [];
|
|
92
|
+
this.starsRef.current = [];
|
|
93
|
+
this.fallingRef.current = [];
|
|
94
|
+
this.frameCount = 0;
|
|
95
|
+
this.resize();
|
|
96
|
+
this.tick();
|
|
97
|
+
}
|
|
98
|
+
updateOptions(options) {
|
|
99
|
+
this.options = { ...this.options, ...options };
|
|
100
|
+
}
|
|
101
|
+
destroy() {
|
|
102
|
+
cancelAnimationFrame(this.raf);
|
|
103
|
+
this.container.removeEventListener('mousemove', this.onMouseMove);
|
|
104
|
+
this.container.removeEventListener('mouseleave', this.onMouseLeave);
|
|
105
|
+
window.removeEventListener('resize', this.onResize);
|
|
106
|
+
this.canvas.remove();
|
|
107
|
+
}
|
|
108
|
+
resize() {
|
|
109
|
+
const dpr = window.devicePixelRatio || 1;
|
|
110
|
+
const rect = this.container.getBoundingClientRect();
|
|
111
|
+
this.canvas.width = rect.width * dpr;
|
|
112
|
+
this.canvas.height = rect.height * dpr;
|
|
113
|
+
this.canvas.style.width = `${rect.width}px`;
|
|
114
|
+
this.canvas.style.height = `${rect.height}px`;
|
|
115
|
+
const ctx = this.canvas.getContext('2d');
|
|
116
|
+
if (ctx)
|
|
117
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { CanvasAnimationController };
|
|
@@ -1 +1,180 @@
|
|
|
1
|
-
import{GRAPHITE_PRESET_IDS
|
|
1
|
+
import { GRAPHITE_PRESET_IDS } from './graphite-presets.js';
|
|
2
|
+
|
|
3
|
+
const SPEED_MS_MIN = 500;
|
|
4
|
+
const SPEED_MS_MAX = 12000;
|
|
5
|
+
const SPEED_MS_BASE = 3000;
|
|
6
|
+
const speedDisplay = {
|
|
7
|
+
min: 0.2,
|
|
8
|
+
max: 4,
|
|
9
|
+
step: 0.1,
|
|
10
|
+
fixed: 1,
|
|
11
|
+
fromAttr: (ms) => {
|
|
12
|
+
const clamped = Math.min(SPEED_MS_MAX, Math.max(SPEED_MS_MIN, ms));
|
|
13
|
+
return Math.round((clamped / SPEED_MS_BASE) * 10) / 10;
|
|
14
|
+
},
|
|
15
|
+
toAttr: (mult) => {
|
|
16
|
+
const clamped = Math.min(4, Math.max(0.2, mult));
|
|
17
|
+
return Math.round(clamped * SPEED_MS_BASE);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const PRESET_OPTIONS = [
|
|
21
|
+
'(none)',
|
|
22
|
+
'neon_dream',
|
|
23
|
+
'sunset_bliss',
|
|
24
|
+
'deep_ocean',
|
|
25
|
+
'forest_mist',
|
|
26
|
+
'northern_lights',
|
|
27
|
+
'monochrome_fog',
|
|
28
|
+
'cotton_candy',
|
|
29
|
+
'cyber_glitch',
|
|
30
|
+
'golden_hour',
|
|
31
|
+
];
|
|
32
|
+
const C = {
|
|
33
|
+
speed: {
|
|
34
|
+
attr: 'speed',
|
|
35
|
+
label: 'Speed (×)',
|
|
36
|
+
kind: 'range',
|
|
37
|
+
min: SPEED_MS_MIN,
|
|
38
|
+
max: SPEED_MS_MAX,
|
|
39
|
+
step: 100,
|
|
40
|
+
default: SPEED_MS_BASE,
|
|
41
|
+
display: speedDisplay,
|
|
42
|
+
},
|
|
43
|
+
blur: { attr: 'blur', label: 'Blur', kind: 'range', min: 0, max: 200, step: 2, default: 80 },
|
|
44
|
+
opacity: { attr: 'opacity', label: 'Opacity', kind: 'range', min: 0, max: 1, step: 0.05, default: 1, fixed: 2 },
|
|
45
|
+
noise: { attr: 'noise', label: 'Noise', kind: 'range', min: 0, max: 0.4, step: 0.01, default: 0.05, fixed: 2 },
|
|
46
|
+
zoom: { attr: 'zoom', label: 'Zoom', kind: 'range', min: 0.5, max: 3, step: 0.1, default: 1, fixed: 1 },
|
|
47
|
+
particleCount: { attr: 'particle-count', label: 'Particle Count', kind: 'range', min: 10, max: 250, step: 5, default: 50 },
|
|
48
|
+
particleCountParticles: { attr: 'particle-count', label: 'Particle Count', kind: 'range', min: 10, max: 250, step: 5, default: 15 },
|
|
49
|
+
particleSize: { attr: 'particle-size', label: 'Particle Size', kind: 'range', min: 1, max: 10, step: 0.5, default: 2, fixed: 1 },
|
|
50
|
+
starCount: { attr: 'star-count', label: 'Star Count', kind: 'range', min: 20, max: 500, step: 10, default: 100 },
|
|
51
|
+
starSize: { attr: 'star-size', label: 'Star Size', kind: 'range', min: 0.5, max: 6, step: 0.5, default: 1.5, fixed: 1 },
|
|
52
|
+
wind: { attr: 'wind', label: 'Wind', kind: 'range', min: 0, max: 3, step: 0.1, default: 0.5, fixed: 1 },
|
|
53
|
+
direction: { attr: 'direction', label: 'Direction', kind: 'select', options: ['left', 'right', 'up', 'down', 'diagonal', 'radial'], default: 'left' },
|
|
54
|
+
intensity: { attr: 'intensity', label: 'Intensity', kind: 'select', options: ['subtle', 'medium', 'vivid'], default: 'subtle' },
|
|
55
|
+
theme: { attr: 'theme', label: 'Theme', kind: 'select', options: ['dark', 'light'], default: 'dark' },
|
|
56
|
+
preset: { attr: 'preset', label: 'Preset', kind: 'select', options: PRESET_OPTIONS, default: '(none)' },
|
|
57
|
+
showVignette: { attr: 'show-vignette', label: 'Vignette', kind: 'toggle', default: true },
|
|
58
|
+
shaderSpeed: { attr: 'shader-speed', label: 'Speed', kind: 'range', min: 0, max: 3, step: 0.01, default: 0.4, fixed: 2 },
|
|
59
|
+
shaderIntensity: { attr: 'shader-intensity', label: 'Intensity', kind: 'range', min: 0.1, max: 3, step: 0.01, default: 1.2, fixed: 2 },
|
|
60
|
+
grain: { attr: 'noise', label: 'Grain', kind: 'range', min: 0, max: 0.5, step: 0.01, default: 0.1, fixed: 2 },
|
|
61
|
+
scale: { attr: 'zoom', label: 'Scale', kind: 'range', min: 0.5, max: 5, step: 0.1, default: 1, fixed: 1 },
|
|
62
|
+
warp: { attr: 'warp', label: 'Warp', kind: 'range', min: 0, max: 2, step: 0.05, default: 1.4, fixed: 2 },
|
|
63
|
+
graphiteTheme: { attr: 'preset', label: 'Theme', kind: 'select', options: [...GRAPHITE_PRESET_IDS], default: 'graphite' },
|
|
64
|
+
};
|
|
65
|
+
function colors(defaults) {
|
|
66
|
+
return { attr: 'colors', label: 'Colors', kind: 'colors', default: defaults };
|
|
67
|
+
}
|
|
68
|
+
const TYPE_CONTROLS = {
|
|
69
|
+
particles: [C.particleCountParticles, C.particleSize, C.speed, C.opacity, colors(['#60a5fa', '#a78bfa', '#f472b6'])],
|
|
70
|
+
stars: [C.starCount, C.starSize, C.speed, C.opacity, colors(['#ffffff', '#e0e7ff', '#c7d2fe'])],
|
|
71
|
+
snow: [C.particleCount, C.particleSize, C.speed, C.wind, colors(['#ffffff', '#f0f9ff', '#e0f2fe'])],
|
|
72
|
+
flowers: [C.particleCount, C.particleSize, C.speed, C.wind, colors(['#ffb7c5', '#ff91a4', '#f8c8dc', '#ffc0cb'])],
|
|
73
|
+
confetti: [C.particleCount, C.particleSize, C.speed, C.wind, colors(['#f44336', '#e91e63', '#9c27b0', '#2196f3', '#4caf50', '#ffeb3b'])],
|
|
74
|
+
aurora: [C.intensity, C.blur, C.speed, C.theme, colors(['#4f46e5', '#ec4899', '#06b6d4', '#8b5cf6'])],
|
|
75
|
+
plasma: [C.speed, C.blur, C.noise, C.showVignette, C.preset, colors(['#7000FF', '#FF00AA', '#3300FF', '#FFCC00', '#00FFFF'])],
|
|
76
|
+
'mesh-flow': [C.speed, C.blur, C.noise, C.zoom, colors(['#4f46e5', '#ec4899', '#06b6d4', '#8b5cf6', '#22d3ee'])],
|
|
77
|
+
fluid: [C.speed, C.blur, C.noise, C.zoom, colors(['#001133', '#0044FF', '#00DDFF', '#00FFAA', '#000066'])],
|
|
78
|
+
radiant: [C.speed, C.blur, C.noise, C.zoom, colors(['#FF4E50', '#FC913A', '#F9D423', '#EDE574', '#E1F5C4'])],
|
|
79
|
+
ethereal: [C.speed, C.blur, C.noise, C.zoom, colors(['#7000FF', '#FF00AA', '#00FFFF', '#FFFFFF', '#3300FF'])],
|
|
80
|
+
graphite: [
|
|
81
|
+
C.shaderSpeed,
|
|
82
|
+
C.shaderIntensity,
|
|
83
|
+
C.grain,
|
|
84
|
+
C.scale,
|
|
85
|
+
C.warp,
|
|
86
|
+
C.graphiteTheme,
|
|
87
|
+
colors(['#000000', '#333333', '#b3b3b3']),
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
function getControlsForType(type) {
|
|
91
|
+
return TYPE_CONTROLS[type] ?? TYPE_CONTROLS.graphite;
|
|
92
|
+
}
|
|
93
|
+
function getControlSliderBounds(control) {
|
|
94
|
+
if (control.display) {
|
|
95
|
+
return {
|
|
96
|
+
min: control.display.min,
|
|
97
|
+
max: control.display.max,
|
|
98
|
+
step: control.display.step,
|
|
99
|
+
fixed: control.display.fixed,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
min: control.min ?? 0,
|
|
104
|
+
max: control.max ?? 100,
|
|
105
|
+
step: control.step ?? 1,
|
|
106
|
+
fixed: control.fixed,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function controlAttrToSlider(control, attrValue) {
|
|
110
|
+
if (control.display)
|
|
111
|
+
return control.display.fromAttr(attrValue);
|
|
112
|
+
return attrValue;
|
|
113
|
+
}
|
|
114
|
+
function controlSliderToAttr(control, sliderValue) {
|
|
115
|
+
if (control.display)
|
|
116
|
+
return control.display.toAttr(sliderValue);
|
|
117
|
+
return sliderValue;
|
|
118
|
+
}
|
|
119
|
+
function readControlValue(el, control) {
|
|
120
|
+
const raw = el.getAttribute(control.attr);
|
|
121
|
+
if (control.kind === 'colors') {
|
|
122
|
+
if (!raw)
|
|
123
|
+
return [...control.default];
|
|
124
|
+
try {
|
|
125
|
+
const parsed = JSON.parse(raw);
|
|
126
|
+
return Array.isArray(parsed) && parsed.length ? [...parsed] : [...control.default];
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
const split = raw.split(',').map((c) => c.trim()).filter(Boolean);
|
|
130
|
+
return split.length ? split : [...control.default];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (control.kind === 'toggle') {
|
|
134
|
+
if (raw === null)
|
|
135
|
+
return control.default;
|
|
136
|
+
return raw !== 'false';
|
|
137
|
+
}
|
|
138
|
+
if (control.kind === 'select') {
|
|
139
|
+
if (!raw)
|
|
140
|
+
return control.default;
|
|
141
|
+
return raw;
|
|
142
|
+
}
|
|
143
|
+
if (raw === null || raw === '')
|
|
144
|
+
return control.default;
|
|
145
|
+
const num = Number(raw);
|
|
146
|
+
return Number.isFinite(num) ? num : control.default;
|
|
147
|
+
}
|
|
148
|
+
function writeControlAttribute(el, control, value) {
|
|
149
|
+
if (control.kind === 'colors') {
|
|
150
|
+
el.setAttribute(control.attr, JSON.stringify(value));
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (control.kind === 'toggle') {
|
|
154
|
+
el.setAttribute(control.attr, value ? 'true' : 'false');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (control.kind === 'select') {
|
|
158
|
+
if (value === '(none)')
|
|
159
|
+
el.removeAttribute(control.attr);
|
|
160
|
+
else
|
|
161
|
+
el.setAttribute(control.attr, String(value));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
el.setAttribute(control.attr, String(value));
|
|
165
|
+
}
|
|
166
|
+
function resetControlsToDefaults(el, controls) {
|
|
167
|
+
controls.forEach((control) => {
|
|
168
|
+
const value = control.default;
|
|
169
|
+
if (control.kind === 'select' && value === control.default) {
|
|
170
|
+
if (value === '(none)')
|
|
171
|
+
el.removeAttribute(control.attr);
|
|
172
|
+
else
|
|
173
|
+
writeControlAttribute(el, control, value);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
writeControlAttribute(el, control, Array.isArray(value) ? [...value] : value);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { controlAttrToSlider, controlSliderToAttr, getControlSliderBounds, getControlsForType, readControlValue, resetControlsToDefaults, writeControlAttribute };
|
|
@@ -1 +1,196 @@
|
|
|
1
|
-
import{hexToRgb
|
|
1
|
+
import { hexToRgb } from './lumina-utils.js';
|
|
2
|
+
import { GRAPHITE_VS_SOURCE, GRAPHITE_FS_SOURCE } from './graphite-shader.js';
|
|
3
|
+
|
|
4
|
+
const CLASS = 'designbase-wc-animation-background';
|
|
5
|
+
const LERP = 0.05;
|
|
6
|
+
function loadShader(gl, type, source) {
|
|
7
|
+
const shader = gl.createShader(type);
|
|
8
|
+
if (!shader)
|
|
9
|
+
return null;
|
|
10
|
+
gl.shaderSource(shader, source);
|
|
11
|
+
gl.compileShader(shader);
|
|
12
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
13
|
+
gl.deleteShader(shader);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return shader;
|
|
17
|
+
}
|
|
18
|
+
function lerp(a, b, t) {
|
|
19
|
+
return a + (b - a) * t;
|
|
20
|
+
}
|
|
21
|
+
function lerpRgb(current, target, t) {
|
|
22
|
+
return [
|
|
23
|
+
lerp(current[0], target[0], t),
|
|
24
|
+
lerp(current[1], target[1], t),
|
|
25
|
+
lerp(current[2], target[2], t),
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
class GraphiteShaderController {
|
|
29
|
+
constructor(container, options) {
|
|
30
|
+
this.raf = 0;
|
|
31
|
+
this.startTime = performance.now();
|
|
32
|
+
this.current = {
|
|
33
|
+
shaderSpeed: 0,
|
|
34
|
+
shaderIntensity: 0,
|
|
35
|
+
grain: 0,
|
|
36
|
+
scale: 0,
|
|
37
|
+
warp: 0,
|
|
38
|
+
color1: [0, 0, 0],
|
|
39
|
+
color2: [0, 0, 0],
|
|
40
|
+
color3: [0, 0, 0],
|
|
41
|
+
};
|
|
42
|
+
this.render = () => {
|
|
43
|
+
const gl = this.gl;
|
|
44
|
+
const program = this.program;
|
|
45
|
+
const positionBuffer = this.positionBuffer;
|
|
46
|
+
if (!gl || !program || !positionBuffer)
|
|
47
|
+
return;
|
|
48
|
+
this.tickLerp();
|
|
49
|
+
const { width, height } = this.resizeCanvas();
|
|
50
|
+
if (width === 0 || height === 0) {
|
|
51
|
+
this.raf = requestAnimationFrame(this.render);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
gl.viewport(0, 0, width, height);
|
|
55
|
+
gl.useProgram(program);
|
|
56
|
+
const aVertexPosition = gl.getAttribLocation(program, 'aVertexPosition');
|
|
57
|
+
const uResolution = gl.getUniformLocation(program, 'uResolution');
|
|
58
|
+
const uTime = gl.getUniformLocation(program, 'uTime');
|
|
59
|
+
const uSpeed = gl.getUniformLocation(program, 'uSpeed');
|
|
60
|
+
const uIntensity = gl.getUniformLocation(program, 'uIntensity');
|
|
61
|
+
const uGrain = gl.getUniformLocation(program, 'uGrain');
|
|
62
|
+
const uScale = gl.getUniformLocation(program, 'uScale');
|
|
63
|
+
const uWarp = gl.getUniformLocation(program, 'uWarp');
|
|
64
|
+
const uColor1 = gl.getUniformLocation(program, 'uColor1');
|
|
65
|
+
const uColor2 = gl.getUniformLocation(program, 'uColor2');
|
|
66
|
+
const uColor3 = gl.getUniformLocation(program, 'uColor3');
|
|
67
|
+
gl.enableVertexAttribArray(aVertexPosition);
|
|
68
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
69
|
+
gl.vertexAttribPointer(aVertexPosition, 2, gl.FLOAT, false, 0, 0);
|
|
70
|
+
const elapsed = (performance.now() - this.startTime) / 1000;
|
|
71
|
+
if (uResolution)
|
|
72
|
+
gl.uniform2f(uResolution, width, height);
|
|
73
|
+
if (uTime)
|
|
74
|
+
gl.uniform1f(uTime, elapsed);
|
|
75
|
+
if (uSpeed)
|
|
76
|
+
gl.uniform1f(uSpeed, this.current.shaderSpeed);
|
|
77
|
+
if (uIntensity)
|
|
78
|
+
gl.uniform1f(uIntensity, this.current.shaderIntensity);
|
|
79
|
+
if (uGrain)
|
|
80
|
+
gl.uniform1f(uGrain, this.current.grain);
|
|
81
|
+
if (uScale)
|
|
82
|
+
gl.uniform1f(uScale, this.current.scale);
|
|
83
|
+
if (uWarp)
|
|
84
|
+
gl.uniform1f(uWarp, this.current.warp);
|
|
85
|
+
if (uColor1)
|
|
86
|
+
gl.uniform3fv(uColor1, this.current.color1);
|
|
87
|
+
if (uColor2)
|
|
88
|
+
gl.uniform3fv(uColor2, this.current.color2);
|
|
89
|
+
if (uColor3)
|
|
90
|
+
gl.uniform3fv(uColor3, this.current.color3);
|
|
91
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
92
|
+
this.raf = requestAnimationFrame(this.render);
|
|
93
|
+
};
|
|
94
|
+
this.container = container;
|
|
95
|
+
this.options = options;
|
|
96
|
+
this.canvas = document.createElement('canvas');
|
|
97
|
+
this.canvas.className = `${CLASS}__shader-canvas`;
|
|
98
|
+
container.appendChild(this.canvas);
|
|
99
|
+
this.syncCurrentImmediate(options);
|
|
100
|
+
this.init();
|
|
101
|
+
}
|
|
102
|
+
updateOptions(options) {
|
|
103
|
+
this.options = { ...this.options, ...options };
|
|
104
|
+
}
|
|
105
|
+
syncCurrentImmediate(options) {
|
|
106
|
+
const [c1, c2, c3] = this.resolveColors(options.colors);
|
|
107
|
+
this.current = {
|
|
108
|
+
shaderSpeed: options.shaderSpeed,
|
|
109
|
+
shaderIntensity: options.shaderIntensity,
|
|
110
|
+
grain: options.grain,
|
|
111
|
+
scale: options.scale,
|
|
112
|
+
warp: options.warp,
|
|
113
|
+
color1: hexToRgb(c1),
|
|
114
|
+
color2: hexToRgb(c2),
|
|
115
|
+
color3: hexToRgb(c3),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
resolveColors(colors) {
|
|
119
|
+
const c1 = colors[0] ?? '#000000';
|
|
120
|
+
const c2 = colors[1] ?? '#333333';
|
|
121
|
+
const c3 = colors[2] ?? '#b3b3b3';
|
|
122
|
+
return [c1, c2, c3];
|
|
123
|
+
}
|
|
124
|
+
resizeCanvas() {
|
|
125
|
+
const rect = this.container.getBoundingClientRect();
|
|
126
|
+
const dpr = window.devicePixelRatio || 1;
|
|
127
|
+
this.canvas.width = Math.max(1, rect.width * dpr);
|
|
128
|
+
this.canvas.height = Math.max(1, rect.height * dpr);
|
|
129
|
+
this.canvas.style.width = `${rect.width}px`;
|
|
130
|
+
this.canvas.style.height = `${rect.height}px`;
|
|
131
|
+
return { width: this.canvas.width, height: this.canvas.height };
|
|
132
|
+
}
|
|
133
|
+
init() {
|
|
134
|
+
const gl = this.canvas.getContext('webgl');
|
|
135
|
+
if (!gl)
|
|
136
|
+
return;
|
|
137
|
+
this.gl = gl;
|
|
138
|
+
const shaderProgram = gl.createProgram();
|
|
139
|
+
if (!shaderProgram)
|
|
140
|
+
return;
|
|
141
|
+
const vertexShader = loadShader(gl, gl.VERTEX_SHADER, GRAPHITE_VS_SOURCE);
|
|
142
|
+
const fragmentShader = loadShader(gl, gl.FRAGMENT_SHADER, GRAPHITE_FS_SOURCE);
|
|
143
|
+
if (!vertexShader || !fragmentShader)
|
|
144
|
+
return;
|
|
145
|
+
gl.attachShader(shaderProgram, vertexShader);
|
|
146
|
+
gl.attachShader(shaderProgram, fragmentShader);
|
|
147
|
+
gl.linkProgram(shaderProgram);
|
|
148
|
+
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS))
|
|
149
|
+
return;
|
|
150
|
+
this.program = shaderProgram;
|
|
151
|
+
this.vertexShader = vertexShader;
|
|
152
|
+
this.fragmentShader = fragmentShader;
|
|
153
|
+
const positionBuffer = gl.createBuffer();
|
|
154
|
+
if (!positionBuffer)
|
|
155
|
+
return;
|
|
156
|
+
this.positionBuffer = positionBuffer;
|
|
157
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
158
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
|
|
159
|
+
this.observer = new ResizeObserver(() => this.resizeCanvas());
|
|
160
|
+
this.observer.observe(this.container);
|
|
161
|
+
this.startTime = performance.now();
|
|
162
|
+
this.render();
|
|
163
|
+
}
|
|
164
|
+
tickLerp() {
|
|
165
|
+
const { colors, shaderSpeed, shaderIntensity, grain, scale, warp } = this.options;
|
|
166
|
+
const [c1, c2, c3] = this.resolveColors(colors);
|
|
167
|
+
const t1 = hexToRgb(c1);
|
|
168
|
+
const t2 = hexToRgb(c2);
|
|
169
|
+
const t3 = hexToRgb(c3);
|
|
170
|
+
this.current.shaderSpeed = lerp(this.current.shaderSpeed, shaderSpeed, LERP);
|
|
171
|
+
this.current.shaderIntensity = lerp(this.current.shaderIntensity, shaderIntensity, LERP);
|
|
172
|
+
this.current.grain = lerp(this.current.grain, grain, LERP);
|
|
173
|
+
this.current.scale = lerp(this.current.scale, scale, LERP);
|
|
174
|
+
this.current.warp = lerp(this.current.warp, warp, LERP);
|
|
175
|
+
this.current.color1 = lerpRgb(this.current.color1, t1, LERP);
|
|
176
|
+
this.current.color2 = lerpRgb(this.current.color2, t2, LERP);
|
|
177
|
+
this.current.color3 = lerpRgb(this.current.color3, t3, LERP);
|
|
178
|
+
}
|
|
179
|
+
destroy() {
|
|
180
|
+
cancelAnimationFrame(this.raf);
|
|
181
|
+
this.observer?.disconnect();
|
|
182
|
+
const gl = this.gl;
|
|
183
|
+
if (gl && this.program) {
|
|
184
|
+
if (this.vertexShader)
|
|
185
|
+
gl.deleteShader(this.vertexShader);
|
|
186
|
+
if (this.fragmentShader)
|
|
187
|
+
gl.deleteShader(this.fragmentShader);
|
|
188
|
+
if (this.positionBuffer)
|
|
189
|
+
gl.deleteBuffer(this.positionBuffer);
|
|
190
|
+
gl.deleteProgram(this.program);
|
|
191
|
+
}
|
|
192
|
+
this.canvas.remove();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { GraphiteShaderController };
|
|
@@ -1 +1,42 @@
|
|
|
1
|
-
const
|
|
1
|
+
const GRAPHITE_PRESETS = {
|
|
2
|
+
graphite: {
|
|
3
|
+
id: 'graphite',
|
|
4
|
+
colors: ['#000000', '#333333', '#b3b3b3'],
|
|
5
|
+
scale: 1.0,
|
|
6
|
+
},
|
|
7
|
+
abyss: {
|
|
8
|
+
id: 'abyss',
|
|
9
|
+
colors: ['#020617', '#0f172a', '#3b82f6'],
|
|
10
|
+
scale: 2.2,
|
|
11
|
+
},
|
|
12
|
+
cherry: {
|
|
13
|
+
id: 'cherry',
|
|
14
|
+
colors: ['#1a0505', '#4a0b1c', '#e11d48'],
|
|
15
|
+
scale: 2.8,
|
|
16
|
+
},
|
|
17
|
+
forest: {
|
|
18
|
+
id: 'forest',
|
|
19
|
+
colors: ['#021207', '#064e3b', '#10b981'],
|
|
20
|
+
scale: 2.0,
|
|
21
|
+
},
|
|
22
|
+
sunset: {
|
|
23
|
+
id: 'sunset',
|
|
24
|
+
colors: ['#170500', '#7c2d12', '#f97316'],
|
|
25
|
+
scale: 3.0,
|
|
26
|
+
},
|
|
27
|
+
amethyst: {
|
|
28
|
+
id: 'amethyst',
|
|
29
|
+
colors: ['#0f051a', '#3b0764', '#a855f7'],
|
|
30
|
+
scale: 2.4,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
const GRAPHITE_DEFAULT_COLORS = GRAPHITE_PRESETS.graphite.colors;
|
|
34
|
+
const GRAPHITE_PRESET_IDS = Object.keys(GRAPHITE_PRESETS);
|
|
35
|
+
function isGraphitePresetId(value) {
|
|
36
|
+
return Boolean(value && value in GRAPHITE_PRESETS);
|
|
37
|
+
}
|
|
38
|
+
function getGraphitePreset(id) {
|
|
39
|
+
return GRAPHITE_PRESETS[id];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { GRAPHITE_DEFAULT_COLORS, GRAPHITE_PRESETS, GRAPHITE_PRESET_IDS, getGraphitePreset, isGraphitePresetId };
|