Otter 样式词典
此软件包是 Otter 框架模块。 。 。 .
说明
这个软件包暴露了一组 钩子 财务报告和审定财务报表 模块 联 合 国 样式词典 提高Tokens设计的能力.
开始
准备你的 样式词典 感谢命令:
ng add @ama-styling/style-dictionary
默认情况下, 命令会进行以下更新 :
- 将 dev 依赖添加到 样式词典包。 。 。 .
- 创建最小值 配置( mjs) cSS和元数据生成所需的配置文件.
- 添加数据
generate:theme财务报告和审定财务报表generate:metadata项目中的脚本 软件包.json。 。 。 .
然后您就可以根据您的项目规格定制此设置 :
- 自定义 样式词典配置 在生成时 配置( mjs) 文档.
- 添加 扩展 通过 增强机制。 。 。 .
- 配置输出文件
getTargetFiles帮助者。 。 。 .
增强
设计托肯扩展
这个 设计托肯斯 格式允许提供 $extensions 属性来增强它应用的托肯.
财产可直接适用于Token:
// colors.token.json
{
"colors": {
"primary": {
"$value": "#000000",
"$extensions": {
"o3rPrivate": true
}
}
}
}
或在一个专用 .extensions.json 文件( 当 ama/json-parser/扩展 解析器已装入 :
// color.token.json
{
"colors": {
"primary": {
"$value": "#000000"
}
}
}
// custom.extensions.json
{
"colors.primary": {
"$description": "Primary private color",
"$extensions": {
"o3rPrivate": true
}
}
}
可用的 Otter 扩展
| 扩展 | 类型 | 说明 | 需要的钩子 |
|---|---|---|---|
| o3r 隐私 | boolean | 确定符号是否标为私有 | 预处理器 : ama/预处理/扩展 主题 : ama/cs/可变 |
| 机会 | boolean | 确定是否在生成时将符号标记为重要 | 预处理器 : ama/预处理/扩展 主题 : ama/cs/可变 |
| o3rScope 选项 | string | 适用于生成变量的范围 | 预处理器 : ama/预处理/扩展 主题 : ama/cs/可变 |
| o3r 元数据 | CMS 元数据 | 生成后应向元数据提供的额外信息 | 预处理器 : ama/预处理/扩展 主题 : ama/json/元数据 |
| o3r 单位 | string | 将指定单位的数值转换为新单位。 它会在未指定单位的"编号"型号符号上添加一个单位. 在复杂类型(如阴影,过渡等)的情况下,该单位会被应用于它们所包含的所有数字类型. | 预处理器 : ama/预处理/扩展 变换 : 地图/转换/单位 |
| o3rRRatio 数据 | number | 适用于上个数值的比率。 该比例将仅适用于"数"类型的符号,或像类型一样适用于"字符串"中确定的第一个数字. 对于复杂类型(如阴影,过渡等),该比率将适用于它们包含的所有数字类型. | 预处理器 : ama/预处理/扩展 变换 : 地图/转换/比例 |
| o3rexpect 覆盖 | boolean | 指出该标志预计将被外部规则所压倒 | 预处理器 : ama/预处理/扩展 |
[尖叫声] 这个 需要的钩子 需要注册到 样式词典配置 以充分支持延期.
模块
解析器
| 名称 | 匹配文件 | 说明 |
|---|---|---|
| ama/json-parser/一行端 | **/*.json | 允许 标记 在 JSON 文件中键入 |
| ama/json-parser/扩展 | **/*.extensions.json | 解析包含的文件 $extensions 在设计托肯顶部应用的指令 |
预处理器
| 名称 | 说明 |
|---|---|
| ama/预处理/扩展 | 添加支持的预处理器 $extensions 脚本中的指令(或专用) extensions.json 存档). 此预处理器对任何Otter钩是强制的. |
变换
| 名称 | 类型 | 标准 | 说明 |
|---|---|---|---|
| 地图/转换/比例 | value | o3rRatio 提供扩展名 | 应用给定 o3rRatio 改为它所指的托肯(s)的数值. |
| 地图/转换/单位 | value | o3rUnit 提供扩展名 | 将它所指的托肯值的单位替换为所提供的 o3rUnit。 。 。 . |
变形组
| 名称 | 说明 |
|---|---|
| ama/cs/建议 | 扩展官员 CSS 变换组 通过添加 ama/transform/ratio 财务报告和审定财务报表 ama/transform/unit |
格式
| 名称 | 选项 | 说明 |
|---|---|---|
| ama/cs/可变 | 见 cs/可变选项 | Render CSS 变量块(基于 内建格式(a) 支持增加 Otter 扩展特性。 。 。 . |
| ama/json/元数据 | 见 cs/可变选项 (适用于 defaultValue(中文(简体) )- 说吧 保持隐私: 包括私有变量 | Render CMS风格元数据(CSS变量及其相关的CMS集成定制属性). |
登记程序
不同的钩/模块可以通过不同的钩/模块单独注册 注册... () 从 StyleDictionary 或全部同时与 register 函数如下:
import { register, baseConfig } from '@ama-styling/style-dictionary';
const sd = new StyleDictionary({
...baseConfig,
// custom configs ...
});
register(sd); // Register all Otter modules
[大 为了能够使用任何所列模块/套接字,它们必须登记在
StyleDefinition举个例子.
[TIP] 帮手
baseConfig将为Otter扩展支持提供最小配置.
帮助者
增强和便利《公约》的配置 StyleDictionary 实例 @ama-styling/style-dictionary 揭露出一批帮手.
获取目标文件
这个 getTargetFiles 函数用于参数化基于 Design Token 生成的文件(遵循与 $extensions:
// Example to generate the `color-primary-**` variables in `my-color-primary.css`
import { getTargetFiles } from '@ama-styling/style-dictionary';
const rule = {
'color.primary': 'my-color-primary.css'
};
// or `const rule = {color: {primary: 'my-color-primary.css'}}`
// or `const rule = {'color.primary': {$extensions: {o3rTargetFile: 'my-color-primary.css'}}}`
// or `const rule = {'color: {primary': {$extensions: {o3rTargetFile: 'my-color-primary.css'}}}}`
const sd = new StyleDictionary({
//...
plateforms: {
css: {
files: [
...getTargetFiles({ rule, { format: 'css', defaultFile: 'default-file.css' } })
]
}
}
});
register(sd); // Register all Otter modules
[注] 这个
format选项将应用到提供给getTargetFiles函数(包括defaultFile) (中文(简体) ).defaultFile定义生成不匹配任何规则的变量的默认文件.
帮助函数 getTargetFiles 正在将过滤器注册到 StyleDictionary 带着独一无二的身份证.
此ID可检索如下:
import { getTargetFiles } from '@ama-styling/style-dictionary';
const sd = new StyleDictionary();
const files = getTargetFiles({ rules, { styleDictionary: sd } });
/**
* Filter IDs registered in {@link sd} Style Dictionary instance
* @type {string[]}
**/
const filterIds = files.map(({ filter }) => filter);
高级
基本节点配置示例
// style-builder.mjs
import { register, getTargetFiles, baseConfiguration } from '@ama-styling/style-dictionary';
import StyleDictionary from 'style-dictionary';
// Rules to generate different CSS files according to Token name
const fileRules = {
colors: 'style/colors.tokens.css',
'components.panel': 'components/panel/panel.tokens.css'
}
const sd = new StyleDictionary({
...baseConfiguration, // Use basic Otter configuration setup
usesDtcg: true, // Use Design Token Standard format
source: ['tokens/*.tokens.json'], // Design Token files
include: ['token.extensions.json'], // Custom extensions
platforms: {
// Generate CSS Files
css: {
options: {
outputReferences: true // to output `--var: var(--other-var)` instead of the value of `--other-var`
},
transformGroup: 'ama/css/recommended',
files: [
...getTargetFiles(fileRules, { format: 'css' }),
// default CSS file where generate variables
{ destination: 'style/default.tokens.css', format: 'css' }
]
},
cms: {
options: {
outputReferences: true
},
transformGroup: 'ama/css/recommended',
files: [
{ destination: 'style.metadata.json', format: 'ama/json/metadata' }
]
}
}
});
// Register otter hooks/modules
register(sd);
if (process.env.CSS_ONLY){
sd.buildPlatform('css');
} else {
sd.buildAllPlatforms();
}
可用以下命令运行 :
node ./style-builder.mjs