real-time-gradient 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +216 -248
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,248 +1,216 @@
1
- # 🌅 dynamic-gradient
2
-
3
- A lightweight JavaScript library for creating smooth, customizable, real-time gradients with flexible control over animation speed, direction, and hues.
4
-
5
- ## UMD (Browser) Usage
6
-
7
- ```html
8
- <script src="dynamic-gradient.min.js"></script>
9
- <script>
10
- const gradient = DynamicGradient.init("#hero", {
11
- type: "linear",
12
- direction: "to right",
13
- colors: ["#ff7e5f", "#feb47b"],
14
- });
15
- </script>
16
- ```
17
-
18
- ## ✨ Features
19
-
20
- - 🎨 Smooth color transitions (linear, radial, conic)
21
-
22
- - ⚡ Dynamic scheduling (interval-based animation)
23
-
24
- - 🔄 Runtime updates (colors, speed, direction)
25
-
26
- - 📦 Framework-agnostic — works with plain JS, React, Vue, etc.
27
-
28
- - 🖼 Gradient-to-text clipping (textClip)
29
-
30
- - 🛠 TypeScript typings
31
-
32
- ## 🖼️ Basic Usage
33
-
34
- ```html
35
- <div id="hero" style="height: 300px;"></div>
36
-
37
- <script type="module">
38
- import DynamicGradient from "dynamic-gradient";
39
-
40
- const gradient = DynamicGradient.init("#hero", {
41
- type: "linear",
42
- direction: "to right",
43
- colors: ["#ff7e5f", "#feb47b"],
44
- transitionDuration: 1000,
45
- schedule: [
46
- { time: "6:00", colors: ["#7fff00ff", "#ffb347ff", "#ff69b4ff"] },
47
- { time: "18:00", colors: ["#ff4500ff", "#9370dbff", "#4682b4ff"] },
48
- { time: "00:00", colors: ["#ffff54ff", "#ff7f50ff", "#daa520ff"] },
49
- ],
50
- });
51
- </script>
52
- ```
53
-
54
- ## ⚙️ API Reference
55
-
56
- `DynamicGradient.init(target, options)`
57
- Initialize a gradient on a DOM element.
58
-
59
- #### Parameters
60
-
61
- - `target`: CSS selector or DOM element
62
- - `options` : configuration object
63
-
64
- #### Options:
65
-
66
- - `type`: `"linear" | "radial"` (default: `"linear"` )
67
- - `direction`: CSS gradient direction (e.g., `"to right"`, `"45deg"` )
68
- - `colors`: array of color hex values
69
- - `transitionDuration`: time in ms for transitions (default: `1000`)
70
- - `schedule`: optional array of {`time: "HH:MM", colors: []`} objects
71
- - `textClip`: boolean (default: `false`) → applies gradient as background-clip for text
72
-
73
- ### `stopEffects()`
74
-
75
- ```js
76
- gradient.stopEffects();
77
- ```
78
-
79
- ### `triggerEffect({ applyColors, duration, hue })`
80
-
81
- Overlay temporary effect
82
-
83
- ```js
84
- gradient.triggerEffect({
85
- hue: "gold",
86
- duration: 2000,
87
- });
88
- ```
89
-
90
- ```js
91
- gradient.triggerEffect({
92
- applyColors: ["#9370dbff", "#4682b4ff"],
93
- duration: 2000,
94
- });
95
- ```
96
-
97
- ### `persistEffect(colors[], duration)`
98
-
99
- Mutate a new gradient smoothly
100
-
101
- ```js
102
- gradient.persistEffect(["#9370db", "#4682b4"], 2000);
103
- ```
104
-
105
- ### `schedule([{ time: "HH:MM", colors: [] }, ...])`
106
-
107
- Allows scheduling of time-based gradients that change automatically throughout the day.
108
-
109
- ```js
110
- const gradient = DynamicGradient.init("#hero", {
111
- type: "linear",
112
- direction: "to right",
113
- colors: ["#ff7f50ff", "#6a5acdff", "#20b2aaff"], // default
114
- schedule: [
115
- { time: "06:00", colors: ["#7fff00ff", "#ffb347ff", "#ff69b4ff"] }, // morning
116
- { time: "18:00", colors: ["#ff4500ff", "#9370dbff", "#4682b4ff"] }, // evening
117
- { time: "00:00", colors: ["#ffff54ff", "#ff7f50ff", "#daa520ff"] }, // midnight
118
- ],
119
- });
120
- ```
121
-
122
- - `time`: "HH:MM" in `24h format`(e.g. `"06:00"`,`"18:30"` )
123
- - `colors`: array of CSS colors for the gradient
124
-
125
- #### Optional per-entry:
126
-
127
- - `type`: `"linear"` or `"radial"`
128
- - `direction`: CSS gradient direction(`"to right"`, `"45deg"`, etc.)
129
-
130
- #### Behavior
131
-
132
- - The most recent matching entry before or equal to the current time will be applied.
133
- - If the time is earlier than the first scheduled entry, it wraps around and uses the last entry.
134
- - The schedule is checked every minute, so changes align with the clock naturally.
135
-
136
- ### `destroy()`
137
-
138
- Stop the gradient animation and clean up.
139
-
140
- ```js
141
- gradient.destroy();
142
- ```
143
-
144
- ## 🎨 Hue Presets
145
-
146
- Some ready-to-use gradient palettes:
147
-
148
- ```js
149
- hues = {
150
- sunset: ["#ff7e5f", "#feb47b"],
151
- ocean: ["#00c6ff", "#0072ff"],
152
- forest: ["#11998e", "#38ef7d"],
153
- fire: ["#ff512f", "#dd2476"],
154
- mono: ["#ffffff", "#000000"],
155
- };
156
- ```
157
-
158
- Additionally, `triggerEffect` accepts special hue keywords:
159
-
160
- - `"white"`, `"black"`, `"gold"`, `"silver"`
161
- - Or any custom hex string (`"#RRGGBB"`)
162
-
163
- Usage:
164
-
165
- ```js
166
- gradient.setGradient({ colors: hues.forest });
167
- ```
168
-
169
- Or:
170
-
171
- ```js
172
- gradient.triggerEffect({ hue: "gold", duration: 2000 });
173
- ```
174
-
175
- ## 📦 TypeScript Typings
176
-
177
- ```ts
178
- // index.d.ts
179
- export type GradientType = "linear" | "radial";
180
-
181
- export type HuePreset = "white" | "black" | "gold" | "silver" | string;
182
-
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);
218
- }
219
-
220
- setGradient(options: {
221
- colors: string[];
222
- type?: GradientType;
223
- direction?: string;
224
- }): void {
225
- // implementation
226
- }
227
-
228
- schedule(entries: ScheduleEntry[]): void {
229
- // implementation
230
- }
231
-
232
- triggerEffect(options?: EffectOptions): void {
233
- // implementation
234
- }
235
-
236
- persistEffect(colors: string[], duration?: number): void {
237
- // implementation
238
- }
239
-
240
- stopEffects(): void {
241
- // implementation
242
- }
243
- }
244
- ```
245
-
246
- ## 📄 License
247
-
248
- MIT © 2025 — @wakenedo
1
+ # 🌅 dynamic-gradient
2
+
3
+ A lightweight JavaScript library for creating smooth, customizable, real-time gradients with flexible control over animation speed, direction, and hues.
4
+
5
+ ## UMD (Browser) Usage
6
+
7
+ ```html
8
+ <script src="dynamic-gradient.min.js"></script>
9
+ <script>
10
+ const gradient = DynamicGradient.init("#hero", {
11
+ type: "linear",
12
+ direction: "to right",
13
+ colors: ["#ff7e5f", "#feb47b"],
14
+ });
15
+ </script>
16
+ ```
17
+
18
+ ## ✨ Features
19
+
20
+ - 🎨 Smooth color transitions (linear, radial, conic)
21
+
22
+ - ⚡ Dynamic scheduling (interval-based animation)
23
+
24
+ - 🔄 Runtime updates (colors, speed, direction)
25
+
26
+ - 📦 Framework-agnostic — works with plain JS, React, Vue, etc.
27
+
28
+ - 🖼 Gradient-to-text clipping (textClip)
29
+
30
+ - 🛠 TypeScript typings
31
+
32
+ ## 🖼️ Basic Usage
33
+
34
+ ```html
35
+ <div id="hero" style="height: 300px;"></div>
36
+
37
+ <script type="module">
38
+ import DynamicGradient from "dynamic-gradient";
39
+
40
+ const gradient = DynamicGradient.init("#hero", {
41
+ type: "linear",
42
+ direction: "to right",
43
+ colors: ["#ff7e5f", "#feb47b"],
44
+ transitionDuration: 1000,
45
+ schedule: [
46
+ { time: "6:00", colors: ["#7fff00ff", "#ffb347ff", "#ff69b4ff"] },
47
+ { time: "18:00", colors: ["#ff4500ff", "#9370dbff", "#4682b4ff"] },
48
+ { time: "00:00", colors: ["#ffff54ff", "#ff7f50ff", "#daa520ff"] },
49
+ ],
50
+ });
51
+ </script>
52
+ ```
53
+
54
+ ## ⚙️ API Reference
55
+
56
+ `DynamicGradient.init(target, options)`
57
+ Initialize a gradient on a DOM element.
58
+
59
+ #### Parameters
60
+
61
+ - `target`: CSS selector or DOM element
62
+ - `options` : configuration object
63
+
64
+ #### Options:
65
+
66
+ - `type`: `"linear" | "radial"` (default: `"linear"` )
67
+ - `direction`: CSS gradient direction (e.g., `"to right"`, `"45deg"` )
68
+ - `colors`: array of color hex values
69
+ - `transitionDuration`: time in ms for transitions (default: `1000`)
70
+ - `schedule`: optional array of {`time: "HH:MM", colors: []`} objects
71
+ - `textClip`: boolean (default: `false`) → applies gradient as background-clip for text
72
+
73
+ ### `stopEffects()`
74
+
75
+ ```js
76
+ gradient.stopEffects();
77
+ ```
78
+
79
+ ### `triggerEffect({ applyColors, duration, hue })`
80
+
81
+ Overlay temporary effect
82
+
83
+ ```js
84
+ gradient.triggerEffect({
85
+ hue: "gold",
86
+ duration: 2000,
87
+ });
88
+ ```
89
+
90
+ ```js
91
+ gradient.triggerEffect({
92
+ applyColors: ["#9370dbff", "#4682b4ff"],
93
+ duration: 2000,
94
+ });
95
+ ```
96
+
97
+ ### `persistEffect(colors[], duration)`
98
+
99
+ Mutate a new gradient smoothly
100
+
101
+ ```js
102
+ gradient.persistEffect(["#9370db", "#4682b4"], 2000);
103
+ ```
104
+
105
+ ### `schedule([{ time: "HH:MM", colors: [] }, ...])`
106
+
107
+ Allows scheduling of time-based gradients that change automatically throughout the day.
108
+
109
+ ```js
110
+ const gradient = DynamicGradient.init("#hero", {
111
+ type: "linear",
112
+ direction: "to right",
113
+ colors: ["#ff7f50ff", "#6a5acdff", "#20b2aaff"], // default
114
+ schedule: [
115
+ { time: "06:00", colors: ["#7fff00ff", "#ffb347ff", "#ff69b4ff"] }, // morning
116
+ { time: "18:00", colors: ["#ff4500ff", "#9370dbff", "#4682b4ff"] }, // evening
117
+ { time: "00:00", colors: ["#ffff54ff", "#ff7f50ff", "#daa520ff"] }, // midnight
118
+ ],
119
+ });
120
+ ```
121
+
122
+ - `time`: "HH:MM" in `24h format`(e.g. `"06:00"`,`"18:30"` )
123
+ - `colors`: array of CSS colors for the gradient
124
+
125
+ #### Optional per-entry:
126
+
127
+ - `type`: `"linear"` or `"radial"`
128
+ - `direction`: CSS gradient direction(`"to right"`, `"45deg"`, etc.)
129
+
130
+ #### Behavior
131
+
132
+ - The most recent matching entry before or equal to the current time will be applied.
133
+ - If the time is earlier than the first scheduled entry, it wraps around and uses the last entry.
134
+ - The schedule is checked every minute, so changes align with the clock naturally.
135
+
136
+ ### `destroy()`
137
+
138
+ Stop the gradient animation and clean up.
139
+
140
+ ```js
141
+ gradient.destroy();
142
+ ```
143
+
144
+ ## 🎨 Hue Presets
145
+
146
+ Some ready-to-use gradient palettes:
147
+
148
+ ```js
149
+ hues = {
150
+ sunset: ["#ff7e5f", "#feb47b"],
151
+ ocean: ["#00c6ff", "#0072ff"],
152
+ forest: ["#11998e", "#38ef7d"],
153
+ fire: ["#ff512f", "#dd2476"],
154
+ mono: ["#ffffff", "#000000"],
155
+ };
156
+ ```
157
+
158
+ Additionally, `triggerEffect` accepts special hue keywords:
159
+
160
+ - `"white"`, `"black"`, `"gold"`, `"silver"`
161
+ - Or any custom hex string (`"#RRGGBB"`)
162
+
163
+ Usage:
164
+
165
+ ```js
166
+ gradient.setGradient({ colors: hues.forest });
167
+ ```
168
+
169
+ Or:
170
+
171
+ ```js
172
+ gradient.triggerEffect({ hue: "gold", duration: 2000 });
173
+ ```
174
+
175
+ ## 📦 TypeScript Typings
176
+
177
+ ```ts
178
+ // index.d.ts
179
+ import DynamicGradientRuntime from "./RealTimeGradient/realTimeGradient.js";
180
+
181
+ // ---- public types ----
182
+ export type GradientType = "linear" | "radial";
183
+
184
+ export interface ScheduleEntry {
185
+ time: string;
186
+ colors: string[];
187
+ type?: GradientType;
188
+ direction?: string;
189
+ }
190
+
191
+ export interface GradientOptions {
192
+ type?: GradientType;
193
+ direction?: string;
194
+ colors?: string[];
195
+ transitionDuration?: number;
196
+ schedule?: ScheduleEntry[];
197
+ textClip?: boolean;
198
+ }
199
+
200
+ export interface EffectOptions {
201
+ applyColors?: string[];
202
+ duration?: number;
203
+ hue?: "white" | "black" | "gold" | "silver" | string;
204
+ loop?: boolean;
205
+ }
206
+
207
+ // 🔗 attach types to runtime symbol
208
+ export const DynamicGradient = DynamicGradientRuntime as unknown as {
209
+ new (container: string | HTMLElement, options?: GradientOptions): any;
210
+ init(container: string | HTMLElement, options?: GradientOptions): any;
211
+ };
212
+ ```
213
+
214
+ ## 📄 License
215
+
216
+ MIT © 2025 @wakenedo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "real-time-gradient",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A Dynamic Gradient background library.",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.es.js",