react-native-bundle-discovery-ui 2.7.0 → 2.9.0
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.
- package/CHANGELOG.md +32 -0
- package/README.md +12 -227
- package/assets/global.css +769 -53
- package/dist/bin.js +61 -16
- package/dist/client/issues.js +5 -0
- package/dist/client/pages/_common.js +258 -86
- package/dist/client/pages/_module.js +347 -0
- package/dist/client/pages/default.js +145 -62
- package/dist/client/pages/module.js +2 -309
- package/dist/client/pages/moduleDiff.js +76 -0
- package/dist/client/pages/package.js +172 -154
- package/dist/client/prepare.js +15 -0
- package/dist/client/queryHelpers.js +445 -81
- package/dist/client/views/{_theme.js → _colorScheme.js} +2 -9
- package/dist/client/views/_html.js +52 -0
- package/dist/client/views/codeDiff.js +66 -0
- package/dist/client/views/compare.js +237 -0
- package/dist/client/views/importGraph.js +255 -0
- package/dist/client/views/insights.js +80 -0
- package/dist/client/views/moduleOverview.js +134 -0
- package/dist/client/views/packageOverview.js +114 -0
- package/dist/client/views/persistedFilterInput.js +27 -0
- package/dist/client/views/reportBar.js +89 -0
- package/dist/client/views/treemap.js +598 -0
- package/dist/discoveryrc.js +26 -7
- package/dist/rsdoctor.js +5 -101
- package/dist/src-Bp8pPQrQ.js +1545 -0
- package/package.json +5 -3
- package/assets/highcharts.css +0 -1
- package/dist/client/_virtual/_rolldown/runtime.js +0 -37
- package/dist/client/views/foamtree.js +0 -103
- package/dist/client/views/highcharts.js +0 -33
- package/dist/src-BSLX-He2.js +0 -36
- package/vendors/foamtree.js +0 -9008
- package/vendors/high-contrast-dark.js +0 -1
- package/vendors/highcharts-exporting.js +0 -13
- package/vendors/highcharts-networkgraph.js +0 -1
- package/vendors/highcharts.js +0 -10
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
require("../issues.js");
|
|
2
|
+
const require_views__colorScheme = require("./_colorScheme.js");
|
|
3
|
+
let d3_hierarchy = require("d3-hierarchy");
|
|
4
|
+
//#region src/client/views/treemap.ts
|
|
5
|
+
const PALETTE = [
|
|
6
|
+
{
|
|
7
|
+
h: 205,
|
|
8
|
+
s: 71,
|
|
9
|
+
l: 41,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
h: 28,
|
|
13
|
+
s: 100,
|
|
14
|
+
l: 53,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
h: 120,
|
|
18
|
+
s: 57,
|
|
19
|
+
l: 40,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
h: 360,
|
|
23
|
+
s: 69,
|
|
24
|
+
l: 50,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
h: 271,
|
|
28
|
+
s: 39,
|
|
29
|
+
l: 57,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
h: 10,
|
|
33
|
+
s: 30,
|
|
34
|
+
l: 42,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
h: 318,
|
|
38
|
+
s: 66,
|
|
39
|
+
l: 68,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
h: 0,
|
|
43
|
+
s: 0,
|
|
44
|
+
l: 50,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
h: 60,
|
|
48
|
+
s: 70,
|
|
49
|
+
l: 44,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
h: 186,
|
|
53
|
+
s: 80,
|
|
54
|
+
l: 45,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
const TONE = {
|
|
58
|
+
blue: PALETTE[0],
|
|
59
|
+
orange: PALETTE[1],
|
|
60
|
+
green: PALETTE[2],
|
|
61
|
+
red: PALETTE[3],
|
|
62
|
+
purple: PALETTE[4],
|
|
63
|
+
olive: PALETTE[8],
|
|
64
|
+
};
|
|
65
|
+
const LIGHT_LABEL_BELOW = 52;
|
|
66
|
+
const HUE_SHIFT_STEPS = [8, 4];
|
|
67
|
+
const MIN_SHADED_SIZE = 6;
|
|
68
|
+
const HEADER_HEIGHT = 16;
|
|
69
|
+
const BREADCRUMB_HEIGHT = 26;
|
|
70
|
+
const FONT = "11px system-ui, -apple-system, sans-serif";
|
|
71
|
+
const MAX_SCALE = 64;
|
|
72
|
+
const COLOR_BY_OPTIONS = [
|
|
73
|
+
{
|
|
74
|
+
value: "package",
|
|
75
|
+
text: "Package",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: "type",
|
|
79
|
+
text: "File type",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: "issues",
|
|
83
|
+
text: "Issues",
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
const TYPE_TONES = [
|
|
87
|
+
{
|
|
88
|
+
text: "js",
|
|
89
|
+
exts: ["js", "jsx", "mjs", "cjs"],
|
|
90
|
+
tone: TONE.olive,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
text: "ts",
|
|
94
|
+
exts: ["ts", "tsx"],
|
|
95
|
+
tone: TONE.blue,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
text: "json",
|
|
99
|
+
exts: ["json"],
|
|
100
|
+
tone: TONE.orange,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
text: "images",
|
|
104
|
+
exts: ["png", "jpg", "jpeg", "gif", "webp", "svg"],
|
|
105
|
+
tone: TONE.purple,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
text: "other",
|
|
109
|
+
exts: [],
|
|
110
|
+
tone: null,
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
const ISSUE_TONES = [
|
|
114
|
+
{
|
|
115
|
+
text: "Duplicate",
|
|
116
|
+
tone: TONE.red,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
text: "Can be removed",
|
|
120
|
+
tone: TONE.orange,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
text: "No issues",
|
|
124
|
+
tone: null,
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
let colorBy = "package";
|
|
128
|
+
function getTypeTone(name) {
|
|
129
|
+
const dot = name.lastIndexOf(".");
|
|
130
|
+
const ext = dot === -1 ? "js" : name.slice(dot + 1).toLowerCase();
|
|
131
|
+
return (
|
|
132
|
+
TYPE_TONES.find((t) => t.exts.includes(ext)) ??
|
|
133
|
+
TYPE_TONES[TYPE_TONES.length - 1]
|
|
134
|
+
).tone;
|
|
135
|
+
}
|
|
136
|
+
function getIssueTone(issues) {
|
|
137
|
+
if (!issues?.length) return null;
|
|
138
|
+
return issues.includes("Duplicate module")
|
|
139
|
+
? ISSUE_TONES[0].tone
|
|
140
|
+
: ISSUE_TONES[1].tone;
|
|
141
|
+
}
|
|
142
|
+
function shade(tone, depth, dark) {
|
|
143
|
+
const lift = Math.min(depth * 1.5, 6);
|
|
144
|
+
return dark
|
|
145
|
+
? {
|
|
146
|
+
h: tone.h,
|
|
147
|
+
s: Math.max(tone.s - 6, 0),
|
|
148
|
+
l: tone.l - 10 + lift / 2,
|
|
149
|
+
}
|
|
150
|
+
: {
|
|
151
|
+
h: tone.h,
|
|
152
|
+
s: tone.s,
|
|
153
|
+
l: tone.l + lift,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function escapeHTML(str) {
|
|
157
|
+
return str.replace(
|
|
158
|
+
/[&<>"']/g,
|
|
159
|
+
(c) =>
|
|
160
|
+
({
|
|
161
|
+
"&": "&",
|
|
162
|
+
"<": "<",
|
|
163
|
+
">": ">",
|
|
164
|
+
'"': """,
|
|
165
|
+
"'": "'",
|
|
166
|
+
})[c],
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
function prependDuplicateTo(label) {
|
|
170
|
+
if (label.includes(" ~ "))
|
|
171
|
+
return `<b class='i-duplicate'>Duplicate</b> ${escapeHTML(label.split(" ~ ")[1])}`;
|
|
172
|
+
return escapeHTML(label);
|
|
173
|
+
}
|
|
174
|
+
function tooltipHTML(node) {
|
|
175
|
+
if (!node.type) return "";
|
|
176
|
+
return [
|
|
177
|
+
`<b>${node.type === "folder" ? "Folder" : "File"}</b>: ${prependDuplicateTo(node.name)}`,
|
|
178
|
+
`<b>Size</b>: ${node.size}`,
|
|
179
|
+
node.type === "folder"
|
|
180
|
+
? `<b>Files</b>: ${node.files}`
|
|
181
|
+
: `<b>Path</b>: ${escapeHTML(node.fullPath ?? "")}`,
|
|
182
|
+
node.issues?.length
|
|
183
|
+
? `<b>Issues</b>: ${node.issues.map(escapeHTML).join(", ")}`
|
|
184
|
+
: "",
|
|
185
|
+
]
|
|
186
|
+
.filter(Boolean)
|
|
187
|
+
.join("<br/>");
|
|
188
|
+
}
|
|
189
|
+
function assignTones(roots) {
|
|
190
|
+
const tones = /* @__PURE__ */ new Map();
|
|
191
|
+
const inherit = (node, tone, level = 0) => {
|
|
192
|
+
tones.set(node, tone);
|
|
193
|
+
const step = HUE_SHIFT_STEPS[level] ?? 0;
|
|
194
|
+
(node.children ?? []).forEach((child, index) => {
|
|
195
|
+
inherit(
|
|
196
|
+
child,
|
|
197
|
+
{
|
|
198
|
+
...tone,
|
|
199
|
+
h: tone.h + ((index % 5) - 2) * step,
|
|
200
|
+
},
|
|
201
|
+
level + 1,
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
roots
|
|
206
|
+
.flatMap((root) => {
|
|
207
|
+
let node = root;
|
|
208
|
+
while (node.children?.length === 1) node = node.children[0];
|
|
209
|
+
return node.children ?? [];
|
|
210
|
+
})
|
|
211
|
+
.sort((a, b) => (b.value ?? 0) - (a.value ?? 0))
|
|
212
|
+
.forEach((node, i) => {
|
|
213
|
+
inherit(node, PALETTE[i % PALETTE.length]);
|
|
214
|
+
});
|
|
215
|
+
return tones;
|
|
216
|
+
}
|
|
217
|
+
function truncate(ctx, text, maxWidth) {
|
|
218
|
+
if (ctx.measureText(text).width <= maxWidth) return text;
|
|
219
|
+
let len = Math.min(text.length - 1, Math.floor(maxWidth / 6));
|
|
220
|
+
while (len > 0 && ctx.measureText(`${text.slice(0, len)}…`).width > maxWidth)
|
|
221
|
+
len--;
|
|
222
|
+
return len > 0 ? `${text.slice(0, len)}…` : "";
|
|
223
|
+
}
|
|
224
|
+
function createTreemap(host, roots) {
|
|
225
|
+
const dark = require_views__colorScheme.isDark();
|
|
226
|
+
let tones = /* @__PURE__ */ new Map();
|
|
227
|
+
const fullRoot = {
|
|
228
|
+
name: "Bundle",
|
|
229
|
+
children: roots,
|
|
230
|
+
};
|
|
231
|
+
host.style.position = "relative";
|
|
232
|
+
host.innerHTML = "";
|
|
233
|
+
const base = document.createElement("canvas");
|
|
234
|
+
const overlay = document.createElement("canvas");
|
|
235
|
+
for (const canvas of [base, overlay]) {
|
|
236
|
+
canvas.style.position = "absolute";
|
|
237
|
+
canvas.style.left = "0";
|
|
238
|
+
canvas.style.top = `${BREADCRUMB_HEIGHT}px`;
|
|
239
|
+
}
|
|
240
|
+
overlay.style.cursor = "pointer";
|
|
241
|
+
overlay.style.touchAction = "none";
|
|
242
|
+
const header = document.createElement("div");
|
|
243
|
+
header.className = "treemap-header";
|
|
244
|
+
const breadcrumb = document.createElement("div");
|
|
245
|
+
breadcrumb.className = "treemap-breadcrumb";
|
|
246
|
+
const controls = document.createElement("div");
|
|
247
|
+
controls.className = "treemap-controls";
|
|
248
|
+
header.append(breadcrumb, controls);
|
|
249
|
+
const tooltip = document.createElement("div");
|
|
250
|
+
tooltip.className = "treemap-tooltip";
|
|
251
|
+
host.append(header, base, overlay, tooltip);
|
|
252
|
+
let focusPath = [fullRoot];
|
|
253
|
+
let root = null;
|
|
254
|
+
let rects = [];
|
|
255
|
+
let hovered = null;
|
|
256
|
+
let width = 0;
|
|
257
|
+
let height = 0;
|
|
258
|
+
let scale = 1;
|
|
259
|
+
let offsetX = 0;
|
|
260
|
+
let offsetY = 0;
|
|
261
|
+
function getTone(node) {
|
|
262
|
+
if (colorBy === "package") return tones.get(node.data);
|
|
263
|
+
if (node.children) return void 0;
|
|
264
|
+
return (
|
|
265
|
+
(colorBy === "type"
|
|
266
|
+
? getTypeTone(node.data.name)
|
|
267
|
+
: getIssueTone(node.data.issues)) ?? void 0
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
function fillLightness(node) {
|
|
271
|
+
const tone = getTone(node);
|
|
272
|
+
if (!tone) return dark ? 18 + node.depth * 4 : 88 - node.depth * 4;
|
|
273
|
+
return shade(tone, node.depth, dark).l;
|
|
274
|
+
}
|
|
275
|
+
function fill(node, delta = 0) {
|
|
276
|
+
const tone = getTone(node);
|
|
277
|
+
if (!tone) return `hsl(0 0% ${fillLightness(node) + delta}%)`;
|
|
278
|
+
const { h, s, l } = shade(tone, node.depth, dark);
|
|
279
|
+
return `hsl(${h} ${s}% ${l + delta}%)`;
|
|
280
|
+
}
|
|
281
|
+
function cushion(ctx, node) {
|
|
282
|
+
const w = node.x1 - node.x0;
|
|
283
|
+
const h = node.y1 - node.y0;
|
|
284
|
+
if (w < MIN_SHADED_SIZE || h < MIN_SHADED_SIZE) return fill(node);
|
|
285
|
+
const gradient = ctx.createLinearGradient(
|
|
286
|
+
node.x0,
|
|
287
|
+
node.y0,
|
|
288
|
+
node.x1,
|
|
289
|
+
node.y1,
|
|
290
|
+
);
|
|
291
|
+
gradient.addColorStop(0, fill(node, 7));
|
|
292
|
+
gradient.addColorStop(1, fill(node, -7));
|
|
293
|
+
return gradient;
|
|
294
|
+
}
|
|
295
|
+
function buildHierarchy() {
|
|
296
|
+
const focus = focusPath[focusPath.length - 1];
|
|
297
|
+
tones = assignTones(focusPath.length === 1 ? roots : [focus]);
|
|
298
|
+
root = (0, d3_hierarchy.hierarchy)(focus)
|
|
299
|
+
.sum((d) => (d.children?.length ? 0 : (d.value ?? 0)))
|
|
300
|
+
.sort((a, b) => (b.value ?? 0) - (a.value ?? 0));
|
|
301
|
+
}
|
|
302
|
+
function layout() {
|
|
303
|
+
if (!root) return;
|
|
304
|
+
rects = (0, d3_hierarchy.treemap)()
|
|
305
|
+
.tile(d3_hierarchy.treemapSquarify)
|
|
306
|
+
.size([width * scale, height * scale])
|
|
307
|
+
.paddingInner(1)
|
|
308
|
+
.paddingOuter(2)
|
|
309
|
+
.paddingTop((node) =>
|
|
310
|
+
node.x1 - node.x0 > 40 && node.y1 - node.y0 > 32 ? HEADER_HEIGHT : 2,
|
|
311
|
+
)
|
|
312
|
+
.round(true)(root)
|
|
313
|
+
.descendants()
|
|
314
|
+
.filter((n) => n.x1 - n.x0 >= 1 && n.y1 - n.y0 >= 1);
|
|
315
|
+
}
|
|
316
|
+
function draw() {
|
|
317
|
+
const dpr = window.devicePixelRatio || 1;
|
|
318
|
+
const ctx = base.getContext("2d");
|
|
319
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
320
|
+
ctx.clearRect(0, 0, width, height);
|
|
321
|
+
ctx.translate(offsetX, offsetY);
|
|
322
|
+
ctx.font = FONT;
|
|
323
|
+
ctx.textBaseline = "middle";
|
|
324
|
+
ctx.strokeStyle = dark ? "rgba(0,0,0,.45)" : "rgba(0,0,0,.18)";
|
|
325
|
+
ctx.lineWidth = 1;
|
|
326
|
+
for (const node of rects) {
|
|
327
|
+
if (
|
|
328
|
+
node.x1 + offsetX < 0 ||
|
|
329
|
+
node.y1 + offsetY < 0 ||
|
|
330
|
+
node.x0 + offsetX > width ||
|
|
331
|
+
node.y0 + offsetY > height
|
|
332
|
+
)
|
|
333
|
+
continue;
|
|
334
|
+
const w = node.x1 - node.x0;
|
|
335
|
+
const h = node.y1 - node.y0;
|
|
336
|
+
ctx.fillStyle = cushion(ctx, node);
|
|
337
|
+
ctx.fillRect(node.x0, node.y0, w, h);
|
|
338
|
+
ctx.strokeRect(node.x0 + 0.5, node.y0 + 0.5, w - 1, h - 1);
|
|
339
|
+
if (w < 30 || h < 12) continue;
|
|
340
|
+
const isFolder = !!node.children;
|
|
341
|
+
if (isFolder && h <= 32) continue;
|
|
342
|
+
const label = truncate(ctx, node.data.name, w - 8);
|
|
343
|
+
if (!label) continue;
|
|
344
|
+
ctx.fillStyle =
|
|
345
|
+
dark || fillLightness(node) < LIGHT_LABEL_BELOW ? "#f4f4f6" : "#16161a";
|
|
346
|
+
ctx.font = isFolder ? `bold ${FONT}` : FONT;
|
|
347
|
+
ctx.fillText(label, node.x0 + 4, node.y0 + HEADER_HEIGHT / 2 + 1);
|
|
348
|
+
ctx.font = FONT;
|
|
349
|
+
}
|
|
350
|
+
drawHover();
|
|
351
|
+
renderBreadcrumb();
|
|
352
|
+
}
|
|
353
|
+
function drawHover() {
|
|
354
|
+
const dpr = window.devicePixelRatio || 1;
|
|
355
|
+
const ctx = overlay.getContext("2d");
|
|
356
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
357
|
+
ctx.clearRect(0, 0, width, height);
|
|
358
|
+
if (!hovered) return;
|
|
359
|
+
ctx.translate(offsetX, offsetY);
|
|
360
|
+
ctx.strokeStyle = dark ? "#fff" : "#000";
|
|
361
|
+
ctx.lineWidth = 2;
|
|
362
|
+
ctx.strokeRect(
|
|
363
|
+
hovered.x0 + 1,
|
|
364
|
+
hovered.y0 + 1,
|
|
365
|
+
hovered.x1 - hovered.x0 - 2,
|
|
366
|
+
hovered.y1 - hovered.y0 - 2,
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
function swatch(tone) {
|
|
370
|
+
return `<span class="treemap-swatch" style="background:${tone === null ? (dark ? "hsl(0 0% 30%)" : "hsl(0 0% 78%)") : (({ h, s, l }) => `hsl(${h} ${s}% ${l}%)`)(shade(tone, 2, dark))}"></span>`;
|
|
371
|
+
}
|
|
372
|
+
function renderControls() {
|
|
373
|
+
controls.innerHTML = `
|
|
374
|
+
<span class="treemap-legend">${(colorBy === "type" ? TYPE_TONES : colorBy === "issues" ? ISSUE_TONES : []).map((item) => `<span>${swatch(item.tone)}${item.text}</span>`).join("")}</span>
|
|
375
|
+
<span class="treemap-color-by-label">Color by:</span>`;
|
|
376
|
+
const group = document.createElement("span");
|
|
377
|
+
group.className = "view-toggle-group treemap-color-by";
|
|
378
|
+
for (const option of COLOR_BY_OPTIONS) {
|
|
379
|
+
const toggle = document.createElement("span");
|
|
380
|
+
toggle.className = `view-toggle onclick${option.value === colorBy ? " checked" : ""}`;
|
|
381
|
+
toggle.textContent = option.text;
|
|
382
|
+
toggle.onclick = () => {
|
|
383
|
+
colorBy = option.value;
|
|
384
|
+
renderControls();
|
|
385
|
+
draw();
|
|
386
|
+
};
|
|
387
|
+
group.append(toggle);
|
|
388
|
+
}
|
|
389
|
+
controls.append(group);
|
|
390
|
+
}
|
|
391
|
+
function renderBreadcrumb() {
|
|
392
|
+
breadcrumb.innerHTML = "";
|
|
393
|
+
focusPath.forEach((node, index) => {
|
|
394
|
+
const item = document.createElement("span");
|
|
395
|
+
item.className = "treemap-breadcrumb-item";
|
|
396
|
+
item.textContent = node.name;
|
|
397
|
+
item.onclick = () => zoomTo(focusPath.slice(0, index + 1));
|
|
398
|
+
breadcrumb.append(item);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
function hitTest(screenX, screenY) {
|
|
402
|
+
const x = screenX - offsetX;
|
|
403
|
+
const y = screenY - offsetY;
|
|
404
|
+
for (let i = rects.length - 1; i >= 0; i--) {
|
|
405
|
+
const n = rects[i];
|
|
406
|
+
if (x >= n.x0 && x < n.x1 && y >= n.y0 && y < n.y1) return n;
|
|
407
|
+
}
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
function zoomTo(path) {
|
|
411
|
+
focusPath = path;
|
|
412
|
+
hovered = null;
|
|
413
|
+
tooltip.style.display = "none";
|
|
414
|
+
scale = 1;
|
|
415
|
+
offsetX = 0;
|
|
416
|
+
offsetY = 0;
|
|
417
|
+
buildHierarchy();
|
|
418
|
+
layout();
|
|
419
|
+
draw();
|
|
420
|
+
}
|
|
421
|
+
function clampOffset() {
|
|
422
|
+
offsetX = Math.min(0, Math.max(offsetX, width - width * scale));
|
|
423
|
+
offsetY = Math.min(0, Math.max(offsetY, height - height * scale));
|
|
424
|
+
}
|
|
425
|
+
let frame = 0;
|
|
426
|
+
let needsLayout = false;
|
|
427
|
+
function scheduleRedraw(relayout) {
|
|
428
|
+
if (relayout) needsLayout = true;
|
|
429
|
+
if (frame) return;
|
|
430
|
+
frame = requestAnimationFrame(() => {
|
|
431
|
+
frame = 0;
|
|
432
|
+
if (needsLayout) layout();
|
|
433
|
+
needsLayout = false;
|
|
434
|
+
draw();
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
overlay.addEventListener(
|
|
438
|
+
"wheel",
|
|
439
|
+
(event) => {
|
|
440
|
+
event.preventDefault();
|
|
441
|
+
const nextScale = Math.min(
|
|
442
|
+
MAX_SCALE,
|
|
443
|
+
Math.max(1, scale * Math.exp(-event.deltaY * 0.002)),
|
|
444
|
+
);
|
|
445
|
+
if (nextScale === scale) return;
|
|
446
|
+
const ratio = nextScale / scale;
|
|
447
|
+
offsetX = event.offsetX - (event.offsetX - offsetX) * ratio;
|
|
448
|
+
offsetY = event.offsetY - (event.offsetY - offsetY) * ratio;
|
|
449
|
+
scale = nextScale;
|
|
450
|
+
clampOffset();
|
|
451
|
+
hovered = null;
|
|
452
|
+
tooltip.style.display = "none";
|
|
453
|
+
scheduleRedraw(true);
|
|
454
|
+
},
|
|
455
|
+
{ passive: false },
|
|
456
|
+
);
|
|
457
|
+
let drag = null;
|
|
458
|
+
let suppressClick = false;
|
|
459
|
+
overlay.addEventListener("pointerdown", (event) => {
|
|
460
|
+
if (event.button !== 0) return;
|
|
461
|
+
drag = {
|
|
462
|
+
x: event.clientX,
|
|
463
|
+
y: event.clientY,
|
|
464
|
+
moved: false,
|
|
465
|
+
};
|
|
466
|
+
overlay.setPointerCapture(event.pointerId);
|
|
467
|
+
});
|
|
468
|
+
overlay.addEventListener("pointerup", () => {
|
|
469
|
+
suppressClick = !!drag?.moved;
|
|
470
|
+
drag = null;
|
|
471
|
+
overlay.style.cursor = "pointer";
|
|
472
|
+
});
|
|
473
|
+
overlay.addEventListener("mousemove", (event) => {
|
|
474
|
+
if (drag) {
|
|
475
|
+
const dx = event.clientX - drag.x;
|
|
476
|
+
const dy = event.clientY - drag.y;
|
|
477
|
+
if (drag.moved || Math.abs(dx) + Math.abs(dy) > 3) {
|
|
478
|
+
drag.moved = true;
|
|
479
|
+
drag.x = event.clientX;
|
|
480
|
+
drag.y = event.clientY;
|
|
481
|
+
offsetX += dx;
|
|
482
|
+
offsetY += dy;
|
|
483
|
+
clampOffset();
|
|
484
|
+
overlay.style.cursor = "grabbing";
|
|
485
|
+
tooltip.style.display = "none";
|
|
486
|
+
scheduleRedraw(false);
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const node = hitTest(event.offsetX, event.offsetY);
|
|
491
|
+
if (node !== hovered) {
|
|
492
|
+
hovered = node;
|
|
493
|
+
drawHover();
|
|
494
|
+
const html = node ? tooltipHTML(node.data) : "";
|
|
495
|
+
tooltip.innerHTML = html;
|
|
496
|
+
tooltip.style.display = html ? "block" : "none";
|
|
497
|
+
}
|
|
498
|
+
const left = Math.min(event.offsetX + 12, width - tooltip.offsetWidth - 4);
|
|
499
|
+
const top =
|
|
500
|
+
event.offsetY + 12 + tooltip.offsetHeight > height
|
|
501
|
+
? event.offsetY - tooltip.offsetHeight - 8
|
|
502
|
+
: event.offsetY + 12;
|
|
503
|
+
tooltip.style.left = `${Math.max(left, 0)}px`;
|
|
504
|
+
tooltip.style.top = `${Math.max(top, 0) + BREADCRUMB_HEIGHT}px`;
|
|
505
|
+
});
|
|
506
|
+
overlay.addEventListener("mouseleave", () => {
|
|
507
|
+
hovered = null;
|
|
508
|
+
drawHover();
|
|
509
|
+
tooltip.style.display = "none";
|
|
510
|
+
});
|
|
511
|
+
overlay.addEventListener("click", (event) => {
|
|
512
|
+
if (suppressClick) {
|
|
513
|
+
suppressClick = false;
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
let node = hitTest(event.offsetX, event.offsetY);
|
|
517
|
+
if (node && !node.children) node = node.parent;
|
|
518
|
+
if (!node || node.depth === 0) return;
|
|
519
|
+
zoomTo([
|
|
520
|
+
...focusPath,
|
|
521
|
+
...node
|
|
522
|
+
.ancestors()
|
|
523
|
+
.reverse()
|
|
524
|
+
.slice(1)
|
|
525
|
+
.map((n) => n.data),
|
|
526
|
+
]);
|
|
527
|
+
});
|
|
528
|
+
overlay.addEventListener("contextmenu", (event) => {
|
|
529
|
+
if (focusPath.length === 1) return;
|
|
530
|
+
event.preventDefault();
|
|
531
|
+
zoomTo(focusPath.slice(0, -1));
|
|
532
|
+
});
|
|
533
|
+
return {
|
|
534
|
+
resize(w, h) {
|
|
535
|
+
width = w;
|
|
536
|
+
height = Math.max(h - BREADCRUMB_HEIGHT, 0);
|
|
537
|
+
const dpr = window.devicePixelRatio || 1;
|
|
538
|
+
for (const canvas of [base, overlay]) {
|
|
539
|
+
canvas.width = width * dpr;
|
|
540
|
+
canvas.height = height * dpr;
|
|
541
|
+
canvas.style.width = `${width}px`;
|
|
542
|
+
canvas.style.height = `${height}px`;
|
|
543
|
+
}
|
|
544
|
+
if (!root) {
|
|
545
|
+
buildHierarchy();
|
|
546
|
+
renderControls();
|
|
547
|
+
}
|
|
548
|
+
clampOffset();
|
|
549
|
+
layout();
|
|
550
|
+
draw();
|
|
551
|
+
},
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
let current = null;
|
|
555
|
+
discovery.view.define("treemap", (el, _config, data, context) => {
|
|
556
|
+
current?.dispose();
|
|
557
|
+
const host = el;
|
|
558
|
+
let chart = null;
|
|
559
|
+
let frame = 0;
|
|
560
|
+
const observer = new ResizeObserver(() => {
|
|
561
|
+
if (!host.isConnected) {
|
|
562
|
+
self.dispose();
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
cancelAnimationFrame(frame);
|
|
566
|
+
frame = requestAnimationFrame(() => {
|
|
567
|
+
const { clientWidth, clientHeight } = host;
|
|
568
|
+
if (clientWidth === 0 || clientHeight === 0) return;
|
|
569
|
+
try {
|
|
570
|
+
chart ??= createTreemap(host, data);
|
|
571
|
+
chart.resize(clientWidth, clientHeight);
|
|
572
|
+
} catch (e) {
|
|
573
|
+
console.error(e, data);
|
|
574
|
+
self.dispose();
|
|
575
|
+
discovery.view.render(
|
|
576
|
+
el,
|
|
577
|
+
{
|
|
578
|
+
view: "alert-danger",
|
|
579
|
+
data: '"Error rendering chart, please check the console for more information."',
|
|
580
|
+
},
|
|
581
|
+
data,
|
|
582
|
+
context,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
const self = {
|
|
588
|
+
dispose() {
|
|
589
|
+
observer.disconnect();
|
|
590
|
+
cancelAnimationFrame(frame);
|
|
591
|
+
chart = null;
|
|
592
|
+
if (current === self) current = null;
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
observer.observe(host);
|
|
596
|
+
current = self;
|
|
597
|
+
});
|
|
598
|
+
//#endregion
|
package/dist/discoveryrc.js
CHANGED
|
@@ -4,21 +4,40 @@ node_path = require_rolldown_runtime.__toESM(node_path);
|
|
|
4
4
|
//#region src/discoveryrc.ts
|
|
5
5
|
const config = {
|
|
6
6
|
name: "react-native-bundle-discovery",
|
|
7
|
-
data: () =>
|
|
8
|
-
require(
|
|
9
|
-
node_path.default.resolve(__dirname, "
|
|
10
|
-
)
|
|
7
|
+
data: () => {
|
|
8
|
+
const { withComparison, withRecommendations } = require(
|
|
9
|
+
node_path.default.resolve(__dirname, "rsdoctor.js"),
|
|
10
|
+
);
|
|
11
|
+
const report = withRecommendations(
|
|
12
|
+
require(
|
|
13
|
+
node_path.default.resolve(__dirname, "../../../tmp/metro-stats.json"),
|
|
14
|
+
),
|
|
15
|
+
);
|
|
16
|
+
const before =
|
|
17
|
+
process.env.COMPARE && node_path.default.resolve(process.env.COMPARE);
|
|
18
|
+
return before ? withComparison(report, require(before), before) : report;
|
|
19
|
+
},
|
|
11
20
|
setup: node_path.default.resolve(__dirname, "client/setup.js"),
|
|
12
21
|
view: {
|
|
13
22
|
assets: [
|
|
14
23
|
node_path.default.resolve(__dirname, "../assets/global.css"),
|
|
15
24
|
node_path.default.resolve(__dirname, "client/pages/default.js"),
|
|
16
25
|
node_path.default.resolve(__dirname, "client/pages/module.js"),
|
|
26
|
+
node_path.default.resolve(__dirname, "client/pages/moduleDiff.js"),
|
|
17
27
|
node_path.default.resolve(__dirname, "client/pages/package.js"),
|
|
18
|
-
node_path.default.resolve(__dirname, "../assets/highcharts.css"),
|
|
19
28
|
node_path.default.resolve(__dirname, "client/views/prettify.js"),
|
|
20
|
-
node_path.default.resolve(__dirname, "client/views/
|
|
21
|
-
node_path.default.resolve(__dirname, "client/views/
|
|
29
|
+
node_path.default.resolve(__dirname, "client/views/importGraph.js"),
|
|
30
|
+
node_path.default.resolve(__dirname, "client/views/moduleOverview.js"),
|
|
31
|
+
node_path.default.resolve(__dirname, "client/views/packageOverview.js"),
|
|
32
|
+
node_path.default.resolve(__dirname, "client/views/insights.js"),
|
|
33
|
+
node_path.default.resolve(__dirname, "client/views/compare.js"),
|
|
34
|
+
node_path.default.resolve(__dirname, "client/views/codeDiff.js"),
|
|
35
|
+
node_path.default.resolve(__dirname, "client/views/reportBar.js"),
|
|
36
|
+
node_path.default.resolve(__dirname, "client/views/treemap.js"),
|
|
37
|
+
node_path.default.resolve(
|
|
38
|
+
__dirname,
|
|
39
|
+
"client/views/persistedFilterInput.js",
|
|
40
|
+
),
|
|
22
41
|
],
|
|
23
42
|
},
|
|
24
43
|
};
|