peachsim 0.1.1655 → 0.1.1659

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 (235) hide show
  1. package/cli/app-config.ts +4 -0
  2. package/cli/app-stubs.ts +43 -6
  3. package/cli/commands/inspect/shared.ts +5 -2
  4. package/cli/commands/inspect/url.ts +2 -1
  5. package/cli/commands/screenshot.ts +5 -5
  6. package/cli/commands/state.ts +9 -6
  7. package/cli/outbound-endpoints.ts +9 -1
  8. package/cli/output-redaction.ts +49 -0
  9. package/dist-lib/agent-daemon-client.cjs +1 -1
  10. package/dist-lib/agent-events.cjs +1 -1
  11. package/dist-lib/attached-projects.cjs +1 -1
  12. package/dist-lib/auth/shared-session.cjs +1 -1
  13. package/dist-lib/backend-origin.cjs +1 -1
  14. package/dist-lib/beta.cjs +1 -1
  15. package/dist-lib/beta.mjs +1 -1
  16. package/dist-lib/bridge-constants.cjs +1 -1
  17. package/dist-lib/bridge-contract-input.cjs +1 -1
  18. package/dist-lib/bridge-contract-input.mjs +1 -1
  19. package/dist-lib/bridge-contract.cjs +1 -1
  20. package/dist-lib/bridge-contract.mjs +1 -1
  21. package/dist-lib/bundle-channel.cjs +11251 -1123
  22. package/dist-lib/capture-contract.cjs +1 -1
  23. package/dist-lib/capture-contract.mjs +1 -1
  24. package/dist-lib/cloud-contract.cjs +1 -1
  25. package/dist-lib/cloud-contract.mjs +1 -1
  26. package/dist-lib/cloud-test-args.cjs +1 -1
  27. package/dist-lib/cloud-test-args.mjs +1 -1
  28. package/dist-lib/cloud.cjs +1 -1
  29. package/dist-lib/cloud.mjs +1 -1
  30. package/dist-lib/config.cjs +29 -5
  31. package/dist-lib/config.mjs +29 -5
  32. package/dist-lib/detox/index.cjs +19 -5
  33. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  34. package/dist-lib/expo-swift-bundle.cjs +8960 -134
  35. package/dist-lib/expo-swift-metadata.cjs +1 -1
  36. package/dist-lib/expo-swift-metadata.mjs +1 -1
  37. package/dist-lib/home-paths.cjs +1 -1
  38. package/dist-lib/host/bridge-host.cjs +9769 -731
  39. package/dist-lib/host/fetch-proxy-handler.cjs +260 -197
  40. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  41. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  42. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  43. package/dist-lib/host/websocket-proxy.cjs +1 -1
  44. package/dist-lib/index.cjs +653 -338
  45. package/dist-lib/jump-to-source-babel.cjs +1 -1
  46. package/dist-lib/jump-to-source-native.cjs +1 -1
  47. package/dist-lib/kotlin-host.cjs +443 -312
  48. package/dist-lib/menu.cjs +1 -1
  49. package/dist-lib/menu.mjs +1 -1
  50. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  51. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  52. package/dist-lib/metro-production-bundle.cjs +1 -1
  53. package/dist-lib/metro-production-bundle.mjs +1 -1
  54. package/dist-lib/metro.cjs +548 -163
  55. package/dist-lib/native-app-identity-project.cjs +179 -33
  56. package/dist-lib/native-app-identity-project.mjs +179 -33
  57. package/dist-lib/native-app-identity.cjs +1 -1
  58. package/dist-lib/native-app-identity.mjs +1 -1
  59. package/dist-lib/native-firebase-metadata.cjs +1 -1
  60. package/dist-lib/native-firebase-metadata.mjs +1 -1
  61. package/dist-lib/plist.cjs +1 -1
  62. package/dist-lib/plist.mjs +1 -1
  63. package/dist-lib/profiles.cjs +1 -1
  64. package/dist-lib/public-brand.cjs +1 -1
  65. package/dist-lib/public-origins-lib-esm.json +23 -23
  66. package/dist-lib/public-origins-lib.json +96 -63
  67. package/dist-lib/react-native-host-modules.cjs +1 -1
  68. package/dist-lib/react-native-host-modules.mjs +1 -1
  69. package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
  70. package/dist-lib/sdk.cjs +1 -1
  71. package/dist-lib/sdk.mjs +1 -1
  72. package/dist-lib/skills.cjs +10651 -1418
  73. package/dist-lib/swift-compile.cjs +8802 -138
  74. package/dist-lib/swift-compile.mjs +8802 -138
  75. package/dist-lib/swift-package.cjs +1 -1
  76. package/dist-lib/swift-package.mjs +1 -1
  77. package/dist-lib/swift-submit.cjs +1 -1
  78. package/dist-lib/swift-submit.mjs +1 -1
  79. package/dist-lib/swift-toolchain.cjs +1 -1
  80. package/dist-lib/swift.cjs +1 -1
  81. package/dist-lib/vite-swift.cjs +8960 -134
  82. package/dist-lib/vite.cjs +149 -163
  83. package/dist-lib/worklet-executable.cjs +1 -1
  84. package/dist-lib/worklet-executable.mjs +1 -1
  85. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +1 -0
  86. package/dist-types/packages/peach-engine/src/engine/app-font-registry.d.ts +14 -0
  87. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +8 -0
  88. package/dist-types/packages/peach-engine/src/engine/node.d.ts +3 -0
  89. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +21 -0
  90. package/dist-types/packages/peach-engine/src/render-worker/gesture-seam-protocol.d.ts +2 -1
  91. package/dist-types/packages/peach-engine/src/render-worker/test-bridge-protocol.d.ts +1 -1
  92. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -0
  93. package/dist-types/packages/peach-globals/src/index.d.ts +25 -0
  94. package/kotlin/README.md +38 -23
  95. package/kotlin/sdk.tar.gz +0 -0
  96. package/package.json +2 -12
  97. package/runtime-companion.json +1 -1
  98. package/src/bundleGlobalFooter.ts +0 -2
  99. package/src/config.ts +54 -2
  100. package/src/configured-bundle-producer.ts +7 -1
  101. package/src/host/fetch-proxy-handler.ts +14 -50
  102. package/src/host/rolldown-bundle-forward.ts +71 -0
  103. package/src/installed-package-versions.ts +54 -2
  104. package/src/kotlin-host.ts +138 -285
  105. package/src/kotlin-module.ts +4 -7
  106. package/src/kotlin-sdk.ts +81 -0
  107. package/src/kotlin-toolchain.ts +152 -0
  108. package/src/kotlin-view-models.ts +1 -1
  109. package/src/kotlinSdkContract.ts +113 -0
  110. package/src/nitro-adapter.lock.json +3 -3
  111. package/src/nitro-bundle.ts +18 -4
  112. package/src/nitro-compile.ts +5 -1
  113. package/src/nitro-source.ts +112 -28
  114. package/src/nitroContract.ts +16 -4
  115. package/src/swift-compile.ts +12 -3
  116. package/src/swift-host.ts +2 -1
  117. package/src/swift-objc-compile.ts +117 -4
  118. package/src/swift-objc-sdk.ts +8792 -135
  119. package/src/swift-objc-standin.ts +1 -0
  120. package/src/vite-plugin-one.ts +73 -134
  121. package/src/worker-system-chunks.ts +14 -4
  122. package/src/xcode-project.ts +261 -34
  123. package/kotlin/AndroidViewSources/android/content/Context.kt +0 -22
  124. package/kotlin/AndroidViewSources/android/content/res/Configuration.kt +0 -25
  125. package/kotlin/AndroidViewSources/android/content/res/Resources.kt +0 -72
  126. package/kotlin/AndroidViewSources/android/graphics/Canvas.kt +0 -22
  127. package/kotlin/AndroidViewSources/android/graphics/Color.kt +0 -13
  128. package/kotlin/AndroidViewSources/android/graphics/Paint.kt +0 -18
  129. package/kotlin/AndroidViewSources/android/util/DisplayMetrics.kt +0 -12
  130. package/kotlin/AndroidViewSources/android/view/View.kt +0 -211
  131. package/kotlin/AndroidViewSources/android/widget/FrameLayout.kt +0 -61
  132. package/kotlin/AndroidViewSources/android/widget/LinearLayout.kt +0 -49
  133. package/kotlin/AndroidViewSources/dev/peach/app/JavaFormat.kt +0 -272
  134. package/kotlin/AppSources/android/app/Activity.kt +0 -174
  135. package/kotlin/AppSources/android/app/Application.kt +0 -11
  136. package/kotlin/AppSources/android/app/UiModeManager.kt +0 -9
  137. package/kotlin/AppSources/android/content/Intent.kt +0 -16
  138. package/kotlin/AppSources/android/os/Bundle.kt +0 -11
  139. package/kotlin/AppSources/android/util/SuperNotCalledException.kt +0 -3
  140. package/kotlin/AppSources/android/view/Window.kt +0 -182
  141. package/kotlin/AppSources/android/view/WindowInsets.kt +0 -9
  142. package/kotlin/AppSources/android/view/WindowInsetsController.kt +0 -17
  143. package/kotlin/AppSources/android/view/WindowManager.kt +0 -16
  144. package/kotlin/AppSources/android/window/BackEvent.kt +0 -24
  145. package/kotlin/AppSources/android/window/OnBackAnimationCallback.kt +0 -7
  146. package/kotlin/AppSources/android/window/OnBackInvokedDispatcher.kt +0 -84
  147. package/kotlin/AppSources/androidx/activity/ActivityFlags.kt +0 -9
  148. package/kotlin/AppSources/androidx/activity/ActivityViewModelLazy.kt +0 -21
  149. package/kotlin/AppSources/androidx/activity/BackEventCompat.kt +0 -43
  150. package/kotlin/AppSources/androidx/activity/ComponentActivity.kt +0 -122
  151. package/kotlin/AppSources/androidx/activity/EdgeToEdge.kt +0 -75
  152. package/kotlin/AppSources/androidx/activity/ExperimentalActivityApi.kt +0 -6
  153. package/kotlin/AppSources/androidx/activity/OnBackPressedCallback.kt +0 -69
  154. package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcher.kt +0 -144
  155. package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcherOwner.kt +0 -7
  156. package/kotlin/AppSources/androidx/activity/compose/BackHandler.kt +0 -86
  157. package/kotlin/AppSources/androidx/activity/compose/ComponentActivity.kt +0 -29
  158. package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerCompat.kt +0 -38
  159. package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerDispatcherCompat.kt +0 -27
  160. package/kotlin/AppSources/androidx/compose/foundation/layout/WindowInsets.kt +0 -15
  161. package/kotlin/AppSources/androidx/compose/ui/platform/AndroidCompositionLocals.kt +0 -27
  162. package/kotlin/AppSources/androidx/compose/ui/platform/ComposeView.kt +0 -68
  163. package/kotlin/AppSources/androidx/compose/ui/res/ColorResources.kt +0 -16
  164. package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +0 -70
  165. package/kotlin/AppSources/androidx/compose/ui/res/StringResources.kt +0 -38
  166. package/kotlin/AppSources/androidx/core/view/WindowCompat.kt +0 -32
  167. package/kotlin/AppSources/androidx/lifecycle/AndroidViewModel.kt +0 -10
  168. package/kotlin/AppSources/dev/peach/app/PeachApp.kt +0 -388
  169. package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +0 -102
  170. package/kotlin/AppSources/dev/peach/app/PeachWindowHost.kt +0 -14
  171. package/kotlin/CompilerSources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +0 -1
  172. package/kotlin/CompilerSources/PeachJniIncoming.kt +0 -243
  173. package/kotlin/CompilerSources/PeachJniPlugin.kt +0 -116
  174. package/kotlin/ComposeSources/PeachComposeHost.kt +0 -724
  175. package/kotlin/ComposeSources/PeachMagnifier.kt +0 -185
  176. package/kotlin/ComposeSources/PeachSemantics.kt +0 -127
  177. package/kotlin/ExpoComposeSources/PeachAndroidView.kt +0 -103
  178. package/kotlin/ExpoComposeSources/PeachExpoViewMount.kt +0 -24
  179. package/kotlin/ExpoComposeSources/dev/peach/expo/PeachExpoCompose.kt +0 -28
  180. package/kotlin/ExpoComposeSources/expo/modules/kotlin/views/ExpoComposeView.kt +0 -70
  181. package/kotlin/ExpoSources/dev/peach/expo/PeachExpoRuntime.kt +0 -516
  182. package/kotlin/ExpoSources/dev/peach/expo/PeachExpoTypes.kt +0 -173
  183. package/kotlin/ExpoSources/expo/modules/kotlin/AppContext.kt +0 -20
  184. package/kotlin/ExpoSources/expo/modules/kotlin/Promise.kt +0 -19
  185. package/kotlin/ExpoSources/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +0 -198
  186. package/kotlin/ExpoSources/expo/modules/kotlin/exception/CodedException.kt +0 -126
  187. package/kotlin/ExpoSources/expo/modules/kotlin/functions/Functions.kt +0 -132
  188. package/kotlin/ExpoSources/expo/modules/kotlin/jni/JavaScriptTypedArray.kt +0 -81
  189. package/kotlin/ExpoSources/expo/modules/kotlin/modules/Module.kt +0 -98
  190. package/kotlin/ExpoSources/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +0 -236
  191. package/kotlin/ExpoSources/expo/modules/kotlin/records/Record.kt +0 -12
  192. package/kotlin/ExpoSources/expo/modules/kotlin/runtime/Runtime.kt +0 -9
  193. package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObject.kt +0 -50
  194. package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +0 -57
  195. package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedRef.kt +0 -19
  196. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/ConcreteTypedArrays.kt +0 -158
  197. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/GenericTypedArray.kt +0 -8
  198. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArray.kt +0 -29
  199. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArrayIterator.kt +0 -9
  200. package/kotlin/ExpoSources/expo/modules/kotlin/types/AnyType.kt +0 -155
  201. package/kotlin/ExpoSources/expo/modules/kotlin/types/Either.kt +0 -91
  202. package/kotlin/ExpoSources/expo/modules/kotlin/types/Enumerable.kt +0 -6
  203. package/kotlin/ExpoSources/expo/modules/kotlin/viewevent/ViewEvent.kt +0 -68
  204. package/kotlin/ExpoSources/expo/modules/kotlin/views/ExpoView.kt +0 -20
  205. package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +0 -72
  206. package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewProps.kt +0 -36
  207. package/kotlin/JniPlatformSources/androidx/annotation/CallSuper.kt +0 -5
  208. package/kotlin/JniPlatformSources/com/facebook/proguard/annotations/DoNotStrip.kt +0 -5
  209. package/kotlin/JniPlatformSources/dalvik/annotation/optimization/FastNative.kt +0 -5
  210. package/kotlin/JniPlatformSources/kotlin/Synchronized.kt +0 -6
  211. package/kotlin/JniPlatformSources/kotlin/jvm/JvmField.kt +0 -5
  212. package/kotlin/JniPlatformSources/kotlin/jvm/JvmStatic.kt +0 -5
  213. package/kotlin/JniSources/com/facebook/jni/HybridData.kt +0 -66
  214. package/kotlin/JniSources/dev/peach/jni/IncomingBindings.kt +0 -157
  215. package/kotlin/JniSources/dev/peach/jni/NativeBindings.kt +0 -77
  216. package/kotlin/JniTransportSources/dev/peach/jni/integration/JniTransport.kt +0 -89
  217. package/kotlin/Sources/android/os/Build.kt +0 -17
  218. package/kotlin/Sources/android/os/Handler.kt +0 -35
  219. package/kotlin/Sources/android/os/Looper.kt +0 -17
  220. package/kotlin/Sources/android/os/MessageQueue.kt +0 -56
  221. package/kotlin/Sources/android/os/SystemClock.kt +0 -14
  222. package/kotlin/Sources/android/util/Log.kt +0 -64
  223. package/kotlin/Sources/androidx/annotation/DrawableRes.kt +0 -14
  224. package/kotlin/Sources/androidx/annotation/Keep.kt +0 -4
  225. package/kotlin/Sources/dev/onejs/one/OneNativeSourceDispatch.kt +0 -7
  226. package/kotlin/Sources/dev/onejs/one/OneNativeSourceViewDispatch.kt +0 -13
  227. package/kotlin/Sources/dev/onejs/one/source/OneModule.kt +0 -4
  228. package/kotlin/Sources/java/lang/Runnable.kt +0 -6
  229. package/kotlin/Sources/java/security/MessageDigest.kt +0 -114
  230. package/kotlin/Sources/java/util/IllegalFormatCodePointException.kt +0 -10
  231. package/kotlin/Sources/java/util/IllegalFormatException.kt +0 -5
  232. package/kotlin/Sources/kotlin/text/StringFormat.kt +0 -9
  233. package/kotlin/Sources/org/json/JSON.kt +0 -307
  234. package/kotlin/tools/abi-classes.main.kts +0 -41
  235. package/kotlin/tools/expo-types.main.kts +0 -127
