@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/transform.js ADDED
@@ -0,0 +1,98 @@
1
+ // Numeric CSS transforms: a `style.transform` value built from numbers instead of a string.
2
+ //
3
+ // import { transform } from '@bake-native/core';
4
+ // <div style={{ transform: transform().translate(x, y).rotate(deg).scale(s) }} />
5
+ //
6
+ // The value is its CSS text wherever a string is expected (`String(t)`, `t.toJSON()`): the web
7
+ // (Octane writes `"" + value` into the element's style) and the build-time snapshot bake see
8
+ // `translate(12.5px, 40px) rotate(30deg) scale(0.8)`. Native: an update whose only change is such
9
+ // a transform crosses to the core as its numbers (batch op `set-transform`), so neither JS nor the
10
+ // core builds or parses the text; the core prints the numbers back as the same text, so the node,
11
+ // its computed style and what the web renders are what the string would give.
12
+ //
13
+ // Each method appends a function and returns the same object: build a new value for every change
14
+ // (a signal or prop compares values by identity) and do not change it once it is set.
15
+
16
+ const TRANSLATE = 1;
17
+ const SCALE = 2;
18
+ const ROTATE = 3;
19
+
20
+ export class Transform {
21
+ constructor() {
22
+ /** [kind, x, y, ...]: what the batch writer sends (batch.oschema `transform`). */
23
+ this.$$bakeTransform = [];
24
+ }
25
+ /** `translate(<x>px, <y>px)` */
26
+ translate(x, y = 0) {
27
+ this.$$bakeTransform.push(TRANSLATE, x, y);
28
+ return this;
29
+ }
30
+ /** `scale(<x>)`, or `scale(<x>, <y>)` when they differ */
31
+ scale(x, y = x) {
32
+ this.$$bakeTransform.push(SCALE, x, y);
33
+ return this;
34
+ }
35
+ /** `rotate(<deg>deg)` */
36
+ rotate(deg) {
37
+ this.$$bakeTransform.push(ROTATE, deg, 0);
38
+ return this;
39
+ }
40
+ /** The CSS text (`none` without functions). bake-core `Transform::text` prints the same. */
41
+ toString() {
42
+ const f = this.$$bakeTransform;
43
+ if (f.length === 0) return 'none';
44
+ let s = '';
45
+ for (let i = 0; i < f.length; i += 3) {
46
+ if (i > 0) s += ' ';
47
+ const k = f[i];
48
+ const x = f[i + 1];
49
+ const y = f[i + 2];
50
+ if (k === TRANSLATE) s += 'translate(' + x + 'px, ' + y + 'px)';
51
+ else if (k === SCALE) s += x === y ? 'scale(' + x + ')' : 'scale(' + x + ', ' + y + ')';
52
+ else s += 'rotate(' + x + 'deg)';
53
+ }
54
+ return s;
55
+ }
56
+ toJSON() {
57
+ return this.toString();
58
+ }
59
+ }
60
+
61
+ /** A new, empty transform (`none`); chain `translate` / `rotate` / `scale` onto it. */
62
+ export function transform() {
63
+ return new Transform();
64
+ }
65
+
66
+ // Own keys, each a defined value equal (===) in both, except `except`, which both have.
67
+ function sameExcept(a, b, except) {
68
+ let n = 0;
69
+ for (const k in b) {
70
+ n++;
71
+ if (k !== except && (b[k] === undefined || b[k] !== a[k])) return false;
72
+ }
73
+ for (const k in a) n--;
74
+ return n === 0 && except in a;
75
+ }
76
+
77
+ /**
78
+ * Host props `next` are `previous` with only the inline `style.transform` changed, to a string
79
+ * or a numeric transform (the native host runtime sends such an update as `set-transform`).
80
+ * @internal
81
+ */
82
+ export function isTransformOnlyUpdate(previous, next) {
83
+ if (previous === null || typeof previous !== 'object' || !sameExcept(previous, next, 'style')) return false;
84
+ const a = previous.style;
85
+ const b = next.style;
86
+ if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object' || Array.isArray(a) || Array.isArray(b)) return false;
87
+ const t = b.transform;
88
+ if (t === a.transform || !isTransformValue(t)) return false;
89
+ return sameExcept(a, b, 'transform');
90
+ }
91
+
92
+ /**
93
+ * A `style.transform` value `set-transform` carries: CSS text or a numeric transform.
94
+ * @internal
95
+ */
96
+ export function isTransformValue(t) {
97
+ return typeof t === 'string' || (t !== null && typeof t === 'object' && Array.isArray(t.$$bakeTransform));
98
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ // Type-check native code without the DOM: extend this and the globals a native bundle
3
+ // cannot use (`document`, `window`, `fetch`, ...) are type errors, as they are build errors in
4
+ // `bake build`. native-globals.d.ts is generated from native-support.json.
5
+ // { "extends": "@bake-native/core/tsconfig.native.json", "include": ["src"] }
6
+ "compilerOptions": {
7
+ "target": "ES2022",
8
+ "lib": ["ES2022"],
9
+ "types": ["@bake-native/core/native-globals"],
10
+ "module": "ESNext",
11
+ "moduleResolution": "Bundler",
12
+ "allowJs": true,
13
+ "noEmit": true,
14
+ "skipLibCheck": true
15
+ }
16
+ }
package/ui/scope.js ADDED
@@ -0,0 +1,103 @@
1
+ // @bake-native/octane/ui v0.1: what the Universal layer has, after @expo/ui's Universal components
2
+ // (`@expo/ui`). One table for the build check (fail-closed.mjs uiIssues), the unit tests and the
3
+ // docs: a component or prop that is not here is a build error on every target, never a silent
4
+ // no-op. Names and prop names are @expo/ui's; Header and TabBar are BakeNative' navigation chrome.
5
+
6
+ const COMMON = ['testID', 'style', 'hidden'];
7
+
8
+ /**
9
+ * component -> { props: [names], values?: { prop: [allowed string literals] }, expo?: note }.
10
+ * `children` is listed where the component takes children.
11
+ */
12
+ export const UI_COMPONENTS = {
13
+ Host: { props: ['children', 'matchContents', 'colorScheme', ...COMMON], values: { colorScheme: ['light', 'dark'] } },
14
+ Column: { props: ['children', 'spacing', 'alignment', ...COMMON], values: { alignment: ['start', 'center', 'end'] } },
15
+ Row: { props: ['children', 'spacing', 'alignment', ...COMMON], values: { alignment: ['start', 'center', 'end'] } },
16
+ Spacer: { props: ['size', 'flexible', 'testID'] },
17
+ Text: { props: ['children', 'textStyle', 'numberOfLines', ...COMMON] },
18
+ Button: { props: ['children', 'label', 'onPress', 'variant', 'disabled', ...COMMON], values: { variant: ['filled', 'outlined', 'text'] } },
19
+ Switch: { props: ['value', 'onValueChange', 'label', 'disabled', 'testID'] },
20
+ Checkbox: { props: ['value', 'onValueChange', 'label', 'disabled', 'testID'] },
21
+ Slider: { props: ['value', 'onValueChange', 'min', 'max', 'step', 'disabled', 'testID'] },
22
+ Picker: { props: ['children', 'selectedValue', 'onValueChange', 'appearance', 'enabled', 'accessibilityLabel', 'testID'], values: { appearance: ['menu', 'wheel'] } },
23
+ 'Picker.Item': { props: ['label', 'value'] },
24
+ TextInput: {
25
+ props: ['value', 'defaultValue', 'onChangeText', 'placeholder', 'secureTextEntry', 'multiline', 'rows', 'maxLength',
26
+ 'autoCapitalize', 'autoCorrect', 'inputMode', 'enterKeyHint', 'autoComplete', 'onSubmitEditing', 'onFocus', 'onBlur',
27
+ 'accessibilityLabel', ...COMMON],
28
+ values: {
29
+ autoCapitalize: ['none', 'characters', 'words', 'sentences'],
30
+ inputMode: ['none', 'text', 'decimal', 'numeric', 'tel', 'search', 'email', 'url'],
31
+ enterKeyHint: ['enter', 'done', 'go', 'next', 'previous', 'search', 'send'],
32
+ },
33
+ },
34
+ // Navigation chrome (not in @expo/ui): the screen's header and tab bar (ui/header.tsrx,
35
+ // ui/tab-bar.tsrx).
36
+ Header: {
37
+ props: ['title', 'subtitle', 'largeTitle', 'transparent', 'blurEffect', 'backgroundColor', 'tintColor', 'titleColor',
38
+ 'shadowVisible', 'backTitle', 'hidden', 'leftItems', 'rightItems', 'onItemPress'],
39
+ },
40
+ TabBar: {
41
+ props: ['tabs', 'selected', 'onSelect', 'tintColor', 'inactiveTintColor', 'backgroundColor', 'labeled', 'hidden', 'minimizeBehavior'],
42
+ values: { minimizeBehavior: ['automatic', 'never', 'onScrollDown', 'onScrollUp'] },
43
+ },
44
+ };
45
+
46
+ /** `style` keys a component inside a Host takes on iOS and macOS, where SwiftUI draws the Host's
47
+ * tree (ui/swift.js maps them to modifiers): padding, size, opacity, background and corner
48
+ * radius, lengths in px. Another key, or a style that is not an object literal, is a build error
49
+ * on ios / mac (ui-style). The Host's own `style` is CSS (it places the Host). */
50
+ export const UI_SWIFT_STYLE_KEYS = [
51
+ 'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
52
+ 'width', 'height', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight',
53
+ 'opacity', 'backgroundColor', 'borderRadius',
54
+ ];
55
+
56
+ /** Other exports of @bake-native/octane/ui (not components). */
57
+ export const UI_EXPORTS = ['TAB_ICONS'];
58
+
59
+ /** @expo/ui Universal exports that @bake-native/octane/ui does not have yet (a later release): a clear
60
+ * build error instead of a missing export. */
61
+ export const UI_LATER = {
62
+ BottomSheet: 'a <dialog open> (an open dialog is a platform sheet), or @bake-native/octane/swift-ui BottomSheet on iOS / macOS',
63
+ Collapsible: 'a <details> element',
64
+ FieldGroup: 'Column with your own section styles',
65
+ Icon: 'an inline <svg>',
66
+ List: 'Column, or VirtualList from @bake-native/octane',
67
+ ListItem: 'Row',
68
+ RNHostView: 'plain elements next to the Host (Universal components are elements on web and Windows)',
69
+ OctaneView: 'plain elements next to the Host',
70
+ ScrollView: 'a <div> with overflow: auto',
71
+ useNativeState: 'useState from octane (state is controlled from JS: value + onChangeText)',
72
+ };
73
+
74
+ /** Props @expo/ui has that @bake-native/octane/ui does not (yet), with what to use instead. */
75
+ export const UI_PROPS_LATER = {
76
+ modifiers: 'style (platform modifiers are in @bake-native/octane/swift-ui)',
77
+ onAppear: 'useEffect in the component that renders it',
78
+ onDisappear: 'the cleanup of a useEffect',
79
+ editable: 'render the value as Text (TextInput has no read-only state in v0.1; Button, Switch, Checkbox and Slider take `disabled`, Picker takes `enabled`)',
80
+ readOnly: 'render the value as Text',
81
+ autoFocus: 'nothing yet (focus is not moved on mount on native targets)',
82
+ snapPoints: 'nothing yet (BottomSheet is a later release)',
83
+ };
84
+
85
+ // ---------------------------------------------------------------- @bake-native/octane/swift-ui
86
+
87
+ /** The import paths of the SwiftUI components (one module). */
88
+ export const SWIFT_UI_MODULES = ['@bake-native/octane/ui/swift-ui'];
89
+
90
+ /** Targets SwiftUI draws on. On the web the components render HTML approximations; on every
91
+ * other target a SwiftUI component left in the bundle is a build error (ui-swift-ui-target). */
92
+ export const SWIFT_UI_TARGETS = ['ios', 'mac'];
93
+
94
+ /** What to use instead of @bake-native/octane/swift-ui on a target SwiftUI does not draw on. */
95
+ export const SWIFT_UI_INSTEAD = "the Universal components of `@bake-native/octane/ui` (every target), or render the SwiftUI screen only in a branch on import.meta.env.BAKE_TARGET ('ios' / 'mac') and something else on the other targets";
96
+
97
+ /** Props of @bake-native/octane/swift-ui components that are not drawn on iOS / macOS (@expo/ui has
98
+ * them), with what to use instead: a build error (ui-swift-ui-prop) on every target. */
99
+ export const SWIFT_UI_PROPS_LATER = {
100
+ Host: {
101
+ ignoreSafeArea: 'the ignoresSafeArea() modifier on the Host\'s content (`modifiers={[ignoresSafeArea()]}`); the Host itself is laid out by CSS, so give it the size you want',
102
+ },
103
+ };
package/ui/swift.js ADDED
@@ -0,0 +1,106 @@
1
+ // @bake-native/octane/ui on iOS and macOS: the Universal props as SwiftUI modifiers (the data
2
+ // @bake-native/octane/ui/swift-ui's modifiers are: `{ $type, ...args }`, applied in order by the host).
3
+ // Used by ui/index.tsrx inside a Host; plain data, no elements.
4
+
5
+ /** Universal `alignment` -> SwiftUI stack alignment (Column: horizontal, Row: vertical). */
6
+ export const COLUMN_ALIGN = { start: 'leading', center: 'center', end: 'trailing' };
7
+ export const ROW_ALIGN = { start: 'top', center: 'center', end: 'bottom' };
8
+
9
+ /** Button `variant` -> `buttonStyle`. */
10
+ export const BUTTON_STYLE = { filled: 'borderedProminent', outlined: 'bordered', text: 'borderless' };
11
+
12
+ const WEIGHT = {
13
+ normal: 'regular', bold: 'bold', 100: 'ultraLight', 200: 'thin', 300: 'light', 400: 'regular',
14
+ 500: 'medium', 600: 'semibold', 700: 'bold', 800: 'heavy', 900: 'black',
15
+ };
16
+ /** CSS `text-align` -> where a block Text sits in the Host's width. */
17
+ export const TEXT_FRAME_ALIGN = { left: 'leading', start: 'leading', center: 'center', right: 'trailing', end: 'trailing' };
18
+ const TEXT_ALIGN = { left: 'leading', start: 'leading', center: 'center', right: 'trailing', end: 'trailing' };
19
+
20
+ const m = ($type, args) => ({ $type, ...(args ?? {}) });
21
+
22
+ /** A CSS length in px (a number, or `'12px'`); undefined otherwise. */
23
+ export function px(v) {
24
+ if (typeof v === 'number') return v;
25
+ if (typeof v !== 'string') return undefined;
26
+ const r = /^\s*(-?\d+(?:\.\d+)?)(?:px)?\s*$/.exec(v);
27
+ return r ? Number(r[1]) : undefined;
28
+ }
29
+
30
+ /** `padding` shorthand (1 to 4 px lengths) -> [top, right, bottom, left]. */
31
+ function box(v) {
32
+ const parts = typeof v === 'number' ? [v] : String(v).trim().split(/\s+/).map(px);
33
+ if (!parts.length || parts.length > 4 || parts.some((p) => p === undefined)) return undefined;
34
+ const [t, r = t, b = t, l = r] = parts;
35
+ return [t, r, b, l];
36
+ }
37
+
38
+ /** `style` -> modifiers: padding, then frame, background, corner radius and opacity (the CSS
39
+ * box: the background covers the padding; `width` / `height` are the border box). */
40
+ export function styleModifiers(style) {
41
+ if (!style) return [];
42
+ const out = [];
43
+ let pad = style.padding != null ? box(style.padding) : undefined;
44
+ const sides = ['paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft'];
45
+ if (sides.some((k) => style[k] != null)) {
46
+ pad = pad ?? [0, 0, 0, 0];
47
+ sides.forEach((k, i) => { if (style[k] != null) pad[i] = px(style[k]) ?? 0; });
48
+ }
49
+ if (pad) out.push(m('padding', { top: pad[0], trailing: pad[1], bottom: pad[2], leading: pad[3] }));
50
+ const frame = {};
51
+ for (const k of ['width', 'height', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight']) {
52
+ const v = px(style[k]);
53
+ if (v !== undefined) frame[k] = v;
54
+ }
55
+ if (Object.keys(frame).length) {
56
+ // An exact width / height with a min / max: SwiftUI's flexible frame takes width as the ideal.
57
+ if (frame.minWidth !== undefined || frame.maxWidth !== undefined || frame.minHeight !== undefined || frame.maxHeight !== undefined) {
58
+ if (frame.width !== undefined) { frame.minWidth = frame.maxWidth = frame.width; }
59
+ if (frame.height !== undefined) { frame.minHeight = frame.maxHeight = frame.height; }
60
+ }
61
+ out.push(m('frame', { ...frame, alignment: 'topLeading' }));
62
+ }
63
+ if (style.backgroundColor) out.push(m('background', { color: style.backgroundColor }));
64
+ const r = px(style.borderRadius);
65
+ if (r !== undefined) out.push(m('cornerRadius', { radius: r }));
66
+ if (style.opacity != null) out.push(m('opacity', { value: Number(style.opacity) }));
67
+ return out;
68
+ }
69
+
70
+ /** Text `textStyle` + `numberOfLines` -> modifiers. */
71
+ export function textModifiers(t, lines) {
72
+ const out = [];
73
+ if (t) {
74
+ const weight = t.fontWeight != null ? WEIGHT[t.fontWeight] : undefined;
75
+ const size = px(t.fontSize);
76
+ if (t.fontFamily) out.push(m('font', { family: String(t.fontFamily).split(',')[0].trim().replace(/^['"]|['"]$/g, ''), size, weight }));
77
+ else if (size !== undefined) out.push(m('font', { size, weight }));
78
+ else if (weight) out.push(m('font', { weight }));
79
+ if (t.color) out.push(m('foregroundStyle', { color: t.color }));
80
+ const k = px(t.letterSpacing);
81
+ if (k !== undefined) out.push(m('kerning', { value: k }));
82
+ const lh = px(t.lineHeight);
83
+ if (lh !== undefined) out.push(m('lineHeight', { height: lh, fontSize: size }));
84
+ if (t.textAlign && TEXT_ALIGN[t.textAlign]) out.push(m('multilineTextAlignment', { alignment: TEXT_ALIGN[t.textAlign] }));
85
+ }
86
+ if (lines > 0) out.push(m('lineLimit', { value: lines }));
87
+ return out;
88
+ }
89
+
90
+ /** Common trailing modifiers: `disabled`, then `testID` as the accessibility identifier. */
91
+ export function common(props, disabled) {
92
+ const out = [];
93
+ if (disabled) out.push(m('disabled', { value: true }));
94
+ if (props.testID != null) out.push(m('accessibilityIdentifier', { value: String(props.testID) }));
95
+ return out;
96
+ }
97
+
98
+ export const tag = (value) => m('tag', { value });
99
+ export const buttonStyle = (style) => m('buttonStyle', { style });
100
+ export const pickerStyle = (style) => m('pickerStyle', { style });
101
+ export const toggleStyle = (style) => m('toggleStyle', { style });
102
+ export const labelsHidden = () => m('labelsHidden');
103
+ export const frame = (args) => m('frame', args);
104
+ export const lineLimit = (value, reservesSpace) => m('lineLimit', { value, reservesSpace });
105
+ export const accessibilityLabel = (value) => m('accessibilityLabel', { value });
106
+ export const textFieldStyle = (style) => m('textFieldStyle', { style });
package/ui/ui.css ADDED
@@ -0,0 +1,272 @@
1
+ /* @bake-native/octane/ui: the Universal components drawn with CSS (web and Windows draw these rules the
2
+ same way; see ui/index.tsrx). Class tests sit in :where(), so a rule weighs what its bare
3
+ element selector does (`button`, as the control baseline in controls.css, which this file
4
+ follows): the app's own class rules (and a component's `style`) override it. */
5
+
6
+ :where(.bake-ui-host) {
7
+ display: block;
8
+ }
9
+ :where(.bake-ui-host.bake-ui-fit) {
10
+ display: inline-block;
11
+ }
12
+ :where(.bake-ui-host.bake-ui-light) {
13
+ color-scheme: light;
14
+ }
15
+ :where(.bake-ui-host.bake-ui-dark) {
16
+ color-scheme: dark;
17
+ }
18
+
19
+ :where(.bake-ui-column) {
20
+ display: flex;
21
+ flex-direction: column;
22
+ }
23
+ :where(.bake-ui-row) {
24
+ display: flex;
25
+ flex-direction: row;
26
+ }
27
+ :where(.bake-ui-spacer) {
28
+ min-width: 0;
29
+ min-height: 0;
30
+ }
31
+
32
+ /* Text sizes are in rem: they follow the system text size on native targets and the browser's
33
+ font size on the web (16px = 1rem by default, so the default look is unchanged). The tab bar
34
+ keeps px, as its fixed height does. */
35
+ :where(.bake-ui-text) {
36
+ font-size: 0.9375rem;
37
+ line-height: 1.25rem;
38
+ }
39
+ :where(.bake-ui-text.bake-ui-line) {
40
+ overflow: hidden;
41
+ white-space: nowrap;
42
+ text-overflow: ellipsis;
43
+ }
44
+
45
+ /* Button: filled (default), outlined, text. */
46
+ button:where(.bake-ui-button) {
47
+ font-size: 0.9375rem;
48
+ line-height: 1.25rem;
49
+ font-weight: 600;
50
+ padding: 7px 16px;
51
+ border-radius: 10px;
52
+ border: 1px solid #007aff;
53
+ background-color: #007aff;
54
+ color: #ffffff;
55
+ }
56
+ button:where(.bake-ui-button-outlined) {
57
+ background-color: transparent;
58
+ color: #007aff;
59
+ }
60
+ button:where(.bake-ui-button-text) {
61
+ background-color: transparent;
62
+ border-color: transparent;
63
+ color: #007aff;
64
+ }
65
+ :where(.bake-ui-disabled) {
66
+ opacity: 0.4;
67
+ }
68
+
69
+ /* Switch and Checkbox: the control with its label. Both are drawn here (no platform control),
70
+ so they are the same size and look on every target. */
71
+ :where(.bake-ui-toggle) {
72
+ display: flex;
73
+ flex-direction: row;
74
+ align-items: center;
75
+ gap: 12px;
76
+ font-size: 0.9375rem;
77
+ line-height: 1.25rem;
78
+ }
79
+ :where(.bake-ui-switch) {
80
+ position: relative;
81
+ flex: none;
82
+ width: 51px;
83
+ height: 31px;
84
+ border-radius: 16px;
85
+ background-color: rgba(120, 120, 128, 0.32);
86
+ }
87
+ :where(.bake-ui-switch.bake-ui-on) {
88
+ background-color: #34c759;
89
+ }
90
+ :where(.bake-ui-thumb) {
91
+ position: absolute;
92
+ top: 2px;
93
+ left: 2px;
94
+ width: 27px;
95
+ height: 27px;
96
+ border-radius: 14px;
97
+ background-color: #ffffff;
98
+ }
99
+ :where(.bake-ui-switch.bake-ui-on .bake-ui-thumb) {
100
+ left: 22px;
101
+ }
102
+ :where(.bake-ui-checkbox) {
103
+ display: flex;
104
+ align-items: center;
105
+ justify-content: center;
106
+ flex: none;
107
+ box-sizing: border-box;
108
+ width: 22px;
109
+ height: 22px;
110
+ border: 2px solid rgba(120, 120, 128, 0.6);
111
+ border-radius: 6px;
112
+ }
113
+ :where(.bake-ui-checkbox.bake-ui-on) {
114
+ border-color: #007aff;
115
+ background-color: #007aff;
116
+ }
117
+ :where(.bake-ui-check) {
118
+ display: block;
119
+ }
120
+
121
+ /* Slider on web and Windows (ui/slider.tsrx): a track, its filled part and a thumb. */
122
+ :where(.bake-ui-slider) {
123
+ position: relative;
124
+ flex: none;
125
+ width: 160px;
126
+ height: 28px;
127
+ /* A drag on the slider moves the thumb, not the page (pointer capture does not stop panning). */
128
+ touch-action: none;
129
+ }
130
+ :where(.bake-ui-slider-track) {
131
+ position: absolute;
132
+ left: 0;
133
+ right: 0;
134
+ top: 12px;
135
+ height: 4px;
136
+ border-radius: 2px;
137
+ background-color: rgba(120, 120, 128, 0.32);
138
+ }
139
+ :where(.bake-ui-slider-fill) {
140
+ position: absolute;
141
+ left: 0;
142
+ top: 12px;
143
+ height: 4px;
144
+ border-radius: 2px;
145
+ background-color: #007aff;
146
+ }
147
+ :where(.bake-ui-slider-thumb) {
148
+ position: absolute;
149
+ top: 2px;
150
+ width: 24px;
151
+ height: 24px;
152
+ margin-left: -12px;
153
+ box-sizing: border-box;
154
+ border: 1px solid rgba(0, 0, 0, 0.12);
155
+ border-radius: 12px;
156
+ background-color: #ffffff;
157
+ }
158
+
159
+ /* Picker: the field drawn here (the selected label and a chevron), a transparent select over it
160
+ for the platform's menu. */
161
+ :where(.bake-ui-picker) {
162
+ position: relative;
163
+ display: flex;
164
+ flex-direction: row;
165
+ align-items: center;
166
+ flex: none;
167
+ box-sizing: border-box;
168
+ height: 2.125rem;
169
+ padding: 0 10px;
170
+ gap: 10px;
171
+ border: 1px solid rgba(127, 127, 127, 0.32);
172
+ border-radius: 8px;
173
+ font-size: 0.9375rem;
174
+ line-height: 1.25rem;
175
+ }
176
+ :where(.bake-ui-chevron) {
177
+ display: block;
178
+ flex: none;
179
+ }
180
+ select:where(.bake-ui-picker-menu) {
181
+ position: absolute;
182
+ left: 0;
183
+ top: 0;
184
+ width: 100%;
185
+ height: 100%;
186
+ margin: 0;
187
+ opacity: 0;
188
+ }
189
+
190
+ input:where(.bake-ui-textinput),
191
+ textarea:where(.bake-ui-textinput) {
192
+ align-self: stretch;
193
+ box-sizing: border-box;
194
+ font-size: 0.9375rem;
195
+ line-height: 1.25rem;
196
+ padding: 7px 10px;
197
+ border-radius: 8px;
198
+ }
199
+
200
+ /* TabBar on web and Windows (ui/tab-bar.tsrx): a bar fixed to the bottom, and a spacer of its
201
+ height where it sits in the page. The bar comes after the page in the document, so it paints
202
+ over it (native paints in document order; no z-index). */
203
+ :where(.bake-ui-tabbar-space) {
204
+ height: 57px;
205
+ }
206
+ :where(.bake-ui-tabbar-space.bake-ui-unlabeled) {
207
+ height: 45px;
208
+ }
209
+ :where(.bake-ui-tabbar) {
210
+ position: fixed;
211
+ left: 0;
212
+ right: 0;
213
+ bottom: 0;
214
+ display: flex;
215
+ flex-direction: row;
216
+ box-sizing: border-box;
217
+ height: 57px;
218
+ padding: 6px 8px;
219
+ border-top: 1px solid rgba(127, 127, 127, 0.25);
220
+ background-color: #f9f9f9;
221
+ }
222
+ :where(.bake-ui-tabbar.bake-ui-unlabeled) {
223
+ height: 45px;
224
+ }
225
+ @media (prefers-color-scheme: dark) {
226
+ :where(.bake-ui-tabbar) {
227
+ background-color: #1c1c1e;
228
+ }
229
+ }
230
+ :where(.bake-ui-tab) {
231
+ position: relative;
232
+ flex: 1 1 0;
233
+ display: flex;
234
+ flex-direction: column;
235
+ align-items: center;
236
+ gap: 2px;
237
+ padding: 2px 0;
238
+ font-size: 11px;
239
+ line-height: 14px;
240
+ }
241
+ :where(.bake-ui-tab-label) {
242
+ align-self: stretch;
243
+ text-align: center;
244
+ }
245
+ :where(.bake-ui-tab-icon) {
246
+ display: block;
247
+ width: 24px;
248
+ height: 24px;
249
+ }
250
+ :where(.bake-ui-badge) {
251
+ position: absolute;
252
+ top: 0;
253
+ left: 50%;
254
+ margin-left: 6px;
255
+ min-width: 16px;
256
+ height: 16px;
257
+ padding: 0 4px;
258
+ box-sizing: border-box;
259
+ border-radius: 8px;
260
+ background-color: #ff3b30;
261
+ color: #ffffff;
262
+ font-size: 11px;
263
+ line-height: 16px;
264
+ text-align: center;
265
+ }
266
+
267
+ /* The web's textarea resize grabber (native text areas have none). */
268
+ @supports not (-bake-native: true) {
269
+ textarea:where(.bake-ui-textinput) {
270
+ resize: none;
271
+ }
272
+ }