peachsim 0.1.2438 → 0.1.2440

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 (183) hide show
  1. package/README.md +30 -98
  2. package/cli/app-catalog.ts +4 -73
  3. package/cli/catalog/content.ts +1 -1
  4. package/cli/cloud-box-artifact.ts +26 -39
  5. package/cli/cloud-client.ts +69 -117
  6. package/cli/cloud-session.ts +2 -9
  7. package/cli/commands/box.ts +6 -6
  8. package/cli/commands/control.ts +4 -11
  9. package/cli/commands/flow.ts +5 -9
  10. package/cli/commands/kotlin.ts +2 -1
  11. package/cli/commands/platform.ts +21 -39
  12. package/cli/commands/record-three.ts +1 -1
  13. package/cli/commands/shell-url.ts +29 -23
  14. package/cli/dev-build-freshness.ts +4 -3
  15. package/cli/native-input.ts +2 -2
  16. package/cli/outbound-endpoints.ts +20 -45
  17. package/cli/remote-project-bundle.ts +8 -14
  18. package/cli/remote-simulators.ts +1 -1
  19. package/cli/send-to-box.ts +2 -1
  20. package/detox/jest-preset.cjs +1 -1
  21. package/detox/jest-transform.cjs +40 -2
  22. package/dist-lib/agent-daemon-client.cjs +34 -24
  23. package/dist-lib/agent-events.cjs +1 -1
  24. package/dist-lib/attached-projects.cjs +19 -17
  25. package/dist-lib/auth/shared-session.cjs +18 -16
  26. package/dist-lib/backend-origin.cjs +1 -1
  27. package/dist-lib/beta.cjs +1 -1
  28. package/dist-lib/beta.mjs +2 -1
  29. package/dist-lib/bridge-constants.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.cjs +1 -1
  31. package/dist-lib/bridge-contract-input.mjs +20 -583
  32. package/dist-lib/bridge-contract.cjs +1 -1
  33. package/dist-lib/bridge-contract.mjs +17 -99
  34. package/dist-lib/bundle-channel.cjs +8743 -5562
  35. package/dist-lib/capture-contract.cjs +1 -1
  36. package/dist-lib/capture-contract.mjs +13 -363
  37. package/dist-lib/cloud-contract.cjs +1 -1
  38. package/dist-lib/cloud-contract.mjs +34 -155
  39. package/dist-lib/cloud-test-args.cjs +1 -1
  40. package/dist-lib/cloud-test-args.mjs +2 -1
  41. package/dist-lib/cloud.cjs +1 -1
  42. package/dist-lib/cloud.mjs +26 -155
  43. package/dist-lib/config.cjs +1 -4
  44. package/dist-lib/config.mjs +11 -30
  45. package/dist-lib/detox/index.cjs +2554 -230
  46. package/dist-lib/detox/jest-preset.cjs +1 -1
  47. package/dist-lib/detox/jest-transform.cjs +40 -2
  48. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  49. package/dist-lib/esm-chunks/acorn-B27MTHKJ.mjs +50 -0
  50. package/dist-lib/esm-chunks/chunk-4U7IGWPB.mjs +42 -0
  51. package/dist-lib/esm-chunks/chunk-5CZQZKYU.mjs +10 -0
  52. package/dist-lib/esm-chunks/chunk-6HFWZJ6C.mjs +115 -0
  53. package/dist-lib/esm-chunks/chunk-6JGALQD5.mjs +12 -0
  54. package/dist-lib/esm-chunks/chunk-ADE23YGG.mjs +30 -0
  55. package/dist-lib/esm-chunks/chunk-D4Z36DQQ.mjs +186 -0
  56. package/dist-lib/esm-chunks/chunk-EATI62W3.mjs +188 -0
  57. package/dist-lib/esm-chunks/chunk-H6QIEJRC.mjs +10992 -0
  58. package/dist-lib/esm-chunks/chunk-HIK3VREC.mjs +1353 -0
  59. package/dist-lib/esm-chunks/chunk-HP7DHONL.mjs +598 -0
  60. package/dist-lib/esm-chunks/chunk-PRZI3CFF.mjs +5719 -0
  61. package/dist-lib/esm-chunks/chunk-QECVPSP3.mjs +10 -0
  62. package/dist-lib/esm-chunks/chunk-R5FNLCBO.mjs +17 -0
  63. package/dist-lib/esm-chunks/chunk-RVMUQQWC.mjs +664 -0
  64. package/dist-lib/esm-chunks/chunk-SJFNKW3W.mjs +57 -0
  65. package/dist-lib/esm-chunks/chunk-WQISIGIX.mjs +10 -0
  66. package/dist-lib/esm-chunks/chunk-X6UKJ5AX.mjs +375 -0
  67. package/dist-lib/esm-chunks/chunk-ZXNBC3PZ.mjs +18959 -0
  68. package/dist-lib/esm-chunks/metro-layout-parser-ZOI5PO4E.mjs +58 -0
  69. package/dist-lib/expo-swift-bundle.cjs +7881 -4717
  70. package/dist-lib/expo-swift-metadata.cjs +1 -1
  71. package/dist-lib/expo-swift-metadata.mjs +16 -165
  72. package/dist-lib/home-paths.cjs +1 -1
  73. package/dist-lib/host/bridge-host.cjs +15685 -11414
  74. package/dist-lib/host/fetch-proxy-handler.cjs +3928 -343
  75. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  76. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -1
  77. package/dist-lib/host/replacement-module-handler.cjs +4 -4
  78. package/dist-lib/host/websocket-proxy.cjs +1 -1
  79. package/dist-lib/index.cjs +9145 -32150
  80. package/dist-lib/jump-to-source-babel.cjs +1 -1
  81. package/dist-lib/jump-to-source-native.cjs +2 -2
  82. package/dist-lib/kotlin-host.cjs +260 -253
  83. package/dist-lib/menu.cjs +1 -1
  84. package/dist-lib/menu.mjs +5 -13
  85. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  86. package/dist-lib/metro-fingerprint-registry.mjs +5 -6
  87. package/dist-lib/metro-production-bundle.cjs +22 -3
  88. package/dist-lib/metro-production-bundle.mjs +26 -92
  89. package/dist-lib/native-app-identity-project.cjs +664 -452
  90. package/dist-lib/native-app-identity-project.mjs +509 -2318
  91. package/dist-lib/native-app-identity.cjs +1 -1
  92. package/dist-lib/native-app-identity.mjs +27 -1340
  93. package/dist-lib/native-firebase-metadata.cjs +1 -1
  94. package/dist-lib/native-firebase-metadata.mjs +5 -18
  95. package/dist-lib/pdfium-raster.cjs +1 -1
  96. package/dist-lib/pdfium-raster.mjs +2 -1
  97. package/dist-lib/plist.cjs +2 -2
  98. package/dist-lib/plist.mjs +5 -7
  99. package/dist-lib/profiles.cjs +2 -1
  100. package/dist-lib/public-brand.cjs +1 -1
  101. package/dist-lib/public-origins-lib-esm.json +246 -187
  102. package/dist-lib/public-origins-lib-static.json +1 -1
  103. package/dist-lib/public-origins-lib.json +1059 -1238
  104. package/dist-lib/react-native-host-modules.cjs +1 -1
  105. package/dist-lib/react-native-host-modules.mjs +2 -1
  106. package/dist-lib/reap-browser.cjs +18 -7
  107. package/dist-lib/scripts/dev-server-scanner.cjs +6 -230
  108. package/dist-lib/sdk.cjs +1 -1
  109. package/dist-lib/sdk.mjs +22 -78
  110. package/dist-lib/skills.cjs +21694 -17393
  111. package/dist-lib/swift-compile.cjs +1355 -1322
  112. package/dist-lib/swift-compile.mjs +68 -19013
  113. package/dist-lib/swift-package.cjs +1 -1
  114. package/dist-lib/swift-package.mjs +35 -630
  115. package/dist-lib/swift-submit.cjs +1 -1
  116. package/dist-lib/swift-submit.mjs +9 -24
  117. package/dist-lib/swift-toolchain.cjs +1 -1
  118. package/dist-lib/swift.cjs +1 -1
  119. package/dist-lib/vendor/@peculiar/x509.cjs +18061 -0
  120. package/dist-lib/vendor/acorn.cjs +5699 -0
  121. package/dist-lib/vendor/bplist-parser.cjs +1589 -0
  122. package/dist-lib/vendor/ignore.cjs +455 -0
  123. package/dist-lib/vendor/magic-string.cjs +1693 -0
  124. package/dist-lib/vendor/plist.cjs +10978 -0
  125. package/dist-lib/vendor/smol-toml.cjs +768 -0
  126. package/dist-lib/vendor/stream-json.cjs +1997 -0
  127. package/dist-lib/vendor/sucrase/dist/index.js.cjs +23593 -0
  128. package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +15750 -0
  129. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +11316 -0
  130. package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +482 -0
  131. package/dist-lib/vendor/sucrase.cjs +23593 -0
  132. package/dist-lib/vendor/terser.cjs +36874 -0
  133. package/dist-lib/vendor/valibot.cjs +6253 -0
  134. package/dist-lib/vendor/zod.cjs +23262 -0
  135. package/dist-lib/worklet-executable.cjs +3 -3
  136. package/dist-lib/worklet-executable.mjs +11 -16
  137. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +4 -0
  138. package/dist-types/packages/peach-engine/src/config.d.ts +1 -1
  139. package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
  140. package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +9 -0
  141. package/kotlin/fork/NOTICE +3 -0
  142. package/kotlin/sdk.tar.gz +0 -0
  143. package/kotlin/toolchain.json +6 -6
  144. package/package.json +17 -121
  145. package/runtime-companion.json +1 -1
  146. package/scripts/dev-server-scanner.ts +13 -223
  147. package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/NSDateComponentsFormatter.h +1 -1
  148. package/src/android-autolinking.ts +2 -2
  149. package/src/bundle-channel.mjs +3 -15
  150. package/src/cloud-contract.ts +3 -4
  151. package/src/config.ts +0 -5
  152. package/src/host/bridge-host.ts +21 -1
  153. package/src/host/server-scan-handler.ts +1 -9
  154. package/src/index.ts +0 -2
  155. package/src/kotlin-host.ts +1 -2
  156. package/src/kotlinDiscoveryContract.ts +1 -0
  157. package/src/metro-production-bundle.ts +28 -6
  158. package/src/native-seam-manifest.ts +0 -13
  159. package/src/native-slices.ts +1 -1
  160. package/src/one-native-app-catalog.ts +8 -27
  161. package/src/one-native-app-config.ts +95 -0
  162. package/src/one-native-source.ts +250 -0
  163. package/src/one-widget-metadata.ts +45 -126
  164. package/src/oneWidgetContract.ts +80 -117
  165. package/src/serverDiscoveryContract.ts +0 -1
  166. package/src/simulator-route.ts +8 -0
  167. package/src/swift-compile.ts +13 -7
  168. package/src/swift-host.ts +2 -0
  169. package/src/swift-package-manifest.ts +13 -8
  170. package/src/vite-plugin.ts +2 -2
  171. package/src/xcode-project.ts +1 -1
  172. package/dist-lib/metro.cjs +0 -27984
  173. package/dist-lib/vite-swift.cjs +0 -43376
  174. package/dist-lib/vite.cjs +0 -21456
  175. package/src/androidAutolinkingContract.ts +0 -48
  176. package/src/androidRootModuleContract.ts +0 -39
  177. package/src/dev-server-open.ts +0 -92
  178. package/src/metro-plugin.ts +0 -578
  179. package/src/one-widget-discovery.ts +0 -23
  180. package/src/swift-vite-lifetime.ts +0 -42
  181. package/src/vite-plugin-one.ts +0 -746
  182. package/src/vite-plugin-swift.ts +0 -225
  183. package/src/vite.d.ts +0 -10
