@bake-native/core 0.0.0 → 0.1.0-rc.0

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 (143) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD_PARTY_NOTICES.txt +548 -0
  3. package/bake-prelude.js +189 -0
  4. package/batch-contract.json +21 -0
  5. package/batch-wire.js +674 -0
  6. package/compat.json +64 -0
  7. package/controls.css +108 -0
  8. package/determinism.js +175 -0
  9. package/devtools.d.ts +13 -0
  10. package/devtools.js +73 -0
  11. package/dialogs.js +59 -0
  12. package/direct-style.js +105 -0
  13. package/direct-table.js +261 -0
  14. package/dist/bake.mjs +2211 -0
  15. package/dist/build-CMsvCcZ0.mjs +1 -0
  16. package/dist/build-CkLSZw06.mjs +5514 -0
  17. package/dist/build-tools-Dxyl6XAf.mjs +80 -0
  18. package/dist/client-Cm7o6dQd.mjs +17544 -0
  19. package/dist/compiler.mjs +4 -0
  20. package/dist/config-B1W8gfZY.mjs +12 -0
  21. package/dist/dev-Cskd8Hl4.mjs +986 -0
  22. package/dist/direct-report-Bdda-k_Y.mjs +153 -0
  23. package/dist/direct-report-Du44nNWl.mjs +1 -0
  24. package/dist/index.d.mts +176 -0
  25. package/dist/index.mjs +1 -0
  26. package/dist/intl-ROnAp2qO.mjs +75 -0
  27. package/dist/jiti-stub-CKcaShwE.mjs +5 -0
  28. package/dist/native-views-BuzB9x5H.mjs +7849 -0
  29. package/dist/octane/package.json +5 -0
  30. package/dist/package-KkUSMoji.mjs +2784 -0
  31. package/dist/react/package.json +13 -0
  32. package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
  33. package/dist/run-D2aPm54a.mjs +6632 -0
  34. package/dist/scope-8W2aIuQ9.mjs +262 -0
  35. package/dist/screens/BakeNativeScreen.native.ts +9 -0
  36. package/dist/screens/package.json +5 -0
  37. package/dom-exception.js +31 -0
  38. package/element-api.js +158 -0
  39. package/first-screen.js +30 -0
  40. package/fonts/Geist-Italic-Variable.ttf +0 -0
  41. package/fonts/Geist-Variable.ttf +0 -0
  42. package/fonts/GeistMono-Italic-Variable.ttf +0 -0
  43. package/fonts/GeistMono-Variable.ttf +0 -0
  44. package/fonts/OFL.txt +93 -0
  45. package/fonts/README.md +27 -0
  46. package/fonts/geist-italic.css +8 -0
  47. package/fonts/geist-mono-italic.css +8 -0
  48. package/fonts/geist-mono.css +8 -0
  49. package/fonts/geist.css +8 -0
  50. package/header-icons.json +53 -0
  51. package/host-runtime.js +508 -0
  52. package/image-props.js +17 -0
  53. package/index.d.ts +8 -0
  54. package/index.js +7 -0
  55. package/licenses/Apache-2.0.txt +73 -0
  56. package/locale-entry.d.ts +1 -0
  57. package/locale-entry.js +1 -0
  58. package/locale.d.ts +28 -0
  59. package/locale.js +124 -0
  60. package/markup-support.js +87 -0
  61. package/media-element.js +115 -0
  62. package/native-args-entry.js +2 -0
  63. package/native-args.d.ts +7 -0
  64. package/native-args.js +155 -0
  65. package/native-entry.js +1 -0
  66. package/native-globals.d.ts +156 -0
  67. package/native-scenarios.d.ts +17 -0
  68. package/native-scenarios.js +46 -0
  69. package/native-support.json +349 -0
  70. package/native.d.ts +52 -0
  71. package/native.js +237 -0
  72. package/package.json +142 -4
  73. package/page-elements.js +123 -0
  74. package/runtime-provides.json +412 -0
  75. package/safe-area.d.ts +1 -0
  76. package/safe-area.js +44 -0
  77. package/swift-ui/modifiers.js +164 -0
  78. package/tab-icons.js +62 -0
  79. package/templates/create/tabs/AGENTS.md +22 -0
  80. package/templates/create/tabs/README.md +43 -0
  81. package/templates/create/tabs/_gitignore +13 -0
  82. package/templates/create/tabs/android/app/build.gradle.kts +79 -0
  83. package/templates/create/tabs/android/app/src/main/AndroidManifest.xml +39 -0
  84. package/templates/create/tabs/android/app/src/main/kotlin/MainActivity.kt +35 -0
  85. package/templates/create/tabs/android/app/src/main/res/values/themes.xml +8 -0
  86. package/templates/create/tabs/android/build.gradle.kts +5 -0
  87. package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  88. package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.properties +9 -0
  89. package/templates/create/tabs/android/gradle.properties +3 -0
  90. package/templates/create/tabs/android/gradlew +248 -0
  91. package/templates/create/tabs/android/settings.gradle.kts +47 -0
  92. package/templates/create/tabs/bake.config.ts +10 -0
  93. package/templates/create/tabs/ios/App/App.swift +30 -0
  94. package/templates/create/tabs/ios/build.sh +23 -0
  95. package/templates/create/tabs/ios/project.yml +57 -0
  96. package/templates/create/tabs/macos/Package.swift +24 -0
  97. package/templates/create/tabs/macos/Sources/__SWIFT_NAME__/App.swift +146 -0
  98. package/templates/create/tabs/macos/build.sh +4 -0
  99. package/templates/create/tabs/package.json +23 -0
  100. package/templates/create/tabs/pnpm-workspace.yaml +6 -0
  101. package/templates/create/tabs/src/App.tsrx +92 -0
  102. package/templates/create/tabs/src/App.tsx +67 -0
  103. package/templates/create/tabs/src/styles.css +32 -0
  104. package/templates/create/tabs/tsconfig.json +5 -0
  105. package/templates/create/tabs/windows/Cargo.toml +29 -0
  106. package/templates/create/tabs/windows/build.rs +9 -0
  107. package/templates/create/tabs/windows/src/main.rs +52 -0
  108. package/templates/create/tabs/windows/src/shell.rs +316 -0
  109. package/templates/module/__NAME__.kt +20 -0
  110. package/templates/module/__NAME__.native.ts +24 -0
  111. package/templates/module/__NAME__.swift +25 -0
  112. package/templates/module/__NAME__.web.ts +13 -0
  113. package/templates/module/__NAME__Test.kt +26 -0
  114. package/templates/module/__NAME__Tests.swift +25 -0
  115. package/templates/module/__SNAKE__.rs +43 -0
  116. package/text.d.ts +20 -0
  117. package/text.js +100 -0
  118. package/transform-entry.js +1 -0
  119. package/transform.d.ts +15 -0
  120. package/transform.js +98 -0
  121. package/tsconfig.native.json +16 -0
  122. package/ui/scope.js +103 -0
  123. package/ui/swift.js +106 -0
  124. package/ui/ui.css +272 -0
  125. package/view-ref-writer.js +268 -0
  126. package/view-ref.d.ts +26 -0
  127. package/view-ref.js +85 -0
  128. package/views/Video.native.ts +68 -0
  129. package/views/generated/VideoViewAndroid.h +68 -0
  130. package/views/generated/VideoViewJSI.h +94 -0
  131. package/views/generated/VideoViewSpec.kt +113 -0
  132. package/views/generated/apple/VideoViewJSI/VideoViewJSIApple.cpp +40 -0
  133. package/views/generated/apple/VideoViewJSI/include/VideoViewJSIApple.h +28 -0
  134. package/views/generated/apple/VideoViewSpec/VideoViewInterop.swift +39 -0
  135. package/views/generated/apple/VideoViewSpec/VideoViewSpec.swift +186 -0
  136. package/views/generated/video_view_spec.rs +189 -0
  137. package/views.d.ts +24 -0
  138. package/views.js +45 -0
  139. package/virtual-window.js +35 -0
  140. package/visibility.js +75 -0
  141. package/web-crypto.js +84 -0
  142. package/web-fetch.js +1071 -0
  143. package/README.md +0 -3
