@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
@@ -0,0 +1,261 @@
1
+ // The JS writer of the core's direct table (docs/design/direct-updates.md, path 1): one per VM.
2
+ // A view's transform and opacity go to the core in one call a JS turn
3
+ // (`globalThis.__bakeDirectTransforms`, native/rust/crates/bake-runtime/src/direct.rs), past the
4
+ // renderer, the batch and the commit. Two callers write through it and share one record per
5
+ // element: signal style bindings (direct-style.js) and `View` refs (view-ref.js).
6
+ //
7
+ // The core addresses views by host id. An element learns its view's id once the commit that
8
+ // creates the view is published (`__bakeElement` op 7, one call a turn for every element waiting),
9
+ // unless the core refuses it: a transition, an animation, translate / rotate / scale or a rule
10
+ // owns its transform or opacity. The call's reply carries what the core reports about bound
11
+ // views since the last one: a view was destroyed, or became ineligible.
12
+
13
+ const TRANSLATE = 1;
14
+ const SCALE = 2;
15
+ const DEG = Math.PI / 180;
16
+ const KIND_TRANSFORM = 0;
17
+ const KIND_OPACITY = 1;
18
+ const KIND_UNBIND = 2;
19
+ const REFUSED = 0xffffffff;
20
+ const EVENT_GONE = 1;
21
+ const EVENT_INELIGIBLE = 2;
22
+ /** Elements a table holds at most (`direct.rs` CAPACITY); more stay on the ordinary path. */
23
+ const CAPACITY = 16384;
24
+
25
+ /** A record's state: asked for its view, writing to it, or not on the table. */
26
+ export const WAITING = 0;
27
+ export const BOUND = 1;
28
+ export const ORDINARY = 2;
29
+
30
+ const tables = new WeakMap();
31
+
32
+ /** The table writer of `global` (the VM's global object). */
33
+ export function directTable(global) {
34
+ let table = tables.get(global);
35
+ if (table === undefined) tables.set(global, (table = createTable(global)));
36
+ return table;
37
+ }
38
+
39
+ /** A new record for element `el`, not on the table. `source` is its style binding (direct-style.js)
40
+ * and `view` its ref's state (view-ref.js), when it has them. */
41
+ export function directRecord(el) {
42
+ return { el, state: ORDINARY, host: 0, refused: false, t: undefined, o: undefined, source: undefined, view: undefined };
43
+ }
44
+
45
+ function createTable(global) {
46
+ // Looked up at the first use: the runtime may install them after the bundle ran.
47
+ let send;
48
+ let elementOp;
49
+ const byHost = new Map();
50
+ // Bound records, and waiting ones that have a view ref.
51
+ const byElement = new Map();
52
+ // Waiting records by element: an element's second writer takes the record of its first.
53
+ const pending = new Map();
54
+ let waiting = [];
55
+ let asked = false;
56
+ let ids = new Uint32Array(0);
57
+ let kinds = new Uint32Array(0);
58
+ let values = new Float32Array(0);
59
+ let count = 0;
60
+ let scheduled = false;
61
+
62
+ function handle(events) {
63
+ for (let i = 0; i + 1 < events.length; i += 2) {
64
+ const e = byHost.get(events[i]);
65
+ if (e === undefined) continue;
66
+ if (events[i + 1] === EVENT_GONE) {
67
+ table.forget(e);
68
+ if (e.view !== undefined) table.onGone(e);
69
+ } else if (events[i + 1] === EVENT_INELIGIBLE) {
70
+ table.unbind(e);
71
+ e.refused = true;
72
+ // Octane sends the binding's latest value (it compares with what it last sent).
73
+ e.source?.retry();
74
+ if (e.view !== undefined) table.onRefused(e);
75
+ }
76
+ }
77
+ }
78
+ function publish() {
79
+ scheduled = false;
80
+ const n = count;
81
+ count = 0;
82
+ const events = send(ids.buffer, values.buffer, n, kinds.buffer);
83
+ if (events !== undefined) handle(events);
84
+ }
85
+ function grow() {
86
+ const n = Math.max(16, ids.length * 2);
87
+ const i2 = new Uint32Array(n);
88
+ i2.set(ids);
89
+ ids = i2;
90
+ const k2 = new Uint32Array(n);
91
+ k2.set(kinds);
92
+ kinds = k2;
93
+ const v2 = new Float32Array(n * 6);
94
+ v2.set(values);
95
+ values = v2;
96
+ }
97
+ function entry(host, kind) {
98
+ if (count === ids.length) grow();
99
+ ids[count] = host;
100
+ kinds[count] = kind;
101
+ if (!scheduled) {
102
+ scheduled = true;
103
+ queueMicrotask(publish);
104
+ }
105
+ return count++ * 6;
106
+ }
107
+
108
+ const table = {
109
+ byElement,
110
+ /** view-ref.js: the core bound or refused a record that has a view ref, or its view is gone. */
111
+ onBound: undefined,
112
+ onRefused: undefined,
113
+ onGone: undefined,
114
+ /** Element `el`'s record, when it is bound or waiting. */
115
+ find(el) {
116
+ return byElement.get(el) ?? pending.get(el);
117
+ },
118
+ /** Whether the runtime has a direct table. */
119
+ available() {
120
+ if (send === undefined) {
121
+ send = global.__bakeDirectTransforms;
122
+ elementOp = global.__bakeElement;
123
+ }
124
+ return typeof send === 'function' && typeof elementOp === 'function';
125
+ },
126
+ /** Queues `e` for its view's host id; false when the table is full. */
127
+ wait(e) {
128
+ if (waiting.length + byHost.size >= CAPACITY) return false;
129
+ e.state = WAITING;
130
+ waiting.push(e);
131
+ pending.set(e.el, e);
132
+ return true;
133
+ },
134
+ /** Binds the waiting records in the core, one call a JS turn (and one more with `again`, for
135
+ * a caller that asks once itself, when the turn ends); those without a view yet keep
136
+ * waiting. False before the core's first commit and while it has an earlier turn to apply. */
137
+ resolve(again = false) {
138
+ if (asked && !again) return true;
139
+ asked = true;
140
+ queueMicrotask(() => {
141
+ asked = false;
142
+ });
143
+ // Drop the ones that left while waiting (a binding moved to another element).
144
+ let n = 0;
145
+ for (let k = 0; k < waiting.length; k++) if (waiting[k].state === WAITING) waiting[n++] = waiting[k];
146
+ waiting.length = n;
147
+ if (n === 0) return true;
148
+ const els = new Uint32Array(n);
149
+ for (let k = 0; k < n; k++) els[k] = waiting[k].el;
150
+ let hosts;
151
+ try {
152
+ hosts = elementOp(7, n, els.buffer);
153
+ } catch (e) {
154
+ if (/^E_NO_LAYOUT:/.test(String(e?.message ?? e))) return false;
155
+ throw e;
156
+ }
157
+ const all = waiting;
158
+ waiting = [];
159
+ for (let k = 0; k < all.length; k++) {
160
+ const e = all[k];
161
+ if (hosts[k] === 0) {
162
+ waiting.push(e);
163
+ continue;
164
+ }
165
+ pending.delete(e.el);
166
+ if (hosts[k] === REFUSED) {
167
+ e.state = ORDINARY;
168
+ e.refused = true;
169
+ if (e.view !== undefined) table.onRefused(e);
170
+ } else {
171
+ e.state = BOUND;
172
+ e.host = hosts[k];
173
+ byHost.set(e.host, e);
174
+ byElement.set(e.el, e);
175
+ if (e.view !== undefined) table.onBound(e);
176
+ }
177
+ }
178
+ return true;
179
+ },
180
+ /** Writes the 2D matrix of `f` (a numeric transform's functions: kind, x, y, ...) to bound
181
+ * record `e`: CSS order, about the view's center. */
182
+ transform(e, f) {
183
+ // One translate, the usual frame-loop value: its matrix without the composition.
184
+ if (f.length === 3 && f[0] === TRANSLATE) {
185
+ const at = entry(e.host, KIND_TRANSFORM);
186
+ values[at] = 1;
187
+ values[at + 1] = 0;
188
+ values[at + 2] = 0;
189
+ values[at + 3] = 1;
190
+ values[at + 4] = f[1];
191
+ values[at + 5] = f[2];
192
+ return;
193
+ }
194
+ let a = 1;
195
+ let b = 0;
196
+ let c = 0;
197
+ let d = 1;
198
+ let x0 = 0;
199
+ let y0 = 0;
200
+ for (let i = 0; i < f.length; i += 3) {
201
+ const kind = f[i];
202
+ const x = f[i + 1];
203
+ const y = f[i + 2];
204
+ if (kind === TRANSLATE) {
205
+ x0 += a * x + c * y;
206
+ y0 += b * x + d * y;
207
+ } else if (kind === SCALE) {
208
+ a *= x;
209
+ b *= x;
210
+ c *= y;
211
+ d *= y;
212
+ } else {
213
+ const r = x * DEG;
214
+ const cs = Math.cos(r);
215
+ const sn = Math.sin(r);
216
+ const na = a * cs + c * sn;
217
+ const nb = b * cs + d * sn;
218
+ c = c * cs - a * sn;
219
+ d = d * cs - b * sn;
220
+ a = na;
221
+ b = nb;
222
+ }
223
+ }
224
+ const at = entry(e.host, KIND_TRANSFORM);
225
+ values[at] = a;
226
+ values[at + 1] = b;
227
+ values[at + 2] = c;
228
+ values[at + 3] = d;
229
+ values[at + 4] = x0;
230
+ values[at + 5] = y0;
231
+ },
232
+ /** Writes opacity `o` (0 ... 1) to bound record `e`. */
233
+ opacity(e, o) {
234
+ // `entry` can replace `values` (a batch that grows): take the offset first.
235
+ const at = entry(e.host, KIND_OPACITY);
236
+ values[at] = o;
237
+ },
238
+ /** Takes `e` off the table. The core unbinds its view with the commit that carries this
239
+ * turn's batches: a property whose declared value changed while bound shows that value,
240
+ * the other keeps its last direct one until its declared value changes. */
241
+ unbind(e) {
242
+ if (e.state === BOUND) {
243
+ entry(e.host, KIND_UNBIND);
244
+ byHost.delete(e.host);
245
+ if (e.view === undefined) byElement.delete(e.el);
246
+ e.host = 0;
247
+ } else if (e.state === WAITING) pending.delete(e.el);
248
+ e.state = ORDINARY;
249
+ },
250
+ /** `e`'s view is gone: a style binding that lives on starts over with its next element. */
251
+ forget(e) {
252
+ byHost.delete(e.host);
253
+ byElement.delete(e.el);
254
+ pending.delete(e.el);
255
+ e.state = ORDINARY;
256
+ e.host = 0;
257
+ e.el = -1;
258
+ },
259
+ };
260
+ return table;
261
+ }