colors


目录

title: Changing colors in SVG
types:
  SVG: '../svg/index.md'
  IconSet: '../icon-set/index.md'
  Color: '../../utils/color.md'
functions:
  stringToColor: '../../utils/string-to-color.md'
  colorToString: '../../utils/color-to-string.md'

Parsing colors in SVG

This function is part of icon manipulation functions in Iconify Tools.

Function [func]parseColors() parses colors in SVG.

It can:

Function parses colors in:

Function does not parse colors in:

Usage

Function has the following parameters:

Function returns array of colors.

Colors

Colors used in callback and returned by function can be two types:

Options

The [prop]options object has the following properties:

Default color

Some icons use system color. Example:

<svg viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" width="1200" height="400">
    <path d="M300 200H150A150 150 0 10300 50z"/>
</svg>

In that icon path uses default fill. In Iconify all icons should use colors set by [prop]color attribute, which means shapes should use [str]currentColor for fill.

If you set [prop]defaultColor option, parser will automatically set color for shapes that use default color.

Example:

src: libraries/tools/icon/color-default.ts
title: 'default-color.ts'
extra:
  - src: libraries/tools/icon/color-default.svg
    title: 'Result:'

Replacing colors

With [prop]callback option you can replace colors.

Callback has the following parameters:

Callback should return:

Example

src: libraries/tools/icon/colors.ts
title: 'example.ts'
extra:
  - src: libraries/tools/icon/colors.json
    title: 'Result:'

版本号 #2
由 壳壳虫 创建于 2026-10-31 14:25:48 UTC
由 壳壳虫 更新于 2026-10-31 14:25:49 UTC