@buoy-gg/assets 7.0.41 → 7.0.43

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 (204) hide show
  1. package/README.md +12 -73
  2. package/bundlers/vite.mjs +1 -53
  3. package/lib/commonjs/autoCapture.js +1 -5
  4. package/lib/commonjs/autoCapture.web.js +1 -6
  5. package/lib/commonjs/capture/assetLifecycle.js +1 -11
  6. package/lib/commonjs/capture/assetLifecycle.web.js +1 -20
  7. package/lib/commonjs/capture/browserAssets.js +1 -83
  8. package/lib/commonjs/capture/expo.js +1 -46
  9. package/lib/commonjs/capture/expo.web.js +1 -19
  10. package/lib/commonjs/capture/install.js +1 -91
  11. package/lib/commonjs/capture/install.web.js +1 -75
  12. package/lib/commonjs/capture/isBuoyAsset.js +1 -23
  13. package/lib/commonjs/capture/measure.js +1 -187
  14. package/lib/commonjs/capture/metroGraph.js +1 -175
  15. package/lib/commonjs/capture/metroGraph.web.js +1 -27
  16. package/lib/commonjs/capture/registry.js +1 -127
  17. package/lib/commonjs/components/AssetDetail.js +1 -211
  18. package/lib/commonjs/components/AssetImage.js +1 -66
  19. package/lib/commonjs/components/AssetRow.js +1 -232
  20. package/lib/commonjs/components/AssetsFilterBar.js +1 -105
  21. package/lib/commonjs/components/AssetsHeader.js +1 -73
  22. package/lib/commonjs/components/AssetsIcon.js +1 -19
  23. package/lib/commonjs/components/AssetsListControls.js +1 -81
  24. package/lib/commonjs/components/AssetsModal.js +1 -378
  25. package/lib/commonjs/components/ScanNotice.js +1 -86
  26. package/lib/commonjs/components/optionalExpoImage.js +1 -16
  27. package/lib/commonjs/components/optionalExpoImage.web.js +1 -10
  28. package/lib/commonjs/export.js +1 -62
  29. package/lib/commonjs/format.js +1 -59
  30. package/lib/commonjs/hooks/useAssetRecords.js +1 -22
  31. package/lib/commonjs/hooks/useAssetScanStatus.js +1 -28
  32. package/lib/commonjs/index.js +1 -294
  33. package/lib/commonjs/preset.js +1 -39
  34. package/lib/commonjs/remote.js +1 -68
  35. package/lib/commonjs/state.js +1 -51
  36. package/lib/commonjs/store/assetStore.js +1 -256
  37. package/lib/commonjs/store/baseline.js +1 -175
  38. package/lib/commonjs/store/insights.js +1 -120
  39. package/lib/commonjs/sync/assetsSyncAdapter.js +1 -157
  40. package/lib/commonjs/types.js +0 -1
  41. package/lib/commonjs/utils/deviceScale.js +1 -50
  42. package/lib/commonjs/utils/testIDs.js +1 -110
  43. package/lib/module/autoCapture.js +1 -5
  44. package/lib/module/autoCapture.web.js +1 -5
  45. package/lib/module/capture/assetLifecycle.js +1 -7
  46. package/lib/module/capture/assetLifecycle.web.js +1 -16
  47. package/lib/module/capture/browserAssets.js +1 -75
  48. package/lib/module/capture/expo.js +1 -41
  49. package/lib/module/capture/expo.web.js +1 -14
  50. package/lib/module/capture/install.js +1 -85
  51. package/lib/module/capture/install.web.js +1 -68
  52. package/lib/module/capture/isBuoyAsset.js +1 -18
  53. package/lib/module/capture/measure.js +1 -180
  54. package/lib/module/capture/metroGraph.js +1 -168
  55. package/lib/module/capture/metroGraph.web.js +1 -21
  56. package/lib/module/capture/registry.js +1 -120
  57. package/lib/module/components/AssetDetail.js +1 -207
  58. package/lib/module/components/AssetImage.js +1 -62
  59. package/lib/module/components/AssetRow.js +1 -228
  60. package/lib/module/components/AssetsFilterBar.js +1 -101
  61. package/lib/module/components/AssetsHeader.js +1 -69
  62. package/lib/module/components/AssetsIcon.js +1 -12
  63. package/lib/module/components/AssetsListControls.js +1 -77
  64. package/lib/module/components/AssetsModal.js +1 -373
  65. package/lib/module/components/ScanNotice.js +1 -82
  66. package/lib/module/components/optionalExpoImage.js +1 -12
  67. package/lib/module/components/optionalExpoImage.web.js +1 -6
  68. package/lib/module/export.js +1 -57
  69. package/lib/module/format.js +1 -51
  70. package/lib/module/hooks/useAssetRecords.js +1 -18
  71. package/lib/module/hooks/useAssetScanStatus.js +1 -23
  72. package/lib/module/index.js +1 -64
  73. package/lib/module/preset.js +1 -35
  74. package/lib/module/remote.js +1 -61
  75. package/lib/module/state.js +1 -47
  76. package/lib/module/store/assetStore.js +1 -240
  77. package/lib/module/store/baseline.js +1 -167
  78. package/lib/module/store/insights.js +1 -116
  79. package/lib/module/sync/assetsSyncAdapter.js +1 -153
  80. package/lib/module/types.js +0 -1
  81. package/lib/module/utils/deviceScale.js +1 -46
  82. package/lib/module/utils/testIDs.js +1 -99
  83. package/lib/web/index.mjs +3 -4
  84. package/package.json +3 -8
  85. package/lib/commonjs/autoCapture.js.map +0 -1
  86. package/lib/commonjs/autoCapture.web.js.map +0 -1
  87. package/lib/commonjs/capture/assetLifecycle.js.map +0 -1
  88. package/lib/commonjs/capture/assetLifecycle.web.js.map +0 -1
  89. package/lib/commonjs/capture/browserAssets.js.map +0 -1
  90. package/lib/commonjs/capture/expo.js.map +0 -1
  91. package/lib/commonjs/capture/expo.web.js.map +0 -1
  92. package/lib/commonjs/capture/install.js.map +0 -1
  93. package/lib/commonjs/capture/install.web.js.map +0 -1
  94. package/lib/commonjs/capture/isBuoyAsset.js.map +0 -1
  95. package/lib/commonjs/capture/measure.js.map +0 -1
  96. package/lib/commonjs/capture/metroGraph.js.map +0 -1
  97. package/lib/commonjs/capture/metroGraph.web.js.map +0 -1
  98. package/lib/commonjs/capture/registry.js.map +0 -1
  99. package/lib/commonjs/components/AssetDetail.js.map +0 -1
  100. package/lib/commonjs/components/AssetImage.js.map +0 -1
  101. package/lib/commonjs/components/AssetRow.js.map +0 -1
  102. package/lib/commonjs/components/AssetsFilterBar.js.map +0 -1
  103. package/lib/commonjs/components/AssetsHeader.js.map +0 -1
  104. package/lib/commonjs/components/AssetsIcon.js.map +0 -1
  105. package/lib/commonjs/components/AssetsListControls.js.map +0 -1
  106. package/lib/commonjs/components/AssetsModal.js.map +0 -1
  107. package/lib/commonjs/components/ScanNotice.js.map +0 -1
  108. package/lib/commonjs/components/optionalExpoImage.js.map +0 -1
  109. package/lib/commonjs/components/optionalExpoImage.web.js.map +0 -1
  110. package/lib/commonjs/export.js.map +0 -1
  111. package/lib/commonjs/format.js.map +0 -1
  112. package/lib/commonjs/hooks/useAssetRecords.js.map +0 -1
  113. package/lib/commonjs/hooks/useAssetScanStatus.js.map +0 -1
  114. package/lib/commonjs/index.js.map +0 -1
  115. package/lib/commonjs/preset.js.map +0 -1
  116. package/lib/commonjs/remote.js.map +0 -1
  117. package/lib/commonjs/state.js.map +0 -1
  118. package/lib/commonjs/store/assetStore.js.map +0 -1
  119. package/lib/commonjs/store/baseline.js.map +0 -1
  120. package/lib/commonjs/store/insights.js.map +0 -1
  121. package/lib/commonjs/sync/assetsSyncAdapter.js.map +0 -1
  122. package/lib/commonjs/types.js.map +0 -1
  123. package/lib/commonjs/utils/deviceScale.js.map +0 -1
  124. package/lib/commonjs/utils/testIDs.js.map +0 -1
  125. package/lib/module/autoCapture.js.map +0 -1
  126. package/lib/module/autoCapture.web.js.map +0 -1
  127. package/lib/module/capture/assetLifecycle.js.map +0 -1
  128. package/lib/module/capture/assetLifecycle.web.js.map +0 -1
  129. package/lib/module/capture/browserAssets.js.map +0 -1
  130. package/lib/module/capture/expo.js.map +0 -1
  131. package/lib/module/capture/expo.web.js.map +0 -1
  132. package/lib/module/capture/install.js.map +0 -1
  133. package/lib/module/capture/install.web.js.map +0 -1
  134. package/lib/module/capture/isBuoyAsset.js.map +0 -1
  135. package/lib/module/capture/measure.js.map +0 -1
  136. package/lib/module/capture/metroGraph.js.map +0 -1
  137. package/lib/module/capture/metroGraph.web.js.map +0 -1
  138. package/lib/module/capture/registry.js.map +0 -1
  139. package/lib/module/components/AssetDetail.js.map +0 -1
  140. package/lib/module/components/AssetImage.js.map +0 -1
  141. package/lib/module/components/AssetRow.js.map +0 -1
  142. package/lib/module/components/AssetsFilterBar.js.map +0 -1
  143. package/lib/module/components/AssetsHeader.js.map +0 -1
  144. package/lib/module/components/AssetsIcon.js.map +0 -1
  145. package/lib/module/components/AssetsListControls.js.map +0 -1
  146. package/lib/module/components/AssetsModal.js.map +0 -1
  147. package/lib/module/components/ScanNotice.js.map +0 -1
  148. package/lib/module/components/optionalExpoImage.js.map +0 -1
  149. package/lib/module/components/optionalExpoImage.web.js.map +0 -1
  150. package/lib/module/export.js.map +0 -1
  151. package/lib/module/format.js.map +0 -1
  152. package/lib/module/hooks/useAssetRecords.js.map +0 -1
  153. package/lib/module/hooks/useAssetScanStatus.js.map +0 -1
  154. package/lib/module/index.js.map +0 -1
  155. package/lib/module/preset.js.map +0 -1
  156. package/lib/module/remote.js.map +0 -1
  157. package/lib/module/state.js.map +0 -1
  158. package/lib/module/store/assetStore.js.map +0 -1
  159. package/lib/module/store/baseline.js.map +0 -1
  160. package/lib/module/store/insights.js.map +0 -1
  161. package/lib/module/sync/assetsSyncAdapter.js.map +0 -1
  162. package/lib/module/types.js.map +0 -1
  163. package/lib/module/utils/deviceScale.js.map +0 -1
  164. package/lib/module/utils/testIDs.js.map +0 -1
  165. package/lib/typescript/autoCapture.d.ts.map +0 -1
  166. package/lib/typescript/autoCapture.web.d.ts.map +0 -1
  167. package/lib/typescript/capture/assetLifecycle.d.ts.map +0 -1
  168. package/lib/typescript/capture/assetLifecycle.web.d.ts.map +0 -1
  169. package/lib/typescript/capture/browserAssets.d.ts.map +0 -1
  170. package/lib/typescript/capture/expo.d.ts.map +0 -1
  171. package/lib/typescript/capture/expo.web.d.ts.map +0 -1
  172. package/lib/typescript/capture/install.d.ts.map +0 -1
  173. package/lib/typescript/capture/install.web.d.ts.map +0 -1
  174. package/lib/typescript/capture/isBuoyAsset.d.ts.map +0 -1
  175. package/lib/typescript/capture/measure.d.ts.map +0 -1
  176. package/lib/typescript/capture/metroGraph.d.ts.map +0 -1
  177. package/lib/typescript/capture/metroGraph.web.d.ts.map +0 -1
  178. package/lib/typescript/capture/registry.d.ts.map +0 -1
  179. package/lib/typescript/components/AssetDetail.d.ts.map +0 -1
  180. package/lib/typescript/components/AssetImage.d.ts.map +0 -1
  181. package/lib/typescript/components/AssetRow.d.ts.map +0 -1
  182. package/lib/typescript/components/AssetsFilterBar.d.ts.map +0 -1
  183. package/lib/typescript/components/AssetsHeader.d.ts.map +0 -1
  184. package/lib/typescript/components/AssetsIcon.d.ts.map +0 -1
  185. package/lib/typescript/components/AssetsListControls.d.ts.map +0 -1
  186. package/lib/typescript/components/AssetsModal.d.ts.map +0 -1
  187. package/lib/typescript/components/ScanNotice.d.ts.map +0 -1
  188. package/lib/typescript/components/optionalExpoImage.d.ts.map +0 -1
  189. package/lib/typescript/components/optionalExpoImage.web.d.ts.map +0 -1
  190. package/lib/typescript/export.d.ts.map +0 -1
  191. package/lib/typescript/format.d.ts.map +0 -1
  192. package/lib/typescript/hooks/useAssetRecords.d.ts.map +0 -1
  193. package/lib/typescript/hooks/useAssetScanStatus.d.ts.map +0 -1
  194. package/lib/typescript/index.d.ts.map +0 -1
  195. package/lib/typescript/preset.d.ts.map +0 -1
  196. package/lib/typescript/remote.d.ts.map +0 -1
  197. package/lib/typescript/state.d.ts.map +0 -1
  198. package/lib/typescript/store/assetStore.d.ts.map +0 -1
  199. package/lib/typescript/store/baseline.d.ts.map +0 -1
  200. package/lib/typescript/store/insights.d.ts.map +0 -1
  201. package/lib/typescript/sync/assetsSyncAdapter.d.ts.map +0 -1
  202. package/lib/typescript/types.d.ts.map +0 -1
  203. package/lib/typescript/utils/deviceScale.d.ts.map +0 -1
  204. package/lib/typescript/utils/testIDs.d.ts.map +0 -1
