chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
+160
View File
@@ -0,0 +1,160 @@
"use strict";
const EventEmitter = require("./vendor/eventemitter3");
const inject = ({ module: [id, code], sourceURL }) => {
if (global.globalEvalWithSourceUrl) {
global.globalEvalWithSourceUrl(code, sourceURL);
} else {
eval(code);
}
};
const injectUpdate = (update) => {
update.added.forEach(inject);
update.modified.forEach(inject);
};
class HMRClient extends EventEmitter {
_isEnabled = false;
_pendingUpdate = null;
_queue = [];
_state = "opening";
constructor(url) {
super();
this._ws = new global.WebSocket(url);
this._ws.onopen = () => {
this._state = "open";
this.emit("open");
this._flushQueue();
};
this._ws.onerror = (error) => {
this.emit("connection-error", error);
};
this._ws.onclose = (closeEvent) => {
this._state = "closed";
this.emit("close", closeEvent);
};
this._ws.onmessage = (message) => {
const data = JSON.parse(String(message.data));
switch (data.type) {
case "bundle-registered":
this.emit("bundle-registered");
break;
case "update-start":
this.emit("update-start", data.body);
break;
case "update":
this.emit("update", data.body);
break;
case "update-done":
this.emit("update-done");
break;
case "error":
this.emit("error", data.body);
break;
default:
this.emit("error", {
type: "unknown-message",
message: data,
});
}
};
this.on("update", (update) => {
if (this._isEnabled) {
injectUpdate(update);
} else if (this._pendingUpdate == null) {
this._pendingUpdate = update;
} else {
this._pendingUpdate = mergeUpdates(this._pendingUpdate, update);
}
});
}
close() {
this._ws.close();
}
send(message) {
switch (this._state) {
case "opening":
this._queue.push(message);
break;
case "open":
this._ws.send(message);
break;
case "closed":
break;
default:
throw new Error("[WebSocketHMRClient] Unknown state: " + this._state);
}
}
_flushQueue() {
this._queue.forEach((message) => this.send(message));
this._queue.length = 0;
}
enable() {
this._isEnabled = true;
const update = this._pendingUpdate;
this._pendingUpdate = null;
if (update != null) {
injectUpdate(update);
}
}
disable() {
this._isEnabled = false;
}
isEnabled() {
return this._isEnabled;
}
hasPendingUpdates() {
return this._pendingUpdate != null;
}
}
function mergeUpdates(base, next) {
const addedIDs = new Set();
const deletedIDs = new Set();
const moduleMap = new Map();
applyUpdateLocally(base);
applyUpdateLocally(next);
function applyUpdateLocally(update) {
update.deleted.forEach((id) => {
if (addedIDs.has(id)) {
addedIDs.delete(id);
} else {
deletedIDs.add(id);
}
moduleMap.delete(id);
});
update.added.forEach((item) => {
const id = item.module[0];
if (deletedIDs.has(id)) {
deletedIDs.delete(id);
} else {
addedIDs.add(id);
}
moduleMap.set(id, item);
});
update.modified.forEach((item) => {
const id = item.module[0];
moduleMap.set(id, item);
});
}
const result = {
isInitialUpdate: next.isInitialUpdate,
revisionId: next.revisionId,
added: [],
modified: [],
deleted: [],
};
deletedIDs.forEach((id) => {
result.deleted.push(id);
});
moduleMap.forEach((item, id) => {
if (deletedIDs.has(id)) {
return;
}
if (addedIDs.has(id)) {
result.added.push(item);
} else {
result.modified.push(item);
}
});
return result;
}
module.exports = HMRClient;
+207
View File
@@ -0,0 +1,207 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
'use strict';
import type {HmrModule} from './types';
import type {HmrMessage, HmrUpdate} from './types';
const EventEmitter = require('./vendor/eventemitter3');
type SocketState = 'opening' | 'open' | 'closed';
const inject = ({module: [id, code], sourceURL}: HmrModule) => {
// Some engines do not support `sourceURL` as a comment. We expose a
// `globalEvalWithSourceUrl` function to handle updates in that case.
if (global.globalEvalWithSourceUrl) {
global.globalEvalWithSourceUrl(code, sourceURL);
} else {
// eslint-disable-next-line no-eval
eval(code);
}
};
const injectUpdate = (update: HmrUpdate) => {
update.added.forEach(inject);
update.modified.forEach(inject);
};
class HMRClient extends EventEmitter {
_isEnabled: boolean = false;
_pendingUpdate: HmrUpdate | null = null;
_queue: Array<string> = [];
_state: SocketState = 'opening';
_ws: WebSocket;
constructor(url: string) {
super();
// Access the global WebSocket object only after enabling the client,
// since some polyfills do the initialization lazily.
this._ws = new global.WebSocket(url);
this._ws.onopen = () => {
this._state = 'open';
this.emit('open');
this._flushQueue();
};
this._ws.onerror = error => {
this.emit('connection-error', error);
};
this._ws.onclose = closeEvent => {
this._state = 'closed';
this.emit('close', closeEvent);
};
this._ws.onmessage = message => {
const data: HmrMessage = JSON.parse(String(message.data));
switch (data.type) {
case 'bundle-registered':
this.emit('bundle-registered');
break;
case 'update-start':
this.emit('update-start', data.body);
break;
case 'update':
this.emit('update', data.body);
break;
case 'update-done':
this.emit('update-done');
break;
case 'error':
this.emit('error', data.body);
break;
default:
this.emit('error', {type: 'unknown-message', message: data});
}
};
this.on('update', (update: HmrUpdate) => {
if (this._isEnabled) {
injectUpdate(update);
} else if (this._pendingUpdate == null) {
this._pendingUpdate = update;
} else {
this._pendingUpdate = mergeUpdates(this._pendingUpdate, update);
}
});
}
close(): void {
this._ws.close();
}
send(message: string): void {
switch (this._state) {
case 'opening':
this._queue.push(message);
break;
case 'open':
this._ws.send(message);
break;
case 'closed':
// Ignore.
break;
default:
throw new Error('[WebSocketHMRClient] Unknown state: ' + this._state);
}
}
_flushQueue(): void {
this._queue.forEach(message => this.send(message));
this._queue.length = 0;
}
enable() {
this._isEnabled = true;
const update = this._pendingUpdate;
this._pendingUpdate = null;
if (update != null) {
injectUpdate(update);
}
}
disable() {
this._isEnabled = false;
}
isEnabled(): boolean {
return this._isEnabled;
}
hasPendingUpdates(): boolean {
return this._pendingUpdate != null;
}
}
function mergeUpdates(base: HmrUpdate, next: HmrUpdate): HmrUpdate {
const addedIDs = new Set<number>();
const deletedIDs = new Set<number>();
const moduleMap = new Map<number, HmrModule>();
// Fill in the temporary maps and sets from both updates in their order.
applyUpdateLocally(base);
applyUpdateLocally(next);
function applyUpdateLocally(update: HmrUpdate) {
update.deleted.forEach(id => {
if (addedIDs.has(id)) {
addedIDs.delete(id);
} else {
deletedIDs.add(id);
}
moduleMap.delete(id);
});
update.added.forEach(item => {
const id = item.module[0];
if (deletedIDs.has(id)) {
deletedIDs.delete(id);
} else {
addedIDs.add(id);
}
moduleMap.set(id, item);
});
update.modified.forEach(item => {
const id = item.module[0];
moduleMap.set(id, item);
});
}
// Now reconstruct a unified update from our in-memory maps and sets.
// Applying it should be equivalent to applying both of them individually.
const result = {
isInitialUpdate: next.isInitialUpdate,
revisionId: next.revisionId,
added: ([]: Array<HmrModule>),
modified: ([]: Array<HmrModule>),
deleted: ([]: Array<number>),
};
deletedIDs.forEach(id => {
result.deleted.push(id);
});
moduleMap.forEach((item, id) => {
if (deletedIDs.has(id)) {
return;
}
if (addedIDs.has(id)) {
result.added.push(item);
} else {
result.modified.push(item);
}
});
return result;
}
module.exports = HMRClient;
+39
View File
@@ -0,0 +1,39 @@
"use strict";
function maybeLoadBundle(moduleID, paths) {
const loadBundle = global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`];
if (loadBundle != null) {
const stringModuleID = String(moduleID);
if (paths != null) {
const bundlePath = paths[stringModuleID];
if (bundlePath != null) {
return loadBundle(bundlePath);
}
}
}
return undefined;
}
function asyncRequireImpl(moduleID, paths) {
const maybeLoadBundlePromise = maybeLoadBundle(moduleID, paths);
const importAll = () => require.importAll(moduleID);
if (maybeLoadBundlePromise != null) {
return maybeLoadBundlePromise.then(importAll);
}
return importAll();
}
async function asyncRequire(moduleID, paths, moduleName) {
return asyncRequireImpl(moduleID, paths);
}
asyncRequire.unstable_importMaybeSync = function unstable_importMaybeSync(
moduleID,
paths,
) {
return asyncRequireImpl(moduleID, paths);
};
asyncRequire.prefetch = function (moduleID, paths, moduleName) {
maybeLoadBundle(moduleID, paths)?.then(
() => {},
() => {},
);
};
module.exports = asyncRequire;
@@ -0,0 +1,87 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
type MetroRequire = {
(number): mixed,
importAll: <T>(number) => T,
...
};
declare var require: MetroRequire;
type DependencyMapPaths = ?$ReadOnly<{[moduleID: number | string]: mixed}>;
declare var __METRO_GLOBAL_PREFIX__: string;
function maybeLoadBundle(
moduleID: number,
paths: DependencyMapPaths,
): void | Promise<void> {
const loadBundle: (bundlePath: mixed) => Promise<void> =
global[`${__METRO_GLOBAL_PREFIX__}__loadBundleAsync`];
if (loadBundle != null) {
const stringModuleID = String(moduleID);
if (paths != null) {
const bundlePath = paths[stringModuleID];
if (bundlePath != null) {
// NOTE: Errors will be swallowed by asyncRequire.prefetch
return loadBundle(bundlePath);
}
}
}
return undefined;
}
function asyncRequireImpl<T>(
moduleID: number,
paths: DependencyMapPaths,
): Promise<T> | T {
const maybeLoadBundlePromise = maybeLoadBundle(moduleID, paths);
const importAll = () => require.importAll<T>(moduleID);
if (maybeLoadBundlePromise != null) {
return maybeLoadBundlePromise.then(importAll);
}
return importAll();
}
async function asyncRequire<T>(
moduleID: number,
paths: DependencyMapPaths,
moduleName?: string, // unused
): Promise<T> {
return asyncRequireImpl<T>(moduleID, paths);
}
// Synchronous version of asyncRequire, which can still return a promise
// if the module is split.
asyncRequire.unstable_importMaybeSync = function unstable_importMaybeSync<T>(
moduleID: number,
paths: DependencyMapPaths,
): Promise<T> | T {
return asyncRequireImpl(moduleID, paths);
};
asyncRequire.prefetch = function (
moduleID: number,
paths: DependencyMapPaths,
moduleName?: string, // unused
): void {
maybeLoadBundle(moduleID, paths)?.then(
() => {},
() => {},
);
};
module.exports = asyncRequire;
@@ -0,0 +1 @@
"use strict";
@@ -0,0 +1,9 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict
*/
+3
View File
@@ -0,0 +1,3 @@
"use strict";
module.exports = null;
@@ -0,0 +1,11 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict
*/
module.exports = null;
+1
View File
@@ -0,0 +1 @@
"use strict";
+102
View File
@@ -0,0 +1,102 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
export type ModuleMap = $ReadOnlyArray<[number, string]>;
export type Bundle = {
+modules: ModuleMap,
+post: string,
+pre: string,
};
export type DeltaBundle = {
+added: ModuleMap,
+modified: ModuleMap,
+deleted: $ReadOnlyArray<number>,
};
export type BundleVariant =
| {+base: true, +revisionId: string, ...Bundle}
| {+base: false, +revisionId: string, ...DeltaBundle};
export type BundleMetadata = {
+pre: number,
+post: number,
+modules: $ReadOnlyArray<[number, number]>,
};
export type FormattedError = {
+type: string,
+message: string,
+errors: Array<{description: string, ...}>,
};
export type HmrModule = {
+module: [number, string],
+sourceMappingURL: string,
+sourceURL: string,
};
export type HmrUpdate = {
+added: $ReadOnlyArray<HmrModule>,
+deleted: $ReadOnlyArray<number>,
+isInitialUpdate: boolean,
+modified: $ReadOnlyArray<HmrModule>,
+revisionId: string,
};
export type HmrUpdateMessage = {
+type: 'update',
+body: HmrUpdate,
};
export type HmrErrorMessage = {
+type: 'error',
+body: FormattedError,
};
export type HmrClientMessage =
| {
+type: 'register-entrypoints',
+entryPoints: Array<string>,
}
| {
+type: 'log',
+level:
| 'trace'
| 'info'
| 'warn'
| 'log'
| 'group'
| 'groupCollapsed'
| 'groupEnd'
| 'debug',
+data: Array<mixed>,
}
| {
+type: 'log-opt-in',
};
export type HmrMessage =
| {
+type: 'bundle-registered',
}
| {
+type: 'update-start',
+body: {
+isInitialUpdate: boolean,
},
}
| {
+type: 'update-done',
}
| HmrUpdateMessage
| HmrErrorMessage;
@@ -0,0 +1,183 @@
"use strict";
var has = Object.prototype.hasOwnProperty,
prefix = "~";
function Events() {}
if (Object.create) {
Events.prototype = Object.create(null);
if (!new Events().__proto__) prefix = false;
}
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
function addListener(emitter, event, fn, context, once) {
if (typeof fn !== "function") {
throw new TypeError("The listener must be a function");
}
var listener = new EE(fn, context || emitter, once),
evt = prefix ? prefix + event : event;
if (!emitter._events[evt])
((emitter._events[evt] = listener), emitter._eventsCount++);
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
else emitter._events[evt] = [emitter._events[evt], listener];
return emitter;
}
function clearEvent(emitter, evt) {
if (--emitter._eventsCount === 0) emitter._events = new Events();
else delete emitter._events[evt];
}
function EventEmitter() {
this._events = new Events();
this._eventsCount = 0;
}
EventEmitter.prototype.eventNames = function eventNames() {
var names = [],
events,
name;
if (this._eventsCount === 0) return names;
for (name in (events = this._events)) {
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
}
if (Object.getOwnPropertySymbols) {
return names.concat(Object.getOwnPropertySymbols(events));
}
return names;
};
EventEmitter.prototype.listeners = function listeners(event) {
var evt = prefix ? prefix + event : event,
handlers = this._events[evt];
if (!handlers) return [];
if (handlers.fn) return [handlers.fn];
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
ee[i] = handlers[i].fn;
}
return ee;
};
EventEmitter.prototype.listenerCount = function listenerCount(event) {
var evt = prefix ? prefix + event : event,
listeners = this._events[evt];
if (!listeners) return 0;
if (listeners.fn) return 1;
return listeners.length;
};
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return false;
var listeners = this._events[evt],
len = arguments.length,
args,
i;
if (listeners.fn) {
if (listeners.once)
this.removeListener(event, listeners.fn, undefined, true);
switch (len) {
case 1:
return (listeners.fn.call(listeners.context), true);
case 2:
return (listeners.fn.call(listeners.context, a1), true);
case 3:
return (listeners.fn.call(listeners.context, a1, a2), true);
case 4:
return (listeners.fn.call(listeners.context, a1, a2, a3), true);
case 5:
return (listeners.fn.call(listeners.context, a1, a2, a3, a4), true);
case 6:
return (listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true);
}
for (i = 1, args = new Array(len - 1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners.fn.apply(listeners.context, args);
} else {
var length = listeners.length,
j;
for (i = 0; i < length; i++) {
if (listeners[i].once)
this.removeListener(event, listeners[i].fn, undefined, true);
switch (len) {
case 1:
listeners[i].fn.call(listeners[i].context);
break;
case 2:
listeners[i].fn.call(listeners[i].context, a1);
break;
case 3:
listeners[i].fn.call(listeners[i].context, a1, a2);
break;
case 4:
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
break;
default:
if (!args)
for (j = 1, args = new Array(len - 1); j < len; j++) {
args[j - 1] = arguments[j];
}
listeners[i].fn.apply(listeners[i].context, args);
}
}
}
return true;
};
EventEmitter.prototype.on = function on(event, fn, context) {
return addListener(this, event, fn, context, false);
};
EventEmitter.prototype.once = function once(event, fn, context) {
return addListener(this, event, fn, context, true);
};
EventEmitter.prototype.removeListener = function removeListener(
event,
fn,
context,
once,
) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return this;
if (!fn) {
clearEvent(this, evt);
return this;
}
var listeners = this._events[evt];
if (listeners.fn) {
if (
listeners.fn === fn &&
(!once || listeners.once) &&
(!context || listeners.context === context)
) {
clearEvent(this, evt);
}
} else {
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
if (
listeners[i].fn !== fn ||
(once && !listeners[i].once) ||
(context && listeners[i].context !== context)
) {
events.push(listeners[i]);
}
}
if (events.length)
this._events[evt] = events.length === 1 ? events[0] : events;
else clearEvent(this, evt);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
var evt;
if (event) {
evt = prefix ? prefix + event : event;
if (this._events[evt]) clearEvent(this, evt);
} else {
this._events = new Events();
this._eventsCount = 0;
}
return this;
};
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
EventEmitter.prefixed = prefix;
EventEmitter.EventEmitter = EventEmitter;
if ("undefined" !== typeof module) {
module.exports = EventEmitter;
}
@@ -0,0 +1,41 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
declare type ListenerFn = (...args: any[]) => mixed;
declare class EventEmitter {
static constructor(): EventEmitter;
static prefixed: string | boolean;
eventNames(): (string | Symbol)[];
listeners(event: string | Symbol): ListenerFn[];
listenerCount(event: string | Symbol): number;
on(event: string | Symbol, listener: ListenerFn, context?: any): this;
addListener(
event: string | Symbol,
listener: ListenerFn,
context?: any,
): this;
once(event: string | Symbol, listener: ListenerFn, context?: any): this;
removeAllListeners(event?: string | Symbol): this;
removeListener(
event: string | Symbol,
listener?: ListenerFn,
context?: any,
once?: boolean,
): this;
off(
event: string | Symbol,
listener?: ListenerFn,
context?: any,
once?: boolean,
): this;
emit(event: string, ...params?: any[]): this;
}
declare module.exports: Class<EventEmitter>;