Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
bc95c4f8
Unverified
Commit
bc95c4f8
authored
Oct 04, 2026
by
Will Binns-Smith
Committed by
GitHub
Oct 04, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unify bundle analyzer delta colors (#99607)
parent
ba80ee48
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
67 deletions
+89
-67
globals.css
apps/bundle-analyzer/app/globals.css
+6
-0
diff-table.tsx
apps/bundle-analyzer/components/diff-table.tsx
+13
-13
diff-treemap.tsx
apps/bundle-analyzer/components/diff-treemap.tsx
+24
-22
route-typeahead.tsx
apps/bundle-analyzer/components/route-typeahead.tsx
+2
-2
sidebar.tsx
apps/bundle-analyzer/components/sidebar.tsx
+2
-2
stat-cards.tsx
apps/bundle-analyzer/components/stat-cards.tsx
+6
-9
treemap-visualizer.tsx
apps/bundle-analyzer/components/treemap-visualizer.tsx
+36
-19
No files found.
apps/bundle-analyzer/app/globals.css
View file @
bc95c4f8
...
@@ -34,6 +34,8 @@
...
@@ -34,6 +34,8 @@
--sidebar-ring
:
oklch
(
0.708
0
0
);
--sidebar-ring
:
oklch
(
0.708
0
0
);
--polyfill
:
#5f707f
;
--polyfill
:
#5f707f
;
--polyfill-foreground
:
#ffffff
;
--polyfill-foreground
:
#ffffff
;
--delta-increase
:
#2563eb
;
--delta-decrease
:
#b45309
;
}
}
.dark
{
.dark
{
...
@@ -66,6 +68,8 @@
...
@@ -66,6 +68,8 @@
--sidebar-ring
:
oklch
(
0.439
0
0
);
--sidebar-ring
:
oklch
(
0.439
0
0
);
--polyfill
:
#5f707f
;
--polyfill
:
#5f707f
;
--polyfill-foreground
:
#ffffff
;
--polyfill-foreground
:
#ffffff
;
--delta-increase
:
#60a5fa
;
--delta-decrease
:
#fbbf24
;
}
}
@theme
inline
{
@theme
inline
{
...
@@ -104,6 +108,8 @@
...
@@ -104,6 +108,8 @@
--color-sidebar-ring
:
var
(
--sidebar-ring
);
--color-sidebar-ring
:
var
(
--sidebar-ring
);
--color-polyfill
:
var
(
--polyfill
);
--color-polyfill
:
var
(
--polyfill
);
--color-polyfill-foreground
:
var
(
--polyfill-foreground
);
--color-polyfill-foreground
:
var
(
--polyfill-foreground
);
--color-delta-increase
:
var
(
--delta-increase
);
--color-delta-decrease
:
var
(
--delta-decrease
);
}
}
@layer
base
{
@layer
base
{
...
...
apps/bundle-analyzer/components/diff-table.tsx
View file @
bc95c4f8
...
@@ -305,8 +305,8 @@ export function DiffTable<Row extends DiffRow>({
...
@@ -305,8 +305,8 @@ export function DiffTable<Row extends DiffRow>({
<
td
<
td
className=
{
cn
(
className=
{
cn
(
'whitespace-nowrap px-4 py-2 text-right font-mono'
,
'whitespace-nowrap px-4 py-2 text-right font-mono'
,
totalDelta
>
0
&&
'text-
red-600 dark:text-red-400
'
,
totalDelta
>
0
&&
'text-
delta-increase
'
,
totalDelta
<
0
&&
'text-
green-600 dark:text-green-400
'
totalDelta
<
0
&&
'text-
delta-decrease
'
)
}
)
}
>
>
{
formatDelta
(
totalDelta
)
}
{
formatDelta
(
totalDelta
)
}
...
@@ -601,8 +601,8 @@ function DiffPackageHeaderRow<Row extends DiffRow>({
...
@@ -601,8 +601,8 @@ function DiffPackageHeaderRow<Row extends DiffRow>({
<
td
<
td
className=
{
cn
(
className=
{
cn
(
'cursor-pointer whitespace-nowrap border-b border-border bg-muted/30 px-4 py-2 text-right font-mono text-xs transition-colors hover:bg-muted/50'
,
'cursor-pointer whitespace-nowrap border-b border-border bg-muted/30 px-4 py-2 text-right font-mono text-xs transition-colors hover:bg-muted/50'
,
d
>
0
&&
'text-
red-600 dark:text-red-400
'
,
d
>
0
&&
'text-
delta-increase
'
,
d
<
0
&&
'text-
green-600 dark:text-green-400
'
,
d
<
0
&&
'text-
delta-decrease
'
,
d
===
0
&&
'text-muted-foreground'
d
===
0
&&
'text-muted-foreground'
)
}
)
}
onClick=
{
onToggle
}
onClick=
{
onToggle
}
...
@@ -628,17 +628,17 @@ function PackageCountBreakdown({
...
@@ -628,17 +628,17 @@ function PackageCountBreakdown({
{
{
label
:
'added'
,
label
:
'added'
,
value
:
counts
.
added
,
value
:
counts
.
added
,
className
:
'text-
red-600 dark:text-red-400
'
,
className
:
'text-
delta-increase
'
,
},
},
{
{
label
:
'removed'
,
label
:
'removed'
,
value
:
counts
.
removed
,
value
:
counts
.
removed
,
className
:
'text-
green-600 dark:text-green-400
'
,
className
:
'text-
delta-decrease
'
,
},
},
{
{
label
:
'changed'
,
label
:
'changed'
,
value
:
counts
.
changed
,
value
:
counts
.
changed
,
className
:
'text-
amber-500
'
,
className
:
'text-
muted-foreground
'
,
},
},
]
]
const
visible
=
entries
.
filter
((
e
)
=>
e
.
value
>
0
)
const
visible
=
entries
.
filter
((
e
)
=>
e
.
value
>
0
)
...
@@ -851,8 +851,8 @@ function DiffTableRow<Row extends DiffRow>({
...
@@ -851,8 +851,8 @@ function DiffTableRow<Row extends DiffRow>({
className=
{
cn
(
className=
{
cn
(
'whitespace-nowrap px-4 py-2 text-right font-mono text-xs'
,
'whitespace-nowrap px-4 py-2 text-right font-mono text-xs'
,
cellClassName
,
cellClassName
,
d
>
0
&&
'text-
red-600 dark:text-red-400
'
,
d
>
0
&&
'text-
delta-increase
'
,
d
<
0
&&
'text-
green-600 dark:text-green-400
'
,
d
<
0
&&
'text-
delta-decrease
'
,
d
===
0
&&
'text-muted-foreground'
d
===
0
&&
'text-muted-foreground'
)
}
)
}
onClick=
{
onClick
}
onClick=
{
onClick
}
...
@@ -1021,7 +1021,7 @@ function StatusIcon({ status }: { status: DiffStatus }) {
...
@@ -1021,7 +1021,7 @@ function StatusIcon({ status }: { status: DiffStatus }) {
if
(
status
===
'added'
)
{
if
(
status
===
'added'
)
{
return
(
return
(
<
PlusCircle
<
PlusCircle
className=
"h-3.5 w-3.5 shrink-0 text-
red-600 dark:text-red-400
"
className=
"h-3.5 w-3.5 shrink-0 text-
delta-increase
"
aria
-
label=
"Added"
aria
-
label=
"Added"
/>
/>
)
)
...
@@ -1029,15 +1029,15 @@ function StatusIcon({ status }: { status: DiffStatus }) {
...
@@ -1029,15 +1029,15 @@ function StatusIcon({ status }: { status: DiffStatus }) {
if
(
status
===
'removed'
)
{
if
(
status
===
'removed'
)
{
return
(
return
(
<
MinusCircle
<
MinusCircle
className=
"h-3.5 w-3.5 shrink-0 text-
green-600 dark:text-green-400
"
className=
"h-3.5 w-3.5 shrink-0 text-
delta-decrease
"
aria
-
label=
"Removed"
aria
-
label=
"Removed"
/>
/>
)
)
}
}
if
(
status
===
'changed'
)
{
if
(
status
===
'changed'
)
{
return
(
return
(
<
ArrowUp
<
ArrowUp
Down
className=
"h-3.5 w-3.5 shrink-0 text-
amber-500
"
className=
"h-3.5 w-3.5 shrink-0 text-
muted-foreground
"
aria
-
label=
"Changed"
aria
-
label=
"Changed"
/>
/>
)
)
...
...
apps/bundle-analyzer/components/diff-treemap.tsx
View file @
bc95c4f8
'use client'
'use client'
import
{
useMemo
,
useState
}
from
'react'
import
{
useMemo
,
useState
}
from
'react'
import
{
rgba
}
from
'polished'
import
type
{
AnalyzeData
}
from
'@/lib/analyze-data'
import
type
{
AnalyzeData
}
from
'@/lib/analyze-data'
import
type
{
DiffSummary
,
SourceDiffRow
}
from
'@/lib/diff'
import
type
{
DiffSummary
,
SourceDiffRow
}
from
'@/lib/diff'
import
{
delta
,
formatDelta
}
from
'@/lib/diff'
import
{
delta
,
formatDelta
}
from
'@/lib/diff'
import
{
createDiffTreemapLayout
}
from
'@/lib/diff-treemap-layout'
import
{
createDiffTreemapLayout
}
from
'@/lib/diff-treemap-layout'
import
{
SizeMode
,
type
LayoutNode
}
from
'@/lib/treemap-layout'
import
{
SizeMode
,
type
LayoutNode
}
from
'@/lib/treemap-layout'
import
{
TreemapVisualizer
}
from
'@/components/treemap-visualizer'
import
{
TreemapVisualizer
,
/** Color-blind-safe blue/amber palette for bundle-size increases/decreases. */
type
CanvasColors
,
const
COLOR_INCREASE
=
'#2563eb'
// blue-600
}
from
'@/components/treemap-visualizer'
const
COLOR_INCREASE_MUTED
=
'rgba(37, 99, 235, 0.6)'
const
COLOR_DECREASE
=
'#d97706'
// amber-600
const
COLOR_DECREASE_MUTED
=
'rgba(217, 119, 6, 0.6)'
interface
DiffTreemapProps
{
interface
DiffTreemapProps
{
summary
:
DiffSummary
<
SourceDiffRow
>
summary
:
DiffSummary
<
SourceDiffRow
>
...
@@ -68,10 +66,13 @@ export function DiffTreemap({
...
@@ -68,10 +66,13 @@ export function DiffTreemap({
)
)
const
{
rowBySourceIndex
,
sourceIndexByKey
}
=
diffLayout
const
{
rowBySourceIndex
,
sourceIndexByKey
}
=
diffLayout
function
getFileColorOverride
(
node
:
LayoutNode
):
string
|
undefined
{
function
getFileColorOverride
(
node
:
LayoutNode
,
colors
:
CanvasColors
):
string
|
undefined
{
if
(
node
.
sourceIndex
===
undefined
)
return
undefined
if
(
node
.
sourceIndex
===
undefined
)
return
undefined
const
row
=
rowBySourceIndex
.
get
(
node
.
sourceIndex
)
const
row
=
rowBySourceIndex
.
get
(
node
.
sourceIndex
)
return
row
?
colorForRow
(
row
,
useCompressed
)
:
undefined
return
row
?
colorForRow
(
row
,
useCompressed
,
colors
)
:
undefined
}
}
// Show size deltas on changed tiles instead of absolute sizes.
// Show size deltas on changed tiles instead of absolute sizes.
...
@@ -129,9 +130,13 @@ export function DiffTreemap({
...
@@ -129,9 +130,13 @@ export function DiffTreemap({
* scheme: bright blue/amber for added/removed and lighter tints scaled by the
* scheme: bright blue/amber for added/removed and lighter tints scaled by the
* relative magnitude of the change for grew/shrank.
* relative magnitude of the change for grew/shrank.
*/
*/
function
colorForRow
(
row
:
SourceDiffRow
,
useCompressed
:
boolean
):
string
{
function
colorForRow
(
if
(
row
.
status
===
'added'
)
return
COLOR_INCREASE
row
:
SourceDiffRow
,
if
(
row
.
status
===
'removed'
)
return
COLOR_DECREASE
useCompressed
:
boolean
,
colors
:
CanvasColors
):
string
{
if
(
row
.
status
===
'added'
)
return
colors
.
increase
if
(
row
.
status
===
'removed'
)
return
colors
.
decrease
const
deltaValue
=
useCompressed
const
deltaValue
=
useCompressed
?
row
.
compressedB
-
row
.
compressedA
?
row
.
compressedB
-
row
.
compressedA
:
row
.
sizeB
-
row
.
sizeA
:
row
.
sizeB
-
row
.
sizeA
...
@@ -141,18 +146,16 @@ function colorForRow(row: SourceDiffRow, useCompressed: boolean): string {
...
@@ -141,18 +146,16 @@ function colorForRow(row: SourceDiffRow, useCompressed: boolean): string {
const
ratio
=
const
ratio
=
baseline
===
0
?
1
:
Math
.
min
(
1
,
Math
.
abs
(
deltaValue
)
/
baseline
)
baseline
===
0
?
1
:
Math
.
min
(
1
,
Math
.
abs
(
deltaValue
)
/
baseline
)
const
alpha
=
0.35
+
ratio
*
0.5
const
alpha
=
0.35
+
ratio
*
0.5
return
deltaValue
>
0
return
rgba
(
deltaValue
>
0
?
colors
.
increase
:
colors
.
decrease
,
alpha
)
?
`rgba(37, 99, 235,
${
alpha
.
toFixed
(
2
)}
)`
:
`rgba(217, 119, 6,
${
alpha
.
toFixed
(
2
)}
)`
}
}
/** Static legend overlay so users can decode the color scheme at a glance. */
/** Static legend overlay so users can decode the color scheme at a glance. */
function
DiffLegend
()
{
function
DiffLegend
()
{
const
items
:
Array
<
{
label
:
string
;
c
olor
:
string
}
>
=
[
const
items
:
Array
<
{
label
:
string
;
c
lassName
:
string
}
>
=
[
{
label
:
'Added'
,
c
olor
:
COLOR_INCREASE
},
{
label
:
'Added'
,
c
lassName
:
'bg-delta-increase'
},
{
label
:
'Grew'
,
c
olor
:
COLOR_INCREASE_MUTED
},
{
label
:
'Grew'
,
c
lassName
:
'bg-delta-increase/60'
},
{
label
:
'Shrank'
,
c
olor
:
COLOR_DECREASE_MUTED
},
{
label
:
'Shrank'
,
c
lassName
:
'bg-delta-decrease/60'
},
{
label
:
'Removed'
,
c
olor
:
COLOR_DECREASE
},
{
label
:
'Removed'
,
c
lassName
:
'bg-delta-decrease'
},
]
]
return
(
return
(
<
div
className=
"absolute bottom-2 left-2 flex items-center gap-3 rounded border border-border bg-background/90 px-2 py-1 text-xs text-muted-foreground shadow-sm"
>
<
div
className=
"absolute bottom-2 left-2 flex items-center gap-3 rounded border border-border bg-background/90 px-2 py-1 text-xs text-muted-foreground shadow-sm"
>
...
@@ -160,8 +163,7 @@ function DiffLegend() {
...
@@ -160,8 +163,7 @@ function DiffLegend() {
<
span
key=
{
item
.
label
}
className=
"flex items-center gap-1.5"
>
<
span
key=
{
item
.
label
}
className=
"flex items-center gap-1.5"
>
<
span
<
span
aria
-
hidden
aria
-
hidden
className=
"inline-block h-3 w-3 rounded-sm"
className=
{
`inline-block h-3 w-3 rounded-sm ${item.className}`
}
style=
{
{
backgroundColor
:
item
.
color
}
}
/>
/>
{
item
.
label
}
{
item
.
label
}
</
span
>
</
span
>
...
...
apps/bundle-analyzer/components/route-typeahead.tsx
View file @
bc95c4f8
...
@@ -309,9 +309,9 @@ function DeltaBadge({
...
@@ -309,9 +309,9 @@ function DeltaBadge({
const
tone
=
const
tone
=
row
.
status
===
'added'
||
d
>
0
row
.
status
===
'added'
||
d
>
0
?
'text-
red-600 dark:text-red-400
'
?
'text-
delta-increase
'
:
row
.
status
===
'removed'
||
d
<
0
:
row
.
status
===
'removed'
||
d
<
0
?
'text-
green-600 dark:text-green-400
'
?
'text-
delta-decrease
'
:
'text-muted-foreground'
:
'text-muted-foreground'
return
(
return
(
...
...
apps/bundle-analyzer/components/sidebar.tsx
View file @
bc95c4f8
...
@@ -300,8 +300,8 @@ function CompareSidebarContent({
...
@@ -300,8 +300,8 @@ function CompareSidebarContent({
<
span
<
span
className=
{
cn
(
className=
{
cn
(
'font-mono'
,
'font-mono'
,
compressedDelta
>
0
&&
'text-
red-600 dark:text-red-400
'
,
compressedDelta
>
0
&&
'text-
delta-increase
'
,
compressedDelta
<
0
&&
'text-
green-600 dark:text-green-400
'
,
compressedDelta
<
0
&&
'text-
delta-decrease
'
,
compressedDelta
===
0
&&
'text-muted-foreground'
compressedDelta
===
0
&&
'text-muted-foreground'
)
}
)
}
>
>
...
...
apps/bundle-analyzer/components/stat-cards.tsx
View file @
bc95c4f8
...
@@ -2,8 +2,7 @@ import { cn } from '@/lib/utils'
...
@@ -2,8 +2,7 @@ import { cn } from '@/lib/utils'
/**
/**
* Inline colored delta rendered next to the `A → B` value. For size deltas,
* Inline colored delta rendered next to the `A → B` value. For size deltas,
* positive deltas (regressions) are red and negative (improvements) are
* positive deltas are blue and negative deltas are amber. Neutral deltas
* emerald — matching how regressions are usually framed. Neutral deltas
* (counts) render muted.
* (counts) render muted.
*/
*/
export
function
DeltaChip
({
export
function
DeltaChip
({
...
@@ -18,9 +17,9 @@ export function DeltaChip({
...
@@ -18,9 +17,9 @@ export function DeltaChip({
const
toneClass
=
const
toneClass
=
tone
===
'size'
tone
===
'size'
?
delta
>
0
?
delta
>
0
?
'text-
red-400
'
?
'text-
delta-increase
'
:
delta
<
0
:
delta
<
0
?
'text-
emerald-400
'
?
'text-
delta-decrease
'
:
'text-muted-foreground'
:
'text-muted-foreground'
:
'text-muted-foreground'
:
'text-muted-foreground'
return
(
return
(
...
@@ -105,12 +104,10 @@ export function CountCard({
...
@@ -105,12 +104,10 @@ export function CountCard({
})
{
})
{
const
toneClass
=
const
toneClass
=
tone
===
'added'
tone
===
'added'
?
'text-
red-500
'
?
'text-
delta-increase
'
:
tone
===
'removed'
:
tone
===
'removed'
?
'text-green-500'
?
'text-delta-decrease'
:
tone
===
'changed'
:
'text-muted-foreground'
?
'text-amber-500'
:
'text-muted-foreground'
return
(
return
(
<
div
className=
"flex min-w-[80px] flex-col gap-1 rounded-md border border-border bg-background/60 px-3 py-2"
>
<
div
className=
"flex min-w-[80px] flex-col gap-1 rounded-md border border-border bg-background/60 px-3 py-2"
>
<
div
className=
"text-[10px] font-medium uppercase tracking-wide text-muted-foreground"
>
<
div
className=
"text-[10px] font-medium uppercase tracking-wide text-muted-foreground"
>
...
...
apps/bundle-analyzer/components/treemap-visualizer.tsx
View file @
bc95c4f8
'use client'
'use client'
import
{
darken
,
lighten
,
readableColor
}
from
'polished'
import
{
darken
,
lighten
,
readableColor
}
from
'polished'
import
{
useTheme
}
from
'next-themes'
import
type
React
from
'react'
import
type
React
from
'react'
import
{
useEffect
,
useLayoutEffect
,
useMemo
,
useRef
,
useState
}
from
'react'
import
{
useEffect
,
useLayoutEffect
,
useMemo
,
useRef
,
useState
}
from
'react'
import
{
import
{
...
@@ -35,7 +36,10 @@ interface TreemapVisualizerProps {
...
@@ -35,7 +36,10 @@ interface TreemapVisualizerProps {
* to the default file-type-based color. Used by the compare view to color
* to the default file-type-based color. Used by the compare view to color
* tiles by diff status (added/removed/grew/shrank) instead of by file type.
* tiles by diff status (added/removed/grew/shrank) instead of by file type.
*/
*/
getFileColorOverride
?:
(
node
:
LayoutNode
)
=>
string
|
undefined
getFileColorOverride
?:
(
node
:
LayoutNode
,
colors
:
CanvasColors
)
=>
string
|
undefined
/**
/**
* Optional override for the size label shown on a tile. Returning `undefined`
* Optional override for the size label shown on a tile. Returning `undefined`
* falls back to `formatBytes(node.size)`. Used by the compare view to show
* falls back to `formatBytes(node.size)`. Used by the compare view to show
...
@@ -50,20 +54,23 @@ interface TreemapVisualizerProps {
...
@@ -50,20 +54,23 @@ interface TreemapVisualizerProps {
overlay
?:
React
.
ReactNode
overlay
?:
React
.
ReactNode
}
}
function
getFileColor
(
node
:
{
function
getFileColor
(
js
?:
boolean
node
:
{
css
?:
boolean
js
?:
boolean
json
?:
boolean
css
?:
boolean
asset
?:
boolean
json
?:
boolean
server
?:
boolean
asset
?:
boolean
client
?:
boolean
server
?:
boolean
traced
?:
boolean
client
?:
boolean
specialModuleType
:
SpecialModule
|
null
traced
?:
boolean
}):
string
{
specialModuleType
:
SpecialModule
|
null
},
colors
:
CanvasColors
):
string
{
const
{
js
,
css
,
json
,
asset
,
client
,
traced
,
specialModuleType
}
=
node
const
{
js
,
css
,
json
,
asset
,
client
,
traced
,
specialModuleType
}
=
node
if
(
isPolyfill
(
specialModuleType
))
{
if
(
isPolyfill
(
specialModuleType
))
{
return
'#5f707f'
return
colors
.
polyfill
}
}
let
color
=
'#9ca3af'
// gray-400 default
let
color
=
'#9ca3af'
// gray-400 default
...
@@ -284,6 +291,7 @@ function nodeOrDescendantsMatchSearch(
...
@@ -284,6 +291,7 @@ function nodeOrDescendantsMatchSearch(
function
drawTreemap
(
function
drawTreemap
(
ctx
:
CanvasRenderingContext2D
,
ctx
:
CanvasRenderingContext2D
,
colors
:
CanvasColors
,
node
:
LayoutNode
,
node
:
LayoutNode
,
hoveredAncestorChain
:
number
[]
|
null
,
hoveredAncestorChain
:
number
[]
|
null
,
selectedAncestorChain
:
number
[],
selectedAncestorChain
:
number
[],
...
@@ -292,7 +300,9 @@ function drawTreemap(
...
@@ -292,7 +300,9 @@ function drawTreemap(
searchQuery
:
string
,
searchQuery
:
string
,
originalData
:
LayoutNode
,
originalData
:
LayoutNode
,
immediateHoveredSourceIndex
:
number
|
undefined
,
immediateHoveredSourceIndex
:
number
|
undefined
,
getFileColorOverride
:
((
node
:
LayoutNode
)
=>
string
|
undefined
)
|
undefined
,
getFileColorOverride
:
|
((
node
:
LayoutNode
,
colors
:
CanvasColors
)
=>
string
|
undefined
)
|
undefined
,
getFileSizeLabel
:
((
node
:
LayoutNode
)
=>
string
|
undefined
)
|
undefined
,
getFileSizeLabel
:
((
node
:
LayoutNode
)
=>
string
|
undefined
)
|
undefined
,
getFileLoadScope
:
((
sourceIndex
:
number
)
=>
SourceLoadScope
)
|
undefined
,
getFileLoadScope
:
((
sourceIndex
:
number
)
=>
SourceLoadScope
)
|
undefined
,
currentPath
:
string
[]
=
[],
currentPath
:
string
[]
=
[],
...
@@ -314,8 +324,6 @@ function drawTreemap(
...
@@ -314,8 +324,6 @@ function drawTreemap(
// Draw ancestor title bars (nodes on path but before the focused node)
// Draw ancestor title bars (nodes on path but before the focused node)
if
(
isOnFocusPath
&&
!
isFocusedNode
&&
type
===
'directory'
)
{
if
(
isOnFocusPath
&&
!
isFocusedNode
&&
type
===
'directory'
)
{
const
colors
=
getThemeColors
()
if
(
titleBarHeight
&&
rect
.
height
>
20
)
{
if
(
titleBarHeight
&&
rect
.
height
>
20
)
{
ctx
.
fillStyle
=
colors
.
dirTitleBg
ctx
.
fillStyle
=
colors
.
dirTitleBg
ctx
.
globalAlpha
=
1.0
ctx
.
globalAlpha
=
1.0
...
@@ -344,6 +352,7 @@ function drawTreemap(
...
@@ -344,6 +352,7 @@ function drawTreemap(
for
(
const
child
of
children
)
{
for
(
const
child
of
children
)
{
drawTreemap
(
drawTreemap
(
ctx
,
ctx
,
colors
,
child
,
child
,
hoveredAncestorChain
,
hoveredAncestorChain
,
selectedAncestorChain
,
selectedAncestorChain
,
...
@@ -411,14 +420,13 @@ function drawTreemap(
...
@@ -411,14 +420,13 @@ function drawTreemap(
}
}
const
opacity
=
fadeOut
?
0.3
:
1.0
const
opacity
=
fadeOut
?
0.3
:
1.0
const
colors
=
getThemeColors
()
// Check if this is the immediately hovered node for brightness boost
// Check if this is the immediately hovered node for brightness boost
const
isImmediateHovered
=
const
isImmediateHovered
=
sourceIndex
!==
undefined
&&
sourceIndex
===
immediateHoveredSourceIndex
sourceIndex
!==
undefined
&&
sourceIndex
===
immediateHoveredSourceIndex
if
(
type
===
'file'
)
{
if
(
type
===
'file'
)
{
let
color
=
getFileColorOverride
?.(
node
)
??
getFileColor
(
node
)
let
color
=
getFileColorOverride
?.(
node
,
colors
)
??
getFileColor
(
node
,
colors
)
// Apply brightness boost to immediately hovered node
// Apply brightness boost to immediately hovered node
if
(
isImmediateHovered
)
{
if
(
isImmediateHovered
)
{
...
@@ -663,6 +671,7 @@ function drawTreemap(
...
@@ -663,6 +671,7 @@ function drawTreemap(
drawTreemap
(
drawTreemap
(
ctx
,
ctx
,
colors
,
child
,
child
,
hoveredAncestorChain
,
hoveredAncestorChain
,
selectedAncestorChain
,
selectedAncestorChain
,
...
@@ -798,7 +807,7 @@ export function TreemapVisualizer({
...
@@ -798,7 +807,7 @@ export function TreemapVisualizer({
canvasHeight
:
800
,
canvasHeight
:
800
,
devicePixelRatio
:
1
,
devicePixelRatio
:
1
,
})
})
const
[,
_setTheme
]
=
useState
<
'light'
|
'dark'
>
(
'light'
)
const
{
resolvedTheme
}
=
useTheme
(
)
// The focused chain needs a manual memo: without it the compiler misses
// The focused chain needs a manual memo: without it the compiler misses
// the expensive layout and redraws the canvas on unrelated renders.
// the expensive layout and redraws the canvas on unrelated renders.
...
@@ -904,6 +913,7 @@ export function TreemapVisualizer({
...
@@ -904,6 +913,7 @@ export function TreemapVisualizer({
drawTreemap
(
drawTreemap
(
ctx
,
ctx
,
getThemeColors
(),
layout
,
layout
,
hoveredAncestorChain
,
hoveredAncestorChain
,
selectedAncestorChain
,
selectedAncestorChain
,
...
@@ -923,6 +933,7 @@ export function TreemapVisualizer({
...
@@ -923,6 +933,7 @@ export function TreemapVisualizer({
dimensions
.
cssWidth
,
dimensions
.
cssWidth
,
dimensions
.
cssHeight
,
dimensions
.
cssHeight
,
dimensions
.
devicePixelRatio
,
dimensions
.
devicePixelRatio
,
resolvedTheme
,
isMouseInTreemap
,
isMouseInTreemap
,
focusedAncestorChain
,
focusedAncestorChain
,
searchQuery
,
searchQuery
,
...
@@ -1079,7 +1090,11 @@ function isDarkMode(): boolean {
...
@@ -1079,7 +1090,11 @@ function isDarkMode(): boolean {
function
getThemeColors
()
{
function
getThemeColors
()
{
const
dark
=
isDarkMode
()
const
dark
=
isDarkMode
()
const
styles
=
getComputedStyle
(
document
.
documentElement
)
return
{
return
{
increase
:
styles
.
getPropertyValue
(
'--delta-increase'
).
trim
(),
decrease
:
styles
.
getPropertyValue
(
'--delta-decrease'
).
trim
(),
polyfill
:
styles
.
getPropertyValue
(
'--polyfill'
).
trim
(),
text
:
dark
?
'#ffffff'
:
'#000000'
,
text
:
dark
?
'#ffffff'
:
'#000000'
,
textMuted
:
dark
?
'rgba(255, 255, 255, 0.6)'
:
'rgba(0, 0, 0, 0.6)'
,
textMuted
:
dark
?
'rgba(255, 255, 255, 0.6)'
:
'rgba(0, 0, 0, 0.6)'
,
border
:
dark
?
'rgba(255, 255, 255, 0.4)'
:
'rgba(180, 180, 180, 0.5)'
,
border
:
dark
?
'rgba(255, 255, 255, 0.4)'
:
'rgba(180, 180, 180, 0.5)'
,
...
@@ -1097,3 +1112,5 @@ function getThemeColors() {
...
@@ -1097,3 +1112,5 @@ function getThemeColors() {
:
'rgba(128, 128, 128, 0.6)'
,
:
'rgba(128, 128, 128, 0.6)'
,
}
}
}
}
export
type
CanvasColors
=
ReturnType
<
typeof
getThemeColors
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment