@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.
- package/Cargo.lock +146 -0
- package/Cargo.toml +16 -0
- package/LICENSE +21 -0
- package/README.md +314 -2
- package/android/orbit.cmake +31 -0
- package/android/src/main/cpp/NativeOrbit.cpp +309 -0
- package/android/src/main/cpp/NativeOrbit.h +35 -0
- package/android/src/main/cpp/orbit_host.h +34 -0
- package/android/src/main/java/com/c9up/orbit/OrbitEffects.kt +286 -0
- package/android/src/main/java/com/c9up/orbit/OrbitHost.kt +258 -0
- package/android/src/main/java/com/c9up/orbit/OrbitImage.kt +346 -0
- package/android/src/main/java/com/c9up/orbit/OrbitInput.kt +145 -0
- package/android/src/main/java/com/c9up/orbit/OrbitPress.kt +110 -0
- package/android/src/main/java/com/c9up/orbit/OrbitVector.kt +115 -0
- package/android/src/main/java/com/c9up/orbit/OrbitViews.kt +362 -0
- package/crates/orbit-host/Cargo.toml +14 -0
- package/crates/orbit-host/src/gesture.rs +561 -0
- package/crates/orbit-host/src/lib.rs +1608 -0
- package/crates/orbit-host/src/motion.rs +328 -0
- package/crates/orbit-host/src/vector.rs +917 -0
- package/dist/color.d.ts +10 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +62 -0
- package/dist/color.js.map +1 -0
- package/dist/commit.d.ts +45 -0
- package/dist/commit.d.ts.map +1 -0
- package/dist/commit.js +172 -0
- package/dist/commit.js.map +1 -0
- package/dist/errors.d.ts +42 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -0
- package/dist/host.d.ts +49 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +18 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/motion.d.ts +18 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +66 -0
- package/dist/motion.js.map +1 -0
- package/dist/node.d.ts +46 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +110 -0
- package/dist/node.js.map +1 -0
- package/dist/pages.d.ts +56 -0
- package/dist/pages.d.ts.map +1 -0
- package/dist/pages.js +157 -0
- package/dist/pages.js.map +1 -0
- package/dist/react-native/index.d.ts +25 -0
- package/dist/react-native/index.d.ts.map +1 -0
- package/dist/react-native/index.js +43 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/server.d.ts +85 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +282 -0
- package/dist/server.js.map +1 -0
- package/dist/stack.d.ts +117 -0
- package/dist/stack.d.ts.map +1 -0
- package/dist/stack.js +299 -0
- package/dist/stack.js.map +1 -0
- package/dist/styles.d.ts +138 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +920 -0
- package/dist/styles.js.map +1 -0
- package/dist/template.d.ts +27 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +1392 -0
- package/dist/template.js.map +1 -0
- package/dist/url.d.ts +45 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +302 -0
- package/dist/url.js.map +1 -0
- package/package.json +90 -3
- package/scripts/build-android.sh +27 -0
- package/scripts/test-styles.mjs +31 -0
- package/specs/NativeOrbit.ts +34 -0
- package/src/color.ts +73 -0
- package/src/commit.ts +206 -0
- package/src/errors.ts +48 -0
- package/src/host.ts +92 -0
- package/src/index.ts +60 -0
- package/src/motion.ts +86 -0
- package/src/node.ts +133 -0
- package/src/pages.ts +210 -0
- package/src/react-native/index.ts +76 -0
- package/src/react-native/react-native.d.ts +31 -0
- package/src/server.ts +359 -0
- package/src/stack.ts +434 -0
- package/src/styles.ts +1024 -0
- package/src/template.ts +1657 -0
- package/src/url.ts +326 -0
package/src/url.ts
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A standard `URL` for the phone, installed when the platform's is not one.
|
|
3
|
+
*
|
|
4
|
+
* React Native's `URL` (0.87) parses with regular expressions: a relative
|
|
5
|
+
* reference is appended to the base (`new URL("/b", "https://h/a")` gives
|
|
6
|
+
* `https://h/a/b`), and `searchParams` is a copy that `search` never sees.
|
|
7
|
+
* photon's router — and any code an app shares with the browser — resolves
|
|
8
|
+
* links and builds queries through it. `installStandardUrl()` probes the
|
|
9
|
+
* global `URL` and, when it gets either wrong, puts this one in its place.
|
|
10
|
+
*
|
|
11
|
+
* Scope: hierarchical URLs (`http:`, `https:`, `ws:`, `wss:`, `file:`…)
|
|
12
|
+
* resolved as RFC 3986 says, parts read and written as WHATWG's `URL` does;
|
|
13
|
+
* an opaque one (`mailto:`, `tel:`, `blob:`) is kept as written.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const SCHEME = /^([a-zA-Z][a-zA-Z\d+.-]*):/;
|
|
17
|
+
const DEFAULT_PORTS: { [scheme: string]: string } = {
|
|
18
|
+
"http:": "80",
|
|
19
|
+
"https:": "443",
|
|
20
|
+
"ws:": "80",
|
|
21
|
+
"wss:": "443",
|
|
22
|
+
"ftp:": "21",
|
|
23
|
+
};
|
|
24
|
+
const SPECIAL = new Set(["http:", "https:", "ws:", "wss:", "ftp:", "file:"]);
|
|
25
|
+
|
|
26
|
+
interface Parts {
|
|
27
|
+
protocol: string;
|
|
28
|
+
username: string;
|
|
29
|
+
password: string;
|
|
30
|
+
hostname: string;
|
|
31
|
+
port: string;
|
|
32
|
+
pathname: string;
|
|
33
|
+
search: string;
|
|
34
|
+
hash: string;
|
|
35
|
+
/** An opaque URL (`mailto:x`): what follows the scheme, as written. */
|
|
36
|
+
opaque: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** RFC 3986 §5.2.4. */
|
|
40
|
+
function removeDotSegments(path: string): string {
|
|
41
|
+
const out: string[] = [];
|
|
42
|
+
const segments = path.split("/");
|
|
43
|
+
for (let i = 0; i < segments.length; i++) {
|
|
44
|
+
const segment = segments[i] ?? "";
|
|
45
|
+
const last = i === segments.length - 1;
|
|
46
|
+
if (segment === ".") {
|
|
47
|
+
if (last) out.push("");
|
|
48
|
+
} else if (segment === "..") {
|
|
49
|
+
if (out.length > 1) out.pop();
|
|
50
|
+
if (last) out.push("");
|
|
51
|
+
} else {
|
|
52
|
+
out.push(segment);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const joined = out.join("/");
|
|
56
|
+
return joined.startsWith("/") ? joined : `/${joined}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function splitTail(rest: string): {
|
|
60
|
+
path: string;
|
|
61
|
+
search: string;
|
|
62
|
+
hash: string;
|
|
63
|
+
} {
|
|
64
|
+
const hashAt = rest.indexOf("#");
|
|
65
|
+
const hash = hashAt >= 0 ? rest.slice(hashAt) : "";
|
|
66
|
+
const beforeHash = hashAt >= 0 ? rest.slice(0, hashAt) : rest;
|
|
67
|
+
const queryAt = beforeHash.indexOf("?");
|
|
68
|
+
const search = queryAt >= 0 ? beforeHash.slice(queryAt) : "";
|
|
69
|
+
const path = queryAt >= 0 ? beforeHash.slice(0, queryAt) : beforeHash;
|
|
70
|
+
return {
|
|
71
|
+
path,
|
|
72
|
+
search: search === "?" ? "" : search,
|
|
73
|
+
hash: hash === "#" ? "" : hash,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function parseAbsolute(input: string): Parts | null {
|
|
78
|
+
const scheme = SCHEME.exec(input);
|
|
79
|
+
if (scheme === null) return null;
|
|
80
|
+
const protocol = `${(scheme[1] ?? "").toLowerCase()}:`;
|
|
81
|
+
let rest = input.slice(scheme[0].length).replace(/\\/g, "/");
|
|
82
|
+
if (!SPECIAL.has(protocol) && !rest.startsWith("//")) {
|
|
83
|
+
return {
|
|
84
|
+
protocol,
|
|
85
|
+
username: "",
|
|
86
|
+
password: "",
|
|
87
|
+
hostname: "",
|
|
88
|
+
port: "",
|
|
89
|
+
pathname: rest,
|
|
90
|
+
search: "",
|
|
91
|
+
hash: "",
|
|
92
|
+
opaque: rest,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
rest = rest.replace(/^\/*/, "");
|
|
96
|
+
const end = rest.search(/[/?#]/);
|
|
97
|
+
const authority = end >= 0 ? rest.slice(0, end) : rest;
|
|
98
|
+
const tail = splitTail(end >= 0 ? rest.slice(end) : "");
|
|
99
|
+
const at = authority.lastIndexOf("@");
|
|
100
|
+
const userInfo = at >= 0 ? authority.slice(0, at) : "";
|
|
101
|
+
const hostPort = at >= 0 ? authority.slice(at + 1) : authority;
|
|
102
|
+
const colon = userInfo.indexOf(":");
|
|
103
|
+
const portMatch = /:(\d*)$/.exec(hostPort);
|
|
104
|
+
const hostname = (
|
|
105
|
+
portMatch ? hostPort.slice(0, portMatch.index) : hostPort
|
|
106
|
+
).toLowerCase();
|
|
107
|
+
if (hostname === "" && protocol !== "file:") return null;
|
|
108
|
+
const port = portMatch?.[1] ?? "";
|
|
109
|
+
return {
|
|
110
|
+
protocol,
|
|
111
|
+
username: colon >= 0 ? userInfo.slice(0, colon) : userInfo,
|
|
112
|
+
password: colon >= 0 ? userInfo.slice(colon + 1) : "",
|
|
113
|
+
hostname,
|
|
114
|
+
port: port === DEFAULT_PORTS[protocol] ? "" : port.replace(/^0+(?=\d)/, ""),
|
|
115
|
+
pathname: removeDotSegments(tail.path === "" ? "/" : tail.path),
|
|
116
|
+
search: tail.search,
|
|
117
|
+
hash: tail.hash,
|
|
118
|
+
opaque: null,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** RFC 3986 §5.2.2: `reference` against an absolute `base`. */
|
|
123
|
+
function resolve(reference: string, base: Parts): Parts | null {
|
|
124
|
+
const ref = reference.trim();
|
|
125
|
+
if (SCHEME.test(ref)) return parseAbsolute(ref);
|
|
126
|
+
if (base.opaque !== null) return null;
|
|
127
|
+
if (ref.startsWith("//") || ref.startsWith("\\\\")) {
|
|
128
|
+
return parseAbsolute(`${base.protocol}${ref}`);
|
|
129
|
+
}
|
|
130
|
+
const tail = splitTail(ref.replace(/\\/g, "/"));
|
|
131
|
+
const next: Parts = { ...base, hash: tail.hash };
|
|
132
|
+
if (tail.path === "") {
|
|
133
|
+
if (tail.search !== "" || ref.includes("?")) next.search = tail.search;
|
|
134
|
+
return next;
|
|
135
|
+
}
|
|
136
|
+
next.search = tail.search;
|
|
137
|
+
if (tail.path.startsWith("/")) {
|
|
138
|
+
next.pathname = removeDotSegments(tail.path);
|
|
139
|
+
} else {
|
|
140
|
+
const dir = base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1);
|
|
141
|
+
next.pathname = removeDotSegments(`${dir}${tail.path}`);
|
|
142
|
+
}
|
|
143
|
+
return next;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** A query whose changes reach the URL it belongs to, as WHATWG's does. */
|
|
147
|
+
class LinkedSearchParams extends URLSearchParams {
|
|
148
|
+
readonly #changed: (query: string) => void;
|
|
149
|
+
constructor(query: string, changed: (query: string) => void) {
|
|
150
|
+
super(query);
|
|
151
|
+
this.#changed = changed;
|
|
152
|
+
}
|
|
153
|
+
override append(name: string, value: string): void {
|
|
154
|
+
super.append(name, value);
|
|
155
|
+
this.#changed(this.toString());
|
|
156
|
+
}
|
|
157
|
+
override delete(name: string): void {
|
|
158
|
+
super.delete(name);
|
|
159
|
+
this.#changed(this.toString());
|
|
160
|
+
}
|
|
161
|
+
override set(name: string, value: string): void {
|
|
162
|
+
super.set(name, value);
|
|
163
|
+
this.#changed(this.toString());
|
|
164
|
+
}
|
|
165
|
+
override sort(): void {
|
|
166
|
+
super.sort();
|
|
167
|
+
this.#changed(this.toString());
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The platform's own `URL`, kept for its `createObjectURL` (blobs). */
|
|
172
|
+
type PlatformUrl = typeof URL;
|
|
173
|
+
|
|
174
|
+
let platformUrl: PlatformUrl | undefined;
|
|
175
|
+
|
|
176
|
+
export class StandardURL {
|
|
177
|
+
#parts: Parts;
|
|
178
|
+
#query: LinkedSearchParams | null = null;
|
|
179
|
+
|
|
180
|
+
static createObjectURL(blob: Blob): string {
|
|
181
|
+
if (platformUrl === undefined)
|
|
182
|
+
throw new TypeError("URL.createObjectURL is not available");
|
|
183
|
+
return platformUrl.createObjectURL(blob);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static revokeObjectURL(url: string): void {
|
|
187
|
+
platformUrl?.revokeObjectURL(url);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static canParse(url: string, base?: string | StandardURL): boolean {
|
|
191
|
+
try {
|
|
192
|
+
new StandardURL(url, base);
|
|
193
|
+
return true;
|
|
194
|
+
} catch {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
constructor(url: string | StandardURL, base?: string | StandardURL) {
|
|
200
|
+
const input = String(url);
|
|
201
|
+
let parts: Parts | null;
|
|
202
|
+
if (base === undefined) {
|
|
203
|
+
parts = parseAbsolute(input.trim());
|
|
204
|
+
} else {
|
|
205
|
+
const from =
|
|
206
|
+
base instanceof StandardURL
|
|
207
|
+
? base.#parts
|
|
208
|
+
: parseAbsolute(String(base).trim());
|
|
209
|
+
if (from === null)
|
|
210
|
+
throw new TypeError(`Invalid base URL: ${String(base)}`);
|
|
211
|
+
parts = resolve(input, from);
|
|
212
|
+
}
|
|
213
|
+
if (parts === null) throw new TypeError(`Invalid URL: ${input}`);
|
|
214
|
+
this.#parts = parts;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
get protocol(): string {
|
|
218
|
+
return this.#parts.protocol;
|
|
219
|
+
}
|
|
220
|
+
get username(): string {
|
|
221
|
+
return this.#parts.username;
|
|
222
|
+
}
|
|
223
|
+
get password(): string {
|
|
224
|
+
return this.#parts.password;
|
|
225
|
+
}
|
|
226
|
+
get hostname(): string {
|
|
227
|
+
return this.#parts.hostname;
|
|
228
|
+
}
|
|
229
|
+
get port(): string {
|
|
230
|
+
return this.#parts.port;
|
|
231
|
+
}
|
|
232
|
+
get host(): string {
|
|
233
|
+
const { hostname, port } = this.#parts;
|
|
234
|
+
return port === "" ? hostname : `${hostname}:${port}`;
|
|
235
|
+
}
|
|
236
|
+
get origin(): string {
|
|
237
|
+
const { protocol, opaque } = this.#parts;
|
|
238
|
+
if (opaque !== null || protocol === "file:") return "null";
|
|
239
|
+
return `${protocol}//${this.host}`;
|
|
240
|
+
}
|
|
241
|
+
get pathname(): string {
|
|
242
|
+
return this.#parts.pathname;
|
|
243
|
+
}
|
|
244
|
+
set pathname(value: string) {
|
|
245
|
+
if (this.#parts.opaque !== null) return;
|
|
246
|
+
this.#parts.pathname = removeDotSegments(
|
|
247
|
+
value.startsWith("/") ? value : `/${value}`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
get search(): string {
|
|
251
|
+
return this.#parts.search;
|
|
252
|
+
}
|
|
253
|
+
set search(value: string) {
|
|
254
|
+
const query = value.startsWith("?") ? value.slice(1) : value;
|
|
255
|
+
this.#parts.search = query === "" ? "" : `?${query}`;
|
|
256
|
+
this.#query = null;
|
|
257
|
+
}
|
|
258
|
+
get hash(): string {
|
|
259
|
+
return this.#parts.hash;
|
|
260
|
+
}
|
|
261
|
+
set hash(value: string) {
|
|
262
|
+
const fragment = value.startsWith("#") ? value.slice(1) : value;
|
|
263
|
+
this.#parts.hash = fragment === "" ? "" : `#${fragment}`;
|
|
264
|
+
}
|
|
265
|
+
get searchParams(): URLSearchParams {
|
|
266
|
+
if (this.#query === null) {
|
|
267
|
+
this.#query = new LinkedSearchParams(this.#parts.search, (query) => {
|
|
268
|
+
this.#parts.search = query === "" ? "" : `?${query}`;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
return this.#query;
|
|
272
|
+
}
|
|
273
|
+
get href(): string {
|
|
274
|
+
const { protocol, username, password, opaque, pathname, search, hash } =
|
|
275
|
+
this.#parts;
|
|
276
|
+
if (opaque !== null) return `${protocol}${opaque}`;
|
|
277
|
+
const credentials =
|
|
278
|
+
username === "" && password === ""
|
|
279
|
+
? ""
|
|
280
|
+
: `${username}${password === "" ? "" : `:${password}`}@`;
|
|
281
|
+
return `${protocol}//${credentials}${this.host}${pathname}${search}${hash}`;
|
|
282
|
+
}
|
|
283
|
+
toString(): string {
|
|
284
|
+
return this.href;
|
|
285
|
+
}
|
|
286
|
+
toJSON(): string {
|
|
287
|
+
return this.href;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Whether `Url` resolves references and links its query as the standard says. */
|
|
292
|
+
function isStandard(Url: PlatformUrl): boolean {
|
|
293
|
+
try {
|
|
294
|
+
if (
|
|
295
|
+
new Url("/b?x=1", "https://h.test/a/c").href !== "https://h.test/b?x=1"
|
|
296
|
+
) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
if (new Url("../d", "https://h.test/a/b/c").href !== "https://h.test/a/d") {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
const url = new Url("https://h.test/");
|
|
303
|
+
url.searchParams.append("q", "1");
|
|
304
|
+
return url.search === "?q=1";
|
|
305
|
+
} catch {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Put a standard `URL` in place of the platform's when the platform's is not
|
|
312
|
+
* one; true when it did. The platform's `createObjectURL` (blobs) stays
|
|
313
|
+
* reachable through the new one.
|
|
314
|
+
*/
|
|
315
|
+
export function installStandardUrl(): boolean {
|
|
316
|
+
const current: unknown = Reflect.get(globalThis, "URL");
|
|
317
|
+
if (typeof current !== "function") {
|
|
318
|
+
Reflect.set(globalThis, "URL", StandardURL);
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
const platform: PlatformUrl = Reflect.get(globalThis, "URL");
|
|
322
|
+
if (isStandard(platform)) return false;
|
|
323
|
+
platformUrl = platform;
|
|
324
|
+
Reflect.set(globalThis, "URL", StandardURL);
|
|
325
|
+
return true;
|
|
326
|
+
}
|