@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
|
@@ -43,10 +43,21 @@ export const fetchColors = async (filters) => {
|
|
|
43
43
|
return [];
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
+
const getSampleSortForProduct = (sample, productId) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
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);
|
|
49
|
+
// put null/undefined at the end
|
|
50
|
+
return (_b = link === null || link === void 0 ? void 0 : link.sort) !== null && _b !== void 0 ? _b : Number.POSITIVE_INFINITY;
|
|
51
|
+
};
|
|
46
52
|
export const fetchSamplesColors = async (filters) => {
|
|
47
53
|
try {
|
|
54
|
+
// you already include Products.* in the query
|
|
55
|
+
const { id: productId } = filters;
|
|
48
56
|
const response = await ApiService.getData(`items/Sample?${fetchColorsQuery(Object.assign({}, filters))}`);
|
|
49
|
-
|
|
57
|
+
const data = (response === null || response === void 0 ? void 0 : response.data) || [];
|
|
58
|
+
// order by junction sort
|
|
59
|
+
const ordered = [...data].sort((a, b) => getSampleSortForProduct(a, productId) - getSampleSortForProduct(b, productId));
|
|
60
|
+
return ordered;
|
|
50
61
|
}
|
|
51
62
|
catch (error) {
|
|
52
63
|
console.error('Error fetching samples colors:', error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.js","sourceRoot":"","sources":["../../../src/components/api/services.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAG/B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAC;AAEzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAA4B,EAAE,EAAE;EAC/D,MAAM,EAAE,SAAS,KAAqB,OAAO,EAAvB,WAAW,UAAK,OAAO,EAAvC,aAA6B,CAAU,CAAC;EAE9C,OAAO,EAAE,CAAC,SAAS,CACjB;IACE,MAAM,EAAE,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;IAClD,MAAM,EAAE;MACN,IAAI,EAAE;QACJ,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAClF,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,WAAW,C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kDAAkD,CAAC,CAAC;IAClE,OAAO,IAAI,CAAC;GACb;EAAC,OAAO,KAAK,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC;GACb;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAAI,EAAE;;EAC3C,IAAI;IACF,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAEtE,OAAO,CAAA,MAAA,MAAA,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,0CAAE,IAAI,0CAAE,OAAO,0CAAE,OAAO,KAAI,EAAE,CAAC;GACrD;EAAC,OAAO,KAAK,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC;GACX;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAA4B,EAAE,SAA8B,EAAE,EAAE;EAC5F,uCAAY,OAAO,GAAK,SAAS,EAAG;AACtC,CAAC,CAAC","sourcesContent":["import qs from 'qs';\nimport { ApiService } from '.';\nimport { ProductShopRelation } from '../../types';\n\nexport const limit = 200;\n\nexport const fetchColorsQuery = (filters: Record<string, any>) => {\n const { sortByHex, ...restFilters } = filters;\n\n return qs.stringify(\n {\n fields: ['*', 'Products.*', 'Samples.*'].join(','),\n filter: {\n _and: [\n ...(restFilters.id ? [{ Products: { Product_id: { _eq: restFilters.id } } }] : []),\n ...(restFilters.sampleId ? [{ Samples: { Sample_id: { _eq: restFilters.sampleId } } }] : []),\n ...(restFilters.colorNumber ? [{ number: { _contains: restFilters.colorNumber } }] : []),\n ...(restFilters.colorName ? [{ name: { _icontains: restFilters.colorName } }] : []),\n ...(restFilters.colorFamily ? [{ colorFamily: { _eq: restFilters.colorFamily } }] : []),\n ],\n },\n sort: sortByHex === 'desc' ? '-hex' : sortByHex === 'asc' ? 'hex' : undefined,\n meta: '*',\n page: restFilters.page !== undefined ? restFilters.page : 1,\n limit: restFilters.colorName ? 200 : limit,\n },\n { encodeValuesOnly: true },\n );\n};\n\nexport const fetchColors = async (filters: Record<string, any>) => {\n try {\n const query = fetchColorsQuery({ ...filters, sortByHex: 'desc' });\n const response = await ApiService.getData(`items/Color?${query}`);\n return response?.data || [];\n } catch (error) {\n console.error('Error fetching colors:', error);\n return [];\n }\n};\n\nconst getSampleSortForProduct = (sample: any, productId: number) => {\n const link = sample?.Products?.find((p: any) => p.Product_id === productId);\n // put null/undefined at the end\n return link?.sort ?? Number.POSITIVE_INFINITY;\n};\n\nexport const fetchSamplesColors = async (filters: Record<string, any>) => {\n try {\n // you already include Products.* in the query\n const { id: productId } = filters;\n const response = await ApiService.getData(`items/Sample?${fetchColorsQuery({ ...filters })}`);\n const data = response?.data || [];\n\n // order by junction sort\n const ordered = [...data].sort((a, b) => getSampleSortForProduct(a, productId) - getSampleSortForProduct(b, productId));\n\n return ordered;\n } catch (error) {\n console.error('Error fetching samples colors:', error);\n return [];\n }\n};\n\nexport const fetchProductData = async (filters: Record<string, any>) => {\n try {\n // Fetch shop details\n const shopResponse = await ApiService.getData(`items/Shop?filter[name][_eq]=${filters.shopName}`);\n const shop = shopResponse?.data?.[0];\n\n if (!shop?.id) {\n console.error('Shop not found');\n return null;\n }\n\n // Fetch product details\n const response = await ApiService.getData(`items/Product?filter[name][_eq]=${filters.productName}&fields=*,images.*,Shop.*,Category.*.*.*.*`);\n const product = response?.data?.[0];\n\n // fetch product samples\n const productSamples = await fetchSamplesColors({ id: product.id, page: 0 });\n\n if (product && product.Shop.some((s: ProductShopRelation) => s.Shop_id === shop.id)) {\n return { ...product, id: product.id, productSamples };\n }\n\n console.error('Product not found or does not belong to the shop');\n return null;\n } catch (error) {\n console.error('Error fetching product data:', error);\n return null;\n }\n};\n\nexport const fetchColorFamilies = async () => {\n try {\n const response = await ApiService.getData(`fields/Color/colorFamily`);\n\n return response?.data?.meta?.options?.choices || [];\n } catch (error) {\n console.error('Error fetching color families:', error);\n return [];\n }\n};\n\nexport const updateFilters = (filters: Record<string, any>, newFilter: Record<string, any>) => {\n return { ...filters, ...newFilter };\n};\n"]}
|
|
@@ -136,10 +136,20 @@ export class Modal {
|
|
|
136
136
|
let mostSimilarIndex = 0;
|
|
137
137
|
let minDistance = Infinity;
|
|
138
138
|
remainingColors.forEach((color, index) => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
try {
|
|
140
|
+
// Validate hex colors before calculating distance
|
|
141
|
+
if (!color.hex || !lastColor.hex) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const distance = chroma.distance(lastColor.hex, color.hex, 'lab');
|
|
145
|
+
if (distance < minDistance) {
|
|
146
|
+
minDistance = distance;
|
|
147
|
+
mostSimilarIndex = index;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.warn(`Error calculating color distance for ${color.hex}:`, error);
|
|
152
|
+
// Skip this color if it causes an error
|
|
143
153
|
}
|
|
144
154
|
});
|
|
145
155
|
// Move the most similar color to sortedColors
|
|
@@ -148,36 +158,65 @@ export class Modal {
|
|
|
148
158
|
return sortedColors;
|
|
149
159
|
}
|
|
150
160
|
getColorHueGroup(hex) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return '
|
|
161
|
-
|
|
161
|
+
try {
|
|
162
|
+
// Validate hex format and handle invalid colors
|
|
163
|
+
if (!hex || typeof hex !== 'string') {
|
|
164
|
+
return 'other';
|
|
165
|
+
}
|
|
166
|
+
// Basic hex validation
|
|
167
|
+
const cleanHex = hex.startsWith('#') ? hex : `#${hex}`;
|
|
168
|
+
if (!/^#[0-9A-Fa-f]{6}$/.test(cleanHex)) {
|
|
169
|
+
console.warn(`Invalid hex color format: ${hex}`);
|
|
170
|
+
return 'other';
|
|
171
|
+
}
|
|
172
|
+
const color = chroma(cleanHex);
|
|
173
|
+
const hue = color.get('hsl.h');
|
|
174
|
+
const saturation = color.get('hsl.s');
|
|
175
|
+
const lightness = color.get('hsl.l');
|
|
176
|
+
// Handle grayscale colors
|
|
177
|
+
if (saturation < 0.1) {
|
|
178
|
+
if (lightness < 0.2)
|
|
179
|
+
return 'black';
|
|
180
|
+
if (lightness > 0.8)
|
|
181
|
+
return 'white';
|
|
182
|
+
return 'gray';
|
|
183
|
+
}
|
|
184
|
+
// Group colors by hue ranges
|
|
185
|
+
if (hue >= 330 || hue < 30)
|
|
186
|
+
return 'red';
|
|
187
|
+
if (hue >= 30 && hue < 90)
|
|
188
|
+
return 'yellow';
|
|
189
|
+
if (hue >= 90 && hue < 150)
|
|
190
|
+
return 'green';
|
|
191
|
+
if (hue >= 150 && hue < 210)
|
|
192
|
+
return 'cyan';
|
|
193
|
+
if (hue >= 210 && hue < 270)
|
|
194
|
+
return 'blue';
|
|
195
|
+
if (hue >= 270 && hue < 330)
|
|
196
|
+
return 'magenta';
|
|
197
|
+
return 'other';
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
console.warn(`Error parsing color "${hex}":`, error);
|
|
201
|
+
return 'other';
|
|
162
202
|
}
|
|
163
|
-
// Group colors by hue ranges
|
|
164
|
-
if (hue >= 330 || hue < 30)
|
|
165
|
-
return 'red';
|
|
166
|
-
if (hue >= 30 && hue < 90)
|
|
167
|
-
return 'yellow';
|
|
168
|
-
if (hue >= 90 && hue < 150)
|
|
169
|
-
return 'green';
|
|
170
|
-
if (hue >= 150 && hue < 210)
|
|
171
|
-
return 'cyan';
|
|
172
|
-
if (hue >= 210 && hue < 270)
|
|
173
|
-
return 'blue';
|
|
174
|
-
if (hue >= 270 && hue < 330)
|
|
175
|
-
return 'magenta';
|
|
176
|
-
return 'other';
|
|
177
203
|
}
|
|
178
204
|
sortColorsByHueAndSimilarity(colors) {
|
|
179
205
|
if ((colors === null || colors === void 0 ? void 0 : colors.length) <= 1)
|
|
180
206
|
return colors;
|
|
207
|
+
// Filter out colors with invalid hex values
|
|
208
|
+
const validColors = colors.filter(color => {
|
|
209
|
+
if (!color.hex || typeof color.hex !== 'string') {
|
|
210
|
+
console.warn(`Color missing hex value:`, color);
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
const cleanHex = color.hex.startsWith('#') ? color.hex : `#${color.hex}`;
|
|
214
|
+
const isValid = /^#[0-9A-Fa-f]{6}$/.test(cleanHex);
|
|
215
|
+
if (!isValid) {
|
|
216
|
+
console.warn(`Invalid hex color format: ${color.hex} for color:`, color);
|
|
217
|
+
}
|
|
218
|
+
return isValid;
|
|
219
|
+
});
|
|
181
220
|
// Group valid colors by their hue family
|
|
182
221
|
const colorGroups = {
|
|
183
222
|
red: [],
|
|
@@ -191,7 +230,7 @@ export class Modal {
|
|
|
191
230
|
white: [],
|
|
192
231
|
other: [],
|
|
193
232
|
};
|
|
194
|
-
|
|
233
|
+
validColors.forEach(color => {
|
|
195
234
|
const group = this.getColorHueGroup(color.hex);
|
|
196
235
|
colorGroups[group].push(color);
|
|
197
236
|
});
|
|
@@ -203,7 +242,7 @@ export class Modal {
|
|
|
203
242
|
sortedGroups.push(this.sortColorsBySimilarity(colorGroups[groupName]));
|
|
204
243
|
}
|
|
205
244
|
});
|
|
206
|
-
// Combine all sorted groups
|
|
245
|
+
// Combine all sorted groups
|
|
207
246
|
return sortedGroups.flat();
|
|
208
247
|
}
|
|
209
248
|
async fetchColorsData({ reset = false } = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/modal/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Method, Element, Prop, Event, EventEmitter, h, State, Listen, Watch } from '@stencil/core';\nimport { APIURL, accessToken } from '../api';\nimport { setDataLayer } from '../../gtmUtils';\nimport { Color, Product } from '../../types';\nimport { fetchColors, fetchProductData, limit, updateFilters } from '../api/services';\nimport { debounce } from '../../utils';\nimport chroma from 'chroma-js';\n\ndeclare global {\n interface Window {\n dataLayer: Record<string, any>[];\n }\n}\n\n@Component({\n tag: 'my-modal',\n styleUrl: 'index.scss',\n assetsDirs: ['assets'],\n})\nexport class Modal {\n private boxDesktopWidth = 130;\n private boxMobileWidth = 70;\n private desktopPadding = 75;\n private mobilePadding = 35;\n private mediumBreakpoint = 1024;\n private colorTimerInterval: ReturnType<typeof setInterval> | undefined;\n\n @Event({ bubbles: true, composed: true }) onSelectedColorEmit: EventEmitter<Color>;\n\n @Event({ bubbles: true, composed: true }) clearSearchText: EventEmitter;\n @Element() modalEl: HTMLElement;\n\n @Prop() shop: string;\n @Prop() product: string;\n @Prop() baselink: string;\n @Prop() selectedcolor: string | null;\n @Prop() arrowDown = 'arrow_down.png';\n\n @State() chunksNum = 12;\n @State() data: Product | null = null;\n @State() preloader = false;\n @State() loading = false;\n @State() currentColor: Color | null = null;\n @State() currentIndex: number | null = null;\n @State() infoBoxWidth: number | null = null;\n @State() boxWidth: number = this.boxDesktopWidth; // box width with gap\n @State() padding: number = this.desktopPadding;\n @State() isMobile: boolean = false;\n @State() showRange: boolean = false;\n @State() colorCategories: string[] | null = null;\n @State() selectedCategory: any = null;\n @State() page = 1;\n @State() colorIsSelected = false;\n @State() colorsList: Color[] = [];\n @State() hasMore = true;\n @State() filters: any = {\n type: 'product' as 'product' | 'sample' | 'number' | 'name' | 'sampleInProduct',\n id: '',\n productId: '',\n page: 1,\n colorNumber: '',\n colorName: '',\n };\n\n debouncedSearchColorsHandler: (event: CustomEvent) => void;\n\n constructor() {\n this.debouncedSearchColorsHandler = debounce(this.searchColor.bind(this), 300);\n }\n\n @Watch('chunksNum')\n setInfoBoxWidth(newValue: number) {\n this.infoBoxWidth = newValue * this.boxWidth;\n }\n\n @Watch('data')\n watchPropHandler(newValue: Product) {\n if (newValue) {\n this.filters = updateFilters(this.filters, { id: newValue.id, type: 'product' });\n this.fetchColorsData();\n }\n }\n\n private clearInterval = () => {\n this.colorTimerInterval && clearInterval(this.colorTimerInterval);\n this.colorTimerInterval = undefined;\n };\n\n private colorTimer = () => {\n if (this.currentColor && this.currentColor.id) {\n this.colorTimerInterval = setInterval(() => {\n this.currentColor?.name &&\n setDataLayer({\n event: 'ColorTimer',\n shop: this.shop,\n product: this.product,\n color: this.currentColor?.name,\n timer: '10',\n });\n }, 10000);\n } else {\n this.clearInterval();\n }\n };\n\n @Method()\n async open() {\n this.modalEl.style.display = 'block';\n }\n @Event() close: EventEmitter;\n closeModalHandler() {\n this.close.emit();\n }\n\n @Event() readyToCLose: EventEmitter;\n handleReadyToClose(value: boolean) {\n this.readyToCLose.emit({ observable: value });\n }\n\n @Listen('closeInfoBox')\n closeInfoBoxHandler() {\n this.currentColor = null;\n this.currentIndex = null;\n }\n\n @Listen('onCurrentColor')\n handleEmitColor(event: CustomEvent<Color>) {\n this.onSelectedColorEmit.emit(event.detail);\n }\n\n private chunks = (xs: Color[], y: Color[][] = []): Color[][] => {\n return xs?.length === 0 ? y : this.chunks(xs?.slice(this.chunksNum), y.concat([xs?.slice(0, this.chunksNum)]));\n };\n\n private calculateBoxCount = () => {\n const modalWidth = this.modalEl.children && this.modalEl.children[0] && this.modalEl.children[0]?.clientWidth - this.padding;\n const boxWidth = this.boxWidth;\n\n const calc = Math.floor(modalWidth / boxWidth);\n\n const boxesCount = calc;\n\n if (!this.preloader) this.chunksNum = boxesCount;\n };\n\n private displayForMobile = () => {\n if (window.innerWidth < this.mediumBreakpoint) {\n this.boxWidth = this.boxMobileWidth;\n this.padding = this.mobilePadding;\n this.isMobile = true;\n } else {\n this.isMobile = false;\n this.boxWidth = this.boxDesktopWidth;\n this.padding = this.desktopPadding;\n }\n };\n\n @Listen('resize', { target: 'window' })\n handleResize() {\n this.calculateBoxCount();\n this.displayForMobile();\n }\n\n private sortColorsBySimilarity(colors: Color[]): Color[] {\n if (colors?.length <= 1) return colors;\n\n const sortedColors: Color[] = [];\n const remainingColors = [...colors];\n\n // Start with the first color\n sortedColors.push(remainingColors.shift()!);\n\n while (remainingColors?.length > 0) {\n // Find the most similar color to the last color in sortedColors\n const lastColor = sortedColors[sortedColors?.length - 1];\n let mostSimilarIndex = 0;\n let minDistance = Infinity;\n\n remainingColors.forEach((color, index) => {\n const distance = chroma.distance(lastColor.hex, color.hex, 'lab');\n if (distance < minDistance) {\n minDistance = distance;\n mostSimilarIndex = index;\n }\n });\n\n // Move the most similar color to sortedColors\n sortedColors.push(remainingColors.splice(mostSimilarIndex, 1)[0]);\n }\n\n return sortedColors;\n }\n\n private getColorHueGroup(hex: string): string {\n const color = chroma(hex);\n const hue = color.get('hsl.h');\n const saturation = color.get('hsl.s');\n const lightness = color.get('hsl.l');\n\n // Handle grayscale colors\n if (saturation < 0.1) {\n if (lightness < 0.2) return 'black';\n if (lightness > 0.8) return 'white';\n return 'gray';\n }\n\n // Group colors by hue ranges\n if (hue >= 330 || hue < 30) return 'red';\n if (hue >= 30 && hue < 90) return 'yellow';\n if (hue >= 90 && hue < 150) return 'green';\n if (hue >= 150 && hue < 210) return 'cyan';\n if (hue >= 210 && hue < 270) return 'blue';\n if (hue >= 270 && hue < 330) return 'magenta';\n\n return 'other';\n }\n\n private sortColorsByHueAndSimilarity(colors: Color[]): Color[] {\n if (colors?.length <= 1) return colors;\n\n // Group valid colors by their hue family\n const colorGroups: Record<string, Color[]> = {\n red: [],\n yellow: [],\n green: [],\n cyan: [],\n blue: [],\n magenta: [],\n gray: [],\n black: [],\n white: [],\n other: [],\n };\n\n colors.forEach(color => {\n const group = this.getColorHueGroup(color.hex);\n colorGroups[group].push(color);\n });\n\n // Sort each group by similarity\n const sortedGroups: Color[][] = [];\n const groupOrder = ['red', 'magenta', 'blue', 'cyan', 'green', 'yellow', 'gray', 'black', 'white', 'other'];\n\n groupOrder.forEach(groupName => {\n if (colorGroups[groupName].length > 0) {\n sortedGroups.push(this.sortColorsBySimilarity(colorGroups[groupName]));\n }\n });\n\n // Combine all sorted groups, then append invalid colors at the end\n return sortedGroups.flat();\n }\n\n private async fetchColorsData({ reset = false } = {}) {\n if (this.loading && !reset) return;\n this.loading = true;\n\n try {\n const colors = await fetchColors(this.filters);\n\n if (reset) {\n // For new searches, sort all colors by hue and similarity\n this.colorsList = this.sortColorsByHueAndSimilarity(colors);\n } else {\n // For pagination, combine and sort all colors\n this.colorsList = this.sortColorsByHueAndSimilarity([...this.colorsList, ...colors]);\n }\n\n this.hasMore = colors.length >= limit;\n } catch (error) {\n console.error('Error fetching colors:', error);\n } finally {\n this.loading = false;\n }\n }\n\n private async loadProductData() {\n this.preloader = true;\n\n const product = await fetchProductData({ shopName: this.shop, productName: this.product });\n\n if (product) {\n this.data = product;\n this.filters = updateFilters(this.filters, { type: 'product', id: product.id });\n\n // Fetch initial colors\n await this.fetchColorsData();\n }\n\n this.preloader = false;\n }\n\n private async loadMoreColors() {\n if (this.loading || !this.hasMore) return; // Prevent spam loading\n\n this.filters = { ...this.filters, page: this.filters.page + 1 }; // Increase page for lazy loading\n\n await this.fetchColorsData({ reset: false }); // Append results\n }\n\n private updateFilterAndFetch(newFilters: Partial<typeof this.filters>) {\n if (!this.data?.id) return;\n\n this.loading = true;\n\n this.filters = updateFilters(this.filters, {\n id: this.data.id,\n sampleId: this.filters.sampleId,\n colorName: this.filters.colorName,\n ...newFilters,\n page: 1,\n });\n\n this.fetchColorsData({ reset: true }).finally(() => {\n this.loading = false;\n });\n }\n\n async searchColor(event: CustomEvent) {\n const query = event.detail?.trim();\n\n this.updateFilterAndFetch({ colorName: query });\n }\n\n @Listen('colorFamilySelected')\n handleColorFamilySelected(event: CustomEvent) {\n this.currentColor = null;\n if (event.detail === this.filters.colorFamily) {\n this.filters = updateFilters(this.filters, { colorFamily: '' });\n this.updateFilterAndFetch({ colorFamily: '' });\n } else {\n this.filters = updateFilters(this.filters, { colorFamily: event.detail });\n this.updateFilterAndFetch({ colorFamily: event.detail });\n }\n }\n\n @Listen('searchColors')\n searchColorsHandler(event: CustomEvent) {\n this.loading = true;\n this.currentColor = null;\n this.debouncedSearchColorsHandler(event);\n }\n\n private handleSampleSelect = (selectedSample?: any) => {\n this.currentColor = null;\n this.selectedCategory = selectedSample.value;\n\n this.updateFilterAndFetch({ sampleId: selectedSample.value, colorFamily: '' });\n };\n\n handleScroll(_event: Event, modalContent: HTMLElement) {\n if (this.loading || !this.hasMore) return;\n\n const scrollTop = modalContent.scrollTop;\n const scrollHeight = modalContent.scrollHeight;\n const clientHeight = modalContent.clientHeight;\n\n // Check if user scrolled to the bottom of the modal\n if (scrollTop + clientHeight >= scrollHeight - 50) {\n this.loadMoreColors();\n }\n }\n\n private openSeletedColor() {\n if (!this.colorsList || !this.selectedcolor) return;\n\n if (!this.colorIsSelected) {\n const result = this.chunks(this.colorsList)\n .map((innerArray, arrayIndex) => {\n const foundColor = innerArray.find(color => color.name.trim()?.toUpperCase() === this.selectedcolor?.trim()?.toUpperCase());\n\n return foundColor ? { color: foundColor, index: arrayIndex } : null;\n })\n .filter(item => item !== null);\n\n this.currentColor = result[0]?.color as any;\n this.currentIndex = result[0]?.index as any;\n this.colorIsSelected = true;\n }\n }\n\n componentWillLoad() {\n this.preloader = true;\n setDataLayer({\n shop: this.shop,\n product: this.product,\n });\n\n this.loadProductData();\n }\n\n componentWillRender() {\n this.displayForMobile();\n this.calculateBoxCount();\n this.colorTimer();\n this.openSeletedColor();\n\n const modalContent = this.modalEl.querySelector('.my-modal') as HTMLElement;\n if (modalContent) {\n modalContent.addEventListener('scroll', event => this.handleScroll(event, modalContent));\n }\n }\n\n private resetColors() {\n this.currentColor = null;\n this.currentIndex = null;\n this.colorIsSelected = false;\n }\n\n private resetAllFilters() {\n // Reset current color selection\n this.resetColors();\n\n // Reset filters to initial state\n this.filters = {\n type: 'product',\n id: this.data?.id || '',\n productId: '',\n page: 1,\n colorNumber: '',\n colorName: '',\n colorFamily: '',\n sampleId: '',\n };\n\n // Reset selected category\n this.selectedCategory = null;\n\n // Clear search text\n this.clearSearchText.emit();\n\n // Fetch colors with reset filters\n this.fetchColorsData({ reset: true });\n }\n\n private resetSelectedCategory() {\n this.resetColors();\n this.colorIsSelected = false;\n this.selectedCategory = null;\n this.filters = updateFilters(this.filters, { sampleId: '' });\n this.fetchColorsData({ reset: true });\n }\n\n render() {\n return (\n <div class={`my-modal`} onMouseEnter={() => this.handleReadyToClose(false)} onMouseLeave={() => this.handleReadyToClose(true)}>\n {this.preloader && (\n <div class={'loader'}>\n <my-loader></my-loader>\n </div>\n )}\n {!this.preloader && this.data && (\n <modal-header\n modalName={this.data.modalName}\n modalLogo={this.data.modalLogo ? `${APIURL}/assets/${this.data.modalLogo}?access_token=${accessToken}` : null}\n modalDescription={this.data.modalDescription}\n shop={this.shop}\n productName={this.data.name}\n productSamples={this.data.productSamples}\n selectedColorFamily={this.filters.colorFamily}\n isMobile={this.isMobile}\n onCloseModal={() => this.closeModalHandler()}\n onSampleSelected={event => this.handleSampleSelect(event.detail)}\n onOnLogoClick={() => this.resetAllFilters()}\n onOnResetCategory={() => this.resetSelectedCategory()}\n ></modal-header>\n )}\n\n <div class={'my-modal__wrapper'}>\n {!this.preloader && (\n <div class={'container_boxes'}>\n {!this.loading && this.colorsList.length === 0 && (\n <div class=\"not-found\">\n <p>Nie zaleziono wyników wyszukiwania pod danym hasłem.</p>\n <p> Wpisz inną nazwę bądź numer koloru lub skorzystaj z kolekcji kolorystycznych.</p>\n </div>\n )}\n {this.colorsList?.length > 0 &&\n this.chunks(this.colorsList).map((color: Color[], index: number) => {\n return (\n <div key={index} class=\"boxes\">\n <div class=\"boxes__list\">\n {color.map((c: Color) => (\n <my-colorbox\n key={c.id}\n onClick={() => {\n if (this.currentColor?.id === c.id) {\n this.currentColor = null;\n } else {\n this.currentColor = c;\n }\n this.currentIndex = index;\n setDataLayer({\n event: 'ColorClick',\n shop: this.shop,\n product: this.product,\n color: c.name,\n });\n this.clearInterval();\n }}\n color={c.hex}\n name={c.name}\n isActive={this.currentColor?.id === c.id}\n shop={this.shop}\n product={this.product}\n isImageInsteadHex={{\n isImageInsteadHex: c.imageInsteadHex,\n bigImage: c.bigImage,\n }}\n ></my-colorbox>\n ))}\n </div>\n\n {this.currentColor?.id && index === this.currentIndex && (\n <my-colorinfo\n currentColor={this.currentColor}\n shop={this.shop}\n product={this.product}\n data={this.data}\n isMobile={this.isMobile}\n infoBoxWidth={this.infoBoxWidth}\n baselink={this.baselink}\n ></my-colorinfo>\n )}\n </div>\n );\n })}\n </div>\n )}\n {this.loading && <my-loader></my-loader>}\n </div>\n {!this.preloader && this.isMobile && (\n <button class=\"button\" onClick={() => this.closeModalHandler()}>\n Zamknij\n </button>\n )}\n </div>\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/modal/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC/G,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,MAAM,MAAM,WAAW,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Method, Element, Prop, Event, EventEmitter, h, State, Listen, Watch } from '@stencil/core';\nimport { APIURL, accessToken } from '../api';\nimport { setDataLayer } from '../../gtmUtils';\nimport { Color, Product } from '../../types';\nimport { fetchColors, fetchProductData, limit, updateFilters } from '../api/services';\nimport { debounce } from '../../utils';\nimport chroma from 'chroma-js';\n\ndeclare global {\n interface Window {\n dataLayer: Record<string, any>[];\n }\n}\n\n@Component({\n tag: 'my-modal',\n styleUrl: 'index.scss',\n assetsDirs: ['assets'],\n})\nexport class Modal {\n private boxDesktopWidth = 130;\n private boxMobileWidth = 70;\n private desktopPadding = 75;\n private mobilePadding = 35;\n private mediumBreakpoint = 1024;\n private colorTimerInterval: ReturnType<typeof setInterval> | undefined;\n\n @Event({ bubbles: true, composed: true }) onSelectedColorEmit: EventEmitter<Color>;\n\n @Event({ bubbles: true, composed: true }) clearSearchText: EventEmitter;\n @Element() modalEl: HTMLElement;\n\n @Prop() shop: string;\n @Prop() product: string;\n @Prop() baselink: string;\n @Prop() selectedcolor: string | null;\n @Prop() arrowDown = 'arrow_down.png';\n\n @State() chunksNum = 12;\n @State() data: Product | null = null;\n @State() preloader = false;\n @State() loading = false;\n @State() currentColor: Color | null = null;\n @State() currentIndex: number | null = null;\n @State() infoBoxWidth: number | null = null;\n @State() boxWidth: number = this.boxDesktopWidth; // box width with gap\n @State() padding: number = this.desktopPadding;\n @State() isMobile: boolean = false;\n @State() showRange: boolean = false;\n @State() colorCategories: string[] | null = null;\n @State() selectedCategory: any = null;\n @State() page = 1;\n @State() colorIsSelected = false;\n @State() colorsList: Color[] = [];\n @State() hasMore = true;\n @State() filters: any = {\n type: 'product' as 'product' | 'sample' | 'number' | 'name' | 'sampleInProduct',\n id: '',\n productId: '',\n page: 1,\n colorNumber: '',\n colorName: '',\n };\n\n debouncedSearchColorsHandler: (event: CustomEvent) => void;\n\n constructor() {\n this.debouncedSearchColorsHandler = debounce(this.searchColor.bind(this), 300);\n }\n\n @Watch('chunksNum')\n setInfoBoxWidth(newValue: number) {\n this.infoBoxWidth = newValue * this.boxWidth;\n }\n\n @Watch('data')\n watchPropHandler(newValue: Product) {\n if (newValue) {\n this.filters = updateFilters(this.filters, { id: newValue.id, type: 'product' });\n this.fetchColorsData();\n }\n }\n\n private clearInterval = () => {\n this.colorTimerInterval && clearInterval(this.colorTimerInterval);\n this.colorTimerInterval = undefined;\n };\n\n private colorTimer = () => {\n if (this.currentColor && this.currentColor.id) {\n this.colorTimerInterval = setInterval(() => {\n this.currentColor?.name &&\n setDataLayer({\n event: 'ColorTimer',\n shop: this.shop,\n product: this.product,\n color: this.currentColor?.name,\n timer: '10',\n });\n }, 10000);\n } else {\n this.clearInterval();\n }\n };\n\n @Method()\n async open() {\n this.modalEl.style.display = 'block';\n }\n @Event() close: EventEmitter;\n closeModalHandler() {\n this.close.emit();\n }\n\n @Event() readyToCLose: EventEmitter;\n handleReadyToClose(value: boolean) {\n this.readyToCLose.emit({ observable: value });\n }\n\n @Listen('closeInfoBox')\n closeInfoBoxHandler() {\n this.currentColor = null;\n this.currentIndex = null;\n }\n\n @Listen('onCurrentColor')\n handleEmitColor(event: CustomEvent<Color>) {\n this.onSelectedColorEmit.emit(event.detail);\n }\n\n private chunks = (xs: Color[], y: Color[][] = []): Color[][] => {\n return xs?.length === 0 ? y : this.chunks(xs?.slice(this.chunksNum), y.concat([xs?.slice(0, this.chunksNum)]));\n };\n\n private calculateBoxCount = () => {\n const modalWidth = this.modalEl.children && this.modalEl.children[0] && this.modalEl.children[0]?.clientWidth - this.padding;\n const boxWidth = this.boxWidth;\n\n const calc = Math.floor(modalWidth / boxWidth);\n\n const boxesCount = calc;\n\n if (!this.preloader) this.chunksNum = boxesCount;\n };\n\n private displayForMobile = () => {\n if (window.innerWidth < this.mediumBreakpoint) {\n this.boxWidth = this.boxMobileWidth;\n this.padding = this.mobilePadding;\n this.isMobile = true;\n } else {\n this.isMobile = false;\n this.boxWidth = this.boxDesktopWidth;\n this.padding = this.desktopPadding;\n }\n };\n\n @Listen('resize', { target: 'window' })\n handleResize() {\n this.calculateBoxCount();\n this.displayForMobile();\n }\n\n private sortColorsBySimilarity(colors: Color[]): Color[] {\n if (colors?.length <= 1) return colors;\n\n const sortedColors: Color[] = [];\n const remainingColors = [...colors];\n\n // Start with the first color\n sortedColors.push(remainingColors.shift()!);\n\n while (remainingColors?.length > 0) {\n // Find the most similar color to the last color in sortedColors\n const lastColor = sortedColors[sortedColors?.length - 1];\n let mostSimilarIndex = 0;\n let minDistance = Infinity;\n\n remainingColors.forEach((color, index) => {\n try {\n // Validate hex colors before calculating distance\n if (!color.hex || !lastColor.hex) {\n return;\n }\n\n const distance = chroma.distance(lastColor.hex, color.hex, 'lab');\n if (distance < minDistance) {\n minDistance = distance;\n mostSimilarIndex = index;\n }\n } catch (error) {\n console.warn(`Error calculating color distance for ${color.hex}:`, error);\n // Skip this color if it causes an error\n }\n });\n\n // Move the most similar color to sortedColors\n sortedColors.push(remainingColors.splice(mostSimilarIndex, 1)[0]);\n }\n\n return sortedColors;\n }\n\n private getColorHueGroup(hex: string): string {\n try {\n // Validate hex format and handle invalid colors\n if (!hex || typeof hex !== 'string') {\n return 'other';\n }\n\n // Basic hex validation\n const cleanHex = hex.startsWith('#') ? hex : `#${hex}`;\n if (!/^#[0-9A-Fa-f]{6}$/.test(cleanHex)) {\n console.warn(`Invalid hex color format: ${hex}`);\n return 'other';\n }\n\n const color = chroma(cleanHex);\n const hue = color.get('hsl.h');\n const saturation = color.get('hsl.s');\n const lightness = color.get('hsl.l');\n\n // Handle grayscale colors\n if (saturation < 0.1) {\n if (lightness < 0.2) return 'black';\n if (lightness > 0.8) return 'white';\n return 'gray';\n }\n\n // Group colors by hue ranges\n if (hue >= 330 || hue < 30) return 'red';\n if (hue >= 30 && hue < 90) return 'yellow';\n if (hue >= 90 && hue < 150) return 'green';\n if (hue >= 150 && hue < 210) return 'cyan';\n if (hue >= 210 && hue < 270) return 'blue';\n if (hue >= 270 && hue < 330) return 'magenta';\n\n return 'other';\n } catch (error) {\n console.warn(`Error parsing color \"${hex}\":`, error);\n return 'other';\n }\n }\n\n private sortColorsByHueAndSimilarity(colors: Color[]): Color[] {\n if (colors?.length <= 1) return colors;\n\n // Filter out colors with invalid hex values\n const validColors = colors.filter(color => {\n if (!color.hex || typeof color.hex !== 'string') {\n console.warn(`Color missing hex value:`, color);\n return false;\n }\n\n const cleanHex = color.hex.startsWith('#') ? color.hex : `#${color.hex}`;\n const isValid = /^#[0-9A-Fa-f]{6}$/.test(cleanHex);\n\n if (!isValid) {\n console.warn(`Invalid hex color format: ${color.hex} for color:`, color);\n }\n\n return isValid;\n });\n\n // Group valid colors by their hue family\n const colorGroups: Record<string, Color[]> = {\n red: [],\n yellow: [],\n green: [],\n cyan: [],\n blue: [],\n magenta: [],\n gray: [],\n black: [],\n white: [],\n other: [],\n };\n\n validColors.forEach(color => {\n const group = this.getColorHueGroup(color.hex);\n colorGroups[group].push(color);\n });\n\n // Sort each group by similarity\n const sortedGroups: Color[][] = [];\n const groupOrder = ['red', 'magenta', 'blue', 'cyan', 'green', 'yellow', 'gray', 'black', 'white', 'other'];\n\n groupOrder.forEach(groupName => {\n if (colorGroups[groupName].length > 0) {\n sortedGroups.push(this.sortColorsBySimilarity(colorGroups[groupName]));\n }\n });\n\n // Combine all sorted groups\n return sortedGroups.flat();\n }\n\n private async fetchColorsData({ reset = false } = {}) {\n if (this.loading && !reset) return;\n this.loading = true;\n\n try {\n const colors = await fetchColors(this.filters);\n\n if (reset) {\n // For new searches, sort all colors by hue and similarity\n this.colorsList = this.sortColorsByHueAndSimilarity(colors);\n } else {\n // For pagination, combine and sort all colors\n this.colorsList = this.sortColorsByHueAndSimilarity([...this.colorsList, ...colors]);\n }\n\n this.hasMore = colors.length >= limit;\n } catch (error) {\n console.error('Error fetching colors:', error);\n } finally {\n this.loading = false;\n }\n }\n\n private async loadProductData() {\n this.preloader = true;\n\n const product = await fetchProductData({ shopName: this.shop, productName: this.product });\n\n if (product) {\n this.data = product;\n this.filters = updateFilters(this.filters, { type: 'product', id: product.id });\n\n // Fetch initial colors\n await this.fetchColorsData();\n }\n\n this.preloader = false;\n }\n\n private async loadMoreColors() {\n if (this.loading || !this.hasMore) return; // Prevent spam loading\n\n this.filters = { ...this.filters, page: this.filters.page + 1 }; // Increase page for lazy loading\n\n await this.fetchColorsData({ reset: false }); // Append results\n }\n\n private updateFilterAndFetch(newFilters: Partial<typeof this.filters>) {\n if (!this.data?.id) return;\n\n this.loading = true;\n\n this.filters = updateFilters(this.filters, {\n id: this.data.id,\n sampleId: this.filters.sampleId,\n colorName: this.filters.colorName,\n ...newFilters,\n page: 1,\n });\n\n this.fetchColorsData({ reset: true }).finally(() => {\n this.loading = false;\n });\n }\n\n async searchColor(event: CustomEvent) {\n const query = event.detail?.trim();\n\n this.updateFilterAndFetch({ colorName: query });\n }\n\n @Listen('colorFamilySelected')\n handleColorFamilySelected(event: CustomEvent) {\n this.currentColor = null;\n if (event.detail === this.filters.colorFamily) {\n this.filters = updateFilters(this.filters, { colorFamily: '' });\n this.updateFilterAndFetch({ colorFamily: '' });\n } else {\n this.filters = updateFilters(this.filters, { colorFamily: event.detail });\n this.updateFilterAndFetch({ colorFamily: event.detail });\n }\n }\n\n @Listen('searchColors')\n searchColorsHandler(event: CustomEvent) {\n this.loading = true;\n this.currentColor = null;\n this.debouncedSearchColorsHandler(event);\n }\n\n private handleSampleSelect = (selectedSample?: any) => {\n this.currentColor = null;\n this.selectedCategory = selectedSample.value;\n\n this.updateFilterAndFetch({ sampleId: selectedSample.value, colorFamily: '' });\n };\n\n handleScroll(_event: Event, modalContent: HTMLElement) {\n if (this.loading || !this.hasMore) return;\n\n const scrollTop = modalContent.scrollTop;\n const scrollHeight = modalContent.scrollHeight;\n const clientHeight = modalContent.clientHeight;\n\n // Check if user scrolled to the bottom of the modal\n if (scrollTop + clientHeight >= scrollHeight - 50) {\n this.loadMoreColors();\n }\n }\n\n private openSeletedColor() {\n if (!this.colorsList || !this.selectedcolor) return;\n\n if (!this.colorIsSelected) {\n const result = this.chunks(this.colorsList)\n .map((innerArray, arrayIndex) => {\n const foundColor = innerArray.find(color => color.name.trim()?.toUpperCase() === this.selectedcolor?.trim()?.toUpperCase());\n\n return foundColor ? { color: foundColor, index: arrayIndex } : null;\n })\n .filter(item => item !== null);\n\n this.currentColor = result[0]?.color as any;\n this.currentIndex = result[0]?.index as any;\n this.colorIsSelected = true;\n }\n }\n\n componentWillLoad() {\n this.preloader = true;\n setDataLayer({\n shop: this.shop,\n product: this.product,\n });\n\n this.loadProductData();\n }\n\n componentWillRender() {\n this.displayForMobile();\n this.calculateBoxCount();\n this.colorTimer();\n this.openSeletedColor();\n\n const modalContent = this.modalEl.querySelector('.my-modal') as HTMLElement;\n if (modalContent) {\n modalContent.addEventListener('scroll', event => this.handleScroll(event, modalContent));\n }\n }\n\n private resetColors() {\n this.currentColor = null;\n this.currentIndex = null;\n this.colorIsSelected = false;\n }\n\n private resetAllFilters() {\n // Reset current color selection\n this.resetColors();\n\n // Reset filters to initial state\n this.filters = {\n type: 'product',\n id: this.data?.id || '',\n productId: '',\n page: 1,\n colorNumber: '',\n colorName: '',\n colorFamily: '',\n sampleId: '',\n };\n\n // Reset selected category\n this.selectedCategory = null;\n\n // Clear search text\n this.clearSearchText.emit();\n\n // Fetch colors with reset filters\n this.fetchColorsData({ reset: true });\n }\n\n private resetSelectedCategory() {\n this.resetColors();\n this.colorIsSelected = false;\n this.selectedCategory = null;\n this.filters = updateFilters(this.filters, { sampleId: '' });\n this.fetchColorsData({ reset: true });\n }\n\n render() {\n return (\n <div class={`my-modal`} onMouseEnter={() => this.handleReadyToClose(false)} onMouseLeave={() => this.handleReadyToClose(true)}>\n {this.preloader && (\n <div class={'loader'}>\n <my-loader></my-loader>\n </div>\n )}\n {!this.preloader && this.data && (\n <modal-header\n modalName={this.data.modalName}\n modalLogo={this.data.modalLogo ? `${APIURL}/assets/${this.data.modalLogo}?access_token=${accessToken}` : null}\n modalDescription={this.data.modalDescription}\n shop={this.shop}\n productName={this.data.name}\n productSamples={this.data.productSamples}\n selectedColorFamily={this.filters.colorFamily}\n isMobile={this.isMobile}\n onCloseModal={() => this.closeModalHandler()}\n onSampleSelected={event => this.handleSampleSelect(event.detail)}\n onOnLogoClick={() => this.resetAllFilters()}\n onOnResetCategory={() => this.resetSelectedCategory()}\n ></modal-header>\n )}\n\n <div class={'my-modal__wrapper'}>\n {!this.preloader && (\n <div class={'container_boxes'}>\n {!this.loading && this.colorsList.length === 0 && (\n <div class=\"not-found\">\n <p>Nie zaleziono wyników wyszukiwania pod danym hasłem.</p>\n <p> Wpisz inną nazwę bądź numer koloru lub skorzystaj z kolekcji kolorystycznych.</p>\n </div>\n )}\n {this.colorsList?.length > 0 &&\n this.chunks(this.colorsList).map((color: Color[], index: number) => {\n return (\n <div key={index} class=\"boxes\">\n <div class=\"boxes__list\">\n {color.map((c: Color) => (\n <my-colorbox\n key={c.id}\n onClick={() => {\n if (this.currentColor?.id === c.id) {\n this.currentColor = null;\n } else {\n this.currentColor = c;\n }\n this.currentIndex = index;\n setDataLayer({\n event: 'ColorClick',\n shop: this.shop,\n product: this.product,\n color: c.name,\n });\n this.clearInterval();\n }}\n color={c.hex}\n name={c.name}\n isActive={this.currentColor?.id === c.id}\n shop={this.shop}\n product={this.product}\n isImageInsteadHex={{\n isImageInsteadHex: c.imageInsteadHex,\n bigImage: c.bigImage,\n }}\n ></my-colorbox>\n ))}\n </div>\n\n {this.currentColor?.id && index === this.currentIndex && (\n <my-colorinfo\n currentColor={this.currentColor}\n shop={this.shop}\n product={this.product}\n data={this.data}\n isMobile={this.isMobile}\n infoBoxWidth={this.infoBoxWidth}\n baselink={this.baselink}\n ></my-colorinfo>\n )}\n </div>\n );\n })}\n </div>\n )}\n {this.loading && <my-loader></my-loader>}\n </div>\n {!this.preloader && this.isMobile && (\n <button class=\"button\" onClick={() => this.closeModalHandler()}>\n Zamknij\n </button>\n )}\n </div>\n );\n }\n}\n"]}
|
|
@@ -3610,10 +3610,20 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
3610
3610
|
let mostSimilarIndex = 0;
|
|
3611
3611
|
let minDistance = Infinity;
|
|
3612
3612
|
remainingColors.forEach((color, index) => {
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3613
|
+
try {
|
|
3614
|
+
// Validate hex colors before calculating distance
|
|
3615
|
+
if (!color.hex || !lastColor.hex) {
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3618
|
+
const distance = chroma.distance(lastColor.hex, color.hex, 'lab');
|
|
3619
|
+
if (distance < minDistance) {
|
|
3620
|
+
minDistance = distance;
|
|
3621
|
+
mostSimilarIndex = index;
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
catch (error) {
|
|
3625
|
+
console.warn(`Error calculating color distance for ${color.hex}:`, error);
|
|
3626
|
+
// Skip this color if it causes an error
|
|
3617
3627
|
}
|
|
3618
3628
|
});
|
|
3619
3629
|
// Move the most similar color to sortedColors
|
|
@@ -3622,36 +3632,65 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
3622
3632
|
return sortedColors;
|
|
3623
3633
|
}
|
|
3624
3634
|
getColorHueGroup(hex) {
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
return '
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3635
|
+
try {
|
|
3636
|
+
// Validate hex format and handle invalid colors
|
|
3637
|
+
if (!hex || typeof hex !== 'string') {
|
|
3638
|
+
return 'other';
|
|
3639
|
+
}
|
|
3640
|
+
// Basic hex validation
|
|
3641
|
+
const cleanHex = hex.startsWith('#') ? hex : `#${hex}`;
|
|
3642
|
+
if (!/^#[0-9A-Fa-f]{6}$/.test(cleanHex)) {
|
|
3643
|
+
console.warn(`Invalid hex color format: ${hex}`);
|
|
3644
|
+
return 'other';
|
|
3645
|
+
}
|
|
3646
|
+
const color = chroma(cleanHex);
|
|
3647
|
+
const hue = color.get('hsl.h');
|
|
3648
|
+
const saturation = color.get('hsl.s');
|
|
3649
|
+
const lightness = color.get('hsl.l');
|
|
3650
|
+
// Handle grayscale colors
|
|
3651
|
+
if (saturation < 0.1) {
|
|
3652
|
+
if (lightness < 0.2)
|
|
3653
|
+
return 'black';
|
|
3654
|
+
if (lightness > 0.8)
|
|
3655
|
+
return 'white';
|
|
3656
|
+
return 'gray';
|
|
3657
|
+
}
|
|
3658
|
+
// Group colors by hue ranges
|
|
3659
|
+
if (hue >= 330 || hue < 30)
|
|
3660
|
+
return 'red';
|
|
3661
|
+
if (hue >= 30 && hue < 90)
|
|
3662
|
+
return 'yellow';
|
|
3663
|
+
if (hue >= 90 && hue < 150)
|
|
3664
|
+
return 'green';
|
|
3665
|
+
if (hue >= 150 && hue < 210)
|
|
3666
|
+
return 'cyan';
|
|
3667
|
+
if (hue >= 210 && hue < 270)
|
|
3668
|
+
return 'blue';
|
|
3669
|
+
if (hue >= 270 && hue < 330)
|
|
3670
|
+
return 'magenta';
|
|
3671
|
+
return 'other';
|
|
3672
|
+
}
|
|
3673
|
+
catch (error) {
|
|
3674
|
+
console.warn(`Error parsing color "${hex}":`, error);
|
|
3675
|
+
return 'other';
|
|
3676
|
+
}
|
|
3651
3677
|
}
|
|
3652
3678
|
sortColorsByHueAndSimilarity(colors) {
|
|
3653
3679
|
if ((colors === null || colors === void 0 ? void 0 : colors.length) <= 1)
|
|
3654
3680
|
return colors;
|
|
3681
|
+
// Filter out colors with invalid hex values
|
|
3682
|
+
const validColors = colors.filter(color => {
|
|
3683
|
+
if (!color.hex || typeof color.hex !== 'string') {
|
|
3684
|
+
console.warn(`Color missing hex value:`, color);
|
|
3685
|
+
return false;
|
|
3686
|
+
}
|
|
3687
|
+
const cleanHex = color.hex.startsWith('#') ? color.hex : `#${color.hex}`;
|
|
3688
|
+
const isValid = /^#[0-9A-Fa-f]{6}$/.test(cleanHex);
|
|
3689
|
+
if (!isValid) {
|
|
3690
|
+
console.warn(`Invalid hex color format: ${color.hex} for color:`, color);
|
|
3691
|
+
}
|
|
3692
|
+
return isValid;
|
|
3693
|
+
});
|
|
3655
3694
|
// Group valid colors by their hue family
|
|
3656
3695
|
const colorGroups = {
|
|
3657
3696
|
red: [],
|
|
@@ -3665,7 +3704,7 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
3665
3704
|
white: [],
|
|
3666
3705
|
other: [],
|
|
3667
3706
|
};
|
|
3668
|
-
|
|
3707
|
+
validColors.forEach(color => {
|
|
3669
3708
|
const group = this.getColorHueGroup(color.hex);
|
|
3670
3709
|
colorGroups[group].push(color);
|
|
3671
3710
|
});
|
|
@@ -3677,7 +3716,7 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
|
3677
3716
|
sortedGroups.push(this.sortColorsBySimilarity(colorGroups[groupName]));
|
|
3678
3717
|
}
|
|
3679
3718
|
});
|
|
3680
|
-
// Combine all sorted groups
|
|
3719
|
+
// Combine all sorted groups
|
|
3681
3720
|
return sortedGroups.flat();
|
|
3682
3721
|
}
|
|
3683
3722
|
async fetchColorsData({ reset = false } = {}) {
|