@buoy-gg/assets 7.0.35 → 7.0.38

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 (165) hide show
  1. package/README.md +41 -12
  2. package/lib/commonjs/capture/expo.js +1 -46
  3. package/lib/commonjs/capture/install.js +1 -78
  4. package/lib/commonjs/capture/isBuoyAsset.js +1 -0
  5. package/lib/commonjs/capture/measure.js +1 -186
  6. package/lib/commonjs/capture/metroGraph.js +1 -148
  7. package/lib/commonjs/capture/registry.js +1 -127
  8. package/lib/commonjs/components/AssetDetail.js +1 -214
  9. package/lib/commonjs/components/AssetImage.js +1 -0
  10. package/lib/commonjs/components/AssetRow.js +1 -233
  11. package/lib/commonjs/components/AssetsFilterBar.js +1 -96
  12. package/lib/commonjs/components/AssetsHeader.js +1 -72
  13. package/lib/commonjs/components/AssetsIcon.js +1 -19
  14. package/lib/commonjs/components/AssetsListControls.js +1 -96
  15. package/lib/commonjs/components/AssetsModal.js +1 -347
  16. package/lib/commonjs/components/ScanNotice.js +1 -0
  17. package/lib/commonjs/components/optionalExpoImage.js +1 -0
  18. package/lib/commonjs/components/optionalExpoImage.web.js +1 -0
  19. package/lib/commonjs/export.js +1 -62
  20. package/lib/commonjs/format.js +1 -59
  21. package/lib/commonjs/hooks/useAssetRecords.js +1 -22
  22. package/lib/commonjs/hooks/useAssetScanStatus.js +1 -0
  23. package/lib/commonjs/index.js +1 -313
  24. package/lib/commonjs/preset.js +1 -39
  25. package/lib/commonjs/remote.js +1 -65
  26. package/lib/commonjs/state.js +1 -51
  27. package/lib/commonjs/store/assetStore.js +1 -241
  28. package/lib/commonjs/store/baseline.js +1 -173
  29. package/lib/commonjs/store/insights.js +1 -120
  30. package/lib/commonjs/sync/assetsSyncAdapter.js +1 -157
  31. package/lib/commonjs/types.js +1 -2
  32. package/lib/commonjs/utils/deviceScale.js +1 -50
  33. package/lib/commonjs/utils/testIDs.js +1 -114
  34. package/lib/module/capture/expo.js +1 -41
  35. package/lib/module/capture/install.js +1 -72
  36. package/lib/module/capture/isBuoyAsset.js +1 -0
  37. package/lib/module/capture/measure.js +1 -179
  38. package/lib/module/capture/metroGraph.js +1 -141
  39. package/lib/module/capture/registry.js +1 -120
  40. package/lib/module/components/AssetDetail.js +1 -210
  41. package/lib/module/components/AssetImage.js +1 -0
  42. package/lib/module/components/AssetRow.js +1 -229
  43. package/lib/module/components/AssetsFilterBar.js +1 -92
  44. package/lib/module/components/AssetsHeader.js +1 -68
  45. package/lib/module/components/AssetsIcon.js +1 -12
  46. package/lib/module/components/AssetsListControls.js +1 -92
  47. package/lib/module/components/AssetsModal.js +1 -342
  48. package/lib/module/components/ScanNotice.js +1 -0
  49. package/lib/module/components/optionalExpoImage.js +1 -0
  50. package/lib/module/components/optionalExpoImage.web.js +1 -0
  51. package/lib/module/export.js +1 -57
  52. package/lib/module/format.js +1 -51
  53. package/lib/module/hooks/useAssetRecords.js +1 -18
  54. package/lib/module/hooks/useAssetScanStatus.js +1 -0
  55. package/lib/module/index.js +1 -63
  56. package/lib/module/preset.js +1 -35
  57. package/lib/module/remote.js +1 -58
  58. package/lib/module/state.js +1 -47
  59. package/lib/module/store/assetStore.js +1 -226
  60. package/lib/module/store/baseline.js +1 -165
  61. package/lib/module/store/insights.js +1 -116
  62. package/lib/module/sync/assetsSyncAdapter.js +1 -153
  63. package/lib/module/types.js +1 -2
  64. package/lib/module/utils/deviceScale.js +1 -46
  65. package/lib/module/utils/testIDs.js +1 -103
  66. package/lib/typescript/capture/isBuoyAsset.d.ts +9 -0
  67. package/lib/typescript/capture/registry.d.ts +1 -1
  68. package/lib/typescript/components/AssetDetail.d.ts +2 -2
  69. package/lib/typescript/components/AssetImage.d.ts +9 -0
  70. package/lib/typescript/components/AssetsFilterBar.d.ts +3 -2
  71. package/lib/typescript/components/AssetsHeader.d.ts +2 -1
  72. package/lib/typescript/components/AssetsListControls.d.ts +2 -9
  73. package/lib/typescript/components/ScanNotice.d.ts +7 -0
  74. package/lib/typescript/components/optionalExpoImage.d.ts +13 -0
  75. package/lib/typescript/components/optionalExpoImage.web.d.ts +3 -0
  76. package/lib/typescript/hooks/useAssetScanStatus.d.ts +6 -0
  77. package/lib/typescript/state.d.ts +2 -0
  78. package/lib/typescript/store/assetStore.d.ts +3 -1
  79. package/lib/typescript/types.d.ts +3 -0
  80. package/lib/typescript/utils/testIDs.d.ts +2 -5
  81. package/package.json +8 -4
  82. package/lib/commonjs/capture/expo.js.map +0 -1
  83. package/lib/commonjs/capture/install.js.map +0 -1
  84. package/lib/commonjs/capture/measure.js.map +0 -1
  85. package/lib/commonjs/capture/metroGraph.js.map +0 -1
  86. package/lib/commonjs/capture/registry.js.map +0 -1
  87. package/lib/commonjs/components/AssetDetail.js.map +0 -1
  88. package/lib/commonjs/components/AssetRow.js.map +0 -1
  89. package/lib/commonjs/components/AssetsFilterBar.js.map +0 -1
  90. package/lib/commonjs/components/AssetsHeader.js.map +0 -1
  91. package/lib/commonjs/components/AssetsIcon.js.map +0 -1
  92. package/lib/commonjs/components/AssetsListControls.js.map +0 -1
  93. package/lib/commonjs/components/AssetsModal.js.map +0 -1
  94. package/lib/commonjs/components/BaselineBar.js +0 -115
  95. package/lib/commonjs/components/BaselineBar.js.map +0 -1
  96. package/lib/commonjs/export.js.map +0 -1
  97. package/lib/commonjs/format.js.map +0 -1
  98. package/lib/commonjs/hooks/useAssetRecords.js.map +0 -1
  99. package/lib/commonjs/index.js.map +0 -1
  100. package/lib/commonjs/preset.js.map +0 -1
  101. package/lib/commonjs/remote.js.map +0 -1
  102. package/lib/commonjs/state.js.map +0 -1
  103. package/lib/commonjs/store/assetStore.js.map +0 -1
  104. package/lib/commonjs/store/baseline.js.map +0 -1
  105. package/lib/commonjs/store/insights.js.map +0 -1
  106. package/lib/commonjs/sync/assetsSyncAdapter.js.map +0 -1
  107. package/lib/commonjs/types.js.map +0 -1
  108. package/lib/commonjs/utils/deviceScale.js.map +0 -1
  109. package/lib/commonjs/utils/testIDs.js.map +0 -1
  110. package/lib/module/capture/expo.js.map +0 -1
  111. package/lib/module/capture/install.js.map +0 -1
  112. package/lib/module/capture/measure.js.map +0 -1
  113. package/lib/module/capture/metroGraph.js.map +0 -1
  114. package/lib/module/capture/registry.js.map +0 -1
  115. package/lib/module/components/AssetDetail.js.map +0 -1
  116. package/lib/module/components/AssetRow.js.map +0 -1
  117. package/lib/module/components/AssetsFilterBar.js.map +0 -1
  118. package/lib/module/components/AssetsHeader.js.map +0 -1
  119. package/lib/module/components/AssetsIcon.js.map +0 -1
  120. package/lib/module/components/AssetsListControls.js.map +0 -1
  121. package/lib/module/components/AssetsModal.js.map +0 -1
  122. package/lib/module/components/BaselineBar.js +0 -111
  123. package/lib/module/components/BaselineBar.js.map +0 -1
  124. package/lib/module/export.js.map +0 -1
  125. package/lib/module/format.js.map +0 -1
  126. package/lib/module/hooks/useAssetRecords.js.map +0 -1
  127. package/lib/module/index.js.map +0 -1
  128. package/lib/module/preset.js.map +0 -1
  129. package/lib/module/remote.js.map +0 -1
  130. package/lib/module/state.js.map +0 -1
  131. package/lib/module/store/assetStore.js.map +0 -1
  132. package/lib/module/store/baseline.js.map +0 -1
  133. package/lib/module/store/insights.js.map +0 -1
  134. package/lib/module/sync/assetsSyncAdapter.js.map +0 -1
  135. package/lib/module/types.js.map +0 -1
  136. package/lib/module/utils/deviceScale.js.map +0 -1
  137. package/lib/module/utils/testIDs.js.map +0 -1
  138. package/lib/typescript/capture/expo.d.ts.map +0 -1
  139. package/lib/typescript/capture/install.d.ts.map +0 -1
  140. package/lib/typescript/capture/measure.d.ts.map +0 -1
  141. package/lib/typescript/capture/metroGraph.d.ts.map +0 -1
  142. package/lib/typescript/capture/registry.d.ts.map +0 -1
  143. package/lib/typescript/components/AssetDetail.d.ts.map +0 -1
  144. package/lib/typescript/components/AssetRow.d.ts.map +0 -1
  145. package/lib/typescript/components/AssetsFilterBar.d.ts.map +0 -1
  146. package/lib/typescript/components/AssetsHeader.d.ts.map +0 -1
  147. package/lib/typescript/components/AssetsIcon.d.ts.map +0 -1
  148. package/lib/typescript/components/AssetsListControls.d.ts.map +0 -1
  149. package/lib/typescript/components/AssetsModal.d.ts.map +0 -1
  150. package/lib/typescript/components/BaselineBar.d.ts +0 -13
  151. package/lib/typescript/components/BaselineBar.d.ts.map +0 -1
  152. package/lib/typescript/export.d.ts.map +0 -1
  153. package/lib/typescript/format.d.ts.map +0 -1
  154. package/lib/typescript/hooks/useAssetRecords.d.ts.map +0 -1
  155. package/lib/typescript/index.d.ts.map +0 -1
  156. package/lib/typescript/preset.d.ts.map +0 -1
  157. package/lib/typescript/remote.d.ts.map +0 -1
  158. package/lib/typescript/state.d.ts.map +0 -1
  159. package/lib/typescript/store/assetStore.d.ts.map +0 -1
  160. package/lib/typescript/store/baseline.d.ts.map +0 -1
  161. package/lib/typescript/store/insights.d.ts.map +0 -1
  162. package/lib/typescript/sync/assetsSyncAdapter.d.ts.map +0 -1
  163. package/lib/typescript/types.d.ts.map +0 -1
  164. package/lib/typescript/utils/deviceScale.d.ts.map +0 -1
  165. package/lib/typescript/utils/testIDs.d.ts.map +0 -1
