rockin 0.0.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.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # rockin
2
+
3
+ Shared React UI for Rockstar projects.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add rockin
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { Button } from "rockin"
15
+ import { Loader } from "rockin"
16
+ import { useMounted } from "rockin"
17
+ import { cn } from "rockin"
18
+ import "rockin/styles.css"
19
+ ```
20
+
21
+ ## Development
22
+
23
+ ```bash
24
+ bun install
25
+ bun run typecheck
26
+ bun run build
27
+ ```
@@ -0,0 +1,201 @@
1
+ // src/icon/bell.tsx
2
+ import { cn } from "cn";
3
+ import {
4
+ LazyMotion,
5
+ domMin,
6
+ m,
7
+ useAnimation,
8
+ useReducedMotion
9
+ } from "motion/react";
10
+ import {
11
+ forwardRef,
12
+ useCallback,
13
+ useEffect,
14
+ useImperativeHandle,
15
+ useRef,
16
+ useState
17
+ } from "react";
18
+ import { jsx, jsxs } from "react/jsx-runtime";
19
+ var BellIcon = forwardRef(
20
+ ({
21
+ onMouseEnter,
22
+ onMouseLeave,
23
+ className,
24
+ size = 24,
25
+ duration = 1,
26
+ isAnimated = true,
27
+ color,
28
+ ...props
29
+ }, ref) => {
30
+ const controls = useAnimation();
31
+ const reduced = useReducedMotion();
32
+ const [ringing, setRinging] = useState(false);
33
+ const ringingRef = useRef(false);
34
+ const ringTimer = useRef(null);
35
+ const stopRing = useCallback(() => {
36
+ ringingRef.current = false;
37
+ setRinging(false);
38
+ controls.start("normal");
39
+ if (ringTimer.current) {
40
+ clearTimeout(ringTimer.current);
41
+ ringTimer.current = null;
42
+ }
43
+ }, [controls]);
44
+ const startRing = useCallback(() => {
45
+ if (reduced) {
46
+ stopRing();
47
+ return;
48
+ }
49
+ if (ringingRef.current) return;
50
+ ringingRef.current = true;
51
+ setRinging(true);
52
+ ringTimer.current = setTimeout(stopRing, 140);
53
+ }, [reduced, stopRing]);
54
+ useEffect(
55
+ () => () => {
56
+ if (ringTimer.current) clearTimeout(ringTimer.current);
57
+ },
58
+ []
59
+ );
60
+ useImperativeHandle(ref, () => {
61
+ return {
62
+ startAnimation: startRing,
63
+ stopAnimation: stopRing
64
+ };
65
+ }, [startRing, stopRing]);
66
+ const handleEnter = useCallback(
67
+ (e) => {
68
+ if (!isAnimated || reduced) return;
69
+ controls.start("animate");
70
+ onMouseEnter?.(e);
71
+ },
72
+ [controls, reduced, isAnimated, onMouseEnter]
73
+ );
74
+ const handleLeave = useCallback(
75
+ (e) => {
76
+ controls.start("normal");
77
+ onMouseLeave?.(e);
78
+ },
79
+ [controls, onMouseLeave]
80
+ );
81
+ const bellVariants = {
82
+ normal: { transform: "rotate(0deg)" },
83
+ ring: {
84
+ transform: "rotate(8deg)",
85
+ transition: {
86
+ duration: 0.14,
87
+ ease: [0.77, 0, 0.175, 1]
88
+ }
89
+ },
90
+ animate: {
91
+ rotate: [0, 7, -18, 14, -9, 5, -2, 0],
92
+ transition: {
93
+ duration: 1.3 * duration,
94
+ ease: "easeInOut",
95
+ times: [0, 0.09, 0.26, 0.45, 0.62, 0.78, 0.9, 1]
96
+ }
97
+ }
98
+ };
99
+ const clapperVariants = {
100
+ normal: { transform: "translateX(0px)" },
101
+ ring: {
102
+ transform: "translateX(1px)",
103
+ transition: {
104
+ duration: 0.14,
105
+ ease: [0.77, 0, 0.175, 1]
106
+ }
107
+ },
108
+ animate: {
109
+ x: [0, 1.5, -5, 4, -2.5, 1.5, -1, 0],
110
+ transition: {
111
+ duration: 1.3 * duration,
112
+ ease: "easeInOut",
113
+ times: [0, 0.09, 0.26, 0.45, 0.62, 0.78, 0.9, 1],
114
+ delay: 0.05 * duration
115
+ }
116
+ }
117
+ };
118
+ return /* @__PURE__ */ jsx(LazyMotion, { features: domMin, strict: true, children: /* @__PURE__ */ jsx(
119
+ m.div,
120
+ {
121
+ className: cn("relative inline-flex", className),
122
+ onMouseEnter: handleEnter,
123
+ onMouseLeave: handleLeave,
124
+ ...props,
125
+ style: { color, ...props.style },
126
+ children: /* @__PURE__ */ jsxs(
127
+ m.svg,
128
+ {
129
+ xmlns: "http://www.w3.org/2000/svg",
130
+ width: size,
131
+ height: size,
132
+ viewBox: "0 0 24 24",
133
+ fill: "none",
134
+ stroke: "currentColor",
135
+ strokeWidth: "2",
136
+ strokeLinecap: "round",
137
+ strokeLinejoin: "round",
138
+ animate: ringing ? "ring" : controls,
139
+ initial: "normal",
140
+ variants: bellVariants,
141
+ style: { transformOrigin: "top center" },
142
+ children: [
143
+ /* @__PURE__ */ jsx(m.path, { d: "M10.268 21a2 2 0 0 0 3.464 0", variants: clapperVariants }),
144
+ /* @__PURE__ */ jsx("path", { d: "M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326" })
145
+ ]
146
+ }
147
+ )
148
+ }
149
+ ) });
150
+ }
151
+ );
152
+ BellIcon.displayName = "BellIcon";
153
+
154
+ // src/icon/icon-swap.tsx
155
+ import { cn as cn2 } from "cn";
156
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
157
+ function IconSwap({ active, first, second, className }) {
158
+ return /* @__PURE__ */ jsxs2(
159
+ "span",
160
+ {
161
+ "aria-hidden": "true",
162
+ className: cn2("t-icon-swap", className),
163
+ "data-state": active ? "b" : "a",
164
+ children: [
165
+ /* @__PURE__ */ jsx2("span", { className: "t-icon", "data-icon": "a", children: first }),
166
+ /* @__PURE__ */ jsx2("span", { className: "t-icon", "data-icon": "b", children: second })
167
+ ]
168
+ }
169
+ );
170
+ }
171
+
172
+ // src/icon/loader.tsx
173
+ import { cn as cn3 } from "cn";
174
+ import React from "react";
175
+ import { jsx as jsx3 } from "react/jsx-runtime";
176
+ var Loader = React.forwardRef(
177
+ ({ className, size = 16, color = "currentColor", style, ...props }, ref) => {
178
+ const bars = Array(12).fill(0);
179
+ return /* @__PURE__ */ jsx3(
180
+ "div",
181
+ {
182
+ ref,
183
+ className: cn3("loader-wrapper", className),
184
+ style: {
185
+ "--spinner-size": `${size}px`,
186
+ "--spinner-color": color,
187
+ ...style
188
+ },
189
+ ...props,
190
+ children: /* @__PURE__ */ jsx3("div", { className: "loader-spinner", children: bars.map((_, i) => /* @__PURE__ */ jsx3("div", { className: "loader-bar" }, `spinner-bar-${i}`)) })
191
+ }
192
+ );
193
+ }
194
+ );
195
+ Loader.displayName = "SpellUI.Loader";
196
+
197
+ export {
198
+ BellIcon,
199
+ IconSwap,
200
+ Loader
201
+ };
@@ -0,0 +1,250 @@
1
+ // src/lib/capacitor.ts
2
+ function isNativeApp() {
3
+ if (typeof window === "undefined") return false;
4
+ return window.Capacitor?.isNativePlatform?.() === true;
5
+ }
6
+ function getNativePlatform() {
7
+ if (!isNativeApp()) return null;
8
+ return window.Capacitor?.getPlatform?.() ?? null;
9
+ }
10
+ function getNativeAppPlugin() {
11
+ if (!isNativeApp()) return null;
12
+ return window.Capacitor?.Plugins?.App ?? null;
13
+ }
14
+ function getNativeStatusBarPlugin() {
15
+ if (!isNativeApp()) return null;
16
+ return window.Capacitor?.Plugins?.StatusBar ?? null;
17
+ }
18
+ function getNativeBrowserPlugin() {
19
+ if (!isNativeApp()) return null;
20
+ return window.Capacitor?.Plugins?.Browser ?? null;
21
+ }
22
+ function getNativeSharePlugin() {
23
+ if (!isNativeApp()) return null;
24
+ return window.Capacitor?.Plugins?.Share ?? null;
25
+ }
26
+ function getNativeCameraPlugin() {
27
+ if (!isNativeApp()) return null;
28
+ return window.Capacitor?.Plugins?.Camera ?? null;
29
+ }
30
+ function getNativeImagePickerPlugin() {
31
+ if (!isNativeApp()) return null;
32
+ return window.Capacitor?.Plugins?.NativeImagePicker ?? null;
33
+ }
34
+ function getNativeShareFilePlugin() {
35
+ if (!isNativeApp()) return null;
36
+ return window.Capacitor?.Plugins?.NativeShareFile ?? null;
37
+ }
38
+ function getNativeThemePlugin() {
39
+ if (!isNativeApp()) return null;
40
+ return window.Capacitor?.Plugins?.NativeTheme ?? null;
41
+ }
42
+ function getNativePaymentPlugin() {
43
+ if (!isNativeApp()) return null;
44
+ return window.Capacitor?.Plugins?.NativePayment ?? null;
45
+ }
46
+ function getNativeShareTargetPlugin() {
47
+ if (!isNativeApp()) return null;
48
+ return window.Capacitor?.Plugins?.NativeShareTarget ?? null;
49
+ }
50
+ function getNativeAppSettingsPlugin() {
51
+ if (!isNativeApp()) return null;
52
+ return window.Capacitor?.Plugins?.NativeAppSettings ?? null;
53
+ }
54
+ function getNativeInAppUpdatePlugin() {
55
+ if (!isNativeApp()) return null;
56
+ return window.Capacitor?.Plugins?.NativeInAppUpdate ?? null;
57
+ }
58
+ async function openNativeAppSettings() {
59
+ const settings = getNativeAppSettingsPlugin();
60
+ if (!settings?.openAppSettings) return false;
61
+ try {
62
+ await settings.openAppSettings();
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+ async function openUpiPaymentUrl(url, options = {}) {
69
+ if (typeof window === "undefined") return false;
70
+ if (options.isNative ?? isNativeApp()) {
71
+ const payment = getNativePaymentPlugin();
72
+ if (payment?.openUpiUrl) {
73
+ const result = await payment.openUpiUrl({
74
+ url,
75
+ title: options.title
76
+ });
77
+ return result.opened;
78
+ }
79
+ }
80
+ window.location.href = url;
81
+ return true;
82
+ }
83
+ async function openExternalUrl(url, options = {}) {
84
+ if (typeof window === "undefined") return false;
85
+ if (options.isNative ?? isNativeApp()) {
86
+ const browser = getNativeBrowserPlugin();
87
+ if (browser?.open) {
88
+ await browser.open({ url });
89
+ return true;
90
+ }
91
+ }
92
+ const opened = window.open(
93
+ url,
94
+ options.target ?? "_blank",
95
+ options.features ?? "noopener,noreferrer"
96
+ );
97
+ return opened != null;
98
+ }
99
+ async function saveNativeShareImage(dataUrl, options = {}) {
100
+ if (!(options.isNative ?? isNativeApp())) return null;
101
+ const plugin = getNativeShareFilePlugin();
102
+ if (!plugin?.saveImage) return null;
103
+ try {
104
+ const result = await plugin.saveImage({
105
+ data: dataUrl,
106
+ fileName: options.fileName
107
+ });
108
+ return result.path ?? null;
109
+ } catch {
110
+ return null;
111
+ }
112
+ }
113
+ async function shareNativeOrWeb(data, options = {}) {
114
+ if (typeof window === "undefined") return false;
115
+ if (options.isNative ?? isNativeApp()) {
116
+ const share = getNativeSharePlugin();
117
+ if (share?.share) {
118
+ await share.share(data);
119
+ return true;
120
+ }
121
+ }
122
+ const { files: _files, ...webData } = data;
123
+ if (typeof navigator.share === "function") {
124
+ await navigator.share(webData);
125
+ return true;
126
+ }
127
+ return false;
128
+ }
129
+ function isNativePickerCancel(error) {
130
+ if (!(error instanceof Error)) return false;
131
+ const message = error.message.toLowerCase();
132
+ return message.includes("cancel") || message.includes("dismiss") || message.includes("no image") || message.includes("user denied");
133
+ }
134
+ function imageTypeFromFormat(format, fallback) {
135
+ if (!format) return fallback;
136
+ const normalized = format.toLowerCase();
137
+ if (normalized === "jpg") return "image/jpeg";
138
+ if (normalized === "jpeg") return "image/jpeg";
139
+ if (normalized === "png") return "image/png";
140
+ if (normalized === "webp") return "image/webp";
141
+ if (normalized === "heic") return "image/heic";
142
+ if (normalized === "heif") return "image/heif";
143
+ return fallback;
144
+ }
145
+ function imageExtensionFromType(type) {
146
+ if (type.includes("png")) return "png";
147
+ if (type.includes("webp")) return "webp";
148
+ if (type.includes("heic")) return "heic";
149
+ if (type.includes("heif")) return "heif";
150
+ return "jpg";
151
+ }
152
+ function nativeSharedFileToFile(sharedFile, fallbackName = "native-image.jpg") {
153
+ const binary = atob(sharedFile.data);
154
+ const bytes = new Uint8Array(binary.length);
155
+ for (let index = 0; index < binary.length; index++) {
156
+ bytes[index] = binary.charCodeAt(index);
157
+ }
158
+ return new File([bytes], sharedFile.name || fallbackName, {
159
+ type: sharedFile.type || "image/jpeg",
160
+ lastModified: Date.now()
161
+ });
162
+ }
163
+ async function nativePhotoToFile(photo, index, prefix) {
164
+ const src = photo.webPath ?? photo.path;
165
+ if (!src) {
166
+ throw new Error("Unable to read selected image.");
167
+ }
168
+ const response = await fetch(src);
169
+ if (!response.ok) {
170
+ throw new Error("Unable to read selected image.");
171
+ }
172
+ const blob = await response.blob();
173
+ const type = blob.type || imageTypeFromFormat(photo.format, "image/jpeg");
174
+ const extension = imageExtensionFromType(type);
175
+ return new File([blob], `${prefix}-${Date.now()}-${index}.${extension}`, {
176
+ type,
177
+ lastModified: Date.now()
178
+ });
179
+ }
180
+ async function pickNativeImageFiles({
181
+ isNative,
182
+ multiple = false,
183
+ limit = multiple ? 10 : 1,
184
+ quality = 85,
185
+ prefix = "image"
186
+ }) {
187
+ if (!(isNative ?? isNativeApp())) return null;
188
+ const camera = getNativeCameraPlugin();
189
+ if (!camera) return null;
190
+ try {
191
+ const photos = multiple && camera.pickImages ? (await camera.pickImages({ limit, quality })).photos : [
192
+ await camera.getPhoto?.({
193
+ allowEditing: false,
194
+ quality,
195
+ resultType: "uri",
196
+ source: "PROMPT"
197
+ })
198
+ ].filter((photo) => Boolean(photo));
199
+ return Promise.all(
200
+ photos.slice(0, limit).map((photo, index) => nativePhotoToFile(photo, index, prefix))
201
+ );
202
+ } catch (error) {
203
+ if (isNativePickerCancel(error)) return [];
204
+ throw error;
205
+ }
206
+ }
207
+ async function pickNativeChooserImageFiles({
208
+ isNative,
209
+ limit = 1,
210
+ title = "Select image"
211
+ }) {
212
+ if (!(isNative ?? isNativeApp())) return null;
213
+ const picker = getNativeImagePickerPlugin();
214
+ if (!picker?.pickImages) return null;
215
+ try {
216
+ const result = await picker.pickImages({
217
+ limit,
218
+ title
219
+ });
220
+ return (result.files ?? []).filter((file) => file.type?.startsWith("image/")).slice(0, limit).map((file) => nativeSharedFileToFile(file));
221
+ } catch (error) {
222
+ if (isNativePickerCancel(error)) return [];
223
+ throw error;
224
+ }
225
+ }
226
+
227
+ export {
228
+ isNativeApp,
229
+ getNativePlatform,
230
+ getNativeAppPlugin,
231
+ getNativeStatusBarPlugin,
232
+ getNativeBrowserPlugin,
233
+ getNativeSharePlugin,
234
+ getNativeCameraPlugin,
235
+ getNativeImagePickerPlugin,
236
+ getNativeShareFilePlugin,
237
+ getNativeThemePlugin,
238
+ getNativePaymentPlugin,
239
+ getNativeShareTargetPlugin,
240
+ getNativeAppSettingsPlugin,
241
+ getNativeInAppUpdatePlugin,
242
+ openNativeAppSettings,
243
+ openUpiPaymentUrl,
244
+ openExternalUrl,
245
+ saveNativeShareImage,
246
+ shareNativeOrWeb,
247
+ nativeSharedFileToFile,
248
+ pickNativeImageFiles,
249
+ pickNativeChooserImageFiles
250
+ };
@@ -0,0 +1,69 @@
1
+ // src/utils/parms-client.ts
2
+ import {
3
+ createParser,
4
+ parseAsString,
5
+ parseAsStringLiteral
6
+ } from "nuqs";
7
+ var parseAsPage = createParser({
8
+ parse(value) {
9
+ const page = Number(value);
10
+ return Number.isInteger(page) && page > 0 ? page : null;
11
+ },
12
+ serialize: String
13
+ }).withDefault(1);
14
+ var parseAsFlag = createParser({
15
+ parse(value) {
16
+ return value === "" || value === "1" || value === "true" ? true : null;
17
+ },
18
+ serialize(value) {
19
+ return value ? "1" : "";
20
+ }
21
+ });
22
+ var searchParams = {
23
+ tab: parseAsString.withDefault(""),
24
+ query: parseAsString.withDefault(""),
25
+ category: parseAsString.withDefault(""),
26
+ productStatus: parseAsStringLiteral([
27
+ "active",
28
+ "draft",
29
+ "archived"
30
+ ]).withDefault("active"),
31
+ user: parseAsString.withDefault(""),
32
+ transaction: parseAsString.withDefault(""),
33
+ page: parseAsPage,
34
+ transactionPage: parseAsPage,
35
+ cart: parseAsFlag.withDefault(false),
36
+ notification: parseAsFlag.withDefault(false)
37
+ };
38
+ var searchParamKeys = {
39
+ tab: "tab",
40
+ query: "q",
41
+ category: "c",
42
+ productStatus: "status",
43
+ user: "u",
44
+ transaction: "id",
45
+ page: "page",
46
+ transactionPage: "tp",
47
+ cart: "cart",
48
+ notification: "notification"
49
+ };
50
+ function hasFlagSearchParam(searchParams2, key) {
51
+ return searchParams2.has(searchParamKeys[key]);
52
+ }
53
+ function buildFlagSearchParamHref(pathname, searchParams2, key, enabled) {
54
+ const searchKey = searchParamKeys[key];
55
+ const nextParams = new URLSearchParams(searchParams2.toString());
56
+ nextParams.delete(searchKey);
57
+ const query = nextParams.toString();
58
+ if (enabled) {
59
+ return query ? `${pathname}?${searchKey}&${query}` : `${pathname}?${searchKey}`;
60
+ }
61
+ return query ? `${pathname}?${query}` : pathname;
62
+ }
63
+
64
+ export {
65
+ searchParams,
66
+ searchParamKeys,
67
+ hasFlagSearchParam,
68
+ buildFlagSearchParamHref
69
+ };