API Reference
Complete reference for all Assets AI components, hooks, and utilities.
Components
Icon
Render icons with AI-powered descriptions or static files.
import { Icon } from 'assets-ai';
<Icon
description="home"
variant="regular"
size={24}
color="#000"
className="icon"
style={{ cursor: 'pointer' }}
fallback={true}
alt="Home icon"
/>
Props:
Name | Type | Default | Description |
---|---|---|---|
description | string | - | AI prompt for generating the icon (required if name not provided) |
name | string | - | Static icon filename, bypasses AI (required if description not provided) |
variant | "regular" | "bold" | "light" | "broken" | "two-tone" | "outline" | "regular" | Icon style variant |
size | number | string | 24 | Icon size in pixels |
color | string | - | Icon color (any valid CSS color) |
className | string | "" | Additional CSS classes |
style | CSSProperties | - | Inline styles object |
fallback | boolean | ReactNode | - | Skeleton loader or custom fallback component |
alt | string | - | Alternative text for accessibility |
Image
Render images with AI-powered descriptions or static files.
import { Image } from 'assets-ai';
<Image
description="sunset over mountains"
width={800}
height={600}
alt="Beautiful sunset"
className="image"
fallback={true}
/>
Props:
Name | Type | Default | Description |
---|---|---|---|
description | string | - | AI prompt for generating the image (required if name not provided) |
name | string | - | Static image filename, bypasses AI (required if description not provided) |
width | number | string | - | Image width in pixels or CSS value |
height | number | string | - | Image height in pixels or CSS value |
alt | string | - | Alternative text (required for accessibility) |
className | string | "" | Additional CSS classes |
fallback | boolean | ReactNode | - | Skeleton loader or custom fallback component |
Video
Render videos with AI-powered descriptions or static files.
import { Video } from 'assets-ai';
<Video
description="ocean waves"
width={1280}
height={720}
controls
autoPlay={false}
loop={false}
muted={false}
className="video"
fallback={true}
/>
Props:
Name | Type | Default | Description |
---|---|---|---|
description | string | - | AI prompt for generating the video (required if name not provided) |
name | string | - | Static video filename, bypasses AI (required if description not provided) |
width | number | string | - | Video width in pixels or CSS value |
height | number | string | - | Video height in pixels or CSS value |
controls | boolean | true | Show video controls |
autoPlay | boolean | false | Auto-play video on load |
loop | boolean | false | Loop video playback |
muted | boolean | false | Mute audio by default |
className | string | "" | Additional CSS classes |
fallback | boolean | ReactNode | - | Skeleton loader or custom fallback component |
Skeleton
Loading placeholder component (used internally by fallback).
import { Skeleton } from 'assets-ai';
<Skeleton
type="icon"
size={24}
className="skeleton"
alt="Loading icon"
/>
Props:
Name | Type | Default | Description |
---|---|---|---|
type | "icon" | "image" | "video" | - | Type of skeleton (required) |
width | number | string | - | Skeleton width |
height | number | string | - | Skeleton height |
size | number | string | - | Size for icon type |
className | string | "" | Additional CSS classes |
alt | string | - | Alternative text |
MediaProvider
Context provider for managing media state.
import { MediaProvider } from 'assets-ai';
<MediaProvider
batchDelay={500}
maxCacheSize={2 * 1024 * 1024}
>
{children}
</MediaProvider>
Props:
Name | Type | Default | Description |
---|---|---|---|
children | ReactNode | - | Application components (required) |
batchDelay | number | 500 | Milliseconds to wait before batching requests |
maxCacheSize | number | 1048576 | Maximum cache size in bytes (1MB default) |
Hooks
useMediaContext
Access the media context in your components.
import { useMediaContext } from 'assets-ai';
function MyComponent() {
const { mediaMap, registerMedia, isItemLoading, getStaticUrl } = useMediaContext();
// Use context values...
}
Returns:
Name | Type | Description |
---|---|---|
mediaMap | MediaMap | Object mapping media keys to URLs |
registerMedia | (type, description, variant?) => void | Register a media request |
isItemLoading | (type, description, variant?) => boolean | Check if media is loading |
getStaticUrl | (type, name) => string | Get static CDN URL |
Example:
function CustomMediaComponent() {
const { mediaMap, registerMedia, isItemLoading } = useMediaContext();
useEffect(() => {
registerMedia("icon", "custom icon", "regular");
}, [registerMedia]);
const url = mediaMap["icon:custom icon:regular"];
const loading = isItemLoading("icon", "custom icon", "regular");
if (loading) return <div>Loading...</div>;
if (url) return <img src={url} alt="Custom icon" />;
return null;
}
Functions
configureMedia
Configure global media settings.
import { configureMedia } from 'assets-ai';
configureMedia({
apiEndpoint: "https://api.oblien.com/icons/fetch",
apiToken: process.env.NEXT_PUBLIC_OBLIEN_TOKEN,
manifestUrl: "/media-manifest.json",
maxCacheSize: 2 * 1024 * 1024,
staticBaseUrls: {
icon: "https://cdn.oblien.com/icons/",
image: "https://cdn.oblien.com/images/",
video: "https://cdn.oblien.com/videos/",
},
});
Parameters:
Name | Type | Default | Description |
---|---|---|---|
apiEndpoint | string | "https://api.oblien.com/icons/fetch" | API endpoint for fetching media |
apiToken | string | "" | Authentication token |
manifestUrl | string | "/media-manifest.json" | Production manifest URL |
maxCacheSize | number | 1048576 | Max cache size in bytes |
staticBaseUrls | object | Oblien CDN URLs | Base URLs for static assets |
clearMediaCache
Clear all cached media URLs from localStorage.
import { clearMediaCache } from 'assets-ai';
function Settings() {
const handleClear = () => {
clearMediaCache();
console.log('Cache cleared!');
};
return <button onClick={handleClear}>Clear Cache</button>;
}
Parameters: None
Returns: void
Types
MediaType
Type of media asset.
type MediaType = "icon" | "image" | "video";
MediaMap
Object mapping media keys to URLs.
type MediaMap = Record<string, string>;
// Example:
const mediaMap: MediaMap = {
"icon:home:regular": "https://cdn.oblien.com/icons/home-regular.svg",
"image:sunset": "https://cdn.oblien.com/images/sunset.jpg",
"video:demo": "https://cdn.oblien.com/videos/demo.mp4",
};
MediaRequest
Media request object structure.
interface MediaRequest {
type: MediaType;
description: string;
variant?: "regular" | "bold" | "light" | "broken" | "two-tone" | "outline";
}
// Example:
const request: MediaRequest = {
type: "icon",
description: "home",
variant: "regular"
};
MediaConfig
Configuration object structure.
interface MediaConfig {
apiEndpoint: string;
apiToken: string;
manifestUrl?: string;
maxCacheSize: number;
staticBaseUrls?: {
icon?: string;
image?: string;
video?: string;
};
}
Environment Variables
NEXT_PUBLIC_OBLIEN_TOKEN
Your Oblien API token for authentication.
NEXT_PUBLIC_OBLIEN_TOKEN=your_token_here
Usage:
configureMedia({
apiToken: process.env.NEXT_PUBLIC_OBLIEN_TOKEN,
});
Cache Keys
Media URLs are stored in localStorage with generated keys:
Format: {type}:{description}:{variant}
Examples:
icon:home:regular
icon:search:bold
image:sunset over mountains:undefined
video:ocean waves:undefined
Storage Key: oblien_media_cache
// Access cache directly
const cache = localStorage.getItem('oblien_media_cache');
const data = JSON.parse(cache || '{}');
console.log(data);
Error Handling
Components handle errors gracefully:
// Missing API token - warnings in console
<Icon description="home" />
// Console: "[Media] API request failed"
// Invalid description - shows fallback
<Icon description="" fallback={<div>Error</div>} />
// Network error - shows fallback or empty space
<Image description="sunset" fallback={true} />
Performance Considerations
Batching
Multiple media requests within the batchDelay
window are automatically batched:
// These 3 requests will be batched together
<Icon description="home" />
<Icon description="search" />
<Icon description="settings" />
// Single API request: POST /fetch with 3 items
Caching
Fetched URLs are cached in localStorage:
// First render - API request
<Icon description="home" />
// Subsequent renders - instant from cache
<Icon description="home" />
Production Manifest
In production, skip runtime requests by using a manifest:
{
"icon:home:regular": "https://cdn.oblien.com/icons/home-regular.svg",
"icon:search:regular": "https://cdn.oblien.com/icons/search-regular.svg"
}
Browser Support
Assets AI supports all modern browsers:
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
Requirements:
- React 18+ or 19+
- localStorage support
- ES6+ JavaScript
TypeScript
Full TypeScript support included:
import type {
MediaType,
MediaMap,
MediaRequest,
MediaContextType
} from 'assets-ai';
const type: MediaType = "icon";
const map: MediaMap = {};
const request: MediaRequest = {
type: "icon",
description: "home",
variant: "regular"
};