@net-protocol/profiles 0.1.3 → 0.1.5
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 +6 -2
- package/dist/index.d.mts +93 -3
- package/dist/index.d.ts +93 -3
- package/dist/index.js +238 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +229 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +28 -3
- package/dist/react.d.ts +28 -3
- package/dist/react.js +27 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +27 -2
- package/dist/react.mjs.map +1 -1
- package/dist/{types-DnEzx4eb.d.mts → types-DDKLfc0r.d.mts} +4 -0
- package/dist/{types-DnEzx4eb.d.ts → types-DDKLfc0r.d.ts} +4 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -104,6 +104,7 @@ function UpdateProfile() {
|
|
|
104
104
|
| X Username | Your X (Twitter) handle | Stored without @ prefix (e.g., `myusername`) |
|
|
105
105
|
| Bio | Short profile bio | Max 280 characters |
|
|
106
106
|
| Display Name | User-chosen display name | Max 25 characters |
|
|
107
|
+
| Token Address | ERC-20 token that represents you | Valid EVM address (0x-prefixed) |
|
|
107
108
|
| Canvas | Custom HTML profile page | For advanced customization |
|
|
108
109
|
|
|
109
110
|
## Storage Keys
|
|
@@ -111,7 +112,8 @@ function UpdateProfile() {
|
|
|
111
112
|
| Key | Description | Data Format |
|
|
112
113
|
|-----|-------------|-------------|
|
|
113
114
|
| `PROFILE_PICTURE_STORAGE_KEY` | Profile picture URL | Plain string (URL) |
|
|
114
|
-
| `
|
|
115
|
+
| `PROFILE_X_USERNAME_STORAGE_KEY` | X username (legacy, prefer metadata) | Plain string |
|
|
116
|
+
| `PROFILE_METADATA_STORAGE_KEY` | Profile metadata JSON | `{ x_username: "handle", bio: "...", display_name: "...", token_address: "0x..." }` |
|
|
115
117
|
| `PROFILE_CANVAS_STORAGE_KEY` | Custom HTML canvas | HTML string |
|
|
116
118
|
|
|
117
119
|
## API Reference
|
|
@@ -121,7 +123,7 @@ function UpdateProfile() {
|
|
|
121
123
|
- `useProfilePicture({ chainId, userAddress })` - Fetch profile picture URL
|
|
122
124
|
- `useProfileXUsername({ chainId, userAddress })` - Fetch X username
|
|
123
125
|
- `useProfileCanvas({ chainId, userAddress })` - Fetch canvas HTML
|
|
124
|
-
- `useBasicUserProfileMetadata({ chainId, userAddress })` - Batch fetch picture
|
|
126
|
+
- `useBasicUserProfileMetadata({ chainId, userAddress })` - Batch fetch picture, username, bio, display name, and token address
|
|
125
127
|
|
|
126
128
|
### Utilities (from `@net-protocol/profiles`)
|
|
127
129
|
|
|
@@ -136,6 +138,8 @@ function UpdateProfile() {
|
|
|
136
138
|
- `isValidXUsername(username)` - Validate X username format
|
|
137
139
|
- `isValidBio(bio)` - Validate bio format (max 280 chars, no control chars)
|
|
138
140
|
- `isValidDisplayName(displayName)` - Validate display name format (max 25 chars, no control chars)
|
|
141
|
+
- `getTokenAddressStorageArgs(tokenAddress)` - Prepare token address update args
|
|
142
|
+
- `isValidTokenAddress(address)` - Validate EVM token address format
|
|
139
143
|
|
|
140
144
|
## Dependencies
|
|
141
145
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as ProfileStorageArgs, a as ProfileMetadata } from './types-
|
|
2
|
-
export { B as BasicUserProfileMetadata, b as UseProfileOptions, U as UserDisplayName, c as UserProfile } from './types-
|
|
1
|
+
import { P as ProfileStorageArgs, a as ProfileMetadata } from './types-DDKLfc0r.mjs';
|
|
2
|
+
export { B as BasicUserProfileMetadata, b as UseProfileOptions, U as UserDisplayName, c as UserProfile } from './types-DDKLfc0r.mjs';
|
|
3
3
|
export { STORAGE_CONTRACT } from '@net-protocol/storage';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -22,6 +22,8 @@ declare const PROFILE_METADATA_STORAGE_KEY = "net-beta0.0.1-profile-metadata";
|
|
|
22
22
|
declare const PROFILE_PICTURE_TOPIC = "profile-picture";
|
|
23
23
|
declare const PROFILE_METADATA_TOPIC = "profile-metadata";
|
|
24
24
|
declare const PROFILE_CANVAS_TOPIC = "profile-canvas";
|
|
25
|
+
declare const PROFILE_CSS_STORAGE_KEY = "net-beta0.0.1-profile-css";
|
|
26
|
+
declare const PROFILE_CSS_TOPIC = "profile-css";
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Convert a string value to hex for storage
|
|
@@ -141,5 +143,93 @@ declare function getBioStorageArgs(bio: string): ProfileStorageArgs;
|
|
|
141
143
|
* @returns Arguments for Storage.put()
|
|
142
144
|
*/
|
|
143
145
|
declare function getDisplayNameStorageArgs(displayName: string): ProfileStorageArgs;
|
|
146
|
+
/**
|
|
147
|
+
* Prepare transaction arguments for updating token address
|
|
148
|
+
* This is a convenience wrapper around getProfileMetadataStorageArgs
|
|
149
|
+
*
|
|
150
|
+
* @param tokenAddress - The ERC-20 token contract address (stored as lowercase)
|
|
151
|
+
* @returns Arguments for Storage.put()
|
|
152
|
+
*/
|
|
153
|
+
declare function getTokenAddressStorageArgs(tokenAddress: string): ProfileStorageArgs;
|
|
154
|
+
/**
|
|
155
|
+
* Validate that a string is a valid EVM token address
|
|
156
|
+
* Returns true if valid (0x-prefixed, 40 hex characters)
|
|
157
|
+
*/
|
|
158
|
+
declare function isValidTokenAddress(address: string): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Maximum CSS size in bytes (10KB — CSS should be small)
|
|
161
|
+
*/
|
|
162
|
+
declare const MAX_CSS_SIZE: number;
|
|
163
|
+
/**
|
|
164
|
+
* Prepare transaction arguments for updating profile custom CSS
|
|
165
|
+
*
|
|
166
|
+
* @param cssContent - CSS string to store
|
|
167
|
+
* @returns Arguments for Storage.put() - [bytesKey, topic, bytesValue]
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const args = getProfileCSSStorageArgs(".profile-themed { --primary: 210 40% 98%; }");
|
|
172
|
+
* writeContract({
|
|
173
|
+
* abi: STORAGE_CONTRACT.abi,
|
|
174
|
+
* address: STORAGE_CONTRACT.address,
|
|
175
|
+
* functionName: "put",
|
|
176
|
+
* args: [args.bytesKey, args.topic, args.bytesValue],
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare function getProfileCSSStorageArgs(cssContent: string): ProfileStorageArgs;
|
|
181
|
+
/**
|
|
182
|
+
* Validate CSS content
|
|
183
|
+
* Returns true if valid (non-empty, within size limit, no script injection)
|
|
184
|
+
*/
|
|
185
|
+
declare function isValidCSS(css: string): boolean;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Single source of truth for profile CSS theming.
|
|
189
|
+
*
|
|
190
|
+
* This file defines:
|
|
191
|
+
* 1. THEME_SELECTORS — the stable set of CSS selectors/variables available for theming
|
|
192
|
+
* 2. DEMO_THEMES — example CSS themes users can apply
|
|
193
|
+
* 3. buildCSSPrompt() — generates an AI prompt describing what can be themed
|
|
194
|
+
*
|
|
195
|
+
* When the profile page structure changes, update THEME_SELECTORS here and
|
|
196
|
+
* everything downstream (AI prompt, docs, validation) stays in sync.
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* A themeable selector or CSS variable group
|
|
200
|
+
*/
|
|
201
|
+
interface ThemeSelector {
|
|
202
|
+
/** CSS selector or variable name */
|
|
203
|
+
selector: string;
|
|
204
|
+
/** Human-readable description of what it targets */
|
|
205
|
+
description: string;
|
|
206
|
+
/** Category for grouping in documentation */
|
|
207
|
+
category: "variable" | "layout" | "component";
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* All themeable selectors available for profile CSS.
|
|
211
|
+
*
|
|
212
|
+
* CSS variables (category: "variable") are the most stable —
|
|
213
|
+
* they survive page restructuring because they're part of the
|
|
214
|
+
* shadcn/Tailwind design system.
|
|
215
|
+
*
|
|
216
|
+
* Layout and component selectors may break when the page structure changes.
|
|
217
|
+
*/
|
|
218
|
+
declare const THEME_SELECTORS: ThemeSelector[];
|
|
219
|
+
/**
|
|
220
|
+
* Demo themes that users can choose from as starting points.
|
|
221
|
+
* Each is a complete CSS string ready to store on-chain.
|
|
222
|
+
*/
|
|
223
|
+
declare const DEMO_THEMES: Record<string, {
|
|
224
|
+
name: string;
|
|
225
|
+
css: string;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* Build an AI prompt that describes the available theming surface.
|
|
229
|
+
* Feed this to an LLM alongside a user's description to generate CSS.
|
|
230
|
+
*
|
|
231
|
+
* @returns A prompt string listing all available selectors and usage rules
|
|
232
|
+
*/
|
|
233
|
+
declare function buildCSSPrompt(): string;
|
|
144
234
|
|
|
145
|
-
export { PROFILE_CANVAS_STORAGE_KEY, PROFILE_CANVAS_TOPIC, PROFILE_METADATA_STORAGE_KEY, PROFILE_METADATA_TOPIC, PROFILE_PICTURE_STORAGE_KEY, PROFILE_PICTURE_TOPIC, PROFILE_X_USERNAME_STORAGE_KEY, ProfileMetadata, ProfileStorageArgs, getBioStorageArgs, getBytesArgsForStorage, getDisplayNameStorageArgs, getProfileCanvasStorageArgs, getProfileMetadataStorageArgs, getProfilePictureStorageArgs, getValueArgForStorage, getXUsernameStorageArgs, isValidBio, isValidDisplayName, isValidUrl, isValidXUsername, parseProfileMetadata };
|
|
235
|
+
export { DEMO_THEMES, MAX_CSS_SIZE, PROFILE_CANVAS_STORAGE_KEY, PROFILE_CANVAS_TOPIC, PROFILE_CSS_STORAGE_KEY, PROFILE_CSS_TOPIC, PROFILE_METADATA_STORAGE_KEY, PROFILE_METADATA_TOPIC, PROFILE_PICTURE_STORAGE_KEY, PROFILE_PICTURE_TOPIC, PROFILE_X_USERNAME_STORAGE_KEY, ProfileMetadata, ProfileStorageArgs, THEME_SELECTORS, type ThemeSelector, buildCSSPrompt, getBioStorageArgs, getBytesArgsForStorage, getDisplayNameStorageArgs, getProfileCSSStorageArgs, getProfileCanvasStorageArgs, getProfileMetadataStorageArgs, getProfilePictureStorageArgs, getTokenAddressStorageArgs, getValueArgForStorage, getXUsernameStorageArgs, isValidBio, isValidCSS, isValidDisplayName, isValidTokenAddress, isValidUrl, isValidXUsername, parseProfileMetadata };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as ProfileStorageArgs, a as ProfileMetadata } from './types-
|
|
2
|
-
export { B as BasicUserProfileMetadata, b as UseProfileOptions, U as UserDisplayName, c as UserProfile } from './types-
|
|
1
|
+
import { P as ProfileStorageArgs, a as ProfileMetadata } from './types-DDKLfc0r.js';
|
|
2
|
+
export { B as BasicUserProfileMetadata, b as UseProfileOptions, U as UserDisplayName, c as UserProfile } from './types-DDKLfc0r.js';
|
|
3
3
|
export { STORAGE_CONTRACT } from '@net-protocol/storage';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -22,6 +22,8 @@ declare const PROFILE_METADATA_STORAGE_KEY = "net-beta0.0.1-profile-metadata";
|
|
|
22
22
|
declare const PROFILE_PICTURE_TOPIC = "profile-picture";
|
|
23
23
|
declare const PROFILE_METADATA_TOPIC = "profile-metadata";
|
|
24
24
|
declare const PROFILE_CANVAS_TOPIC = "profile-canvas";
|
|
25
|
+
declare const PROFILE_CSS_STORAGE_KEY = "net-beta0.0.1-profile-css";
|
|
26
|
+
declare const PROFILE_CSS_TOPIC = "profile-css";
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Convert a string value to hex for storage
|
|
@@ -141,5 +143,93 @@ declare function getBioStorageArgs(bio: string): ProfileStorageArgs;
|
|
|
141
143
|
* @returns Arguments for Storage.put()
|
|
142
144
|
*/
|
|
143
145
|
declare function getDisplayNameStorageArgs(displayName: string): ProfileStorageArgs;
|
|
146
|
+
/**
|
|
147
|
+
* Prepare transaction arguments for updating token address
|
|
148
|
+
* This is a convenience wrapper around getProfileMetadataStorageArgs
|
|
149
|
+
*
|
|
150
|
+
* @param tokenAddress - The ERC-20 token contract address (stored as lowercase)
|
|
151
|
+
* @returns Arguments for Storage.put()
|
|
152
|
+
*/
|
|
153
|
+
declare function getTokenAddressStorageArgs(tokenAddress: string): ProfileStorageArgs;
|
|
154
|
+
/**
|
|
155
|
+
* Validate that a string is a valid EVM token address
|
|
156
|
+
* Returns true if valid (0x-prefixed, 40 hex characters)
|
|
157
|
+
*/
|
|
158
|
+
declare function isValidTokenAddress(address: string): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Maximum CSS size in bytes (10KB — CSS should be small)
|
|
161
|
+
*/
|
|
162
|
+
declare const MAX_CSS_SIZE: number;
|
|
163
|
+
/**
|
|
164
|
+
* Prepare transaction arguments for updating profile custom CSS
|
|
165
|
+
*
|
|
166
|
+
* @param cssContent - CSS string to store
|
|
167
|
+
* @returns Arguments for Storage.put() - [bytesKey, topic, bytesValue]
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const args = getProfileCSSStorageArgs(".profile-themed { --primary: 210 40% 98%; }");
|
|
172
|
+
* writeContract({
|
|
173
|
+
* abi: STORAGE_CONTRACT.abi,
|
|
174
|
+
* address: STORAGE_CONTRACT.address,
|
|
175
|
+
* functionName: "put",
|
|
176
|
+
* args: [args.bytesKey, args.topic, args.bytesValue],
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
declare function getProfileCSSStorageArgs(cssContent: string): ProfileStorageArgs;
|
|
181
|
+
/**
|
|
182
|
+
* Validate CSS content
|
|
183
|
+
* Returns true if valid (non-empty, within size limit, no script injection)
|
|
184
|
+
*/
|
|
185
|
+
declare function isValidCSS(css: string): boolean;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Single source of truth for profile CSS theming.
|
|
189
|
+
*
|
|
190
|
+
* This file defines:
|
|
191
|
+
* 1. THEME_SELECTORS — the stable set of CSS selectors/variables available for theming
|
|
192
|
+
* 2. DEMO_THEMES — example CSS themes users can apply
|
|
193
|
+
* 3. buildCSSPrompt() — generates an AI prompt describing what can be themed
|
|
194
|
+
*
|
|
195
|
+
* When the profile page structure changes, update THEME_SELECTORS here and
|
|
196
|
+
* everything downstream (AI prompt, docs, validation) stays in sync.
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* A themeable selector or CSS variable group
|
|
200
|
+
*/
|
|
201
|
+
interface ThemeSelector {
|
|
202
|
+
/** CSS selector or variable name */
|
|
203
|
+
selector: string;
|
|
204
|
+
/** Human-readable description of what it targets */
|
|
205
|
+
description: string;
|
|
206
|
+
/** Category for grouping in documentation */
|
|
207
|
+
category: "variable" | "layout" | "component";
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* All themeable selectors available for profile CSS.
|
|
211
|
+
*
|
|
212
|
+
* CSS variables (category: "variable") are the most stable —
|
|
213
|
+
* they survive page restructuring because they're part of the
|
|
214
|
+
* shadcn/Tailwind design system.
|
|
215
|
+
*
|
|
216
|
+
* Layout and component selectors may break when the page structure changes.
|
|
217
|
+
*/
|
|
218
|
+
declare const THEME_SELECTORS: ThemeSelector[];
|
|
219
|
+
/**
|
|
220
|
+
* Demo themes that users can choose from as starting points.
|
|
221
|
+
* Each is a complete CSS string ready to store on-chain.
|
|
222
|
+
*/
|
|
223
|
+
declare const DEMO_THEMES: Record<string, {
|
|
224
|
+
name: string;
|
|
225
|
+
css: string;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* Build an AI prompt that describes the available theming surface.
|
|
229
|
+
* Feed this to an LLM alongside a user's description to generate CSS.
|
|
230
|
+
*
|
|
231
|
+
* @returns A prompt string listing all available selectors and usage rules
|
|
232
|
+
*/
|
|
233
|
+
declare function buildCSSPrompt(): string;
|
|
144
234
|
|
|
145
|
-
export { PROFILE_CANVAS_STORAGE_KEY, PROFILE_CANVAS_TOPIC, PROFILE_METADATA_STORAGE_KEY, PROFILE_METADATA_TOPIC, PROFILE_PICTURE_STORAGE_KEY, PROFILE_PICTURE_TOPIC, PROFILE_X_USERNAME_STORAGE_KEY, ProfileMetadata, ProfileStorageArgs, getBioStorageArgs, getBytesArgsForStorage, getDisplayNameStorageArgs, getProfileCanvasStorageArgs, getProfileMetadataStorageArgs, getProfilePictureStorageArgs, getValueArgForStorage, getXUsernameStorageArgs, isValidBio, isValidDisplayName, isValidUrl, isValidXUsername, parseProfileMetadata };
|
|
235
|
+
export { DEMO_THEMES, MAX_CSS_SIZE, PROFILE_CANVAS_STORAGE_KEY, PROFILE_CANVAS_TOPIC, PROFILE_CSS_STORAGE_KEY, PROFILE_CSS_TOPIC, PROFILE_METADATA_STORAGE_KEY, PROFILE_METADATA_TOPIC, PROFILE_PICTURE_STORAGE_KEY, PROFILE_PICTURE_TOPIC, PROFILE_X_USERNAME_STORAGE_KEY, ProfileMetadata, ProfileStorageArgs, THEME_SELECTORS, type ThemeSelector, buildCSSPrompt, getBioStorageArgs, getBytesArgsForStorage, getDisplayNameStorageArgs, getProfileCSSStorageArgs, getProfileCanvasStorageArgs, getProfileMetadataStorageArgs, getProfilePictureStorageArgs, getTokenAddressStorageArgs, getValueArgForStorage, getXUsernameStorageArgs, isValidBio, isValidCSS, isValidDisplayName, isValidTokenAddress, isValidUrl, isValidXUsername, parseProfileMetadata };
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,8 @@ var PROFILE_METADATA_STORAGE_KEY = "net-beta0.0.1-profile-metadata";
|
|
|
12
12
|
var PROFILE_PICTURE_TOPIC = "profile-picture";
|
|
13
13
|
var PROFILE_METADATA_TOPIC = "profile-metadata";
|
|
14
14
|
var PROFILE_CANVAS_TOPIC = "profile-canvas";
|
|
15
|
+
var PROFILE_CSS_STORAGE_KEY = "net-beta0.0.1-profile-css";
|
|
16
|
+
var PROFILE_CSS_TOPIC = "profile-css";
|
|
15
17
|
function getValueArgForStorage(value) {
|
|
16
18
|
return viem.stringToHex(value);
|
|
17
19
|
}
|
|
@@ -65,10 +67,12 @@ function parseProfileMetadata(jsonData) {
|
|
|
65
67
|
const usernameWithoutAt = storedUsername?.startsWith("@") ? storedUsername.slice(1) : storedUsername;
|
|
66
68
|
const bio = parsed?.bio && typeof parsed.bio === "string" && parsed.bio.length > 0 ? parsed.bio : void 0;
|
|
67
69
|
const display_name = parsed?.display_name && typeof parsed.display_name === "string" && parsed.display_name.length > 0 ? parsed.display_name : void 0;
|
|
70
|
+
const token_address = parsed?.token_address && typeof parsed.token_address === "string" && parsed.token_address.length > 0 ? parsed.token_address.toLowerCase() : void 0;
|
|
68
71
|
return {
|
|
69
72
|
x_username: usernameWithoutAt,
|
|
70
73
|
bio,
|
|
71
|
-
display_name
|
|
74
|
+
display_name,
|
|
75
|
+
token_address
|
|
72
76
|
};
|
|
73
77
|
} catch {
|
|
74
78
|
return void 0;
|
|
@@ -106,28 +110,261 @@ function getBioStorageArgs(bio) {
|
|
|
106
110
|
function getDisplayNameStorageArgs(displayName) {
|
|
107
111
|
return getProfileMetadataStorageArgs({ display_name: displayName });
|
|
108
112
|
}
|
|
113
|
+
function getTokenAddressStorageArgs(tokenAddress) {
|
|
114
|
+
return getProfileMetadataStorageArgs({
|
|
115
|
+
token_address: tokenAddress.toLowerCase()
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function isValidTokenAddress(address) {
|
|
119
|
+
if (!address) return false;
|
|
120
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
121
|
+
}
|
|
122
|
+
var MAX_CSS_SIZE = 10 * 1024;
|
|
123
|
+
function getProfileCSSStorageArgs(cssContent) {
|
|
124
|
+
const { bytesKey, bytesValue } = getBytesArgsForStorage(
|
|
125
|
+
PROFILE_CSS_STORAGE_KEY,
|
|
126
|
+
cssContent
|
|
127
|
+
);
|
|
128
|
+
return {
|
|
129
|
+
bytesKey,
|
|
130
|
+
topic: PROFILE_CSS_TOPIC,
|
|
131
|
+
bytesValue
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function isValidCSS(css) {
|
|
135
|
+
if (!css || css.trim().length === 0) return false;
|
|
136
|
+
if (Buffer.byteLength(css, "utf-8") > MAX_CSS_SIZE) return false;
|
|
137
|
+
const lowerCSS = css.toLowerCase();
|
|
138
|
+
if (lowerCSS.includes("expression(")) return false;
|
|
139
|
+
if (lowerCSS.includes("behavior:")) return false;
|
|
140
|
+
if (lowerCSS.includes("javascript:")) return false;
|
|
141
|
+
if (/<script/i.test(css)) return false;
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/theme-selectors.ts
|
|
146
|
+
var THEME_SELECTORS = [
|
|
147
|
+
// --- CSS Variables (stable) ---
|
|
148
|
+
{
|
|
149
|
+
selector: "--background",
|
|
150
|
+
description: "Page background color (HSL values, e.g. '210 40% 2%')",
|
|
151
|
+
category: "variable"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
selector: "--foreground",
|
|
155
|
+
description: "Default text color",
|
|
156
|
+
category: "variable"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
selector: "--primary",
|
|
160
|
+
description: "Primary accent color (buttons, links, headings)",
|
|
161
|
+
category: "variable"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
selector: "--primary-foreground",
|
|
165
|
+
description: "Text on primary-colored elements",
|
|
166
|
+
category: "variable"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
selector: "--secondary",
|
|
170
|
+
description: "Secondary accent color",
|
|
171
|
+
category: "variable"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
selector: "--secondary-foreground",
|
|
175
|
+
description: "Text on secondary-colored elements",
|
|
176
|
+
category: "variable"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
selector: "--muted",
|
|
180
|
+
description: "Muted/subdued background",
|
|
181
|
+
category: "variable"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
selector: "--muted-foreground",
|
|
185
|
+
description: "Text on muted backgrounds",
|
|
186
|
+
category: "variable"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
selector: "--accent",
|
|
190
|
+
description: "Accent color for highlights",
|
|
191
|
+
category: "variable"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
selector: "--accent-foreground",
|
|
195
|
+
description: "Text on accent-colored elements",
|
|
196
|
+
category: "variable"
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
selector: "--card",
|
|
200
|
+
description: "Card/panel background color",
|
|
201
|
+
category: "variable"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
selector: "--card-foreground",
|
|
205
|
+
description: "Text inside cards",
|
|
206
|
+
category: "variable"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
selector: "--border",
|
|
210
|
+
description: "Border color",
|
|
211
|
+
category: "variable"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
selector: "--ring",
|
|
215
|
+
description: "Focus ring color",
|
|
216
|
+
category: "variable"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
selector: "--radius",
|
|
220
|
+
description: "Border radius (e.g. '0.5rem')",
|
|
221
|
+
category: "variable"
|
|
222
|
+
},
|
|
223
|
+
// --- Layout selectors (may change with page restructuring) ---
|
|
224
|
+
{
|
|
225
|
+
selector: ".profile-themed",
|
|
226
|
+
description: "Root wrapper for all themed profile content",
|
|
227
|
+
category: "layout"
|
|
228
|
+
},
|
|
229
|
+
// --- Component selectors (may change with page restructuring) ---
|
|
230
|
+
{
|
|
231
|
+
selector: ".profile-themed .profile-header",
|
|
232
|
+
description: "Profile header area (name, picture, bio)",
|
|
233
|
+
category: "component"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
selector: ".profile-themed .profile-tabs",
|
|
237
|
+
description: "Tab navigation bar",
|
|
238
|
+
category: "component"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
selector: ".profile-themed .profile-content",
|
|
242
|
+
description: "Main content area below tabs",
|
|
243
|
+
category: "component"
|
|
244
|
+
}
|
|
245
|
+
];
|
|
246
|
+
var DEMO_THEMES = {
|
|
247
|
+
hotPink: {
|
|
248
|
+
name: "Hot Pink Scene",
|
|
249
|
+
css: `.profile-themed {
|
|
250
|
+
--background: 320 80% 4%;
|
|
251
|
+
--foreground: 320 20% 95%;
|
|
252
|
+
--primary: 330 100% 60%;
|
|
253
|
+
--primary-foreground: 0 0% 100%;
|
|
254
|
+
--secondary: 280 60% 20%;
|
|
255
|
+
--secondary-foreground: 320 20% 95%;
|
|
256
|
+
--muted: 320 40% 12%;
|
|
257
|
+
--muted-foreground: 320 20% 70%;
|
|
258
|
+
--accent: 330 100% 60%;
|
|
259
|
+
--accent-foreground: 0 0% 100%;
|
|
260
|
+
--card: 320 60% 6%;
|
|
261
|
+
--card-foreground: 320 20% 95%;
|
|
262
|
+
--border: 330 60% 25%;
|
|
263
|
+
--ring: 330 100% 60%;
|
|
264
|
+
}`
|
|
265
|
+
},
|
|
266
|
+
midnightGrunge: {
|
|
267
|
+
name: "Midnight Grunge",
|
|
268
|
+
css: `.profile-themed {
|
|
269
|
+
--background: 220 30% 3%;
|
|
270
|
+
--foreground: 220 10% 80%;
|
|
271
|
+
--primary: 45 90% 55%;
|
|
272
|
+
--primary-foreground: 220 30% 5%;
|
|
273
|
+
--secondary: 220 20% 12%;
|
|
274
|
+
--secondary-foreground: 220 10% 80%;
|
|
275
|
+
--muted: 220 20% 8%;
|
|
276
|
+
--muted-foreground: 220 10% 50%;
|
|
277
|
+
--accent: 45 90% 55%;
|
|
278
|
+
--accent-foreground: 220 30% 5%;
|
|
279
|
+
--card: 220 25% 5%;
|
|
280
|
+
--card-foreground: 220 10% 80%;
|
|
281
|
+
--border: 220 15% 15%;
|
|
282
|
+
--ring: 45 90% 55%;
|
|
283
|
+
}`
|
|
284
|
+
},
|
|
285
|
+
ocean: {
|
|
286
|
+
name: "Deep Ocean",
|
|
287
|
+
css: `.profile-themed {
|
|
288
|
+
--background: 200 60% 3%;
|
|
289
|
+
--foreground: 190 20% 90%;
|
|
290
|
+
--primary: 190 80% 50%;
|
|
291
|
+
--primary-foreground: 200 60% 5%;
|
|
292
|
+
--secondary: 210 40% 15%;
|
|
293
|
+
--secondary-foreground: 190 20% 90%;
|
|
294
|
+
--muted: 200 40% 8%;
|
|
295
|
+
--muted-foreground: 190 20% 55%;
|
|
296
|
+
--accent: 170 70% 45%;
|
|
297
|
+
--accent-foreground: 200 60% 5%;
|
|
298
|
+
--card: 200 50% 5%;
|
|
299
|
+
--card-foreground: 190 20% 90%;
|
|
300
|
+
--border: 200 30% 18%;
|
|
301
|
+
--ring: 190 80% 50%;
|
|
302
|
+
}`
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
function buildCSSPrompt() {
|
|
306
|
+
const variableLines = THEME_SELECTORS.filter(
|
|
307
|
+
(s) => s.category === "variable"
|
|
308
|
+
).map((s) => ` ${s.selector}: ${s.description}`).join("\n");
|
|
309
|
+
const layoutLines = THEME_SELECTORS.filter((s) => s.category === "layout").map((s) => ` ${s.selector} \u2014 ${s.description}`).join("\n");
|
|
310
|
+
const componentLines = THEME_SELECTORS.filter(
|
|
311
|
+
(s) => s.category === "component"
|
|
312
|
+
).map((s) => ` ${s.selector} \u2014 ${s.description}`).join("\n");
|
|
313
|
+
return `You are a CSS theme generator for a user profile page.
|
|
314
|
+
All styles MUST be scoped under the .profile-themed wrapper class.
|
|
315
|
+
|
|
316
|
+
## CSS Variables (stable \u2014 preferred for theming)
|
|
317
|
+
These use HSL values WITHOUT the hsl() wrapper (e.g. "210 40% 98%"):
|
|
318
|
+
${variableLines}
|
|
319
|
+
|
|
320
|
+
## Layout Selectors (may change across site updates)
|
|
321
|
+
${layoutLines}
|
|
322
|
+
|
|
323
|
+
## Component Selectors (may change across site updates)
|
|
324
|
+
${componentLines}
|
|
325
|
+
|
|
326
|
+
## Rules
|
|
327
|
+
1. All selectors MUST start with .profile-themed
|
|
328
|
+
2. CSS variables go inside .profile-themed { ... } as custom properties
|
|
329
|
+
3. Use only valid CSS \u2014 no JavaScript, no expressions, no imports
|
|
330
|
+
4. Keep the output under 10KB
|
|
331
|
+
5. Prefer CSS variables over direct selector styling for durability
|
|
332
|
+
6. HSL values are bare numbers: "210 40% 98%" not "hsl(210, 40%, 98%)"
|
|
333
|
+
|
|
334
|
+
Given a user description, output ONLY the CSS (no explanation, no markdown fences).`;
|
|
335
|
+
}
|
|
109
336
|
|
|
110
337
|
Object.defineProperty(exports, "STORAGE_CONTRACT", {
|
|
111
338
|
enumerable: true,
|
|
112
339
|
get: function () { return storage.STORAGE_CONTRACT; }
|
|
113
340
|
});
|
|
341
|
+
exports.DEMO_THEMES = DEMO_THEMES;
|
|
342
|
+
exports.MAX_CSS_SIZE = MAX_CSS_SIZE;
|
|
114
343
|
exports.PROFILE_CANVAS_STORAGE_KEY = PROFILE_CANVAS_STORAGE_KEY;
|
|
115
344
|
exports.PROFILE_CANVAS_TOPIC = PROFILE_CANVAS_TOPIC;
|
|
345
|
+
exports.PROFILE_CSS_STORAGE_KEY = PROFILE_CSS_STORAGE_KEY;
|
|
346
|
+
exports.PROFILE_CSS_TOPIC = PROFILE_CSS_TOPIC;
|
|
116
347
|
exports.PROFILE_METADATA_STORAGE_KEY = PROFILE_METADATA_STORAGE_KEY;
|
|
117
348
|
exports.PROFILE_METADATA_TOPIC = PROFILE_METADATA_TOPIC;
|
|
118
349
|
exports.PROFILE_PICTURE_STORAGE_KEY = PROFILE_PICTURE_STORAGE_KEY;
|
|
119
350
|
exports.PROFILE_PICTURE_TOPIC = PROFILE_PICTURE_TOPIC;
|
|
120
351
|
exports.PROFILE_X_USERNAME_STORAGE_KEY = PROFILE_X_USERNAME_STORAGE_KEY;
|
|
352
|
+
exports.THEME_SELECTORS = THEME_SELECTORS;
|
|
353
|
+
exports.buildCSSPrompt = buildCSSPrompt;
|
|
121
354
|
exports.getBioStorageArgs = getBioStorageArgs;
|
|
122
355
|
exports.getBytesArgsForStorage = getBytesArgsForStorage;
|
|
123
356
|
exports.getDisplayNameStorageArgs = getDisplayNameStorageArgs;
|
|
357
|
+
exports.getProfileCSSStorageArgs = getProfileCSSStorageArgs;
|
|
124
358
|
exports.getProfileCanvasStorageArgs = getProfileCanvasStorageArgs;
|
|
125
359
|
exports.getProfileMetadataStorageArgs = getProfileMetadataStorageArgs;
|
|
126
360
|
exports.getProfilePictureStorageArgs = getProfilePictureStorageArgs;
|
|
361
|
+
exports.getTokenAddressStorageArgs = getTokenAddressStorageArgs;
|
|
127
362
|
exports.getValueArgForStorage = getValueArgForStorage;
|
|
128
363
|
exports.getXUsernameStorageArgs = getXUsernameStorageArgs;
|
|
129
364
|
exports.isValidBio = isValidBio;
|
|
365
|
+
exports.isValidCSS = isValidCSS;
|
|
130
366
|
exports.isValidDisplayName = isValidDisplayName;
|
|
367
|
+
exports.isValidTokenAddress = isValidTokenAddress;
|
|
131
368
|
exports.isValidUrl = isValidUrl;
|
|
132
369
|
exports.isValidXUsername = isValidXUsername;
|
|
133
370
|
exports.parseProfileMetadata = parseProfileMetadata;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/utils.ts"],"names":["stringToHex","toBytes32"],"mappings":";;;;;;;AASO,IAAM,0BAAA,GAA6B;AACnC,IAAM,2BAAA,GAA8B;AACpC,IAAM,8BAAA,GACX;AACK,IAAM,4BAAA,GAA+B;AAMrC,IAAM,qBAAA,GAAwB;AAC9B,IAAM,sBAAA,GAAyB;AAC/B,IAAM,oBAAA,GAAuB;ACN7B,SAAS,sBAAsB,KAAA,EAA8B;AAClE,EAAA,OAAOA,iBAAY,KAAK,CAAA;AAC1B;AAKO,SAAS,sBAAA,CACd,KACA,KAAA,EACwD;AACxD,EAAA,MAAM,QAAA,GAAWC,eAAU,GAAG,CAAA;AAC9B,EAAA,MAAM,UAAA,GAAa,sBAAsB,KAAK,CAAA;AAC9C,EAAA,OAAO,EAAE,UAAU,UAAA,EAAW;AAChC;AAoBO,SAAS,6BACd,QAAA,EACoB;AACpB,EAAA,MAAM,EAAE,QAAA,EAAU,UAAA,EAAW,GAAI,sBAA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,CAAK,GAAG,CAAA;AACnE,EAAA,OAAO,CAAC,eAAA;AACV;AAMO,SAAS,mBAAmB,WAAA,EAA8B;AAC/D,EAAA,IAAI,CAAC,aAAa,OAAO,KAAA;AACzB,EAAA,IAAI,WAAA,CAAY,MAAA,GAAS,EAAA,EAAI,OAAO,KAAA;AAGpC,EAAA,MAAM,eAAA,GAAkB,iBAAA,CAAkB,IAAA,CAAK,WAAW,CAAA;AAC1D,EAAA,OAAO,CAAC,eAAA;AACV;AASO,SAAS,kBAAkB,GAAA,EAAiC;AACjE,EAAA,OAAO,6BAAA,CAA8B,EAAE,GAAA,EAAK,CAAA;AAC9C;AASO,SAAS,0BACd,WAAA,EACoB;AACpB,EAAA,OAAO,6BAAA,CAA8B,EAAE,YAAA,EAAc,WAAA,EAAa,CAAA;AACpE","file":"index.js","sourcesContent":["/**\n * Profile-related storage keys\n *\n * Using descriptive keys under 32 bytes to avoid hashing complexity and work seamlessly\n * with existing storage infrastructure. The key includes app prefix and versioning for\n * clarity and future-proofing.\n *\n * NOTE: if we change these keys, users will not be able to see their profile data\n */\nexport const PROFILE_CANVAS_STORAGE_KEY = \"net-beta0.0.1-profile-canvas\";\nexport const PROFILE_PICTURE_STORAGE_KEY = \"net-beta0.0.1-profile-picture\";\nexport const PROFILE_X_USERNAME_STORAGE_KEY =\n \"net-beta0.0.1-profile-x-username\";\nexport const PROFILE_METADATA_STORAGE_KEY = \"net-beta0.0.1-profile-metadata\";\n\n/**\n * Topic strings used when writing to storage\n * These are the second argument to Storage.put()\n */\nexport const PROFILE_PICTURE_TOPIC = \"profile-picture\";\nexport const PROFILE_METADATA_TOPIC = \"profile-metadata\";\nexport const PROFILE_CANVAS_TOPIC = \"profile-canvas\";\n","import { stringToHex } from \"viem\";\nimport { toBytes32 } from \"@net-protocol/core\";\nimport {\n PROFILE_PICTURE_STORAGE_KEY,\n PROFILE_METADATA_STORAGE_KEY,\n PROFILE_CANVAS_STORAGE_KEY,\n PROFILE_PICTURE_TOPIC,\n PROFILE_METADATA_TOPIC,\n PROFILE_CANVAS_TOPIC,\n} from \"./constants\";\nimport type { ProfileMetadata, ProfileStorageArgs } from \"./types\";\n\n/**\n * Convert a string value to hex for storage\n */\nexport function getValueArgForStorage(value: string): `0x${string}` {\n return stringToHex(value);\n}\n\n/**\n * Get storage args (key as bytes32, value as hex)\n */\nexport function getBytesArgsForStorage(\n key: string,\n value: string\n): { bytesKey: `0x${string}`; bytesValue: `0x${string}` } {\n const bytesKey = toBytes32(key) as `0x${string}`;\n const bytesValue = getValueArgForStorage(value);\n return { bytesKey, bytesValue };\n}\n\n/**\n * Prepare transaction arguments for updating profile picture\n *\n * @param imageUrl - The URL of the profile picture\n * @returns Arguments for Storage.put() - [bytesKey, topic, bytesValue]\n *\n * @example\n * ```ts\n * const args = getProfilePictureStorageArgs(\"https://example.com/image.jpg\");\n * // Use with wagmi writeContract:\n * writeContract({\n * abi: STORAGE_CONTRACT.abi,\n * address: STORAGE_CONTRACT.address,\n * functionName: \"put\",\n * args: [args.bytesKey, args.topic, args.bytesValue],\n * });\n * ```\n */\nexport function getProfilePictureStorageArgs(\n imageUrl: string\n): ProfileStorageArgs {\n const { bytesKey, bytesValue } = getBytesArgsForStorage(\n PROFILE_PICTURE_STORAGE_KEY,\n imageUrl\n );\n return {\n bytesKey,\n topic: PROFILE_PICTURE_TOPIC,\n bytesValue,\n };\n}\n\n/**\n * Prepare transaction arguments for updating profile metadata (X username, etc.)\n *\n * @param metadata - Profile metadata object to store\n * @returns Arguments for Storage.put() - [bytesKey, topic, bytesValue]\n *\n * @example\n * ```ts\n * const args = getProfileMetadataStorageArgs({ x_username: \"myusername\" });\n * writeContract({\n * abi: STORAGE_CONTRACT.abi,\n * address: STORAGE_CONTRACT.address,\n * functionName: \"put\",\n * args: [args.bytesKey, args.topic, args.bytesValue],\n * });\n * ```\n */\nexport function getProfileMetadataStorageArgs(\n metadata: ProfileMetadata\n): ProfileStorageArgs {\n const jsonString = JSON.stringify(metadata);\n const { bytesKey, bytesValue } = getBytesArgsForStorage(\n PROFILE_METADATA_STORAGE_KEY,\n jsonString\n );\n return {\n bytesKey,\n topic: PROFILE_METADATA_TOPIC,\n bytesValue,\n };\n}\n\n/**\n * Prepare transaction arguments for updating X username\n * This is a convenience wrapper around getProfileMetadataStorageArgs\n *\n * Note: Username is stored WITHOUT the @ prefix. The @ is stripped if provided.\n *\n * @param username - X/Twitter username (with or without @)\n * @returns Arguments for Storage.put()\n */\nexport function getXUsernameStorageArgs(username: string): ProfileStorageArgs {\n // Strip @ prefix if present - store username without @\n const normalizedUsername = username.startsWith(\"@\")\n ? username.slice(1)\n : username;\n return getProfileMetadataStorageArgs({ x_username: normalizedUsername });\n}\n\n/**\n * Prepare transaction arguments for updating profile canvas (HTML content)\n *\n * @param htmlContent - HTML content for the profile canvas\n * @returns Arguments for Storage.put()\n *\n * @example\n * ```ts\n * const args = getProfileCanvasStorageArgs(\"<div>My custom profile</div>\");\n * writeContract({\n * abi: STORAGE_CONTRACT.abi,\n * address: STORAGE_CONTRACT.address,\n * functionName: \"put\",\n * args: [args.bytesKey, args.topic, args.bytesValue],\n * });\n * ```\n */\nexport function getProfileCanvasStorageArgs(\n htmlContent: string\n): ProfileStorageArgs {\n const { bytesKey, bytesValue } = getBytesArgsForStorage(\n PROFILE_CANVAS_STORAGE_KEY,\n htmlContent\n );\n return {\n bytesKey,\n topic: PROFILE_CANVAS_TOPIC,\n bytesValue,\n };\n}\n\n/**\n * Parse profile metadata JSON and extract profile data\n *\n * @param jsonData - JSON string from storage\n * @returns Parsed profile metadata or undefined if invalid\n */\nexport function parseProfileMetadata(\n jsonData: string\n): ProfileMetadata | undefined {\n try {\n const parsed = JSON.parse(jsonData);\n const storedUsername =\n parsed?.x_username &&\n typeof parsed.x_username === \"string\" &&\n parsed.x_username.length > 0\n ? parsed.x_username\n : undefined;\n\n // Strip @ if present for backwards compatibility with older stored data\n const usernameWithoutAt = storedUsername?.startsWith(\"@\")\n ? storedUsername.slice(1)\n : storedUsername;\n\n // Extract bio if present\n const bio =\n parsed?.bio && typeof parsed.bio === \"string\" && parsed.bio.length > 0\n ? parsed.bio\n : undefined;\n\n // Extract display name if present\n const display_name =\n parsed?.display_name &&\n typeof parsed.display_name === \"string\" &&\n parsed.display_name.length > 0\n ? parsed.display_name\n : undefined;\n\n return {\n x_username: usernameWithoutAt,\n bio,\n display_name,\n };\n } catch {\n return undefined;\n }\n}\n\n/**\n * Validate that a string is a valid URL\n */\nexport function isValidUrl(url: string): boolean {\n if (!url) return false;\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate X/Twitter username format\n * Returns true if valid (alphanumeric and underscores, 1-15 chars)\n */\nexport function isValidXUsername(username: string): boolean {\n if (!username) return false;\n // Remove @ prefix if present\n const cleanUsername = username.startsWith(\"@\") ? username.slice(1) : username;\n // X usernames: 1-15 chars, alphanumeric and underscores only\n return /^[a-zA-Z0-9_]{1,15}$/.test(cleanUsername);\n}\n\n/**\n * Validate bio format\n * Returns true if valid (max 280 chars, no control characters except newlines)\n */\nexport function isValidBio(bio: string): boolean {\n if (!bio) return false;\n if (bio.length > 280) return false;\n // Allow printable characters, spaces, and newlines. Disallow other control chars.\n // eslint-disable-next-line no-control-regex\n const hasControlChars = /[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]/.test(bio);\n return !hasControlChars;\n}\n\n/**\n * Validate display name format\n * Returns true if valid (1-25 characters, no control characters except spaces)\n */\nexport function isValidDisplayName(displayName: string): boolean {\n if (!displayName) return false;\n if (displayName.length > 25) return false;\n // Disallow control characters\n // eslint-disable-next-line no-control-regex\n const hasControlChars = /[\\x00-\\x1F\\x7F]/.test(displayName);\n return !hasControlChars;\n}\n\n/**\n * Prepare transaction arguments for updating bio\n * This is a convenience wrapper around getProfileMetadataStorageArgs\n *\n * @param bio - The bio text\n * @returns Arguments for Storage.put()\n */\nexport function getBioStorageArgs(bio: string): ProfileStorageArgs {\n return getProfileMetadataStorageArgs({ bio });\n}\n\n/**\n * Prepare transaction arguments for updating display name\n * This is a convenience wrapper around getProfileMetadataStorageArgs\n *\n * @param displayName - The display name (max 25 characters)\n * @returns Arguments for Storage.put()\n */\nexport function getDisplayNameStorageArgs(\n displayName: string\n): ProfileStorageArgs {\n return getProfileMetadataStorageArgs({ display_name: displayName });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/utils.ts","../src/theme-selectors.ts"],"names":["stringToHex","toBytes32"],"mappings":";;;;;;;AASO,IAAM,0BAAA,GAA6B;AACnC,IAAM,2BAAA,GAA8B;AACpC,IAAM,8BAAA,GACX;AACK,IAAM,4BAAA,GAA+B;AAMrC,IAAM,qBAAA,GAAwB;AAC9B,IAAM,sBAAA,GAAyB;AAC/B,IAAM,oBAAA,GAAuB;AAC7B,IAAM,uBAAA,GAA0B;AAChC,IAAM,iBAAA,GAAoB;ACN1B,SAAS,sBAAsB,KAAA,EAA8B;AAClE,EAAA,OAAOA,iBAAY,KAAK,CAAA;AAC1B;AAKO,SAAS,sBAAA,CACd,KACA,KAAA,EACwD;AACxD,EAAA,MAAM,QAAA,GAAWC,eAAU,GAAG,CAAA;AAC9B,EAAA,MAAM,UAAA,GAAa,sBAAsB,KAAK,CAAA;AAC9C,EAAA,OAAO,EAAE,UAAU,UAAA,EAAW;AAChC;AAoBO,SAAS,6BACd,QAAA,EACoB;AACpB,EAAA,MAAM,EAAE,QAAA,EAAU,UAAA,EAAW,GAAI,sBAAA;AAAA,IAC/B,2BAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO;AAAA,IACL,QAAA;AAAA,IACA,KAAA,EAAO,qBAAA;AAAA,IACP;AAAA,GACF;AACF;AAmBO,SAAS,8BACd,QAAA,EACoB;AACpB,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAA;AAC1C,EAAA,MAAM,EAAE,QAAA,EAAU,UAAA,EAAW,GAAI,sBAAA;AAAA,IAC/B,4BAAA;AAAA,IACA;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Z,EAAA,OAAO,CAAA;AAAA;;AAAA;AAAA;AAAA,EAKP,aAAa;;AAAA;AAAA,EAGb,WAAW;;AAAA;AAAA,EAGX,cAAc;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,mFAAA,CAAA;AAWhB","file":"index.js","sourcesContent":["/**\n * Profile-related storage keys\n *\n * Using descriptive keys under 32 bytes to avoid hashing complexity and work seamlessly\n * with existing storage infrastructure. The key includes app prefix and versioning for\n * clarity and future-proofing.\n *\n * NOTE: if we change these keys, users will not be able to see their profile data\n */\nexport const PROFILE_CANVAS_STORAGE_KEY = \"net-beta0.0.1-profile-canvas\";\nexport const PROFILE_PICTURE_STORAGE_KEY = \"net-beta0.0.1-profile-picture\";\nexport const PROFILE_X_USERNAME_STORAGE_KEY =\n \"net-beta0.0.1-profile-x-username\";\nexport const PROFILE_METADATA_STORAGE_KEY = \"net-beta0.0.1-profile-metadata\";\n\n/**\n * Topic strings used when writing to storage\n * These are the second argument to Storage.put()\n */\nexport const PROFILE_PICTURE_TOPIC = \"profile-picture\";\nexport const PROFILE_METADATA_TOPIC = \"profile-metadata\";\nexport const PROFILE_CANVAS_TOPIC = \"profile-canvas\";\nexport const PROFILE_CSS_STORAGE_KEY = \"net-beta0.0.1-profile-css\";\nexport const PROFILE_CSS_TOPIC = \"profile-css\";\n","import { stringToHex } from \"viem\";\nimport { toBytes32 } from \"@net-protocol/core\";\nimport {\n PROFILE_PICTURE_STORAGE_KEY,\n PROFILE_METADATA_STORAGE_KEY,\n PROFILE_CANVAS_STORAGE_KEY,\n PROFILE_CSS_STORAGE_KEY,\n PROFILE_PICTURE_TOPIC,\n PROFILE_METADATA_TOPIC,\n PROFILE_CANVAS_TOPIC,\n PROFILE_CSS_TOPIC,\n} from \"./constants\";\nimport type { ProfileMetadata, ProfileStorageArgs } from \"./types\";\n\n/**\n * Convert a string value to hex for storage\n */\nexport function getValueArgForStorage(value: string): `0x${string}` {\n return stringToHex(value);\n}\n\n/**\n * Get storage args (key as bytes32, value as hex)\n */\nexport function getBytesArgsForStorage(\n key: string,\n value: string\n): { bytesKey: `0x${string}`; bytesValue: `0x${string}` } {\n const bytesKey = toBytes32(key) as `0x${string}`;\n const bytesValue = getValueArgForStorage(value);\n return { bytesKey, bytesValue };\n}\n\n/**\n * Prepare transaction arguments for updating profile picture\n *\n * @param imageUrl - The URL of the profile picture\n * @returns Arguments for Storage.put() - [bytesKey, topic, bytesValue]\n *\n * @example\n * ```ts\n * const args = getProfilePictureStorageArgs(\"https://example.com/image.jpg\");\n * // Use with wagmi writeContract:\n * writeContract({\n * abi: STORAGE_CONTRACT.abi,\n * address: STORAGE_CONTRACT.address,\n * functionName: \"put\",\n * args: [args.bytesKey, args.topic, args.bytesValue],\n * });\n * ```\n */\nexport function getProfilePictureStorageArgs(\n imageUrl: string\n): ProfileStorageArgs {\n const { bytesKey, bytesValue } = getBytesArgsForStorage(\n PROFILE_PICTURE_STORAGE_KEY,\n imageUrl\n );\n return {\n bytesKey,\n topic: PROFILE_PICTURE_TOPIC,\n bytesValue,\n };\n}\n\n/**\n * Prepare transaction arguments for updating profile metadata (X username, etc.)\n *\n * @param metadata - Profile metadata object to store\n * @returns Arguments for Storage.put() - [bytesKey, topic, bytesValue]\n *\n * @example\n * ```ts\n * const args = getProfileMetadataStorageArgs({ x_username: \"myusername\" });\n * writeContract({\n * abi: STORAGE_CONTRACT.abi,\n * address: STORAGE_CONTRACT.address,\n * functionName: \"put\",\n * args: [args.bytesKey, args.topic, args.bytesValue],\n * });\n * ```\n */\nexport function getProfileMetadataStorageArgs(\n metadata: ProfileMetadata\n): ProfileStorageArgs {\n const jsonString = JSON.stringify(metadata);\n const { bytesKey, bytesValue } = getBytesArgsForStorage(\n PROFILE_METADATA_STORAGE_KEY,\n jsonString\n );\n return {\n bytesKey,\n topic: PROFILE_METADATA_TOPIC,\n bytesValue,\n };\n}\n\n/**\n * Prepare transaction arguments for updating X username\n * This is a convenience wrapper around getProfileMetadataStorageArgs\n *\n * Note: Username is stored WITHOUT the @ prefix. The @ is stripped if provided.\n *\n * @param username - X/Twitter username (with or without @)\n * @returns Arguments for Storage.put()\n */\nexport function getXUsernameStorageArgs(username: string): ProfileStorageArgs {\n // Strip @ prefix if present - store username without @\n const normalizedUsername = username.startsWith(\"@\")\n ? username.slice(1)\n : username;\n return getProfileMetadataStorageArgs({ x_username: normalizedUsername });\n}\n\n/**\n * Prepare transaction arguments for updating profile canvas (HTML content)\n *\n * @param htmlContent - HTML content for the profile canvas\n * @returns Arguments for Storage.put()\n *\n * @example\n * ```ts\n * const args = getProfileCanvasStorageArgs(\"<div>My custom profile</div>\");\n * writeContract({\n * abi: STORAGE_CONTRACT.abi,\n * address: STORAGE_CONTRACT.address,\n * functionName: \"put\",\n * args: [args.bytesKey, args.topic, args.bytesValue],\n * });\n * ```\n */\nexport function getProfileCanvasStorageArgs(\n htmlContent: string\n): ProfileStorageArgs {\n const { bytesKey, bytesValue } = getBytesArgsForStorage(\n PROFILE_CANVAS_STORAGE_KEY,\n htmlContent\n );\n return {\n bytesKey,\n topic: PROFILE_CANVAS_TOPIC,\n bytesValue,\n };\n}\n\n/**\n * Parse profile metadata JSON and extract profile data\n *\n * @param jsonData - JSON string from storage\n * @returns Parsed profile metadata or undefined if invalid\n */\nexport function parseProfileMetadata(\n jsonData: string\n): ProfileMetadata | undefined {\n try {\n const parsed = JSON.parse(jsonData);\n const storedUsername =\n parsed?.x_username &&\n typeof parsed.x_username === \"string\" &&\n parsed.x_username.length > 0\n ? parsed.x_username\n : undefined;\n\n // Strip @ if present for backwards compatibility with older stored data\n const usernameWithoutAt = storedUsername?.startsWith(\"@\")\n ? storedUsername.slice(1)\n : storedUsername;\n\n // Extract bio if present\n const bio =\n parsed?.bio && typeof parsed.bio === \"string\" && parsed.bio.length > 0\n ? parsed.bio\n : undefined;\n\n // Extract display name if present\n const display_name =\n parsed?.display_name &&\n typeof parsed.display_name === \"string\" &&\n parsed.display_name.length > 0\n ? parsed.display_name\n : undefined;\n\n // Extract token address if present (stored as lowercase)\n const token_address =\n parsed?.token_address &&\n typeof parsed.token_address === \"string\" &&\n parsed.token_address.length > 0\n ? parsed.token_address.toLowerCase()\n : undefined;\n\n return {\n x_username: usernameWithoutAt,\n bio,\n display_name,\n token_address,\n };\n } catch {\n return undefined;\n }\n}\n\n/**\n * Validate that a string is a valid URL\n */\nexport function isValidUrl(url: string): boolean {\n if (!url) return false;\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate X/Twitter username format\n * Returns true if valid (alphanumeric and underscores, 1-15 chars)\n */\nexport function isValidXUsername(username: string): boolean {\n if (!username) return false;\n // Remove @ prefix if present\n const cleanUsername = username.startsWith(\"@\") ? username.slice(1) : username;\n // X usernames: 1-15 chars, alphanumeric and underscores only\n return /^[a-zA-Z0-9_]{1,15}$/.test(cleanUsername);\n}\n\n/**\n * Validate bio format\n * Returns true if valid (max 280 chars, no control characters except newlines)\n */\nexport function isValidBio(bio: string): boolean {\n if (!bio) return false;\n if (bio.length > 280) return false;\n // Allow printable characters, spaces, and newlines. Disallow other control chars.\n // eslint-disable-next-line no-control-regex\n const hasControlChars = /[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]/.test(bio);\n return !hasControlChars;\n}\n\n/**\n * Validate display name format\n * Returns true if valid (1-25 characters, no control characters except spaces)\n */\nexport function isValidDisplayName(displayName: string): boolean {\n if (!displayName) return false;\n if (displayName.length > 25) return false;\n // Disallow control characters\n // eslint-disable-next-line no-control-regex\n const hasControlChars = /[\\x00-\\x1F\\x7F]/.test(displayName);\n return !hasControlChars;\n}\n\n/**\n * Prepare transaction arguments for updating bio\n * This is a convenience wrapper around getProfileMetadataStorageArgs\n *\n * @param bio - The bio text\n * @returns Arguments for Storage.put()\n */\nexport function getBioStorageArgs(bio: string): ProfileStorageArgs {\n return getProfileMetadataStorageArgs({ bio });\n}\n\n/**\n * Prepare transaction arguments for updating display name\n * This is a convenience wrapper around getProfileMetadataStorageArgs\n *\n * @param displayName - The display name (max 25 characters)\n * @returns Arguments for Storage.put()\n */\nexport function getDisplayNameStorageArgs(\n displayName: string\n): ProfileStorageArgs {\n return getProfileMetadataStorageArgs({ display_name: displayName });\n}\n\n/**\n * Prepare transaction arguments for updating token address\n * This is a convenience wrapper around getProfileMetadataStorageArgs\n *\n * @param tokenAddress - The ERC-20 token contract address (stored as lowercase)\n * @returns Arguments for Storage.put()\n */\nexport function getTokenAddressStorageArgs(\n tokenAddress: string\n): ProfileStorageArgs {\n return getProfileMetadataStorageArgs({\n token_address: tokenAddress.toLowerCase(),\n });\n}\n\n/**\n * Validate that a string is a valid EVM token address\n * Returns true if valid (0x-prefixed, 40 hex characters)\n */\nexport function isValidTokenAddress(address: string): boolean {\n if (!address) return false;\n return /^0x[a-fA-F0-9]{40}$/.test(address);\n}\n\n/**\n * Maximum CSS size in bytes (10KB — CSS should be small)\n */\nexport const MAX_CSS_SIZE = 10 * 1024;\n\n/**\n * Prepare transaction arguments for updating profile custom CSS\n *\n * @param cssContent - CSS string to store\n * @returns Arguments for Storage.put() - [bytesKey, topic, bytesValue]\n *\n * @example\n * ```ts\n * const args = getProfileCSSStorageArgs(\".profile-themed { --primary: 210 40% 98%; }\");\n * writeContract({\n * abi: STORAGE_CONTRACT.abi,\n * address: STORAGE_CONTRACT.address,\n * functionName: \"put\",\n * args: [args.bytesKey, args.topic, args.bytesValue],\n * });\n * ```\n */\nexport function getProfileCSSStorageArgs(\n cssContent: string\n): ProfileStorageArgs {\n const { bytesKey, bytesValue } = getBytesArgsForStorage(\n PROFILE_CSS_STORAGE_KEY,\n cssContent\n );\n return {\n bytesKey,\n topic: PROFILE_CSS_TOPIC,\n bytesValue,\n };\n}\n\n/**\n * Validate CSS content\n * Returns true if valid (non-empty, within size limit, no script injection)\n */\nexport function isValidCSS(css: string): boolean {\n if (!css || css.trim().length === 0) return false;\n if (Buffer.byteLength(css, \"utf-8\") > MAX_CSS_SIZE) return false;\n // Block script injection via CSS expressions/behavior/url(javascript:)\n const lowerCSS = css.toLowerCase();\n if (lowerCSS.includes(\"expression(\")) return false;\n if (lowerCSS.includes(\"behavior:\")) return false;\n if (lowerCSS.includes(\"javascript:\")) return false;\n if (/<script/i.test(css)) return false;\n return true;\n}\n","/**\n * Single source of truth for profile CSS theming.\n *\n * This file defines:\n * 1. THEME_SELECTORS — the stable set of CSS selectors/variables available for theming\n * 2. DEMO_THEMES — example CSS themes users can apply\n * 3. buildCSSPrompt() — generates an AI prompt describing what can be themed\n *\n * When the profile page structure changes, update THEME_SELECTORS here and\n * everything downstream (AI prompt, docs, validation) stays in sync.\n */\n\n/**\n * A themeable selector or CSS variable group\n */\nexport interface ThemeSelector {\n /** CSS selector or variable name */\n selector: string;\n /** Human-readable description of what it targets */\n description: string;\n /** Category for grouping in documentation */\n category: \"variable\" | \"layout\" | \"component\";\n}\n\n/**\n * All themeable selectors available for profile CSS.\n *\n * CSS variables (category: \"variable\") are the most stable —\n * they survive page restructuring because they're part of the\n * shadcn/Tailwind design system.\n *\n * Layout and component selectors may break when the page structure changes.\n */\nexport const THEME_SELECTORS: ThemeSelector[] = [\n // --- CSS Variables (stable) ---\n {\n selector: \"--background\",\n description: \"Page background color (HSL values, e.g. '210 40% 2%')\",\n category: \"variable\",\n },\n {\n selector: \"--foreground\",\n description: \"Default text color\",\n category: \"variable\",\n },\n {\n selector: \"--primary\",\n description: \"Primary accent color (buttons, links, headings)\",\n category: \"variable\",\n },\n {\n selector: \"--primary-foreground\",\n description: \"Text on primary-colored elements\",\n category: \"variable\",\n },\n {\n selector: \"--secondary\",\n description: \"Secondary accent color\",\n category: \"variable\",\n },\n {\n selector: \"--secondary-foreground\",\n description: \"Text on secondary-colored elements\",\n category: \"variable\",\n },\n {\n selector: \"--muted\",\n description: \"Muted/subdued background\",\n category: \"variable\",\n },\n {\n selector: \"--muted-foreground\",\n description: \"Text on muted backgrounds\",\n category: \"variable\",\n },\n {\n selector: \"--accent\",\n description: \"Accent color for highlights\",\n category: \"variable\",\n },\n {\n selector: \"--accent-foreground\",\n description: \"Text on accent-colored elements\",\n category: \"variable\",\n },\n {\n selector: \"--card\",\n description: \"Card/panel background color\",\n category: \"variable\",\n },\n {\n selector: \"--card-foreground\",\n description: \"Text inside cards\",\n category: \"variable\",\n },\n {\n selector: \"--border\",\n description: \"Border color\",\n category: \"variable\",\n },\n {\n selector: \"--ring\",\n description: \"Focus ring color\",\n category: \"variable\",\n },\n {\n selector: \"--radius\",\n description: \"Border radius (e.g. '0.5rem')\",\n category: \"variable\",\n },\n\n // --- Layout selectors (may change with page restructuring) ---\n {\n selector: \".profile-themed\",\n description: \"Root wrapper for all themed profile content\",\n category: \"layout\",\n },\n\n // --- Component selectors (may change with page restructuring) ---\n {\n selector: \".profile-themed .profile-header\",\n description: \"Profile header area (name, picture, bio)\",\n category: \"component\",\n },\n {\n selector: \".profile-themed .profile-tabs\",\n description: \"Tab navigation bar\",\n category: \"component\",\n },\n {\n selector: \".profile-themed .profile-content\",\n description: \"Main content area below tabs\",\n category: \"component\",\n },\n];\n\n/**\n * Demo themes that users can choose from as starting points.\n * Each is a complete CSS string ready to store on-chain.\n */\nexport const DEMO_THEMES: Record<string, { name: string; css: string }> = {\n hotPink: {\n name: \"Hot Pink Scene\",\n css: `.profile-themed {\n --background: 320 80% 4%;\n --foreground: 320 20% 95%;\n --primary: 330 100% 60%;\n --primary-foreground: 0 0% 100%;\n --secondary: 280 60% 20%;\n --secondary-foreground: 320 20% 95%;\n --muted: 320 40% 12%;\n --muted-foreground: 320 20% 70%;\n --accent: 330 100% 60%;\n --accent-foreground: 0 0% 100%;\n --card: 320 60% 6%;\n --card-foreground: 320 20% 95%;\n --border: 330 60% 25%;\n --ring: 330 100% 60%;\n}`,\n },\n midnightGrunge: {\n name: \"Midnight Grunge\",\n css: `.profile-themed {\n --background: 220 30% 3%;\n --foreground: 220 10% 80%;\n --primary: 45 90% 55%;\n --primary-foreground: 220 30% 5%;\n --secondary: 220 20% 12%;\n --secondary-foreground: 220 10% 80%;\n --muted: 220 20% 8%;\n --muted-foreground: 220 10% 50%;\n --accent: 45 90% 55%;\n --accent-foreground: 220 30% 5%;\n --card: 220 25% 5%;\n --card-foreground: 220 10% 80%;\n --border: 220 15% 15%;\n --ring: 45 90% 55%;\n}`,\n },\n ocean: {\n name: \"Deep Ocean\",\n css: `.profile-themed {\n --background: 200 60% 3%;\n --foreground: 190 20% 90%;\n --primary: 190 80% 50%;\n --primary-foreground: 200 60% 5%;\n --secondary: 210 40% 15%;\n --secondary-foreground: 190 20% 90%;\n --muted: 200 40% 8%;\n --muted-foreground: 190 20% 55%;\n --accent: 170 70% 45%;\n --accent-foreground: 200 60% 5%;\n --card: 200 50% 5%;\n --card-foreground: 190 20% 90%;\n --border: 200 30% 18%;\n --ring: 190 80% 50%;\n}`,\n },\n};\n\n/**\n * Build an AI prompt that describes the available theming surface.\n * Feed this to an LLM alongside a user's description to generate CSS.\n *\n * @returns A prompt string listing all available selectors and usage rules\n */\nexport function buildCSSPrompt(): string {\n const variableLines = THEME_SELECTORS.filter(\n (s) => s.category === \"variable\"\n )\n .map((s) => ` ${s.selector}: ${s.description}`)\n .join(\"\\n\");\n\n const layoutLines = THEME_SELECTORS.filter((s) => s.category === \"layout\")\n .map((s) => ` ${s.selector} — ${s.description}`)\n .join(\"\\n\");\n\n const componentLines = THEME_SELECTORS.filter(\n (s) => s.category === \"component\"\n )\n .map((s) => ` ${s.selector} — ${s.description}`)\n .join(\"\\n\");\n\n return `You are a CSS theme generator for a user profile page.\nAll styles MUST be scoped under the .profile-themed wrapper class.\n\n## CSS Variables (stable — preferred for theming)\nThese use HSL values WITHOUT the hsl() wrapper (e.g. \"210 40% 98%\"):\n${variableLines}\n\n## Layout Selectors (may change across site updates)\n${layoutLines}\n\n## Component Selectors (may change across site updates)\n${componentLines}\n\n## Rules\n1. All selectors MUST start with .profile-themed\n2. CSS variables go inside .profile-themed { ... } as custom properties\n3. Use only valid CSS — no JavaScript, no expressions, no imports\n4. Keep the output under 10KB\n5. Prefer CSS variables over direct selector styling for durability\n6. HSL values are bare numbers: \"210 40% 98%\" not \"hsl(210, 40%, 98%)\"\n\nGiven a user description, output ONLY the CSS (no explanation, no markdown fences).`;\n}\n"]}
|