@mkbabb/value.js 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -674
- package/dist/easing.d.ts +112 -0
- package/dist/index.d.ts +29 -0
- package/dist/math.d.ts +9 -0
- package/dist/parsing/color.d.ts +27 -0
- package/dist/parsing/index.d.ts +32 -0
- package/dist/parsing/math.d.ts +28 -0
- package/dist/parsing/units.d.ts +19 -0
- package/dist/parsing/utils.d.ts +24 -0
- package/dist/transform/decompose.d.ts +61 -0
- package/dist/units/color/colorFilter.d.ts +7 -0
- package/dist/units/color/constants.d.ts +992 -0
- package/dist/units/color/gamut.d.ts +60 -0
- package/dist/units/color/index.d.ts +171 -0
- package/dist/units/color/matrix.d.ts +28 -0
- package/dist/units/color/normalize.d.ts +10 -0
- package/dist/units/color/utils.d.ts +77 -0
- package/dist/units/constants.d.ts +33 -0
- package/dist/units/index.d.ts +51 -0
- package/dist/units/normalize.d.ts +9 -0
- package/dist/units/utils.d.ts +17 -0
- package/dist/utils.d.ts +28 -0
- package/dist/value.cjs +20 -0
- package/package.json +6 -6
- package/dist/value.d.ts +0 -2
package/dist/easing.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export declare function linear(t: number): number;
|
|
2
|
+
/**
|
|
3
|
+
* CSS Easing Level 2 `linear()` — piecewise-linear timing function.
|
|
4
|
+
*
|
|
5
|
+
* Each stop is `{ output: number, input?: number }`.
|
|
6
|
+
* - `output` is the easing output value (typically 0–1 but can overshoot).
|
|
7
|
+
* - `input` is the progress percentage (0–100). If omitted, stops are
|
|
8
|
+
* evenly distributed.
|
|
9
|
+
*
|
|
10
|
+
* Syntax examples:
|
|
11
|
+
* linear(0, 0.25, 1) → three evenly-spaced stops
|
|
12
|
+
* linear(0, 0.25 75%, 1) → second stop at 75% input
|
|
13
|
+
* linear(0, 0.5 25% 75%, 1) → second stop spans 25%–75% (flat segment)
|
|
14
|
+
*/
|
|
15
|
+
export interface LinearStop {
|
|
16
|
+
output: number;
|
|
17
|
+
input?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function cssLinear(stops: LinearStop[]): (t: number) => number;
|
|
20
|
+
export declare function easeInQuad(t: number): number;
|
|
21
|
+
export declare function easeOutQuad(t: number): number;
|
|
22
|
+
export declare function easeInOutQuad(t: number): number;
|
|
23
|
+
export declare function easeInCubic(t: number): number;
|
|
24
|
+
export declare function easeOutCubic(t: number): number;
|
|
25
|
+
export declare function easeInOutCubic(t: number): number;
|
|
26
|
+
export declare function smoothStep3(t: number): number;
|
|
27
|
+
export declare const CSSCubicBezier: (x1: number, y1: number, x2: number, y2: number) => (x: number) => number;
|
|
28
|
+
export declare function easeInBounce(t: number): number;
|
|
29
|
+
export declare function bounceInEase(t: number): number;
|
|
30
|
+
export declare function bounceInEaseHalf(t: number): number;
|
|
31
|
+
export declare function bounceOutEase(t: number): number;
|
|
32
|
+
export declare function bounceOutEaseHalf(t: number): number;
|
|
33
|
+
export declare function bounceInOutEase(t: number): number;
|
|
34
|
+
export declare function easeInSine(t: number): number;
|
|
35
|
+
export declare function easeOutSine(t: number): number;
|
|
36
|
+
export declare function easeInOutSine(t: number): number;
|
|
37
|
+
export declare function easeInCirc(t: number): number;
|
|
38
|
+
export declare function easeOutCirc(t: number): number;
|
|
39
|
+
export declare function easeInOutCirc(t: number): number;
|
|
40
|
+
export declare function easeInExpo(t: number): number;
|
|
41
|
+
export declare function easeOutExpo(t: number): number;
|
|
42
|
+
export declare function easeInOutExpo(t: number): number;
|
|
43
|
+
export declare const jumpTerms: readonly ["jump-start", "jump-end", "jump-none", "jump-both", "start", "end", "both"];
|
|
44
|
+
export declare function steppedEase(steps: number, jumpTerm?: (typeof jumpTerms)[number]): (t: number) => number;
|
|
45
|
+
export declare function stepStart(): (t: number) => number;
|
|
46
|
+
export declare function stepEnd(): (t: number) => number;
|
|
47
|
+
export declare const bezierPresets: {
|
|
48
|
+
readonly ease: readonly [0.25, 0.1, 0.25, 1];
|
|
49
|
+
readonly "ease-in": readonly [0.42, 0, 1, 1];
|
|
50
|
+
readonly "ease-out": readonly [0, 0, 0.58, 1];
|
|
51
|
+
readonly "ease-in-out": readonly [0.42, 0, 0.58, 1];
|
|
52
|
+
readonly "ease-in-back": readonly [0.6, -0.28, 0.735, 0.045];
|
|
53
|
+
readonly "ease-out-back": readonly [0.175, 0.885, 0.32, 1.275];
|
|
54
|
+
readonly "ease-in-out-back": readonly [0.68, -0.55, 0.265, 1.55];
|
|
55
|
+
};
|
|
56
|
+
export declare const timingFunctions: {
|
|
57
|
+
readonly linear: typeof linear;
|
|
58
|
+
readonly easeInQuad: typeof easeInQuad;
|
|
59
|
+
readonly "ease-in-quad": typeof easeInQuad;
|
|
60
|
+
readonly easeOutQuad: typeof easeOutQuad;
|
|
61
|
+
readonly "ease-out-quad": typeof easeOutQuad;
|
|
62
|
+
readonly easeInOutQuad: typeof easeInOutQuad;
|
|
63
|
+
readonly "ease-in-out-quad": typeof easeInOutQuad;
|
|
64
|
+
readonly easeInCubic: typeof easeInCubic;
|
|
65
|
+
readonly "ease-in-cubic": typeof easeInCubic;
|
|
66
|
+
readonly easeOutCubic: typeof easeOutCubic;
|
|
67
|
+
readonly "ease-out-cubic": typeof easeOutCubic;
|
|
68
|
+
readonly easeInOutCubic: typeof easeInOutCubic;
|
|
69
|
+
readonly "ease-in-out-cubic": typeof easeInOutCubic;
|
|
70
|
+
readonly easeInBounce: typeof easeInBounce;
|
|
71
|
+
readonly "ease-in-bounce": typeof easeInBounce;
|
|
72
|
+
readonly bounceInEase: typeof bounceInEase;
|
|
73
|
+
readonly "bounce-in-ease": typeof bounceInEase;
|
|
74
|
+
readonly bounceInEaseHalf: typeof bounceInEaseHalf;
|
|
75
|
+
readonly "bounce-in-ease-half": typeof bounceInEaseHalf;
|
|
76
|
+
readonly bounceOutEase: typeof bounceOutEase;
|
|
77
|
+
readonly "bounce-out-ease": typeof bounceOutEase;
|
|
78
|
+
readonly bounceOutEaseHalf: typeof bounceOutEaseHalf;
|
|
79
|
+
readonly "bounce-out-ease-half": typeof bounceOutEaseHalf;
|
|
80
|
+
readonly bounceInOutEase: typeof bounceInOutEase;
|
|
81
|
+
readonly "bounce-in-out-ease": typeof bounceInOutEase;
|
|
82
|
+
readonly easeInSine: typeof easeInSine;
|
|
83
|
+
readonly "ease-in-sine": typeof easeInSine;
|
|
84
|
+
readonly easeOutSine: typeof easeOutSine;
|
|
85
|
+
readonly "ease-out-sine": typeof easeOutSine;
|
|
86
|
+
readonly easeInOutSine: typeof easeInOutSine;
|
|
87
|
+
readonly "ease-in-out-sine": typeof easeInOutSine;
|
|
88
|
+
readonly easeInCirc: typeof easeInCirc;
|
|
89
|
+
readonly "ease-in-circ": typeof easeInCirc;
|
|
90
|
+
readonly easeOutCirc: typeof easeOutCirc;
|
|
91
|
+
readonly "ease-out-circ": typeof easeOutCirc;
|
|
92
|
+
readonly easeInOutCirc: typeof easeInOutCirc;
|
|
93
|
+
readonly "ease-in-out-circ": typeof easeInOutCirc;
|
|
94
|
+
readonly easeInExpo: typeof easeInExpo;
|
|
95
|
+
readonly "ease-in-expo": typeof easeInExpo;
|
|
96
|
+
readonly easeOutExpo: typeof easeOutExpo;
|
|
97
|
+
readonly "ease-out-expo": typeof easeOutExpo;
|
|
98
|
+
readonly easeInOutExpo: typeof easeInOutExpo;
|
|
99
|
+
readonly "ease-in-out-expo": typeof easeInOutExpo;
|
|
100
|
+
readonly smoothStep3: typeof smoothStep3;
|
|
101
|
+
readonly "smooth-step-3": typeof smoothStep3;
|
|
102
|
+
readonly ease: (x: number) => number;
|
|
103
|
+
readonly "ease-in": (x: number) => number;
|
|
104
|
+
readonly "ease-out": (x: number) => number;
|
|
105
|
+
readonly "ease-in-out": (x: number) => number;
|
|
106
|
+
readonly "ease-in-back": (x: number) => number;
|
|
107
|
+
readonly "ease-out-back": (x: number) => number;
|
|
108
|
+
readonly "ease-in-out-back": (x: number) => number;
|
|
109
|
+
readonly steps: typeof steppedEase;
|
|
110
|
+
readonly "step-start": typeof stepStart;
|
|
111
|
+
readonly "step-end": typeof stepEnd;
|
|
112
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { ValueUnit, FunctionValue, ValueArray } from './units';
|
|
2
|
+
export type { InterpolatedVar } from './units';
|
|
3
|
+
export { ABSOLUTE_LENGTH_UNITS, RELATIVE_LENGTH_UNITS, LENGTH_UNITS, TIME_UNITS, ANGLE_UNITS, PERCENTAGE_UNITS, FREQUENCY_UNITS, RESOLUTION_UNITS, FLEX_UNITS, COMPUTED_UNITS, STRING_UNITS, COLOR_UNITS, UNITS, BLACKLISTED_COALESCE_UNITS, STYLE_NAMES, } from './units/constants';
|
|
4
|
+
export type { MatrixValues } from './units/constants';
|
|
5
|
+
export { isColorUnit, flattenObject, unflattenObject, unflattenObjectToString, isCSSStyleName, unpackMatrixValues, convertAbsoluteUnitToPixels, convertToPixels, convertToMs, convertToDegrees, convertToHz, convertToDPI, convert2, } from './units/utils';
|
|
6
|
+
export { getComputedValue, normalizeNumericUnits, normalizeValueUnits, } from './units/normalize';
|
|
7
|
+
export { Color, RGBColor, HSLColor, HSVColor, HWBColor, LABColor, LCHColor, OKLABColor, OKLCHColor, XYZColor, KelvinColor, LinearSRGBColor, DisplayP3Color, AdobeRGBColor, ProPhotoRGBColor, Rec2020Color, } from './units/color';
|
|
8
|
+
export type { ColorSpaceMap } from './units/color';
|
|
9
|
+
export { RGBA_MAX, ALPHA_RANGE, RGB_RANGE, UNIT_RANGE, HUE_RANGE, COLOR_SPACE_RANGES, ALPHA_DENORM_UNIT, COLOR_SPACE_DENORM_UNITS, COLOR_SPACE_NAMES, WHITE_POINT_D65, WHITE_POINT_D50, WHITE_POINT_D65_D50, WHITE_POINT_D50_D65, WHITE_POINTS, XYZ_TO_LMS_MATRIX, LMS_TO_XYZ_MATRIX, LMS_TO_OKLAB_MATRIX, OKLAB_TO_LMS_MATRIX, LMS_TO_LINEAR_SRGB, LINEAR_SRGB_TO_LMS, OKLAB_TO_LMS_COEFF, GAMUT_SECTOR_COEFFICIENTS, COLOR_NAMES, } from './units/color/constants';
|
|
10
|
+
export type { ColorSpace, WhitePoint } from './units/color/constants';
|
|
11
|
+
export { transformMat3, transposeMat3, multiplyMat3, invertMat3, } from './units/color/matrix';
|
|
12
|
+
export type { Vec3, Mat3 } from './units/color/matrix';
|
|
13
|
+
export { getFormattedColorSpaceRange, hex2rgb, rgb2hex, kelvin2rgb, rgb2kelvin, hsv2hsl, hsl2hsv, hwb2hsl, hsl2hwb, rgb2hsl, hsl2rgb, xyz2lab, lab2xyz, srgbToLinear, linearToSrgb, rgb2xyz, xyz2rgb, lch2lab, lab2lch, oklab2xyz, xyz2oklab, oklab2lab, lab2oklab, oklab2oklch, oklch2oklab, oklch2lab, lab2oklch, hsl2xyz, xyz2hsl, hsv2xyz, xyz2hsv, hwb2xyz, xyz2hwb, lch2xyz, xyz2lch, oklch2xyz, xyz2oklch, kelvin2xyz, xyz2kelvin, adobeRgbToLinear, linearToAdobeRgb, proPhotoToLinear, linearToProPhoto, rec2020ToLinear, linearToRec2020, linearSrgb2xyz, xyz2linearSrgb, displayP32xyz, xyz2displayP3, adobeRgb2xyz, xyz2adobeRgb, proPhoto2xyz, xyz2proPhoto, rec20202xyz, xyz2rec2020, color2, gamutMap, interpolateHue, mixColors, CYLINDRICAL_HUE_COMPONENT, } from './units/color/utils';
|
|
14
|
+
export type { HueInterpolationMethod } from './units/color/utils';
|
|
15
|
+
export { normalizeColorUnitComponent, normalizeColor, normalizeColorUnit, colorUnit2, normalizeColorUnits, } from './units/color/normalize';
|
|
16
|
+
export { DELTA_E_OK_JND, deltaEOK, oklabToLinearSRGB, isInSRGBGamut, computeMaxSaturation, findCusp, findGamutIntersection, gamutMapOKLab, srgbToOKLab, gamutMapSRGB, } from './units/color/gamut';
|
|
17
|
+
export { clamp, scale, lerp, logerp, deCasteljau, cubicBezier, interpBezier, cubicBezierToSVG, cubicBezierToString, } from './math';
|
|
18
|
+
export { FRAME_RATE, isObject, clone, arrayEquals, sleep, waitUntil, debounce, createHash, memoize, hyphenToCamelCase, camelCaseToHyphen, seekPreviousValue, requestAnimationFrame, cancelAnimationFrame, } from './utils';
|
|
19
|
+
export type { MemoizeOptions } from './utils';
|
|
20
|
+
export { rgb2ColorFilter, cssFiltersToString } from './units/color/colorFilter';
|
|
21
|
+
export { linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, smoothStep3, CSSCubicBezier, easeInBounce, bounceInEase, bounceInEaseHalf, bounceOutEase, bounceOutEaseHalf, bounceInOutEase, easeInSine, easeOutSine, easeInOutSine, easeInCirc, easeOutCirc, easeInOutCirc, easeInExpo, easeOutExpo, easeInOutExpo, jumpTerms, steppedEase, stepStart, stepEnd, cssLinear, bezierPresets, timingFunctions, } from './easing';
|
|
22
|
+
export type { LinearStop } from './easing';
|
|
23
|
+
export { CSS_WIDE_KEYWORDS, CSSString, CSSFunction, CSSJSON, CSSValues, parseCSSValue, parseCSSPercent, parseCSSTime, } from './parsing';
|
|
24
|
+
export { CSSValueUnit, parseCSSValueUnit } from './parsing/units';
|
|
25
|
+
export { evaluateMathFunction } from './parsing/math';
|
|
26
|
+
export { CSSColor, parseCSSColor } from './parsing/color';
|
|
27
|
+
export { istring, identifier, none, integer, number, succeed, fail, tryParse, parseResult, } from './parsing/utils';
|
|
28
|
+
export { decomposeMatrix2D, decomposeMatrix3D, recomposeMatrix3D, slerp, interpolateDecomposed, } from './transform/decompose';
|
|
29
|
+
export type { DecomposedMatrix2D, DecomposedMatrix3D, Vec4, Mat4, } from './transform/decompose';
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
2
|
+
export declare function scale(value: number, fromMin: number, fromMax: number, toMin?: number, toMax?: number): number;
|
|
3
|
+
export declare function lerp(t: number, start: number, end: number): number;
|
|
4
|
+
export declare function logerp(t: number, start: number, end: number): number;
|
|
5
|
+
export declare function deCasteljau(t: number, points: number[]): number;
|
|
6
|
+
export declare function cubicBezier(t: number, x1: number, y1: number, x2: number, y2: number): number[];
|
|
7
|
+
export declare function interpBezier(t: number, points: number[][]): number[];
|
|
8
|
+
export declare function cubicBezierToSVG(x1: number, y1: number, x2: number, y2: number): string;
|
|
9
|
+
export declare function cubicBezierToString(x1: number, y1: number, x2: number, y2: number): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Parser } from '@mkbabb/parse-that';
|
|
2
|
+
import { ValueUnit } from '../units';
|
|
3
|
+
type ComponentExpr = {
|
|
4
|
+
type: "ref";
|
|
5
|
+
name: string;
|
|
6
|
+
} | {
|
|
7
|
+
type: "calc";
|
|
8
|
+
expr: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: "literal";
|
|
11
|
+
value: number;
|
|
12
|
+
} | {
|
|
13
|
+
type: "none";
|
|
14
|
+
};
|
|
15
|
+
export declare const CSSColor: {
|
|
16
|
+
Value: Parser<ValueUnit<any, string | undefined>>;
|
|
17
|
+
colorValue: Parser<ValueUnit<any, string | undefined>>;
|
|
18
|
+
componentExpr: Parser<ComponentExpr>;
|
|
19
|
+
sep: Parser<string>;
|
|
20
|
+
alphaSep: Parser<string>;
|
|
21
|
+
div: Parser<string>;
|
|
22
|
+
};
|
|
23
|
+
export declare function registerColorNames(names: Record<string, string>): void;
|
|
24
|
+
export declare function clearCustomColorNames(): void;
|
|
25
|
+
export declare function getCustomColorNames(): ReadonlyMap<string, string>;
|
|
26
|
+
export declare function parseCSSColor(input: string): ValueUnit;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Parser } from '@mkbabb/parse-that';
|
|
2
|
+
import { FunctionValue, ValueArray, ValueUnit } from '../units';
|
|
3
|
+
export declare const CSS_WIDE_KEYWORDS: readonly ["inherit", "initial", "unset", "revert", "revert-layer"];
|
|
4
|
+
export declare const CSSString: Parser<ValueUnit<string, string | undefined>>;
|
|
5
|
+
export declare const CSSFunction: {
|
|
6
|
+
Function: Parser<any>;
|
|
7
|
+
Value: Parser<any>;
|
|
8
|
+
FunctionArgs: Parser<ValueArray<any>>;
|
|
9
|
+
};
|
|
10
|
+
export declare const CSSJSON: Parser<ValueUnit<any, string>>;
|
|
11
|
+
export declare const CSSValues: {
|
|
12
|
+
Value: Parser<any>;
|
|
13
|
+
Values: Parser<any[]>;
|
|
14
|
+
};
|
|
15
|
+
export declare const parseCSSValue: ((input: string) => ValueUnit | FunctionValue) & {
|
|
16
|
+
cache: Map<string, {
|
|
17
|
+
value: ValueUnit<any, string | undefined> | FunctionValue<any, string>;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
export declare const parseCSSPercent: ((input: string | number) => number) & {
|
|
22
|
+
cache: Map<string, {
|
|
23
|
+
value: number;
|
|
24
|
+
timestamp: number;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
export declare const parseCSSTime: ((input: string) => number) & {
|
|
28
|
+
cache: Map<string, {
|
|
29
|
+
value: number;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Parser } from '@mkbabb/parse-that';
|
|
2
|
+
import { FunctionValue, ValueUnit } from '../units';
|
|
3
|
+
/**
|
|
4
|
+
* Parse a calc() expression into a proper AST.
|
|
5
|
+
*
|
|
6
|
+
* Grammar (CSS Values L4 §10):
|
|
7
|
+
* <calc-sum> = <calc-product> [ ['+' | '-'] <calc-product> ]*
|
|
8
|
+
* <calc-product> = <calc-value> [ ['*' | '/'] <calc-value> ]*
|
|
9
|
+
* <calc-value> = <number> | <dimension> | <percentage> | '(' <calc-sum> ')' | <math-function>
|
|
10
|
+
*/
|
|
11
|
+
export declare function createCalcParser(valueParser: Parser<any>, mathFunctionParser: Parser<any>): Parser<any>;
|
|
12
|
+
/**
|
|
13
|
+
* Create the complete math function parser.
|
|
14
|
+
* Returns a parser that handles calc(), min(), max(), clamp(), etc.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createMathFunctionParsers(valueParser: Parser<any>): {
|
|
17
|
+
calcFn: Parser<FunctionValue<any, "calc">>;
|
|
18
|
+
mathFunction: Parser<any>;
|
|
19
|
+
calcSum: Parser<any>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Evaluate a math FunctionValue to a numeric ValueUnit.
|
|
23
|
+
* Returns null if the expression can't be fully resolved.
|
|
24
|
+
*
|
|
25
|
+
* The result unit is determined by the first resolvable argument's unit,
|
|
26
|
+
* since CSS requires type-compatible arguments.
|
|
27
|
+
*/
|
|
28
|
+
export declare function evaluateMathFunction(fn: FunctionValue): ValueUnit | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Parser } from '@mkbabb/parse-that';
|
|
2
|
+
import { ValueUnit } from '../units';
|
|
3
|
+
import { CSSColor, parseCSSColor, registerColorNames, clearCustomColorNames, getCustomColorNames } from './color';
|
|
4
|
+
export { CSSColor, parseCSSColor, registerColorNames, clearCustomColorNames, getCustomColorNames };
|
|
5
|
+
export declare const CSSValueUnit: {
|
|
6
|
+
Length: Parser<ValueUnit<number, string>>;
|
|
7
|
+
Angle: Parser<ValueUnit<number, string>>;
|
|
8
|
+
Time: Parser<ValueUnit<number, string>>;
|
|
9
|
+
TimePercentage: Parser<ValueUnit<any, string | undefined>>;
|
|
10
|
+
Frequency: Parser<ValueUnit<number, string>>;
|
|
11
|
+
Resolution: Parser<ValueUnit<number, string>>;
|
|
12
|
+
Flex: Parser<ValueUnit<number, string>>;
|
|
13
|
+
Percentage: Parser<ValueUnit<any, string | undefined>>;
|
|
14
|
+
Color: Parser<ValueUnit<any, string | undefined>>;
|
|
15
|
+
Slash: Parser<ValueUnit<string, string>>;
|
|
16
|
+
Value: Parser<ValueUnit<any, string | undefined>>;
|
|
17
|
+
sep: Parser<string>;
|
|
18
|
+
};
|
|
19
|
+
export declare function parseCSSValueUnit(input: string): ValueUnit;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Parser } from '@mkbabb/parse-that';
|
|
2
|
+
/** Case-insensitive string match. Returns the matched portion of the input. */
|
|
3
|
+
export declare const istring: (str: string) => Parser<string>;
|
|
4
|
+
export declare const identifier: Parser<string>;
|
|
5
|
+
export declare const none: Parser<string>;
|
|
6
|
+
export declare const integer: Parser<number>;
|
|
7
|
+
export declare const number: Parser<number>;
|
|
8
|
+
/** Parser that always succeeds with the given value without consuming input. */
|
|
9
|
+
export declare function succeed<T>(value: T): Parser<T>;
|
|
10
|
+
/** Parser that always fails with the given message. */
|
|
11
|
+
export declare function fail(message: string): Parser<never>;
|
|
12
|
+
/**
|
|
13
|
+
* Try to parse; return the result or throw on failure.
|
|
14
|
+
* Equivalent to Parsimmon's `.tryParse()`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function tryParse<T>(parser: Parser<T>, input: string): T;
|
|
17
|
+
/**
|
|
18
|
+
* Parse and return a result object with `.status` and `.value`.
|
|
19
|
+
* Equivalent to Parsimmon's `.parse()` return shape.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseResult<T>(parser: Parser<T>, input: string): {
|
|
22
|
+
status: boolean;
|
|
23
|
+
value: T;
|
|
24
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Transform Matrix Decomposition and Recomposition.
|
|
3
|
+
*
|
|
4
|
+
* Implements the CSSOM View spec algorithm (§15.1) for 2D matrices
|
|
5
|
+
* and polar decomposition for 3D matrices.
|
|
6
|
+
* Also includes quaternion slerp for smooth rotation interpolation.
|
|
7
|
+
*/
|
|
8
|
+
export type Vec4 = [number, number, number, number];
|
|
9
|
+
export type Mat4 = number[];
|
|
10
|
+
export interface DecomposedMatrix2D {
|
|
11
|
+
translateX: number;
|
|
12
|
+
translateY: number;
|
|
13
|
+
scaleX: number;
|
|
14
|
+
scaleY: number;
|
|
15
|
+
angle: number;
|
|
16
|
+
skew: number;
|
|
17
|
+
}
|
|
18
|
+
export interface DecomposedMatrix3D {
|
|
19
|
+
translate: [number, number, number];
|
|
20
|
+
scale: [number, number, number];
|
|
21
|
+
skew: [number, number, number];
|
|
22
|
+
quaternion: Vec4;
|
|
23
|
+
perspective: Vec4;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Decompose a 2D CSS matrix(a, b, c, d, e, f) into translate, scale, rotation, and skew.
|
|
27
|
+
*
|
|
28
|
+
* The matrix maps like:
|
|
29
|
+
* | a c e |
|
|
30
|
+
* | b d f |
|
|
31
|
+
* | 0 0 1 |
|
|
32
|
+
*/
|
|
33
|
+
export declare function decomposeMatrix2D(a: number, b: number, c: number, d: number, e: number, f: number): DecomposedMatrix2D;
|
|
34
|
+
/**
|
|
35
|
+
* Decompose a CSS matrix3d (16 values in column-major CSS order) into
|
|
36
|
+
* translate, scale, skew, rotation (quaternion), and perspective.
|
|
37
|
+
*
|
|
38
|
+
* CSS `matrix3d(a1,b1,c1,d1, a2,b2,c2,d2, a3,b3,c3,d3, a4,b4,c4,d4)` maps to:
|
|
39
|
+
* | a1 a2 a3 a4 |
|
|
40
|
+
* | b1 b2 b3 b4 |
|
|
41
|
+
* | c1 c2 c3 c4 |
|
|
42
|
+
* | d1 d2 d3 d4 |
|
|
43
|
+
* The parameter order is already column-major: [a1,b1,c1,d1, a2,b2,c2,d2, ...].
|
|
44
|
+
*
|
|
45
|
+
* Based on the "unmatrix" algorithm from the CSS Transforms spec.
|
|
46
|
+
*/
|
|
47
|
+
export declare function decomposeMatrix3D(cssValues: number[]): DecomposedMatrix3D | null;
|
|
48
|
+
/**
|
|
49
|
+
* Spherical linear interpolation between two quaternions.
|
|
50
|
+
* Both quaternions should be normalized.
|
|
51
|
+
*/
|
|
52
|
+
export declare function slerp(qa: Vec4, qb: Vec4, t: number): Vec4;
|
|
53
|
+
/**
|
|
54
|
+
* Recompose a 3D decomposed matrix back into a CSS matrix3d() value array (16 values, column-major CSS order).
|
|
55
|
+
*/
|
|
56
|
+
export declare function recomposeMatrix3D(d: DecomposedMatrix3D): number[];
|
|
57
|
+
/**
|
|
58
|
+
* Interpolate between two decomposed 3D matrices at parameter t.
|
|
59
|
+
* Uses slerp for rotation, lerp for everything else.
|
|
60
|
+
*/
|
|
61
|
+
export declare function interpolateDecomposed(a: DecomposedMatrix3D, b: DecomposedMatrix3D, t: number): DecomposedMatrix3D;
|