gradiente 2.0.1 → 2.1.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/dist/index.d.mts +53 -26
- package/dist/index.mjs +633 -107
- package/package.json +54 -68
package/dist/index.d.mts
CHANGED
|
@@ -10,14 +10,14 @@ declare function fromPercent(value: number): number;
|
|
|
10
10
|
//#region src/utils/math/angle.d.ts
|
|
11
11
|
type AngleUnit = 'deg' | 'rad' | 'turn' | 'grad';
|
|
12
12
|
declare function isAngleUnit(unit: string): unit is AngleUnit;
|
|
13
|
+
declare function isAngle(value: string): boolean;
|
|
14
|
+
declare function angleValueFromString(value: string): number;
|
|
13
15
|
declare function degToRad(value: number): number;
|
|
14
16
|
declare function radToDeg(value: number): number;
|
|
15
17
|
declare function turnToRad(value: number): number;
|
|
16
18
|
declare function gradToRad(value: number): number;
|
|
17
19
|
declare function normalizeAngleDeg(value: number, digits?: number): number;
|
|
18
|
-
declare function normalizeAngleRad(value: number): number;
|
|
19
|
-
declare function toAngleRad(value: number, unit: AngleUnit): number;
|
|
20
|
-
declare function normalizeAngle(value: number, unit: AngleUnit, digits?: number): number;
|
|
20
|
+
declare function normalizeAngleRad(value: number, digits?: number): number;
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/abi.d.ts
|
|
23
23
|
/***************************************************************************************************/
|
|
@@ -84,6 +84,17 @@ declare function matchExpression(classified: GradientAbiInput[], patternTokens:
|
|
|
84
84
|
declare function isValid(input: GradientAbiInput[], pattern: string): boolean;
|
|
85
85
|
declare function validate(classified: GradientAbiInput[], pattern: string): boolean;
|
|
86
86
|
//#endregion
|
|
87
|
+
//#region src/gradients/helpers.d.ts
|
|
88
|
+
declare const GRADIENT_COLOR_SPACE: readonly ["oklab", "lch", "oklch", "hsl", "hwb", "lab", "srgb", "srgb-linear", "xyz", "display-p3", "a98-rgb", "prophoto-rgb", "rec2020"];
|
|
89
|
+
declare const GRADIENT_HUE_INTERPOLATIONS: readonly ['shorter', 'longer', 'increasing', 'decreasing'];
|
|
90
|
+
declare const GRADIENT_POLAR_COLOR_SPACES: readonly ["hsl", "hwb", "lch", "oklch"];
|
|
91
|
+
type GradientHueInterpolation = (typeof GRADIENT_HUE_INTERPOLATIONS)[number];
|
|
92
|
+
type GradientColorSpace = (typeof GRADIENT_COLOR_SPACE)[number];
|
|
93
|
+
type GradientPolarColorSpace = (typeof GRADIENT_POLAR_COLOR_SPACES)[number];
|
|
94
|
+
declare function isGradientHueInterpolation(value: string): value is GradientHueInterpolation;
|
|
95
|
+
declare function isGradientColorSpace(value: string): value is GradientColorSpace;
|
|
96
|
+
declare function isGradientPolarColorSpace(value: string): value is GradientPolarColorSpace;
|
|
97
|
+
//#endregion
|
|
87
98
|
//#region src/gradients/types.d.ts
|
|
88
99
|
/**
|
|
89
100
|
* Shared scalar units
|
|
@@ -131,7 +142,6 @@ type GradientPosition = {
|
|
|
131
142
|
*/
|
|
132
143
|
type GradientHueInterpolationMethod = "shorter" | "longer" | "increasing" | "decreasing";
|
|
133
144
|
type GradientRectangularColorSpace = "srgb" | "srgb-linear" | "display-p3" | "display-p3-linear" | "a98-rgb" | "prophoto-rgb" | "rec2020" | "lab" | "oklab" | "xyz" | "xyz-d50" | "xyz-d65";
|
|
134
|
-
type GradientPolarColorSpace = "hsl" | "hwb" | "lch" | "oklch";
|
|
135
145
|
type GradientColorInterpolation = {
|
|
136
146
|
kind: "rectangular";
|
|
137
147
|
space: GradientRectangularColorSpace;
|
|
@@ -236,21 +246,28 @@ declare abstract class GradientBase<TConfig = unknown> implements IGradientBase<
|
|
|
236
246
|
}
|
|
237
247
|
//#endregion
|
|
238
248
|
//#region src/gradients/LinearGradient.d.ts
|
|
239
|
-
type
|
|
249
|
+
type GradientInterpolation = {
|
|
250
|
+
colorSpace: GradientColorSpace;
|
|
251
|
+
hue?: GradientHueInterpolation;
|
|
252
|
+
};
|
|
253
|
+
type LinearGradientConfig = {
|
|
240
254
|
angle: number;
|
|
255
|
+
interpolation?: GradientInterpolation;
|
|
241
256
|
};
|
|
242
257
|
declare class LinearGradient extends GradientBase<LinearGradientConfig> {
|
|
243
258
|
readonly type = "linear-gradient";
|
|
244
259
|
constructor(config: GradientData<LinearGradientConfig>);
|
|
245
|
-
static normalizeConfig(value:
|
|
246
|
-
value: number;
|
|
247
|
-
unit: AngleUnit;
|
|
248
|
-
} | string): LinearGradientConfig;
|
|
260
|
+
static normalizeConfig(value: string): LinearGradientConfig;
|
|
249
261
|
static fromString(input: string): LinearGradient;
|
|
250
262
|
static fromAbi(abi: GradientAbi): LinearGradient;
|
|
251
263
|
clone(): this;
|
|
252
264
|
toString(): string;
|
|
253
265
|
protected _validateConfig(_: LinearGradientConfig): void;
|
|
266
|
+
private static _normalizeConfigInterpolation;
|
|
267
|
+
private _parseConfigToString;
|
|
268
|
+
private _parseAngleToString;
|
|
269
|
+
private _parseInterpolationToString;
|
|
270
|
+
private static _tokenizeConfigInput;
|
|
254
271
|
}
|
|
255
272
|
//#endregion
|
|
256
273
|
//#region src/gradients/RadialGradient.d.ts
|
|
@@ -338,19 +355,6 @@ interface ICanvasPaintResult {
|
|
|
338
355
|
draw(ctx: CanvasRenderingContext2D, width: number, height: number): void;
|
|
339
356
|
}
|
|
340
357
|
//#endregion
|
|
341
|
-
//#region src/gradient-transformer/GradientTransformer.d.ts
|
|
342
|
-
declare class GradientTransformer {
|
|
343
|
-
private static readonly _modules;
|
|
344
|
-
private static _initialized;
|
|
345
|
-
static add(module: IGradientTransformerModule): void;
|
|
346
|
-
static get(target: string, gradientType: string): IGradientTransformerModule | null;
|
|
347
|
-
static remove(target: string, gradientType: string): boolean;
|
|
348
|
-
static to<TOutput = unknown>(target: string, input: string | GradientBase<any>): TOutput;
|
|
349
|
-
static from<TOutput = unknown>(target: string, gradientType: string, input: TOutput): GradientBase<any>;
|
|
350
|
-
private static _ensureInitialized;
|
|
351
|
-
private static _getKey;
|
|
352
|
-
}
|
|
353
|
-
//#endregion
|
|
354
358
|
//#region src/gradient-transformer/modules/css/ModuleTransformerLinearGradientToCss.d.ts
|
|
355
359
|
declare class ModuleTransformerLinearGradientToCss implements IGradientTransformerModule<string> {
|
|
356
360
|
readonly target = "css";
|
|
@@ -374,14 +378,14 @@ declare class ModuleTransformerConicGradientToCss implements IGradientTransforme
|
|
|
374
378
|
//#endregion
|
|
375
379
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerLinearGradientToCanvas.d.ts
|
|
376
380
|
declare class ModuleTransformerLinearGradientToCanvas implements IGradientTransformerModule<ICanvasPaintResult> {
|
|
377
|
-
readonly target = "canvas";
|
|
381
|
+
readonly target = "canvas-2d";
|
|
378
382
|
readonly gradientType = "linear-gradient";
|
|
379
383
|
to(input: GradientBase<any>): ICanvasPaintResult;
|
|
380
384
|
}
|
|
381
385
|
//#endregion
|
|
382
386
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerRadialGradientToCanvas.d.ts
|
|
383
387
|
declare class ModuleTransformerRadialGradientToCanvas implements IGradientTransformerModule<ICanvasPaintResult> {
|
|
384
|
-
readonly target = "canvas";
|
|
388
|
+
readonly target = "canvas-2d";
|
|
385
389
|
readonly gradientType = "radial-gradient";
|
|
386
390
|
to(input: GradientBase<any>): ICanvasPaintResult;
|
|
387
391
|
private _resolve;
|
|
@@ -389,7 +393,7 @@ declare class ModuleTransformerRadialGradientToCanvas implements IGradientTransf
|
|
|
389
393
|
//#endregion
|
|
390
394
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerConicGradientToCanvas.d.ts
|
|
391
395
|
declare class ModuleTransformerConicGradientToCanvas implements IGradientTransformerModule<ICanvasPaintResult> {
|
|
392
|
-
readonly target = "canvas";
|
|
396
|
+
readonly target = "canvas-2d";
|
|
393
397
|
readonly gradientType = "conic-gradient";
|
|
394
398
|
to(input: GradientBase<any>): ICanvasPaintResult;
|
|
395
399
|
private _resolvePosition;
|
|
@@ -404,4 +408,27 @@ declare class ModuleTransformerConicGradientToCanvas implements IGradientTransfo
|
|
|
404
408
|
private _clamp01;
|
|
405
409
|
}
|
|
406
410
|
//#endregion
|
|
407
|
-
|
|
411
|
+
//#region src/gradient-transformer/modules/webgl/ModuleTransformerLinearGradientToWebgl.d.ts
|
|
412
|
+
interface IWebGLPaintResult {
|
|
413
|
+
draw(canvas: HTMLCanvasElement, width: number, height: number): void;
|
|
414
|
+
}
|
|
415
|
+
declare class ModuleTransformerLinearGradientToCanvasWebGL implements IGradientTransformerModule<IWebGLPaintResult> {
|
|
416
|
+
readonly target = "canvas-webgl";
|
|
417
|
+
readonly gradientType = "linear-gradient";
|
|
418
|
+
to(input: GradientBase<any>): IWebGLPaintResult;
|
|
419
|
+
}
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/gradient-transformer/GradientTransformer.d.ts
|
|
422
|
+
declare class GradientTransformer {
|
|
423
|
+
private static readonly _modules;
|
|
424
|
+
private static _initialized;
|
|
425
|
+
static add(module: IGradientTransformerModule): void;
|
|
426
|
+
static get(target: string, gradientType: string): IGradientTransformerModule | null;
|
|
427
|
+
static remove(target: string, gradientType: string): boolean;
|
|
428
|
+
static to<TOutput = unknown>(target: string, input: string | GradientBase<any>): TOutput;
|
|
429
|
+
static from<TOutput = unknown>(target: string, gradientType: string, input: TOutput): GradientBase<any>;
|
|
430
|
+
private static _ensureInitialized;
|
|
431
|
+
private static _getKey;
|
|
432
|
+
}
|
|
433
|
+
//#endregion
|
|
434
|
+
export { AbiInputType, AngleUnit, AnyGradient, ConicGradient, ConicGradientConfig, GRADIENT_COLOR_SPACE, GRADIENT_HUE_INTERPOLATIONS, GRADIENT_POLAR_COLOR_SPACES, GradientAbi, GradientAbiInput, GradientAngleUnit, GradientAngleValue, GradientBase, GradientColorHint, GradientColorInterpolation, GradientColorSpace, GradientColorStop, GradientCommonConfig, GradientData, GradientFactory, GradientHueInterpolation, GradientHueInterpolationMethod, GradientInterpolation, GradientLengthPercentage, GradientLengthUnit, GradientLengthValue, GradientNumberValue, GradientPercentValue, GradientPolarColorSpace, GradientPosition, GradientPositionKeywordX, GradientPositionKeywordY, GradientRectangularColorSpace, GradientStop, GradientTransformer, GradientType, ICanvasPaintResult, IGradientBase, IGradientStatic, IGradientTransformerModule, IWebGLPaintResult, LinearGradient, LinearGradientConfig, ModuleTransformerConicGradientToCanvas, ModuleTransformerConicGradientToCss, ModuleTransformerLinearGradientToCanvas, ModuleTransformerLinearGradientToCanvasWebGL, ModuleTransformerLinearGradientToCss, ModuleTransformerRadialGradientToCanvas, ModuleTransformerRadialGradientToCss, PatternTokenKind, RadialGradient, RadialGradientConfig, RadialGradientExtent, RadialGradientShape, RadialGradientSize, angleValueFromString, ceilTo, clamp, degToRad, floorTo, format, fromPercent, gradToRad, isAngle, isAngleUnit, isColorHint, isColorStop, isConfig, isGradient, isGradientColorSpace, isGradientHueInterpolation, isGradientPolarColorSpace, isPatternSyntaxValid, isPatternValid, isValid, matchExpression, normalizeAngleDeg, normalizeAngleRad, parse, parseStringToAbi, radToDeg, roundTo, splitTopLevelByWhitespace, toPercent, tokenizePattern, transformFrom, transformTo, truncTo, turnToRad, validate, validatePattern, validatePatternSemantic, validatePatternStructure, validatePatternSyntax };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { converter, formatRgb, parse as parse$1 } from "culori";
|
|
1
|
+
import { converter, fixupHueDecreasing, fixupHueIncreasing, fixupHueLonger, fixupHueShorter, formatRgb, interpolate, parse as parse$1 } from "culori";
|
|
2
2
|
//#region src/utils/math/base.ts
|
|
3
3
|
function roundTo(value, digits) {
|
|
4
4
|
const factor = 10 ** digits;
|
|
@@ -30,6 +30,26 @@ function fromPercent(value) {
|
|
|
30
30
|
function isAngleUnit(unit) {
|
|
31
31
|
return unit === "deg" || unit === "rad" || unit === "turn" || unit === "grad";
|
|
32
32
|
}
|
|
33
|
+
function isAngle(value) {
|
|
34
|
+
try {
|
|
35
|
+
return typeof angleValueFromString(value) === "number";
|
|
36
|
+
} catch (e) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function angleValueFromString(value) {
|
|
41
|
+
const match = value.match(/^([+-]?(?:\d+\.?\d*|\.\d+))(deg|rad|turn|grad)$/);
|
|
42
|
+
if (match === null) throw new Error(`Invalid angle value: "${value}"`);
|
|
43
|
+
if (!isAngleUnit(match[2])) throw new Error(`Unsupported angle unit: "${match[2]}"`);
|
|
44
|
+
if (!Number.isFinite(+match[1])) throw new SyntaxError(`Invalid angle value: "${match[1]}"`);
|
|
45
|
+
const angleValue = Number(match[1]);
|
|
46
|
+
switch (match[2]) {
|
|
47
|
+
case "deg": return degToRad(angleValue);
|
|
48
|
+
case "rad": return angleValue;
|
|
49
|
+
case "turn": return turnToRad(angleValue);
|
|
50
|
+
case "grad": return gradToRad(angleValue);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
33
53
|
function degToRad(value) {
|
|
34
54
|
return value * Math.PI / 180;
|
|
35
55
|
}
|
|
@@ -45,21 +65,9 @@ function gradToRad(value) {
|
|
|
45
65
|
function normalizeAngleDeg(value, digits = 3) {
|
|
46
66
|
return roundTo((value % 360 + 360) % 360, digits);
|
|
47
67
|
}
|
|
48
|
-
function normalizeAngleRad(value) {
|
|
68
|
+
function normalizeAngleRad(value, digits = 6) {
|
|
49
69
|
const tau = Math.PI * 2;
|
|
50
|
-
return (value % tau + tau) % tau;
|
|
51
|
-
}
|
|
52
|
-
function toAngleRad(value, unit) {
|
|
53
|
-
switch (unit) {
|
|
54
|
-
case "deg": return degToRad(value);
|
|
55
|
-
case "rad": return value;
|
|
56
|
-
case "turn": return turnToRad(value);
|
|
57
|
-
case "grad": return gradToRad(value);
|
|
58
|
-
default: throw new Error(`Unsupported angle unit: ${String(unit)}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function normalizeAngle(value, unit, digits = 6) {
|
|
62
|
-
return roundTo(normalizeAngleRad(toAngleRad(value, unit)), digits);
|
|
70
|
+
return roundTo((value % tau + tau) % tau, digits);
|
|
63
71
|
}
|
|
64
72
|
//#endregion
|
|
65
73
|
//#region src/dsl/types.ts
|
|
@@ -700,6 +708,44 @@ function splitTopLevelByWhitespace(value) {
|
|
|
700
708
|
return result;
|
|
701
709
|
}
|
|
702
710
|
//#endregion
|
|
711
|
+
//#region src/gradients/helpers.ts
|
|
712
|
+
const GRADIENT_COLOR_SPACE = [
|
|
713
|
+
"oklab",
|
|
714
|
+
"lch",
|
|
715
|
+
"oklch",
|
|
716
|
+
"hsl",
|
|
717
|
+
"hwb",
|
|
718
|
+
"lab",
|
|
719
|
+
"srgb",
|
|
720
|
+
"srgb-linear",
|
|
721
|
+
"xyz",
|
|
722
|
+
"display-p3",
|
|
723
|
+
"a98-rgb",
|
|
724
|
+
"prophoto-rgb",
|
|
725
|
+
"rec2020"
|
|
726
|
+
];
|
|
727
|
+
const GRADIENT_HUE_INTERPOLATIONS = [
|
|
728
|
+
"shorter",
|
|
729
|
+
"longer",
|
|
730
|
+
"increasing",
|
|
731
|
+
"decreasing"
|
|
732
|
+
];
|
|
733
|
+
const GRADIENT_POLAR_COLOR_SPACES = [
|
|
734
|
+
"hsl",
|
|
735
|
+
"hwb",
|
|
736
|
+
"lch",
|
|
737
|
+
"oklch"
|
|
738
|
+
];
|
|
739
|
+
function isGradientHueInterpolation(value) {
|
|
740
|
+
return GRADIENT_HUE_INTERPOLATIONS.includes(value);
|
|
741
|
+
}
|
|
742
|
+
function isGradientColorSpace(value) {
|
|
743
|
+
return GRADIENT_COLOR_SPACE.includes(value);
|
|
744
|
+
}
|
|
745
|
+
function isGradientPolarColorSpace(value) {
|
|
746
|
+
return GRADIENT_POLAR_COLOR_SPACES.includes(value);
|
|
747
|
+
}
|
|
748
|
+
//#endregion
|
|
703
749
|
//#region src/gradients/GradientBase.ts
|
|
704
750
|
var GradientBase = class {
|
|
705
751
|
_isRepeating;
|
|
@@ -725,8 +771,8 @@ var GradientBase = class {
|
|
|
725
771
|
return {
|
|
726
772
|
type: this.type,
|
|
727
773
|
isRepeating: this.isRepeating,
|
|
728
|
-
config: this.config,
|
|
729
|
-
stops: this.stops
|
|
774
|
+
config: this._cloneConfig(this.config),
|
|
775
|
+
stops: this._cloneStops(this.stops)
|
|
730
776
|
};
|
|
731
777
|
}
|
|
732
778
|
addStop(stop) {
|
|
@@ -799,12 +845,10 @@ var GradientBase = class {
|
|
|
799
845
|
}
|
|
800
846
|
}
|
|
801
847
|
_cloneStops(stops) {
|
|
802
|
-
return stops
|
|
848
|
+
return structuredClone(stops);
|
|
803
849
|
}
|
|
804
850
|
_cloneConfig(value) {
|
|
805
|
-
|
|
806
|
-
if (Array.isArray(value)) return [...value];
|
|
807
|
-
return { ...value };
|
|
851
|
+
return structuredClone(value);
|
|
808
852
|
}
|
|
809
853
|
_buildSerializedStopTokens() {
|
|
810
854
|
const result = [];
|
|
@@ -962,66 +1006,75 @@ var GradientBase = class {
|
|
|
962
1006
|
var LinearGradient = class LinearGradient extends GradientBase {
|
|
963
1007
|
type = "linear-gradient";
|
|
964
1008
|
constructor(config) {
|
|
1009
|
+
config.config.angle = normalizeAngleRad(config.config.angle);
|
|
1010
|
+
if (config.config.interpolation) {
|
|
1011
|
+
config.config.interpolation = LinearGradient._normalizeConfigInterpolation(config.config.interpolation);
|
|
1012
|
+
console.log(config);
|
|
1013
|
+
}
|
|
965
1014
|
super(config);
|
|
966
1015
|
}
|
|
967
1016
|
static normalizeConfig(value) {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (
|
|
972
|
-
|
|
973
|
-
if (directions.length === 0 || directions.length > 2) throw new SyntaxError("Linear gradient keyword direction must contain one or two direction tokens");
|
|
974
|
-
const allowed = new Set([
|
|
975
|
-
"top",
|
|
976
|
-
"right",
|
|
977
|
-
"bottom",
|
|
978
|
-
"left"
|
|
979
|
-
]);
|
|
980
|
-
for (const direction of directions) if (!allowed.has(direction)) throw new SyntaxError(`Invalid linear gradient direction token: "${direction}"`);
|
|
981
|
-
if (new Set(directions).size !== directions.length) throw new SyntaxError("Linear gradient keyword direction cannot contain duplicate tokens");
|
|
982
|
-
const hasTop = directions.includes("top");
|
|
983
|
-
const hasRight = directions.includes("right");
|
|
984
|
-
const hasBottom = directions.includes("bottom");
|
|
985
|
-
const hasLeft = directions.includes("left");
|
|
986
|
-
if (hasTop && hasBottom || hasLeft && hasRight) throw new SyntaxError("Linear gradient keyword direction contains conflicting tokens");
|
|
987
|
-
if (hasTop && hasLeft) return { angle: degToRad(315) };
|
|
988
|
-
else if (hasTop && hasRight) return { angle: degToRad(45) };
|
|
989
|
-
else if (hasBottom && hasLeft) return { angle: degToRad(225) };
|
|
990
|
-
else if (hasBottom && hasRight) return { angle: degToRad(135) };
|
|
991
|
-
else if (hasTop) return { angle: degToRad(0) };
|
|
992
|
-
else if (hasRight) return { angle: degToRad(90) };
|
|
993
|
-
else if (hasBottom) return { angle: degToRad(180) };
|
|
994
|
-
else if (hasLeft) return { angle: degToRad(270) };
|
|
995
|
-
throw new SyntaxError(`Unsupported linear gradient keyword direction: "${value}"`);
|
|
1017
|
+
const tokenizedValue = LinearGradient._tokenizeConfigInput(value);
|
|
1018
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1019
|
+
for (const token of tokenizedValue) {
|
|
1020
|
+
if (seen.has(token.type)) throw new SyntaxError(`Duplicate linear gradient config token: "${token.type}"`);
|
|
1021
|
+
seen.add(token.type);
|
|
996
1022
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1023
|
+
const angleToken = tokenizedValue.find((token) => token.type === "angle");
|
|
1024
|
+
const colorSpaceToken = tokenizedValue.find((token) => token.type === "colorSpace");
|
|
1025
|
+
const hueToken = tokenizedValue.find((token) => token.type === "hue");
|
|
1026
|
+
const assembledConfig = {
|
|
1027
|
+
angle: 3.141593,
|
|
1028
|
+
interpolation: {
|
|
1029
|
+
hue: "shorter",
|
|
1030
|
+
colorSpace: "oklab"
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
if (angleToken) {
|
|
1034
|
+
const value = angleToken.value;
|
|
1035
|
+
if (value.startsWith("to ")) {
|
|
1036
|
+
const tokens = value.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
1037
|
+
if (tokens.length === 0) throw new SyntaxError("Linear gradient angle keyword cannot be empty");
|
|
1038
|
+
if (tokens[0] !== "to") throw new SyntaxError("Linear gradient keyword direction must start with \"to\"");
|
|
1039
|
+
const directions = tokens.slice(1);
|
|
1040
|
+
if (directions.length === 0 || directions.length > 2) throw new SyntaxError("Linear gradient keyword direction must contain one or two direction tokens");
|
|
1041
|
+
const allowed = new Set([
|
|
1042
|
+
"top",
|
|
1043
|
+
"right",
|
|
1044
|
+
"bottom",
|
|
1045
|
+
"left"
|
|
1046
|
+
]);
|
|
1047
|
+
for (const direction of directions) if (!allowed.has(direction)) throw new SyntaxError(`Invalid linear gradient direction token: "${direction}"`);
|
|
1048
|
+
if (new Set(directions).size !== directions.length) throw new SyntaxError("Linear gradient keyword direction cannot contain duplicate tokens");
|
|
1049
|
+
const hasTop = directions.includes("top");
|
|
1050
|
+
const hasRight = directions.includes("right");
|
|
1051
|
+
const hasBottom = directions.includes("bottom");
|
|
1052
|
+
const hasLeft = directions.includes("left");
|
|
1053
|
+
if (hasTop && hasBottom || hasLeft && hasRight) throw new SyntaxError("Linear gradient keyword direction contains conflicting tokens");
|
|
1054
|
+
if (hasTop && hasLeft) assembledConfig.angle = degToRad(315);
|
|
1055
|
+
else if (hasTop && hasRight) assembledConfig.angle = degToRad(45);
|
|
1056
|
+
else if (hasBottom && hasLeft) assembledConfig.angle = degToRad(225);
|
|
1057
|
+
else if (hasBottom && hasRight) assembledConfig.angle = degToRad(135);
|
|
1058
|
+
else if (hasTop) assembledConfig.angle = degToRad(0);
|
|
1059
|
+
else if (hasRight) assembledConfig.angle = degToRad(90);
|
|
1060
|
+
else if (hasBottom) assembledConfig.angle = degToRad(180);
|
|
1061
|
+
else if (hasLeft) assembledConfig.angle = degToRad(270);
|
|
1062
|
+
else throw new SyntaxError(`Unsupported linear gradient keyword direction: "${value}"`);
|
|
1063
|
+
} else assembledConfig.angle = normalizeAngleRad(angleValueFromString(value));
|
|
1003
1064
|
}
|
|
1065
|
+
if (colorSpaceToken) assembledConfig.interpolation.colorSpace = colorSpaceToken.value;
|
|
1066
|
+
if (hueToken) assembledConfig.interpolation.hue = hueToken.value;
|
|
1067
|
+
return assembledConfig;
|
|
1004
1068
|
}
|
|
1005
1069
|
static fromString(input) {
|
|
1006
1070
|
return LinearGradient.fromAbi(parseStringToAbi(input));
|
|
1007
1071
|
}
|
|
1008
1072
|
static fromAbi(abi) {
|
|
1009
|
-
let config = { angle:
|
|
1073
|
+
let config = { angle: 3.141592 };
|
|
1010
1074
|
if (abi.inputs[0].type === "config") {
|
|
1011
1075
|
const inputValue = abi.inputs[0].value.trim().toLowerCase();
|
|
1012
1076
|
if (inputValue.length === 0) throw new SyntaxError("Linear gradient config cannot be empty");
|
|
1013
|
-
|
|
1014
|
-
else {
|
|
1015
|
-
const match = inputValue.match(/^([+-]?(?:\d+\.?\d*|\.\d+))(deg|rad|turn|grad)$/i);
|
|
1016
|
-
if (match === null) throw new SyntaxError(`Invalid linear gradient angle: "${inputValue}"`);
|
|
1017
|
-
const rawValue = Number(match[1]);
|
|
1018
|
-
const unit = match[2].toLowerCase();
|
|
1019
|
-
if (!Number.isFinite(rawValue)) throw new SyntaxError(`Invalid linear gradient angle value: "${inputValue}"`);
|
|
1020
|
-
config = LinearGradient.normalizeConfig({
|
|
1021
|
-
value: rawValue,
|
|
1022
|
-
unit
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1077
|
+
config = LinearGradient.normalizeConfig(inputValue);
|
|
1025
1078
|
}
|
|
1026
1079
|
const inputsWithoutConfig = abi.inputs[0]?.type === "config" ? abi.inputs.slice(1) : abi.inputs;
|
|
1027
1080
|
const stops = LinearGradient._normalizeAbiInputsToStops(inputsWithoutConfig);
|
|
@@ -1035,9 +1088,96 @@ var LinearGradient = class LinearGradient extends GradientBase {
|
|
|
1035
1088
|
return new LinearGradient(this.toJSON());
|
|
1036
1089
|
}
|
|
1037
1090
|
toString() {
|
|
1038
|
-
return `${this.isRepeating ? `repeating-${this.type}` : this.type}(${[this.
|
|
1091
|
+
return `${this.isRepeating ? `repeating-${this.type}` : this.type}(${[this._parseConfigToString(this.config), ...this._serializeStopsCompact()].filter(Boolean).join(", ")})`;
|
|
1039
1092
|
}
|
|
1040
1093
|
_validateConfig(_) {}
|
|
1094
|
+
static _normalizeConfigInterpolation(value) {
|
|
1095
|
+
const { colorSpace, hue } = value;
|
|
1096
|
+
if (hue === void 0) return { colorSpace };
|
|
1097
|
+
if (!isGradientPolarColorSpace(colorSpace)) return { colorSpace };
|
|
1098
|
+
return {
|
|
1099
|
+
colorSpace,
|
|
1100
|
+
hue
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
_parseConfigToString(config) {
|
|
1104
|
+
const { angle, interpolation } = config;
|
|
1105
|
+
const configParts = [];
|
|
1106
|
+
const angleString = this._parseAngleToString(angle);
|
|
1107
|
+
if (angleString.length > 0) configParts.push(angleString);
|
|
1108
|
+
if (interpolation !== void 0) configParts.push(this._parseInterpolationToString(interpolation));
|
|
1109
|
+
return configParts.join(" ");
|
|
1110
|
+
}
|
|
1111
|
+
_parseAngleToString(angle) {
|
|
1112
|
+
const angleDeg = normalizeAngleDeg(radToDeg(angle), 3);
|
|
1113
|
+
switch (angleDeg) {
|
|
1114
|
+
case 0: return "to top";
|
|
1115
|
+
case 45: return "to top right";
|
|
1116
|
+
case 90: return "to right";
|
|
1117
|
+
case 135: return "to bottom right";
|
|
1118
|
+
case 180: return "";
|
|
1119
|
+
case 225: return "to bottom left";
|
|
1120
|
+
case 270: return "to left";
|
|
1121
|
+
case 315: return "to top left";
|
|
1122
|
+
default: return `${angleDeg}deg`;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
_parseInterpolationToString(interpolation) {
|
|
1126
|
+
const { colorSpace, hue } = interpolation;
|
|
1127
|
+
if (hue === void 0) return `in ${colorSpace}`;
|
|
1128
|
+
return `in ${colorSpace} ${hue} hue`;
|
|
1129
|
+
}
|
|
1130
|
+
static _tokenizeConfigInput(value) {
|
|
1131
|
+
const inputValue = value.trim().toLowerCase();
|
|
1132
|
+
if (inputValue.length === 0) throw new SyntaxError("Linear gradient config cannot be empty");
|
|
1133
|
+
const parts = inputValue.split(/\s+/);
|
|
1134
|
+
const tokens = [];
|
|
1135
|
+
for (let index = 0; index < parts.length; index += 1) {
|
|
1136
|
+
const part = parts[index];
|
|
1137
|
+
if (part === "in") {
|
|
1138
|
+
const colorSpace = parts[index + 1];
|
|
1139
|
+
if (colorSpace === void 0 || !isGradientColorSpace(colorSpace)) throw new SyntaxError(`Expected color space after "in"`);
|
|
1140
|
+
tokens.push({
|
|
1141
|
+
type: "colorSpace",
|
|
1142
|
+
value: colorSpace
|
|
1143
|
+
});
|
|
1144
|
+
index += 1;
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
if (isAngle(part)) {
|
|
1148
|
+
tokens.push({
|
|
1149
|
+
type: "angle",
|
|
1150
|
+
value: part
|
|
1151
|
+
});
|
|
1152
|
+
continue;
|
|
1153
|
+
}
|
|
1154
|
+
if (part === "to") {
|
|
1155
|
+
const directionParts = [];
|
|
1156
|
+
const firstDirection = parts[index + 1];
|
|
1157
|
+
const secondDirection = parts[index + 2];
|
|
1158
|
+
if (firstDirection !== void 0) directionParts.push(firstDirection);
|
|
1159
|
+
if (secondDirection === "left" || secondDirection === "right") directionParts.push(secondDirection);
|
|
1160
|
+
const direction = `to ${directionParts.join(" ")}`;
|
|
1161
|
+
tokens.push({
|
|
1162
|
+
type: "angle",
|
|
1163
|
+
value: direction
|
|
1164
|
+
});
|
|
1165
|
+
index += directionParts.length;
|
|
1166
|
+
continue;
|
|
1167
|
+
}
|
|
1168
|
+
if (isGradientHueInterpolation(part)) {
|
|
1169
|
+
if (parts[index + 1] !== "hue") throw new SyntaxError(`Expected "hue" after "${part}"`);
|
|
1170
|
+
tokens.push({
|
|
1171
|
+
type: "hue",
|
|
1172
|
+
value: part
|
|
1173
|
+
});
|
|
1174
|
+
index += 1;
|
|
1175
|
+
continue;
|
|
1176
|
+
}
|
|
1177
|
+
throw new SyntaxError(`Unknown linear gradient config token: "${part}"`);
|
|
1178
|
+
}
|
|
1179
|
+
return tokens;
|
|
1180
|
+
}
|
|
1041
1181
|
};
|
|
1042
1182
|
//#endregion
|
|
1043
1183
|
//#region src/gradients/RadialGradient.ts
|
|
@@ -1332,14 +1472,163 @@ var ModuleTransformerConicGradientToCss = class {
|
|
|
1332
1472
|
}
|
|
1333
1473
|
};
|
|
1334
1474
|
//#endregion
|
|
1475
|
+
//#region src/gradient-transformer/modules/helpers/expand-repeating-stops.ts
|
|
1476
|
+
function positiveModulo(value, modulo) {
|
|
1477
|
+
return (value % modulo + modulo) % modulo;
|
|
1478
|
+
}
|
|
1479
|
+
function sampleColorAtPosition(stops, position) {
|
|
1480
|
+
const colorStops = stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
1481
|
+
if (colorStops.length === 0) throw new Error("Cannot sample color from empty stops.");
|
|
1482
|
+
if (position <= colorStops[0].position) return colorStops[0].value;
|
|
1483
|
+
const lastStop = colorStops[colorStops.length - 1];
|
|
1484
|
+
if (position >= lastStop.position) return lastStop.value;
|
|
1485
|
+
for (let index = 0; index < colorStops.length - 1; index += 1) {
|
|
1486
|
+
const current = colorStops[index];
|
|
1487
|
+
const next = colorStops[index + 1];
|
|
1488
|
+
if (position >= current.position && position <= next.position) {
|
|
1489
|
+
const range = next.position - current.position || 1;
|
|
1490
|
+
const localT = (position - current.position) / range;
|
|
1491
|
+
return formatRgb(interpolate([current.value, next.value], "rgb")(localT));
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
return lastStop.value;
|
|
1495
|
+
}
|
|
1496
|
+
function sampleRepeatingColorAtPosition(stops, position, firstPosition, period) {
|
|
1497
|
+
return sampleColorAtPosition(stops, firstPosition + positiveModulo(position - firstPosition, period));
|
|
1498
|
+
}
|
|
1499
|
+
function expandRepeatingStops(stops) {
|
|
1500
|
+
const colorStops = stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
1501
|
+
if (colorStops.length < 2) return colorStops;
|
|
1502
|
+
const firstPosition = colorStops[0].position;
|
|
1503
|
+
const period = colorStops[colorStops.length - 1].position - firstPosition;
|
|
1504
|
+
if (period <= 0) return colorStops;
|
|
1505
|
+
const result = [];
|
|
1506
|
+
let order = 0;
|
|
1507
|
+
result.push({
|
|
1508
|
+
type: "color-stop",
|
|
1509
|
+
value: sampleRepeatingColorAtPosition(colorStops, 0, firstPosition, period),
|
|
1510
|
+
position: 0,
|
|
1511
|
+
_order: order
|
|
1512
|
+
});
|
|
1513
|
+
order += 1;
|
|
1514
|
+
const startRepeat = Math.floor((0 - firstPosition) / period) - 1;
|
|
1515
|
+
const endRepeat = Math.ceil((1 - firstPosition) / period) + 1;
|
|
1516
|
+
for (let repeatIndex = startRepeat; repeatIndex <= endRepeat; repeatIndex += 1) {
|
|
1517
|
+
const offset = repeatIndex * period;
|
|
1518
|
+
for (const stop of colorStops) {
|
|
1519
|
+
const position = stop.position + offset;
|
|
1520
|
+
if (position <= 0 || position >= 1) continue;
|
|
1521
|
+
result.push({
|
|
1522
|
+
...stop,
|
|
1523
|
+
position,
|
|
1524
|
+
_order: order
|
|
1525
|
+
});
|
|
1526
|
+
order += 1;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
result.push({
|
|
1530
|
+
type: "color-stop",
|
|
1531
|
+
value: sampleRepeatingColorAtPosition(colorStops, 1, firstPosition, period),
|
|
1532
|
+
position: 1,
|
|
1533
|
+
_order: order
|
|
1534
|
+
});
|
|
1535
|
+
return result.sort((a, b) => {
|
|
1536
|
+
if (a.position === b.position) return a._order - b._order;
|
|
1537
|
+
return a.position - b.position;
|
|
1538
|
+
}).map(({ _order, ...stop }) => stop);
|
|
1539
|
+
}
|
|
1540
|
+
//#endregion
|
|
1541
|
+
//#region src/gradient-transformer/modules/helpers/resolve-renderable-linear-gradient-stops.ts
|
|
1542
|
+
function getHueFixup(hue) {
|
|
1543
|
+
switch (hue) {
|
|
1544
|
+
case "longer": return fixupHueLonger;
|
|
1545
|
+
case "increasing": return fixupHueIncreasing;
|
|
1546
|
+
case "decreasing": return fixupHueDecreasing;
|
|
1547
|
+
default: return fixupHueShorter;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
function colorSpaceToCuloriMode(colorSpace) {
|
|
1551
|
+
switch (colorSpace) {
|
|
1552
|
+
case "a98-rgb": return "a98";
|
|
1553
|
+
case "display-p3": return "p3";
|
|
1554
|
+
case "prophoto-rgb": return "prophoto";
|
|
1555
|
+
case "xyz": return "xyz65";
|
|
1556
|
+
case "srgb":
|
|
1557
|
+
case "srgb-linear": return "rgb";
|
|
1558
|
+
default: return colorSpace;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
function createCuloriInterpolationOverrides(interpolation) {
|
|
1562
|
+
if (interpolation.hue === void 0) return;
|
|
1563
|
+
return { h: { fixup: getHueFixup(interpolation.hue) } };
|
|
1564
|
+
}
|
|
1565
|
+
function getColorStopsWithPositions(stops) {
|
|
1566
|
+
const colorStops = stops.filter((stop) => stop.type === "color-stop");
|
|
1567
|
+
if (colorStops.length === 0) return [];
|
|
1568
|
+
if (colorStops.length === 1) return [{
|
|
1569
|
+
...colorStops[0],
|
|
1570
|
+
position: colorStops[0].position ?? 0
|
|
1571
|
+
}];
|
|
1572
|
+
return colorStops.map((stop, index) => {
|
|
1573
|
+
if (stop.position != null) return stop;
|
|
1574
|
+
if (index === 0) return {
|
|
1575
|
+
...stop,
|
|
1576
|
+
position: 0
|
|
1577
|
+
};
|
|
1578
|
+
if (index === colorStops.length - 1) return {
|
|
1579
|
+
...stop,
|
|
1580
|
+
position: 1
|
|
1581
|
+
};
|
|
1582
|
+
return {
|
|
1583
|
+
...stop,
|
|
1584
|
+
position: index / (colorStops.length - 1)
|
|
1585
|
+
};
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
function formatColorForCanvas(input) {
|
|
1589
|
+
const color = toRgb$4(input);
|
|
1590
|
+
if (!color) throw new Error("Failed to convert interpolated color to rgb.");
|
|
1591
|
+
return formatRgb(color);
|
|
1592
|
+
}
|
|
1593
|
+
const DEFAULT_SAMPLE_COUNT = 64;
|
|
1594
|
+
const toRgb$4 = converter("rgb");
|
|
1595
|
+
function resolveRenderableLinearGradientStops(gradient, sampleCount = DEFAULT_SAMPLE_COUNT) {
|
|
1596
|
+
const colorStops = getColorStopsWithPositions(gradient.stops);
|
|
1597
|
+
const interpolation = gradient.config.interpolation;
|
|
1598
|
+
if (colorStops.length < 2) return colorStops;
|
|
1599
|
+
if (interpolation === void 0) return gradient.isRepeating ? expandRepeatingStops(colorStops) : colorStops;
|
|
1600
|
+
const sampledStops = [];
|
|
1601
|
+
const mode = colorSpaceToCuloriMode(interpolation.colorSpace);
|
|
1602
|
+
const overrides = createCuloriInterpolationOverrides(interpolation);
|
|
1603
|
+
for (let index = 0; index < colorStops.length - 1; index += 1) {
|
|
1604
|
+
const current = colorStops[index];
|
|
1605
|
+
const next = colorStops[index + 1];
|
|
1606
|
+
const startPosition = current.position;
|
|
1607
|
+
const endPosition = next.position;
|
|
1608
|
+
const colorInterpolator = interpolate([current.value, next.value], mode, overrides);
|
|
1609
|
+
for (let sampleIndex = 0; sampleIndex <= sampleCount; sampleIndex += 1) {
|
|
1610
|
+
if (index > 0 && sampleIndex === 0) continue;
|
|
1611
|
+
const localT = sampleIndex / sampleCount;
|
|
1612
|
+
const position = startPosition + (endPosition - startPosition) * localT;
|
|
1613
|
+
const color = colorInterpolator(localT);
|
|
1614
|
+
sampledStops.push({
|
|
1615
|
+
type: "color-stop",
|
|
1616
|
+
value: formatColorForCanvas(color),
|
|
1617
|
+
position
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
return gradient.isRepeating ? expandRepeatingStops(sampledStops) : sampledStops;
|
|
1622
|
+
}
|
|
1623
|
+
//#endregion
|
|
1335
1624
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerLinearGradientToCanvas.ts
|
|
1336
|
-
const toRgb$
|
|
1625
|
+
const toRgb$3 = converter("rgb");
|
|
1337
1626
|
function toCanvasColor$1(input) {
|
|
1338
|
-
const color = toRgb$
|
|
1627
|
+
const color = toRgb$3(input);
|
|
1339
1628
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
1340
1629
|
return formatRgb(color);
|
|
1341
1630
|
}
|
|
1342
|
-
function getStopRange$
|
|
1631
|
+
function getStopRange$2(stops) {
|
|
1343
1632
|
const colorStops = stops.filter((stop) => stop.type === "color-stop" && stop.position != null);
|
|
1344
1633
|
if (!colorStops.length) return {
|
|
1345
1634
|
min: 0,
|
|
@@ -1352,7 +1641,7 @@ function getStopRange$1(stops) {
|
|
|
1352
1641
|
stops: colorStops
|
|
1353
1642
|
};
|
|
1354
1643
|
}
|
|
1355
|
-
function normalizeStops$
|
|
1644
|
+
function normalizeStops$2(stops, min, max) {
|
|
1356
1645
|
const range = max - min || 1;
|
|
1357
1646
|
return stops.filter((stop) => stop.type === "color-stop" && stop.position != null).map((stop) => ({
|
|
1358
1647
|
...stop,
|
|
@@ -1360,38 +1649,37 @@ function normalizeStops$1(stops, min, max) {
|
|
|
1360
1649
|
}));
|
|
1361
1650
|
}
|
|
1362
1651
|
var ModuleTransformerLinearGradientToCanvas = class {
|
|
1363
|
-
target = "canvas";
|
|
1652
|
+
target = "canvas-2d";
|
|
1364
1653
|
gradientType = "linear-gradient";
|
|
1365
1654
|
to(input) {
|
|
1366
1655
|
const gradient = input;
|
|
1367
1656
|
return { draw: (ctx, width, height) => {
|
|
1368
1657
|
const angle = gradient.config.angle;
|
|
1369
|
-
const
|
|
1370
|
-
const
|
|
1371
|
-
const
|
|
1372
|
-
const
|
|
1373
|
-
const
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
const { min, max, stops } = getStopRange$
|
|
1379
|
-
let startX = x0;
|
|
1380
|
-
let startY = y0;
|
|
1381
|
-
let endX = x1;
|
|
1382
|
-
let endY = y1;
|
|
1658
|
+
const dirX = Math.sin(angle);
|
|
1659
|
+
const dirY = -Math.cos(angle);
|
|
1660
|
+
const centerX = width / 2;
|
|
1661
|
+
const centerY = height / 2;
|
|
1662
|
+
const lineLength = Math.abs(width * dirX) + Math.abs(height * dirY);
|
|
1663
|
+
let startX = centerX - dirX * lineLength / 2;
|
|
1664
|
+
let startY = centerY - dirY * lineLength / 2;
|
|
1665
|
+
let endX = centerX + dirX * lineLength / 2;
|
|
1666
|
+
let endY = centerY + dirY * lineLength / 2;
|
|
1667
|
+
const { min, max, stops } = getStopRange$2(resolveRenderableLinearGradientStops(gradient));
|
|
1383
1668
|
let normalizedStops = stops;
|
|
1384
1669
|
if (min < 0 || max > 1) {
|
|
1385
|
-
const vx =
|
|
1386
|
-
const vy =
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1670
|
+
const vx = endX - startX;
|
|
1671
|
+
const vy = endY - startY;
|
|
1672
|
+
const baseStartX = startX;
|
|
1673
|
+
const baseStartY = startY;
|
|
1674
|
+
startX = baseStartX + vx * min;
|
|
1675
|
+
startY = baseStartY + vy * min;
|
|
1676
|
+
endX = baseStartX + vx * max;
|
|
1677
|
+
endY = baseStartY + vy * max;
|
|
1678
|
+
normalizedStops = normalizeStops$2(stops, min, max);
|
|
1392
1679
|
}
|
|
1393
1680
|
const canvasGradient = ctx.createLinearGradient(startX, startY, endX, endY);
|
|
1394
1681
|
for (const stop of normalizedStops) canvasGradient.addColorStop(stop.position, toCanvasColor$1(stop.value));
|
|
1682
|
+
ctx.clearRect(0, 0, width, height);
|
|
1395
1683
|
ctx.fillStyle = canvasGradient;
|
|
1396
1684
|
ctx.fillRect(0, 0, width, height);
|
|
1397
1685
|
} };
|
|
@@ -1399,13 +1687,13 @@ var ModuleTransformerLinearGradientToCanvas = class {
|
|
|
1399
1687
|
};
|
|
1400
1688
|
//#endregion
|
|
1401
1689
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerRadialGradientToCanvas.ts
|
|
1402
|
-
const toRgb$
|
|
1690
|
+
const toRgb$2 = converter("rgb");
|
|
1403
1691
|
function toCanvasColor(input) {
|
|
1404
|
-
const color = toRgb$
|
|
1692
|
+
const color = toRgb$2(input);
|
|
1405
1693
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
1406
1694
|
return formatRgb(color);
|
|
1407
1695
|
}
|
|
1408
|
-
function getStopRange(stops) {
|
|
1696
|
+
function getStopRange$1(stops) {
|
|
1409
1697
|
const colorStops = stops.filter((stop) => stop.type === "color-stop" && stop.position != null);
|
|
1410
1698
|
if (!colorStops.length) return {
|
|
1411
1699
|
min: 0,
|
|
@@ -1418,7 +1706,7 @@ function getStopRange(stops) {
|
|
|
1418
1706
|
stops: colorStops
|
|
1419
1707
|
};
|
|
1420
1708
|
}
|
|
1421
|
-
function normalizeStops(stops, min, max) {
|
|
1709
|
+
function normalizeStops$1(stops, min, max) {
|
|
1422
1710
|
const range = max - min || 1;
|
|
1423
1711
|
return stops.map((stop) => ({
|
|
1424
1712
|
...stop,
|
|
@@ -1426,7 +1714,7 @@ function normalizeStops(stops, min, max) {
|
|
|
1426
1714
|
}));
|
|
1427
1715
|
}
|
|
1428
1716
|
var ModuleTransformerRadialGradientToCanvas = class {
|
|
1429
|
-
target = "canvas";
|
|
1717
|
+
target = "canvas-2d";
|
|
1430
1718
|
gradientType = "radial-gradient";
|
|
1431
1719
|
to(input) {
|
|
1432
1720
|
const gradient = input;
|
|
@@ -1441,17 +1729,17 @@ var ModuleTransformerRadialGradientToCanvas = class {
|
|
|
1441
1729
|
const dx = Math.max(x, width - x);
|
|
1442
1730
|
const dy = Math.max(y, height - y);
|
|
1443
1731
|
const radius = Math.sqrt(dx * dx + dy * dy);
|
|
1444
|
-
const { min, max, stops } = getStopRange(gradient.stops);
|
|
1732
|
+
const { min, max, stops } = getStopRange$1(gradient.stops);
|
|
1445
1733
|
let innerRadius = 0;
|
|
1446
1734
|
let outerRadius = radius;
|
|
1447
1735
|
let normalizedStops = stops;
|
|
1448
1736
|
if (min >= 0 && (min < 0 || max > 1)) {
|
|
1449
1737
|
innerRadius = radius * min;
|
|
1450
1738
|
outerRadius = radius * max;
|
|
1451
|
-
normalizedStops = normalizeStops(stops, min, max);
|
|
1739
|
+
normalizedStops = normalizeStops$1(stops, min, max);
|
|
1452
1740
|
} else if (max > 1) {
|
|
1453
1741
|
outerRadius = radius * max;
|
|
1454
|
-
normalizedStops = normalizeStops(stops, min, max);
|
|
1742
|
+
normalizedStops = normalizeStops$1(stops, min, max);
|
|
1455
1743
|
}
|
|
1456
1744
|
const g = ctx.createRadialGradient(x, y, innerRadius, x, y, outerRadius);
|
|
1457
1745
|
for (const stop of normalizedStops) g.addColorStop(stop.position, toCanvasColor(stop.value));
|
|
@@ -1467,9 +1755,9 @@ var ModuleTransformerRadialGradientToCanvas = class {
|
|
|
1467
1755
|
};
|
|
1468
1756
|
//#endregion
|
|
1469
1757
|
//#region src/gradient-transformer/modules/canvas/ModuleTransformerConicGradientToCanvas.ts
|
|
1470
|
-
const toRgb = converter("rgb");
|
|
1758
|
+
const toRgb$1 = converter("rgb");
|
|
1471
1759
|
var ModuleTransformerConicGradientToCanvas = class {
|
|
1472
|
-
target = "canvas";
|
|
1760
|
+
target = "canvas-2d";
|
|
1473
1761
|
gradientType = "conic-gradient";
|
|
1474
1762
|
to(input) {
|
|
1475
1763
|
const gradient = input;
|
|
@@ -1566,7 +1854,7 @@ var ModuleTransformerConicGradientToCanvas = class {
|
|
|
1566
1854
|
};
|
|
1567
1855
|
}
|
|
1568
1856
|
_parseColor(input) {
|
|
1569
|
-
const color = toRgb(input);
|
|
1857
|
+
const color = toRgb$1(input);
|
|
1570
1858
|
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
1571
1859
|
return {
|
|
1572
1860
|
r: Math.round((color.r ?? 0) * 255),
|
|
@@ -1580,6 +1868,243 @@ var ModuleTransformerConicGradientToCanvas = class {
|
|
|
1580
1868
|
}
|
|
1581
1869
|
};
|
|
1582
1870
|
//#endregion
|
|
1871
|
+
//#region src/gradient-transformer/modules/webgl/ModuleTransformerLinearGradientToWebgl.ts
|
|
1872
|
+
const toRgb = converter("rgb");
|
|
1873
|
+
const MAX_STOPS = 128;
|
|
1874
|
+
function toWebGLColor(input) {
|
|
1875
|
+
const color = toRgb(input);
|
|
1876
|
+
if (!color) throw new Error(`Failed to convert color: ${input}`);
|
|
1877
|
+
return [
|
|
1878
|
+
color.r ?? 0,
|
|
1879
|
+
color.g ?? 0,
|
|
1880
|
+
color.b ?? 0,
|
|
1881
|
+
color.alpha ?? 1
|
|
1882
|
+
];
|
|
1883
|
+
}
|
|
1884
|
+
function getStopRange(stops) {
|
|
1885
|
+
const colorStops = stops.filter((stop) => stop.type === "color-stop" && stop.position != null);
|
|
1886
|
+
if (!colorStops.length) return {
|
|
1887
|
+
min: 0,
|
|
1888
|
+
max: 1,
|
|
1889
|
+
stops: []
|
|
1890
|
+
};
|
|
1891
|
+
return {
|
|
1892
|
+
min: Math.min(...colorStops.map((stop) => stop.position)),
|
|
1893
|
+
max: Math.max(...colorStops.map((stop) => stop.position)),
|
|
1894
|
+
stops: colorStops
|
|
1895
|
+
};
|
|
1896
|
+
}
|
|
1897
|
+
function normalizeStops(stops, min, max) {
|
|
1898
|
+
const range = max - min || 1;
|
|
1899
|
+
return stops.filter((stop) => stop.type === "color-stop" && stop.position != null).map((stop) => ({
|
|
1900
|
+
...stop,
|
|
1901
|
+
position: (stop.position - min) / range
|
|
1902
|
+
}));
|
|
1903
|
+
}
|
|
1904
|
+
function createShader(gl, type, source) {
|
|
1905
|
+
const shader = gl.createShader(type);
|
|
1906
|
+
if (!shader) throw new Error("Failed to create WebGL shader.");
|
|
1907
|
+
gl.shaderSource(shader, source);
|
|
1908
|
+
gl.compileShader(shader);
|
|
1909
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
1910
|
+
const error = gl.getShaderInfoLog(shader);
|
|
1911
|
+
gl.deleteShader(shader);
|
|
1912
|
+
throw new Error(`WebGL shader compile error: ${error}`);
|
|
1913
|
+
}
|
|
1914
|
+
return shader;
|
|
1915
|
+
}
|
|
1916
|
+
function createProgram(gl, vertexSource, fragmentSource) {
|
|
1917
|
+
const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexSource);
|
|
1918
|
+
const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentSource);
|
|
1919
|
+
const program = gl.createProgram();
|
|
1920
|
+
if (!program) throw new Error("Failed to create WebGL program.");
|
|
1921
|
+
gl.attachShader(program, vertexShader);
|
|
1922
|
+
gl.attachShader(program, fragmentShader);
|
|
1923
|
+
gl.linkProgram(program);
|
|
1924
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
1925
|
+
const error = gl.getProgramInfoLog(program);
|
|
1926
|
+
gl.deleteProgram(program);
|
|
1927
|
+
throw new Error(`WebGL program link error: ${error}`);
|
|
1928
|
+
}
|
|
1929
|
+
return program;
|
|
1930
|
+
}
|
|
1931
|
+
function getColorStopCount(stops) {
|
|
1932
|
+
return stops.filter((stop) => stop.type === "color-stop").length;
|
|
1933
|
+
}
|
|
1934
|
+
function getWebGLSampleCount(gradient, maxStops) {
|
|
1935
|
+
const colorStopCount = getColorStopCount(gradient.stops);
|
|
1936
|
+
const segmentCount = Math.max(1, colorStopCount - 1);
|
|
1937
|
+
return Math.max(2, Math.floor((maxStops - 1) / segmentCount));
|
|
1938
|
+
}
|
|
1939
|
+
function getColorAtPosition(stops, position) {
|
|
1940
|
+
const colorStops = stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
1941
|
+
if (colorStops.length === 0) throw new Error("Cannot sample color from empty gradient stops.");
|
|
1942
|
+
if (position <= colorStops[0].position) return colorStops[0].value;
|
|
1943
|
+
const lastStop = colorStops[colorStops.length - 1];
|
|
1944
|
+
if (position >= lastStop.position) return lastStop.value;
|
|
1945
|
+
for (let index = 0; index < colorStops.length - 1; index += 1) {
|
|
1946
|
+
const current = colorStops[index];
|
|
1947
|
+
const next = colorStops[index + 1];
|
|
1948
|
+
if (position >= current.position && position <= next.position) {
|
|
1949
|
+
const range = next.position - current.position || 1;
|
|
1950
|
+
const localT = (position - current.position) / range;
|
|
1951
|
+
return formatRgb(interpolate([current.value, next.value], "rgb")(localT));
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
return lastStop.value;
|
|
1955
|
+
}
|
|
1956
|
+
function fitStopsToWebGLLimit(stops, maxStops) {
|
|
1957
|
+
const colorStops = stops.filter((stop) => stop.type === "color-stop" && stop.position != null).sort((a, b) => a.position - b.position);
|
|
1958
|
+
if (colorStops.length <= maxStops) return colorStops;
|
|
1959
|
+
const sampledStops = [];
|
|
1960
|
+
for (let index = 0; index < maxStops; index += 1) {
|
|
1961
|
+
const position = index / (maxStops - 1);
|
|
1962
|
+
sampledStops.push({
|
|
1963
|
+
type: "color-stop",
|
|
1964
|
+
value: getColorAtPosition(colorStops, position),
|
|
1965
|
+
position
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
return sampledStops;
|
|
1969
|
+
}
|
|
1970
|
+
var ModuleTransformerLinearGradientToCanvasWebGL = class {
|
|
1971
|
+
target = "canvas-webgl";
|
|
1972
|
+
gradientType = "linear-gradient";
|
|
1973
|
+
to(input) {
|
|
1974
|
+
const gradient = input;
|
|
1975
|
+
return { draw: (canvas, width, height) => {
|
|
1976
|
+
const gl = canvas.getContext("webgl");
|
|
1977
|
+
if (!gl) throw new Error("WebGL is not supported.");
|
|
1978
|
+
canvas.width = width;
|
|
1979
|
+
canvas.height = height;
|
|
1980
|
+
gl.viewport(0, 0, width, height);
|
|
1981
|
+
const program = createProgram(gl, `
|
|
1982
|
+
attribute vec2 a_position;
|
|
1983
|
+
varying vec2 v_uv;
|
|
1984
|
+
|
|
1985
|
+
void main() {
|
|
1986
|
+
v_uv = a_position * 0.5 + 0.5;
|
|
1987
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
1988
|
+
}
|
|
1989
|
+
`, `
|
|
1990
|
+
precision mediump float;
|
|
1991
|
+
|
|
1992
|
+
varying vec2 v_uv;
|
|
1993
|
+
|
|
1994
|
+
uniform vec2 u_start;
|
|
1995
|
+
uniform vec2 u_end;
|
|
1996
|
+
uniform int u_stopCount;
|
|
1997
|
+
uniform float u_positions[${MAX_STOPS}];
|
|
1998
|
+
uniform vec4 u_colors[${MAX_STOPS}];
|
|
1999
|
+
|
|
2000
|
+
vec4 getGradientColor(float t) {
|
|
2001
|
+
vec4 result = u_colors[0];
|
|
2002
|
+
|
|
2003
|
+
for (int i = 0; i < ${MAX_STOPS - 1}; i++) {
|
|
2004
|
+
if (i >= u_stopCount - 1) {
|
|
2005
|
+
break;
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
float currentPosition = u_positions[i];
|
|
2009
|
+
float nextPosition = u_positions[i + 1];
|
|
2010
|
+
|
|
2011
|
+
if (t <= currentPosition) {
|
|
2012
|
+
return u_colors[i];
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
if (t >= currentPosition && t <= nextPosition) {
|
|
2016
|
+
float localT = (t - currentPosition) / max(nextPosition - currentPosition, 0.00001);
|
|
2017
|
+
return mix(u_colors[i], u_colors[i + 1], localT);
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
result = u_colors[i + 1];
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
return result;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
void main() {
|
|
2027
|
+
vec2 axis = u_end - u_start;
|
|
2028
|
+
vec2 point = v_uv;
|
|
2029
|
+
|
|
2030
|
+
float axisLengthSquared = dot(axis, axis);
|
|
2031
|
+
float t = dot(point - u_start, axis) / axisLengthSquared;
|
|
2032
|
+
|
|
2033
|
+
t = clamp(t, 0.0, 1.0);
|
|
2034
|
+
|
|
2035
|
+
gl_FragColor = getGradientColor(t);
|
|
2036
|
+
}
|
|
2037
|
+
`);
|
|
2038
|
+
gl.useProgram(program);
|
|
2039
|
+
const positionBuffer = gl.createBuffer();
|
|
2040
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
|
|
2041
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
|
2042
|
+
-1,
|
|
2043
|
+
-1,
|
|
2044
|
+
1,
|
|
2045
|
+
-1,
|
|
2046
|
+
-1,
|
|
2047
|
+
1,
|
|
2048
|
+
-1,
|
|
2049
|
+
1,
|
|
2050
|
+
1,
|
|
2051
|
+
-1,
|
|
2052
|
+
1,
|
|
2053
|
+
1
|
|
2054
|
+
]), gl.STATIC_DRAW);
|
|
2055
|
+
const positionLocation = gl.getAttribLocation(program, "a_position");
|
|
2056
|
+
gl.enableVertexAttribArray(positionLocation);
|
|
2057
|
+
gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0);
|
|
2058
|
+
const angle = gradient.config.angle;
|
|
2059
|
+
const dirX = Math.sin(angle);
|
|
2060
|
+
const dirY = -Math.cos(angle);
|
|
2061
|
+
const centerX = width / 2;
|
|
2062
|
+
const centerY = height / 2;
|
|
2063
|
+
const lineLength = Math.abs(width * dirX) + Math.abs(height * dirY);
|
|
2064
|
+
let startX = centerX - dirX * lineLength / 2;
|
|
2065
|
+
let startY = centerY - dirY * lineLength / 2;
|
|
2066
|
+
let endX = centerX + dirX * lineLength / 2;
|
|
2067
|
+
let endY = centerY + dirY * lineLength / 2;
|
|
2068
|
+
const { min, max, stops } = getStopRange(resolveRenderableLinearGradientStops(gradient, getWebGLSampleCount(gradient, MAX_STOPS)));
|
|
2069
|
+
let normalizedStops = stops;
|
|
2070
|
+
if (min < 0 || max > 1) {
|
|
2071
|
+
const vx = endX - startX;
|
|
2072
|
+
const vy = endY - startY;
|
|
2073
|
+
const baseStartX = startX;
|
|
2074
|
+
const baseStartY = startY;
|
|
2075
|
+
startX = baseStartX + vx * min;
|
|
2076
|
+
startY = baseStartY + vy * min;
|
|
2077
|
+
endX = baseStartX + vx * max;
|
|
2078
|
+
endY = baseStartY + vy * max;
|
|
2079
|
+
normalizedStops = normalizeStops(stops, min, max);
|
|
2080
|
+
}
|
|
2081
|
+
const startU = startX / width;
|
|
2082
|
+
const startV = 1 - startY / height;
|
|
2083
|
+
const endU = endX / width;
|
|
2084
|
+
const endV = 1 - endY / height;
|
|
2085
|
+
const limitedStops = fitStopsToWebGLLimit(normalizedStops, MAX_STOPS);
|
|
2086
|
+
const positions = new Float32Array(MAX_STOPS);
|
|
2087
|
+
const colors = new Float32Array(MAX_STOPS * 4);
|
|
2088
|
+
limitedStops.forEach((stop, index) => {
|
|
2089
|
+
const color = toWebGLColor(stop.value);
|
|
2090
|
+
positions[index] = stop.position;
|
|
2091
|
+
colors[index * 4 + 0] = color[0];
|
|
2092
|
+
colors[index * 4 + 1] = color[1];
|
|
2093
|
+
colors[index * 4 + 2] = color[2];
|
|
2094
|
+
colors[index * 4 + 3] = color[3];
|
|
2095
|
+
});
|
|
2096
|
+
gl.uniform2f(gl.getUniformLocation(program, "u_start"), startU, startV);
|
|
2097
|
+
gl.uniform2f(gl.getUniformLocation(program, "u_end"), endU, endV);
|
|
2098
|
+
gl.uniform1i(gl.getUniformLocation(program, "u_stopCount"), limitedStops.length);
|
|
2099
|
+
gl.uniform1fv(gl.getUniformLocation(program, "u_positions"), positions);
|
|
2100
|
+
gl.uniform4fv(gl.getUniformLocation(program, "u_colors"), colors);
|
|
2101
|
+
gl.clearColor(0, 0, 0, 0);
|
|
2102
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
2103
|
+
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
|
2104
|
+
} };
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
//#endregion
|
|
1583
2108
|
//#region src/gradient-transformer/GradientTransformer.ts
|
|
1584
2109
|
var GradientTransformer = class {
|
|
1585
2110
|
static _modules = /* @__PURE__ */ new Map();
|
|
@@ -1616,6 +2141,7 @@ var GradientTransformer = class {
|
|
|
1616
2141
|
this.add(new ModuleTransformerLinearGradientToCanvas());
|
|
1617
2142
|
this.add(new ModuleTransformerRadialGradientToCanvas());
|
|
1618
2143
|
this.add(new ModuleTransformerConicGradientToCanvas());
|
|
2144
|
+
this.add(new ModuleTransformerLinearGradientToCanvasWebGL());
|
|
1619
2145
|
}
|
|
1620
2146
|
static _getKey(target, gradientType) {
|
|
1621
2147
|
return `${target}:${gradientType}`;
|
|
@@ -1677,4 +2203,4 @@ function transformFrom(target, gradientType, input) {
|
|
|
1677
2203
|
return GradientTransformer.from(target, gradientType, input);
|
|
1678
2204
|
}
|
|
1679
2205
|
//#endregion
|
|
1680
|
-
export { ConicGradient, GradientBase, GradientFactory, GradientTransformer, LinearGradient, ModuleTransformerConicGradientToCanvas, ModuleTransformerConicGradientToCss, ModuleTransformerLinearGradientToCanvas, ModuleTransformerLinearGradientToCss, ModuleTransformerRadialGradientToCanvas, ModuleTransformerRadialGradientToCss, PatternTokenKind, RadialGradient, ceilTo, clamp, degToRad, floorTo, format, fromPercent, gradToRad, isAngleUnit, isColorHint, isColorStop, isConfig, isGradient, isPatternSyntaxValid, isPatternValid, isValid, matchExpression,
|
|
2206
|
+
export { ConicGradient, GRADIENT_COLOR_SPACE, GRADIENT_HUE_INTERPOLATIONS, GRADIENT_POLAR_COLOR_SPACES, GradientBase, GradientFactory, GradientTransformer, LinearGradient, ModuleTransformerConicGradientToCanvas, ModuleTransformerConicGradientToCss, ModuleTransformerLinearGradientToCanvas, ModuleTransformerLinearGradientToCanvasWebGL, ModuleTransformerLinearGradientToCss, ModuleTransformerRadialGradientToCanvas, ModuleTransformerRadialGradientToCss, PatternTokenKind, RadialGradient, angleValueFromString, ceilTo, clamp, degToRad, floorTo, format, fromPercent, gradToRad, isAngle, isAngleUnit, isColorHint, isColorStop, isConfig, isGradient, isGradientColorSpace, isGradientHueInterpolation, isGradientPolarColorSpace, isPatternSyntaxValid, isPatternValid, isValid, matchExpression, normalizeAngleDeg, normalizeAngleRad, parse, parseStringToAbi, radToDeg, roundTo, splitTopLevelByWhitespace, toPercent, tokenizePattern, transformFrom, transformTo, truncTo, turnToRad, validate, validatePattern, validatePatternSemantic, validatePatternStructure, validatePatternSyntax };
|
package/package.json
CHANGED
|
@@ -1,68 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "gradiente",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
5
|
-
"description": "Lightweight gradient toolkit for modern rendering systems.",
|
|
6
|
-
"author": "Nice Arti <nikcrav@gmail.com>",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"homepage": "https://flowscape-ui.github.io/gradiente/",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"gradiente",
|
|
11
|
-
"gradient",
|
|
12
|
-
"gradients",
|
|
13
|
-
"flowscape",
|
|
14
|
-
"color"
|
|
15
|
-
],
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/Flowscape-UI/gradiente.git"
|
|
19
|
-
},
|
|
20
|
-
"bugs": {
|
|
21
|
-
"url": "https://github.com/Flowscape-UI/gradiente/issues"
|
|
22
|
-
},
|
|
23
|
-
"exports": {
|
|
24
|
-
".": "./dist/index.mjs",
|
|
25
|
-
"./package.json": "./package.json"
|
|
26
|
-
},
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build": "tsdown",
|
|
33
|
-
"dev": "tsdown --watch",
|
|
34
|
-
"test": "vitest",
|
|
35
|
-
"typecheck": "tsc --noEmit",
|
|
36
|
-
"release": "bumpp",
|
|
37
|
-
"prepublishOnly": "pnpm run build",
|
|
38
|
-
"lint": "eslint .",
|
|
39
|
-
"lint:fix": "eslint . --fix"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"@vue-flow/core": "^1.48.2",
|
|
56
|
-
"bumpp": "^11.0.1",
|
|
57
|
-
"eslint": "^10.2.0",
|
|
58
|
-
"tsdown": "^0.21.7",
|
|
59
|
-
"typescript": "^6.0.2",
|
|
60
|
-
"typescript-eslint": "^8.58.2",
|
|
61
|
-
"vite": "^8.0.8",
|
|
62
|
-
"vitepress": "^1.6.4",
|
|
63
|
-
"vitest": "^4.1.2"
|
|
64
|
-
},
|
|
65
|
-
"dependencies": {
|
|
66
|
-
"culori": "^4.0.2"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "gradiente",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.1.0",
|
|
5
|
+
"description": "Lightweight gradient toolkit for modern rendering systems.",
|
|
6
|
+
"author": "Nice Arti <nikcrav@gmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://flowscape-ui.github.io/gradiente/",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"gradiente",
|
|
11
|
+
"gradient",
|
|
12
|
+
"gradients",
|
|
13
|
+
"flowscape",
|
|
14
|
+
"color"
|
|
15
|
+
],
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/Flowscape-UI/gradiente.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/Flowscape-UI/gradiente/issues"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/index.mjs",
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsdown",
|
|
33
|
+
"dev": "tsdown --watch",
|
|
34
|
+
"test": "vitest",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"release": "bumpp",
|
|
37
|
+
"prepublishOnly": "pnpm run build",
|
|
38
|
+
"lint": "eslint .",
|
|
39
|
+
"lint:fix": "eslint . --fix"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@eslint/js": "^10.0.1",
|
|
43
|
+
"@types/culori": "^4.0.1",
|
|
44
|
+
"@types/node": "^25.5.0",
|
|
45
|
+
"bumpp": "^11.0.1",
|
|
46
|
+
"tsdown": "^0.21.7",
|
|
47
|
+
"typescript": "^6.0.2",
|
|
48
|
+
"typescript-eslint": "^8.58.2",
|
|
49
|
+
"vitest": "^4.1.5"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"culori": "^4.0.2"
|
|
53
|
+
}
|
|
54
|
+
}
|