@nasp/icons
Version:
Universal design and icon system for NASP Asset Studio, with NaspScript language support.
68 lines (56 loc) • 1.83 kB
Markdown
# NASP Design Kit API Reference
## NASPIconLibrary
### Methods
#### `async init(path = 'icons.json')`
- Loads icon data from a JSON file.
- **Parameters:**
- `path` (string): Path to the icons JSON file (default: 'icons.json').
- **Returns:** Promise<void>
- **Usage:**
```js
await NASPIconLibrary.init();
```
#### `getIconSVG(name)`
- Returns the raw SVG string for a given icon key.
- **Parameters:**
- `name` (string): The icon key (e.g., 'Search').
- **Returns:** string | null
- **Usage:**
```js
const svg = NASPIconLibrary.getIconSVG('Search');
```
#### `createIcon(name, props = {})`
- Returns a styled SVG string for a given icon and properties.
- **Parameters:**
- `name` (string): The icon key.
- `props` (object):
- `size` (number): Width/height in px
- `color` (string): Stroke color (e.g., '#5865f2')
- `class` (string): CSS class
- **Returns:** string (SVG markup)
- **Usage:**
```js
const svg = NASPIconLibrary.createIcon('Search', { size: 32, color: '#5865f2' });
```
#### `async parse()`
- Finds all `<nasp-icon>` tags in the DOM and replaces them with SVGs (browser only).
- **Returns:** Promise<void>
- **Usage:**
```js
await NASPIconLibrary.parse();
```
---
## NaspScript
### Methods
#### `parse(script, { renderIcon })`
- Parses a NaspScript string and returns HTML.
- **Parameters:**
- `script` (string): NaspScript code
- `renderIcon` (function): Function to render an icon (e.g., NASPIconLibrary.createIcon)
- **Returns:** string (HTML)
- **Usage:**
```js
const html = NaspScript.parse('icon "Search" size 32 color #5865f2', { renderIcon: NASPIconLibrary.createIcon });
```
---
For more, see [Getting Started](getting-started.md) and [NaspScript Language Guide](NaspScript.md).