@c9up/orbit 0.0.0-stage → 0.1.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 (95) hide show
  1. package/Cargo.lock +146 -0
  2. package/Cargo.toml +16 -0
  3. package/LICENSE +21 -0
  4. package/README.md +314 -2
  5. package/android/orbit.cmake +31 -0
  6. package/android/src/main/cpp/NativeOrbit.cpp +309 -0
  7. package/android/src/main/cpp/NativeOrbit.h +35 -0
  8. package/android/src/main/cpp/orbit_host.h +34 -0
  9. package/android/src/main/java/com/c9up/orbit/OrbitEffects.kt +286 -0
  10. package/android/src/main/java/com/c9up/orbit/OrbitHost.kt +258 -0
  11. package/android/src/main/java/com/c9up/orbit/OrbitImage.kt +346 -0
  12. package/android/src/main/java/com/c9up/orbit/OrbitInput.kt +145 -0
  13. package/android/src/main/java/com/c9up/orbit/OrbitPress.kt +110 -0
  14. package/android/src/main/java/com/c9up/orbit/OrbitVector.kt +115 -0
  15. package/android/src/main/java/com/c9up/orbit/OrbitViews.kt +362 -0
  16. package/crates/orbit-host/Cargo.toml +14 -0
  17. package/crates/orbit-host/src/gesture.rs +561 -0
  18. package/crates/orbit-host/src/lib.rs +1608 -0
  19. package/crates/orbit-host/src/motion.rs +328 -0
  20. package/crates/orbit-host/src/vector.rs +917 -0
  21. package/dist/color.d.ts +10 -0
  22. package/dist/color.d.ts.map +1 -0
  23. package/dist/color.js +62 -0
  24. package/dist/color.js.map +1 -0
  25. package/dist/commit.d.ts +45 -0
  26. package/dist/commit.d.ts.map +1 -0
  27. package/dist/commit.js +172 -0
  28. package/dist/commit.js.map +1 -0
  29. package/dist/errors.d.ts +42 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/errors.js +15 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/host.d.ts +49 -0
  34. package/dist/host.d.ts.map +1 -0
  35. package/dist/host.js +18 -0
  36. package/dist/host.js.map +1 -0
  37. package/dist/index.d.ts +29 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +29 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/motion.d.ts +18 -0
  42. package/dist/motion.d.ts.map +1 -0
  43. package/dist/motion.js +66 -0
  44. package/dist/motion.js.map +1 -0
  45. package/dist/node.d.ts +46 -0
  46. package/dist/node.d.ts.map +1 -0
  47. package/dist/node.js +110 -0
  48. package/dist/node.js.map +1 -0
  49. package/dist/pages.d.ts +56 -0
  50. package/dist/pages.d.ts.map +1 -0
  51. package/dist/pages.js +157 -0
  52. package/dist/pages.js.map +1 -0
  53. package/dist/react-native/index.d.ts +25 -0
  54. package/dist/react-native/index.d.ts.map +1 -0
  55. package/dist/react-native/index.js +43 -0
  56. package/dist/react-native/index.js.map +1 -0
  57. package/dist/server.d.ts +85 -0
  58. package/dist/server.d.ts.map +1 -0
  59. package/dist/server.js +282 -0
  60. package/dist/server.js.map +1 -0
  61. package/dist/stack.d.ts +117 -0
  62. package/dist/stack.d.ts.map +1 -0
  63. package/dist/stack.js +299 -0
  64. package/dist/stack.js.map +1 -0
  65. package/dist/styles.d.ts +138 -0
  66. package/dist/styles.d.ts.map +1 -0
  67. package/dist/styles.js +920 -0
  68. package/dist/styles.js.map +1 -0
  69. package/dist/template.d.ts +27 -0
  70. package/dist/template.d.ts.map +1 -0
  71. package/dist/template.js +1392 -0
  72. package/dist/template.js.map +1 -0
  73. package/dist/url.d.ts +45 -0
  74. package/dist/url.d.ts.map +1 -0
  75. package/dist/url.js +302 -0
  76. package/dist/url.js.map +1 -0
  77. package/package.json +90 -3
  78. package/scripts/build-android.sh +27 -0
  79. package/scripts/test-styles.mjs +31 -0
  80. package/specs/NativeOrbit.ts +34 -0
  81. package/src/color.ts +73 -0
  82. package/src/commit.ts +206 -0
  83. package/src/errors.ts +48 -0
  84. package/src/host.ts +92 -0
  85. package/src/index.ts +60 -0
  86. package/src/motion.ts +86 -0
  87. package/src/node.ts +133 -0
  88. package/src/pages.ts +210 -0
  89. package/src/react-native/index.ts +76 -0
  90. package/src/react-native/react-native.d.ts +31 -0
  91. package/src/server.ts +359 -0
  92. package/src/stack.ts +434 -0
  93. package/src/styles.ts +1024 -0
  94. package/src/template.ts +1657 -0
  95. package/src/url.ts +326 -0