@@ -1,141 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Metro dev-server graph fetch.
5
- *
6
- * The dev server serves `<entry>.assets` next to `<entry>.bundle` — the full
7
- * dependency graph's AssetData[], INCLUDING assets never required at runtime
8
- * and the `fileSystemLocation`/`files` fields Metro strips from runtime
9
- * records. Deriving the URL by swapping `.bundle` → `.assets` on the running
10
- * bundle's scriptURL keeps the entry path and platform/dev query params
11
- * intact for both RN CLI (index.bundle) and Expo (…/entry.bundle) layouts.
12
- *
13
- * Graph-only records (in the graph, not the registry) are exactly the
14
- * "shipped but never loaded" set. Dev-only: no server, no graph.
15
- */
16
-
17
- import { assetsState } from "../state";
18
- import { assetKey, invalidate, upsertRecord } from "../store/assetStore";
19
- export function getScriptURL() {
20
- try {
21
- const {
22
- NativeModules
23
- } = require("react-native");
24
- const sourceCode = NativeModules?.SourceCode;
25
- const url = sourceCode?.getConstants?.().scriptURL ?? sourceCode?.scriptURL;
26
- return typeof url === "string" ? url : null;
27
- } catch {
28
- return null;
29
- }
30
- }
31
-
32
- /** http(s) origin of the Metro dev server, or null when running embedded. */
33
- export function getDevServerOrigin() {
34
- const scriptURL = getScriptURL();
35
- const match = scriptURL?.match(/^https?:\/\/[^/]+/);
36
- return match ? match[0] : null;
37
- }
38
-
39
- /**
40
- * Candidate graph URLs, most-likely first. The straight `.bundle`→`.assets`
41
- * swap works for RN CLI, but Expo dev builds serve a VIRTUAL entry
42
- * (.expo/.virtual-metro-entry.bundle) that only exists for .bundle requests —
43
- * its .assets twin 404s — so the real entry modules are tried next, keeping
44
- * the original query string (platform/dev/etc.) intact.
45
- */
46
- export function getGraphURLCandidates() {
47
- const scriptURL = getScriptURL();
48
- if (!scriptURL || !/^https?:\/\//.test(scriptURL)) return [];
49
- const origin = getDevServerOrigin();
50
- const queryIndex = scriptURL.indexOf("?");
51
- const query = queryIndex >= 0 ? scriptURL.slice(queryIndex) : "?platform=ios&dev=true";
52
- const candidates = [];
53
- if (scriptURL.includes(".bundle")) {
54
- candidates.push(scriptURL.replace(".bundle", ".assets"));
55
- }
56
- if (origin) {
57
- candidates.push(`${origin}/node_modules/expo-router/entry.assets${query}`, `${origin}/node_modules/expo/AppEntry.assets${query}`, `${origin}/index.assets${query}`);
58
- }
59
- return candidates;
60
- }
61
-
62
- /** Fetch the full asset graph from the dev server and merge it into the store. */
63
- export async function fetchAssetGraph() {
64
- const s = assetsState();
65
- const candidates = getGraphURLCandidates();
66
- if (!candidates.length) {
67
- s.graphSupported = false;
68
- s.graphError = "No Metro dev server (embedded bundle)";
69
- invalidate();
70
- return {
71
- ok: false,
72
- message: s.graphError
73
- };
74
- }
75
- if (s.graphFetchInFlight) return {
76
- ok: false,
77
- message: "Graph fetch already running"
78
- };
79
- s.graphFetchInFlight = true;
80
- try {
81
- let data = null;
82
- let lastError = "";
83
- for (const url of candidates) {
84
- try {
85
- const response = await fetch(url);
86
- if (!response.ok) {
87
- lastError = `Metro responded ${response.status} for ${url}`;
88
- continue;
89
- }
90
- const parsed = await response.json();
91
- if (Array.isArray(parsed)) {
92
- data = parsed;
93
- break;
94
- }
95
- lastError = "Unexpected .assets payload shape";
96
- } catch (error) {
97
- lastError = String(error?.message ?? error);
98
- }
99
- }
100
- if (!Array.isArray(data)) throw new Error(lastError || "No graph endpoint answered");
101
- const graph = data;
102
- for (const asset of graph) {
103
- if (!asset || typeof asset.name !== "string" || typeof asset.type !== "string") {
104
- continue;
105
- }
106
- upsertRecord({
107
- key: assetKey(asset.httpServerLocation, asset.name, asset.type),
108
- name: asset.name,
109
- type: asset.type,
110
- origin: "graph",
111
- hash: asset.hash,
112
- httpServerLocation: asset.httpServerLocation,
113
- width: asset.width ?? undefined,
114
- height: asset.height ?? undefined,
115
- scales: asset.scales,
116
- fileSystemLocation: asset.fileSystemLocation,
117
- files: asset.files,
118
- fileHashes: asset.fileHashes
119
- });
120
- }
121
- s.graphSupported = true;
122
- s.graphCount = graph.length;
123
- s.graphError = null;
124
- invalidate();
125
- return {
126
- ok: true,
127
- count: graph.length
128
- };
129
- } catch (error) {
130
- s.graphSupported = getDevServerOrigin() != null;
131
- s.graphError = String(error?.message ?? error);
132
- invalidate();
133
- return {
134
- ok: false,
135
- message: s.graphError
136
- };
137
- } finally {
138
- s.graphFetchInFlight = false;
139
- }
140
- }
141
- //# sourceMappingURL=metroGraph.js.map
1
+ "use strict";import{assetsState}from"../state";import{assetKey,invalidate,upsertRecord}from"../store/assetStore";const GRAPH_TIMEOUT_MS=9e4;async function fetchGraphPayload(e,t){const r=new AbortController;let a;try{return await Promise.race([(async()=>{const t=await fetch(e,{signal:r.signal});if(!t.ok)throw new Error(`Metro responded ${t.status} for ${e}`);return t.json()})(),new Promise((e,n)=>{a=setTimeout(()=>{n(new Error("Asset discovery timed out. Try again.")),r.abort()},Math.max(0,t))})])}finally{clearTimeout(a)}}export function getScriptURL(){try{const{NativeModules:e}=require("react-native"),t=e?.SourceCode,r=t?.getConstants?.().scriptURL??t?.scriptURL;return"string"==typeof r?r:null}catch{return null}}export function getDevServerOrigin(){const e=getScriptURL(),t=e?.match(/^https?:\/\/[^/]+/);return t?t[0]:null}export function getGraphURLCandidates(){const e=getScriptURL();if(!e||!/^https?:\/\//.test(e))return[];const t=getDevServerOrigin(),r=e.indexOf("?"),a=r>=0?e.slice(r):"?platform=ios&dev=true",n=[];return e.includes(".bundle")&&n.push(e.replace(".bundle",".assets")),t&&n.push(`${t}/node_modules/expo-router/entry.assets${a}`,`${t}/node_modules/expo/AppEntry.assets${a}`,`${t}/index.assets${a}`),n}export async function fetchAssetGraph(){const e=assetsState(),t=getGraphURLCandidates();if(!t.length)return e.graphSupported=!1,e.graphError="No Metro dev server (embedded bundle)",invalidate(),{ok:!1,message:e.graphError};if(e.graphFetchInFlight)return{ok:!1,message:"Graph fetch already running"};e.graphFetchInFlight=!0,e.graphFetchStartedAt=Date.now(),e.graphError=null,invalidate();const r=e.graphFetchStartedAt+9e4;try{let a=null,n="";for(const e of t)try{const t=await fetchGraphPayload(e,r-Date.now());if(Array.isArray(t)){a=t;break}n="Unexpected .assets payload shape"}catch(e){if(n=String(e?.message??e),Date.now()>=r)break}if(!Array.isArray(a))throw new Error(n||"No graph endpoint answered");const s=a;let o=0;for(const e of s)e&&"string"==typeof e.name&&"string"==typeof e.type&&upsertRecord({key:assetKey(e.httpServerLocation,e.name,e.type),name:e.name,type:e.type,origin:"graph",hash:e.hash,httpServerLocation:e.httpServerLocation,width:e.width??void 0,height:e.height??void 0,scales:e.scales,fileSystemLocation:e.fileSystemLocation,files:e.files,fileHashes:e.fileHashes})&&o++;return e.graphSupported=!0,e.graphCount=o,e.graphError=null,invalidate(),{ok:!0,count:o}}catch(t){return e.graphSupported=null!=getDevServerOrigin(),e.graphError=String(t?.message??t),invalidate(),{ok:!1,message:e.graphError}}finally{e.graphFetchInFlight=!1,e.graphFetchStartedAt=null,invalidate()}}
@@ -1,120 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Runtime access to @react-native/assets-registry.
5
- *
6
- * Asset ids are contiguous 1..N (`assets.push` return value), so a plain
7
- * getAssetByID walk enumerates every asset registered so far — including
8
- * everything registered BEFORE this tool was evaluated. That's why, unlike
9
- * the images tool, there is no "must be the first import" requirement here:
10
- * the walk backfills whatever the patch missed.
11
- *
12
- * registerAsset is patched (plain non-frozen CommonJS export, looked up at
13
- * call time by Metro's generated asset modules) purely for LIVE updates as
14
- * lazily-required assets register later.
15
- */
16
-
17
- import { upsertRecord, assetKey } from "../store/assetStore";
18
-
19
- /** Runtime shape of a registry entry (fileSystemLocation/files are stripped by Metro). */
20
-
21
- let cachedRegistry;
22
- export function getRegistryModule() {
23
- if (cachedRegistry !== undefined) return cachedRegistry;
24
- let mod = null;
25
- try {
26
- mod = require("@react-native/assets-registry/registry");
27
- } catch {
28
- // Old RN layouts (< 0.72) don't ship @react-native/assets-registry as a
29
- // resolvable package — the registry only exists at this deep path. RN's
30
- // deep-import deprecation warning fires when this executes, but it only
31
- // executes on those old layouts, where there is no other way in.
32
- try {
33
- mod = require("react-native/Libraries/Image/AssetRegistry");
34
- } catch {
35
- mod = null;
36
- }
37
- }
38
- cachedRegistry = mod && typeof mod.getAssetByID === "function" ? mod : null;
39
- return cachedRegistry;
40
- }
41
-
42
- /** resolveAssetSource(id) → this environment's URI (dev URL / file:// / res id). */
43
- export function resolveRegistryAsset(registryId) {
44
- try {
45
- const {
46
- Image
47
- } = require("react-native");
48
- const resolved = Image.resolveAssetSource(registryId);
49
- if (resolved && typeof resolved.uri === "string") {
50
- return {
51
- uri: resolved.uri,
52
- scale: resolved.scale ?? 1
53
- };
54
- }
55
- } catch {
56
- // resolution is enrichment — never let it break the walk
57
- }
58
- return null;
59
- }
60
- export function upsertFromPackagerAsset(registryId, asset) {
61
- const resolved = resolveRegistryAsset(registryId);
62
- return upsertRecord({
63
- key: assetKey(asset.httpServerLocation, asset.name, asset.type),
64
- name: asset.name,
65
- type: asset.type,
66
- origin: "registry",
67
- registryId,
68
- hash: asset.hash,
69
- httpServerLocation: asset.httpServerLocation,
70
- width: asset.width ?? undefined,
71
- height: asset.height ?? undefined,
72
- scales: asset.scales,
73
- resolvedUri: resolved?.uri,
74
- resolvedScale: resolved?.scale,
75
- loaded: true
76
- });
77
- }
78
-
79
- /** Enumerate every asset registered so far. Returns the highest id seen. */
80
- export function walkRegistry() {
81
- const registry = getRegistryModule();
82
- if (!registry) return 0;
83
- let id = 0;
84
- for (;;) {
85
- const asset = registry.getAssetByID(id + 1);
86
- if (!asset) break;
87
- id++;
88
- upsertFromPackagerAsset(id, asset);
89
- }
90
- return id;
91
- }
92
- const PATCH_MARKER = "__buoyAssetsPatched";
93
-
94
- /**
95
- * Wrap registerAsset so future registrations stream in live. Safe to call
96
- * more than once (marker guard); the walk covers anything registered before.
97
- */
98
- export function patchRegisterAsset() {
99
- const registry = getRegistryModule();
100
- if (!registry) return false;
101
- const original = registry.registerAsset;
102
- if (original[PATCH_MARKER]) return true;
103
- const wrapped = asset => {
104
- const id = original.call(registry, asset);
105
- try {
106
- upsertFromPackagerAsset(id, asset);
107
- } catch {
108
- // never break app asset registration
109
- }
110
- return id;
111
- };
112
- wrapped[PATCH_MARKER] = true;
113
- try {
114
- registry.registerAsset = wrapped;
115
- } catch {
116
- return false;
117
- }
118
- return true;
119
- }
120
- //# sourceMappingURL=registry.js.map
1
+ "use strict";import{upsertRecord,assetKey}from"../store/assetStore";let cachedRegistry;export function getRegistryModule(){if(void 0!==cachedRegistry)return cachedRegistry;let e=null;try{e=require("@react-native/assets-registry/registry")}catch{try{e=require("react-native/Libraries/Image/AssetRegistry")}catch{e=null}}return cachedRegistry=e&&"function"==typeof e.getAssetByID?e:null,cachedRegistry}export function resolveRegistryAsset(e){try{const{Image:t}=require("react-native"),r=t.resolveAssetSource(e);if(r&&"string"==typeof r.uri)return{uri:r.uri,scale:r.scale??1}}catch{}return null}export function upsertFromPackagerAsset(e,t){const r=resolveRegistryAsset(e);return upsertRecord({key:assetKey(t.httpServerLocation,t.name,t.type),name:t.name,type:t.type,origin:"registry",registryId:e,hash:t.hash,httpServerLocation:t.httpServerLocation,width:t.width??void 0,height:t.height??void 0,scales:t.scales,resolvedUri:r?.uri,resolvedScale:r?.scale,loaded:!0})}export function walkRegistry(){const e=getRegistryModule();if(!e)return 0;let t=0;for(;;){const r=e.getAssetByID(t+1);if(!r)break;t++,upsertFromPackagerAsset(t,r)}return t}const PATCH_MARKER="__buoyAssetsPatched";export function patchRegisterAsset(){const e=getRegistryModule();if(!e)return!1;const t=e.registerAsset;if(t[PATCH_MARKER])return!0;const r=r=>{const s=t.call(e,r);try{upsertFromPackagerAsset(s,r)}catch{}return s};r[PATCH_MARKER]=!0;try{e.registerAsset=r}catch{return!1}return!0}
@@ -1,210 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * AssetDetail — full metadata for one asset: preview, identity, dimensions,
5
- * per-scale sizes, resolution info, and which audit findings apply.
6
- *
7
- * Image previews render through the numeric registry id (works in every
8
- * environment); fonts render a pangram with fontFamily set to the asset name
9
- * — a best-effort guess (family ≠ filename for many fonts) that falls back
10
- * to the system font silently when it misses.
11
- */
12
-
13
- import { Image, ScrollView, StyleSheet, Text, View } from "react-native";
14
- import { night } from "@buoy-gg/shared-ui";
15
- import { displaySource } from "../capture/measure";
16
- import { formatBytes, formatDimensions, formatScales } from "../format";
17
- import { estDecodedBytes } from "../store/assetStore";
18
- import { ASSETS_TEST_IDS, assetDetailRowTestID, assetFindingTestID } from "../utils/testIDs";
19
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
- function Row({
21
- label,
22
- value
23
- }) {
24
- const testID = assetDetailRowTestID(label);
25
- return /*#__PURE__*/_jsxs(View, {
26
- style: styles.kvRow,
27
- testID: testID,
28
- children: [/*#__PURE__*/_jsx(Text, {
29
- style: styles.kvLabel,
30
- children: label
31
- }), /*#__PURE__*/_jsx(Text, {
32
- style: styles.kvValue,
33
- selectable: true,
34
- testID: `${testID}-value`,
35
- children: value
36
- })]
37
- });
38
- }
39
- function Preview({
40
- record
41
- }) {
42
- if (record.kind === "image") {
43
- const source = displaySource(record);
44
- if (source == null) return null;
45
- return /*#__PURE__*/_jsx(View, {
46
- style: styles.previewBox,
47
- testID: ASSETS_TEST_IDS.detailPreview,
48
- children: /*#__PURE__*/_jsx(Image, {
49
- testID: "buoy-internal-assets-preview",
50
- source: source,
51
- style: styles.previewImage,
52
- resizeMode: "contain"
53
- })
54
- });
55
- }
56
- if (record.kind === "font") {
57
- return /*#__PURE__*/_jsx(View, {
58
- style: styles.previewBox,
59
- testID: ASSETS_TEST_IDS.detailFontPreview,
60
- children: /*#__PURE__*/_jsx(Text, {
61
- style: [styles.fontPreview, {
62
- fontFamily: record.name
63
- }],
64
- children: "The quick brown fox jumps over the lazy dog 0123456789"
65
- })
66
- });
67
- }
68
- return null;
69
- }
70
- export function AssetDetail({
71
- record,
72
- insights
73
- }) {
74
- const findings = [];
75
- if (insights.neverLoaded.includes(record.id)) {
76
- findings.push("Never loaded — shipped in the bundle but no code required it");
77
- }
78
- if (insights.scaleGaps.includes(record.id)) {
79
- findings.push("Scale gap — no variant covers this device's pixel ratio");
80
- }
81
- if (insights.webpCandidates.includes(record.id)) {
82
- findings.push("WebP candidate — large png/jpeg, converting typically saves 20–40%");
83
- }
84
- const duplicate = insights.duplicates.find(d => d.ids.includes(record.id));
85
- if (duplicate) {
86
- findings.push(`Duplicate content — identical bytes shipped ${duplicate.ids.length} times`);
87
- }
88
- if (insights.overDecode.includes(record.id)) {
89
- findings.push("Decodes larger than 2× this entire screen — resize the source, no view can need this many pixels");
90
- }
91
- if (insights.heavyGifs.includes(record.id)) {
92
- findings.push("Heavy GIF — every frame decodes into memory; a video or Lottie is typically ~90% smaller");
93
- }
94
- if (insights.heavyFonts.includes(record.id)) {
95
- findings.push("Heavy font — likely an unsubset icon font; subsetting to used glyphs usually saves most of it");
96
- }
97
- if (insights.scaleAnomalies.includes(record.id)) {
98
- findings.push("Scale anomaly — a higher-resolution variant is smaller in bytes than a lower one; check the exports");
99
- }
100
- const estimate = estDecodedBytes(record);
101
- return /*#__PURE__*/_jsxs(ScrollView, {
102
- style: styles.scroll,
103
- contentContainerStyle: styles.content,
104
- testID: ASSETS_TEST_IDS.detailScroll,
105
- children: [/*#__PURE__*/_jsx(Preview, {
106
- record: record
107
- }), findings.length > 0 ? /*#__PURE__*/_jsx(View, {
108
- style: styles.findings,
109
- testID: ASSETS_TEST_IDS.detailFindings,
110
- children: findings.map((finding, index) => /*#__PURE__*/_jsx(Text, {
111
- style: styles.findingText,
112
- testID: assetFindingTestID(index),
113
- children: finding
114
- }, finding))
115
- }) : null, /*#__PURE__*/_jsx(Row, {
116
- label: "Name",
117
- value: `${record.name}.${record.type}`
118
- }), /*#__PURE__*/_jsx(Row, {
119
- label: "Kind",
120
- value: record.kind
121
- }), /*#__PURE__*/_jsx(Row, {
122
- label: "Status",
123
- value: record.loaded ? "Loaded (registered at runtime)" : "In bundle, never loaded"
124
- }), record.kind === "image" ? /*#__PURE__*/_jsx(Row, {
125
- label: "Dimensions",
126
- value: `${formatDimensions(record)} (logical)`
127
- }) : null, record.kind === "image" && record.scales.length ? /*#__PURE__*/_jsx(Row, {
128
- label: "Scales",
129
- value: formatScales(record.scales)
130
- }) : null, record.sizesByScale ? Object.entries(record.sizesByScale).map(([scale, bytes]) => /*#__PURE__*/_jsx(Row, {
131
- label: `Size @${scale}x`,
132
- value: formatBytes(bytes)
133
- }, scale)) : null, record.sizeBytes != null && record.sizeSource === "measured" ? /*#__PURE__*/_jsx(Row, {
134
- label: "Total size",
135
- value: formatBytes(record.sizeBytes)
136
- }) : null, estimate > 0 ? /*#__PURE__*/_jsx(Row, {
137
- label: "Decoded memory",
138
- value: `~${formatBytes(estimate)} (RGBA)`
139
- }) : null, record.registryId != null ? /*#__PURE__*/_jsx(Row, {
140
- label: "Registry id",
141
- value: String(record.registryId)
142
- }) : null, record.hash ? /*#__PURE__*/_jsx(Row, {
143
- label: "Hash",
144
- value: record.hash
145
- }) : null, record.httpServerLocation ? /*#__PURE__*/_jsx(Row, {
146
- label: "Location",
147
- value: record.httpServerLocation
148
- }) : null, record.fileSystemLocation ? /*#__PURE__*/_jsx(Row, {
149
- label: "Source dir",
150
- value: record.fileSystemLocation
151
- }) : null, record.resolvedUri ? /*#__PURE__*/_jsx(Row, {
152
- label: "Resolved URI",
153
- value: record.resolvedUri
154
- }) : null]
155
- });
156
- }
157
- const styles = StyleSheet.create({
158
- scroll: {
159
- flex: 1
160
- },
161
- content: {
162
- padding: 12,
163
- gap: 8
164
- },
165
- previewBox: {
166
- borderRadius: 8,
167
- backgroundColor: night.color.bg,
168
- padding: 12,
169
- alignItems: "center",
170
- justifyContent: "center",
171
- minHeight: 96
172
- },
173
- previewImage: {
174
- width: "100%",
175
- height: 140
176
- },
177
- fontPreview: {
178
- color: night.color.text,
179
- fontSize: 16,
180
- textAlign: "center"
181
- },
182
- findings: {
183
- borderRadius: 8,
184
- borderWidth: 1,
185
- borderColor: night.color.border,
186
- backgroundColor: night.color.surface,
187
- padding: 10,
188
- gap: 6
189
- },
190
- findingText: {
191
- color: night.color.textSecondary,
192
- fontSize: 11,
193
- lineHeight: 15
194
- },
195
- kvRow: {
196
- gap: 2
197
- },
198
- kvLabel: {
199
- color: night.color.textTertiary,
200
- fontSize: 9,
201
- fontWeight: "700",
202
- letterSpacing: 0.5,
203
- textTransform: "uppercase"
204
- },
205
- kvValue: {
206
- color: night.color.text,
207
- fontSize: 12
208
- }
209
- });
210
- //# sourceMappingURL=AssetDetail.js.map
1
+ "use strict";import{ScrollView,StyleSheet,Text,View}from"react-native";import{night}from"@buoy-gg/shared-ui";import{AssetImage}from"./AssetImage";import{formatBytes,formatDimensions,formatScales}from"../format";import{estDecodedBytes}from"../store/assetStore";import{ASSETS_TEST_IDS,assetDetailRowTestID,assetFindingTestID}from"../utils/testIDs";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";function Row({label:e,value:t}){const s=assetDetailRowTestID(e);return _jsxs(View,{style:styles.kvRow,testID:s,children:[_jsx(Text,{style:styles.kvLabel,children:e}),_jsx(Text,{style:styles.kvValue,selectable:!0,testID:`${s}-value`,children:t})]})}function Preview({record:e}){return"image"===e.kind?_jsx(View,{style:styles.previewBox,testID:ASSETS_TEST_IDS.detailPreview,children:_jsx(AssetImage,{testID:"buoy-internal-assets-preview",record:e,style:styles.previewImage})}):"font"===e.kind?_jsx(View,{style:styles.previewBox,testID:ASSETS_TEST_IDS.detailFontPreview,children:_jsx(Text,{style:[styles.fontPreview,{fontFamily:e.name}],children:"The quick brown fox jumps over the lazy dog 0123456789"})}):null}export function AssetDetail({record:e,insights:t}){const s=[];t.neverLoaded.includes(e.id)&&s.push("Not observed in the runtime registry this app run. This does not prove the asset is unused."),t.scaleGaps.includes(e.id)&&s.push("Scale gap — no variant covers this device's pixel ratio"),t.webpCandidates.includes(e.id)&&s.push("WebP candidate — large png/jpeg, converting typically saves 20–40%");const i=t.duplicates.find(t=>t.ids.includes(e.id));i&&s.push(`Duplicate content — identical bytes shipped ${i.ids.length} times`),t.overDecode.includes(e.id)&&s.push("Decodes larger than 2× this entire screen — resize the source, no view can need this many pixels"),t.heavyGifs.includes(e.id)&&s.push("Heavy GIF — every frame decodes into memory; a video or Lottie is typically ~90% smaller"),t.heavyFonts.includes(e.id)&&s.push("Heavy font — likely an unsubset icon font; subsetting to used glyphs usually saves most of it"),t.scaleAnomalies.includes(e.id)&&s.push("Scale anomaly — a higher-resolution variant is smaller in bytes than a lower one; check the exports");const l=estDecodedBytes(e);return _jsxs(ScrollView,{style:styles.scroll,contentContainerStyle:styles.content,testID:ASSETS_TEST_IDS.detailScroll,children:[_jsx(Preview,{record:e}),s.length>0?_jsx(View,{style:styles.findings,testID:ASSETS_TEST_IDS.detailFindings,children:s.map((e,t)=>_jsx(Text,{style:styles.findingText,testID:assetFindingTestID(t),children:e},e))}):null,_jsx(Row,{label:"Name",value:`${e.name}.${e.type}`}),_jsx(Row,{label:"Kind",value:e.kind}),_jsx(Row,{label:"Status",value:e.loaded?"Loaded (registered at runtime)":"Not observed in the runtime registry"}),"image"===e.kind?_jsx(Row,{label:"Dimensions",value:`${formatDimensions(e)} (logical)`}):null,"image"===e.kind&&e.scales.length?_jsx(Row,{label:"Scales",value:formatScales(e.scales)}):null,e.sizesByScale?Object.entries(e.sizesByScale).map(([e,t])=>_jsx(Row,{label:`Size @${e}x`,value:formatBytes(t)},e)):null,null!=e.sizeBytes&&"measured"===e.sizeSource?_jsx(Row,{label:"Total size",value:formatBytes(e.sizeBytes)}):null,l>0?_jsx(Row,{label:"Decoded memory",value:`~${formatBytes(l)} (RGBA)`}):null,null!=e.registryId?_jsx(Row,{label:"Registry id",value:String(e.registryId)}):null,e.hash?_jsx(Row,{label:"Hash",value:e.hash}):null,e.httpServerLocation?_jsx(Row,{label:"Location",value:e.httpServerLocation}):null,e.fileSystemLocation?_jsx(Row,{label:"Source dir",value:e.fileSystemLocation}):null,e.resolvedUri?_jsx(Row,{label:"Resolved URI",value:e.resolvedUri}):null]})}const styles=StyleSheet.create({scroll:{flex:1},content:{padding:12,gap:8},previewBox:{borderRadius:8,backgroundColor:night.color.bg,padding:12,alignItems:"center",justifyContent:"center",minHeight:96},previewImage:{width:"100%",height:140},fontPreview:{color:night.color.text,fontSize:16,textAlign:"center"},findings:{borderRadius:8,borderWidth:1,borderColor:night.color.border,backgroundColor:night.color.surface,padding:10,gap:6},findingText:{color:night.color.textSecondary,fontSize:11,lineHeight:15},kvRow:{gap:2},kvLabel:{color:night.color.textTertiary,fontSize:9,fontWeight:"700",letterSpacing:.5,textTransform:"uppercase"},kvValue:{color:night.color.text,fontSize:12}});
@@ -0,0 +1 @@
1
+ "use strict";import{useState}from"react";import{Image,Platform,StyleSheet,Text,View}from"react-native";import{night}from"@buoy-gg/shared-ui";import{displaySource}from"../capture/measure";import{getExpoPreviewImage}from"./optionalExpoImage";import{jsx as _jsx}from"react/jsx-runtime";export function AssetImage({record:e,style:t,testID:r,compact:o=!1}){const s=displaySource(e),a="svg"===e.type.toLowerCase(),i=a&&"web"!==Platform.OS?getExpoPreviewImage():null,l=`${e.key}:${e.hash??""}:${"number"==typeof s?s:s?.uri??""}`,[n,c]=useState(null);if(null==s||n===l||a&&"web"!==Platform.OS&&!i){const e=a?"SVG preview unavailable":"Image preview unavailable";return _jsx(View,{style:[t,styles.fallback],accessibilityLabel:e,testID:`${r}-unavailable`,children:_jsx(Text,{style:styles.text,children:o?a?"SVG":"IMG":e})})}const m=()=>c(l);return i?_jsx(i,{source:s,style:t,contentFit:"contain",onError:m,testID:r}):_jsx(Image,{source:s,style:t,resizeMode:"contain",onError:m,testID:r})}const styles=StyleSheet.create({fallback:{alignItems:"center",justifyContent:"center"},text:{color:night.color.textSecondary,fontSize:10,textAlign:"center"}});