@buoy-gg/assets 7.0.29 → 7.0.31

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.
Files changed (95) hide show
  1. package/lib/commonjs/components/AssetDetail.js +10 -1
  2. package/lib/commonjs/components/AssetDetail.js.map +1 -1
  3. package/lib/commonjs/components/AssetRow.js +13 -4
  4. package/lib/commonjs/components/AssetRow.js.map +1 -1
  5. package/lib/commonjs/components/AssetsFilterBar.js +4 -0
  6. package/lib/commonjs/components/AssetsFilterBar.js.map +1 -1
  7. package/lib/commonjs/components/AssetsHeader.js +11 -5
  8. package/lib/commonjs/components/AssetsHeader.js.map +1 -1
  9. package/lib/commonjs/components/AssetsListControls.js +5 -3
  10. package/lib/commonjs/components/AssetsListControls.js.map +1 -1
  11. package/lib/commonjs/components/AssetsModal.js +10 -0
  12. package/lib/commonjs/components/AssetsModal.js.map +1 -1
  13. package/lib/commonjs/components/BaselineBar.js +5 -0
  14. package/lib/commonjs/components/BaselineBar.js.map +1 -1
  15. package/lib/commonjs/index.js +53 -0
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/store/assetStore.js +8 -1
  18. package/lib/commonjs/store/assetStore.js.map +1 -1
  19. package/lib/commonjs/store/baseline.js +9 -1
  20. package/lib/commonjs/store/baseline.js.map +1 -1
  21. package/lib/commonjs/store/insights.js +2 -11
  22. package/lib/commonjs/store/insights.js.map +1 -1
  23. package/lib/commonjs/utils/deviceScale.js +50 -0
  24. package/lib/commonjs/utils/deviceScale.js.map +1 -0
  25. package/lib/commonjs/utils/testIDs.js +114 -0
  26. package/lib/commonjs/utils/testIDs.js.map +1 -0
  27. package/lib/module/components/AssetDetail.js +10 -1
  28. package/lib/module/components/AssetDetail.js.map +1 -1
  29. package/lib/module/components/AssetRow.js +13 -4
  30. package/lib/module/components/AssetRow.js.map +1 -1
  31. package/lib/module/components/AssetsFilterBar.js +4 -0
  32. package/lib/module/components/AssetsFilterBar.js.map +1 -1
  33. package/lib/module/components/AssetsHeader.js +11 -5
  34. package/lib/module/components/AssetsHeader.js.map +1 -1
  35. package/lib/module/components/AssetsListControls.js +5 -3
  36. package/lib/module/components/AssetsListControls.js.map +1 -1
  37. package/lib/module/components/AssetsModal.js +10 -0
  38. package/lib/module/components/AssetsModal.js.map +1 -1
  39. package/lib/module/components/BaselineBar.js +5 -0
  40. package/lib/module/components/BaselineBar.js.map +1 -1
  41. package/lib/module/index.js +4 -0
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/store/assetStore.js +8 -1
  44. package/lib/module/store/assetStore.js.map +1 -1
  45. package/lib/module/store/baseline.js +9 -1
  46. package/lib/module/store/baseline.js.map +1 -1
  47. package/lib/module/store/insights.js +1 -10
  48. package/lib/module/store/insights.js.map +1 -1
  49. package/lib/module/utils/deviceScale.js +46 -0
  50. package/lib/module/utils/deviceScale.js.map +1 -0
  51. package/lib/module/utils/testIDs.js +103 -0
  52. package/lib/module/utils/testIDs.js.map +1 -0
  53. package/lib/typescript/components/AssetDetail.d.ts.map +1 -1
  54. package/lib/typescript/components/AssetRow.d.ts.map +1 -1
  55. package/lib/typescript/components/AssetsFilterBar.d.ts.map +1 -1
  56. package/lib/typescript/components/AssetsHeader.d.ts.map +1 -1
  57. package/lib/typescript/components/AssetsListControls.d.ts.map +1 -1
  58. package/lib/typescript/components/AssetsModal.d.ts.map +1 -1
  59. package/lib/typescript/components/BaselineBar.d.ts.map +1 -1
  60. package/lib/typescript/index.d.ts +1 -0
  61. package/lib/typescript/index.d.ts.map +1 -1
  62. package/lib/typescript/store/assetStore.d.ts +6 -0
  63. package/lib/typescript/store/assetStore.d.ts.map +1 -1
  64. package/lib/typescript/store/baseline.d.ts.map +1 -1
  65. package/lib/typescript/store/insights.d.ts.map +1 -1
  66. package/lib/typescript/utils/deviceScale.d.ts +25 -0
  67. package/lib/typescript/utils/deviceScale.d.ts.map +1 -0
  68. package/lib/typescript/utils/testIDs.d.ts +75 -0
  69. package/lib/typescript/utils/testIDs.d.ts.map +1 -0
  70. package/package.json +5 -6
  71. package/src/capture/expo.ts +0 -45
  72. package/src/capture/install.ts +0 -73
  73. package/src/capture/measure.ts +0 -167
  74. package/src/capture/metroGraph.ts +0 -146
  75. package/src/capture/registry.ts +0 -137
  76. package/src/components/AssetDetail.tsx +0 -207
  77. package/src/components/AssetRow.tsx +0 -243
  78. package/src/components/AssetsFilterBar.tsx +0 -99
  79. package/src/components/AssetsHeader.tsx +0 -75
  80. package/src/components/AssetsIcon.tsx +0 -9
  81. package/src/components/AssetsListControls.tsx +0 -101
  82. package/src/components/AssetsModal.tsx +0 -371
  83. package/src/components/BaselineBar.tsx +0 -98
  84. package/src/export.ts +0 -110
  85. package/src/format.ts +0 -53
  86. package/src/hooks/useAssetRecords.ts +0 -26
  87. package/src/index.tsx +0 -87
  88. package/src/preset.tsx +0 -35
  89. package/src/remote.ts +0 -65
  90. package/src/state.ts +0 -84
  91. package/src/store/assetStore.ts +0 -209
  92. package/src/store/baseline.ts +0 -152
  93. package/src/store/insights.ts +0 -145
  94. package/src/sync/assetsSyncAdapter.ts +0 -151
  95. package/src/types.ts +0 -160
