@sigx/lynx-runtime-main 0.2.4

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.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Main Thread ops executor.
3
+ *
4
+ * Receives the flat-array ops buffer sent by the Background Thread via
5
+ * callLepusMethod('sigxPatchUpdate', { data: JSON.stringify(ops) }) and applies
6
+ * each operation using Lynx PAPI.
7
+ */
8
+ /**
9
+ * SharedValue bridge state — registered wvids and last-published snapshots.
10
+ * The op handlers (`OP.REGISTER_AV_BRIDGE` / `OP.UNREGISTER_AV_BRIDGE` below)
11
+ * mutate these collections; `animated-bridge-mt.ts:flushAvBridgePublishes`
12
+ * reads them on every flush boundary to compute the diff to publish to BG.
13
+ */
14
+ export declare const bridgedAvWvids: Set<number>;
15
+ export declare const bridgedAvLastValues: Map<number, unknown>;
16
+ export declare function setPlaceholder(parent: MainThreadElement, el: MainThreadElement): void;
17
+ export declare function applyOps(ops: unknown[]): void;
18
+ /** Reset module state — for testing and hot reload. */
19
+ export declare function resetMainThreadState(): void;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * MT-side runOnBackground — dispatches function calls from the Main Thread
3
+ * to the Background Thread via 'Lynx.Sigx.RunOnBackground' events.
4
+ *
5
+ * Called inside extracted worklet bodies on the Main Thread. The SWC LEPUS
6
+ * pass leaves bare `runOnBackground(_jsFnK)` references in the registered
7
+ * worklet body; we install this implementation as `globalThis.runOnBackground`
8
+ * from `entry-main.ts` so the bare identifier resolves at runtime.
9
+ *
10
+ * Mirrors @lynx-js/react/runtime/lib/worklet/call/runOnMainThread (the dual
11
+ * direction) and vue-lynx's run-on-background-mt.ts. Sigx-namespaced event
12
+ * types so we don't conflict with upstream's own bridge if it ships in the
13
+ * same lynx process.
14
+ */
15
+ interface JsFnHandle {
16
+ _jsFnId?: number;
17
+ _execId?: number;
18
+ _isFirstScreen?: boolean;
19
+ _error?: string;
20
+ }
21
+ export declare function runOnBackground(handle: JsFnHandle): (...args: unknown[]) => Promise<unknown>;
22
+ export declare function resetRunOnBackgroundMtState(): void;
23
+ export {};
@@ -0,0 +1,28 @@
1
+ interface GestureWorklet {
2
+ _wkltId: string;
3
+ _execId?: number;
4
+ _c?: Record<string, unknown>;
5
+ _jsFn?: Record<string, unknown>;
6
+ _workletType?: string;
7
+ }
8
+ interface BaseGesture {
9
+ __isSerialized: true;
10
+ type: number;
11
+ id: number;
12
+ callbacks: Record<string, GestureWorklet>;
13
+ waitFor?: BaseGesture[];
14
+ simultaneousWith?: BaseGesture[];
15
+ continueWith?: BaseGesture[];
16
+ config?: Record<string, unknown>;
17
+ }
18
+ interface ComposedGesture {
19
+ __isSerialized: true;
20
+ type: -1;
21
+ gestures: AnyGesture[];
22
+ }
23
+ type AnyGesture = BaseGesture | ComposedGesture;
24
+ interface GestureOptions {
25
+ domSet?: boolean;
26
+ }
27
+ export declare function processGesture(dom: MainThreadElement, gesture: AnyGesture | undefined, oldGesture: AnyGesture | undefined, isFirstScreen: boolean, gestureOptions?: GestureOptions): void;
28
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Helpers for invoking worklets from the BG → MT bridge.
3
+ *
4
+ * Most of the worklet machinery (registry, ref map, event dispatch) is owned
5
+ * by `@lynx-js/react/worklet-runtime`, which is side-effect-imported from
6
+ * `entry-main.ts`. That runtime installs `globalThis.lynxWorkletImpl`,
7
+ * `globalThis.registerWorkletInternal`, and `globalThis.runWorklet`. Lynx
8
+ * native dispatches MT-routed events directly into `runWorklet`.
9
+ *
10
+ * What sigx-lynx still needs to provide is the `runOnMainThread` BG → MT call
11
+ * path: BG ships `{ wkltId, args }` over `callLepusMethod('sigxRunOnMT')`, the
12
+ * MT bridge handler in `entry-main.ts` calls `invokeWorklet()` here, and we
13
+ * look up the function in upstream's `_workletMap`.
14
+ */
15
+ export interface WorkletPlaceholder {
16
+ _wkltId: string;
17
+ _c?: Record<string, unknown>;
18
+ }
19
+ /**
20
+ * Invoke a worklet by id with the given args. Used by the runOnMainThread
21
+ * bridge — event-driven worklets go through Lynx's native runWorklet path
22
+ * and never touch this function.
23
+ */
24
+ export declare function invokeWorklet(wkltId: string, captured: Record<string, unknown> | undefined, args: unknown[]): unknown;
25
+ /** Reset hook — for testing. The upstream worklet-runtime has its own state. */
26
+ export declare function resetWorkletEvents(): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Worklet ref registry — manages MainThreadRef state on the Main Thread.
3
+ *
4
+ * Each ref is identified by a worklet variable ID (wvid) assigned on the
5
+ * BG thread. When INIT_MT_REF arrives, we create a holder. When SET_MT_REF
6
+ * arrives, we set the holder's .current to the real element wrapper.
7
+ */
8
+ interface WorkletRefHolder {
9
+ current: unknown;
10
+ }
11
+ /**
12
+ * Initialize a worklet ref on the Main Thread.
13
+ * Called when the BG thread sends INIT_MT_REF(wvid, initValue).
14
+ */
15
+ export declare function initWorkletRef(wvid: number, initValue: unknown): void;
16
+ /**
17
+ * Bind a worklet ref to a Main Thread element.
18
+ * Called when the BG thread sends SET_MT_REF(elementId, wvid).
19
+ * The ref's .current is set to an MTElementWrapper around the real element.
20
+ */
21
+ export declare function bindWorkletRef(wvid: number, el: MainThreadElement): void;
22
+ /**
23
+ * Get a worklet ref holder by wvid — used by worklet event handlers
24
+ * to access refs.
25
+ */
26
+ export declare function getWorkletRef(wvid: number): WorkletRefHolder | undefined;
27
+ /**
28
+ * Reset all worklet refs — for testing and hot reload.
29
+ */
30
+ export declare function resetWorkletRefs(): void;
31
+ export {};
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@sigx/lynx-runtime-main",
3
+ "version": "0.2.4",
4
+ "description": "Main Thread (Lepus) entry and ops applier for SignalX Lynx renderer",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "sideEffects": true,
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./entry-main": {
15
+ "import": "./dist/entry-main.js",
16
+ "types": "./dist/entry-main.d.ts"
17
+ },
18
+ "./install-hybrid-worklet": {
19
+ "import": "./dist/install-hybrid-worklet.js",
20
+ "types": "./dist/install-hybrid-worklet.d.ts"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "keywords": [
28
+ "sigx",
29
+ "lynx",
30
+ "main-thread"
31
+ ],
32
+ "author": "Andreas Ekdahl",
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/signalxjs/lynx.git",
37
+ "directory": "packages/lynx-runtime-main"
38
+ },
39
+ "homepage": "https://github.com/signalxjs/lynx/tree/main/packages/lynx-runtime-main",
40
+ "bugs": {
41
+ "url": "https://github.com/signalxjs/lynx/issues"
42
+ },
43
+ "dependencies": {
44
+ "@lynx-js/react": "^0.120.0",
45
+ "@sigx/lynx-runtime-internal": "0.2.4"
46
+ },
47
+ "peerDependencies": {
48
+ "@lynx-js/types": ">=3.0.0"
49
+ },
50
+ "peerDependenciesMeta": {
51
+ "@lynx-js/types": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@lynx-js/types": "^3.7.0",
57
+ "@sigx/vite": "^0.4.3",
58
+ "typescript": "^6.0.3",
59
+ "vite": "^8.0.12"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ },
64
+ "scripts": {
65
+ "build": "vite build && tsgo --emitDeclarationOnly",
66
+ "dev": "vite build --watch"
67
+ }
68
+ }