@mkbabb/value.js 0.3.0 → 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
@@ -225,6 +225,7 @@ export declare const COLOR_NAMES: {
225
225
  readonly tan: "#d2b48c";
226
226
  readonly teal: "#008080";
227
227
  readonly thistle: "#d8bfd8";
228
+ readonly transparent: "rgba(0, 0, 0, 0)";
228
229
  readonly tomato: "#ff6347";
229
230
  readonly turquoise: "#40e0d0";
230
231
  readonly violet: "#ee82ee";
@@ -626,7 +627,7 @@ export declare const COLOR_SPACE_RANGES: {
626
627
  };
627
628
  readonly number: {
628
629
  readonly min: 0;
629
- readonly max: 100;
630
+ readonly max: 1;
630
631
  };
631
632
  };
632
633
  readonly a: {
@@ -668,7 +669,7 @@ export declare const COLOR_SPACE_RANGES: {
668
669
  };
669
670
  readonly number: {
670
671
  readonly min: 0;
671
- readonly max: 100;
672
+ readonly max: 1;
672
673
  };
673
674
  };
674
675
  readonly c: {
@@ -1032,12 +1033,16 @@ export declare function convertToDegrees(value: number, unit: (typeof ANGLE_UNIT
1032
1033
 
1033
1034
  export declare function convertToDPI(value: number, unit: (typeof RESOLUTION_UNITS)[number]): number;
1034
1035
 
1036
+ export declare function convertToHz(value: number, unit: (typeof FREQUENCY_UNITS)[number]): number;
1037
+
1035
1038
  export declare function convertToMs(value: number, unit: (typeof TIME_UNITS)[number]): number;
1036
1039
 
1037
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;
1038
1041
 
1039
1042
  export declare function createHash(algorithm: string, data: string): Promise<string>;
1040
1043
 
1044
+ export declare const CSS_WIDE_KEYWORDS: readonly ["inherit", "initial", "unset", "revert", "revert-layer"];
1045
+
1041
1046
  export declare const CSSColor: {
1042
1047
  Value: Parser<ValueUnit<any, string | undefined>>;
1043
1048
  colorValue: Parser<ValueUnit<any, string | undefined>>;
@@ -1047,7 +1052,7 @@ export declare const CSSColor: {
1047
1052
  div: Parser<string>;
1048
1053
  };
1049
1054
 
1050
- 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;
1051
1056
 
1052
1057
  export declare function cssFiltersToString(filters: number[]): string;
1053
1058
 
@@ -1059,6 +1064,8 @@ export declare const CSSFunction: {
1059
1064
 
1060
1065
  export declare const CSSJSON: Parser<ValueUnit<any, string>>;
1061
1066
 
1067
+ export declare function cssLinear(stops: LinearStop[]): (t: number) => number;
1068
+
1062
1069
  export declare const CSSString: Parser<ValueUnit<string, string | undefined>>;
1063
1070
 
1064
1071
  export declare const CSSValues: {
@@ -1071,7 +1078,9 @@ export declare const CSSValueUnit: {
1071
1078
  Angle: Parser<ValueUnit<number, string>>;
1072
1079
  Time: Parser<ValueUnit<number, string>>;
1073
1080
  TimePercentage: Parser<ValueUnit<any, string | undefined>>;
1081
+ Frequency: Parser<ValueUnit<number, string>>;
1074
1082
  Resolution: Parser<ValueUnit<number, string>>;
1083
+ Flex: Parser<ValueUnit<number, string>>;
1075
1084
  Percentage: Parser<ValueUnit<any, string | undefined>>;
1076
1085
  Color: Parser<ValueUnit<any, string | undefined>>;
1077
1086
  Slash: Parser<ValueUnit<string, string>>;
@@ -1093,6 +1102,48 @@ export declare function debounce<T extends (...args: any[]) => any>(func: T, wai
1093
1102
 
1094
1103
  export declare function deCasteljau(t: number, points: number[]): number;
1095
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
+
1096
1147
  /**
1097
1148
  * Analytical sRGB gamut mapping based on Bjorn Ottosson's ok_color.h
1098
1149
  * https://bottosson.github.io/posts/gamutclipping/
@@ -1150,6 +1201,15 @@ export declare function easeOutQuad(t: number): number;
1150
1201
 
1151
1202
  export declare function easeOutSine(t: number): number;
1152
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
+
1153
1213
  /** Parser that always fails with the given message. */
1154
1214
  export declare function fail(message: string): Parser<never>;
1155
1215
 
@@ -1175,8 +1235,12 @@ export declare function findGamutIntersection(a_: number, b_: number, L1: number
1175
1235
 
1176
1236
  export declare const flattenObject: (obj: any) => Record<string, any>;
1177
1237
 
1238
+ export declare const FLEX_UNITS: readonly ["fr"];
1239
+
1178
1240
  export declare const FRAME_RATE: number;
1179
1241
 
1242
+ export declare const FREQUENCY_UNITS: readonly ["Hz", "kHz"];
1243
+
1180
1244
  export declare class FunctionValue<T = any, N extends string = string> {
1181
1245
  name: N;
1182
1246
  values: Array<ValueUnit<T> | FunctionValue<T>>;
@@ -1325,6 +1389,12 @@ export declare const integer: Parser<number>;
1325
1389
 
1326
1390
  export declare function interpBezier(t: number, points: number[][]): number[];
1327
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
+
1328
1398
  export declare type InterpolatedVar<T> = {
1329
1399
  start: ValueUnit<T>;
1330
1400
  stop: ValueUnit<T>;
@@ -1398,7 +1468,7 @@ export declare class LCHColor<T = number> extends Color<T> {
1398
1468
  set h(value: T);
1399
1469
  }
1400
1470
 
1401
- 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"];
1402
1472
 
1403
1473
  export declare function lerp(t: number, start: number, end: number): number;
1404
1474
 
@@ -1418,6 +1488,24 @@ export declare class LinearSRGBColor<T = number> extends Color<T> {
1418
1488
  set b(value: T);
1419
1489
  }
1420
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
+
1421
1509
  export declare function linearToAdobeRgb(c: number): number;
1422
1510
 
1423
1511
  export declare function linearToProPhoto(c: number): number;
@@ -1446,6 +1534,8 @@ number,
1446
1534
  number
1447
1535
  ];
1448
1536
 
1537
+ export declare type Mat4 = number[];
1538
+
1449
1539
  export declare interface MatrixValues {
1450
1540
  scaleX: number;
1451
1541
  scaleY: number;
@@ -1496,7 +1586,7 @@ export declare const normalizeColorUnit: (color: ValueUnit<Color<ValueUnit<numbe
1496
1586
 
1497
1587
  export declare const normalizeColorUnitComponent: (v: number, unit: string, colorSpace: ColorSpace, component: string, inverse?: boolean) => ValueUnit<number, string>;
1498
1588
 
1499
- 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];
1500
1590
 
1501
1591
  export declare const normalizeNumericUnits: (a: ValueUnit, b: ValueUnit, inplace?: boolean) => [ValueUnit, ValueUnit];
1502
1592
 
@@ -1614,12 +1704,17 @@ export declare class Rec2020Color<T = number> extends Color<T> {
1614
1704
 
1615
1705
  export declare function rec2020ToLinear(c: number): number;
1616
1706
 
1617
- 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"];
1618
1713
 
1619
1714
  declare function requestAnimationFrame_2(callback: FrameRequestCallback): number | NodeJS.Timeout;
1620
1715
  export { requestAnimationFrame_2 as requestAnimationFrame }
1621
1716
 
1622
- export declare const RESOLUTION_UNITS: readonly ["dpi", "dpcm", "dppx", "cqw"];
1717
+ export declare const RESOLUTION_UNITS: readonly ["dpi", "dpcm", "dppx"];
1623
1718
 
1624
1719
  export declare function rgb2ColorFilter(color: RGBColor<number>): {
1625
1720
  values: number[];
@@ -1664,6 +1759,12 @@ export declare function seekPreviousValue<T>(ix: number, values: T[], pred: (f:
1664
1759
 
1665
1760
  export declare function sleep(ms: number): Promise<unknown>;
1666
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
+
1667
1768
  export declare function smoothStep3(t: number): number;
1668
1769
 
1669
1770
  export declare function srgbToLinear(channel: number): number;
@@ -1735,13 +1836,13 @@ export declare const timingFunctions: {
1735
1836
  readonly "ease-in-out-expo": typeof easeInOutExpo;
1736
1837
  readonly smoothStep3: typeof smoothStep3;
1737
1838
  readonly "smooth-step-3": typeof smoothStep3;
1738
- readonly ease: (t: number) => number;
1739
- readonly "ease-in": (t: number) => number;
1740
- readonly "ease-out": (t: number) => number;
1741
- readonly "ease-in-out": (t: number) => number;
1742
- readonly "ease-in-back": (t: number) => number;
1743
- readonly "ease-out-back": (t: number) => number;
1744
- 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;
1745
1846
  readonly steps: typeof steppedEase;
1746
1847
  readonly "step-start": typeof stepStart;
1747
1848
  readonly "step-end": typeof stepEnd;
@@ -1774,7 +1875,7 @@ export declare const UNIT_RANGE: {
1774
1875
  };
1775
1876
  };
1776
1877
 
1777
- 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];
1778
1879
 
1779
1880
  export declare const unpackMatrixValues: (value: FunctionValue) => MatrixValues;
1780
1881
 
@@ -1820,6 +1921,15 @@ export declare class ValueUnit<T = any, U = (typeof UNITS)[number] | string> {
1820
1921
  */
1821
1922
  export declare type Vec3 = [number, number, number];
1822
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
+
1823
1933
  export declare function waitUntil(condition: () => boolean, delay?: number): Promise<void>;
1824
1934
 
1825
1935
  export declare const WHITE_POINT_D50: Vec3;