peachsim 0.1.2935 → 0.1.2937
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 +6 -8
- package/cli/account-gate.ts +20 -3
- package/cli/app-bundle-resources.ts +66 -19
- package/cli/catalog/meta.ts +2 -106
- package/cli/command-agent.ts +7 -0
- package/cli/command-registry.ts +0 -1
- package/cli/commands/control.ts +13 -5
- package/cli/commands/daemon.ts +4 -2
- package/cli/commands/device.ts +78 -8
- package/cli/commands/do-chain.ts +11 -8
- package/cli/commands/inspect/core.ts +4 -9
- package/cli/commands/inspect/settling.ts +1 -0
- package/cli/commands/logout.ts +6 -1
- package/cli/commands/map.ts +2 -6
- package/cli/commands/package.ts +112 -57
- package/cli/commands/shell-url.ts +0 -1
- package/cli/download-auth.ts +2 -0
- package/cli/drivers/playwright-provisioning.ts +10 -38
- package/cli/github-workflow-identity.ts +8 -0
- package/cli/internal-child-contract.ts +1 -0
- package/cli/internal-child.ts +5 -0
- package/cli/main.ts +2 -10
- package/cli/outbound-endpoints.ts +26 -0
- package/detox/index.ts +227 -131
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +47 -3
- package/dist-lib/bridge-contract-input.mjs +6 -6
- package/dist-lib/bridge-contract.cjs +10 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +12779 -9515
- package/dist-lib/capture-contract.cjs +39 -17
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +8 -8
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +6 -6
- package/dist-lib/detox/index.cjs +200 -132
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-Q5TRRYSO.mjs → acorn-IIBLEO25.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-UDWBTBVG.mjs → chunk-4FTPQKPT.mjs} +10 -1
- package/dist-lib/esm-chunks/chunk-4WIDTRBB.mjs +10232 -0
- package/dist-lib/esm-chunks/{chunk-LCMFYMT7.mjs → chunk-5QZOQ3NZ.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BJ2OGUX7.mjs → chunk-CIY67HNL.mjs} +39 -17
- package/dist-lib/esm-chunks/{chunk-SKQTNQYE.mjs → chunk-CQFEMJ64.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-AXWVXRHX.mjs → chunk-CWVMCW23.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-MTALOHQR.mjs → chunk-F6DZ4DS2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-I4R7IZRD.mjs → chunk-HJMF6O7L.mjs} +74 -46
- package/dist-lib/esm-chunks/chunk-I6T4PXJF.mjs +154 -0
- package/dist-lib/esm-chunks/{chunk-XWAUZKIA.mjs → chunk-IJU3JMWM.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-CXWUIOCH.mjs → chunk-KODEPXQC.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-WJE5QHSD.mjs → chunk-LD4K2VBL.mjs} +155 -36
- package/dist-lib/esm-chunks/{chunk-2TSM64HI.mjs → chunk-LTE7YMEG.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-3GGOXUJA.mjs → chunk-M3CSKAJE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-7G5UETIG.mjs → chunk-NA6DJPB6.mjs} +43 -1
- package/dist-lib/esm-chunks/{chunk-MSUHMNAI.mjs → chunk-NNAX24FS.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VDJA4LP4.mjs → chunk-PZPJJBAS.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UEEEJVQA.mjs → chunk-QXSTHMWN.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-S2RJB5I7.mjs → chunk-RBPVK5YI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VRAXNGYT.mjs → chunk-SCT5OFDV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-T3M73LGP.mjs → chunk-U3CJGYSP.mjs} +50 -6
- package/dist-lib/esm-chunks/{chunk-SLUGTGQQ.mjs → chunk-VXTOQ522.mjs} +12 -6
- package/dist-lib/esm-chunks/{chunk-EL44SZMV.mjs → chunk-WMSVGYTH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-FEDEPSEV.mjs → chunk-WRWINRWK.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BNO52N2S.mjs → chunk-YZF2USRD.mjs} +1905 -8760
- package/dist-lib/esm-chunks/{chunk-TQLKYMVP.mjs → chunk-ZNHR6C3L.mjs} +1 -1
- package/dist-lib/esm-chunks/{download-auth-registry-G75MIT55.mjs → download-auth-registry-AHS5MSIB.mjs} +4 -4
- package/dist-lib/esm-chunks/{metro-layout-parser-FXLUDTYT.mjs → metro-layout-parser-24ZYK5UP.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-524D4MA2.mjs → swift-package-prebuilt-L4YNXQRD.mjs} +15 -15
- package/dist-lib/esm-chunks/{swift-sdk-app-module-EX544YJY.mjs → swift-sdk-app-module-RM652JSW.mjs} +87 -71
- package/dist-lib/esm-chunks/{swift-sdk-image-LOTMWVM7.mjs → swift-sdk-image-5PQ44UJT.mjs} +15 -15
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-UO6B3M4U.mjs → swift-sdk-image-producer-GD3SM6YI.mjs} +5 -5
- package/dist-lib/esm-chunks/swift-sdk-later-data-62QYJ2KH.mjs +590 -0
- package/dist-lib/expo-swift-bundle.cjs +21037 -17896
- package/dist-lib/expo-swift-metadata.cjs +8 -2
- package/dist-lib/expo-swift-metadata.mjs +9 -8
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +22481 -18741
- package/dist-lib/host/fetch-proxy-handler.cjs +21079 -17980
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +68 -38
- package/dist-lib/kotlin-host.cjs +97 -21
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +23 -1
- package/dist-lib/metro-production-bundle.mjs +24 -4
- package/dist-lib/native-app-identity-project.cjs +3582 -571
- package/dist-lib/native-app-identity-project.mjs +1024 -398
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +132 -116
- package/dist-lib/public-origins-lib.json +215 -173
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +17 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +6 -7
- package/dist-lib/sdk.mjs +13 -14
- package/dist-lib/skills.cjs +23216 -19650
- package/dist-lib/swift-compile.cjs +4337 -2905
- package/dist-lib/swift-compile.mjs +15 -13
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +6 -6
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +19 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +94 -32
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +8 -5
- package/dist-lib/worklet-executable.mjs +9 -6
- package/dist-types/packages/peach-engine/src/canvaskit-artifact-urls.d.ts +2 -1
- package/dist-types/packages/peach-engine/src/capture/compositor-presentation-recording.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/generated/canvaskit-artifact-hashes.d.ts +26 -0
- package/dist-types/packages/peach-engine/src/engine/guest-scene-inspect.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/engine/inspect-info.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/metalTypes.d.ts +32 -2
- package/dist-types/packages/peach-engine/src/engine/portalContract.d.ts +24 -0
- package/dist-types/packages/peach-engine/src/engine/remote-display-protocol.d.ts +12 -2
- package/dist-types/packages/peach-engine/src/guest/http-cookie-storage.d.ts +73 -0
- package/dist-types/packages/peach-engine/src/guest/native-evaluation-lease.d.ts +5 -0
- package/dist-types/packages/peach-engine/src/guest/nitro-jsi-host.d.ts +3 -1
- package/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +225 -9
- package/dist-types/packages/peach-engine/src/ios/chrome-metrics.d.ts +4 -1
- package/dist-types/packages/peach-engine/src/ios/duo-vertical-bar-geometry.d.ts +0 -1
- package/dist-types/packages/peach-engine/src/native-preview-bundle.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/remote-stream/canvas-display-compositor.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/remote-stream/canvas-display-contract.d.ts +44 -10
- package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +4 -3
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +2 -4
- package/dist-types/packages/peach-engine/src/render-worker/metro-bundle-metadata.d.ts +2 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-widgetContract.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +15 -27
- package/dist-types/packages/peach-engine/src/render-worker/reanimated-readiness.d.ts +2 -6
- package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +11 -3
- package/dist-types/packages/peach-engine/src/settings/devices.d.ts +3 -1
- package/dist-types/packages/peach-engine/src/settings/duo-fold.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/webview-automation-host.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/app-bundle-resources.d.ts +10 -0
- package/dist-types/packages/peach-globals/src/compositorBridgeContract.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/hostStorageBridgeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +2 -2
- package/dist-types/packages/peach-globals/src/lockstepCaptureBridgeContract.d.ts +9 -6
- package/dist-types/packages/peach-globals/src/nodeContract.d.ts +11 -0
- package/dist-types/packages/peach-globals/src/oneWidgetContract.d.ts +28 -0
- package/package.json +2 -2
- package/runtime-companion.json +1 -1
- package/sdk/ios/System/Library/Frameworks/CoreHaptics.framework/Headers/CoreHaptics.h +251 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INImage.h +14 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INIntent.h +18 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INIntentIdentifiers.h +30 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INIntentResponse.h +12 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INInteraction.h +35 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INObjectCollection.h +0 -7
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INObjectSection.h +0 -7
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INOutgoingMessageType.h +7 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INPerson.h +36 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INPersonHandle.h +22 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INSendMessageIntent+UserNotifications.h +6 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INSendMessageIntent.h +33 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/INSpeakableString.h +24 -0
- package/sdk/ios/System/Library/Frameworks/Intents.framework/Headers/Intents.h +11 -7
- package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMailComposeViewController.h +1 -1
- package/sdk/ios/System/Library/Frameworks/MessageUI.framework/Headers/MFMessageComposeViewController.h +1 -1
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRenderCommandEncoder.h +0 -8
- package/sdk/ios/System/Library/Frameworks/MetalTypes.framework/Headers/MetalTypes.h +8 -0
- package/sdk/ios/System/Library/Frameworks/Social.framework/Headers/SLServiceTypes.h +9 -0
- package/sdk/ios/System/Library/Frameworks/Social.framework/Headers/Social.h +1 -0
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotification.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationAction.h +2 -2
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationAttachment.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationCategory.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationContent.h +2 -2
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationRequest.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationResponse.h +2 -2
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationSound.h +1 -1
- package/sdk/ios/System/Library/Frameworks/UserNotifications.framework/Headers/UNNotificationTrigger.h +5 -5
- package/sdk/ios/usr/lib/swift/UIKit.swiftmodule/arm64-apple-ios-simulator.swiftinterface +4 -0
- package/sdk/ios/wasm/include/unistd.h +1 -0
- package/src/acorn-program.ts +3 -0
- package/src/audio-codec-archives.ts +141 -0
- package/src/bridge-contract-input.ts +61 -1
- package/src/bridge-contract.ts +45 -4
- package/src/bundle-channel.mjs +44 -30
- package/src/capture-contract.ts +57 -39
- package/src/conformance-comparison-contract.ts +2 -0
- package/src/expo-discovery-cache.ts +0 -2
- package/src/expo-macro-host.ts +8 -3
- package/src/expo-native-compiler-digest.ts +0 -1
- package/src/expo-native-prebuilt.ts +1 -1
- package/src/expo-native-workspace.ts +83 -45
- package/src/expo-pod-prebuilt.ts +1 -0
- package/src/expo-swift-host.ts +158 -77
- package/src/expo-swift-legacy-runtime-source.ts +12 -1
- package/src/expo-swift-view-source.ts +51 -20
- package/src/expo-workspace-exclusion.ts +7 -1
- package/src/expoSwiftContract.ts +10 -1
- package/src/ffmpeg-source-build.ts +123 -59
- package/src/genrule-archives.ts +7 -2
- package/src/genrule-library-builds.ts +101 -18
- package/src/host/bridge-host.ts +10 -1
- package/src/installed-native-libraries.ts +147 -23
- package/src/installed-package-versions.ts +30 -0
- package/src/ios-rn-bundle-request.ts +3 -1
- package/src/ios-rn-bundle.ts +38 -27
- package/src/ios-rn-compile.ts +23 -6
- package/src/ios-rn-startup.ts +2 -1
- package/src/java-module-abi.ts +4 -3
- package/src/kotlin-host.ts +4 -4
- package/src/kotlin-library-sources.ts +8 -5
- package/src/metro-production-bundle.ts +24 -0
- package/src/native-firebase-config.ts +2 -0
- package/src/native-framework-compiler.ts +5 -0
- package/src/native-package-slice-build.ts +3 -0
- package/src/native-package-slice.ts +15 -10
- package/src/native-preparation.ts +4 -1
- package/src/native-static-libraries.ts +107 -33
- package/src/nativeRuntimePackageIndex.ts +1 -4
- package/src/nitro-adapter.lock.json +286 -286
- package/src/nitro-app-providers.ts +20 -8
- package/src/nitro-compile.ts +131 -37
- package/src/nitro-dependencies.ts +42 -8
- package/src/nitro-source.ts +40 -36
- package/src/nitro-superset.lock.json +4 -4
- package/src/nitroAdapterContract.ts +32 -7
- package/src/nitroContract.ts +21 -37
- package/src/one-direct-host-source.ts +247 -140
- package/src/one-fabric.ts +129 -0
- package/src/one-native-controls-package.ts +95 -21
- package/src/one-native-controls-release.ts +147 -14
- package/src/one-native-source.ts +4 -1
- package/src/one-nitro-inputs.ts +1 -1
- package/src/one-nitro-source.ts +45 -1
- package/src/one-sdk/source.ts +10 -41
- package/src/one-widget-metadata.ts +2 -2
- package/src/one-widget-package.ts +1 -1
- package/src/oneSdkContract.ts +3 -0
- package/src/playwright-browser-paths.ts +30 -0
- package/src/pods-install.ts +6 -2
- package/src/pods-post-install.ts +2 -2
- package/src/pods-project.ts +10 -0
- package/src/podspec-ruby-stdlib.ts +73 -0
- package/src/podspec-ruby.ts +1 -1
- package/src/podspec-sources.ts +31 -13
- package/src/process-group.ts +135 -5
- package/src/published-swift-sdk.ts +25 -1
- package/src/react-native-bridge-modules.ts +35 -3
- package/src/react-native-core-build.ts +14 -2
- package/src/react-native-core.ts +12 -2
- package/src/rive-runtime-dependencies.ts +178 -40
- package/src/serverDiscoveryContract.ts +1 -1
- package/src/storageSnapshotContract.ts +1 -1
- package/src/swift-app-data-store.ts +35 -0
- package/src/swift-compile.ts +403 -121
- package/src/swift-compiler-digest.ts +4 -0
- package/src/swift-darwin-records.ts +6 -0
- package/src/swift-distribution-mirror.ts +10 -1
- package/src/swift-distribution.lock.json +19 -18
- package/src/swift-distribution.ts +17 -1
- package/src/swift-entry-module.ts +1 -0
- package/src/swift-guest-compile.ts +8 -1
- package/src/swift-host.ts +79 -23
- package/src/swift-installed-targets.ts +51 -20
- package/src/swift-objc-standin.ts +60 -8
- package/src/swift-packages.ts +104 -24
- package/src/swift-project-user.ts +2 -1
- package/src/swift-reproducible.ts +99 -1
- package/src/swift-root-lock.ts +52 -46
- package/src/swift-sdk-app-module.ts +65 -13
- package/src/swift-sdk-image-producer.ts +2 -1
- package/src/swift-sdk-image.ts +23 -8
- package/src/swift-sdk-later-data.ts +294 -44
- package/src/swift-sdk-surface.ts +233 -55
- package/src/swift-shared-sdk.ts +7 -0
- package/src/swift-standin-builtin-behavior.ts +18 -0
- package/src/swift-standin-emit.ts +242 -54
- package/src/swift-standins.ts +184 -38
- package/src/swift-startup-split.ts +19 -9
- package/src/swift-toolchain.ts +18 -0
- package/src/swift-wasm-prune.ts +179 -9
- package/src/swift-xcframework.ts +16 -0
- package/src/swiftContract.ts +4 -1
- package/src/swiftSdkLinkContract.ts +2 -0
- package/src/swiftTargetContract.ts +1 -0
- package/src/turbo-bundle.ts +6 -3
- package/src/turbo-codegen-intake.ts +106 -16
- package/src/turbo-compile.ts +89 -68
- package/src/turbo-fabric-app.ts +287 -23
- package/src/turbo-provider-host.ts +122 -31
- package/src/turbo-runtime.lock.json +26 -26
- package/src/turbo-source.ts +374 -157
- package/src/vite-plugin.ts +48 -112
- package/src/wasm-binary-sections.ts +40 -0
- package/src/wasm-code-immediates.ts +35 -5
- package/src/widget-extension-bundle.ts +15 -1
- package/src/worklet-executable.ts +2 -1
- package/src/worklet-kernel.ts +5 -3
- package/src/worklets-babel.ts +2 -1
- package/src/xcode-project.ts +151 -53
- package/src/xcode-scheme-actions.ts +104 -0
- package/cli/commands/canvas.ts +0 -1204
- package/dist-lib/esm-chunks/chunk-B5QD2KEV.mjs +0 -2787
- package/dist-lib/vendor/magic-string.cjs +0 -1693
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +0 -127
- package/src/appBundleResourcesContract.ts +0 -51
- package/src/canvas-groups.ts +0 -28
- package/src/canvas-map-layout.ts +0 -161
- package/src/oneWidgetContract.ts +0 -134
package/cli/commands/canvas.ts
DELETED
|
@@ -1,1204 +0,0 @@
|
|
|
1
|
-
// peach canvas: lay out live apps, and maps of an app, on one canvas sim. the
|
|
2
|
-
// working file is peach-canvas.json; every change posts the whole canvas to the
|
|
3
|
-
// connected canvas sim, which acks the revision once the board commits it.
|
|
4
|
-
|
|
5
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
6
|
-
import { hostname } from 'node:os'
|
|
7
|
-
import { dirname, resolve } from 'node:path'
|
|
8
|
-
import { isCanvasMapAgent } from '@peach/globals'
|
|
9
|
-
import { groupCanvasItems, type CanvasGrouping } from '../../src/canvas-groups'
|
|
10
|
-
import { layoutCanvasGroups } from '../../src/canvas-map-layout'
|
|
11
|
-
import { devices, isDeviceModel, type DeviceModel } from '../../src/device-catalog'
|
|
12
|
-
import { layoutFlowGraph } from '../../src/flow-graph-layout'
|
|
13
|
-
import { isRecord } from '../../src/is-record'
|
|
14
|
-
import { LAUNCH_METADATA_QUERY_PARAM } from '../../src/launchMetadataContract'
|
|
15
|
-
import { cliAgentName } from '../command-agent'
|
|
16
|
-
import { getCliIdentity } from '../current-sim'
|
|
17
|
-
import { createBridgeFromParsed, evalInBridge, parseBridgeCliArgs } from '../ws-bridge'
|
|
18
|
-
|
|
19
|
-
type CanvasItem = {
|
|
20
|
-
id: string
|
|
21
|
-
title: string | null
|
|
22
|
-
app: string
|
|
23
|
-
bundleUrl: string | null
|
|
24
|
-
// the staged fonts, asset catalog and native configuration of that bundle's app
|
|
25
|
-
launchMetadata: string | null
|
|
26
|
-
nativeSource: string | null
|
|
27
|
-
launchArgs?: string[]
|
|
28
|
-
// the link the app launches with
|
|
29
|
-
url: string | null
|
|
30
|
-
// a png the canvas draws until the app first runs
|
|
31
|
-
poster: string | null
|
|
32
|
-
device: DeviceModel
|
|
33
|
-
x: number
|
|
34
|
-
y: number
|
|
35
|
-
width: number
|
|
36
|
-
height: number
|
|
37
|
-
live: boolean
|
|
38
|
-
radius: number | null
|
|
39
|
-
// the map this item is a screen of
|
|
40
|
-
map: string | null
|
|
41
|
-
project?: string
|
|
42
|
-
person?: string
|
|
43
|
-
agent?: string
|
|
44
|
-
machine?: string
|
|
45
|
-
label?: string
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type LocalCanvas = {
|
|
49
|
-
version: 1
|
|
50
|
-
rev: number
|
|
51
|
-
items: CanvasItem[]
|
|
52
|
-
edges: Array<{ from: string; to: string }>
|
|
53
|
-
focused: string | null
|
|
54
|
-
groupBy?: CanvasGrouping
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ITEM_GAP = 80
|
|
58
|
-
const GROUP_PADDING = 64
|
|
59
|
-
// the top row keeps the same title room as the rows below it
|
|
60
|
-
const GROUP_TOP = ITEM_GAP
|
|
61
|
-
const FLOW_GAP_X = 120
|
|
62
|
-
const FLOW_GAP_Y = 64
|
|
63
|
-
const PUSH_TIMEOUT_MS = 20_000
|
|
64
|
-
const CANVAS_BRIDGE_TIMEOUT_MS = PUSH_TIMEOUT_MS + 5_000
|
|
65
|
-
|
|
66
|
-
const HELP = `
|
|
67
|
-
peach canvas — lay out live apps and maps of an app on one canvas
|
|
68
|
-
|
|
69
|
-
usage:
|
|
70
|
-
peach canvas open
|
|
71
|
-
peach canvas place <app> [--device <model>] [--at x,y] [--id <id>] [--radius <pt>]
|
|
72
|
-
peach canvas place --bundle <url|file> [--app-fonts-dir <dir>] [--url <link>] [--device <model>] [--at x,y] [--id <id>]
|
|
73
|
-
peach canvas map --bundle <url|file> [--app-fonts-dir <dir>] [--map <file>] [--scheme myapp://] [--device <model>] [--at x,y] [--id <name>]
|
|
74
|
-
peach canvas move <id> --at x,y
|
|
75
|
-
peach canvas group --by project|person|agent|machine|label
|
|
76
|
-
peach canvas move-group <name> --at x,y
|
|
77
|
-
peach canvas tag <id> [--project <name>] [--person <name>] [--agent <name>] [--machine <name>] [--label <name>]
|
|
78
|
-
peach canvas resize <id> --size width,height
|
|
79
|
-
peach canvas arrange [--by title|device|app] [--columns <n>] [--gap <pt>]
|
|
80
|
-
peach canvas arrange --flow
|
|
81
|
-
peach canvas focus [id]
|
|
82
|
-
peach canvas enter [id]
|
|
83
|
-
peach canvas live <id>
|
|
84
|
-
peach canvas freeze <id>
|
|
85
|
-
peach canvas camera --at x,y --scale <n>
|
|
86
|
-
peach canvas camera --path <file>
|
|
87
|
-
peach canvas agent <item> --name <name> --step <step> [--id <agent>] [--machine <name>] [--action <json>]
|
|
88
|
-
peach canvas agent remove --id <agent>
|
|
89
|
-
peach canvas follow <agent|off>
|
|
90
|
-
peach canvas remove <id>
|
|
91
|
-
peach canvas list
|
|
92
|
-
peach canvas describe
|
|
93
|
-
peach canvas push
|
|
94
|
-
peach canvas view fit
|
|
95
|
-
peach canvas view <id>
|
|
96
|
-
peach canvas view --center x,y [--scale <n>]
|
|
97
|
-
|
|
98
|
-
verbs:
|
|
99
|
-
open open or reuse a canvas sim
|
|
100
|
-
place run a built-in app, or a guest bundle, live on the canvas
|
|
101
|
-
map put a map from peach map on the canvas: every route a live app, linked by its taps
|
|
102
|
-
move move an item to canvas coordinates
|
|
103
|
-
group arrange items into named groups sized for the window
|
|
104
|
-
move-group move a group and all its items
|
|
105
|
-
tag set an item's grouping fields or label
|
|
106
|
-
resize change an item's size in points
|
|
107
|
-
arrange lay items out in rows within their groups, or each map along its links with --flow
|
|
108
|
-
focus select an item, or clear focus without an id
|
|
109
|
-
enter drive an app with peach describe and peach do, or exit it without an id
|
|
110
|
-
live resume an item's app
|
|
111
|
-
freeze retain an item's last frame and app state
|
|
112
|
-
agent attach the caller to an item, update its step, or report an external driver's action
|
|
113
|
-
follow follow one agent between items, or stop with off
|
|
114
|
-
camera set the canvas translation and scale, or play a path
|
|
115
|
-
remove take an item, or a whole map by its name, off the canvas
|
|
116
|
-
list print the working file's items
|
|
117
|
-
describe print the saved groups, items and their state as JSON
|
|
118
|
-
push post the working file to the canvas sim again, as after a reload
|
|
119
|
-
view fit the canvas, bring one item into view at 100%, or center a canvas point
|
|
120
|
-
|
|
121
|
-
options:
|
|
122
|
-
--device <model> the item's device (default: iphone-17-pro)
|
|
123
|
-
--at x,y the item's top left corner in canvas points (default: append to its group or row)
|
|
124
|
-
--id <id> item id (default: the app id, numbered when taken), or a map name (default: the scheme)
|
|
125
|
-
--bundle <url> a Metro bundle url, a built bundle file, or a packaged app's launch url, the item or every route of a map runs
|
|
126
|
-
--app-fonts-dir <dir> the project holding the fonts a built bundle's app links natively
|
|
127
|
-
--map <file> map: the map working file (default: peach-map.json)
|
|
128
|
-
--scheme <url> map: deep link scheme (default: the one the map was crawled with)
|
|
129
|
-
--url <link> the deep link the item's app launches with
|
|
130
|
-
--radius <pt> corner radius in points (default: the device's display)
|
|
131
|
-
--size width,height custom item size in points
|
|
132
|
-
--by <key> arrange: order items by title, device or app (default: the canvas's order)
|
|
133
|
-
--columns <n> arrange: items per row (default: fit the window)
|
|
134
|
-
--gap <pt> arrange: space between items (default: ${ITEM_GAP})
|
|
135
|
-
--flow arrange: lay each map out along its links and leave other items in place
|
|
136
|
-
--path <file> camera: JSON array of {ms,x,y,scale} keyframes, starting at 0 ms
|
|
137
|
-
--file <path> working file (default: peach-canvas.json)
|
|
138
|
-
--name <name> agent's displayed name
|
|
139
|
-
--machine <name> agent's machine (default: this hostname)
|
|
140
|
-
--step <text> agent's current step
|
|
141
|
-
--action <json> an agent action in item coordinates, reported by an external driver
|
|
142
|
-
--sim <id> target a specific canvas sim
|
|
143
|
-
|
|
144
|
-
examples:
|
|
145
|
-
peach canvas open
|
|
146
|
-
peach canvas place photos
|
|
147
|
-
peach canvas enter photos
|
|
148
|
-
peach describe
|
|
149
|
-
peach canvas place notes --device iphone-se
|
|
150
|
-
peach canvas place --bundle "http://localhost:8081/index.bundle?platform=ios"
|
|
151
|
-
peach canvas place --bundle "http://localhost:8081/index.bundle?platform=ios" --url myapp://settings
|
|
152
|
-
peach canvas map --bundle "http://localhost:8081/index.bundle?platform=ios"
|
|
153
|
-
peach canvas view fit
|
|
154
|
-
`
|
|
155
|
-
|
|
156
|
-
function flag(args: string[], name: string): string | undefined {
|
|
157
|
-
const index = args.indexOf(name)
|
|
158
|
-
if (index < 0) return undefined
|
|
159
|
-
const value = args[index + 1]
|
|
160
|
-
if (!value || value.startsWith('--')) throw new Error(`${name} requires a value`)
|
|
161
|
-
return value
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function point(value: string, name: string): { x: number; y: number } {
|
|
165
|
-
if (value.split(',').length !== 2) throw new Error(`${name} takes two coordinates`)
|
|
166
|
-
const [x, y] = value.split(',').map(Number)
|
|
167
|
-
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
|
168
|
-
throw new Error(`${name} takes x,y in canvas points, got "${value}"`)
|
|
169
|
-
}
|
|
170
|
-
return { x, y }
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function size(value: string): { width: number; height: number } {
|
|
174
|
-
const { x: width, y: height } = point(value, '--size')
|
|
175
|
-
if (width <= 0 || height <= 0 || width > 2048 || height > 2048)
|
|
176
|
-
throw new Error('--size dimensions must be greater than zero and at most 2048 points')
|
|
177
|
-
return { width, height }
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function readCanvas(file: string): LocalCanvas {
|
|
181
|
-
if (!existsSync(file))
|
|
182
|
-
return { version: 1, rev: 0, items: [], edges: [], focused: null }
|
|
183
|
-
const parsed: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
|
184
|
-
if (
|
|
185
|
-
!isRecord(parsed) ||
|
|
186
|
-
parsed.version !== 1 ||
|
|
187
|
-
!Array.isArray(parsed.items) ||
|
|
188
|
-
!Number.isSafeInteger(parsed.rev) ||
|
|
189
|
-
typeof parsed.rev !== 'number' ||
|
|
190
|
-
parsed.rev < 0
|
|
191
|
-
) {
|
|
192
|
-
throw new Error(`${file} is not a peach canvas file`)
|
|
193
|
-
}
|
|
194
|
-
const items: CanvasItem[] = []
|
|
195
|
-
const itemIds = new Set<string>()
|
|
196
|
-
for (const raw of parsed.items) {
|
|
197
|
-
if (!isRecord(raw)) throw new Error(`${file} contains an invalid canvas item`)
|
|
198
|
-
const { id, app, device, x, y } = raw
|
|
199
|
-
if (
|
|
200
|
-
typeof id !== 'string' ||
|
|
201
|
-
!id ||
|
|
202
|
-
typeof app !== 'string' ||
|
|
203
|
-
!app ||
|
|
204
|
-
typeof device !== 'string' ||
|
|
205
|
-
!isDeviceModel(device) ||
|
|
206
|
-
typeof x !== 'number' ||
|
|
207
|
-
!Number.isFinite(x) ||
|
|
208
|
-
typeof y !== 'number' ||
|
|
209
|
-
!Number.isFinite(y) ||
|
|
210
|
-
itemIds.has(id)
|
|
211
|
-
)
|
|
212
|
-
throw new Error(`${file} contains an invalid canvas item`)
|
|
213
|
-
const width = raw.width ?? devices[device].width
|
|
214
|
-
const height = raw.height ?? devices[device].height
|
|
215
|
-
const radius = raw.radius ?? null
|
|
216
|
-
const live = raw.live ?? true
|
|
217
|
-
const bundleUrl = raw.bundleUrl ?? null
|
|
218
|
-
const launchMetadata = raw.launchMetadata ?? null
|
|
219
|
-
const nativeSource = raw.nativeSource ?? null
|
|
220
|
-
const launchArgs = raw.launchArgs
|
|
221
|
-
const url = raw.url ?? null
|
|
222
|
-
const title = raw.title ?? null
|
|
223
|
-
const poster = raw.poster ?? null
|
|
224
|
-
const map = raw.map ?? null
|
|
225
|
-
const metadata: Partial<Record<CanvasGrouping, string>> = {}
|
|
226
|
-
for (const field of ['project', 'person', 'agent', 'machine', 'label'] as const) {
|
|
227
|
-
const value = raw[field]
|
|
228
|
-
if (value !== undefined && typeof value !== 'string')
|
|
229
|
-
throw new Error(`${file} contains an invalid canvas ${field}`)
|
|
230
|
-
if (typeof value === 'string' && value.trim()) metadata[field] = value.trim()
|
|
231
|
-
}
|
|
232
|
-
if (
|
|
233
|
-
typeof width !== 'number' ||
|
|
234
|
-
!Number.isFinite(width) ||
|
|
235
|
-
width <= 0 ||
|
|
236
|
-
width > 2048 ||
|
|
237
|
-
typeof height !== 'number' ||
|
|
238
|
-
!Number.isFinite(height) ||
|
|
239
|
-
height <= 0 ||
|
|
240
|
-
height > 2048 ||
|
|
241
|
-
(radius !== null &&
|
|
242
|
-
(typeof radius !== 'number' || !Number.isFinite(radius) || radius < 0)) ||
|
|
243
|
-
typeof live !== 'boolean' ||
|
|
244
|
-
(bundleUrl !== null && typeof bundleUrl !== 'string') ||
|
|
245
|
-
(launchMetadata !== null && typeof launchMetadata !== 'string') ||
|
|
246
|
-
(nativeSource !== null && typeof nativeSource !== 'string') ||
|
|
247
|
-
(launchArgs !== undefined &&
|
|
248
|
-
(!Array.isArray(launchArgs) ||
|
|
249
|
-
!launchArgs.every((arg) => typeof arg === 'string'))) ||
|
|
250
|
-
(url !== null && typeof url !== 'string') ||
|
|
251
|
-
(title !== null && typeof title !== 'string') ||
|
|
252
|
-
(poster !== null && typeof poster !== 'string') ||
|
|
253
|
-
(map !== null && (typeof map !== 'string' || !map))
|
|
254
|
-
)
|
|
255
|
-
throw new Error(`${file} contains an invalid canvas item`)
|
|
256
|
-
items.push({
|
|
257
|
-
id,
|
|
258
|
-
title,
|
|
259
|
-
app,
|
|
260
|
-
bundleUrl,
|
|
261
|
-
launchMetadata,
|
|
262
|
-
nativeSource,
|
|
263
|
-
launchArgs,
|
|
264
|
-
url,
|
|
265
|
-
poster,
|
|
266
|
-
device,
|
|
267
|
-
x,
|
|
268
|
-
y,
|
|
269
|
-
width,
|
|
270
|
-
height,
|
|
271
|
-
live,
|
|
272
|
-
radius,
|
|
273
|
-
map,
|
|
274
|
-
...metadata,
|
|
275
|
-
})
|
|
276
|
-
itemIds.add(id)
|
|
277
|
-
}
|
|
278
|
-
const focused = parsed.focused ?? null
|
|
279
|
-
if (focused !== null && (typeof focused !== 'string' || !itemIds.has(focused)))
|
|
280
|
-
throw new Error(`${file} names an invalid focused item`)
|
|
281
|
-
const edges: LocalCanvas['edges'] = []
|
|
282
|
-
for (const raw of Array.isArray(parsed.edges) ? parsed.edges : []) {
|
|
283
|
-
if (
|
|
284
|
-
!isRecord(raw) ||
|
|
285
|
-
typeof raw.from !== 'string' ||
|
|
286
|
-
typeof raw.to !== 'string' ||
|
|
287
|
-
!itemIds.has(raw.from) ||
|
|
288
|
-
!itemIds.has(raw.to)
|
|
289
|
-
)
|
|
290
|
-
throw new Error(`${file} contains an invalid canvas edge`)
|
|
291
|
-
edges.push({ from: raw.from, to: raw.to })
|
|
292
|
-
}
|
|
293
|
-
const groupBy = parsed.groupBy
|
|
294
|
-
if (
|
|
295
|
-
groupBy !== undefined &&
|
|
296
|
-
groupBy !== 'project' &&
|
|
297
|
-
groupBy !== 'person' &&
|
|
298
|
-
groupBy !== 'agent' &&
|
|
299
|
-
groupBy !== 'machine' &&
|
|
300
|
-
groupBy !== 'label'
|
|
301
|
-
)
|
|
302
|
-
throw new Error(`${file} contains an invalid grouping`)
|
|
303
|
-
return { version: 1, rev: parsed.rev, items, edges, focused, groupBy }
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// each screen of a map one column right of the screen that leads to it, as a
|
|
307
|
-
// published map lays out, from the map's own corner
|
|
308
|
-
function arrangeMap(canvas: LocalCanvas, name: string, origin: { x: number; y: number }) {
|
|
309
|
-
const screens = canvas.items.filter((item) => item.map === name)
|
|
310
|
-
const positions = layoutFlowGraph(
|
|
311
|
-
screens.map((item, order) => ({
|
|
312
|
-
id: item.id,
|
|
313
|
-
width: item.width,
|
|
314
|
-
height: item.height,
|
|
315
|
-
order,
|
|
316
|
-
})),
|
|
317
|
-
canvas.edges.filter(
|
|
318
|
-
(edge) =>
|
|
319
|
-
screens.some((item) => item.id === edge.from) &&
|
|
320
|
-
screens.some((item) => item.id === edge.to),
|
|
321
|
-
),
|
|
322
|
-
{ gapX: FLOW_GAP_X, gapY: FLOW_GAP_Y },
|
|
323
|
-
)
|
|
324
|
-
for (const item of screens) {
|
|
325
|
-
const position = positions.get(item.id) ?? { x: 0, y: 0 }
|
|
326
|
-
Object.assign(item, { x: origin.x + position.x, y: origin.y + position.y })
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function mapCorner(canvas: LocalCanvas, name: string): { x: number; y: number } | null {
|
|
331
|
-
const screens = canvas.items.filter((item) => item.map === name)
|
|
332
|
-
return screens.length
|
|
333
|
-
? {
|
|
334
|
-
x: Math.min(...screens.map((item) => item.x)),
|
|
335
|
-
y: Math.min(...screens.map((item) => item.y)),
|
|
336
|
-
}
|
|
337
|
-
: null
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function removeItems(canvas: LocalCanvas, gone: (item: CanvasItem) => boolean): void {
|
|
341
|
-
const ids = new Set(canvas.items.filter(gone).map((item) => item.id))
|
|
342
|
-
canvas.items = canvas.items.filter((item) => !ids.has(item.id))
|
|
343
|
-
canvas.edges = canvas.edges.filter((edge) => !ids.has(edge.from) && !ids.has(edge.to))
|
|
344
|
-
if (canvas.focused !== null && ids.has(canvas.focused)) canvas.focused = null
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function groupBounds(items: CanvasItem[]) {
|
|
348
|
-
const left = Math.min(...items.map((item) => item.x))
|
|
349
|
-
const top = Math.min(...items.map((item) => item.y))
|
|
350
|
-
const right = Math.max(...items.map((item) => item.x + item.width))
|
|
351
|
-
const bottom = Math.max(...items.map((item) => item.y + item.height))
|
|
352
|
-
return { left, top, right, bottom }
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function nextItemPosition(canvas: LocalCanvas, item: CanvasItem) {
|
|
356
|
-
const by = canvas.groupBy
|
|
357
|
-
if (!by || !canvas.items.length)
|
|
358
|
-
return {
|
|
359
|
-
x: Math.max(0, ...canvas.items.map((item) => item.x + item.width + ITEM_GAP)),
|
|
360
|
-
y: 0,
|
|
361
|
-
}
|
|
362
|
-
const groups = groupCanvasItems([...canvas.items, item], by)
|
|
363
|
-
const siblings = groups
|
|
364
|
-
.find((group) => group.items.includes(item))!
|
|
365
|
-
.items.filter((candidate) => candidate !== item)
|
|
366
|
-
const otherGroups = groups
|
|
367
|
-
.filter((group) => !group.items.includes(item))
|
|
368
|
-
.map(({ items }) => groupBounds(items))
|
|
369
|
-
const spacing = ITEM_GAP * 2 + GROUP_PADDING * 2
|
|
370
|
-
const top = Math.min(...canvas.items.map(({ y }) => y))
|
|
371
|
-
if (!siblings.length)
|
|
372
|
-
return { x: Math.max(...otherGroups.map(({ right }) => right)) + spacing, y: top }
|
|
373
|
-
const bounds = groupBounds(siblings)
|
|
374
|
-
const y = Math.max(...siblings.map((sibling) => sibling.y))
|
|
375
|
-
const x =
|
|
376
|
-
Math.max(
|
|
377
|
-
...siblings
|
|
378
|
-
.filter((sibling) => sibling.y === y)
|
|
379
|
-
.map((sibling) => sibling.x + sibling.width),
|
|
380
|
-
) + ITEM_GAP
|
|
381
|
-
const row = [
|
|
382
|
-
{ x, y },
|
|
383
|
-
{ x: bounds.left, y: bounds.bottom + ITEM_GAP },
|
|
384
|
-
{ x: bounds.left, y: bounds.top - item.height - ITEM_GAP },
|
|
385
|
-
{ x: bounds.left - item.width - ITEM_GAP, y: bounds.top },
|
|
386
|
-
].find(
|
|
387
|
-
({ x, y }) =>
|
|
388
|
-
!otherGroups.some(
|
|
389
|
-
(other) =>
|
|
390
|
-
Math.min(x, bounds.left) < other.right + GROUP_PADDING * 2 &&
|
|
391
|
-
Math.max(x + item.width, bounds.right) > other.left - GROUP_PADDING * 2 &&
|
|
392
|
-
Math.min(y, bounds.top) < other.bottom + GROUP_PADDING + GROUP_TOP &&
|
|
393
|
-
Math.max(y + item.height, bounds.bottom) >
|
|
394
|
-
other.top - GROUP_PADDING - GROUP_TOP,
|
|
395
|
-
),
|
|
396
|
-
)
|
|
397
|
-
if (row) return row
|
|
398
|
-
const offset =
|
|
399
|
-
Math.max(...otherGroups.map(({ bottom }) => bottom)) + spacing - bounds.top
|
|
400
|
-
for (const sibling of siblings) sibling.y += offset
|
|
401
|
-
return { x: bounds.left, y: bounds.bottom + offset + ITEM_GAP }
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
function closeRowGap(canvas: LocalCanvas, removed: CanvasItem) {
|
|
405
|
-
if (removed.map) return
|
|
406
|
-
const siblings = canvas.groupBy
|
|
407
|
-
? groupCanvasItems(canvas.items, canvas.groupBy).find(({ items }) =>
|
|
408
|
-
items.includes(removed),
|
|
409
|
-
)!.items
|
|
410
|
-
: canvas.items
|
|
411
|
-
const row = siblings
|
|
412
|
-
.filter((item) => !item.map && item.y === removed.y && item.x > removed.x)
|
|
413
|
-
.toSorted((a, b) => a.x - b.x)
|
|
414
|
-
const gap = removed.width + ITEM_GAP
|
|
415
|
-
let next = removed.x + gap
|
|
416
|
-
for (const item of row) {
|
|
417
|
-
if (item.x !== next) break
|
|
418
|
-
next += item.width + ITEM_GAP
|
|
419
|
-
item.x -= gap
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
type AppLaunch = Pick<
|
|
424
|
-
CanvasItem,
|
|
425
|
-
'bundleUrl' | 'launchMetadata' | 'nativeSource' | 'launchArgs'
|
|
426
|
-
>
|
|
427
|
-
|
|
428
|
-
// an app's fonts, asset catalog and native configuration reach its item as they
|
|
429
|
-
// reach a device: staged by the launch its bundle resolves to
|
|
430
|
-
async function resolveLaunch(
|
|
431
|
-
target: string,
|
|
432
|
-
bridgePort: number,
|
|
433
|
-
appFontsDir?: string,
|
|
434
|
-
): Promise<AppLaunch> {
|
|
435
|
-
const { buildShellUrl, resolveShellBaseUrlForBridgePort } = await import('./shell-url')
|
|
436
|
-
const { prebuiltBundleFile, stagePrebuiltBundle } = await import('./control')
|
|
437
|
-
const file = prebuiltBundleFile(target)
|
|
438
|
-
const launch = new URL(
|
|
439
|
-
await buildShellUrl(
|
|
440
|
-
file ? (await stagePrebuiltBundle(file, bridgePort)).bundleUrl : target,
|
|
441
|
-
resolveShellBaseUrlForBridgePort(bridgePort),
|
|
442
|
-
{ bridgePort, appFontsDir },
|
|
443
|
-
),
|
|
444
|
-
)
|
|
445
|
-
const bundleUrl = launch.searchParams.get('bundle')
|
|
446
|
-
if (!bundleUrl) throw new Error(`${target} names no bundle`)
|
|
447
|
-
const launchArgs = launch.searchParams.getAll('arg')
|
|
448
|
-
return {
|
|
449
|
-
bundleUrl,
|
|
450
|
-
launchMetadata: launch.searchParams.get(LAUNCH_METADATA_QUERY_PARAM),
|
|
451
|
-
nativeSource: launch.searchParams.get('nativeSource'),
|
|
452
|
-
launchArgs: launchArgs.length ? launchArgs : undefined,
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
// a map is a group of items: one live app per mapped route, launched by its
|
|
457
|
-
// deep link, with the taps between them as edges. placing a map again replaces
|
|
458
|
-
// its screens where they sat and leaves the rest of the canvas alone
|
|
459
|
-
async function placeMap(
|
|
460
|
-
canvas: LocalCanvas,
|
|
461
|
-
args: string[],
|
|
462
|
-
launch: AppLaunch,
|
|
463
|
-
): Promise<number> {
|
|
464
|
-
const { deepLink, deepLinkBase, readLocalMap } = await import('./map')
|
|
465
|
-
const mapFile = resolve(flag(args, '--map') ?? 'peach-map.json')
|
|
466
|
-
const map = readLocalMap(mapFile)
|
|
467
|
-
const scheme = flag(args, '--scheme') ?? map.scheme
|
|
468
|
-
if (!scheme) throw new Error(`${mapFile} records no scheme; pass --scheme myapp://`)
|
|
469
|
-
const device = flag(args, '--device') ?? 'iphone-17-pro'
|
|
470
|
-
if (!isDeviceModel(device))
|
|
471
|
-
throw new Error(`unknown device "${device}"; see peach device list`)
|
|
472
|
-
// a deep link opens a route's default state, so other states have no live item
|
|
473
|
-
const routed = map.screens.flatMap((screen) =>
|
|
474
|
-
screen.route !== null && screen.state === null
|
|
475
|
-
? [{ id: screen.id, route: screen.route, title: screen.title, png: screen.png }]
|
|
476
|
-
: [],
|
|
477
|
-
)
|
|
478
|
-
if (routed.length === 0) throw new Error(`${mapFile} has no routed screens`)
|
|
479
|
-
const base = deepLinkBase(scheme)
|
|
480
|
-
const name = flag(args, '--id') ?? base.slice(0, -'://'.length)
|
|
481
|
-
const at = flag(args, '--at')
|
|
482
|
-
const corner = at ? point(at, '--at') : mapCorner(canvas, name)
|
|
483
|
-
removeItems(canvas, (item) => item.map === name)
|
|
484
|
-
const origin = corner ?? {
|
|
485
|
-
x: Math.max(0, ...canvas.items.map((item) => item.x + item.width + ITEM_GAP)),
|
|
486
|
-
y: 0,
|
|
487
|
-
}
|
|
488
|
-
const taken = new Set(canvas.items.map((item) => item.id))
|
|
489
|
-
const itemIds = new Map<string, string>()
|
|
490
|
-
for (const screen of routed) {
|
|
491
|
-
const slug =
|
|
492
|
-
screen.route.replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-+|-+$/g, '') || 'root'
|
|
493
|
-
let id = slug
|
|
494
|
-
for (let n = 2; taken.has(id); n++) id = `${slug}-${n}`
|
|
495
|
-
taken.add(id)
|
|
496
|
-
itemIds.set(screen.id, id)
|
|
497
|
-
}
|
|
498
|
-
const { width, height } = devices[device]
|
|
499
|
-
for (const screen of routed) {
|
|
500
|
-
const png = resolve(dirname(mapFile), screen.png)
|
|
501
|
-
canvas.items.push({
|
|
502
|
-
id: itemIds.get(screen.id) ?? screen.id,
|
|
503
|
-
title: screen.title,
|
|
504
|
-
app: 'connect',
|
|
505
|
-
...launch,
|
|
506
|
-
url: deepLink(base, screen.route),
|
|
507
|
-
poster: existsSync(png) ? png : null,
|
|
508
|
-
device,
|
|
509
|
-
x: 0,
|
|
510
|
-
y: 0,
|
|
511
|
-
width,
|
|
512
|
-
height,
|
|
513
|
-
live: true,
|
|
514
|
-
radius: null,
|
|
515
|
-
map: name,
|
|
516
|
-
})
|
|
517
|
-
}
|
|
518
|
-
for (const edge of map.edges) {
|
|
519
|
-
const from = itemIds.get(edge.from)
|
|
520
|
-
const to = itemIds.get(edge.to)
|
|
521
|
-
if (from && to && from !== to) canvas.edges.push({ from, to })
|
|
522
|
-
}
|
|
523
|
-
arrangeMap(canvas, name, origin)
|
|
524
|
-
return routed.length
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
const ARRANGE_KEYS = {
|
|
528
|
-
title: (item: CanvasItem) => item.label ?? item.title ?? item.id,
|
|
529
|
-
device: (item: CanvasItem) => item.device,
|
|
530
|
-
app: (item: CanvasItem) => item.bundleUrl ?? item.app,
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
function arrangeGrid(canvas: LocalCanvas, args: string[], pane: unknown): void {
|
|
534
|
-
const by = flag(args, '--by')
|
|
535
|
-
if (by !== undefined) {
|
|
536
|
-
if (by !== 'title' && by !== 'device' && by !== 'app')
|
|
537
|
-
throw new Error('--by takes title, device or app')
|
|
538
|
-
const key = ARRANGE_KEYS[by]
|
|
539
|
-
canvas.items.sort((a, b) =>
|
|
540
|
-
key(a).localeCompare(key(b), undefined, { numeric: true }),
|
|
541
|
-
)
|
|
542
|
-
}
|
|
543
|
-
const columnFlag = flag(args, '--columns')
|
|
544
|
-
const columns = columnFlag === undefined ? undefined : Number(columnFlag)
|
|
545
|
-
const gap = Number(flag(args, '--gap') ?? ITEM_GAP)
|
|
546
|
-
if (columns !== undefined && (!Number.isSafeInteger(columns) || columns < 1))
|
|
547
|
-
throw new Error('--columns must be a whole number of at least 1')
|
|
548
|
-
if (!Number.isFinite(gap) || gap < 0)
|
|
549
|
-
throw new Error('--gap must be a nonnegative number')
|
|
550
|
-
if (canvas.items.length === 0) return
|
|
551
|
-
if (
|
|
552
|
-
!isRecord(pane) ||
|
|
553
|
-
typeof pane.width !== 'number' ||
|
|
554
|
-
typeof pane.height !== 'number' ||
|
|
555
|
-
!Number.isFinite(pane.width) ||
|
|
556
|
-
!Number.isFinite(pane.height) ||
|
|
557
|
-
pane.width <= 0 ||
|
|
558
|
-
pane.height <= 0
|
|
559
|
-
)
|
|
560
|
-
throw new Error('the canvas window has no measurable size')
|
|
561
|
-
const { width, height } = pane
|
|
562
|
-
const pad = canvas.groupBy ? GROUP_PADDING : 0
|
|
563
|
-
const groups = canvas.groupBy
|
|
564
|
-
? groupCanvasItems(canvas.items, canvas.groupBy).map(({ items }) => items)
|
|
565
|
-
: [canvas.items]
|
|
566
|
-
const placements = layoutCanvasGroups(groups, {
|
|
567
|
-
items: { columns, gapX: gap, gapY: gap },
|
|
568
|
-
groups: { gapX: ITEM_GAP * 2, gapY: ITEM_GAP * 2 },
|
|
569
|
-
padding: { left: pad, right: pad, top: canvas.groupBy ? GROUP_TOP : 0, bottom: pad },
|
|
570
|
-
fit: {
|
|
571
|
-
width,
|
|
572
|
-
height,
|
|
573
|
-
margin: Math.min(48, width / 4, height / 4),
|
|
574
|
-
titleRoom: canvas.groupBy ? 44 : 0,
|
|
575
|
-
},
|
|
576
|
-
}).groups
|
|
577
|
-
groups.forEach((items, index) => {
|
|
578
|
-
const group = placements[index]!
|
|
579
|
-
items.forEach((item, index) => {
|
|
580
|
-
const point = group.items[index]!
|
|
581
|
-
item.x = group.x + point.x
|
|
582
|
-
item.y = group.y + point.y
|
|
583
|
-
})
|
|
584
|
-
})
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
function findItem(canvas: LocalCanvas, id: string | undefined): CanvasItem {
|
|
588
|
-
const item = canvas.items.find((entry) => entry.id === id)
|
|
589
|
-
if (!item) throw new Error(`no item "${id ?? ''}" on the canvas; see peach canvas list`)
|
|
590
|
-
return item
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
function canvasSections({ groupBy, items }: LocalCanvas) {
|
|
594
|
-
if (!groupBy) return []
|
|
595
|
-
return groupCanvasItems(items, groupBy).map(({ key, name, items }) => {
|
|
596
|
-
const { left, top, right, bottom } = groupBounds(items)
|
|
597
|
-
return {
|
|
598
|
-
id: `group:${groupBy}:${key}`,
|
|
599
|
-
title: name,
|
|
600
|
-
x: left - GROUP_PADDING,
|
|
601
|
-
y: top - GROUP_TOP,
|
|
602
|
-
width: right - left + GROUP_PADDING * 2,
|
|
603
|
-
height: bottom - top + GROUP_TOP + GROUP_PADDING,
|
|
604
|
-
outline: 'bounds' as const,
|
|
605
|
-
members: { screenIds: items.map((item) => item.id), sectionIds: [] },
|
|
606
|
-
}
|
|
607
|
-
})
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
function canvasData(canvas: LocalCanvas, preserveCameraOnUpdates: boolean) {
|
|
611
|
-
const posters = new Map<string, string>()
|
|
612
|
-
for (const { poster } of canvas.items) {
|
|
613
|
-
if (poster && !posters.has(poster)) {
|
|
614
|
-
posters.set(
|
|
615
|
-
poster,
|
|
616
|
-
`data:image/png;base64,${readFileSync(poster).toString('base64')}`,
|
|
617
|
-
)
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
return {
|
|
621
|
-
rev: canvas.rev,
|
|
622
|
-
acknowledgeOnCommit: true,
|
|
623
|
-
backgroundStyle: 'checker',
|
|
624
|
-
controls: 'embedded',
|
|
625
|
-
artboardControls: 'none',
|
|
626
|
-
panPointers: 2,
|
|
627
|
-
moveItems: true,
|
|
628
|
-
preserveCameraOnUpdates: preserveCameraOnUpdates ? ('unless-fitted' as const) : false,
|
|
629
|
-
layoutTransitionKey: `peach-canvas:${canvas.groupBy ?? ''}`,
|
|
630
|
-
selectedScreenId: canvas.focused ?? undefined,
|
|
631
|
-
edges: canvas.edges,
|
|
632
|
-
pins: [],
|
|
633
|
-
sections: canvasSections(canvas),
|
|
634
|
-
screens: canvas.items.map((item) => ({
|
|
635
|
-
id: item.id,
|
|
636
|
-
title: item.label ?? item.title ?? item.id,
|
|
637
|
-
x: item.x,
|
|
638
|
-
y: item.y,
|
|
639
|
-
width: item.width,
|
|
640
|
-
height: item.height,
|
|
641
|
-
deviceModel: item.device,
|
|
642
|
-
status: 'ready',
|
|
643
|
-
...(item.radius === null ? {} : { cornerRadius: item.radius }),
|
|
644
|
-
content: {
|
|
645
|
-
kind: 'app',
|
|
646
|
-
appId: item.app,
|
|
647
|
-
live: item.live,
|
|
648
|
-
...(item.bundleUrl ? { bundleUrl: item.bundleUrl } : {}),
|
|
649
|
-
...(item.launchMetadata ? { launchMetadata: item.launchMetadata } : {}),
|
|
650
|
-
...(item.nativeSource ? { nativeSource: item.nativeSource } : {}),
|
|
651
|
-
...(item.launchArgs ? { launchArgs: item.launchArgs } : {}),
|
|
652
|
-
...(item.url ? { url: item.url } : {}),
|
|
653
|
-
...(item.poster ? { poster: posters.get(item.poster) } : {}),
|
|
654
|
-
},
|
|
655
|
-
})),
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
// a canvas takes its data from its own page; a post during boot can land before
|
|
660
|
-
// the listener exists, so it reposts until the canvas acks this revision
|
|
661
|
-
function pushCode(data: ReturnType<typeof canvasData>, timeoutMs: number): string {
|
|
662
|
-
return `(async () => {
|
|
663
|
-
const data = ${JSON.stringify(data)}
|
|
664
|
-
if (!window.__peachCanvasMoves) {
|
|
665
|
-
window.__peachCanvasMoves = []
|
|
666
|
-
window.addEventListener('message', (event) => {
|
|
667
|
-
const message = event.data
|
|
668
|
-
if (message?.type === 'sootsim-action' && message.action === 'canvas-map-move') window.__peachCanvasMoves.push(message.value)
|
|
669
|
-
})
|
|
670
|
-
}
|
|
671
|
-
if (!window.__peachCanvasGroupMovesInstalled) {
|
|
672
|
-
window.__peachCanvasGroupMovesInstalled = true
|
|
673
|
-
window.addEventListener('message', (event) => {
|
|
674
|
-
const message = event.data
|
|
675
|
-
if (message?.type === 'sootsim-action' && message.action === 'canvas-map-group-move') window.__peachCanvasMoves.push(message.value)
|
|
676
|
-
})
|
|
677
|
-
}
|
|
678
|
-
const post = () => {
|
|
679
|
-
if (!window.__peachCanvasPlaced) window.postMessage({ type: 'contrast-action', action: 'set-fullscreen-app', value: true }, '*')
|
|
680
|
-
window.postMessage({ type: 'contrast-action', action: 'canvas-map-data', value: data }, '*')
|
|
681
|
-
}
|
|
682
|
-
return await new Promise((done) => {
|
|
683
|
-
const finish = (applied) => {
|
|
684
|
-
if (applied) window.__peachCanvasPlaced = true
|
|
685
|
-
clearInterval(timer)
|
|
686
|
-
clearTimeout(deadline)
|
|
687
|
-
window.removeEventListener('message', onMessage)
|
|
688
|
-
done({ applied })
|
|
689
|
-
}
|
|
690
|
-
const onMessage = (event) => {
|
|
691
|
-
const message = event.data
|
|
692
|
-
if (message?.type === 'sootsim-action' && message.action === 'canvas-map-data-applied' && message.rev === data.rev) finish(true)
|
|
693
|
-
}
|
|
694
|
-
window.addEventListener('message', onMessage)
|
|
695
|
-
const timer = setInterval(post, 700)
|
|
696
|
-
const deadline = setTimeout(() => finish(false), ${timeoutMs})
|
|
697
|
-
post()
|
|
698
|
-
})
|
|
699
|
-
})()`
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// a fullscreen canvas fills its page; take the size and pending drags in one read
|
|
703
|
-
const PAGE_STATE_CODE = `(() => {
|
|
704
|
-
const moves = window.__peachCanvasMoves ?? []
|
|
705
|
-
if (moves.length) window.__peachCanvasMoves = []
|
|
706
|
-
return { moves, pane: { width: window.innerWidth, height: window.innerHeight } }
|
|
707
|
-
})()`
|
|
708
|
-
|
|
709
|
-
function commandCode(command: unknown): string {
|
|
710
|
-
return `(() => {
|
|
711
|
-
window.postMessage({ type: 'contrast-action', action: 'canvas-map-command', value: ${JSON.stringify(command)} }, '*')
|
|
712
|
-
return { ok: true }
|
|
713
|
-
})()`
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
function enterCode(screenId: string | null): string {
|
|
717
|
-
return `new Promise((resolve, reject) => {
|
|
718
|
-
const screenId = ${JSON.stringify(screenId)}
|
|
719
|
-
const onMessage = (event) => {
|
|
720
|
-
const message = event.data
|
|
721
|
-
if (message?.type !== 'sootsim-action' || message.action !== 'canvas-map-drive' ||
|
|
722
|
-
message.value?.screenId !== screenId) return
|
|
723
|
-
clearTimeout(deadline)
|
|
724
|
-
window.removeEventListener('message', onMessage)
|
|
725
|
-
resolve({ ok: true })
|
|
726
|
-
}
|
|
727
|
-
const deadline = setTimeout(() => {
|
|
728
|
-
window.removeEventListener('message', onMessage)
|
|
729
|
-
reject(new Error('canvas did not enter the requested item. Run peach canvas push first.'))
|
|
730
|
-
}, 3000)
|
|
731
|
-
window.addEventListener('message', onMessage)
|
|
732
|
-
window.postMessage({ type: 'contrast-action', action: 'canvas-map-command', value: { kind: 'drive', screenId } }, '*')
|
|
733
|
-
})`
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
function cameraPath(file: string): { ms: number; x: number; y: number; scale: number }[] {
|
|
737
|
-
const value: unknown = JSON.parse(readFileSync(file, 'utf8'))
|
|
738
|
-
if (!Array.isArray(value) || value.length < 2)
|
|
739
|
-
throw new Error('camera path needs at least two keyframes')
|
|
740
|
-
const frames: { ms: number; x: number; y: number; scale: number }[] = []
|
|
741
|
-
for (const frame of value) {
|
|
742
|
-
if (
|
|
743
|
-
!isRecord(frame) ||
|
|
744
|
-
typeof frame.ms !== 'number' ||
|
|
745
|
-
!Number.isFinite(frame.ms) ||
|
|
746
|
-
typeof frame.x !== 'number' ||
|
|
747
|
-
!Number.isFinite(frame.x) ||
|
|
748
|
-
typeof frame.y !== 'number' ||
|
|
749
|
-
!Number.isFinite(frame.y) ||
|
|
750
|
-
typeof frame.scale !== 'number' ||
|
|
751
|
-
!Number.isFinite(frame.scale) ||
|
|
752
|
-
frame.scale <= 0 ||
|
|
753
|
-
(frames.length === 0 ? frame.ms !== 0 : frame.ms <= frames[frames.length - 1]!.ms)
|
|
754
|
-
)
|
|
755
|
-
throw new Error(
|
|
756
|
-
'camera keyframes need increasing ms from 0, finite x,y and positive scale',
|
|
757
|
-
)
|
|
758
|
-
frames.push({ ms: frame.ms, x: frame.x, y: frame.y, scale: frame.scale })
|
|
759
|
-
}
|
|
760
|
-
return frames
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
function cameraPathCode(frames: ReturnType<typeof cameraPath>): string {
|
|
764
|
-
return `(async () => {
|
|
765
|
-
const frames = ${JSON.stringify(frames)}
|
|
766
|
-
const start = performance.now()
|
|
767
|
-
let index = 0
|
|
768
|
-
await new Promise((done) => {
|
|
769
|
-
const step = (now) => {
|
|
770
|
-
const elapsed = now - start
|
|
771
|
-
while (index < frames.length - 2 && elapsed >= frames[index + 1].ms) index++
|
|
772
|
-
const from = frames[index], to = frames[index + 1]
|
|
773
|
-
const t = Math.min(1, Math.max(0, (elapsed - from.ms) / (to.ms - from.ms)))
|
|
774
|
-
const value = { kind: 'camera', x: from.x + (to.x - from.x) * t, y: from.y + (to.y - from.y) * t, scale: from.scale + (to.scale - from.scale) * t }
|
|
775
|
-
window.postMessage({ type: 'contrast-action', action: 'canvas-map-command', value }, '*')
|
|
776
|
-
if (elapsed >= frames[frames.length - 1].ms) done()
|
|
777
|
-
else requestAnimationFrame(step)
|
|
778
|
-
}
|
|
779
|
-
step(start)
|
|
780
|
-
})
|
|
781
|
-
return { ok: true }
|
|
782
|
-
})()`
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
export async function runCanvas(
|
|
786
|
-
args: string[],
|
|
787
|
-
opts: { port?: number; verbose?: boolean },
|
|
788
|
-
): Promise<number> {
|
|
789
|
-
try {
|
|
790
|
-
return await dispatch(args, opts)
|
|
791
|
-
} catch (error) {
|
|
792
|
-
console.error(
|
|
793
|
-
` canvas failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
794
|
-
)
|
|
795
|
-
return 1
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
async function dispatch(
|
|
800
|
-
args: string[],
|
|
801
|
-
opts: { port?: number; verbose?: boolean },
|
|
802
|
-
): Promise<number> {
|
|
803
|
-
const readBridgeArgs = () =>
|
|
804
|
-
parseBridgeCliArgs(args, {
|
|
805
|
-
port: opts.port,
|
|
806
|
-
commandTimeoutMs: CANVAS_BRIDGE_TIMEOUT_MS,
|
|
807
|
-
stripBooleanFlags: ['--help', '-h'],
|
|
808
|
-
stripValueFlags: [
|
|
809
|
-
'--file',
|
|
810
|
-
'--device',
|
|
811
|
-
'--at',
|
|
812
|
-
'--id',
|
|
813
|
-
'--bundle',
|
|
814
|
-
'--app-fonts-dir',
|
|
815
|
-
'--url',
|
|
816
|
-
'--radius',
|
|
817
|
-
'--center',
|
|
818
|
-
'--scale',
|
|
819
|
-
'--path',
|
|
820
|
-
'--size',
|
|
821
|
-
'--map',
|
|
822
|
-
'--scheme',
|
|
823
|
-
'--by',
|
|
824
|
-
'--project',
|
|
825
|
-
'--person',
|
|
826
|
-
'--agent',
|
|
827
|
-
'--machine',
|
|
828
|
-
'--label',
|
|
829
|
-
'--name',
|
|
830
|
-
'--step',
|
|
831
|
-
'--action',
|
|
832
|
-
],
|
|
833
|
-
})
|
|
834
|
-
const parsed = readBridgeArgs()
|
|
835
|
-
const [verb, target] = parsed.positional
|
|
836
|
-
if (!verb || verb === 'help' || args.includes('--help') || args.includes('-h')) {
|
|
837
|
-
console.log(HELP)
|
|
838
|
-
return verb ? 0 : 1
|
|
839
|
-
}
|
|
840
|
-
if (verb === 'open') {
|
|
841
|
-
const { runOpenCommand } = await import('./control')
|
|
842
|
-
const opened = await runOpenCommand(
|
|
843
|
-
['canvas-map', '--device', 'canvas-workspace', '--no-describe', ...args.slice(1)],
|
|
844
|
-
{ ...opts, reuseUnchangedSim: true },
|
|
845
|
-
)
|
|
846
|
-
if (!opened) return 1
|
|
847
|
-
// a canvas opens on the working file it was left with, through the sim it just opened
|
|
848
|
-
const file = resolve(flag(args, '--file') ?? 'peach-canvas.json')
|
|
849
|
-
if (!existsSync(file)) return 0
|
|
850
|
-
const bridge = createBridgeFromParsed(readBridgeArgs())
|
|
851
|
-
try {
|
|
852
|
-
await pushCanvas(file, readCanvas(file), bridge)
|
|
853
|
-
} finally {
|
|
854
|
-
bridge.close()
|
|
855
|
-
}
|
|
856
|
-
return 0
|
|
857
|
-
}
|
|
858
|
-
const file = resolve(flag(args, '--file') ?? 'peach-canvas.json')
|
|
859
|
-
const canvas = readCanvas(file)
|
|
860
|
-
if (verb === 'describe') {
|
|
861
|
-
console.log(
|
|
862
|
-
JSON.stringify({
|
|
863
|
-
...canvas,
|
|
864
|
-
groupBy: canvas.groupBy ?? null,
|
|
865
|
-
groups: canvasSections(canvas),
|
|
866
|
-
}),
|
|
867
|
-
)
|
|
868
|
-
return 0
|
|
869
|
-
}
|
|
870
|
-
if (verb === 'enter') {
|
|
871
|
-
const item = target === undefined ? null : findItem(canvas, target)
|
|
872
|
-
if (item?.live === false) throw new Error(`run peach canvas live ${item.id} first`)
|
|
873
|
-
const bridge = createBridgeFromParsed(parsed)
|
|
874
|
-
try {
|
|
875
|
-
await evalInBridge(bridge, enterCode(item?.id ?? null), { acquireLock: true })
|
|
876
|
-
} finally {
|
|
877
|
-
bridge.close()
|
|
878
|
-
}
|
|
879
|
-
return 0
|
|
880
|
-
}
|
|
881
|
-
if (verb === 'agent' || verb === 'follow') {
|
|
882
|
-
// the same id the cli puts on the actions it drives (command-agent.ts)
|
|
883
|
-
const agentId = flag(args, '--id') ?? getCliIdentity().key
|
|
884
|
-
let command: unknown
|
|
885
|
-
let worked: { item: CanvasItem; agent: string; machine: string } | null = null
|
|
886
|
-
if (verb === 'follow') {
|
|
887
|
-
if (!target) throw new Error('follow takes an agent id or off')
|
|
888
|
-
command = { kind: 'follow-agent', agentId: target === 'off' ? null : target }
|
|
889
|
-
} else if (target === 'remove') {
|
|
890
|
-
if (!agentId) throw new Error('agent remove takes --id <agent>')
|
|
891
|
-
command = { kind: 'remove-agent', agentId }
|
|
892
|
-
} else {
|
|
893
|
-
const item = findItem(canvas, target)
|
|
894
|
-
const rawAction = flag(args, '--action')
|
|
895
|
-
const detail: unknown = rawAction ? JSON.parse(rawAction) : undefined
|
|
896
|
-
const agent = {
|
|
897
|
-
id: agentId,
|
|
898
|
-
name: flag(args, '--name') ?? cliAgentName(agentId),
|
|
899
|
-
machine: flag(args, '--machine') ?? hostname(),
|
|
900
|
-
step: flag(args, '--step'),
|
|
901
|
-
screenId: item.id,
|
|
902
|
-
...(detail ? { action: { sequence: Date.now(), detail } } : {}),
|
|
903
|
-
}
|
|
904
|
-
if (!isCanvasMapAgent(agent))
|
|
905
|
-
throw new Error(
|
|
906
|
-
'agent takes --id, --name and --step, with an optional agent action JSON',
|
|
907
|
-
)
|
|
908
|
-
command = { kind: 'agent', agent }
|
|
909
|
-
if (item.agent !== agent.name || item.machine !== agent.machine)
|
|
910
|
-
worked = { item, agent: agent.name, machine: agent.machine }
|
|
911
|
-
}
|
|
912
|
-
const bridge = createBridgeFromParsed(parsed)
|
|
913
|
-
try {
|
|
914
|
-
await evalInBridge(bridge, commandCode(command))
|
|
915
|
-
// the item an agent works on carries its name and machine, so grouping by
|
|
916
|
-
// agent or machine follows the agents
|
|
917
|
-
if (worked) {
|
|
918
|
-
const state = await evalInBridge(bridge, PAGE_STATE_CODE)
|
|
919
|
-
applyCanvasMoves(canvas, state)
|
|
920
|
-
worked.item.agent = worked.agent
|
|
921
|
-
worked.item.machine = worked.machine
|
|
922
|
-
if (canvas.groupBy === 'agent' || canvas.groupBy === 'machine')
|
|
923
|
-
arrangeGrid(canvas, [], isRecord(state) ? state.pane : undefined)
|
|
924
|
-
await pushCanvas(file, canvas, bridge)
|
|
925
|
-
}
|
|
926
|
-
} finally {
|
|
927
|
-
bridge.close()
|
|
928
|
-
}
|
|
929
|
-
return 0
|
|
930
|
-
}
|
|
931
|
-
if (verb === 'camera') {
|
|
932
|
-
const path = flag(args, '--path')
|
|
933
|
-
if (path) {
|
|
934
|
-
if (flag(args, '--at') || flag(args, '--scale'))
|
|
935
|
-
throw new Error('camera --path cannot be combined with --at or --scale')
|
|
936
|
-
const frames = cameraPath(resolve(path))
|
|
937
|
-
const bridge = createBridgeFromParsed({
|
|
938
|
-
...parsed,
|
|
939
|
-
commandTimeoutMs: Math.max(
|
|
940
|
-
parsed.commandTimeoutMs,
|
|
941
|
-
frames[frames.length - 1]!.ms + CANVAS_BRIDGE_TIMEOUT_MS,
|
|
942
|
-
),
|
|
943
|
-
})
|
|
944
|
-
try {
|
|
945
|
-
await evalInBridge(bridge, cameraPathCode(frames))
|
|
946
|
-
} finally {
|
|
947
|
-
bridge.close()
|
|
948
|
-
}
|
|
949
|
-
return 0
|
|
950
|
-
}
|
|
951
|
-
const at = flag(args, '--at')
|
|
952
|
-
if (!at) throw new Error('camera takes --at x,y and --scale <n>')
|
|
953
|
-
const scale = Number(flag(args, '--scale'))
|
|
954
|
-
if (!Number.isFinite(scale) || scale <= 0) throw new Error('--scale must be positive')
|
|
955
|
-
const bridge = createBridgeFromParsed(parsed)
|
|
956
|
-
try {
|
|
957
|
-
await evalInBridge(
|
|
958
|
-
bridge,
|
|
959
|
-
commandCode({ kind: 'camera', ...point(at, '--at'), scale }),
|
|
960
|
-
)
|
|
961
|
-
} finally {
|
|
962
|
-
bridge.close()
|
|
963
|
-
}
|
|
964
|
-
return 0
|
|
965
|
-
}
|
|
966
|
-
if (verb === 'list') {
|
|
967
|
-
for (const item of canvas.items) {
|
|
968
|
-
console.log(
|
|
969
|
-
` ${item.id} ${item.bundleUrl ?? item.app}${item.url ? ` ${item.url}` : ''} ${item.device} at ${item.x},${item.y}${item.map ? ` map ${item.map}` : ''}`,
|
|
970
|
-
)
|
|
971
|
-
}
|
|
972
|
-
console.log(` ${canvas.items.length} items`)
|
|
973
|
-
return 0
|
|
974
|
-
}
|
|
975
|
-
if (verb === 'view') {
|
|
976
|
-
const center = flag(args, '--center')
|
|
977
|
-
let command: unknown
|
|
978
|
-
if (target === 'fit') command = 'fit'
|
|
979
|
-
else if (center) {
|
|
980
|
-
const { x, y } = point(center, '--center')
|
|
981
|
-
command = {
|
|
982
|
-
kind: 'view-center',
|
|
983
|
-
x,
|
|
984
|
-
y,
|
|
985
|
-
scale: Number(flag(args, '--scale') ?? 1),
|
|
986
|
-
animate: false,
|
|
987
|
-
}
|
|
988
|
-
} else {
|
|
989
|
-
command = { kind: 'view-screen', screenId: findItem(canvas, target).id }
|
|
990
|
-
}
|
|
991
|
-
const bridge = createBridgeFromParsed(parsed)
|
|
992
|
-
try {
|
|
993
|
-
await evalInBridge(bridge, commandCode(command))
|
|
994
|
-
} finally {
|
|
995
|
-
bridge.close()
|
|
996
|
-
}
|
|
997
|
-
return 0
|
|
998
|
-
}
|
|
999
|
-
const bridge = createBridgeFromParsed(parsed)
|
|
1000
|
-
try {
|
|
1001
|
-
const state = await evalInBridge(bridge, PAGE_STATE_CODE)
|
|
1002
|
-
applyCanvasMoves(canvas, state)
|
|
1003
|
-
const pane = isRecord(state) ? state.pane : undefined
|
|
1004
|
-
const message = await editCanvas(canvas, verb, target, args, parsed.wsPort, pane)
|
|
1005
|
-
if (message === undefined) return 1
|
|
1006
|
-
await pushCanvas(
|
|
1007
|
-
file,
|
|
1008
|
-
canvas,
|
|
1009
|
-
bridge,
|
|
1010
|
-
verb === 'place' || verb === 'remove' || verb === 'map',
|
|
1011
|
-
)
|
|
1012
|
-
console.log(` ${message} (${file})`)
|
|
1013
|
-
} finally {
|
|
1014
|
-
bridge.close()
|
|
1015
|
-
}
|
|
1016
|
-
return 0
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function applyCanvasMoves(canvas: LocalCanvas, dragged: unknown): void {
|
|
1020
|
-
if (!isRecord(dragged) || !Array.isArray(dragged.moves) || dragged.moves.length === 0)
|
|
1021
|
-
return
|
|
1022
|
-
const items = new Map(canvas.items.map((item) => [item.id, item]))
|
|
1023
|
-
const groups = new Map(canvasSections(canvas).map((section) => [section.id, section]))
|
|
1024
|
-
for (const move of dragged.moves) {
|
|
1025
|
-
if (!isRecord(move) || move.rev !== canvas.rev) continue
|
|
1026
|
-
if (typeof move.sectionId === 'string') {
|
|
1027
|
-
const group = groups.get(move.sectionId)
|
|
1028
|
-
if (!group || typeof move.x !== 'number' || typeof move.y !== 'number') continue
|
|
1029
|
-
for (const id of group.members.screenIds) {
|
|
1030
|
-
const item = items.get(id)!
|
|
1031
|
-
item.x += move.x - group.x
|
|
1032
|
-
item.y += move.y - group.y
|
|
1033
|
-
}
|
|
1034
|
-
group.x = move.x
|
|
1035
|
-
group.y = move.y
|
|
1036
|
-
continue
|
|
1037
|
-
}
|
|
1038
|
-
if (!Array.isArray(move.positions)) continue
|
|
1039
|
-
for (const position of move.positions) {
|
|
1040
|
-
if (!isRecord(position) || typeof position.screenId !== 'string') continue
|
|
1041
|
-
const item = items.get(position.screenId)
|
|
1042
|
-
if (item && typeof position.x === 'number' && typeof position.y === 'number')
|
|
1043
|
-
Object.assign(item, { x: position.x, y: position.y })
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
async function editCanvas(
|
|
1049
|
-
canvas: LocalCanvas,
|
|
1050
|
-
verb: string,
|
|
1051
|
-
target: string | undefined,
|
|
1052
|
-
args: string[],
|
|
1053
|
-
wsPort: number,
|
|
1054
|
-
pane: unknown,
|
|
1055
|
-
): Promise<string | undefined> {
|
|
1056
|
-
if (verb === 'place') {
|
|
1057
|
-
const bundle = flag(args, '--bundle')
|
|
1058
|
-
const launch = bundle
|
|
1059
|
-
? await resolveLaunch(bundle, wsPort, flag(args, '--app-fonts-dir'))
|
|
1060
|
-
: { bundleUrl: null, launchMetadata: null, nativeSource: null }
|
|
1061
|
-
const app = bundle ? (target ?? 'connect') : target
|
|
1062
|
-
if (!app) throw new Error('place takes a built-in app id or --bundle <url>')
|
|
1063
|
-
const device = flag(args, '--device') ?? 'iphone-17-pro'
|
|
1064
|
-
if (!isDeviceModel(device))
|
|
1065
|
-
throw new Error(`unknown device "${device}"; see peach device list`)
|
|
1066
|
-
const at = flag(args, '--at')
|
|
1067
|
-
const base = flag(args, '--id') ?? app
|
|
1068
|
-
let id = base
|
|
1069
|
-
for (let n = 2; canvas.items.some((item) => item.id === id); n++) id = `${base}-${n}`
|
|
1070
|
-
const radius = flag(args, '--radius')
|
|
1071
|
-
const cornerRadius = radius === undefined ? null : Number(radius)
|
|
1072
|
-
if (cornerRadius !== null && (!Number.isFinite(cornerRadius) || cornerRadius < 0))
|
|
1073
|
-
throw new Error('--radius must be a nonnegative number')
|
|
1074
|
-
const customSize = flag(args, '--size')
|
|
1075
|
-
const dimensions = customSize
|
|
1076
|
-
? size(customSize)
|
|
1077
|
-
: { width: devices[device].width, height: devices[device].height }
|
|
1078
|
-
const item: CanvasItem = {
|
|
1079
|
-
id,
|
|
1080
|
-
title: null,
|
|
1081
|
-
app,
|
|
1082
|
-
...launch,
|
|
1083
|
-
url: flag(args, '--url') ?? null,
|
|
1084
|
-
poster: null,
|
|
1085
|
-
device,
|
|
1086
|
-
...dimensions,
|
|
1087
|
-
live: true,
|
|
1088
|
-
x: 0,
|
|
1089
|
-
y: 0,
|
|
1090
|
-
radius: cornerRadius,
|
|
1091
|
-
map: null,
|
|
1092
|
-
...Object.fromEntries(
|
|
1093
|
-
['project', 'person', 'agent', 'machine', 'label'].flatMap((field) => {
|
|
1094
|
-
const value = flag(args, `--${field}`)
|
|
1095
|
-
return value ? [[field, value]] : []
|
|
1096
|
-
}),
|
|
1097
|
-
),
|
|
1098
|
-
}
|
|
1099
|
-
Object.assign(item, at ? point(at, '--at') : nextItemPosition(canvas, item))
|
|
1100
|
-
canvas.items.push(item)
|
|
1101
|
-
} else if (verb === 'map') {
|
|
1102
|
-
const bundle = flag(args, '--bundle')
|
|
1103
|
-
if (!bundle) throw new Error('map needs --bundle <metro bundle url>')
|
|
1104
|
-
const routes = await placeMap(
|
|
1105
|
-
canvas,
|
|
1106
|
-
args,
|
|
1107
|
-
await resolveLaunch(bundle, wsPort, flag(args, '--app-fonts-dir')),
|
|
1108
|
-
)
|
|
1109
|
-
return `${routes} routes live on the canvas`
|
|
1110
|
-
} else if (verb === 'move') {
|
|
1111
|
-
const at = flag(args, '--at')
|
|
1112
|
-
if (!at) throw new Error('move takes --at x,y')
|
|
1113
|
-
Object.assign(findItem(canvas, target), point(at, '--at'))
|
|
1114
|
-
} else if (verb === 'tag') {
|
|
1115
|
-
const item = findItem(canvas, target)
|
|
1116
|
-
let changed = false
|
|
1117
|
-
for (const field of ['project', 'person', 'agent', 'machine', 'label'] as const) {
|
|
1118
|
-
const value = flag(args, `--${field}`)
|
|
1119
|
-
if (value === undefined) continue
|
|
1120
|
-
if (value.trim()) item[field] = value.trim()
|
|
1121
|
-
else delete item[field]
|
|
1122
|
-
changed = true
|
|
1123
|
-
}
|
|
1124
|
-
if (!changed) throw new Error('tag takes at least one grouping field or --label')
|
|
1125
|
-
} else if (verb === 'group') {
|
|
1126
|
-
const by = flag(args, '--by')
|
|
1127
|
-
if (
|
|
1128
|
-
by !== 'project' &&
|
|
1129
|
-
by !== 'person' &&
|
|
1130
|
-
by !== 'agent' &&
|
|
1131
|
-
by !== 'machine' &&
|
|
1132
|
-
by !== 'label'
|
|
1133
|
-
)
|
|
1134
|
-
throw new Error('--by takes project, person, agent, machine or label')
|
|
1135
|
-
canvas.groupBy = by
|
|
1136
|
-
arrangeGrid(canvas, [], pane)
|
|
1137
|
-
} else if (verb === 'move-group') {
|
|
1138
|
-
if (!canvas.groupBy) throw new Error('group the canvas first')
|
|
1139
|
-
const at = flag(args, '--at')
|
|
1140
|
-
if (!at) throw new Error('move-group takes --at x,y')
|
|
1141
|
-
const group = groupCanvasItems(canvas.items, canvas.groupBy).find(
|
|
1142
|
-
(entry) => entry.name === target,
|
|
1143
|
-
)
|
|
1144
|
-
if (!group) throw new Error(`no group "${target ?? ''}" on the canvas`)
|
|
1145
|
-
const origin = {
|
|
1146
|
-
x: Math.min(...group.items.map((item) => item.x)) - GROUP_PADDING,
|
|
1147
|
-
y: Math.min(...group.items.map((item) => item.y)) - GROUP_TOP,
|
|
1148
|
-
}
|
|
1149
|
-
const to = point(at, '--at')
|
|
1150
|
-
for (const item of group.items) {
|
|
1151
|
-
item.x += to.x - origin.x
|
|
1152
|
-
item.y += to.y - origin.y
|
|
1153
|
-
}
|
|
1154
|
-
} else if (verb === 'remove') {
|
|
1155
|
-
const item = canvas.items.find((item) => item.id === target)
|
|
1156
|
-
if (item) {
|
|
1157
|
-
closeRowGap(canvas, item)
|
|
1158
|
-
removeItems(canvas, (item) => item.id === target)
|
|
1159
|
-
} else if (canvas.items.some((item) => item.map === target))
|
|
1160
|
-
removeItems(canvas, (item) => item.map === target)
|
|
1161
|
-
else findItem(canvas, target)
|
|
1162
|
-
} else if (verb === 'resize') {
|
|
1163
|
-
const dimensions = flag(args, '--size')
|
|
1164
|
-
if (!dimensions) throw new Error('resize takes --size width,height')
|
|
1165
|
-
Object.assign(findItem(canvas, target), size(dimensions))
|
|
1166
|
-
} else if (verb === 'arrange') {
|
|
1167
|
-
if (!args.includes('--flow')) arrangeGrid(canvas, args, pane)
|
|
1168
|
-
else {
|
|
1169
|
-
const names = new Set(canvas.items.flatMap((item) => item.map ?? []))
|
|
1170
|
-
if (names.size === 0)
|
|
1171
|
-
throw new Error('--flow needs a map on the canvas; see peach canvas map')
|
|
1172
|
-
for (const name of names) {
|
|
1173
|
-
const corner = mapCorner(canvas, name)
|
|
1174
|
-
if (corner) arrangeMap(canvas, name, corner)
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
} else if (verb === 'focus') {
|
|
1178
|
-
canvas.focused = target ? findItem(canvas, target).id : null
|
|
1179
|
-
} else if (verb === 'live' || verb === 'freeze') {
|
|
1180
|
-
findItem(canvas, target).live = verb === 'live'
|
|
1181
|
-
} else if (verb !== 'push') {
|
|
1182
|
-
console.error(` unknown canvas verb: ${verb}\n${HELP}`)
|
|
1183
|
-
return
|
|
1184
|
-
}
|
|
1185
|
-
return `canvas has ${canvas.items.length} items`
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
// save the canvas as its next revision and post it to the canvas sim
|
|
1189
|
-
async function pushCanvas(
|
|
1190
|
-
file: string,
|
|
1191
|
-
canvas: LocalCanvas,
|
|
1192
|
-
bridge: ReturnType<typeof createBridgeFromParsed>,
|
|
1193
|
-
preserveCameraOnUpdates = false,
|
|
1194
|
-
): Promise<void> {
|
|
1195
|
-
canvas.rev += 1
|
|
1196
|
-
writeFileSync(file, `${JSON.stringify(canvas, null, 2)}\n`)
|
|
1197
|
-
const result = await evalInBridge(
|
|
1198
|
-
bridge,
|
|
1199
|
-
pushCode(canvasData(canvas, preserveCameraOnUpdates), PUSH_TIMEOUT_MS),
|
|
1200
|
-
)
|
|
1201
|
-
if (!isRecord(result) || result.applied !== true) {
|
|
1202
|
-
throw new Error('the sim did not apply the canvas; open one with peach canvas open')
|
|
1203
|
-
}
|
|
1204
|
-
}
|