@wistia/ui 0.13.7 → 0.13.8-beta.3631de1a.e2e0ac7
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/index.cjs +91 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +91 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
/*
|
|
3
|
-
* @license @wistia/ui v0.13.
|
|
3
|
+
* @license @wistia/ui v0.13.8-beta.3631de1a.e2e0ac7
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) 2024-2025, Wistia, Inc. and its affiliates.
|
|
6
6
|
*
|
|
@@ -148,6 +148,7 @@ __export(index_exports, {
|
|
|
148
148
|
ValueNameOrHexCode: () => ValueNameOrHexCode,
|
|
149
149
|
ValueSwatch: () => ValueSwatch,
|
|
150
150
|
WistiaLogo: () => WistiaLogo,
|
|
151
|
+
calculateContrast: () => calculateContrast,
|
|
151
152
|
colorSchemeOptions: () => colorSchemeOptions,
|
|
152
153
|
copyToClipboard: () => copyToClipboard,
|
|
153
154
|
dateTime: () => dateTime,
|
|
@@ -1453,8 +1454,9 @@ var import_styled_components7 = require("styled-components");
|
|
|
1453
1454
|
var zIndexTokens = import_styled_components7.css`
|
|
1454
1455
|
--wui-zindex-under: -1;
|
|
1455
1456
|
--wui-zindex-backdrop: 500;
|
|
1456
|
-
--wui-zindex-modal: 500;
|
|
1457
1457
|
--wui-zindex-menu: 500;
|
|
1458
|
+
--wui-zindex-modal: 500;
|
|
1459
|
+
--wui-zindex-popover: 500;
|
|
1458
1460
|
--wui-zindex-select: 500;
|
|
1459
1461
|
--wui-zindex-tooltip: 500;
|
|
1460
1462
|
`;
|
|
@@ -9760,6 +9762,16 @@ var compositeOverWhite = (color, alpha = 1) => {
|
|
|
9760
9762
|
b: compositeChannel(colorAsRgb.b)
|
|
9761
9763
|
};
|
|
9762
9764
|
};
|
|
9765
|
+
var calculateContrast = ({
|
|
9766
|
+
backgroundColor,
|
|
9767
|
+
foregroundColor = DEFAULT_COLOR_FOR_COMPARISON,
|
|
9768
|
+
backgroundOpacity = DEFAULT_OPACITY_FOR_CONTRAST_CALCULATION
|
|
9769
|
+
}) => {
|
|
9770
|
+
const backgroundColorAsRgb = convertToRgb(backgroundColor);
|
|
9771
|
+
const foregroundColorAsRgb = convertToRgb(foregroundColor);
|
|
9772
|
+
const compositeBackground = compositeOverWhite(backgroundColorAsRgb, backgroundOpacity);
|
|
9773
|
+
return (0, import_fn3.wcagContrast)(compositeBackground, foregroundColorAsRgb);
|
|
9774
|
+
};
|
|
9763
9775
|
var snapValueToEdges = (value) => {
|
|
9764
9776
|
if (value > 1 - VALUE_CHANNEL_SNAP_EPSILON) {
|
|
9765
9777
|
return 1;
|
|
@@ -9782,13 +9794,15 @@ var updateSearchBounds = (searchingBrighter, contrast, minContrast, midValue, se
|
|
|
9782
9794
|
return { newSearchLow: searchLow, newSearchHigh: midValue };
|
|
9783
9795
|
};
|
|
9784
9796
|
var getAccessibleColorByValueChannelChange = ({
|
|
9785
|
-
|
|
9797
|
+
originalColor,
|
|
9786
9798
|
colorForComparison,
|
|
9787
9799
|
minContrast,
|
|
9788
9800
|
maxIterations = 50,
|
|
9789
9801
|
direction,
|
|
9790
|
-
opacityForContrastCalculation
|
|
9802
|
+
opacityForContrastCalculation,
|
|
9803
|
+
shouldConvertToHex = true
|
|
9791
9804
|
}) => {
|
|
9805
|
+
const originalHsv = convertToHsv(originalColor);
|
|
9792
9806
|
const searchingBrighter = direction === "brighter";
|
|
9793
9807
|
const lowValue = searchingBrighter ? originalHsv.v : 0;
|
|
9794
9808
|
const highValue = searchingBrighter ? 1 : originalHsv.v;
|
|
@@ -9799,10 +9813,11 @@ var getAccessibleColorByValueChannelChange = ({
|
|
|
9799
9813
|
v: extremeValue,
|
|
9800
9814
|
mode: "hsv"
|
|
9801
9815
|
};
|
|
9802
|
-
const extremeContrast = (
|
|
9803
|
-
|
|
9804
|
-
colorForComparison
|
|
9805
|
-
|
|
9816
|
+
const extremeContrast = calculateContrast({
|
|
9817
|
+
backgroundColor: shouldConvertToHex ? (0, import_fn3.formatHex)(extremeVariant) : extremeVariant,
|
|
9818
|
+
foregroundColor: colorForComparison,
|
|
9819
|
+
backgroundOpacity: opacityForContrastCalculation
|
|
9820
|
+
});
|
|
9806
9821
|
if (extremeContrast < minContrast) {
|
|
9807
9822
|
return null;
|
|
9808
9823
|
}
|
|
@@ -9818,10 +9833,11 @@ var getAccessibleColorByValueChannelChange = ({
|
|
|
9818
9833
|
v: midValue,
|
|
9819
9834
|
mode: "hsv"
|
|
9820
9835
|
};
|
|
9821
|
-
const contrast = (
|
|
9822
|
-
|
|
9823
|
-
colorForComparison
|
|
9824
|
-
|
|
9836
|
+
const contrast = calculateContrast({
|
|
9837
|
+
backgroundColor: shouldConvertToHex ? (0, import_fn3.formatHex)(candidateHsv) : candidateHsv,
|
|
9838
|
+
foregroundColor: colorForComparison,
|
|
9839
|
+
backgroundOpacity: opacityForContrastCalculation
|
|
9840
|
+
});
|
|
9825
9841
|
if (contrast >= minContrast) {
|
|
9826
9842
|
bestSoFar = candidateHsv;
|
|
9827
9843
|
}
|
|
@@ -9841,7 +9857,7 @@ var getAccessibleColorByValueChannelChange = ({
|
|
|
9841
9857
|
}
|
|
9842
9858
|
return bestSoFar;
|
|
9843
9859
|
};
|
|
9844
|
-
var chooseClosestDerivativeToOriginal = (brighterOption, darkerOption,
|
|
9860
|
+
var chooseClosestDerivativeToOriginal = (brighterOption, darkerOption, originalColor) => {
|
|
9845
9861
|
const hsvDifference = (0, import_fn3.differenceEuclidean)("hsv");
|
|
9846
9862
|
if (!brighterOption && !darkerOption) {
|
|
9847
9863
|
return null;
|
|
@@ -9852,8 +9868,8 @@ var chooseClosestDerivativeToOriginal = (brighterOption, darkerOption, originalH
|
|
|
9852
9868
|
if (!darkerOption && brighterOption != null) {
|
|
9853
9869
|
return brighterOption;
|
|
9854
9870
|
}
|
|
9855
|
-
const brighterDifference = brighterOption === null ? Infinity : hsvDifference(
|
|
9856
|
-
const darkerDifference = darkerOption === null ? Infinity : hsvDifference(
|
|
9871
|
+
const brighterDifference = brighterOption === null ? Infinity : hsvDifference(originalColor, brighterOption);
|
|
9872
|
+
const darkerDifference = darkerOption === null ? Infinity : hsvDifference(originalColor, darkerOption);
|
|
9857
9873
|
if (brighterDifference <= darkerDifference && brighterOption != null) {
|
|
9858
9874
|
return brighterOption;
|
|
9859
9875
|
}
|
|
@@ -9863,12 +9879,13 @@ var chooseClosestDerivativeToOriginal = (brighterOption, darkerOption, originalH
|
|
|
9863
9879
|
throw new Error("Unable to determine the best accessible color variant");
|
|
9864
9880
|
};
|
|
9865
9881
|
var getAccessibleColorBySaturationAndValueChange = ({
|
|
9866
|
-
|
|
9882
|
+
originalColor,
|
|
9867
9883
|
colorForComparison,
|
|
9868
9884
|
minContrast,
|
|
9869
9885
|
direction,
|
|
9870
9886
|
opacityForContrastCalculation
|
|
9871
9887
|
}) => {
|
|
9888
|
+
const originalHsv = convertToHsv(originalColor);
|
|
9872
9889
|
const hsvDifference = (0, import_fn3.differenceEuclidean)("hsv");
|
|
9873
9890
|
const maxIterations = 50;
|
|
9874
9891
|
let lowStep = 0;
|
|
@@ -9894,7 +9911,11 @@ var getAccessibleColorBySaturationAndValueChange = ({
|
|
|
9894
9911
|
};
|
|
9895
9912
|
};
|
|
9896
9913
|
const checkContrast = (hsv) => {
|
|
9897
|
-
return (
|
|
9914
|
+
return calculateContrast({
|
|
9915
|
+
backgroundColor: (0, import_fn3.formatHex)(hsv),
|
|
9916
|
+
foregroundColor: colorForComparison,
|
|
9917
|
+
backgroundOpacity: opacityForContrastCalculation
|
|
9918
|
+
});
|
|
9898
9919
|
};
|
|
9899
9920
|
const extremeHsv = getHsvForStep(highStep);
|
|
9900
9921
|
if (checkContrast(extremeHsv) < minContrast) {
|
|
@@ -9923,7 +9944,7 @@ var getAccessibleColorBySaturationAndValueChange = ({
|
|
|
9923
9944
|
return bestCandidate;
|
|
9924
9945
|
};
|
|
9925
9946
|
var getAccessibleColorInDirection = ({
|
|
9926
|
-
|
|
9947
|
+
originalColor,
|
|
9927
9948
|
colorForComparison,
|
|
9928
9949
|
minContrast,
|
|
9929
9950
|
maxIterations = 50,
|
|
@@ -9931,7 +9952,7 @@ var getAccessibleColorInDirection = ({
|
|
|
9931
9952
|
opacityForContrastCalculation
|
|
9932
9953
|
}) => {
|
|
9933
9954
|
const valueResult = getAccessibleColorByValueChannelChange({
|
|
9934
|
-
|
|
9955
|
+
originalColor,
|
|
9935
9956
|
colorForComparison,
|
|
9936
9957
|
minContrast,
|
|
9937
9958
|
maxIterations,
|
|
@@ -9942,7 +9963,7 @@ var getAccessibleColorInDirection = ({
|
|
|
9942
9963
|
return valueResult;
|
|
9943
9964
|
}
|
|
9944
9965
|
return getAccessibleColorBySaturationAndValueChange({
|
|
9945
|
-
|
|
9966
|
+
originalColor,
|
|
9946
9967
|
colorForComparison,
|
|
9947
9968
|
minContrast,
|
|
9948
9969
|
direction,
|
|
@@ -9950,21 +9971,23 @@ var getAccessibleColorInDirection = ({
|
|
|
9950
9971
|
});
|
|
9951
9972
|
};
|
|
9952
9973
|
var getAccessibleColor = ({
|
|
9953
|
-
|
|
9974
|
+
originalColor,
|
|
9954
9975
|
colorForComparison,
|
|
9955
9976
|
minContrast = DEFAULT_MIN_CONTRAST,
|
|
9956
9977
|
maxIterations = 50,
|
|
9957
9978
|
opacityForContrastCalculation
|
|
9958
9979
|
}) => {
|
|
9959
|
-
const
|
|
9960
|
-
|
|
9961
|
-
|
|
9962
|
-
|
|
9980
|
+
const originalColorAsHsv = convertToHsv(originalColor);
|
|
9981
|
+
const originalContrast = calculateContrast({
|
|
9982
|
+
backgroundColor: (0, import_fn3.formatHex)(originalColorAsHsv),
|
|
9983
|
+
foregroundColor: colorForComparison,
|
|
9984
|
+
backgroundOpacity: opacityForContrastCalculation
|
|
9985
|
+
});
|
|
9963
9986
|
if (originalContrast >= minContrast) {
|
|
9964
|
-
return
|
|
9987
|
+
return convertToHsv(originalColor);
|
|
9965
9988
|
}
|
|
9966
9989
|
const brighterOption = getAccessibleColorInDirection({
|
|
9967
|
-
|
|
9990
|
+
originalColor,
|
|
9968
9991
|
colorForComparison,
|
|
9969
9992
|
minContrast,
|
|
9970
9993
|
maxIterations,
|
|
@@ -9972,43 +9995,45 @@ var getAccessibleColor = ({
|
|
|
9972
9995
|
opacityForContrastCalculation
|
|
9973
9996
|
});
|
|
9974
9997
|
const darkerOption = getAccessibleColorInDirection({
|
|
9975
|
-
|
|
9998
|
+
originalColor,
|
|
9976
9999
|
colorForComparison,
|
|
9977
10000
|
minContrast,
|
|
9978
10001
|
maxIterations,
|
|
9979
10002
|
direction: "darker",
|
|
9980
10003
|
opacityForContrastCalculation
|
|
9981
10004
|
});
|
|
9982
|
-
const result = chooseClosestDerivativeToOriginal(brighterOption, darkerOption,
|
|
10005
|
+
const result = chooseClosestDerivativeToOriginal(brighterOption, darkerOption, originalColor);
|
|
9983
10006
|
if (result == null) {
|
|
9984
10007
|
throw new Error(
|
|
9985
|
-
`Unable to get accessible derivative for ${(0, import_fn3.formatHex)(
|
|
10008
|
+
`Unable to get accessible derivative for ${(0, import_fn3.formatHex)(originalColor)} at minimum contrast ratio ${minContrast}`
|
|
9986
10009
|
);
|
|
9987
10010
|
}
|
|
9988
10011
|
return result;
|
|
9989
10012
|
};
|
|
9990
10013
|
var hasAccessibleDerivatives = ({
|
|
9991
|
-
|
|
10014
|
+
originalColor,
|
|
9992
10015
|
colorForComparison,
|
|
9993
10016
|
minContrast = DEFAULT_MIN_CONTRAST,
|
|
9994
10017
|
opacityForContrastCalculation
|
|
9995
10018
|
}) => {
|
|
9996
|
-
const
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
|
|
10019
|
+
const originalColorAsHsv = convertToHsv(originalColor);
|
|
10020
|
+
const originalContrast = calculateContrast({
|
|
10021
|
+
backgroundColor: (0, import_fn3.formatHex)(originalColorAsHsv),
|
|
10022
|
+
foregroundColor: colorForComparison,
|
|
10023
|
+
backgroundOpacity: opacityForContrastCalculation
|
|
10024
|
+
});
|
|
10000
10025
|
if (originalContrast >= minContrast) {
|
|
10001
10026
|
return true;
|
|
10002
10027
|
}
|
|
10003
10028
|
const brighterOption = getAccessibleColorInDirection({
|
|
10004
|
-
|
|
10029
|
+
originalColor,
|
|
10005
10030
|
colorForComparison,
|
|
10006
10031
|
minContrast,
|
|
10007
10032
|
direction: "brighter",
|
|
10008
10033
|
opacityForContrastCalculation
|
|
10009
10034
|
});
|
|
10010
10035
|
const darkerOption = getAccessibleColorInDirection({
|
|
10011
|
-
|
|
10036
|
+
originalColor,
|
|
10012
10037
|
colorForComparison,
|
|
10013
10038
|
minContrast,
|
|
10014
10039
|
direction: "darker",
|
|
@@ -10032,27 +10057,28 @@ var ColorPickerProvider = ({
|
|
|
10032
10057
|
const [nonDerivedValueAsHsv, setNonDerivedValueAsHsv] = (0, import_react41.useState)(convertToHsv(valueAsHex));
|
|
10033
10058
|
const [shouldEnforceMinContrast, setShouldEnforceMinContrast] = (0, import_react41.useState)(false);
|
|
10034
10059
|
const getAccessibleDerivativeColor = (0, import_react41.useCallback)(
|
|
10035
|
-
(
|
|
10036
|
-
|
|
10060
|
+
(originalColor) => getAccessibleColor({
|
|
10061
|
+
originalColor,
|
|
10037
10062
|
colorForComparison,
|
|
10038
10063
|
minContrast: minimumContrastRatio,
|
|
10039
10064
|
opacityForContrastCalculation
|
|
10040
10065
|
}),
|
|
10041
10066
|
[colorForComparison, minimumContrastRatio, opacityForContrastCalculation]
|
|
10042
10067
|
);
|
|
10043
|
-
const valueAsHsv = shouldEnforceMinContrast ? getAccessibleDerivativeColor(nonDerivedValueAsHsv) : nonDerivedValueAsHsv;
|
|
10044
|
-
const currentContrastRatio = (
|
|
10045
|
-
|
|
10046
|
-
colorForComparison
|
|
10047
|
-
|
|
10068
|
+
const valueAsHsv = shouldEnforceMinContrast ? getAccessibleDerivativeColor((0, import_fn4.formatHex)(nonDerivedValueAsHsv)) : nonDerivedValueAsHsv;
|
|
10069
|
+
const currentContrastRatio = calculateContrast({
|
|
10070
|
+
backgroundColor: valueAsHex,
|
|
10071
|
+
foregroundColor: colorForComparison,
|
|
10072
|
+
backgroundOpacity: opacityForContrastCalculation
|
|
10073
|
+
});
|
|
10048
10074
|
const hasAccessibleDerivativesValue = (0, import_react41.useMemo)(() => {
|
|
10049
10075
|
return hasAccessibleDerivatives({
|
|
10050
|
-
|
|
10076
|
+
originalColor: valueAsHex,
|
|
10051
10077
|
colorForComparison,
|
|
10052
10078
|
minContrast: minimumContrastRatio,
|
|
10053
10079
|
opacityForContrastCalculation
|
|
10054
10080
|
});
|
|
10055
|
-
}, [
|
|
10081
|
+
}, [valueAsHex, colorForComparison, minimumContrastRatio, opacityForContrastCalculation]);
|
|
10056
10082
|
const onChangeNonDerivedValueAsHsv = (0, import_react41.useCallback)((nonDerivedValue) => {
|
|
10057
10083
|
setNonDerivedValueAsHsv(nonDerivedValue);
|
|
10058
10084
|
}, []);
|
|
@@ -10076,15 +10102,21 @@ var ColorPickerProvider = ({
|
|
|
10076
10102
|
const setShouldEnforceMinContrastWrapped = (0, import_react41.useCallback)(
|
|
10077
10103
|
(newShouldEnforceMinContrast) => {
|
|
10078
10104
|
setShouldEnforceMinContrast(newShouldEnforceMinContrast);
|
|
10079
|
-
const newColorAsHsv = newShouldEnforceMinContrast ? getAccessibleDerivativeColor(
|
|
10105
|
+
const newColorAsHsv = newShouldEnforceMinContrast ? getAccessibleDerivativeColor(valueAsHex) : nonDerivedValueAsHsv;
|
|
10080
10106
|
const currentHsv = valueAsHsv;
|
|
10081
10107
|
if (currentHsv.h !== newColorAsHsv.h || currentHsv.s !== newColorAsHsv.s || currentHsv.v !== newColorAsHsv.v) {
|
|
10082
10108
|
changeValueSmoothly(newColorAsHsv);
|
|
10083
10109
|
}
|
|
10084
10110
|
},
|
|
10085
|
-
[
|
|
10111
|
+
[
|
|
10112
|
+
changeValueSmoothly,
|
|
10113
|
+
getAccessibleDerivativeColor,
|
|
10114
|
+
nonDerivedValueAsHsv,
|
|
10115
|
+
valueAsHex,
|
|
10116
|
+
valueAsHsv
|
|
10117
|
+
]
|
|
10086
10118
|
);
|
|
10087
|
-
const whatValuePropShouldBe = shouldEnforceMinContrast ? (0, import_fn4.formatHex)(getAccessibleDerivativeColor(nonDerivedValueAsHsv)) : (0, import_fn4.formatHex)(nonDerivedValueAsHsv);
|
|
10119
|
+
const whatValuePropShouldBe = shouldEnforceMinContrast ? (0, import_fn4.formatHex)(getAccessibleDerivativeColor((0, import_fn4.formatHex)(nonDerivedValueAsHsv))) : (0, import_fn4.formatHex)(nonDerivedValueAsHsv);
|
|
10088
10120
|
(0, import_react41.useEffect)(() => {
|
|
10089
10121
|
if (valueAsHex !== whatValuePropShouldBe && !isTransitioning) {
|
|
10090
10122
|
onValueChange(whatValuePropShouldBe);
|
|
@@ -10715,6 +10747,9 @@ var Container6 = import_styled_components57.default.div`
|
|
|
10715
10747
|
justify-content: end;
|
|
10716
10748
|
align-items: center;
|
|
10717
10749
|
`;
|
|
10750
|
+
var floorToTenth = (value) => {
|
|
10751
|
+
return Math.floor(value * 10) / 10;
|
|
10752
|
+
};
|
|
10718
10753
|
var ContrastIndicator = () => {
|
|
10719
10754
|
const { currentContrastRatio, minimumContrastRatio } = useColorPickerState();
|
|
10720
10755
|
const isContrastSufficient = currentContrastRatio >= minimumContrastRatio;
|
|
@@ -10734,7 +10769,7 @@ var ContrastIndicator = () => {
|
|
|
10734
10769
|
renderAs: "span",
|
|
10735
10770
|
variant: "body4Mono",
|
|
10736
10771
|
children: [
|
|
10737
|
-
currentContrastRatio.toFixed(
|
|
10772
|
+
floorToTenth(currentContrastRatio).toFixed(1),
|
|
10738
10773
|
":1"
|
|
10739
10774
|
]
|
|
10740
10775
|
}
|
|
@@ -11546,11 +11581,13 @@ var calculateContrastCurve = (width, height, hue, minimumContrastRatio, colorFor
|
|
|
11546
11581
|
const saturationChanel = x / (width - 1);
|
|
11547
11582
|
const initialValueChannelForSearch = limit === "upper" ? 0 : 1;
|
|
11548
11583
|
const colorForXAsHsv = getAccessibleColorByValueChannelChange({
|
|
11549
|
-
|
|
11584
|
+
originalColor: { h: hue, s: saturationChanel, v: initialValueChannelForSearch, mode: "hsv" },
|
|
11550
11585
|
colorForComparison,
|
|
11551
11586
|
minContrast: minimumContrastRatio,
|
|
11552
11587
|
direction: limit === "upper" ? "brighter" : "darker",
|
|
11553
|
-
opacityForContrastCalculation
|
|
11588
|
+
opacityForContrastCalculation,
|
|
11589
|
+
// We set shouldConvertToHex to false to make the curve smoother.
|
|
11590
|
+
shouldConvertToHex: false
|
|
11554
11591
|
});
|
|
11555
11592
|
if (colorForXAsHsv != null) {
|
|
11556
11593
|
const point = {
|
|
@@ -14523,6 +14560,7 @@ PopoverArrow.displayName = "PopoverArrow_UI";
|
|
|
14523
14560
|
// src/components/Popover/Popover.tsx
|
|
14524
14561
|
var import_jsx_runtime282 = require("react/jsx-runtime");
|
|
14525
14562
|
var StyledContent2 = (0, import_styled_components90.default)(import_react_popover5.Content)`
|
|
14563
|
+
z-index: var(--wui-zindex-popover);
|
|
14526
14564
|
${({ $colorScheme }) => getColorScheme($colorScheme)};
|
|
14527
14565
|
${({ $unstyled }) => !$unstyled && import_styled_components90.css`
|
|
14528
14566
|
border-radius: var(--wui-border-radius-02);
|
|
@@ -16970,6 +17008,7 @@ var ContextMenu = ({
|
|
|
16970
17008
|
ValueNameOrHexCode,
|
|
16971
17009
|
ValueSwatch,
|
|
16972
17010
|
WistiaLogo,
|
|
17011
|
+
calculateContrast,
|
|
16973
17012
|
colorSchemeOptions,
|
|
16974
17013
|
copyToClipboard,
|
|
16975
17014
|
dateTime,
|