@gradient-ui/gradient-engine 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -0
- package/dist/animation.cjs +60 -0
- package/dist/animation.mjs +89 -0
- package/dist/core.cjs +1 -0
- package/dist/core.mjs +16 -0
- package/dist/css-CaOuUhfh.js +17 -0
- package/dist/css-YuAJQW13.cjs +1 -0
- package/dist/effects.cjs +96 -0
- package/dist/effects.mjs +321 -0
- package/dist/formatters.cjs +1 -0
- package/dist/formatters.mjs +37 -0
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +45 -0
- package/dist/material.cjs +1 -0
- package/dist/material.mjs +6 -0
- package/dist/presets-55krt4L_.js +354 -0
- package/dist/presets-UIJJyagu.cjs +1 -0
- package/dist/svg-BVcl24Cf.cjs +32 -0
- package/dist/svg-CZThYPKf.js +118 -0
- package/dist/tokens-DMGI7_df.cjs +9 -0
- package/dist/tokens-OfSofVKl.js +204 -0
- package/dist/types/animation/css.d.ts +12 -0
- package/dist/types/animation/index.d.ts +1 -0
- package/dist/types/color.d.ts +10 -0
- package/dist/types/colorMath.d.ts +3 -0
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/core.d.ts +9 -0
- package/dist/types/effects/index.d.ts +2 -0
- package/dist/types/effects/morph.d.ts +5 -0
- package/dist/types/effects/shadow.d.ts +3 -0
- package/dist/types/formatters/canvas.d.ts +2 -0
- package/dist/types/formatters/css.d.ts +3 -0
- package/dist/types/formatters/index.d.ts +3 -0
- package/dist/types/formatters/svg.d.ts +5 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/material.d.ts +1 -0
- package/dist/types/model.d.ts +5 -0
- package/dist/types/palette.d.ts +6 -0
- package/dist/types/presets.d.ts +239 -0
- package/dist/types/recipes.d.ts +14 -0
- package/dist/types/tokens.d.ts +99 -0
- package/dist/types/types.d.ts +117 -0
- package/dist/types/utils.d.ts +10 -0
- package/dist/utils-6iJ6IpZZ.cjs +1 -0
- package/dist/utils-B_VQDGMy.js +67 -0
- package/package.json +114 -0
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Gradient Engine
|
|
2
|
+
|
|
3
|
+
Framework-free gradient generation engine used by Gradient UI.
|
|
4
|
+
|
|
5
|
+
`@gradient-ui/gradient-engine` creates deterministic gradient models, CSS
|
|
6
|
+
gradients, SVG gradients, canvas gradient descriptors, shadows, morph effects,
|
|
7
|
+
animation CSS and material tokens. It does not touch the DOM by default, so it
|
|
8
|
+
can be used from Vue, React, vanilla JavaScript, server builds or design-system
|
|
9
|
+
tooling.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @gradient-ui/gradient-engine
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import {
|
|
21
|
+
createGradientFromColor,
|
|
22
|
+
createGradientMaterial
|
|
23
|
+
} from '@gradient-ui/gradient-engine';
|
|
24
|
+
|
|
25
|
+
const background = createGradientFromColor('#704aff', {
|
|
26
|
+
recipe: 'glare',
|
|
27
|
+
type: 'linear',
|
|
28
|
+
direction: 135
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const material = createGradientMaterial('#704aff', {
|
|
32
|
+
preset: 'materialAction',
|
|
33
|
+
animation: {
|
|
34
|
+
preset: 'shift',
|
|
35
|
+
duration: 6000
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`createGradientFromColor` returns a ready-to-use CSS background value.
|
|
41
|
+
`createGradientMaterial` returns a richer object for components: CSS variables,
|
|
42
|
+
CSS text, optional keyframes, effects and the underlying gradient model.
|
|
43
|
+
|
|
44
|
+
## API Layers
|
|
45
|
+
|
|
46
|
+
The package is split into small subpath exports:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { createGradientFromColor } from '@gradient-ui/gradient-engine/core';
|
|
50
|
+
import { toCssGradient } from '@gradient-ui/gradient-engine/formatters';
|
|
51
|
+
import { createGradientMorph } from '@gradient-ui/gradient-engine/effects';
|
|
52
|
+
import { toGradientAnimationCSS } from '@gradient-ui/gradient-engine/animation';
|
|
53
|
+
import { createGradientMaterial } from '@gradient-ui/gradient-engine/material';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
- `core` creates palettes, recipes and gradient models.
|
|
57
|
+
- `formatters` converts models to CSS, SVG and canvas-friendly output.
|
|
58
|
+
- `effects` creates shadow, drop-shadow and morph effect values.
|
|
59
|
+
- `animation` creates CSS keyframes and animation declarations.
|
|
60
|
+
- `material` creates component-oriented tokens for UI libraries.
|
|
61
|
+
|
|
62
|
+
## Recipes
|
|
63
|
+
|
|
64
|
+
Gradient recipes describe color harmony, not rendering format.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
createGradientFromColor('#704aff', { recipe: 'monochrome' });
|
|
68
|
+
createGradientFromColor('#704aff', { recipe: 'complementary' });
|
|
69
|
+
createGradientFromColor('#704aff', { recipe: 'split-complementary' });
|
|
70
|
+
createGradientFromColor('#704aff', { recipe: 'analogous' });
|
|
71
|
+
createGradientFromColor('#704aff', { recipe: 'triadic' });
|
|
72
|
+
createGradientFromColor('#704aff', { recipe: 'tetradic' });
|
|
73
|
+
createGradientFromColor('#704aff', { recipe: 'rectangle' });
|
|
74
|
+
createGradientFromColor('#704aff', { recipe: 'square' });
|
|
75
|
+
createGradientFromColor('#704aff', { recipe: 'duotone' });
|
|
76
|
+
createGradientFromColor('#704aff', { recipe: 'glare' });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Gradient Types
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
createGradientFromColor('#704aff', {
|
|
83
|
+
type: 'linear',
|
|
84
|
+
direction: 135
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
createGradientFromColor('#704aff', {
|
|
88
|
+
type: 'radial',
|
|
89
|
+
shape: 'circle',
|
|
90
|
+
position: '50% 45%'
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
createGradientFromColor('#704aff', {
|
|
94
|
+
type: 'conic',
|
|
95
|
+
position: '50% 50%'
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Materials
|
|
100
|
+
|
|
101
|
+
Materials are the bridge between the pure engine and component libraries.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
const material = createGradientMaterial('#704aff', {
|
|
105
|
+
preset: 'materialAction',
|
|
106
|
+
recipe: 'glare',
|
|
107
|
+
effects: true,
|
|
108
|
+
animation: {
|
|
109
|
+
preset: 'shift',
|
|
110
|
+
duration: 6000
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The returned object is intentionally serializable:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
material.id;
|
|
119
|
+
material.className;
|
|
120
|
+
material.style;
|
|
121
|
+
material.cssVars;
|
|
122
|
+
material.cssText;
|
|
123
|
+
material.keyframes;
|
|
124
|
+
material.gradient;
|
|
125
|
+
material.effects;
|
|
126
|
+
material.animation;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
This lets a Vue, React or vanilla adapter decide how to apply the result:
|
|
130
|
+
inline styles, a generated stylesheet, CSS variables, SSR-injected CSS or a
|
|
131
|
+
client runtime registry.
|
|
132
|
+
|
|
133
|
+
## SVG
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import {
|
|
137
|
+
createGradientModelFromColor,
|
|
138
|
+
toSvgGradient
|
|
139
|
+
} from '@gradient-ui/gradient-engine';
|
|
140
|
+
|
|
141
|
+
const model = createGradientModelFromColor('#704aff', {
|
|
142
|
+
recipe: 'analogous',
|
|
143
|
+
type: 'linear'
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const svg = toSvgGradient(model, {
|
|
147
|
+
id: 'brand-gradient'
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
SVG helpers are for generated markup and definitions. They do not mount the SVG
|
|
152
|
+
into the document.
|
|
153
|
+
|
|
154
|
+
## Animations
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { toGradientAnimationCSS } from '@gradient-ui/gradient-engine';
|
|
158
|
+
|
|
159
|
+
const animation = toGradientAnimationCSS({
|
|
160
|
+
name: 'hero-gradient',
|
|
161
|
+
preset: 'shift',
|
|
162
|
+
duration: 8000
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Available presets: `shift`, `pulse`, `rotate`, `hue-rotate`.
|
|
167
|
+
|
|
168
|
+
Different surfaces should opt into animation carefully. For example, `rotate`
|
|
169
|
+
is useful for large decorative surfaces, but usually too aggressive for compact
|
|
170
|
+
buttons and borders.
|
|
171
|
+
|
|
172
|
+
## Effects
|
|
173
|
+
|
|
174
|
+
Effects are plain strings or serializable descriptions.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import {
|
|
178
|
+
createGradientBoxShadow,
|
|
179
|
+
createGradientDropShadow,
|
|
180
|
+
createGradientMorph
|
|
181
|
+
} from '@gradient-ui/gradient-engine/effects';
|
|
182
|
+
|
|
183
|
+
const boxShadow = createGradientBoxShadow('#704aff');
|
|
184
|
+
const dropShadow = createGradientDropShadow('#704aff');
|
|
185
|
+
const morph = createGradientMorph('#704aff', {
|
|
186
|
+
preset: 'liquid',
|
|
187
|
+
blobCount: 5
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The engine only creates values. DOM-specific mounting for SVG filters, style
|
|
192
|
+
tags or animation lifecycles belongs in an adapter.
|
|
193
|
+
|
|
194
|
+
## SSR
|
|
195
|
+
|
|
196
|
+
The core package is SSR-safe because it has no browser side effects. For SSR,
|
|
197
|
+
generate the material/model on the server, serialize `cssVars`, `cssText` and
|
|
198
|
+
`keyframes`, then let the client adapter mount optional runtime effects such as
|
|
199
|
+
morph SVG filters.
|
|
200
|
+
|
|
201
|
+
## Version
|
|
202
|
+
|
|
203
|
+
`0.5.0` is the first standalone release line for the engine extracted from
|
|
204
|
+
Gradient UI.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
MIT
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./utils-6iJ6IpZZ.cjs"),c=t=>`@keyframes ${t} {
|
|
2
|
+
0% {
|
|
3
|
+
background-position: 0% 50%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
50% {
|
|
7
|
+
background-position: 100% 50%;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
100% {
|
|
11
|
+
background-position: 0% 50%;
|
|
12
|
+
}
|
|
13
|
+
}`,f=t=>`@keyframes ${t} {
|
|
14
|
+
0%, 100% {
|
|
15
|
+
filter: saturate(1) brightness(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
50% {
|
|
19
|
+
filter: saturate(1.22) brightness(1.08);
|
|
20
|
+
}
|
|
21
|
+
}`,d=t=>`@keyframes ${t} {
|
|
22
|
+
0%, 100% {
|
|
23
|
+
filter: hue-rotate(0deg) saturate(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
50% {
|
|
27
|
+
filter: hue-rotate(28deg) saturate(1.18);
|
|
28
|
+
}
|
|
29
|
+
}`,l=t=>`@keyframes ${t} {
|
|
30
|
+
from {
|
|
31
|
+
transform: translate(-50%, -50%) rotate(0deg);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
to {
|
|
35
|
+
transform: translate(-50%, -50%) rotate(360deg);
|
|
36
|
+
}
|
|
37
|
+
}`,o=(t={})=>{const e=t.name??"g-gradient-shift",n=m.toCssDuration(t.duration??6e3),r=t.easing??"ease-in-out",i=t.selector??".g-gradient-animated",a=t.preset??"shift";return{duration:n,easing:r,name:e,preset:a,selector:i}},s=(t={})=>{const{name:e,preset:n}=o(t);return n==="pulse"?f(e):n==="hue-rotate"?d(e):n==="rotate"?l(e):c(e)},g=(t={})=>{const{duration:e,easing:n,name:r,preset:i}=o(t);return`${r} ${e} ${i==="rotate"?"linear":n} infinite`},u=(t={})=>{const{duration:e,easing:n,name:r,preset:i,selector:a}=o(t);return i==="rotate"?`${a} {
|
|
38
|
+
position: relative;
|
|
39
|
+
overflow: hidden;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
${a}::before {
|
|
43
|
+
content: '';
|
|
44
|
+
position: absolute;
|
|
45
|
+
top: 50%;
|
|
46
|
+
left: 50%;
|
|
47
|
+
width: 200%;
|
|
48
|
+
height: 200%;
|
|
49
|
+
min-width: 150vmax;
|
|
50
|
+
min-height: 150vmax;
|
|
51
|
+
background: inherit;
|
|
52
|
+
animation: ${r} ${e} linear infinite;
|
|
53
|
+
transform-origin: center;
|
|
54
|
+
}`:i==="pulse"||i==="hue-rotate"?`${a} {
|
|
55
|
+
animation: ${r} ${e} ${n} infinite;
|
|
56
|
+
}`:`${a} {
|
|
57
|
+
animation: ${r} ${e} ${n} infinite;
|
|
58
|
+
background-size: 220% 220%;
|
|
59
|
+
}`},$=(t={})=>{const e=s(t),n=u(t);return`${e}
|
|
60
|
+
${n}`};exports.getGradientAnimationOptions=o;exports.toGradientAnimationCSS=$;exports.toGradientAnimationKeyframes=s;exports.toGradientAnimationStyles=u;exports.toGradientAnimationValue=g;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { t as s } from "./utils-B_VQDGMy.js";
|
|
2
|
+
const u = (t) => `@keyframes ${t} {
|
|
3
|
+
0% {
|
|
4
|
+
background-position: 0% 50%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
50% {
|
|
8
|
+
background-position: 100% 50%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
100% {
|
|
12
|
+
background-position: 0% 50%;
|
|
13
|
+
}
|
|
14
|
+
}`, f = (t) => `@keyframes ${t} {
|
|
15
|
+
0%, 100% {
|
|
16
|
+
filter: saturate(1) brightness(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
50% {
|
|
20
|
+
filter: saturate(1.22) brightness(1.08);
|
|
21
|
+
}
|
|
22
|
+
}`, m = (t) => `@keyframes ${t} {
|
|
23
|
+
0%, 100% {
|
|
24
|
+
filter: hue-rotate(0deg) saturate(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
50% {
|
|
28
|
+
filter: hue-rotate(28deg) saturate(1.18);
|
|
29
|
+
}
|
|
30
|
+
}`, c = (t) => `@keyframes ${t} {
|
|
31
|
+
from {
|
|
32
|
+
transform: translate(-50%, -50%) rotate(0deg);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
to {
|
|
36
|
+
transform: translate(-50%, -50%) rotate(360deg);
|
|
37
|
+
}
|
|
38
|
+
}`, o = (t = {}) => {
|
|
39
|
+
const e = t.name ?? "g-gradient-shift", n = s(t.duration ?? 6e3), r = t.easing ?? "ease-in-out", a = t.selector ?? ".g-gradient-animated", i = t.preset ?? "shift";
|
|
40
|
+
return {
|
|
41
|
+
duration: n,
|
|
42
|
+
easing: r,
|
|
43
|
+
name: e,
|
|
44
|
+
preset: i,
|
|
45
|
+
selector: a
|
|
46
|
+
};
|
|
47
|
+
}, d = (t = {}) => {
|
|
48
|
+
const { name: e, preset: n } = o(t);
|
|
49
|
+
return n === "pulse" ? f(e) : n === "hue-rotate" ? m(e) : n === "rotate" ? c(e) : u(e);
|
|
50
|
+
}, $ = (t = {}) => {
|
|
51
|
+
const { duration: e, easing: n, name: r, preset: a } = o(t);
|
|
52
|
+
return `${r} ${e} ${a === "rotate" ? "linear" : n} infinite`;
|
|
53
|
+
}, g = (t = {}) => {
|
|
54
|
+
const { duration: e, easing: n, name: r, preset: a, selector: i } = o(t);
|
|
55
|
+
return a === "rotate" ? `${i} {
|
|
56
|
+
position: relative;
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
${i}::before {
|
|
61
|
+
content: '';
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: 50%;
|
|
64
|
+
left: 50%;
|
|
65
|
+
width: 200%;
|
|
66
|
+
height: 200%;
|
|
67
|
+
min-width: 150vmax;
|
|
68
|
+
min-height: 150vmax;
|
|
69
|
+
background: inherit;
|
|
70
|
+
animation: ${r} ${e} linear infinite;
|
|
71
|
+
transform-origin: center;
|
|
72
|
+
}` : a === "pulse" || a === "hue-rotate" ? `${i} {
|
|
73
|
+
animation: ${r} ${e} ${n} infinite;
|
|
74
|
+
}` : `${i} {
|
|
75
|
+
animation: ${r} ${e} ${n} infinite;
|
|
76
|
+
background-size: 220% 220%;
|
|
77
|
+
}`;
|
|
78
|
+
}, h = (t = {}) => {
|
|
79
|
+
const e = d(t), n = g(t);
|
|
80
|
+
return `${e}
|
|
81
|
+
${n}`;
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
o as getGradientAnimationOptions,
|
|
85
|
+
h as toGradientAnimationCSS,
|
|
86
|
+
d as toGradientAnimationKeyframes,
|
|
87
|
+
g as toGradientAnimationStyles,
|
|
88
|
+
$ as toGradientAnimationValue
|
|
89
|
+
};
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./presets-UIJJyagu.cjs"),i=require("./css-YuAJQW13.cjs"),a=(t,r={})=>i.toCssGradient(e.createGradientModel(t,r)),d=(t,r={})=>a(e.createPalette(t),r);exports.createGradientModel=e.createGradientModel;exports.createGradientModelFromColor=e.createGradientModelFromColor;exports.createRecipeStops=e.createRecipeStops;exports.defineGradientPreset=e.defineGradientPreset;exports.defineGradientPresetRegistry=e.defineGradientPresetRegistry;exports.getGradientPreset=e.getGradientPreset;exports.gradientPresets=e.gradientPresets;exports.gradientRecipes=e.gradientRecipes;exports.createGradient=a;exports.createGradientFromColor=d;
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { c as r, b as a } from "./presets-55krt4L_.js";
|
|
2
|
+
import { a as m, d as p, e as f, f as g, g as l, h as P, i as C } from "./presets-55krt4L_.js";
|
|
3
|
+
import { t as s } from "./css-CaOuUhfh.js";
|
|
4
|
+
const o = (e, t = {}) => s(r(e, t)), n = (e, t = {}) => o(a(e), t);
|
|
5
|
+
export {
|
|
6
|
+
o as createGradient,
|
|
7
|
+
n as createGradientFromColor,
|
|
8
|
+
r as createGradientModel,
|
|
9
|
+
m as createGradientModelFromColor,
|
|
10
|
+
p as createRecipeStops,
|
|
11
|
+
f as defineGradientPreset,
|
|
12
|
+
g as defineGradientPresetRegistry,
|
|
13
|
+
l as getGradientPreset,
|
|
14
|
+
P as gradientPresets,
|
|
15
|
+
C as gradientRecipes
|
|
16
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { D as p, n as c, f as a, d as e, e as r, g as D } from "./utils-B_VQDGMy.js";
|
|
2
|
+
const $ = (t, i = p) => `linear-gradient(${c(i)}, ${t.join(", ")})`, I = (t) => {
|
|
3
|
+
const i = t.stops.map(a).join(", ");
|
|
4
|
+
if (t.type === "radial") {
|
|
5
|
+
const s = t.shape ?? "ellipse", n = t.size ?? e, o = t.position ?? r;
|
|
6
|
+
return `radial-gradient(${s} ${n} at ${o}, ${i})`;
|
|
7
|
+
}
|
|
8
|
+
if (t.type === "conic") {
|
|
9
|
+
const s = c(t.direction), n = t.position ?? r, o = D(t.stops).map(a).join(", ");
|
|
10
|
+
return `conic-gradient(from ${s} at ${n}, ${o})`;
|
|
11
|
+
}
|
|
12
|
+
return $(t.stops.map(a), t.direction);
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
$ as c,
|
|
16
|
+
I as t
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const i=require("./utils-6iJ6IpZZ.cjs"),a=(t,n=i.DEFAULT_GRADIENT_DIRECTION)=>`linear-gradient(${i.normalizeDirection(n)}, ${t.join(", ")})`,e=t=>{const n=t.stops.map(i.formatStop).join(", ");if(t.type==="radial"){const o=t.shape??"ellipse",s=t.size??i.DEFAULT_GRADIENT_SIZE,r=t.position??i.DEFAULT_GRADIENT_POSITION;return`radial-gradient(${o} ${s} at ${r}, ${n})`}if(t.type==="conic"){const o=i.normalizeDirection(t.direction),s=t.position??i.DEFAULT_GRADIENT_POSITION,r=i.getConicStops(t.stops).map(i.formatStop).join(", ");return`conic-gradient(from ${o} at ${s}, ${r})`}return a(t.stops.map(i.formatStop),t.direction)};exports.createLinearGradient=a;exports.toCssGradient=e;
|
package/dist/effects.cjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./utils-6iJ6IpZZ.cjs"),N="http://www.w3.org/2000/svg",G={soft:{blobCount:5,blur:40,contrast:18,duration:12e3,opacity:.76,scale:1.05},liquid:{blobCount:6,blur:46,contrast:22,duration:9200,opacity:.82,scale:1.18},ripple:{blobCount:7,blur:34,contrast:20,duration:7200,opacity:.78,scale:.94}},y=(t={})=>{const r=G[t.preset??"soft"];return{blobCount:Math.max(2,Math.round(t.blobCount??r.blobCount)),blur:c.clamp(t.blur??r.blur,0,80),contrast:c.clamp(t.contrast??r.contrast,0,36),duration:t.duration??r.duration,id:t.id??"g-gradient-morph",opacity:c.clamp(t.opacity??r.opacity),scale:c.clamp(t.scale??r.scale,.4,2)}},T=(t,r)=>{var o,n;return((o=t.stops[r%t.stops.length])==null?void 0:o.color)??((n=t.stops[0])==null?void 0:n.color)??"currentColor"},X=t=>{if(typeof t=="number")return t;const r=Number.parseFloat(t);return Number.isFinite(r)?r:9e3},Y=(t,r)=>{const o=Math.sin((t+1)*12.9898+r*78.233)*43758.5453;return o-Math.floor(o)},g=(t,r,o,n)=>o+Y(t,r)*(n-o),m=t=>Number(t.toFixed(3)),M=[{animationName:"g-gradient-morph-drift",dx:20,dx2:8,dy:-8,dy2:16,originX:"50%",originY:"50%",scaleMid:1.16,scaleTo:1.04,x:6,y:58},{animationName:"g-gradient-morph-orbit",dx:-18,dx2:10,dy:18,dy2:-10,originX:"24%",originY:"68%",scaleMid:.96,scaleTo:1.12,x:44,y:20},{animationName:"g-gradient-morph-float",dx:-16,dx2:-8,dy:-12,dy2:18,originX:"50%",originY:"50%",scaleMid:1.2,scaleTo:1.08,x:74,y:58},{animationName:"g-gradient-morph-orbit",dx:12,dx2:-20,dy:14,dy2:6,originX:"70%",originY:"30%",scaleMid:1.04,scaleTo:1.18,x:88,y:25},{animationName:"g-gradient-morph-drift",dx:24,dx2:-12,dy:-16,dy2:-8,originX:"50%",originY:"50%",scaleMid:1.12,scaleTo:.98,x:30,y:78},{animationName:"g-gradient-morph-float",dx:-22,dx2:14,dy:10,dy2:-18,originX:"50%",originY:"50%",scaleMid:.94,scaleTo:1.1,x:104,y:82},{animationName:"g-gradient-morph-orbit",dx:14,dx2:-16,dy:-22,dy2:10,originX:"35%",originY:"35%",scaleMid:1.18,scaleTo:1.02,x:55,y:64},{animationName:"g-gradient-morph-drift",dx:-18,dx2:18,dy:-14,dy2:14,originX:"50%",originY:"50%",scaleMid:1.08,scaleTo:.96,x:18,y:24}],v=(t,r={})=>{const{blobCount:o,duration:n,scale:d}=y(r),a=X(n);return Array.from({length:o},(s,e)=>{const i=M[e%M.length],l=g(e,1,.88,1.16),p=g(e,2,.86,1.24),u=g(e,3,.72,1),$=g(e,4,0,4),x=(34+e%4*9)*d*l;return{animationName:i.animationName,blur:m($),color:T(t,e),delay:Math.round(e*-.19*a-g(e,5,0,900)),dx:m(i.dx*g(e,6,.84,1.18)),dx2:m(i.dx2*g(e,7,.82,1.22)),dy:m(i.dy*g(e,8,.84,1.18)),dy2:m(i.dy2*g(e,9,.82,1.22)),duration:Math.round(a*(1+e%3*.11)*p),opacity:m(u),originX:i.originX,originY:i.originY,rotateMid:Math.round(g(e,10,95,165)),rotateTo:Math.round(g(e,11,220,310)),scaleMid:i.scaleMid,scaleTo:i.scaleTo,size:m(x),x:i.x,y:i.y}})},C=(t={})=>`url(#${y(t).id}) blur(${y(t).blur}px)`,B=(t={})=>{const{blur:r,contrast:o,id:n}=y(t),d=Math.max(2,Math.round(r*.25)),a=-(o*.45),s=o<=0?"":`
|
|
2
|
+
<feColorMatrix in="g-gradient-morph-blur" mode="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 ${o} ${a}" result="g-gradient-morph-goo" />
|
|
3
|
+
<feBlend in="SourceGraphic" in2="g-gradient-morph-goo" />`;return`<svg xmlns="${N}" width="0" height="0" aria-hidden="true" focusable="false" style="position:absolute;overflow:hidden;inline-size:0;block-size:0;">
|
|
4
|
+
<filter id="${n}" x="-30%" y="-30%" width="160%" height="160%" color-interpolation-filters="sRGB">
|
|
5
|
+
<feGaussianBlur in="SourceGraphic" stdDeviation="${d}" result="g-gradient-morph-blur" />${s}
|
|
6
|
+
</filter>
|
|
7
|
+
</svg>`},k=(t,r={})=>{const o=r.selector??".g-gradient-morph",{opacity:n}=y(r),d=v(t,r);return`${o} {
|
|
8
|
+
position: relative;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
${o}__blobs {
|
|
13
|
+
position: absolute;
|
|
14
|
+
inset: -18%;
|
|
15
|
+
opacity: ${n};
|
|
16
|
+
filter: ${C(r)};
|
|
17
|
+
mix-blend-mode: hard-light;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
${o}__blob {
|
|
21
|
+
position: absolute;
|
|
22
|
+
transform: translate(-50%, -50%);
|
|
23
|
+
transform-origin: var(--g-gradient-morph-origin-x) var(--g-gradient-morph-origin-y);
|
|
24
|
+
opacity: var(--g-gradient-morph-opacity);
|
|
25
|
+
filter: blur(var(--g-gradient-morph-blur));
|
|
26
|
+
border-radius: 999px;
|
|
27
|
+
background: radial-gradient(circle, var(--g-gradient-morph-blob-color) 0%, transparent 72%);
|
|
28
|
+
animation: var(--g-gradient-morph-animation) var(--g-gradient-morph-duration, 9000ms) ease-in-out infinite alternate;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
${d.map((a,s)=>`${o}__blob:nth-child(${s+1}) {
|
|
32
|
+
top: ${a.y}%;
|
|
33
|
+
left: ${a.x}%;
|
|
34
|
+
width: ${a.size}%;
|
|
35
|
+
aspect-ratio: 1;
|
|
36
|
+
--g-gradient-morph-blob-color: ${a.color};
|
|
37
|
+
--g-gradient-morph-x: ${a.dx}%;
|
|
38
|
+
--g-gradient-morph-x2: ${a.dx2}%;
|
|
39
|
+
--g-gradient-morph-y: ${a.dy}%;
|
|
40
|
+
--g-gradient-morph-y2: ${a.dy2}%;
|
|
41
|
+
--g-gradient-morph-origin-x: ${a.originX};
|
|
42
|
+
--g-gradient-morph-origin-y: ${a.originY};
|
|
43
|
+
--g-gradient-morph-animation: ${a.animationName};
|
|
44
|
+
--g-gradient-morph-blur: ${a.blur}px;
|
|
45
|
+
--g-gradient-morph-opacity: ${a.opacity};
|
|
46
|
+
--g-gradient-morph-rotate-mid: ${a.rotateMid}deg;
|
|
47
|
+
--g-gradient-morph-rotate-to: ${a.rotateTo}deg;
|
|
48
|
+
--g-gradient-morph-scale-mid: ${a.scaleMid};
|
|
49
|
+
--g-gradient-morph-scale: ${a.scaleTo};
|
|
50
|
+
animation-delay: ${a.delay}ms;
|
|
51
|
+
animation-duration: ${c.toCssDuration(a.duration)};
|
|
52
|
+
}`).join(`
|
|
53
|
+
|
|
54
|
+
`)}
|
|
55
|
+
|
|
56
|
+
@keyframes g-gradient-morph-drift {
|
|
57
|
+
0% {
|
|
58
|
+
transform: translate(-50%, -50%) scale(0.92);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
42% {
|
|
62
|
+
transform: translate(calc(-50% + var(--g-gradient-morph-x)), calc(-50% + var(--g-gradient-morph-y))) scale(var(--g-gradient-morph-scale));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
100% {
|
|
66
|
+
transform: translate(calc(-50% + var(--g-gradient-morph-x2)), calc(-50% + var(--g-gradient-morph-y2))) scale(var(--g-gradient-morph-scale-mid));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@keyframes g-gradient-morph-float {
|
|
71
|
+
0% {
|
|
72
|
+
transform: translate(-50%, -50%) scale(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
50% {
|
|
76
|
+
transform: translate(calc(-50% + var(--g-gradient-morph-x)), calc(-50% + var(--g-gradient-morph-y))) scale(var(--g-gradient-morph-scale-mid));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
100% {
|
|
80
|
+
transform: translate(calc(-50% + var(--g-gradient-morph-x2)), calc(-50% + var(--g-gradient-morph-y2))) scale(var(--g-gradient-morph-scale));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@keyframes g-gradient-morph-orbit {
|
|
85
|
+
0% {
|
|
86
|
+
transform: translate(-50%, -50%) rotate(0deg) scale(0.96);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
50% {
|
|
90
|
+
transform: translate(calc(-50% + var(--g-gradient-morph-x)), calc(-50% + var(--g-gradient-morph-y))) rotate(var(--g-gradient-morph-rotate-mid)) scale(var(--g-gradient-morph-scale-mid));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
100% {
|
|
94
|
+
transform: translate(calc(-50% + var(--g-gradient-morph-x2)), calc(-50% + var(--g-gradient-morph-y2))) rotate(var(--g-gradient-morph-rotate-to)) scale(var(--g-gradient-morph-scale));
|
|
95
|
+
}
|
|
96
|
+
}`},S=(t,r)=>{const o=t.stops.filter(a=>a.position>=25&&a.position<=85),n=t.stops.filter(a=>!o.includes(a));return[...o,...n].sort((a,s)=>Math.abs(a.position-50)-Math.abs(s.position-50)).slice(0,r)},D=(t,r)=>t*([1,.54,.3,.18][r]??.12),h=(t,r)=>{const o=String(t).match(/^(-?\d*\.?\d+)(.*)$/);return o?`${Math.round(Number(o[1])*r*1e3)/1e3}${o[2]||"px"}`:null},b=(t,r,o)=>h(t,1/r)??(o===0?c.toCssLength(t):"0px"),L=(t,r)=>h(t,1/Math.sqrt(r))??c.toCssLength(t),_=(t,r={})=>{var f;const o=r.x??0,n=r.y??6,d=r.blur??14,a=r.spread??-3,s=r.opacity??.24,e=Math.max(1,Math.round(r.layers??2)),i=((f=S(t,1)[0])==null?void 0:f.color)??"#000000",l=`${c.toCssLength(o)} ${c.toCssLength(n)} ${c.toCssLength(d)} ${c.toCssLength(a)} ${c.toCssColor(i,s)}`;if(e===1)return l;const p=h(o,.35)??"0px",u=h(n,.35)??"2px",$=h(d,.3)??"4px",x=h(a,.5)??"-2px",w=Math.min(.18,s*.65);return`${`${p} ${u} ${$} ${x} ${c.toCssColor("#000000",w)}`}, ${l}`},F=(t,r={})=>{const o=r.x??0,n=r.y??6,d=r.blur??14,a=r.opacity??.42,s=Math.max(1,Math.round(r.layers??2)),e=L(d,s);return S(t,s).map((i,l)=>{const p=b(o,s,l),u=b(n,s,l);return`drop-shadow(${p} ${u} ${e} ${c.toCssColor(i.color,D(a,l))})`}).join(" ")};exports.createGradientMorphBlobs=v;exports.toGradientBoxShadow=_;exports.toGradientDropShadow=F;exports.toGradientMorphCSS=k;exports.toGradientMorphFilter=C;exports.toGradientMorphFilterMarkup=B;
|