react-iro-gradient-picker 1.2.4 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6438,10 +6438,18 @@ var validGradient = (function (input) {
6438
6438
  var colorStops = [];
6439
6439
  // Determine if first part is direction/angle or color stop
6440
6440
  var firstPart = parts[0];
6441
- var isDirection = /^\d+deg$/i.test(firstPart) ||
6442
- /^to\s+/.test(firstPart) ||
6443
- /^(?:circle|ellipse)/.test(firstPart) ||
6444
- /at\s+/.test(firstPart);
6441
+ var isDirection = false;
6442
+ if (type === 'linear') {
6443
+ isDirection = /^\d+deg$/i.test(firstPart) || /^to\s+/.test(firstPart);
6444
+ }
6445
+ else if (type === 'radial') {
6446
+ // For radial gradients, check for size, shape, or position keywords
6447
+ isDirection =
6448
+ /^(?:circle|ellipse)/.test(firstPart) ||
6449
+ /at\s+/.test(firstPart) ||
6450
+ /^(?:closest-side|closest-corner|farthest-side|farthest-corner)$/i.test(firstPart) ||
6451
+ /^\d+(?:%|px|em|rem)?$/i.test(firstPart); // Size values like "70", "70%", "70px"
6452
+ }
6445
6453
  if (isDirection) {
6446
6454
  if (type === 'linear') {
6447
6455
  if (/^\d+deg$/i.test(firstPart)) {
@@ -6601,12 +6609,23 @@ var parseGradient = (function (str) {
6601
6609
  var findF = (_a = LINEAR_POS.find(function (item) { return item.name === angle_1; })) === null || _a === void 0 ? void 0 : _a.angle;
6602
6610
  var helperAngle = type === 'linear' ? '180' : 'circle at center';
6603
6611
  var modifier = findF || angle_1 || helperAngle;
6612
+ // For radial gradients, preserve the full modifier string to maintain positioning
6613
+ var processedModifier = void 0;
6614
+ if (type === 'radial') {
6615
+ // Keep the full radial gradient specification
6616
+ processedModifier = modifier;
6617
+ }
6618
+ else {
6619
+ // For linear gradients, extract number if it's a degree value
6620
+ processedModifier =
6621
+ modifier.match(/\d+/) !== null
6622
+ ? Number((_b = modifier.match(/\d+/)) === null || _b === void 0 ? void 0 : _b.join(''))
6623
+ : modifier;
6624
+ }
6604
6625
  return {
6605
6626
  gradient: typeof gradient !== 'string' ? gradient.original : str,
6606
6627
  type: type,
6607
- modifier: modifier.match(/\d+/) !== null
6608
- ? Number((_b = modifier.match(/\d+/)) === null || _b === void 0 ? void 0 : _b.join(''))
6609
- : modifier,
6628
+ modifier: processedModifier,
6610
6629
  stops: stops.map(function (stop, index) {
6611
6630
  var formatStop = ["".concat(stop.color), index];
6612
6631
  if (stop.position || stop.position === 0) {
@@ -7463,9 +7482,18 @@ var Markers = function (_a) {
7463
7482
  };
7464
7483
  var onDrag = function (e) {
7465
7484
  var _a;
7466
- var x = e.clientX;
7467
- var y = e.clientY;
7485
+ // Defensive check for event object
7486
+ if (!e) {
7487
+ console.warn('onDrag called with undefined event object');
7488
+ return;
7489
+ }
7490
+ var x = e.clientX || 0;
7491
+ var y = e.clientY || 0;
7468
7492
  var rect = (_a = node === null || node === void 0 ? void 0 : node.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
7493
+ if (!rect) {
7494
+ console.warn('Unable to get bounding rect for drag operation');
7495
+ return;
7496
+ }
7469
7497
  var rootDistance = y - rect.y;
7470
7498
  // Now we know user is actually dragging
7471
7499
  setIsDragging(true);
@@ -7720,10 +7748,15 @@ var GradientPanel = function (_a) {
7720
7748
  }
7721
7749
  };
7722
7750
  var onDrag = function (e) {
7723
- var x = e.clientX;
7724
- var y = e.clientY;
7725
- var shiftKey = e.shiftKey;
7726
- var ctrlKey = e.ctrlKey * 2;
7751
+ // Defensive check for event object
7752
+ if (!e) {
7753
+ console.warn('onDrag called with undefined event object');
7754
+ return;
7755
+ }
7756
+ var x = e.clientX || 0;
7757
+ var y = e.clientY || 0;
7758
+ var shiftKey = e.shiftKey || false;
7759
+ var ctrlKey = (e.ctrlKey || false) * 2;
7727
7760
  pointMoveTo({
7728
7761
  x: x,
7729
7762
  y: y,
@@ -7862,7 +7895,10 @@ var IroGradient = function (_a) {
7862
7895
  console.warn('Gradient parsing failed, using fallback:', parsed);
7863
7896
  var fallback = parseGradient('linear-gradient(90deg, #ffffff 0%, #000000 100%)');
7864
7897
  // Ensure fallback has valid structure
7865
- if (fallback && typeof fallback === 'object' && Array.isArray(fallback.stops) && fallback.stops.length > 0) {
7898
+ if (fallback &&
7899
+ typeof fallback === 'object' &&
7900
+ Array.isArray(fallback.stops) &&
7901
+ fallback.stops.length > 0) {
7866
7902
  return fallback;
7867
7903
  }
7868
7904
  // Ultimate fallback with guaranteed structure
@@ -7877,7 +7913,10 @@ var IroGradient = function (_a) {
7877
7913
  };
7878
7914
  }
7879
7915
  // Validate parsed result has required structure
7880
- if (parsed && typeof parsed === 'object' && Array.isArray(parsed.stops) && parsed.stops.length > 0) {
7916
+ if (parsed &&
7917
+ typeof parsed === 'object' &&
7918
+ Array.isArray(parsed.stops) &&
7919
+ parsed.stops.length > 0) {
7881
7920
  return parsed;
7882
7921
  }
7883
7922
  // If parsed result is invalid, use ultimate fallback
@@ -7912,11 +7951,22 @@ var IroGradient = function (_a) {
7912
7951
  var isUpdatingFromGradientStop = React.useRef(false);
7913
7952
  var _t = __read(React.useState(200), 2), pickerWidth = _t[0], setPickerWidth = _t[1];
7914
7953
  // Safe extraction of stop data with fallbacks
7915
- var safeStops = Array.isArray(stops) && stops.length > 0 ? stops : [['rgba(255, 255, 255, 1)', 0, 0], ['rgba(0, 0, 0, 1)', 1, 1]];
7954
+ var safeStops = Array.isArray(stops) && stops.length > 0
7955
+ ? stops
7956
+ : [
7957
+ ['rgba(255, 255, 255, 1)', 0, 0],
7958
+ ['rgba(0, 0, 0, 1)', 1, 1]
7959
+ ];
7916
7960
  var safeLastStop = rgbaToArray(safeStops[safeStops.length - 1][0]);
7917
- var safeParsedLastStop = Array.isArray(safeLastStop) && safeLastStop.length >= 4 ? safeLastStop : [255, 255, 255, 1];
7961
+ var safeParsedLastStop = Array.isArray(safeLastStop) && safeLastStop.length >= 4
7962
+ ? safeLastStop
7963
+ : [255, 255, 255, 1];
7918
7964
  var activeStopIndex = safeStops.length - 1;
7919
- var activeStop = rgbaToHex([safeParsedLastStop[0], safeParsedLastStop[1], safeParsedLastStop[2]]);
7965
+ var activeStop = rgbaToHex([
7966
+ safeParsedLastStop[0],
7967
+ safeParsedLastStop[1],
7968
+ safeParsedLastStop[2]
7969
+ ]);
7920
7970
  var activeAlpha = Math.round(safeParsedLastStop[3] * 100);
7921
7971
  // Responsive width for IroColorPicker - match solid picker logic
7922
7972
  React.useEffect(function () {