@@ -1,18 +1 @@
1
- "use strict";
2
-
3
- /** Identify Buoy-owned resources by package location, never by asset name. */
4
- export function isBuoyAssetPath(value) {
5
- if (!value) return false;
6
- let path = value;
7
- try {
8
- path = decodeURIComponent(path);
9
- } catch {
10
- // Keep readable path segments when an unrelated escape is malformed.
11
- }
12
- path = path.replace(/\\/g, "/");
13
- return /(?:^|\/)node_modules\/@buoy-gg\/[^/]+(?:\/|$)/.test(path) || /(?:^|\/)buoy-packages\/packages\/[^/]+(?:\/|$)/.test(path) || /(?:^|\/)packages\/floating-tools-core\/(?:src|lib\/(?:module|commonjs))\/icons\/assets(?:\/|$)/.test(path);
14
- }
15
- export function isBuoyAsset(asset) {
16
- return [asset.key, asset.httpServerLocation, asset.fileSystemLocation, ...(asset.files ?? [])].some(isBuoyAssetPath);
17
- }
18
- //# sourceMappingURL=isBuoyAsset.js.map
1
+ "use strict";export function isBuoyAssetPath(e){if(!e)return false;let t=e;try{t=decodeURIComponent(t)}catch{}t=t.replace(/\\/g,"/");return/(?:^|\/)node_modules\/@buoy-gg\/[^/]+(?:\/|$)/.test(t)||/(?:^|\/)buoy-packages\/packages\/[^/]+(?:\/|$)/.test(t)||/(?:^|\/)packages\/floating-tools-core\/(?:src|lib\/(?:module|commonjs))\/icons\/assets(?:\/|$)/.test(t)}export function isBuoyAsset(e){return[e.key,e.httpServerLocation,e.fileSystemLocation,...e.files??[]].some(isBuoyAssetPath)}
@@ -1,180 +1 @@
1
- "use strict";
2
-
3
- import { Platform } from 'react-native';
4
- /**
5
- * Byte-size measurement.
6
- *
7
- * Dev only in practice: each scale variant is fetched from the Metro dev
8
- * server (HEAD first for Content-Length, GET-blob fallback since Metro
9
- * doesn't reliably answer HEAD) and the per-variant sizes are summed onto
10
- * the record. Android release resource ids and iOS file:// URIs are not
11
- * measurable from JS — those records keep `estDecodedBytes` as their only
12
- * size signal and the UI marks them as estimates.
13
- */
14
-
15
- import { assetsState } from "../state";
16
- import { getSnapshot, invalidate, updateRecord } from "../store/assetStore";
17
- import { getDevServerOrigin } from "./metroGraph";
18
- const CONCURRENCY = 4;
19
-
20
- /**
21
- * Best displayable URL for a record: the resolved runtime URI, or (dev) the
22
- * same dev-server URL the measurement pass uses — this is what gives graph-
23
- * only (never-loaded) images real thumbnails.
24
- */
25
- export function previewURL(record) {
26
- if (record.resolvedUri) return record.resolvedUri;
27
- const variants = variantURLs(record);
28
- return variants.length ? variants[0].url : null;
29
- }
30
-
31
- /**
32
- * Image source for thumbnails/previews. On device the NUMERIC registry id is
33
- * preferred (resolves natively — works for Android release resource ids too).
34
- * On dashboard mirrors that id belongs to the DEVICE's registry and rn-web
35
- * throws "asset with ID N could not be found" — use the device's http(s)
36
- * URL instead (the Metro dev server is reachable from the desktop).
37
- */
38
- export function displaySource(record) {
39
- const mirror = assetsState().captureDisabled;
40
- if (!mirror && record.registryId != null) return record.registryId;
41
- const uri = previewURL(record);
42
- if (!uri) return null;
43
- if (mirror && !/^https?:\/\//.test(uri)) return null;
44
- return {
45
- uri
46
- };
47
- }
48
-
49
- /** All scale-variant URLs for a record, derived without re-encoding pitfalls. */
50
- export function variantURLs(record) {
51
- const scales = record.scales.length ? record.scales : [1];
52
-
53
- // Preferred: string surgery on the URL resolveAssetSource already proved
54
- // works (handles Expo's ?unstable_path= form and monorepo rewrites).
55
- const resolved = record.resolvedUri;
56
- if (resolved && /^https?:\/\//.test(resolved) && record.resolvedScale != null) {
57
- const pickedSuffix = record.resolvedScale === 1 ? "" : `@${record.resolvedScale}x`;
58
- const marker = `${pickedSuffix}.${record.type}`;
59
- if (resolved.includes(marker) || pickedSuffix === "") {
60
- return scales.map(scale => {
61
- const suffix = scale === 1 ? "" : `@${scale}x`;
62
- const url = (pickedSuffix === "" ? resolved.replace(`.${record.type}`, `${suffix}.${record.type}`) : resolved.replace(marker, `${suffix}.${record.type}`)).replace(/ /g, "%20"); // RN's asset path builder doesn't encode spaces
63
- return {
64
- scale,
65
- url
66
- };
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()}${record.hash ? `&hash=${record.hash}` : ""}`.replace(/ /g, "%20");
81
- return {
82
- scale,
83
- url
84
- };
85
- });
86
- }
87
- function platformName() {
88
- try {
89
- return Platform.OS;
90
- } catch {
91
- return "ios";
92
- }
93
- }
94
- async function fetchSize(url) {
95
- try {
96
- const head = await fetch(url, {
97
- method: "HEAD"
98
- });
99
- if (head.ok) {
100
- const length = Number(head.headers.get("content-length"));
101
- if (Number.isFinite(length) && length > 0) return length;
102
- }
103
- } catch {
104
- // fall through to GET
105
- }
106
- try {
107
- const response = await fetch(url);
108
- if (!response.ok) return null;
109
- const blob = await response.blob();
110
- return blob.size > 0 ? blob.size : null;
111
- } catch {
112
- return null;
113
- }
114
- }
115
- async function measureRecord(record) {
116
- const variants = variantURLs(record);
117
- if (!variants.length) {
118
- updateRecord(record.id, {
119
- sizeSource: "estimate"
120
- });
121
- return;
122
- }
123
- const sizesByScale = {};
124
- let total = 0;
125
- for (const {
126
- scale,
127
- url
128
- } of variants) {
129
- const size = await fetchSize(url);
130
- if (size != null) {
131
- sizesByScale[String(scale)] = size;
132
- total += size;
133
- }
134
- }
135
- if (total > 0) {
136
- updateRecord(record.id, {
137
- sizesByScale,
138
- sizeBytes: total,
139
- sizeSource: "measured"
140
- });
141
- } else {
142
- updateRecord(record.id, {
143
- sizeSource: "estimate"
144
- });
145
- }
146
- }
147
-
148
- /** Measure every unmeasured record; safe to re-run (skips measured ones). */
149
- export async function measureSizes() {
150
- const s = assetsState();
151
- if (s.measuring) return {
152
- measured: s.measuredCount,
153
- total: getSnapshot().length
154
- };
155
- const pending = getSnapshot().filter(r => r.sizeSource !== "measured");
156
- s.measuring = true;
157
- invalidate();
158
- try {
159
- let index = 0;
160
- const worker = async () => {
161
- for (;;) {
162
- const next = pending[index++];
163
- if (!next) return;
164
- await measureRecord(next);
165
- s.measuredCount = getSnapshot().filter(r => r.sizeSource === "measured").length;
166
- }
167
- };
168
- await Promise.all(Array.from({
169
- length: Math.min(CONCURRENCY, pending.length)
170
- }, worker));
171
- } finally {
172
- s.measuring = false;
173
- invalidate();
174
- }
175
- return {
176
- measured: s.measuredCount,
177
- total: getSnapshot().length
178
- };
179
- }
180
- //# sourceMappingURL=measure.js.map
1
+ "use strict";import{Platform as p}from"react-native";import{assetsState as f}from"../state";import{getSnapshot as l,invalidate as m,updateRecord as c}from"../store/assetStore";import{getDevServerOrigin as h}from"./metroGraph";const g=4;export function previewURL(t){if(t.resolvedUri)return t.resolvedUri;const n=variantURLs(t);return n.length?n[0].url:null}export function displaySource(t){const n=f().captureDisabled;if(!n&&t.registryId!=null)return t.registryId;const e=previewURL(t);if(!e)return null;if(n&&!/^https?:\/\//.test(e))return null;return{uri:e}}export function variantURLs(t){const n=t.scales.length?t.scales:[1];const e=t.resolvedUri;if(e&&/^https?:\/\//.test(e)&&t.resolvedScale!=null){const s=t.resolvedScale===1?"":`@${t.resolvedScale}x`;const a=`${s}.${t.type}`;if(e.includes(a)||s===""){return n.map(r=>{const u=r===1?"":`@${r}x`;const o=(s===""?e.replace(`.${t.type}`,`${u}.${t.type}`):e.replace(a,`${u}.${t.type}`)).replace(/ /g,"%20");return{scale:r,url:o}})}}const i=h();if(!i||!t.httpServerLocation)return[];return n.map(s=>{const a=s===1?"":`@${s}x`;const r=`${t.httpServerLocation}/${t.name}${a}.${t.type}`;const u=r.includes("?")?"&":"?";const o=`${i}${r}${u}platform=${y()}${t.hash?`&hash=${t.hash}`:""}`.replace(/ /g,"%20");return{scale:s,url:o}})}function y(){try{return p.OS}catch{return"ios"}}async function S(t){try{const n=await fetch(t,{method:"HEAD"});if(n.ok){const e=Number(n.headers.get("content-length"));if(Number.isFinite(e)&&e>0)return e}}catch{}try{const n=await fetch(t);if(!n.ok)return null;const e=await n.blob();return e.size>0?e.size:null}catch{return null}}async function $(t){const n=variantURLs(t);if(!n.length){c(t.id,{sizeSource:"estimate"});return}const e={};let i=0;for(const{scale:s,url:a}of n){const r=await S(a);if(r!=null){e[String(s)]=r;i+=r}}if(i>0){c(t.id,{sizesByScale:e,sizeBytes:i,sizeSource:"measured"})}else{c(t.id,{sizeSource:"estimate"})}}export async function measureSizes(){const t=f();if(t.measuring)return{measured:t.measuredCount,total:l().length};const n=l().filter(e=>e.sizeSource!=="measured");t.measuring=true;m();try{let e=0;const i=async()=>{for(;;){const s=n[e++];if(!s)return;await $(s);t.measuredCount=l().filter(a=>a.sizeSource==="measured").length}};await Promise.all(Array.from({length:Math.min(g,n.length)},i))}finally{t.measuring=false;m()}return{measured:t.measuredCount,total:l().length}}
@@ -1,168 +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
- const GRAPH_TIMEOUT_MS = 90_000;
20
-
21
- /** Bound the whole discovery pass, including response body reads. */
22
- async function fetchGraphPayload(url, remainingMs) {
23
- const controller = new AbortController();
24
- let timer;
25
- try {
26
- return await Promise.race([(async () => {
27
- const response = await fetch(url, {
28
- signal: controller.signal
29
- });
30
- if (!response.ok) throw new Error(`Metro responded ${response.status} for ${url}`);
31
- return response.json();
32
- })(), new Promise((_, reject) => {
33
- timer = setTimeout(() => {
34
- reject(new Error("Asset discovery timed out. Try again."));
35
- controller.abort();
36
- }, Math.max(0, remainingMs));
37
- })]);
38
- } finally {
39
- clearTimeout(timer);
40
- }
41
- }
42
- export function getScriptURL() {
43
- try {
44
- const {
45
- NativeModules
46
- } = require("react-native");
47
- const sourceCode = NativeModules?.SourceCode;
48
- const url = sourceCode?.getConstants?.().scriptURL ?? sourceCode?.scriptURL;
49
- return typeof url === "string" ? url : null;
50
- } catch {
51
- return null;
52
- }
53
- }
54
-
55
- /** http(s) origin of the Metro dev server, or null when running embedded. */
56
- export function getDevServerOrigin() {
57
- const scriptURL = getScriptURL();
58
- const match = scriptURL?.match(/^https?:\/\/[^/]+/);
59
- return match ? match[0] : null;
60
- }
61
-
62
- /**
63
- * Candidate graph URLs, most-likely first. The straight `.bundle`→`.assets`
64
- * swap works for RN CLI, but Expo dev builds serve a VIRTUAL entry
65
- * (.expo/.virtual-metro-entry.bundle) that only exists for .bundle requests —
66
- * its .assets twin 404s — so the real entry modules are tried next, keeping
67
- * the original query string (platform/dev/etc.) intact.
68
- */
69
- export function getGraphURLCandidates() {
70
- const scriptURL = getScriptURL();
71
- if (!scriptURL || !/^https?:\/\//.test(scriptURL)) return [];
72
- const origin = getDevServerOrigin();
73
- const queryIndex = scriptURL.indexOf("?");
74
- const query = queryIndex >= 0 ? scriptURL.slice(queryIndex) : "?platform=ios&dev=true";
75
- const candidates = [];
76
- if (scriptURL.includes(".bundle")) {
77
- candidates.push(scriptURL.replace(".bundle", ".assets"));
78
- }
79
- if (origin) {
80
- candidates.push(`${origin}/node_modules/expo-router/entry.assets${query}`, `${origin}/node_modules/expo/AppEntry.assets${query}`, `${origin}/index.assets${query}`);
81
- }
82
- return candidates;
83
- }
84
-
85
- /** Fetch the full asset graph from the dev server and merge it into the store. */
86
- export async function fetchAssetGraph() {
87
- const s = assetsState();
88
- const candidates = getGraphURLCandidates();
89
- if (!candidates.length) {
90
- s.graphSupported = false;
91
- s.graphError = "No Metro dev server (embedded bundle)";
92
- invalidate();
93
- return {
94
- ok: false,
95
- message: s.graphError
96
- };
97
- }
98
- if (s.graphFetchInFlight) return {
99
- ok: false,
100
- message: "Graph fetch already running"
101
- };
102
- s.graphFetchInFlight = true;
103
- s.graphFetchStartedAt = Date.now();
104
- s.graphError = null;
105
- invalidate();
106
- const deadline = s.graphFetchStartedAt + GRAPH_TIMEOUT_MS;
107
- try {
108
- let data = null;
109
- let lastError = "";
110
- for (const url of candidates) {
111
- try {
112
- const parsed = await fetchGraphPayload(url, deadline - Date.now());
113
- if (Array.isArray(parsed)) {
114
- data = parsed;
115
- break;
116
- }
117
- lastError = "Unexpected .assets payload shape";
118
- } catch (error) {
119
- lastError = String(error?.message ?? error);
120
- if (Date.now() >= deadline) break;
121
- }
122
- }
123
- if (!Array.isArray(data)) throw new Error(lastError || "No graph endpoint answered");
124
- const graph = data;
125
- let count = 0;
126
- for (const asset of graph) {
127
- if (!asset || typeof asset.name !== "string" || typeof asset.type !== "string") {
128
- continue;
129
- }
130
- const record = upsertRecord({
131
- key: assetKey(asset.httpServerLocation, asset.name, asset.type),
132
- name: asset.name,
133
- type: asset.type,
134
- origin: "graph",
135
- hash: asset.hash,
136
- httpServerLocation: asset.httpServerLocation,
137
- width: asset.width ?? undefined,
138
- height: asset.height ?? undefined,
139
- scales: asset.scales,
140
- fileSystemLocation: asset.fileSystemLocation,
141
- files: asset.files,
142
- fileHashes: asset.fileHashes
143
- });
144
- if (record) count++;
145
- }
146
- s.graphSupported = true;
147
- s.graphCount = count;
148
- s.graphError = null;
149
- invalidate();
150
- return {
151
- ok: true,
152
- count
153
- };
154
- } catch (error) {
155
- s.graphSupported = getDevServerOrigin() != null;
156
- s.graphError = String(error?.message ?? error);
157
- invalidate();
158
- return {
159
- ok: false,
160
- message: s.graphError
161
- };
162
- } finally {
163
- s.graphFetchInFlight = false;
164
- s.graphFetchStartedAt = null;
165
- invalidate();
166
- }
167
- }
168
- //# sourceMappingURL=metroGraph.js.map
1
+ "use strict";import{assetsState as h}from"../state";import{assetKey as l,invalidate as i,upsertRecord as u}from"../store/assetStore";const d=9e4;async function f(e,r){const a=new AbortController;let n;try{return await Promise.race([(async()=>{const s=await fetch(e,{signal:a.signal});if(!s.ok)throw new Error(`Metro responded ${s.status} for ${e}`);return s.json()})(),new Promise((s,c)=>{n=setTimeout(()=>{c(new Error("Asset discovery timed out. Try again."));a.abort()},Math.max(0,r))})])}finally{clearTimeout(n)}}export function getScriptURL(){try{const{NativeModules:e}=require("react-native");const r=e?.SourceCode;const a=r?.getConstants?.().scriptURL??r?.scriptURL;return typeof a==="string"?a:null}catch{return null}}export function getDevServerOrigin(){const e=getScriptURL();const r=e?.match(/^https?:\/\/[^/]+/);return r?r[0]:null}export function getGraphURLCandidates(){const e=getScriptURL();if(!e||!/^https?:\/\//.test(e))return[];const r=getDevServerOrigin();const a=e.indexOf("?");const n=a>=0?e.slice(a):"?platform=ios&dev=true";const s=[];if(e.includes(".bundle")){s.push(e.replace(".bundle",".assets"))}if(r){s.push(`${r}/node_modules/expo-router/entry.assets${n}`,`${r}/node_modules/expo/AppEntry.assets${n}`,`${r}/index.assets${n}`)}return s}export async function fetchAssetGraph(){const e=h();const r=getGraphURLCandidates();if(!r.length){e.graphSupported=false;e.graphError="No Metro dev server (embedded bundle)";i();return{ok:false,message:e.graphError}}if(e.graphFetchInFlight)return{ok:false,message:"Graph fetch already running"};e.graphFetchInFlight=true;e.graphFetchStartedAt=Date.now();e.graphError=null;i();const a=e.graphFetchStartedAt+d;try{let n=null;let s="";for(const t of r){try{const o=await f(t,a-Date.now());if(Array.isArray(o)){n=o;break}s="Unexpected .assets payload shape"}catch(o){s=String(o?.message??o);if(Date.now()>=a)break}}if(!Array.isArray(n))throw new Error(s||"No graph endpoint answered");const c=n;let p=0;for(const t of c){if(!t||typeof t.name!=="string"||typeof t.type!=="string"){continue}const o=u({key:l(t.httpServerLocation,t.name,t.type),name:t.name,type:t.type,origin:"graph",hash:t.hash,httpServerLocation:t.httpServerLocation,width:t.width??void 0,height:t.height??void 0,scales:t.scales,fileSystemLocation:t.fileSystemLocation,files:t.files,fileHashes:t.fileHashes});if(o)p++}e.graphSupported=true;e.graphCount=p;e.graphError=null;i();return{ok:true,count:p}}catch(n){e.graphSupported=getDevServerOrigin()!=null;e.graphError=String(n?.message??n);i();return{ok:false,message:e.graphError}}finally{e.graphFetchInFlight=false;e.graphFetchStartedAt=null;i()}}
@@ -1,21 +1 @@
1
- "use strict";
2
-
3
- import { scanBrowserAssets, getBrowserAssetManifest } from './browserAssets';
4
- export function getScriptURL() {
5
- return null;
6
- }
7
- export function getDevServerOrigin() {
8
- return null;
9
- }
10
- export async function fetchAssetGraph() {
11
- scanBrowserAssets();
12
- const count = getBrowserAssetManifest().length;
13
- return count ? {
14
- ok: true,
15
- count
16
- } : {
17
- ok: false,
18
- message: 'Register a browser asset manifest to inspect files that have not loaded yet.'
19
- };
20
- }
21
- //# sourceMappingURL=metroGraph.web.js.map
1
+ "use strict";import{scanBrowserAssets as t,getBrowserAssetManifest as r}from"./browserAssets";export function getScriptURL(){return null}export function getDevServerOrigin(){return null}export async function fetchAssetGraph(){t();const e=r().length;return e?{ok:true,count:e}:{ok:false,message:"Register a browser asset manifest to inspect files that have not loaded yet."}}
@@ -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 as o,assetKey as u}from"../store/assetStore";let i;export function getRegistryModule(){if(i!==void 0)return i;let t=null;try{t=require("@react-native/assets-registry/registry")}catch{try{t=require("react-native/Libraries/Image/AssetRegistry")}catch{t=null}}i=t&&typeof t.getAssetByID==="function"?t:null;return i}export function resolveRegistryAsset(t){try{const{Image:e}=require("react-native");const r=e.resolveAssetSource(t);if(r&&typeof r.uri==="string"){return{uri:r.uri,scale:r.scale??1}}}catch{}return null}export function upsertFromPackagerAsset(t,e){const r=resolveRegistryAsset(t);return o({key:u(e.httpServerLocation,e.name,e.type),name:e.name,type:e.type,origin:"registry",registryId:t,hash:e.hash,httpServerLocation:e.httpServerLocation,width:e.width??void 0,height:e.height??void 0,scales:e.scales,resolvedUri:r?.uri,resolvedScale:r?.scale,loaded:true})}export function walkRegistry(){const t=getRegistryModule();if(!t)return 0;let e=0;for(;;){const r=t.getAssetByID(e+1);if(!r)break;e++;upsertFromPackagerAsset(e,r)}return e}const c="__buoyAssetsPatched";export function patchRegisterAsset(){const t=getRegistryModule();if(!t)return false;const e=t.registerAsset;if(e[c])return true;const r=n=>{const s=e.call(t,n);try{upsertFromPackagerAsset(s,n)}catch{}return s};r[c]=true;try{t.registerAsset=r}catch{return false}return true}