@@ -1,167 +0,0 @@
1
- /**
2
- * Byte-size measurement.
3
- *
4
- * Dev only in practice: each scale variant is fetched from the Metro dev
5
- * server (HEAD first for Content-Length, GET-blob fallback since Metro
6
- * doesn't reliably answer HEAD) and the per-variant sizes are summed onto
7
- * the record. Android release resource ids and iOS file:// URIs are not
8
- * measurable from JS — those records keep `estDecodedBytes` as their only
9
- * size signal and the UI marks them as estimates.
10
- */
11
-
12
- import { assetsState } from "../state";
13
- import { getSnapshot, invalidate, updateRecord } from "../store/assetStore";
14
- import { getDevServerOrigin } from "./metroGraph";
15
- import type { AssetRecord } from "../types";
16
-
17
- const CONCURRENCY = 4;
18
-
19
- /**
20
- * Best displayable URL for a record: the resolved runtime URI, or (dev) the
21
- * same dev-server URL the measurement pass uses — this is what gives graph-
22
- * only (never-loaded) images real thumbnails.
23
- */
24
- export function previewURL(record: AssetRecord): string | null {
25
- if (record.resolvedUri) return record.resolvedUri;
26
- const variants = variantURLs(record);
27
- return variants.length ? variants[0]!.url : null;
28
- }
29
-
30
- /**
31
- * Image source for thumbnails/previews. On device the NUMERIC registry id is
32
- * preferred (resolves natively — works for Android release resource ids too).
33
- * On dashboard mirrors that id belongs to the DEVICE's registry and rn-web
34
- * throws "asset with ID N could not be found" — use the device's http(s)
35
- * URL instead (the Metro dev server is reachable from the desktop).
36
- */
37
- export function displaySource(
38
- record: AssetRecord
39
- ): number | { uri: string } | null {
40
- const mirror = assetsState().captureDisabled;
41
- if (!mirror && record.registryId != null) return record.registryId;
42
- const uri = previewURL(record);
43
- if (!uri) return null;
44
- if (mirror && !/^https?:\/\//.test(uri)) return null;
45
- return { uri };
46
- }
47
-
48
- /** All scale-variant URLs for a record, derived without re-encoding pitfalls. */
49
- export function variantURLs(record: AssetRecord): Array<{ scale: number; url: string }> {
50
- const scales = record.scales.length ? record.scales : [1];
51
-
52
- // Preferred: string surgery on the URL resolveAssetSource already proved
53
- // works (handles Expo's ?unstable_path= form and monorepo rewrites).
54
- const resolved = record.resolvedUri;
55
- if (resolved && /^https?:\/\//.test(resolved) && record.resolvedScale != null) {
56
- const pickedSuffix = record.resolvedScale === 1 ? "" : `@${record.resolvedScale}x`;
57
- const marker = `${pickedSuffix}.${record.type}`;
58
- if (resolved.includes(marker) || pickedSuffix === "") {
59
- return scales.map((scale) => {
60
- const suffix = scale === 1 ? "" : `@${scale}x`;
61
- const url = (
62
- pickedSuffix === ""
63
- ? resolved.replace(`.${record.type}`, `${suffix}.${record.type}`)
64
- : resolved.replace(marker, `${suffix}.${record.type}`)
65
- ).replace(/ /g, "%20"); // RN's asset path builder doesn't encode spaces
66
- return { scale, url };
67
- });
68
- }
69
- }
70
-
71
- // Graph-only records: rebuild the dev-server URL the way Metro's
72
- // AssetSourceResolver does (plain concatenation), encoding only spaces —
73
- // full encodeURI would double-encode Expo's pre-escaped unstable_path.
74
- const origin = getDevServerOrigin();
75
- if (!origin || !record.httpServerLocation) return [];
76
- return scales.map((scale) => {
77
- const suffix = scale === 1 ? "" : `@${scale}x`;
78
- const path = `${record.httpServerLocation}/${record.name}${suffix}.${record.type}`;
79
- const sep = path.includes("?") ? "&" : "?";
80
- const url = `${origin}${path}${sep}platform=${platformName()}${
81
- record.hash ? `&hash=${record.hash}` : ""
82
- }`.replace(/ /g, "%20");
83
- return { scale, url };
84
- });
85
- }
86
-
87
- function platformName(): string {
88
- try {
89
- return require("react-native").Platform.OS;
90
- } catch {
91
- return "ios";
92
- }
93
- }
94
-
95
- async function fetchSize(url: string): Promise<number | null> {
96
- try {
97
- const head = await fetch(url, { method: "HEAD" });
98
- if (head.ok) {
99
- const length = Number(head.headers.get("content-length"));
100
- if (Number.isFinite(length) && length > 0) return length;
101
- }
102
- } catch {
103
- // fall through to GET
104
- }
105
- try {
106
- const response = await fetch(url);
107
- if (!response.ok) return null;
108
- const blob = await response.blob();
109
- return blob.size > 0 ? blob.size : null;
110
- } catch {
111
- return null;
112
- }
113
- }
114
-
115
- async function measureRecord(record: AssetRecord): Promise<void> {
116
- const variants = variantURLs(record);
117
- if (!variants.length) {
118
- updateRecord(record.id, { sizeSource: "estimate" });
119
- return;
120
- }
121
- const sizesByScale: Record<string, number> = {};
122
- let total = 0;
123
- for (const { scale, url } of variants) {
124
- const size = await fetchSize(url);
125
- if (size != null) {
126
- sizesByScale[String(scale)] = size;
127
- total += size;
128
- }
129
- }
130
- if (total > 0) {
131
- updateRecord(record.id, { sizesByScale, sizeBytes: total, sizeSource: "measured" });
132
- } else {
133
- updateRecord(record.id, { sizeSource: "estimate" });
134
- }
135
- }
136
-
137
- /** Measure every unmeasured record; safe to re-run (skips measured ones). */
138
- export async function measureSizes(): Promise<{ measured: number; total: number }> {
139
- const s = assetsState();
140
- if (s.measuring) return { measured: s.measuredCount, total: getSnapshot().length };
141
- const pending = getSnapshot().filter((r) => r.sizeSource !== "measured");
142
- s.measuring = true;
143
- invalidate();
144
- try {
145
- let index = 0;
146
- const worker = async () => {
147
- for (;;) {
148
- const next = pending[index++];
149
- if (!next) return;
150
- await measureRecord(next);
151
- s.measuredCount = getSnapshot().filter(
152
- (r) => r.sizeSource === "measured"
153
- ).length;
154
- }
155
- };
156
- await Promise.all(
157
- Array.from({ length: Math.min(CONCURRENCY, pending.length) }, worker)
158
- );
159
- } finally {
160
- s.measuring = false;
161
- invalidate();
162
- }
163
- return {
164
- measured: s.measuredCount,
165
- total: getSnapshot().length,
166
- };
167
- }
@@ -1,146 +0,0 @@
1
- /**
2
- * Metro dev-server graph fetch.
3
- *
4
- * The dev server serves `<entry>.assets` next to `<entry>.bundle` — the full
5
- * dependency graph's AssetData[], INCLUDING assets never required at runtime
6
- * and the `fileSystemLocation`/`files` fields Metro strips from runtime
7
- * records. Deriving the URL by swapping `.bundle` → `.assets` on the running
8
- * bundle's scriptURL keeps the entry path and platform/dev query params
9
- * intact for both RN CLI (index.bundle) and Expo (…/entry.bundle) layouts.
10
- *
11
- * Graph-only records (in the graph, not the registry) are exactly the
12
- * "shipped but never loaded" set. Dev-only: no server, no graph.
13
- */
14
-
15
- import { assetsState } from "../state";
16
- import { assetKey, invalidate, upsertRecord } from "../store/assetStore";
17
-
18
- interface GraphAssetData {
19
- __packager_asset?: boolean;
20
- fileSystemLocation?: string;
21
- httpServerLocation: string;
22
- width?: number | null;
23
- height?: number | null;
24
- scales: number[];
25
- files?: string[];
26
- fileHashes?: string[];
27
- hash: string;
28
- name: string;
29
- type: string;
30
- }
31
-
32
- export function getScriptURL(): string | null {
33
- try {
34
- const { NativeModules } = require("react-native");
35
- const sourceCode = NativeModules?.SourceCode;
36
- const url: unknown =
37
- sourceCode?.getConstants?.().scriptURL ?? sourceCode?.scriptURL;
38
- return typeof url === "string" ? url : null;
39
- } catch {
40
- return null;
41
- }
42
- }
43
-
44
- /** http(s) origin of the Metro dev server, or null when running embedded. */
45
- export function getDevServerOrigin(): string | null {
46
- const scriptURL = getScriptURL();
47
- const match = scriptURL?.match(/^https?:\/\/[^/]+/);
48
- return match ? match[0] : null;
49
- }
50
-
51
- /**
52
- * Candidate graph URLs, most-likely first. The straight `.bundle`→`.assets`
53
- * swap works for RN CLI, but Expo dev builds serve a VIRTUAL entry
54
- * (.expo/.virtual-metro-entry.bundle) that only exists for .bundle requests —
55
- * its .assets twin 404s — so the real entry modules are tried next, keeping
56
- * the original query string (platform/dev/etc.) intact.
57
- */
58
- export function getGraphURLCandidates(): string[] {
59
- const scriptURL = getScriptURL();
60
- if (!scriptURL || !/^https?:\/\//.test(scriptURL)) return [];
61
- const origin = getDevServerOrigin();
62
- const queryIndex = scriptURL.indexOf("?");
63
- const query = queryIndex >= 0 ? scriptURL.slice(queryIndex) : "?platform=ios&dev=true";
64
- const candidates: string[] = [];
65
- if (scriptURL.includes(".bundle")) {
66
- candidates.push(scriptURL.replace(".bundle", ".assets"));
67
- }
68
- if (origin) {
69
- candidates.push(
70
- `${origin}/node_modules/expo-router/entry.assets${query}`,
71
- `${origin}/node_modules/expo/AppEntry.assets${query}`,
72
- `${origin}/index.assets${query}`
73
- );
74
- }
75
- return candidates;
76
- }
77
-
78
- /** Fetch the full asset graph from the dev server and merge it into the store. */
79
- export async function fetchAssetGraph(): Promise<
80
- { ok: true; count: number } | { ok: false; message: string }
81
- > {
82
- const s = assetsState();
83
- const candidates = getGraphURLCandidates();
84
- if (!candidates.length) {
85
- s.graphSupported = false;
86
- s.graphError = "No Metro dev server (embedded bundle)";
87
- invalidate();
88
- return { ok: false, message: s.graphError };
89
- }
90
- if (s.graphFetchInFlight) return { ok: false, message: "Graph fetch already running" };
91
- s.graphFetchInFlight = true;
92
- try {
93
- let data: unknown = null;
94
- let lastError = "";
95
- for (const url of candidates) {
96
- try {
97
- const response = await fetch(url);
98
- if (!response.ok) {
99
- lastError = `Metro responded ${response.status} for ${url}`;
100
- continue;
101
- }
102
- const parsed: unknown = await response.json();
103
- if (Array.isArray(parsed)) {
104
- data = parsed;
105
- break;
106
- }
107
- lastError = "Unexpected .assets payload shape";
108
- } catch (error) {
109
- lastError = String((error as Error)?.message ?? error);
110
- }
111
- }
112
- if (!Array.isArray(data)) throw new Error(lastError || "No graph endpoint answered");
113
- const graph = data as GraphAssetData[];
114
- for (const asset of graph) {
115
- if (!asset || typeof asset.name !== "string" || typeof asset.type !== "string") {
116
- continue;
117
- }
118
- upsertRecord({
119
- key: assetKey(asset.httpServerLocation, asset.name, asset.type),
120
- name: asset.name,
121
- type: asset.type,
122
- origin: "graph",
123
- hash: asset.hash,
124
- httpServerLocation: asset.httpServerLocation,
125
- width: asset.width ?? undefined,
126
- height: asset.height ?? undefined,
127
- scales: asset.scales,
128
- fileSystemLocation: asset.fileSystemLocation,
129
- files: asset.files,
130
- fileHashes: asset.fileHashes,
131
- });
132
- }
133
- s.graphSupported = true;
134
- s.graphCount = graph.length;
135
- s.graphError = null;
136
- invalidate();
137
- return { ok: true, count: graph.length };
138
- } catch (error) {
139
- s.graphSupported = getDevServerOrigin() != null;
140
- s.graphError = String((error as Error)?.message ?? error);
141
- invalidate();
142
- return { ok: false, message: s.graphError };
143
- } finally {
144
- s.graphFetchInFlight = false;
145
- }
146
- }
@@ -1,137 +0,0 @@
1
- /**
2
- * Runtime access to @react-native/assets-registry.
3
- *
4
- * Asset ids are contiguous 1..N (`assets.push` return value), so a plain
5
- * getAssetByID walk enumerates every asset registered so far — including
6
- * everything registered BEFORE this tool was evaluated. That's why, unlike
7
- * the images tool, there is no "must be the first import" requirement here:
8
- * the walk backfills whatever the patch missed.
9
- *
10
- * registerAsset is patched (plain non-frozen CommonJS export, looked up at
11
- * call time by Metro's generated asset modules) purely for LIVE updates as
12
- * lazily-required assets register later.
13
- */
14
-
15
- import { upsertRecord, assetKey } from "../store/assetStore";
16
- import type { AssetRecord } from "../types";
17
-
18
- /** Runtime shape of a registry entry (fileSystemLocation/files are stripped by Metro). */
19
- export interface PackagerAsset {
20
- __packager_asset: boolean;
21
- httpServerLocation: string;
22
- width?: number | null;
23
- height?: number | null;
24
- scales: number[];
25
- hash: string;
26
- name: string;
27
- type: string;
28
- }
29
-
30
- interface RegistryModule {
31
- registerAsset: (asset: PackagerAsset) => number;
32
- getAssetByID: (assetId: number) => PackagerAsset | undefined;
33
- }
34
-
35
- let cachedRegistry: RegistryModule | null | undefined;
36
-
37
- export function getRegistryModule(): RegistryModule | null {
38
- if (cachedRegistry !== undefined) return cachedRegistry;
39
- let mod: RegistryModule | null = null;
40
- try {
41
- mod = require("@react-native/assets-registry/registry");
42
- } catch {
43
- // Old RN layouts (< 0.72) don't ship @react-native/assets-registry as a
44
- // resolvable package — the registry only exists at this deep path. RN's
45
- // deep-import deprecation warning fires when this executes, but it only
46
- // executes on those old layouts, where there is no other way in.
47
- try {
48
- mod = require("react-native/Libraries/Image/AssetRegistry");
49
- } catch {
50
- mod = null;
51
- }
52
- }
53
- cachedRegistry =
54
- mod && typeof mod.getAssetByID === "function" ? mod : null;
55
- return cachedRegistry;
56
- }
57
-
58
- /** resolveAssetSource(id) → this environment's URI (dev URL / file:// / res id). */
59
- export function resolveRegistryAsset(
60
- registryId: number
61
- ): { uri: string; scale: number } | null {
62
- try {
63
- const { Image } = require("react-native");
64
- const resolved = Image.resolveAssetSource(registryId);
65
- if (resolved && typeof resolved.uri === "string") {
66
- return { uri: resolved.uri, scale: resolved.scale ?? 1 };
67
- }
68
- } catch {
69
- // resolution is enrichment — never let it break the walk
70
- }
71
- return null;
72
- }
73
-
74
- export function upsertFromPackagerAsset(
75
- registryId: number,
76
- asset: PackagerAsset
77
- ): AssetRecord {
78
- const resolved = resolveRegistryAsset(registryId);
79
- return upsertRecord({
80
- key: assetKey(asset.httpServerLocation, asset.name, asset.type),
81
- name: asset.name,
82
- type: asset.type,
83
- origin: "registry",
84
- registryId,
85
- hash: asset.hash,
86
- httpServerLocation: asset.httpServerLocation,
87
- width: asset.width ?? undefined,
88
- height: asset.height ?? undefined,
89
- scales: asset.scales,
90
- resolvedUri: resolved?.uri,
91
- resolvedScale: resolved?.scale,
92
- loaded: true,
93
- });
94
- }
95
-
96
- /** Enumerate every asset registered so far. Returns the highest id seen. */
97
- export function walkRegistry(): number {
98
- const registry = getRegistryModule();
99
- if (!registry) return 0;
100
- let id = 0;
101
- for (;;) {
102
- const asset = registry.getAssetByID(id + 1);
103
- if (!asset) break;
104
- id++;
105
- upsertFromPackagerAsset(id, asset);
106
- }
107
- return id;
108
- }
109
-
110
- const PATCH_MARKER = "__buoyAssetsPatched";
111
-
112
- /**
113
- * Wrap registerAsset so future registrations stream in live. Safe to call
114
- * more than once (marker guard); the walk covers anything registered before.
115
- */
116
- export function patchRegisterAsset(): boolean {
117
- const registry = getRegistryModule();
118
- if (!registry) return false;
119
- const original = registry.registerAsset;
120
- if ((original as unknown as Record<string, unknown>)[PATCH_MARKER]) return true;
121
- const wrapped = (asset: PackagerAsset): number => {
122
- const id = original.call(registry, asset);
123
- try {
124
- upsertFromPackagerAsset(id, asset);
125
- } catch {
126
- // never break app asset registration
127
- }
128
- return id;
129
- };
130
- (wrapped as unknown as Record<string, unknown>)[PATCH_MARKER] = true;
131
- try {
132
- registry.registerAsset = wrapped;
133
- } catch {
134
- return false;
135
- }
136
- return true;
137
- }
@@ -1,207 +0,0 @@
1
- /**
2
- * AssetDetail — full metadata for one asset: preview, identity, dimensions,
3
- * per-scale sizes, resolution info, and which audit findings apply.
4
- *
5
- * Image previews render through the numeric registry id (works in every
6
- * environment); fonts render a pangram with fontFamily set to the asset name
7
- * — a best-effort guess (family ≠ filename for many fonts) that falls back
8
- * to the system font silently when it misses.
9
- */
10
-
11
- import { Image, ScrollView, StyleSheet, Text, View } from "react-native";
12
- import { night } from "@buoy-gg/shared-ui";
13
- import { displaySource } from "../capture/measure";
14
- import { formatBytes, formatDimensions, formatScales } from "../format";
15
- import { estDecodedBytes } from "../store/assetStore";
16
- import type { AssetRecord, AssetsInsights } from "../types";
17
-
18
- interface AssetDetailProps {
19
- record: AssetRecord;
20
- insights: AssetsInsights;
21
- }
22
-
23
- function Row({ label, value }: { label: string; value: string }) {
24
- return (
25
- <View style={styles.kvRow}>
26
- <Text style={styles.kvLabel}>{label}</Text>
27
- <Text style={styles.kvValue} selectable>
28
- {value}
29
- </Text>
30
- </View>
31
- );
32
- }
33
-
34
- function Preview({ record }: { record: AssetRecord }) {
35
- if (record.kind === "image") {
36
- const source = displaySource(record);
37
- if (source == null) return null;
38
- return (
39
- <View style={styles.previewBox}>
40
- <Image
41
- testID="buoy-internal-assets-preview"
42
- source={source}
43
- style={styles.previewImage}
44
- resizeMode="contain"
45
- />
46
- </View>
47
- );
48
- }
49
- if (record.kind === "font") {
50
- return (
51
- <View style={styles.previewBox}>
52
- <Text style={[styles.fontPreview, { fontFamily: record.name }]}>
53
- The quick brown fox jumps over the lazy dog 0123456789
54
- </Text>
55
- </View>
56
- );
57
- }
58
- return null;
59
- }
60
-
61
- export function AssetDetail({ record, insights }: AssetDetailProps) {
62
- const findings: string[] = [];
63
- if (insights.neverLoaded.includes(record.id)) {
64
- findings.push("Never loaded — shipped in the bundle but no code required it");
65
- }
66
- if (insights.scaleGaps.includes(record.id)) {
67
- findings.push("Scale gap — no variant covers this device's pixel ratio");
68
- }
69
- if (insights.webpCandidates.includes(record.id)) {
70
- findings.push("WebP candidate — large png/jpeg, converting typically saves 20–40%");
71
- }
72
- const duplicate = insights.duplicates.find((d) => d.ids.includes(record.id));
73
- if (duplicate) {
74
- findings.push(
75
- `Duplicate content — identical bytes shipped ${duplicate.ids.length} times`
76
- );
77
- }
78
- if (insights.overDecode.includes(record.id)) {
79
- findings.push(
80
- "Decodes larger than 2× this entire screen — resize the source, no view can need this many pixels"
81
- );
82
- }
83
- if (insights.heavyGifs.includes(record.id)) {
84
- findings.push(
85
- "Heavy GIF — every frame decodes into memory; a video or Lottie is typically ~90% smaller"
86
- );
87
- }
88
- if (insights.heavyFonts.includes(record.id)) {
89
- findings.push(
90
- "Heavy font — likely an unsubset icon font; subsetting to used glyphs usually saves most of it"
91
- );
92
- }
93
- if (insights.scaleAnomalies.includes(record.id)) {
94
- findings.push(
95
- "Scale anomaly — a higher-resolution variant is smaller in bytes than a lower one; check the exports"
96
- );
97
- }
98
-
99
- const estimate = estDecodedBytes(record);
100
-
101
- return (
102
- <ScrollView style={styles.scroll} contentContainerStyle={styles.content}>
103
- <Preview record={record} />
104
-
105
- {findings.length > 0 ? (
106
- <View style={styles.findings}>
107
- {findings.map((finding) => (
108
- <Text key={finding} style={styles.findingText}>
109
- {finding}
110
- </Text>
111
- ))}
112
- </View>
113
- ) : null}
114
-
115
- <Row label="Name" value={`${record.name}.${record.type}`} />
116
- <Row label="Kind" value={record.kind} />
117
- <Row
118
- label="Status"
119
- value={record.loaded ? "Loaded (registered at runtime)" : "In bundle, never loaded"}
120
- />
121
- {record.kind === "image" ? (
122
- <Row label="Dimensions" value={`${formatDimensions(record)} (logical)`} />
123
- ) : null}
124
- {record.kind === "image" && record.scales.length ? (
125
- <Row label="Scales" value={formatScales(record.scales)} />
126
- ) : null}
127
-
128
- {record.sizesByScale
129
- ? Object.entries(record.sizesByScale).map(([scale, bytes]) => (
130
- <Row key={scale} label={`Size @${scale}x`} value={formatBytes(bytes)} />
131
- ))
132
- : null}
133
- {record.sizeBytes != null && record.sizeSource === "measured" ? (
134
- <Row label="Total size" value={formatBytes(record.sizeBytes)} />
135
- ) : null}
136
- {estimate > 0 ? (
137
- <Row label="Decoded memory" value={`~${formatBytes(estimate)} (RGBA)`} />
138
- ) : null}
139
-
140
- {record.registryId != null ? (
141
- <Row label="Registry id" value={String(record.registryId)} />
142
- ) : null}
143
- {record.hash ? <Row label="Hash" value={record.hash} /> : null}
144
- {record.httpServerLocation ? (
145
- <Row label="Location" value={record.httpServerLocation} />
146
- ) : null}
147
- {record.fileSystemLocation ? (
148
- <Row label="Source dir" value={record.fileSystemLocation} />
149
- ) : null}
150
- {record.resolvedUri ? <Row label="Resolved URI" value={record.resolvedUri} /> : null}
151
- </ScrollView>
152
- );
153
- }
154
-
155
- const styles = StyleSheet.create({
156
- scroll: {
157
- flex: 1,
158
- },
159
- content: {
160
- padding: 12,
161
- gap: 8,
162
- },
163
- previewBox: {
164
- borderRadius: 8,
165
- backgroundColor: night.color.bg,
166
- padding: 12,
167
- alignItems: "center",
168
- justifyContent: "center",
169
- minHeight: 96,
170
- },
171
- previewImage: {
172
- width: "100%",
173
- height: 140,
174
- },
175
- fontPreview: {
176
- color: night.color.text,
177
- fontSize: 16,
178
- textAlign: "center",
179
- },
180
- findings: {
181
- borderRadius: 8,
182
- borderWidth: 1,
183
- borderColor: night.color.border,
184
- backgroundColor: night.color.surface,
185
- padding: 10,
186
- gap: 6,
187
- },
188
- findingText: {
189
- color: night.color.textSecondary,
190
- fontSize: 11,
191
- lineHeight: 15,
192
- },
193
- kvRow: {
194
- gap: 2,
195
- },
196
- kvLabel: {
197
- color: night.color.textTertiary,
198
- fontSize: 9,
199
- fontWeight: "700",
200
- letterSpacing: 0.5,
201
- textTransform: "uppercase",
202
- },
203
- kvValue: {
204
- color: night.color.text,
205
- fontSize: 12,
206
- },
207
- });