@vsreact/core 0.0.2 → 0.0.3
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/dist/animation.d.ts +19 -0
- package/dist/animation.js +43 -0
- package/dist/controls.d.ts +85 -2
- package/dist/controls.js +89 -11
- package/dist/cx.d.ts +6 -0
- package/dist/cx.js +26 -0
- package/dist/hooks.d.ts +8 -0
- package/dist/hooks.js +15 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -3
- package/dist/theme.js +76 -1
- package/dist/tw.js +4 -0
- package/package.json +1 -1
- package/src/animation.test.tsx +56 -1
- package/src/animation.ts +71 -0
- package/src/controls.test.tsx +131 -0
- package/src/controls.tsx +352 -19
- package/src/cx.ts +33 -0
- package/src/hooks.ts +18 -0
- package/src/index.ts +50 -24
- package/src/theme.ts +76 -1
- package/src/tw.test.ts +26 -0
- package/src/tw.ts +4 -0
package/dist/animation.d.ts
CHANGED
|
@@ -17,3 +17,22 @@ export interface TweenOptions {
|
|
|
17
17
|
/** Eased progress 0→1 that starts when the component mounts. */
|
|
18
18
|
export declare function useTween({ duration, delay, easing, onComplete }: TweenOptions): number;
|
|
19
19
|
export declare function lerp(from: number, to: number, t: number): number;
|
|
20
|
+
export interface SpringOptions {
|
|
21
|
+
/** Spring constant — higher snaps faster. Default 170. */
|
|
22
|
+
stiffness?: number;
|
|
23
|
+
/** Velocity drag — higher settles with less bounce. Default 24. */
|
|
24
|
+
damping?: number;
|
|
25
|
+
mass?: number;
|
|
26
|
+
/** Distance from target below which the spring snaps and stops. */
|
|
27
|
+
restDelta?: number;
|
|
28
|
+
}
|
|
29
|
+
/** One semi-implicit Euler integration step; exported for tests and for
|
|
30
|
+
driving springs from your own loops. Returns [position, velocity]. */
|
|
31
|
+
export declare function springStep(position: number, velocity: number, target: number, { stiffness, damping, mass }: SpringOptions, dtMs: number): [number, number];
|
|
32
|
+
/**
|
|
33
|
+
* A value that springs toward `target` whenever it changes — for
|
|
34
|
+
* interactive motion where a fixed-duration tween feels wrong (toggle
|
|
35
|
+
* thumbs, drawers, meters chasing levels). Runs on the host timer like
|
|
36
|
+
* useTween; starts at rest on the initial target.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useSpring(target: number, options?: SpringOptions): number;
|
package/dist/animation.js
CHANGED
|
@@ -45,3 +45,46 @@ export function useTween({ duration, delay = 0, easing = Easing.outCubic, onComp
|
|
|
45
45
|
export function lerp(from, to, t) {
|
|
46
46
|
return from + (to - from) * t;
|
|
47
47
|
}
|
|
48
|
+
/** One semi-implicit Euler integration step; exported for tests and for
|
|
49
|
+
driving springs from your own loops. Returns [position, velocity]. */
|
|
50
|
+
export function springStep(position, velocity, target, { stiffness = 170, damping = 24, mass = 1 }, dtMs) {
|
|
51
|
+
const dt = dtMs / 1000;
|
|
52
|
+
const acceleration = (-stiffness * (position - target) - damping * velocity) / mass;
|
|
53
|
+
const v = velocity + acceleration * dt;
|
|
54
|
+
return [position + v * dt, v];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A value that springs toward `target` whenever it changes — for
|
|
58
|
+
* interactive motion where a fixed-duration tween feels wrong (toggle
|
|
59
|
+
* thumbs, drawers, meters chasing levels). Runs on the host timer like
|
|
60
|
+
* useTween; starts at rest on the initial target.
|
|
61
|
+
*/
|
|
62
|
+
export function useSpring(target, options = {}) {
|
|
63
|
+
const [value, setValue] = useState(target);
|
|
64
|
+
const state = useRef({ position: target, velocity: 0 });
|
|
65
|
+
const targetRef = useRef(target);
|
|
66
|
+
targetRef.current = target;
|
|
67
|
+
const optionsRef = useRef(options);
|
|
68
|
+
optionsRef.current = options;
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const restDelta = optionsRef.current.restDelta ?? 0.001;
|
|
71
|
+
if (Math.abs(state.current.position - targetRef.current) <= restDelta &&
|
|
72
|
+
Math.abs(state.current.velocity) <= restDelta) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const id = setInterval(() => {
|
|
76
|
+
const s = state.current;
|
|
77
|
+
const [p, v] = springStep(s.position, s.velocity, targetRef.current, optionsRef.current, FRAME_MS);
|
|
78
|
+
s.position = p;
|
|
79
|
+
s.velocity = v;
|
|
80
|
+
if (Math.abs(p - targetRef.current) <= restDelta && Math.abs(v) <= restDelta) {
|
|
81
|
+
s.position = targetRef.current;
|
|
82
|
+
s.velocity = 0;
|
|
83
|
+
clearInterval(id);
|
|
84
|
+
}
|
|
85
|
+
setValue(s.position);
|
|
86
|
+
}, FRAME_MS);
|
|
87
|
+
return () => clearInterval(id);
|
|
88
|
+
}, [target]);
|
|
89
|
+
return value;
|
|
90
|
+
}
|
package/dist/controls.d.ts
CHANGED
|
@@ -24,7 +24,12 @@ export interface ParamKnobProps {
|
|
|
24
24
|
export declare function ParamKnob({ paramId, label, size, trackColor, valueColor }: ParamKnobProps): import("react").JSX.Element;
|
|
25
25
|
export interface SliderProps {
|
|
26
26
|
value: number;
|
|
27
|
+
/** Track length when horizontal (default 160). */
|
|
27
28
|
width?: number;
|
|
29
|
+
/** Track length when vertical (default 160). */
|
|
30
|
+
height?: number;
|
|
31
|
+
/** Vertical fader — drag up for more, fill rises from the bottom. */
|
|
32
|
+
vertical?: boolean;
|
|
28
33
|
label?: string;
|
|
29
34
|
disabled?: boolean;
|
|
30
35
|
trackColor?: string;
|
|
@@ -33,11 +38,89 @@ export interface SliderProps {
|
|
|
33
38
|
onBegin?: () => void;
|
|
34
39
|
onEnd?: () => void;
|
|
35
40
|
}
|
|
36
|
-
export declare function Slider({ value, width, label, disabled, trackColor, valueColor, onChange, onBegin, onEnd, }: SliderProps): import("react").JSX.Element;
|
|
41
|
+
export declare function Slider({ value, width, height, vertical, label, disabled, trackColor, valueColor, onChange, onBegin, onEnd, }: SliderProps): import("react").JSX.Element;
|
|
37
42
|
export interface ParamSliderProps {
|
|
38
43
|
paramId: string;
|
|
39
44
|
label?: string;
|
|
40
45
|
width?: number;
|
|
46
|
+
height?: number;
|
|
47
|
+
vertical?: boolean;
|
|
41
48
|
}
|
|
42
49
|
/** A Slider bound to an APVTS parameter (via ParameterBridge). */
|
|
43
|
-
export declare function ParamSlider({ paramId, label, width }: ParamSliderProps): import("react").JSX.Element;
|
|
50
|
+
export declare function ParamSlider({ paramId, label, width, height, vertical }: ParamSliderProps): import("react").JSX.Element;
|
|
51
|
+
export interface ToggleProps {
|
|
52
|
+
on: boolean;
|
|
53
|
+
label?: string;
|
|
54
|
+
/** Track height; width is 1.8×. Default 22. */
|
|
55
|
+
size?: number;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
trackColor?: string;
|
|
58
|
+
onColor?: string;
|
|
59
|
+
thumbColor?: string;
|
|
60
|
+
onChange: (on: boolean) => void;
|
|
61
|
+
}
|
|
62
|
+
/** A switch with a spring-animated thumb — bypass, on/off, A/B. */
|
|
63
|
+
export declare function Toggle({ on, label, size, disabled, trackColor, onColor, thumbColor, onChange, }: ToggleProps): import("react").JSX.Element;
|
|
64
|
+
export interface ParamToggleProps {
|
|
65
|
+
paramId: string;
|
|
66
|
+
label?: string;
|
|
67
|
+
size?: number;
|
|
68
|
+
trackColor?: string;
|
|
69
|
+
onColor?: string;
|
|
70
|
+
thumbColor?: string;
|
|
71
|
+
}
|
|
72
|
+
/** A Toggle bound to a bool-style APVTS parameter (on = value ≥ 0.5). */
|
|
73
|
+
export declare function ParamToggle({ paramId, label, ...rest }: ParamToggleProps): import("react").JSX.Element;
|
|
74
|
+
export interface XYPadProps {
|
|
75
|
+
/** Normalized 0..1. */
|
|
76
|
+
x: number;
|
|
77
|
+
/** Normalized 0..1 — 1 is the TOP of the pad (drag up for more). */
|
|
78
|
+
y: number;
|
|
79
|
+
width?: number;
|
|
80
|
+
height?: number;
|
|
81
|
+
label?: string;
|
|
82
|
+
disabled?: boolean;
|
|
83
|
+
trackColor?: string;
|
|
84
|
+
valueColor?: string;
|
|
85
|
+
onChange: (x: number, y: number) => void;
|
|
86
|
+
onBegin?: () => void;
|
|
87
|
+
onEnd?: () => void;
|
|
88
|
+
}
|
|
89
|
+
/** A 2D drag pad with crosshair — filter cutoff/resonance, pan/depth… */
|
|
90
|
+
export declare function XYPad({ x, y, width, height, label, disabled, trackColor, valueColor, onChange, onBegin, onEnd, }: XYPadProps): import("react").JSX.Element;
|
|
91
|
+
export interface ParamXYPadProps {
|
|
92
|
+
paramX: string;
|
|
93
|
+
paramY: string;
|
|
94
|
+
width?: number;
|
|
95
|
+
height?: number;
|
|
96
|
+
label?: string;
|
|
97
|
+
trackColor?: string;
|
|
98
|
+
valueColor?: string;
|
|
99
|
+
}
|
|
100
|
+
/** An XYPad driving two APVTS parameters at once. */
|
|
101
|
+
export declare function ParamXYPad({ paramX, paramY, label, ...rest }: ParamXYPadProps): import("react").JSX.Element;
|
|
102
|
+
export interface SegmentedProps {
|
|
103
|
+
options: string[];
|
|
104
|
+
index: number;
|
|
105
|
+
label?: string;
|
|
106
|
+
disabled?: boolean;
|
|
107
|
+
trackColor?: string;
|
|
108
|
+
activeColor?: string;
|
|
109
|
+
textColor?: string;
|
|
110
|
+
activeTextColor?: string;
|
|
111
|
+
onChange: (index: number) => void;
|
|
112
|
+
}
|
|
113
|
+
/** A row of exclusive options — oscillator shapes, filter modes, A/B/C. */
|
|
114
|
+
export declare function Segmented({ options, index, label, disabled, trackColor, activeColor, textColor, activeTextColor, onChange, }: SegmentedProps): import("react").JSX.Element;
|
|
115
|
+
export interface ParamSegmentedProps {
|
|
116
|
+
paramId: string;
|
|
117
|
+
options: string[];
|
|
118
|
+
label?: string;
|
|
119
|
+
trackColor?: string;
|
|
120
|
+
activeColor?: string;
|
|
121
|
+
textColor?: string;
|
|
122
|
+
activeTextColor?: string;
|
|
123
|
+
}
|
|
124
|
+
/** A Segmented bound to a choice-style APVTS parameter: the normalized
|
|
125
|
+
value maps to an option index (index / (count − 1)). */
|
|
126
|
+
export declare function ParamSegmented({ paramId, options, label, ...rest }: ParamSegmentedProps): import("react").JSX.Element;
|
package/dist/controls.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// The built-in VST controls — knobs, sliders, toggles, XY pads, segmented
|
|
3
|
+
// switches — drawn by the VSReacT painter and driven by drag gestures.
|
|
4
|
+
// Each has a Param* variant bound to an APVTS parameter.
|
|
4
5
|
import { useRef } from "react";
|
|
5
6
|
import { View, Text } from "./primitives";
|
|
6
7
|
import { useParameter } from "./parameters";
|
|
8
|
+
import { useSpring } from "./animation";
|
|
9
|
+
const clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
7
10
|
/** Vertical-drag-to-value mapping shared by Knob (and tested in isolation). */
|
|
8
11
|
export function dragToValue(startValue, dy, sensitivity = 0.005) {
|
|
9
|
-
return
|
|
12
|
+
return clamp01(startValue - dy * sensitivity);
|
|
10
13
|
}
|
|
11
14
|
const ARC_START = -135;
|
|
12
15
|
const ARC_END = 135;
|
|
@@ -33,20 +36,95 @@ export function ParamKnob({ paramId, label, size, trackColor, valueColor }) {
|
|
|
33
36
|
const param = useParameter(paramId);
|
|
34
37
|
return (_jsx(Knob, { value: param.value, text: param.text, label: label ?? param.name.toUpperCase(), size: size, trackColor: trackColor, valueColor: valueColor, onChange: param.set, onBegin: param.begin, onEnd: param.end }));
|
|
35
38
|
}
|
|
36
|
-
export function Slider({ value, width = 160, label, disabled, trackColor = "#2A2F27", valueColor = "#C6F135", onChange, onBegin, onEnd, }) {
|
|
39
|
+
export function Slider({ value, width = 160, height = 160, vertical, label, disabled, trackColor = "#2A2F27", valueColor = "#C6F135", onChange, onBegin, onEnd, }) {
|
|
37
40
|
const startValue = useRef(0);
|
|
38
|
-
const clamped =
|
|
39
|
-
|
|
41
|
+
const clamped = clamp01(value);
|
|
42
|
+
const onDragStart = disabled
|
|
43
|
+
? undefined
|
|
44
|
+
: () => {
|
|
45
|
+
startValue.current = clamped;
|
|
46
|
+
onBegin?.();
|
|
47
|
+
};
|
|
48
|
+
const onDragEnd = disabled ? undefined : () => onEnd?.();
|
|
49
|
+
if (vertical) {
|
|
50
|
+
return (_jsxs(View, { className: "items-center gap-2", children: [_jsxs(View, { className: `w-[18] relative ${disabled ? "opacity-40" : "cursor-pointer"}`, style: { height }, onDragStart: onDragStart, onDrag: disabled ? undefined : (e) => onChange(clamp01(startValue.current - e.dy / height)), onDragEnd: onDragEnd, children: [_jsx(View, { className: "absolute w-[4] rounded-full left-[7] top-0 bottom-0", style: { backgroundColor: trackColor } }), _jsx(View, { className: "absolute w-[4] rounded-full left-[7] bottom-0", style: { height: clamped * height, backgroundColor: valueColor } }), _jsx(View, { className: "absolute w-[12] h-[12] rounded-full left-[3]", style: { top: (1 - clamped) * (height - 12), backgroundColor: valueColor } })] }), label !== undefined ? (_jsx(Text, { className: "text-faint text-[10] font-bold tracking-widest", children: label })) : null] }));
|
|
51
|
+
}
|
|
52
|
+
return (_jsxs(View, { className: "gap-2", children: [_jsxs(View, { className: `h-[18] justify-center relative ${disabled ? "opacity-40" : "cursor-pointer"}`, style: { width }, onDragStart: onDragStart, onDrag: disabled ? undefined : (e) => onChange(clamp01(startValue.current + e.dx / width)), onDragEnd: onDragEnd, children: [_jsx(View, { className: "h-[4] rounded-full", style: { backgroundColor: trackColor } }), _jsx(View, { className: "absolute h-[4] rounded-full top-[7]", style: { width: clamped * width, backgroundColor: valueColor } }), _jsx(View, { className: "absolute w-[12] h-[12] rounded-full top-[3]", style: { left: clamped * (width - 12), backgroundColor: valueColor } })] }), label !== undefined ? (_jsx(Text, { className: "text-faint text-[10] font-bold tracking-widest", children: label })) : null] }));
|
|
53
|
+
}
|
|
54
|
+
/** A Slider bound to an APVTS parameter (via ParameterBridge). */
|
|
55
|
+
export function ParamSlider({ paramId, label, width, height, vertical }) {
|
|
56
|
+
const param = useParameter(paramId);
|
|
57
|
+
return (_jsx(Slider, { value: param.value, label: label ?? param.name.toUpperCase(), width: width, height: height, vertical: vertical, onChange: param.set, onBegin: param.begin, onEnd: param.end }));
|
|
58
|
+
}
|
|
59
|
+
/** A switch with a spring-animated thumb — bypass, on/off, A/B. */
|
|
60
|
+
export function Toggle({ on, label, size = 22, disabled, trackColor = "#2A2F27", onColor = "#C6F135", thumbColor = "#F4F4F5", onChange, }) {
|
|
61
|
+
const t = useSpring(on ? 1 : 0, { stiffness: 300, damping: 28 });
|
|
62
|
+
const trackWidth = Math.round(size * 1.8);
|
|
63
|
+
const thumb = size - 6;
|
|
64
|
+
const travel = trackWidth - thumb - 6;
|
|
65
|
+
return (_jsxs(View, { className: "items-center gap-2", children: [_jsx(View, { className: `relative rounded-full ${disabled ? "opacity-40" : "cursor-pointer"}`, style: { width: trackWidth, height: size, backgroundColor: on ? onColor : trackColor }, onClick: disabled ? undefined : () => onChange(!on), children: _jsx(View, { className: "absolute rounded-full", style: {
|
|
66
|
+
width: thumb,
|
|
67
|
+
height: thumb,
|
|
68
|
+
top: 3,
|
|
69
|
+
left: 3 + clamp01(t) * travel,
|
|
70
|
+
backgroundColor: thumbColor,
|
|
71
|
+
} }) }), label !== undefined ? (_jsx(Text, { className: "text-faint text-[10] font-bold tracking-widest", children: label })) : null] }));
|
|
72
|
+
}
|
|
73
|
+
/** A Toggle bound to a bool-style APVTS parameter (on = value ≥ 0.5). */
|
|
74
|
+
export function ParamToggle({ paramId, label, ...rest }) {
|
|
75
|
+
const param = useParameter(paramId);
|
|
76
|
+
return (_jsx(Toggle, { on: param.value >= 0.5, label: label ?? param.name.toUpperCase(), onChange: (next) => {
|
|
77
|
+
param.begin();
|
|
78
|
+
param.set(next ? 1 : 0);
|
|
79
|
+
param.end();
|
|
80
|
+
}, ...rest }));
|
|
81
|
+
}
|
|
82
|
+
/** A 2D drag pad with crosshair — filter cutoff/resonance, pan/depth… */
|
|
83
|
+
export function XYPad({ x, y, width = 160, height = 160, label, disabled, trackColor = "#161B17", valueColor = "#C6F135", onChange, onBegin, onEnd, }) {
|
|
84
|
+
const start = useRef({ x: 0, y: 0 });
|
|
85
|
+
const cxv = clamp01(x);
|
|
86
|
+
const cyv = clamp01(y);
|
|
87
|
+
const thumb = 14;
|
|
88
|
+
const tx = cxv * (width - thumb);
|
|
89
|
+
const ty = (1 - cyv) * (height - thumb);
|
|
90
|
+
return (_jsxs(View, { className: "items-center gap-2", children: [_jsxs(View, { className: `relative rounded-lg overflow-hidden border ${disabled ? "opacity-40" : "cursor-pointer"}`, style: { width, height, backgroundColor: trackColor, borderColor: "#00000055" }, onDragStart: disabled
|
|
40
91
|
? undefined
|
|
41
92
|
: () => {
|
|
42
|
-
|
|
93
|
+
start.current = { x: cxv, y: cyv };
|
|
43
94
|
onBegin?.();
|
|
44
95
|
}, onDrag: disabled
|
|
45
96
|
? undefined
|
|
46
|
-
: (e) => onChange(
|
|
97
|
+
: (e) => onChange(clamp01(start.current.x + e.dx / width), clamp01(start.current.y - e.dy / height)), onDragEnd: disabled ? undefined : () => onEnd?.(), children: [_jsx(View, { className: "absolute left-0 right-0 h-[1]", style: { top: ty + thumb / 2, backgroundColor: valueColor, opacity: 0.35 } }), _jsx(View, { className: "absolute top-0 bottom-0 w-[1]", style: { left: tx + thumb / 2, backgroundColor: valueColor, opacity: 0.35 } }), _jsx(View, { className: "absolute rounded-full", style: { width: thumb, height: thumb, left: tx, top: ty, backgroundColor: valueColor } })] }), label !== undefined ? (_jsx(Text, { className: "text-faint text-[10] font-bold tracking-widest", children: label })) : null] }));
|
|
47
98
|
}
|
|
48
|
-
/**
|
|
49
|
-
export function
|
|
99
|
+
/** An XYPad driving two APVTS parameters at once. */
|
|
100
|
+
export function ParamXYPad({ paramX, paramY, label, ...rest }) {
|
|
101
|
+
const px = useParameter(paramX);
|
|
102
|
+
const py = useParameter(paramY);
|
|
103
|
+
return (_jsx(XYPad, { x: px.value, y: py.value, label: label ?? `${px.name} / ${py.name}`.toUpperCase(), onChange: (nx, ny) => {
|
|
104
|
+
px.set(nx);
|
|
105
|
+
py.set(ny);
|
|
106
|
+
}, onBegin: () => {
|
|
107
|
+
px.begin();
|
|
108
|
+
py.begin();
|
|
109
|
+
}, onEnd: () => {
|
|
110
|
+
px.end();
|
|
111
|
+
py.end();
|
|
112
|
+
}, ...rest }));
|
|
113
|
+
}
|
|
114
|
+
/** A row of exclusive options — oscillator shapes, filter modes, A/B/C. */
|
|
115
|
+
export function Segmented({ options, index, label, disabled, trackColor = "#2A2F27", activeColor = "#C6F135", textColor = "#a1a1aa", activeTextColor = "#09090b", onChange, }) {
|
|
116
|
+
const current = Math.min(options.length - 1, Math.max(0, index));
|
|
117
|
+
return (_jsxs(View, { className: "items-center gap-2", children: [_jsx(View, { className: `flex-row rounded-lg p-[3] gap-[3] ${disabled ? "opacity-40" : ""}`, style: { backgroundColor: trackColor }, children: options.map((option, i) => (_jsx(View, { className: `px-3 py-[6] rounded-md ${disabled ? "" : "cursor-pointer"}`, style: { backgroundColor: i === current ? activeColor : "#00000000" }, onClick: disabled ? undefined : () => onChange(i), children: _jsx(Text, { className: "text-[11] font-bold tracking-wide", style: { color: i === current ? activeTextColor : textColor }, children: option }) }, `${option}-${i}`))) }), label !== undefined ? (_jsx(Text, { className: "text-faint text-[10] font-bold tracking-widest", children: label })) : null] }));
|
|
118
|
+
}
|
|
119
|
+
/** A Segmented bound to a choice-style APVTS parameter: the normalized
|
|
120
|
+
value maps to an option index (index / (count − 1)). */
|
|
121
|
+
export function ParamSegmented({ paramId, options, label, ...rest }) {
|
|
50
122
|
const param = useParameter(paramId);
|
|
51
|
-
|
|
123
|
+
const count = Math.max(1, options.length);
|
|
124
|
+
const index = Math.round(param.value * (count - 1));
|
|
125
|
+
return (_jsx(Segmented, { options: options, index: index, label: label ?? param.name.toUpperCase(), onChange: (i) => {
|
|
126
|
+
param.begin();
|
|
127
|
+
param.set(count <= 1 ? 0 : i / (count - 1));
|
|
128
|
+
param.end();
|
|
129
|
+
}, ...rest }));
|
|
52
130
|
}
|
package/dist/cx.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type ClassValue = string | number | null | false | undefined | ClassValue[] | Record<string, unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* `cx("flex", active && "bg-red-500", { "opacity-40": disabled })`
|
|
4
|
+
* → `"flex bg-red-500 opacity-40"`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cx(...inputs: ClassValue[]): string;
|
package/dist/cx.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// cx — compose conditional className strings (a tiny clsx).
|
|
2
|
+
/**
|
|
3
|
+
* `cx("flex", active && "bg-red-500", { "opacity-40": disabled })`
|
|
4
|
+
* → `"flex bg-red-500 opacity-40"`.
|
|
5
|
+
*/
|
|
6
|
+
export function cx(...inputs) {
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const input of inputs) {
|
|
9
|
+
if (!input && input !== 0)
|
|
10
|
+
continue;
|
|
11
|
+
if (typeof input === "string" || typeof input === "number") {
|
|
12
|
+
out.push(String(input));
|
|
13
|
+
}
|
|
14
|
+
else if (Array.isArray(input)) {
|
|
15
|
+
const nested = cx(...input);
|
|
16
|
+
if (nested)
|
|
17
|
+
out.push(nested);
|
|
18
|
+
}
|
|
19
|
+
else if (typeof input === "object") {
|
|
20
|
+
for (const [key, value] of Object.entries(input))
|
|
21
|
+
if (value)
|
|
22
|
+
out.push(key);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return out.join(" ");
|
|
26
|
+
}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscribes to a C++ event (RootView::sendNativeEvent) for the lifetime
|
|
3
|
+
* of the component. The handler can close over fresh state — it is kept
|
|
4
|
+
* current without resubscribing.
|
|
5
|
+
*
|
|
6
|
+
* useNativeEvent("download:progress", (p) => setProgress(p.ratio));
|
|
7
|
+
*/
|
|
8
|
+
export declare function useNativeEvent(name: string, handler: (payload: any) => void): void;
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Convenience hooks over the native bridge.
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { native } from "./native";
|
|
4
|
+
/**
|
|
5
|
+
* Subscribes to a C++ event (RootView::sendNativeEvent) for the lifetime
|
|
6
|
+
* of the component. The handler can close over fresh state — it is kept
|
|
7
|
+
* current without resubscribing.
|
|
8
|
+
*
|
|
9
|
+
* useNativeEvent("download:progress", (p) => setProgress(p.ratio));
|
|
10
|
+
*/
|
|
11
|
+
export function useNativeEvent(name, handler) {
|
|
12
|
+
const handlerRef = useRef(handler);
|
|
13
|
+
handlerRef.current = handler;
|
|
14
|
+
useEffect(() => native.on(name, (payload) => handlerRef.current(payload)), [name]);
|
|
15
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,15 @@ export { View, Text, Image, TextInput, NativeView } from "./primitives";
|
|
|
4
4
|
export type { CommonProps, TextProps, ImageProps, TextInputProps, NativeViewProps, } from "./primitives";
|
|
5
5
|
export { render, unmount } from "./render";
|
|
6
6
|
export { native } from "./native";
|
|
7
|
+
export { useNativeEvent } from "./hooks";
|
|
7
8
|
export { configureTheme, tw } from "./tw";
|
|
8
9
|
export type { Style, ResolvedClasses } from "./tw";
|
|
9
|
-
export {
|
|
10
|
-
export type {
|
|
10
|
+
export { cx } from "./cx";
|
|
11
|
+
export type { ClassValue } from "./cx";
|
|
12
|
+
export { useTween, useSpring, springStep, lerp, Easing } from "./animation";
|
|
13
|
+
export type { TweenOptions, SpringOptions, EasingFn } from "./animation";
|
|
11
14
|
export { useParameter } from "./parameters";
|
|
12
15
|
export type { ParameterState, ParameterHandle } from "./parameters";
|
|
13
|
-
export { Knob, Slider, ParamKnob, ParamSlider, dragToValue } from "./controls";
|
|
14
|
-
export type { KnobProps, SliderProps, ParamKnobProps, ParamSliderProps } from "./controls";
|
|
16
|
+
export { Knob, Slider, Toggle, XYPad, Segmented, ParamKnob, ParamSlider, ParamToggle, ParamXYPad, ParamSegmented, dragToValue, } from "./controls";
|
|
17
|
+
export type { KnobProps, SliderProps, ToggleProps, XYPadProps, SegmentedProps, ParamKnobProps, ParamSliderProps, ParamToggleProps, ParamXYPadProps, ParamSegmentedProps, } from "./controls";
|
|
15
18
|
export type { DragEventPayload } from "./primitives";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
// vsreact public API. runtime must load first — it installs the
|
|
1
|
+
// @vsreact/core public API. runtime must load first — it installs the
|
|
2
2
|
// timer/console/microtask shims react depends on inside QuickJS.
|
|
3
3
|
import "./runtime";
|
|
4
4
|
import "./bridge";
|
|
5
5
|
export { View, Text, Image, TextInput, NativeView } from "./primitives";
|
|
6
6
|
export { render, unmount } from "./render";
|
|
7
7
|
export { native } from "./native";
|
|
8
|
+
export { useNativeEvent } from "./hooks";
|
|
8
9
|
export { configureTheme, tw } from "./tw";
|
|
9
|
-
export {
|
|
10
|
+
export { cx } from "./cx";
|
|
11
|
+
export { useTween, useSpring, springStep, lerp, Easing } from "./animation";
|
|
10
12
|
export { useParameter } from "./parameters";
|
|
11
|
-
export { Knob, Slider, ParamKnob, ParamSlider, dragToValue } from "./controls";
|
|
13
|
+
export { Knob, Slider, Toggle, XYPad, Segmented, ParamKnob, ParamSlider, ParamToggle, ParamXYPad, ParamSegmented, dragToValue, } from "./controls";
|
package/dist/theme.js
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
|
-
// Tailwind v3
|
|
1
|
+
// The full Tailwind v3 color palette.
|
|
2
2
|
const palettes = {
|
|
3
|
+
slate: {
|
|
4
|
+
"50": "#f8fafc", "100": "#f1f5f9", "200": "#e2e8f0", "300": "#cbd5e1",
|
|
5
|
+
"400": "#94a3b8", "500": "#64748b", "600": "#475569", "700": "#334155",
|
|
6
|
+
"800": "#1e293b", "900": "#0f172a", "950": "#020617",
|
|
7
|
+
},
|
|
8
|
+
gray: {
|
|
9
|
+
"50": "#f9fafb", "100": "#f3f4f6", "200": "#e5e7eb", "300": "#d1d5db",
|
|
10
|
+
"400": "#9ca3af", "500": "#6b7280", "600": "#4b5563", "700": "#374151",
|
|
11
|
+
"800": "#1f2937", "900": "#111827", "950": "#030712",
|
|
12
|
+
},
|
|
13
|
+
stone: {
|
|
14
|
+
"50": "#fafaf9", "100": "#f5f5f4", "200": "#e7e5e4", "300": "#d6d3d1",
|
|
15
|
+
"400": "#a8a29e", "500": "#78716c", "600": "#57534e", "700": "#44403c",
|
|
16
|
+
"800": "#292524", "900": "#1c1917", "950": "#0c0a09",
|
|
17
|
+
},
|
|
18
|
+
orange: {
|
|
19
|
+
"50": "#fff7ed", "100": "#ffedd5", "200": "#fed7aa", "300": "#fdba74",
|
|
20
|
+
"400": "#fb923c", "500": "#f97316", "600": "#ea580c", "700": "#c2410c",
|
|
21
|
+
"800": "#9a3412", "900": "#7c2d12", "950": "#431407",
|
|
22
|
+
},
|
|
23
|
+
yellow: {
|
|
24
|
+
"50": "#fefce8", "100": "#fef9c3", "200": "#fef08a", "300": "#fde047",
|
|
25
|
+
"400": "#facc15", "500": "#eab308", "600": "#ca8a04", "700": "#a16207",
|
|
26
|
+
"800": "#854d0e", "900": "#713f12", "950": "#422006",
|
|
27
|
+
},
|
|
28
|
+
green: {
|
|
29
|
+
"50": "#f0fdf4", "100": "#dcfce7", "200": "#bbf7d0", "300": "#86efac",
|
|
30
|
+
"400": "#4ade80", "500": "#22c55e", "600": "#16a34a", "700": "#15803d",
|
|
31
|
+
"800": "#166534", "900": "#14532d", "950": "#052e16",
|
|
32
|
+
},
|
|
33
|
+
teal: {
|
|
34
|
+
"50": "#f0fdfa", "100": "#ccfbf1", "200": "#99f6e4", "300": "#5eead4",
|
|
35
|
+
"400": "#2dd4bf", "500": "#14b8a6", "600": "#0d9488", "700": "#0f766e",
|
|
36
|
+
"800": "#115e59", "900": "#134e4a", "950": "#042f2e",
|
|
37
|
+
},
|
|
38
|
+
cyan: {
|
|
39
|
+
"50": "#ecfeff", "100": "#cffafe", "200": "#a5f3fc", "300": "#67e8f9",
|
|
40
|
+
"400": "#22d3ee", "500": "#06b6d4", "600": "#0891b2", "700": "#0e7490",
|
|
41
|
+
"800": "#155e75", "900": "#164e63", "950": "#083344",
|
|
42
|
+
},
|
|
43
|
+
blue: {
|
|
44
|
+
"50": "#eff6ff", "100": "#dbeafe", "200": "#bfdbfe", "300": "#93c5fd",
|
|
45
|
+
"400": "#60a5fa", "500": "#3b82f6", "600": "#2563eb", "700": "#1d4ed8",
|
|
46
|
+
"800": "#1e40af", "900": "#1e3a8a", "950": "#172554",
|
|
47
|
+
},
|
|
48
|
+
indigo: {
|
|
49
|
+
"50": "#eef2ff", "100": "#e0e7ff", "200": "#c7d2fe", "300": "#a5b4fc",
|
|
50
|
+
"400": "#818cf8", "500": "#6366f1", "600": "#4f46e5", "700": "#4338ca",
|
|
51
|
+
"800": "#3730a3", "900": "#312e81", "950": "#1e1b4b",
|
|
52
|
+
},
|
|
53
|
+
violet: {
|
|
54
|
+
"50": "#f5f3ff", "100": "#ede9fe", "200": "#ddd6fe", "300": "#c4b5fd",
|
|
55
|
+
"400": "#a78bfa", "500": "#8b5cf6", "600": "#7c3aed", "700": "#6d28d9",
|
|
56
|
+
"800": "#5b21b6", "900": "#4c1d95", "950": "#2e1065",
|
|
57
|
+
},
|
|
58
|
+
purple: {
|
|
59
|
+
"50": "#faf5ff", "100": "#f3e8ff", "200": "#e9d5ff", "300": "#d8b4fe",
|
|
60
|
+
"400": "#c084fc", "500": "#a855f7", "600": "#9333ea", "700": "#7e22ce",
|
|
61
|
+
"800": "#6b21a8", "900": "#581c87", "950": "#3b0764",
|
|
62
|
+
},
|
|
63
|
+
fuchsia: {
|
|
64
|
+
"50": "#fdf4ff", "100": "#fae8ff", "200": "#f5d0fe", "300": "#f0abfc",
|
|
65
|
+
"400": "#e879f9", "500": "#d946ef", "600": "#c026d3", "700": "#a21caf",
|
|
66
|
+
"800": "#86198f", "900": "#701a75", "950": "#4a044e",
|
|
67
|
+
},
|
|
68
|
+
pink: {
|
|
69
|
+
"50": "#fdf2f8", "100": "#fce7f3", "200": "#fbcfe8", "300": "#f9a8d4",
|
|
70
|
+
"400": "#f472b6", "500": "#ec4899", "600": "#db2777", "700": "#be185d",
|
|
71
|
+
"800": "#9d174d", "900": "#831843", "950": "#500724",
|
|
72
|
+
},
|
|
73
|
+
rose: {
|
|
74
|
+
"50": "#fff1f2", "100": "#ffe4e6", "200": "#fecdd3", "300": "#fda4af",
|
|
75
|
+
"400": "#fb7185", "500": "#f43f5e", "600": "#e11d48", "700": "#be123c",
|
|
76
|
+
"800": "#9f1239", "900": "#881337", "950": "#4c0519",
|
|
77
|
+
},
|
|
3
78
|
zinc: {
|
|
4
79
|
"50": "#fafafa", "100": "#f4f4f5", "200": "#e4e4e7", "300": "#d4d4d8",
|
|
5
80
|
"400": "#a1a1aa", "500": "#71717a", "600": "#52525b", "700": "#3f3f46",
|
package/dist/tw.js
CHANGED
|
@@ -71,6 +71,7 @@ const staticClasses = {
|
|
|
71
71
|
};
|
|
72
72
|
const textSizes = {
|
|
73
73
|
xs: 12, sm: 14, base: 16, lg: 18, xl: 20, "2xl": 24, "3xl": 30, "4xl": 36,
|
|
74
|
+
"5xl": 48, "6xl": 60,
|
|
74
75
|
};
|
|
75
76
|
const radiusSizes = {
|
|
76
77
|
"": 4, sm: 2, md: 6, lg: 8, xl: 12, "2xl": 16, "3xl": 24, full: 9999,
|
|
@@ -90,6 +91,7 @@ const radiusCorners = {
|
|
|
90
91
|
const lengthKeys = {
|
|
91
92
|
w: ["width"],
|
|
92
93
|
h: ["height"],
|
|
94
|
+
size: ["width", "height"],
|
|
93
95
|
"min-w": ["minWidth"],
|
|
94
96
|
"min-h": ["minHeight"],
|
|
95
97
|
"max-w": ["maxWidth"],
|
|
@@ -116,6 +118,8 @@ const lengthKeys = {
|
|
|
116
118
|
bottom: ["bottom"],
|
|
117
119
|
left: ["left"],
|
|
118
120
|
inset: ["left", "right", "top", "bottom"],
|
|
121
|
+
"inset-x": ["left", "right"],
|
|
122
|
+
"inset-y": ["top", "bottom"],
|
|
119
123
|
basis: ["flexBasis"],
|
|
120
124
|
};
|
|
121
125
|
const warned = new Set();
|
package/package.json
CHANGED
package/src/animation.test.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { Easing, lerp } from "./animation";
|
|
2
|
+
import { Easing, lerp, springStep } from "./animation";
|
|
3
|
+
import { cx } from "./cx";
|
|
3
4
|
|
|
4
5
|
describe("animation", () => {
|
|
5
6
|
test("easing curves start at 0 and end at 1", () => {
|
|
@@ -20,3 +21,57 @@ describe("animation", () => {
|
|
|
20
21
|
expect(lerp(4, 4, 0.3)).toBe(4);
|
|
21
22
|
});
|
|
22
23
|
});
|
|
24
|
+
|
|
25
|
+
describe("springStep", () => {
|
|
26
|
+
const settle = (options = {}) => {
|
|
27
|
+
let p = 0;
|
|
28
|
+
let v = 0;
|
|
29
|
+
for (let i = 0; i < 600; i++) [p, v] = springStep(p, v, 1, options, 16);
|
|
30
|
+
return [p, v];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
test("converges to the target and comes to rest", () => {
|
|
34
|
+
const [p, v] = settle();
|
|
35
|
+
expect(p).toBeCloseTo(1, 3);
|
|
36
|
+
expect(Math.abs(v)).toBeLessThan(0.001);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("accelerates toward the target from rest", () => {
|
|
40
|
+
const [p1, v1] = springStep(0, 0, 1, {}, 16);
|
|
41
|
+
expect(v1).toBeGreaterThan(0);
|
|
42
|
+
expect(p1).toBeGreaterThan(0);
|
|
43
|
+
expect(p1).toBeLessThan(1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("underdamped springs overshoot; overdamped don't", () => {
|
|
47
|
+
let p = 0;
|
|
48
|
+
let v = 0;
|
|
49
|
+
let peak = 0;
|
|
50
|
+
for (let i = 0; i < 600; i++) {
|
|
51
|
+
[p, v] = springStep(p, v, 1, { stiffness: 300, damping: 8 }, 16);
|
|
52
|
+
peak = Math.max(peak, p);
|
|
53
|
+
}
|
|
54
|
+
expect(peak).toBeGreaterThan(1.01);
|
|
55
|
+
|
|
56
|
+
p = 0;
|
|
57
|
+
v = 0;
|
|
58
|
+
peak = 0;
|
|
59
|
+
for (let i = 0; i < 600; i++) {
|
|
60
|
+
[p, v] = springStep(p, v, 1, { stiffness: 120, damping: 40 }, 16);
|
|
61
|
+
peak = Math.max(peak, p);
|
|
62
|
+
}
|
|
63
|
+
expect(peak).toBeLessThanOrEqual(1.001);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("cx", () => {
|
|
68
|
+
test("joins strings and skips falsy values", () => {
|
|
69
|
+
expect(cx("flex", false && "hidden", undefined, null, "", "gap-2")).toBe("flex gap-2");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("supports arrays and object maps", () => {
|
|
73
|
+
expect(cx(["flex", ["items-center"]], { "opacity-40": true, "cursor-pointer": false })).toBe(
|
|
74
|
+
"flex items-center opacity-40",
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|