Devup UI Documentation

repository·main·Indexed 18 days ago

https://github.com/dev-five-git/devup-ui

A zero-runtime, zero-config CSS-in-JS library featuring a Rust-powered preprocessor for build-time style extraction. It provides an API compatible with styled-components and Emotion, supporting React Server Components (RSC). The ecosystem includes @devup-ui/bun-plugin for Bun build integration, a WebAssembly-based extractor, and a dedicated ESLint plugin to enforce literal values and prevent redundant responsive styles.

Tokens
103.3K
Snippets
358
Records
497
Agent score
62%

What's inside Devup UI

  1. How color optimization works

    main

    Devup UI normalizes and compresses color values to reduce the character count in the final CSS bundle through several techniques:

    • RGB/RGBA to Hex Conversion: All rgb() and rgba() values are converted to compact hexadecimal format.
    • Hex Shortening: 6-digit hex codes are reduced to 3 digits (e.g., #ffffff#fff) and 8-digit hex codes are reduced to 4 digits when the alpha channel is fully opaque (e.g., #ffffffff#ffff).
    • Alpha Channel Optimization: Unnecessary opacity information is removed. Fully opaque colors are shortened to 3-digit hex, while partial transparency is preserved using 4-digit hex.
    // RGB/RGBA to Hex
    <Box bg="rgb(255, 0, 0)" />       // Output: #f00
    <Box bg="rgba(255, 0, 0, 0.5)" /> // Output: #f000
    
    // Hex Shortening & Alpha Optimization
    // #ffffff → #fff
    // #ffffffff → #ffff
    // #ff0000ff → #f00
  2. Handle Nested Groups

    main

    When nesting elements with data-group, the _group* selector applies to the nearest parent that possesses the data-group attribute. This allows you to create complex, layered interactive components where inner elements respond to their immediate container while outer elements respond to the main container.

    <Box bg="white" data-group p={4}>
      <Text _groupHover={{ color: 'blue' }}>Responds to outer group</Text>
    
      <Box bg="$backgroundMuted" data-group mt={2} p={2}>
        <Text _groupHover={{ color: 'red' }}>Responds to inner group</Text>
      </Box>
    </Box>
  3. Understand responsive array behavior for length tokens

    main

    There is a critical distinction between using a token as a standalone value versus using it inside a manual responsive array:

    1. Standalone Token: If you pass "$token" directly to a prop, Devup UI expands it into all defined breakpoints.
    2. Token inside an Array: If you pass a token inside a manual array (e.g., ['8px', null, '$token']), the token does not expand. Instead, the array itself defines the breakpoints, and the token is treated as a single value at its specific index.
    SyntaxBehaviorClasses
    px="$containerX"Expands to all defined breakpointsMultiple
    px={ "$containerX" }Expands to all defined breakpointsMultiple
    px={ ["$containerX"] }Single value at index 01
    px={ ["8px", null, "$containerX"] }8px at index 0, token at index 22
    {/* The token stays as a single value at breakpoint index 2 */}
    <Box px={['8px', null, '$containerX']} />
  4. Ad-blocker compatibility in N/M Base

    main

    Devup UI is designed to avoid common ad-blocker triggers that can break UI layouts. Ad-blockers often look for the string ad in class names to identify and hide advertisements.

    Safety Measures:

    • Pattern Avoidance: Any class name that would end in ad is automatically transformed to a-d.
    • Character Set: Only a-z, -, and _ are used to avoid triggering filters.
    • No Leading Digits: Class names never start with digits, ensuring compliance with CSS constraints and avoiding accidental pattern matches.
  5. Understand Devup UI Style Storage and De-duplication

    main

    Devup UI uses a centralized style storage mechanism to eliminate CSS duplication. Instead of generating redundant styles, it ensures that identical style declarations across your application are mapped to exactly one atomic class.

    How it works:

    • When a style is encountered, Devup UI checks the storage.
    • If the style signature already exists, the existing atomic class is reused.
    • If the style is new, a new class is generated and registered in the storage.

    Requirement: To guarantee effective de-duplication, your build pipeline must use exactly one style storage. Multiple storages will fragment duplicate detection, potentially causing the same style to be generated with different class names.

  6. How the N/M Base class name system works

    main

    Devup UI uses a custom N/M base numbering system to generate compact, collision-free, and ad-blocker-safe class names. The system converts unique style signatures into short alphabetic strings.

    The Base Systems

    • N Base: Uses a-z and _ (27 characters).
    • M Base: Uses a-z, 0-9, and _ (37 characters).

    Generation Process

    1. Style Signature: A unique key is created by combining the property, level, value, selector, and style order.
    2. File Identifier: A file-specific identifier is added (converting the filename to a number) to allow for per-file CSS splitting.
    3. Sequential Assignment: Styles are assigned a number based on their order in the GLOBAL_CLASS_MAP.
    4. N/M Conversion: The number is converted to an alphabetic string using the two-phase N/M approach.
    5. Final Combination: The file identifier and class number are combined (e.g., a-a) to ensure uniqueness across different files.
  7. Understand numeric style scaling in Devup UI

    main

    Devup UI uses a scaling system for numeric style properties where a value of n is automatically converted to n * 4px.

    Example:

    • h={25} results in height: 100px (25 * 4).
    • w={2} results in width: 8px (2 * 4).

    Exceptions: The following properties are not multiplied by 4 and will use the literal numeric value provided:

    • opacity
    • flex
    • z-index
    • line-clamp / -webkit-line-clamp
    • font-weight
    • line-height
    • scale
    • aspect-ratio
    • flex-grow
    • flex-shrink
    • order
    • grid-column, grid-column-start, grid-column-end
    • grid-row, grid-row-start, grid-row-end
    • animation-iteration-count
    • tab-size, moz-tab-size