@sigx/lynx 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/LICENSE +21 -0
- package/README.md +112 -0
- package/jsx-dev-runtime.ts +1 -0
- package/jsx-runtime.ts +1 -0
- package/package.json +30 -0
- package/src/index.ts +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Andreas Ekdahl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# @sigx/lynx
|
|
2
|
+
|
|
3
|
+
Public framework barrel for [SignalX](https://github.com/signalxjs) on Lynx. This is the package you import from in app code — it re-exports everything from `@sigx/reactivity`, `@sigx/runtime-core`, and `@sigx/runtime-lynx` under one namespace.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sigx/lynx
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import {
|
|
13
|
+
signal, effect, computed, batch, // reactivity
|
|
14
|
+
component, defineApp, onMounted, // runtime-core
|
|
15
|
+
useMainThreadRef, runOnMainThread, // main-thread scripting
|
|
16
|
+
runOnBackground, // BG-thread bridge
|
|
17
|
+
useSharedValue, useScrollViewOffset, // cross-thread state
|
|
18
|
+
useAnimatedStyle, // MT style bindings
|
|
19
|
+
type MainThread, type Define,
|
|
20
|
+
} from '@sigx/lynx';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## What's inside
|
|
24
|
+
|
|
25
|
+
| Surface | From | Use for |
|
|
26
|
+
| ---------------------- | -------------------------- | ------------------------------------------------------------- |
|
|
27
|
+
| `signal`, `effect`, `computed`, `batch`, `untrack`, `watch`, `effectScope` | `@sigx/reactivity` | Reactive state and computations on the BG thread. |
|
|
28
|
+
| `component`, `defineApp`, `defineDirective`, `onMounted`, `onUnmounted`, `onUpdated`, `onCreated`, `provide`/`inject` | `@sigx/runtime-core` | Component model, lifecycle, dependency injection. |
|
|
29
|
+
| `useMainThreadRef`, `MainThreadRef` | `@sigx/runtime-lynx` | Refs whose `.current` value lives on the main UI thread. |
|
|
30
|
+
| `runOnMainThread`, `runOnBackground`, `transformToWorklet` | `@sigx/runtime-lynx` | Cross-thread function calls. |
|
|
31
|
+
| `useSharedValue`, `SharedValue`, `SharedValueState` | `@sigx/runtime-lynx` | **The cross-thread primitive** — MT-writable, BG-observable values (see below). |
|
|
32
|
+
| `useAnimatedStyle` | `@sigx/runtime-lynx` | Bind an element style to a `SharedValue` via a named mapper (linear or range-mapped), applied on MT every flush. |
|
|
33
|
+
| `OP`, `pushOp`, `scheduleFlush`, `takeOps`, `flushNow` | `@sigx/runtime-lynx` | Lower-level op-queue access for runtime authors. |
|
|
34
|
+
| `registerBgSink`, `unregisterBgSink`, `ingestAvPublishes` | `@sigx/runtime-lynx` | Lower-level SharedValue bridge primitives (the building blocks under `useSharedValue`). |
|
|
35
|
+
| `MainThread`, `Define`, `ViewAttributes`, etc. | `@sigx/runtime-lynx` | JSX type annotations. |
|
|
36
|
+
|
|
37
|
+
For touch handling and gesture components (`<Pressable>`, `<Draggable>`, `<Swipeable>`), install [`@sigx/gestures`](../gestures) on top. For spring/tween animation drivers, install [`@sigx/motion`](../motion).
|
|
38
|
+
|
|
39
|
+
## SharedValue — the cross-thread primitive
|
|
40
|
+
|
|
41
|
+
`useSharedValue<T>(initial)` returns a value you can **write from a main-thread worklet** and **read reactively from the background thread**.
|
|
42
|
+
|
|
43
|
+
It's not animation-specific. `SharedValue` is a general "fast state lives on the other thread" primitive. Animation, gestures, scroll, sensors, layout — they're all parallel customers of the same bridge.
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { useSharedValue } from '@sigx/lynx';
|
|
47
|
+
import { Draggable } from '@sigx/gestures';
|
|
48
|
+
|
|
49
|
+
const tx = useSharedValue(0);
|
|
50
|
+
|
|
51
|
+
<Draggable translateX={tx} />
|
|
52
|
+
<text>x = {tx.value}px</text> // BG-reactive, updates per drag frame
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The MT side mutates `tx.current.value` from inside a `'main thread'` worklet (zero-latency). On every `__FlushElementTree` boundary, the runtime diffs registered values and dispatches a single batched event to the BG thread, where each value lands in a sigx `signal`. A BG `effect(() => sv.value)` re-runs reactively without injecting BG into the gesture hot path.
|
|
56
|
+
|
|
57
|
+
### Customers of the bridge
|
|
58
|
+
|
|
59
|
+
| Customer | What it provides | Built on |
|
|
60
|
+
| --- | --- | --- |
|
|
61
|
+
| Animation | `withSpring`, `withTiming`, `animate` | `@sigx/motion` |
|
|
62
|
+
| Gestures | `<Pressable>`, `<Draggable>`, `<Swipeable>` | `@sigx/gestures` |
|
|
63
|
+
| Scroll | `<ScrollView offsetY={sv} offsetX={sv}>` | `@sigx/gestures` |
|
|
64
|
+
| Style bindings | `useAnimatedStyle(elRef, sv, mapperName, params)` | `@sigx/lynx` |
|
|
65
|
+
|
|
66
|
+
### Scroll-driven UI example
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import {
|
|
70
|
+
useSharedValue, useAnimatedStyle, useMainThreadRef,
|
|
71
|
+
type MainThread,
|
|
72
|
+
} from '@sigx/lynx';
|
|
73
|
+
import { ScrollView } from '@sigx/gestures';
|
|
74
|
+
|
|
75
|
+
const scrollY = useSharedValue(0);
|
|
76
|
+
const heroRef = useMainThreadRef<MainThread.Element | null>(null);
|
|
77
|
+
|
|
78
|
+
// Parallax: as scroll goes 0 → 300, the hero translates 0 → -150 px.
|
|
79
|
+
useAnimatedStyle(heroRef, scrollY, 'translateY', {
|
|
80
|
+
inputRange: [0, 300],
|
|
81
|
+
outputRange: [0, -150],
|
|
82
|
+
extrapolate: 'clamp',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
<ScrollView offsetY={scrollY}>
|
|
86
|
+
<view main-thread:ref={heroRef}><image src={hero} /></view>
|
|
87
|
+
<text>Body…</text>
|
|
88
|
+
<text>Scroll position (BG-reactive): {scrollY.value.toFixed(0)}px</text>
|
|
89
|
+
</ScrollView>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Scroll → `<ScrollView>`'s internal MT worklet writes `scrollY.current.value` → flush triggers `useAnimatedStyle`'s mapper and applies the transform → MT publishes the diff to BG → `<text>` updates reactively. End-to-end, never crosses to BG inside the scroll hot path. The user just passes a `SharedValue` — same shape as `<Draggable translateX={tx}>`.
|
|
93
|
+
|
|
94
|
+
### What this is not
|
|
95
|
+
|
|
96
|
+
- **Not bidirectional.** Writes from BG (`sv.value = 100`) are no-op'd with a dev warning. Authoritative state lives on MT; BG observes. A bidirectional bridge would be a larger design and isn't currently scoped.
|
|
97
|
+
|
|
98
|
+
### Differentiator
|
|
99
|
+
|
|
100
|
+
Neither vue-lynx nor react-lynx ships a BG-observable MT value. React-lynx's `MainThreadRef.current` *throws* on BG; framer-motion-style libraries store animation state in MT-only refs. The diff/publish bridge in `@sigx/runtime-lynx` is what makes `effect(() => sv.value)` work — a primitive unique to sigx-lynx as of 2026-04.
|
|
101
|
+
|
|
102
|
+
### Deprecation note
|
|
103
|
+
|
|
104
|
+
Prior to Phase 2.8, `SharedValue` / `useSharedValue` were named `AnimatedValue` / `useAnimatedValue`. The old names still work via deprecated re-exports for one minor cycle. Migrate at your convenience.
|
|
105
|
+
|
|
106
|
+
## Build pipeline
|
|
107
|
+
|
|
108
|
+
The `'main thread'` directive transform that powers main-thread event handlers is provided by [`@sigx/lynx-plugin`](../lynx-plugin) — register it in your rspack/rspeedy config.
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { jsxDEV, Fragment } from '@sigx/runtime-core';
|
package/jsx-runtime.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { jsx, jsxs, Fragment } from '@sigx/runtime-core';
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sigx/lynx",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "sigx-lynx framework — meta-package re-exporting @sigx/reactivity + @sigx/runtime-core + @sigx/runtime-lynx",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./jsx-runtime": "./jsx-runtime.ts",
|
|
11
|
+
"./jsx-dev-runtime": "./jsx-dev-runtime.ts"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"jsx-runtime.ts",
|
|
16
|
+
"jsx-dev-runtime.ts"
|
|
17
|
+
],
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@sigx/reactivity": "^0.4.1",
|
|
20
|
+
"@sigx/runtime-lynx": "^0.2.4",
|
|
21
|
+
"@sigx/runtime-core": "^0.4.1"
|
|
22
|
+
},
|
|
23
|
+
"author": "Andreas Ekdahl",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/viewti/core.git",
|
|
28
|
+
"directory": "packages/lynx"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="@sigx/runtime-lynx" />
|
|
2
|
+
// Side-effect import: registers lynxMount as the default mount, installs
|
|
3
|
+
// the platform model processor, augments PlatformTypes with ShadowElement,
|
|
4
|
+
// and adds the global JSX intrinsic element types for <view>, <text>, etc.
|
|
5
|
+
import '@sigx/runtime-lynx';
|
|
6
|
+
|
|
7
|
+
// Re-export the public surface so users only need a single import:
|
|
8
|
+
//
|
|
9
|
+
// import { component, signal, defineApp, type Define } from '@sigx/lynx';
|
|
10
|
+
//
|
|
11
|
+
// Mirrors the layering of `sigx` (web meta) and `@sigx/terminal` (terminal meta).
|
|
12
|
+
export * from '@sigx/reactivity';
|
|
13
|
+
export * from '@sigx/runtime-core';
|
|
14
|
+
export * from '@sigx/runtime-lynx';
|