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'
99 type LayoutNode ,
1010 type LayoutNodeInfo ,
1111} from '@/lib/treemap-layout'
12+ import { SpecialModule } from '@/lib/types'
1213
1314interface TreemapVisualizerProps {
1415 analyzeData : AnalyzeData
@@ -23,6 +24,8 @@ interface TreemapVisualizerProps {
2324 onHoveredNodeChangeDelayed ?: ( nodeInfo : LayoutNodeInfo | null ) => void
2425 searchQuery ?: string
2526 filterSource ?: ( sourceIndex : number ) => boolean
27+ isModulePolyfillChunk ?: ( sourceIndex : number ) => boolean
28+ isNoModulePolyfillChunk ?: ( sourceIndex : number ) => boolean
2629}
2730
2831function getFileColor ( node : {
@@ -33,8 +36,13 @@ function getFileColor(node: {
3336 server ?: boolean
3437 client ?: boolean
3538 traced ?: boolean
39+ specialModuleType : SpecialModule | null
3640} ) : string {
37- const { js, css, json, asset, client, traced } = node
41+ const { js, css, json, asset, client, traced, specialModuleType } = node
42+
43+ if ( isPolyfill ( specialModuleType ) ) {
44+ return '#DE2670'
45+ }
3846
3947 let color = '#9ca3af' // gray-400 default
4048 if ( js ) color = '#0068d6'
@@ -54,6 +62,13 @@ function getFileColor(node: {
5462 return color
5563}
5664
65+ function isPolyfill ( specialModuleType : SpecialModule | null ) : boolean {
66+ return (
67+ specialModuleType === SpecialModule . POLYFILL_MODULE ||
68+ specialModuleType === SpecialModule . POLYFILL_NOMODULE
69+ )
70+ }
71+
5772function findNodeAtPosition (
5873 node : LayoutNode ,
5974 x : number ,
@@ -320,7 +335,8 @@ function drawTreemap(
320335 ctx . strokeRect ( rect . x , rect . y , rect . width , rect . height )
321336
322337 if ( rect . width > 60 && rect . height > 30 ) {
323- ctx . fillStyle = colors . text
338+ const textColor = readableColor ( color )
339+ ctx . fillStyle = textColor
324340 ctx . font = '12px sans-serif'
325341 ctx . textAlign = 'center'
326342 ctx . textBaseline = 'middle'
@@ -516,6 +532,7 @@ function wrapLayoutWithAncestorsUsingIndices(
516532 titleBarHeight : titleBarHeight ,
517533 children : [ currentNode ] ,
518534 sourceIndex : ancestorIndex ,
535+ specialModuleType : null ,
519536 }
520537
521538 currentNode = ancestorNode
@@ -539,6 +556,7 @@ function wrapLayoutWithAncestorsUsingIndices(
539556 titleBarHeight : minTitleBarHeight ,
540557 children : [ currentNode ] ,
541558 sourceIndex : rootIndex ,
559+ specialModuleType : null ,
542560 }
543561
544562 return rootNode
0 commit comments