@ppg_pl/tinting 0.0.3 → 0.0.5
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/cjs/modal-header_9.cjs.entry.js +83 -33
- package/dist/cjs/modal-header_9.cjs.entry.js.map +1 -1
- package/dist/collection/components/api/services.js +12 -1
- package/dist/collection/components/api/services.js.map +1 -1
- package/dist/collection/components/modal/index.js +70 -31
- package/dist/collection/components/modal/index.js.map +1 -1
- package/dist/components/index10.js +71 -32
- package/dist/components/index10.js.map +1 -1
- package/dist/components/index2.js +12 -1
- package/dist/components/index2.js.map +1 -1
- package/dist/esm/modal-header_9.entry.js +83 -33
- package/dist/esm/modal-header_9.entry.js.map +1 -1
- package/dist/tinting/p-398633de.entry.js +15 -0
- package/dist/tinting/p-398633de.entry.js.map +1 -0
- package/dist/tinting/tinting.esm.js +1 -1
- package/dist/types/components/api/services.d.ts +1 -1
- package/package.json +1 -1
- package/www/build/p-398633de.entry.js +15 -0
- package/www/build/p-398633de.entry.js.map +1 -0
- package/www/build/tinting.esm.js +1 -1
- package/dist/tinting/p-1028bea2.entry.js +0 -15
- package/dist/tinting/p-1028bea2.entry.js.map +0 -1
- package/www/build/p-1028bea2.entry.js +0 -15
- package/www/build/p-1028bea2.entry.js.map +0 -1
|
@@ -2565,10 +2565,21 @@ const fetchColors = async (filters) => {
|
|
|
2565
2565
|
return [];
|
|
2566
2566
|
}
|
|
2567
2567
|
};
|
|
2568
|
+
const getSampleSortForProduct = (sample, productId) => {
|
|
2569
|
+
var _a, _b;
|
|
2570
|
+
const link = (_a = sample === null || sample === void 0 ? void 0 : sample.Products) === null || _a === void 0 ? void 0 : _a.find((p) => p.Product_id === productId);
|
|
2571
|
+
// put null/undefined at the end
|
|
2572
|
+
return (_b = link === null || link === void 0 ? void 0 : link.sort) !== null && _b !== void 0 ? _b : Number.POSITIVE_INFINITY;
|
|
2573
|
+
};
|
|
2568
2574
|
const fetchSamplesColors = async (filters) => {
|
|
2569
2575
|
try {
|
|
2576
|
+
// you already include Products.* in the query
|
|
2577
|
+
const { id: productId } = filters;
|
|
2570
2578
|
const response = await ApiService.getData(`items/Sample?${fetchColorsQuery(Object.assign({}, filters))}`);
|
|
2571
|
-
|
|
2579
|
+
const data = (response === null || response === void 0 ? void 0 : response.data) || [];
|
|
2580
|
+
// order by junction sort
|
|
2581
|
+
const ordered = [...data].sort((a, b) => getSampleSortForProduct(a, productId) - getSampleSortForProduct(b, productId));
|
|
2582
|
+
return ordered;
|
|
2572
2583
|
}
|
|
2573
2584
|
catch (error) {
|
|
2574
2585
|
console.error('Error fetching samples colors:', error);
|
|
@@ -6601,10 +6612,20 @@ const Modal = class {
|
|
|
6601
6612
|
let mostSimilarIndex = 0;
|
|
6602
6613
|
let minDistance = Infinity;
|
|
6603
6614
|
remainingColors.forEach((color, index) => {
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6615
|
+
try {
|
|
6616
|
+
// Validate hex colors before calculating distance
|
|
6617
|
+
if (!color.hex || !lastColor.hex) {
|
|
6618
|
+
return;
|
|
6619
|
+
}
|
|
6620
|
+
const distance = chroma.distance(lastColor.hex, color.hex, 'lab');
|
|
6621
|
+
if (distance < minDistance) {
|
|
6622
|
+
minDistance = distance;
|
|
6623
|
+
mostSimilarIndex = index;
|
|
6624
|
+
}
|
|
6625
|
+
}
|
|
6626
|
+
catch (error) {
|
|
6627
|
+
console.warn(`Error calculating color distance for ${color.hex}:`, error);
|
|
6628
|
+
// Skip this color if it causes an error
|
|
6608
6629
|
}
|
|
6609
6630
|
});
|
|
6610
6631
|
// Move the most similar color to sortedColors
|
|
@@ -6613,36 +6634,65 @@ const Modal = class {
|
|
|
6613
6634
|
return sortedColors;
|
|
6614
6635
|
}
|
|
6615
6636
|
getColorHueGroup(hex) {
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
return '
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6637
|
+
try {
|
|
6638
|
+
// Validate hex format and handle invalid colors
|
|
6639
|
+
if (!hex || typeof hex !== 'string') {
|
|
6640
|
+
return 'other';
|
|
6641
|
+
}
|
|
6642
|
+
// Basic hex validation
|
|
6643
|
+
const cleanHex = hex.startsWith('#') ? hex : `#${hex}`;
|
|
6644
|
+
if (!/^#[0-9A-Fa-f]{6}$/.test(cleanHex)) {
|
|
6645
|
+
console.warn(`Invalid hex color format: ${hex}`);
|
|
6646
|
+
return 'other';
|
|
6647
|
+
}
|
|
6648
|
+
const color = chroma(cleanHex);
|
|
6649
|
+
const hue = color.get('hsl.h');
|
|
6650
|
+
const saturation = color.get('hsl.s');
|
|
6651
|
+
const lightness = color.get('hsl.l');
|
|
6652
|
+
// Handle grayscale colors
|
|
6653
|
+
if (saturation < 0.1) {
|
|
6654
|
+
if (lightness < 0.2)
|
|
6655
|
+
return 'black';
|
|
6656
|
+
if (lightness > 0.8)
|
|
6657
|
+
return 'white';
|
|
6658
|
+
return 'gray';
|
|
6659
|
+
}
|
|
6660
|
+
// Group colors by hue ranges
|
|
6661
|
+
if (hue >= 330 || hue < 30)
|
|
6662
|
+
return 'red';
|
|
6663
|
+
if (hue >= 30 && hue < 90)
|
|
6664
|
+
return 'yellow';
|
|
6665
|
+
if (hue >= 90 && hue < 150)
|
|
6666
|
+
return 'green';
|
|
6667
|
+
if (hue >= 150 && hue < 210)
|
|
6668
|
+
return 'cyan';
|
|
6669
|
+
if (hue >= 210 && hue < 270)
|
|
6670
|
+
return 'blue';
|
|
6671
|
+
if (hue >= 270 && hue < 330)
|
|
6672
|
+
return 'magenta';
|
|
6673
|
+
return 'other';
|
|
6674
|
+
}
|
|
6675
|
+
catch (error) {
|
|
6676
|
+
console.warn(`Error parsing color "${hex}":`, error);
|
|
6677
|
+
return 'other';
|
|
6678
|
+
}
|
|
6642
6679
|
}
|
|
6643
6680
|
sortColorsByHueAndSimilarity(colors) {
|
|
6644
6681
|
if ((colors === null || colors === void 0 ? void 0 : colors.length) <= 1)
|
|
6645
6682
|
return colors;
|
|
6683
|
+
// Filter out colors with invalid hex values
|
|
6684
|
+
const validColors = colors.filter(color => {
|
|
6685
|
+
if (!color.hex || typeof color.hex !== 'string') {
|
|
6686
|
+
console.warn(`Color missing hex value:`, color);
|
|
6687
|
+
return false;
|
|
6688
|
+
}
|
|
6689
|
+
const cleanHex = color.hex.startsWith('#') ? color.hex : `#${color.hex}`;
|
|
6690
|
+
const isValid = /^#[0-9A-Fa-f]{6}$/.test(cleanHex);
|
|
6691
|
+
if (!isValid) {
|
|
6692
|
+
console.warn(`Invalid hex color format: ${color.hex} for color:`, color);
|
|
6693
|
+
}
|
|
6694
|
+
return isValid;
|
|
6695
|
+
});
|
|
6646
6696
|
// Group valid colors by their hue family
|
|
6647
6697
|
const colorGroups = {
|
|
6648
6698
|
red: [],
|
|
@@ -6656,7 +6706,7 @@ const Modal = class {
|
|
|
6656
6706
|
white: [],
|
|
6657
6707
|
other: [],
|
|
6658
6708
|
};
|
|
6659
|
-
|
|
6709
|
+
validColors.forEach(color => {
|
|
6660
6710
|
const group = this.getColorHueGroup(color.hex);
|
|
6661
6711
|
colorGroups[group].push(color);
|
|
6662
6712
|
});
|
|
@@ -6668,7 +6718,7 @@ const Modal = class {
|
|
|
6668
6718
|
sortedGroups.push(this.sortColorsBySimilarity(colorGroups[groupName]));
|
|
6669
6719
|
}
|
|
6670
6720
|
});
|
|
6671
|
-
// Combine all sorted groups
|
|
6721
|
+
// Combine all sorted groups
|
|
6672
6722
|
return sortedGroups.flat();
|
|
6673
6723
|
}
|
|
6674
6724
|
async fetchColorsData({ reset = false } = {}) {
|