@ppg_pl/tinting 0.0.2 → 0.0.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.
@@ -148,8 +148,6 @@ export class Modal {
148
148
  return sortedColors;
149
149
  }
150
150
  getColorHueGroup(hex) {
151
- if (!hex || !chroma.valid(hex))
152
- return 'other';
153
151
  const color = chroma(hex);
154
152
  const hue = color.get('hsl.h');
155
153
  const saturation = color.get('hsl.s');
@@ -180,9 +178,6 @@ export class Modal {
180
178
  sortColorsByHueAndSimilarity(colors) {
181
179
  if ((colors === null || colors === void 0 ? void 0 : colors.length) <= 1)
182
180
  return colors;
183
- // Separate valid and invalid hex colors
184
- const validColors = colors.filter(c => typeof c.hex === 'string' && c.hex && chroma.valid(c.hex));
185
- const invalidColors = colors.filter(c => !c.hex || !chroma.valid(c.hex));
186
181
  // Group valid colors by their hue family
187
182
  const colorGroups = {
188
183
  red: [],
@@ -196,7 +191,7 @@ export class Modal {
196
191
  white: [],
197
192
  other: [],
198
193
  };
199
- validColors.forEach(color => {
194
+ colors.forEach(color => {
200
195
  const group = this.getColorHueGroup(color.hex);
201
196
  colorGroups[group].push(color);
202
197
  });
@@ -209,10 +204,10 @@ export class Modal {
209
204
  }
210
205
  });
211
206
  // Combine all sorted groups, then append invalid colors at the end
212
- return [...sortedGroups.flat(), ...invalidColors];
207
+ return sortedGroups.flat();
213
208
  }
214
209
  async fetchColorsData({ reset = false } = {}) {
215
- if (this.loading)
210
+ if (this.loading && !reset)
216
211
  return;
217
212
  this.loading = true;
218
213
  try {
@@ -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,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC/G,OAAO,EAAE,MAAM,E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,CACjB,CACG,CACP,CAAC;YACJ,CAAC,CAAC,CACA,CACP;QACA,IAAI,CAAC,OAAO,IAAI,oBAAuB,CACpC;MACL,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,QAAQ,IAAI,CACnC,cAAQ,KAAK,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,cAErD,CACV,CACG,CACP,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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 if (!hex || !chroma.valid(hex)) return 'other';\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 // Separate valid and invalid hex colors\n const validColors = colors.filter(c => typeof c.hex === 'string' && c.hex && chroma.valid(c.hex));\n const invalidColors = colors.filter(c => !c.hex || !chroma.valid(c.hex));\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, then append invalid colors at the end\n return [...sortedGroups.flat(), ...invalidColors];\n }\n\n private async fetchColorsData({ reset = false } = {}) {\n if (this.loading) 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,CAAC;AAa/B,MAAM,OAAO,KAAK;EA+ChB;IA9CQ,oBAAe,GAAG,GAAG,CAAC;IACtB,mBAAc,GAAG,EAAE,CAAC;IACpB,mBAAc,GAAG,EAAE,CAAC;IACpB,kBAAa,GAAG,EAAE,CAAC;IACnB,qBAAgB,GAAG,IAAI,CAAC;IA2DxB,kBAAa,GAAG,GAAG,EAAE;MAC3B,IAAI,CAAC,kBAAkB,IAAI,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;MAClE,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;IACtC,CAAC,CAAC;IAEM,eAAU,GAAG,GAAG,EAAE;MACxB,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,EAAE,EAAE;QAC7C,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE;;UACzC,CAAA,MAAA,IAAI,CAAC,YAAY,0CAAE,IAAI;YACrB,YAAY,CAAC;cACX,KAAK,EAAE,YAAY;cACnB,IAAI,EAA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,KAAK,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,cAErD,CACV,CACG,CACP,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"]}
@@ -3622,8 +3622,6 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
3622
3622
  return sortedColors;
3623
3623
  }
3624
3624
  getColorHueGroup(hex) {
3625
- if (!hex || !chroma.valid(hex))
3626
- return 'other';
3627
3625
  const color = chroma(hex);
3628
3626
  const hue = color.get('hsl.h');
3629
3627
  const saturation = color.get('hsl.s');
@@ -3654,9 +3652,6 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
3654
3652
  sortColorsByHueAndSimilarity(colors) {
3655
3653
  if ((colors === null || colors === void 0 ? void 0 : colors.length) <= 1)
3656
3654
  return colors;
3657
- // Separate valid and invalid hex colors
3658
- const validColors = colors.filter(c => typeof c.hex === 'string' && c.hex && chroma.valid(c.hex));
3659
- const invalidColors = colors.filter(c => !c.hex || !chroma.valid(c.hex));
3660
3655
  // Group valid colors by their hue family
3661
3656
  const colorGroups = {
3662
3657
  red: [],
@@ -3670,7 +3665,7 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
3670
3665
  white: [],
3671
3666
  other: [],
3672
3667
  };
3673
- validColors.forEach(color => {
3668
+ colors.forEach(color => {
3674
3669
  const group = this.getColorHueGroup(color.hex);
3675
3670
  colorGroups[group].push(color);
3676
3671
  });
@@ -3683,10 +3678,10 @@ const Modal = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
3683
3678
  }
3684
3679
  });
3685
3680
  // Combine all sorted groups, then append invalid colors at the end
3686
- return [...sortedGroups.flat(), ...invalidColors];
3681
+ return sortedGroups.flat();
3687
3682
  }
3688
3683
  async fetchColorsData({ reset = false } = {}) {
3689
- if (this.loading)
3684
+ if (this.loading && !reset)
3690
3685
  return;
3691
3686
  this.loading = true;
3692
3687
  try {