@finsweet/webflow-apps-utils 1.0.23 → 1.0.24
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.
|
@@ -89,8 +89,11 @@
|
|
|
89
89
|
.join('');
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
//
|
|
92
|
+
// Extract alpha channel if present (8-digit hex)
|
|
93
|
+
let alpha = 100;
|
|
93
94
|
if (normalizedHex.length === 8) {
|
|
95
|
+
const alphaHex = normalizedHex.substring(6, 8);
|
|
96
|
+
alpha = Math.round((parseInt(alphaHex, 16) / 255) * 100);
|
|
94
97
|
normalizedHex = normalizedHex.substring(0, 6);
|
|
95
98
|
}
|
|
96
99
|
|
|
@@ -203,8 +206,9 @@
|
|
|
203
206
|
|
|
204
207
|
function handleFullColorChange(fullColor: ColorObject) {
|
|
205
208
|
oncolorchange?.(fullColor);
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
// Preserve the alpha channel by using the full hex value with alpha
|
|
210
|
+
// The fullColor.hex already includes the alpha channel if alpha < 100
|
|
211
|
+
color = fullColor.hex;
|
|
208
212
|
}
|
|
209
213
|
|
|
210
214
|
let showColorSelect = $state(defaultShowColorSelect);
|
|
@@ -108,6 +108,26 @@
|
|
|
108
108
|
return normalizeHex(colorInput);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
// Helper function to extract alpha value from hex color
|
|
112
|
+
function extractAlphaFromHex(hexColor: string): number {
|
|
113
|
+
if (hexColor.startsWith('#') && hexColor.length === 9) {
|
|
114
|
+
// 8-digit hex with alpha channel (#RRGGBBAA)
|
|
115
|
+
const alphaHex = hexColor.slice(7, 9);
|
|
116
|
+
const alphaValue = parseInt(alphaHex, 16);
|
|
117
|
+
return Math.round((alphaValue / 255) * 100);
|
|
118
|
+
}
|
|
119
|
+
return 100; // Default to 100% opacity if no alpha channel
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Helper function to get hex without alpha channel
|
|
123
|
+
function getHexWithoutAlpha(hexColor: string): string {
|
|
124
|
+
if (hexColor.startsWith('#') && hexColor.length === 9) {
|
|
125
|
+
// Remove alpha channel from 8-digit hex
|
|
126
|
+
return hexColor.slice(0, 7);
|
|
127
|
+
}
|
|
128
|
+
return hexColor;
|
|
129
|
+
}
|
|
130
|
+
|
|
111
131
|
// Color conversion utilities
|
|
112
132
|
function hsbToRgb(h: number, s: number, b: number): [number, number, number] {
|
|
113
133
|
h = h / 360;
|
|
@@ -377,6 +397,7 @@
|
|
|
377
397
|
let hexInputValue = $state('');
|
|
378
398
|
let isHexEditing = $state(false);
|
|
379
399
|
let prevHexValue = $state('');
|
|
400
|
+
let isInitialized = $state(false);
|
|
380
401
|
|
|
381
402
|
function handleHexFocus(event: FocusEvent) {
|
|
382
403
|
prevHexValue = hexValue;
|
|
@@ -508,10 +529,18 @@
|
|
|
508
529
|
|
|
509
530
|
// Watch for prop changes - FIXED: Better color normalization
|
|
510
531
|
$effect(() => {
|
|
532
|
+
// Skip effect during initial mount to prevent overriding alpha
|
|
533
|
+
if (!isInitialized) return;
|
|
534
|
+
|
|
511
535
|
const normalized = normalizeColorToHex(color);
|
|
512
|
-
if
|
|
513
|
-
|
|
514
|
-
|
|
536
|
+
// Extract alpha value from the original color if it has an alpha channel
|
|
537
|
+
const alphaFromColor = extractAlphaFromHex(color);
|
|
538
|
+
|
|
539
|
+
// Use hex without alpha for internal processing
|
|
540
|
+
const hexWithoutAlpha = getHexWithoutAlpha(normalized);
|
|
541
|
+
if (hexWithoutAlpha !== hexValue) {
|
|
542
|
+
hexValue = hexWithoutAlpha;
|
|
543
|
+
const [h, s, b] = hexToHsb(hexValue);
|
|
515
544
|
hue = h;
|
|
516
545
|
saturation = s;
|
|
517
546
|
brightness = b;
|
|
@@ -519,6 +548,11 @@
|
|
|
519
548
|
// Force position update after state changes
|
|
520
549
|
setTimeout(() => updateColorPickerPosition(), 0);
|
|
521
550
|
}
|
|
551
|
+
|
|
552
|
+
// Only update alpha if it's different from current alpha
|
|
553
|
+
if (alphaFromColor !== alpha) {
|
|
554
|
+
alpha = alphaFromColor;
|
|
555
|
+
}
|
|
522
556
|
});
|
|
523
557
|
|
|
524
558
|
let currentColor = $derived(
|
|
@@ -527,14 +561,19 @@
|
|
|
527
561
|
|
|
528
562
|
onMount(() => {
|
|
529
563
|
const normalized = normalizeColorToHex(color);
|
|
530
|
-
|
|
531
|
-
const
|
|
564
|
+
// Extract alpha value from the original color if it has an alpha channel
|
|
565
|
+
const alphaFromColor = extractAlphaFromHex(color);
|
|
566
|
+
alpha = alphaFromColor;
|
|
567
|
+
|
|
568
|
+
// Use hex without alpha for internal processing
|
|
569
|
+
hexValue = getHexWithoutAlpha(normalized);
|
|
570
|
+
const [h, s, b] = hexToHsb(hexValue);
|
|
532
571
|
hue = h;
|
|
533
572
|
saturation = s;
|
|
534
573
|
brightness = b;
|
|
535
574
|
[rgbRed, rgbGreen, rgbBlue] = hsbToRgb(hue, saturation, brightness);
|
|
536
575
|
|
|
537
|
-
console.log('ColorSelect mounted', { color });
|
|
576
|
+
console.log('ColorSelect mounted', { color, alpha: alphaFromColor });
|
|
538
577
|
updateColor();
|
|
539
578
|
// Delay position update to ensure DOM is ready
|
|
540
579
|
|
|
@@ -543,6 +582,9 @@
|
|
|
543
582
|
document.addEventListener('mousemove', handleMouseMove);
|
|
544
583
|
document.addEventListener('mouseup', handleMouseUp);
|
|
545
584
|
|
|
585
|
+
// Mark as initialized after setting up the initial state
|
|
586
|
+
isInitialized = true;
|
|
587
|
+
|
|
546
588
|
return () => {
|
|
547
589
|
document.removeEventListener('mousemove', handleMouseMove);
|
|
548
590
|
document.removeEventListener('mouseup', handleMouseUp);
|