@@ -0,0 +1,57 @@
1
+ /*! peach v0.1.2440 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
+
3
+ // ../peach-globals/src/bundle-global-footer.ts
4
+ function findBundleFooter(source, prefix) {
5
+ let end = source.length;
6
+ while (end > 0) {
7
+ const newline = source.lastIndexOf("\n", end - 1);
8
+ if (newline < 0) return -1;
9
+ const line = newline + 1;
10
+ if (source.startsWith(prefix, line)) return newline;
11
+ if (!isFooterBlockLine(source, line, end)) return -1;
12
+ end = newline;
13
+ }
14
+ return -1;
15
+ }
16
+ function isFooterBlockLine(source, line, end) {
17
+ return line === end || source.startsWith("globalThis.", line) || source.startsWith("//", line);
18
+ }
19
+ function readFooter(source, prefix, suffix, name) {
20
+ const start = findBundleFooter(source, prefix);
21
+ if (start < 0) return null;
22
+ const end = source.indexOf("\n", start + 1);
23
+ const line = source.slice(start + 1, end < 0 ? void 0 : end);
24
+ if (!line.endsWith(suffix)) throw new Error(`${name} footer is truncated`);
25
+ const value = JSON.parse(
26
+ line.slice(prefix.length, suffix ? -suffix.length : void 0)
27
+ );
28
+ if (value === null) throw new Error(`${name} footer has no metadata`);
29
+ return value;
30
+ }
31
+ function readBundleGlobalFooter(source, name) {
32
+ return readFooter(source, `globalThis.${name}=`, ";", name);
33
+ }
34
+ function detachFooter(source, prefix, suffix, name) {
35
+ const start = findBundleFooter(source, prefix);
36
+ if (start < 0) return { source, value: null };
37
+ const value = readFooter(source, prefix, suffix, name);
38
+ const end = source.indexOf("\n", start + 1);
39
+ return { source: source.slice(0, start) + (end < 0 ? "" : source.slice(end)), value };
40
+ }
41
+ function insertBundleGlobalFooter(source, name, value) {
42
+ return insertFooter(source, `globalThis.${name}=`, ";", name, value);
43
+ }
44
+ function insertFooter(source, prefix, suffix, name, value) {
45
+ source = detachFooter(source, prefix, suffix, name).source;
46
+ const json = JSON.stringify(value).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/<\//g, "<\\/");
47
+ const footer = `
48
+ ${prefix}${json}${suffix}`;
49
+ const identity = findBundleFooter(source, "globalThis.__sootsimModulePaths=");
50
+ return identity < 0 ? source + footer : source.slice(0, identity) + footer + source.slice(identity);
51
+ }
52
+
53
+ export {
54
+ findBundleFooter,
55
+ readBundleGlobalFooter,
56
+ insertBundleGlobalFooter
57
+ };
@@ -0,0 +1,10 @@
1
+ /*! peach v0.1.2440 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
+
3
+ // src/is-record.ts
4
+ function isRecord(value) {
5
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6
+ }
7
+
8
+ export {
9
+ isRecord
10
+ };
@@ -0,0 +1,375 @@
1
+ /*! peach v0.1.2440 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
+
3
+ // src/capture-contract.ts
4
+ var RNX_SCREEN_CAPTURE_VERSION = 1;
5
+ function isLiveRasterSource(node) {
6
+ const source = node.props?.source;
7
+ return node.type === "image" && !!source && typeof source === "object" && "uri" in source && typeof source.uri === "string" && source.uri.startsWith("live:");
8
+ }
9
+ function rasterLayerFrame(node) {
10
+ const visible = node.visibleFrame;
11
+ if (isLiveRasterSource(node) && visible && visible.width > 0 && visible.height > 0) {
12
+ return { x: visible.x, y: visible.y, width: visible.width, height: visible.height };
13
+ }
14
+ return node.frame ?? {
15
+ x: node.absolutePosition.x,
16
+ y: node.absolutePosition.y,
17
+ width: node.layout.width,
18
+ height: node.layout.height
19
+ };
20
+ }
21
+ function selectRnxRasterNodeIds(tree, pixelRatio) {
22
+ const nodesById = new Map(tree.nodes.map((node) => [node.nodeId, node]));
23
+ const maxLayerArea = tree.width * tree.height * 0.25;
24
+ const eligible = /* @__PURE__ */ new Map();
25
+ for (const node of tree.nodes) {
26
+ const liveVideo = isLiveRasterSource(node);
27
+ const visibleFrame = liveVideo ? rasterLayerFrame(node) : node.visibleFrame ?? node.frame;
28
+ if (!visibleFrame || visibleFrame.width <= 0 || visibleFrame.height <= 0) continue;
29
+ const glass = node.style._liquidGlass !== void 0 || node.style._liquidGlassEdge !== void 0 || node.style._liquidGlassMaterialTint !== void 0;
30
+ const unsupported = node.type === "masked-view" || liveVideo || node.type === "text" && typeof node.text === "string" && (/\p{Emoji_Presentation}/u.test(node.text) || /\uFE0F|\u200D|\u20E3|\p{Emoji_Modifier}|\p{Regional_Indicator}/u.test(
31
+ node.text
32
+ )) || glass;
33
+ if (!unsupported) continue;
34
+ const captured = rasterLayerFrame(node);
35
+ const area = captured.width * captured.height;
36
+ if (liveVideo || area <= maxLayerArea) {
37
+ eligible.set(node.nodeId, { nodeId: node.nodeId, area, liveVideo, ownPaint: false });
38
+ } else if (glass) {
39
+ eligible.set(node.nodeId, { nodeId: node.nodeId, area, liveVideo, ownPaint: true });
40
+ }
41
+ }
42
+ for (const nodeId of [...eligible.keys()]) {
43
+ let parentNodeId = nodesById.get(nodeId)?.parentNodeId ?? null;
44
+ while (parentNodeId !== null) {
45
+ const parent = eligible.get(parentNodeId);
46
+ if (parent && !parent.ownPaint) {
47
+ eligible.delete(nodeId);
48
+ break;
49
+ }
50
+ parentNodeId = nodesById.get(parentNodeId)?.parentNodeId ?? null;
51
+ }
52
+ }
53
+ const candidates = [...eligible.values()].sort(
54
+ (left, right) => Number(right.liveVideo) - Number(left.liveVideo) || Number(right.ownPaint) - Number(left.ownPaint) || left.area - right.area || left.nodeId - right.nodeId
55
+ );
56
+ const screenArea = tree.width * tree.height;
57
+ const selection = { nodeIds: /* @__PURE__ */ new Set(), ownPaint: /* @__PURE__ */ new Set() };
58
+ let atlasArea = 0;
59
+ let layerArea = 0;
60
+ for (const candidate of candidates) {
61
+ const leading = candidate.liveVideo || candidate.ownPaint;
62
+ if (atlasArea + candidate.area > screenArea * (leading ? 1 : 1.25) || !leading && layerArea + candidate.area > screenArea * 0.5) {
63
+ continue;
64
+ }
65
+ selection.nodeIds.add(candidate.nodeId);
66
+ if (candidate.ownPaint) selection.ownPaint.add(candidate.nodeId);
67
+ atlasArea += candidate.area;
68
+ if (!leading) layerArea += candidate.area;
69
+ }
70
+ const picked = [...selection.nodeIds];
71
+ while (picked.length > 0) {
72
+ const fits = fitRnxCaptureRegions(
73
+ rnxRasterRegionRequests(tree, selection),
74
+ pixelRatio,
75
+ {
76
+ pixelWidth: Math.round(tree.width * pixelRatio),
77
+ pixelHeight: Math.round(tree.height * pixelRatio)
78
+ }
79
+ );
80
+ if (fits) break;
81
+ const dropped = picked.pop();
82
+ selection.nodeIds.delete(dropped);
83
+ selection.ownPaint.delete(dropped);
84
+ }
85
+ return selection;
86
+ }
87
+ function rnxRasterFrames(tree, nodeIds) {
88
+ const frames = /* @__PURE__ */ new Map();
89
+ for (const node of tree.nodes) {
90
+ if (!nodeIds.has(node.nodeId)) continue;
91
+ const frame = rasterLayerFrame(node);
92
+ const glassOutset = liquidGlassPaintOutset(node.style._liquidGlass, frame);
93
+ const shadowRadius = typeof node.style.shadowRadius === "number" ? node.style.shadowRadius : 0;
94
+ const shadowOffset = node.style.shadowOffset;
95
+ const shadowOffsetX = shadowOffset && typeof shadowOffset === "object" && typeof Reflect.get(shadowOffset, "width") === "number" ? Reflect.get(shadowOffset, "width") : 0;
96
+ const shadowOffsetY = shadowOffset && typeof shadowOffset === "object" && typeof Reflect.get(shadowOffset, "height") === "number" ? Reflect.get(shadowOffset, "height") : 0;
97
+ const left = Math.max(
98
+ 0,
99
+ frame.x - Math.max(glassOutset.x, shadowRadius - shadowOffsetX, 0)
100
+ );
101
+ const top = Math.max(
102
+ 0,
103
+ frame.y - Math.max(glassOutset.top, shadowRadius - shadowOffsetY, 0)
104
+ );
105
+ const right = Math.min(
106
+ tree.width,
107
+ frame.x + frame.width + Math.max(glassOutset.x, shadowRadius + shadowOffsetX, 0)
108
+ );
109
+ const bottom = Math.min(
110
+ tree.height,
111
+ frame.y + frame.height + Math.max(glassOutset.bottom, shadowRadius + shadowOffsetY, 0)
112
+ );
113
+ if (right > left && bottom > top) {
114
+ frames.set(node.nodeId, {
115
+ x: left,
116
+ y: top,
117
+ width: right - left,
118
+ height: bottom - top
119
+ });
120
+ }
121
+ }
122
+ return frames;
123
+ }
124
+ function liquidGlassPaintOutset(glass, frame) {
125
+ const outset = { x: 0, top: 0, bottom: 0 };
126
+ if (!glass || typeof glass !== "object") return outset;
127
+ const contour = Reflect.get(glass, "contour");
128
+ const shadows = [
129
+ Reflect.get(glass, "shadow"),
130
+ Math.min(frame.width, frame.height) > 62 ? Reflect.get(glass, "tallShadow") : null,
131
+ ...Array.isArray(contour) ? contour : []
132
+ ];
133
+ for (const shadow of shadows) {
134
+ if (!shadow || typeof shadow !== "object") continue;
135
+ const sigma = Reflect.get(shadow, "sigma");
136
+ if (typeof sigma !== "number") continue;
137
+ const offsetY = Reflect.get(shadow, "offsetY");
138
+ const spread = Reflect.get(shadow, "spread");
139
+ const [spreadX, spreadY] = typeof spread === "number" ? [spread, spread] : Array.isArray(spread) && typeof spread[0] === "number" && typeof spread[1] === "number" ? [spread[0], spread[1]] : [0, 0];
140
+ const dy = typeof offsetY === "number" ? offsetY : 0;
141
+ const blur = sigma * 3;
142
+ outset.x = Math.max(outset.x, spreadX + blur);
143
+ outset.top = Math.max(outset.top, spreadY + blur - dy);
144
+ outset.bottom = Math.max(outset.bottom, spreadY + blur + dy);
145
+ }
146
+ return outset;
147
+ }
148
+ function rnxCaptureRasterRegions(capture, pixelRatio) {
149
+ const tree = {
150
+ width: capture.tree.viewport.width,
151
+ height: capture.tree.viewport.height,
152
+ nodes: capture.tree.nodes.map((node) => ({
153
+ nodeId: node.nodeId,
154
+ parentNodeId: node.parentNodeId,
155
+ type: node.type,
156
+ props: node.props,
157
+ text: node.text,
158
+ style: node.style.resolved,
159
+ layout: node.layout.local,
160
+ frame: node.layout.frame,
161
+ absolutePosition: node.layout.absolutePosition,
162
+ visibleFrame: node.layout.visibleFrame
163
+ }))
164
+ };
165
+ const selection = selectRnxRasterNodeIds(tree, pixelRatio);
166
+ return rnxRasterRegionRequests(tree, selection);
167
+ }
168
+ function rnxRasterRegionRequests(tree, selection) {
169
+ const frames = rnxRasterFrames(tree, selection.nodeIds);
170
+ return [...selection.nodeIds].flatMap((nodeId) => {
171
+ const frame = frames.get(nodeId);
172
+ if (!frame) return [];
173
+ return [
174
+ {
175
+ key: String(nodeId),
176
+ nodeId,
177
+ frame,
178
+ ...selection.ownPaint.has(nodeId) ? { ownPaint: true } : {}
179
+ }
180
+ ];
181
+ });
182
+ }
183
+ function packRnxCaptureRegions(regions, pixelRatio, surface) {
184
+ const packed = fitRnxCaptureRegions(regions, pixelRatio, surface);
185
+ if (!packed) throw new Error("capture regions cannot fit in one bounded atlas");
186
+ return packed;
187
+ }
188
+ function fitRnxCaptureRegions(regions, pixelRatio, surface) {
189
+ const physical = regions.map((region) => {
190
+ let left = Math.floor(region.frame.x * pixelRatio);
191
+ let top = Math.floor(region.frame.y * pixelRatio);
192
+ let right = Math.ceil((region.frame.x + region.frame.width) * pixelRatio);
193
+ let bottom = Math.ceil((region.frame.y + region.frame.height) * pixelRatio);
194
+ if (left / pixelRatio > region.frame.x) left -= 1;
195
+ if (top / pixelRatio > region.frame.y) top -= 1;
196
+ if (left / pixelRatio + (right - left) / pixelRatio < region.frame.x + region.frame.width)
197
+ right += 1;
198
+ if (top / pixelRatio + (bottom - top) / pixelRatio < region.frame.y + region.frame.height)
199
+ bottom += 1;
200
+ if (left < 0 || top < 0 || right > surface.pixelWidth || bottom > surface.pixelHeight || right <= left || bottom <= top) {
201
+ throw new Error(`capture region ${region.key} is outside the app surface`);
202
+ }
203
+ return {
204
+ key: region.key,
205
+ nodeId: region.nodeId,
206
+ ...region.ownPaint ? { ownPaint: true } : {},
207
+ frame: {
208
+ x: left / pixelRatio,
209
+ y: top / pixelRatio,
210
+ width: (right - left) / pixelRatio,
211
+ height: (bottom - top) / pixelRatio
212
+ },
213
+ sourceX: left,
214
+ sourceY: top,
215
+ pixelWidth: right - left,
216
+ pixelHeight: bottom - top
217
+ };
218
+ });
219
+ const largestWidth = Math.max(...physical.map((region) => region.pixelWidth));
220
+ const totalArea = physical.reduce(
221
+ (area, region) => area + region.pixelWidth * region.pixelHeight,
222
+ 0
223
+ );
224
+ if (totalArea > 4194304) return null;
225
+ const candidates = [
226
+ largestWidth,
227
+ Math.max(largestWidth, Math.ceil(Math.sqrt(totalArea))),
228
+ Math.max(largestWidth, surface.pixelWidth),
229
+ 4096
230
+ ];
231
+ const ordered = [...physical].sort(
232
+ (left, right) => right.pixelHeight - left.pixelHeight || right.pixelWidth - left.pixelWidth || left.key.localeCompare(right.key)
233
+ );
234
+ let best = null;
235
+ for (const candidate of [...new Set(candidates)]) {
236
+ if (candidate > 4096) continue;
237
+ let x = 0;
238
+ let y = 0;
239
+ let rowHeight = 0;
240
+ let usedWidth = 0;
241
+ const packed = [];
242
+ for (const region of ordered) {
243
+ if (x > 0 && x + region.pixelWidth > candidate) {
244
+ y += rowHeight;
245
+ x = 0;
246
+ rowHeight = 0;
247
+ }
248
+ packed.push({ ...region, atlasX: x, atlasY: y });
249
+ x += region.pixelWidth;
250
+ rowHeight = Math.max(rowHeight, region.pixelHeight);
251
+ usedWidth = Math.max(usedWidth, x);
252
+ }
253
+ const height2 = y + rowHeight;
254
+ if (height2 > 4096 || usedWidth * height2 > 4194304) continue;
255
+ const result = { width: usedWidth, height: height2, regions: packed };
256
+ if (!best || result.width * result.height < best.width * best.height) best = result;
257
+ }
258
+ if (!best) return null;
259
+ const width = best.width / pixelRatio;
260
+ const height = best.height / pixelRatio;
261
+ return {
262
+ width,
263
+ height,
264
+ pixelWidth: best.width,
265
+ pixelHeight: best.height,
266
+ regions: best.regions,
267
+ atlasRegions: best.regions.map((region) => ({
268
+ key: region.key,
269
+ nodeId: region.nodeId,
270
+ ...region.ownPaint ? { ownPaint: true } : {},
271
+ frame: region.frame,
272
+ // a region flush with the far edge is anchored to the logical edge so
273
+ // its source never runs past the atlas by a rounding hair
274
+ source: {
275
+ x: region.atlasX + region.pixelWidth === best.width ? width - region.frame.width : region.atlasX / pixelRatio,
276
+ y: region.atlasY + region.pixelHeight === best.height ? height - region.frame.height : region.atlasY / pixelRatio,
277
+ width: region.frame.width,
278
+ height: region.frame.height
279
+ }
280
+ }))
281
+ };
282
+ }
283
+ function captureRecord(value) {
284
+ return value !== null && typeof value === "object" && !Array.isArray(value);
285
+ }
286
+ function captureInteger(value) {
287
+ return typeof value === "number" && Number.isSafeInteger(value);
288
+ }
289
+ function captureNumber(value) {
290
+ return typeof value === "number" && Number.isFinite(value);
291
+ }
292
+ function captureNullableString(value) {
293
+ return value === null || typeof value === "string";
294
+ }
295
+ function captureRect(value) {
296
+ return captureRecord(value) && captureNumber(value.x) && captureNumber(value.y) && captureNumber(value.width) && captureNumber(value.height);
297
+ }
298
+ function captureOptionalString(value) {
299
+ return value === void 0 || typeof value === "string";
300
+ }
301
+ function captureOptionalNullableString(value) {
302
+ return value === void 0 || captureNullableString(value);
303
+ }
304
+ function captureFontRegistration(value) {
305
+ return captureRecord(value) && typeof value.family === "string" && value.family.length > 0 && captureOptionalString(value.url) && captureOptionalString(value.sourceLabel) && captureOptionalNullableString(value.parsedFamily) && captureOptionalNullableString(value.parsedPostScript) && captureOptionalNullableString(value.fullName);
306
+ }
307
+ function capturePoint(value) {
308
+ return captureRecord(value) && captureNumber(value.x) && captureNumber(value.y);
309
+ }
310
+ function captureNode(value) {
311
+ if (!captureRecord(value) || !captureInteger(value.nodeId) || !(value.parentNodeId === null || captureInteger(value.parentNodeId)) || !Array.isArray(value.childNodeIds) || !value.childNodeIds.every(captureInteger) || !captureInteger(value.paintIndex) || typeof value.type !== "string" || !captureNullableString(value.id) || !captureNullableString(value.testID) || !captureNullableString(value.text) || !captureInteger(value.childCount) || !captureRecord(value.accessibility) || !captureRecord(value.interaction) || !captureRecord(value.layout) || !captureRecord(value.style) || !captureRecord(value.source) || !captureRecord(value.props) || !captureRecord(value.inspection)) {
312
+ return false;
313
+ }
314
+ const accessibility = value.accessibility;
315
+ if (typeof accessibility.accessible !== "boolean" || !captureNullableString(accessibility.label) || !captureNullableString(accessibility.role) || !captureNullableString(accessibility.hint) || !(accessibility.liveRegion === null || accessibility.liveRegion === "none" || accessibility.liveRegion === "polite" || accessibility.liveRegion === "assertive") || !(accessibility.state === null || captureRecord(accessibility.state)) || !(accessibility.value === null || captureRecord(accessibility.value))) {
316
+ return false;
317
+ }
318
+ const interaction = value.interaction;
319
+ if (typeof interaction.pressed !== "boolean" || typeof interaction.pressable !== "boolean" || typeof interaction.textInput !== "boolean" || !(interaction.textSelection === null || captureRecord(interaction.textSelection)) || typeof interaction.secureTextEntry !== "boolean" || !captureNullableString(interaction.placeholder) || !capturePoint(interaction.scrollOffset) || !(interaction.zoomScale === null || captureNumber(interaction.zoomScale)) || typeof interaction.nativePinchEnabled !== "boolean" || !(interaction.contentOffsetProp === null || captureRecord(interaction.contentOffsetProp)) || !(interaction.strokeDashoffsetProp === null || captureNumber(interaction.strokeDashoffsetProp))) {
320
+ return false;
321
+ }
322
+ const layout = value.layout;
323
+ if (!captureRect(layout.local) || !(layout.frame === null || captureRect(layout.frame)) || !capturePoint(layout.absolutePosition) || !(layout.visibleFrame === null || captureRect(layout.visibleFrame))) {
324
+ return false;
325
+ }
326
+ const style = value.style;
327
+ return captureRecord(style.resolved) && captureRecord(style.authored) && captureRecord(style.computed) && captureRecord(style.tokenBindings) && (value.textLines === void 0 || Array.isArray(value.textLines));
328
+ }
329
+ function isRnxScreenCapture(value) {
330
+ if (!captureRecord(value) || value.contractVersion !== RNX_SCREEN_CAPTURE_VERSION || !captureInteger(value.capturedAt) || !(value.committedRoute === void 0 || value.committedRoute === null || captureRecord(value.committedRoute) && typeof value.committedRoute.href === "string" && value.committedRoute.href.startsWith("/")) || !captureRecord(value.tree) || !(value.fonts === void 0 || Array.isArray(value.fonts) && value.fonts.length <= 200 && value.fonts.every(captureFontRegistration)) || !(value.visual === void 0 || captureRecord(value.visual))) {
331
+ return false;
332
+ }
333
+ const tree = value.tree;
334
+ const visual = value.visual;
335
+ return captureRecord(tree.viewport) && captureInteger(tree.viewport.width) && tree.viewport.width > 0 && captureInteger(tree.viewport.height) && tree.viewport.height > 0 && captureInteger(tree.rootNodeId) && (tree.commitRevision === void 0 || captureInteger(tree.commitRevision)) && Array.isArray(tree.nodes) && tree.nodes.every(captureNode) && (visual === void 0 || visual.kind === "png" && (visual.producer === "headless-cpu-app-surface" || visual.producer === "browser-compositor-app-surface") && typeof visual.dataUri === "string" && visual.dataUri.startsWith("data:image/png;base64,") && captureInteger(visual.pixelWidth) && visual.pixelWidth > 0 && captureInteger(visual.pixelHeight) && visual.pixelHeight > 0);
336
+ }
337
+ function isRnxCaptureRegionAtlas(value) {
338
+ if (!captureRecord(value) || value.kind !== "png-atlas" || value.producer !== "headless-cpu-app-surface" && value.producer !== "browser-compositor-app-surface" || typeof value.dataUri !== "string" || !value.dataUri.startsWith("data:image/png;base64,") || !captureNumber(value.width) || value.width <= 0 || !captureNumber(value.height) || value.height <= 0 || !captureInteger(value.pixelWidth) || value.pixelWidth <= 0 || !captureInteger(value.pixelHeight) || value.pixelHeight <= 0 || !Array.isArray(value.regions) || value.regions.length === 0 || value.regions.length > 256) {
339
+ return false;
340
+ }
341
+ const scale = value.pixelWidth / value.width;
342
+ if (!Number.isInteger(scale) || scale < 1 || scale > 4 || Math.abs(value.height * scale - value.pixelHeight) > 1e-6) {
343
+ return false;
344
+ }
345
+ const keys = /* @__PURE__ */ new Set();
346
+ for (const region of value.regions) {
347
+ if (!captureRecord(region) || typeof region.key !== "string" || region.key.length === 0 || keys.has(region.key) || !captureInteger(region.nodeId) || region.nodeId <= 0 || region.ownPaint !== void 0 && region.ownPaint !== true || !captureRect(region.frame) || region.frame.width <= 0 || region.frame.height <= 0 || !captureRect(region.source) || region.source.x < 0 || region.source.y < 0 || region.source.width !== region.frame.width || region.source.height !== region.frame.height || region.source.x + region.source.width > value.width || region.source.y + region.source.height > value.height) {
348
+ return false;
349
+ }
350
+ keys.add(region.key);
351
+ }
352
+ return true;
353
+ }
354
+ function describeInvalidScreenCapture(value) {
355
+ if (!captureRecord(value)) return `capture is ${value === null ? "null" : typeof value}`;
356
+ const tree = value.tree;
357
+ if (!captureRecord(tree) || !Array.isArray(tree.nodes))
358
+ return `capture tree is not a node list; keys ${Object.keys(value).join(",")}`;
359
+ const index = tree.nodes.findIndex((node) => !captureNode(node));
360
+ if (index < 0)
361
+ return `tree nodes are valid; contractVersion ${String(value.contractVersion)}, capturedAt ${String(value.capturedAt)}, viewport ${JSON.stringify(tree.viewport)}, rootNodeId ${String(tree.rootNodeId)}`;
362
+ return `node ${index} of ${tree.nodes.length} is invalid: ${JSON.stringify(tree.nodes[index])?.slice(0, 2e3)}`;
363
+ }
364
+
365
+ export {
366
+ RNX_SCREEN_CAPTURE_VERSION,
367
+ selectRnxRasterNodeIds,
368
+ rnxRasterFrames,
369
+ rnxCaptureRasterRegions,
370
+ rnxRasterRegionRequests,
371
+ packRnxCaptureRegions,
372
+ isRnxScreenCapture,
373
+ isRnxCaptureRegionAtlas,
374
+ describeInvalidScreenCapture
375
+ };