react-iro-gradient-picker 1.1.7 → 1.2.3
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/README.md +113 -1
- package/dist/components/core/Colorpicker/IroGradient/index.d.ts +2 -2
- package/dist/components/core/Colorpicker/IroSolid/index.d.ts +2 -2
- package/dist/components/core/Colorpicker/helper.d.ts +2 -1
- package/dist/index.es.js +272 -122
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +275 -121
- package/dist/index.js.map +1 -1
- package/dist/lib/types/types.d.ts +44 -1
- package/dist/utils/gradient/gradientConverter.d.ts +17 -0
- package/dist/utils/gradient/index.d.ts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/validation/validGradient.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -124,7 +124,67 @@ function App() {
|
|
124
124
|
export default App;
|
125
125
|
```
|
126
126
|
|
127
|
-
###
|
127
|
+
### � **NEW: Enhanced Gradient Object Support**
|
128
|
+
|
129
|
+
**v1.2.0+ supports both CSS strings AND gradient objects for maximum flexibility!**
|
130
|
+
|
131
|
+
```tsx
|
132
|
+
import React, { useState } from 'react';
|
133
|
+
import ColorPicker from 'react-iro-gradient-picker';
|
134
|
+
import 'react-iro-gradient-picker/dist/index.css';
|
135
|
+
|
136
|
+
function GradientObjectExample() {
|
137
|
+
// Define gradient as an object
|
138
|
+
const [gradientData, setGradientData] = useState({
|
139
|
+
type: 'linear',
|
140
|
+
angle: 120,
|
141
|
+
stops: [
|
142
|
+
{ color: '#FF6B6B', position: 0 }, // Red at 0%
|
143
|
+
{ color: '#FFD93D', position: 50 }, // Yellow at 50%
|
144
|
+
{ color: '#6BCB77', position: 100 } // Green at 100%
|
145
|
+
]
|
146
|
+
});
|
147
|
+
|
148
|
+
return (
|
149
|
+
<ColorPicker
|
150
|
+
value={gradientData} // 🎯 Pass object directly!
|
151
|
+
onChange={(cssGradient) => {
|
152
|
+
console.log('Generated CSS:', cssGradient);
|
153
|
+
// Component auto-switches to gradient tab
|
154
|
+
// Sets angle to 120°, creates 3 stops with exact colors/positions
|
155
|
+
}}
|
156
|
+
gradient={true}
|
157
|
+
solid={true}
|
158
|
+
showGradientAngle={true}
|
159
|
+
showGradientStops={true}
|
160
|
+
/>
|
161
|
+
);
|
162
|
+
}
|
163
|
+
```
|
164
|
+
|
165
|
+
**🚀 What happens when you pass a gradient object:**
|
166
|
+
|
167
|
+
- ✅ **Auto-switches to gradient tab**
|
168
|
+
- ✅ **Sets angle slider to specified degrees** (120° in example)
|
169
|
+
- ✅ **Creates gradient stops** at exact positions (0%, 50%, 100%)
|
170
|
+
- ✅ **Sets stop colors** to specified values (#FF6B6B, #FFD93D, #6BCB77)
|
171
|
+
- ✅ **Updates gradient preview** to match exactly
|
172
|
+
- ✅ **Returns CSS gradient string** in onChange callback
|
173
|
+
|
174
|
+
**📋 Gradient Object Structure:**
|
175
|
+
|
176
|
+
```typescript
|
177
|
+
interface IGradientData {
|
178
|
+
type: 'linear' | 'radial';
|
179
|
+
angle?: number; // For linear gradients (0-360 degrees)
|
180
|
+
stops: Array<{
|
181
|
+
color: string; // Any valid CSS color
|
182
|
+
position: number; // 0-100 (percentage)
|
183
|
+
}>;
|
184
|
+
}
|
185
|
+
```
|
186
|
+
|
187
|
+
### �🌙 With Dark Theme Support
|
128
188
|
|
129
189
|
```tsx
|
130
190
|
import React, { useState } from 'react';
|
@@ -212,6 +272,58 @@ This is an enhanced version of the original react-gcolor-picker with major impro
|
|
212
272
|
- **Updated Dependencies** - Latest versions of all packages
|
213
273
|
- **Better Build Process** - Optimized for modern React applications
|
214
274
|
|
275
|
+
## 🎨 Supported CSS Gradient Formats
|
276
|
+
|
277
|
+
**v1.2.2+ supports all standard CSS gradient formats with robust parsing:**
|
278
|
+
|
279
|
+
### Linear Gradients
|
280
|
+
|
281
|
+
```css
|
282
|
+
/* Angle-based directions */
|
283
|
+
linear-gradient(120deg, #FF6B6B, #FFD93D, #6BCB77)
|
284
|
+
linear-gradient(45deg, #4FACFE, #00F2FE, #38EF7D)
|
285
|
+
linear-gradient(200deg, #FF9A9E, #FAD0C4, #FBC2EB)
|
286
|
+
linear-gradient(60deg, #30CFD0, #330867, #6A82FB)
|
287
|
+
|
288
|
+
/* Named directions */
|
289
|
+
linear-gradient(to top right, #FF6B6B, #FFD93D)
|
290
|
+
linear-gradient(to bottom, #4FACFE, #00F2FE)
|
291
|
+
linear-gradient(to left, #FF9A9E, #FAD0C4)
|
292
|
+
|
293
|
+
/* With explicit positions */
|
294
|
+
linear-gradient(90deg, #FF6B6B 0%, #FFD93D 50%, #6BCB77 100%)
|
295
|
+
|
296
|
+
/* Without positions (auto-distributed) */
|
297
|
+
linear-gradient(180deg, #FF9966, #FF5E62, #F54EA2)
|
298
|
+
```
|
299
|
+
|
300
|
+
### Radial Gradients
|
301
|
+
|
302
|
+
```css
|
303
|
+
/* Basic circle gradients */
|
304
|
+
radial-gradient(circle at center, #00C9FF, #92FE9D, #0061FF)
|
305
|
+
radial-gradient(circle at top left, #FF6B6B, #FF4757, #2F3542)
|
306
|
+
radial-gradient(circle at bottom right, #1E90FF, #3742FA, #2C3E50)
|
307
|
+
|
308
|
+
/* Positioned radial gradients */
|
309
|
+
radial-gradient(circle at 70% 30%, #2ED573, #1EAE98, #004E64)
|
310
|
+
radial-gradient(circle at 20% 80%, #FFB347, #FFCC33, #FF6347)
|
311
|
+
radial-gradient(circle at top center, #FF7E5F, #FEB47B, #FFD93D)
|
312
|
+
radial-gradient(circle at right center, #6A82FB, #FC5C7D, #FF85A1)
|
313
|
+
|
314
|
+
/* Complex positioning */
|
315
|
+
radial-gradient(circle at 30% 70%, #11998E, #38EF7D, #8BC34A)
|
316
|
+
radial-gradient(circle at 80% 20%, #F7971E, #FFD200, #FF512F)
|
317
|
+
radial-gradient(circle at 40% 40%, #C6FFDD, #FBD786, #F7797D)
|
318
|
+
```
|
319
|
+
|
320
|
+
### Advanced Features
|
321
|
+
|
322
|
+
- **Auto-positioning**: Color stops without explicit positions are automatically distributed evenly
|
323
|
+
- **Flexible syntax**: Supports various positioning keywords and percentage values
|
324
|
+
- **Error recovery**: Invalid gradients fall back to a default gradient instead of crashing
|
325
|
+
- **Type safety**: Full TypeScript support with proper gradient object interfaces
|
326
|
+
|
215
327
|
## Props
|
216
328
|
|
217
329
|
| Attribute | Type | Default | Description |
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { FC } from 'react';
|
2
|
-
import {
|
3
|
-
declare const IroSolidColorPicker: FC<
|
2
|
+
import { IPropsSolid } from '../../../../lib/types';
|
3
|
+
declare const IroSolidColorPicker: FC<IPropsSolid>;
|
4
4
|
export default IroSolidColorPicker;
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
import { TValueProp } from '../../../lib/types';
|
2
|
+
export declare const getIndexActiveTag: (value: TValueProp) => string;
|
2
3
|
export declare const checkValidColorsArray: (arr: string[], type: "solid" | "grad") => string[];
|
3
4
|
export declare const arraysEqual: (a: Array<any>, b: Array<any>) => boolean;
|
4
5
|
export declare const shallowEqual: (object1: any, object2: any) => boolean;
|
package/dist/index.es.js
CHANGED
@@ -6386,111 +6386,139 @@ var isValidRgba = (function (rgba) {
|
|
6386
6386
|
return !!rgbaToHex(rgba);
|
6387
6387
|
});
|
6388
6388
|
|
6389
|
-
var
|
6390
|
-
|
6391
|
-
|
6392
|
-
|
6393
|
-
|
6394
|
-
|
6395
|
-
|
6396
|
-
|
6397
|
-
|
6398
|
-
|
6399
|
-
|
6400
|
-
var rColorHex = /\#(?:[a-f0-9]{6,8}|[a-f0-9]{3})/;
|
6401
|
-
var rDigits3 = /\(\s*(?:\d{1,3}%?\s*,\s*){2}%?\d{1,3}%?\s*\)/;
|
6402
|
-
var rDigits4 = /\(\s*(?:\d{1,3}%?\s*,\s*){2}%?\d{1,3}%?\s*,\s*\d*\.?\d+\)/;
|
6403
|
-
var rValue = /(?:[+-]?\d*\.?\d+)(?:%|[a-z]+)?/;
|
6404
|
-
var rKeyword = /[_a-z-][_a-z0-9-]*/;
|
6405
|
-
var rColor = combineRegExp([
|
6406
|
-
'(?:',
|
6407
|
-
rColorHex,
|
6408
|
-
'|',
|
6409
|
-
'(?:rgb|hsl)',
|
6410
|
-
rDigits3,
|
6411
|
-
'|',
|
6412
|
-
'(?:rgba|hsla)',
|
6413
|
-
rDigits4,
|
6414
|
-
'|',
|
6415
|
-
rKeyword,
|
6416
|
-
')'
|
6417
|
-
], '');
|
6418
|
-
var rColorStop = combineRegExp([rColor, '(?:\\s+', rValue, '(?:\\s+', rValue, ')?)?'], '');
|
6419
|
-
var rColorStopList = combineRegExp(['(?:', rColorStop, rComma, ')*', rColorStop], '');
|
6420
|
-
var rLineCapture = combineRegExp(['(?:(', rAngle, ')|', rSideCornerCapture, '|', rRadial, ')'], '');
|
6421
|
-
var rGradientSearch = combineRegExp(['(?:(', rLineCapture, ')', rComma, ')?(', rColorStopList, ')'], searchFlags);
|
6422
|
-
var rColorStopSearch = combineRegExp([
|
6423
|
-
'\\s*(',
|
6424
|
-
rColor,
|
6425
|
-
')',
|
6426
|
-
'(?:\\s+',
|
6427
|
-
'(',
|
6428
|
-
rValue,
|
6429
|
-
'))?',
|
6430
|
-
'(?:',
|
6431
|
-
rComma,
|
6432
|
-
'\\s*)?'
|
6433
|
-
], searchFlags);
|
6434
|
-
return {
|
6435
|
-
gradientSearch: rGradientSearch,
|
6436
|
-
colorStopSearch: rColorStopSearch
|
6437
|
-
};
|
6438
|
-
};
|
6439
|
-
var parseGradient$1 = function (regExpLib, input) {
|
6440
|
-
var result = {
|
6441
|
-
stops: [],
|
6442
|
-
angle: '',
|
6443
|
-
line: '',
|
6444
|
-
original: ''
|
6445
|
-
};
|
6446
|
-
var matchGradient, matchColorStop, stopResult;
|
6447
|
-
regExpLib.gradientSearch.lastIndex = 0;
|
6448
|
-
matchGradient = regExpLib.gradientSearch.exec(input);
|
6449
|
-
if (matchGradient !== null) {
|
6450
|
-
result = __assign(__assign({}, result), { original: matchGradient[0] });
|
6451
|
-
if (matchGradient[1]) {
|
6452
|
-
result.line = matchGradient[1];
|
6389
|
+
var validGradient = (function (input) {
|
6390
|
+
try {
|
6391
|
+
// Clean input
|
6392
|
+
var cleanInput = input
|
6393
|
+
.trim()
|
6394
|
+
.replace(/;$/, '')
|
6395
|
+
.replace(/^background-image:\s*/, '');
|
6396
|
+
// Extract gradient type and content
|
6397
|
+
var gradientMatch = cleanInput.match(/^(linear|radial)-gradient\s*\(\s*(.*)\s*\)$/i);
|
6398
|
+
if (!gradientMatch) {
|
6399
|
+
return 'Failed to find gradient';
|
6453
6400
|
}
|
6454
|
-
|
6455
|
-
|
6401
|
+
var _a = __read(gradientMatch, 3), type = _a[1], content = _a[2];
|
6402
|
+
var parts = [];
|
6403
|
+
var currentPart = '';
|
6404
|
+
var parenDepth = 0;
|
6405
|
+
var inQuotes = false;
|
6406
|
+
// Parse content by splitting on commas, but respect parentheses and quotes
|
6407
|
+
for (var i = 0; i < content.length; i++) {
|
6408
|
+
var char = content[i];
|
6409
|
+
if (char === '"' || char === "'") {
|
6410
|
+
inQuotes = !inQuotes;
|
6411
|
+
}
|
6412
|
+
else if (!inQuotes) {
|
6413
|
+
if (char === '(')
|
6414
|
+
parenDepth++;
|
6415
|
+
else if (char === ')')
|
6416
|
+
parenDepth--;
|
6417
|
+
else if (char === ',' && parenDepth === 0) {
|
6418
|
+
parts.push(currentPart.trim());
|
6419
|
+
currentPart = '';
|
6420
|
+
continue;
|
6421
|
+
}
|
6422
|
+
}
|
6423
|
+
currentPart += char;
|
6456
6424
|
}
|
6457
|
-
if (
|
6458
|
-
|
6425
|
+
if (currentPart.trim()) {
|
6426
|
+
parts.push(currentPart.trim());
|
6459
6427
|
}
|
6460
|
-
|
6461
|
-
|
6462
|
-
|
6463
|
-
|
6464
|
-
|
6465
|
-
|
6466
|
-
|
6467
|
-
|
6468
|
-
|
6428
|
+
var angle = '';
|
6429
|
+
var line = '';
|
6430
|
+
var colorStops = [];
|
6431
|
+
// Determine if first part is direction/angle or color stop
|
6432
|
+
var firstPart = parts[0];
|
6433
|
+
var isDirection = /^\d+deg$/i.test(firstPart) ||
|
6434
|
+
/^to\s+/.test(firstPart) ||
|
6435
|
+
/^(?:circle|ellipse)/.test(firstPart) ||
|
6436
|
+
/at\s+/.test(firstPart);
|
6437
|
+
if (isDirection) {
|
6438
|
+
if (type === 'linear') {
|
6439
|
+
if (/^\d+deg$/i.test(firstPart)) {
|
6440
|
+
angle = firstPart.replace(/deg$/i, '');
|
6441
|
+
}
|
6442
|
+
else if (/^to\s+/.test(firstPart)) {
|
6443
|
+
line = firstPart;
|
6444
|
+
// Convert named directions to angles
|
6445
|
+
var directionMap = {
|
6446
|
+
'to top': '0',
|
6447
|
+
'to top right': '45',
|
6448
|
+
'to right': '90',
|
6449
|
+
'to bottom right': '135',
|
6450
|
+
'to bottom': '180',
|
6451
|
+
'to bottom left': '225',
|
6452
|
+
'to left': '270',
|
6453
|
+
'to top left': '315'
|
6454
|
+
};
|
6455
|
+
angle = directionMap[firstPart] || '0';
|
6456
|
+
}
|
6457
|
+
}
|
6458
|
+
else {
|
6459
|
+
line = firstPart;
|
6469
6460
|
}
|
6470
|
-
|
6471
|
-
matchColorStop = regExpLib.colorStopSearch.exec(matchGradient[5]);
|
6461
|
+
colorStops = parts.slice(1);
|
6472
6462
|
}
|
6473
|
-
|
6474
|
-
|
6475
|
-
|
6476
|
-
|
6477
|
-
|
6478
|
-
var result;
|
6479
|
-
var rGradientEnclosedInBrackets = /.*gradient\s*\(((?:\([^\)]*\)|[^\)\(]*)*)\)/;
|
6480
|
-
var match = rGradientEnclosedInBrackets.exec(input);
|
6481
|
-
if (match !== null) {
|
6482
|
-
result = parseGradient$1(regExpLib, match[1]);
|
6483
|
-
if (result.original.trim() !== match[1].trim()) {
|
6484
|
-
result.parseWarning = true;
|
6463
|
+
else {
|
6464
|
+
// No explicit direction, use defaults
|
6465
|
+
angle = type === 'linear' ? '180' : '';
|
6466
|
+
line = type === 'radial' ? 'circle at center' : '';
|
6467
|
+
colorStops = parts;
|
6485
6468
|
}
|
6486
|
-
|
6487
|
-
|
6469
|
+
// Parse color stops
|
6470
|
+
var stops_1 = [];
|
6471
|
+
for (var i = 0; i < colorStops.length; i++) {
|
6472
|
+
var stopString = colorStops[i].trim();
|
6473
|
+
// Try to extract color and position
|
6474
|
+
var stopMatch = stopString.match(/^(.+?)(?:\s+(\d+(?:\.\d+)?)(%)?)?$/);
|
6475
|
+
if (stopMatch) {
|
6476
|
+
var _b = __read(stopMatch, 4), colorStr = _b[1], positionStr = _b[2], isPercent = _b[3];
|
6477
|
+
var tinyColorInstance = tinycolor(colorStr.trim());
|
6478
|
+
if (tinyColorInstance.isValid()) {
|
6479
|
+
var stop_1 = {
|
6480
|
+
color: tinyColorInstance.toRgbString()
|
6481
|
+
};
|
6482
|
+
if (positionStr) {
|
6483
|
+
var position = parseFloat(positionStr);
|
6484
|
+
// Assume percentage if no unit specified
|
6485
|
+
if (isPercent || !isPercent) {
|
6486
|
+
position = position / 100;
|
6487
|
+
}
|
6488
|
+
stop_1.position = Math.max(0, Math.min(1, position));
|
6489
|
+
}
|
6490
|
+
stops_1.push(stop_1);
|
6491
|
+
}
|
6492
|
+
}
|
6493
|
+
}
|
6494
|
+
// Auto-assign positions if missing
|
6495
|
+
stops_1.forEach(function (stop, index) {
|
6496
|
+
if (!stop.hasOwnProperty('position')) {
|
6497
|
+
stop.position = stops_1.length > 1 ? index / (stops_1.length - 1) : 0;
|
6498
|
+
}
|
6499
|
+
});
|
6500
|
+
// Ensure we have at least 2 stops
|
6501
|
+
if (stops_1.length === 0) {
|
6502
|
+
return 'No valid color stops found';
|
6488
6503
|
}
|
6504
|
+
else if (stops_1.length === 1) {
|
6505
|
+
// Duplicate the single stop to create a valid gradient
|
6506
|
+
stops_1.push({
|
6507
|
+
color: stops_1[0].color,
|
6508
|
+
position: 1
|
6509
|
+
});
|
6510
|
+
}
|
6511
|
+
return {
|
6512
|
+
stops: stops_1,
|
6513
|
+
angle: angle,
|
6514
|
+
line: line,
|
6515
|
+
original: cleanInput
|
6516
|
+
};
|
6489
6517
|
}
|
6490
|
-
|
6491
|
-
|
6518
|
+
catch (error) {
|
6519
|
+
console.warn('Error parsing gradient:', error);
|
6520
|
+
return 'Failed to parse gradient';
|
6492
6521
|
}
|
6493
|
-
return result;
|
6494
6522
|
});
|
6495
6523
|
|
6496
6524
|
var LINEAR_POS = [
|
@@ -6574,6 +6602,94 @@ var parseGradient = (function (str) {
|
|
6574
6602
|
}
|
6575
6603
|
});
|
6576
6604
|
|
6605
|
+
/**
|
6606
|
+
* Convert gradient object to CSS gradient string
|
6607
|
+
*/
|
6608
|
+
function gradientObjectToCss(gradientData) {
|
6609
|
+
var type = gradientData.type, _a = gradientData.angle, angle = _a === void 0 ? 90 : _a, stops = gradientData.stops;
|
6610
|
+
// Convert stops to CSS format
|
6611
|
+
var cssStops = stops
|
6612
|
+
.sort(function (a, b) { return a.position - b.position; }) // Ensure stops are in order
|
6613
|
+
.map(function (stop) {
|
6614
|
+
var color = tinycolor(stop.color);
|
6615
|
+
return "".concat(color.toRgbString(), " ").concat(stop.position, "%");
|
6616
|
+
})
|
6617
|
+
.join(', ');
|
6618
|
+
if (type === 'linear') {
|
6619
|
+
return "linear-gradient(".concat(angle, "deg, ").concat(cssStops, ")");
|
6620
|
+
}
|
6621
|
+
else {
|
6622
|
+
return "radial-gradient(circle, ".concat(cssStops, ")");
|
6623
|
+
}
|
6624
|
+
}
|
6625
|
+
/**
|
6626
|
+
* Convert CSS gradient string to gradient object
|
6627
|
+
*/
|
6628
|
+
function cssToGradientObject(cssGradient) {
|
6629
|
+
try {
|
6630
|
+
var parsed = parseGradient(cssGradient);
|
6631
|
+
if (!parsed) {
|
6632
|
+
return null;
|
6633
|
+
}
|
6634
|
+
var type = parsed.type, modifier = parsed.modifier, stops = parsed.stops;
|
6635
|
+
// Convert stops to object format
|
6636
|
+
var gradientStops = stops.map(function (stop) { return ({
|
6637
|
+
color: String(stop[0]), // Ensure it's a string
|
6638
|
+
position: Math.round(stop[1] * 100) // Convert to percentage
|
6639
|
+
}); });
|
6640
|
+
// Extract angle from modifier (for linear gradients)
|
6641
|
+
var angle = 90; // Default angle
|
6642
|
+
if (type === 'linear' && modifier && typeof modifier === 'string') {
|
6643
|
+
var angleMatch = modifier.match(/(\d+)deg/);
|
6644
|
+
if (angleMatch) {
|
6645
|
+
angle = parseInt(angleMatch[1], 10);
|
6646
|
+
}
|
6647
|
+
}
|
6648
|
+
return {
|
6649
|
+
type: type,
|
6650
|
+
angle: type === 'linear' ? angle : undefined,
|
6651
|
+
stops: gradientStops,
|
6652
|
+
defaultActiveTab: 'gradient'
|
6653
|
+
};
|
6654
|
+
}
|
6655
|
+
catch (error) {
|
6656
|
+
console.warn('Failed to parse CSS gradient:', error);
|
6657
|
+
return null;
|
6658
|
+
}
|
6659
|
+
}
|
6660
|
+
/**
|
6661
|
+
* Check if a value is a gradient object
|
6662
|
+
*/
|
6663
|
+
function isGradientObject(value) {
|
6664
|
+
return (value &&
|
6665
|
+
typeof value === 'object' &&
|
6666
|
+
'type' in value &&
|
6667
|
+
'stops' in value &&
|
6668
|
+
Array.isArray(value.stops) &&
|
6669
|
+
value.stops.length > 0 &&
|
6670
|
+
value.stops.every(function (stop) {
|
6671
|
+
return stop &&
|
6672
|
+
typeof stop === 'object' &&
|
6673
|
+
'color' in stop &&
|
6674
|
+
'position' in stop &&
|
6675
|
+
typeof stop.position === 'number';
|
6676
|
+
}));
|
6677
|
+
}
|
6678
|
+
/**
|
6679
|
+
* Normalize value to always return a CSS gradient string
|
6680
|
+
*/
|
6681
|
+
function normalizeGradientValue(value) {
|
6682
|
+
if (typeof value === 'string') {
|
6683
|
+
return value;
|
6684
|
+
}
|
6685
|
+
if (isGradientObject(value)) {
|
6686
|
+
return gradientObjectToCss(value);
|
6687
|
+
}
|
6688
|
+
// Fallback
|
6689
|
+
return 'linear-gradient(90deg, #ffffff 0%, #000000 100%)';
|
6690
|
+
}
|
6691
|
+
// End of file
|
6692
|
+
|
6577
6693
|
var getAlphaValue = function (value) {
|
6578
6694
|
value.replace(/%/i, '');
|
6579
6695
|
if (value[0] === '0' && value.length > 1) {
|
@@ -6980,28 +7096,35 @@ IroColorPicker.displayName = 'IroColorPicker';
|
|
6980
7096
|
|
6981
7097
|
var getIndexActiveTag = function (value) {
|
6982
7098
|
var tab = 'solid';
|
6983
|
-
|
6984
|
-
if (value) {
|
6985
|
-
|
6986
|
-
|
6987
|
-
|
6988
|
-
|
6989
|
-
|
6990
|
-
|
6991
|
-
|
6992
|
-
tab = 'solid';
|
6993
|
-
return tab;
|
6994
|
-
}
|
6995
|
-
var rgba = rgbaToArray(value);
|
6996
|
-
if (rgba) {
|
6997
|
-
if (isValidRgba([rgba[0], rgba[1], rgba[2]])) {
|
7099
|
+
// Handle gradient object
|
7100
|
+
if (isGradientObject(value)) {
|
7101
|
+
return 'gradient';
|
7102
|
+
}
|
7103
|
+
// Handle string value
|
7104
|
+
if (typeof value === 'string') {
|
7105
|
+
var validValue = tinycolor(value).isValid();
|
7106
|
+
if (value) {
|
7107
|
+
if (value === 'transparent') {
|
6998
7108
|
tab = 'solid';
|
6999
7109
|
return tab;
|
7000
7110
|
}
|
7001
|
-
|
7002
|
-
|
7003
|
-
|
7004
|
-
|
7111
|
+
if (validValue &&
|
7112
|
+
!value.trim().startsWith('radial-gradient') &&
|
7113
|
+
!value.trim().startsWith('linear-gradient')) {
|
7114
|
+
tab = 'solid';
|
7115
|
+
return tab;
|
7116
|
+
}
|
7117
|
+
var rgba = rgbaToArray(value);
|
7118
|
+
if (rgba) {
|
7119
|
+
if (isValidRgba([rgba[0], rgba[1], rgba[2]])) {
|
7120
|
+
tab = 'solid';
|
7121
|
+
return tab;
|
7122
|
+
}
|
7123
|
+
}
|
7124
|
+
else {
|
7125
|
+
tab = 'gradient';
|
7126
|
+
return tab;
|
7127
|
+
}
|
7005
7128
|
}
|
7006
7129
|
}
|
7007
7130
|
return tab;
|
@@ -7636,7 +7759,19 @@ var IroGradient = function (_a) {
|
|
7636
7759
|
// Store the initial value for reset functionality
|
7637
7760
|
var initialValue = useRef(value);
|
7638
7761
|
var parsedColors = useCallback(function () {
|
7639
|
-
|
7762
|
+
try {
|
7763
|
+
var parsed = parseGradient(value);
|
7764
|
+
// If parsing failed, return fallback gradient
|
7765
|
+
if (typeof parsed === 'string') {
|
7766
|
+
console.warn('Gradient parsing failed, using fallback:', parsed);
|
7767
|
+
return parseGradient('linear-gradient(90deg, #ffffff 0%, #000000 100%)');
|
7768
|
+
}
|
7769
|
+
return parsed;
|
7770
|
+
}
|
7771
|
+
catch (error) {
|
7772
|
+
console.warn('Error parsing gradient, using fallback:', error);
|
7773
|
+
return parseGradient('linear-gradient(90deg, #ffffff 0%, #000000 100%)');
|
7774
|
+
}
|
7640
7775
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
7641
7776
|
}, [value]);
|
7642
7777
|
var _s = parsedColors(), stops = _s.stops, type = _s.type, modifier = _s.modifier;
|
@@ -8326,7 +8461,22 @@ var PopupTabsBodyItem = function (_a) {
|
|
8326
8461
|
|
8327
8462
|
var ColorPicker = function (_a) {
|
8328
8463
|
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;
|
8329
|
-
|
8464
|
+
// Convert object value to CSS string for internal use
|
8465
|
+
var cssValue = normalizeGradientValue(value);
|
8466
|
+
// Auto-switch to gradient tab if receiving gradient object
|
8467
|
+
var initialTab = isGradientObject(value)
|
8468
|
+
? 'gradient'
|
8469
|
+
: defaultActiveTab || getIndexActiveTag(value);
|
8470
|
+
var _w = __read(useState(initialTab), 2), activeTab = _w[0], setActiveTab = _w[1];
|
8471
|
+
// Auto-switch tab when value changes from object to string or vice versa
|
8472
|
+
React.useEffect(function () {
|
8473
|
+
if (isGradientObject(value) && activeTab !== 'gradient') {
|
8474
|
+
setActiveTab('gradient');
|
8475
|
+
if (typeof onChangeTabs === 'function') {
|
8476
|
+
onChangeTabs('gradient');
|
8477
|
+
}
|
8478
|
+
}
|
8479
|
+
}, [value, activeTab, onChangeTabs]);
|
8330
8480
|
var onChangeSolid = function (value) {
|
8331
8481
|
onChange(value);
|
8332
8482
|
};
|
@@ -8349,18 +8499,18 @@ var ColorPicker = function (_a) {
|
|
8349
8499
|
React.createElement(PopupTabsHeaderLabel, { tabName: 'gradient', onClick: function () { return onChangeTab('gradient'); } }, "Gradient")),
|
8350
8500
|
React.createElement(PopupTabsBody, null,
|
8351
8501
|
React.createElement(PopupTabsBodyItem, { tabName: 'solid' },
|
8352
|
-
React.createElement(IroSolidColorPicker, { onChange: onChangeSolid, value:
|
8502
|
+
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 })),
|
8353
8503
|
React.createElement(PopupTabsBodyItem, { tabName: 'gradient' },
|
8354
|
-
React.createElement(IroGradient, { onChange: onChangeGradient, value:
|
8504
|
+
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 })))))));
|
8355
8505
|
}
|
8356
8506
|
return (React.createElement(ThemeProvider, null,
|
8357
8507
|
React.createElement("div", { className: 'relative dark iro-gradient-picker', "data-color-picker-theme": true },
|
8358
8508
|
React.createElement(ThemeToggle, null),
|
8359
8509
|
solid || gradient ? (React.createElement(PopupTabs, { popupWidth: popupWidth },
|
8360
8510
|
React.createElement(PopupTabsBody, null,
|
8361
|
-
solid ? (React.createElement(IroSolidColorPicker, { onChange: onChangeSolid, value:
|
8362
|
-
gradient ? (React.createElement(IroGradient, { onChange: onChangeGradient, value:
|
8511
|
+
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)),
|
8512
|
+
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)));
|
8363
8513
|
};
|
8364
8514
|
|
8365
|
-
export { ColorPicker, DEFAULT_COLORS, InputRgba, PopupTabs, PopupTabsBody, PopupTabsBodyItem, PopupTabsHeader, PopupTabsHeaderLabel, RADIALS_POS, ThemeProvider, ThemeToggle, TinyColor, checkFormat, cn, ColorPicker as default, getGradient, getHexAlpha, hexToRgba, isValidHex, isValidRgba, parseGradient, rgbaToArray, rgbaToHex, useDebounce, validGradient };
|
8515
|
+
export { ColorPicker, DEFAULT_COLORS, InputRgba, PopupTabs, PopupTabsBody, PopupTabsBodyItem, PopupTabsHeader, PopupTabsHeaderLabel, RADIALS_POS, ThemeProvider, ThemeToggle, TinyColor, checkFormat, cn, cssToGradientObject, ColorPicker as default, getGradient, getHexAlpha, gradientObjectToCss, hexToRgba, isGradientObject, isValidHex, isValidRgba, normalizeGradientValue, parseGradient, rgbaToArray, rgbaToHex, useDebounce, validGradient };
|
8366
8516
|
//# sourceMappingURL=index.es.js.map
|