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

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 (144) 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/close-watcher.js +137 -0
  7. package/compat.json +64 -0
  8. package/controls.css +108 -0
  9. package/determinism.js +175 -0
  10. package/devtools.d.ts +13 -0
  11. package/devtools.js +73 -0
  12. package/dialogs.js +59 -0
  13. package/direct-style.js +105 -0
  14. package/direct-table.js +261 -0
  15. package/dist/bake.mjs +2211 -0
  16. package/dist/build-BrSFpaK1.mjs +1 -0
  17. package/dist/build-tools-Dxyl6XAf.mjs +80 -0
  18. package/dist/build-vAPG2xQv.mjs +5516 -0
  19. package/dist/client-Cm7o6dQd.mjs +17544 -0
  20. package/dist/compiler.mjs +4 -0
  21. package/dist/config-B1W8gfZY.mjs +12 -0
  22. package/dist/dev-xZblYmDc.mjs +990 -0
  23. package/dist/direct-report-Bdda-k_Y.mjs +153 -0
  24. package/dist/direct-report-Du44nNWl.mjs +1 -0
  25. package/dist/index.d.mts +176 -0
  26. package/dist/index.mjs +1 -0
  27. package/dist/intl-ROnAp2qO.mjs +75 -0
  28. package/dist/jiti-stub-CKcaShwE.mjs +5 -0
  29. package/dist/native-views-BQ8TtbQj.mjs +8046 -0
  30. package/dist/octane/package.json +5 -0
  31. package/dist/package-D2aYD6A4.mjs +2789 -0
  32. package/dist/react/package.json +13 -0
  33. package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
  34. package/dist/run-BtyJGAQB.mjs +6632 -0
  35. package/dist/scope-8W2aIuQ9.mjs +262 -0
  36. package/dist/screens/BakeNativeScreen.native.ts +9 -0
  37. package/dist/screens/package.json +5 -0
  38. package/dom-exception.js +31 -0
  39. package/element-api.js +158 -0
  40. package/first-screen.js +30 -0
  41. package/fonts/Geist-Italic-Variable.ttf +0 -0
  42. package/fonts/Geist-Variable.ttf +0 -0
  43. package/fonts/GeistMono-Italic-Variable.ttf +0 -0
  44. package/fonts/GeistMono-Variable.ttf +0 -0
  45. package/fonts/OFL.txt +93 -0
  46. package/fonts/README.md +27 -0
  47. package/fonts/geist-italic.css +8 -0
  48. package/fonts/geist-mono-italic.css +8 -0
  49. package/fonts/geist-mono.css +8 -0
  50. package/fonts/geist.css +8 -0
  51. package/header-icons.json +53 -0
  52. package/host-runtime.js +521 -0
  53. package/image-props.js +17 -0
  54. package/index.d.ts +8 -0
  55. package/index.js +7 -0
  56. package/licenses/Apache-2.0.txt +73 -0
  57. package/locale-entry.d.ts +1 -0
  58. package/locale-entry.js +1 -0
  59. package/locale.d.ts +28 -0
  60. package/locale.js +124 -0
  61. package/markup-support.js +87 -0
  62. package/media-element.js +115 -0
  63. package/native-args-entry.js +2 -0
  64. package/native-args.d.ts +7 -0
  65. package/native-args.js +155 -0
  66. package/native-entry.js +1 -0
  67. package/native-globals.d.ts +166 -0
  68. package/native-scenarios.d.ts +17 -0
  69. package/native-scenarios.js +46 -0
  70. package/native-support.json +366 -0
  71. package/native.d.ts +52 -0
  72. package/native.js +237 -0
  73. package/package.json +143 -4
  74. package/page-elements.js +123 -0
  75. package/runtime-provides.json +412 -0
  76. package/safe-area.d.ts +1 -0
  77. package/safe-area.js +44 -0
  78. package/swift-ui/modifiers.js +176 -0
  79. package/tab-icons.js +62 -0
  80. package/templates/create/tabs/AGENTS.md +22 -0
  81. package/templates/create/tabs/README.md +43 -0
  82. package/templates/create/tabs/_gitignore +13 -0
  83. package/templates/create/tabs/android/app/build.gradle.kts +79 -0
  84. package/templates/create/tabs/android/app/src/main/AndroidManifest.xml +39 -0
  85. package/templates/create/tabs/android/app/src/main/kotlin/MainActivity.kt +35 -0
  86. package/templates/create/tabs/android/app/src/main/res/values/themes.xml +8 -0
  87. package/templates/create/tabs/android/build.gradle.kts +5 -0
  88. package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  89. package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.properties +9 -0
  90. package/templates/create/tabs/android/gradle.properties +3 -0
  91. package/templates/create/tabs/android/gradlew +248 -0
  92. package/templates/create/tabs/android/settings.gradle.kts +47 -0
  93. package/templates/create/tabs/bake.config.ts +10 -0
  94. package/templates/create/tabs/ios/App/App.swift +30 -0
  95. package/templates/create/tabs/ios/build.sh +23 -0
  96. package/templates/create/tabs/ios/project.yml +57 -0
  97. package/templates/create/tabs/macos/Package.swift +24 -0
  98. package/templates/create/tabs/macos/Sources/__SWIFT_NAME__/App.swift +146 -0
  99. package/templates/create/tabs/macos/build.sh +4 -0
  100. package/templates/create/tabs/package.json +23 -0
  101. package/templates/create/tabs/pnpm-workspace.yaml +6 -0
  102. package/templates/create/tabs/src/App.tsrx +92 -0
  103. package/templates/create/tabs/src/App.tsx +67 -0
  104. package/templates/create/tabs/src/styles.css +32 -0
  105. package/templates/create/tabs/tsconfig.json +5 -0
  106. package/templates/create/tabs/windows/Cargo.toml +29 -0
  107. package/templates/create/tabs/windows/build.rs +9 -0
  108. package/templates/create/tabs/windows/src/main.rs +52 -0
  109. package/templates/create/tabs/windows/src/shell.rs +316 -0
  110. package/templates/module/__NAME__.kt +20 -0
  111. package/templates/module/__NAME__.native.ts +24 -0
  112. package/templates/module/__NAME__.swift +25 -0
  113. package/templates/module/__NAME__.web.ts +13 -0
  114. package/templates/module/__NAME__Test.kt +26 -0
  115. package/templates/module/__NAME__Tests.swift +25 -0
  116. package/templates/module/__SNAKE__.rs +43 -0
  117. package/text.d.ts +20 -0
  118. package/text.js +100 -0
  119. package/transform-entry.js +1 -0
  120. package/transform.d.ts +15 -0
  121. package/transform.js +98 -0
  122. package/tsconfig.native.json +16 -0
  123. package/ui/scope.js +103 -0
  124. package/ui/swift.js +106 -0
  125. package/ui/ui.css +272 -0
  126. package/view-ref-writer.js +268 -0
  127. package/view-ref.d.ts +26 -0
  128. package/view-ref.js +85 -0
  129. package/views/Video.native.ts +68 -0
  130. package/views/generated/VideoViewAndroid.h +68 -0
  131. package/views/generated/VideoViewJSI.h +94 -0
  132. package/views/generated/VideoViewSpec.kt +113 -0
  133. package/views/generated/apple/VideoViewJSI/VideoViewJSIApple.cpp +40 -0
  134. package/views/generated/apple/VideoViewJSI/include/VideoViewJSIApple.h +28 -0
  135. package/views/generated/apple/VideoViewSpec/VideoViewInterop.swift +39 -0
  136. package/views/generated/apple/VideoViewSpec/VideoViewSpec.swift +186 -0
  137. package/views/generated/video_view_spec.rs +189 -0
  138. package/views.d.ts +24 -0
  139. package/views.js +45 -0
  140. package/virtual-window.js +35 -0
  141. package/visibility.js +75 -0
  142. package/web-crypto.js +84 -0
  143. package/web-fetch.js +1071 -0
  144. package/README.md +0 -3
