@buoy-gg/images 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +58 -0
- package/README.md +58 -0
- package/lib/commonjs/capture/actions.js +227 -0
- package/lib/commonjs/capture/actions.js.map +1 -0
- package/lib/commonjs/capture/install.js +41 -0
- package/lib/commonjs/capture/install.js.map +1 -0
- package/lib/commonjs/capture/installExpoImage.js +99 -0
- package/lib/commonjs/capture/installExpoImage.js.map +1 -0
- package/lib/commonjs/capture/installRnImage.js +128 -0
- package/lib/commonjs/capture/installRnImage.js.map +1 -0
- package/lib/commonjs/capture/overrides.js +286 -0
- package/lib/commonjs/capture/overrides.js.map +1 -0
- package/lib/commonjs/capture/savings.js +193 -0
- package/lib/commonjs/capture/savings.js.map +1 -0
- package/lib/commonjs/capture/shared.js +367 -0
- package/lib/commonjs/capture/shared.js.map +1 -0
- package/lib/commonjs/components/ImageDetail.js +444 -0
- package/lib/commonjs/components/ImageDetail.js.map +1 -0
- package/lib/commonjs/components/ImageDetailFooter.js +232 -0
- package/lib/commonjs/components/ImageDetailFooter.js.map +1 -0
- package/lib/commonjs/components/ImageRow.js +164 -0
- package/lib/commonjs/components/ImageRow.js.map +1 -0
- package/lib/commonjs/components/ImagesHeader.js +63 -0
- package/lib/commonjs/components/ImagesHeader.js.map +1 -0
- package/lib/commonjs/components/ImagesIcon.js +59 -0
- package/lib/commonjs/components/ImagesIcon.js.map +1 -0
- package/lib/commonjs/components/ImagesListFooter.js +194 -0
- package/lib/commonjs/components/ImagesListFooter.js.map +1 -0
- package/lib/commonjs/components/ImagesModal.js +173 -0
- package/lib/commonjs/components/ImagesModal.js.map +1 -0
- package/lib/commonjs/components/ImagesRoot.js +24 -0
- package/lib/commonjs/components/ImagesRoot.js.map +1 -0
- package/lib/commonjs/components/InsightsBar.js +59 -0
- package/lib/commonjs/components/InsightsBar.js.map +1 -0
- package/lib/commonjs/export.js +81 -0
- package/lib/commonjs/export.js.map +1 -0
- package/lib/commonjs/format.js +117 -0
- package/lib/commonjs/format.js.map +1 -0
- package/lib/commonjs/hooks/useImageRecords.js +20 -0
- package/lib/commonjs/hooks/useImageRecords.js.map +1 -0
- package/lib/commonjs/index.js +236 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/preset.js +45 -0
- package/lib/commonjs/preset.js.map +1 -0
- package/lib/commonjs/register.js +19 -0
- package/lib/commonjs/register.js.map +1 -0
- package/lib/commonjs/state.js +54 -0
- package/lib/commonjs/state.js.map +1 -0
- package/lib/commonjs/store/imageEventStore.js +160 -0
- package/lib/commonjs/store/imageEventStore.js.map +1 -0
- package/lib/commonjs/store/insights.js +76 -0
- package/lib/commonjs/store/insights.js.map +1 -0
- package/lib/commonjs/sync/imagesSyncAdapter.js +315 -0
- package/lib/commonjs/sync/imagesSyncAdapter.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/capture/actions.js +214 -0
- package/lib/module/capture/actions.js.map +1 -0
- package/lib/module/capture/install.js +36 -0
- package/lib/module/capture/install.js.map +1 -0
- package/lib/module/capture/installExpoImage.js +94 -0
- package/lib/module/capture/installExpoImage.js.map +1 -0
- package/lib/module/capture/installRnImage.js +122 -0
- package/lib/module/capture/installRnImage.js.map +1 -0
- package/lib/module/capture/overrides.js +269 -0
- package/lib/module/capture/overrides.js.map +1 -0
- package/lib/module/capture/savings.js +189 -0
- package/lib/module/capture/savings.js.map +1 -0
- package/lib/module/capture/shared.js +359 -0
- package/lib/module/capture/shared.js.map +1 -0
- package/lib/module/components/ImageDetail.js +440 -0
- package/lib/module/components/ImageDetail.js.map +1 -0
- package/lib/module/components/ImageDetailFooter.js +228 -0
- package/lib/module/components/ImageDetailFooter.js.map +1 -0
- package/lib/module/components/ImageRow.js +160 -0
- package/lib/module/components/ImageRow.js.map +1 -0
- package/lib/module/components/ImagesHeader.js +59 -0
- package/lib/module/components/ImagesHeader.js.map +1 -0
- package/lib/module/components/ImagesIcon.js +55 -0
- package/lib/module/components/ImagesIcon.js.map +1 -0
- package/lib/module/components/ImagesListFooter.js +190 -0
- package/lib/module/components/ImagesListFooter.js.map +1 -0
- package/lib/module/components/ImagesModal.js +169 -0
- package/lib/module/components/ImagesModal.js.map +1 -0
- package/lib/module/components/ImagesRoot.js +20 -0
- package/lib/module/components/ImagesRoot.js.map +1 -0
- package/lib/module/components/InsightsBar.js +55 -0
- package/lib/module/components/InsightsBar.js.map +1 -0
- package/lib/module/export.js +76 -0
- package/lib/module/export.js.map +1 -0
- package/lib/module/format.js +108 -0
- package/lib/module/format.js.map +1 -0
- package/lib/module/hooks/useImageRecords.js +16 -0
- package/lib/module/hooks/useImageRecords.js.map +1 -0
- package/lib/module/index.js +73 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/preset.js +40 -0
- package/lib/module/preset.js.map +1 -0
- package/lib/module/register.js +19 -0
- package/lib/module/register.js.map +1 -0
- package/lib/module/state.js +50 -0
- package/lib/module/state.js.map +1 -0
- package/lib/module/store/imageEventStore.js +146 -0
- package/lib/module/store/imageEventStore.js.map +1 -0
- package/lib/module/store/insights.js +71 -0
- package/lib/module/store/insights.js.map +1 -0
- package/lib/module/sync/imagesSyncAdapter.js +311 -0
- package/lib/module/sync/imagesSyncAdapter.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/capture/actions.d.ts +49 -0
- package/lib/typescript/capture/actions.d.ts.map +1 -0
- package/lib/typescript/capture/install.d.ts +15 -0
- package/lib/typescript/capture/install.d.ts.map +1 -0
- package/lib/typescript/capture/installExpoImage.d.ts +23 -0
- package/lib/typescript/capture/installExpoImage.d.ts.map +1 -0
- package/lib/typescript/capture/installRnImage.d.ts +24 -0
- package/lib/typescript/capture/installRnImage.d.ts.map +1 -0
- package/lib/typescript/capture/overrides.d.ts +83 -0
- package/lib/typescript/capture/overrides.d.ts.map +1 -0
- package/lib/typescript/capture/savings.d.ts +37 -0
- package/lib/typescript/capture/savings.d.ts.map +1 -0
- package/lib/typescript/capture/shared.d.ts +61 -0
- package/lib/typescript/capture/shared.d.ts.map +1 -0
- package/lib/typescript/components/ImageDetail.d.ts +13 -0
- package/lib/typescript/components/ImageDetail.d.ts.map +1 -0
- package/lib/typescript/components/ImageDetailFooter.d.ts +19 -0
- package/lib/typescript/components/ImageDetailFooter.d.ts.map +1 -0
- package/lib/typescript/components/ImageRow.d.ts +15 -0
- package/lib/typescript/components/ImageRow.d.ts.map +1 -0
- package/lib/typescript/components/ImagesHeader.d.ts +25 -0
- package/lib/typescript/components/ImagesHeader.d.ts.map +1 -0
- package/lib/typescript/components/ImagesIcon.d.ts +13 -0
- package/lib/typescript/components/ImagesIcon.d.ts.map +1 -0
- package/lib/typescript/components/ImagesListFooter.d.ts +8 -0
- package/lib/typescript/components/ImagesListFooter.d.ts.map +1 -0
- package/lib/typescript/components/ImagesModal.d.ts +17 -0
- package/lib/typescript/components/ImagesModal.d.ts.map +1 -0
- package/lib/typescript/components/ImagesRoot.d.ts +11 -0
- package/lib/typescript/components/ImagesRoot.d.ts.map +1 -0
- package/lib/typescript/components/InsightsBar.d.ts +13 -0
- package/lib/typescript/components/InsightsBar.d.ts.map +1 -0
- package/lib/typescript/export.d.ts +12 -0
- package/lib/typescript/export.d.ts.map +1 -0
- package/lib/typescript/format.d.ts +26 -0
- package/lib/typescript/format.d.ts.map +1 -0
- package/lib/typescript/hooks/useImageRecords.d.ts +11 -0
- package/lib/typescript/hooks/useImageRecords.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +33 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/preset.d.ts +38 -0
- package/lib/typescript/preset.d.ts.map +1 -0
- package/lib/typescript/register.d.ts +15 -0
- package/lib/typescript/register.d.ts.map +1 -0
- package/lib/typescript/state.d.ts +54 -0
- package/lib/typescript/state.d.ts.map +1 -0
- package/lib/typescript/store/imageEventStore.d.ts +34 -0
- package/lib/typescript/store/imageEventStore.d.ts.map +1 -0
- package/lib/typescript/store/insights.d.ts +11 -0
- package/lib/typescript/store/insights.d.ts.map +1 -0
- package/lib/typescript/sync/imagesSyncAdapter.d.ts +205 -0
- package/lib/typescript/sync/imagesSyncAdapter.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +121 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +67 -0
- package/register.d.ts +1 -0
- package/register.js +15 -0
- package/src/capture/actions.ts +206 -0
- package/src/capture/install.ts +36 -0
- package/src/capture/installExpoImage.ts +115 -0
- package/src/capture/installRnImage.tsx +133 -0
- package/src/capture/overrides.ts +282 -0
- package/src/capture/savings.ts +193 -0
- package/src/capture/shared.ts +387 -0
- package/src/components/ImageDetail.tsx +456 -0
- package/src/components/ImageDetailFooter.tsx +270 -0
- package/src/components/ImageRow.tsx +148 -0
- package/src/components/ImagesHeader.tsx +77 -0
- package/src/components/ImagesIcon.tsx +66 -0
- package/src/components/ImagesListFooter.tsx +193 -0
- package/src/components/ImagesModal.tsx +195 -0
- package/src/components/ImagesRoot.tsx +18 -0
- package/src/components/InsightsBar.tsx +51 -0
- package/src/export.ts +100 -0
- package/src/format.ts +85 -0
- package/src/hooks/useImageRecords.ts +24 -0
- package/src/index.tsx +108 -0
- package/src/preset.tsx +35 -0
- package/src/register.ts +17 -0
- package/src/state.ts +88 -0
- package/src/store/imageEventStore.ts +162 -0
- package/src/store/insights.ts +66 -0
- package/src/sync/imagesSyncAdapter.ts +261 -0
- package/src/types.ts +111 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @buoy-gg/images
|
|
3
|
+
*
|
|
4
|
+
* Image debugger for React Native: a live registry of every image the app
|
|
5
|
+
* loads — RN core <Image> (via the official component-decorator hook) and
|
|
6
|
+
* expo-image (via a timing-immune class patch) — with cache verdicts
|
|
7
|
+
* (memory/disk/network), load timings, decoded-vs-displayed oversize checks,
|
|
8
|
+
* estimated decoded/wasted memory, and a failure log with HTTP details where
|
|
9
|
+
* the platform provides them.
|
|
10
|
+
*
|
|
11
|
+
* Image HTTP traffic never touches the JS network stack, so network devtools
|
|
12
|
+
* cannot see it — this tool is the visibility layer for images.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Side-effect: install capture as early as this package is imported. For full
|
|
16
|
+
// RN-core coverage, import "@buoy-gg/images/register" FIRST in your entry file
|
|
17
|
+
// (the RN decorator must beat React Native's Image module evaluation).
|
|
18
|
+
import "./register";
|
|
19
|
+
|
|
20
|
+
// =============================================================================
|
|
21
|
+
// PRESET (Primary entry point — pass to <FloatingDevTools apps={[...]} />)
|
|
22
|
+
// =============================================================================
|
|
23
|
+
export { imagesToolPreset, createImagesTool } from "./preset";
|
|
24
|
+
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// ROOT (optional; capture also auto-installs on package import)
|
|
27
|
+
// =============================================================================
|
|
28
|
+
export { ImagesRoot } from "./components/ImagesRoot";
|
|
29
|
+
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// COMPONENTS
|
|
32
|
+
// =============================================================================
|
|
33
|
+
export { ImagesModal } from "./components/ImagesModal";
|
|
34
|
+
export { ImagesIcon, IMAGES_ICON_COLOR } from "./components/ImagesIcon";
|
|
35
|
+
|
|
36
|
+
// =============================================================================
|
|
37
|
+
// CAPTURE
|
|
38
|
+
// =============================================================================
|
|
39
|
+
export { installImageCapture, getCaptureStatus } from "./capture/install";
|
|
40
|
+
|
|
41
|
+
// =============================================================================
|
|
42
|
+
// ACTIONS
|
|
43
|
+
// =============================================================================
|
|
44
|
+
export {
|
|
45
|
+
hardReloadRecord,
|
|
46
|
+
retryRecord,
|
|
47
|
+
evictExpoDiskEntry,
|
|
48
|
+
} from "./capture/actions";
|
|
49
|
+
export type { ActionResult } from "./capture/actions";
|
|
50
|
+
|
|
51
|
+
// =============================================================================
|
|
52
|
+
// SIMULATION OVERRIDES
|
|
53
|
+
// =============================================================================
|
|
54
|
+
export {
|
|
55
|
+
setOverride,
|
|
56
|
+
clearOverride,
|
|
57
|
+
getOverride,
|
|
58
|
+
flashRecord,
|
|
59
|
+
setNetworkMode,
|
|
60
|
+
setBlankImages,
|
|
61
|
+
getGlobalModes,
|
|
62
|
+
setOverrideForAllMounted,
|
|
63
|
+
clearAllOverrides,
|
|
64
|
+
flashAllMounted,
|
|
65
|
+
} from "./capture/overrides";
|
|
66
|
+
export { hardReloadAllMounted } from "./capture/actions";
|
|
67
|
+
export type { ImageOverride, OverrideSource, NetworkMode } from "./capture/overrides";
|
|
68
|
+
|
|
69
|
+
// =============================================================================
|
|
70
|
+
// SAVINGS PROVER + INSIGHTS
|
|
71
|
+
// =============================================================================
|
|
72
|
+
export { proveSavings } from "./capture/savings";
|
|
73
|
+
export type { SavingsResult } from "./capture/savings";
|
|
74
|
+
export { computeInsights, insightChips } from "./store/insights";
|
|
75
|
+
export { formatRecordMarkdown, formatRegistryMarkdown } from "./export";
|
|
76
|
+
|
|
77
|
+
// =============================================================================
|
|
78
|
+
// EXTERNAL SYNC (device → desktop dashboard / MCP)
|
|
79
|
+
// =============================================================================
|
|
80
|
+
export { imagesSyncAdapter } from "./sync/imagesSyncAdapter";
|
|
81
|
+
|
|
82
|
+
// =============================================================================
|
|
83
|
+
// STORE + HOOKS
|
|
84
|
+
// =============================================================================
|
|
85
|
+
export { useImageRecords } from "./hooks/useImageRecords";
|
|
86
|
+
export {
|
|
87
|
+
clearRecords,
|
|
88
|
+
getSnapshot as getImageRecords,
|
|
89
|
+
subscribe as subscribeImageRecords,
|
|
90
|
+
computeStats,
|
|
91
|
+
oversizeFactor,
|
|
92
|
+
estDecodedBytes,
|
|
93
|
+
estWastedBytes,
|
|
94
|
+
} from "./store/imageEventStore";
|
|
95
|
+
|
|
96
|
+
// =============================================================================
|
|
97
|
+
// TYPES
|
|
98
|
+
// =============================================================================
|
|
99
|
+
export type {
|
|
100
|
+
ImageRecord,
|
|
101
|
+
ImageStats,
|
|
102
|
+
ImageInsights,
|
|
103
|
+
ImageLib,
|
|
104
|
+
ImageStatus,
|
|
105
|
+
CacheVerdict,
|
|
106
|
+
SourceKind,
|
|
107
|
+
CaptureStatus,
|
|
108
|
+
} from "./types";
|
package/src/preset.tsx
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-configured Images tool for FloatingDevTools.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```tsx
|
|
6
|
+
* import { imagesToolPreset } from '@buoy-gg/images';
|
|
7
|
+
*
|
|
8
|
+
* <FloatingDevTools apps={[imagesToolPreset]} />
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { ImagesIcon, IMAGES_ICON_COLOR } from "./components/ImagesIcon";
|
|
13
|
+
import { ImagesModal } from "./components/ImagesModal";
|
|
14
|
+
|
|
15
|
+
export const imagesToolPreset = {
|
|
16
|
+
id: "images",
|
|
17
|
+
name: "IMAGES",
|
|
18
|
+
description: "Image loads, caching, failures, and oversize checks",
|
|
19
|
+
slot: "both" as const,
|
|
20
|
+
icon: ({ size, color }: { size: number; color?: string }) => (
|
|
21
|
+
<ImagesIcon size={size} color={color || IMAGES_ICON_COLOR} />
|
|
22
|
+
),
|
|
23
|
+
component: ImagesModal,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Create a custom Images tool configuration. */
|
|
27
|
+
export function createImagesTool(
|
|
28
|
+
options: { name?: string; description?: string } = {}
|
|
29
|
+
) {
|
|
30
|
+
return {
|
|
31
|
+
...imagesToolPreset,
|
|
32
|
+
name: options.name ?? imagesToolPreset.name,
|
|
33
|
+
description: options.description ?? imagesToolPreset.description,
|
|
34
|
+
};
|
|
35
|
+
}
|
package/src/register.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side-effect entry: installs image capture on import.
|
|
3
|
+
*
|
|
4
|
+
* Import this FIRST in your app entry file so the RN-core <Image> decorator
|
|
5
|
+
* lands before React Native's Image module is evaluated:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import "@buoy-gg/images/register";
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* This module intentionally imports nothing that touches react-native's Image
|
|
12
|
+
* (directly or transitively) before installing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { installImageCapture } from "./capture/install";
|
|
16
|
+
|
|
17
|
+
installImageCapture();
|
package/src/state.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global singleton state for the Images tool.
|
|
3
|
+
*
|
|
4
|
+
* The package can get evaluated twice as two separate module instances (e.g.
|
|
5
|
+
* the `/register` entry shim resolving to one copy while the package root
|
|
6
|
+
* import resolves to another — lib vs src). If capture state lived in module
|
|
7
|
+
* scope, the early copy would install the RN decorator and collect records
|
|
8
|
+
* while the UI copy read an empty store and a false "decorator never ran"
|
|
9
|
+
* flag. Keying all mutable state on globalThis under a well-known symbol makes
|
|
10
|
+
* every copy operate on the same data.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { ImageRecord } from "./types";
|
|
14
|
+
|
|
15
|
+
export interface ImagesGlobalState {
|
|
16
|
+
// store
|
|
17
|
+
records: ImageRecord[];
|
|
18
|
+
byId: Map<number, ImageRecord>;
|
|
19
|
+
nextId: number;
|
|
20
|
+
listeners: Set<() => void>;
|
|
21
|
+
snapshot: ImageRecord[];
|
|
22
|
+
emitScheduled: boolean;
|
|
23
|
+
// install flags
|
|
24
|
+
captureInstalled: boolean;
|
|
25
|
+
rnInstalled: boolean;
|
|
26
|
+
expoInstalled: boolean;
|
|
27
|
+
// rn decorator status
|
|
28
|
+
decoratorRegistered: boolean;
|
|
29
|
+
decoratorInvoked: boolean;
|
|
30
|
+
attachSeen: number;
|
|
31
|
+
// expo patch status
|
|
32
|
+
expoAvailable: boolean;
|
|
33
|
+
expoPatched: boolean;
|
|
34
|
+
// actions
|
|
35
|
+
/** recordId → pending reload request for the RN wrapper to consume. */
|
|
36
|
+
reloadRequests: Map<number, { nonce: number; bust: boolean }>;
|
|
37
|
+
/** Notified when a reload request is issued (wrappers re-check their nonce). */
|
|
38
|
+
actionListeners: Set<() => void>;
|
|
39
|
+
/** recordId → live expo-image class instance (has reloadAsync etc.). */
|
|
40
|
+
expoInstances: Map<number, unknown>;
|
|
41
|
+
// simulation overrides
|
|
42
|
+
/** recordId → active override (source swap / forced error / style merge). */
|
|
43
|
+
overrides: Map<number, unknown>;
|
|
44
|
+
/** recordId → epoch-ms until which the locate-flash border is shown. */
|
|
45
|
+
flashUntil: Map<number, number>;
|
|
46
|
+
/** Per-record render version (bumped by any action touching that record). */
|
|
47
|
+
recordVersions: Map<number, number>;
|
|
48
|
+
/** Render version for global-mode changes (affects every image). */
|
|
49
|
+
globalVersion: number;
|
|
50
|
+
/** Monotonic counter feeding both version maps. */
|
|
51
|
+
versionCounter: number;
|
|
52
|
+
/** App-wide simulation modes. */
|
|
53
|
+
globalModes: { network: "normal" | "offline" | "cold"; blank: boolean };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const KEY = Symbol.for("buoy.images.globalState.v1");
|
|
57
|
+
|
|
58
|
+
export function imagesState(): ImagesGlobalState {
|
|
59
|
+
const g = globalThis as Record<symbol, ImagesGlobalState | undefined>;
|
|
60
|
+
if (!g[KEY]) {
|
|
61
|
+
g[KEY] = {
|
|
62
|
+
records: [],
|
|
63
|
+
byId: new Map(),
|
|
64
|
+
nextId: 1,
|
|
65
|
+
listeners: new Set(),
|
|
66
|
+
snapshot: [],
|
|
67
|
+
emitScheduled: false,
|
|
68
|
+
captureInstalled: false,
|
|
69
|
+
rnInstalled: false,
|
|
70
|
+
expoInstalled: false,
|
|
71
|
+
decoratorRegistered: false,
|
|
72
|
+
decoratorInvoked: false,
|
|
73
|
+
attachSeen: 0,
|
|
74
|
+
expoAvailable: false,
|
|
75
|
+
expoPatched: false,
|
|
76
|
+
reloadRequests: new Map(),
|
|
77
|
+
actionListeners: new Set(),
|
|
78
|
+
expoInstances: new Map(),
|
|
79
|
+
overrides: new Map(),
|
|
80
|
+
flashUntil: new Map(),
|
|
81
|
+
recordVersions: new Map(),
|
|
82
|
+
globalVersion: 0,
|
|
83
|
+
versionCounter: 0,
|
|
84
|
+
globalModes: { network: "normal", blank: false },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return g[KEY];
|
|
88
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* imageEventStore
|
|
3
|
+
*
|
|
4
|
+
* Bounded buffer of ImageRecords fed by the capture layer (installRnImage /
|
|
5
|
+
* installExpoImage). Follows the console tool's store shape — Set of
|
|
6
|
+
* listeners, frame-coalesced emit so bursty image grids don't turn every
|
|
7
|
+
* event into its own React commit — but ALL mutable state lives on the
|
|
8
|
+
* globalThis singleton (see ../state.ts) so a dual module instance of this
|
|
9
|
+
* package still reads/writes one shared store.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { PixelRatio } from "react-native";
|
|
13
|
+
import { imagesState } from "../state";
|
|
14
|
+
import type { ImageRecord, ImageStats } from "../types";
|
|
15
|
+
|
|
16
|
+
/** Max records retained before the oldest are dropped. */
|
|
17
|
+
const MAX_RECORDS = 500;
|
|
18
|
+
|
|
19
|
+
function emit(): void {
|
|
20
|
+
const s = imagesState();
|
|
21
|
+
if (s.emitScheduled) return;
|
|
22
|
+
s.emitScheduled = true;
|
|
23
|
+
requestAnimationFrame(() => {
|
|
24
|
+
s.emitScheduled = false;
|
|
25
|
+
for (const listener of s.listeners) listener();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Snapshot identity only changes on emit, so useSyncExternalStore stays cheap. */
|
|
30
|
+
function invalidate(): void {
|
|
31
|
+
const s = imagesState();
|
|
32
|
+
s.snapshot = [...s.records];
|
|
33
|
+
emit();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createRecord(
|
|
37
|
+
partial: Omit<ImageRecord, "id" | "createdAt" | "loadCount" | "mounted" | "status">
|
|
38
|
+
): ImageRecord {
|
|
39
|
+
const s = imagesState();
|
|
40
|
+
const record: ImageRecord = {
|
|
41
|
+
...partial,
|
|
42
|
+
id: s.nextId++,
|
|
43
|
+
createdAt: Date.now(),
|
|
44
|
+
status: "pending",
|
|
45
|
+
mounted: true,
|
|
46
|
+
loadCount: 0,
|
|
47
|
+
};
|
|
48
|
+
s.records.push(record);
|
|
49
|
+
s.byId.set(record.id, record);
|
|
50
|
+
if (s.records.length > MAX_RECORDS) {
|
|
51
|
+
const dropped = s.records.splice(0, s.records.length - MAX_RECORDS);
|
|
52
|
+
for (const d of dropped) s.byId.delete(d.id);
|
|
53
|
+
}
|
|
54
|
+
invalidate();
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Mutate a record in place (records are owned by the store) and notify. */
|
|
59
|
+
export function updateRecord(
|
|
60
|
+
id: number,
|
|
61
|
+
patch: Partial<ImageRecord>
|
|
62
|
+
): ImageRecord | undefined {
|
|
63
|
+
const s = imagesState();
|
|
64
|
+
const record = s.byId.get(id);
|
|
65
|
+
if (!record) return undefined;
|
|
66
|
+
Object.assign(record, patch);
|
|
67
|
+
invalidate();
|
|
68
|
+
return record;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function getRecord(id: number): ImageRecord | undefined {
|
|
72
|
+
return imagesState().byId.get(id);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function getSnapshot(): ImageRecord[] {
|
|
76
|
+
return imagesState().snapshot;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function subscribe(listener: () => void): () => void {
|
|
80
|
+
const s = imagesState();
|
|
81
|
+
s.listeners.add(listener);
|
|
82
|
+
return () => imagesState().listeners.delete(listener);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function clearRecords(): void {
|
|
86
|
+
const s = imagesState();
|
|
87
|
+
// Keep records still actively loading so in-flight events don't orphan.
|
|
88
|
+
s.records = s.records.filter(
|
|
89
|
+
(r) => r.mounted && r.status !== "loaded" && r.status !== "error"
|
|
90
|
+
);
|
|
91
|
+
s.byId = new Map(s.records.map((r) => [r.id, r]));
|
|
92
|
+
invalidate();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Derived math (shared by rows, detail view, and stats)
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
/** Physical pixels actually needed to fill the laid-out view 1:1. */
|
|
100
|
+
export function neededPixels(record: ImageRecord): { width: number; height: number } | null {
|
|
101
|
+
if (!record.layout || record.layout.width <= 0 || record.layout.height <= 0) return null;
|
|
102
|
+
const scale = PixelRatio.get();
|
|
103
|
+
return {
|
|
104
|
+
width: Math.round(record.layout.width * scale),
|
|
105
|
+
height: Math.round(record.layout.height * scale),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Linear oversize factor: how many times larger (per axis, area-normalized)
|
|
111
|
+
* the decoded bitmap is vs what the view needs. 1 = perfect, 2 = 4× the pixels.
|
|
112
|
+
*/
|
|
113
|
+
export function oversizeFactor(record: ImageRecord): number | null {
|
|
114
|
+
const needed = neededPixels(record);
|
|
115
|
+
if (!needed || !record.intrinsic) return null;
|
|
116
|
+
const neededArea = needed.width * needed.height;
|
|
117
|
+
const intrinsicArea = record.intrinsic.width * record.intrinsic.height;
|
|
118
|
+
if (neededArea <= 0 || intrinsicArea <= 0) return null;
|
|
119
|
+
return Math.sqrt(intrinsicArea / neededArea);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Estimated decoded-bitmap memory for a loaded record (RGBA8888). */
|
|
123
|
+
export function estDecodedBytes(record: ImageRecord): number {
|
|
124
|
+
if (!record.intrinsic) return 0;
|
|
125
|
+
return record.intrinsic.width * record.intrinsic.height * 4;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Decoded bytes beyond what the laid-out size needs (0 if not oversized). */
|
|
129
|
+
export function estWastedBytes(record: ImageRecord): number {
|
|
130
|
+
const needed = neededPixels(record);
|
|
131
|
+
if (!needed || !record.intrinsic) return 0;
|
|
132
|
+
const wasted =
|
|
133
|
+
(record.intrinsic.width * record.intrinsic.height -
|
|
134
|
+
needed.width * needed.height) *
|
|
135
|
+
4;
|
|
136
|
+
return Math.max(0, wasted);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function computeStats(list: ImageRecord[]): ImageStats {
|
|
140
|
+
const stats: ImageStats = {
|
|
141
|
+
total: list.length,
|
|
142
|
+
loading: 0,
|
|
143
|
+
loaded: 0,
|
|
144
|
+
errors: 0,
|
|
145
|
+
networkLoads: 0,
|
|
146
|
+
estDecodedBytes: 0,
|
|
147
|
+
estWastedBytes: 0,
|
|
148
|
+
};
|
|
149
|
+
for (const r of list) {
|
|
150
|
+
// Unmounted in-flight records are stale (the instance died mid-load) —
|
|
151
|
+
// they must not count as live in-flight work.
|
|
152
|
+
if ((r.status === "loading" || r.status === "pending") && r.mounted) stats.loading++;
|
|
153
|
+
if (r.status === "loaded") stats.loaded++;
|
|
154
|
+
if (r.status === "error") stats.errors++;
|
|
155
|
+
if (r.progressSeen || r.cacheVerdict === "none") stats.networkLoads++;
|
|
156
|
+
if (r.mounted && r.status === "loaded") {
|
|
157
|
+
stats.estDecodedBytes += estDecodedBytes(r);
|
|
158
|
+
stats.estWastedBytes += estWastedBytes(r);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return stats;
|
|
162
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-record insights — findings computed purely from data the registry
|
|
3
|
+
* already holds (no extra instrumentation): duplicate simultaneous loads,
|
|
4
|
+
* retry storms, iOS image-queue saturation, missing alt text, and
|
|
5
|
+
* layout-shifting images.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ImageInsights, ImageRecord } from "../types";
|
|
9
|
+
|
|
10
|
+
/** loadCount at/above this flags render-thrash reload storms. */
|
|
11
|
+
const RETRY_STORM_THRESHOLD = 5;
|
|
12
|
+
/** RCTImageLoader allows 4 concurrent loading tasks on iOS. */
|
|
13
|
+
const IOS_CONCURRENT_LOAD_LIMIT = 4;
|
|
14
|
+
|
|
15
|
+
export function computeInsights(records: ImageRecord[]): ImageInsights {
|
|
16
|
+
const byUri = new Map<string, number>();
|
|
17
|
+
const retryStorms: ImageInsights["retryStorms"] = [];
|
|
18
|
+
const layoutShifters: ImageInsights["layoutShifters"] = [];
|
|
19
|
+
let missingAlt = 0;
|
|
20
|
+
let rnLoading = 0;
|
|
21
|
+
|
|
22
|
+
for (const r of records) {
|
|
23
|
+
if (r.mounted && r.uri) {
|
|
24
|
+
byUri.set(r.uri, (byUri.get(r.uri) ?? 0) + 1);
|
|
25
|
+
}
|
|
26
|
+
if (r.loadCount >= RETRY_STORM_THRESHOLD) {
|
|
27
|
+
retryStorms.push({ id: r.id, uri: r.uri, loadCount: r.loadCount });
|
|
28
|
+
}
|
|
29
|
+
if ((r.layoutShifts ?? 0) > 0) {
|
|
30
|
+
layoutShifters.push({ id: r.id, uri: r.uri, shifts: r.layoutShifts ?? 0 });
|
|
31
|
+
}
|
|
32
|
+
if (r.mounted && r.hasAltText === false) missingAlt++;
|
|
33
|
+
if (r.lib === "rn" && r.mounted && r.status === "loading") rnLoading++;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const duplicates = [...byUri.entries()]
|
|
37
|
+
.filter(([, count]) => count > 1)
|
|
38
|
+
.map(([uri, count]) => ({ uri, count }))
|
|
39
|
+
.sort((a, b) => b.count - a.count);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
duplicates,
|
|
43
|
+
retryStorms: retryStorms.sort((a, b) => b.loadCount - a.loadCount),
|
|
44
|
+
queueSaturated: rnLoading > IOS_CONCURRENT_LOAD_LIMIT,
|
|
45
|
+
missingAlt,
|
|
46
|
+
layoutShifters,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Compact one-line chips for UI/MCP surfacing. Empty array = all clear. */
|
|
51
|
+
export function insightChips(insights: ImageInsights): string[] {
|
|
52
|
+
const chips: string[] = [];
|
|
53
|
+
if (insights.duplicates.length > 0) {
|
|
54
|
+
const extra = insights.duplicates.reduce((n, d) => n + d.count - 1, 0);
|
|
55
|
+
chips.push(`${insights.duplicates.length} duplicate URL${insights.duplicates.length > 1 ? "s" : ""} (${extra} redundant loads)`);
|
|
56
|
+
}
|
|
57
|
+
if (insights.retryStorms.length > 0) {
|
|
58
|
+
chips.push(`${insights.retryStorms.length} retry storm${insights.retryStorms.length > 1 ? "s" : ""}`);
|
|
59
|
+
}
|
|
60
|
+
if (insights.queueSaturated) chips.push("iOS image queue saturated (>4 loading)");
|
|
61
|
+
if (insights.missingAlt > 0) chips.push(`${insights.missingAlt} missing alt text`);
|
|
62
|
+
if (insights.layoutShifters.length > 0) {
|
|
63
|
+
chips.push(`${insights.layoutShifters.length} layout-shifting image${insights.layoutShifters.length > 1 ? "s" : ""}`);
|
|
64
|
+
}
|
|
65
|
+
return chips;
|
|
66
|
+
}
|