package/tab-icons.js ADDED
@@ -0,0 +1,62 @@
1
+ // The tab bar icon table and tab helpers, shared by the platform tab bar (ui/native-tab-bar.tsrx) and the CSS tab bar
2
+ // of @bake-native/octane/ui (ui/tab-bar.tsrx). Plain JS: importing it brings no element plan into a bundle.
3
+
4
+ // Icons every target can draw: an SF Symbol (iOS, macOS) and Material Symbols geometry
5
+ // (24x24 SVG path, Android and web), outline when idle and filled when selected, as the platform
6
+ // tab bars do. Name one (`icon: 'home'`) or bring your own (`icon: { sf, path }`).
7
+ const MD = {
8
+ home: 'M12 5.69l5 4.5V18h-2v-6H9v6H7v-7.81l5-4.5M12 3L2 12h3v8h6v-6h2v6h6v-8h3L12 3z',
9
+ homeFill: 'M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z',
10
+ search: 'M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z',
11
+ person: 'M12 6c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2m0 10c2.7 0 5.8 1.29 6 2H6c.23-.72 3.31-2 6-2m0-12C9.79 4 8 5.79 8 8s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4zm0 10c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z',
12
+ personFill: 'M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z',
13
+ settings: 'M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z',
14
+ bell: 'M16 17H8v-6c0-2.48 1.51-4.5 4-4.5s4 2.02 4 4.5v6zm2-1v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2zm-6 6c1.1 0 2-.9 2-2h-4c0 1.1.89 2 2 2z',
15
+ bellFill: 'M12 22c1.1 0 2-.9 2-2h-4c0 1.1.89 2 2 2zm6-6v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2z',
16
+ heart: 'M16.5 3c-1.74 0-3.41.81-4.5 2.09C10.91 3.81 9.24 3 7.5 3 4.42 3 2 5.42 2 8.5c0 3.78 3.4 6.86 8.55 11.54L12 21.35l1.45-1.32C18.6 15.36 22 12.28 22 8.5 22 5.42 19.58 3 16.5 3zm-4.4 15.55l-.1.1-.1-.1C7.14 14.24 4 11.39 4 8.5 4 6.5 5.5 5 7.5 5c1.54 0 3.04.99 3.57 2.36h1.87C13.46 5.99 14.96 5 16.5 5c2 0 3.5 1.5 3.5 3.5 0 2.89-3.14 5.74-7.9 10.05z',
17
+ heartFill: 'M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z',
18
+ star: 'M22 9.24l-7.19-.62L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21 12 17.27 18.18 21l-1.63-7.03L22 9.24zM12 15.4l-3.76 2.27 1-4.28-3.32-2.88 4.38-.38L12 6.1l1.71 4.04 4.38.38-3.32 2.88 1 4.28L12 15.4z',
19
+ starFill: 'M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z',
20
+ list: 'M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z',
21
+ chart: 'M5 9.2h3V19H5zM10.6 5h2.8v14h-2.8zm5.6 8H19v6h-2.8z',
22
+ chat: 'M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z',
23
+ chatFill: 'M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z',
24
+ inbox: 'M19 3H4.99c-1.11 0-1.98.89-1.98 2L3 19c0 1.1.88 2 1.99 2H19c1.1 0 2-.9 2-2V5c0-1.11-.9-2-2-2zm0 12h-4c0 1.66-1.35 3-3 3s-3-1.34-3-3H4.99V5H19v10z',
25
+ grid: 'M3 3v8h8V3H3zm6 6H5V5h4v4zm-6 4v8h8v-8H3zm6 6H5v-4h4v4zm4-16v8h8V3h-8zm6 6h-4V5h4v4zm-6 4v8h8v-8h-8zm6 6h-4v-4h4v4z',
26
+ gridFill: 'M3 3h8v8H3zm10 0h8v8h-8zM3 13h8v8H3zm10 0h8v8h-8z',
27
+ box: 'M20 2H4c-1 0-2 .9-2 2v3.01c0 .72.43 1.34 1 1.69V20c0 1.1 1.1 2 2 2h14c.9 0 2-.9 2-2V8.7c.57-.35 1-.97 1-1.69V4c0-1.1-1-2-2-2zm-5 12H9v-2h6v2zm5-7H4V4l16-.02V7z',
28
+ bag: 'M19 6h-2c0-2.76-2.24-5-5-5S7 3.24 7 6H5c-1.1 0-1.99.9-1.99 2L3 20c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm-7-3c1.66 0 3 1.34 3 3H9c0-1.66 1.34-3 3-3zm0 10c-2.76 0-5-2.24-5-5h2c0 1.66 1.34 3 3 3s3-1.34 3-3h2c0 2.76-2.24 5-5 5z',
29
+ };
30
+
31
+ /** The icon names `TabBar` tabs take: SF Symbol (idle, selected) and Material path (idle, selected). */
32
+ export const TAB_ICONS = {
33
+ home: ['house', 'house.fill', MD.home, MD.homeFill],
34
+ search: ['magnifyingglass', 'magnifyingglass', MD.search, MD.search],
35
+ person: ['person', 'person.fill', MD.person, MD.personFill],
36
+ settings: ['gearshape', 'gearshape.fill', MD.settings, MD.settings],
37
+ bell: ['bell', 'bell.fill', MD.bell, MD.bellFill],
38
+ heart: ['heart', 'heart.fill', MD.heart, MD.heartFill],
39
+ star: ['star', 'star.fill', MD.star, MD.starFill],
40
+ list: ['list.bullet', 'list.bullet', MD.list, MD.list],
41
+ chart: ['chart.bar', 'chart.bar.fill', MD.chart, MD.chart],
42
+ chat: ['bubble.left', 'bubble.left.fill', MD.chat, MD.chatFill],
43
+ inbox: ['tray', 'tray.fill', MD.inbox, MD.inbox],
44
+ grid: ['square.grid.2x2', 'square.grid.2x2.fill', MD.grid, MD.gridFill],
45
+ box: ['shippingbox', 'shippingbox.fill', MD.box, MD.box],
46
+ bag: ['bag', 'bag.fill', MD.bag, MD.bag],
47
+ };
48
+
49
+ // `icon` (a TAB_ICONS name or { sf, path }) or `systemImage` (an SF Symbol name; one of the
50
+ // table's gets its Material path too, any other shows only on Apple targets).
51
+ export function tabIcon(t) {
52
+ const icon = t.icon ?? t.systemImage;
53
+ if (icon == null) return {};
54
+ if (typeof icon === 'string') {
55
+ const row = TAB_ICONS[icon] ?? Object.values(TAB_ICONS).find((r) => r[0] === icon || r[1] === icon);
56
+ if (row) return { systemImage: icon === row[1] ? row[1] : row[0], selectedSystemImage: row[1], iconPath: row[2], selectedIconPath: row[3] };
57
+ if (t.icon != null) throw new Error(`TabBar: unknown icon '${icon}' (one of ${Object.keys(TAB_ICONS).join(', ')}, or { sf, path })`);
58
+ return { systemImage: icon };
59
+ }
60
+ return { systemImage: icon.sf, selectedSystemImage: icon.sfSelected, iconPath: icon.path, selectedIconPath: icon.pathSelected };
61
+ }
62
+ export const tabLabel = (t) => t.label ?? t.title ?? t.id;
@@ -0,0 +1,22 @@
1
+ # Agent notes
2
+
3
+ This app uses __RENDERER_NAME__. The UI lives in `__APP_ENTRY__` and `src/styles.css`.
4
+
5
+ - The app targets __TARGET_LIST__ (`targets` in `bake.config.ts`). Use
6
+ `pnpm exec bake check --target <target>` to check without writing a bundle. Use the target's
7
+ build command in the README. Native builds reject unsupported elements, attributes, globals,
8
+ and CSS with the reason and a supported alternative.
9
+ - Keep code that only one target can run behind `import.meta.env.BAKE_TARGET` (`'web'`, `'ios'`,
10
+ `'mac'`, `'android'`, `'windows'`), decided at module level so the other targets' bundles do
11
+ not contain it (see `TabBar` in `__APP_ENTRY__`).
12
+ - Render the first screen from deterministic props and state. Read time and live data in events
13
+ or effects. Use stable keys for lists.
14
+ - Do not call native functions during render: the build-time snapshot bake has no native
15
+ modules.
16
+ - Native modules live in `native/<name>/`: a spec (`<Name>.native.ts`) and one implementation
17
+ per target (`.swift`, `.kt`, `.rs`, `.web.ts`). Get one from the registry with
18
+ `pnpm exec bake add <name>` (recorded in `bake-modules.json`; `bake diff` / `bake upgrade` merge
19
+ registry updates). Write a new one with `pnpm exec bake native new <Name> --spec`: spec first,
20
+ then each implementation, then `pnpm exec bake check`. Never edit `.bake/`: it is generated.
21
+ - `__RENDERER_PACKAGE__` supplies the renderer. The app supplies its `__RENDERER__` runtime and Vite.
22
+ __HOSTS_BULLET__
@@ -0,0 +1,43 @@
1
+ # __TITLE__
2
+
3
+ A [BakeNative](https://bake-native.com) app: one __RENDERER_NAME__ component (`__APP_ENTRY__`) with a native tab
4
+ bar, built for __TARGET_NAMES__ (`bake.config.ts`).
5
+
6
+ __BAKENATIVE_NOTE__
7
+
8
+ __HOSTS_NOTE__
9
+
10
+ __SCREENS_NOTE__
11
+
12
+ ## Build
13
+
14
+ ```sh
15
+ pnpm install
16
+ ```
17
+
18
+ `bake.config.ts` lists the targets the app ships on. `bake build`, `bake check` and `bake dev` use
19
+ them when `--target` is not given, and refuse a target that is not listed. Add one there (and
20
+ its host folder, from `bake create`) to ship on another platform. Run
21
+ `pnpm exec bake check --target <target>` to check a target without writing a bundle.
22
+
23
+ Use the build command for your target. For native build tools and host requirements, see the
24
+ [installation guide](https://bake-native.com/docs/installation).
25
+
26
+ | Target | Command | Then |
27
+ | --- | --- | --- |
28
+ __TARGET_ROWS__
29
+
30
+ `--bake` writes the first-screen snapshot (`app.baked`): the native hosts show it before any
31
+ JavaScript runs.
32
+
33
+ Render the first screen from deterministic props and state. Read live values such as the clock
34
+ or native data in event handlers or effects. A native build must produce a valid first frame.
35
+
36
+ ## Layout
37
+
38
+ ```text
39
+ bake.config.ts the targets the app ships on
40
+ __APP_ENTRY__ the app: Header, TabBar (__RENDERER_PACKAGE__/ui) and three tab pages
41
+ src/styles.css the stylesheet every target uses
42
+ __HOST_LAYOUT__
43
+ ```
@@ -0,0 +1,13 @@
1
+ node_modules/
2
+ dist/
3
+ .bake/
4
+ ios/App/Bundle/
5
+ ios/App/BakeNativeBrand.xcassets/
6
+ ios/*.xcodeproj/
7
+ macos/.build/
8
+ macos/Sources/*/Bundle/
9
+ android/.gradle/
10
+ android/build/
11
+ android/app/build/
12
+ android/local.properties
13
+ windows/target/
@@ -0,0 +1,79 @@
1
+ import java.util.Properties
2
+
3
+ plugins {
4
+ alias(libs.plugins.android.application)
5
+ }
6
+
7
+ // The baked bundle (`pnpm build:android` in the project root: dist/android) goes into the APK's
8
+ // assets as bakenative/app/{app.hbc, app.baked, app.css, manifest.json} with its images (assets/) and
9
+ // @font-face files (fonts/) and third-party notices (THIRD_PARTY_NOTICES.txt / .json).
10
+ val bundleDir = rootDir.resolve("../dist/android")
11
+ val nativeAppDir = bundleDir.resolve("native-app")
12
+ val appBranding = Properties().apply {
13
+ providers.fileContents(layout.projectDirectory.file(nativeAppDir.resolve("app.properties").canonicalPath))
14
+ .asText.orNull?.reader()?.use { load(it) }
15
+ }
16
+ val bundleAssets = layout.buildDirectory.dir("generated/bakenative-assets")
17
+ // The first-party modules the bundle uses (generated by `pnpm build:android` too:
18
+ // ../.bake/native/android, included by settings.gradle.kts once it exists).
19
+ val appModules = findProject(":bakenative-app-modules")
20
+ // The app's minSdk: android.minSdk in bake.config.ts, which `pnpm build:android` writes to
21
+ // ../.bake/native/android/min-sdk (29, the BakeNative host's minimum, before the first build).
22
+ val bakeMinSdk = providers.fileContents(layout.projectDirectory.file(rootDir.resolve("../.bake/native/android/min-sdk").canonicalPath))
23
+ .asText.map { it.trim().toInt() }.getOrElse(29)
24
+ val copyBundle = tasks.register<Sync>("copyBakeNativeBundle") {
25
+ // Local values, not the script's: the configuration cache cannot store a reference to the
26
+ // build script object.
27
+ val hbc = bundleDir.resolve("app.hbc")
28
+ val linked = appModules != null
29
+ doFirst {
30
+ check(hbc.isFile) { "$hbc is missing: run `pnpm build:android` in the project root" }
31
+ // Without the registration the APK would have none of the modules the bundle calls
32
+ // (E_UNKNOWN_MODULE at run time).
33
+ check(linked) { "../.bake/native/android is missing: run `pnpm build:android` in the project root, then build again" }
34
+ }
35
+ from(bundleDir) {
36
+ include("app.hbc", "*.baked", "app.css", "manifest.json", "assets/**", "fonts/**", "THIRD_PARTY_NOTICES.*")
37
+ into("bakenative/app")
38
+ }
39
+ into(bundleAssets)
40
+ }
41
+
42
+ android {
43
+ namespace = "__APP_ID__"
44
+ compileSdk = 37
45
+
46
+ defaultConfig {
47
+ applicationId = appBranding.getProperty("appId", "__APP_ID__")
48
+ manifestPlaceholders["bakeNativeName"] = appBranding.getProperty("name", "__TITLE__")
49
+ manifestPlaceholders["bakeNativeIcon"] = appBranding.getProperty("icon", "@android:mipmap/sym_def_app_icon")
50
+ manifestPlaceholders["bakeNativeTheme"] = appBranding.getProperty("theme", "@style/Theme.App")
51
+ minSdk = bakeMinSdk
52
+ targetSdk = 36
53
+ versionCode = 1
54
+ versionName = "0.1.0"
55
+ // The ABIs libbakenative.so and Hermes were built for (build-rust.sh BAKE_ANDROID_ABIS): arm64-v8a
56
+ // (devices, Apple Silicon emulators) unless -Pbakenative.abis=x86_64 (an x86_64 emulator).
57
+ ndk {
58
+ abiFilters += providers.gradleProperty("bakenative.abis").orElse("arm64-v8a").get()
59
+ .split(',').map { it.trim() }.filter { it.isNotEmpty() }
60
+ }
61
+ }
62
+
63
+ sourceSets.getByName("main").res.srcDir(nativeAppDir.resolve("res"))
64
+ sourceSets.getByName("main").assets.directories += bundleAssets.get().asFile.path
65
+
66
+ packaging {
67
+ // Hermes and the core are loaded from the APK, page-aligned and uncompressed.
68
+ jniLibs.useLegacyPackaging = false
69
+ }
70
+ }
71
+
72
+ tasks.named("preBuild") { dependsOn(copyBundle) }
73
+
74
+ dependencies {
75
+ implementation(project(":bakenative"))
76
+ // The modules the bundle uses and BakeNativeBundleModules.root(), which MainActivity registers.
77
+ appModules?.let { implementation(it) }
78
+ implementation(libs.androidx.activity.compose)
79
+ }
@@ -0,0 +1,39 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <!-- The schemes Linking.canOpenURL asks about (Android 11+ package visibility): add the ones
4
+ the app checks. -->
5
+ <queries>
6
+ <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="https" /></intent>
7
+ <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="http" /></intent>
8
+ <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="mailto" /></intent>
9
+ <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="tel" /></intent>
10
+ <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="sms" /></intent>
11
+ <intent><action android:name="android.intent.action.VIEW" /><data android:scheme="geo" /></intent>
12
+ </queries>
13
+ <application
14
+ android:label="${bakeNativeName}"
15
+ android:icon="${bakeNativeIcon}"
16
+ android:theme="${bakeNativeTheme}">
17
+ <!-- The BakeNativeView follows dark mode, font scale, size and rotation itself: the Activity
18
+ is not recreated for them (configChanges), so the screen never reloads. -->
19
+ <activity
20
+ android:name="__APP_ID__.MainActivity"
21
+ android:exported="true"
22
+ android:launchMode="singleTask"
23
+ android:configChanges="uiMode|fontScale|orientation|screenSize|screenLayout|smallestScreenSize|density|keyboardHidden|keyboard"
24
+ android:windowSoftInputMode="adjustResize">
25
+ <intent-filter>
26
+ <action android:name="android.intent.action.MAIN" />
27
+ <category android:name="android.intent.category.LAUNCHER" />
28
+ </intent-filter>
29
+ <!-- Deep links: __NAME__://… starts the app (Linking.getInitialURL) or, while it runs,
30
+ reaches JS as the host event url (onNewIntent). -->
31
+ <intent-filter>
32
+ <action android:name="android.intent.action.VIEW" />
33
+ <category android:name="android.intent.category.DEFAULT" />
34
+ <category android:name="android.intent.category.BROWSABLE" />
35
+ <data android:scheme="__NAME__" />
36
+ </intent-filter>
37
+ </activity>
38
+ </application>
39
+ </manifest>
@@ -0,0 +1,35 @@
1
+ package __APP_ID__
2
+
3
+ import android.content.Intent
4
+ import android.os.Bundle
5
+ import androidx.activity.ComponentActivity
6
+ import dev.bakenative.BakeNativeBundle
7
+ import dev.bakenative.BakeNativeView
8
+ import dev.bakenative.generated.BakeNativeBundleModules
9
+ import org.json.JSONObject
10
+
11
+ /**
12
+ * The whole app: a [BakeNativeView] running the __RENDERER_NAME__ app (__APP_ENTRY__) in the window. A
13
+ * [ComponentActivity] (it provides the ViewTreeLifecycleOwner the view's Compose controls need).
14
+ * Header and TabBar (__RENDERER_PACKAGE__/ui) draw the Material top bar and navigation bar.
15
+ */
16
+ class MainActivity : ComponentActivity() {
17
+ private lateinit var view: BakeNativeView
18
+
19
+ override fun onCreate(savedInstanceState: Bundle?) {
20
+ super.onCreate(savedInstanceState)
21
+ window.setDecorFitsSystemWindows(false)
22
+ view = BakeNativeView(this)
23
+ view.modules.registerAll(BakeNativeBundleModules.root())
24
+ setContentView(view)
25
+ view.load(BakeNativeBundle.Asset("bakenative/app"))
26
+ }
27
+
28
+ /** A deep link while the app runs (launchMode singleTask): JS gets it as the host event `url`. */
29
+ override fun onNewIntent(intent: Intent) {
30
+ super.onNewIntent(intent)
31
+ setIntent(intent)
32
+ val url = intent.dataString
33
+ if (intent.action == Intent.ACTION_VIEW && url != null) view.send("url", JSONObject.quote(url))
34
+ }
35
+ }
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <!-- Day/night window background (no flash of the wrong color before the first frame). -->
4
+ <style name="Theme.App" parent="@android:style/Theme.DeviceDefault.DayNight">
5
+ <item name="android:windowActionBar">false</item>
6
+ <item name="android:windowNoTitle">true</item>
7
+ </style>
8
+ </resources>
@@ -0,0 +1,5 @@
1
+ plugins {
2
+ alias(libs.plugins.android.application) apply false
3
+ alias(libs.plugins.android.library) apply false
4
+ alias(libs.plugins.kotlin.compose) apply false
5
+ }
@@ -0,0 +1,9 @@
1
+ distributionBase=GRADLE_USER_HOME
2
+ distributionPath=wrapper/dists
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip
4
+ networkTimeout=10000
5
+ retries=0
6
+ retryBackOffMs=500
7
+ validateDistributionUrl=true
8
+ zipStoreBase=GRADLE_USER_HOME
9
+ zipStorePath=wrapper/dists
@@ -0,0 +1,3 @@
1
+ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
2
+ org.gradle.configuration-cache=true
3
+ android.useAndroidX=true
@@ -0,0 +1,248 @@
1
+ #!/bin/sh
2
+
3
+ #
4
+ # Copyright © 2015 the original authors.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # https://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ # SPDX-License-Identifier: Apache-2.0
19
+ #
20
+
21
+ ##############################################################################
22
+ #
23
+ # gradlew start up script for POSIX generated by Gradle.
24
+ #
25
+ # Important for running:
26
+ #
27
+ # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28
+ # noncompliant, but you have some other compliant shell such as ksh or
29
+ # bash, then to run this script, type that shell name before the whole
30
+ # command line, like:
31
+ #
32
+ # ksh gradlew
33
+ #
34
+ # Busybox and similar reduced shells will NOT work, because this script
35
+ # requires all of these POSIX shell features:
36
+ # * functions;
37
+ # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38
+ # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39
+ # * compound commands having a testable exit status, especially «case»;
40
+ # * various built-in commands including «command», «set», and «ulimit».
41
+ #
42
+ # Important for patching:
43
+ #
44
+ # (2) This script targets any POSIX shell, so it avoids extensions provided
45
+ # by Bash, Ksh, etc; in particular arrays are avoided.
46
+ #
47
+ # The "traditional" practice of packing multiple parameters into a
48
+ # space-separated string is a well documented source of bugs and security
49
+ # problems, so this is (mostly) avoided, by progressively accumulating
50
+ # options in "$@", and eventually passing that to Java.
51
+ #
52
+ # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53
+ # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54
+ # see the in-line comments for details.
55
+ #
56
+ # There are tweaks for specific operating systems such as AIX, CygWin,
57
+ # Darwin, MinGW, and NonStop.
58
+ #
59
+ # (3) This script is generated from the Groovy template
60
+ # https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61
+ # within the Gradle project.
62
+ #
63
+ # You can find Gradle at https://github.com/gradle/gradle/.
64
+ #
65
+ ##############################################################################
66
+
67
+ # Attempt to set APP_HOME
68
+
69
+ # Resolve links: $0 may be a link
70
+ app_path=$0
71
+
72
+ # Need this for daisy-chained symlinks.
73
+ while
74
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75
+ [ -h "$app_path" ]
76
+ do
77
+ ls=$( ls -ld "$app_path" )
78
+ link=${ls#*' -> '}
79
+ case $link in #(
80
+ /*) app_path=$link ;; #(
81
+ *) app_path=$APP_HOME$link ;;
82
+ esac
83
+ done
84
+
85
+ # This is normally unused
86
+ # shellcheck disable=SC2034
87
+ APP_BASE_NAME=${0##*/}
88
+ # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89
+ APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90
+
91
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
92
+ MAX_FD=maximum
93
+
94
+ warn () {
95
+ echo "$*"
96
+ } >&2
97
+
98
+ die () {
99
+ echo
100
+ echo "$*"
101
+ echo
102
+ exit 1
103
+ } >&2
104
+
105
+ # OS specific support (must be 'true' or 'false').
106
+ cygwin=false
107
+ msys=false
108
+ darwin=false
109
+ nonstop=false
110
+ case "$( uname )" in #(
111
+ CYGWIN* ) cygwin=true ;; #(
112
+ Darwin* ) darwin=true ;; #(
113
+ MSYS* | MINGW* ) msys=true ;; #(
114
+ NONSTOP* ) nonstop=true ;;
115
+ esac
116
+
117
+
118
+
119
+ # Determine the Java command to use to start the JVM.
120
+ if [ -n "$JAVA_HOME" ] ; then
121
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
122
+ # IBM's JDK on AIX uses strange locations for the executables
123
+ JAVACMD=$JAVA_HOME/jre/sh/java
124
+ else
125
+ JAVACMD=$JAVA_HOME/bin/java
126
+ fi
127
+ if [ ! -x "$JAVACMD" ] ; then
128
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
129
+
130
+ Please set the JAVA_HOME variable in your environment to match the
131
+ location of your Java installation."
132
+ fi
133
+ else
134
+ JAVACMD=java
135
+ if ! command -v java >/dev/null 2>&1
136
+ then
137
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
138
+
139
+ Please set the JAVA_HOME variable in your environment to match the
140
+ location of your Java installation."
141
+ fi
142
+ fi
143
+
144
+ # Increase the maximum file descriptors if we can.
145
+ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
146
+ case $MAX_FD in #(
147
+ max*)
148
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
149
+ # shellcheck disable=SC2039,SC3045
150
+ MAX_FD=$( ulimit -H -n ) ||
151
+ warn "Could not query maximum file descriptor limit"
152
+ esac
153
+ case $MAX_FD in #(
154
+ '' | soft) :;; #(
155
+ *)
156
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
157
+ # shellcheck disable=SC2039,SC3045
158
+ ulimit -n "$MAX_FD" ||
159
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
160
+ esac
161
+ fi
162
+
163
+ # Collect all arguments for the java command, stacking in reverse order:
164
+ # * args from the command line
165
+ # * the main class name
166
+ # * -classpath
167
+ # * -D...appname settings
168
+ # * --module-path (only if needed)
169
+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
170
+
171
+ # For Cygwin or MSYS, switch paths to Windows format before running java
172
+ if "$cygwin" || "$msys" ; then
173
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
174
+
175
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
176
+
177
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
178
+ for arg do
179
+ if
180
+ case $arg in #(
181
+ -*) false ;; # don't mess with options #(
182
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183
+ [ -e "$t" ] ;; #(
184
+ *) false ;;
185
+ esac
186
+ then
187
+ arg=$( cygpath --path --ignore --mixed "$arg" )
188
+ fi
189
+ # Roll the args list around exactly as many times as the number of
190
+ # args, so each arg winds up back in the position where it started, but
191
+ # possibly modified.
192
+ #
193
+ # NB: a `for` loop captures its iteration list before it begins, so
194
+ # changing the positional parameters here affects neither the number of
195
+ # iterations, nor the values presented in `arg`.
196
+ shift # remove old arg
197
+ set -- "$@" "$arg" # push replacement arg
198
+ done
199
+ fi
200
+
201
+
202
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203
+ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204
+
205
+ # Collect all arguments for the java command:
206
+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207
+ # and any embedded shellness will be escaped.
208
+ # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209
+ # treated as '${Hostname}' itself on the command line.
210
+
211
+ set -- \
212
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
213
+ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
214
+ "$@"
215
+
216
+ # Stop when "xargs" is not available.
217
+ if ! command -v xargs >/dev/null 2>&1
218
+ then
219
+ die "xargs is not available"
220
+ fi
221
+
222
+ # Use "xargs" to parse quoted args.
223
+ #
224
+ # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
225
+ #
226
+ # In Bash we could simply go:
227
+ #
228
+ # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
229
+ # set -- "${ARGS[@]}" "$@"
230
+ #
231
+ # but POSIX shell has neither arrays nor command substitution, so instead we
232
+ # post-process each arg (as a line of input to sed) to backslash-escape any
233
+ # character that might be a shell metacharacter, then use eval to reverse
234
+ # that process (while maintaining the separation between arguments), and wrap
235
+ # the whole thing up as a single "set" statement.
236
+ #
237
+ # This will of course break if any of these variables contains a newline or
238
+ # an unmatched quote.
239
+ #
240
+
241
+ eval "set -- $(
242
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
243
+ xargs -n1 |
244
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
245
+ tr '\n' ' '
246
+ )" '"$@"'
247
+
248
+ exec "$JAVACMD" "$@"
@@ -0,0 +1,47 @@
1
+ // The Android app: one Activity whose content is the __RENDERER_NAME__ app. The BakeNative library modules
2
+ // build from source in your BakeNative checkout (native/android); its libbakenative.so comes from
3
+ // native/android/bakenative/build-rust.sh there.
4
+ // :bakenative, :controls BakeNativeView and its controls
5
+ // :modules, :modules-* the native module DSL and the first-party modules (Share, ...): a
6
+ // module is in the APK only when :bakenative-app-modules depends on it
7
+ // :bakenative-app-modules ../.bake/native/android, written by `pnpm build:android` (bake build):
8
+ // the first-party modules the bundle uses (manifest.json requires.modules)
9
+ pluginManagement {
10
+ repositories {
11
+ google()
12
+ mavenCentral()
13
+ gradlePluginPortal()
14
+ }
15
+ }
16
+
17
+ val bakenative = file("__BAKENATIVE__")
18
+
19
+ dependencyResolutionManagement {
20
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
21
+ repositories {
22
+ google()
23
+ mavenCentral()
24
+ }
25
+ versionCatalogs {
26
+ create("libs") { from(files(bakenative.resolve("native/android/gradle/libs.versions.toml"))) }
27
+ }
28
+ }
29
+
30
+ rootProject.name = "__NAME__"
31
+ include(":app")
32
+ include(":bakenative")
33
+ project(":bakenative").projectDir = bakenative.resolve("native/android/bakenative")
34
+ include(":controls")
35
+ project(":controls").projectDir = bakenative.resolve("native/android/controls")
36
+ include(":modules")
37
+ project(":modules").projectDir = bakenative.resolve("native/android/modules")
38
+ bakenative.resolve("native/android").listFiles { f -> f.isDirectory && f.name.startsWith("modules-") }?.sorted()?.forEach {
39
+ include(":${it.name}")
40
+ project(":${it.name}").projectDir = it
41
+ }
42
+ // Written by the first `pnpm build:android`; until then the app's preBuild asks for it.
43
+ val appModules = file("../.bake/native/android")
44
+ if (appModules.resolve("build.gradle.kts").isFile) {
45
+ include(":bakenative-app-modules")
46
+ project(":bakenative-app-modules").projectDir = appModules
47
+ }
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from '@bake-native/core';
2
+
3
+ // The platforms this app ships on: bake build, bake check and bake dev use them when --target is not
4
+ // given, and refuse a target that is not listed. Docs: https://bake-native.com/docs/reference/config
5
+ export default defineConfig({
6
+ renderer: '__RENDERER__',
7
+ targets: __TARGETS__,
8
+ __APP_CONFIG__
9
+ __COMPILER__
10
+ });