@mkbabb/value.js 0.3.1 → 0.4.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/value.d.ts CHANGED
@@ -627,7 +627,7 @@ export declare const COLOR_SPACE_RANGES: {
627
627
  };
628
628
  readonly number: {
629
629
  readonly min: 0;
630
- readonly max: 100;
630
+ readonly max: 1;
631
631
  };
632
632
  };
633
633
  readonly a: {
@@ -669,7 +669,7 @@ export declare const COLOR_SPACE_RANGES: {
669
669
  };
670
670
  readonly number: {
671
671
  readonly min: 0;
672
- readonly max: 100;
672
+ readonly max: 1;
673
673
  };
674
674
  };
675
675
  readonly c: {
@@ -1033,12 +1033,16 @@ export declare function convertToDegrees(value: number, unit: (typeof ANGLE_UNIT
1033
1033
 
1034
1034
  export declare function convertToDPI(value: number, unit: (typeof RESOLUTION_UNITS)[number]): number;
1035
1035
 
1036
+ export declare function convertToHz(value: number, unit: (typeof FREQUENCY_UNITS)[number]): number;
1037
+
1036
1038
  export declare function convertToMs(value: number, unit: (typeof TIME_UNITS)[number]): number;
1037
1039
 
1038
1040
  export declare function convertToPixels(value: number, unit: (typeof ABSOLUTE_LENGTH_UNITS)[number] | (typeof RELATIVE_LENGTH_UNITS)[number] | (typeof PERCENTAGE_UNITS)[number], element?: HTMLElement, property?: string): number;
1039
1041
 
1040
1042
  export declare function createHash(algorithm: string, data: string): Promise<string>;
1041
1043
 
1044
+ export declare const CSS_WIDE_KEYWORDS: readonly ["inherit", "initial", "unset", "revert", "revert-layer"];
1045
+
1042
1046
  export declare const CSSColor: {
1043
1047
  Value: Parser<ValueUnit<any, string | undefined>>;
1044
1048
  colorValue: Parser<ValueUnit<any, string | undefined>>;
@@ -1048,7 +1052,7 @@ export declare const CSSColor: {
1048
1052
  div: Parser<string>;
1049
1053
  };
1050
1054
 
1051
- export declare const CSSCubicBezier: (x1: number, y1: number, x2: number, y2: number) => (t: number) => number;
1055
+ export declare const CSSCubicBezier: (x1: number, y1: number, x2: number, y2: number) => (x: number) => number;
1052
1056
 
1053
1057
  export declare function cssFiltersToString(filters: number[]): string;
1054
1058
 
@@ -1060,6 +1064,8 @@ export declare const CSSFunction: {
1060
1064
 
1061
1065
  export declare const CSSJSON: Parser<ValueUnit<any, string>>;
1062
1066
 
1067
+ export declare function cssLinear(stops: LinearStop[]): (t: number) => number;
1068
+
1063
1069
  export declare const CSSString: Parser<ValueUnit<string, string | undefined>>;
1064
1070
 
1065
1071
  export declare const CSSValues: {
@@ -1072,7 +1078,9 @@ export declare const CSSValueUnit: {
1072
1078
  Angle: Parser<ValueUnit<number, string>>;
1073
1079
  Time: Parser<ValueUnit<number, string>>;
1074
1080
  TimePercentage: Parser<ValueUnit<any, string | undefined>>;
1081
+ Frequency: Parser<ValueUnit<number, string>>;
1075
1082
  Resolution: Parser<ValueUnit<number, string>>;
1083
+ Flex: Parser<ValueUnit<number, string>>;
1076
1084
  Percentage: Parser<ValueUnit<any, string | undefined>>;
1077
1085
  Color: Parser<ValueUnit<any, string | undefined>>;
1078
1086
  Slash: Parser<ValueUnit<string, string>>;
@@ -1094,6 +1102,48 @@ export declare function debounce<T extends (...args: any[]) => any>(func: T, wai
1094
1102
 
1095
1103
  export declare function deCasteljau(t: number, points: number[]): number;
1096
1104
 
1105
+ export declare interface DecomposedMatrix2D {
1106
+ translateX: number;
1107
+ translateY: number;
1108
+ scaleX: number;
1109
+ scaleY: number;
1110
+ angle: number;
1111
+ skew: number;
1112
+ }
1113
+
1114
+ export declare interface DecomposedMatrix3D {
1115
+ translate: [number, number, number];
1116
+ scale: [number, number, number];
1117
+ skew: [number, number, number];
1118
+ quaternion: Vec4;
1119
+ perspective: Vec4;
1120
+ }
1121
+
1122
+ /**
1123
+ * Decompose a 2D CSS matrix(a, b, c, d, e, f) into translate, scale, rotation, and skew.
1124
+ *
1125
+ * The matrix maps like:
1126
+ * | a c e |
1127
+ * | b d f |
1128
+ * | 0 0 1 |
1129
+ */
1130
+ export declare function decomposeMatrix2D(a: number, b: number, c: number, d: number, e: number, f: number): DecomposedMatrix2D;
1131
+
1132
+ /**
1133
+ * Decompose a CSS matrix3d (16 values in column-major CSS order) into
1134
+ * translate, scale, skew, rotation (quaternion), and perspective.
1135
+ *
1136
+ * CSS `matrix3d(a1,b1,c1,d1, a2,b2,c2,d2, a3,b3,c3,d3, a4,b4,c4,d4)` maps to:
1137
+ * | a1 a2 a3 a4 |
1138
+ * | b1 b2 b3 b4 |
1139
+ * | c1 c2 c3 c4 |
1140
+ * | d1 d2 d3 d4 |
1141
+ * The parameter order is already column-major: [a1,b1,c1,d1, a2,b2,c2,d2, ...].
1142
+ *
1143
+ * Based on the "unmatrix" algorithm from the CSS Transforms spec.
1144
+ */
1145
+ export declare function decomposeMatrix3D(cssValues: number[]): DecomposedMatrix3D | null;
1146
+
1097
1147
  /**
1098
1148
  * Analytical sRGB gamut mapping based on Bjorn Ottosson's ok_color.h
1099
1149
  * https://bottosson.github.io/posts/gamutclipping/
@@ -1151,6 +1201,15 @@ export declare function easeOutQuad(t: number): number;
1151
1201
 
1152
1202
  export declare function easeOutSine(t: number): number;
1153
1203
 
1204
+ /**
1205
+ * Evaluate a math FunctionValue to a numeric ValueUnit.
1206
+ * Returns null if the expression can't be fully resolved.
1207
+ *
1208
+ * The result unit is determined by the first resolvable argument's unit,
1209
+ * since CSS requires type-compatible arguments.
1210
+ */
1211
+ export declare function evaluateMathFunction(fn: FunctionValue): ValueUnit | null;
1212
+
1154
1213
  /** Parser that always fails with the given message. */
1155
1214
  export declare function fail(message: string): Parser<never>;
1156
1215
 
@@ -1176,8 +1235,12 @@ export declare function findGamutIntersection(a_: number, b_: number, L1: number
1176
1235
 
1177
1236
  export declare const flattenObject: (obj: any) => Record<string, any>;
1178
1237
 
1238
+ export declare const FLEX_UNITS: readonly ["fr"];
1239
+
1179
1240
  export declare const FRAME_RATE: number;
1180
1241
 
1242
+ export declare const FREQUENCY_UNITS: readonly ["Hz", "kHz"];
1243
+
1181
1244
  export declare class FunctionValue<T = any, N extends string = string> {
1182
1245
  name: N;
1183
1246
  values: Array<ValueUnit<T> | FunctionValue<T>>;
@@ -1326,6 +1389,12 @@ export declare const integer: Parser<number>;
1326
1389
 
1327
1390
  export declare function interpBezier(t: number, points: number[][]): number[];
1328
1391
 
1392
+ /**
1393
+ * Interpolate between two decomposed 3D matrices at parameter t.
1394
+ * Uses slerp for rotation, lerp for everything else.
1395
+ */
1396
+ export declare function interpolateDecomposed(a: DecomposedMatrix3D, b: DecomposedMatrix3D, t: number): DecomposedMatrix3D;
1397
+
1329
1398
  export declare type InterpolatedVar<T> = {
1330
1399
  start: ValueUnit<T>;
1331
1400
  stop: ValueUnit<T>;
@@ -1399,7 +1468,7 @@ export declare class LCHColor<T = number> extends Color<T> {
1399
1468
  set h(value: T);
1400
1469
  }
1401
1470
 
1402
- export declare const LENGTH_UNITS: readonly ["px", "cm", "mm", "Q", "in", "pc", "pt", "em", "ex", "ch", "rem", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vb", "vi", "svw", "svh", "lvw", "lvh", "dvw", "dvh"];
1471
+ export declare const LENGTH_UNITS: readonly ["px", "cm", "mm", "Q", "in", "pc", "pt", "em", "ex", "ch", "cap", "ic", "rem", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vb", "vi", "svw", "svh", "svi", "svb", "svmin", "svmax", "lvw", "lvh", "lvi", "lvb", "lvmin", "lvmax", "dvw", "dvh", "dvi", "dvb", "dvmin", "dvmax", "cqw", "cqh", "cqi", "cqb", "cqmin", "cqmax"];
1403
1472
 
1404
1473
  export declare function lerp(t: number, start: number, end: number): number;
1405
1474
 
@@ -1419,6 +1488,24 @@ export declare class LinearSRGBColor<T = number> extends Color<T> {
1419
1488
  set b(value: T);
1420
1489
  }
1421
1490
 
1491
+ /**
1492
+ * CSS Easing Level 2 `linear()` — piecewise-linear timing function.
1493
+ *
1494
+ * Each stop is `{ output: number, input?: number }`.
1495
+ * - `output` is the easing output value (typically 0–1 but can overshoot).
1496
+ * - `input` is the progress percentage (0–100). If omitted, stops are
1497
+ * evenly distributed.
1498
+ *
1499
+ * Syntax examples:
1500
+ * linear(0, 0.25, 1) → three evenly-spaced stops
1501
+ * linear(0, 0.25 75%, 1) → second stop at 75% input
1502
+ * linear(0, 0.5 25% 75%, 1) → second stop spans 25%–75% (flat segment)
1503
+ */
1504
+ export declare interface LinearStop {
1505
+ output: number;
1506
+ input?: number;
1507
+ }
1508
+
1422
1509
  export declare function linearToAdobeRgb(c: number): number;
1423
1510
 
1424
1511
  export declare function linearToProPhoto(c: number): number;
@@ -1447,6 +1534,8 @@ number,
1447
1534
  number
1448
1535
  ];
1449
1536
 
1537
+ export declare type Mat4 = number[];
1538
+
1450
1539
  export declare interface MatrixValues {
1451
1540
  scaleX: number;
1452
1541
  scaleY: number;
@@ -1497,7 +1586,7 @@ export declare const normalizeColorUnit: (color: ValueUnit<Color<ValueUnit<numbe
1497
1586
 
1498
1587
  export declare const normalizeColorUnitComponent: (v: number, unit: string, colorSpace: ColorSpace, component: string, inverse?: boolean) => ValueUnit<number, string>;
1499
1588
 
1500
- export declare const normalizeColorUnits: (a: ValueUnit<Color<ValueUnit<number>>, "color">, b: ValueUnit<Color<ValueUnit<number>>, "color">, to?: ColorSpace, normalized?: boolean, inverse?: boolean, inplace?: boolean) => readonly [ValueUnit<RGBColor<ValueUnit<number, string | undefined>> | HSLColor<ValueUnit<number, string | undefined>> | HSVColor<ValueUnit<number, string | undefined>> | HWBColor<ValueUnit<number, string | undefined>> | LABColor<ValueUnit<number, string | undefined>> | LCHColor<ValueUnit<number, string | undefined>> | OKLABColor<ValueUnit<number, string | undefined>> | OKLCHColor<ValueUnit<number, string | undefined>> | XYZColor<ValueUnit<number, string | undefined>> | KelvinColor<ValueUnit<number, string | undefined>> | LinearSRGBColor<ValueUnit<number, string | undefined>> | DisplayP3Color<ValueUnit<number, string | undefined>> | AdobeRGBColor<ValueUnit<number, string | undefined>> | ProPhotoRGBColor<ValueUnit<number, string | undefined>> | Rec2020Color<ValueUnit<number, string | undefined>>, "color">, ValueUnit<RGBColor<ValueUnit<number, string | undefined>> | HSLColor<ValueUnit<number, string | undefined>> | HSVColor<ValueUnit<number, string | undefined>> | HWBColor<ValueUnit<number, string | undefined>> | LABColor<ValueUnit<number, string | undefined>> | LCHColor<ValueUnit<number, string | undefined>> | OKLABColor<ValueUnit<number, string | undefined>> | OKLCHColor<ValueUnit<number, string | undefined>> | XYZColor<ValueUnit<number, string | undefined>> | KelvinColor<ValueUnit<number, string | undefined>> | LinearSRGBColor<ValueUnit<number, string | undefined>> | DisplayP3Color<ValueUnit<number, string | undefined>> | AdobeRGBColor<ValueUnit<number, string | undefined>> | ProPhotoRGBColor<ValueUnit<number, string | undefined>> | Rec2020Color<ValueUnit<number, string | undefined>>, "color">];
1589
+ export declare const normalizeColorUnits: (a: ValueUnit<Color<ValueUnit<number>>, "color">, b: ValueUnit<Color<ValueUnit<number>>, "color">, to?: ColorSpace, normalized?: boolean, inverse?: boolean, inplace?: boolean, hueMethod?: HueInterpolationMethod) => readonly [ValueUnit<RGBColor<ValueUnit<number, string | undefined>> | HSLColor<ValueUnit<number, string | undefined>> | HSVColor<ValueUnit<number, string | undefined>> | HWBColor<ValueUnit<number, string | undefined>> | LABColor<ValueUnit<number, string | undefined>> | LCHColor<ValueUnit<number, string | undefined>> | OKLABColor<ValueUnit<number, string | undefined>> | OKLCHColor<ValueUnit<number, string | undefined>> | XYZColor<ValueUnit<number, string | undefined>> | KelvinColor<ValueUnit<number, string | undefined>> | LinearSRGBColor<ValueUnit<number, string | undefined>> | DisplayP3Color<ValueUnit<number, string | undefined>> | AdobeRGBColor<ValueUnit<number, string | undefined>> | ProPhotoRGBColor<ValueUnit<number, string | undefined>> | Rec2020Color<ValueUnit<number, string | undefined>>, "color">, ValueUnit<RGBColor<ValueUnit<number, string | undefined>> | HSLColor<ValueUnit<number, string | undefined>> | HSVColor<ValueUnit<number, string | undefined>> | HWBColor<ValueUnit<number, string | undefined>> | LABColor<ValueUnit<number, string | undefined>> | LCHColor<ValueUnit<number, string | undefined>> | OKLABColor<ValueUnit<number, string | undefined>> | OKLCHColor<ValueUnit<number, string | undefined>> | XYZColor<ValueUnit<number, string | undefined>> | KelvinColor<ValueUnit<number, string | undefined>> | LinearSRGBColor<ValueUnit<number, string | undefined>> | DisplayP3Color<ValueUnit<number, string | undefined>> | AdobeRGBColor<ValueUnit<number, string | undefined>> | ProPhotoRGBColor<ValueUnit<number, string | undefined>> | Rec2020Color<ValueUnit<number, string | undefined>>, "color">, HueInterpolationMethod | undefined];
1501
1590
 
1502
1591
  export declare const normalizeNumericUnits: (a: ValueUnit, b: ValueUnit, inplace?: boolean) => [ValueUnit, ValueUnit];
1503
1592
 
@@ -1615,12 +1704,17 @@ export declare class Rec2020Color<T = number> extends Color<T> {
1615
1704
 
1616
1705
  export declare function rec2020ToLinear(c: number): number;
1617
1706
 
1618
- export declare const RELATIVE_LENGTH_UNITS: readonly ["em", "ex", "ch", "rem", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vb", "vi", "svw", "svh", "lvw", "lvh", "dvw", "dvh"];
1707
+ /**
1708
+ * Recompose a 3D decomposed matrix back into a CSS matrix3d() value array (16 values, column-major CSS order).
1709
+ */
1710
+ export declare function recomposeMatrix3D(d: DecomposedMatrix3D): number[];
1711
+
1712
+ export declare const RELATIVE_LENGTH_UNITS: readonly ["em", "ex", "ch", "cap", "ic", "rem", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vb", "vi", "svw", "svh", "svi", "svb", "svmin", "svmax", "lvw", "lvh", "lvi", "lvb", "lvmin", "lvmax", "dvw", "dvh", "dvi", "dvb", "dvmin", "dvmax", "cqw", "cqh", "cqi", "cqb", "cqmin", "cqmax"];
1619
1713
 
1620
1714
  declare function requestAnimationFrame_2(callback: FrameRequestCallback): number | NodeJS.Timeout;
1621
1715
  export { requestAnimationFrame_2 as requestAnimationFrame }
1622
1716
 
1623
- export declare const RESOLUTION_UNITS: readonly ["dpi", "dpcm", "dppx", "cqw"];
1717
+ export declare const RESOLUTION_UNITS: readonly ["dpi", "dpcm", "dppx"];
1624
1718
 
1625
1719
  export declare function rgb2ColorFilter(color: RGBColor<number>): {
1626
1720
  values: number[];
@@ -1665,6 +1759,12 @@ export declare function seekPreviousValue<T>(ix: number, values: T[], pred: (f:
1665
1759
 
1666
1760
  export declare function sleep(ms: number): Promise<unknown>;
1667
1761
 
1762
+ /**
1763
+ * Spherical linear interpolation between two quaternions.
1764
+ * Both quaternions should be normalized.
1765
+ */
1766
+ export declare function slerp(qa: Vec4, qb: Vec4, t: number): Vec4;
1767
+
1668
1768
  export declare function smoothStep3(t: number): number;
1669
1769
 
1670
1770
  export declare function srgbToLinear(channel: number): number;
@@ -1736,13 +1836,13 @@ export declare const timingFunctions: {
1736
1836
  readonly "ease-in-out-expo": typeof easeInOutExpo;
1737
1837
  readonly smoothStep3: typeof smoothStep3;
1738
1838
  readonly "smooth-step-3": typeof smoothStep3;
1739
- readonly ease: (t: number) => number;
1740
- readonly "ease-in": (t: number) => number;
1741
- readonly "ease-out": (t: number) => number;
1742
- readonly "ease-in-out": (t: number) => number;
1743
- readonly "ease-in-back": (t: number) => number;
1744
- readonly "ease-out-back": (t: number) => number;
1745
- readonly "ease-in-out-back": (t: number) => number;
1839
+ readonly ease: (x: number) => number;
1840
+ readonly "ease-in": (x: number) => number;
1841
+ readonly "ease-out": (x: number) => number;
1842
+ readonly "ease-in-out": (x: number) => number;
1843
+ readonly "ease-in-back": (x: number) => number;
1844
+ readonly "ease-out-back": (x: number) => number;
1845
+ readonly "ease-in-out-back": (x: number) => number;
1746
1846
  readonly steps: typeof steppedEase;
1747
1847
  readonly "step-start": typeof stepStart;
1748
1848
  readonly "step-end": typeof stepEnd;
@@ -1775,7 +1875,7 @@ export declare const UNIT_RANGE: {
1775
1875
  };
1776
1876
  };
1777
1877
 
1778
- export declare const UNITS: readonly ["px", "cm", "mm", "Q", "in", "pc", "pt", "em", "ex", "ch", "rem", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vb", "vi", "svw", "svh", "lvw", "lvh", "dvw", "dvh", "s", "ms", "deg", "rad", "grad", "turn", "%", "dpi", "dpcm", "dppx", "cqw", "var", "calc", "string", "color", "", undefined];
1878
+ export declare const UNITS: readonly ["px", "cm", "mm", "Q", "in", "pc", "pt", "em", "ex", "ch", "cap", "ic", "rem", "lh", "rlh", "vw", "vh", "vmin", "vmax", "vb", "vi", "svw", "svh", "svi", "svb", "svmin", "svmax", "lvw", "lvh", "lvi", "lvb", "lvmin", "lvmax", "dvw", "dvh", "dvi", "dvb", "dvmin", "dvmax", "cqw", "cqh", "cqi", "cqb", "cqmin", "cqmax", "s", "ms", "deg", "rad", "grad", "turn", "%", "Hz", "kHz", "dpi", "dpcm", "dppx", "fr", "var", "calc", "string", "color", "", undefined];
1779
1879
 
1780
1880
  export declare const unpackMatrixValues: (value: FunctionValue) => MatrixValues;
1781
1881
 
@@ -1821,6 +1921,15 @@ export declare class ValueUnit<T = any, U = (typeof UNITS)[number] | string> {
1821
1921
  */
1822
1922
  export declare type Vec3 = [number, number, number];
1823
1923
 
1924
+ /**
1925
+ * CSS Transform Matrix Decomposition and Recomposition.
1926
+ *
1927
+ * Implements the CSSOM View spec algorithm (§15.1) for 2D matrices
1928
+ * and polar decomposition for 3D matrices.
1929
+ * Also includes quaternion slerp for smooth rotation interpolation.
1930
+ */
1931
+ export declare type Vec4 = [number, number, number, number];
1932
+
1824
1933
  export declare function waitUntil(condition: () => boolean, delay?: number): Promise<void>;
1825
1934
 
1826
1935
  export declare const WHITE_POINT_D50: Vec3;