@wistia/ui 0.13.5 → 0.13.6-beta.790fd64a.9cfdd20

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 CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*
3
- * @license @wistia/ui v0.13.5
3
+ * @license @wistia/ui v0.13.6-beta.790fd64a.9cfdd20
4
4
  *
5
5
  * Copyright (c) 2024-2025, Wistia, Inc. and its affiliates.
6
6
  *
@@ -9745,10 +9745,21 @@ var THREE_SIXTY = 360;
9745
9745
  var TWO_FIFTY_FIVE = 255;
9746
9746
  var DEFAULT_MIN_CONTRAST = 4.5;
9747
9747
  var DEFAULT_COLOR_FOR_COMPARISON = "#ffffff";
9748
+ var DEFAULT_OPACITY_FOR_CONTRAST_CALCULATION = 1;
9748
9749
 
9749
9750
  // src/components/ColorPicker/contrast-utils.ts
9750
9751
  var CONTRAST_EPSILON = 4e-3;
9751
9752
  var VALUE_CHANNEL_SNAP_EPSILON = 5e-4;
9753
+ var compositeOverWhite = (color, alpha = 1) => {
9754
+ const compositeChannel = (channel) => alpha * channel + (1 - alpha);
9755
+ const colorAsRgb = convertToRgb(color);
9756
+ return {
9757
+ mode: "rgb",
9758
+ r: compositeChannel(colorAsRgb.r),
9759
+ g: compositeChannel(colorAsRgb.g),
9760
+ b: compositeChannel(colorAsRgb.b)
9761
+ };
9762
+ };
9752
9763
  var snapValueToEdges = (value) => {
9753
9764
  if (value > 1 - VALUE_CHANNEL_SNAP_EPSILON) {
9754
9765
  return 1;
@@ -9775,7 +9786,8 @@ var getAccessibleColorByValueChannelChange = ({
9775
9786
  colorForComparison,
9776
9787
  minContrast,
9777
9788
  maxIterations = 50,
9778
- direction
9789
+ direction,
9790
+ opacityForContrastCalculation
9779
9791
  }) => {
9780
9792
  const searchingBrighter = direction === "brighter";
9781
9793
  const lowValue = searchingBrighter ? originalHsv.v : 0;
@@ -9787,7 +9799,10 @@ var getAccessibleColorByValueChannelChange = ({
9787
9799
  v: extremeValue,
9788
9800
  mode: "hsv"
9789
9801
  };
9790
- const extremeContrast = (0, import_fn3.wcagContrast)(extremeVariant, colorForComparison);
9802
+ const extremeContrast = (0, import_fn3.wcagContrast)(
9803
+ compositeOverWhite(extremeVariant, opacityForContrastCalculation),
9804
+ colorForComparison
9805
+ );
9791
9806
  if (extremeContrast < minContrast) {
9792
9807
  return null;
9793
9808
  }
@@ -9803,7 +9818,10 @@ var getAccessibleColorByValueChannelChange = ({
9803
9818
  v: midValue,
9804
9819
  mode: "hsv"
9805
9820
  };
9806
- const contrast = (0, import_fn3.wcagContrast)(candidateHsv, colorForComparison);
9821
+ const contrast = (0, import_fn3.wcagContrast)(
9822
+ compositeOverWhite(candidateHsv, opacityForContrastCalculation),
9823
+ colorForComparison
9824
+ );
9807
9825
  if (contrast >= minContrast) {
9808
9826
  bestSoFar = candidateHsv;
9809
9827
  }
@@ -9848,7 +9866,8 @@ var getAccessibleColorBySaturationAndValueChange = ({
9848
9866
  originalHsv,
9849
9867
  colorForComparison,
9850
9868
  minContrast,
9851
- direction
9869
+ direction,
9870
+ opacityForContrastCalculation
9852
9871
  }) => {
9853
9872
  const hsvDifference = (0, import_fn3.differenceEuclidean)("hsv");
9854
9873
  const maxIterations = 50;
@@ -9875,7 +9894,7 @@ var getAccessibleColorBySaturationAndValueChange = ({
9875
9894
  };
9876
9895
  };
9877
9896
  const checkContrast = (hsv) => {
9878
- return (0, import_fn3.wcagContrast)(hsv, colorForComparison);
9897
+ return (0, import_fn3.wcagContrast)(compositeOverWhite(hsv, opacityForContrastCalculation), colorForComparison);
9879
9898
  };
9880
9899
  const extremeHsv = getHsvForStep(highStep);
9881
9900
  if (checkContrast(extremeHsv) < minContrast) {
@@ -9908,14 +9927,16 @@ var getAccessibleColorInDirection = ({
9908
9927
  colorForComparison,
9909
9928
  minContrast,
9910
9929
  maxIterations = 50,
9911
- direction
9930
+ direction,
9931
+ opacityForContrastCalculation
9912
9932
  }) => {
9913
9933
  const valueResult = getAccessibleColorByValueChannelChange({
9914
9934
  originalHsv,
9915
9935
  colorForComparison,
9916
9936
  minContrast,
9917
9937
  maxIterations,
9918
- direction
9938
+ direction,
9939
+ opacityForContrastCalculation
9919
9940
  });
9920
9941
  if (valueResult !== null) {
9921
9942
  return valueResult;
@@ -9924,16 +9945,21 @@ var getAccessibleColorInDirection = ({
9924
9945
  originalHsv,
9925
9946
  colorForComparison,
9926
9947
  minContrast,
9927
- direction
9948
+ direction,
9949
+ opacityForContrastCalculation
9928
9950
  });
9929
9951
  };
9930
9952
  var getAccessibleColor = ({
9931
9953
  originalHsv,
9932
9954
  colorForComparison,
9933
9955
  minContrast = DEFAULT_MIN_CONTRAST,
9934
- maxIterations = 50
9956
+ maxIterations = 50,
9957
+ opacityForContrastCalculation
9935
9958
  }) => {
9936
- const originalContrast = (0, import_fn3.wcagContrast)(originalHsv, colorForComparison);
9959
+ const originalContrast = (0, import_fn3.wcagContrast)(
9960
+ compositeOverWhite(originalHsv, opacityForContrastCalculation),
9961
+ colorForComparison
9962
+ );
9937
9963
  if (originalContrast >= minContrast) {
9938
9964
  return originalHsv;
9939
9965
  }
@@ -9942,14 +9968,16 @@ var getAccessibleColor = ({
9942
9968
  colorForComparison,
9943
9969
  minContrast,
9944
9970
  maxIterations,
9945
- direction: "brighter"
9971
+ direction: "brighter",
9972
+ opacityForContrastCalculation
9946
9973
  });
9947
9974
  const darkerOption = getAccessibleColorInDirection({
9948
9975
  originalHsv,
9949
9976
  colorForComparison,
9950
9977
  minContrast,
9951
9978
  maxIterations,
9952
- direction: "darker"
9979
+ direction: "darker",
9980
+ opacityForContrastCalculation
9953
9981
  });
9954
9982
  const result = chooseClosestDerivativeToOriginal(brighterOption, darkerOption, originalHsv);
9955
9983
  if (result == null) {
@@ -9962,9 +9990,13 @@ var getAccessibleColor = ({
9962
9990
  var hasAccessibleDerivatives = ({
9963
9991
  originalHsv,
9964
9992
  colorForComparison,
9965
- minContrast = DEFAULT_MIN_CONTRAST
9993
+ minContrast = DEFAULT_MIN_CONTRAST,
9994
+ opacityForContrastCalculation
9966
9995
  }) => {
9967
- const originalContrast = (0, import_fn3.wcagContrast)(originalHsv, colorForComparison);
9996
+ const originalContrast = (0, import_fn3.wcagContrast)(
9997
+ compositeOverWhite(originalHsv, opacityForContrastCalculation),
9998
+ colorForComparison
9999
+ );
9968
10000
  if (originalContrast >= minContrast) {
9969
10001
  return true;
9970
10002
  }
@@ -9972,13 +10004,15 @@ var hasAccessibleDerivatives = ({
9972
10004
  originalHsv,
9973
10005
  colorForComparison,
9974
10006
  minContrast,
9975
- direction: "brighter"
10007
+ direction: "brighter",
10008
+ opacityForContrastCalculation
9976
10009
  });
9977
10010
  const darkerOption = getAccessibleColorInDirection({
9978
10011
  originalHsv,
9979
10012
  colorForComparison,
9980
10013
  minContrast,
9981
- direction: "darker"
10014
+ direction: "darker",
10015
+ opacityForContrastCalculation
9982
10016
  });
9983
10017
  return brighterOption !== null || darkerOption !== null;
9984
10018
  };
@@ -9988,10 +10022,11 @@ var import_jsx_runtime225 = require("react/jsx-runtime");
9988
10022
  var ColorPickerContext = (0, import_react41.createContext)(null);
9989
10023
  var ColorPickerProvider = ({
9990
10024
  children,
9991
- value: valueAsHex,
10025
+ colorForComparison,
10026
+ minimumContrastRatio,
9992
10027
  onValueChange,
9993
- minimumContrastRatio = DEFAULT_MIN_CONTRAST,
9994
- colorForComparison = DEFAULT_COLOR_FOR_COMPARISON
10028
+ opacityForContrastCalculation,
10029
+ value: valueAsHex
9995
10030
  }) => {
9996
10031
  const [isTransitioning, setIsTransitioning] = (0, import_react41.useState)(false);
9997
10032
  const [nonDerivedValueAsHsv, setNonDerivedValueAsHsv] = (0, import_react41.useState)(convertToHsv(valueAsHex));
@@ -10000,19 +10035,24 @@ var ColorPickerProvider = ({
10000
10035
  (originalHsv) => getAccessibleColor({
10001
10036
  originalHsv,
10002
10037
  colorForComparison,
10003
- minContrast: minimumContrastRatio
10038
+ minContrast: minimumContrastRatio,
10039
+ opacityForContrastCalculation
10004
10040
  }),
10005
- [minimumContrastRatio, colorForComparison]
10041
+ [colorForComparison, minimumContrastRatio, opacityForContrastCalculation]
10006
10042
  );
10007
10043
  const valueAsHsv = shouldEnforceMinContrast ? getAccessibleDerivativeColor(nonDerivedValueAsHsv) : nonDerivedValueAsHsv;
10008
- const currentContrastRatio = (0, import_fn4.wcagContrast)(valueAsHsv, colorForComparison);
10044
+ const currentContrastRatio = (0, import_fn4.wcagContrast)(
10045
+ compositeOverWhite(valueAsHsv, opacityForContrastCalculation),
10046
+ colorForComparison
10047
+ );
10009
10048
  const hasAccessibleDerivativesValue = (0, import_react41.useMemo)(() => {
10010
10049
  return hasAccessibleDerivatives({
10011
10050
  originalHsv: valueAsHsv,
10012
10051
  colorForComparison,
10013
- minContrast: minimumContrastRatio
10052
+ minContrast: minimumContrastRatio,
10053
+ opacityForContrastCalculation
10014
10054
  });
10015
- }, [valueAsHsv, colorForComparison, minimumContrastRatio]);
10055
+ }, [valueAsHsv, colorForComparison, minimumContrastRatio, opacityForContrastCalculation]);
10016
10056
  const onChangeNonDerivedValueAsHsv = (0, import_react41.useCallback)((nonDerivedValue) => {
10017
10057
  setNonDerivedValueAsHsv(nonDerivedValue);
10018
10058
  }, []);
@@ -10061,6 +10101,7 @@ var ColorPickerProvider = ({
10061
10101
  nonDerivedValueAsHex: (0, import_fn4.formatHex)(nonDerivedValueAsHsv),
10062
10102
  nonDerivedValueAsHsv,
10063
10103
  onChangeNonDerivedValueAsHsv,
10104
+ opacityForContrastCalculation,
10064
10105
  setShouldEnforceMinContrast: setShouldEnforceMinContrastWrapped,
10065
10106
  shouldEnforceMinContrast,
10066
10107
  valueAsHex,
@@ -10075,6 +10116,7 @@ var ColorPickerProvider = ({
10075
10116
  minimumContrastRatio,
10076
10117
  nonDerivedValueAsHsv,
10077
10118
  onChangeNonDerivedValueAsHsv,
10119
+ opacityForContrastCalculation,
10078
10120
  setShouldEnforceMinContrastWrapped,
10079
10121
  shouldEnforceMinContrast,
10080
10122
  valueAsHex,
@@ -10540,6 +10582,7 @@ var ColorPicker = ({
10540
10582
  children,
10541
10583
  colorForComparison = DEFAULT_COLOR_FOR_COMPARISON,
10542
10584
  minimumContrastRatio = DEFAULT_MIN_CONTRAST,
10585
+ opacityForContrastCalculation = DEFAULT_OPACITY_FOR_CONTRAST_CALCULATION,
10543
10586
  onValueChange,
10544
10587
  value
10545
10588
  }) => {
@@ -10549,6 +10592,7 @@ var ColorPicker = ({
10549
10592
  colorForComparison,
10550
10593
  minimumContrastRatio,
10551
10594
  onValueChange,
10595
+ opacityForContrastCalculation,
10552
10596
  value,
10553
10597
  children
10554
10598
  }
@@ -11491,7 +11535,7 @@ var Canvas2 = import_styled_components63.default.canvas`
11491
11535
  display: block;
11492
11536
  width: 100%;
11493
11537
  `;
11494
- var calculateContrastCurve = (width, height, hue, minimumContrastRatio, colorForComparison, limit) => {
11538
+ var calculateContrastCurve = (width, height, hue, minimumContrastRatio, colorForComparison, limit, opacityForContrastCalculation) => {
11495
11539
  const contrastPoints = [];
11496
11540
  for (let x = 0; x < width; x += 1) {
11497
11541
  const saturationChanel = x / (width - 1);
@@ -11500,7 +11544,8 @@ var calculateContrastCurve = (width, height, hue, minimumContrastRatio, colorFor
11500
11544
  originalHsv: { h: hue, s: saturationChanel, v: initialValueChannelForSearch, mode: "hsv" },
11501
11545
  colorForComparison,
11502
11546
  minContrast: minimumContrastRatio,
11503
- direction: limit === "upper" ? "brighter" : "darker"
11547
+ direction: limit === "upper" ? "brighter" : "darker",
11548
+ opacityForContrastCalculation
11504
11549
  });
11505
11550
  if (colorForXAsHsv != null) {
11506
11551
  const point = {
@@ -11540,7 +11585,8 @@ var HSVSaturationValueCanvas = ({
11540
11585
  hue,
11541
11586
  shouldShowContrastCurve = false,
11542
11587
  minimumContrastRatio = DEFAULT_MIN_CONTRAST,
11543
- colorForComparison
11588
+ colorForComparison,
11589
+ opacityForContrastCalculation
11544
11590
  }) => {
11545
11591
  const canvasRef = (0, import_react51.useRef)(null);
11546
11592
  (0, import_react51.useEffect)(() => {
@@ -11564,7 +11610,8 @@ var HSVSaturationValueCanvas = ({
11564
11610
  hue,
11565
11611
  minimumContrastRatio,
11566
11612
  colorForComparison,
11567
- "upper"
11613
+ "upper",
11614
+ opacityForContrastCalculation
11568
11615
  );
11569
11616
  const minHsvValueChannelCurve = calculateContrastCurve(
11570
11617
  width,
@@ -11572,7 +11619,8 @@ var HSVSaturationValueCanvas = ({
11572
11619
  hue,
11573
11620
  minimumContrastRatio,
11574
11621
  colorForComparison,
11575
- "lower"
11622
+ "lower",
11623
+ opacityForContrastCalculation
11576
11624
  );
11577
11625
  if (minHsvValueChannelCurve.length > 0) {
11578
11626
  drawSmoothCurve(ctx, minHsvValueChannelCurve);
@@ -11581,7 +11629,13 @@ var HSVSaturationValueCanvas = ({
11581
11629
  drawSmoothCurve(ctx, maxHsvValueChannelCurve);
11582
11630
  }
11583
11631
  }
11584
- }, [hue, shouldShowContrastCurve, minimumContrastRatio, colorForComparison]);
11632
+ }, [
11633
+ hue,
11634
+ shouldShowContrastCurve,
11635
+ minimumContrastRatio,
11636
+ colorForComparison,
11637
+ opacityForContrastCalculation
11638
+ ]);
11585
11639
  return /* @__PURE__ */ (0, import_jsx_runtime249.jsx)(
11586
11640
  Canvas2,
11587
11641
  {
@@ -11626,14 +11680,15 @@ var SaturationAndValuePicker = ({
11626
11680
  dataTestId
11627
11681
  }) => {
11628
11682
  const {
11629
- valueAsHex,
11630
- onChangeNonDerivedValueAsHsv,
11631
- valueAsHsv,
11683
+ colorForComparison,
11632
11684
  isTransitioning,
11633
11685
  minimumContrastRatio,
11634
- colorForComparison,
11686
+ nonDerivedValueAsHsv,
11687
+ onChangeNonDerivedValueAsHsv,
11688
+ opacityForContrastCalculation,
11635
11689
  shouldEnforceMinContrast,
11636
- nonDerivedValueAsHsv
11690
+ valueAsHex,
11691
+ valueAsHsv
11637
11692
  } = useColorPickerState();
11638
11693
  const containerRef = (0, import_react52.useRef)(null);
11639
11694
  const thumbRef = (0, import_react52.useRef)(null);
@@ -11786,6 +11841,7 @@ var SaturationAndValuePicker = ({
11786
11841
  colorForComparison,
11787
11842
  hue: nonDerivedValueAsHsv.h ?? 0,
11788
11843
  minimumContrastRatio,
11844
+ opacityForContrastCalculation,
11789
11845
  shouldShowContrastCurve: shouldEnforceMinContrast
11790
11846
  }
11791
11847
  ),