peachsim 0.1.1653 → 0.1.1655

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 (111) hide show
  1. package/cli/app-stubs.ts +97 -14
  2. package/cli/bridge-diagnostics.ts +10 -7
  3. package/cli/cloud-client.ts +11 -2
  4. package/cli/commands/doctor.ts +20 -10
  5. package/cli/commands/inspect/core.ts +2 -1
  6. package/cli/commands/inspect/shared.ts +2 -0
  7. package/cli/commands/inspect.ts +11 -2
  8. package/cli/output-redaction.ts +22 -6
  9. package/cli/pause-aware-timeout.ts +24 -10
  10. package/cli/ws-bridge.ts +17 -1
  11. package/dist-lib/agent-daemon-client.cjs +1 -1
  12. package/dist-lib/agent-events.cjs +1 -1
  13. package/dist-lib/attached-projects.cjs +1 -1
  14. package/dist-lib/auth/shared-session.cjs +1 -1
  15. package/dist-lib/backend-origin.cjs +1 -1
  16. package/dist-lib/beta.cjs +1 -1
  17. package/dist-lib/beta.mjs +1 -1
  18. package/dist-lib/bridge-constants.cjs +1 -1
  19. package/dist-lib/bridge-contract-input.cjs +1 -1
  20. package/dist-lib/bridge-contract-input.mjs +1 -1
  21. package/dist-lib/bridge-contract.cjs +1 -1
  22. package/dist-lib/bridge-contract.mjs +1 -1
  23. package/dist-lib/bundle-channel.cjs +277 -244
  24. package/dist-lib/capture-contract.cjs +1 -1
  25. package/dist-lib/capture-contract.mjs +1 -1
  26. package/dist-lib/cloud-contract.cjs +1 -1
  27. package/dist-lib/cloud-contract.mjs +1 -1
  28. package/dist-lib/cloud-test-args.cjs +1 -1
  29. package/dist-lib/cloud-test-args.mjs +1 -1
  30. package/dist-lib/cloud.cjs +1 -1
  31. package/dist-lib/cloud.mjs +1 -1
  32. package/dist-lib/config.cjs +1 -1
  33. package/dist-lib/config.mjs +1 -1
  34. package/dist-lib/detox/index.cjs +47 -12
  35. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  36. package/dist-lib/expo-swift-bundle.cjs +276 -243
  37. package/dist-lib/expo-swift-metadata.cjs +1 -1
  38. package/dist-lib/expo-swift-metadata.mjs +1 -1
  39. package/dist-lib/home-paths.cjs +1 -1
  40. package/dist-lib/host/bridge-host.cjs +320 -246
  41. package/dist-lib/host/fetch-proxy-handler.cjs +191 -31
  42. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  43. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  44. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  45. package/dist-lib/host/websocket-proxy.cjs +1 -1
  46. package/dist-lib/index.cjs +633 -373
  47. package/dist-lib/jump-to-source-babel.cjs +1 -1
  48. package/dist-lib/jump-to-source-native.cjs +1 -1
  49. package/dist-lib/kotlin-host.cjs +1 -1
  50. package/dist-lib/menu.cjs +1 -1
  51. package/dist-lib/menu.mjs +1 -1
  52. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  53. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  54. package/dist-lib/metro-production-bundle.cjs +1 -1
  55. package/dist-lib/metro-production-bundle.mjs +1 -1
  56. package/dist-lib/metro.cjs +62 -14
  57. package/dist-lib/native-app-identity-project.cjs +1 -1
  58. package/dist-lib/native-app-identity-project.mjs +1 -1
  59. package/dist-lib/native-app-identity.cjs +1 -1
  60. package/dist-lib/native-app-identity.mjs +1 -1
  61. package/dist-lib/native-firebase-metadata.cjs +1 -1
  62. package/dist-lib/native-firebase-metadata.mjs +1 -1
  63. package/dist-lib/plist.cjs +1 -1
  64. package/dist-lib/plist.mjs +1 -1
  65. package/dist-lib/profiles.cjs +1 -1
  66. package/dist-lib/public-brand.cjs +1 -1
  67. package/dist-lib/public-origins-lib-esm.json +23 -23
  68. package/dist-lib/public-origins-lib.json +62 -54
  69. package/dist-lib/react-native-host-modules.cjs +1 -1
  70. package/dist-lib/react-native-host-modules.mjs +1 -1
  71. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  72. package/dist-lib/sdk.cjs +2 -2
  73. package/dist-lib/sdk.mjs +2 -2
  74. package/dist-lib/skills.cjs +535 -380
  75. package/dist-lib/swift-compile.cjs +258 -197
  76. package/dist-lib/swift-compile.mjs +257 -197
  77. package/dist-lib/swift-package.cjs +1 -1
  78. package/dist-lib/swift-package.mjs +1 -1
  79. package/dist-lib/swift-submit.cjs +1 -1
  80. package/dist-lib/swift-submit.mjs +1 -1
  81. package/dist-lib/swift-toolchain.cjs +1 -1
  82. package/dist-lib/swift.cjs +1 -1
  83. package/dist-lib/vite-swift.cjs +276 -243
  84. package/dist-lib/vite.cjs +385 -200
  85. package/dist-lib/worklet-executable.cjs +1 -1
  86. package/dist-lib/worklet-executable.mjs +1 -1
  87. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +1 -0
  88. package/dist-types/packages/peach-compat/src/stubs/screen-transition-math.d.ts +10 -7
  89. package/dist-types/packages/peach-engine/src/capture/browser-composite.d.ts +10 -0
  90. package/dist-types/packages/peach-engine/src/cli-companion.d.ts +1 -0
  91. package/dist-types/packages/peach-engine/src/engine/node.d.ts +3 -1
  92. package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +1 -1
  93. package/dist-types/packages/peach-engine/src/engine/text-first-baseline.d.ts +23 -0
  94. package/dist-types/packages/peach-engine/src/engine/types.d.ts +1 -1
  95. package/dist-types/packages/peach-engine/src/engine/visible-frame.d.ts +1 -0
  96. package/dist-types/packages/peach-engine/src/observability/types.d.ts +1 -0
  97. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +38 -0
  98. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +9 -0
  99. package/package.json +5 -1
  100. package/runtime-companion.json +1 -1
  101. package/src/bridge-contract.ts +2 -0
  102. package/src/bundleGlobalFooter.ts +9 -0
  103. package/src/host/fetch-proxy-handler.ts +54 -0
  104. package/src/sfSymbolMetricsContract.ts +268 -0
  105. package/src/swift-compile.ts +302 -238
  106. package/src/swift-distribution.lock.json +20 -46
  107. package/src/swift-objc-metadata.ts +21 -7
  108. package/src/swift-objc-sdk.ts +13 -0
  109. package/src/swiftContract.ts +2 -0
  110. package/src/vite-plugin-one.ts +161 -16
  111. package/src/host/lease-owner.test.ts +0 -49
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.1653 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.1655 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; } catch {}
3
3
  "use strict";
