funuicss 3.6.19 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/theme/theme.js CHANGED
@@ -70,7 +70,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
70
70
  }
71
71
  };
72
72
  Object.defineProperty(exports, "__esModule", { value: true });
73
- exports.useComponentVariant = exports.useTypographyValue = exports.useColor = exports.useProjectData = exports.useThemeConfig = exports.useTypography = exports.useColors = exports.useComponentConfig = exports.useThemeValue = exports.useVariant = exports.useTheme = void 0;
73
+ exports.useVariable = exports.useVariables = exports.useComponentVariant = exports.useTypographyValue = exports.useColor = exports.useProjectData = exports.useThemeConfig = exports.useTypography = exports.useColors = exports.useComponentConfig = exports.useThemeValue = exports.getAllVariables = exports.getVariable = exports.useVariant = exports.useTheme = void 0;
74
74
  var react_1 = __importStar(require("react"));
75
75
  var themes_1 = require("./themes");
76
76
  var darkenUtils_1 = require("./darkenUtils");
@@ -97,53 +97,64 @@ var useVariant = function () {
97
97
  };
98
98
  exports.useVariant = useVariant;
99
99
  /* -------------------------------------------------------------------------- */
100
- /* CDN THEME LOADER */
100
+ /* LOCAL FILE MANAGEMENT */
101
101
  /* -------------------------------------------------------------------------- */
