rockin 0.0.36 → 0.0.38

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,3 +1,5 @@
1
+ import * as _ui_sdk_core from '@ui-sdk/core';
2
+
1
3
  type PluginListenerHandle = {
2
4
  remove: () => Promise<void>;
3
5
  };
@@ -197,4 +199,80 @@ declare function pickNativeChooserImageFiles({ isNative, limit, title, }: {
197
199
  title?: string;
198
200
  }): Promise<File[] | null>;
199
201
 
200
- export { type NativeSharePayload, type NativeSharedFile, type NativeUpdateInfo, type NativeUpdateState, getNativeAppPlugin, getNativeAppSettingsPlugin, getNativeBrowserPlugin, getNativeCameraPlugin, getNativeImagePickerPlugin, getNativeInAppUpdatePlugin, getNativePaymentPlugin, getNativePlatform, getNativeShareFilePlugin, getNativeSharePlugin, getNativeShareTargetPlugin, getNativeStatusBarPlugin, getNativeThemePlugin, isNativeApp, nativeSharedFileToFile, openExternalUrl, openNativeAppSettings, openUpiPaymentUrl, pickNativeChooserImageFiles, pickNativeImageFiles, saveNativeShareImage, shareNativeOrWeb };
202
+ declare const ACCENTS: readonly ["slate", "violet", "mint", "gold"];
203
+ type Accent = (typeof ACCENTS)[number];
204
+ declare const PREFERENCE_COOKIES: {
205
+ readonly colorScheme: "color-scheme";
206
+ readonly accent: "accent";
207
+ };
208
+ /**
209
+ * The app's saved preferences, kept in cookies so the server renders them too.
210
+ * Create them once per request from its `Cookie` header.
211
+ */
212
+ declare function createAppPreferences(cookie?: string | null): {
213
+ colorScheme: {
214
+ attribute: `data-${string}`;
215
+ global: boolean;
216
+ values: readonly ("system" | "light" | "dark")[];
217
+ defaultValue: "system" | "light" | "dark";
218
+ storage: {
219
+ id: string;
220
+ kind: "local" | "session" | "cookie";
221
+ readsOnServer: boolean;
222
+ script: (options: _ui_sdk_core.StorageScriptOptions) => string | undefined;
223
+ available: () => boolean;
224
+ get: () => string | null;
225
+ set: (value: string) => boolean;
226
+ remove: () => boolean;
227
+ subscribe(listener: (value: string | null) => void): () => void;
228
+ } | undefined;
229
+ initialState: _ui_sdk_core.ColorSchemeState;
230
+ get: () => _ui_sdk_core.ColorSchemeState;
231
+ set: (next: "system" | "light" | "dark", change?: {
232
+ reason?: _ui_sdk_core.ChangeReason;
233
+ event?: Event;
234
+ }) => boolean;
235
+ subscribe: (listener: (state: _ui_sdk_core.ColorSchemeState) => void) => () => void;
236
+ follow: <Key extends string>(store: _ui_sdk_core.ColorSchemeStore<Key>, key: Key) => () => void;
237
+ };
238
+ accent: {
239
+ attribute: `data-${string}`;
240
+ global: boolean;
241
+ values: readonly ("gold" | "violet" | "slate" | "mint")[];
242
+ defaultValue: "gold" | "violet" | "slate" | "mint";
243
+ storage: {
244
+ id: string;
245
+ kind: "local" | "session" | "cookie";
246
+ readsOnServer: boolean;
247
+ script: (options: _ui_sdk_core.StorageScriptOptions) => string | undefined;
248
+ available: () => boolean;
249
+ get: () => string | null;
250
+ set: (value: string) => boolean;
251
+ remove: () => boolean;
252
+ subscribe(listener: (value: string | null) => void): () => void;
253
+ } | undefined;
254
+ initialState: {
255
+ value: "gold" | "violet" | "slate" | "mint";
256
+ };
257
+ get: () => {
258
+ value: "gold" | "violet" | "slate" | "mint";
259
+ };
260
+ set: (next: "gold" | "violet" | "slate" | "mint", change?: {
261
+ reason?: _ui_sdk_core.ChangeReason;
262
+ event?: Event;
263
+ }) => boolean;
264
+ subscribe: (listener: (state: {
265
+ value: "gold" | "violet" | "slate" | "mint";
266
+ }) => void) => () => void;
267
+ follow: <Key extends string>(store: _ui_sdk_core.PreferenceStore<Key, {
268
+ value: "gold" | "violet" | "slate" | "mint";
269
+ }>, key: Key) => () => void;
270
+ };
271
+ };
272
+ type AppPreferences = ReturnType<typeof createAppPreferences>;
273
+ /** The `<html>` attributes for a request's saved preferences. */
274
+ declare function preferenceAttributes(cookie?: string | null): Record<`data-${string}`, string>;
275
+ /** Sets the saved preferences on `<html>` while the page parses, before it paints. */
276
+ declare function preferencesScript(cookie?: string | null): string;
277
+
278
+ export { ACCENTS, type Accent, type AppPreferences, type NativeSharePayload, type NativeSharedFile, type NativeUpdateInfo, type NativeUpdateState, PREFERENCE_COOKIES, createAppPreferences, getNativeAppPlugin, getNativeAppSettingsPlugin, getNativeBrowserPlugin, getNativeCameraPlugin, getNativeImagePickerPlugin, getNativeInAppUpdatePlugin, getNativePaymentPlugin, getNativePlatform, getNativeShareFilePlugin, getNativeSharePlugin, getNativeShareTargetPlugin, getNativeStatusBarPlugin, getNativeThemePlugin, isNativeApp, nativeSharedFileToFile, openExternalUrl, openNativeAppSettings, openUpiPaymentUrl, pickNativeChooserImageFiles, pickNativeImageFiles, preferenceAttributes, preferencesScript, saveNativeShareImage, shareNativeOrWeb };
package/dist/lib/index.js CHANGED
@@ -21,8 +21,18 @@ import {
21
21
  pickNativeImageFiles,
22
22
  saveNativeShareImage,
23
23
  shareNativeOrWeb
24
- } from "../chunk-ATPUW3SQ.js";
24
+ } from "../chunk-2LD63YUK.js";
25
+ import {
26
+ ACCENTS,
27
+ PREFERENCE_COOKIES,
28
+ createAppPreferences,
29
+ preferenceAttributes,
30
+ preferencesScript
31
+ } from "../chunk-X56ZEDOW.js";
25
32
  export {
33
+ ACCENTS,
34
+ PREFERENCE_COOKIES,
35
+ createAppPreferences,
26
36
  getNativeAppPlugin,
27
37
  getNativeAppSettingsPlugin,
28
38
  getNativeBrowserPlugin,
@@ -43,6 +53,8 @@ export {
43
53
  openUpiPaymentUrl,
44
54
  pickNativeChooserImageFiles,
45
55
  pickNativeImageFiles,
56
+ preferenceAttributes,
57
+ preferencesScript,
46
58
  saveNativeShareImage,
47
59
  shareNativeOrWeb
48
60
  };
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { ThemeProvider } from 'next-themes';
3
2
 
4
3
  declare const browserThemeColors: {
5
4
  readonly light: "#ffffff";
@@ -7,11 +6,14 @@ declare const browserThemeColors: {
7
6
  };
8
7
  type BrowserTheme = keyof typeof browserThemeColors;
9
8
  type BrowserThemeColors = Record<BrowserTheme, string>;
10
- type ProviderProps = React.ComponentProps<typeof ThemeProvider> & {
9
+ type ClientProviderProps = {
10
+ children?: React.ReactNode;
11
+ /** The request's `Cookie` header, so saved preferences render on the server. */
12
+ cookie?: string | null;
11
13
  light?: string;
12
14
  dark?: string;
13
15
  fullscreen?: boolean;
14
16
  };
15
- declare function Provider({ children, light, dark, fullscreen, ...props }: ProviderProps): React.JSX.Element;
17
+ declare function ClientProvider({ children, light, dark, fullscreen, cookie, }: ClientProviderProps): React.JSX.Element;
16
18
 
17
- export { type BrowserTheme, type BrowserThemeColors, Provider, type ProviderProps, browserThemeColors };
19
+ export { type BrowserTheme, type BrowserThemeColors, ClientProvider, type ClientProviderProps, browserThemeColors };
package/dist/provider.js CHANGED
@@ -1,13 +1,124 @@
1
1
  "use client";
2
2
  import {
3
- Provider,
4
- browserThemeColors
5
- } from "./chunk-54ZJAEO5.js";
6
- import "./chunk-GBVAFFZR.js";
7
- import "./chunk-3ZGQJTWY.js";
8
- import "./chunk-RT2YVQ2Y.js";
9
- import "./chunk-ATPUW3SQ.js";
3
+ TooltipProvider
4
+ } from "./chunk-GBVAFFZR.js";
5
+ import {
6
+ useFullscreen,
7
+ useNative
8
+ } from "./chunk-WR27Y55B.js";
9
+ import "./chunk-2LD63YUK.js";
10
+ import {
11
+ PreferencesProvider,
12
+ usePreferences,
13
+ useTheme
14
+ } from "./chunk-G3RYS466.js";
15
+ import {
16
+ TopLoader
17
+ } from "./chunk-3ZGQJTWY.js";
18
+ import "./chunk-X56ZEDOW.js";
19
+
20
+ // src/provider.tsx
21
+ import * as React from "react";
22
+ import { usePreference } from "@ui-sdk/react/preferences";
23
+ import { useShortcut } from "@ui-sdk/react/shortcuts";
24
+ import { GooeyToaster } from "goey-toast";
25
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
26
+ var browserThemeColors = {
27
+ light: "#ffffff",
28
+ dark: "#000000"
29
+ };
30
+ function BrowserChrome({ light, dark }) {
31
+ const { colorScheme } = usePreferences();
32
+ const { value, resolved } = usePreference(colorScheme);
33
+ React.useEffect(() => {
34
+ if (resolved === "unknown") return;
35
+ const style = resolved === "dark" ? "black-translucent" : "default";
36
+ for (const meta of document.head.querySelectorAll(
37
+ 'meta[name="apple-mobile-web-app-status-bar-style"]'
38
+ ))
39
+ meta.content = style;
40
+ window.dispatchEvent(
41
+ new CustomEvent("kdpower:theme-change", { detail: { theme: resolved } })
42
+ );
43
+ }, [resolved]);
44
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
45
+ value === "system" ? /* @__PURE__ */ jsxs(Fragment, { children: [
46
+ /* @__PURE__ */ jsx(
47
+ "meta",
48
+ {
49
+ name: "theme-color",
50
+ media: "(prefers-color-scheme: light)",
51
+ content: light
52
+ }
53
+ ),
54
+ /* @__PURE__ */ jsx(
55
+ "meta",
56
+ {
57
+ name: "theme-color",
58
+ media: "(prefers-color-scheme: dark)",
59
+ content: dark
60
+ }
61
+ )
62
+ ] }) : /* @__PURE__ */ jsx("meta", { name: "theme-color", content: value === "dark" ? dark : light }),
63
+ /* @__PURE__ */ jsx("style", { href: `rockin-chrome-${light}-${dark}`, precedence: "default", children: `:root{background-color:light-dark(${light},${dark})}` })
64
+ ] });
65
+ }
66
+ function ClientProvider({
67
+ children,
68
+ light = browserThemeColors.light,
69
+ dark = browserThemeColors.dark,
70
+ fullscreen = true,
71
+ cookie
72
+ }) {
73
+ return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(PreferencesProvider, { cookie, children: /* @__PURE__ */ jsxs(TopLoader, { children: [
74
+ /* @__PURE__ */ jsx(AppToaster, {}),
75
+ /* @__PURE__ */ jsx(AppStatusBarBackground, {}),
76
+ /* @__PURE__ */ jsx(BrowserChrome, { light, dark }),
77
+ /* @__PURE__ */ jsx(ThemeHotkey, {}),
78
+ fullscreen ? /* @__PURE__ */ jsx(FullscreenHotkey, {}) : null,
79
+ children
80
+ ] }) }) });
81
+ }
82
+ function AppToaster() {
83
+ const { resolvedTheme } = useTheme();
84
+ const toasterTheme = resolvedTheme === "dark" ? "dark" : "light";
85
+ return /* @__PURE__ */ jsx(
86
+ GooeyToaster,
87
+ {
88
+ theme: toasterTheme,
89
+ position: "bottom-right",
90
+ closeButton: "top-left"
91
+ },
92
+ toasterTheme
93
+ );
94
+ }
95
+ function AppStatusBarBackground() {
96
+ return /* @__PURE__ */ jsx(
97
+ "div",
98
+ {
99
+ "aria-hidden": true,
100
+ className: "fixed inset-x-0 top-0 z-50 hidden h-(--app-safe-top) bg-background/80 backdrop-blur-xl standalone:block native:block"
101
+ }
102
+ );
103
+ }
104
+ function ThemeHotkey() {
105
+ const { resolvedTheme, setTheme } = useTheme();
106
+ useShortcut(
107
+ "d",
108
+ () => setTheme(resolvedTheme === "dark" ? "light" : "dark"),
109
+ { description: "Toggle dark mode" }
110
+ );
111
+ return null;
112
+ }
113
+ function FullscreenHotkey() {
114
+ const isNative = useNative();
115
+ const { toggleFullscreen } = useFullscreen();
116
+ useShortcut(isNative ? null : "f", () => void toggleFullscreen(), {
117
+ description: "Toggle full screen"
118
+ });
119
+ return null;
120
+ }
10
121
  export {
11
- Provider,
122
+ ClientProvider,
12
123
  browserThemeColors
13
124
  };