11'use client'
22
3- import { darken , lighten } from 'polished'
3+ import { darken , lighten , readableColor } from 'polished'
44import type React from 'react'
55import { useEffect , useMemo , useRef , useState } from 'react'
66import type { AnalyzeData } from '@/lib/analyze-data'
@@ -23,6 +23,8 @@ interface TreemapVisualizerProps {
2323 onHoveredNodeChangeDelayed ?: ( nodeInfo : LayoutNodeInfo | null ) => void
2424 searchQuery ?: string
2525 filterSource ?: ( sourceIndex : number ) => boolean
26+ isModulePolyfillChunk ?: ( sourceIndex : number ) => boolean
27+ isNoModulePolyfillChunk ?: ( sourceIndex : number ) => boolean
2628}
2729
2830function getFileColor ( node : {
@@ -184,6 +186,8 @@ function drawTreemap(
184186 searchQuery : string ,
185187 originalData : LayoutNode ,
186188 immediateHoveredSourceIndex : number | undefined ,
189+ isModulePolyfillChunk : ( sourceIndex : number ) => boolean ,
190+ isNoModuePolyfillChunk : ( sourceIndex : number ) => boolean ,
187191 currentPath : string [ ] = [ ] ,
188192 parentFadedOut = false ,
189193 insideActiveSubtree = false
@@ -241,6 +245,8 @@ function drawTreemap(
241245 searchQuery ,
242246 originalData ,
243247 immediateHoveredSourceIndex ,
248+ isModulePolyfillChunk ,
249+ isNoModuePolyfillChunk ,
244250 path ,
245251 parentFadedOut ,
246252 insideActiveSubtree
@@ -305,6 +311,13 @@ function drawTreemap(
305311
306312 if ( type === 'file' ) {
307313 let color = getFileColor ( node )
314+ const isPolyfill =
315+ sourceIndex !== undefined &&
316+ ( isModulePolyfillChunk ( sourceIndex ) ||
317+ isNoModuePolyfillChunk ( sourceIndex ) )
318+ if ( isPolyfill ) {
319+ color = '#DE2670'
320+ }
308321
309322 // Apply brightness boost to immediately hovered node
310323 if ( isImmediateHovered ) {
@@ -320,7 +333,9 @@ function drawTreemap(
320333 ctx . strokeRect ( rect . x , rect . y , rect . width , rect . height )
321334
322335 if ( rect . width > 60 && rect . height > 30 ) {
323- ctx . fillStyle = colors . text
336+ // Use readableColor to ensure good contrast against the background
337+ const textColor = isPolyfill ? readableColor ( color ) : colors . text
338+ ctx . fillStyle = textColor
324339 ctx . font = '12px sans-serif'
325340 ctx . textAlign = 'center'
326341 ctx . textBaseline = 'middle'
@@ -467,6 +482,8 @@ function drawTreemap(
467482 searchQuery ,
468483 originalData ,
469484 immediateHoveredSourceIndex ,
485+ isModulePolyfillChunk ,
486+ isNoModuePolyfillChunk ,
470487 path ,
471488 childFadeOut ,
472489 childInsideActiveSubtree
@@ -556,6 +573,8 @@ export function TreemapVisualizer({
556573 onHoveredNodeChangeDelayed,
557574 searchQuery = '' ,
558575 filterSource,
576+ isModulePolyfillChunk = ( ) => false ,
577+ isNoModulePolyfillChunk = ( ) => false ,
559578} : TreemapVisualizerProps ) {
560579 const canvasRef = useRef < HTMLCanvasElement > ( null )
561580 const containerRef = useRef < HTMLDivElement > ( null )
@@ -707,7 +726,9 @@ export function TreemapVisualizer({
707726 focusedAncestorChain ,
708727 searchQuery ,
709728 layout ,
710- hoveredNode ?. sourceIndex
729+ hoveredNode ?. sourceIndex ,
730+ isModulePolyfillChunk ,
731+ isNoModulePolyfillChunk
711732 )
712733 } , [
713734 layout ,
@@ -719,6 +740,8 @@ export function TreemapVisualizer({
719740 focusedAncestorChain ,
720741 searchQuery ,
721742 hoveredNode ,
743+ isModulePolyfillChunk ,
744+ isNoModulePolyfillChunk ,
722745 ] )
723746
724747 const handleClick = ( e : React . MouseEvent < HTMLCanvasElement > ) => {
0 commit comments