@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.
- package/LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.txt +548 -0
- package/bake-prelude.js +189 -0
- package/batch-contract.json +21 -0
- package/batch-wire.js +674 -0
- package/compat.json +64 -0
- package/controls.css +108 -0
- package/determinism.js +175 -0
- package/devtools.d.ts +13 -0
- package/devtools.js +73 -0
- package/dialogs.js +59 -0
- package/direct-style.js +105 -0
- package/direct-table.js +261 -0
- package/dist/bake.mjs +2211 -0
- package/dist/build-CMsvCcZ0.mjs +1 -0
- package/dist/build-CkLSZw06.mjs +5514 -0
- package/dist/build-tools-Dxyl6XAf.mjs +80 -0
- package/dist/client-Cm7o6dQd.mjs +17544 -0
- package/dist/compiler.mjs +4 -0
- package/dist/config-B1W8gfZY.mjs +12 -0
- package/dist/dev-Cskd8Hl4.mjs +986 -0
- package/dist/direct-report-Bdda-k_Y.mjs +153 -0
- package/dist/direct-report-Du44nNWl.mjs +1 -0
- package/dist/index.d.mts +176 -0
- package/dist/index.mjs +1 -0
- package/dist/intl-ROnAp2qO.mjs +75 -0
- package/dist/jiti-stub-CKcaShwE.mjs +5 -0
- package/dist/native-views-BuzB9x5H.mjs +7849 -0
- package/dist/octane/package.json +5 -0
- package/dist/package-KkUSMoji.mjs +2784 -0
- package/dist/react/package.json +13 -0
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/dist/run-D2aPm54a.mjs +6632 -0
- package/dist/scope-8W2aIuQ9.mjs +262 -0
- package/dist/screens/BakeNativeScreen.native.ts +9 -0
- package/dist/screens/package.json +5 -0
- package/dom-exception.js +31 -0
- package/element-api.js +158 -0
- package/first-screen.js +30 -0
- package/fonts/Geist-Italic-Variable.ttf +0 -0
- package/fonts/Geist-Variable.ttf +0 -0
- package/fonts/GeistMono-Italic-Variable.ttf +0 -0
- package/fonts/GeistMono-Variable.ttf +0 -0
- package/fonts/OFL.txt +93 -0
- package/fonts/README.md +27 -0
- package/fonts/geist-italic.css +8 -0
- package/fonts/geist-mono-italic.css +8 -0
- package/fonts/geist-mono.css +8 -0
- package/fonts/geist.css +8 -0
- package/header-icons.json +53 -0
- package/host-runtime.js +508 -0
- package/image-props.js +17 -0
- package/index.d.ts +8 -0
- package/index.js +7 -0
- package/licenses/Apache-2.0.txt +73 -0
- package/locale-entry.d.ts +1 -0
- package/locale-entry.js +1 -0
- package/locale.d.ts +28 -0
- package/locale.js +124 -0
- package/markup-support.js +87 -0
- package/media-element.js +115 -0
- package/native-args-entry.js +2 -0
- package/native-args.d.ts +7 -0
- package/native-args.js +155 -0
- package/native-entry.js +1 -0
- package/native-globals.d.ts +156 -0
- package/native-scenarios.d.ts +17 -0
- package/native-scenarios.js +46 -0
- package/native-support.json +349 -0
- package/native.d.ts +52 -0
- package/native.js +237 -0
- package/package.json +142 -4
- package/page-elements.js +123 -0
- package/runtime-provides.json +412 -0
- package/safe-area.d.ts +1 -0
- package/safe-area.js +44 -0
- package/swift-ui/modifiers.js +164 -0
- package/tab-icons.js +62 -0
- package/templates/create/tabs/AGENTS.md +22 -0
- package/templates/create/tabs/README.md +43 -0
- package/templates/create/tabs/_gitignore +13 -0
- package/templates/create/tabs/android/app/build.gradle.kts +79 -0
- package/templates/create/tabs/android/app/src/main/AndroidManifest.xml +39 -0
- package/templates/create/tabs/android/app/src/main/kotlin/MainActivity.kt +35 -0
- package/templates/create/tabs/android/app/src/main/res/values/themes.xml +8 -0
- package/templates/create/tabs/android/build.gradle.kts +5 -0
- package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/templates/create/tabs/android/gradle.properties +3 -0
- package/templates/create/tabs/android/gradlew +248 -0
- package/templates/create/tabs/android/settings.gradle.kts +47 -0
- package/templates/create/tabs/bake.config.ts +10 -0
- package/templates/create/tabs/ios/App/App.swift +30 -0
- package/templates/create/tabs/ios/build.sh +23 -0
- package/templates/create/tabs/ios/project.yml +57 -0
- package/templates/create/tabs/macos/Package.swift +24 -0
- package/templates/create/tabs/macos/Sources/__SWIFT_NAME__/App.swift +146 -0
- package/templates/create/tabs/macos/build.sh +4 -0
- package/templates/create/tabs/package.json +23 -0
- package/templates/create/tabs/pnpm-workspace.yaml +6 -0
- package/templates/create/tabs/src/App.tsrx +92 -0
- package/templates/create/tabs/src/App.tsx +67 -0
- package/templates/create/tabs/src/styles.css +32 -0
- package/templates/create/tabs/tsconfig.json +5 -0
- package/templates/create/tabs/windows/Cargo.toml +29 -0
- package/templates/create/tabs/windows/build.rs +9 -0
- package/templates/create/tabs/windows/src/main.rs +52 -0
- package/templates/create/tabs/windows/src/shell.rs +316 -0
- package/templates/module/__NAME__.kt +20 -0
- package/templates/module/__NAME__.native.ts +24 -0
- package/templates/module/__NAME__.swift +25 -0
- package/templates/module/__NAME__.web.ts +13 -0
- package/templates/module/__NAME__Test.kt +26 -0
- package/templates/module/__NAME__Tests.swift +25 -0
- package/templates/module/__SNAKE__.rs +43 -0
- package/text.d.ts +20 -0
- package/text.js +100 -0
- package/transform-entry.js +1 -0
- package/transform.d.ts +15 -0
- package/transform.js +98 -0
- package/tsconfig.native.json +16 -0
- package/ui/scope.js +103 -0
- package/ui/swift.js +106 -0
- package/ui/ui.css +272 -0
- package/view-ref-writer.js +268 -0
- package/view-ref.d.ts +26 -0
- package/view-ref.js +85 -0
- package/views/Video.native.ts +68 -0
- package/views/generated/VideoViewAndroid.h +68 -0
- package/views/generated/VideoViewJSI.h +94 -0
- package/views/generated/VideoViewSpec.kt +113 -0
- package/views/generated/apple/VideoViewJSI/VideoViewJSIApple.cpp +40 -0
- package/views/generated/apple/VideoViewJSI/include/VideoViewJSIApple.h +28 -0
- package/views/generated/apple/VideoViewSpec/VideoViewInterop.swift +39 -0
- package/views/generated/apple/VideoViewSpec/VideoViewSpec.swift +186 -0
- package/views/generated/video_view_spec.rs +189 -0
- package/views.d.ts +24 -0
- package/views.js +45 -0
- package/virtual-window.js +35 -0
- package/visibility.js +75 -0
- package/web-crypto.js +84 -0
- package/web-fetch.js +1071 -0
- package/README.md +0 -3
package/compat.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "The version table: which runtime, host protocol, Hermes bytecode, schemas and Octane this @bake-native/core release builds for, and the toolchain package each host installs (its bin/ tools, apps and libraries, and apple/: the prebuilt Apple runtime iOS and macOS apps link). bake build refuses any other combination (src/compat.ts); tools/check-versions.mjs keeps it equal to the Rust core, the Swift host, the Hermes pin and the toolchain packages. Change versions with tools/release/version.mjs.",
|
|
3
|
+
"@bake-native/core": "0.1.0-rc.0",
|
|
4
|
+
"runtime": {
|
|
5
|
+
"version": "0.1.0-rc.0",
|
|
6
|
+
"series": "0.1"
|
|
7
|
+
},
|
|
8
|
+
"hostProtocol": 4,
|
|
9
|
+
"minHostProtocol": 4,
|
|
10
|
+
"hermes": {
|
|
11
|
+
"commit": "f7b0b8632a926720a777564d1264c027a95bb49f",
|
|
12
|
+
"bytecode": 100
|
|
13
|
+
},
|
|
14
|
+
"schemaDigest": "0xa9dcbcdd1891d852",
|
|
15
|
+
"batchDigest": "0xd4c77b3d54621b67",
|
|
16
|
+
"octane": "0.27.1",
|
|
17
|
+
"toolchain": {
|
|
18
|
+
"darwin-arm64": {
|
|
19
|
+
"package": "@bake-native/toolchain-darwin-arm64",
|
|
20
|
+
"tools": [
|
|
21
|
+
"hermesc",
|
|
22
|
+
"bake-css-lint",
|
|
23
|
+
"bake-frame",
|
|
24
|
+
"bake-snap"
|
|
25
|
+
],
|
|
26
|
+
"apple": [
|
|
27
|
+
"BakeNative.xcframework.zip",
|
|
28
|
+
"runtime.json"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"darwin-x64": {
|
|
32
|
+
"package": "@bake-native/toolchain-darwin-x64",
|
|
33
|
+
"tools": [
|
|
34
|
+
"hermesc",
|
|
35
|
+
"bake-css-lint"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"linux-x64": {
|
|
39
|
+
"package": "@bake-native/toolchain-linux-x64",
|
|
40
|
+
"tools": [
|
|
41
|
+
"hermesc",
|
|
42
|
+
"bake-css-lint"
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"win32-x64": {
|
|
46
|
+
"package": "@bake-native/toolchain-win32-x64",
|
|
47
|
+
"tools": [
|
|
48
|
+
"hermesc",
|
|
49
|
+
"bake-css-lint",
|
|
50
|
+
"bake-frame"
|
|
51
|
+
],
|
|
52
|
+
"apps": [
|
|
53
|
+
"bakenative-app"
|
|
54
|
+
],
|
|
55
|
+
"libraries": [
|
|
56
|
+
"hermesvm.dll",
|
|
57
|
+
"bakenative_hermes.dll",
|
|
58
|
+
"msvcp140.dll",
|
|
59
|
+
"vcruntime140.dll",
|
|
60
|
+
"vcruntime140_1.dll"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
package/controls.css
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* BakeNative control baseline: imported first by every target (web + native).
|
|
2
|
+
|
|
3
|
+
Buttons and text fields look the same everywhere: renderers paint these boxes themselves,
|
|
4
|
+
and author CSS overrides them as usual. Opt into the platform's own button or field with
|
|
5
|
+
class="native": the baseline skips it, so the browser shows its control and the native
|
|
6
|
+
renderers show NSButton / UIButton / NSTextField / UITextField at their intrinsic size (CSS
|
|
7
|
+
padding, border and font do not apply there). Painting a background, border or radius on it
|
|
8
|
+
hands the box back to you.
|
|
9
|
+
|
|
10
|
+
Form controls (checkbox / switch, range, select, progress, meter, date / time, color) keep
|
|
11
|
+
their platform look: the browser's control on web, the system control on iOS and macOS.
|
|
12
|
+
`appearance: none` draws one as a plain CSS box. Multi-line fields have no native counterpart
|
|
13
|
+
and are always drawn.
|
|
14
|
+
|
|
15
|
+
Tests sit inside :where(), so every rule weighs what a bare `button` / `input` selector does
|
|
16
|
+
and author rules override it. */
|
|
17
|
+
button:where(:not(.native)) {
|
|
18
|
+
appearance: none;
|
|
19
|
+
-webkit-appearance: none;
|
|
20
|
+
font-family: inherit;
|
|
21
|
+
font-size: 0.875em;
|
|
22
|
+
line-height: normal;
|
|
23
|
+
color: inherit;
|
|
24
|
+
background-color: rgba(127, 127, 127, 0.16);
|
|
25
|
+
border: 1px solid rgba(127, 127, 127, 0.32);
|
|
26
|
+
border-radius: 6px;
|
|
27
|
+
padding: 4px 12px;
|
|
28
|
+
margin: 0;
|
|
29
|
+
}
|
|
30
|
+
input:where(:not(.native)):where(:not([type]), [type='text'], [type='search'], [type='email'], [type='password'],
|
|
31
|
+
[type='number'], [type='tel'], [type='url']),
|
|
32
|
+
textarea {
|
|
33
|
+
appearance: none;
|
|
34
|
+
-webkit-appearance: none;
|
|
35
|
+
font-family: inherit;
|
|
36
|
+
font-size: 0.875em;
|
|
37
|
+
line-height: normal;
|
|
38
|
+
color: inherit;
|
|
39
|
+
background-color: transparent;
|
|
40
|
+
border: 1px solid rgba(127, 127, 127, 0.32);
|
|
41
|
+
border-radius: 6px;
|
|
42
|
+
padding: 4px 8px;
|
|
43
|
+
margin: 0;
|
|
44
|
+
}
|
|
45
|
+
button:where(.native),
|
|
46
|
+
input:where(.native) {
|
|
47
|
+
margin: 0;
|
|
48
|
+
}
|
|
49
|
+
input:where([type='checkbox'], [type='range'], [type='date'], [type='time'], [type='datetime-local'], [type='color']),
|
|
50
|
+
select,
|
|
51
|
+
progress,
|
|
52
|
+
meter {
|
|
53
|
+
font-family: inherit;
|
|
54
|
+
font-size: 0.875em;
|
|
55
|
+
margin: 0;
|
|
56
|
+
}
|
|
57
|
+
/* @bake-native/octane/swift-ui: a Host is a block box (SwiftUI content inside; size it with CSS or
|
|
58
|
+
matchContents). */
|
|
59
|
+
swiftui-host {
|
|
60
|
+
display: block;
|
|
61
|
+
}
|
|
62
|
+
/* An open <dialog> is a bottom sheet: iOS and macOS present it as a SwiftUI sheet (the
|
|
63
|
+
platform draws the sheet's chrome, the dialog's children are your HTML); the browser shows the
|
|
64
|
+
same dialog pinned to the bottom of the viewport. */
|
|
65
|
+
dialog[open] {
|
|
66
|
+
/* Native lays the sheet out on its own; absolute is what it always used there (fixed is web only). */
|
|
67
|
+
position: absolute;
|
|
68
|
+
inset: auto 0 0 0;
|
|
69
|
+
box-sizing: border-box;
|
|
70
|
+
width: 100%;
|
|
71
|
+
max-width: 40rem;
|
|
72
|
+
max-height: 90vh;
|
|
73
|
+
margin: 0 auto;
|
|
74
|
+
/* Content past max-height scrolls: Windows and Android scroll the dialog as an inner scroll
|
|
75
|
+
container; the iOS and macOS sheets are as tall as the dialog's content, at most most of the
|
|
76
|
+
screen / window, and scroll it themselves. */
|
|
77
|
+
overflow: auto;
|
|
78
|
+
padding: 24px 20px 32px;
|
|
79
|
+
border: 0;
|
|
80
|
+
border-radius: 20px 20px 0 0;
|
|
81
|
+
background-color: Canvas;
|
|
82
|
+
color: CanvasText;
|
|
83
|
+
}
|
|
84
|
+
/* Web: pin the dialog to the bottom of the viewport. Native presents it as a sheet laid out on
|
|
85
|
+
its own (not in the page), which also draws its own shadow. */
|
|
86
|
+
@supports not (-bake-native: true) {
|
|
87
|
+
dialog[open] {
|
|
88
|
+
position: fixed;
|
|
89
|
+
z-index: 1000;
|
|
90
|
+
box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.25);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/* @bake-native/octane/ui: the native header is chrome, not page content. */
|
|
94
|
+
bake-header,
|
|
95
|
+
bake-tabbar {
|
|
96
|
+
display: none;
|
|
97
|
+
}
|
|
98
|
+
/* <details> / <summary>: tapping the summary opens and closes it on every target. No disclosure
|
|
99
|
+
marker (native draws no ::marker): draw your own, e.g. with details[open] > summary rules. */
|
|
100
|
+
summary {
|
|
101
|
+
display: block;
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
}
|
|
104
|
+
@supports not (-bake-native: true) {
|
|
105
|
+
summary::-webkit-details-marker {
|
|
106
|
+
display: none;
|
|
107
|
+
}
|
|
108
|
+
}
|
package/determinism.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// The time, randomness and locale environment of a root on the Rust runtime.
|
|
2
|
+
//
|
|
3
|
+
// `now()` is the root's injected clock in ms (`__bakeNow`: live, or driven by a test / agent
|
|
4
|
+
// through `bake_root_clock` / `inspect clock`). `det` is `__bakeDeterminism`, resolved by the runtime
|
|
5
|
+
// at open (native/rust/crates/bake-runtime/src/determinism.rs):
|
|
6
|
+
// { driven, startMs, seed, locale, timeZone, tzOffsetMin, intlTimeZone }
|
|
7
|
+
//
|
|
8
|
+
// - Date.now(), new Date() and performance.now() all read the injected clock. `startMs` pins the
|
|
9
|
+
// epoch time at clock 0 (driven default 2026-01-01T00:00:00Z); without it the epoch follows the
|
|
10
|
+
// wall clock (live).
|
|
11
|
+
// - `seed` makes Math.random a fixed sequence (mulberry32).
|
|
12
|
+
// - `tzOffsetMin` gives local-time Date methods a fixed offset (zones without DST only), on every
|
|
13
|
+
// target, with or without Intl. Without Intl (a Hermes built without it), toLocale*String uses
|
|
14
|
+
// one fixed en-US form.
|
|
15
|
+
// - `locale` / `intlTimeZone` become the defaults of Intl and the toLocale* methods where the
|
|
16
|
+
// engine has Intl (every Hermes target: docs/design/hermes-intl.md); `globalThis.__bakeLocale`
|
|
17
|
+
// either way.
|
|
18
|
+
//
|
|
19
|
+
// Plain module, no imports: host-runtime.js installs it before the app module runs, and
|
|
20
|
+
// determinism.test.mjs runs it under node.
|
|
21
|
+
|
|
22
|
+
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
23
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
24
|
+
// ISO date-time without an offset: local time (ES2015+). Date-only ISO strings stay UTC.
|
|
25
|
+
const LOCAL_ISO = /^[+-]?\d{4,6}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?$/;
|
|
26
|
+
|
|
27
|
+
const pad = (n, w = 2) => String(n).padStart(w, '0');
|
|
28
|
+
|
|
29
|
+
/** Math.random replacement: 32-bit state, [0, 1). */
|
|
30
|
+
export function mulberry32(seed) {
|
|
31
|
+
let a = seed >>> 0;
|
|
32
|
+
return function random() {
|
|
33
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
34
|
+
let t = a;
|
|
35
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
36
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
37
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function installDeterminism(g, now, det) {
|
|
42
|
+
det = det || {};
|
|
43
|
+
const RealDate = g.Date;
|
|
44
|
+
const P = RealDate.prototype;
|
|
45
|
+
const getTime = P.getTime;
|
|
46
|
+
const epoch = typeof det.startMs === 'number' ? det.startMs : RealDate.now() - now();
|
|
47
|
+
const dateNow = () => Math.floor(epoch + now());
|
|
48
|
+
const tz = typeof det.tzOffsetMin === 'number' ? det.tzOffsetMin * 60000 : null;
|
|
49
|
+
const parse = (s) => {
|
|
50
|
+
if (tz !== null && typeof s === 'string' && LOCAL_ISO.test(s)) return RealDate.parse(s + 'Z') - tz;
|
|
51
|
+
return RealDate.parse(s);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// `new Date()` / `Date()` read the injected clock; instances are ordinary Dates.
|
|
55
|
+
function BakeDate(...args) {
|
|
56
|
+
if (!(this instanceof BakeDate)) return new BakeDate().toString();
|
|
57
|
+
if (args.length === 0) return new RealDate(dateNow());
|
|
58
|
+
if (args.length === 1) {
|
|
59
|
+
const v = args[0];
|
|
60
|
+
if (typeof v === 'string') return new RealDate(parse(v));
|
|
61
|
+
return new RealDate(v instanceof RealDate ? getTime.call(v) : v);
|
|
62
|
+
}
|
|
63
|
+
if (tz === null) return new RealDate(...args);
|
|
64
|
+
return new RealDate(RealDate.UTC(...args) - tz);
|
|
65
|
+
}
|
|
66
|
+
BakeDate.prototype = P;
|
|
67
|
+
BakeDate.now = dateNow;
|
|
68
|
+
BakeDate.parse = parse;
|
|
69
|
+
BakeDate.UTC = RealDate.UTC;
|
|
70
|
+
Object.defineProperty(P, 'constructor', { value: BakeDate, writable: true, configurable: true });
|
|
71
|
+
g.Date = BakeDate;
|
|
72
|
+
(g.performance ??= {}).now = now;
|
|
73
|
+
|
|
74
|
+
if (typeof det.seed === 'number') g.Math.random = mulberry32(det.seed);
|
|
75
|
+
|
|
76
|
+
if (det.locale) {
|
|
77
|
+
g.__bakeLocale = det.locale;
|
|
78
|
+
if (g.navigator && typeof g.navigator === 'object') {
|
|
79
|
+
try {
|
|
80
|
+
Object.defineProperty(g.navigator, 'language', { value: det.locale, configurable: true });
|
|
81
|
+
Object.defineProperty(g.navigator, 'languages', { value: [det.locale], configurable: true });
|
|
82
|
+
} catch (e) {}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const hasIntl = typeof g.Intl !== 'undefined' && g.Intl && typeof g.Intl.DateTimeFormat === 'function';
|
|
87
|
+
|
|
88
|
+
if (tz !== null) {
|
|
89
|
+
const offsetMin = det.tzOffsetMin;
|
|
90
|
+
const shifted = (d) => new RealDate(getTime.call(d) + tz);
|
|
91
|
+
for (const name of ['FullYear', 'Month', 'Date', 'Day', 'Hours', 'Minutes', 'Seconds', 'Milliseconds']) {
|
|
92
|
+
const utcGet = P['getUTC' + name];
|
|
93
|
+
P['get' + name] = function () {
|
|
94
|
+
return utcGet.call(shifted(this));
|
|
95
|
+
};
|
|
96
|
+
if (name === 'Day') continue;
|
|
97
|
+
const utcSet = P['setUTC' + name];
|
|
98
|
+
P['set' + name] = function (...a) {
|
|
99
|
+
const s = shifted(this);
|
|
100
|
+
utcSet.apply(s, a);
|
|
101
|
+
return P.setTime.call(this, getTime.call(s) - tz);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
P.getTimezoneOffset = function () {
|
|
105
|
+
return isNaN(getTime.call(this)) ? NaN : -offsetMin;
|
|
106
|
+
};
|
|
107
|
+
const abs = Math.abs(offsetMin);
|
|
108
|
+
const gmt = 'GMT' + (offsetMin < 0 ? '-' : '+') + pad(Math.floor(abs / 60)) + pad(abs % 60);
|
|
109
|
+
const year = (y) => (y < 0 ? '-' + pad(-y, 6) : pad(y, 4));
|
|
110
|
+
const invalid = (d) => isNaN(getTime.call(d));
|
|
111
|
+
P.toDateString = function () {
|
|
112
|
+
if (invalid(this)) return 'Invalid Date';
|
|
113
|
+
return `${DAYS[this.getDay()]} ${MONTHS[this.getMonth()]} ${pad(this.getDate())} ${year(this.getFullYear())}`;
|
|
114
|
+
};
|
|
115
|
+
P.toTimeString = function () {
|
|
116
|
+
if (invalid(this)) return 'Invalid Date';
|
|
117
|
+
return `${pad(this.getHours())}:${pad(this.getMinutes())}:${pad(this.getSeconds())} ${gmt}`;
|
|
118
|
+
};
|
|
119
|
+
P.toString = function () {
|
|
120
|
+
if (invalid(this)) return 'Invalid Date';
|
|
121
|
+
return this.toDateString() + ' ' + this.toTimeString();
|
|
122
|
+
};
|
|
123
|
+
if (!hasIntl) {
|
|
124
|
+
// No Intl (a Hermes built without it): one fixed form instead of the engine's host-zone one.
|
|
125
|
+
P.toLocaleDateString = function () {
|
|
126
|
+
if (invalid(this)) return 'Invalid Date';
|
|
127
|
+
return `${this.getMonth() + 1}/${this.getDate()}/${this.getFullYear()}`;
|
|
128
|
+
};
|
|
129
|
+
P.toLocaleTimeString = function () {
|
|
130
|
+
if (invalid(this)) return 'Invalid Date';
|
|
131
|
+
const h = this.getHours();
|
|
132
|
+
return `${h % 12 || 12}:${pad(this.getMinutes())}:${pad(this.getSeconds())} ${h < 12 ? 'AM' : 'PM'}`;
|
|
133
|
+
};
|
|
134
|
+
P.toLocaleString = function () {
|
|
135
|
+
if (invalid(this)) return 'Invalid Date';
|
|
136
|
+
return this.toLocaleDateString() + ', ' + this.toLocaleTimeString();
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (hasIntl && (det.locale || det.intlTimeZone)) {
|
|
142
|
+
const I = g.Intl;
|
|
143
|
+
const locale = det.locale || undefined;
|
|
144
|
+
const zoned = (options) =>
|
|
145
|
+
det.intlTimeZone && !(options && options.timeZone) ? { ...options, timeZone: det.intlTimeZone } : options;
|
|
146
|
+
const wrap = (Ctor, withZone) => {
|
|
147
|
+
if (typeof Ctor !== 'function') return Ctor;
|
|
148
|
+
const W = function (locales, options) {
|
|
149
|
+
return new Ctor(locales ?? locale, withZone ? zoned(options) : options);
|
|
150
|
+
};
|
|
151
|
+
W.prototype = Ctor.prototype;
|
|
152
|
+
W.supportedLocalesOf = Ctor.supportedLocalesOf;
|
|
153
|
+
return W;
|
|
154
|
+
};
|
|
155
|
+
I.DateTimeFormat = wrap(I.DateTimeFormat, true);
|
|
156
|
+
for (const name of ['NumberFormat', 'Collator', 'PluralRules', 'RelativeTimeFormat', 'ListFormat']) {
|
|
157
|
+
if (I[name]) I[name] = wrap(I[name], false);
|
|
158
|
+
}
|
|
159
|
+
for (const name of ['toLocaleString', 'toLocaleDateString', 'toLocaleTimeString']) {
|
|
160
|
+
const orig = P[name];
|
|
161
|
+
P[name] = function (locales, options) {
|
|
162
|
+
return orig.call(this, locales ?? locale, zoned(options));
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const numberLocale = g.Number.prototype.toLocaleString;
|
|
166
|
+
g.Number.prototype.toLocaleString = function (locales, options) {
|
|
167
|
+
return numberLocale.call(this, locales ?? locale, options);
|
|
168
|
+
};
|
|
169
|
+
const compare = g.String.prototype.localeCompare;
|
|
170
|
+
g.String.prototype.localeCompare = function (that, locales, options) {
|
|
171
|
+
return compare.call(this, that, locales ?? locale, options);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return { dateNow, RealDate };
|
|
175
|
+
}
|
package/devtools.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @bake-native/octane/devtools: what an app shows `bake inspect`. See devtools.js.
|
|
2
|
+
|
|
3
|
+
/** JSON values only: what crosses the inspect transport. */
|
|
4
|
+
export type InspectJson = null | boolean | number | string | InspectJson[] | { [key: string]: InspectJson };
|
|
5
|
+
|
|
6
|
+
/** `bake inspect state [name...]` returns `{ [name]: get() }`. Returns a function that removes it. */
|
|
7
|
+
export function exposeState(name: string, get: () => unknown): () => void;
|
|
8
|
+
|
|
9
|
+
/** Called with the new locale when `bake inspect prefer --locale` changes it (null: the launch locale). */
|
|
10
|
+
export function onLocaleChange(fn: (locale: string | null) => void): () => void;
|
|
11
|
+
|
|
12
|
+
/** The locale in effect: the `prefer` override, else the launch locale. */
|
|
13
|
+
export function currentLocale(): string | null;
|
package/devtools.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @bake-native/octane/devtools: what an app shows `bake inspect`. Import it in the app; it costs
|
|
2
|
+
// nothing until something asks.
|
|
3
|
+
//
|
|
4
|
+
// exposeState(name, get) `bake inspect state [name...]` returns { name: get() } (JSON values);
|
|
5
|
+
// returns a function that removes it
|
|
6
|
+
// onLocaleChange(fn) `bake inspect prefer --locale ko-KR` calls fn('ko-KR') (null: back to
|
|
7
|
+
// the system locale); returns a function that unsubscribes
|
|
8
|
+
// currentLocale() the locale in effect (the override, else the launch locale)
|
|
9
|
+
//
|
|
10
|
+
// Native: the core calls `__bakeInspectState(names)` / `__bakePreferLocale(locale)` on the JS
|
|
11
|
+
// thread (debug cores only: a release core has no inspect transport and never calls them). Web:
|
|
12
|
+
// the same globals on `window`, for e2e fixtures (`browser.evaluate`). No other runtime cost.
|
|
13
|
+
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
const states = (g.__bakeStates ??= new Map());
|
|
16
|
+
const localeListeners = (g.__bakeLocaleListeners ??= new Set());
|
|
17
|
+
const launchLocale = g.__bakeLocale ?? g.navigator?.language ?? null;
|
|
18
|
+
let override = null;
|
|
19
|
+
|
|
20
|
+
/** Exposes `get()` as state `name` to `bake inspect state`. */
|
|
21
|
+
export function exposeState(name, get) {
|
|
22
|
+
if (typeof name !== 'string' || !/^[\w.$-]+$/.test(name)) throw new TypeError(`exposeState: not a state name: ${String(name)}`);
|
|
23
|
+
if (typeof get !== 'function') throw new TypeError('exposeState: get must be a function');
|
|
24
|
+
states.set(name, get);
|
|
25
|
+
return () => {
|
|
26
|
+
if (states.get(name) === get) states.delete(name);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** `fn(locale)` when `bake inspect prefer --locale` changes it. */
|
|
31
|
+
export function onLocaleChange(fn) {
|
|
32
|
+
localeListeners.add(fn);
|
|
33
|
+
return () => localeListeners.delete(fn);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function currentLocale() {
|
|
37
|
+
return override ?? launchLocale;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function snapshot(value) {
|
|
41
|
+
// JSON values only: what crosses the inspect transport. Functions / cycles are refused.
|
|
42
|
+
return JSON.parse(JSON.stringify(value === undefined ? null : value));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
g.__bakeInspectState = (names) => {
|
|
46
|
+
try {
|
|
47
|
+
const keys = names ?? [...states.keys()];
|
|
48
|
+
const out = {};
|
|
49
|
+
for (const key of keys) {
|
|
50
|
+
const get = states.get(key);
|
|
51
|
+
if (!get) return JSON.stringify({ error: `no state named ${key} (exposed: ${[...states.keys()].join(', ') || 'none'})` });
|
|
52
|
+
out[key] = snapshot(get());
|
|
53
|
+
}
|
|
54
|
+
return JSON.stringify({ state: out });
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return JSON.stringify({ error: `reading state failed: ${e && e.message ? e.message : String(e)}` });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
g.__bakePreferLocale = (locale) => {
|
|
61
|
+
override = locale ?? null;
|
|
62
|
+
const effective = currentLocale();
|
|
63
|
+
g.__bakeLocale = effective;
|
|
64
|
+
const nav = g.navigator;
|
|
65
|
+
if (nav && typeof nav === 'object' && effective) {
|
|
66
|
+
try {
|
|
67
|
+
Object.defineProperty(nav, 'language', { value: effective, configurable: true });
|
|
68
|
+
Object.defineProperty(nav, 'languages', { value: [effective], configurable: true });
|
|
69
|
+
} catch (e) {}
|
|
70
|
+
}
|
|
71
|
+
for (const fn of [...localeListeners]) fn(effective);
|
|
72
|
+
return true;
|
|
73
|
+
};
|
package/dialogs.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// `alert()` and `confirm()` on the native targets: the platform's system dialog (the built-in
|
|
2
|
+
// `native.BakeDialogs` module every host registers: UIAlertController, NSAlert, AlertDialog,
|
|
3
|
+
// MessageBox).
|
|
4
|
+
//
|
|
5
|
+
// Every shipped host runs Hermes on the UI thread, and a blocking call would need a nested modal
|
|
6
|
+
// loop that iOS and Android do not have. So on native these return a Promise: `await confirm(x)`
|
|
7
|
+
// gives the same boolean the web's blocking dialog does, and the build fails on a confirm() whose
|
|
8
|
+
// result is not awaited or returned (`if (confirm(x))`: a Promise is always truthy;
|
|
9
|
+
// global-confirm-sync) and on `.then` of either, which throws on the web (global-dialog-then;
|
|
10
|
+
// fail-closed.mjs).
|
|
11
|
+
//
|
|
12
|
+
// - One dialog at a time: calls made while one is shown wait their turn, in order.
|
|
13
|
+
// - A dismissal (back on Android, Escape on desktop) resolves as Cancel: confirm() gives false.
|
|
14
|
+
// - No window to present from (a closed root, an app without the built-in modules): resolves as
|
|
15
|
+
// Cancel at once and warns, so app code needs no try.
|
|
16
|
+
// - The bake records a first-render call as a read (bake-prelude.js), so a baked first screen never
|
|
17
|
+
// depends on a dialog.
|
|
18
|
+
//
|
|
19
|
+
// Bundled only when the app names `alert` or `confirm` (bake build, __BAKE_DIALOGS__); the bundle's
|
|
20
|
+
// manifest then requires the runtime global `dialogs` (compat.mjs).
|
|
21
|
+
|
|
22
|
+
/** Installs `g.alert` and `g.confirm` (Promise-returning). */
|
|
23
|
+
export function installDialogs(g) {
|
|
24
|
+
let tail = Promise.resolve();
|
|
25
|
+
const dialogs = () => g.native?.BakeDialogs;
|
|
26
|
+
|
|
27
|
+
/** Runs `call` after every dialog before it closed; `cancel` when there is nothing to show it in. */
|
|
28
|
+
const queue = (what, message, cancel) => {
|
|
29
|
+
const text = message === undefined ? '' : String(message);
|
|
30
|
+
const run = () => {
|
|
31
|
+
const module = dialogs();
|
|
32
|
+
if (typeof module?.[what] !== 'function') {
|
|
33
|
+
// bake build's layout preview has no host: nothing to warn about.
|
|
34
|
+
if (g.__bakeBakePreview !== true) g.console?.warn?.(`${what}(): this root has no system dialogs (BakeDialogs); resolving as Cancel`);
|
|
35
|
+
return cancel;
|
|
36
|
+
}
|
|
37
|
+
const failed = (e) => {
|
|
38
|
+
g.console?.warn?.(`${what}(): ${e?.message ?? e}; resolving as Cancel`);
|
|
39
|
+
return cancel;
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
return module[what](text).then((value) => (what === 'confirm' ? value === true : undefined), failed);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return failed(e);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const result = tail.then(run, run);
|
|
48
|
+
tail = result.then(() => undefined, () => undefined);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const define = (name, fn) => Object.defineProperty(g, name, { value: fn, writable: true, configurable: true, enumerable: false });
|
|
53
|
+
define('alert', function alert(message) {
|
|
54
|
+
return queue('alert', message, undefined);
|
|
55
|
+
});
|
|
56
|
+
define('confirm', function confirm(message) {
|
|
57
|
+
return queue('confirm', message, false);
|
|
58
|
+
});
|
|
59
|
+
}
|
package/direct-style.js
ADDED
|
@@ -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
|
+
}
|