package/dist/node.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The tree orbit keeps in JS: one node per native element, with the props
3
+ * the host lays out and draws. Signals write props straight into it; a commit
4
+ * sends only what changed (see `commit.ts`).
5
+ */
6
+ export type Style = {
7
+ [key: string]: string | number;
8
+ };
9
+ export type Props = {
10
+ [key: string]: unknown;
11
+ };
12
+ export type Handler = (type: string, payload: unknown) => void;
13
+ type Value<T> = T | (() => T);
14
+ /** Style as the host reads it: flattened, colours as ARGB integers. */
15
+ export declare function flatten(style: Style): Props;
16
+ export declare function setDirtyListener(listener: () => void): void;
17
+ /** A run of children that a reactive slot replaces wholesale. */
18
+ export declare class Region {
19
+ parent: NativeNode | null;
20
+ items: Child[];
21
+ set(items: Child[]): void;
22
+ }
23
+ export type Child = NativeNode | Region;
24
+ export declare class NativeNode {
25
+ readonly viewName: string;
26
+ props: Props;
27
+ readonly children: Child[];
28
+ readonly tag: number;
29
+ parent: NativeNode | null;
30
+ /** Props changed since the last commit, or null. */
31
+ pendingProps: Props | null;
32
+ /** Something below this node changed since the last commit. */
33
+ childrenDirty: boolean;
34
+ onEvent: Handler | null;
35
+ /** An image's bytes, sent to the host's memory with the next commit. */
36
+ pendingBytes: Uint8Array | null;
37
+ /** A scroll view's offset readers (dp), told on each native scroll. */
38
+ readonly scrollListeners: Array<(y: number) => void>;
39
+ constructor(viewName: string, props: Props, children: Child[]);
40
+ flatChildren(): NativeNode[];
41
+ setProps(patch: Props): void;
42
+ }
43
+ /** Raw text content, static or signal-backed: the effect patches only `text`. */
44
+ export declare function rawText(content: Value<string>): NativeNode;
45
+ export {};
46
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot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AC,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC,CAAM;gBAGhD,QAAQ,EAAE,MAAM,EAClB,KAAK,EAAE,KAAK,EACV,QAAQ,EAAE,KAAK,EAAE;IAK3B,YAAY,IAAI,UAAU,EAAE;IAI5B,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAO5B;AAED,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,UAAU,CAU1D"}
package/dist/node.js ADDED
@@ -0,0 +1,110 @@
1
+ import { effect } from "@c9up/aurora/core";
2
+ import { colorToArgb } from "./color.js";
3
+ const COLOR_KEYS = new Set([
4
+ "backgroundColor",
5
+ "color",
6
+ "borderColor",
7
+ "shadowColor",
8
+ "placeholderColor",
9
+ ]);
10
+ // Tags the host keys its views by. Even numbers from 2^30, out of the way of
11
+ // anything else that might share a surface.
12
+ let nextTag = 1 << 30;
13
+ function allocateTag() {
14
+ nextTag += 2;
15
+ return nextTag;
16
+ }
17
+ /** Style as the host reads it: flattened, colours as ARGB integers. */
18
+ export function flatten(style) {
19
+ const out = {};
20
+ for (const [key, value] of Object.entries(style)) {
21
+ out[key] =
22
+ COLOR_KEYS.has(key) && typeof value === "string"
23
+ ? colorToArgb(value)
24
+ : value;
25
+ }
26
+ return out;
27
+ }
28
+ /** Called whenever a node below `from` changed: the commit walks this path. */
29
+ let onDirty = () => { };
30
+ export function setDirtyListener(listener) {
31
+ onDirty = listener;
32
+ }
33
+ function markChildrenDirty(from) {
34
+ for (let p = from; p && !p.childrenDirty; p = p.parent)
35
+ p.childrenDirty = true;
36
+ onDirty();
37
+ }
38
+ /** A run of children that a reactive slot replaces wholesale. */
39
+ export class Region {
40
+ parent = null;
41
+ items = [];
42
+ set(items) {
43
+ this.items = items;
44
+ for (const item of items)
45
+ adopt(item, this.parent);
46
+ markChildrenDirty(this.parent);
47
+ }
48
+ }
49
+ function adopt(child, parent) {
50
+ child.parent = parent;
51
+ if (child instanceof Region)
52
+ for (const item of child.items)
53
+ adopt(item, parent);
54
+ }
55
+ function flattenInto(children, out) {
56
+ for (const child of children) {
57
+ if (child instanceof Region)
58
+ flattenInto(child.items, out);
59
+ else
60
+ out.push(child);
61
+ }
62
+ return out;
63
+ }
64
+ export class NativeNode {
65
+ viewName;
66
+ props;
67
+ children;
68
+ tag = allocateTag();
69
+ parent = null;
70
+ /** Props changed since the last commit, or null. */
71
+ pendingProps = null;
72
+ /** Something below this node changed since the last commit. */
73
+ childrenDirty = false;
74
+ onEvent = null;
75
+ /** An image's bytes, sent to the host's memory with the next commit. */
76
+ pendingBytes = null;
77
+ /** A scroll view's offset readers (dp), told on each native scroll. */
78
+ scrollListeners = [];
79
+ constructor(viewName, props, children) {
80
+ this.viewName = viewName;
81
+ this.props = props;
82
+ this.children = children;
83
+ for (const child of children)
84
+ adopt(child, this);
85
+ }
86
+ flatChildren() {
87
+ return flattenInto(this.children, []);
88
+ }
89
+ setProps(patch) {
90
+ Object.assign(this.props, patch);
91
+ this.pendingProps = this.pendingProps
92
+ ? Object.assign(this.pendingProps, patch)
93
+ : { ...patch };
94
+ markChildrenDirty(this.parent);
95
+ }
96
+ }
97
+ /** Raw text content, static or signal-backed: the effect patches only `text`. */
98
+ export function rawText(content) {
99
+ const raw = new NativeNode("RCTRawText", { text: "" }, []);
100
+ if (typeof content === "function") {
101
+ effect(() => raw.setProps({ text: content() }));
102
+ // The first run is the initial content, not a change to send.
103
+ raw.pendingProps = null;
104
+ }
105
+ else {
106
+ raw.props.text = content;
107
+ }
108
+ return raw;
109
+ }
110
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAazC,MAAM,UAAU,G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;QACX,OAAO,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC;IAED,QAAQ,CAAC,KAAY;QACpB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY;YACpC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC;YACzC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC;QAChB,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACD;AAED,iFAAiF;AACjF,MAAM,UAAU,OAAO,CAAC,OAAsB;IAC7C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC3D,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QAChD,8DAA8D;QAC9D,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC;IACzB,CAAC;SAAM,CAAC;QACP,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * `@c9up/orbit/pages` — pages the ream server drives, on the phone.
3
+ *
4
+ * The server stays the router: a link or a visit asks it for the next page
5
+ * object (photon's protocol, the one the browser speaks after `visits: true`)
6
+ * and the app shows the page it names — an aurora component bundled with the
7
+ * app — as a screen of a stack. The same controller answers the browser and
8
+ * the phone.
9
+ *
10
+ * run(() => html`${serverPages({
11
+ * server: 'https://app.example',
12
+ * pages: { Home, Orders, Order },
13
+ * })}`)
14
+ *
15
+ * photon's router does the protocol — visits, partial reloads, deferred
16
+ * props, the version check, history — and this is where it runs: requests to
17
+ * the server, a back stack in memory mirrored by the screens, the back button
18
+ * going through photon's history. A covered page keeps its state; going back
19
+ * shows it as it was, without a request.
20
+ */
21
+ import type { TemplateResult } from "@c9up/aurora/renderer";
22
+ import { type ServerConnection } from "./server.js";
23
+ import { type Stack, type StackOptions } from "./stack.js";
24
+ /**
25
+ * A page: an aurora component taking the page object's props. Declared as a
26
+ * method so a page typed with its own props (`{ orders: Order[] }`) is one.
27
+ */
28
+ type PageFunction = {
29
+ page(props: Record<string, unknown>): TemplateResult;
30
+ }["page"];
31
+ export interface ServerPagesOptions {
32
+ /**
33
+ * The ream server: its origin (https, or http to this machine through
34
+ * `adb reverse` or to the emulator's host `10.0.2.2`), or the connection
35
+ * `connectServer` made — the one comet and relay go through too.
36
+ */
37
+ server: string | ServerConnection;
38
+ /** The pages the server may name, by the name it renders them under. */
39
+ pages: {
40
+ [name: string]: PageFunction;
41
+ };
42
+ /** The first page's path. Default `/`. */
43
+ url?: string;
44
+ /** How screens change (`transition`, `duration`, `background`). */
45
+ stack?: Omit<StackOptions, "back">;
46
+ /** Shown until the first page has arrived. */
47
+ loading?: () => TemplateResult;
48
+ /** Shown when the server could not give a page; `retry` asks again. */
49
+ failed?: (error: unknown, retry: () => void) => TemplateResult;
50
+ /** A link off the server (another site, `mailto:`): the platform opens it. */
51
+ open?: (url: string) => void;
52
+ }
53
+ /** The stack the server's pages are shown in; put it in a template. */
54
+ export declare function serverPages(options: ServerPagesOptions): Stack;
55
+ export {};
56
+ //# sourceMappingURL=pages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAe,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAGxE;;;GAGG;AACH,KAAK,YAAY,GAAG;IACnB,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc,CAAC;CACrD,CAAC,MAAM,CAAC,CAAC;AAEV,MAAM,WAAW,kBAAkB;IAClC;;;;OAIG;IACH,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAClC,wEAAwE;IACxE,KAAK,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAC;IACxC,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,KAAK,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACnC,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,cAAc,CAAC;IAC/B,uEAAuE;IACvE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,cAAc,CAAC;IAC/D,8EAA8E;IAC9E,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7B;AAoBD,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,KAAK,CA+H9D"}
package/dist/pages.js ADDED
@@ -0,0 +1,157 @@
1
+ /**
2
+ * `@c9up/orbit/pages` — pages the ream server drives, on the phone.
3
+ *
4
+ * The server stays the router: a link or a visit asks it for the next page
5
+ * object (photon's protocol, the one the browser speaks after `visits: true`)
6
+ * and the app shows the page it names — an aurora component bundled with the
7
+ * app — as a screen of a stack. The same controller answers the browser and
8
+ * the phone.
9
+ *
10
+ * run(() => html`${serverPages({
11
+ * server: 'https://app.example',
12
+ * pages: { Home, Orders, Order },
13
+ * })}`)
14
+ *
15
+ * photon's router does the protocol — visits, partial reloads, deferred
16
+ * props, the version check, history — and this is where it runs: requests to
17
+ * the server, a back stack in memory mirrored by the screens, the back button
18
+ * going through photon's history. A covered page keeps its state; going back
19
+ * shows it as it was, without a request.
20
+ */
21
+ import { html } from "@c9up/aurora/core";
22
+ import { bootPage, router, } from "@c9up/photon/client/core";
23
+ import { OrbitError } from "./errors.js";
24
+ import { connectServer } from "./server.js";
25
+ import { createStack } from "./stack.js";
26
+ import { setLinkHandler } from "./template.js";
27
+ /** What photon hands back from `resolveComponent`: one of `pages`, a function. */
28
+ function isPage(value) {
29
+ return typeof value === "function";
30
+ }
31
+ const Loading = () => html `<div class="flex-1"></div>`;
32
+ const Failed = (error, retry) => html `<div class="flex-1 items-center justify-center gap-4 p-6">
33
+ <p class="text-center">${error instanceof Error ? error.message : String(error)}</p>
34
+ <button class="rounded-md border px-4 py-2" @click=${retry}>Retry</button>
35
+ </div>`;
36
+ /** The stack the server's pages are shown in; put it in a template. */
37
+ export function serverPages(options) {
38
+ const server = typeof options.server === "string"
39
+ ? connectServer(options.server)
40
+ : options.server;
41
+ const origin = server.origin;
42
+ const first = server.url(options.url ?? "/");
43
+ const failed = options.failed ?? Failed;
44
+ let entries = [{ state: null, url: first }];
45
+ let restore;
46
+ /** The page a visit rendered, waiting for photon to say how it goes in history. */
47
+ let pending = null;
48
+ /** The back button asked photon for the previous entry. */
49
+ let popping = false;
50
+ const current = () => {
51
+ const entry = entries.at(-1);
52
+ if (entry === undefined)
53
+ throw new Error("[orbit] server pages: empty history");
54
+ return entry;
55
+ };
56
+ const absolute = (url) => new URL(url, current().url).href;
57
+ const stack = createStack(options.loading ?? Loading, {
58
+ ...options.stack,
59
+ back: () => {
60
+ if (entries.length < 2 || restore === undefined)
61
+ return false;
62
+ entries.pop();
63
+ popping = true;
64
+ restore(current().state);
65
+ return true;
66
+ },
67
+ });
68
+ /** The visit's page goes in as photon wrote it in history. */
69
+ const place = (how) => {
70
+ const next = pending;
71
+ pending = null;
72
+ if (next === null)
73
+ return;
74
+ if (how === "push")
75
+ stack.push(next.page, next.props);
76
+ else
77
+ stack.replaceInPlace(next.page, next.props);
78
+ };
79
+ const host = {
80
+ href: () => current().url,
81
+ baseUri: () => current().url,
82
+ // The connection refuses another origin, sends the session cookie and
83
+ // keeps the XSRF token the server sets.
84
+ fetch: (url, init) => server.fetch(absolute(url), init),
85
+ state: () => current().state,
86
+ push: (state, url) => {
87
+ entries.push({ state, url: absolute(url) });
88
+ place("push");
89
+ },
90
+ replace: (state, url) => {
91
+ entries[entries.length - 1] = { state, url: absolute(url) };
92
+ place("replace");
93
+ },
94
+ load: (url) => start(absolute(url)),
95
+ reload: () => start(current().url),
96
+ emit: () => { },
97
+ cookie: (name) => (name === "XSRF-TOKEN" ? server.xsrf() : undefined),
98
+ memoryHistory: true,
99
+ listen: (wire) => {
100
+ restore = wire.restore;
101
+ },
102
+ };
103
+ const adapter = {
104
+ update(page, props) {
105
+ if (!isPage(page))
106
+ return;
107
+ if (popping) {
108
+ // The covered screen is the page coming back, as it was left.
109
+ popping = false;
110
+ stack.pop();
111
+ return;
112
+ }
113
+ pending = { page, props };
114
+ },
115
+ unmount() { },
116
+ };
117
+ const resolveComponent = async (name) => {
118
+ const page = Object.hasOwn(options.pages, name)
119
+ ? options.pages[name]
120
+ : undefined;
121
+ if (page === undefined) {
122
+ throw new OrbitError("E_ORBIT_UNKNOWN_PAGE", `[orbit] the server named the page "${name}", which this app does not have`);
123
+ }
124
+ return { default: page };
125
+ };
126
+ /** A first load of `url`: the history starts again from its page. */
127
+ function start(url) {
128
+ entries = [{ state: null, url }];
129
+ pending = null;
130
+ popping = false;
131
+ bootPage({
132
+ host,
133
+ url,
134
+ resolveComponent,
135
+ mount: async (_target, page, data) => {
136
+ if (isPage(page))
137
+ stack.reset(page, data.props);
138
+ return adapter;
139
+ },
140
+ }).catch((error) => {
141
+ stack.reset(() => failed(error, () => start(url)), undefined);
142
+ });
143
+ }
144
+ setLinkHandler((href) => {
145
+ const url = absolute(href);
146
+ if (new URL(url).origin === origin) {
147
+ const target = new URL(url);
148
+ void router.visit(target.pathname + target.search + target.hash);
149
+ }
150
+ else {
151
+ options.open?.(url);
152
+ }
153
+ });
154
+ start(first);
155
+ return stack;
156
+ }
157
+ //# sourceMappingURL=pages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages.js","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EACN,QAAQ,EAGR,MAAM,GACN,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,WAAW,EAAiC,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA+B/C,kFAAkF;AAClF,SAAS,MAAM,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACpC,CAAC;AAED,MAAM,OAAO,GAAG,GAAmB,EAAE,CAAC,IAAI,CAAA,4BAA4B,CAAC;AAEvE,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,KAAiB,EAAkB,EAAE,CACpE,IAAI,CAAA;2BACsB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;uDAC1B,KAAK;QACpD,CAAC;AAOT,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,OAA2B;IACtD,MAAM,MAAM,GACX,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;QACjC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;QAC/B,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACnB,MAAM,MAAM,GAAG,MAAM,C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9up/orbit/react-native";
5
+ * import { App } from "./App.js";
6
+ * run(App);
7
+ *
8
+ * React Native supplies the JS engine, the JSI module registry and the
9
+ * activity; nothing of React is used. `run` registers the app under the name
10
+ * the activity `ream android:*` generates starts, gives orbit its native host
11
+ * and the app's style table, and mounts the root component with the launch
12
+ * props (intent extras). The
13
+ * back button and the back gesture pop the innermost shown stack; with none
14
+ * to pop, the app goes back as any Android app does. React Native's `URL` is
15
+ * replaced by a standard one when it is not one (see `url.ts`).
16
+ */
17
+ import type { TemplateResult } from "@c9up/aurora/renderer";
18
+ /** The name the generated activity starts the app by. */
19
+ export declare const APP_NAME = "main";
20
+ export type LaunchProps = {
21
+ [key: string]: unknown;
22
+ };
23
+ /** Register `root` as the app and mount it when the activity starts. */
24
+ export declare function run(root: (props: LaunchProps) => TemplateResult): void;
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react-native/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAsB5D,yDAAyD;AACzD,eAAO,MAAM,QAAQ,SAAS,CAAC;AAE/B,MAAM,MAAM,WAAW,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAmBrD,wEAAwE;AACxE,wBAAgB,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,cAAc,GAAG,IAAI,CActE"}
@@ -0,0 +1,43 @@
1
+ // The app's style table: `ream android:*` compiles the app's Tailwind build
2
+ // into it and Metro serves it under this name.
3
+ import styles from "@c9up/orbit-styles";
4
+ import { AppRegistry, BackHandler, Dimensions, TurboModuleRegistry, } from "react-native";
5
+ import { OrbitError } from "../errors.js";
6
+ import { NATIVE_MODULE_NAME, useHost } from "../host.js";
7
+ import { goBack } from "../stack.js";
8
+ import { useStyles } from "../styles.js";
9
+ import { mount } from "../template.js";
10
+ import { installStandardUrl } from "../url.js";
11
+ // Before the app's own modules run: React Native's URL resolves a relative
12
+ // reference by appending it to the base, and photon's router (and any code
13
+ // shared with the browser) needs the standard one.
14
+ installStandardUrl();
15
+ /** The name the generated activity starts the app by. */
16
+ export const APP_NAME = "main";
17
+ const METHODS = [
18
+ "setViewport",
19
+ "commit",
20
+ "imageBytes",
21
+ "layout",
22
+ "scroll",
23
+ "setEventHandler",
24
+ ];
25
+ function isOrbitHost(value) {
26
+ return (typeof value === "object" &&
27
+ value !== null &&
28
+ METHODS.every((name) => typeof Reflect.get(value, name) === "function"));
29
+ }
30
+ /** Register `root` as the app and mount it when the activity starts. */
31
+ export function run(root) {
32
+ AppRegistry.registerRunnable(APP_NAME, ({ initialProps }) => {
33
+ const host = TurboModuleRegistry.getEnforcing(NATIVE_MODULE_NAME);
34
+ if (!isOrbitHost(host)) {
35
+ throw new OrbitError("E_ORBIT_NO_HOST", `[orbit] the ${NATIVE_MODULE_NAME} module is not orbit's native host: is the app built by ream android:build?`);
36
+ }
37
+ useHost(host);
38
+ useStyles(styles);
39
+ BackHandler.addEventListener("hardwareBackPress", goBack);
40
+ mount(root(initialProps ?? {}), { viewport: Dimensions.get("window") });
41
+ });
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react-native/index.ts"],"names":[],"mappings":"AAiBA,4EAA4E;AAC5E,+CAA+C;AAC/C,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EACN,WAAW,EACX,WAAW,EACX,UAAU,EACV,mBAAmB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAkB,OAAO,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,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AC,EAAE,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The app's ream server, as one connection: what pages, comet calls and relay
3
+ * subscriptions all go through on the phone.
4
+ *
5
+ * const server = connectServer('https://app.example')
6
+ * serverPages({ server, pages })
7
+ * const rpc = createRpcClient({ url: server.url('/rpc'), transport: server.json })
8
+ * configureRelay({
9
+ * sseUrl: server.url('/__relay/events'),
10
+ * subscribeUrl: server.url('/__relay/subscribe'),
11
+ * unsubscribeUrl: server.url('/__relay/unsubscribe'),
12
+ * stream: server.stream,
13
+ * fetch: server.fetch,
14
+ * })
15
+ *
16
+ * A browser gets this from the page for free: one origin, its cookies sent
17
+ * along, the `XSRF-TOKEN` cookie readable by the page, an `EventSource`. An
18
+ * app has none of it, so the connection gives each: requests to the server's
19
+ * origin only, with the session cookie (React Native sends cookies only with
20
+ * `credentials: 'include'`), the `XSRF-TOKEN` the server set echoed on every
21
+ * mutation, and server-sent events read from React Native's streaming XHR.
22
+ */
23
+ export interface ServerConnection {
24
+ /** The server's origin (`https://app.example`). */
25
+ readonly origin: string;
26
+ /** `path` on the server, absolute. */
27
+ url(path: string): string;
28
+ /**
29
+ * A request to the server: refused for another origin, carrying the
30
+ * session cookie and, on a mutation, the `X-XSRF-TOKEN` the server's
31
+ * `XSRF-TOKEN` cookie set.
32
+ */
33
+ fetch(url: string, init?: RequestInit): Promise<Response>;
34
+ /**
35
+ * POST `body` as JSON and resolve the JSON answer (nothing for a 204): the
36
+ * shape of comet's `RpcTransport`.
37
+ */
38
+ json(url: string, body: unknown, options?: {
39
+ signal?: AbortSignal;
40
+ }): Promise<unknown>;
41
+ /** A server-sent event stream at `url`: what relay's `stream` option takes. */
42
+ stream(url: string): ServerEventStream;
43
+ /** The `XSRF-TOKEN` the server set last, if any. */
44
+ xsrf(): string | undefined;
45
+ /**
46
+ * Send `Authorization: Bearer <token>` with every request and stream from
47
+ * now on (`null` stops): an API's token, which — unlike a browser's
48
+ * `EventSource` — the phone can send on server-sent events too.
49
+ */
50
+ authorize(token: string | null): void;
51
+ }
52
+ /** Connect to the app's ream server: https, or http to this machine or the emulator's host. */
53
+ export declare function connectServer(server: string): ServerConnection;
54
+ /** A server-sent event: its type, data and id, as an `EventSource`'s `MessageEvent` carries them. */
55
+ export interface ServerEvent {
56
+ readonly type: string;
57
+ readonly data?: string;
58
+ readonly lastEventId?: string;
59
+ }
60
+ type Listener = (event: ServerEvent) => void;
61
+ /**
62
+ * Server-sent events over XHR — what `EventSource` does, where there is
63
+ * none (React Native): the stream is read as it arrives, parsed as the
64
+ * HTML standard says (`event:`, `data:`, `id:`, `retry:`, comments), each
65
+ * event dispatched under its type; a dropped connection dispatches `error`
66
+ * and reconnects after `retry` ms with `Last-Event-ID`. An answer that is
67
+ * not a 200 `text/event-stream` fails the stream for good (`error`, no
68
+ * reconnect), as `EventSource` does.
69
+ */
70
+ export declare class ServerEventStream {
71
+ #private;
72
+ static readonly CONNECTING = 0;
73
+ static readonly OPEN = 1;
74
+ static readonly CLOSED = 2;
75
+ readonly url: string;
76
+ readyState: number;
77
+ constructor(url: string, headers?: () => Record<string, string>, options?: {
78
+ credentials?: boolean;
79
+ });
80
+ addEventListener(type: string, listener: Listener): void;
81
+ removeEventListener(type: string, listener: Listener): void;
82
+ close(): void;
83
+ }
84
+ export {};
85
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,WAAW,gBAAgB;IAChC,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sCAAsC;IACtC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OA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