@gradient-ui/gradient-engine 0.5.0 → 0.6.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 +22 -2
- package/dist/animation.cjs +1 -1
- package/dist/animation.mjs +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.mjs +12 -9
- package/dist/{css-YuAJQW13.cjs → css-BVHXLMRl.cjs} +1 -1
- package/dist/{css-CaOuUhfh.js → css-DVaTTIqS.js} +1 -1
- package/dist/design-tokens.cjs +1 -0
- package/dist/design-tokens.mjs +8 -0
- package/dist/designTokens-BnzZfRES.js +116 -0
- package/dist/designTokens-C1WdzS3v.cjs +1 -0
- package/dist/effects.cjs +137 -32
- package/dist/effects.mjs +221 -104
- package/dist/formatters.cjs +1 -1
- package/dist/formatters.mjs +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +61 -41
- package/dist/material.cjs +9 -1
- package/dist/material.mjs +236 -4
- package/dist/presets-BBLdqUE4.cjs +316 -0
- package/dist/presets-DYXLx_nN.js +4025 -0
- package/dist/{svg-BVcl24Cf.cjs → svg-dGtLYnIJ.cjs} +1 -1
- package/dist/{svg-CZThYPKf.js → svg-hZus3ztj.js} +2 -2
- package/dist/types/color.d.ts +1 -0
- package/dist/types/colorSeeds.d.ts +22 -0
- package/dist/types/colorSystem.d.ts +20 -0
- package/dist/types/designTokens.d.ts +24 -0
- package/dist/types/effects/index.d.ts +1 -1
- package/dist/types/effects/morph.d.ts +4 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/material.d.ts +1 -1
- package/dist/types/palette.d.ts +7 -0
- package/dist/types/scheme.d.ts +3 -0
- package/dist/types/tokens.d.ts +9 -1
- package/dist/types/types.d.ts +10 -0
- package/dist/types-BFr1fN-7.js +22 -0
- package/dist/types-BMLEvdee.cjs +1 -0
- package/dist/utils-BzSNCfat.js +76 -0
- package/dist/utils-D83DMCMa.cjs +1 -0
- package/package.json +9 -1
- package/dist/presets-55krt4L_.js +0 -354
- package/dist/presets-UIJJyagu.cjs +0 -1
- package/dist/tokens-DMGI7_df.cjs +0 -9
- package/dist/tokens-OfSofVKl.js +0 -204
- package/dist/utils-6iJ6IpZZ.cjs +0 -1
- package/dist/utils-B_VQDGMy.js +0 -67
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const $=require("./utils-
|
|
1
|
+
"use strict";const $=require("./utils-D83DMCMa.cjs"),B=require("./css-BVHXLMRl.cjs"),p="http://www.w3.org/2000/svg",G="http://www.w3.org/1999/xhtml",c=e=>e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">"),x=e=>{const t=e.opacity===void 0?"":` stop-opacity="${$.clamp(e.opacity)}"`;return`<stop offset="${e.position}%" stop-color="${e.color}"${t} />`},P=(e,t)=>{var r,a,i;return{active:t.activeStroke??((r=e.stops[Math.max(0,Math.floor(e.stops.length/2))])==null?void 0:r.color)??((a=e.stops[0])==null?void 0:a.color)??"currentColor",background:t.backgroundStroke??((i=e.stops[0])==null?void 0:i.color)??t.activeStroke??"currentColor"}},A=(e,t)=>{var n;const r=(n=e.match(/\bviewBox=(["'])(.*?)\1/i))==null?void 0:n[2];if(r)return r;const a=t.width??240,i=t.height??120;return`0 0 ${a} ${i}`},N=e=>{var t;return((t=e.replace(/<\?xml[\s\S]*?\?>/gi,"").replace(/<!doctype[\s\S]*?>/gi,"").match(/<svg\b[^>]*>([\s\S]*?)<\/svg>/i))==null?void 0:t[1].trim())??e},j=e=>{const t=e.trim().split(/(?=M\s*[-+.\d])/).map(r=>r.trim()).filter(Boolean);return t.length>1?t:[e]},O=e=>[...e.matchAll(/<path\b[^>]*\sd=(["'])([\s\S]*?)\1/gi)].flatMap(t=>j(t[2])),v=e=>{var t;return Math.max(1,((t=e.match(/[LlHhVvCcSsQqTtAaZz]/g))==null?void 0:t.length)??0)},T=(e,t)=>{const a=.5+(1-v(e)/t)*.22;return Math.round(a*1e3)/1e3},k=e=>{const[t="0",r="0",a="240",i="120"]=e.trim().split(/[\s,]+/);return{height:Number(i)||120,width:Number(a)||240,x:Number(t)||0,y:Number(r)||0}},V=(e,t,r)=>{if(r.viewBoxPadding===!1)return e;const a=k(e),i=Math.max(t*2,Math.min(a.width,a.height)*.02),n=r.viewBoxPadding??i;return[a.x-n,a.y-n,a.width+n*2,a.height+n*2].join(" ")},W=e=>{const{height:t,width:r}=k(e);return{height:Number(t)||120,width:Number(r)||240}},U=(e,t,r)=>{if(r.normalizeStrokeWidth===!1)return e;const{height:a,width:i}=W(t),n=r.strokeWidthBase??180;return e*(Math.min(i,a)/n)},S=(e,t={})=>{const r=t.id??"g-gradient",a=e.stops.map(x).join("");return e.type==="radial"?`<radialGradient id="${r}" cx="${t.cx??"50%"}" cy="${t.cy??"50%"}" r="${t.r??"75%"}">${a}</radialGradient>`:e.type==="conic"?`<pattern id="${r}" patternUnits="objectBoundingBox" width="1" height="1"><foreignObject x="0" y="0" width="100%" height="100%"><div xmlns="${G}" style="width:100%;height:100%;background:${c(B.toCssGradient(e))};"></div></foreignObject></pattern>`:`<linearGradient id="${r}" x1="${t.x1??"0%"}" y1="${t.y1??"0%"}" x2="${t.x2??"100%"}" y2="${t.y2??"100%"}">${a}</linearGradient>`},q=(e,t={})=>{const r=t.id??"g-gradient",a=t.width??240,i=t.height??120,n=t.rx??18;return`<svg xmlns="${p}" viewBox="0 0 ${a} ${i}" role="img">
|
|
2
2
|
<defs>
|
|
3
3
|
${S(e,t)}
|
|
4
4
|
</defs>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as y, b as v } from "./utils-
|
|
2
|
-
import { t as C } from "./css-
|
|
1
|
+
import { t as y, b as v } from "./utils-BzSNCfat.js";
|
|
2
|
+
import { t as C } from "./css-DVaTTIqS.js";
|
|
3
3
|
const m = "http://www.w3.org/2000/svg", G = "http://www.w3.org/1999/xhtml", c = (e) => e.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"), p = (e) => {
|
|
4
4
|
const t = e.opacity === void 0 ? "" : ` stop-opacity="${v(e.opacity)}"`;
|
|
5
5
|
return `<stop offset="${e.position}%" stop-color="${e.color}"${t} />`;
|
package/dist/types/color.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export declare const parseColor: (input: ColorInput) => RgbColor | null;
|
|
|
8
8
|
export declare const rgbToHex: ({ r, g, b }: RgbColor) => string;
|
|
9
9
|
export declare const rgbToChannels: ({ r, g, b }: RgbColor) => string;
|
|
10
10
|
export declare const colorToHex: (input: ColorInput, fallback: string) => string;
|
|
11
|
+
export declare const getContrastingColor: (color: ColorInput) => "#ffffff" | "#0d0d12";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const COLOR_SEEDS: {
|
|
2
|
+
readonly red: "#F44336";
|
|
3
|
+
readonly pink: "#E91E63";
|
|
4
|
+
readonly purple: "#9C27B0";
|
|
5
|
+
readonly deepPurple: "#673AB7";
|
|
6
|
+
readonly indigo: "#3F51B5";
|
|
7
|
+
readonly blue: "#2196F3";
|
|
8
|
+
readonly lightBlue: "#03A9F4";
|
|
9
|
+
readonly cyan: "#00BCD4";
|
|
10
|
+
readonly teal: "#009688";
|
|
11
|
+
readonly green: "#4CAF50";
|
|
12
|
+
readonly lightGreen: "#8BC34A";
|
|
13
|
+
readonly lime: "#CDDC39";
|
|
14
|
+
readonly yellow: "#FFEB3B";
|
|
15
|
+
readonly amber: "#FFC107";
|
|
16
|
+
readonly orange: "#FF9800";
|
|
17
|
+
readonly deepOrange: "#FF5722";
|
|
18
|
+
readonly brown: "#795548";
|
|
19
|
+
readonly grey: "#9E9E9E";
|
|
20
|
+
readonly blueGrey: "#607D8B";
|
|
21
|
+
};
|
|
22
|
+
export type ColorFamily = keyof typeof COLOR_SEEDS;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ColorPalettePair } from './palette';
|
|
2
|
+
import type { ColorInput } from './color';
|
|
3
|
+
import type { ThemeTokens } from './scheme';
|
|
4
|
+
export interface ThemeColorDefinition {
|
|
5
|
+
color: ColorInput;
|
|
6
|
+
onColor?: ColorInput;
|
|
7
|
+
palette?: boolean;
|
|
8
|
+
gradient?: string | false;
|
|
9
|
+
}
|
|
10
|
+
export type ThemeColorValue = ColorInput | ThemeColorDefinition;
|
|
11
|
+
export type ThemeColorExtensions = Record<string, ThemeColorValue>;
|
|
12
|
+
export interface ColorSystem {
|
|
13
|
+
colors: ThemeTokens;
|
|
14
|
+
gradients: ThemeTokens;
|
|
15
|
+
palettes: Record<string, ColorPalettePair>;
|
|
16
|
+
}
|
|
17
|
+
export interface ColorSystemOptions {
|
|
18
|
+
colors?: ThemeColorExtensions;
|
|
19
|
+
}
|
|
20
|
+
export declare const createColorSystem: (seed: ColorInput, options?: ColorSystemOptions) => ColorSystem;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ColorInput } from './color';
|
|
2
|
+
import { type ColorSystem, type ThemeColorExtensions } from './colorSystem';
|
|
3
|
+
import { type CreatedGradientTokens, type GradientTokenOptions } from './tokens';
|
|
4
|
+
import { type ThemeMode, type ThemeTokens } from './scheme';
|
|
5
|
+
export declare const DEFAULT_SEED = "#4e51ff";
|
|
6
|
+
export interface DesignTokenOptions {
|
|
7
|
+
seed?: ColorInput;
|
|
8
|
+
mode?: ThemeMode;
|
|
9
|
+
colors?: ThemeColorExtensions;
|
|
10
|
+
gradientTokens?: GradientTokenOptions;
|
|
11
|
+
}
|
|
12
|
+
export interface CreatedDesignTokens {
|
|
13
|
+
seed: string;
|
|
14
|
+
mode: ThemeMode;
|
|
15
|
+
tokens: {
|
|
16
|
+
theme: ThemeTokens;
|
|
17
|
+
colors: ThemeTokens;
|
|
18
|
+
gradients: ThemeTokens;
|
|
19
|
+
};
|
|
20
|
+
colorSystem: ColorSystem;
|
|
21
|
+
gradientTokens: CreatedGradientTokens;
|
|
22
|
+
}
|
|
23
|
+
export declare const normalizeDesignTokenSeed: (seed?: ColorInput) => string;
|
|
24
|
+
export declare const createDesignTokens: (options?: DesignTokenOptions) => CreatedDesignTokens;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createGradientMorphBlobs, toGradientMorphCSS, toGradientMorphFilter, toGradientMorphFilterMarkup } from './morph';
|
|
1
|
+
export { createGradientMorphBlobs, isGradientMorphBlendMode, resolveGradientMorphBlendMode, toGradientMorphCSS, toGradientMorphFilter, toGradientMorphFilterMarkup, toGradientMorphMarkup } from './morph';
|
|
2
2
|
export { toGradientBoxShadow, toGradientDropShadow } from './shadow';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type { GradientModel, GradientMorphBlob, GradientMorphOptions } from '../types';
|
|
1
|
+
import type { GradientModel, GradientMorphBlob, GradientMorphBlendMode, GradientMorphMarkupOptions, GradientMorphOptions } from '../types';
|
|
2
|
+
export declare const isGradientMorphBlendMode: (value: string) => value is GradientMorphBlendMode;
|
|
3
|
+
export declare const resolveGradientMorphBlendMode: (value: string | undefined) => GradientMorphBlendMode;
|
|
2
4
|
export declare const createGradientMorphBlobs: (model: GradientModel, options?: GradientMorphOptions) => GradientMorphBlob[];
|
|
3
5
|
export declare const toGradientMorphFilter: (options?: GradientMorphOptions) => string;
|
|
4
6
|
export declare const toGradientMorphFilterMarkup: (options?: GradientMorphOptions) => string;
|
|
5
7
|
export declare const toGradientMorphCSS: (model: GradientModel, options?: GradientMorphOptions) => string;
|
|
8
|
+
export declare const toGradientMorphMarkup: (model: GradientModel, options?: GradientMorphMarkupOptions) => string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export * from './core';
|
|
2
2
|
export * from './color';
|
|
3
|
+
export * from './colorSeeds';
|
|
4
|
+
export * from './colorSystem';
|
|
3
5
|
export * from './palette';
|
|
6
|
+
export * from './scheme';
|
|
4
7
|
export * from './formatters';
|
|
5
8
|
export * from './effects';
|
|
6
9
|
export { toGradientAnimationCSS } from './animation';
|
|
7
10
|
export * from './material';
|
|
11
|
+
export * from './designTokens';
|
package/dist/types/material.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createGradientMaterial, createGradientPreset, createGradientTokens, type CreatedGradientMaterial, type CreatedGradientPreset, type CreatedGradientTokens, type GradientAnimationTokenEntry, type GradientEffectTokenEntry, type GradientMaterialOptions, type GradientTokenEntry, type GradientTokenOptions, type GradientTokenRecipe } from './tokens';
|
|
1
|
+
export { createGradientMaterial, createGradientPreset, createGradientTokens, clearGradientMaterialCache, getGradientMaterialCacheStats, setGradientMaterialCacheLimit, type CreatedGradientMaterial, type CreatedGradientPreset, type CreatedGradientTokens, type GradientAnimationTokenEntry, type GradientEffectTokenEntry, type GradientMaterialOptions, type GradientTokenEntry, type GradientTokenOptions, type GradientTokenRecipe } from './tokens';
|
package/dist/types/palette.d.ts
CHANGED
|
@@ -2,5 +2,12 @@ import { type ColorInput } from './color';
|
|
|
2
2
|
export declare const COLOR_SHADES: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
|
|
3
3
|
export type ColorShade = (typeof COLOR_SHADES)[number];
|
|
4
4
|
export type ColorPalette = Record<ColorShade, string>;
|
|
5
|
+
export interface ColorPalettePair {
|
|
6
|
+
colors: ColorPalette;
|
|
7
|
+
onColors: ColorPalette;
|
|
8
|
+
}
|
|
5
9
|
export declare const SHADE_TONES: Record<ColorShade, number>;
|
|
10
|
+
export declare const ON_SHADE_TONES: Record<ColorShade, number>;
|
|
6
11
|
export declare const createPalette: (seed: ColorInput) => ColorPalette;
|
|
12
|
+
export declare const createOnPalette: (seed: ColorInput) => ColorPalette;
|
|
13
|
+
export declare const createPalettePair: (seed: ColorInput) => ColorPalettePair;
|
package/dist/types/tokens.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ColorInput } from './color';
|
|
2
2
|
import { type GradientPresetName, type GradientPresetRegistry } from './presets';
|
|
3
|
-
import type { GradientAnimationOptions, GradientMorphBlob, GradientMorphOptions, GradientModel, GradientOptions, GradientRecipe, GradientShadowOptions, GradientStop } from './types';
|
|
3
|
+
import type { GradientAnimationOptions, GradientMorphBlendMode, GradientMorphBlob, GradientMorphOptions, GradientModel, GradientOptions, GradientRecipe, GradientShadowOptions, GradientStop } from './types';
|
|
4
4
|
export type GradientTokenRecipe = GradientRecipe | GradientPresetName | 'mesh' | 'soft';
|
|
5
5
|
export interface GradientTokenEntry {
|
|
6
6
|
value: string;
|
|
@@ -23,6 +23,8 @@ export interface GradientEffectTokenEntry {
|
|
|
23
23
|
value: string;
|
|
24
24
|
cssVar: string;
|
|
25
25
|
svg: string;
|
|
26
|
+
blendMode: GradientMorphBlendMode;
|
|
27
|
+
blendModeCssVar: string;
|
|
26
28
|
};
|
|
27
29
|
}
|
|
28
30
|
export interface GradientAnimationTokenEntry {
|
|
@@ -85,6 +87,12 @@ export interface CreatedGradientMaterial {
|
|
|
85
87
|
animation?: GradientAnimationTokenEntry;
|
|
86
88
|
morphBlobs?: GradientMorphBlob[];
|
|
87
89
|
}
|
|
90
|
+
export declare const clearGradientMaterialCache: () => void;
|
|
91
|
+
export declare const setGradientMaterialCacheLimit: (limit: number) => void;
|
|
92
|
+
export declare const getGradientMaterialCacheStats: () => {
|
|
93
|
+
limit: number;
|
|
94
|
+
size: number;
|
|
95
|
+
};
|
|
88
96
|
export declare const createGradientPreset: (seed: ColorInput, recipe?: GradientTokenRecipe, options?: GradientOptions & {
|
|
89
97
|
animation?: GradientAnimationOptions;
|
|
90
98
|
dropShadow?: GradientShadowOptions;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -36,10 +36,15 @@ export interface GradientShadowOptions {
|
|
|
36
36
|
layers?: number;
|
|
37
37
|
}
|
|
38
38
|
export type GradientMorphPreset = 'soft' | 'liquid' | 'ripple';
|
|
39
|
+
export declare const GRADIENT_MORPH_BLEND_MODES: readonly ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"];
|
|
40
|
+
export type GradientMorphBlendMode = (typeof GRADIENT_MORPH_BLEND_MODES)[number];
|
|
41
|
+
export declare const DEFAULT_GRADIENT_MORPH_BLEND_MODE = "hard-light";
|
|
39
42
|
export interface GradientMorphOptions {
|
|
40
43
|
id?: string;
|
|
41
44
|
preset?: GradientMorphPreset;
|
|
45
|
+
blendMode?: GradientMorphBlendMode;
|
|
42
46
|
blobCount?: number;
|
|
47
|
+
blobOpacity?: number;
|
|
43
48
|
blur?: number;
|
|
44
49
|
contrast?: number;
|
|
45
50
|
duration?: number | string;
|
|
@@ -47,6 +52,11 @@ export interface GradientMorphOptions {
|
|
|
47
52
|
scale?: number;
|
|
48
53
|
selector?: string;
|
|
49
54
|
}
|
|
55
|
+
export interface GradientMorphMarkupOptions extends GradientMorphOptions {
|
|
56
|
+
width?: number;
|
|
57
|
+
height?: number;
|
|
58
|
+
rx?: number;
|
|
59
|
+
}
|
|
50
60
|
export interface GradientMorphBlob {
|
|
51
61
|
animationName: string;
|
|
52
62
|
blur: number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const o = [
|
|
2
|
+
"normal",
|
|
3
|
+
"multiply",
|
|
4
|
+
"screen",
|
|
5
|
+
"overlay",
|
|
6
|
+
"darken",
|
|
7
|
+
"lighten",
|
|
8
|
+
"color-dodge",
|
|
9
|
+
"color-burn",
|
|
10
|
+
"hard-light",
|
|
11
|
+
"soft-light",
|
|
12
|
+
"difference",
|
|
13
|
+
"exclusion",
|
|
14
|
+
"hue",
|
|
15
|
+
"saturation",
|
|
16
|
+
"color",
|
|
17
|
+
"luminosity"
|
|
18
|
+
], l = "hard-light";
|
|
19
|
+
export {
|
|
20
|
+
l as D,
|
|
21
|
+
o as G
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o=["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],D="hard-light";exports.DEFAULT_GRADIENT_MORPH_BLEND_MODE=D;exports.GRADIENT_MORPH_BLEND_MODES=o;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const o = (t, n = 0, r = 1) => Math.min(r, Math.max(n, t)), a = (t) => {
|
|
2
|
+
const n = t / 255;
|
|
3
|
+
return n <= 0.04045 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4;
|
|
4
|
+
}, i = (t) => {
|
|
5
|
+
const n = t.slice(1), r = n.length === 3 || n.length === 4 ? n.slice(0, 3).split("").map((s) => s.repeat(2)).join("") : n.slice(0, 6);
|
|
6
|
+
return r.length !== 6 || !/^[\da-f]{6}$/i.test(r) ? null : {
|
|
7
|
+
r: parseInt(r.slice(0, 2), 16),
|
|
8
|
+
g: parseInt(r.slice(2, 4), 16),
|
|
9
|
+
b: parseInt(r.slice(4, 6), 16)
|
|
10
|
+
};
|
|
11
|
+
}, f = (t) => {
|
|
12
|
+
const n = t.match(
|
|
13
|
+
/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:\s*[,/]\s*[\d.]+%?)?\s*\)$/i
|
|
14
|
+
);
|
|
15
|
+
return n ? {
|
|
16
|
+
r: o(Number(n[1]), 0, 255),
|
|
17
|
+
g: o(Number(n[2]), 0, 255),
|
|
18
|
+
b: o(Number(n[3]), 0, 255)
|
|
19
|
+
} : null;
|
|
20
|
+
}, e = (t) => {
|
|
21
|
+
if (typeof t == "number") {
|
|
22
|
+
const r = t & 16777215;
|
|
23
|
+
return {
|
|
24
|
+
r: r >> 16 & 255,
|
|
25
|
+
g: r >> 8 & 255,
|
|
26
|
+
b: r & 255
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const n = t.trim();
|
|
30
|
+
return n.startsWith("#") ? i(n) : n.toLowerCase().startsWith("rgb") ? f(n) : null;
|
|
31
|
+
}, u = ({ r: t, g: n, b: r }) => `#${[t, n, r].map((s) => Math.round(s).toString(16).padStart(2, "0")).join("")}`, l = ({ r: t, g: n, b: r }) => `${Math.round(t)}, ${Math.round(n)}, ${Math.round(r)}`, g = (t, n) => {
|
|
32
|
+
const r = e(t) ?? e(n);
|
|
33
|
+
if (!r)
|
|
34
|
+
throw new Error(`Invalid fallback color: ${n}`);
|
|
35
|
+
return u(r);
|
|
36
|
+
}, m = (t) => 0.2126 * a(t.r) + 0.7152 * a(t.g) + 0.0722 * a(t.b), d = (t) => {
|
|
37
|
+
const n = e(t);
|
|
38
|
+
if (!n) return "#ffffff";
|
|
39
|
+
const r = m(n), s = 1.05 / (r + 0.05), c = (r + 0.05) / 0.055;
|
|
40
|
+
return s >= c ? "#ffffff" : "#0d0d12";
|
|
41
|
+
}, b = 135, I = "center", $ = "farthest-corner", C = (t = 135) => typeof t == "number" ? `${t}deg` : t, T = (t) => typeof t == "number" ? `${t}px` : t, D = (t) => typeof t == "number" ? `${t}ms` : t, p = (t, n = 0, r = 1) => Math.min(r, Math.max(n, t)), h = (t, n) => {
|
|
42
|
+
if (n === void 0) return t;
|
|
43
|
+
const r = e(t);
|
|
44
|
+
return r ? `rgb(${l(r).replace(/,/g, "")} / ${p(n)})` : t;
|
|
45
|
+
}, E = ({ color: t, opacity: n, position: r }) => `${h(t, n)} ${r}%`, N = (t, n, r) => ({
|
|
46
|
+
color: t,
|
|
47
|
+
position: n
|
|
48
|
+
}), x = (t) => {
|
|
49
|
+
if (t.length <= 1) return t;
|
|
50
|
+
const n = t.map((s) => ({
|
|
51
|
+
...s,
|
|
52
|
+
position: s.position / 2
|
|
53
|
+
})), r = [...t].reverse().map((s) => ({
|
|
54
|
+
...s,
|
|
55
|
+
position: 100 - s.position / 2
|
|
56
|
+
}));
|
|
57
|
+
return [...n, ...r];
|
|
58
|
+
};
|
|
59
|
+
export {
|
|
60
|
+
b as D,
|
|
61
|
+
u as a,
|
|
62
|
+
p as b,
|
|
63
|
+
g as c,
|
|
64
|
+
$ as d,
|
|
65
|
+
I as e,
|
|
66
|
+
E as f,
|
|
67
|
+
d as g,
|
|
68
|
+
x as h,
|
|
69
|
+
N as i,
|
|
70
|
+
h as j,
|
|
71
|
+
T as k,
|
|
72
|
+
C as n,
|
|
73
|
+
e as p,
|
|
74
|
+
l as r,
|
|
75
|
+
D as t
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const s=(t,n=0,r=1)=>Math.min(r,Math.max(n,t)),a=t=>{const n=t/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4},m=t=>{const n=t.slice(1),r=n.length===3||n.length===4?n.slice(0,3).split("").map(o=>o.repeat(2)).join(""):n.slice(0,6);return r.length!==6||!/^[\da-f]{6}$/i.test(r)?null:{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16)}},p=t=>{const n=t.match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:\s*[,/]\s*[\d.]+%?)?\s*\)$/i);return n?{r:s(Number(n[1]),0,255),g:s(Number(n[2]),0,255),b:s(Number(n[3]),0,255)}:null},e=t=>{if(typeof t=="number"){const r=t&16777215;return{r:r>>16&255,g:r>>8&255,b:r&255}}const n=t.trim();return n.startsWith("#")?m(n):n.toLowerCase().startsWith("rgb")?p(n):null},c=({r:t,g:n,b:r})=>`#${[t,n,r].map(o=>Math.round(o).toString(16).padStart(2,"0")).join("")}`,i=({r:t,g:n,b:r})=>`${Math.round(t)}, ${Math.round(n)}, ${Math.round(r)}`,T=(t,n)=>{const r=e(t)??e(n);if(!r)throw new Error(`Invalid fallback color: ${n}`);return c(r)},g=t=>.2126*a(t.r)+.7152*a(t.g)+.0722*a(t.b),I=t=>{const n=e(t);if(!n)return"#ffffff";const r=g(n),o=1.05/(r+.05),u=(r+.05)/.055;return o>=u?"#ffffff":"#0d0d12"};const h="center",C="farthest-corner",D=(t=135)=>typeof t=="number"?`${t}deg`:t,E=t=>typeof t=="number"?`${t}px`:t,b=t=>typeof t=="number"?`${t}ms`:t,l=(t,n=0,r=1)=>Math.min(r,Math.max(n,t)),f=(t,n)=>{if(n===void 0)return t;const r=e(t);return r?`rgb(${i(r).replace(/,/g,"")} / ${l(n)})`:t},d=({color:t,opacity:n,position:r})=>`${f(t,n)} ${r}%`,N=(t,n,r)=>({color:t,position:n}),A=t=>{if(t.length<=1)return t;const n=t.map(o=>({...o,position:o.position/2})),r=[...t].reverse().map(o=>({...o,position:100-o.position/2}));return[...n,...r]};exports.DEFAULT_GRADIENT_DIRECTION=135;exports.DEFAULT_GRADIENT_POSITION=h;exports.DEFAULT_GRADIENT_SIZE=C;exports.clamp=l;exports.colorToHex=T;exports.createStop=N;exports.formatStop=d;exports.getConicStops=A;exports.getContrastingColor=I;exports.normalizeDirection=D;exports.parseColor=e;exports.rgbToChannels=i;exports.rgbToHex=c;exports.toCssColor=f;exports.toCssDuration=b;exports.toCssLength=E;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradient-ui/gradient-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Framework-free gradient generation engine for CSS, SVG, canvas, effects and material tokens.",
|
|
@@ -75,6 +75,11 @@
|
|
|
75
75
|
"import": "./dist/material.mjs",
|
|
76
76
|
"require": "./dist/material.cjs"
|
|
77
77
|
},
|
|
78
|
+
"./design-tokens": {
|
|
79
|
+
"types": "./dist/types/designTokens.d.ts",
|
|
80
|
+
"import": "./dist/design-tokens.mjs",
|
|
81
|
+
"require": "./dist/design-tokens.cjs"
|
|
82
|
+
},
|
|
78
83
|
"./package.json": "./package.json"
|
|
79
84
|
},
|
|
80
85
|
"typesVersions": {
|
|
@@ -94,6 +99,9 @@
|
|
|
94
99
|
"material": [
|
|
95
100
|
"dist/types/material.d.ts"
|
|
96
101
|
],
|
|
102
|
+
"design-tokens": [
|
|
103
|
+
"dist/types/designTokens.d.ts"
|
|
104
|
+
],
|
|
97
105
|
"*": [
|
|
98
106
|
"dist/types/index.d.ts"
|
|
99
107
|
]
|