4
4
  var __defProp = Object.defineProperty;
@@ -1,4 +1,4 @@
1
- /*! peach v0.1.1653 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
1
+ /*! peach v0.1.1655 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
2
2
 
3
3
  // src/worklet-executable.ts
4
4
  import { parse } from "acorn";
@@ -100,6 +100,7 @@ interface PanRecognizerState {
100
100
  t: number;
101
101
  }>;
102
102
  active: boolean;
103
+ pastHysteresis: boolean;
103
104
  prevCount: number;
104
105
  }
105
106
  export declare function estimatePanVelocity(samples: PanRecognizerState['velocitySamples']): {
@@ -177,15 +177,15 @@ export declare function iosZoomProgress(fraction: number): number;
177
177
  export declare function iosZoomPopProgress(fraction: number): number;
178
178
  export declare function androidScreenTransitionProgress(progress: number): number;
179
179
  export declare function androidAnimationKeepsPreviousTransform(animation: ScreenTransitionAnimation): boolean;
180
- export interface ZoomInteraction {
180
+ export interface ZoomInteraction<T = number> {
181
181
  touchX: number;
182
182
  touchY: number;
183
- anchorX: number;
184
- anchorY: number;
185
- contentScale: number;
186
- boundsProgress: number;
187
- sourceOpacity: number;
188
- behindProgress: number;
183
+ anchorX: T;
184
+ anchorY: T;
185
+ contentScale: T;
186
+ boundsProgress: T;
187
+ sourceOpacity: T;
188
+ behindProgress: T;
189
189
  }
190
190
  export interface ZoomTargetRect {
191
191
  x: number;
@@ -244,6 +244,7 @@ export declare const ZOOM_EDGE_COMMIT_SCALE_SPRING: {
244
244
  export declare const ZOOM_RELEASE_CANCEL_MS = 450;
245
245
  export declare const ZOOM_RELEASE_PRESENTATION_LEAD_MS: number;
246
246
  export declare function zoomReleasePose(release: ZoomRelease, source: ZoomSourceRect, target: ZoomTargetRect, elapsedMs: number): ZoomInteraction;
247
+ export declare function zoomReleasePoseState<T>(math: TransitionScalarMath<T>, release: ZoomRelease, source: ZoomSourceRect, target: ZoomTargetRect, elapsedMs: T): ZoomInteraction<T>;
247
248
  export declare function sheetStackTransform(width: number, height: number, depth: number, presenterTop?: number): {
248
249
  scale: number;
249
250
  factor: number;
@@ -260,6 +261,8 @@ export interface ScreenZoomState<T> extends ScreenSlideState<T> {
260
261
  zoomClip?: ZoomClip<T>;
261
262
  }
262
263
  export declare function screenZoomEase<T>(math: TransitionScalarMath<T>, elapsedMs: T, durationMs: number): T;
264
+ export declare function screenZoomShadowLift<T>(math: TransitionScalarMath<T>, morph: T): T;
265
+ export declare function screenZoomReleaseState<T>(math: TransitionScalarMath<T>, input: ScreenZoomInput, release: ZoomRelease, releaseMs: T, driverClock: boolean): ScreenZoomState<T>;
263
266
  export declare function screenZoomTimedState<T>(math: TransitionScalarMath<T>, input: ScreenZoomInput, p: T, barItemsMs?: T): ScreenZoomState<T>;
264
267
  export declare function computeScreenTransition(input: ScreenSlideInput): ScreenSlideTransforms;
265
268
  export declare function computeScreenSlide(input: ScreenSlideInput): ScreenSlideTransforms;
@@ -31,6 +31,16 @@ export declare const BROWSER_COMPOSITE_RIM_COLORS: {
31
31
  readonly dark: 'rgb(0 0 0)';
32
32
  };
33
33
  export declare const BROWSER_COMPOSITE_RIM_WIDTH = 4;
34
+ export declare function browserCompositeRimBorder(layout: {
35
+ width: number;
36
+ height: number;
37
+ }, painted: {
38
+ width: number;
39
+ height: number;
40
+ }, devicePixelRatio: number): {
41
+ x: number;
42
+ y: number;
43
+ };
34
44
  export interface BrowserCompositeRaster {
35
45
  width: number;
36
46
  height: number;
@@ -33,4 +33,5 @@ export * as settings_store from './settings/store.d.ts';
33
33
  export * as web_authentication_automation_host from './web-authentication-automation-host.d.ts';
34
34
  export * as webview_automation_host from './webview-automation-host.d.ts';
35
35
  export * as playwright_sim_host from './playwright-sim-host.d.ts';
36
+ export * as rolldown_bundle_inventory from './rolldown-bundle-inventory.d.ts';
36
37
  export * as rolldown_production_fingerprint from './rolldown-production-fingerprint.d.ts';
@@ -1,3 +1,4 @@
1
+ import type { TextGuides } from './text-first-baseline.d.ts';
1
2
  export { beginReadFrame, endReadFrame, readAnimatedValue, readPresentedAnimatedValue, } from './animated-value.d.ts';
2
3
  import type { NativeRenderer } from '../../../../../src/config.ts';
3
4
  import type { AndroidEdgeEffectState } from './android-stretch-effect.d.ts';
@@ -216,7 +217,7 @@ export declare class SootSimNode {
216
217
  _pendingOnLayoutLayout: SootSimLayout | null;
217
218
  _lastOnTextLayoutDispatchedSignature: string | null;
218
219
  _pendingOnTextLayoutLines: SootSimTextLayoutLine[] | null;
219
- _firstTextLineCenter: number | null;
220
+ _textGuides: TextGuides | null;
220
221
  _guideOffset: number;
221
222
  _onLayoutDispatchScheduled: boolean;
222
223
  private _classicLayoutAnimFrom;
@@ -509,6 +510,7 @@ export declare class SootSimNode {
509
510
  _sfSymbolPlaceholders: {
510
511
  placeholderIndex: number;
511
512
  codePoint: number;
513
+ size: number;
512
514
  color: unknown;
513
515
  }[] | null;
514
516
  _shadowCache: {
@@ -185,7 +185,7 @@ export interface SceneNativeBinding {
185
185
  _peach_scene_set_blend_runtime(slot: number, effect: number): void;
186
186
  _peach_scene_set_damage_outsets(slot: number, known: number, left: number, top: number, right: number, bottom: number, glassPadding: number, glassMaterial: number, glassIntensity: number): void;
187
187
  _peach_scene_set_outline(slot: number, r: number, g: number, b: number, a: number, width: number, offset: number, style: number): void;
188
- _peach_scene_set_scroll_indicator(slot: number, horizontal: number, pos: number, length: number, thickness: number, margin: number, radius: number, alpha: number, white: number): void;
188
+ _peach_scene_set_scroll_indicator(slot: number, horizontal: number, pos: number, length: number, thickness: number, margin: number, radius: number, alpha: number, white: number, rtl: number): void;
189
189
  _peach_scene_set_fading_edges(slot: number, horizontal: number, length: number, edges: number): void;
190
190
  _peach_walk_painted_images(): number;
191
191
  _peach_anim_create(ints: number, doubles: number): number;
@@ -0,0 +1,23 @@
1
+ import type { SootSimStyle } from './types.d.ts';
2
+ export interface ParagraphBaselineInputs {
3
+ style: SootSimStyle;
4
+ fontFamily: string | undefined;
5
+ fontSize: number;
6
+ firstLineBaseline: number;
7
+ lineCount: number;
8
+ paragraphLeading: number;
9
+ paragraphLineHeight: number | null;
10
+ firstFragmentY: number;
11
+ textFontScale: number | null;
12
+ contentHeight: number;
13
+ deviceScale: number;
14
+ }
15
+ export declare function compressedTextKitBaseline(style: SootSimStyle, fontSize: number, paragraphLineHeight: number | null): number | null;
16
+ export declare function iosParagraphBaselineOffset(input: ParagraphBaselineInputs): number | null;
17
+ export declare function iosFirstTextLineCenter(input: ParagraphBaselineInputs, capHeight: number): number | null;
18
+ export interface TextGuides {
19
+ firstTextLineCenter: number;
20
+ firstTextBaseline: number;
21
+ lastTextBaseline: number;
22
+ }
23
+ export declare function iosTextGuides(input: ParagraphBaselineInputs, capHeight: number, lastLineBaseline: number): TextGuides | null;
@@ -387,7 +387,7 @@ export interface SootSimStyle {
387
387
  _androidTextView?: true;
388
388
  _androidTextSize?: 'dimension' | 'sp';
389
389
  _swiftUILayout?: true;
390
- _swiftUIVerticalGuide?: 'firstTextLineCenter';
390
+ _swiftUIVerticalGuide?: 'firstTextLineCenter' | 'firstTextBaseline' | 'lastTextBaseline';
391
391
  _swiftUIPlatformView?: true;
392
392
  _uikitControlContent?: true;
393
393
  _numericText?: NumericTextPaintRequest;
@@ -39,6 +39,7 @@ export interface VisibleFrameOptions {
39
39
  explain?: boolean;
40
40
  }
41
41
  export declare function nodeClipsDescendants(node: SootSimNode): boolean;
42
+ export declare function getClippedOccluderRect(node: SootSimNode, root: SootSimNode, query: VisibleFrameQuery): InspectOcclusionRect | null;
42
43
  export declare function inspectPaintChildren(node: SootSimNode): import("./node.d.ts").SootSimChild[];
43
44
  export declare function getNodeVisibleFrame(node: SootSimNode, abs: {
44
45
  x: number;
@@ -14,6 +14,7 @@ export type NetworkEntry = {
14
14
  error: string | null;
15
15
  size: number | null;
16
16
  type: string | null;
17
+ requestedType?: string;
17
18
  sourcePath?: string;
18
19
  sourceHash?: string;
19
20
  requestBody?: string | null;
@@ -1071,6 +1071,7 @@ export interface CompositorStats {
1071
1071
  lastReceivedGeneration: number | null;
1072
1072
  lastRuntimeGeneration: number | null;
1073
1073
  active: number;
1074
+ lifecycle: ScreenTransitionLifecycleStats;
1074
1075
  };
1075
1076
  promotedLayers: {
1076
1077
  promoted: number;
@@ -1349,6 +1350,33 @@ export interface CompositorScrollRegistryEntry {
1349
1350
  slotDragStartTime: number;
1350
1351
  slotPresentationDisplacementY: number;
1351
1352
  }
1353
+ export declare const SCREEN_TRANSITION_DONE_OUTCOMES: readonly ['stale-generation', 'unbound-generation', 'no-claim', 'claim-mismatch', 'no-active-transition', 'completed'];
1354
+ export type ScreenTransitionDoneOutcome = (typeof SCREEN_TRANSITION_DONE_OUTCOMES)[number];
1355
+ export type ScreenTransitionLifecycleEvent = {
1356
+ seq: number;
1357
+ surfaceId: AuxAppSurfaceId;
1358
+ generation: number;
1359
+ stackId: number;
1360
+ transitionId: number;
1361
+ dropped: boolean;
1362
+ atEpochMs: number;
1363
+ } & ({
1364
+ kind: 'sent';
1365
+ posted: boolean;
1366
+ completionPaintFrameToken: number | null;
1367
+ presentedFrameToken: number | null;
1368
+ } | {
1369
+ kind: 'received';
1370
+ outcome: ScreenTransitionDoneOutcome;
1371
+ surfaceGeneration: number;
1372
+ });
1373
+ export type ScreenTransitionLifecycleStats = {
1374
+ clock: 'epochMs';
1375
+ observedAtEpochMs: number;
1376
+ capacity: number;
1377
+ total: number;
1378
+ events: ScreenTransitionLifecycleEvent[];
1379
+ };
1352
1380
  export type ShellToCompositorMessage = {
1353
1381
  type: 'screenCaptureProtection';
1354
1382
  request: import('../capture/nativeScreenCaptureContract.d.ts').NativeScreenCaptureRequest;
@@ -1565,6 +1593,16 @@ export type ShellToCompositorMessage = {
1565
1593
  generation: number;
1566
1594
  stackId: number;
1567
1595
  hold: boolean;
1596
+ } | {
1597
+ type: 'screenTransitionDoneReceipt';
1598
+ surfaceId: AuxAppSurfaceId;
1599
+ generation: number;
1600
+ stackId: number;
1601
+ transitionId: number;
1602
+ dropped: boolean;
1603
+ outcome: ScreenTransitionDoneOutcome;
1604
+ surfaceGeneration: number;
1605
+ receivedAtEpochMs: number;
1568
1606
  } | {
1569
1607
  type: 'lottieIntent';
1570
1608
  surfaceId: AuxAppSurfaceId;
@@ -80,5 +80,14 @@ export interface RolldownInventoryReceipt {
80
80
  inventory: RolldownBundleInventory;
81
81
  }
82
82
  export declare function carryRolldownBundleInventory(receipt: RolldownInventoryReceipt | null, report: (receipt: RolldownInventoryReceipt) => void): void;
83
+ export declare function stripRolldownBundleInventoryFooter(source: string): string;
84
+ export declare function hasRolldownInventoryMarkers(source: string): boolean;
85
+ export declare function buildRolldownBundleInventory(source: string): Promise<RolldownBundleInventory>;
86
+ export declare function attachRolldownBundleInventory(source: string): Promise<string>;
87
+ export declare function releasableMultipartPrefix(payload: string, contentType: string): {
88
+ length: number;
89
+ bundleStarted: boolean;
90
+ };
91
+ export declare function attachRolldownBundleHttpPayload(payload: string, contentType: string | undefined): Promise<string>;
83
92
  export declare function readRolldownBundleInventory(source: string): Promise<RolldownBundleInventory>;
84
93
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peachsim",
3
- "version": "0.1.1653",
3
+ "version": "0.1.1655",
4
4
  "description": "Vite and Metro plugins, testing drivers, and SDK exports for peach.",
5
5
  "author": "Tamagui LLC",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -337,6 +337,10 @@
337
337
  "scripts/dev-server-scanner.ts",
338
338
  "scripts/optional-demo-registry.ts",
339
339
  "detox/",
340
+ "!**/*.test.*",
341
+ "!**/*.spec.*",
342
+ "!**/__tests__/**",
343
+ "!**/fixtures/**",
340
344
  "README.md",