@@ -1,102 +0,0 @@
1
- package dev.peach.app
2
-
3
- import androidx.compose.ui.graphics.Brush
4
- import androidx.compose.ui.graphics.Color
5
- import androidx.compose.ui.graphics.ImageBitmap
6
- import androidx.compose.ui.graphics.SolidColor
7
- import androidx.compose.ui.graphics.asComposeImageBitmap
8
- import androidx.compose.ui.graphics.vector.ImageVector
9
- import kotlin.io.encoding.Base64
10
- import kotlin.io.encoding.ExperimentalEncodingApi
11
- import org.jetbrains.skia.Bitmap as SkiaBitmap
12
- import org.jetbrains.skia.BlendMode
13
- import org.jetbrains.skia.Canvas
14
- import org.jetbrains.skia.Codec
15
- import org.jetbrains.skia.Data
16
- import org.jetbrains.skia.FilterMipmap
17
- import org.jetbrains.skia.FilterMode
18
- import org.jetbrains.skia.Image
19
- import org.jetbrains.skia.MipmapMode
20
- import org.jetbrains.skia.Paint
21
- import org.jetbrains.skia.Rect
22
-
23
- // one file a drawable resource resolves to under a density (ResTable_config's
24
- // value, 0 for an unqualified directory) and a platform version: a vector the
25
- // build translated into ImageVector.Builder calls for a day or night
26
- // configuration, a non-vector XML drawable, or an encoded bitmap
27
- internal sealed class PeachDrawable(val path: String, val density: Int, val version: Int) {
28
- class Vector(path: String, density: Int, version: Int, val build: (night: Boolean) -> ImageVector) :
29
- PeachDrawable(path, density, version)
30
- class Xml(path: String, density: Int, version: Int) : PeachDrawable(path, density, version)
31
- class Bitmap(path: String, density: Int, version: Int, val ninePatch: Boolean, val data: String) :
32
- PeachDrawable(path, density, version)
33
- }
34
-
35
- private const val DENSITY_DEFAULT = 0
36
- private const val DENSITY_MEDIUM = 160
37
- private const val DENSITY_ANY = 0xfffe
38
- private const val DENSITY_NONE = 0xffff
39
-
40
- // the file the resource table picks for the display's density, then the
41
- // highest platform version
42
- internal fun peachDrawable(files: List<PeachDrawable>, densityDpi: Int): PeachDrawable =
43
- files.reduce { best, file -> if (isBetter(file, best, densityDpi)) file else best }
44
-
45
- // ResTable_config::isBetterThan's density rule: anydpi wins, then between two
46
- // densities on one side of the request the nearer, across it the larger
47
- // unless the smaller is close enough
48
- private fun isBetter(a: PeachDrawable, b: PeachDrawable, requested: Int): Boolean {
49
- if (a.density != b.density) {
50
- val thisDensity = if (a.density == DENSITY_DEFAULT) DENSITY_MEDIUM else a.density
51
- val otherDensity = if (b.density == DENSITY_DEFAULT) DENSITY_MEDIUM else b.density
52
- if (thisDensity == DENSITY_ANY) return true
53
- if (otherDensity == DENSITY_ANY) return false
54
- var high = thisDensity
55
- var low = otherDensity
56
- var bigger = true
57
- if (low > high) {
58
- high = otherDensity
59
- low = thisDensity
60
- bigger = false
61
- }
62
- if (requested >= high) return bigger
63
- if (low >= requested) return !bigger
64
- return if ((2 * low - requested) * high > requested * requested) !bigger else bigger
65
- }
66
- return a.version > b.version
67
- }
68
-
69
- // ImageDecoder.computeDensity, which resources decode drawables through: a
70
- // bitmap drawn for a higher density than the display's is scaled down, its
71
- // size rounded, through a linear filtered draw with the source blend; one
72
- // drawn for a lower density, or nodpi, keeps its pixels, as from API 28 the
73
- // upscale is left to draw time, which BitmapPainter does not do. as
74
- // ImageDecoder does, the codec decodes into a bitmap and the scale draws into
75
- // another
76
- @OptIn(ExperimentalEncodingApi::class)
77
- internal fun peachDecodeBitmap(drawable: PeachDrawable.Bitmap, targetDensity: Int): ImageBitmap {
78
- if (drawable.ninePatch)
79
- throw UnsupportedOperationException("peach kotlin: the nine-patch drawable ${drawable.path} is not drawn yet")
80
- val decoded = Codec.makeFromData(Data.makeFromBytes(Base64.decode(drawable.data))).readPixels()
81
- val density = if (drawable.density == DENSITY_DEFAULT) DENSITY_MEDIUM else drawable.density
82
- if (drawable.density == DENSITY_NONE || density <= targetDensity) return decoded.asComposeImageBitmap()
83
- val scale = targetDensity.toFloat() / density
84
- val width = maxOf((decoded.width * scale + 0.5f).toInt(), 1)
85
- val height = maxOf((decoded.height * scale + 0.5f).toInt(), 1)
86
- val scaled = SkiaBitmap().apply { allocN32Pixels(width, height) }
87
- val canvas = Canvas(scaled)
88
- canvas.scale(width.toFloat() / decoded.width, height.toFloat() / decoded.height)
89
- canvas.drawImageRect(
90
- Image.makeFromBitmap(decoded),
91
- Rect.makeWH(decoded.width.toFloat(), decoded.height.toFloat()),
92
- Rect.makeWH(decoded.width.toFloat(), decoded.height.toFloat()),
93
- FilterMipmap(FilterMode.LINEAR, MipmapMode.NONE),
94
- Paint().apply { blendMode = BlendMode.SRC },
95
- false,
96
- )
97
- canvas.close()
98
- return scaled.asComposeImageBitmap()
99
- }
100
-
101
- // ComplexColorCompat.willDraw: a transparent solid color draws nothing
102
- internal fun peachBrush(argb: Int): Brush? = if (argb != 0) SolidColor(Color(argb)) else null
@@ -1,14 +0,0 @@
1
- package dev.peach.app
2
-
3
- import androidx.compose.ui.platform.ComposeView
4
-
5
- // the device side of a window: one Peach scene for the window's life, which
6
- // composes whichever ComposeView the window holds once that view attaches.
7
- // the composition ends when the view disposes it.
8
- internal interface PeachWindowHost {
9
- fun compose(view: ComposeView): AutoCloseable
10
-
11
- // the inset policy or status bar the window asks the device for changed
12
- // after it was added
13
- fun windowChanged()
14
- }
@@ -1,243 +0,0 @@
1
- @file:OptIn(org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI::class)
2
- package dev.peach.compiler
3
-
4
- import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
5
- import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
6
- import org.jetbrains.kotlin.codegen.JvmCodegenUtil
7
- import org.jetbrains.kotlin.descriptors.ClassKind
8
- import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
9
- import org.jetbrains.kotlin.descriptors.Modality
10
- import org.jetbrains.kotlin.ir.IrElement
11
- import org.jetbrains.kotlin.ir.builders.*
12
- import org.jetbrains.kotlin.ir.builders.declarations.*
13
- import org.jetbrains.kotlin.ir.declarations.*
14
- import org.jetbrains.kotlin.ir.expressions.*
15
- import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
16
- import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
17
- import org.jetbrains.kotlin.ir.types.*
18
- import org.jetbrains.kotlin.ir.util.*
19
- import org.jetbrains.kotlin.ir.visitors.*
20
- import org.jetbrains.kotlin.load.java.JvmAbi
21
- import org.jetbrains.kotlin.name.*
22
-
23
- internal fun jniMethodName(function: IrSimpleFunction): String {
24
- val explicit = function.getAnnotation(FqName("kotlin.jvm.JvmName"))
25
- val name = explicit?.arguments?.firstOrNull() as? org.jetbrains.kotlin.ir.expressions.IrConst
26
- if (name?.value is String) return name.value as String
27
- val property = function.correspondingPropertySymbol?.owner
28
- val base = if (property == null) function.name.asString()
29
- else if (property.getter == function) JvmAbi.getterName(property.name.asString())
30
- else JvmAbi.setterName(property.name.asString())
31
- val published = FqName("kotlin.PublishedApi")
32
- return if (function.visibility == DescriptorVisibilities.INTERNAL &&
33
- !function.hasAnnotation(published) && property?.hasAnnotation(published) != true) {
34
- base + "$" + NameUtils.sanitizeAsJavaIdentifier(JvmCodegenUtil.prepareModuleName(function.file.module.name))
35
- } else base
36
- }
37
-
38
- internal fun isJvmStatic(function: IrSimpleFunction) = function.hasAnnotation(FqName("kotlin.jvm.JvmStatic"))
39
-
40
- internal fun exposesJvmField(property: IrProperty) =
41
- property.isConst || property.backingField?.hasAnnotation(FqName("kotlin.jvm.JvmField")) == true
42
-
43
- // this plugin runs before JVM lowering, which hoists companion members into the enclosing
44
- // class and makes object properties static; native callers see that JVM layout.
45
- internal fun jniDeclaringClass(member: IrDeclaration): IrClass {
46
- val type = member.parent as IrClass
47
- val outer = type.parent as? IrClass
48
- if (!type.isCompanion || outer == null) return type
49
- val hoisted = when (member) {
50
- is IrSimpleFunction -> isJvmStatic(member)
51
- // an interface cannot hold private static fields, so only exposed ones leave its companion
52
- is IrField -> !outer.isInterface || member.correspondingPropertySymbol?.owner?.let(::exposesJvmField) == true
53
- else -> false
54
- }
55
- return if (hoisted) outer else type
56
- }
57
-
58
- internal fun jniIsStatic(member: IrDeclaration): Boolean = when (member) {
59
- is IrSimpleFunction -> member.dispatchReceiverParameter == null || isJvmStatic(member)
60
- is IrField -> member.isStatic || (member.correspondingPropertySymbol != null && (member.parent as IrClass).kind == ClassKind.OBJECT)
61
- else -> false
62
- }
63
-
64
- // thunks reference original IR declarations, including private backing fields.
65
- internal class IncomingBindings(
66
- private val context: IrPluginContext,
67
- private val classDescriptor: (IrClass) -> String,
68
- private val descriptor: (IrType, Boolean) -> String?,
69
- ) {
70
- private val builtins = context.irBuiltIns
71
- private val any = builtins.anyNType
72
- private val array = builtins.arrayClass.typeWith(any)
73
- private var serial = 0
74
- private fun runtime(name: String): IrSimpleFunctionSymbol = context.referenceFunctions(
75
- CallableId(FqName("dev.peach.jni"), Name.identifier(name)),
76
- ).single()
77
- private fun owner(type: IrClass) = classDescriptor(type).removePrefix("L").removeSuffix(";")
78
-
79
- // a signature mentioning a type with no binary name can never be formed by
80
- // a native caller, so the member is not JNI-addressable and stays unregistered
81
- private fun signature(function: IrSimpleFunction): String? {
82
- val parts = function.parameters.filter { it.kind == IrParameterKind.Regular }
83
- .map { descriptor(it.type, false) ?: return null }
84
- val result = descriptor(function.returnType, true) ?: return null
85
- return "(" + parts.joinToString("") + ")" + result
86
- }
87
-
88
- // platform Java properties can forward to their canonical method spelling.
89
- private fun forwardsToJvmMethod(function: IrSimpleFunction): Boolean {
90
- if (function.correspondingPropertySymbol?.owner?.getter != function ||
91
- function.modality != Modality.FINAL || function.annotations.isNotEmpty()) return false
92
- val expression = when (val body = function.body) {
93
- is IrExpressionBody -> body.expression
94
- is IrBlockBody -> (body.statements.singleOrNull() as? IrReturn)?.value
95
- else -> null
96
- }
97
- val call = expression as? IrCall ?: return false
98
- val target = call.symbol.owner
99
- if (target.parent != function.parent || target.correspondingPropertySymbol != null ||
100
- target.isFakeOverride || target.typeParameters.isNotEmpty() ||
101
- target.visibility != function.visibility || call.superQualifierSymbol != null ||
102
- jniMethodName(target) != jniMethodName(function) || signature(target) != signature(function) ||
103
- target.parameters.size != function.parameters.size) return false
104
- return function.parameters.indices.all { index ->
105
- (call.arguments[index] as? IrGetValue)?.symbol == function.parameters[index].symbol
106
- }
107
- }
108
-
109
- fun generate(module: IrModuleFragment) {
110
- val initialize = context.referenceFunctions(CallableId(FqName("dev.peach.jni"), Name.identifier("initializeIncomingBindings"))).singleOrNull()?.owner ?: return
111
- val classes = mutableListOf<IrClass>()
112
- module.acceptChildrenVoid(object : IrVisitorVoid() {
113
- override fun visitElement(element: IrElement) { element.acceptChildrenVoid(this) }
114
- override fun visitClass(declaration: IrClass) {
115
- if (!declaration.isExternal && declaration.classId != null &&
116
- declaration.typeParameters.isEmpty() && declaration.kind != ClassKind.ANNOTATION_CLASS &&
117
- !declaration.fqNameWhenAvailable.toString().startsWith("dev.peach.jni.")) classes += declaration
118
- declaration.acceptChildrenVoid(this)
119
- }
120
- })
121
- val registerClass = runtime("registerIncomingClass")
122
- val registerMethod = runtime("registerIncomingMethod")
123
- val registerField = runtime("registerIncomingField")
124
- initialize.body = DeclarationIrBuilder(context, initialize.symbol).irBlockBody {
125
- for (type in classes) {
126
- val file = type.file
127
- val check = thunk(file, listOf(any), builtins.booleanType) { fn -> irIs(irGet(fn.parameters[0]), type.defaultType) }
128
- +irCall(registerClass).apply {
129
- arguments[0] = irString(owner(type))
130
- arguments[1] = irVararg(builtins.stringType, type.superTypes.mapNotNull { it.classOrNull?.owner }.map { irString(owner(it)) })
131
- arguments[2] = reference(check)
132
- }
133
- for (function in type.declarations.filterIsInstance<IrSimpleFunction>() + type.declarations.filterIsInstance<IrProperty>().flatMap { listOfNotNull(it.getter, it.setter) }) {
134
- // composables need a composer no JNI caller can supply, like suspend continuations
135
- if (function.isFakeOverride || function.typeParameters.isNotEmpty() || function.isSuspend || function.hasAnnotation(FqName("androidx.compose.runtime.Composable")) || function.parameters.any { it.kind == IrParameterKind.ExtensionReceiver }) continue
136
- val property = function.correspondingPropertySymbol?.owner
137
- if (property != null && (exposesJvmField(property) ||
138
- (function.origin == IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR && function.annotations.isEmpty() && DescriptorVisibilities.isPrivate(function.visibility)))) continue
139
- if (forwardsToJvmMethod(function)) continue
140
- val parameters = function.parameters.filter { it.kind == IrParameterKind.Regular }
141
- val signature = signature(function) ?: continue
142
- val static = jniIsStatic(function)
143
- fun methodThunk(nonvirtual: Boolean) = thunk(file, listOf(any, array), any) { fn ->
144
- val call = irCall(function.symbol).apply {
145
- function.dispatchReceiverParameter?.let { receiver ->
146
- arguments[receiver.indexInParameters] = if (static) irGetObject(type.symbol) else irAs(irGet(fn.parameters[0]), type.defaultType)
147
- }
148
- parameters.forEachIndexed { index, parameter ->
149
- arguments[parameter.indexInParameters] = irAs(argument(fn, index), parameter.type)
150
- }
151
- if (nonvirtual && !static) superQualifierSymbol = type.symbol
152
- }
153
- irImplicitCast(call, any)
154
- }
155
- val virtual = methodThunk(false)
156
- val direct = if (function.modality != Modality.ABSTRACT) methodThunk(true) else null
157
- +irCall(registerMethod).apply {
158
- arguments[0] = irString(owner(jniDeclaringClass(function)))
159
- arguments[1] = irString(jniMethodName(function))
160
- arguments[2] = irString(signature)
161
- arguments[3] = irBoolean(static)
162
- arguments[4] = irInt(parameters.size)
163
- arguments[5] = reference(virtual)
164
- arguments[6] = direct?.let { reference(it) } ?: irNull(registerMethod.owner.parameters[6].type)
165
- }
166
- }
167
- if (type.modality != Modality.ABSTRACT && type.kind == ClassKind.CLASS && !type.isInner) {
168
- for (constructor in type.constructors) {
169
- val parameters = constructor.parameters.filter { it.kind == IrParameterKind.Regular }
170
- val parameterDescriptors = parameters.map { descriptor(it.type, false) }
171
- if (parameterDescriptors.any { it == null }) continue
172
- val construct = thunk(file, listOf(any, array), any) { fn ->
173
- irImplicitCast(irCallConstructor(constructor.symbol, emptyList()).apply {
174
- parameters.forEachIndexed { index, parameter ->
175
- arguments[parameter.indexInParameters] = irAs(argument(fn, index), parameter.type)
176
- }
177
- }, any)
178
- }
179
- +irCall(registerMethod).apply {
180
- arguments[0] = irString(owner(type))
181
- arguments[1] = irString("<init>")
182
- arguments[2] = irString("(" + parameterDescriptors.joinToString("") + ")V")
183
- arguments[3] = irFalse()
184
- arguments[4] = irInt(parameters.size)
185
- arguments[5] = reference(construct)
186
- arguments[6] = irNull(registerMethod.owner.parameters[6].type)
187
- }
188
- }
189
- }
190
- val fields = type.declarations.filterIsInstance<IrField>() + type.declarations.filterIsInstance<IrProperty>().mapNotNull { it.backingField }
191
- for (field in fields) {
192
- val fieldDescriptor = descriptor(field.type, false) ?: continue
193
- val static = jniIsStatic(field)
194
- fun DeclarationIrBuilder.receiver(fn: IrSimpleFunction): IrExpression? = when {
195
- field.isStatic -> null
196
- static -> irGetObject(type.symbol)
197
- else -> irAs(irGet(fn.parameters[0]), type.defaultType)
198
- }
199
- val read = thunk(file, listOf(any), any) { fn -> irImplicitCast(irGetField(receiver(fn), field), any) }
200
- val write = if (!field.isFinal) thunk(file, listOf(any, any), builtins.unitType) { fn ->
201
- irSetField(receiver(fn), field, irAs(irGet(fn.parameters[1]), field.type))
202
- } else null
203
- +irCall(registerField).apply {
204
- arguments[0] = irString(owner(jniDeclaringClass(field)))
205
- arguments[1] = irString(field.name.asString())
206
- arguments[2] = irString(fieldDescriptor)
207
- arguments[3] = irBoolean(static)
208
- arguments[4] = reference(read)
209
- arguments[5] = write?.let { reference(it) } ?: irNull(registerField.owner.parameters[5].type)
210
- }
211
- }
212
- }
213
- }
214
- }
215
-
216
- private fun thunk(file: IrFile, parameters: List<IrType>, result: IrType, body: DeclarationIrBuilder.(IrSimpleFunction) -> IrExpression): IrSimpleFunction {
217
- val fn = context.irFactory.buildFun {
218
- name = Name.identifier("peachJniIncoming${serial++}")
219
- returnType = result
220
- visibility = DescriptorVisibilities.INTERNAL
221
- }
222
- fn.parent = file
223
- parameters.forEachIndexed { index, type -> fn.addValueParameter("p$index", type) }
224
- val builder = DeclarationIrBuilder(context, fn.symbol)
225
- fn.body = builder.irBlockBody { +irReturn(builder.body(fn)) }
226
- file.declarations += fn
227
- return fn
228
- }
229
-
230
- private fun reference(fn: IrSimpleFunction): IrExpression = IrFunctionReferenceImpl(
231
- fn.startOffset, fn.endOffset,
232
- builtins.functionN(fn.parameters.size).typeWith(fn.parameters.map { it.type } + fn.returnType),
233
- fn.symbol, 0, fn.symbol,
234
- )
235
-
236
- private fun DeclarationIrBuilder.argument(fn: IrSimpleFunction, index: Int): IrExpression {
237
- val get = builtins.arrayClass.owner.functions.single { it.name.asString() == "get" }
238
- return irCall(get.symbol, any).apply {
239
- arguments[0] = irGet(fn.parameters[1])
240
- arguments[1] = irInt(index)
241
- }
242
- }
243
- }
@@ -1,116 +0,0 @@
1
- @file:OptIn(org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi::class)
2
- package dev.peach.compiler
3
-
4
- import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
5
- import org.jetbrains.kotlin.config.CompilerConfiguration
6
- import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
7
- import org.jetbrains.kotlin.fir.FirSession
8
- import org.jetbrains.kotlin.fir.declarations.*
9
- import org.jetbrains.kotlin.fir.extensions.*
10
- import org.jetbrains.kotlin.fir.expressions.builder.*
11
- import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
12
- import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
13
- import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
14
- import org.jetbrains.kotlin.name.*
15
- import org.jetbrains.kotlin.types.ConstantValueKind
16
- import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
17
- import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
18
- import org.jetbrains.kotlin.ir.declarations.*
19
- import org.jetbrains.kotlin.ir.builders.*
20
- import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
21
- import org.jetbrains.kotlin.ir.util.*
22
- import org.jetbrains.kotlin.ir.types.*
23
- import org.jetbrains.kotlin.ir.util.isNullable as isNullableType
24
- import org.jetbrains.kotlin.ir.visitors.*
25
-
26
- class Registrar : CompilerPluginRegistrar() {
27
- override val pluginId = "dev.peach.jni"
28
- override val supportsK2 = true
29
- override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
30
- FirExtensionRegistrarAdapter.registerExtension(FirRegistrar())
31
- IrGenerationExtension.registerExtension(Lower())
32
- }
33
- }
34
- class FirRegistrar : FirExtensionRegistrar() {
35
- override fun ExtensionRegistrarContext.configurePlugin() { +::NativeStatus }
36
- }
37
- class NativeStatus(session: FirSession) : FirStatusTransformerExtension(session) {
38
- override fun needTransformStatus(declaration: FirDeclaration) = declaration is FirNamedFunction && declaration.status.isExternal
39
- override fun transformStatus(status: FirDeclarationStatus, function: FirNamedFunction, containingClass: org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol<*>?, isLocal: Boolean): FirDeclarationStatus {
40
- if (containingClass == null || containingClass.rawStatus.isExternal) return status
41
- val suppression = buildAnnotation {
42
- annotationTypeRef = buildResolvedTypeRef {
43
- coneType = ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(ClassId.topLevel(FqName("kotlin.Suppress"))), emptyArray(), false)
44
- }
45
- argumentMapping = buildAnnotationArgumentMapping {
46
- mapping[Name.identifier("names")] = buildVarargArgumentsExpression {
47
- coneElementTypeOrNull = ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(ClassId.topLevel(FqName("kotlin.String"))), emptyArray(), false)
48
- coneTypeOrNull = ConeClassLikeTypeImpl(ConeClassLikeLookupTagImpl(ClassId.topLevel(FqName("kotlin.Array"))), arrayOf(coneElementTypeOrNull!!), false)
49
- for (name in listOf("NESTED_EXTERNAL_DECLARATION", "WRONG_EXTERNAL_DECLARATION", "WRONG_EXTERNAL_FUNCTION_RETURN_TYPE", "WRONG_JS_INTEROP_TYPE")) {
50
- arguments += buildLiteralExpression(null, ConstantValueKind.String, name, setType = true)
51
- }
52
- }
53
- }
54
- }
55
- function.replaceAnnotations(function.annotations + suppression)
56
- return status
57
- }
58
- }
59
- class Lower : IrGenerationExtension {
60
- override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
61
- val target by lazy { pluginContext.referenceFunctions(CallableId(FqName("dev.peach.jni"), Name.identifier("invoke"))).single() }
62
- moduleFragment.acceptChildrenVoid(object: IrVisitorVoid() {
63
- override fun visitElement(element: org.jetbrains.kotlin.ir.IrElement) { element.acceptChildrenVoid(this) }
64
- override fun visitSimpleFunction(declaration: IrSimpleFunction) {
65
- val receiver = declaration.dispatchReceiverParameter
66
- if (!declaration.isExternal || receiver == null) return
67
- if ((declaration.parent as? IrClass)?.isExternal == true) return
68
- check(declaration.body == null) { "JNI native member cannot have a Kotlin body" }
69
- check(declaration.typeParameters.isEmpty()) { "JNI native type parameters require explicit erasure" }
70
- val parameters = declaration.parameters.filter { it.kind == IrParameterKind.Regular }
71
- val owner = classDescriptor(jniDeclaringClass(declaration)).removePrefix("L").removeSuffix(";")
72
- val signature = "(" + parameters.joinToString("") { descriptor(it.type) } + ")" + descriptor(declaration.returnType, true)
73
- declaration.isExternal = false
74
- declaration.body = DeclarationIrBuilder(pluginContext, declaration.symbol).irBlockBody {
75
- val call = irCall(target).apply {
76
- arguments[0] = if (isJvmStatic(declaration)) irNull(pluginContext.irBuiltIns.anyNType) else irGet(receiver)
77
- arguments[1] = irString(owner)
78
- arguments[2] = irString(jniMethodName(declaration))
79
- arguments[3] = irString(signature)
80
- arguments[4] = irVararg(pluginContext.irBuiltIns.anyNType, parameters.map { irImplicitCast(irGet(it), pluginContext.irBuiltIns.anyNType) })
81
- }
82
- if (declaration.returnType == pluginContext.irBuiltIns.unitType) +call
83
- else +irReturn(irAs(call, declaration.returnType))
84
- }
85
- }
86
- })
87
- IncomingBindings(pluginContext, ::classDescriptor, ::descriptorOrNull).generate(moduleFragment)
88
- }
89
- private fun classDescriptor(type: IrClass): String =
90
- classDescriptorOrNull(type) ?: error("JNI native declarations require a named class: ${type.name} in ${type.file.name}")
91
- // anonymous and local classes have no binary name a native caller can spell,
92
- // so members typed by them have no JNI descriptor at all
93
- private fun classDescriptorOrNull(type: IrClass): String? {
94
- val kotlinId = type.classId ?: return null
95
- val id = JavaToKotlinClassMap.mapKotlinToJava(kotlinId.asSingleFqName().toUnsafe()) ?: kotlinId
96
- val pkg = id.packageFqName.asString().replace('.', '/')
97
- return "L" + (if (pkg.isEmpty()) "" else "$pkg/") + id.relativeClassName.asString().replace('.', '$') + ";"
98
- }
99
- private fun descriptor(type: IrType, result: Boolean = false): String =
100
- descriptorOrNull(type, result) ?: error("JNI native type has no JNI descriptor: $type")
101
- private fun descriptorOrNull(type: IrType, result: Boolean = false): String? {
102
- val name = type.classFqName?.asString() ?: return null
103
- if (!type.isNullableType()) {
104
- val primitive = mapOf("kotlin.Boolean" to "Z", "kotlin.Byte" to "B", "kotlin.Char" to "C", "kotlin.Short" to "S", "kotlin.Int" to "I", "kotlin.Long" to "J", "kotlin.Float" to "F", "kotlin.Double" to "D")
105
- primitive[name]?.let { return it }
106
- if (result && name == "kotlin.Unit") return "V"
107
- }
108
- val arrays = mapOf("kotlin.BooleanArray" to "Z", "kotlin.ByteArray" to "B", "kotlin.CharArray" to "C", "kotlin.ShortArray" to "S", "kotlin.IntArray" to "I", "kotlin.LongArray" to "J", "kotlin.FloatArray" to "F", "kotlin.DoubleArray" to "D")
109
- arrays[name]?.let { return "[$it" }
110
- if (name == "kotlin.Array") {
111
- val element = (type as IrSimpleType).arguments.single() as? IrTypeProjection ?: return null
112
- return descriptorOrNull(element.type.makeNullable())?.let { "[$it" }
113
- }
114
- return type.classOrNull?.owner?.let { classDescriptorOrNull(it) }
115
- }
116
- }