react-iro-gradient-picker 1.3.1 → 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.js CHANGED
@@ -123,23 +123,6 @@ var ThemeProvider = function (_a) {
123
123
  return (React__default["default"].createElement(ThemeContext.Provider, { value: value }, children));
124
124
  };
125
125
 
126
- // Simple sun and moon icons as SVG components
127
- var SunIcon = function (_a) {
128
- var className = _a.className;
129
- return (React__default["default"].createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
130
- React__default["default"].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' })));
131
- };
132
- var MoonIcon = function (_a) {
133
- var className = _a.className;
134
- return (React__default["default"].createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
135
- React__default["default"].createElement("path", { d: 'M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z' })));
136
- };
137
- var ThemeToggle = function (_a) {
138
- var className = _a.className;
139
- var _b = useTheme(), theme = _b.theme, toggleTheme = _b.toggleTheme;
140
- return (React__default["default"].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__default["default"].createElement(MoonIcon, { className: 'theme-toggle-icon' })) : (React__default["default"].createElement(SunIcon, { className: 'theme-toggle-icon' }))));
141
- };
142
-
143
126
  /*!
144
127
  * iro.js v5.5.2
145
128
  * 2016-2021 James Daniel
@@ -7351,9 +7334,9 @@ var shallowEqual = function (object1, object2) {
7351
7334
  };
7352
7335
 
7353
7336
  var DefaultColorPanel = function (_a) {
7354
- var _b = _a.defaultColors, defaultColors = _b === void 0 ? [] : _b, setColor = _a.setColor, setActiveColor = _a.setActiveColor, setInit = _a.setInit, colorType = _a.colorType;
7355
- var _c = __read(React.useState(-1), 2), active = _c[0], setActive = _c[1];
7356
- var _d = __read(React.useState([]), 2), formatedDefColors = _d[0], setFormatedDefColors = _d[1];
7337
+ 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;
7338
+ var _d = __read(React.useState(-1), 2), active = _d[0], setActive = _d[1];
7339
+ var _e = __read(React.useState([]), 2), formatedDefColors = _e[0], setFormatedDefColors = _e[1];
7357
7340
  React.useEffect(function () {
7358
7341
  if (colorType === 'gradient') {
7359
7342
  var validGradients = checkValidColorsArray(defaultColors, 'grad');
@@ -7372,12 +7355,27 @@ var DefaultColorPanel = function (_a) {
7372
7355
  };
7373
7356
  });
7374
7357
  setFormatedDefColors(displayGradients);
7358
+ // Set initial active state if currentValue matches a gradient
7359
+ if (currentValue) {
7360
+ var matchIndex = validGradients.findIndex(function (grad) { return grad === currentValue; });
7361
+ if (matchIndex !== -1) {
7362
+ setActive(matchIndex);
7363
+ }
7364
+ }
7375
7365
  }
7376
7366
  else {
7377
- setFormatedDefColors(checkValidColorsArray(defaultColors, 'solid'));
7367
+ var solidColors = checkValidColorsArray(defaultColors, 'solid');
7368
+ setFormatedDefColors(solidColors);
7369
+ // Set initial active state if currentValue matches a solid color
7370
+ if (currentValue) {
7371
+ var matchIndex = solidColors.findIndex(function (color) { return color.toLowerCase() === currentValue.toLowerCase(); });
7372
+ if (matchIndex !== -1) {
7373
+ setActive(matchIndex);
7374
+ }
7375
+ }
7378
7376
  }
7379
7377
  // eslint-disable-next-line react-hooks/exhaustive-deps
7380
- }, []);
7378
+ }, [currentValue]);
7381
7379
  var onChooseColor = function (item, index) {
7382
7380
  // Allow re-applying the same color (removed guard clause that prevented this)
7383
7381
  // This enables users to reset back to a popular color after making changes
@@ -7442,14 +7440,21 @@ var DefaultColorPanel = function (_a) {
7442
7440
  if (!Array.isArray(defaultColors) || !defaultColors.length) {
7443
7441
  return null;
7444
7442
  }
7443
+ // Determine sizing classes based on size prop
7444
+ var sizeClasses = {
7445
+ compact: { button: 'w-8 h-8', gap: 'gap-1.5' },
7446
+ default: { button: 'w-10 h-10', gap: 'gap-4' },
7447
+ large: { button: 'w-12 h-12', gap: 'gap-5' }
7448
+ };
7449
+ var _f = sizeClasses[size], buttonSize = _f.button, gapSize = _f.gap;
7445
7450
  return (React__default["default"].createElement("div", { className: 'w-full' },
7446
7451
  React__default["default"].createElement("h3", { className: 'text-sm font-medium colorpicker-text' }, "Popular Colors"),
7447
- React__default["default"].createElement("div", { className: 'grid grid-cols-5 gap-4 py-4' }, formatedDefColors.map(function (item, index) {
7452
+ React__default["default"].createElement("div", { className: cn('grid grid-cols-5 py-4', gapSize) }, formatedDefColors.map(function (item, index) {
7448
7453
  switch (colorType) {
7449
7454
  case 'gradient':
7450
7455
  if (typeof item !== 'string') {
7451
7456
  var gradient = item.gradient;
7452
- return (React__default["default"].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
7457
+ return (React__default["default"].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
7453
7458
  ? 'border-blue-500 dark:border-blue-400 shadow-lg scale-105'
7454
7459
  : 'border-slate-200 dark:border-slate-600 hover:border-slate-300 dark:hover:border-slate-500'), style: { background: gradient } },
7455
7460
  React__default["default"].createElement("div", { className: 'absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors duration-200' })));
@@ -7459,7 +7464,7 @@ var DefaultColorPanel = function (_a) {
7459
7464
  }
7460
7465
  case 'solid':
7461
7466
  if (typeof item === 'string') {
7462
- return (React__default["default"].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
7467
+ return (React__default["default"].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
7463
7468
  ? 'border-blue-500 dark:border-blue-400 shadow-lg scale-105'
7464
7469
  : 'border-slate-200 dark:border-slate-600 hover:border-slate-300 dark:hover:border-slate-500'), style: {
7465
7470
  background: item,
@@ -8026,7 +8031,7 @@ var useDebounce = (function (value, delay) {
8026
8031
  });
8027
8032
 
8028
8033
  var IroGradient = function (_a) {
8029
- 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;
8034
+ 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;
8030
8035
  // Store the initial value for reset functionality
8031
8036
  var initialValue = React.useRef(value);
8032
8037
  var parsedColors = React.useCallback(function () {
@@ -8087,13 +8092,13 @@ var IroGradient = function (_a) {
8087
8092
  }
8088
8093
  // eslint-disable-next-line react-hooks/exhaustive-deps
8089
8094
  }, [value]);
8090
- var _s = parsedColors(), stops = _s.stops, type = _s.type, modifier = _s.modifier;
8095
+ var _t = parsedColors(), stops = _t.stops, type = _t.type, modifier = _t.modifier;
8091
8096
  var iroPickerRef = React.useRef(null);
8092
8097
  var containerRef = React.useRef(null);
8093
8098
  var isUpdatingFromGradientStop = React.useRef(false);
8094
8099
  var lastUpdateAttempt = React.useRef(0); // Track last update attempt
8095
8100
  var isPickerInitialized = React.useRef(false); // Track if picker is already initialized
8096
- var _t = __read(React.useState(200), 2), pickerWidth = _t[0], setPickerWidth = _t[1];
8101
+ var _u = __read(React.useState(200), 2), pickerWidth = _u[0], setPickerWidth = _u[1];
8097
8102
  // Safe extraction of stop data with fallbacks
8098
8103
  var safeStops = Array.isArray(stops) && stops.length > 0
8099
8104
  ? stops
@@ -8150,18 +8155,18 @@ var IroGradient = function (_a) {
8150
8155
  resizeObserver.observe(containerRef.current);
8151
8156
  return function () { return resizeObserver.disconnect(); };
8152
8157
  }, []);
8153
- var _u = __read(React.useState({
8158
+ var _v = __read(React.useState({
8154
8159
  gradient: value,
8155
8160
  type: type,
8156
8161
  modifier: modifier,
8157
8162
  stops: safeStops
8158
- }), 2), color = _u[0], setColor = _u[1];
8159
- var _v = __read(React.useState({
8163
+ }), 2), color = _v[0], setColor = _v[1];
8164
+ var _w = __read(React.useState({
8160
8165
  hex: activeStop,
8161
8166
  alpha: activeAlpha,
8162
8167
  loc: safeStops[activeStopIndex][1],
8163
8168
  index: activeStopIndex
8164
- }), 2), activeColor = _v[0], setActiveColor = _v[1];
8169
+ }), 2), activeColor = _w[0], setActiveColor = _w[1];
8165
8170
  var debounceColor = useDebounce(color, debounceMS);
8166
8171
  // Update iro picker color
8167
8172
  var updateIroPickerColor = React.useCallback(function (colorData, retryCount) {
@@ -8385,6 +8390,13 @@ var IroGradient = function (_a) {
8385
8390
  };
8386
8391
  // Update iro picker when color is selected from default colors panel
8387
8392
  var handleColorFromPanel = function (newColor) {
8393
+ console.log('handleColorFromPanel called with:', newColor);
8394
+ // Ensure the gradient CSS string is properly set
8395
+ if ((newColor === null || newColor === void 0 ? void 0 : newColor.stops) && !newColor.gradient) {
8396
+ // Reconstruct the gradient string if missing
8397
+ newColor.gradient = getGradient(newColor.type || 'linear', newColor.stops, newColor.modifier || 90, format, showAlpha);
8398
+ console.log('Reconstructed gradient:', newColor.gradient);
8399
+ }
8388
8400
  setColor(newColor);
8389
8401
  if (newColor === null || newColor === void 0 ? void 0 : newColor.stops) {
8390
8402
  var lastStop = rgbaToArray(newColor.stops[newColor.stops.length - 1][0]);
@@ -8395,6 +8407,7 @@ var IroGradient = function (_a) {
8395
8407
  loc: newColor.stops[newColor.stops.length - 1][1],
8396
8408
  index: newColor.stops.length - 1
8397
8409
  };
8410
+ console.log('Setting activeColor to:', newActiveColor);
8398
8411
  setActiveColor(newActiveColor);
8399
8412
  // Note: useEffect will handle iro picker update automatically when activeColor changes
8400
8413
  }
@@ -8451,7 +8464,11 @@ var IroGradient = function (_a) {
8451
8464
  React__default["default"].createElement("div", { className: 'rounded-lg colorpicker-glass px-4' },
8452
8465
  React__default["default"].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 })),
8453
8466
  React__default["default"].createElement("div", { className: 'pt-4 px-2' },
8454
- React__default["default"].createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: function () { }, setActiveColor: handleSetActiveColor, colorType: 'gradient' })),
8467
+ React__default["default"].createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: function () { }, setActiveColor: handleSetActiveColor, colorType: 'gradient', currentValue: color.gradient, size: popupWidth < 250
8468
+ ? 'compact'
8469
+ : popupWidth <= 350
8470
+ ? 'default'
8471
+ : 'large' })),
8455
8472
  showInputs && (React__default["default"].createElement("div", { className: 'rounded-lg colorpicker-glass flex items-center gap-2' },
8456
8473
  React__default["default"].createElement("div", { className: 'flex-1' },
8457
8474
  React__default["default"].createElement(InputRgba, { hex: activeColor.hex, alpha: activeColor.alpha, showAlpha: showAlpha, onChange: function (value) {
@@ -8465,14 +8482,14 @@ var IroGradient = function (_a) {
8465
8482
  };
8466
8483
 
8467
8484
  var IroSolidColorPicker = function (_a) {
8468
- 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;
8485
+ 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;
8469
8486
  var node = React.useRef(null);
8470
8487
  var iroPickerRef = React.useRef(null);
8471
8488
  // Store the initial value for reset functionality
8472
8489
  var initialValue = React.useRef(value);
8473
- var _k = __read(React.useState(true), 2), init = _k[0], setInit = _k[1];
8474
- var _l = __read(React.useState(getHexAlpha(value)), 2), color = _l[0], setColor = _l[1];
8475
- var _m = __read(React.useState(200), 2), pickerWidth = _m[0], setPickerWidth = _m[1];
8490
+ var _l = __read(React.useState(true), 2), init = _l[0], setInit = _l[1];
8491
+ var _m = __read(React.useState(getHexAlpha(value)), 2), color = _m[0], setColor = _m[1];
8492
+ var _o = __read(React.useState(200), 2), pickerWidth = _o[0], setPickerWidth = _o[1];
8476
8493
  var pickerWidthRef = React.useRef(200);
8477
8494
  // Update ref when state changes
8478
8495
  React.useEffect(function () {
@@ -8718,7 +8735,11 @@ var IroSolidColorPicker = function (_a) {
8718
8735
  } },
8719
8736
  React__default["default"].createElement(IroColorPicker, { ref: iroPickerRef, width: pickerWidth, color: iroColorValue, layout: layoutConfig, onColorChange: handleColorChange })))),
8720
8737
  React__default["default"].createElement("div", { className: 'border-t pt-4 colorpicker-glass rounded-lg' },
8721
- React__default["default"].createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: setInit, colorType: 'solid' })),
8738
+ React__default["default"].createElement(DefaultColorPanel, { defaultColors: defaultColors, setColor: handleColorFromPanel, setInit: setInit, colorType: 'solid', currentValue: color.hex, size: popupWidth < 250
8739
+ ? 'compact'
8740
+ : popupWidth <= 350
8741
+ ? 'default'
8742
+ : 'large' })),
8722
8743
  showInputs && (React__default["default"].createElement("div", { className: 'rounded-lg colorpicker-glass flex items-center gap-2' },
8723
8744
  React__default["default"].createElement("div", { className: 'flex-1' },
8724
8745
  React__default["default"].createElement(InputRgba, { hex: color.hex, alpha: color.alpha, format: format, showAlpha: showAlpha, onChange: handleInputChange, onSubmitChange: handleInputSubmit })),
@@ -8770,27 +8791,50 @@ var PopupTabsBodyItem = function (_a) {
8770
8791
  };
8771
8792
 
8772
8793
  var ColorPicker = function (_a) {
8773
- 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;
8794
+ 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;
8774
8795
  // Convert object value to CSS string for internal use
8775
8796
  var cssValue = normalizeGradientValue(value);
8776
8797
  // Auto-switch to gradient tab if receiving gradient object
8777
8798
  var initialTab = isGradientObject(value)
8778
8799
  ? 'gradient'
8779
8800
  : defaultActiveTab || getIndexActiveTag(value);
8780
- var _w = __read(React.useState(initialTab), 2), activeTab = _w[0], setActiveTab = _w[1];
8801
+ var _x = __read(React.useState(initialTab), 2), activeTab = _x[0], setActiveTab = _x[1];
8802
+ // Track the gradient value separately - use default gradient at specified index or fallback
8803
+ var getDefaultGradient = function () {
8804
+ var gradients = defaultColors.filter(function (color) {
8805
+ return typeof color === 'string' &&
8806
+ (color.includes('linear-gradient') || color.includes('radial-gradient'));
8807
+ });
8808
+ // Use the defaultGradientIndex if valid, otherwise fallback
8809
+ if (gradients.length > 0) {
8810
+ var index = Math.max(0, Math.min(defaultGradientIndex, gradients.length - 1));
8811
+ return gradients[index];
8812
+ }
8813
+ return 'linear-gradient(90deg, rgb(255, 177, 153) 0%, rgb(255, 8, 68) 100%)';
8814
+ };
8815
+ var _y = __read(React.useState(isGradientObject(value) || getIndexActiveTag(value) === 'gradient'
8816
+ ? cssValue
8817
+ : getDefaultGradient()), 2), gradientValue = _y[0], setGradientValue = _y[1];
8781
8818
  // Auto-switch tab when value changes from object to string or vice versa
8782
8819
  React__default["default"].useEffect(function () {
8783
8820
  if (isGradientObject(value) && activeTab !== 'gradient') {
8784
8821
  setActiveTab('gradient');
8822
+ setGradientValue(cssValue); // Update gradient value when external value is gradient
8785
8823
  if (typeof onChangeTabs === 'function') {
8786
8824
  onChangeTabs('gradient');
8787
8825
  }
8788
8826
  }
8789
- }, [value, activeTab, onChangeTabs]);
8827
+ else if (isGradientObject(value) ||
8828
+ getIndexActiveTag(value) === 'gradient') {
8829
+ // Update gradient value if external value is a gradient
8830
+ setGradientValue(cssValue);
8831
+ }
8832
+ }, [value, cssValue, activeTab, onChangeTabs]);
8790
8833
  var onChangeSolid = function (value) {
8791
8834
  onChange(value);
8792
8835
  };
8793
8836
  var onChangeGradient = function (value) {
8837
+ setGradientValue(value); // Track gradient changes
8794
8838
  onChange(value);
8795
8839
  };
8796
8840
  var onChangeTab = function (tab) {
@@ -8798,28 +8842,46 @@ var ColorPicker = function (_a) {
8798
8842
  if (typeof onChangeTabs === 'function' && !!onChangeTabs) {
8799
8843
  onChangeTabs(tab);
8800
8844
  }
8845
+ // When switching to gradient tab from solid, emit the default gradient
8846
+ if (tab === 'gradient' && activeTab === 'solid') {
8847
+ onChange(gradientValue);
8848
+ }
8801
8849
  };
8802
8850
  if (solid && gradient) {
8803
8851
  return (React__default["default"].createElement(ThemeProvider, null,
8804
8852
  React__default["default"].createElement("div", { className: 'relative dark iro-gradient-picker', "data-color-picker-theme": true },
8805
- React__default["default"].createElement(ThemeToggle, null),
8806
8853
  React__default["default"].createElement(PopupTabs, { activeTab: activeTab, popupWidth: popupWidth },
8807
8854
  React__default["default"].createElement(PopupTabsHeader, null,
8808
8855
  React__default["default"].createElement(PopupTabsHeaderLabel, { tabName: 'solid', onClick: function () { return onChangeTab('solid'); } }, "Solid"),
8809
8856
  React__default["default"].createElement(PopupTabsHeaderLabel, { tabName: 'gradient', onClick: function () { return onChangeTab('gradient'); } }, "Gradient")),
8810
8857
  React__default["default"].createElement(PopupTabsBody, null,
8811
8858
  React__default["default"].createElement(PopupTabsBodyItem, { tabName: 'solid' },
8812
- React__default["default"].createElement(IroSolidColorPicker, { onChange: onChangeSolid, value: cssValue, format: format, defaultColors: defaultColors, debounceMS: debounceMS, debounce: debounce, showAlpha: showAlpha, showInputs: showInputs, colorBoardHeight: colorBoardHeight, showReset: showReset, onReset: onReset })),
8859
+ React__default["default"].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 })),
8813
8860
  React__default["default"].createElement(PopupTabsBodyItem, { tabName: 'gradient' },
8814
- React__default["default"].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 })))))));
8861
+ React__default["default"].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 })))))));
8815
8862
  }
8816
8863
  return (React__default["default"].createElement(ThemeProvider, null,
8817
- React__default["default"].createElement("div", { className: 'relative dark iro-gradient-picker', "data-color-picker-theme": true },
8818
- React__default["default"].createElement(ThemeToggle, null),
8819
- solid || gradient ? (React__default["default"].createElement(PopupTabs, { popupWidth: popupWidth },
8820
- React__default["default"].createElement(PopupTabsBody, null,
8821
- solid ? (React__default["default"].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__default["default"].createElement(React.Fragment, null)),
8822
- gradient ? (React__default["default"].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__default["default"].createElement(React.Fragment, null))))) : null)));
8864
+ React__default["default"].createElement("div", { className: 'relative dark iro-gradient-picker', "data-color-picker-theme": true }, solid || gradient ? (React__default["default"].createElement(PopupTabs, { popupWidth: popupWidth },
8865
+ React__default["default"].createElement(PopupTabsBody, null,
8866
+ solid ? (React__default["default"].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__default["default"].createElement(React.Fragment, null)),
8867
+ gradient ? (React__default["default"].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__default["default"].createElement(React.Fragment, null))))) : null)));
8868
+ };
8869
+
8870
+ // Simple sun and moon icons as SVG components
8871
+ var SunIcon = function (_a) {
8872
+ var className = _a.className;
8873
+ return (React__default["default"].createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
8874
+ React__default["default"].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' })));
8875
+ };
8876
+ var MoonIcon = function (_a) {
8877
+ var className = _a.className;
8878
+ return (React__default["default"].createElement("svg", { className: className, fill: 'currentColor', viewBox: '0 0 20 20' },
8879
+ React__default["default"].createElement("path", { d: 'M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z' })));
8880
+ };
8881
+ var ThemeToggle = function (_a) {
8882
+ var className = _a.className;
8883
+ var _b = useTheme(), theme = _b.theme, toggleTheme = _b.toggleTheme;
8884
+ return (React__default["default"].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__default["default"].createElement(MoonIcon, { className: 'theme-toggle-icon' })) : (React__default["default"].createElement(SunIcon, { className: 'theme-toggle-icon' }))));
8823
8885
  };
8824
8886
 
8825
8887
  exports.ColorPicker = ColorPicker;