real-time-gradient 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -176,56 +176,69 @@ gradient.triggerEffect({ hue: "gold", duration: 2000 });
176
176
 
177
177
  ```ts
178
178
  // index.d.ts
179
- declare module "real-time-gradient" {
180
- type GradientType = "linear" | "radial";
179
+ export type GradientType = "linear" | "radial";
181
180
 
182
- type HuePreset = "white" | "black" | "gold" | "silver" | string;
183
- // string allows custom hex codes "#RRGGBB"
181
+ export type HuePreset = "white" | "black" | "gold" | "silver" | string;
184
182
 
185
- interface ScheduleEntry {
186
- time: string; // "HH:MM" in 24h format
187
- colors: string[]; // array of CSS color values
188
- type?: GradientType;
189
- direction?: string;
183
+ export interface ScheduleEntry {
184
+ time: string;
185
+ colors: string[];
186
+ }
187
+
188
+ export interface GradientOptions {
189
+ type?: GradientType;
190
+ direction?: string;
191
+ colors?: string[];
192
+ transitionDuration?: number;
193
+ schedule?: ScheduleEntry[];
194
+ textClip?: boolean;
195
+ }
196
+
197
+ export interface EffectOptions {
198
+ applyColors?: string[];
199
+ duration?: number;
200
+ hue?: HuePreset;
201
+ }
202
+
203
+ export class DynamicGradient {
204
+ private container: HTMLElement;
205
+ private options: GradientOptions;
206
+
207
+ constructor(container: string | HTMLElement, options: GradientOptions = {}) {
208
+ this.container =
209
+ typeof container === "string"
210
+ ? (document.querySelector(container) as HTMLElement)
211
+ : container;
212
+
213
+ this.options = options;
214
+ }
215
+
216
+ static init(container: string | HTMLElement, options?: GradientOptions) {
217
+ return new DynamicGradient(container, options);
190
218
  }
191
219
 
192
- interface GradientOptions {
220
+ setGradient(options: {
221
+ colors: string[];
193
222
  type?: GradientType;
194
223
  direction?: string;
195
- colors?: string[];
196
- transitionDuration?: number;
197
- schedule?: ScheduleEntry[];
198
- textClip?: boolean;
224
+ }): void {
225
+ // implementation
199
226
  }
200
227
 
201
- interface EffectOptions {
202
- applyColors?: string[];
203
- duration?: number;
204
- hue?: HuePreset;
228
+ schedule(entries: ScheduleEntry[]): void {
229
+ // implementation
205
230
  }
206
231
 
207
- export class DynamicGradient {
208
- constructor(container: string | HTMLElement, options?: GradientOptions);
209
-
210
- static init(
211
- container: string | HTMLElement,
212
- options?: GradientOptions
213
- ): DynamicGradient;
214
-
215
- setGradient(options: {
216
- colors: string[];
217
- type?: GradientType;
218
- direction?: string;
219
- }): void;
220
-
221
- schedule(entries: ScheduleEntry[]): void;
222
-
223
- triggerEffect(options?: EffectOptions): void;
232
+ triggerEffect(options?: EffectOptions): void {
233
+ // implementation
234
+ }
224
235
 
225
- persistEffect(colors: string[], duration?: number): void;
236
+ persistEffect(colors: string[], duration?: number): void {
237
+ // implementation
238
+ }
226
239
 
227
- stopEffects(): void;
228
- destroy(): void;
240
+ stopEffects(): void {
241
+ // implementation
229
242
  }
230
243
  }
231
244
  ```
package/dist/index.d.ts CHANGED
@@ -1 +1,25 @@
1
- export {}
1
+ export type GradientType = "linear" | "radial";
2
+ export interface ScheduleEntry {
3
+ time: string;
4
+ colors: string[];
5
+ type?: GradientType;
6
+ direction?: string;
7
+ }
8
+ export interface GradientOptions {
9
+ type?: GradientType;
10
+ direction?: string;
11
+ colors?: string[];
12
+ transitionDuration?: number;
13
+ schedule?: ScheduleEntry[];
14
+ textClip?: boolean;
15
+ }
16
+ export interface EffectOptions {
17
+ applyColors?: string[];
18
+ duration?: number;
19
+ hue?: "white" | "black" | "gold" | "silver" | string;
20
+ loop?: boolean;
21
+ }
22
+ export declare const DynamicGradient: {
23
+ new (container: string | HTMLElement, options?: GradientOptions): any;
24
+ init(container: string | HTMLElement, options?: GradientOptions): any;
25
+ };
package/dist/index.es.js CHANGED
@@ -16,7 +16,7 @@ function f(n, e, t) {
16
16
  transition: `opacity ${t}ms ease-in-out`
17
17
  }), n.appendChild(i), i;
