react-iro-gradient-picker 1.1.5 → 1.1.7

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;
@@ -7821,7 +7792,9 @@ var IroGradient = function (_a) {
7821
7792
  React.useEffect(function () {
7822
7793
  var initializeIroPicker = function () {
7823
7794
  var _a, _b;
7824
- if (((_b = (_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) === null || _b === void 0 ? void 0 : _b.color) && activeColor.hex) {
7795
+ if (((_b = (_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) === null || _b === void 0 ? void 0 : _b.color) &&
7796
+ activeColor.hex &&
7797
+ typeof activeColor.alpha === 'number') {
7825
7798
  console.log('🚀 Initializing iro picker with activeColor:', activeColor);
7826
7799
  // Wait a bit for the picker to be fully ready, then update
7827
7800
  setTimeout(function () {
@@ -7842,13 +7815,19 @@ var IroGradient = function (_a) {
7842
7815
  var handleSetActiveColor = React.useCallback(function (newActiveColor) {
7843
7816
  console.log('🎯 Gradient stop clicked, setting active color:', newActiveColor);
7844
7817
  setActiveColor(newActiveColor);
7845
- // Force immediate update of iro picker with longer delay for first-time reliability
7846
- setTimeout(function () {
7847
- updateIroPickerColor({
7848
- hex: newActiveColor.hex,
7849
- alpha: newActiveColor.alpha
7850
- });
7851
- }, 50); // Increased from 5ms to 50ms for better first-time success
7818
+ // Validate before updating iro picker
7819
+ if (newActiveColor.hex && typeof newActiveColor.alpha === 'number') {
7820
+ // Force immediate update of iro picker with longer delay for first-time reliability
7821
+ setTimeout(function () {
7822
+ updateIroPickerColor({
7823
+ hex: newActiveColor.hex,
7824
+ alpha: newActiveColor.alpha
7825
+ });
7826
+ }, 50); // Increased from 5ms to 50ms for better first-time success
7827
+ }
7828
+ else {
7829
+ console.log('⚠️ Skipping iro picker update in handleSetActiveColor - invalid data:', newActiveColor);
7830
+ }
7852
7831
  }, [updateIroPickerColor]);
7853
7832
  // Update iro picker when activeColor changes (e.g., clicking gradient stops)
7854
7833
  React.useEffect(function () {
@@ -7858,18 +7837,14 @@ var IroGradient = function (_a) {
7858
7837
  index: activeColor.index,
7859
7838
  loc: activeColor.loc
7860
7839
  });
7840
+ // Validate activeColor before proceeding
7841
+ if (!activeColor.hex || typeof activeColor.alpha !== 'number') {
7842
+ console.log('⚠️ Skipping iro picker update - invalid activeColor:', activeColor);
7843
+ return;
7844
+ }
7861
7845
  // Add a small delay to ensure the activeColor state has fully updated
7862
7846
  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
- }
7847
+ updateIroPickerColor({ hex: activeColor.hex, alpha: activeColor.alpha });
7873
7848
  }, 10);
7874
7849
  return function () { return clearTimeout(timeoutId); };
7875
7850
  }, [activeColor, updateIroPickerColor]);
@@ -7947,7 +7922,10 @@ var IroGradient = function (_a) {
7947
7922
  setActiveColor(newActiveColor);
7948
7923
  // Update iro picker if available
7949
7924
  if ((_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) {
7950
- updateIroPickerColor(newActiveColor);
7925
+ updateIroPickerColor({
7926
+ hex: newActiveColor.hex,
7927
+ alpha: newActiveColor.alpha
7928
+ });
7951
7929
  }
7952
7930
  // Call onChange with initial value
7953
7931
  onChange(initialValue.current);
@@ -7958,17 +7936,20 @@ var IroGradient = function (_a) {
7958
7936
  var handleColorFromPanel = function (newColor) {
7959
7937
  setColor(newColor);
7960
7938
  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]]);
7939
+ var lastStop_1 = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
7940
+ var activeStop_1 = rgbaToHex([lastStop_1[0], lastStop_1[1], lastStop_1[2]]);
7963
7941
  var newActiveColor = {
7964
7942
  hex: activeStop_1,
7965
- alpha: Math.round(lastStop[3] * 100),
7943
+ alpha: Math.round(lastStop_1[3] * 100),
7966
7944
  loc: newColor.stops[newColor.stops.length - 1][1],
7967
7945
  index: newColor.stops.length - 1
7968
7946
  };
7969
7947
  setActiveColor(newActiveColor);
7970
7948
  // Update the iro color picker
7971
- updateIroPickerColor(newActiveColor);
7949
+ updateIroPickerColor({
7950
+ hex: newActiveColor.hex,
7951
+ alpha: newActiveColor.alpha
7952
+ });
7972
7953
  }
7973
7954
  };
7974
7955
  var handleIroColorChange = function (iroColor) {