102
- var loadThemeFromCDN = function (projectId) { return __awaiter(void 0, void 0, void 0, function () {
103
- var publicResponse, data, error_1, publicUrl, response, data, error_2;
102
+ var loadLocalTheme = function () { return __awaiter(void 0, void 0, void 0, function () {
103
+ var response, data, error_1;
104
104
  return __generator(this, function (_a) {
105
105
  switch (_a.label) {
106
106
  case 0:
107
107
  _a.trys.push([0, 4, , 5]);
108
- return [4 /*yield*/, fetch("/funui.json", {
108
+ return [4 /*yield*/, fetch('/funui.json', {
109
109
  cache: 'no-cache',
110
110
  })];
111
111
  case 1:
112
- publicResponse = _a.sent();
113
- if (!publicResponse.ok) return [3 /*break*/, 3];
114
- return [4 /*yield*/, publicResponse.json()];
112
+ response = _a.sent();
113
+ if (!response.ok) return [3 /*break*/, 3];
114
+ return [4 /*yield*/, response.json()];
115
115
  case 2:
116
116
  data = _a.sent();
117
- console.log('✅ Loaded theme from public folder');
117
+ console.log('✅ Loaded theme from local file');
118
118
  return [2 /*return*/, data];
119
119
  case 3: return [3 /*break*/, 5];
120
120
  case 4:
121
121
  error_1 = _a.sent();
122
- console.log('No theme in public folder, checking Firebase Storage...');
122
+ console.log('No local theme file found');
123
123
  return [3 /*break*/, 5];
124
- case 5:
125
- _a.trys.push([5, 10, , 11]);
124
+ case 5: return [2 /*return*/, null];
125
+ }
126
+ });
127
+ }); };
128
+ /* -------------------------------------------------------------------------- */
129
+ /* CDN THEME LOADER */
130
+ /* -------------------------------------------------------------------------- */
131
+ var loadThemeFromCDN = function (projectId) { return __awaiter(void 0, void 0, void 0, function () {
132
+ var publicUrl, response, data, error_2;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0:
136
+ _a.trys.push([0, 5, , 6]);
126
137
  publicUrl = "https://firebasestorage.googleapis.com/v0/b/funui-4bcd1.firebasestorage.app/o/themes%2F".concat(projectId, ".json?alt=media");
127
138
  return [4 /*yield*/, fetch(publicUrl, {
128
139
  cache: 'no-cache',
129
140
  })];
130
- case 6:
141
+ case 1:
131
142
  response = _a.sent();
132
- if (!response.ok) return [3 /*break*/, 8];
143
+ if (!response.ok) return [3 /*break*/, 3];
133
144
  return [4 /*yield*/, response.json()];
134
- case 7:
145
+ case 2:
135
146
  data = _a.sent();
136
147
  console.log('✅ Loaded theme from Firebase Storage CDN');
137
148
  return [2 /*return*/, data];
138
- case 8:
149
+ case 3:
139
150
  console.error('Firebase Storage fetch failed:', response.status, response.statusText);
140
- _a.label = 9;
141
- case 9: return [3 /*break*/, 11];
142
- case 10:
151
+ _a.label = 4;
152
+ case 4: return [3 /*break*/, 6];
153
+ case 5:
143
154
  error_2 = _a.sent();
144
155
  console.error('Error loading from Firebase Storage:', error_2);
145
- return [3 /*break*/, 11];
146
- case 11: return [2 /*return*/, null];
156
+ return [3 /*break*/, 6];
157
+ case 6: return [2 /*return*/, null];
147
158
  }
148
159
  });
149
160
  }); };
@@ -155,7 +166,6 @@ var applyTypographyVariables = function (typography, root) {
155
166
  return;
156
167
  Object.entries(typography).forEach(function (_a) {
157
168
  var key = _a[0], value = _a[1];
158
- // Convert flat keys to CSS custom property format
159
169
  var cssVarName = "--".concat(key.replace(/_/g, '-'));
160
170
  root.style.setProperty(cssVarName, value);
161
171
  });
@@ -165,7 +175,6 @@ var applyColorVariables = function (colors, root) {
165
175
  return;
166
176
  Object.entries(colors).forEach(function (_a) {
167
177
  var key = _a[0], value = _a[1];
168
- // Convert flat keys to CSS custom property format
169
178
  var cssVarName = "--".concat(key.replace(/_/g, '-'));
170
179
  root.style.setProperty(cssVarName, value);
171
180
  });
@@ -173,15 +182,12 @@ var applyColorVariables = function (colors, root) {
173
182
  var applyThemeConfig = function (themeConfig, root) {
174
183
  if (!themeConfig)
175
184
  return;
176
- // Apply colors if they exist
177
185
  if (themeConfig.colors) {
178
186
  applyColorVariables(themeConfig.colors, root);
179
187
  }
180
- // Apply typography if it exists
181
188
  if (themeConfig.typography) {
182
189
  applyTypographyVariables(themeConfig.typography, root);
183
190
  }
184
- // Apply any other theme config properties
185
191
  Object.entries(themeConfig).forEach(function (_a) {
186
192
  var key = _a[0], value = _a[1];
187
193
  if (key !== 'colors' && key !== 'typography' && typeof value === 'string') {
@@ -191,6 +197,23 @@ var applyThemeConfig = function (themeConfig, root) {
191
197
  });
192
198
  };
193
199
  /* -------------------------------------------------------------------------- */
200
+ /* VARIABLES HELPER */
201
+ /* -------------------------------------------------------------------------- */
202
+ var cachedProjectData = null;
203
+ var getVariable = function (name) {
204
+ if (!(cachedProjectData === null || cachedProjectData === void 0 ? void 0 : cachedProjectData.variables)) {
205
+ console.warn('No variables available. Make sure ThemeProvider is mounted.');
206
+ return undefined;
207
+ }
208
+ var variable = cachedProjectData.variables.find(function (v) { return v.name === name; });
209
+ return variable;
210
+ };
211
+ exports.getVariable = getVariable;
212
+ var getAllVariables = function () {
213
+ return (cachedProjectData === null || cachedProjectData === void 0 ? void 0 : cachedProjectData.variables) || [];
214
+ };
215
+ exports.getAllVariables = getAllVariables;
216
+ /* -------------------------------------------------------------------------- */
194
217
  /* COMPONENT */
195
218
  /* -------------------------------------------------------------------------- */
196
219
  var ThemeProvider = function (_a) {
@@ -223,7 +246,7 @@ var ThemeProvider = function (_a) {
223
246
  });
224
247
  }
225
248
  }, [theme]);
226
- /* ---------------------- CDN Theme Sync ----------------------- */
249
+ /* ---------------------- CDN Theme Sync with Local File ----------------------- */
227
250
  (0, react_1.useEffect)(function () {
228
251
  if (typeof window === 'undefined' || !projectId) {
229
252
  setIsLoading(false);
@@ -232,51 +255,68 @@ var ThemeProvider = function (_a) {
232
255
  }
233
256
  var root = document.documentElement;
234
257
  var pollTimer;
235
- var fetchFromCDN = function () { return __awaiter(void 0, void 0, void 0, function () {
236
- var cdnTheme, newVersion, err_1;
258
+ var syncTheme = function () { return __awaiter(void 0, void 0, void 0, function () {
259
+ var localTheme, localVersion, cdnTheme, cdnVersion, err_1;
237
260
  return __generator(this, function (_a) {
238
261
  switch (_a.label) {
239
262
  case 0:
240
- _a.trys.push([0, 2, 3, 4]);
241
- return [4 /*yield*/, loadThemeFromCDN(projectId)];
263
+ _a.trys.push([0, 3, 4, 5]);
264
+ return [4 /*yield*/, loadLocalTheme()];
242
265
  case 1:
266
+ localTheme = _a.sent();
267
+ localVersion = (localTheme === null || localTheme === void 0 ? void 0 : localTheme.version) || 0;
268
+ return [4 /*yield*/, loadThemeFromCDN(projectId)];
269
+ case 2:
243
270
  cdnTheme = _a.sent();
271
+ cdnVersion = (cdnTheme === null || cdnTheme === void 0 ? void 0 : cdnTheme.version) || 0;
244
272
  if (cdnTheme) {
245
- newVersion = cdnTheme.version || Date.now();
246
- if (!currentVersion || newVersion !== currentVersion) {
247
- // Apply theme data to CSS variables and state
273
+ // Compare versions and use the newer one
274
+ if (cdnVersion !== localVersion) {
275
+ console.log("\uD83D\uDD04 Version mismatch: Local(".concat(localVersion, ") vs CDN(").concat(cdnVersion, ")"));
276
+ console.log('ℹ️ Using CDN version. Please update your local funui.json file manually.');
277
+ }
278
+ // Always use CDN theme if available
279
+ if (!currentVersion || cdnVersion !== currentVersion) {
248
280
  applyThemeData(cdnTheme, root);
249
- setCurrentVersion(newVersion);
250
- console.log('✅ Theme updated from CDN');
281
+ setCurrentVersion(cdnVersion);
282
+ console.log('✅ Theme loaded from CDN');
251
283
  }
252
284
  else {
253
- console.log('✓ Theme unchanged');
285
+ console.log('✓ Theme up to date');
254
286
  }
255
287
  setError(null);
256
288
  }
289
+ else if (localTheme) {
290
+ // CDN not available but we have local
291
+ console.log('⚠️ Using local theme (CDN unavailable)');
292
+ applyThemeData(localTheme, root);
293
+ setCurrentVersion(localVersion);
294
+ setError(null);
295
+ }
257
296
  else {
258
- console.warn('⚠️ No theme found in CDN');
259
- setError('Theme not found in CDN');
297
+ // No theme available anywhere
298
+ console.warn('⚠️ No theme found');
299
+ setError('Theme not found');
260
300
  }
261
- return [3 /*break*/, 4];
262
- case 2:
263
- err_1 = _a.sent();
264
- console.error('Error loading theme from CDN:', err_1);
265
- setError('Failed to load theme from CDN');
266
- return [3 /*break*/, 4];
301
+ return [3 /*break*/, 5];
267
302
  case 3:
303
+ err_1 = _a.sent();
304
+ console.error('Error syncing theme:', err_1);
305
+ setError('Failed to sync theme');
306
+ return [3 /*break*/, 5];
307
+ case 4:
268
308
  setIsLoading(false);
269
309
  setIsInitialLoad(false);
270
310
  return [7 /*endfinally*/];
271
- case 4: return [2 /*return*/];
311
+ case 5: return [2 /*return*/];
272
312
  }
273
313
  });
274
314
  }); };
275
- // Initial load
276
- fetchFromCDN();
315
+ // Initial sync
316
+ syncTheme();
277
317
  // Poll for updates every 5 minutes
278
318
  pollTimer = setInterval(function () {
279
- fetchFromCDN();
319
+ syncTheme();
280
320
  }, 5 * 60 * 1000);
281
321
  return function () {
282
322
  clearInterval(pollTimer);
@@ -289,6 +329,8 @@ var ThemeProvider = function (_a) {
289
329
  setVariant(newVariant);
290
330
  setThemeConfig(themeConfig);
291
331
  setProjectData(data);
332
+ // Cache for variable access
333
+ cachedProjectData = data;
292
334
  // Apply all theme config to CSS variables
293
335
  applyThemeConfig(themeConfig, root);
294
336
  };
@@ -346,22 +388,32 @@ var useProjectData = function () {
346
388
  return projectData;
347
389
  };
348
390
  exports.useProjectData = useProjectData;
349
- // Get specific color value
350
391
  var useColor = function (colorName) {
351
392
  var colors = (0, exports.useColors)();
352
393
  return colors[colorName];
353
394
  };
354
395
  exports.useColor = useColor;
355
- // Get specific typography value
356
396
  var useTypographyValue = function (property) {
357
397
  var typography = (0, exports.useTypography)();
358
398
  return typography[property];
359
399
  };
360
400
  exports.useTypographyValue = useTypographyValue;
361
- // Get component variant
362
401
  var useComponentVariant = function (componentName, variantName) {
363
402
  if (variantName === void 0) { variantName = 'default'; }
364
403
  var componentConfig = (0, exports.useComponentConfig)(componentName);
365
404
  return componentConfig[variantName] || {};
366
405
  };
367
406
  exports.useComponentVariant = useComponentVariant;
407
+ // Hook to access variables
408
+ var useVariables = function () {
409
+ var projectData = (0, exports.useTheme)().projectData;
410
+ return (projectData === null || projectData === void 0 ? void 0 : projectData.variables) || [];
411
+ };
412
+ exports.useVariables = useVariables;
413
+ // Hook to get a specific variable
414
+ var useVariable = function (name) {
415
+ var variables = (0, exports.useVariables)();
416
+ var variable = variables.find(function (v) { return v.name === name; });
417
+ return variable === null || variable === void 0 ? void 0 : variable.value;
418
+ };
419
+ exports.useVariable = useVariable;
@@ -1,191 +0,0 @@
1
- import { Auth, User, UserCredential } from 'firebase/auth';
2
- interface AuthResponse {
3
- user: User;
4
- credential: UserCredential;
5
- isNewUser?: boolean;
6
- }
7
- interface AuthStateCallback {
8
- (user: User | null): void;
9
- }
10
- type ProviderType = 'google' | 'facebook' | 'github' | 'twitter' | 'microsoft' | 'apple';
11
- /**
12
- * Firebase Authentication Operations
13
- * Users must pass their Auth instance to each method
14
- */
15
- export declare const FunFireAuth: {
16
- /**
17
- * 📧 Sign in with email and password
18
- * @param auth - Firebase Auth instance
19
- * @param email - User email
20
- * @param password - User password
21
- */
22
- signInWithEmail: (auth: Auth, email: string, password: string) => Promise<AuthResponse>;
23
- /**
24
- * ✍️ Create account with email and password
25
- * @param auth - Firebase Auth instance
26
- * @param email - User email
27
- * @param password - User password
28
- * @param displayName - Optional display name
29
- * @param photoURL - Optional photo URL
30
- */
31
- createAccount: (auth: Auth, email: string, password: string, displayName?: string, photoURL?: string) => Promise<AuthResponse>;
32
- /**
33
- * 🔐 Sign in with Google (Popup)
34
- * @param auth - Firebase Auth instance
35
- */
36
- signInWithGoogle: (auth: Auth) => Promise<AuthResponse>;
37
- /**
38
- * 🔐 Sign in with Facebook (Popup)
39
- * @param auth - Firebase Auth instance
40
- */
41
- signInWithFacebook: (auth: Auth) => Promise<AuthResponse>;
42
- /**
43
- * 🔐 Sign in with GitHub (Popup)
44
- * @param auth - Firebase Auth instance
45
- */
46
- signInWithGithub: (auth: Auth) => Promise<AuthResponse>;
47
- /**
48
- * 🔐 Sign in with Twitter (Popup)
49
- * @param auth - Firebase Auth instance
50
- */
51
- signInWithTwitter: (auth: Auth) => Promise<AuthResponse>;
52
- /**
53
- * 🔐 Sign in with Microsoft (Popup)
54
- * @param auth - Firebase Auth instance
55
- */
56
- signInWithMicrosoft: (auth: Auth) => Promise<AuthResponse>;
57
- /**
58
- * 🔐 Sign in with Apple (Popup)
59
- * @param auth - Firebase Auth instance
60
- */
61
- signInWithApple: (auth: Auth) => Promise<AuthResponse>;
62
- /**
63
- * 🔐 Generic provider sign in with redirect (better for mobile)
64
- * @param auth - Firebase Auth instance
65
- * @param providerType - Provider type
66
- */
67
- signInWithRedirect: (auth: Auth, providerType: ProviderType) => Promise<void>;
68
- /**
69
- * 🚪 Sign out
70
- * @param auth - Firebase Auth instance
71
- */
72
- signOut: (auth: Auth) => Promise<void>;
73
- /**
74
- * 🔄 Send password reset email
75
- * @param auth - Firebase Auth instance
76
- * @param email - User email
77
- * @param actionCodeSettings - Optional action code settings for custom redirect
78
- */
79
- resetPassword: (auth: Auth, email: string, actionCodeSettings?: {
80
- url: string;
81
- handleCodeInApp?: boolean;
82
- }) => Promise<void>;
83
- /**
84
- * ✉️ Send email verification
85
- * @param auth - Firebase Auth instance
86
- * @param actionCodeSettings - Optional action code settings for custom redirect
87
- */
88
- sendVerificationEmail: (auth: Auth, actionCodeSettings?: {
89
- url: string;
90
- handleCodeInApp?: boolean;
91
- }) => Promise<void>;
92
- /**
93
- * 🔑 Update user password
94
- * @param auth - Firebase Auth instance
95
- * @param newPassword - New password
96
- */
97
- updatePassword: (auth: Auth, newPassword: string) => Promise<void>;
98
- /**
99
- * 📧 Update user email
100
- * @param auth - Firebase Auth instance
101
- * @param newEmail - New email
102
- */
103
- updateEmail: (auth: Auth, newEmail: string) => Promise<void>;
104
- /**
105
- * 👤 Update user profile
106
- * @param auth - Firebase Auth instance
107
- * @param displayName - Display name
108
- * @param photoURL - Photo URL
109
- */
110
- updateProfile: (auth: Auth, displayName?: string, photoURL?: string) => Promise<void>;
111
- /**
112
- * 🔐 Reauthenticate user (required before sensitive operations)
113
- * @param auth - Firebase Auth instance
114
- * @param password - Current password
115
- */
116
- reauthenticate: (auth: Auth, password: string) => Promise<UserCredential>;
117
- /**
118
- * ❌ Delete user account
119
- * @param auth - Firebase Auth instance
120
- */
121
- deleteAccount: (auth: Auth) => Promise<void>;
122
- /**
123
- * 👁️ Listen to auth state changes
124
- * @param auth - Firebase Auth instance
125
- * @param callback - Callback function that receives user or null
126
- * @returns Unsubscribe function
127
- */
128
- onAuthStateChanged: (auth: Auth, callback: AuthStateCallback) => (() => void);
129
- /**
130
- * 🔍 Get current user
131
- * @param auth - Firebase Auth instance
132
- * @returns Current user or null
133
- */
134
- getCurrentUser: (auth: Auth) => User | null;
135
- /**
136
- * 🔍 Check if email exists
137
- * @param auth - Firebase Auth instance
138
- * @param email - Email to check
139
- * @returns Array of sign-in methods for the email
140
- */
141
- checkEmailExists: (auth: Auth, email: string) => Promise<string[]>;
142
- /**
143
- * ✅ Apply action code (email verification, password reset)
144
- * @param auth - Firebase Auth instance
145
- * @param code - Action code from email link
146
- */
147
- applyActionCode: (auth: Auth, code: string) => Promise<void>;
148
- /**
149
- * 🔍 Verify password reset code
150
- * @param auth - Firebase Auth instance
151
- * @param code - Password reset code
152
- * @returns Email associated with the code
153
- */
154
- verifyPasswordResetCode: (auth: Auth, code: string) => Promise<string>;
155
- /**
156
- * ✅ Confirm password reset
157
- * @param auth - Firebase Auth instance
158
- * @param code - Password reset code
159
- * @param newPassword - New password
160
- */
161
- confirmPasswordReset: (auth: Auth, code: string, newPassword: string) => Promise<void>;
162
- /**
163
- * 🔗 Link account with Google
164
- * @param auth - Firebase Auth instance
165
- */
166
- linkWithGoogle: (auth: Auth) => Promise<UserCredential>;
167
- /**
168
- * 🔓 Unlink provider from account
169
- * @param auth - Firebase Auth instance
170
- * @param providerId - Provider ID to unlink (e.g., 'google.com', 'password')
171
- */
172
- unlinkProvider: (auth: Auth, providerId: string) => Promise<User>;
173
- /**
174
- * 📱 Get ID token (for backend verification)
175
- * @param auth - Firebase Auth instance
176
- * @param forceRefresh - Force token refresh
177
- */
178
- getIdToken: (auth: Auth, forceRefresh?: boolean) => Promise<string>;
179
- };
180
- export declare const AuthErrorCodes: {
181
- EMAIL_EXISTS: string;
182
- INVALID_EMAIL: string;
183
- WEAK_PASSWORD: string;
184
- USER_NOT_FOUND: string;
185
- WRONG_PASSWORD: string;
186
- TOO_MANY_REQUESTS: string;
187
- NETWORK_ERROR: string;
188
- POPUP_CLOSED: string;
189
- REQUIRES_RECENT_LOGIN: string;
190
- };
191
- export type { AuthResponse, AuthStateCallback, ProviderType };