341
345
  "LICENSE"
342
346
  ],
@@ -1 +1 @@
1
- {"abi":1,"sha256":"d58f0fedc3c0065faaafcf578781567b6cdac88e5c062a8354111d37fdf3c465","file":"node/cli-d58f0fedc3c0065faaafcf578781567b6cdac88e5c062a8354111d37fdf3c465.cjs"}
1
+ {"abi":1,"sha256":"6f6a55398d832d1703346a258bf9f81bf78fded8cf5d83cdf51e5e15ccd7a1ce","file":"node/cli-6f6a55398d832d1703346a258bf9f81bf78fded8cf5d83cdf51e5e15ccd7a1ce.cjs"}
@@ -359,6 +359,8 @@ export interface SemanticReadyProbe {
359
359
  // ms the counted tree had held its shape when the count was read; 0 when
360
360
  // the reader cannot tell
361
361
  treeQuietMs: number
362
+ // visible inspectable content nodes; 0 without a walk when a ready guest's
363
+ // painted surface already decides readiness
362
364
  targets: number
363
365
  liveFrameActive: boolean
364
366
  paintedAppContent: boolean
@@ -68,10 +68,19 @@ export function readBundleGlobalFooter(source: string, name: string): unknown {
68
68
  }
69
69
 
70
70
  // transport metadata is parsed before evaluation and has no guest JS effect.
71
+ export const ROLLDOWN_INVENTORY_HEADER = 'X-Peach-Rolldown-Inventory'
72
+
71
73
  export function readBundleMetadataFooter(source: string, name: string): unknown {
72
74
  return readFooter(source, `// peach.${name}=`, '', name)
73
75
  }
74
76
 
77
+ export function stripBundleMetadataFooter(source: string, name: string): string {
78
+ const start = findBundleFooter(source, `// peach.${name}=`)
79
+ if (start < 0) return source
80
+ const end = source.indexOf('\n', start + 1)
81
+ return source.slice(0, start) + (end < 0 ? '' : source.slice(end))
82
+ }
83
+
75
84
  // removes the footer line so a rewrite of the bundle's code (minification)
76
85
  // cannot reshape it; the caller inserts the value again afterwards.
77
86
  export function detachBundleGlobalFooter(
@@ -27,12 +27,15 @@
27
27
  import http, { type IncomingMessage, type ServerResponse } from 'http'
28
28
  import https from 'https'
29
29
  import { Http2ServerRequest, type Http2ServerResponse } from 'node:http2'
30
+ import { Readable } from 'stream'
30
31
  import { finished, pipeline } from 'stream/promises'
31
32
  import {
32
33
  isLoopbackHost,
33
34
  isTrustedBridgeRequest,
34
35
  normalizeHostname,
35
36
  } from '../backend-origin.ts'
37
+ import { ROLLDOWN_INVENTORY_HEADER } from '../bundleGlobalFooter.ts'
38
+ import { getCliRuntime } from '../cli-runtime.ts'
36
39
  import { PACKAGE_VERSIONS_HEADER } from '../packageVersionsContract'
37
40
  import { readDevServerPackageVersions } from './dev-server-package-versions.ts'
38
41
  import {
@@ -253,6 +256,16 @@ export async function handleFetchProxyRequest(
253
256
  if (packageVersions)
254
257
  res.setHeader(PACKAGE_VERSIONS_HEADER, JSON.stringify(packageVersions))
255
258
  }
259
+ if (
260
+ isBundleProxyRequestUrl(req.url) &&
261
+ req.method === 'GET' &&
262
+ upstream.statusCode === 200 &&
263
+ upstreamUrl.pathname.endsWith('.bundle') &&
264
+ upstream.headers['x-peach-rolldown-inventory'] !== '1'
265
+ ) {
266
+ res.setHeader(ROLLDOWN_INVENTORY_HEADER, '1')
267
+ res.removeHeader('content-length')
268
+ }
256
269
  applyFetchProxyCors(req, res)
257
270
  if (setCookies.length > 0)
258
271
  res.setHeader('x-sootsim-set-cookie', setCookies.join(', '))
@@ -494,6 +507,47 @@ async function proxyUpstream(
494
507
  if (redirects > 0) res.setHeader(FETCH_PROXY_RESPONSE_URL_HEADER, targetUrl.href)
495
508
  await route.respond(proxyRes, hopCookies)
496
509
  res.statusCode = status
510
+ if (
511
+ isBundleProxyRequestUrl(req.url) &&
512
+ method === 'GET' &&
513
+ status === 200 &&
514
+ targetUrl.pathname.endsWith('.bundle') &&
515
+ proxyRes.headers['x-peach-rolldown-inventory'] !== '1'
516
+ ) {
517
+ const contentType =
518
+ typeof proxyRes.headers['content-type'] === 'string'
519
+ ? proxyRes.headers['content-type']
520
+ : ''
521
+ const inventory = getCliRuntime().rolldown_bundle_inventory
522
+ res.removeHeader('content-length')
523
+ // metro's multipart build progress has to reach the client while the
524
+ // build runs, so everything before the bundle part's body streams through
525
+ // as it arrives and only the bundle itself waits for its inventory
526
+ const annotate = async function* () {
527
+ const decoder = new TextDecoder()
528
+ let payload = ''
529
+ let sent = 0
530
+ let bundleStarted = false
531
+ for await (const chunk of proxyRes) {
532
+ payload += decoder.decode(chunk, { stream: true })
533
+ if (bundleStarted) continue
534
+ const releasable = inventory.releasableMultipartPrefix(payload, contentType)
535
+ bundleStarted = releasable.bundleStarted
536
+ if (releasable.length > sent) {
537
+ yield Buffer.from(payload.slice(sent, releasable.length), 'utf8')
538
+ sent = releasable.length
539
+ }
540
+ }
541
+ payload += decoder.decode()
542
+ const annotated = await inventory.attachRolldownBundleHttpPayload(
543
+ payload,
544
+ contentType,
545
+ )
546
+ yield Buffer.from(annotated.slice(sent), 'utf8')
547
+ }
548
+ await pipeline(Readable.from(annotate(), { objectMode: false }), res)
549
+ return
550
+ }
497
551
  await pipeline(proxyRes, res)
498
552
  }
499
553
 
@@ -0,0 +1,268 @@
1
+ import {
2
+ SF_SYMBOL_SCALES,
3
+ SF_SYMBOL_WEIGHTS,
4
+ SF_SYMBOL_WEIGHT_AXIS,
5
+ sfSymbolImageAlignment,
6
+ type SfSymbolImageMetadata,
7
+ type SfSymbolScale,
8
+ type SfSymbolWeight,
9
+ } from './assetCatalogContract'
10
+
11
+ // every symbol's image metrics, small enough to load whole before an app boots
12
+ // so UIImage.size and alignmentRectInsets answer synchronously. a drawing's
13
+ // outline is not in it: the vectors stay in their lazy buckets and only paint
14
+ // from them.
15
+ //
16
+ // coreui's metrics are piecewise linear along the weight axis, so a variant
17
+ // stores its four columns at four weights and the other five interpolate. the
18
+ // knots are the masters each scale's metrics bend at. a scale with a bend
19
+ // elsewhere fails the generator's check against the measured rows.
20
+ const MASTER_KNOTS: readonly SfSymbolWeight[] = [
21
+ 'ultraLight',
22
+ 'regular',
23
+ 'heavy',
24
+ 'black',
25
+ ]
26
+ // small scale metrics carry rounding noise along the axis, so it stores all nine
27
+ export function sfSymbolMetricKnots(scale: SfSymbolScale): readonly SfSymbolWeight[] {
28
+ return scale === 'small' ? SF_SYMBOL_WEIGHTS : MASTER_KNOTS
29
+ }
30
+
31
+ // per name and knot, in this order
32
+ const COLUMNS = ['canvasWidth', 'canvasHeight', 'left', 'right', 'baseline'] as const
33
+ export type SfSymbolMetricColumn = (typeof COLUMNS)[number]
34
+ // per variant, shared by every name
35
+ const CONSTANTS = ['referencePointSize', 'basePointSize', 'top', 'bottom', 'cap'] as const
36
+
37
+ // the system font's ascender and descender, the same units UIFont uses
38
+ const UNITS_PER_EM = 2048
39
+ const ASCENDER_UNITS = 1950
40
+ const DESCENDER_UNITS = 494
41
+
42
+ const VARIANT_COUNT = SF_SYMBOL_SCALES.length * SF_SYMBOL_WEIGHTS.length
43
+ const KNOT_VARIANT_COUNT = SF_SYMBOL_SCALES.reduce(
44
+ (count, scale) => count + sfSymbolMetricKnots(scale).length,
45
+ 0,
46
+ )
47
+
48
+ // the metrics a name carries at one variant, before the point size scales them
49
+ export interface SfSymbolMetricRow {
50
+ referencePointSize: number
51
+ basePointSize: number
52
+ canvasWidth: number
53
+ canvasHeight: number
54
+ left: number
55
+ top: number
56
+ right: number
57
+ bottom: number
58
+ baseline: number
59
+ cap: number
60
+ }
61
+
62
+ export function sfSymbolMetricRow(drawing: SfSymbolImageMetadata): SfSymbolMetricRow {
63
+ return {
64
+ referencePointSize: drawing.referencePointSize,
65
+ basePointSize: drawing.basePointSize,
66
+ canvasWidth: drawing.referenceCanvasSize[0],
67
+ canvasHeight: drawing.referenceCanvasSize[1],
68
+ left: drawing.insets[0],
69
+ top: drawing.insets[1],
70
+ right: drawing.insets[2],
71
+ bottom: drawing.insets[3],
72
+ baseline: drawing.baselineOffsetUnrounded,
73
+ cap: drawing.capHeightUnrounded,
74
+ }
75
+ }
76
+
77
+ function variantIndex(scale: SfSymbolScale, weight: SfSymbolWeight): number {
78
+ return (
79
+ SF_SYMBOL_SCALES.indexOf(scale) * SF_SYMBOL_WEIGHTS.length +
80
+ SF_SYMBOL_WEIGHTS.indexOf(weight)
81
+ )
82
+ }
83
+
84
+ function knotIndex(scale: SfSymbolScale, knot: SfSymbolWeight) {
85
+ let before = 0
86
+ for (const earlier of SF_SYMBOL_SCALES) {
87
+ if (earlier === scale) break
88
+ before += sfSymbolMetricKnots(earlier).length
89
+ }
90
+ return before + sfSymbolMetricKnots(scale).indexOf(knot)
91
+ }
92
+
93
+ // the weights between two knots interpolate by their axis coordinate
94
+ function bracket(scale: SfSymbolScale, weight: SfSymbolWeight) {
95
+ const knots = sfSymbolMetricKnots(scale)
96
+ const axis = SF_SYMBOL_WEIGHT_AXIS[weight]
97
+ let low = 0
98
+ while (low < knots.length - 2 && SF_SYMBOL_WEIGHT_AXIS[knots[low + 1]!] <= axis) low++
99
+ const lowKnot = knots[low]!
100
+ const highKnot = knots[low + 1]!
101
+ const lowAxis = SF_SYMBOL_WEIGHT_AXIS[lowKnot]
102
+ return {
103
+ lowKnot,
104
+ highKnot,
105
+ t: (axis - lowAxis) / (SF_SYMBOL_WEIGHT_AXIS[highKnot] - lowAxis),
106
+ }
107
+ }
108
+
109
+ // layout, little endian: u32 name count, u32 name bytes, the names (utf-8,
110
+ // newline separated, sorted) padded to 4, the per variant constants, then each
111
+ // knot variant's columns of one float32 per name.
112
+ export function encodeSfSymbolMetrics(
113
+ rows: ReadonlyMap<string, ReadonlyMap<string, SfSymbolMetricRow>>,
114
+ ): Uint8Array {
115
+ const names = [...(rows.get(variantKey('medium', 'regular')) ?? [])].map(([n]) => n)
116
+ names.sort()
117
+ const nameBytes = new TextEncoder().encode(names.join('\n'))
118
+ const namesLength = Math.ceil(nameBytes.length / 4) * 4
119
+ const header = 8 + namesLength
120
+ const out = new Uint8Array(
121
+ header +
122
+ 4 *
123
+ (VARIANT_COUNT * CONSTANTS.length +
124
+ KNOT_VARIANT_COUNT * COLUMNS.length * names.length),
125
+ )
126
+ const view = new DataView(out.buffer)
127
+ view.setUint32(0, names.length, true)
128
+ view.setUint32(4, nameBytes.length, true)
129
+ out.set(nameBytes, 8)
130
+ let offset = header
131
+ const put = (value: number) => {
132
+ view.setFloat32(offset, value, true)
133
+ offset += 4
134
+ }
135
+ for (const scale of SF_SYMBOL_SCALES)
136
+ for (const weight of SF_SYMBOL_WEIGHTS) {
137
+ const variant = rows.get(variantKey(scale, weight))
138
+ if (!variant) throw new Error(`SF Symbol metrics: ${scale}-${weight} missing`)
139
+ const first = variant.get(names[0]!)!
140
+ for (const name of names) {
141
+ const row = variant.get(name)
142
+ if (!row)
143
+ throw new Error(`SF Symbol metrics: ${name} missing at ${scale}-${weight}`)
144
+ for (const key of CONSTANTS)
145
+ if (Math.fround(row[key]) !== Math.fround(first[key]))
146
+ throw new Error(
147
+ `SF Symbol metrics: ${key} varies by name at ${scale}-${weight}`,
148
+ )
149
+ }
150
+ for (const key of CONSTANTS) put(first[key])
151
+ }
152
+ for (const scale of SF_SYMBOL_SCALES)
153
+ for (const knot of sfSymbolMetricKnots(scale)) {
154
+ const variant = rows.get(variantKey(scale, knot))!
155
+ for (const column of COLUMNS)
156
+ for (const name of names) put(variant.get(name)![column])
157
+ }
158
+ return out
159
+ }
160
+
161
+ function variantKey(scale: SfSymbolScale, weight: SfSymbolWeight): string {
162
+ return `${scale}-${weight}`
163
+ }
164
+
165
+ export class SfSymbolMetrics {
166
+ readonly names: readonly string[]
167
+ private readonly index = new Map<string, number>()
168
+ private readonly constants: Float32Array
169
+ private readonly columns: Float32Array
170
+
171
+ constructor(bytes: Uint8Array) {
172
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)
173
+ const count = view.getUint32(0, true)
174
+ const nameLength = view.getUint32(4, true)
175
+ this.names = new TextDecoder().decode(bytes.subarray(8, 8 + nameLength)).split('\n')
176
+ if (this.names.length !== count)
177
+ throw new Error('SF Symbol metrics: name count mismatch')
178
+ this.names.forEach((name, i) => this.index.set(name, i))
179
+ const header = 8 + Math.ceil(nameLength / 4) * 4
180
+ const floats = bytes.byteLength - header
181
+ if (floats % 4 !== 0) throw new Error('SF Symbol metrics: malformed')
182
+ const all = new Float32Array(bytes.slice(header).buffer)
183
+ const constantCount = VARIANT_COUNT * CONSTANTS.length
184
+ if (all.length !== constantCount + KNOT_VARIANT_COUNT * COLUMNS.length * count)
185
+ throw new Error('SF Symbol metrics: size mismatch')
186
+ this.constants = all.subarray(0, constantCount)
187
+ this.columns = all.subarray(constantCount)
188
+ }
189
+
190
+ has(name: string): boolean {
191
+ return this.index.has(name)
192
+ }
193
+
194
+ /** a name's metrics at a variant, or undefined for a name with no symbol. */
195
+ row(name: string, scale: SfSymbolScale, weight: SfSymbolWeight) {
196
+ const at = this.index.get(name)
197
+ if (at === undefined) return undefined
198
+ const { lowKnot, highKnot, t } = bracket(scale, weight)
199
+ const count = this.names.length
200
+ const read = (knot: SfSymbolWeight, column: number) =>
201
+ this.columns[(knotIndex(scale, knot) * COLUMNS.length + column) * count + at]!
202
+ const value = (column: number) => {
203
+ const low = read(lowKnot, column)
204
+ return t === 0 ? low : low + (read(highKnot, column) - low) * t
205
+ }
206
+ const constant = (key: (typeof CONSTANTS)[number]) =>
207
+ this.constants[
208
+ variantIndex(scale, weight) * CONSTANTS.length + CONSTANTS.indexOf(key)
209
+ ]!
210
+ const metadata: SfSymbolImageMetadata = {
211
+ referencePointSize: constant('referencePointSize'),
212
+ basePointSize: constant('basePointSize'),
213
+ baselineOffsetUnrounded: value(4),
214
+ capHeightUnrounded: constant('cap'),
215
+ referenceCanvasSize: [value(0), value(1)],
216
+ insets: [value(2), constant('top'), value(3), constant('bottom')],
217
+ layers: [],
218
+ }
219
+ return metadata
220
+ }
221
+
222
+ /** uiimage's size, insets and baseline for a name, in device pixels. */
223
+ alignment(
224
+ name: string,
225
+ pointSize: number,
226
+ scale: SfSymbolScale,
227
+ weight: SfSymbolWeight,
228
+ displayScale: number,
229
+ ) {
230
+ const metadata = this.row(name, scale, weight)
231
+ return metadata && sfSymbolImageAlignment(metadata, pointSize, displayScale)
232
+ }
233
+
234
+ /**
235
+ * uikit's UIImage for a name, in points: its size, alignment rect insets and
236
+ * baseline from the bottom. the alignment rect runs from the font's rounded
237
+ * ascender to its rounded descender, widened by any negative bearing.
238
+ */
239
+ image(
240
+ name: string,
241
+ pointSize: number,
242
+ scale: SfSymbolScale,
243
+ weight: SfSymbolWeight,
244
+ displayScale: number,
245
+ ) {
246
+ const metadata = this.row(name, scale, weight)
247
+ if (!metadata) return undefined
248
+ const box = sfSymbolImageAlignment(metadata, pointSize, displayScale)
249
+ const snap = (value: number) => Math.round(value * displayScale) / displayScale
250
+ const width = box.width / displayScale
251
+ const height = box.height / displayScale
252
+ const baseline = box.baseline / displayScale
253
+ const bearing = (inset: number) =>
254
+ Math.max(
255
+ -Math.round((inset * pointSize * displayScale) / metadata.basePointSize),
256
+ 0,
257
+ ) / displayScale
258
+ return {
259
+ width,
260
+ height,
261
+ top: height - baseline - snap((pointSize * ASCENDER_UNITS) / UNITS_PER_EM),
262
+ left: bearing(metadata.insets[0]),
263
+ bottom: baseline - snap((pointSize * DESCENDER_UNITS) / UNITS_PER_EM),
264
+ right: bearing(metadata.insets[2]),
265
+ baseline,
266
+ }
267
+ }
268
+ }