@farcaster/snap 1.17.2 → 1.19.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/dist/react/components/slider.js +2 -1
- package/dist/react-native/components/snap-action-button.js +1 -1
- package/dist/react-native/components/snap-badge.js +2 -1
- package/dist/react-native/components/snap-bar-chart.js +2 -2
- package/dist/react-native/components/snap-cell-grid.js +1 -1
- package/dist/react-native/components/snap-input.js +2 -1
- package/dist/react-native/components/snap-item.js +4 -3
- package/dist/react-native/components/snap-progress.js +1 -1
- package/dist/react-native/components/snap-slider.js +6 -5
- package/dist/react-native/components/snap-switch.js +1 -0
- package/dist/react-native/components/snap-text.js +1 -1
- package/dist/react-native/components/snap-toggle-group.js +2 -1
- package/dist/react-native/theme.js +10 -10
- package/dist/react-native/v2/snap-view.js +1 -1
- package/dist/schemas.d.ts +6 -11
- package/dist/schemas.js +2 -9
- package/dist/server/parseRequest.js +20 -27
- package/dist/ui/catalog.d.ts +1 -0
- package/dist/ui/slider.d.ts +1 -0
- package/dist/ui/slider.js +2 -0
- package/llms.txt +1 -0
- package/package.json +1 -1
- package/src/react/components/slider.tsx +11 -1
- package/src/react-native/components/snap-action-button.tsx +1 -1
- package/src/react-native/components/snap-badge.tsx +2 -1
- package/src/react-native/components/snap-bar-chart.tsx +2 -2
- package/src/react-native/components/snap-cell-grid.tsx +1 -1
- package/src/react-native/components/snap-input.tsx +2 -1
- package/src/react-native/components/snap-item.tsx +4 -3
- package/src/react-native/components/snap-progress.tsx +1 -1
- package/src/react-native/components/snap-slider.tsx +10 -7
- package/src/react-native/components/snap-switch.tsx +1 -0
- package/src/react-native/components/snap-text.tsx +1 -1
- package/src/react-native/components/snap-toggle-group.tsx +2 -1
- package/src/react-native/theme.tsx +10 -10
- package/src/react-native/v2/snap-view.tsx +1 -1
- package/src/schemas.ts +2 -9
- package/src/server/parseRequest.ts +21 -31
- package/src/ui/slider.ts +2 -0
|
@@ -11,6 +11,7 @@ export function SnapSlider({ element: { props }, }) {
|
|
|
11
11
|
const max = Number(props.max ?? 100);
|
|
12
12
|
const step = Number(props.step ?? 1);
|
|
13
13
|
const label = props.label ? String(props.label) : undefined;
|
|
14
|
+
const showValue = props.showValue === true;
|
|
14
15
|
const path = `/inputs/${name}`;
|
|
15
16
|
const raw = get(path);
|
|
16
17
|
const value = raw !== undefined
|
|
@@ -18,7 +19,7 @@ export function SnapSlider({ element: { props }, }) {
|
|
|
18
19
|
: props.defaultValue !== undefined
|
|
19
20
|
? Number(props.defaultValue)
|
|
20
21
|
: (min + max) / 2;
|
|
21
|
-
return (_jsxs("div", { className: "flex w-full flex-col gap-1.5", children: [label && _jsx(Label, { style: { color: colors.text }, children: label }), _jsx("input", { type: "range", min: min, max: max, step: step, value: value, onChange: (e) => set(path, Number(e.target.value)), className: "w-full h-2.5 rounded-full appearance-none cursor-pointer", style: {
|
|
22
|
+
return (_jsxs("div", { className: "flex w-full flex-col gap-1.5", children: [label && (_jsxs("div", { className: "flex items-center justify-between", children: [_jsx(Label, { style: { color: colors.text }, children: label }), showValue && (_jsx("span", { style: { color: colors.textMuted, fontSize: 13, lineHeight: "18px" }, children: Math.round(value) }))] })), _jsx("input", { type: "range", min: min, max: max, step: step, value: value, onChange: (e) => set(path, Number(e.target.value)), className: "w-full h-2.5 rounded-full appearance-none cursor-pointer", style: {
|
|
22
23
|
backgroundColor: colors.muted,
|
|
23
24
|
accentColor: colors.accent,
|
|
24
25
|
} })] }));
|
|
@@ -47,7 +47,7 @@ export function SnapActionButton({ element, emit, }) {
|
|
|
47
47
|
const I = ICON_MAP[iconName];
|
|
48
48
|
return _jsx(I, { size: 16, color: iconColor });
|
|
49
49
|
})()
|
|
50
|
-
: null, _jsx(Text, { style: { color: textColor, fontSize: 14, fontWeight: "600" }, children: label }), showExternalIcon ? (_jsx(ExternalLink, { size: 14, color: iconColor, style: { opacity: 0.6 } })) : null] }) }));
|
|
50
|
+
: null, _jsx(Text, { style: { color: textColor, fontSize: 14, lineHeight: 18, fontWeight: "600" }, children: label }), showExternalIcon ? (_jsx(ExternalLink, { size: 14, color: iconColor, style: { opacity: 0.6 } })) : null] }) }));
|
|
51
51
|
}
|
|
52
52
|
const styles = StyleSheet.create({
|
|
53
53
|
outer: { flex: 1, minWidth: 0 },
|
|
@@ -10,7 +10,7 @@ export function SnapBadge({ element: { props }, }) {
|
|
|
10
10
|
const iconName = props.icon ? String(props.icon) : undefined;
|
|
11
11
|
const isAccent = !color || color === "accent";
|
|
12
12
|
const resolvedColor = isAccent ? accentHex : hex(color);
|
|
13
|
-
const isFilled = variant
|
|
13
|
+
const isFilled = variant !== "outline";
|
|
14
14
|
const Icon = iconName ? ICON_MAP[iconName] : undefined;
|
|
15
15
|
return (_jsxs(View, { style: [
|
|
16
16
|
styles.badge,
|
|
@@ -35,6 +35,7 @@ const styles = StyleSheet.create({
|
|
|
35
35
|
},
|
|
36
36
|
label: {
|
|
37
37
|
fontSize: 12,
|
|
38
|
+
lineHeight: 16,
|
|
38
39
|
fontWeight: "500",
|
|
39
40
|
},
|
|
40
41
|
});
|
|
@@ -32,8 +32,8 @@ export function SnapBarChart({ element: { props }, }) {
|
|
|
32
32
|
const styles = StyleSheet.create({
|
|
33
33
|
wrap: { flex: 1, width: "100%", gap: 8 },
|
|
34
34
|
row: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
35
|
-
label: { width: 80, fontSize: 12, textAlign: "right" },
|
|
35
|
+
label: { width: 80, fontSize: 12, lineHeight: 16, textAlign: "right" },
|
|
36
36
|
track: { flex: 1, height: 10, borderRadius: 9999, overflow: "hidden" },
|
|
37
37
|
fill: { height: "100%", borderRadius: 9999 },
|
|
38
|
-
value: { width: 32, fontSize: 12, fontVariant: ["tabular-nums"] },
|
|
38
|
+
value: { width: 32, fontSize: 12, lineHeight: 16, fontVariant: ["tabular-nums"] },
|
|
39
39
|
});
|
|
@@ -91,6 +91,6 @@ const styles = StyleSheet.create({
|
|
|
91
91
|
alignItems: "center",
|
|
92
92
|
justifyContent: "center",
|
|
93
93
|
},
|
|
94
|
-
cellText: { fontSize: 12, fontWeight: "600" },
|
|
94
|
+
cellText: { fontSize: 12, lineHeight: 16, fontWeight: "600" },
|
|
95
95
|
selectionText: { fontSize: 11, fontFamily: "monospace", marginTop: 6 },
|
|
96
96
|
});
|
|
@@ -25,12 +25,13 @@ export function SnapInput({ element: { props }, }) {
|
|
|
25
25
|
}
|
|
26
26
|
const styles = StyleSheet.create({
|
|
27
27
|
wrap: { width: "100%", gap: 4 },
|
|
28
|
-
label: { fontSize: 13, fontWeight: "500" },
|
|
28
|
+
label: { fontSize: 13, lineHeight: 18, fontWeight: "500" },
|
|
29
29
|
input: {
|
|
30
30
|
borderWidth: 1,
|
|
31
31
|
borderRadius: 8,
|
|
32
32
|
paddingHorizontal: 12,
|
|
33
33
|
paddingVertical: 10,
|
|
34
34
|
fontSize: 14,
|
|
35
|
+
lineHeight: 18,
|
|
35
36
|
},
|
|
36
37
|
});
|
|
@@ -8,12 +8,11 @@ export function SnapItem({ element: { props }, children, }) {
|
|
|
8
8
|
? String(props.description)
|
|
9
9
|
: undefined;
|
|
10
10
|
const variant = String(props.variant ?? "default");
|
|
11
|
-
const containerVariant = { paddingVertical:
|
|
12
|
-
return (_jsxs(View, { style: [styles.container, containerVariant], children: [_jsxs(View, { style: styles.content, children: [_jsx(Text, { style: [styles.title, { color: colors.text }], children: title }), description ? (_jsx(Text, { style: [styles.description, { color: colors.textSecondary }], children: description })) : null] }), children ? (_jsx(View, { style: styles.actions, children: _jsx(View, { style: { flex: 0 }, children: children }) })) : null] }));
|
|
11
|
+
const containerVariant = { paddingVertical: 6, paddingHorizontal: 10 };
|
|
12
|
+
return (_jsxs(View, { style: [styles.container, containerVariant], children: [_jsxs(View, { style: styles.content, children: [title ? _jsx(Text, { style: [styles.title, { color: colors.text }], children: title }) : null, description ? (_jsx(Text, { style: [styles.description, { color: colors.textSecondary }], children: description })) : null] }), children ? (_jsx(View, { style: styles.actions, children: _jsx(View, { style: { flex: 0 }, children: children }) })) : null] }));
|
|
13
13
|
}
|
|
14
14
|
const styles = StyleSheet.create({
|
|
15
15
|
container: {
|
|
16
|
-
flex: 1,
|
|
17
16
|
flexDirection: "row",
|
|
18
17
|
alignItems: "center",
|
|
19
18
|
},
|
|
@@ -22,10 +21,12 @@ const styles = StyleSheet.create({
|
|
|
22
21
|
},
|
|
23
22
|
title: {
|
|
24
23
|
fontSize: 15,
|
|
24
|
+
lineHeight: 20,
|
|
25
25
|
fontWeight: "500",
|
|
26
26
|
},
|
|
27
27
|
description: {
|
|
28
28
|
fontSize: 13,
|
|
29
|
+
lineHeight: 18,
|
|
29
30
|
marginTop: 1,
|
|
30
31
|
},
|
|
31
32
|
actions: {
|
|
@@ -13,7 +13,7 @@ export function SnapProgress({ element: { props }, }) {
|
|
|
13
13
|
}
|
|
14
14
|
const styles = StyleSheet.create({
|
|
15
15
|
wrap: { flex: 1, width: "100%", gap: 4 },
|
|
16
|
-
label: { fontSize: 13 },
|
|
16
|
+
label: { fontSize: 13, lineHeight: 18 },
|
|
17
17
|
track: {
|
|
18
18
|
height: 10,
|
|
19
19
|
borderRadius: 9999,
|
|
@@ -20,23 +20,24 @@ export function SnapSlider({ element: { props }, }) {
|
|
|
20
20
|
? Math.min(max, Math.max(min, value))
|
|
21
21
|
: fallback;
|
|
22
22
|
const label = props.label != null ? String(props.label) : null;
|
|
23
|
+
const showValue = props.showValue === true;
|
|
23
24
|
const minLabel = props.minLabel != null ? String(props.minLabel) : null;
|
|
24
25
|
const maxLabel = props.maxLabel != null ? String(props.maxLabel) : null;
|
|
25
|
-
return (_jsxs(View, { style: styles.wrap, children: [label ? (_jsxs(View, { style: styles.labelRow, children: [_jsx(Text, { style: [styles.label, { color: colors.text }], children: label }), _jsx(Text, { style: [styles.valueText, { color: colors.textSecondary }], children: String(Math.round(clamped)) })] })) : null, _jsx(Slider, { style: styles.slider, minimumValue: min, maximumValue: max, step: step > 0 ? step : 1, value: clamped, onValueChange: (v) => set(path, v), minimumTrackTintColor: accentHex, maximumTrackTintColor: colors.muted, thumbTintColor: accentHex }), minLabel != null || maxLabel != null ? (_jsxs(View, { style: styles.minMaxRow, children: [_jsx(Text, { style: [styles.minMax, { color: colors.textSecondary }], children: minLabel ?? String(min) }), _jsx(Text, { style: [styles.minMax, { color: colors.textSecondary }], children: maxLabel ?? String(max) })] })) : null] }));
|
|
26
|
+
return (_jsxs(View, { style: styles.wrap, children: [label ? (_jsxs(View, { style: styles.labelRow, children: [_jsx(Text, { style: [styles.label, { color: colors.text }], children: label }), showValue && (_jsx(Text, { style: [styles.valueText, { color: colors.textSecondary }], children: String(Math.round(clamped)) }))] })) : null, _jsx(Slider, { style: styles.slider, minimumValue: min, maximumValue: max, step: step > 0 ? step : 1, value: clamped, onValueChange: (v) => set(path, v), minimumTrackTintColor: accentHex, maximumTrackTintColor: colors.muted, thumbTintColor: accentHex }), minLabel != null || maxLabel != null ? (_jsxs(View, { style: styles.minMaxRow, children: [_jsx(Text, { style: [styles.minMax, { color: colors.textSecondary }], children: minLabel ?? String(min) }), _jsx(Text, { style: [styles.minMax, { color: colors.textSecondary }], children: maxLabel ?? String(max) })] })) : null] }));
|
|
26
27
|
}
|
|
27
28
|
const styles = StyleSheet.create({
|
|
28
|
-
wrap: { width: "100%", gap:
|
|
29
|
+
wrap: { width: "100%", gap: 2 },
|
|
29
30
|
labelRow: {
|
|
30
31
|
flexDirection: "row",
|
|
31
32
|
justifyContent: "space-between",
|
|
32
33
|
alignItems: "center",
|
|
33
34
|
},
|
|
34
|
-
label: { fontSize: 13, fontWeight: "500", flex: 1 },
|
|
35
|
-
valueText: { fontSize: 13 },
|
|
35
|
+
label: { fontSize: 13, lineHeight: 18, fontWeight: "500", flex: 1 },
|
|
36
|
+
valueText: { fontSize: 13, lineHeight: 18 },
|
|
36
37
|
slider: { width: "100%", height: 40 },
|
|
37
38
|
minMaxRow: {
|
|
38
39
|
flexDirection: "row",
|
|
39
40
|
justifyContent: "space-between",
|
|
40
41
|
},
|
|
41
|
-
minMax: { fontSize: 12 },
|
|
42
|
+
minMax: { fontSize: 12, lineHeight: 16 },
|
|
42
43
|
});
|
|
@@ -3,7 +3,7 @@ import { StyleSheet, Text, View } from "react-native";
|
|
|
3
3
|
import { useSnapTheme } from "../theme.js";
|
|
4
4
|
const SIZE_STYLES = {
|
|
5
5
|
md: { fontSize: 16, lineHeight: 24 },
|
|
6
|
-
sm: { fontSize: 13 },
|
|
6
|
+
sm: { fontSize: 13, lineHeight: 18 },
|
|
7
7
|
};
|
|
8
8
|
const WEIGHT_MAP = {
|
|
9
9
|
bold: "700",
|
|
@@ -69,7 +69,7 @@ export function SnapToggleGroup({ element: { props }, }) {
|
|
|
69
69
|
}
|
|
70
70
|
const styles = StyleSheet.create({
|
|
71
71
|
wrap: { width: "100%", gap: 6 },
|
|
72
|
-
label: { fontSize: 13, fontWeight: "500" },
|
|
72
|
+
label: { fontSize: 13, lineHeight: 18, fontWeight: "500" },
|
|
73
73
|
group: {
|
|
74
74
|
padding: 4,
|
|
75
75
|
borderRadius: 8,
|
|
@@ -93,6 +93,7 @@ const styles = StyleSheet.create({
|
|
|
93
93
|
},
|
|
94
94
|
optionText: {
|
|
95
95
|
fontSize: 13,
|
|
96
|
+
lineHeight: 18,
|
|
96
97
|
fontWeight: "500",
|
|
97
98
|
},
|
|
98
99
|
});
|
|
@@ -6,11 +6,11 @@ const DEFAULT_LIGHT = {
|
|
|
6
6
|
text: "#111111",
|
|
7
7
|
textSecondary: "#6b7280",
|
|
8
8
|
border: "#E5E7EB",
|
|
9
|
-
inputBg: "rgba(0,0,0,0.
|
|
10
|
-
muted: "rgba(0,0,0,0.
|
|
11
|
-
mutedSubtle: "rgba(0,0,0,0.
|
|
12
|
-
mutedHover: "rgba(0,0,0,0.
|
|
13
|
-
mutedSelected: "rgba(0,0,0,0.
|
|
9
|
+
inputBg: "rgba(0,0,0,0.06)",
|
|
10
|
+
muted: "rgba(0,0,0,0.08)",
|
|
11
|
+
mutedSubtle: "rgba(0,0,0,0.04)",
|
|
12
|
+
mutedHover: "rgba(0,0,0,0.12)",
|
|
13
|
+
mutedSelected: "rgba(0,0,0,0.16)",
|
|
14
14
|
};
|
|
15
15
|
const DEFAULT_DARK = {
|
|
16
16
|
bg: "#111318",
|
|
@@ -18,11 +18,11 @@ const DEFAULT_DARK = {
|
|
|
18
18
|
text: "#fafafa",
|
|
19
19
|
textSecondary: "#a1a1aa",
|
|
20
20
|
border: "#2D2D44",
|
|
21
|
-
inputBg: "rgba(255,255,255,0.
|
|
22
|
-
muted: "rgba(255,255,255,0.
|
|
23
|
-
mutedSubtle: "rgba(255,255,255,0.
|
|
24
|
-
mutedHover: "rgba(255,255,255,0.
|
|
25
|
-
mutedSelected: "rgba(255,255,255,0.
|
|
21
|
+
inputBg: "rgba(255,255,255,0.04)",
|
|
22
|
+
muted: "rgba(255,255,255,0.06)",
|
|
23
|
+
mutedSubtle: "rgba(255,255,255,0.03)",
|
|
24
|
+
mutedHover: "rgba(255,255,255,0.08)",
|
|
25
|
+
mutedSelected: "rgba(255,255,255,0.12)",
|
|
26
26
|
};
|
|
27
27
|
const SnapThemeContext = createContext({
|
|
28
28
|
mode: "dark",
|
|
@@ -57,7 +57,7 @@ function SnapCardV2Inner({ snap, handlers, loading, borderRadius, showOverflowWa
|
|
|
57
57
|
cardStyles.card,
|
|
58
58
|
{
|
|
59
59
|
borderRadius,
|
|
60
|
-
maxHeight,
|
|
60
|
+
...(!showOverflowWarning && { maxHeight: SNAP_MAX_HEIGHT }),
|
|
61
61
|
borderColor: colors.border,
|
|
62
62
|
backgroundColor: colors.surface,
|
|
63
63
|
},
|
package/dist/schemas.d.ts
CHANGED
|
@@ -68,17 +68,12 @@ export type SnapHandlerResult = {
|
|
|
68
68
|
effects?: z.input<typeof snapResponseSchema>["effects"];
|
|
69
69
|
ui: SnapSpecInput;
|
|
70
70
|
};
|
|
71
|
-
/**
|
|
72
|
-
* @deprecated `nonce` and `audience` are currently optional for backward
|
|
73
|
-
* compatibility but will become **required** in a future major version.
|
|
74
|
-
* Clients should always include both fields.
|
|
75
|
-
*/
|
|
76
71
|
export declare const payloadSchema: z.ZodObject<{
|
|
77
72
|
fid: z.ZodNumber;
|
|
78
73
|
inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
|
|
79
74
|
timestamp: z.ZodNumber;
|
|
80
|
-
nonce: z.
|
|
81
|
-
audience: z.
|
|
75
|
+
nonce: z.ZodString;
|
|
76
|
+
audience: z.ZodString;
|
|
82
77
|
}, z.core.$strip>;
|
|
83
78
|
export type SnapPayload = z.infer<typeof payloadSchema>;
|
|
84
79
|
export declare const ACTION_TYPE_GET: "get";
|
|
@@ -91,8 +86,8 @@ declare const snapPostActionSchema: z.ZodObject<{
|
|
|
91
86
|
fid: z.ZodNumber;
|
|
92
87
|
inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
|
|
93
88
|
timestamp: z.ZodNumber;
|
|
94
|
-
nonce: z.
|
|
95
|
-
audience: z.
|
|
89
|
+
nonce: z.ZodString;
|
|
90
|
+
audience: z.ZodString;
|
|
96
91
|
type: z.ZodLiteral<"post">;
|
|
97
92
|
}, z.core.$strip>;
|
|
98
93
|
export type SnapPostAction = z.infer<typeof snapPostActionSchema>;
|
|
@@ -102,8 +97,8 @@ export declare const snapActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
102
97
|
fid: z.ZodNumber;
|
|
103
98
|
inputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>>;
|
|
104
99
|
timestamp: z.ZodNumber;
|
|
105
|
-
nonce: z.
|
|
106
|
-
audience: z.
|
|
100
|
+
nonce: z.ZodString;
|
|
101
|
+
audience: z.ZodString;
|
|
107
102
|
type: z.ZodLiteral<"post">;
|
|
108
103
|
}, z.core.$strip>], "type">;
|
|
109
104
|
export type SnapAction = z.infer<typeof snapActionSchema>;
|
package/dist/schemas.js
CHANGED
|
@@ -31,20 +31,13 @@ const postInputValueSchema = z.union([
|
|
|
31
31
|
z.boolean(),
|
|
32
32
|
z.array(z.string()),
|
|
33
33
|
]);
|
|
34
|
-
/**
|
|
35
|
-
* @deprecated `nonce` and `audience` are currently optional for backward
|
|
36
|
-
* compatibility but will become **required** in a future major version.
|
|
37
|
-
* Clients should always include both fields.
|
|
38
|
-
*/
|
|
39
34
|
export const payloadSchema = z
|
|
40
35
|
.object({
|
|
41
36
|
fid: z.number().int().nonnegative(),
|
|
42
37
|
inputs: z.record(z.string(), postInputValueSchema).default({}),
|
|
43
38
|
timestamp: z.number().int(),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/** @deprecated Will become required. Clients should always send the target server origin. */
|
|
47
|
-
audience: z.string().optional(),
|
|
39
|
+
nonce: z.string(),
|
|
40
|
+
audience: z.string(),
|
|
48
41
|
})
|
|
49
42
|
.strip();
|
|
50
43
|
export const ACTION_TYPE_GET = "get";
|
|
@@ -77,36 +77,29 @@ export async function parseRequest(request, options = {}) {
|
|
|
77
77
|
},
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const url = new URL(request.url);
|
|
91
|
-
const proto = request.headers.get("x-forwarded-proto") ??
|
|
92
|
-
url.protocol.replace(":", "");
|
|
93
|
-
const host = request.headers.get("x-forwarded-host") ?? url.host;
|
|
94
|
-
expectedOrigin = `${proto}://${host}`;
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
// do nothing
|
|
98
|
-
}
|
|
80
|
+
// Audience validation: ensure the payload audience matches the server origin.
|
|
81
|
+
let expectedOrigin = options.requestOrigin;
|
|
82
|
+
if (expectedOrigin === undefined) {
|
|
83
|
+
try {
|
|
84
|
+
const url = new URL(request.url);
|
|
85
|
+
const proto = request.headers.get("x-forwarded-proto") ??
|
|
86
|
+
url.protocol.replace(":", "");
|
|
87
|
+
const host = request.headers.get("x-forwarded-host") ?? url.host;
|
|
88
|
+
expectedOrigin = `${proto}://${host}`;
|
|
99
89
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
success: false,
|
|
103
|
-
error: {
|
|
104
|
-
type: "origin_mismatch",
|
|
105
|
-
message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
|
|
106
|
-
},
|
|
107
|
-
};
|
|
90
|
+
catch {
|
|
91
|
+
// do nothing
|
|
108
92
|
}
|
|
109
93
|
}
|
|
94
|
+
if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
|
|
95
|
+
return {
|
|
96
|
+
success: false,
|
|
97
|
+
error: {
|
|
98
|
+
type: "origin_mismatch",
|
|
99
|
+
message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
110
103
|
return {
|
|
111
104
|
success: true,
|
|
112
105
|
action: {
|
package/dist/ui/catalog.d.ts
CHANGED
|
@@ -295,6 +295,7 @@ export declare const snapJsonRenderCatalog: import("@json-render/core").Catalog<
|
|
|
295
295
|
step: z.ZodOptional<z.ZodNumber>;
|
|
296
296
|
defaultValue: z.ZodOptional<z.ZodNumber>;
|
|
297
297
|
label: z.ZodOptional<z.ZodString>;
|
|
298
|
+
showValue: z.ZodOptional<z.ZodBoolean>;
|
|
298
299
|
}, z.core.$strip>;
|
|
299
300
|
description: string;
|
|
300
301
|
};
|
package/dist/ui/slider.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export declare const sliderProps: z.ZodObject<{
|
|
|
9
9
|
step: z.ZodOptional<z.ZodNumber>;
|
|
10
10
|
defaultValue: z.ZodOptional<z.ZodNumber>;
|
|
11
11
|
label: z.ZodOptional<z.ZodString>;
|
|
12
|
+
showValue: z.ZodOptional<z.ZodBoolean>;
|
|
12
13
|
}, z.core.$strip>;
|
|
13
14
|
export type SliderProps = z.infer<typeof sliderProps>;
|
package/dist/ui/slider.js
CHANGED
|
@@ -10,6 +10,8 @@ export const sliderProps = z
|
|
|
10
10
|
step: z.number().optional(),
|
|
11
11
|
defaultValue: z.number().optional(),
|
|
12
12
|
label: z.string().max(SLIDER_MAX_LABEL_CHARS).optional(),
|
|
13
|
+
/** When true, display the current value next to the label. */
|
|
14
|
+
showValue: z.boolean().optional(),
|
|
13
15
|
})
|
|
14
16
|
.superRefine((val, ctx) => {
|
|
15
17
|
if (val.min > val.max) {
|
package/llms.txt
CHANGED
|
@@ -134,6 +134,7 @@ Field values are sent in POST `inputs[name]` when a `submit` action fires.
|
|
|
134
134
|
- `step` (number, optional, > 0. Default: 1)
|
|
135
135
|
- `defaultValue` (number, optional, between min and max)
|
|
136
136
|
- `label` (string, optional, max 60)
|
|
137
|
+
- `showValue` (boolean, optional): display the current value next to the label
|
|
137
138
|
- POST value: number
|
|
138
139
|
|
|
139
140
|
**switch** — Boolean toggle.
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ export function SnapSlider({
|
|
|
16
16
|
const max = Number(props.max ?? 100);
|
|
17
17
|
const step = Number(props.step ?? 1);
|
|
18
18
|
const label = props.label ? String(props.label) : undefined;
|
|
19
|
+
const showValue = props.showValue === true;
|
|
19
20
|
const path = `/inputs/${name}`;
|
|
20
21
|
const raw = get(path);
|
|
21
22
|
const value =
|
|
@@ -27,7 +28,16 @@ export function SnapSlider({
|
|
|
27
28
|
|
|
28
29
|
return (
|
|
29
30
|
<div className="flex w-full flex-col gap-1.5">
|
|
30
|
-
{label &&
|
|
31
|
+
{label && (
|
|
32
|
+
<div className="flex items-center justify-between">
|
|
33
|
+
<Label style={{ color: colors.text }}>{label}</Label>
|
|
34
|
+
{showValue && (
|
|
35
|
+
<span style={{ color: colors.textMuted, fontSize: 13, lineHeight: "18px" }}>
|
|
36
|
+
{Math.round(value)}
|
|
37
|
+
</span>
|
|
38
|
+
)}
|
|
39
|
+
</div>
|
|
40
|
+
)}
|
|
31
41
|
<input
|
|
32
42
|
type="range"
|
|
33
43
|
min={min}
|
|
@@ -65,7 +65,7 @@ export function SnapActionButton({
|
|
|
65
65
|
return <I size={16} color={iconColor} />;
|
|
66
66
|
})()
|
|
67
67
|
: null}
|
|
68
|
-
<Text style={{ color: textColor, fontSize: 14, fontWeight: "600" }}>
|
|
68
|
+
<Text style={{ color: textColor, fontSize: 14, lineHeight: 18, fontWeight: "600" }}>
|
|
69
69
|
{label}
|
|
70
70
|
</Text>
|
|
71
71
|
{showExternalIcon ? (
|
|
@@ -13,7 +13,7 @@ export function SnapBadge({
|
|
|
13
13
|
const iconName = props.icon ? String(props.icon) : undefined;
|
|
14
14
|
const isAccent = !color || color === "accent";
|
|
15
15
|
const resolvedColor = isAccent ? accentHex : hex(color);
|
|
16
|
-
const isFilled = variant
|
|
16
|
+
const isFilled = variant !== "outline";
|
|
17
17
|
|
|
18
18
|
const Icon = iconName ? ICON_MAP[iconName] : undefined;
|
|
19
19
|
|
|
@@ -54,6 +54,7 @@ const styles = StyleSheet.create({
|
|
|
54
54
|
},
|
|
55
55
|
label: {
|
|
56
56
|
fontSize: 12,
|
|
57
|
+
lineHeight: 16,
|
|
57
58
|
fontWeight: "500",
|
|
58
59
|
},
|
|
59
60
|
});
|
|
@@ -66,8 +66,8 @@ export function SnapBarChart({
|
|
|
66
66
|
const styles = StyleSheet.create({
|
|
67
67
|
wrap: { flex: 1, width: "100%", gap: 8 },
|
|
68
68
|
row: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
69
|
-
label: { width: 80, fontSize: 12, textAlign: "right" },
|
|
69
|
+
label: { width: 80, fontSize: 12, lineHeight: 16, textAlign: "right" },
|
|
70
70
|
track: { flex: 1, height: 10, borderRadius: 9999, overflow: "hidden" },
|
|
71
71
|
fill: { height: "100%", borderRadius: 9999 },
|
|
72
|
-
value: { width: 32, fontSize: 12, fontVariant: ["tabular-nums"] },
|
|
72
|
+
value: { width: 32, fontSize: 12, lineHeight: 16, fontVariant: ["tabular-nums"] },
|
|
73
73
|
});
|
|
@@ -147,6 +147,6 @@ const styles = StyleSheet.create({
|
|
|
147
147
|
alignItems: "center",
|
|
148
148
|
justifyContent: "center",
|
|
149
149
|
},
|
|
150
|
-
cellText: { fontSize: 12, fontWeight: "600" },
|
|
150
|
+
cellText: { fontSize: 12, lineHeight: 16, fontWeight: "600" },
|
|
151
151
|
selectionText: { fontSize: 11, fontFamily: "monospace", marginTop: 6 },
|
|
152
152
|
});
|
|
@@ -46,12 +46,13 @@ export function SnapInput({
|
|
|
46
46
|
|
|
47
47
|
const styles = StyleSheet.create({
|
|
48
48
|
wrap: { width: "100%", gap: 4 },
|
|
49
|
-
label: { fontSize: 13, fontWeight: "500" },
|
|
49
|
+
label: { fontSize: 13, lineHeight: 18, fontWeight: "500" },
|
|
50
50
|
input: {
|
|
51
51
|
borderWidth: 1,
|
|
52
52
|
borderRadius: 8,
|
|
53
53
|
paddingHorizontal: 12,
|
|
54
54
|
paddingVertical: 10,
|
|
55
55
|
fontSize: 14,
|
|
56
|
+
lineHeight: 18,
|
|
56
57
|
},
|
|
57
58
|
});
|
|
@@ -14,12 +14,12 @@ export function SnapItem({
|
|
|
14
14
|
: undefined;
|
|
15
15
|
const variant = String(props.variant ?? "default");
|
|
16
16
|
|
|
17
|
-
const containerVariant = { paddingVertical:
|
|
17
|
+
const containerVariant = { paddingVertical: 6, paddingHorizontal: 10 };
|
|
18
18
|
|
|
19
19
|
return (
|
|
20
20
|
<View style={[styles.container, containerVariant]}>
|
|
21
21
|
<View style={styles.content}>
|
|
22
|
-
<Text style={[styles.title, { color: colors.text }]}>{title}</Text>
|
|
22
|
+
{title ? <Text style={[styles.title, { color: colors.text }]}>{title}</Text> : null}
|
|
23
23
|
{description ? (
|
|
24
24
|
<Text style={[styles.description, { color: colors.textSecondary }]}>
|
|
25
25
|
{description}
|
|
@@ -37,7 +37,6 @@ export function SnapItem({
|
|
|
37
37
|
|
|
38
38
|
const styles = StyleSheet.create({
|
|
39
39
|
container: {
|
|
40
|
-
flex: 1,
|
|
41
40
|
flexDirection: "row",
|
|
42
41
|
alignItems: "center",
|
|
43
42
|
},
|
|
@@ -46,10 +45,12 @@ const styles = StyleSheet.create({
|
|
|
46
45
|
},
|
|
47
46
|
title: {
|
|
48
47
|
fontSize: 15,
|
|
48
|
+
lineHeight: 20,
|
|
49
49
|
fontWeight: "500",
|
|
50
50
|
},
|
|
51
51
|
description: {
|
|
52
52
|
fontSize: 13,
|
|
53
|
+
lineHeight: 18,
|
|
53
54
|
marginTop: 1,
|
|
54
55
|
},
|
|
55
56
|
actions: {
|
|
@@ -26,6 +26,7 @@ export function SnapSlider({
|
|
|
26
26
|
: fallback;
|
|
27
27
|
|
|
28
28
|
const label = props.label != null ? String(props.label) : null;
|
|
29
|
+
const showValue = props.showValue === true;
|
|
29
30
|
const minLabel = props.minLabel != null ? String(props.minLabel) : null;
|
|
30
31
|
const maxLabel = props.maxLabel != null ? String(props.maxLabel) : null;
|
|
31
32
|
|
|
@@ -34,9 +35,11 @@ export function SnapSlider({
|
|
|
34
35
|
{label ? (
|
|
35
36
|
<View style={styles.labelRow}>
|
|
36
37
|
<Text style={[styles.label, { color: colors.text }]}>{label}</Text>
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
|
|
38
|
+
{showValue && (
|
|
39
|
+
<Text style={[styles.valueText, { color: colors.textSecondary }]}>
|
|
40
|
+
{String(Math.round(clamped))}
|
|
41
|
+
</Text>
|
|
42
|
+
)}
|
|
40
43
|
</View>
|
|
41
44
|
) : null}
|
|
42
45
|
<Slider
|
|
@@ -65,18 +68,18 @@ export function SnapSlider({
|
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
const styles = StyleSheet.create({
|
|
68
|
-
wrap: { width: "100%", gap:
|
|
71
|
+
wrap: { width: "100%", gap: 2 },
|
|
69
72
|
labelRow: {
|
|
70
73
|
flexDirection: "row",
|
|
71
74
|
justifyContent: "space-between",
|
|
72
75
|
alignItems: "center",
|
|
73
76
|
},
|
|
74
|
-
label: { fontSize: 13, fontWeight: "500", flex: 1 },
|
|
75
|
-
valueText: { fontSize: 13 },
|
|
77
|
+
label: { fontSize: 13, lineHeight: 18, fontWeight: "500", flex: 1 },
|
|
78
|
+
valueText: { fontSize: 13, lineHeight: 18 },
|
|
76
79
|
slider: { width: "100%", height: 40 },
|
|
77
80
|
minMaxRow: {
|
|
78
81
|
flexDirection: "row",
|
|
79
82
|
justifyContent: "space-between",
|
|
80
83
|
},
|
|
81
|
-
minMax: { fontSize: 12 },
|
|
84
|
+
minMax: { fontSize: 12, lineHeight: 16 },
|
|
82
85
|
});
|
|
@@ -4,7 +4,7 @@ import { useSnapTheme } from "../theme";
|
|
|
4
4
|
|
|
5
5
|
const SIZE_STYLES: Record<string, { fontSize: number; lineHeight?: number; fontWeight?: "400" | "500" | "600" | "700" }> = {
|
|
6
6
|
md: { fontSize: 16, lineHeight: 24 },
|
|
7
|
-
sm: { fontSize: 13 },
|
|
7
|
+
sm: { fontSize: 13, lineHeight: 18 },
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
const WEIGHT_MAP: Record<string, "400" | "500" | "600" | "700"> = {
|
|
@@ -97,7 +97,7 @@ export function SnapToggleGroup({
|
|
|
97
97
|
|
|
98
98
|
const styles = StyleSheet.create({
|
|
99
99
|
wrap: { width: "100%", gap: 6 },
|
|
100
|
-
label: { fontSize: 13, fontWeight: "500" },
|
|
100
|
+
label: { fontSize: 13, lineHeight: 18, fontWeight: "500" },
|
|
101
101
|
group: {
|
|
102
102
|
padding: 4,
|
|
103
103
|
borderRadius: 8,
|
|
@@ -121,6 +121,7 @@ const styles = StyleSheet.create({
|
|
|
121
121
|
},
|
|
122
122
|
optionText: {
|
|
123
123
|
fontSize: 13,
|
|
124
|
+
lineHeight: 18,
|
|
124
125
|
fontWeight: "500",
|
|
125
126
|
},
|
|
126
127
|
});
|
|
@@ -24,11 +24,11 @@ const DEFAULT_LIGHT: SnapNativeColors = {
|
|
|
24
24
|
text: "#111111",
|
|
25
25
|
textSecondary: "#6b7280",
|
|
26
26
|
border: "#E5E7EB",
|
|
27
|
-
inputBg: "rgba(0,0,0,0.
|
|
28
|
-
muted: "rgba(0,0,0,0.
|
|
29
|
-
mutedSubtle: "rgba(0,0,0,0.
|
|
30
|
-
mutedHover: "rgba(0,0,0,0.
|
|
31
|
-
mutedSelected: "rgba(0,0,0,0.
|
|
27
|
+
inputBg: "rgba(0,0,0,0.06)",
|
|
28
|
+
muted: "rgba(0,0,0,0.08)",
|
|
29
|
+
mutedSubtle: "rgba(0,0,0,0.04)",
|
|
30
|
+
mutedHover: "rgba(0,0,0,0.12)",
|
|
31
|
+
mutedSelected: "rgba(0,0,0,0.16)",
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
const DEFAULT_DARK: SnapNativeColors = {
|
|
@@ -37,11 +37,11 @@ const DEFAULT_DARK: SnapNativeColors = {
|
|
|
37
37
|
text: "#fafafa",
|
|
38
38
|
textSecondary: "#a1a1aa",
|
|
39
39
|
border: "#2D2D44",
|
|
40
|
-
inputBg: "rgba(255,255,255,0.
|
|
41
|
-
muted: "rgba(255,255,255,0.
|
|
42
|
-
mutedSubtle: "rgba(255,255,255,0.
|
|
43
|
-
mutedHover: "rgba(255,255,255,0.
|
|
44
|
-
mutedSelected: "rgba(255,255,255,0.
|
|
40
|
+
inputBg: "rgba(255,255,255,0.04)",
|
|
41
|
+
muted: "rgba(255,255,255,0.06)",
|
|
42
|
+
mutedSubtle: "rgba(255,255,255,0.03)",
|
|
43
|
+
mutedHover: "rgba(255,255,255,0.08)",
|
|
44
|
+
mutedSelected: "rgba(255,255,255,0.12)",
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// ─── Context ──────────────────────────────────────────
|
package/src/schemas.ts
CHANGED
|
@@ -81,20 +81,13 @@ const postInputValueSchema = z.union([
|
|
|
81
81
|
z.array(z.string()),
|
|
82
82
|
]);
|
|
83
83
|
|
|
84
|
-
/**
|
|
85
|
-
* @deprecated `nonce` and `audience` are currently optional for backward
|
|
86
|
-
* compatibility but will become **required** in a future major version.
|
|
87
|
-
* Clients should always include both fields.
|
|
88
|
-
*/
|
|
89
84
|
export const payloadSchema = z
|
|
90
85
|
.object({
|
|
91
86
|
fid: z.number().int().nonnegative(),
|
|
92
87
|
inputs: z.record(z.string(), postInputValueSchema).default({}),
|
|
93
88
|
timestamp: z.number().int(),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/** @deprecated Will become required. Clients should always send the target server origin. */
|
|
97
|
-
audience: z.string().optional(),
|
|
89
|
+
nonce: z.string(),
|
|
90
|
+
audience: z.string(),
|
|
98
91
|
})
|
|
99
92
|
.strip();
|
|
100
93
|
|
|
@@ -148,39 +148,29 @@ export async function parseRequest(
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
const url = new URL(request.url);
|
|
165
|
-
const proto =
|
|
166
|
-
request.headers.get("x-forwarded-proto") ??
|
|
167
|
-
url.protocol.replace(":", "");
|
|
168
|
-
const host = request.headers.get("x-forwarded-host") ?? url.host;
|
|
169
|
-
expectedOrigin = `${proto}://${host}`;
|
|
170
|
-
} catch {
|
|
171
|
-
// do nothing
|
|
172
|
-
}
|
|
151
|
+
// Audience validation: ensure the payload audience matches the server origin.
|
|
152
|
+
let expectedOrigin = options.requestOrigin;
|
|
153
|
+
if (expectedOrigin === undefined) {
|
|
154
|
+
try {
|
|
155
|
+
const url = new URL(request.url);
|
|
156
|
+
const proto =
|
|
157
|
+
request.headers.get("x-forwarded-proto") ??
|
|
158
|
+
url.protocol.replace(":", "");
|
|
159
|
+
const host = request.headers.get("x-forwarded-host") ?? url.host;
|
|
160
|
+
expectedOrigin = `${proto}://${host}`;
|
|
161
|
+
} catch {
|
|
162
|
+
// do nothing
|
|
173
163
|
}
|
|
164
|
+
}
|
|
174
165
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
166
|
+
if (expectedOrigin !== undefined && body.audience !== expectedOrigin) {
|
|
167
|
+
return {
|
|
168
|
+
success: false,
|
|
169
|
+
error: {
|
|
170
|
+
type: "origin_mismatch",
|
|
171
|
+
message: `payload audience "${body.audience}" does not match expected origin "${expectedOrigin}"`,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
184
174
|
}
|
|
185
175
|
|
|
186
176
|
return {
|
package/src/ui/slider.ts
CHANGED
|
@@ -12,6 +12,8 @@ export const sliderProps = z
|
|
|
12
12
|
step: z.number().optional(),
|
|
13
13
|
defaultValue: z.number().optional(),
|
|
14
14
|
label: z.string().max(SLIDER_MAX_LABEL_CHARS).optional(),
|
|
15
|
+
/** When true, display the current value next to the label. */
|
|
16
|
+
showValue: z.boolean().optional(),
|
|
15
17
|
})
|
|
16
18
|
.superRefine((val, ctx) => {
|
|
17
19
|
if (val.min > val.max) {
|