@shohojdhara/atomix 0.3.10 → 0.3.11

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/dist/index.js CHANGED
@@ -19337,39 +19337,13 @@ class ThemeLogger {
19337
19337
  tokens = input;
19338
19338
  }
19339
19339
  // Merge with defaults and generate CSS
19340
- else {
19341
- // Check if we're in a browser environment
19342
- if ("undefined" != typeof window) throw new ThemeError("No input provided and config loading is not available in browser environment. Please provide tokens explicitly or use Node.js/SSR environment.", ThemeErrorCode.CONFIG_LOAD_FAILED, {
19343
- environment: "browser"
19344
- });
19345
- // Load from config when no input provided
19346
- let loadThemeFromConfigSync, loadAtomixConfig;
19347
- try {
19348
- const configLoaderModule = require("../config/configLoader"), loaderModule = require("../../config/loader");
19349
- // Get prefix from config if needed
19350
- if (loadThemeFromConfigSync = configLoaderModule.loadThemeFromConfigSync, loadAtomixConfig = loaderModule.loadAtomixConfig,
19351
- tokens = loadThemeFromConfigSync(), !options?.prefix) try {
19352
- const config = loadAtomixConfig({
19353
- configPath: "atomix.config.ts",
19354
- required: !1
19355
- });
19356
- options = {
19357
- ...options,
19358
- prefix: config?.prefix || "atomix"
19359
- };
19360
- } catch (error) {
19361
- // If config loading fails, use default prefix
19362
- options = {
19363
- ...options,
19364
- prefix: "atomix"
19365
- };
19366
- }
19367
- } catch (error) {
19368
- throw new ThemeError("No input provided and config loading is not available in this environment. Please provide tokens explicitly.", ThemeErrorCode.CONFIG_LOAD_FAILED, {
19369
- error: error instanceof Error ? error.message : String(error)
19370
- });
19371
- }
19372
- }
19340
+ else
19341
+ // Auto-loading config from file system is removed for browser compatibility.
19342
+ // If no input is provided, we return an empty theme (using defaults only) or user must provide tokens.
19343
+ // This allows createTheme to be isomorphic.
19344
+ // Warn in development if no input provided
19345
+ "production" !== process.env.NODE_ENV && "undefined" != typeof window && console.warn("Atomix: createTheme() called without tokens. Using default tokens only."),
19346
+ tokens = {};
19373
19347
  const allTokens = createTokens(tokens), prefix = options?.prefix ?? "atomix";
19374
19348
  // Get prefix from options or use default
