@tola/icon
在 HTML 中内联渲染已配置的 SVG 图标,或将其发布为独立 SVG 资源。
导入
#import "@tola/icon:0.0.0": *SVG 的 fill 或 stroke 使用 currentColor 时,内联图标会自动跟随所在位置的文字颜色;显式颜色保持不变。
导出成员
icon
let icon(
id: string,
attrs: dictionary = (:),
label: none | string = none,
module: none | string = none,
) = content;将已配置图标以 1em 高的内联 SVG 插入 HTML 文档。
调用时立即校验 id。仅适用于 HTML 文档;PDF 等格式请用 icon-bytes 或 icon-url。
位置参数
idstring必填:区分大小写的"namespace:name"图标标识,来自[icons.collections]。
命名参数
modulenone | string默认值:none:拥有该图标集合的可选模块别名;省略时使用站点集合。labelnone | string默认值:none:供屏幕阅读器读取的非空名称;省略或传none时标记为装饰性图标(aria-hidden="true")。attrsdictionary默认值:(:):添加到根<svg>的字符串属性字典(例如(class: "brand",))。class与style会追加;无障碍属性(aria-label、aria-labelledby、aria-hidden、role、focusable)由label统一控制,不可写在attrs中。
插入装饰性图标与带无障碍标签的图标
#import "@tola/icon:0.0.0": icon
#document("index.html")[
#icon("brand:mark")
#icon("brand:mark", label: "站点标志", attrs: (class: "brand",))
]icon-bytes
let icon-bytes(
id: str,
module: str | none = none,
) = bytes;返回图标的原始 SVG 字节,供 Typst image(...) 或自定义 asset(...) 发布。
位置参数
idstr必填:区分大小写的"namespace:name"图标标识。
命名参数
modulestr | none默认值:none:拥有该图标集合的可选模块别名;省略时使用站点集合。
icon-url
let icon-url(
id: str,
module: str | none = none,
) = str;将图标发布为独立 SVG 文件并返回带 site.base-path 的浏览器 URL。
仅发布求值过程中实际引用到的图标。
位置参数
idstr必填:区分大小写的"namespace:name"图标标识。
命名参数
modulestr | none默认值:none:拥有该图标集合的可选模块别名;省略时使用站点集合。
通过 `<img>` 加载已发布的 SVG 图标
#import "@tola/icon:0.0.0": icon-url
#document("index.html")[
#html.img(src: icon-url("brand:mark"), alt: "站点标志")
]