18
18
  }
19
- function m(n, e, t) {
19
+ function v(n, e, t) {
20
20
  const i = document.createElement("span");
21
21
  i.textContent = n.textContent, Object.assign(i.style, {
22
22
  position: "absolute",
@@ -36,21 +36,21 @@ function m(n, e, t) {
36
36
  zIndex: 20
37
37
  });
38
38
  const s = n.parentNode;
39
- getComputedStyle(s).position === "static" && (s.style.position = "relative"), s.appendChild(i), requestAnimationFrame(() => {
39
+ return getComputedStyle(s).position === "static" && (s.style.position = "relative"), s.appendChild(i), requestAnimationFrame(() => {
40
40
  i.style.opacity = "1";
41
- });
41
+ }), i;
42
42
  }
43
43
  function b(n, e) {
44
44
  if (n.__dgTextFx && n.__dgTextFx.duration !== e) {
45
- const { a, b: o } = n.__dgTextFx;
46
- return a.style.transition = o.style.transition = `opacity ${e}ms ease-in-out`, n.__dgTextFx.duration = e, n.__dgTextFx;
45
+ const { a: o, b: a } = n.__dgTextFx;
46
+ return o.style.transition = a.style.transition = `opacity ${e}ms ease-in-out`, n.__dgTextFx.duration = e, n.__dgTextFx;
47
47
  }
48
48
  if (n.__dgTextFx) return n.__dgTextFx;
49
49
  const t = n.parentNode;
50
50
  getComputedStyle(t).position === "static" && (t.style.position = "relative");
51
- const i = (a) => {
52
- const o = document.createElement("span");
53
- return o.textContent = n.textContent, Object.assign(o.style, {
51
+ const i = (o) => {
52
+ const a = document.createElement("span");
53
+ return a.textContent = n.textContent, Object.assign(a.style, {
54
54
  position: "absolute",
55
55
  top: 0,
56
56
  left: 0,
@@ -64,9 +64,9 @@ function b(n, e) {
64
64
  pointerEvents: "none",
65
65
  opacity: "0",
66
66
  willChange: "opacity",
67
- zIndex: a,
67
+ zIndex: o,
68
68
  transition: `opacity ${e}ms ease-in-out`
69
- }), t.appendChild(o), o;
69
+ }), t.appendChild(a), a;
70
70
  }, s = i(20), r = i(21);
71
71
  return n.__dgTextFx = { a: s, b: r, visible: null, duration: e }, n.__dgTextFx;
72
72
  }
@@ -89,7 +89,7 @@ const p = {
89
89
  gold: "#ffe864ff",
90
90
  silver: "#d4d4d4ff"
91
91
  };
92
- class g {
92
+ let I = class g {
93
93
  constructor(e, t = {}) {
94
94
  if (this.container = typeof e == "string" ? document.querySelector(e) : e, !this.container)
95
95
  throw new Error("DynamicGradient: container not found.");
@@ -97,27 +97,20 @@ class g {
97
97
  }
98
98
  /** Apply gradient with optional transition */
99
99
  applyGradient(e = this.colors, t = this.type, i = this.direction, s = !0) {
100
- const r = c(e, t, i), a = this.container.style.background;
101
- if (r !== a) {
102
- if (this.textClip) {
103
- const o = m(
104
- this.container,
105
- r,
106
- this.duration
107
- );
108
- this.container.style.background = o, this.container.style.fontWeight = "inherit";
109
- } else
110
- s ? (this.transitionOverlay && this.transitionOverlay.remove(), this.transitionOverlay = f(
111
- this.container,
112
- r,
113
- this.transitionDuration
114
- ), requestAnimationFrame(() => {
115
- this.transitionOverlay.style.opacity = "1";
116
- }), setTimeout(() => {
117
- this.container.style.background = r, this.transitionOverlay.remove(), this.transitionOverlay = null;
118
- }, this.transitionDuration)) : this.container.style.background = r;
119
- this.colors = e, this.type = t, this.direction = i;
120
- }
100
+ const r = c(e, t, i), o = this.container.style.background;
101
+ r !== o && (this.textClip ? (v(
102
+ this.container,
103
+ r,
104
+ this.transitionDuration
105
+ ), this.container.style.fontWeight = "inherit") : s ? (this.transitionOverlay && this.transitionOverlay.remove(), this.transitionOverlay = f(
106
+ this.container,
107
+ r,
108
+ this.transitionDuration
109
+ ), requestAnimationFrame(() => {
110
+ this.transitionOverlay.style.opacity = "1";
111
+ }), setTimeout(() => {
112
+ this.container.style.background = r, this.transitionOverlay.remove(), this.transitionOverlay = null;
113
+ }, this.transitionDuration)) : this.container.style.background = r, this.colors = e, this.type = t, this.direction = i);
121
114
  }
122
115
  /** Allow toggling text-clip dynamically */
123
116
  setTextClip(e = !0) {
@@ -132,10 +125,10 @@ class g {
132
125
  } = {}) {
133
126
  let r;
134
127
  p[s] ? r = p[s] : /^#([0-9A-F]{3}){1,2}$/i.test(s) ? r = s : r = "#ffffff";
135
- const a = e ? c(e, this.type, this.direction) : c([...this.colors, r], this.type, this.direction);
128
+ const o = e ? c(e, this.type, this.direction) : c([...this.colors, r], this.type, this.direction);
136
129
  if (this.textClip) {
137
130
  const y = b(this.container, t), d = () => {
138
- const { a: h, b: v, visible: x } = y, l = x === "a" ? v : h, T = e ? c(e, this.type, this.direction) : c(
131
+ const { a: h, b: m, visible: x } = y, l = x === "a" ? m : h, T = e ? c(e, this.type, this.direction) : c(
139
132
  [...this.colors, p[s] || r],
140
133
  this.type,
141
134
  this.direction
@@ -152,7 +145,7 @@ class g {
152
145
  this.type,
153
146
  this.direction,
154
147
  !1
155
- ), h.style.opacity = "0", v.style.opacity = "0";
148
+ ), h.style.opacity = "0", m.style.opacity = "0";
156
149
  }, t * 2);
157
150
  };
158
151
  d();
@@ -160,16 +153,16 @@ class g {
160
153
  }
161
154
  this.effectOverlay || (this.effectOverlay = f(
162
155
  this.container,
163
- a,
156
+ o,
164
157
  t
165
158
  ));
166
- const o = this.effectOverlay, u = () => {
167
- o.style.background = a, o.style.opacity = "1", setTimeout(() => {
168
- o.style.opacity = "0";
159
+ const a = this.effectOverlay, u = () => {
160
+ a.style.background = o, a.style.opacity = "1", setTimeout(() => {
161
+ a.style.opacity = "0";
169
162
  }, t);
170
163
  };
171
164
  this.effectRunning || (this.effectRunning = !0, u(), i ? (this.effectLoopInterval && clearInterval(this.effectLoopInterval), this.effectLoopInterval = setInterval(u, t * 2)) : setTimeout(() => {
172
- o.remove(), this.effectOverlay = null;
165
+ a.remove(), this.effectOverlay = null;
173
166
  }, t * 2));
174
167
  }
175
168
  persistEffect(e = this.colors, t = this.transitionDuration) {
@@ -179,7 +172,7 @@ class g {
179
172
  this.direction
180
173
  );
181
174
  if (this.textClip) {
182
- const s = m(
175
+ const s = v(
183
176
  this.container,
184
177
  i,
185
178
  t
@@ -206,8 +199,8 @@ class g {
206
199
  this.stopEffects(), this.currentInterval && (clearInterval(this.currentInterval), this.currentInterval = null), this.transitionOverlay && (this.transitionOverlay.remove(), this.transitionOverlay = null), this.effectOverlay && (this.effectOverlay.remove(), this.effectOverlay = null);
207
200
  }
208
201
  setGradient({ colors: e, type: t, direction: i }) {
209
- const s = e || this.colors, r = t || this.type, a = i || this.direction;
210
- s.join(",") === this.colors.join(",") && r === this.type && a === this.direction || this.applyGradient(s, r, a, !0);
202
+ const s = e || this.colors, r = t || this.type, o = i || this.direction;
203
+ s.join(",") === this.colors.join(",") && r === this.type && o === this.direction || this.applyGradient(s, r, o, !0);
211
204
  }
212
205
  schedule(e = []) {
213
206
  this.scheduleData = e.map((t) => ({
@@ -225,7 +218,8 @@ class g {
225
218
  static init(e, t) {
226
219
  return new g(e, t);
227
220
  }
228
- }
221
+ };
222
+ const O = I;
229
223
  export {
230
- g as DynamicGradient
224
+ O as DynamicGradient
231
225
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.RealTimeGradient={}))})(this,function(h){"use strict";function l(n,e="linear",t="to right"){return e==="linear"?`linear-gradient(${t}, ${n.join(",")})`:`radial-gradient(circle, ${n.join(",")})`}function f(n,e,t){const i=document.createElement("div");return Object.assign(i.style,{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:0,background:e,opacity:"0",transition:`opacity ${t}ms ease-in-out`}),n.appendChild(i),i}function d(n,e,t){const i=document.createElement("span");i.textContent=n.textContent,Object.assign(i.style,{position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"inline-block",background:e,WebkitBackgroundClip:"text",backgroundClip:"text",WebkitTextFillColor:"transparent",color:"transparent",pointerEvents:"none",opacity:"0",transition:`opacity ${t}ms ease-in-out`,zIndex:20});const s=n.parentNode;getComputedStyle(s).position==="static"&&(s.style.position="relative"),s.appendChild(i),requestAnimationFrame(()=>{i.style.opacity="1"})}function T(n,e){if(n.__dgTextFx&&n.__dgTextFx.duration!==e){const{a,b:o}=n.__dgTextFx;return a.style.transition=o.style.transition=`opacity ${e}ms ease-in-out`,n.__dgTextFx.duration=e,n.__dgTextFx}if(n.__dgTextFx)return n.__dgTextFx;const t=n.parentNode;getComputedStyle(t).position==="static"&&(t.style.position="relative");const i=a=>{const o=document.createElement("span");return o.textContent=n.textContent,Object.assign(o.style,{position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"inline-block",WebkitBackgroundClip:"text",backgroundClip:"text",WebkitTextFillColor:"transparent",color:"transparent",pointerEvents:"none",opacity:"0",willChange:"opacity",zIndex:a,transition:`opacity ${e}ms ease-in-out`}),t.appendChild(o),o},s=i(20),r=i(21);return n.__dgTextFx={a:s,b:r,visible:null,duration:e},n.__dgTextFx}function b(){const n=new Date;return`${String(n.getHours()).padStart(2,"0")}:${String(n.getMinutes()).padStart(2,"0")}`}function k(n,e){if(!n.length)return null;let t=n[0];for(let i=0;i<n.length;i++)e>=n[i].time&&(t=n[i]);return e<n[0].time&&(t=n[n.length-1]),t}const u={white:"#ffffff",black:"#000000",gold:"#ffe864ff",silver:"#d4d4d4ff"};class p{constructor(e,t={}){if(this.container=typeof e=="string"?document.querySelector(e):e,!this.container)throw new Error("DynamicGradient: container not found.");this.type=t.type||"linear",this.direction=t.direction||"to right",this.colors=t.colors||["#1e3c72","#2a5298"],this.transitionDuration=t.transitionDuration??1500,this.textClip=t.textClip||!1,this.scheduleData=t.schedule||[],this.currentInterval=null,this.lastAppliedKey=null,this.container.style.position=this.container.style.position||"relative",this.applyGradient(this.colors,this.type,this.direction,!1),this.scheduleData.length>0&&this.schedule(this.scheduleData)}applyGradient(e=this.colors,t=this.type,i=this.direction,s=!0){const r=l(e,t,i),a=this.container.style.background;if(r!==a){if(this.textClip){const o=d(this.container,r,this.duration);this.container.style.background=o,this.container.style.fontWeight="inherit"}else s?(this.transitionOverlay&&this.transitionOverlay.remove(),this.transitionOverlay=f(this.container,r,this.transitionDuration),requestAnimationFrame(()=>{this.transitionOverlay.style.opacity="1"}),setTimeout(()=>{this.container.style.background=r,this.transitionOverlay.remove(),this.transitionOverlay=null},this.transitionDuration)):this.container.style.background=r;this.colors=e,this.type=t,this.direction=i}}setTextClip(e=!0){this.textClip=e,this.applyGradient(this.colors,this.type,this.direction,!1)}triggerEffect({applyColors:e=null,duration:t=this.transitionDuration,loop:i=!0,hue:s="white"}={}){let r;u[s]?r=u[s]:/^#([0-9A-F]{3}){1,2}$/i.test(s)?r=s:r="#ffffff";const a=e?l(e,this.type,this.direction):l([...this.colors,r],this.type,this.direction);if(this.textClip){const v=T(this.container,t),g=()=>{const{a:y,b:x,visible:C}=v,c=C==="a"?x:y,O=e?l(e,this.type,this.direction):l([...this.colors,u[s]||r],this.type,this.direction);c.style.background=O,c.style.backgroundClip="text",c.style.transition=`opacity ${t}ms ease-in-out`,c.style.opacity="0",requestAnimationFrame(()=>{requestAnimationFrame(()=>{c.style.opacity="1"})}),setTimeout(()=>{c.style.opacity="0"},t),v.visible=c===y?"a":"b",i?(this.effectLoopTimeout&&clearTimeout(this.effectLoopTimeout),this.effectLoopTimeout=setTimeout(g,t*2)):setTimeout(()=>{this.applyGradient(e||this.colors,this.type,this.direction,!1),y.style.opacity="0",x.style.opacity="0"},t*2)};g();return}this.effectOverlay||(this.effectOverlay=f(this.container,a,t));const o=this.effectOverlay,m=()=>{o.style.background=a,o.style.opacity="1",setTimeout(()=>{o.style.opacity="0"},t)};this.effectRunning||(this.effectRunning=!0,m(),i?(this.effectLoopInterval&&clearInterval(this.effectLoopInterval),this.effectLoopInterval=setInterval(m,t*2)):setTimeout(()=>{o.remove(),this.effectOverlay=null},t*2))}persistEffect(e=this.colors,t=this.transitionDuration){const i=l(e,this.type,this.direction);if(this.textClip){const s=d(this.container,i,t);requestAnimationFrame(()=>{s.style.opacity="1"}),setTimeout(()=>{this.applyGradient(e,this.type,this.direction,!1)},t)}else{const s=f(this.container,i,t);requestAnimationFrame(()=>{s.style.opacity="1"}),setTimeout(()=>{this.applyGradient(e,this.type,this.direction,!1),s.remove()},t)}}stopEffects(){this.effectLoopInterval&&(clearInterval(this.effectLoopInterval),this.effectLoopInterval=null),this.effectLoopTimeout&&(clearTimeout(this.effectLoopTimeout),this.effectLoopTimeout=null),this.effectRunning=!1}destroy(){this.stopEffects(),this.currentInterval&&(clearInterval(this.currentInterval),this.currentInterval=null),this.transitionOverlay&&(this.transitionOverlay.remove(),this.transitionOverlay=null),this.effectOverlay&&(this.effectOverlay.remove(),this.effectOverlay=null)}setGradient({colors:e,type:t,direction:i}){const s=e||this.colors,r=t||this.type,a=i||this.direction;s.join(",")===this.colors.join(",")&&r===this.type&&a===this.direction||this.applyGradient(s,r,a,!0)}schedule(e=[]){this.scheduleData=e.map(t=>({...t,time:t.time.padStart(5,"0")})).sort((t,i)=>t.time.localeCompare(i.time)),this.currentInterval&&clearInterval(this.currentInterval),this.checkSchedule(),this.currentInterval=setInterval(()=>this.checkSchedule(),60*1e3)}checkSchedule(){const e=b(),t=k(this.scheduleData,e);if(t){const i=`${t.time}-${t.colors.join(",")}`;i!==this.lastAppliedKey&&(this.setGradient(t),this.lastAppliedKey=i)}}static init(e,t){return new p(e,t)}}h.DynamicGradient=p,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.RealTimeGradient={}))})(this,function(h){"use strict";function l(n,e="linear",t="to right"){return e==="linear"?`linear-gradient(${t}, ${n.join(",")})`:`radial-gradient(circle, ${n.join(",")})`}function f(n,e,t){const i=document.createElement("div");return Object.assign(i.style,{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:0,background:e,opacity:"0",transition:`opacity ${t}ms ease-in-out`}),n.appendChild(i),i}function y(n,e,t){const i=document.createElement("span");i.textContent=n.textContent,Object.assign(i.style,{position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"inline-block",background:e,WebkitBackgroundClip:"text",backgroundClip:"text",WebkitTextFillColor:"transparent",color:"transparent",pointerEvents:"none",opacity:"0",transition:`opacity ${t}ms ease-in-out`,zIndex:20});const s=n.parentNode;return getComputedStyle(s).position==="static"&&(s.style.position="relative"),s.appendChild(i),requestAnimationFrame(()=>{i.style.opacity="1"}),i}function T(n,e){if(n.__dgTextFx&&n.__dgTextFx.duration!==e){const{a:o,b:a}=n.__dgTextFx;return o.style.transition=a.style.transition=`opacity ${e}ms ease-in-out`,n.__dgTextFx.duration=e,n.__dgTextFx}if(n.__dgTextFx)return n.__dgTextFx;const t=n.parentNode;getComputedStyle(t).position==="static"&&(t.style.position="relative");const i=o=>{const a=document.createElement("span");return a.textContent=n.textContent,Object.assign(a.style,{position:"absolute",top:0,left:0,width:"100%",height:"100%",display:"inline-block",WebkitBackgroundClip:"text",backgroundClip:"text",WebkitTextFillColor:"transparent",color:"transparent",pointerEvents:"none",opacity:"0",willChange:"opacity",zIndex:o,transition:`opacity ${e}ms ease-in-out`}),t.appendChild(a),a},s=i(20),r=i(21);return n.__dgTextFx={a:s,b:r,visible:null,duration:e},n.__dgTextFx}function b(){const n=new Date;return`${String(n.getHours()).padStart(2,"0")}:${String(n.getMinutes()).padStart(2,"0")}`}function k(n,e){if(!n.length)return null;let t=n[0];for(let i=0;i<n.length;i++)e>=n[i].time&&(t=n[i]);return e<n[0].time&&(t=n[n.length-1]),t}const u={white:"#ffffff",black:"#000000",gold:"#ffe864ff",silver:"#d4d4d4ff"},C=class x{constructor(e,t={}){if(this.container=typeof e=="string"?document.querySelector(e):e,!this.container)throw new Error("DynamicGradient: container not found.");this.type=t.type||"linear",this.direction=t.direction||"to right",this.colors=t.colors||["#1e3c72","#2a5298"],this.transitionDuration=t.transitionDuration??1500,this.textClip=t.textClip||!1,this.scheduleData=t.schedule||[],this.currentInterval=null,this.lastAppliedKey=null,this.container.style.position=this.container.style.position||"relative",this.applyGradient(this.colors,this.type,this.direction,!1),this.scheduleData.length>0&&this.schedule(this.scheduleData)}applyGradient(e=this.colors,t=this.type,i=this.direction,s=!0){const r=l(e,t,i),o=this.container.style.background;r!==o&&(this.textClip?(y(this.container,r,this.transitionDuration),this.container.style.fontWeight="inherit"):s?(this.transitionOverlay&&this.transitionOverlay.remove(),this.transitionOverlay=f(this.container,r,this.transitionDuration),requestAnimationFrame(()=>{this.transitionOverlay.style.opacity="1"}),setTimeout(()=>{this.container.style.background=r,this.transitionOverlay.remove(),this.transitionOverlay=null},this.transitionDuration)):this.container.style.background=r,this.colors=e,this.type=t,this.direction=i)}setTextClip(e=!0){this.textClip=e,this.applyGradient(this.colors,this.type,this.direction,!1)}triggerEffect({applyColors:e=null,duration:t=this.transitionDuration,loop:i=!0,hue:s="white"}={}){let r;u[s]?r=u[s]:/^#([0-9A-F]{3}){1,2}$/i.test(s)?r=s:r="#ffffff";const o=e?l(e,this.type,this.direction):l([...this.colors,r],this.type,this.direction);if(this.textClip){const m=T(this.container,t),v=()=>{const{a:p,b:g,visible:O}=m,c=O==="a"?g:p,I=e?l(e,this.type,this.direction):l([...this.colors,u[s]||r],this.type,this.direction);c.style.background=I,c.style.backgroundClip="text",c.style.transition=`opacity ${t}ms ease-in-out`,c.style.opacity="0",requestAnimationFrame(()=>{requestAnimationFrame(()=>{c.style.opacity="1"})}),setTimeout(()=>{c.style.opacity="0"},t),m.visible=c===p?"a":"b",i?(this.effectLoopTimeout&&clearTimeout(this.effectLoopTimeout),this.effectLoopTimeout=setTimeout(v,t*2)):setTimeout(()=>{this.applyGradient(e||this.colors,this.type,this.direction,!1),p.style.opacity="0",g.style.opacity="0"},t*2)};v();return}this.effectOverlay||(this.effectOverlay=f(this.container,o,t));const a=this.effectOverlay,d=()=>{a.style.background=o,a.style.opacity="1",setTimeout(()=>{a.style.opacity="0"},t)};this.effectRunning||(this.effectRunning=!0,d(),i?(this.effectLoopInterval&&clearInterval(this.effectLoopInterval),this.effectLoopInterval=setInterval(d,t*2)):setTimeout(()=>{a.remove(),this.effectOverlay=null},t*2))}persistEffect(e=this.colors,t=this.transitionDuration){const i=l(e,this.type,this.direction);if(this.textClip){const s=y(this.container,i,t);requestAnimationFrame(()=>{s.style.opacity="1"}),setTimeout(()=>{this.applyGradient(e,this.type,this.direction,!1)},t)}else{const s=f(this.container,i,t);requestAnimationFrame(()=>{s.style.opacity="1"}),setTimeout(()=>{this.applyGradient(e,this.type,this.direction,!1),s.remove()},t)}}stopEffects(){this.effectLoopInterval&&(clearInterval(this.effectLoopInterval),this.effectLoopInterval=null),this.effectLoopTimeout&&(clearTimeout(this.effectLoopTimeout),this.effectLoopTimeout=null),this.effectRunning=!1}destroy(){this.stopEffects(),this.currentInterval&&(clearInterval(this.currentInterval),this.currentInterval=null),this.transitionOverlay&&(this.transitionOverlay.remove(),this.transitionOverlay=null),this.effectOverlay&&(this.effectOverlay.remove(),this.effectOverlay=null)}setGradient({colors:e,type:t,direction:i}){const s=e||this.colors,r=t||this.type,o=i||this.direction;s.join(",")===this.colors.join(",")&&r===this.type&&o===this.direction||this.applyGradient(s,r,o,!0)}schedule(e=[]){this.scheduleData=e.map(t=>({...t,time:t.time.padStart(5,"0")})).sort((t,i)=>t.time.localeCompare(i.time)),this.currentInterval&&clearInterval(this.currentInterval),this.checkSchedule(),this.currentInterval=setInterval(()=>this.checkSchedule(),60*1e3)}checkSchedule(){const e=b(),t=k(this.scheduleData,e);if(t){const i=`${t.time}-${t.colors.join(",")}`;i!==this.lastAppliedKey&&(this.setGradient(t),this.lastAppliedKey=i)}}static init(e,t){return new x(e,t)}};h.DynamicGradient=C,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "real-time-gradient",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A Dynamic Gradient background library.",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.es.js",
7
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.es.js",
11
+ "require": "./dist/index.umd.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
8
15
  "scripts": {
9
16
  "build": "vite build"
10
17
  },