react-smart-copy 1.17.0 → 1.17.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/dist/color.cjs +53 -20
- package/dist/color.cjs.map +1 -1
- package/dist/color.js +53 -20
- package/dist/color.js.map +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/rich.cjs +53 -20
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.js +53 -20
- package/dist/rich.js.map +1 -1
- package/package.json +3 -2
package/dist/rich.cjs
CHANGED
|
@@ -474,6 +474,18 @@ const fromLinear = (c) => {
|
|
|
474
474
|
const abs = Math.abs(c);
|
|
475
475
|
return abs > .0031308 ? Math.sign(c) * (1.055 * abs ** (1 / 2.4) - .055) : 12.92 * c;
|
|
476
476
|
};
|
|
477
|
+
/** Applies `f` to each component; the result stays a three-component vector. */
|
|
478
|
+
const map3 = ([x, y, z], f) => [
|
|
479
|
+
f(x, 0),
|
|
480
|
+
f(y, 1),
|
|
481
|
+
f(z, 2)
|
|
482
|
+
];
|
|
483
|
+
/** Three numbers as a vector, or null when one is missing. */
|
|
484
|
+
const vec3 = ([x, y, z]) => typeof x === "number" && typeof y === "number" && typeof z === "number" ? [
|
|
485
|
+
x,
|
|
486
|
+
y,
|
|
487
|
+
z
|
|
488
|
+
] : null;
|
|
477
489
|
const linearRgb = (c) => [
|
|
478
490
|
toLinear(c.r),
|
|
479
491
|
toLinear(c.g),
|
|
@@ -655,12 +667,12 @@ const OKLAB_TO_LMS = [
|
|
|
655
667
|
const toXyz = (c) => mul(SRGB_TO_XYZ, linearRgb(c));
|
|
656
668
|
const fromXyz = (xyz, alpha) => fromLinearRgb(mul(XYZ_TO_SRGB, xyz), alpha);
|
|
657
669
|
/** Display P3 channels (gamma-encoded, 0 to 1 inside P3). */
|
|
658
|
-
const toP3 = (c) => mul(XYZ_TO_P3, toXyz(c))
|
|
659
|
-
const fromP3 = (p3, alpha) => fromXyz(mul(P3_TO_XYZ, p3
|
|
670
|
+
const toP3 = (c) => map3(mul(XYZ_TO_P3, toXyz(c)), fromLinear);
|
|
671
|
+
const fromP3 = (p3, alpha) => fromXyz(mul(P3_TO_XYZ, map3(p3, toLinear)), alpha);
|
|
660
672
|
const fromXyzD50 = (xyz, alpha) => fromXyz(mul(D50_TO_D65, xyz), alpha);
|
|
661
673
|
/** OKLab: L in [0, 1], a and b around ±0.4. */
|
|
662
|
-
const toOklab = (c) => mul(LMS_TO_OKLAB, mul(LRGB_TO_LMS, linearRgb(c))
|
|
663
|
-
const fromOklab = (lab, alpha) => fromLinearRgb(mul(LMS_TO_LRGB, mul(OKLAB_TO_LMS, lab)
|
|
674
|
+
const toOklab = (c) => mul(LMS_TO_OKLAB, map3(mul(LRGB_TO_LMS, linearRgb(c)), Math.cbrt));
|
|
675
|
+
const fromOklab = (lab, alpha) => fromLinearRgb(mul(LMS_TO_LRGB, map3(mul(OKLAB_TO_LMS, lab), (v) => v ** 3)), alpha);
|
|
664
676
|
const D50_WHITE = [
|
|
665
677
|
.3457 / .3585,
|
|
666
678
|
1,
|
|
@@ -670,7 +682,7 @@ const KAPPA = 24389 / 27;
|
|
|
670
682
|
const EPSILON = 216 / 24389;
|
|
671
683
|
/** CIE Lab (D50): L in [0, 100], a and b around ±125. */
|
|
672
684
|
const toLab = (c) => {
|
|
673
|
-
const [x, y, z] = mul(D65_TO_D50, toXyz(c))
|
|
685
|
+
const [x, y, z] = map3(mul(D65_TO_D50, toXyz(c)), (v, i) => v / D50_WHITE[i]);
|
|
674
686
|
const f = (v) => v > EPSILON ? Math.cbrt(v) : (KAPPA * v + 16) / 116;
|
|
675
687
|
const [fx, fy, fz] = [
|
|
676
688
|
f(x),
|
|
@@ -692,7 +704,7 @@ const fromLab = ([l, a, b], alpha) => {
|
|
|
692
704
|
l > KAPPA * EPSILON ? fy ** 3 : l / KAPPA,
|
|
693
705
|
fz ** 3 > EPSILON ? fz ** 3 : (116 * fz - 16) / KAPPA
|
|
694
706
|
];
|
|
695
|
-
return fromXyzD50(xyz
|
|
707
|
+
return fromXyzD50(map3(xyz, (v, i) => v * D50_WHITE[i]), alpha);
|
|
696
708
|
};
|
|
697
709
|
/** Lab-like to its polar form: lightness, chroma, and hue in degrees from 0 to 360. */
|
|
698
710
|
const toPolar = ([l, a, b]) => [
|
|
@@ -705,22 +717,37 @@ const fromPolar = ([l, c, h]) => [
|
|
|
705
717
|
c * Math.cos(h * Math.PI / 180),
|
|
706
718
|
c * Math.sin(h * Math.PI / 180)
|
|
707
719
|
];
|
|
708
|
-
|
|
720
|
+
const clip01 = (v) => Math.min(1, Math.max(0, v));
|
|
721
|
+
/**
|
|
722
|
+
* Below this spread between channels a colour is grey: what is left is rounding error from
|
|
723
|
+
* converting it (from Lab, OKLCH, P3...), and its hue and saturation would be noise. The
|
|
724
|
+
* faintest real tint in 8-bit sRGB, such as #fffffe, has a spread of about 0.004.
|
|
725
|
+
*/
|
|
726
|
+
const GREY = 1e-9;
|
|
727
|
+
/**
|
|
728
|
+
* Hue, saturation and lightness of a colour inside sRGB (hue 0 for greys), with s and l in [0, 1].
|
|
729
|
+
* Channels are clipped first: colours count as inside sRGB within rounding error, a little past 0 or 1.
|
|
730
|
+
*/
|
|
709
731
|
function toHsl(c) {
|
|
710
|
-
const
|
|
711
|
-
|
|
732
|
+
const [r, g, b] = map3([
|
|
733
|
+
c.r,
|
|
734
|
+
c.g,
|
|
735
|
+
c.b
|
|
736
|
+
], clip01);
|
|
737
|
+
const max = Math.max(r, g, b);
|
|
738
|
+
const min = Math.min(r, g, b);
|
|
712
739
|
const l = (max + min) / 2;
|
|
713
740
|
const d = max - min;
|
|
714
|
-
if (d
|
|
741
|
+
if (d < GREY) return [
|
|
715
742
|
0,
|
|
716
743
|
0,
|
|
717
744
|
l
|
|
718
745
|
];
|
|
719
746
|
const s = (max - l) / Math.min(l, 1 - l);
|
|
720
747
|
let h;
|
|
721
|
-
if (max ===
|
|
722
|
-
else if (max ===
|
|
723
|
-
else h = (
|
|
748
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0);
|
|
749
|
+
else if (max === g) h = (b - r) / d + 2;
|
|
750
|
+
else h = (r - g) / d + 4;
|
|
724
751
|
return [
|
|
725
752
|
h * 60,
|
|
726
753
|
s,
|
|
@@ -744,13 +771,18 @@ function fromHwb(h, w, b, alpha) {
|
|
|
744
771
|
const scale = (v) => v * (1 - w - b) + w;
|
|
745
772
|
return color(scale(pure.r), scale(pure.g), scale(pure.b), alpha);
|
|
746
773
|
}
|
|
747
|
-
/** Hue, whiteness and blackness of an sRGB colour, with w and b in [0, 1]. */
|
|
774
|
+
/** Hue, whiteness and blackness of an sRGB colour, with w and b in [0, 1] (channels clipped, as in `toHsl`). */
|
|
748
775
|
function toHwb(c) {
|
|
749
776
|
const [h] = toHsl(c);
|
|
777
|
+
const [r, g, b] = map3([
|
|
778
|
+
c.r,
|
|
779
|
+
c.g,
|
|
780
|
+
c.b
|
|
781
|
+
], clip01);
|
|
750
782
|
return [
|
|
751
783
|
h,
|
|
752
|
-
Math.min(
|
|
753
|
-
1 - Math.max(
|
|
784
|
+
Math.min(r, g, b),
|
|
785
|
+
1 - Math.max(r, g, b)
|
|
754
786
|
];
|
|
755
787
|
}
|
|
756
788
|
/** Distance in OKLab: about 0.02 is the smallest difference people notice. */
|
|
@@ -764,9 +796,8 @@ const channels = (c, gamut) => gamut === "srgb" ? [
|
|
|
764
796
|
c.g,
|
|
765
797
|
c.b
|
|
766
798
|
] : toP3(c);
|
|
767
|
-
const clip01 = (v) => Math.min(1, Math.max(0, v));
|
|
768
799
|
const clipTo = (c, gamut) => {
|
|
769
|
-
const [x, y, z] = channels(c, gamut)
|
|
800
|
+
const [x, y, z] = map3(channels(c, gamut), clip01);
|
|
770
801
|
return gamut === "srgb" ? color(x, y, z, c.alpha) : fromP3([
|
|
771
802
|
x,
|
|
772
803
|
y,
|
|
@@ -943,7 +974,8 @@ function split(args) {
|
|
|
943
974
|
function rgb(parts, legacy) {
|
|
944
975
|
if (legacy && new Set(parts.map((part) => part.kind)).size !== 1) return null;
|
|
945
976
|
const values = parts.map((part) => amount(part, 255, ["number", "percent"]));
|
|
946
|
-
|
|
977
|
+
const vector = vec3(values);
|
|
978
|
+
return vector === null ? null : map3(vector, (v) => clamp(v, 0, 255) / 255);
|
|
947
979
|
}
|
|
948
980
|
const PREDEFINED = {
|
|
949
981
|
srgb: ([r, g, b], alpha) => color(r, g, b, alpha),
|
|
@@ -962,7 +994,8 @@ function predefined(args) {
|
|
|
962
994
|
if (convert === void 0 || parsed === null || parsed.legacy) return null;
|
|
963
995
|
const values = parsed.parts.map((part) => amount(part, 1, ["number", "percent"]));
|
|
964
996
|
const alpha = alphaOf(parsed.alpha);
|
|
965
|
-
|
|
997
|
+
const vector = vec3(values);
|
|
998
|
+
return vector === null || alpha === null ? null : convert(vector, alpha);
|
|
966
999
|
}
|
|
967
1000
|
function functional(name, args) {
|
|
968
1001
|
if (name === "color") return predefined(args);
|