@farcaster/snap 1.15.0 → 1.15.1

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.
@@ -1,6 +1,8 @@
1
1
  import { type ReactNode } from "react";
2
- export declare function SnapPreviewAccentProvider({ pageAccent, children, }: {
2
+ export declare function SnapPreviewAccentProvider({ pageAccent, appearance, children, }: {
3
3
  pageAccent: string | undefined;
4
+ appearance?: "light" | "dark";
4
5
  children: ReactNode;
5
6
  }): import("react/jsx-runtime").JSX.Element;
6
7
  export declare function useSnapPreviewPageAccent(): string | undefined;
8
+ export declare function useSnapAppearance(): "light" | "dark";
@@ -1,10 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { createContext, useContext } from "react";
4
- const SnapPreviewAccentContext = createContext(null);
5
- export function SnapPreviewAccentProvider({ pageAccent, children, }) {
6
- return (_jsx(SnapPreviewAccentContext.Provider, { value: { pageAccent }, children: children }));
4
+ const SnapPreviewContext = createContext(null);
5
+ export function SnapPreviewAccentProvider({ pageAccent, appearance = "dark", children, }) {
6
+ return (_jsx(SnapPreviewContext.Provider, { value: { pageAccent, appearance }, children: children }));
7
7
  }
8
8
  export function useSnapPreviewPageAccent() {
9
- return useContext(SnapPreviewAccentContext)?.pageAccent;
9
+ return useContext(SnapPreviewContext)?.pageAccent;
10
+ }
11
+ export function useSnapAppearance() {
12
+ return useContext(SnapPreviewContext)?.appearance ?? "dark";
10
13
  }
@@ -1,9 +1,8 @@
1
1
  "use client";
2
2
  import { useMemo } from "react";
3
3
  import { useStateStore } from "@json-render/react";
4
- import { useColorMode } from "@neynar/ui/color-mode";
5
4
  import { resolveSnapPaletteHex } from "../lib/resolve-palette-hex.js";
6
- import { useSnapPreviewPageAccent } from "../accent-context.js";
5
+ import { useSnapPreviewPageAccent, useSnapAppearance } from "../accent-context.js";
7
6
  import { PALETTE_DARK_HEX, PALETTE_LIGHT_HEX } from "@farcaster/snap";
8
7
  /** Readable foreground color (black or white) for a given hex background. */
9
8
  export function pickForegroundForBg(hex) {
@@ -69,7 +68,7 @@ function buildSnapColors(accentName, mode) {
69
68
  */
70
69
  export function useSnapColors() {
71
70
  const { get } = useStateStore();
72
- const { mode } = useColorMode();
71
+ const mode = useSnapAppearance();
73
72
  const pageAccent = useSnapPreviewPageAccent();
74
73
  const fromState = get("/theme/accent");
75
74
  const accentRaw = (typeof pageAccent === "string" && pageAccent.length > 0
@@ -188,7 +188,7 @@ export function SnapView({ snap, handlers, loading = false, appearance = "dark",
188
188
  opacity: loading ? 1 : 0,
189
189
  pointerEvents: loading ? "auto" : "none",
190
190
  transition: "opacity 0.3s ease, backdrop-filter 0.3s ease",
191
- }, children: "Loading..." }), _jsx("div", { style: previewSurfaceStyle, children: _jsx(SnapPreviewAccentProvider, { pageAccent: snap.theme?.accent, children: _jsx(SnapCatalogView, { spec: spec, state: initialState, loading: false, onStateChange: (changes) => {
191
+ }, children: "Loading..." }), _jsx("div", { style: previewSurfaceStyle, children: _jsx(SnapPreviewAccentProvider, { pageAccent: snap.theme?.accent, appearance: appearance, children: _jsx(SnapCatalogView, { spec: spec, state: initialState, loading: false, onStateChange: (changes) => {
192
192
  applyStatePaths(stateRef.current, changes);
193
193
  }, onAction: handleAction }, pageKey) }) })] }));
194
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/snap",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "description": "Farcaster Snaps 🫰",
5
5
  "repository": {
6
6
  "type": "git",
@@ -2,28 +2,35 @@
2
2
 
3
3
  import { createContext, useContext, type ReactNode } from "react";
4
4
 
5
- type SnapPreviewAccentContextValue = {
5
+ type SnapPreviewContextValue = {
6
6
  /** From loaded snap `page.theme.accent` (undefined if the snap omits it). */
7
7
  pageAccent: string | undefined;
8
+ /** Light/dark appearance passed from SnapView. */
9
+ appearance: "light" | "dark";
8
10
  };
9
11
 
10
- const SnapPreviewAccentContext =
11
- createContext<SnapPreviewAccentContextValue | null>(null);
12
+ const SnapPreviewContext = createContext<SnapPreviewContextValue | null>(null);
12
13
 
13
14
  export function SnapPreviewAccentProvider({
14
15
  pageAccent,
16
+ appearance = "dark",
15
17
  children,
16
18
  }: {
17
19
  pageAccent: string | undefined;
20
+ appearance?: "light" | "dark";
18
21
  children: ReactNode;
19
22
  }) {
20
23
  return (
21
- <SnapPreviewAccentContext.Provider value={{ pageAccent }}>
24
+ <SnapPreviewContext.Provider value={{ pageAccent, appearance }}>
22
25
  {children}
23
- </SnapPreviewAccentContext.Provider>
26
+ </SnapPreviewContext.Provider>
24
27
  );
25
28
  }
26
29
 
27
30
  export function useSnapPreviewPageAccent(): string | undefined {
28
- return useContext(SnapPreviewAccentContext)?.pageAccent;
31
+ return useContext(SnapPreviewContext)?.pageAccent;
32
+ }
33
+
34
+ export function useSnapAppearance(): "light" | "dark" {
35
+ return useContext(SnapPreviewContext)?.appearance ?? "dark";
29
36
  }
@@ -2,9 +2,8 @@
2
2
 
3
3
  import { useMemo } from "react";
4
4
  import { useStateStore } from "@json-render/react";
5
- import { useColorMode } from "@neynar/ui/color-mode";
6
5
  import { resolveSnapPaletteHex } from "../lib/resolve-palette-hex";
7
- import { useSnapPreviewPageAccent } from "../accent-context";
6
+ import { useSnapPreviewPageAccent, useSnapAppearance } from "../accent-context";
8
7
  import type { PaletteColor } from "@farcaster/snap";
9
8
  import { PALETTE_DARK_HEX, PALETTE_LIGHT_HEX } from "@farcaster/snap";
10
9
 
@@ -113,7 +112,7 @@ function buildSnapColors(
113
112
  */
114
113
  export function useSnapColors(): SnapColors {
115
114
  const { get } = useStateStore();
116
- const { mode } = useColorMode();
115
+ const mode = useSnapAppearance();
117
116
  const pageAccent = useSnapPreviewPageAccent();
118
117
  const fromState = get("/theme/accent");
119
118
  const accentRaw =
@@ -304,7 +304,7 @@ export function SnapView({
304
304
  </div>
305
305
 
306
306
  <div style={previewSurfaceStyle}>
307
- <SnapPreviewAccentProvider pageAccent={snap.theme?.accent}>
307
+ <SnapPreviewAccentProvider pageAccent={snap.theme?.accent} appearance={appearance}>
308
308
  <SnapCatalogView
309
309
  key={pageKey}
310
310
  spec={spec}