@@ -0,0 +1,105 @@
1
+ // Direct style bindings (docs/design/direct-updates.md, "Choosing the path"): a signal bound to an
2
+ // element's inline `transform` / `opacity` (`style={{ transform: t$ }}`) changes the view through
3
+ // the core's direct table instead of an Octane update, a batch and a commit. The app writes its
4
+ // signal as always: the write stays an ordinary signal write (its value stored, every other
5
+ // subscriber notified); only the binding's reaction differs (`driver.styleBindingChange`, called
6
+ // by Octane for a style binding of one host, with the binding's source: its `style`, `keys`,
7
+ // `retry` and a `hostState` slot this module keeps its state for the element in).
8
+ //
9
+ // An element is bound once its view exists (direct-table.js; the core refuses one whose transform
10
+ // or opacity something else owns). A value the table cannot carry
11
+ // (CSS text, `none`, an opacity that is not a number) or another bound style key leaves the direct
12
+ // path for good: the change goes on to Octane, which sends the latest value, and the view is
13
+ // unbound in the same JS turn, so the host goes from the last direct value to the latest one.
14
+ // The core tells JS (through `__bakeDirectTransforms`' result) when a bound view is destroyed or
15
+ // becomes ineligible (a class change brought a transition); the latter leaves the same way, its
16
+ // binding's `retry` handing the latest value to Octane.
17
+ import { BOUND, ORDINARY, WAITING, directRecord, directTable } from './direct-table.js';
18
+
19
+ /** Marks a style object whose bindings stay on the batch path (bake.config.ts `direct.exclude`). */
20
+ export const NO_DIRECT = Symbol.for('bakenative.noDirect');
21
+
22
+ /** The `styleBindingChange` driver option. */
23
+ export function directStyleBindings(global) {
24
+ const table = directTable(global);
25
+ // Back to the ordinary path for good; the core unbinds the view with the commit that carries
26
+ // Octane's latest value (the host drops the direct values after it). A view its ref writes
27
+ // too (view-ref.js) stays bound for the ref.
28
+ function leave(e) {
29
+ e.auto = false;
30
+ if (e.view === undefined) table.unbind(e);
31
+ }
32
+
33
+ /** Octane: style binding `source` of element `el` changed; true when the direct table took it. */
34
+ return function styleBindingChange(source, el, read) {
35
+ let e = source.hostState;
36
+ if (e === undefined || e.el !== el) {
37
+ // First change of this binding, or of its binding to another element.
38
+ if (e !== undefined) leave(e);
39
+ // A rerender can replace the style source of a view that is still bound. Carry the
40
+ // binding to the new source so it can consume the core's events and retry its own value.
41
+ e = table.find(el) ?? directRecord(el);
42
+ if (e.source !== undefined && e.source !== source) e.source.hostState = undefined;
43
+ e.source = source;
44
+ e.auto = true;
45
+ source.hostState = e;
46
+ const keys = source.keys;
47
+ if (!table.available() || source.style[NO_DIRECT] === true
48
+ || keys.some((key) => key !== 'transform' && key !== 'opacity')) {
49
+ leave(e);
50
+ return false;
51
+ }
52
+ if (e.state === ORDINARY && !e.refused && !table.wait(e)) {
53
+ // Full: this binding asks again at its next change.
54
+ source.hostState = undefined;
55
+ return false;
56
+ }
57
+ }
58
+ if (!e.auto || e.state === ORDINARY) return false;
59
+ if (e.state === WAITING) {
60
+ table.resolve();
61
+ if (e.state !== BOUND) return false;
62
+ }
63
+ const style = source.style;
64
+ const keys = source.keys;
65
+ let t;
66
+ let o;
67
+ let tChanged = false;
68
+ let oChanged = false;
69
+ for (let i = 0; i < keys.length; i++) {
70
+ const k = keys[i];
71
+ const v = style[k][read]();
72
+ if (k === 'transform') {
73
+ if (v !== e.t) {
74
+ t = v;
75
+ tChanged = true;
76
+ }
77
+ } else if (k === 'opacity') {
78
+ if (v !== e.o) {
79
+ o = v;
80
+ oChanged = true;
81
+ }
82
+ } else {
83
+ // Another bound key: this path cannot tell which one changed. Returning false hands this
84
+ // change to Octane, which sends the latest values.
85
+ leave(e);
86
+ return false;
87
+ }
88
+ }
89
+ // Check both values before writing either: a view leaves whole.
90
+ const f = tChanged ? t?.$$bakeTransform : undefined;
91
+ if ((tChanged && (f === undefined || f.length === 0)) || (oChanged && typeof o !== 'number')) {
92
+ leave(e);
93
+ return false;
94
+ }
95
+ if (tChanged) {
96
+ table.transform(e, f);
97
+ e.t = t;
98
+ }
99
+ if (oChanged) {
100
+ table.opacity(e, o);
101
+ e.o = o;
102
+ }
103
+ return true;
104
+ };
105
+ }
@@ -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
+ }