19375
19349
  return generateCSSVariables$1(allTokens, {
@@ -19600,24 +19574,12 @@ class ThemeLogger {
19600
19574
  }
19601
19575
 
19602
19576
  /**
19603
- * CSS File Utilities
19577
+ * Theme System Constants
19604
19578
  *
19605
- * Save CSS to file system (Node.js only).
19579
+ * Centralized constants for the theme system to avoid magic numbers and strings.
19606
19580
  */
19607
19581
  /**
19608
- * Save CSS to file
19609
- *
19610
- * Writes CSS string to a file. Only works in Node.js environment.
19611
- *
19612
- * @param css - CSS string to save
19613
- * @param filePath - Output file path
19614
- * @throws Error if called in browser environment
19615
- *
19616
- * @example
19617
- * ```typescript
19618
- * const css = ':root { --atomix-color-primary: #7AFFD7; }';
19619
- * await saveCSSFile(css, './themes/custom.css');
19620
- * ```
19582
+ * Default storage key for theme persistence
19621
19583
  */ "undefined" != typeof process && process.env;
19622
19584
 
19623
19585
  /**
@@ -20392,141 +20354,6 @@ function generateClassName(block, element, modifiers) {
20392
20354
  return property => getComponentThemeValue(component, property, variant, size);
20393
20355
  }
20394
20356
 
20395
- /**
20396
- * Atomix Config Loader
20397
- *
20398
- * Helper functions to load atomix.config.ts from external projects.
20399
- * Similar to how Tailwind loads tailwind.config.js
20400
- */
20401
- /**
20402
- * Load Atomix configuration from project root
20403
- *
20404
- * Attempts to load atomix.config.ts from the current working directory.
20405
- * Falls back to default config if file doesn't exist.
20406
- *
20407
- * @param options - Loader options
20408
- * @returns Loaded configuration or default
20409
- *
20410
- * @example
20411
- * ```typescript
20412
- * import { loadAtomixConfig } from '@shohojdhara/atomix/config';
20413
- * import { createTheme } from '@shohojdhara/atomix/theme';
20414
- *
20415
- * const config = loadAtomixConfig();
20416
- * const theme = createTheme(config.theme?.tokens || {});
20417
- * ```
20418
- */ function loadAtomixConfig(options = {}) {
20419
- const {configPath: configPath = "atomix.config.ts", required: required = !1} = options, defaultConfig = {
20420
- prefix: "atomix",
20421
- theme: {
20422
- extend: {}
20423
- }
20424
- };
20425
- // Default config
20426
- // In browser environments, config loading is not supported
20427
- if ("undefined" != typeof window) {
20428
- if (required) throw new Error("loadAtomixConfig: Not available in browser environment. Config loading requires Node.js/SSR environment.");
20429
- return defaultConfig;
20430
- }
20431
- // Try to load config file
20432
- try {
20433
- // Use dynamic import for ESM compatibility
20434
- const configModule = require(configPath), config = configModule.default || configModule;
20435
- // Validate it's an AtomixConfig
20436
- if (config && "object" == typeof config) return config;
20437
- throw new Error("Invalid config format");
20438
- } catch (error) {
20439
- if (required) throw new Error(`Failed to load config from ${configPath}: ${error.message}`);
20440
- // Return default config if not required
20441
- return defaultConfig;
20442
- }
20443
- }
20444
-
20445
- /**
20446
- * Resolve config path
20447
- *
20448
- * Finds atomix.config.ts in the project, checking common locations.
20449
- * Returns null in browser environments where file system access is not available.
20450
- *
20451
- * This function is designed to work in Node.js environments only.
20452
- * In browser builds, it will always return null without attempting to access Node.js modules.
20453
- *
20454
- * @internal This function uses Node.js modules and should not be called in browser environments.
20455
- */
20456
- /**
20457
- * Theme Configuration Loader
20458
- *
20459
- * Provides functions to load theme configurations from atomix.config.ts
20460
- * Includes both sync and async versions, with automatic fallbacks
20461
- */
20462
- /**
20463
- * Load theme from config file (synchronous, Node.js only)
20464
- * @param configPath - Path to config file (default: atomix.config.ts)
20465
- * @returns DesignTokens from theme configuration
20466
- * @throws Error if config loading is not available in browser environment
20467
- */
20468
- function loadThemeFromConfigSync(options) {
20469
- // Check if we're in a browser environment
20470
- if ("undefined" != typeof window) throw new Error("loadThemeFromConfigSync: Not available in browser environment. Config loading requires Node.js/SSR environment.");
20471
- // Use static import - the function handles browser environment checks internally
20472
- let config;
20473
- try {
20474
- config = loadAtomixConfig({
20475
- configPath: options?.configPath || "atomix.config.ts",
20476
- required: !1 !== options?.required
20477
- });
20478
- } catch (error) {
20479
- if (!1 !== options?.required) throw new Error("Config loader module not available");
20480
- // Return empty tokens if config is not required
20481
- return createTokens({});
20482
- }
20483
- if (!config?.theme) return createTokens({});
20484
- // Extract tokens from config.theme structure
20485
- // config.theme can have: { extend?: ThemeTokens, tokens?: ThemeTokens, themes?: ... }
20486
- // We need to extract the actual DesignTokens (flat structure)
20487
- const themeConfig = config.theme;
20488
- // Check if theme is directly a flat object (DesignTokens format)
20489
- // This handles the case where config.theme might be passed as DesignTokens directly
20490
- return createTokens(!themeConfig || "object" != typeof themeConfig || "extend" in themeConfig || "tokens" in themeConfig || "themes" in themeConfig ? {} : themeConfig);
20491
- // If theme has nested structure (extend/tokens/themes), we can't directly use it
20492
- // Return empty tokens - the theme system will use defaults
20493
- // TODO: Add proper conversion from ThemeTokens to DesignTokens if needed
20494
- }
20495
-
20496
- /**
20497
- * Load theme from config file (asynchronous)
20498
- * @param configPath - Path to config file (default: atomix.config.ts)
20499
- * @returns Promise resolving to DesignTokens from theme configuration
20500
- */ async function loadThemeFromConfig(options) {
20501
- // Check if we're in a browser environment
20502
- if ("undefined" != typeof window) throw new Error("loadThemeFromConfig: Not available in browser environment. Config loading requires Node.js/SSR environment.");
20503
- // Use static import with runtime check
20504
- // The function will handle browser environment checks internally
20505
- let config;
20506
- try {
20507
- // loadAtomixConfig is synchronous, not async
20508
- config = loadAtomixConfig({
20509
- configPath: options?.configPath || "atomix.config.ts",
20510
- required: !1 !== options?.required
20511
- });
20512
- } catch (error) {
20513
- if (!1 !== options?.required) throw new Error("Config loader module not available");
20514
- // Return empty tokens if config is not required
20515
- return createTokens({});
20516
- }
20517
- if (!config?.theme) return createTokens({});
20518
- // Extract tokens from config.theme structure
20519
- // config.theme can have: { extend?: ThemeTokens, tokens?: ThemeTokens, themes?: ... }
20520
- // We need to extract the actual DesignTokens (flat structure)
20521
- const themeConfig = config.theme;
20522
- // Check if theme is directly a flat object (DesignTokens format)
20523
- // This handles the case where config.theme might be passed as DesignTokens directly
20524
- return createTokens(!themeConfig || "object" != typeof themeConfig || "extend" in themeConfig || "tokens" in themeConfig || "themes" in themeConfig ? {} : themeConfig);
20525
- // If theme has nested structure (extend/tokens/themes), we can't directly use it
20526
- // Return empty tokens - the theme system will use defaults
20527
- // TODO: Add proper conversion from ThemeTokens to DesignTokens if needed
20528
- }
20529
-
20530
20357
  /**
20531
20358
  * Theme Context
20532
20359
  *
@@ -20568,21 +20395,9 @@ const ThemeProvider = ({children: children, defaultTheme: defaultTheme, themes:
20568
20395
  if (stored) return stored;
20569
20396
  }
20570
20397
  // If defaultTheme is provided, use it
20571
- if (null != defaultTheme) return defaultTheme;
20572
- // Try to load from atomix.config.ts as fallback, but only in Node.js/SSR environments
20573
- if ("undefined" == typeof window) try {
20574
- // Dynamically import the config loader to avoid bundling issues in browser
20575
- // eslint-disable-next-line @typescript-eslint/no-var-requires
20576
- const {loadThemeFromConfigSync: loadThemeFromConfigSync} = require("../config/configLoader"), configTokens = loadThemeFromConfigSync();
20577
- if (configTokens && Object.keys(configTokens).length > 0)
20578
- // For simplicity, we'll treat config tokens as a special theme name
20579
- return "config-theme";
20580
- } catch (error) {
20581
- // Failed to load theme from config, using default
20582
- }
20398
+ return null != defaultTheme ? defaultTheme : "default";
20583
20399
  // Default fallback
20584
- return "default";
20585
- }), [ defaultTheme, enablePersistence, storageKey ]), [currentTheme, setCurrentTheme] = React.useState((() => "string" == typeof initialDefaultTheme ? initialDefaultTheme : "tokens-theme")), [activeTokens, setActiveTokens] = React.useState((() =>
20400
+ }), [ defaultTheme, enablePersistence, storageKey ]), [currentTheme, setCurrentTheme] = React.useState((() => "string" == typeof initialDefaultTheme ? initialDefaultTheme : "tokens-theme")), [activeTokens, setActiveTokens] = React.useState((() =>
20586
20401
  // If defaultTheme is DesignTokens, store them
20587
20402
  defaultTheme && "string" != typeof defaultTheme ? createTokens(defaultTheme) : null)), [isLoading, setIsLoading] = React.useState(!1), [error, setError] = React.useState(null), loadedThemesRef = React.useRef(new Set), themePromisesRef = React.useRef({}), abortControllerRef = React.useRef(null);
20588
20403
  // Handle initial DesignTokens defaultTheme
@@ -23577,6 +23392,7 @@ class RTLManager {
23577
23392
  // Core Theme Functions
23578
23393
  // ============================================================================
23579
23394
  // Create theme CSS from DesignTokens
23395
+ // File saving utilities removed to prevent bundling Node.js modules in browser
23580
23396
  /**
23581
23397
  * Inject theme CSS into DOM
23582
23398
  */ function injectTheme(css, id = "atomix-theme") {
@@ -23589,30 +23405,6 @@ class RTLManager {
23589
23405
  removeCSS(id);
23590
23406
  }
23591
23407
 
23592
- /**
23593
- * Save theme to CSS file
23594
- */ async function saveTheme(css, filePath) {
23595
- await async function(css, filePath) {
23596
- // Check if in browser environment
23597
- if ("undefined" != typeof window) throw new Error("saveCSSFile can only be used in Node.js environment. Use injectCSS() for browser environments.");
23598
- // Dynamic import to avoid bundling Node.js modules in browser builds
23599
- const fs = await import("fs/promises"), dir = (await import("path")).dirname(filePath);
23600
- await fs.mkdir(dir, {
23601
- recursive: !0
23602
- }),
23603
- // Write file
23604
- await fs.writeFile(filePath, css, "utf8");
23605
- }
23606
- /**
23607
- * Theme System Constants
23608
- *
23609
- * Centralized constants for the theme system to avoid magic numbers and strings.
23610
- */
23611
- /**
23612
- * Default storage key for theme persistence
23613
- */ (css, filePath);
23614
- }
23615
-
23616
23408
  /**
23617
23409
  * CSS Variables Constants
23618
23410
  *
@@ -23989,8 +23781,6 @@ const composables = composablesImport, utils = utilsImport, types = typesImport,
23989
23781
  isCSSInjected: isCSSInjected,
23990
23782
  isDesignTokens: isDesignTokens,
23991
23783
  isValidCSSVariableName: isValidCSSVariableName,
23992
- loadThemeFromConfig: loadThemeFromConfig,
23993
- loadThemeFromConfigSync: loadThemeFromConfigSync,
23994
23784
  mapSCSSTokensToCSSVars: mapSCSSTokensToCSSVars,
23995
23785
  mergeCSSVars: mergeCSSVars,
23996
23786
  mergeTheme: mergeTheme,
@@ -23999,7 +23789,6 @@ const composables = composablesImport, utils = utilsImport, types = typesImport,
23999
23789
  removeCSS: removeCSS,
24000
23790
  removeCSSVariables: removeCSSVariables,
24001
23791
  removeTheme: removeTheme,
24002
- saveTheme: saveTheme,
24003
23792
  themePropertyToCSSVar: themePropertyToCSSVar,
24004
23793
  unregisterTheme: unregisterTheme,
24005
23794
  useComponentTheme: useComponentTheme,
@@ -24265,11 +24054,9 @@ exports.isDesignTokens = isDesignTokens, exports.isSlot = function(value) {
24265
24054
  * Merge multiple slot configurations
24266
24055
  * Later slots override earlier ones
24267
24056
  */ , exports.isValidCSSVariableName = isValidCSSVariableName, exports.isYouTubeUrl = isYouTubeUrl,
24268
- exports.loadAtomixConfig = loadAtomixConfig, exports.loadThemeFromConfig = loadThemeFromConfig,
24269
- exports.loadThemeFromConfigSync = loadThemeFromConfigSync, exports.mapSCSSTokensToCSSVars = mapSCSSTokensToCSSVars,
24270
- exports.mergeCSSVars = mergeCSSVars, exports.mergeClassNames = mergeClassNames,
24271
- exports.mergeComponentProps = mergeComponentProps, exports.mergePartStyles = mergePartStyles,
24272
- exports.mergeSlots = function(...slots) {
24057
+ exports.mapSCSSTokensToCSSVars = mapSCSSTokensToCSSVars, exports.mergeCSSVars = mergeCSSVars,
24058
+ exports.mergeClassNames = mergeClassNames, exports.mergeComponentProps = mergeComponentProps,
24059
+ exports.mergePartStyles = mergePartStyles, exports.mergeSlots = function(...slots) {
24273
24060
  const filtered = slots.filter((s => void 0 !== s));
24274
24061
  if (0 !== filtered.length) return 1 === filtered.length ? filtered[0] : _reduceInstanceProperty(filtered).call(filtered, ((acc, slot) => ({
24275
24062
  ...acc,
@@ -24293,42 +24080,8 @@ function(name, primaryColor, secondaryColor) {
24293
24080
  }
24294
24081
  });
24295
24082
  }, exports.registerTheme = registerTheme, exports.removeCSS = removeCSS, exports.removeCSSVariables = removeCSSVariables,
24296
- exports.removeTheme = removeTheme, exports.renderSlot = renderSlot, exports.resolveConfigPath = function() {
24297
- // Early return for browser environments - prevents any Node.js module access
24298
- // This check happens before any require() calls, preventing bundlers from analyzing them
24299
- if ("undefined" != typeof window || "undefined" == typeof process || !process.cwd) return null;
24300
- // Only attempt to load Node.js modules in Node.js runtime
24301
- // Use a lazy-loading pattern that prevents static analysis by bundlers
24302
- try {
24303
- // Create a function that only executes in Node.js runtime
24304
- // Use string-based module names to prevent static analysis by bundlers
24305
- const modules = (() => {
24306
- // These requires are only executed at runtime in Node.js environments
24307
- // They are marked as external in Rollup config and should not be bundled
24308
- // Using string concatenation and computed property access to prevent static analysis
24309
- if ("undefined" == typeof require) return null;
24310
- // Use a try-catch wrapper to safely access require
24311
- try {
24312
- // Build module names dynamically to prevent static analysis
24313
- const moduleNames = [ "fs", "path" ];
24314
- // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
24315
- return {
24316
- fs: require(moduleNames[0]),
24317
- path: require(moduleNames[1])
24318
- };
24319
- } catch {
24320
- return null;
24321
- }
24322
- })();
24323
- if (!modules) return null;
24324
- const {fs: fs, path: path} = modules, cwd = process.cwd(), possiblePaths = [ path.join(cwd, "atomix.config.ts"), path.join(cwd, "atomix.config.js"), path.join(cwd, "atomix.config.mjs") ];
24325
- for (const configPath of possiblePaths) if (fs.existsSync(configPath)) return configPath;
24326
- } catch (error) {
24327
- // Silently fail in browser environments or when modules are unavailable
24328
- return null;
24329
- }
24330
- return null;
24331
- }, exports.saveTheme = saveTheme, exports.sliderConstants = sliderConstants, exports.supportsDarkMode = function(theme) {
24083
+ exports.removeTheme = removeTheme, exports.renderSlot = renderSlot, exports.sliderConstants = sliderConstants,
24084
+ exports.supportsDarkMode = function(theme) {
24332
24085
  var _context;
24333
24086
  return "dark" === theme.palette?.mode || !0 === theme.supportsDarkMode || Boolean((null == (_context = theme.a11y?.modes) ? void 0 : Function.call.bind(_includesInstanceProperty(_context), _context))?.("dark"));
24334
24087
  }, exports.theme = theme, exports.themePropertyToCSSVar = themePropertyToCSSVar,