react-iro-gradient-picker 1.2.12 → 1.2.14

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.es.js CHANGED
@@ -6904,16 +6904,42 @@ var IroColorPicker = forwardRef(function (_a, ref) {
6904
6904
  };
6905
6905
  // eslint-disable-next-line react-hooks/exhaustive-deps
6906
6906
  }, [padding, margin]); // Remove width from dependencies to prevent recreation
6907
+ // Add state to track when picker is ready (removed as it's set but not used)
6907
6908
  useImperativeHandle(ref, function () { return ({
6908
6909
  colorPicker: colorPickerRef.current
6909
6910
  }); });
6910
- // Create a shared picker creation function
6911
+ // Create a shared picker creation function with enhanced error handling
6911
6912
  var createColorPicker = useCallback(function (pickerWidth) {
6912
- if (!containerRef.current || colorPickerRef.current)
6913
+ if (!containerRef.current) {
6914
+ console.warn('IroColorPicker: Container ref not available, skipping creation');
6913
6915
  return;
6916
+ }
6917
+ // More thorough check for existing picker
6918
+ if (colorPickerRef.current) {
6919
+ try {
6920
+ // Check if picker is still valid and functioning
6921
+ if (colorPickerRef.current.color &&
6922
+ typeof colorPickerRef.current.color.hexString === 'string') {
6923
+ return;
6924
+ }
6925
+ }
6926
+ catch (error) { }
6927
+ }
6928
+ // Clean up any existing picker first
6929
+ if (colorPickerRef.current) {
6930
+ try {
6931
+ // Proper cleanup of event listeners and resources
6932
+ if (typeof colorPickerRef.current.off === 'function') {
6933
+ colorPickerRef.current.off();
6934
+ }
6935
+ colorPickerRef.current = null;
6936
+ }
6937
+ catch (error) {
6938
+ console.warn('IroColorPicker: Error cleaning up existing picker:', error);
6939
+ }
6940
+ }
6914
6941
  // Capture the container reference for cleanup
6915
6942
  var currentContainer = containerRef.current;
6916
- console.log('🔧 IroColorPicker recreating picker - width prop:', width, 'containerWidth:', containerWidth);
6917
6943
  // IMPORTANT: Clear any existing DOM content first
6918
6944
  if (currentContainer) {
6919
6945
  currentContainer.innerHTML = '';
@@ -6921,6 +6947,7 @@ var IroColorPicker = forwardRef(function (_a, ref) {
6921
6947
  // Set theme-appropriate border color and background
6922
6948
  var themeBorderColor = theme === 'light' ? '#ffffff' : '#334155';
6923
6949
  var themeBorderWidth = theme === 'light' ? 1 : 0;
6950
+ // Enhanced options with better default values
6924
6951
  var options = {
6925
6952
  width: pickerWidth,
6926
6953
  color: colors ? undefined : color,
@@ -6936,20 +6963,36 @@ var IroColorPicker = forwardRef(function (_a, ref) {
6936
6963
  handleRadius: handleRadius,
6937
6964
  activeHandleRadius: activeHandleRadius || handleRadius,
6938
6965
  handleSvg: handleSvg,
6939
- handleProps: handleProps,
6966
+ handleProps: handleProps || { x: 0, y: 0 }, // Ensure defaults are always set
6940
6967
  wheelLightness: wheelLightness,
6941
6968
  wheelAngle: wheelAngle,
6942
6969
  wheelDirection: wheelDirection,
6943
6970
  sliderSize: sliderSize,
6944
6971
  boxHeight: boxHeight
6945
6972
  };
6946
- // Remove undefined values
6973
+ // Remove undefined values but preserve explicit defaults
6947
6974
  Object.keys(options).forEach(function (key) {
6948
6975
  if (options[key] === undefined) {
6949
6976
  delete options[key];
6950
6977
  }
6951
6978
  });
6952
- colorPickerRef.current = new iro$1.ColorPicker(containerRef.current, options);
6979
+ try {
6980
+ // Create the picker with enhanced error handling
6981
+ colorPickerRef.current = new iro$1.ColorPicker(containerRef.current, options);
6982
+ // Validate the picker was created successfully
6983
+ if (!colorPickerRef.current || !colorPickerRef.current.color) {
6984
+ throw new Error('ColorPicker was not created properly');
6985
+ }
6986
+ // Update picker ready state and notify parent
6987
+ // Force update of imperative handle by calling onMount callback
6988
+ if (onMount) {
6989
+ setTimeout(function () { return onMount(colorPickerRef.current); }, 0);
6990
+ }
6991
+ }
6992
+ catch (error) {
6993
+ colorPickerRef.current = null;
6994
+ return null; // Return null to indicate failure
6995
+ }
6953
6996
  // Apply theme styles to iro.js elements after creation
6954
6997
  var applyThemeStyles = function () {
6955
6998
  if (!containerRef.current)
@@ -7025,31 +7068,34 @@ var IroColorPicker = forwardRef(function (_a, ref) {
7025
7068
  onInputStart,
7026
7069
  onInputMove,
7027
7070
  onInputEnd,
7028
- onMount,
7029
- width,
7030
- containerWidth
7071
+ onMount
7031
7072
  ]);
7032
7073
  // Cleanup function
7033
7074
  var cleanup = useCallback(function () {
7034
7075
  if (colorPickerRef.current) {
7035
- // Clean up event listeners
7036
- if (onColorChange) {
7037
- colorPickerRef.current.off('color:change', onColorChange);
7038
- }
7039
- if (onInputChange) {
7040
- colorPickerRef.current.off('input:change', onInputChange);
7041
- }
7042
- if (onInputStart) {
7043
- colorPickerRef.current.off('input:start', onInputStart);
7044
- }
7045
- if (onInputMove) {
7046
- colorPickerRef.current.off('input:move', onInputMove);
7047
- }
7048
- if (onInputEnd) {
7049
- colorPickerRef.current.off('input:end', onInputEnd);
7076
+ try {
7077
+ // Clean up event listeners
7078
+ if (onColorChange) {
7079
+ colorPickerRef.current.off('color:change', onColorChange);
7080
+ }
7081
+ if (onInputChange) {
7082
+ colorPickerRef.current.off('input:change', onInputChange);
7083
+ }
7084
+ if (onInputStart) {
7085
+ colorPickerRef.current.off('input:start', onInputStart);
7086
+ }
7087
+ if (onInputMove) {
7088
+ colorPickerRef.current.off('input:move', onInputMove);
7089
+ }
7090
+ if (onInputEnd) {
7091
+ colorPickerRef.current.off('input:end', onInputEnd);
7092
+ }
7093
+ if (onMount) {
7094
+ colorPickerRef.current.off('mount', onMount);
7095
+ }
7050
7096
  }
7051
- if (onMount) {
7052
- colorPickerRef.current.off('mount', onMount);
7097
+ catch (error) {
7098
+ console.warn('Error cleaning up iro picker event listeners:', error);
7053
7099
  }
7054
7100
  // Set to null to ensure clean recreation
7055
7101
  colorPickerRef.current = null;
@@ -7066,38 +7112,70 @@ var IroColorPicker = forwardRef(function (_a, ref) {
7066
7112
  useEffect(function () {
7067
7113
  if (!width)
7068
7114
  return;
7069
- if (!containerRef.current || colorPickerRef.current) {
7070
- // Clear existing picker to force recreation
7071
- if (colorPickerRef.current) {
7072
- colorPickerRef.current = null;
7073
- }
7074
- }
7075
- var currentContainer = createColorPicker(width);
7115
+ var retryCount = 0;
7116
+ var maxRetries = 3;
7117
+ var createWithRetry = function () {
7118
+ // Longer initial delay to ensure DOM is completely ready
7119
+ var timeoutId = setTimeout(function () {
7120
+ try {
7121
+ var result = createColorPicker(width);
7122
+ if (!result &&
7123
+ colorPickerRef.current === null &&
7124
+ retryCount < maxRetries) {
7125
+ retryCount++;
7126
+ // Exponential backoff: 100ms, 200ms, 400ms
7127
+ setTimeout(createWithRetry, 100 * Math.pow(2, retryCount - 1));
7128
+ }
7129
+ }
7130
+ catch (error) {
7131
+ if (retryCount < maxRetries) {
7132
+ retryCount++;
7133
+ setTimeout(createWithRetry, 100 * Math.pow(2, retryCount - 1));
7134
+ }
7135
+ }
7136
+ }, 100); // Increased from 50ms to 100ms
7137
+ return function () { return clearTimeout(timeoutId); };
7138
+ };
7139
+ var cleanup = createWithRetry();
7076
7140
  return function () {
7141
+ if (cleanup)
7142
+ cleanup();
7077
7143
  cleanup();
7078
- // IMPORTANT: Clear DOM content to prevent visual artifacts
7079
- if (currentContainer) {
7080
- currentContainer.innerHTML = '';
7081
- }
7082
7144
  };
7083
7145
  }, [width, theme, createColorPicker, cleanup]);
7084
7146
  // useEffect for when containerWidth is used (internal ResizeObserver)
7085
7147
  useEffect(function () {
7086
7148
  if (width)
7087
7149
  return; // Don't run if width prop is provided
7088
- if (!containerRef.current || colorPickerRef.current) {
7089
- // Clear existing picker to force recreation
7090
- if (colorPickerRef.current) {
7091
- colorPickerRef.current = null;
7092
- }
7093
- }
7094
- var currentContainer = createColorPicker(containerWidth);
7150
+ var retryCount = 0;
7151
+ var maxRetries = 3;
7152
+ var createWithRetry = function () {
7153
+ // Longer initial delay to ensure DOM is completely ready
7154
+ var timeoutId = setTimeout(function () {
7155
+ try {
7156
+ var result = createColorPicker(containerWidth);
7157
+ if (!result &&
7158
+ colorPickerRef.current === null &&
7159
+ retryCount < maxRetries) {
7160
+ retryCount++;
7161
+ // Exponential backoff: 100ms, 200ms, 400ms
7162
+ setTimeout(createWithRetry, 100 * Math.pow(2, retryCount - 1));
7163
+ }
7164
+ }
7165
+ catch (error) {
7166
+ if (retryCount < maxRetries) {
7167
+ retryCount++;
7168
+ setTimeout(createWithRetry, 100 * Math.pow(2, retryCount - 1));
7169
+ }
7170
+ }
7171
+ }, 100); // Increased from 50ms to 100ms
7172
+ return function () { return clearTimeout(timeoutId); };
7173
+ };
7174
+ var cleanup = createWithRetry();
7095
7175
  return function () {
7176
+ if (cleanup)
7177
+ cleanup();
7096
7178
  cleanup();
7097
- // IMPORTANT: Clear DOM content to prevent visual artifacts
7098
- if (currentContainer) {
7099
- currentContainer.innerHTML = '';
7100
- }
7101
7179
  };
7102
7180
  }, [containerWidth, theme, createColorPicker, cleanup, width]);
7103
7181
  // Update color when prop changes
@@ -7293,9 +7371,8 @@ var DefaultColorPanel = function (_a) {
7293
7371
  // eslint-disable-next-line react-hooks/exhaustive-deps
7294
7372
  }, []);
7295
7373
  var onChooseColor = function (item, index) {
7296
- if (index === active) {
7297
- return;
7298
- }
7374
+ // Allow re-applying the same color (removed guard clause that prevented this)
7375
+ // This enables users to reset back to a popular color after making changes
7299
7376
  if (colorType === 'gradient' && typeof item !== 'string') {
7300
7377
  // If this is a simplified display object (identified by dummy stops), parse the gradient properly
7301
7378
  if (item.stops.length === 2 &&
@@ -7473,20 +7550,37 @@ var Markers = function (_a) {
7473
7550
  window.addEventListener('mouseup', onDragEnd);
7474
7551
  };
7475
7552
  var onDrag = function (e) {
7476
- var _a;
7477
7553
  // Defensive check for event object
7478
7554
  if (!e) {
7479
7555
  console.warn('onDrag called with undefined event object');
7480
7556
  return;
7481
7557
  }
7558
+ // More defensive check for component and node availability
7559
+ if (!node || !node.current) {
7560
+ console.warn('Unable to get bounding rect: component reference unavailable');
7561
+ // Clean up event listeners if component is no longer mounted
7562
+ window.removeEventListener('mousemove', onDrag);
7563
+ window.removeEventListener('mouseup', onDragEnd);
7564
+ return;
7565
+ }
7482
7566
  var x = e.clientX || 0;
7483
7567
  var y = e.clientY || 0;
7484
- var rect = (_a = node === null || node === void 0 ? void 0 : node.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
7568
+ var rect;
7569
+ try {
7570
+ rect = node.current.getBoundingClientRect();
7571
+ }
7572
+ catch (error) {
7573
+ console.warn('Unable to get bounding rect for drag operation:', error);
7574
+ // Clean up event listeners on error
7575
+ window.removeEventListener('mousemove', onDrag);
7576
+ window.removeEventListener('mouseup', onDragEnd);
7577
+ return;
7578
+ }
7485
7579
  if (!rect) {
7486
- console.warn('Unable to get bounding rect for drag operation');
7580
+ console.warn('Unable to get bounding rect: getBoundingClientRect returned null');
7487
7581
  return;
7488
7582
  }
7489
- var rootDistance = y - rect.y;
7583
+ var rootDistance = y - (rect.y || rect.top);
7490
7584
  // Now we know user is actually dragging
7491
7585
  setIsDragging(true);
7492
7586
  if (rootDistance > 80 && stops.length > 2) {
@@ -7502,11 +7596,33 @@ var Markers = function (_a) {
7502
7596
  });
7503
7597
  };
7504
7598
  var onDragEnd = function (e) {
7505
- var _a;
7506
- var x = e.clientX;
7507
- var y = e.clientY;
7508
- var rect = (_a = node === null || node === void 0 ? void 0 : node.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
7509
- var rootDistance = y - rect.y;
7599
+ // Always remove listeners first, regardless of errors
7600
+ removeListeners();
7601
+ setIsDragging(false); // Mark as not dragging
7602
+ // Defensive event and component checks
7603
+ if (!e) {
7604
+ console.warn('onDragEnd called with undefined event object');
7605
+ return;
7606
+ }
7607
+ if (!node || !node.current) {
7608
+ console.warn('onDragEnd: component reference unavailable');
7609
+ return;
7610
+ }
7611
+ var x = e.clientX || 0;
7612
+ var y = e.clientY || 0;
7613
+ var rect;
7614
+ try {
7615
+ rect = node.current.getBoundingClientRect();
7616
+ }
7617
+ catch (error) {
7618
+ console.warn('Unable to get bounding rect in onDragEnd:', error);
7619
+ return;
7620
+ }
7621
+ if (!rect) {
7622
+ console.warn('onDragEnd: getBoundingClientRect returned null');
7623
+ return;
7624
+ }
7625
+ var rootDistance = y - (rect.y || rect.top);
7510
7626
  if (rootDistance > 80 && stops.length > 2) {
7511
7627
  setNeedDeleteActive(true);
7512
7628
  }
@@ -7514,8 +7630,6 @@ var Markers = function (_a) {
7514
7630
  x: x,
7515
7631
  y: y
7516
7632
  });
7517
- setIsDragging(false); // Mark as not dragging
7518
- removeListeners();
7519
7633
  };
7520
7634
  var onTouchStart = function (e, color) {
7521
7635
  setInit(false);
@@ -7548,7 +7662,7 @@ var Markers = function (_a) {
7548
7662
  var x = e.targetTouches[0].clientX;
7549
7663
  var y = e.targetTouches[0].clientY;
7550
7664
  var rect = (_a = node === null || node === void 0 ? void 0 : node.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
7551
- var rootDistance = y - rect.y;
7665
+ var rootDistance = y - ((rect === null || rect === void 0 ? void 0 : rect.y) || (rect === null || rect === void 0 ? void 0 : rect.top) || 0);
7552
7666
  // Now we know user is actually dragging
7553
7667
  setIsDragging(true);
7554
7668
  if (rootDistance > 80 && stops.length > 2) {
@@ -7678,6 +7792,33 @@ var RADIALS_POS = [
7678
7792
  { pos: 'br', css: 'circle at right bottom', active: false }
7679
7793
  ];
7680
7794
 
7795
+ // Map aliases like 'circle at top center' to 'circle at center top', etc.
7796
+ // Also handle edge cases like numeric sizes (70, 150%) -> default to center
7797
+ var normalizeRadialPosition = function (modifier) {
7798
+ var _a;
7799
+ if (typeof modifier !== 'string')
7800
+ return modifier;
7801
+ // Handle edge cases:
7802
+ // - Pure numeric sizes (70, 150%, 200px, etc.) -> default to center
7803
+ // - Size keywords (closest-side, farthest-corner, etc.) -> default to center
7804
+ if (/^\d+(%|px|em|rem)?$/.test(modifier.trim()) ||
7805
+ /^(closest-side|closest-corner|farthest-side|farthest-corner)$/i.test(modifier.trim())) {
7806
+ return 'circle at center';
7807
+ }
7808
+ // Handle standard "circle at position" or "ellipse at position" format
7809
+ var match = modifier.match(/^(circle|ellipse) at (.+)$/);
7810
+ if (!match) {
7811
+ // If it doesn't match any known pattern, default to center for radial gradients
7812
+ return 'circle at center';
7813
+ }
7814
+ var pos = ((_a = match[2]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
7815
+ pos = pos
7816
+ .replace(/^top center$/i, 'center top')
7817
+ .replace(/^bottom center$/i, 'center bottom')
7818
+ .replace(/^left center$/i, 'center left')
7819
+ .replace(/^right center$/i, 'center right');
7820
+ return "".concat(match[1], " at ").concat(pos);
7821
+ };
7681
7822
  var GradientPanel = function (_a) {
7682
7823
  var color = _a.color, setColor = _a.setColor, activeColor = _a.activeColor, setActiveColor = _a.setActiveColor, setInit = _a.setInit, _b = _a.format, format = _b === void 0 ? 'rgb' : _b, _c = _a.showAlpha, showAlpha = _c === void 0 ? true : _c, _d = _a.showGradientResult, showGradientResult = _d === void 0 ? true : _d, _e = _a.showGradientStops, showGradientStops = _e === void 0 ? true : _e, _f = _a.showGradientMode, showGradientMode = _f === void 0 ? true : _f, _g = _a.showGradientAngle, showGradientAngle = _g === void 0 ? true : _g, _h = _a.showGradientPosition, showGradientPosition = _h === void 0 ? true : _h, _j = _a.allowAddGradientStops, allowAddGradientStops = _j === void 0 ? true : _j;
7683
7824
  var angleNode = useRef();
@@ -7823,10 +7964,11 @@ var GradientPanel = function (_a) {
7823
7964
  }, []);
7824
7965
  useEffect(function () {
7825
7966
  if (type === 'radial') {
7826
- var activePos = radialsPosition.find(function (item) { return item.css === modifier; });
7827
- setColor(__assign(__assign({}, color), { modifier: (activePos === null || activePos === void 0 ? void 0 : activePos.css) || modifier, gradient: "".concat(getGradient('radial', stops, (activePos === null || activePos === void 0 ? void 0 : activePos.css) || modifier, format, showAlpha)) }));
7967
+ var normalizedModifier_1 = normalizeRadialPosition(String(modifier));
7968
+ var activePos = RADIALS_POS.find(function (item) { return item.css === normalizedModifier_1; });
7969
+ setColor(__assign(__assign({}, color), { modifier: (activePos === null || activePos === void 0 ? void 0 : activePos.css) || normalizedModifier_1, gradient: "".concat(getGradient('radial', stops, (activePos === null || activePos === void 0 ? void 0 : activePos.css) || normalizedModifier_1, format, showAlpha)) }));
7828
7970
  setRadialPosition(RADIALS_POS.map(function (item) {
7829
- if (item.css === modifier) {
7971
+ if (item.css === normalizedModifier_1) {
7830
7972
  return __assign(__assign({}, item), { active: true });
7831
7973
  }
7832
7974
  return __assign(__assign({}, item), { active: false });
@@ -7941,6 +8083,8 @@ var IroGradient = function (_a) {
7941
8083
  var iroPickerRef = useRef(null);
7942
8084
  var containerRef = useRef(null);
7943
8085
  var isUpdatingFromGradientStop = useRef(false);
8086
+ var lastUpdateAttempt = useRef(0); // Track last update attempt
8087
+ var isPickerInitialized = useRef(false); // Track if picker is already initialized
7944
8088
  var _t = __read(useState(200), 2), pickerWidth = _t[0], setPickerWidth = _t[1];
7945
8089
  // Safe extraction of stop data with fallbacks
7946
8090
  var safeStops = Array.isArray(stops) && stops.length > 0
@@ -8014,17 +8158,37 @@ var IroGradient = function (_a) {
8014
8158
  // Update iro picker color
8015
8159
  var updateIroPickerColor = useCallback(function (colorData, retryCount) {
8016
8160
  if (retryCount === void 0) { retryCount = 0; }
8017
- var maxRetries = 5;
8018
- // Validate input data
8019
- if (!colorData || !colorData.hex || typeof colorData.alpha !== 'number') {
8020
- console.log('❌ Invalid color data provided to updateIroPickerColor:', colorData);
8161
+ var maxRetries = 3; // Reduced from 5 to limit spam
8162
+ // Enhanced validation for color data
8163
+ if (!colorData ||
8164
+ typeof colorData.hex !== 'string' ||
8165
+ typeof colorData.alpha !== 'number') {
8021
8166
  return; // Early return if invalid data
8022
8167
  }
8168
+ // Throttle rapid calls - but allow calls if color is significantly different
8169
+ var now = Date.now();
8170
+ var timeSinceLastUpdate = now - lastUpdateAttempt.current;
8171
+ // Allow immediate update if throttling time has passed OR if it's a significant color change
8172
+ if (timeSinceLastUpdate < 100) {
8173
+ return;
8174
+ }
8175
+ lastUpdateAttempt.current = now;
8023
8176
  var updateColor = function () {
8024
- var _a, _b, _c, _d, _e, _f;
8177
+ // Enhanced picker readiness check
8178
+ var isPickerReady = function () {
8179
+ try {
8180
+ return (iroPickerRef.current &&
8181
+ iroPickerRef.current.colorPicker &&
8182
+ iroPickerRef.current.colorPicker.color &&
8183
+ typeof iroPickerRef.current.colorPicker.color.set === 'function');
8184
+ }
8185
+ catch (error) {
8186
+ console.warn('Error checking picker readiness:', error);
8187
+ return false;
8188
+ }
8189
+ };
8025
8190
  // Check if picker is properly initialized
8026
- if (((_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) &&
8027
- iroPickerRef.current.colorPicker.color) {
8191
+ if (isPickerReady()) {
8028
8192
  var iroColor = showAlpha
8029
8193
  ? {
8030
8194
  r: parseInt(colorData.hex.slice(1, 3), 16),
@@ -8036,52 +8200,33 @@ var IroGradient = function (_a) {
8036
8200
  try {
8037
8201
  // Set flag to prevent circular updates
8038
8202
  isUpdatingFromGradientStop.current = true;
8039
- console.log('🎨 Updating iro picker in gradient mode (attempt:', retryCount + 1, '):', {
8040
- hex: colorData.hex,
8041
- alpha: colorData.alpha,
8042
- iroColor: iroColor,
8043
- pickerReady: !!((_c = (_b = iroPickerRef.current) === null || _b === void 0 ? void 0 : _b.colorPicker) === null || _c === void 0 ? void 0 : _c.color)
8044
- });
8045
8203
  iroPickerRef.current.colorPicker.color.set(iroColor);
8046
8204
  // Reset flag after a short delay
8047
8205
  setTimeout(function () {
8048
8206
  isUpdatingFromGradientStop.current = false;
8049
8207
  }, 100);
8050
- console.log('✅ Successfully updated iro picker');
8051
8208
  }
8052
8209
  catch (error) {
8053
8210
  isUpdatingFromGradientStop.current = false;
8054
- console.warn('❌ Error updating iro color picker:', error);
8055
- // Retry with exponential backoff
8211
+ // Retry with exponential backoff only for actual errors, not readiness issues
8056
8212
  if (retryCount < maxRetries) {
8057
- var delay = 100 * Math.pow(2, retryCount); // 100ms, 200ms, 400ms, etc.
8058
- console.log("\uD83D\uDD04 Retrying in ".concat(delay, "ms (attempt ").concat(retryCount + 2, "/").concat(maxRetries + 1, ")"));
8213
+ var delay = 150 + retryCount * 100; // 150ms, 250ms, 350ms
8059
8214
  setTimeout(function () {
8060
8215
  updateIroPickerColor(colorData, retryCount + 1);
8061
8216
  }, delay);
8062
8217
  }
8063
- else {
8064
- console.error('💥 Max retries reached, giving up on iro picker update');
8065
- }
8066
8218
  }
8067
8219
  }
8068
8220
  else {
8069
- console.log('⏳ Iro picker not ready, retrying...', {
8070
- hasRef: !!iroPickerRef.current,
8071
- hasColorPicker: !!((_d = iroPickerRef.current) === null || _d === void 0 ? void 0 : _d.colorPicker),
8072
- hasColor: !!((_f = (_e = iroPickerRef.current) === null || _e === void 0 ? void 0 : _e.colorPicker) === null || _f === void 0 ? void 0 : _f.color),
8073
- attempt: retryCount + 1
8074
- });
8075
- // If picker is not ready, retry with increasing delays
8076
- if (retryCount < maxRetries) {
8077
- var delay = 50 + retryCount * 100; // 50ms, 150ms, 250ms, etc.
8221
+ // If picker is not ready, wait longer before retrying
8222
+ if (retryCount < 3) {
8223
+ // Reduced max retries for readiness checks
8224
+ // Longer delays for picker readiness: 200ms, 500ms, 1000ms
8225
+ var delay = 200 + retryCount * 300;
8078
8226
  setTimeout(function () {
8079
8227
  updateIroPickerColor(colorData, retryCount + 1);
8080
8228
  }, delay);
8081
8229
  }
8082
- else {
8083
- console.error('💥 Iro picker never became ready, giving up');
8084
- }
8085
8230
  }
8086
8231
  };
8087
8232
  updateColor();
@@ -8095,11 +8240,16 @@ var IroGradient = function (_a) {
8095
8240
  // Initialize iro picker with current activeColor when component mounts or picker becomes ready
8096
8241
  useEffect(function () {
8097
8242
  var initializeIroPicker = function () {
8098
- var _a, _b;
8099
- if (((_b = (_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) === null || _b === void 0 ? void 0 : _b.color) &&
8243
+ var _a, _b, _c, _d;
8244
+ // Skip if picker is already initialized and working
8245
+ if (isPickerInitialized.current &&
8246
+ ((_b = (_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) === null || _b === void 0 ? void 0 : _b.color)) {
8247
+ return;
8248
+ }
8249
+ if (((_d = (_c = iroPickerRef.current) === null || _c === void 0 ? void 0 : _c.colorPicker) === null || _d === void 0 ? void 0 : _d.color) &&
8100
8250
  activeColor.hex &&
8101
8251
  typeof activeColor.alpha === 'number') {
8102
- console.log('🚀 Initializing iro picker with activeColor:', activeColor);
8252
+ isPickerInitialized.current = true;
8103
8253
  // Wait a bit for the picker to be fully ready, then update
8104
8254
  setTimeout(function () {
8105
8255
  updateIroPickerColor({
@@ -8109,49 +8259,45 @@ var IroGradient = function (_a) {
8109
8259
  }, 200);
8110
8260
  }
8111
8261
  };
8112
- // Try immediately
8113
- initializeIroPicker();
8114
- // Also try after a delay in case picker wasn't ready
8115
- var timeoutId = setTimeout(initializeIroPicker, 500);
8116
- return function () { return clearTimeout(timeoutId); };
8262
+ // Only initialize if not already initialized
8263
+ if (!isPickerInitialized.current) {
8264
+ // Try immediately
8265
+ initializeIroPicker();
8266
+ // Also try after a delay in case picker wasn't ready
8267
+ var timeoutId_1 = setTimeout(initializeIroPicker, 500);
8268
+ return function () { return clearTimeout(timeoutId_1); };
8269
+ }
8270
+ // Return empty cleanup function when no initialization is needed
8271
+ return function () { };
8117
8272
  }, [activeColor, updateIroPickerColor]); // Initialize when activeColor or updateFunction changes
8118
8273
  // Custom setActiveColor that also updates iro picker
8119
8274
  var handleSetActiveColor = useCallback(function (newActiveColor) {
8120
- console.log('🎯 Gradient stop clicked, setting active color:', newActiveColor);
8121
- setActiveColor(newActiveColor);
8122
- // Validate before updating iro picker
8123
- if (newActiveColor.hex && typeof newActiveColor.alpha === 'number') {
8124
- // Force immediate update of iro picker with longer delay for first-time reliability
8125
- setTimeout(function () {
8126
- updateIroPickerColor({
8127
- hex: newActiveColor.hex,
8128
- alpha: newActiveColor.alpha
8129
- });
8130
- }, 50); // Increased from 5ms to 50ms for better first-time success
8275
+ // Handle both direct values and function updaters
8276
+ if (typeof newActiveColor === 'function') {
8277
+ // This is a function updater - call setActiveColor properly
8278
+ setActiveColor(function (prev) {
8279
+ var updated = newActiveColor(prev);
8280
+ // Note: useEffect will handle iro picker update automatically
8281
+ return updated;
8282
+ });
8131
8283
  }
8132
8284
  else {
8133
- console.log('⚠️ Skipping iro picker update in handleSetActiveColor - invalid data:', newActiveColor);
8285
+ // This is a direct value - just update state, useEffect will handle iro picker update
8286
+ setActiveColor(newActiveColor);
8134
8287
  }
8135
- }, [updateIroPickerColor]);
8136
- // Update iro picker when activeColor changes (e.g., clicking gradient stops)
8288
+ }, [] // No dependencies needed since we're just calling setState
8289
+ );
8290
+ // Update iro picker when activeColor's hex or alpha changes (not location)
8137
8291
  useEffect(function () {
8138
- console.log('🔄 ActiveColor changed in gradient:', {
8139
- hex: activeColor.hex,
8140
- alpha: activeColor.alpha,
8141
- index: activeColor.index,
8142
- loc: activeColor.loc
8143
- });
8292
+ var hex = activeColor.hex, alpha = activeColor.alpha;
8144
8293
  // Validate activeColor before proceeding
8145
- if (!activeColor.hex || typeof activeColor.alpha !== 'number') {
8146
- console.log('⚠️ Skipping iro picker update - invalid activeColor:', activeColor);
8294
+ if (!hex || typeof alpha !== 'number') {
8147
8295
  return;
8148
8296
  }
8149
- // Add a small delay to ensure the activeColor state has fully updated
8150
- var timeoutId = setTimeout(function () {
8151
- updateIroPickerColor({ hex: activeColor.hex, alpha: activeColor.alpha });
8152
- }, 10);
8153
- return function () { return clearTimeout(timeoutId); };
8154
- }, [activeColor, updateIroPickerColor]);
8297
+ // Update iro picker immediately when color changes
8298
+ updateIroPickerColor({ hex: hex, alpha: alpha });
8299
+ // eslint-disable-next-line react-hooks/exhaustive-deps
8300
+ }, [activeColor.hex, activeColor.alpha, updateIroPickerColor]); // Only depend on hex and alpha, not full activeColor
8155
8301
  var updateGradient = useCallback(function (newColor) {
8156
8302
  if (Array.isArray(newColor)) {
8157
8303
  // Handle the case where it's called with stops array
@@ -8212,7 +8358,6 @@ var IroGradient = function (_a) {
8212
8358
  };
8213
8359
  // Reset to initial color
8214
8360
  var handleResetColor = function () {
8215
- var _a;
8216
8361
  var initialParsed = parseGradient(initialValue.current);
8217
8362
  setColor(initialParsed);
8218
8363
  // Reset active color to the last stop of the initial gradient
@@ -8224,13 +8369,7 @@ var IroGradient = function (_a) {
8224
8369
  index: initialParsed.stops.length - 1
8225
8370
  };
8226
8371
  setActiveColor(newActiveColor);
8227
- // Update iro picker if available
8228
- if ((_a = iroPickerRef.current) === null || _a === void 0 ? void 0 : _a.colorPicker) {
8229
- updateIroPickerColor({
8230
- hex: newActiveColor.hex,
8231
- alpha: newActiveColor.alpha
8232
- });
8233
- }
8372
+ // Note: useEffect will handle iro picker update automatically when activeColor changes
8234
8373
  // Call onChange with initial value
8235
8374
  onChange(initialValue.current);
8236
8375
  // Call onReset callback if provided
@@ -8249,11 +8388,7 @@ var IroGradient = function (_a) {
8249
8388
  index: newColor.stops.length - 1
8250
8389
  };
8251
8390
  setActiveColor(newActiveColor);
8252
- // Update the iro color picker
8253
- updateIroPickerColor({
8254
- hex: newActiveColor.hex,
8255
- alpha: newActiveColor.alpha
8256
- });
8391
+ // Note: useEffect will handle iro picker update automatically when activeColor changes
8257
8392
  }
8258
8393
  };
8259
8394
  var handleIroColorChange = function (iroColor) {
@@ -8334,7 +8469,6 @@ var IroSolidColorPicker = function (_a) {
8334
8469
  // Update ref when state changes
8335
8470
  useEffect(function () {
8336
8471
  pickerWidthRef.current = pickerWidth;
8337
- console.log('📊 Picker width state changed to:', pickerWidth);
8338
8472
  }, [pickerWidth]);
8339
8473
  // Calculate responsive width based on container
8340
8474
  var getResponsiveWidth = function (containerWidth) {
@@ -8362,7 +8496,6 @@ var IroSolidColorPicker = function (_a) {
8362
8496
  var newWidth = Math.floor(getResponsiveWidth(rect.width));
8363
8497
  if (Math.abs(newWidth - pickerWidthRef.current) > 5) {
8364
8498
  // Only update if significant change
8365
- console.log('� Size update:', { container: rect.width, newWidth: newWidth });
8366
8499
  setPickerWidth(newWidth);
8367
8500
  }
8368
8501
  }
@@ -8389,20 +8522,17 @@ var IroSolidColorPicker = function (_a) {
8389
8522
  }
8390
8523
  var debug = window.debugPicker;
8391
8524
  debug.getCurrentWidth = function () {
8392
- console.log('Current picker width:', pickerWidth);
8393
8525
  return pickerWidth;
8394
8526
  };
8395
8527
  debug.getContainerWidth = function () {
8396
8528
  var _a;
8397
8529
  var width = (_a = node.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width;
8398
- console.log('Current container width:', width);
8399
8530
  return width;
8400
8531
  };
8401
8532
  debug.forceResize = function () {
8402
8533
  if (node.current) {
8403
8534
  var rect = node.current.getBoundingClientRect();
8404
8535
  var newWidth = Math.floor(getResponsiveWidth(rect.width));
8405
- console.log('🔧 Force resize:', { container: rect.width, newWidth: newWidth });
8406
8536
  setPickerWidth(newWidth);
8407
8537
  }
8408
8538
  };
@@ -8447,11 +8577,6 @@ var IroSolidColorPicker = function (_a) {
8447
8577
  }
8448
8578
  }, [value, showAlpha]);
8449
8579
  var handleColorChange = function (iroColor) {
8450
- console.log('🎨 Alpha slider changed!', {
8451
- hex: iroColor.hexString,
8452
- alpha: iroColor.alpha,
8453
- alphaPercent: Math.round(iroColor.alpha * 100)
8454
- });
8455
8580
  var newColor = {
8456
8581
  hex: iroColor.hexString,
8457
8582
  alpha: Math.round(iroColor.alpha * 100)