react-iro-gradient-picker 1.4.0 → 1.4.1

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
@@ -115,23 +115,6 @@ var ThemeProvider = function (_a) {
115
115
  return (React.createElement(ThemeContext.Provider, { value: value }, children));
116
116
  };
117
117
 
118
- // Simple sun and moon icons as SVG components
119
- var SunIcon = function (_a) {
120
- var className = _a.className;
121
- return (React.createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
122
- React.createElement("path", { fillRule: 'evenodd', d: 'M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z', clipRule: 'evenodd' })));
123
- };
124
- var MoonIcon = function (_a) {
125
- var className = _a.className;
126
- return (React.createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
127
- React.createElement("path", { d: 'M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z' })));
128
- };
129
- var ThemeToggle = function (_a) {
130
- var className = _a.className;
131
- var _b = useTheme(), theme = _b.theme, toggleTheme = _b.toggleTheme;
132
- return (React.createElement("button", { onClick: toggleTheme, className: "theme-toggle ".concat(className || ''), "aria-label": "Switch to ".concat(theme === 'light' ? 'dark' : 'light', " theme"), title: "Switch to ".concat(theme === 'light' ? 'dark' : 'light', " theme") }, theme === 'light' ? (React.createElement(MoonIcon, { className: 'theme-toggle-icon' })) : (React.createElement(SunIcon, { className: 'theme-toggle-icon' }))));
133
- };
134
-
135
118
  /*!
136
119
  * iro.js v5.5.2
137
120
  * 2016-2021 James Daniel
@@ -7343,9 +7326,9 @@ var shallowEqual = function (object1, object2) {
7343
7326
  };
7344
7327
 
7345
7328
  var DefaultColorPanel = function (_a) {
7346
- var _b = _a.defaultColors, defaultColors = _b === void 0 ? [] : _b, setColor = _a.setColor, setActiveColor = _a.setActiveColor, setInit = _a.setInit, colorType = _a.colorType;
7347
- var _c = __read(useState(-1), 2), active = _c[0], setActive = _c[1];
7348
- var _d = __read(useState([]), 2), formatedDefColors = _d[0], setFormatedDefColors = _d[1];
7329
+ var _b = _a.defaultColors, defaultColors = _b === void 0 ? [] : _b, setColor = _a.setColor, setActiveColor = _a.setActiveColor, setInit = _a.setInit, colorType = _a.colorType, currentValue = _a.currentValue, _c = _a.size, size = _c === void 0 ? 'default' : _c;
7330
+ var _d = __read(useState(-1), 2), active = _d[0], setActive = _d[1];
7331
+ var _e = __read(useState([]), 2), formatedDefColors = _e[0], setFormatedDefColors = _e[1];
7349
7332
  useEffect(function () {
7350
7333
  if (colorType === 'gradient') {
7351
7334
  var validGradients = checkValidColorsArray(defaultColors, 'grad');
@@ -7364,12 +7347,27 @@ var DefaultColorPanel = function (_a) {
7364
7347
  };
7365
7348
  });
7366
7349
  setFormatedDefColors(displayGradients);
7350
+ // Set initial active state if currentValue matches a gradient
7351
+ if (currentValue) {
7352
+ var matchIndex = validGradients.findIndex(function (grad) { return grad === currentValue; });
7353
+ if (matchIndex !== -1) {
7354
+ setActive(matchIndex);
7355
+ }
7356
+ }
7367
7357
  }
7368
7358
  else {
7369
- setFormatedDefColors(checkValidColorsArray(defaultColors, 'solid'));
7359
+ var solidColors = checkValidColorsArray(defaultColors, 'solid');
7360
+ setFormatedDefColors(solidColors);
7361
+ // Set initial active state if currentValue matches a solid color
7362
+ if (currentValue) {
7363
+ var matchIndex = solidColors.findIndex(function (color) { return color.toLowerCase() === currentValue.toLowerCase(); });
7364
+ if (matchIndex !== -1) {
7365
+ setActive(matchIndex);
7366
+ }
7367
+ }
7370
7368
  }
7371
7369
  // eslint-disable-next-line react-hooks/exhaustive-deps
7372
- }, []);
7370
+ }, [currentValue]);
7373
7371
  var onChooseColor = function (item, index) {
7374
7372
  // Allow re-applying the same color (removed guard clause that prevented this)
7375
7373
  // This enables users to reset back to a popular color after making changes
@@ -7434,14 +7432,21 @@ var DefaultColorPanel = function (_a) {
7434
7432
  if (!Array.isArray(defaultColors) || !defaultColors.length) {
7435
7433
  return null;
7436
7434
  }
7435
+ // Determine sizing classes based on size prop
7436
+ var sizeClasses = {
7437
+ compact: { button: 'w-8 h-8', gap: 'gap-1.5' },
7438
+ default: { button: 'w-10 h-10', gap: 'gap-4' },
7439
+ large: { button: 'w-12 h-12', gap: 'gap-5' }
7440
+ };
7441
+ var _f = sizeClasses[size], buttonSize = _f.button, gapSize = _f.gap;
7437
7442
  return (React.createElement("div", { className: 'w-full' },
7438
7443
  React.createElement("h3", { className: 'text-sm font-medium colorpicker-text' }, "Popular Colors"),
7439
- React.createElement("div", { className: 'grid grid-cols-5 gap-4 py-4' }, formatedDefColors.map(function (item, index) {
7444
+ React.createElement("div", { className: cn('grid grid-cols-5 py-4', gapSize) }, formatedDefColors.map(function (item, index) {
7440
7445
  switch (colorType) {
7441
7446
  case 'gradient':
7442
7447
  if (typeof item !== 'string') {
7443
7448
  var gradient = item.gradient;
7444
- return (React.createElement("button", { type: 'button', onClick: function () { return onChooseColor(item, index); }, key: item.gradient + index, className: cn('aspect-square w-10 h-10 rounded-md border-2 transition-all duration-200', 'hover:scale-110 hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500/50', 'relative overflow-hidden group', active === index
7449
+ return (React.createElement("button", { type: 'button', onClick: function () { return onChooseColor(item, index); }, key: item.gradient + index, className: cn('aspect-square rounded-md border-2 transition-all duration-200', buttonSize, 'hover:scale-110 hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500/50', 'relative overflow-hidden group', active === index
7445
7450
  ? 'border-blue-500 dark:border-blue-400 shadow-lg scale-105'
7446
7451
  : 'border-slate-200 dark:border-slate-600 hover:border-slate-300 dark:hover:border-slate-500'), style: { background: gradient } },
7447
7452
  React.createElement("div", { className: 'absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors duration-200' })));
@@ -7451,7 +7456,7 @@ var DefaultColorPanel = function (_a) {
7451
7456
  }
7452
7457
  case 'solid':
7453
7458
  if (typeof item === 'string') {
7454
- return (React.createElement("button", { type: 'button', onClick: function () { return onChooseColor(item, index); }, key: item + index, className: cn('aspect-square w-10 h-10 rounded-md border-2 transition-all duration-200', 'hover:scale-110 hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500/50', 'relative overflow-hidden group', active === index
7459
+ return (React.createElement("button", { type: 'button', onClick: function () { return onChooseColor(item, index); }, key: item + index, className: cn('aspect-square rounded-md border-2 transition-all duration-200', buttonSize, 'hover:scale-110 hover:shadow-lg focus:outline-none focus:ring-2 focus:ring-blue-500/50', 'relative overflow-hidden group', active === index
7455
7460
  ? 'border-blue-500 dark:border-blue-400 shadow-lg scale-105'
7456
7461
  : 'border-slate-200 dark:border-slate-600 hover:border-slate-300 dark:hover:border-slate-500'), style: {
7457
7462
  background: item,
@@ -8018,7 +8023,7 @@ var useDebounce = (function (value, delay) {
8018
8023
  });
8019
8024
 
8020
8025
  var IroGradient = function (_a) {
8021
- 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;
8026
+ 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, _s = _a.popupWidth, popupWidth = _s === void 0 ? 280 : _s;
8022
8027
  // Store the initial value for reset functionality
8023
8028
  var initialValue = useRef(value);
8024
8029
  var parsedColors = useCallback(function () {
@@ -8079,13 +8084,13 @@ var IroGradient = function (_a) {
8079
8084
  }
8080
8085
  // eslint-disable-next-line react-hooks/exhaustive-deps
8081
8086
  }, [value]);
8082
- var _s = parsedColors(), stops = _s.stops, type = _s.type, modifier = _s.modifier;
8087
+ var _t = parsedColors(), stops = _t.stops, type = _t.type, modifier = _t.modifier;
8083
8088
  var iroPickerRef = useRef(null);
8084
8089
  var containerRef = useRef(null);
8085
8090
  var isUpdatingFromGradientStop = useRef(false);
8086
8091
  var lastUpdateAttempt = useRef(0); // Track last update attempt
8087
8092
  var isPickerInitialized = useRef(false); // Track if picker is already initialized
8088
- var _t = __read(useState(200), 2), pickerWidth = _t[0], setPickerWidth = _t[1];
8093
+ var _u = __read(useState(200), 2), pickerWidth = _u[0], setPickerWidth = _u[1];
8089
8094
  // Safe extraction of stop data with fallbacks
8090
8095
  var safeStops = Array.isArray(stops) && stops.length > 0
8091
8096
  ? stops
@@ -8142,18 +8147,18 @@ var IroGradient = function (_a) {
8142
8147
  resizeObserver.observe(containerRef.current);
8143
8148
  return function () { return resizeObserver.disconnect(); };
8144
8149
  }, []);
8145
- var _u = __read(useState({
8150
+ var _v = __read(useState({
8146
8151
  gradient: value,
8147
8152
  type: type,
8148
8153
  modifier: modifier,
8149
8154
  stops: safeStops
8150
- }), 2), color = _u[0], setColor = _u[1];
8151
- var _v = __read(useState({
8155
+ }), 2), color = _v[0], setColor = _v[1];
8156
+ var _w = __read(useState({
8152
8157
  hex: activeStop,
8153
8158
  alpha: activeAlpha,
8154
8159
  loc: safeStops[activeStopIndex][1],
8155
8160
  index: activeStopIndex
8156
- }), 2), activeColor = _v[0], setActiveColor = _v[1];
8161
+ }), 2), activeColor = _w[0], setActiveColor = _w[1];
8157
8162
  var debounceColor = useDebounce(color, debounceMS);
8158
8163
  // Update iro picker color
8159
8164
  var updateIroPickerColor = useCallback(function (colorData, retryCount) {
@@ -8377,6 +8382,13 @@ var IroGradient = function (_a) {
8377
8382
  };
8378
8383
  // Update iro picker when color is selected from default colors panel
8379
8384
  var handleColorFromPanel = function (newColor) {
8385
+ console.log('handleColorFromPanel called with:', newColor);
8386
+ // Ensure the gradient CSS string is properly set
8387
+ if ((newColor === null || newColor === void 0 ? void 0 : newColor.stops) && !newColor.gradient) {
8388
+ // Reconstruct the gradient string if missing
8389
+ newColor.gradient = getGradient(newColor.type || 'linear', newColor.stops, newColor.modifier || 90, format, showAlpha);
8390
+ console.log('Reconstructed gradient:', newColor.gradient);
8391
+ }
8380
8392
  setColor(newColor);
8381
8393
  if (newColor === null || newColor === void 0 ? void 0 : newColor.stops) {
8382
8394
  var lastStop = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
@@ -8387,6 +8399,7 @@ var IroGradient = function (_a) {
8387
8399
  loc: newColor.stops[newColor.stops.length - 1][1],
8388
8400
  index: newColor.stops.length - 1
8389
8401
  };
8402
+ console.log('Setting activeColor to:', newActiveColor);
8390
8403
  setActiveColor(newActiveColor);
8391
8404
  // Note: useEffect will handle iro picker update automatically when activeColor changes
8392
8405
  }
@@ -8443,7 +8456,11 @@ var IroGradient = function (_a) {
8443
8456
  React.createElement("div", { className: 'rounded-lg colorpicker-glass px-4' },
8444
8457
  React.createElement(GradientPanel$1, { color: color, activeColor: activeColor, setActiveColor: handleSetActiveColor, setColor: updateGradient, setInit: setInit, format: format, showAlpha: showAlpha, showGradientResult: showGradientResult, showGradientStops: showGradientStops, showGradientMode: showGradientMode, showGradientAngle: showGradientAngle, showGradientPosition: showGradientPosition, allowAddGradientStops: allowAddGradientStops })),
8445
8458
  React.createElement("div", { className: 'pt-4 px-2' },
8446
- React.createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: function () { }, setActiveColor: handleSetActiveColor, colorType: 'gradient' })),
8459
+ React.createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: function () { }, setActiveColor: handleSetActiveColor, colorType: 'gradient', currentValue: color.gradient, size: popupWidth < 250
8460
+ ? 'compact'
8461
+ : popupWidth <= 350
8462
+ ? 'default'
8463
+ : 'large' })),
8447
8464
  showInputs && (React.createElement("div", { className: 'rounded-lg colorpicker-glass flex items-center gap-2' },
8448
8465
  React.createElement("div", { className: 'flex-1' },
8449
8466
  React.createElement(InputRgba, { hex: activeColor.hex, alpha: activeColor.alpha, showAlpha: showAlpha, onChange: function (value) {
@@ -8457,14 +8474,14 @@ var IroGradient = function (_a) {
8457
8474
  };
8458
8475
 
8459
8476
  var IroSolidColorPicker = function (_a) {
8460
- var _b = _a.value, value = _b === void 0 ? '#ffffff' : _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, defaultColors = _a.defaultColors, _j = _a.showReset, showReset = _j === void 0 ? false : _j, onReset = _a.onReset;
8477
+ var _b = _a.value, value = _b === void 0 ? '#ffffff' : _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, defaultColors = _a.defaultColors, _j = _a.showReset, showReset = _j === void 0 ? false : _j, onReset = _a.onReset, _k = _a.popupWidth, popupWidth = _k === void 0 ? 280 : _k;
8461
8478
  var node = useRef(null);
8462
8479
  var iroPickerRef = useRef(null);
8463
8480
  // Store the initial value for reset functionality
8464
8481
  var initialValue = useRef(value);
8465
- var _k = __read(useState(true), 2), init = _k[0], setInit = _k[1];
8466
- var _l = __read(useState(getHexAlpha(value)), 2), color = _l[0], setColor = _l[1];
8467
- var _m = __read(useState(200), 2), pickerWidth = _m[0], setPickerWidth = _m[1];
8482
+ var _l = __read(useState(true), 2), init = _l[0], setInit = _l[1];
8483
+ var _m = __read(useState(getHexAlpha(value)), 2), color = _m[0], setColor = _m[1];
8484
+ var _o = __read(useState(200), 2), pickerWidth = _o[0], setPickerWidth = _o[1];
8468
8485
  var pickerWidthRef = useRef(200);
8469
8486
  // Update ref when state changes
8470
8487
  useEffect(function () {
@@ -8710,7 +8727,11 @@ var IroSolidColorPicker = function (_a) {
8710
8727
  } },
8711
8728
  React.createElement(IroColorPicker, { ref: iroPickerRef, width: pickerWidth, color: iroColorValue, layout: layoutConfig, onColorChange: handleColorChange })))),
8712
8729
  React.createElement("div", { className: 'border-t pt-4 colorpicker-glass rounded-lg' },
8713
- React.createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: setInit, colorType: 'solid' })),
8730
+ React.createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: setInit, colorType: 'solid', currentValue: color.hex, size: popupWidth < 250
8731
+ ? 'compact'
8732
+ : popupWidth <= 350
8733
+ ? 'default'
8734
+ : 'large' })),
8714
8735
  showInputs && (React.createElement("div", { className: 'rounded-lg colorpicker-glass flex items-center gap-2' },
8715
8736
  React.createElement("div", { className: 'flex-1' },
8716
8737
  React.createElement(InputRgba, { hex: color.hex, alpha: color.alpha, format: format, showAlpha: showAlpha, onChange: handleInputChange, onSubmitChange: handleInputSubmit })),
@@ -8762,27 +8783,50 @@ var PopupTabsBodyItem = function (_a) {
8762
8783
  };
8763
8784
 
8764
8785
  var ColorPicker = function (_a) {
8765
- var _b = _a.value, value = _b === void 0 ? '#ffffff' : _b, _c = _a.format, format = _c === void 0 ? 'rgb' : _c, _d = _a.gradient, gradient = _d === void 0 ? false : _d, _e = _a.solid, solid = _e === void 0 ? true : _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.popupWidth, popupWidth = _r === void 0 ? 267 : _r, _s = _a.colorBoardHeight, colorBoardHeight = _s === void 0 ? 120 : _s, _t = _a.defaultColors, defaultColors = _t === void 0 ? DEFAULT_COLORS : _t, defaultActiveTab = _a.defaultActiveTab, onChangeTabs = _a.onChangeTabs, _u = _a.onChange, onChange = _u === void 0 ? function () { return ({}); } : _u, _v = _a.showReset, showReset = _v === void 0 ? false : _v, onReset = _a.onReset;
8786
+ var _b = _a.value, value = _b === void 0 ? '#ffffff' : _b, _c = _a.format, format = _c === void 0 ? 'rgb' : _c, _d = _a.gradient, gradient = _d === void 0 ? false : _d, _e = _a.solid, solid = _e === void 0 ? true : _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.popupWidth, popupWidth = _r === void 0 ? 267 : _r, _s = _a.colorBoardHeight, colorBoardHeight = _s === void 0 ? 120 : _s, _t = _a.defaultColors, defaultColors = _t === void 0 ? DEFAULT_COLORS : _t, defaultActiveTab = _a.defaultActiveTab, _u = _a.defaultGradientIndex, defaultGradientIndex = _u === void 0 ? 7 : _u, onChangeTabs = _a.onChangeTabs, _v = _a.onChange, onChange = _v === void 0 ? function () { return ({}); } : _v, _w = _a.showReset, showReset = _w === void 0 ? false : _w, onReset = _a.onReset;
8766
8787
  // Convert object value to CSS string for internal use
8767
8788
  var cssValue = normalizeGradientValue(value);
8768
8789
  // Auto-switch to gradient tab if receiving gradient object
8769
8790
  var initialTab = isGradientObject(value)
8770
8791
  ? 'gradient'
8771
8792
  : defaultActiveTab || getIndexActiveTag(value);
8772
- var _w = __read(useState(initialTab), 2), activeTab = _w[0], setActiveTab = _w[1];
8793
+ var _x = __read(useState(initialTab), 2), activeTab = _x[0], setActiveTab = _x[1];
8794
+ // Track the gradient value separately - use default gradient at specified index or fallback
8795
+ var getDefaultGradient = function () {
8796
+ var gradients = defaultColors.filter(function (color) {
8797
+ return typeof color === 'string' &&
8798
+ (color.includes('linear-gradient') || color.includes('radial-gradient'));
8799
+ });
8800
+ // Use the defaultGradientIndex if valid, otherwise fallback
8801
+ if (gradients.length > 0) {
8802
+ var index = Math.max(0, Math.min(defaultGradientIndex, gradients.length - 1));
8803
+ return gradients[index];
8804
+ }
8805
+ return 'linear-gradient(90deg, rgb(255, 177, 153) 0%, rgb(255, 8, 68) 100%)';
8806
+ };
8807
+ var _y = __read(useState(isGradientObject(value) || getIndexActiveTag(value) === 'gradient'
8808
+ ? cssValue
8809
+ : getDefaultGradient()), 2), gradientValue = _y[0], setGradientValue = _y[1];
8773
8810
  // Auto-switch tab when value changes from object to string or vice versa
8774
8811
  React.useEffect(function () {
8775
8812
  if (isGradientObject(value) && activeTab !== 'gradient') {
8776
8813
  setActiveTab('gradient');
8814
+ setGradientValue(cssValue); // Update gradient value when external value is gradient
8777
8815
  if (typeof onChangeTabs === 'function') {
8778
8816
  onChangeTabs('gradient');
8779
8817
  }
8780
8818
  }
8781
- }, [value, activeTab, onChangeTabs]);
8819
+ else if (isGradientObject(value) ||
8820
+ getIndexActiveTag(value) === 'gradient') {
8821
+ // Update gradient value if external value is a gradient
8822
+ setGradientValue(cssValue);
8823
+ }
8824
+ }, [value, cssValue, activeTab, onChangeTabs]);
8782
8825
  var onChangeSolid = function (value) {
8783
8826
  onChange(value);
8784
8827
  };
8785
8828
  var onChangeGradient = function (value) {
8829
+ setGradientValue(value); // Track gradient changes
8786
8830
  onChange(value);
8787
8831
  };
8788
8832
  var onChangeTab = function (tab) {
@@ -8790,28 +8834,46 @@ var ColorPicker = function (_a) {
8790
8834
  if (typeof onChangeTabs === 'function' && !!onChangeTabs) {
8791
8835
  onChangeTabs(tab);
8792
8836
  }
8837
+ // When switching to gradient tab from solid, emit the default gradient
8838
+ if (tab === 'gradient' && activeTab === 'solid') {
8839
+ onChange(gradientValue);
8840
+ }
8793
8841
  };
8794
8842
  if (solid && gradient) {
8795
8843
  return (React.createElement(ThemeProvider, null,
8796
8844
  React.createElement("div", { className: 'relative dark iro-gradient-picker', "data-color-picker-theme": true },
8797
- React.createElement(ThemeToggle, null),
8798
8845
  React.createElement(PopupTabs, { activeTab: activeTab, popupWidth: popupWidth },
8799
8846
  React.createElement(PopupTabsHeader, null,
8800
8847
  React.createElement(PopupTabsHeaderLabel, { tabName: 'solid', onClick: function () { return onChangeTab('solid'); } }, "Solid"),
8801
8848
  React.createElement(PopupTabsHeaderLabel, { tabName: 'gradient', onClick: function () { return onChangeTab('gradient'); } }, "Gradient")),
8802
8849
  React.createElement(PopupTabsBody, null,
8803
8850
  React.createElement(PopupTabsBodyItem, { tabName: 'solid' },
8804
- React.createElement(IroSolidColorPicker, { onChange: onChangeSolid, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset })),
8851
+ React.createElement(IroSolidColorPicker, { onChange: onChangeSolid, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset, popupWidth: popupWidth })),
8805
8852
  React.createElement(PopupTabsBodyItem, { tabName: 'gradient' },
8806
- React.createElement(IroGradient, { onChange: onChangeGradient, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, showGradientResult: showGradientResult, showGradientStops: showGradientStops, showGradientMode: showGradientMode, showGradientAngle: showGradientAngle, showGradientPosition: showGradientPosition, allowAddGradientStops: allowAddGradientStops, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset })))))));
8853
+ React.createElement(IroGradient, { onChange: onChangeGradient, value: gradientValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, showGradientResult: showGradientResult, showGradientStops: showGradientStops, showGradientMode: showGradientMode, showGradientAngle: showGradientAngle, showGradientPosition: showGradientPosition, allowAddGradientStops: allowAddGradientStops, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset, popupWidth: popupWidth })))))));
8807
8854
  }
8808
8855
  return (React.createElement(ThemeProvider, null,
8809
- React.createElement("div", { className: 'relative dark iro-gradient-picker', "data-color-picker-theme": true },
8810
- React.createElement(ThemeToggle, null),
8811
- solid || gradient ? (React.createElement(PopupTabs, { popupWidth: popupWidth },
8812
- React.createElement(PopupTabsBody, null,
8813
- solid ? (React.createElement(IroSolidColorPicker, { onChange: onChangeSolid, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset })) : (React.createElement(Fragment, null)),
8814
- gradient ? (React.createElement(IroGradient, { onChange: onChangeGradient, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, showGradientResult: showGradientResult, showGradientStops: showGradientStops, showGradientMode: showGradientMode, showGradientAngle: showGradientAngle, showGradientPosition: showGradientPosition, allowAddGradientStops: allowAddGradientStops, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset })) : (React.createElement(Fragment, null))))) : null)));
8856
+ React.createElement("div", { className: 'relative dark iro-gradient-picker', "data-color-picker-theme": true }, solid || gradient ? (React.createElement(PopupTabs, { popupWidth: popupWidth },
8857
+ React.createElement(PopupTabsBody, null,
8858
+ solid ? (React.createElement(IroSolidColorPicker, { onChange: onChangeSolid, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset, popupWidth: popupWidth })) : (React.createElement(Fragment, null)),
8859
+ gradient ? (React.createElement(IroGradient, { onChange: onChangeGradient, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, showGradientResult: showGradientResult, showGradientStops: showGradientStops, showGradientMode: showGradientMode, showGradientAngle: showGradientAngle, showGradientPosition: showGradientPosition, allowAddGradientStops: allowAddGradientStops, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset, popupWidth: popupWidth })) : (React.createElement(Fragment, null))))) : null)));
8860
+ };
8861
+
8862
+ // Simple sun and moon icons as SVG components
8863
+ var SunIcon = function (_a) {
8864
+ var className = _a.className;
8865
+ return (React.createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
8866
+ React.createElement("path", { fillRule: 'evenodd', d: 'M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z', clipRule: 'evenodd' })));
8867
+ };
8868
+ var MoonIcon = function (_a) {
8869
+ var className = _a.className;
8870
+ return (React.createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
8871
+ React.createElement("path", { d: 'M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z' })));
8872
+ };
8873
+ var ThemeToggle = function (_a) {
8874
+ var className = _a.className;
8875
+ var _b = useTheme(), theme = _b.theme, toggleTheme = _b.toggleTheme;
8876
+ return (React.createElement("button", { onClick: toggleTheme, className: "theme-toggle ".concat(className || ''), "aria-label": "Switch to ".concat(theme === 'light' ? 'dark' : 'light', " theme"), title: "Switch to ".concat(theme === 'light' ? 'dark' : 'light', " theme") }, theme === 'light' ? (React.createElement(MoonIcon, { className: 'theme-toggle-icon' })) : (React.createElement(SunIcon, { className: 'theme-toggle-icon' }))));
8815
8877
  };
8816
8878
 
8817
8879
  export { ColorPicker, DEFAULT_COLORS, InputRgba, PopupTabs, PopupTabsBody, PopupTabsBodyItem, PopupTabsHeader, PopupTabsHeaderLabel, RADIALS_POS, ThemeProvider, ThemeToggle, TinyColor, checkFormat, cn, cssToGradientObject, ColorPicker as default, flexibleGradientToCss, getGradient, getHexAlpha, gradientObjectToCss, hexToRgba, isGradientObject, isValidHex, isValidRgba, normalizeGradientValue, parseGradient, rgbaToArray, rgbaToHex, useDebounce, validGradient };