@@ -70,7 +70,7 @@ const sortedOptionalDependencies = computed(() => {
7070})
7171
7272// Fetch size information for dependencies that require it
73- const { data : serverSizes , pending : sizesLoading } = await useAsyncData (
73+ const { data : sizereqData , pending : sizereqLoading } = await useAsyncData (
7474 ` sizes:${props .packageName }:${props .version } ` ,
7575 async (_app , { signal }) => {
7676 const entries = sortedDependencies .value
@@ -113,11 +113,12 @@ const { data: serverSizes, pending: sizesLoading } = await useAsyncData(
113113 },
114114 {
115115 watch: [sortedDependencies ],
116+ server: false ,
116117 },
117118)
118119
119120// Minimum percentage to be shown as an individual slice
120- const THRESHOLD_PERCENT = 10
121+ const THRESHOLD_PERCENT = 2
121122
122123type Sizereq = {
123124 info: InstallSizeResult
@@ -132,61 +133,66 @@ const sortedSizereqDependecies = computed(() => {
132133 return { visible: [], others: [], totalOthersSize: 0 , othersPercentage: 0 }
133134 }
134135
135- const total = props .packageSize .totalSize
136-
137- // 1. Map everything first, preserving the 'bundled' flag from the source
138- const allMapped = props .packageSize .dependencies
139- .map (depSize => {
140- const bundled = ! sortedDependencies .value .some (([name ]) => name === depSize .name )
141- const percent = props .packageSize ? (depSize .size / props .packageSize .totalSize ) * 100 : 0
142- const serverData = serverSizes .value ?.[depSize .name ]
143- const error = serverData ?.kind === ' error' ? serverData .error : null
144- return {
145- info:
146- serverData ?.kind === ' success'
147- ? {
148- package: depSize .name ,
149- totalSize: serverData .packageSize ?.totalSize ?? depSize .size ,
150- selfSize: serverData .packageSize ?.selfSize ?? depSize .size ,
151- }
152- : {
153- package: depSize .name ,
154- totalSize: depSize .size ,
155- selfSize: depSize .size ,
156- },
157- error ,
158- bundled ,
159- percent ,
160- } as Sizereq
161- })
162- .sort ((a , b ) => {
163- // Bundled first
164- if (a .bundled !== b .bundled ) return a .bundled ? - 1 : 1
165- return b .info .totalSize - a .info .totalSize
166- })
136+ const allMapped = props .packageSize .dependencies .map (depSize => {
137+ let bundled: boolean = false
138+ switch (typeof props .bundledDependencies ) {
139+ case ' boolean' :
140+ bundled = props .bundledDependencies
141+ break
142+ case ' object' :
143+ bundled = props .bundledDependencies .some (name => name === depSize .name )
144+ break
145+ }
146+ const percent = props .packageSize ? (depSize .size / props .packageSize .totalSize ) * 100 : 0
147+ const serverData = sizereqData .value ?.[depSize .name ]
148+ const error = serverData ?.kind === ' error' ? serverData .error : null
149+ return {
150+ info:
151+ serverData ?.kind === ' success' && serverData .packageSize
152+ ? {
153+ package: depSize .name ,
154+ version: depSize .version ,
155+ totalSize: serverData .packageSize .totalSize ,
156+ selfSize: serverData .packageSize .selfSize ,
157+ }
158+ : {
159+ package: depSize .name ,
160+ version: depSize .version ,
161+ totalSize: depSize .size ,
162+ selfSize: depSize .size ,
163+ },
164+ error ,
165+ bundled ,
166+ percent ,
167+ } as Sizereq
168+ })
167169
168170 const visible: Sizereq [] = []
169171 const others: Sizereq [] = []
170172
171173 for (const dep of allMapped ) {
172- const percentage = (dep .info .totalSize / total ) * 100
174+ const percentage = (dep .info .selfSize / props . packageSize . totalSize ) * 100
173175 if (percentage >= THRESHOLD_PERCENT ) {
174176 visible .push ({ ... dep , percent: percentage })
175177 } else {
176178 others .push (dep )
177179 }
178180 }
179181
180- const totalOthersSize = others .reduce ((acc , d ) => acc + d .info .totalSize , 0 )
181- const othersPercentage = (totalOthersSize / total ) * 100
182+ const othersSelfSize = others .reduce ((acc , d ) => acc + d .info .selfSize , 0 )
183+ const othersPercentage = (othersSelfSize / props . packageSize . totalSize ) * 100
182184
183- if (othersPercentage < THRESHOLD_PERCENT || others .length === 1 ) {
184- visible .push (others [0 ]! )
185- others .length = 0
186- visible .sort ((a , b ) => b .info .totalSize - a .info .totalSize )
187- }
185+ // if (others.length === 1) {
186+ // visible.push(others[0]!)
187+ // others.length = 0
188+ // visible.sort((a, b) => b.info.totalSize - a.info.totalSize)
189+ // } else if (others.length > 1 && othersPercentage < THRESHOLD_PERCENT) {
190+ // visible.push(...others)
191+ // others.length = 0
192+ // visible.sort((a, b) => b.info.totalSize - a.info.totalSize)
193+ // }
188194
189- return { visible , others , totalOthersSize , othersPercentage }
195+ return { visible , others , totalOthersSize: othersSelfSize , othersPercentage }
190196})
191197
192198const othersTooltip = computed (() => {
@@ -220,12 +226,11 @@ const remainingWidth = computed(() => {
220226 const total = props .packageSize ?.totalSize
221227 if (! total ) return 100
222228
223- // Sum up everything we actually HAVE data for
224229 const self = props .packageSize .selfSize || 0
225230 const depsSum = [
226231 ... sortedSizereqDependecies .value .visible ,
227232 ... sortedSizereqDependecies .value .others ,
228- ].reduce ((acc , d ) => acc + d .info .totalSize , 0 )
233+ ].reduce ((acc , d ) => acc + d .info .selfSize , 0 )
229234
230235 const width = ((total - (self + depsSum )) / total ) * 100
231236 return Math .max (0 , width )
@@ -325,17 +330,22 @@ const bytesFormatter = useBytesFormatter()
325330 size: bytesFormatter.format(props.packageSize?.selfSize || 0),
326331 })
327332 "
328- class =" h-full bg-blue-500 "
333+ class =" h-full bg-accent "
329334 :style =" { width: selfSizeWidth + '%' }"
330335 />
331336
332337 <template v-for =" dep in sortedSizereqDependecies .visible " :key =" dep .info .package " >
333338 <TooltipApp
334339 :text =" `${dep.info.package}\n${getDepSizeTooltip(dep.info.package)}`"
335340 class =" h-full"
336- :class =" dep.bundled ? 'bg-blue-500 ' : 'bg-fg'"
341+ :class =" dep.bundled ? 'bg-accent ' : 'bg-fg'"
337342 :style =" { width: dep.percent + '%' }"
338- />
343+ >
344+ <RouterLink
345+ :to =" packageRoute(dep.info.package, dep.info.version)"
346+ class =" block w-full h-full"
347+ />
348+ </TooltipApp >
339349 </template >
340350
341351 <TooltipApp
@@ -434,7 +444,7 @@ const bytesFormatter = useBytesFormatter()
434444 <span
435445 class =" i-lucide:info w-3 h-3 opacity-50 transition-opacity hover:opacity-100"
436446 :class =" {
437- 'i-svg-spinners:ring-resize': sizesLoading && !serverSizes ?.[dep],
447+ 'i-svg-spinners:ring-resize': sizereqLoading && !sizereqData ?.[dep],
438448 }"
439449 aria-hidden =" true"
440450 />
0 commit comments