@designbasekorea/ui-wc 0.5.6 → 0.6.1
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-35a9b0f5.js +1 -0
- package/dist/esm/components/animation-background/canvas-controller.js +1 -121
- package/dist/esm/components/animation-background/controls.js +1 -180
- package/dist/esm/components/animation-background/graphite-controller.js +1 -196
- package/dist/esm/components/animation-background/graphite-presets.js +1 -42
- package/dist/esm/components/animation-background/graphite-shader.js +1 -111
- package/dist/esm/components/animation-background/layers.js +1 -369
- package/dist/esm/components/animation-background/lumina-presets.js +1 -53
- package/dist/esm/components/animation-background/lumina-shaders.js +1 -181
- package/dist/esm/components/animation-background/lumina-utils.js +1 -60
- package/dist/esm/components/animation-background/particle-defaults.js +1 -36
- package/dist/esm/components/animation-background/renderers.js +1 -167
- package/dist/esm/components/animation-background/shader-controller.js +1 -154
- package/dist/esm/components/color-picker-utils.js +1 -134
- package/dist/esm/components/date-picker-utils.js +1 -140
- package/dist/esm/components/db-accordion.js +1 -304
- package/dist/esm/components/db-ad-banner.js +1 -455
- package/dist/esm/components/db-ai-chat-list.d.ts +43 -0
- package/dist/esm/components/db-ai-chat-list.js +1 -0
- package/dist/esm/components/db-ai-chat.d.ts +159 -0
- package/dist/esm/components/db-ai-chat.js +1 -0
- package/dist/esm/components/db-alert.js +1 -149
- package/dist/esm/components/db-animation-background.js +1 -486
- package/dist/esm/components/db-animation-text.js +1 -601
- package/dist/esm/components/db-app-badge.js +1 -88
- package/dist/esm/components/db-audio-player.js +1 -752
- package/dist/esm/components/db-avatar.js +1 -188
- package/dist/esm/components/db-backdrop.js +1 -139
- package/dist/esm/components/db-badge.js +1 -91
- package/dist/esm/components/db-banner.js +1 -188
- package/dist/esm/components/db-bottom-navigation.js +1 -146
- package/dist/esm/components/db-bottom-sheet.js +1 -481
- package/dist/esm/components/db-breadcrumbs.js +1 -329
- package/dist/esm/components/db-button.js +1 -316
- package/dist/esm/components/db-calendar.js +1 -675
- package/dist/esm/components/db-card.js +1 -265
- package/dist/esm/components/db-carousel.js +1 -264
- package/dist/esm/components/db-chat-composer.d.ts +134 -0
- package/dist/esm/components/db-chat-composer.js +1 -0
- package/dist/esm/components/db-chat-list.d.ts +47 -0
- package/dist/esm/components/db-chat-list.js +1 -0
- package/dist/esm/components/db-chat-message.d.ts +39 -0
- package/dist/esm/components/db-chat-message.js +1 -0
- package/dist/esm/components/db-chat-orb.d.ts +99 -0
- package/dist/esm/components/db-chat-orb.js +1 -0
- package/dist/esm/components/db-chat-room.d.ts +71 -0
- package/dist/esm/components/db-chat-room.js +1 -0
- package/dist/esm/components/db-chat-suggestions.d.ts +44 -0
- package/dist/esm/components/db-chat-suggestions.js +1 -0
- package/dist/esm/components/db-chat-typing.d.ts +22 -0
- package/dist/esm/components/db-chat-typing.js +1 -0
- package/dist/esm/components/db-chat-welcome.d.ts +32 -0
- package/dist/esm/components/db-chat-welcome.js +1 -0
- package/dist/esm/components/db-chat-widget.d.ts +146 -0
- package/dist/esm/components/db-chat-widget.js +1 -0
- package/dist/esm/components/db-checkbox.js +1 -202
- package/dist/esm/components/db-chip.js +1 -104
- package/dist/esm/components/db-code-block.js +1 -304
- package/dist/esm/components/db-color-picker.js +1 -746
- package/dist/esm/components/db-confirm.js +1 -191
- package/dist/esm/components/db-container.js +1 -39
- package/dist/esm/components/db-context-menu.js +1 -265
- package/dist/esm/components/db-countdown.js +1 -146
- package/dist/esm/components/db-cursor-follower.js +1 -173
- package/dist/esm/components/db-date-picker.js +1 -837
- package/dist/esm/components/db-divider.js +1 -66
- package/dist/esm/components/db-download-progress.d.ts +89 -0
- package/dist/esm/components/db-download-progress.js +1 -0
- package/dist/esm/components/db-drawer.js +1 -245
- package/dist/esm/components/db-dropdown.js +1 -493
- package/dist/esm/components/db-dropzone.js +1 -266
- package/dist/esm/components/db-email-verify.d.ts +64 -0
- package/dist/esm/components/db-email-verify.js +1 -0
- package/dist/esm/components/db-empty-state.js +1 -97
- package/dist/esm/components/db-file-uploader.js +1 -256
- package/dist/esm/components/db-floating-action-button.js +1 -139
- package/dist/esm/components/db-footer.js +1 -385
- package/dist/esm/components/db-form.js +1 -566
- package/dist/esm/components/db-gantt.js +1 -882
- package/dist/esm/components/db-gradient.js +1 -133
- package/dist/esm/components/db-grid-background.js +1 -909
- package/dist/esm/components/db-grid.js +1 -73
- package/dist/esm/components/db-icons.d.ts +3 -0
- package/dist/esm/components/db-icons.js +1 -82
- package/dist/esm/components/db-image-list.js +1 -214
- package/dist/esm/components/db-image-placeholder.js +1 -96
- package/dist/esm/components/db-image.js +1 -289
- package/dist/esm/components/db-indicator.js +1 -517
- package/dist/esm/components/db-input.js +1 -420
- package/dist/esm/components/db-kanban.js +1 -538
- package/dist/esm/components/db-label.js +1 -66
- package/dist/esm/components/db-lightbox.js +1 -372
- package/dist/esm/components/db-list.js +1 -340
- package/dist/esm/components/db-logo-svg.js +1 -72
- package/dist/esm/components/db-logo.js +1 -106
- package/dist/esm/components/db-lottie.js +1 -109
- package/dist/esm/components/db-markdown-editor.js +1 -458
- package/dist/esm/components/db-marquee.js +1 -402
- package/dist/esm/components/db-masonry.js +1 -94
- package/dist/esm/components/db-menu-item.js +1 -211
- package/dist/esm/components/db-modal.js +1 -522
- package/dist/esm/components/db-navbar.js +1 -680
- package/dist/esm/components/db-onboarding-modal.js +1 -322
- package/dist/esm/components/db-otp-input.d.ts +53 -0
- package/dist/esm/components/db-otp-input.js +1 -0
- package/dist/esm/components/db-page-header.js +1 -312
- package/dist/esm/components/db-pagination.js +1 -271
- package/dist/esm/components/db-phone-verify.d.ts +63 -0
- package/dist/esm/components/db-phone-verify.js +1 -0
- package/dist/esm/components/db-popover.js +1 -580
- package/dist/esm/components/db-progress-step.js +1 -166
- package/dist/esm/components/db-progress.js +1 -171
- package/dist/esm/components/db-progressbar.js +1 -72
- package/dist/esm/components/db-radio.js +1 -172
- package/dist/esm/components/db-random-gradient.js +1 -121
- package/dist/esm/components/db-range-slider.js +1 -811
- package/dist/esm/components/db-rating.js +1 -325
- package/dist/esm/components/db-reorder.js +1 -286
- package/dist/esm/components/db-resizable-panels.js +1 -282
- package/dist/esm/components/db-scroll-area.js +1 -126
- package/dist/esm/components/db-search-bar.js +1 -668
- package/dist/esm/components/db-section-app-download.js +1 -101
- package/dist/esm/components/db-section-contact.js +1 -102
- package/dist/esm/components/db-section-cta.js +1 -150
- package/dist/esm/components/db-section-faq.js +1 -120
- package/dist/esm/components/db-section-feature-grid.js +1 -137
- package/dist/esm/components/db-section-feature.js +1 -179
- package/dist/esm/components/db-section-hero.js +1 -243
- package/dist/esm/components/db-section-logo-cloud.js +1 -138
- package/dist/esm/components/db-section-pricing.js +1 -166
- package/dist/esm/components/db-section-stats.js +1 -129
- package/dist/esm/components/db-section-testimonials.js +1 -252
- package/dist/esm/components/db-section.js +1 -385
- package/dist/esm/components/db-segment-control.js +1 -231
- package/dist/esm/components/db-select.js +1 -571
- package/dist/esm/components/db-share-icons.js +1 -40
- package/dist/esm/components/db-share.js +1 -489
- package/dist/esm/components/db-sidebar.d.ts +20 -0
- package/dist/esm/components/db-sidebar.js +1 -1068
- package/dist/esm/components/db-skeleton.js +1 -94
- package/dist/esm/components/db-spinner.js +1 -102
- package/dist/esm/components/db-split-view.js +1 -297
- package/dist/esm/components/db-stack.js +1 -46
- package/dist/esm/components/db-stat.js +1 -218
- package/dist/esm/components/db-stepper.js +1 -398
- package/dist/esm/components/db-table.js +1 -412
- package/dist/esm/components/db-tabs.js +1 -335
- package/dist/esm/components/db-testimonial.d.ts +2 -0
- package/dist/esm/components/db-testimonial.js +1 -162
- package/dist/esm/components/db-textarea.js +1 -233
- package/dist/esm/components/db-time-picker.js +1 -523
- package/dist/esm/components/db-timeline.js +1 -174
- package/dist/esm/components/db-toast.js +1 -158
- package/dist/esm/components/db-toggle.js +1 -162
- package/dist/esm/components/db-toolbar.js +1 -94
- package/dist/esm/components/db-tooltip.js +1 -440
- package/dist/esm/components/db-top-banner.js +1 -121
- package/dist/esm/components/db-tutorial.js +1 -324
- package/dist/esm/components/db-two-factor.d.ts +71 -0
- package/dist/esm/components/db-two-factor.js +1 -0
- package/dist/esm/components/db-video-player.js +1 -503
- package/dist/esm/components/db-youtube-player.js +1 -194
- package/dist/esm/components/highlight-code.js +1 -65
- package/dist/esm/components/input-validation.js +1 -50
- package/dist/esm/components/marketing-block-host-utils.js +1 -9
- package/dist/esm/components/number-scrub.js +1 -117
- package/dist/esm/components/random-gradient-palettes.js +1 -67
- package/dist/esm/components/section-block-header-utils.js +1 -48
- package/dist/esm/helpers/confirm.js +1 -52
- package/dist/esm/helpers/toast.js +1 -73
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +1 -111
- package/dist/esm/node_modules/prismjs/components/prism-bash.js +1 -235
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +1 -31
- package/dist/esm/node_modules/prismjs/components/prism-css.js +1 -64
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +1 -172
- package/dist/esm/node_modules/prismjs/components/prism-json.js +1 -27
- package/dist/esm/node_modules/prismjs/components/prism-jsx.js +1 -143
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +1 -186
- package/dist/esm/node_modules/prismjs/components/prism-scss.js +1 -81
- package/dist/esm/node_modules/prismjs/components/prism-tsx.js +1 -15
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +1 -60
- package/dist/index.cjs +1 -55414
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1125 -2
- package/dist/index.esm.js +1 -38284
- package/dist/react/chunks/lottie-14e7addb.js +1 -0
- package/dist/react/index.cjs +1 -56503
- package/dist/react/index.d.ts +1637 -21
- package/dist/react/index.esm.js +1 -39373
- package/package.json +2 -2
- package/dist/chunks/lottie-e273b936.js +0 -17032
- package/dist/react/chunks/lottie-72a4c6d4.js +0 -17032
|
@@ -1,121 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{drawFallingParticles as e,drawStars as t,drawParticles as s}from"./renderers.js";import{toSpeedRate as i}from"./lumina-utils.js";const n=["snow","flowers","confetti"];class CanvasAnimationController{constructor(o,a){this.raf=0,this.frameCount=0,this.mouse={x:-9999,y:-9999},this.particlesRef={current:[]},this.starsRef={current:[]},this.fallingRef={current:[]},this.tick=()=>{const o=this.canvas.getContext("2d");if(!o)return void(this.raf=requestAnimationFrame(this.tick));const a=window.devicePixelRatio||1,r=this.canvas.width/a,c=this.canvas.height/a,{type:h,colors:l,speed:u,particleCount:v,particleSize:m,starCount:d,starSize:p,clickable:f,wind:w,layerOpacity:R}=this.options;o.clearRect(0,0,r,c);const g=i(u),y=this.frameCount*g;switch(this.frameCount+=1,h){case"particles":s(o,r,c,this.particlesRef,{count:v,colors:l,size:m,speed:u,mouse:this.mouse,clickable:f,layerOpacity:R});break;case"stars":t(o,r,c,this.starsRef,{count:d,colors:l,size:p,time:y,layerOpacity:R,speedRate:g});break;case"snow":case"flowers":case"confetti":(function isFallingType(e){return n.includes(e)})(h)&&e(o,r,c,this.fallingRef,h,{count:v,colors:l,size:m,speed:u,wind:w,layerOpacity:R})}this.raf=requestAnimationFrame(this.tick)},this.container=o,this.options=a,this.canvas=document.createElement("canvas"),this.canvas.className="designbase-wc-animation-background__canvas",o.appendChild(this.canvas),this.onResize=()=>this.resize(),this.onMouseMove=e=>{if("particles"!==this.options.type)return;const t=this.container.getBoundingClientRect();this.mouse={x:e.clientX-t.left,y:e.clientY-t.top}},this.onMouseLeave=()=>{this.mouse={x:-9999,y:-9999}},o.addEventListener("mousemove",this.onMouseMove),o.addEventListener("mouseleave",this.onMouseLeave),window.addEventListener("resize",this.onResize),this.particlesRef.current=[],this.starsRef.current=[],this.fallingRef.current=[],this.frameCount=0,this.resize(),this.tick()}updateOptions(e){this.options={...this.options,...e}}destroy(){cancelAnimationFrame(this.raf),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseleave",this.onMouseLeave),window.removeEventListener("resize",this.onResize),this.canvas.remove()}resize(){const e=window.devicePixelRatio||1,t=this.container.getBoundingClientRect();this.canvas.width=t.width*e,this.canvas.height=t.height*e,this.canvas.style.width=`${t.width}px`,this.canvas.style.height=`${t.height}px`;const s=this.canvas.getContext("2d");s&&s.setTransform(e,0,0,e,0,0)}}export{CanvasAnimationController};
|
|
@@ -1,180 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{GRAPHITE_PRESET_IDS as e}from"./graphite-presets.js";const t=3e3,r={speed:{attr:"speed",label:"Speed (×)",kind:"range",min:500,max:12e3,step:100,default:t,display:{min:.2,max:4,step:.1,fixed:1,fromAttr:e=>{const r=Math.min(12e3,Math.max(500,e));return Math.round(r/t*10)/10},toAttr:e=>{const r=Math.min(4,Math.max(.2,e));return Math.round(r*t)}}},blur:{attr:"blur",label:"Blur",kind:"range",min:0,max:200,step:2,default:80},opacity:{attr:"opacity",label:"Opacity",kind:"range",min:0,max:1,step:.05,default:1,fixed:2},noise:{attr:"noise",label:"Noise",kind:"range",min:0,max:.4,step:.01,default:.05,fixed:2},zoom:{attr:"zoom",label:"Zoom",kind:"range",min:.5,max:3,step:.1,default:1,fixed:1},particleCount:{attr:"particle-count",label:"Particle Count",kind:"range",min:10,max:250,step:5,default:50},particleCountParticles:{attr:"particle-count",label:"Particle Count",kind:"range",min:10,max:250,step:5,default:15},particleSize:{attr:"particle-size",label:"Particle Size",kind:"range",min:1,max:10,step:.5,default:2,fixed:1},starCount:{attr:"star-count",label:"Star Count",kind:"range",min:20,max:500,step:10,default:100},starSize:{attr:"star-size",label:"Star Size",kind:"range",min:.5,max:6,step:.5,default:1.5,fixed:1},wind:{attr:"wind",label:"Wind",kind:"range",min:0,max:3,step:.1,default:.5,fixed:1},direction:{attr:"direction",label:"Direction",kind:"select",options:["left","right","up","down","diagonal","radial"],default:"left"},intensity:{attr:"intensity",label:"Intensity",kind:"select",options:["subtle","medium","vivid"],default:"subtle"},theme:{attr:"theme",label:"Theme",kind:"select",options:["dark","light"],default:"dark"},preset:{attr:"preset",label:"Preset",kind:"select",options:["(none)","neon_dream","sunset_bliss","deep_ocean","forest_mist","northern_lights","monochrome_fog","cotton_candy","cyber_glitch","golden_hour"],default:"(none)"},showVignette:{attr:"show-vignette",label:"Vignette",kind:"toggle",default:!0},shaderSpeed:{attr:"shader-speed",label:"Speed",kind:"range",min:0,max:3,step:.01,default:.4,fixed:2},shaderIntensity:{attr:"shader-intensity",label:"Intensity",kind:"range",min:.1,max:3,step:.01,default:1.2,fixed:2},grain:{attr:"noise",label:"Grain",kind:"range",min:0,max:.5,step:.01,default:.1,fixed:2},scale:{attr:"zoom",label:"Scale",kind:"range",min:.5,max:5,step:.1,default:1,fixed:1},warp:{attr:"warp",label:"Warp",kind:"range",min:0,max:2,step:.05,default:1.4,fixed:2},graphiteTheme:{attr:"preset",label:"Theme",kind:"select",options:[...e],default:"graphite"}};function colors(e){return{attr:"colors",label:"Colors",kind:"colors",default:e}}const a={particles:[r.particleCountParticles,r.particleSize,r.speed,r.opacity,colors(["#60a5fa","#a78bfa","#f472b6"])],stars:[r.starCount,r.starSize,r.speed,r.opacity,colors(["#ffffff","#e0e7ff","#c7d2fe"])],snow:[r.particleCount,r.particleSize,r.speed,r.wind,colors(["#ffffff","#f0f9ff","#e0f2fe"])],flowers:[r.particleCount,r.particleSize,r.speed,r.wind,colors(["#ffb7c5","#ff91a4","#f8c8dc","#ffc0cb"])],confetti:[r.particleCount,r.particleSize,r.speed,r.wind,colors(["#f44336","#e91e63","#9c27b0","#2196f3","#4caf50","#ffeb3b"])],aurora:[r.intensity,r.blur,r.speed,r.theme,colors(["#4f46e5","#ec4899","#06b6d4","#8b5cf6"])],plasma:[r.speed,r.blur,r.noise,r.showVignette,r.preset,colors(["#7000FF","#FF00AA","#3300FF","#FFCC00","#00FFFF"])],"mesh-flow":[r.speed,r.blur,r.noise,r.zoom,colors(["#4f46e5","#ec4899","#06b6d4","#8b5cf6","#22d3ee"])],fluid:[r.speed,r.blur,r.noise,r.zoom,colors(["#001133","#0044FF","#00DDFF","#00FFAA","#000066"])],radiant:[r.speed,r.blur,r.noise,r.zoom,colors(["#FF4E50","#FC913A","#F9D423","#EDE574","#E1F5C4"])],ethereal:[r.speed,r.blur,r.noise,r.zoom,colors(["#7000FF","#FF00AA","#00FFFF","#FFFFFF","#3300FF"])],graphite:[r.shaderSpeed,r.shaderIntensity,r.grain,r.scale,r.warp,r.graphiteTheme,colors(["#000000","#333333","#b3b3b3"])]};function getControlsForType(e){return a[e]??a.graphite}function getControlSliderBounds(e){return e.display?{min:e.display.min,max:e.display.max,step:e.display.step,fixed:e.display.fixed}:{min:e.min??0,max:e.max??100,step:e.step??1,fixed:e.fixed}}function controlAttrToSlider(e,t){return e.display?e.display.fromAttr(t):t}function controlSliderToAttr(e,t){return e.display?e.display.toAttr(t):t}function readControlValue(e,t){const r=e.getAttribute(t.attr);if("colors"===t.kind){if(!r)return[...t.default];try{const e=JSON.parse(r);return Array.isArray(e)&&e.length?[...e]:[...t.default]}catch{const e=r.split(",").map(e=>e.trim()).filter(Boolean);return e.length?e:[...t.default]}}if("toggle"===t.kind)return null===r?t.default:"false"!==r;if("select"===t.kind)return r||t.default;if(null===r||""===r)return t.default;const a=Number(r);return Number.isFinite(a)?a:t.default}function writeControlAttribute(e,t,r){"colors"!==t.kind?"toggle"!==t.kind?"select"!==t.kind?e.setAttribute(t.attr,String(r)):"(none)"===r?e.removeAttribute(t.attr):e.setAttribute(t.attr,String(r)):e.setAttribute(t.attr,r?"true":"false"):e.setAttribute(t.attr,JSON.stringify(r))}function resetControlsToDefaults(e,t){t.forEach(t=>{const r=t.default;"select"!==t.kind||r!==t.default?writeControlAttribute(e,t,Array.isArray(r)?[...r]:r):"(none)"===r?e.removeAttribute(t.attr):writeControlAttribute(e,t,r)})}export{controlAttrToSlider,controlSliderToAttr,getControlSliderBounds,getControlsForType,readControlValue,resetControlsToDefaults,writeControlAttribute};
|
|
@@ -1,196 +1 @@
|
|
|
1
|
-
import
|
|
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
|
+
import{hexToRgb as r}from"./lumina-utils.js";import{GRAPHITE_VS_SOURCE as e,GRAPHITE_FS_SOURCE as t}from"./graphite-shader.js";const i=.05;function loadShader(r,e,t){const i=r.createShader(e);return i?(r.shaderSource(i,t),r.compileShader(i),r.getShaderParameter(i,r.COMPILE_STATUS)?i:(r.deleteShader(i),null)):null}function lerp(r,e,t){return r+(e-r)*t}function lerpRgb(r,e,t){return[lerp(r[0],e[0],t),lerp(r[1],e[1],t),lerp(r[2],e[2],t)]}class GraphiteShaderController{constructor(r,e){this.raf=0,this.startTime=performance.now(),this.current={shaderSpeed:0,shaderIntensity:0,grain:0,scale:0,warp:0,color1:[0,0,0],color2:[0,0,0],color3:[0,0,0]},this.render=()=>{const r=this.gl,e=this.program,t=this.positionBuffer;if(!r||!e||!t)return;this.tickLerp();const{width:i,height:n}=this.resizeCanvas();if(0===i||0===n)return void(this.raf=requestAnimationFrame(this.render));r.viewport(0,0,i,n),r.useProgram(e);const s=r.getAttribLocation(e,"aVertexPosition"),o=r.getUniformLocation(e,"uResolution"),a=r.getUniformLocation(e,"uTime"),h=r.getUniformLocation(e,"uSpeed"),c=r.getUniformLocation(e,"uIntensity"),u=r.getUniformLocation(e,"uGrain"),l=r.getUniformLocation(e,"uScale"),d=r.getUniformLocation(e,"uWarp"),f=r.getUniformLocation(e,"uColor1"),m=r.getUniformLocation(e,"uColor2"),p=r.getUniformLocation(e,"uColor3");r.enableVertexAttribArray(s),r.bindBuffer(r.ARRAY_BUFFER,t),r.vertexAttribPointer(s,2,r.FLOAT,!1,0,0);const g=(performance.now()-this.startTime)/1e3;o&&r.uniform2f(o,i,n),a&&r.uniform1f(a,g),h&&r.uniform1f(h,this.current.shaderSpeed),c&&r.uniform1f(c,this.current.shaderIntensity),u&&r.uniform1f(u,this.current.grain),l&&r.uniform1f(l,this.current.scale),d&&r.uniform1f(d,this.current.warp),f&&r.uniform3fv(f,this.current.color1),m&&r.uniform3fv(m,this.current.color2),p&&r.uniform3fv(p,this.current.color3),r.drawArrays(r.TRIANGLE_STRIP,0,4),this.raf=requestAnimationFrame(this.render)},this.container=r,this.options=e,this.canvas=document.createElement("canvas"),this.canvas.className="designbase-wc-animation-background__shader-canvas",r.appendChild(this.canvas),this.syncCurrentImmediate(e),this.init()}updateOptions(r){this.options={...this.options,...r}}syncCurrentImmediate(e){const[t,i,n]=this.resolveColors(e.colors);this.current={shaderSpeed:e.shaderSpeed,shaderIntensity:e.shaderIntensity,grain:e.grain,scale:e.scale,warp:e.warp,color1:r(t),color2:r(i),color3:r(n)}}resolveColors(r){return[r[0]??"#000000",r[1]??"#333333",r[2]??"#b3b3b3"]}resizeCanvas(){const r=this.container.getBoundingClientRect(),e=window.devicePixelRatio||1;return this.canvas.width=Math.max(1,r.width*e),this.canvas.height=Math.max(1,r.height*e),this.canvas.style.width=`${r.width}px`,this.canvas.style.height=`${r.height}px`,{width:this.canvas.width,height:this.canvas.height}}init(){const r=this.canvas.getContext("webgl");if(!r)return;this.gl=r;const i=r.createProgram();if(!i)return;const n=loadShader(r,r.VERTEX_SHADER,e),s=loadShader(r,r.FRAGMENT_SHADER,t);if(!n||!s)return;if(r.attachShader(i,n),r.attachShader(i,s),r.linkProgram(i),!r.getProgramParameter(i,r.LINK_STATUS))return;this.program=i,this.vertexShader=n,this.fragmentShader=s;const o=r.createBuffer();o&&(this.positionBuffer=o,r.bindBuffer(r.ARRAY_BUFFER,o),r.bufferData(r.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),r.STATIC_DRAW),this.observer=new ResizeObserver(()=>this.resizeCanvas()),this.observer.observe(this.container),this.startTime=performance.now(),this.render())}tickLerp(){const{colors:e,shaderSpeed:t,shaderIntensity:n,grain:s,scale:o,warp:a}=this.options,[h,c,u]=this.resolveColors(e),l=r(h),d=r(c),f=r(u);this.current.shaderSpeed=lerp(this.current.shaderSpeed,t,i),this.current.shaderIntensity=lerp(this.current.shaderIntensity,n,i),this.current.grain=lerp(this.current.grain,s,i),this.current.scale=lerp(this.current.scale,o,i),this.current.warp=lerp(this.current.warp,a,i),this.current.color1=lerpRgb(this.current.color1,l,i),this.current.color2=lerpRgb(this.current.color2,d,i),this.current.color3=lerpRgb(this.current.color3,f,i)}destroy(){cancelAnimationFrame(this.raf),this.observer?.disconnect();const r=this.gl;r&&this.program&&(this.vertexShader&&r.deleteShader(this.vertexShader),this.fragmentShader&&r.deleteShader(this.fragmentShader),this.positionBuffer&&r.deleteBuffer(this.positionBuffer),r.deleteProgram(this.program)),this.canvas.remove()}}export{GraphiteShaderController};
|
|
@@ -1,42 +1 @@
|
|
|
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 };
|
|
1
|
+
const e={graphite:{id:"graphite",colors:["#000000","#333333","#b3b3b3"],scale:1},abyss:{id:"abyss",colors:["#020617","#0f172a","#3b82f6"],scale:2.2},cherry:{id:"cherry",colors:["#1a0505","#4a0b1c","#e11d48"],scale:2.8},forest:{id:"forest",colors:["#021207","#064e3b","#10b981"],scale:2},sunset:{id:"sunset",colors:["#170500","#7c2d12","#f97316"],scale:3},amethyst:{id:"amethyst",colors:["#0f051a","#3b0764","#a855f7"],scale:2.4}},s=e.graphite.colors,r=Object.keys(e);function isGraphitePresetId(s){return Boolean(s&&s in e)}function getGraphitePreset(s){return e[s]}export{s as GRAPHITE_DEFAULT_COLORS,e as GRAPHITE_PRESETS,r as GRAPHITE_PRESET_IDS,getGraphitePreset,isGraphitePresetId};
|