react-iro-gradient-picker 1.1.4 → 1.1.6

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.js CHANGED
@@ -7640,39 +7640,22 @@ var useDebounce = (function (value, delay) {
7640
7640
  });
7641
7641
 
7642
7642
  var IroGradient = function (_a) {
7643
- var _b;
7644
- var _c = _a.value, value = _c === void 0 ? 'linear-gradient(90deg, #ffffff 0%, #000000 100%)' : _c, _d = _a.onChange, onChange = _d === void 0 ? function () { return ({}); } : _d, _e = _a.format, format = _e === void 0 ? 'rgb' : _e, _f = _a.debounceMS, debounceMS = _f === void 0 ? 300 : _f, _g = _a.debounce, debounce = _g === void 0 ? true : _g, _h = _a.showAlpha, showAlpha = _h === void 0 ? true : _h, _j = _a.showInputs, showInputs = _j === void 0 ? true : _j, _k = _a.showGradientResult, showGradientResult = _k === void 0 ? true : _k, _l = _a.showGradientStops, showGradientStops = _l === void 0 ? true : _l, _m = _a.showGradientMode, showGradientMode = _m === void 0 ? true : _m, _o = _a.showGradientAngle, showGradientAngle = _o === void 0 ? true : _o, _p = _a.showGradientPosition, showGradientPosition = _p === void 0 ? true : _p, _q = _a.allowAddGradientStops, allowAddGradientStops = _q === void 0 ? true : _q, _r = _a.colorBoardHeight, colorBoardHeight = _r === void 0 ? 120 : _r, defaultColors = _a.defaultColors, _s = _a.showReset, showReset = _s === void 0 ? false : _s, onReset = _a.onReset;
7643
+ var _b = _a.value, value = _b === void 0 ? 'linear-gradient(90deg, #ffffff 0%, #000000 100%)' : _b, _c = _a.onChange, onChange = _c === void 0 ? function () { return ({}); } : _c, _d = _a.format, format = _d === void 0 ? 'rgb' : _d, _e = _a.debounceMS, debounceMS = _e === void 0 ? 300 : _e, _f = _a.debounce, debounce = _f === void 0 ? true : _f, _g = _a.showAlpha, showAlpha = _g === void 0 ? true : _g, _h = _a.showInputs, showInputs = _h === void 0 ? true : _h, _j = _a.showGradientResult, showGradientResult = _j === void 0 ? true : _j, _k = _a.showGradientStops, showGradientStops = _k === void 0 ? true : _k, _l = _a.showGradientMode, showGradientMode = _l === void 0 ? true : _l, _m = _a.showGradientAngle, showGradientAngle = _m === void 0 ? true : _m, _o = _a.showGradientPosition, showGradientPosition = _o === void 0 ? true : _o, _p = _a.allowAddGradientStops, allowAddGradientStops = _p === void 0 ? true : _p, _q = _a.colorBoardHeight, colorBoardHeight = _q === void 0 ? 120 : _q, defaultColors = _a.defaultColors, _r = _a.showReset, showReset = _r === void 0 ? false : _r, onReset = _a.onReset;
7645
7644
  // Store the initial value for reset functionality
7646
7645
  var initialValue = React.useRef(value);
7647
7646
  var parsedColors = React.useCallback(function () {
7648
7647
  return parseGradient(value);
7649
7648
  // eslint-disable-next-line react-hooks/exhaustive-deps
7650
7649
  }, [value]);
7651
- var _t = parsedColors(), stops = _t.stops, type = _t.type, modifier = _t.modifier;
7652
- // Safely extract active stop information with fallbacks
7653
- var safeStops = stops && stops.length > 0
7654
- ? stops
7655
- : [
7656
- ['rgba(255,255,255,1)', 0],
7657
- ['rgba(0,0,0,1)', 100]
7658
- ];
7659
- var activeStopIndex = safeStops.length - 1;
7660
- var activeStop = '#ffffff';
7661
- var activeAlpha = 100;
7662
- try {
7663
- var lastStop = rgbaToArray(safeStops[activeStopIndex][0]);
7664
- if (lastStop && lastStop.length >= 4) {
7665
- activeStop = rgbaToHex([lastStop[0], lastStop[1], lastStop[2]]);
7666
- activeAlpha = Math.round((lastStop[3] || 1) * 100);
7667
- }
7668
- }
7669
- catch (error) {
7670
- console.warn('⚠️ Error parsing gradient stops, using defaults:', error);
7671
- }
7650
+ var _s = parsedColors(), stops = _s.stops, type = _s.type, modifier = _s.modifier;
7651
+ var lastStop = rgbaToArray(stops[stops.length - 1][0]);
7652
+ var activeStopIndex = stops.length - 1;
7653
+ var activeStop = rgbaToHex([lastStop[0], lastStop[1], lastStop[2]]);
7654
+ var activeAlpha = Math.round(lastStop[3] * 100);
7672
7655
  var iroPickerRef = React.useRef(null);
7673
7656
  var containerRef = React.useRef(null);
7674
7657
  var isUpdatingFromGradientStop = React.useRef(false);
7675
- var _u = __read(React.useState(200), 2), pickerWidth = _u[0], setPickerWidth = _u[1];
7658
+ var _t = __read(React.useState(200), 2), pickerWidth = _t[0], setPickerWidth = _t[1];
7676
7659
  // Responsive width for IroColorPicker - match solid picker logic
7677
7660
  React.useEffect(function () {
7678
7661
  if (!containerRef.current)
@@ -7711,39 +7694,27 @@ var IroGradient = function (_a) {
7711
7694
  resizeObserver.observe(containerRef.current);
7712
7695
  return function () { return resizeObserver.disconnect(); };
7713
7696
  }, []);
7714
- var _v = __read(React.useState({
7697
+ var _u = __read(React.useState({
7715
7698
  gradient: value,
7716
7699
  type: type,
7717
7700
  modifier: modifier,
7718
- stops: safeStops
7719
- }), 2), color = _v[0], setColor = _v[1];
7720
- var _w = __read(React.useState({
7721
- hex: activeStop || '#ffffff',
7722
- alpha: activeAlpha !== null && activeAlpha !== void 0 ? activeAlpha : 100,
7723
- loc: ((_b = safeStops[activeStopIndex]) === null || _b === void 0 ? void 0 : _b[1]) || 0,
7724
- index: activeStopIndex || 0
7725
- }), 2), activeColor = _w[0], setActiveColor = _w[1];
7701
+ stops: stops
7702
+ }), 2), color = _u[0], setColor = _u[1];
7703
+ var _v = __read(React.useState({
7704
+ hex: activeStop,
7705
+ alpha: activeAlpha,
7706
+ loc: stops[activeStopIndex][1],
7707
+ index: activeStopIndex
7708
+ }), 2), activeColor = _v[0], setActiveColor = _v[1];
7726
7709
  var debounceColor = useDebounce(color, debounceMS);
7727
7710
  // Update iro picker color
7728
7711
  var updateIroPickerColor = React.useCallback(function (colorData, retryCount) {
7729
7712
  if (retryCount === void 0) { retryCount = 0; }
7730
7713
  var maxRetries = 5;
7731
- // Validate input data before proceeding
7732
- if (!colorData || !colorData.hex || colorData.alpha == null) {
7733
- console.warn('❌ Invalid color data provided to updateIroPickerColor:', colorData);
7734
- return;
7735
- }
7736
- // Ensure hex is valid (starts with # and has proper length)
7737
- if (!/^#[0-9A-Fa-f]{6}$/i.test(colorData.hex)) {
7738
- console.warn('❌ Invalid hex format provided:', colorData.hex);
7739
- return;
7740
- }
7741
- // Ensure alpha is a valid number between 0 and 100
7742
- if (isNaN(colorData.alpha) ||
7743
- colorData.alpha < 0 ||
7744
- colorData.alpha > 100) {
7745
- console.warn('❌ Invalid alpha value provided:', colorData.alpha);
7746
- return;
7714
+ // Validate input data
7715
+ if (!colorData || !colorData.hex || typeof colorData.alpha !== 'number') {
7716
+ console.log('❌ Invalid color data provided to updateIroPickerColor:', colorData);
7717
+ return; // Early return if invalid data
7747
7718
  }
7748
7719
  var updateColor = function () {
7749
7720
  var _a, _b, _c, _d, _e, _f;
@@ -7860,19 +7831,16 @@ var IroGradient = function (_a) {
7860
7831
  });
7861
7832
  // Add a small delay to ensure the activeColor state has fully updated
7862
7833
  var timeoutId = setTimeout(function () {
7863
- // Only call updateIroPickerColor if we have valid hex and alpha values
7864
- if (activeColor.hex && activeColor.alpha != null) {
7865
- updateIroPickerColor({
7866
- hex: activeColor.hex,
7867
- alpha: activeColor.alpha
7868
- });
7869
- }
7870
- else {
7871
- console.warn('⚠️ Skipping iro picker update due to invalid activeColor:', activeColor);
7872
- }
7834
+ updateIroPickerColor({ hex: activeColor.hex, alpha: activeColor.alpha });
7873
7835
  }, 10);
7874
7836
  return function () { return clearTimeout(timeoutId); };
7875
- }, [activeColor, updateIroPickerColor]);
7837
+ }, [
7838
+ activeColor.hex,
7839
+ activeColor.alpha,
7840
+ activeColor.index,
7841
+ activeColor.loc,
7842
+ updateIroPickerColor
7843
+ ]);
7876
7844
  var updateGradient = React.useCallback(function (newColor) {
7877
7845
  if (Array.isArray(newColor)) {
7878
7846
  // Handle the case where it's called with stops array
@@ -7947,7 +7915,10 @@ var IroGradient = function (_a) {
7947
7915
  setActiveColor(newActiveColor);
7948
7916
  // Update iro picker if available
7949
7917
  if ((_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) {
7950
- updateIroPickerColor(newActiveColor);
7918
+ updateIroPickerColor({
7919
+ hex: newActiveColor.hex,
7920
+ alpha: newActiveColor.alpha
7921
+ });
7951
7922
  }
7952
7923
  // Call onChange with initial value
7953
7924
  onChange(initialValue.current);
@@ -7958,17 +7929,20 @@ var IroGradient = function (_a) {
7958
7929
  var handleColorFromPanel = function (newColor) {
7959
7930
  setColor(newColor);
7960
7931
  if (newColor === null || newColor === void 0 ? void 0 : newColor.stops) {
7961
- var lastStop = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
7962
- var activeStop_1 = rgbaToHex([lastStop[0], lastStop[1], lastStop[2]]);
7932
+ var lastStop_1 = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
7933
+ var activeStop_1 = rgbaToHex([lastStop_1[0], lastStop_1[1], lastStop_1[2]]);
7963
7934
  var newActiveColor = {
7964
7935
  hex: activeStop_1,
7965
- alpha: Math.round(lastStop[3] * 100),
7936
+ alpha: Math.round(lastStop_1[3] * 100),
7966
7937
  loc: newColor.stops[newColor.stops.length - 1][1],
7967
7938
  index: newColor.stops.length - 1
7968
7939
  };
7969
7940
  setActiveColor(newActiveColor);
7970
7941
  // Update the iro color picker
7971
- updateIroPickerColor(newActiveColor);
7942
+ updateIroPickerColor({
7943
+ hex: newActiveColor.hex,
7944
+ alpha: newActiveColor.alpha
7945
+ });
7972
7946
  }
7973
7947
  };
7974
7948
  var handleIroColorChange = function (iroColor) {