gradiente 1.0.2 → 2.0.1
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 +94 -175
- package/dist/index.d.mts +363 -291
- package/dist/index.mjs +1534 -1284
- package/package.json +16 -13
- package/LICENSE +0 -21
package/dist/index.d.mts
CHANGED
|
@@ -1,199 +1,3 @@
|
|
|
1
|
-
//#region src/token.d.ts
|
|
2
|
-
declare const TokenKind: {
|
|
3
|
-
readonly PAREN_OPEN: 'paren-open';
|
|
4
|
-
readonly PAREN_CLOSE: 'paren-close';
|
|
5
|
-
readonly COMMA: 'comma';
|
|
6
|
-
readonly SLASH: 'slash';
|
|
7
|
-
readonly FUNCTION_LINEAR_GRADIENT: 'function-linear-gradient';
|
|
8
|
-
readonly FUNCTION_REPEATING_LINEAR_GRADIENT: 'function-repeating-linear-gradient';
|
|
9
|
-
readonly FUNCTION_RADIAL_GRADIENT: 'function-radial-gradient';
|
|
10
|
-
readonly FUNCTION_REPEATING_RADIAL_GRADIENT: 'function-repeating-radial-gradient';
|
|
11
|
-
readonly FUNCTION_CONIC_GRADIENT: 'function-conic-gradient';
|
|
12
|
-
readonly FUNCTION_REPEATING_CONIC_GRADIENT: 'function-repeating-conic-gradient';
|
|
13
|
-
readonly FUNCTION_DIAMOND_GRADIENT: 'function-diamond-gradient';
|
|
14
|
-
readonly FUNCTION_REPEATING_DIAMOND_GRADIENT: 'function-repeating-diamond-gradient';
|
|
15
|
-
readonly FUNCTION_MESH_GRADIENT: 'function-mesh-gradient';
|
|
16
|
-
readonly TO: 'to';
|
|
17
|
-
readonly TOP: 'top';
|
|
18
|
-
readonly BOTTOM: 'bottom';
|
|
19
|
-
readonly LEFT: 'left';
|
|
20
|
-
readonly RIGHT: 'right';
|
|
21
|
-
readonly AT: 'at';
|
|
22
|
-
readonly FROM: 'from';
|
|
23
|
-
readonly CENTER: 'center';
|
|
24
|
-
readonly CIRCLE: 'circle';
|
|
25
|
-
readonly ELLIPSE: 'ellipse';
|
|
26
|
-
readonly CLOSEST_SIDE: 'closest-side';
|
|
27
|
-
readonly CLOSEST_CORNER: 'closest-corner';
|
|
28
|
-
readonly FARTHEST_SIDE: 'farthest-side';
|
|
29
|
-
readonly FARTHEST_CORNER: 'farthest-corner';
|
|
30
|
-
readonly IN: 'in';
|
|
31
|
-
readonly SHORTER: 'shorter';
|
|
32
|
-
readonly LONGER: 'longer';
|
|
33
|
-
readonly INCREASING: 'increasing';
|
|
34
|
-
readonly DECREASING: 'decreasing';
|
|
35
|
-
readonly HUE: 'hue';
|
|
36
|
-
readonly IDENT: 'ident';
|
|
37
|
-
readonly NUMBER: 'number';
|
|
38
|
-
readonly PERCENTAGE: 'percentage';
|
|
39
|
-
readonly DIMENSION: 'dimension';
|
|
40
|
-
readonly FUNCTION: 'function';
|
|
41
|
-
readonly HASH: 'hash';
|
|
42
|
-
readonly STRING: 'string';
|
|
43
|
-
readonly WHITESPACE: 'whitespace';
|
|
44
|
-
readonly EOF: 'eof';
|
|
45
|
-
readonly UNKNOWN: 'unknown';
|
|
46
|
-
};
|
|
47
|
-
type TokenKind = (typeof TokenKind)[keyof typeof TokenKind];
|
|
48
|
-
interface TokenBase {
|
|
49
|
-
kind: TokenKind;
|
|
50
|
-
start: number;
|
|
51
|
-
end: number;
|
|
52
|
-
raw: string;
|
|
53
|
-
}
|
|
54
|
-
interface PunctuationToken extends TokenBase {
|
|
55
|
-
kind: typeof TokenKind.PAREN_OPEN | typeof TokenKind.PAREN_CLOSE | typeof TokenKind.COMMA | typeof TokenKind.SLASH;
|
|
56
|
-
}
|
|
57
|
-
interface KeywordToken extends TokenBase {
|
|
58
|
-
kind: typeof TokenKind.TO | typeof TokenKind.TOP | typeof TokenKind.BOTTOM | typeof TokenKind.LEFT | typeof TokenKind.RIGHT | typeof TokenKind.AT | typeof TokenKind.FROM | typeof TokenKind.CENTER | typeof TokenKind.CIRCLE | typeof TokenKind.ELLIPSE | typeof TokenKind.CLOSEST_SIDE | typeof TokenKind.CLOSEST_CORNER | typeof TokenKind.FARTHEST_SIDE | typeof TokenKind.FARTHEST_CORNER | typeof TokenKind.IN | typeof TokenKind.SHORTER | typeof TokenKind.LONGER | typeof TokenKind.INCREASING | typeof TokenKind.DECREASING | typeof TokenKind.HUE;
|
|
59
|
-
}
|
|
60
|
-
interface GradientFunctionToken extends TokenBase {
|
|
61
|
-
kind: typeof TokenKind.FUNCTION_LINEAR_GRADIENT | typeof TokenKind.FUNCTION_REPEATING_LINEAR_GRADIENT | typeof TokenKind.FUNCTION_RADIAL_GRADIENT | typeof TokenKind.FUNCTION_REPEATING_RADIAL_GRADIENT | typeof TokenKind.FUNCTION_CONIC_GRADIENT | typeof TokenKind.FUNCTION_REPEATING_CONIC_GRADIENT | typeof TokenKind.FUNCTION_DIAMOND_GRADIENT | typeof TokenKind.FUNCTION_REPEATING_DIAMOND_GRADIENT | typeof TokenKind.FUNCTION_MESH_GRADIENT;
|
|
62
|
-
name: string;
|
|
63
|
-
}
|
|
64
|
-
interface FunctionToken extends TokenBase {
|
|
65
|
-
kind: typeof TokenKind.FUNCTION;
|
|
66
|
-
name: string;
|
|
67
|
-
}
|
|
68
|
-
interface IdentToken extends TokenBase {
|
|
69
|
-
kind: typeof TokenKind.IDENT;
|
|
70
|
-
value: string;
|
|
71
|
-
}
|
|
72
|
-
interface NumberToken extends TokenBase {
|
|
73
|
-
kind: typeof TokenKind.NUMBER;
|
|
74
|
-
value: number;
|
|
75
|
-
sign: -1 | 1;
|
|
76
|
-
}
|
|
77
|
-
interface PercentageToken extends TokenBase {
|
|
78
|
-
kind: typeof TokenKind.PERCENTAGE;
|
|
79
|
-
value: number;
|
|
80
|
-
sign: -1 | 1;
|
|
81
|
-
}
|
|
82
|
-
interface DimensionToken extends TokenBase {
|
|
83
|
-
kind: typeof TokenKind.DIMENSION;
|
|
84
|
-
value: number;
|
|
85
|
-
sign: -1 | 1;
|
|
86
|
-
unit: string;
|
|
87
|
-
}
|
|
88
|
-
interface HashToken extends TokenBase {
|
|
89
|
-
kind: typeof TokenKind.HASH;
|
|
90
|
-
value: string;
|
|
91
|
-
}
|
|
92
|
-
interface StringToken extends TokenBase {
|
|
93
|
-
kind: typeof TokenKind.STRING;
|
|
94
|
-
value: string;
|
|
95
|
-
quote: '"' | "'";
|
|
96
|
-
}
|
|
97
|
-
interface WhitespaceToken extends TokenBase {
|
|
98
|
-
kind: typeof TokenKind.WHITESPACE;
|
|
99
|
-
}
|
|
100
|
-
interface EofToken extends TokenBase {
|
|
101
|
-
kind: typeof TokenKind.EOF;
|
|
102
|
-
}
|
|
103
|
-
interface UnknownToken extends TokenBase {
|
|
104
|
-
kind: typeof TokenKind.UNKNOWN;
|
|
105
|
-
}
|
|
106
|
-
type GradientLexerToken = PunctuationToken | KeywordToken | GradientFunctionToken | FunctionToken | IdentToken | NumberToken | PercentageToken | DimensionToken | HashToken | StringToken | WhitespaceToken | EofToken | UnknownToken;
|
|
107
|
-
declare const GradientFunctionNameToToken: {
|
|
108
|
-
readonly 'linear-gradient': "function-linear-gradient";
|
|
109
|
-
readonly 'repeating-linear-gradient': "function-repeating-linear-gradient";
|
|
110
|
-
readonly 'radial-gradient': "function-radial-gradient";
|
|
111
|
-
readonly 'repeating-radial-gradient': "function-repeating-radial-gradient";
|
|
112
|
-
readonly 'conic-gradient': "function-conic-gradient";
|
|
113
|
-
readonly 'repeating-conic-gradient': "function-repeating-conic-gradient";
|
|
114
|
-
readonly 'diamond-gradient': "function-diamond-gradient";
|
|
115
|
-
readonly 'repeating-diamond-gradient': "function-repeating-diamond-gradient";
|
|
116
|
-
readonly 'mesh-gradient': "function-mesh-gradient";
|
|
117
|
-
};
|
|
118
|
-
declare const KeywordNameToToken: {
|
|
119
|
-
readonly to: "to";
|
|
120
|
-
readonly top: "top";
|
|
121
|
-
readonly bottom: "bottom";
|
|
122
|
-
readonly left: "left";
|
|
123
|
-
readonly right: "right";
|
|
124
|
-
readonly at: "at";
|
|
125
|
-
readonly from: "from";
|
|
126
|
-
readonly center: "center";
|
|
127
|
-
readonly circle: "circle";
|
|
128
|
-
readonly ellipse: "ellipse";
|
|
129
|
-
readonly 'closest-side': "closest-side";
|
|
130
|
-
readonly 'closest-corner': "closest-corner";
|
|
131
|
-
readonly 'farthest-side': "farthest-side";
|
|
132
|
-
readonly 'farthest-corner': "farthest-corner";
|
|
133
|
-
readonly in: "in";
|
|
134
|
-
readonly shorter: "shorter";
|
|
135
|
-
readonly longer: "longer";
|
|
136
|
-
readonly increasing: "increasing";
|
|
137
|
-
readonly decreasing: "decreasing";
|
|
138
|
-
readonly hue: "hue";
|
|
139
|
-
};
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/lexer/base.d.ts
|
|
142
|
-
interface LexerState {
|
|
143
|
-
source: string;
|
|
144
|
-
length: number;
|
|
145
|
-
position: number;
|
|
146
|
-
}
|
|
147
|
-
interface SourceSpan {
|
|
148
|
-
start: number;
|
|
149
|
-
end: number;
|
|
150
|
-
raw: string;
|
|
151
|
-
}
|
|
152
|
-
declare function createLexerState(source: string): LexerState;
|
|
153
|
-
declare function isEnd(state: LexerState): boolean;
|
|
154
|
-
declare function currentChar(state: LexerState): string | null;
|
|
155
|
-
declare function peekChar(state: LexerState, offset?: number): string | null;
|
|
156
|
-
declare function advance(state: LexerState, step?: number): void;
|
|
157
|
-
declare function isWhitespaceChar(char: string | null): boolean;
|
|
158
|
-
declare function isDigitChar(char: string | null): boolean;
|
|
159
|
-
declare function isSignChar(char: string | null): boolean;
|
|
160
|
-
declare function isIdentifierStartChar(char: string | null): boolean;
|
|
161
|
-
declare function isIdentifierChar(char: string | null): boolean;
|
|
162
|
-
declare function isAlphaChar(char: string | null): boolean;
|
|
163
|
-
declare function readWhile(state: LexerState, predicate: (char: string | null) => boolean): string;
|
|
164
|
-
declare function createSpan(source: string, start: number, end: number): SourceSpan;
|
|
165
|
-
//#endregion
|
|
166
|
-
//#region src/lexer/lexer.d.ts
|
|
167
|
-
declare function nextToken(state: LexerState): GradientLexerToken;
|
|
168
|
-
declare function tokenize(source: string): GradientLexerToken[];
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region src/guard.d.ts
|
|
171
|
-
declare function isGradientFunctionToken(token: GradientLexerToken): boolean;
|
|
172
|
-
declare function isKeywordToken(token: GradientLexerToken): boolean;
|
|
173
|
-
declare function isNumericToken(token: GradientLexerToken): boolean;
|
|
174
|
-
//#endregion
|
|
175
|
-
//#region src/source.d.ts
|
|
176
|
-
declare function getSourceSlice(source: string, start: number, end: number): string;
|
|
177
|
-
declare function getTokenSourceSlice(source: string, startToken: GradientLexerToken, endToken: GradientLexerToken): string;
|
|
178
|
-
declare function getTokenRangeSourceSlice(source: string, tokens: readonly GradientLexerToken[], startIndex: number, endIndex: number): string;
|
|
179
|
-
declare function findBalancedFunctionEndIndex(tokens: readonly GradientLexerToken[], startIndex: number): number;
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/utils/parser-utils.d.ts
|
|
182
|
-
declare function isTriviaToken(token: GradientLexerToken): boolean;
|
|
183
|
-
declare function getTokenAt(tokens: readonly GradientLexerToken[], index: number): GradientLexerToken | null;
|
|
184
|
-
declare function findNextNonWhitespaceIndex(tokens: readonly GradientLexerToken[], startIndex: number): number;
|
|
185
|
-
declare function getNonWhitespaceTokenAt(tokens: readonly GradientLexerToken[], startIndex: number): GradientLexerToken | null;
|
|
186
|
-
declare function skipWhitespace(tokens: readonly GradientLexerToken[], startIndex: number): number;
|
|
187
|
-
declare function consumeIf(tokens: readonly GradientLexerToken[], index: number, kind: GradientLexerToken['kind']): {
|
|
188
|
-
matched: boolean;
|
|
189
|
-
nextIndex: number;
|
|
190
|
-
token: GradientLexerToken | null;
|
|
191
|
-
};
|
|
192
|
-
declare function expectToken(tokens: readonly GradientLexerToken[], index: number, kind: GradientLexerToken['kind'], message?: string): {
|
|
193
|
-
token: GradientLexerToken;
|
|
194
|
-
nextIndex: number;
|
|
195
|
-
};
|
|
196
|
-
//#endregion
|
|
197
1
|
//#region src/utils/math/base.d.ts
|
|
198
2
|
declare function roundTo(value: number, digits: number): number;
|
|
199
3
|
declare function floorTo(value: number, digits: number): number;
|
|
@@ -214,122 +18,390 @@ declare function normalizeAngleDeg(value: number, digits?: number): number;
|
|
|
214
18
|
declare function normalizeAngleRad(value: number): number;
|
|
215
19
|
declare function toAngleRad(value: number, unit: AngleUnit): number;
|
|
216
20
|
declare function normalizeAngle(value: number, unit: AngleUnit, digits?: number): number;
|
|
217
|
-
declare function parseAngleFromToken(token: GradientLexerToken): number | null;
|
|
218
21
|
//#endregion
|
|
219
|
-
//#region src/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
22
|
+
//#region src/abi.d.ts
|
|
23
|
+
/***************************************************************************************************/
|
|
24
|
+
type AbiInputType = "config" | "color-stop" | "color-hint";
|
|
25
|
+
type GradientAbi = {
|
|
26
|
+
functionName: string;
|
|
27
|
+
isRepeating: boolean;
|
|
28
|
+
inputs: GradientAbiInput[];
|
|
29
|
+
};
|
|
30
|
+
type GradientAbiInput = {
|
|
31
|
+
type: string;
|
|
32
|
+
value: string;
|
|
33
|
+
};
|
|
34
|
+
declare function parseStringToAbi(value: string, pattern?: string): GradientAbi;
|
|
35
|
+
declare function isColorHint(value: string): boolean;
|
|
36
|
+
declare function isColorStop(value: string): boolean;
|
|
37
|
+
declare function isConfig(value: string): boolean;
|
|
38
|
+
declare function splitTopLevelByWhitespace(value: string): string[];
|
|
224
39
|
//#endregion
|
|
225
|
-
//#region src/
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
stops: readonly GradientColorStopNode[];
|
|
40
|
+
//#region src/dsl/types.d.ts
|
|
41
|
+
declare enum PatternTokenKind {
|
|
42
|
+
START = "^",
|
|
43
|
+
END = ".",
|
|
44
|
+
GROUP_OPEN = "(",
|
|
45
|
+
GROUP_CLOSE = ")",
|
|
46
|
+
COMMA = ",",
|
|
47
|
+
SEQUENCE_OPEN = "[",
|
|
48
|
+
SEQUENCE_CLOSE = "]",
|
|
49
|
+
OR = "|",
|
|
50
|
+
AND = "&",
|
|
51
|
+
NOT = "!",
|
|
52
|
+
REPEAT = "~",
|
|
53
|
+
CONFIG = "config",
|
|
54
|
+
COLOR_STOP = "color-stop",
|
|
55
|
+
COLOR_HINT = "color-hint"
|
|
242
56
|
}
|
|
243
57
|
//#endregion
|
|
244
|
-
//#region src/
|
|
245
|
-
|
|
58
|
+
//#region src/dsl/pattern-validator.d.ts
|
|
59
|
+
/********************************************************************/
|
|
60
|
+
/********************************************************************/
|
|
61
|
+
declare function validatePattern(input: string): boolean;
|
|
62
|
+
declare function isPatternValid(input: string): boolean;
|
|
63
|
+
/********************************************************************/
|
|
64
|
+
/********************************************************************/
|
|
65
|
+
declare function validatePatternSyntax(input: string): boolean;
|
|
66
|
+
declare function isPatternSyntaxValid(input: string): boolean;
|
|
67
|
+
declare function validatePatternSemantic(input: string): boolean;
|
|
68
|
+
/********************************************************************/
|
|
69
|
+
/********************************************************************/
|
|
70
|
+
declare function validatePatternStructure(input: string): boolean;
|
|
71
|
+
/********************************************************************/
|
|
72
|
+
/********************************************************************/
|
|
73
|
+
declare function tokenizePattern(input: string): PatternTokenKind[];
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/dsl/match.d.ts
|
|
76
|
+
type MatchResult = {
|
|
77
|
+
matched: boolean;
|
|
78
|
+
nextInputIndex: number;
|
|
79
|
+
nextPatternIndex: number;
|
|
80
|
+
};
|
|
81
|
+
declare function matchExpression(classified: GradientAbiInput[], patternTokens: PatternTokenKind[], inputIndex: number, patternIndex: number): MatchResult;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/dsl/index.d.ts
|
|
84
|
+
declare function isValid(input: GradientAbiInput[], pattern: string): boolean;
|
|
85
|
+
declare function validate(classified: GradientAbiInput[], pattern: string): boolean;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/gradients/types.d.ts
|
|
88
|
+
/**
|
|
89
|
+
* Shared scalar units
|
|
90
|
+
*/
|
|
91
|
+
type GradientAngleUnit = "deg" | "rad" | "turn" | "grad";
|
|
92
|
+
type GradientLengthUnit = "px" | "em" | "rem" | "vw" | "vh" | "vmin" | "vmax" | "cm" | "mm" | "in" | "pt" | "pc";
|
|
93
|
+
type GradientNumberValue = {
|
|
94
|
+
kind: "number";
|
|
95
|
+
value: number;
|
|
96
|
+
};
|
|
97
|
+
type GradientPercentValue = {
|
|
98
|
+
kind: "percent";
|
|
99
|
+
value: number;
|
|
100
|
+
};
|
|
101
|
+
type GradientLengthValue = {
|
|
102
|
+
kind: "length";
|
|
103
|
+
value: number;
|
|
104
|
+
unit: GradientLengthUnit;
|
|
105
|
+
};
|
|
106
|
+
type GradientAngleValue = {
|
|
107
|
+
kind: "angle";
|
|
108
|
+
value: number;
|
|
109
|
+
unit: GradientAngleUnit;
|
|
110
|
+
};
|
|
111
|
+
type GradientLengthPercentage = GradientLengthValue | GradientPercentValue;
|
|
112
|
+
type GradientPositionKeywordX = "left" | "center" | "right";
|
|
113
|
+
type GradientPositionKeywordY = "top" | "center" | "bottom";
|
|
114
|
+
/**
|
|
115
|
+
* Position model
|
|
116
|
+
* Не строка, а нормальная структура.
|
|
117
|
+
*/
|
|
118
|
+
type GradientPosition = {
|
|
119
|
+
kind: "keywords";
|
|
120
|
+
x: GradientPositionKeywordX;
|
|
121
|
+
y: GradientPositionKeywordY;
|
|
122
|
+
} | {
|
|
123
|
+
kind: "values";
|
|
124
|
+
x: GradientLengthPercentage;
|
|
125
|
+
y: GradientLengthPercentage;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Color interpolation
|
|
129
|
+
* Вынесено отдельно от geometry.
|
|
130
|
+
* Это критично для future-proof модели.
|
|
131
|
+
*/
|
|
132
|
+
type GradientHueInterpolationMethod = "shorter" | "longer" | "increasing" | "decreasing";
|
|
133
|
+
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
|
+
type GradientColorInterpolation = {
|
|
136
|
+
kind: "rectangular";
|
|
137
|
+
space: GradientRectangularColorSpace;
|
|
138
|
+
} | {
|
|
139
|
+
kind: "polar";
|
|
140
|
+
space: GradientPolarColorSpace;
|
|
141
|
+
hueMethod?: GradientHueInterpolationMethod;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Shared stop model
|
|
145
|
+
* Твой текущий stop layer сюда ложится нормально.
|
|
146
|
+
*/
|
|
147
|
+
type GradientColorStop = {
|
|
148
|
+
type: "color-stop";
|
|
149
|
+
color: string;
|
|
150
|
+
position: number | null;
|
|
151
|
+
};
|
|
152
|
+
type GradientColorHint = {
|
|
153
|
+
type: "color-hint";
|
|
154
|
+
position: number;
|
|
155
|
+
};
|
|
156
|
+
type GradientStop = {
|
|
157
|
+
type: "color-stop" | "color-hint";
|
|
158
|
+
value: string;
|
|
159
|
+
position: number;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Base config fields common to all gradient classes
|
|
163
|
+
*/
|
|
164
|
+
type GradientCommonConfig = {
|
|
165
|
+
interpolation?: GradientColorInterpolation | null;
|
|
166
|
+
};
|
|
246
167
|
//#endregion
|
|
247
|
-
//#region src/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
168
|
+
//#region src/gradients/GradientBase.d.ts
|
|
169
|
+
type GradientType = string;
|
|
170
|
+
interface GradientData<TConfig = unknown> {
|
|
171
|
+
isRepeating: boolean;
|
|
172
|
+
config: TConfig;
|
|
173
|
+
stops: GradientStop[];
|
|
253
174
|
}
|
|
254
|
-
interface
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
175
|
+
interface IGradientBase<TConfig = unknown> {
|
|
176
|
+
readonly type: GradientType;
|
|
177
|
+
readonly isRepeating: boolean;
|
|
178
|
+
readonly config: TConfig;
|
|
179
|
+
readonly stops: GradientStop[];
|
|
180
|
+
clone(): this;
|
|
181
|
+
toString(): string;
|
|
182
|
+
toJSON(): GradientData<TConfig>;
|
|
183
|
+
addStop(stop: GradientStop): void;
|
|
184
|
+
removeStop(index: number): void;
|
|
185
|
+
equals(other: IGradientBase<TConfig>): boolean;
|
|
186
|
+
}
|
|
187
|
+
declare abstract class GradientBase<TConfig = unknown> implements IGradientBase<TConfig> {
|
|
188
|
+
abstract readonly type: GradientType;
|
|
189
|
+
private _isRepeating;
|
|
190
|
+
private _config;
|
|
191
|
+
private _stops;
|
|
192
|
+
constructor(options: GradientData<TConfig>);
|
|
193
|
+
get isRepeating(): boolean;
|
|
194
|
+
get config(): TConfig;
|
|
195
|
+
get stops(): GradientStop[];
|
|
196
|
+
abstract clone(): this;
|
|
197
|
+
abstract toString(): string;
|
|
198
|
+
toJSON(): GradientData<TConfig> & {
|
|
199
|
+
type: GradientType;
|
|
200
|
+
};
|
|
201
|
+
addStop(stop: GradientStop): void;
|
|
202
|
+
static fromString(_: string): void;
|
|
203
|
+
static fromAbi(_: GradientAbi): void;
|
|
204
|
+
removeStop(index: number): void;
|
|
205
|
+
equals(other: IGradientBase<TConfig>): boolean;
|
|
206
|
+
protected _minColorStopsCount(): number;
|
|
207
|
+
protected _getSortedStops(stops: GradientStop[]): GradientStop[];
|
|
208
|
+
protected abstract _validateConfig(value: TConfig): void;
|
|
209
|
+
private _validateStops;
|
|
210
|
+
protected _validateStopsShape(value: GradientStop[]): void;
|
|
211
|
+
protected _validateStopsSequence(value: GradientStop[]): void;
|
|
212
|
+
private _cloneStops;
|
|
213
|
+
private _cloneConfig;
|
|
214
|
+
protected _buildSerializedStopTokens(): Array<{
|
|
215
|
+
type: 'color-hint';
|
|
216
|
+
position: number;
|
|
217
|
+
} | {
|
|
218
|
+
type: 'color-stop';
|
|
219
|
+
value: string;
|
|
220
|
+
positions: [number] | [number, number];
|
|
221
|
+
}>;
|
|
222
|
+
protected _canOmitAllStopPositions(tokens: Array<{
|
|
223
|
+
type: 'color-hint';
|
|
224
|
+
position: number;
|
|
225
|
+
} | {
|
|
226
|
+
type: 'color-stop';
|
|
227
|
+
value: string;
|
|
228
|
+
positions: [number] | [number, number];
|
|
229
|
+
}>): boolean;
|
|
230
|
+
protected _serializeStopsCompact(): string[];
|
|
231
|
+
protected _formatPercent(value: number): number;
|
|
232
|
+
protected static _normalizeAbiInputsToStops(inputs: GradientAbiInput[]): GradientStop[];
|
|
233
|
+
private static _parsePosition;
|
|
234
|
+
private static _parseColorStopInput;
|
|
235
|
+
private static _resolvePendingStops;
|
|
258
236
|
}
|
|
259
237
|
//#endregion
|
|
260
|
-
//#region src/
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
type
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
238
|
+
//#region src/gradients/LinearGradient.d.ts
|
|
239
|
+
type LinearGradientConfig = GradientCommonConfig & {
|
|
240
|
+
angle: number;
|
|
241
|
+
};
|
|
242
|
+
declare class LinearGradient extends GradientBase<LinearGradientConfig> {
|
|
243
|
+
readonly type = "linear-gradient";
|
|
244
|
+
constructor(config: GradientData<LinearGradientConfig>);
|
|
245
|
+
static normalizeConfig(value: {
|
|
246
|
+
value: number;
|
|
247
|
+
unit: AngleUnit;
|
|
248
|
+
} | string): LinearGradientConfig;
|
|
249
|
+
static fromString(input: string): LinearGradient;
|
|
250
|
+
static fromAbi(abi: GradientAbi): LinearGradient;
|
|
251
|
+
clone(): this;
|
|
252
|
+
toString(): string;
|
|
253
|
+
protected _validateConfig(_: LinearGradientConfig): void;
|
|
271
254
|
}
|
|
272
|
-
|
|
273
|
-
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/gradients/RadialGradient.d.ts
|
|
257
|
+
type RadialGradientShape = "circle" | "ellipse";
|
|
258
|
+
type RadialGradientExtent = "closest-side" | "closest-corner" | "farthest-side" | "farthest-corner";
|
|
259
|
+
type RadialGradientSize = {
|
|
260
|
+
kind: "extent";
|
|
261
|
+
value: RadialGradientExtent;
|
|
262
|
+
} | {
|
|
263
|
+
kind: "explicit";
|
|
264
|
+
x: GradientLengthPercentage;
|
|
265
|
+
y?: GradientLengthPercentage;
|
|
266
|
+
};
|
|
267
|
+
type RadialGradientConfig = GradientCommonConfig & {
|
|
274
268
|
shape: RadialGradientShape;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
269
|
+
size: RadialGradientSize;
|
|
270
|
+
position: GradientPosition;
|
|
271
|
+
};
|
|
272
|
+
declare class RadialGradient extends GradientBase<RadialGradientConfig> {
|
|
273
|
+
readonly type = "radial-gradient";
|
|
274
|
+
constructor(config: GradientData<RadialGradientConfig>);
|
|
275
|
+
static fromString(input: string): RadialGradient;
|
|
276
|
+
static fromAbi(abi: GradientAbi): RadialGradient;
|
|
277
|
+
clone(): this;
|
|
278
|
+
toString(): string;
|
|
279
|
+
protected _validateConfig(config: RadialGradientConfig): void;
|
|
280
|
+
private _serializeRadialConfig;
|
|
281
|
+
private _serializePosition;
|
|
282
|
+
private _formatLengthPercentage;
|
|
283
|
+
private static _parseConfig;
|
|
284
|
+
private static _parseLengthPercentage;
|
|
278
285
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
position:
|
|
284
|
-
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/gradients/ConicGradient.d.ts
|
|
288
|
+
type ConicGradientConfig = GradientCommonConfig & {
|
|
289
|
+
from: GradientAngleValue;
|
|
290
|
+
position: GradientPosition;
|
|
291
|
+
};
|
|
292
|
+
declare class ConicGradient extends GradientBase<ConicGradientConfig> {
|
|
293
|
+
readonly type = "conic-gradient";
|
|
294
|
+
constructor(config: GradientData<ConicGradientConfig>);
|
|
295
|
+
clone(): this;
|
|
296
|
+
toString(): string;
|
|
297
|
+
static fromString(input: string): ConicGradient;
|
|
298
|
+
static fromAbi(abi: GradientAbi): ConicGradient;
|
|
299
|
+
protected _validateConfig(config: ConicGradientConfig): void;
|
|
300
|
+
private _serializeConfig;
|
|
301
|
+
private _serializePosition;
|
|
302
|
+
private _formatLengthPercentage;
|
|
303
|
+
private static _parseConfig;
|
|
304
|
+
private static _parseLengthPercentage;
|
|
305
|
+
private static _parseAngle;
|
|
285
306
|
}
|
|
286
307
|
//#endregion
|
|
287
|
-
//#region src/
|
|
288
|
-
|
|
308
|
+
//#region src/gradients/GradientFactory.d.ts
|
|
309
|
+
interface IGradientStatic<TGradient extends GradientBase = GradientBase> {
|
|
310
|
+
fromAbi(abi: GradientAbi): TGradient;
|
|
311
|
+
fromString(input: string): TGradient;
|
|
312
|
+
}
|
|
313
|
+
declare class GradientFactory {
|
|
314
|
+
private static readonly _registry;
|
|
315
|
+
private static _initialized;
|
|
316
|
+
static add(type: string, value: IGradientStatic): void;
|
|
317
|
+
static get(functionName: string): IGradientStatic | null;
|
|
318
|
+
static remove(functionName: string): boolean;
|
|
319
|
+
static create(input: string | GradientAbi): IGradientBase<any>;
|
|
320
|
+
static isValid(input: string): boolean;
|
|
321
|
+
private static _ensureInitialized;
|
|
322
|
+
}
|
|
323
|
+
type AnyGradient = LinearGradient | RadialGradient | ConicGradient;
|
|
324
|
+
declare function parse(input: string): AnyGradient;
|
|
325
|
+
declare function isGradient(input: string): boolean;
|
|
326
|
+
declare function format(input: string | AnyGradient): string;
|
|
327
|
+
declare function transformTo(target: string, input: string | GradientBase<any>): unknown;
|
|
328
|
+
declare function transformFrom<TInput = unknown>(target: string, gradientType: string, input: TInput): GradientBase<any>;
|
|
289
329
|
//#endregion
|
|
290
|
-
//#region src/
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
330
|
+
//#region src/gradient-transformer/modules/types.d.ts
|
|
331
|
+
interface IGradientTransformerModule<TOutput = unknown> {
|
|
332
|
+
readonly target: string;
|
|
333
|
+
readonly gradientType: string;
|
|
334
|
+
to(input: GradientBase<any>): TOutput;
|
|
335
|
+
from?(input: TOutput): GradientBase<any>;
|
|
296
336
|
}
|
|
297
|
-
interface
|
|
298
|
-
|
|
299
|
-
color: string;
|
|
300
|
-
position: GradientLengthPercentageNode;
|
|
337
|
+
interface ICanvasPaintResult {
|
|
338
|
+
draw(ctx: CanvasRenderingContext2D, width: number, height: number): void;
|
|
301
339
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
340
|
+
//#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;
|
|
306
352
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/gradient-transformer/modules/css/ModuleTransformerLinearGradientToCss.d.ts
|
|
355
|
+
declare class ModuleTransformerLinearGradientToCss implements IGradientTransformerModule<string> {
|
|
356
|
+
readonly target = "css";
|
|
357
|
+
readonly gradientType = "linear-gradient";
|
|
358
|
+
to(input: GradientBase<any>): string;
|
|
310
359
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/gradient-transformer/modules/css/ModuleTransformerRadialGradientToCss.d.ts
|
|
362
|
+
declare class ModuleTransformerRadialGradientToCss implements IGradientTransformerModule<string> {
|
|
363
|
+
readonly target = "css";
|
|
364
|
+
readonly gradientType = "radial-gradient";
|
|
365
|
+
to(input: GradientBase<any>): string;
|
|
315
366
|
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/gradient-transformer/modules/css/ModuleTransformerConicGradientToCss.d.ts
|
|
369
|
+
declare class ModuleTransformerConicGradientToCss implements IGradientTransformerModule<string> {
|
|
370
|
+
readonly target = "css";
|
|
371
|
+
readonly gradientType = "conic-gradient";
|
|
372
|
+
to(input: GradientBase<any>): string;
|
|
322
373
|
}
|
|
323
|
-
type GradientNode = LinearGradientNode | RadialGradientNode | ConicGradientNode;
|
|
324
374
|
//#endregion
|
|
325
|
-
//#region src/
|
|
326
|
-
declare
|
|
375
|
+
//#region src/gradient-transformer/modules/canvas/ModuleTransformerLinearGradientToCanvas.d.ts
|
|
376
|
+
declare class ModuleTransformerLinearGradientToCanvas implements IGradientTransformerModule<ICanvasPaintResult> {
|
|
377
|
+
readonly target = "canvas";
|
|
378
|
+
readonly gradientType = "linear-gradient";
|
|
379
|
+
to(input: GradientBase<any>): ICanvasPaintResult;
|
|
380
|
+
}
|
|
327
381
|
//#endregion
|
|
328
|
-
//#region src/
|
|
329
|
-
declare
|
|
330
|
-
|
|
382
|
+
//#region src/gradient-transformer/modules/canvas/ModuleTransformerRadialGradientToCanvas.d.ts
|
|
383
|
+
declare class ModuleTransformerRadialGradientToCanvas implements IGradientTransformerModule<ICanvasPaintResult> {
|
|
384
|
+
readonly target = "canvas";
|
|
385
|
+
readonly gradientType = "radial-gradient";
|
|
386
|
+
to(input: GradientBase<any>): ICanvasPaintResult;
|
|
387
|
+
private _resolve;
|
|
388
|
+
}
|
|
331
389
|
//#endregion
|
|
332
|
-
//#region src/
|
|
333
|
-
declare
|
|
390
|
+
//#region src/gradient-transformer/modules/canvas/ModuleTransformerConicGradientToCanvas.d.ts
|
|
391
|
+
declare class ModuleTransformerConicGradientToCanvas implements IGradientTransformerModule<ICanvasPaintResult> {
|
|
392
|
+
readonly target = "canvas";
|
|
393
|
+
readonly gradientType = "conic-gradient";
|
|
394
|
+
to(input: GradientBase<any>): ICanvasPaintResult;
|
|
395
|
+
private _resolvePosition;
|
|
396
|
+
private _resolve;
|
|
397
|
+
private _resolveKeywordX;
|
|
398
|
+
private _resolveKeywordY;
|
|
399
|
+
private _toRad;
|
|
400
|
+
private _normalizeStops;
|
|
401
|
+
private _sampleColor;
|
|
402
|
+
private _mixColor;
|
|
403
|
+
private _parseColor;
|
|
404
|
+
private _clamp01;
|
|
405
|
+
}
|
|
334
406
|
//#endregion
|
|
335
|
-
export {
|
|
407
|
+
export { AbiInputType, AngleUnit, AnyGradient, ConicGradient, ConicGradientConfig, GradientAbi, GradientAbiInput, GradientAngleUnit, GradientAngleValue, GradientBase, GradientColorHint, GradientColorInterpolation, GradientColorStop, GradientCommonConfig, GradientData, GradientFactory, GradientHueInterpolationMethod, GradientLengthPercentage, GradientLengthUnit, GradientLengthValue, GradientNumberValue, GradientPercentValue, GradientPolarColorSpace, GradientPosition, GradientPositionKeywordX, GradientPositionKeywordY, GradientRectangularColorSpace, GradientStop, GradientTransformer, GradientType, ICanvasPaintResult, IGradientBase, IGradientStatic, IGradientTransformerModule, LinearGradient, LinearGradientConfig, ModuleTransformerConicGradientToCanvas, ModuleTransformerConicGradientToCss, ModuleTransformerLinearGradientToCanvas, ModuleTransformerLinearGradientToCss, ModuleTransformerRadialGradientToCanvas, ModuleTransformerRadialGradientToCss, PatternTokenKind, RadialGradient, RadialGradientConfig, RadialGradientExtent, RadialGradientShape, RadialGradientSize, ceilTo, clamp, degToRad, floorTo, format, fromPercent, gradToRad, isAngleUnit, isColorHint, isColorStop, isConfig, isGradient, isPatternSyntaxValid, isPatternValid, isValid, matchExpression, normalizeAngle, normalizeAngleDeg, normalizeAngleRad, parse, parseStringToAbi, radToDeg, roundTo, splitTopLevelByWhitespace, toAngleRad, toPercent, tokenizePattern, transformFrom, transformTo, truncTo, turnToRad, validate, validatePattern, validatePatternSemantic, validatePatternStructure, validatePatternSyntax };
|