|
| 1 | +# 貢献ガイド |
| 2 | + |
| 3 | +`@ant-design/icons-svg` は、Ant Design 公式チームが推奨する SVG ライブラリです。さまざまな UI ライブラリやフレームワークで使用できる抽象ノード(基本的にはプレーンオブジェクト)を提供します。 |
| 4 | + |
| 5 | +## プロジェクト構造 |
| 6 | + |
| 7 | +```bash |
| 8 | +. |
| 9 | +├── ReadMe.md |
| 10 | +├── babel.config.cjs # jestで使用されるbabel設定 |
| 11 | +├── docs |
| 12 | +├── es # TypeScriptコンパイラの出力ディレクトリ(--module esnext) |
| 13 | +├── gulpfile.ts # コアのgulp設定 |
| 14 | +├── inline-svg # 処理されたアイコンが拡張子 ".svg" で出力されるディレクトリ |
| 15 | +├── inline-namespaced-svg # 処理されたアイコンが拡張子 ".svg" で出力され、SVG名前空間(xmlns="http://www.w3.org/2000/svg")を含むディレクトリ |
| 16 | +├── jest.config.cjs |
| 17 | +├── lib # TypeScriptコンパイラの出力ディレクトリ(--module commonjs) |
| 18 | +├── package.json |
| 19 | +├── plugins # カスタムgulpプラグイン |
| 20 | +├── scripts # 一部のカスタムスクリプト |
| 21 | +├── src # ソースディレクトリ。 "src" 内のすべてのファイルはgulpによって生成され、tscによってコンパイルされます |
| 22 | +├── svg # 生のアイコンディレクトリ。ここにアイコンを追加できます。 |
| 23 | +├── tasks/creators # gulpタスクファクトリ関数 |
| 24 | +├── templates # 一部のテンプレート |
| 25 | +├── test |
| 26 | +├── tsconfig.build.json # ビルド時のTypeScript設定 |
| 27 | +├── tsconfig.json # "npm run generate" 実行時のランタイムTypeScript設定 |
| 28 | +├── typings.d.ts |
| 29 | +└── utils |
| 30 | +``` |
| 31 | + |
| 32 | +## 生成ワークフロー |
| 33 | + |
| 34 | +次のコマンドを実行します |
| 35 | + |
| 36 | +```bash |
| 37 | +yarn generate # または `yarn g` |
| 38 | +``` |
| 39 | + |
| 40 | +`gulp` ワークフローを開始します。以下のワークフローを参照してください。 |
| 41 | + |
| 42 | +```txt |
| 43 | +1. 生成されたまたはコンパイルされたファイルをクリーンアップ(削除)します |
| 44 | +2. 次のタスクを並行して実行します: |
| 45 | + 2.1 一部のファイルを "src" ディレクトリにコピーします(例:helpers.ts、types.ts) |
| 46 | + 2.2 "filled" テーマの抽象ノードを生成します |
| 47 | + 2.3 "outlined" テーマの抽象ノードを生成します |
| 48 | + 2.4 "twotone" テーマの抽象ノードを生成します |
| 49 | +3. 次のタスクを並行して実行します: |
| 50 | + 3.1 index.ts を生成します |
| 51 | + 3.2 inline-svg ディレクトリを生成します |
| 52 | + 3.3 inline-namespaced-svg ディレクトリを生成します |
| 53 | +``` |
| 54 | + |
| 55 | +## ビルドワークフロー |
| 56 | + |
| 57 | +次のコマンドを実行します |
| 58 | + |
| 59 | +```bash |
| 60 | +yarn build |
| 61 | +``` |
| 62 | + |
| 63 | +`tsc` を使用してファイルを "src" から `es`、`lib` ディレクトリにコンパイルします。 |
| 64 | + |
| 65 | +## アイコンの追加/変更/削除方法 |
| 66 | + |
| 67 | +### アイコンの追加方法 |
| 68 | + |
| 69 | +アイコンが次のルールに従っていることを確認してください: |
| 70 | + |
| 71 | +1. アイコンは [Ant Design 公式ライブラリサイト](https://www.iconfont.cn/collections/detail?spm=a313x.7781069.1998910419.d9df05512&cid=9402) から取得するか、コミュニティから要求され、[Ant Design アイコンデザインルール](https://ant.design/docs/spec/icon) に適合している必要があります。 |
| 72 | + |
| 73 | +2. アイコンには `viewBox` 属性があり、その値は `0 0 1024 1024` である必要があります。 |
| 74 | + |
| 75 | +3. アイコンには `64px` の余白が必要です。 |
| 76 | + |
| 77 | +アイコンを `svg` ディレクトリ内のテーマ固有のフォルダ(`filled`、`outlined`、`twotone` のいずれか)に追加します。 |
| 78 | + |
| 79 | +ワークフローコマンドを実行します。 |
| 80 | + |
| 81 | +```bash |
| 82 | +# ".ts" ファイルを "src" ディレクトリに生成します |
| 83 | +yarn generate |
| 84 | + |
| 85 | +# "src" ディレクトリ内のファイルをコンパイルします |
| 86 | +yarn build |
| 87 | +``` |
| 88 | + |
| 89 | +### アイコンの変更/削除方法 |
| 90 | + |
| 91 | +`svg` ディレクトリ内のアイコンを変更/削除し、ワークフローコマンドを実行します。 |
| 92 | + |
| 93 | +## gulpタスク |
| 94 | + |
| 95 | +### アイコン生成タスク |
| 96 | + |
| 97 | +```ts |
| 98 | +generateIcons(options: GenerateIconsOptions): () => NodeJS.ReadWriteStream |
| 99 | +``` |
| 100 | + |
| 101 | +このタスクは、特定のディレクトリ内のすべての `.svg` ファイルを `svgo` を使用して圧縮し、抽象ノードに変換します。 |
| 102 | + |
| 103 | +`GenerateIconsOptions`: |
| 104 | + |
| 105 | +```ts |
| 106 | +// gulpfile.ts |
| 107 | + |
| 108 | +generateIcons({ |
| 109 | + // アイコンテーマを設定します |
| 110 | + theme: 'filled', |
| 111 | + |
| 112 | + // ソース |
| 113 | + from: ['svg/filled/*.svg'], |
| 114 | + |
| 115 | + // 出力ディレクトリ |
| 116 | + toDir: 'src/asn', |
| 117 | + |
| 118 | + // プラグインSVGOの設定 |
| 119 | + svgoConfig: generalConfig, |
| 120 | + |
| 121 | + // 変換関数のコレクション。詳細は以下を参照してください |
| 122 | + extraNodeTransformFactories: [ |
| 123 | + assignAttrsAtTag('svg', { focusable: 'false' }), |
| 124 | + adjustViewBox |
| 125 | + ], |
| 126 | + |
| 127 | + // テンプレートを適用する前の抽象ノードのシリアル化操作。詳細は以下を参照してください |
| 128 | + stringify: JSON.stringify, |
| 129 | + |
| 130 | + // テンプレート |
| 131 | + template: iconTemplate, |
| 132 | + |
| 133 | + // テンプレート内の補間マッピング |
| 134 | + mapToInterpolate: ({ name, content }) => ({ |
| 135 | + identifier: getIdentifier({ name, themeSuffix: 'Filled' }), |
| 136 | + content |
| 137 | + }), |
| 138 | + |
| 139 | + // 出力ファイル名 |
| 140 | + filename: ({ name }) => getIdentifier({ name, themeSuffix: 'Filled' }) |
| 141 | +}); |
| 142 | +``` |
| 143 | + |
| 144 | +#### extraNodeTransformFactories |
| 145 | + |
| 146 | +これは、各抽象ノードを処理する関数を含む配列です。 |
| 147 | + |
| 148 | +```ts |
| 149 | +interface TransformFactory { |
| 150 | + (options: TransformOptions): (asn: AbstractNode) => AbstractNode; |
| 151 | +} |
| 152 | + |
| 153 | +type TransformOptions = { |
| 154 | + name: string; |
| 155 | + theme: ThemeType; |
| 156 | +}; |
| 157 | + |
| 158 | +interface AbstractNode { |
| 159 | + tag: string; |
| 160 | + attrs: { |
| 161 | + [key: string]: string; |
| 162 | + }; |
| 163 | + children?: AbstractNode[]; |
| 164 | +} |
| 165 | +``` |
| 166 | + |
| 167 | +現在の `gulpfile.ts` の設定は次のとおりです。 |
| 168 | + |
| 169 | +```ts |
| 170 | +extraNodeTransformFactories: [ |
| 171 | + assignAttrsAtTag('svg', { focusable: 'false' }), |
| 172 | + adjustViewBox |
| 173 | +] |
| 174 | +``` |
| 175 | + |
| 176 | +`assignAttrsAtTag('svg', { focusable: 'false' })` |
| 177 | + |
| 178 | +各 `svg` ノード(`svg` XMLタグ)に対して、キーと値のペアを属性に割り当てます。例:`focusable="false"` |
| 179 | + |
| 180 | +`adjustViewBox` |
| 181 | + |
| 182 | +これは、アイコンのビュー ボックスを調整し、余白領域を削除します。 (`viewBox="64 64 896 896"`) |
| 183 | + |
| 184 | +```ts |
| 185 | +const adjustViewBox: TransformFactory = assignAttrsAtTag('svg', ({ name }) => ({ |
| 186 | + viewBox: includes(name, OLD_ICON_NAMES) ? '0 0 1024 1024' : '64 64 896 896' |
| 187 | +})); |
| 188 | +``` |
| 189 | + |
| 190 | +`assignAttrsAtTag` は、ノードに追加の属性を追加するのに役立つヘルプ関数であることに注意してください。 |
| 191 | + |
| 192 | +```ts |
| 193 | +function assignAttrsAtTag( |
| 194 | + tag: string, |
| 195 | + extraPropsOrFn: |
| 196 | + | Dictionary |
| 197 | + | (( |
| 198 | + options: TransformOptions & { previousAttrs: Dictionary } |
| 199 | + ) => Dictionary) |
| 200 | +): TransformFactory; |
| 201 | + |
| 202 | +type Dictionary = Record<string, string>; |
| 203 | +``` |
| 204 | + |
| 205 | +#### 例:すべての `path` タグに `hello="world"` を追加 |
| 206 | + |
| 207 | +```ts |
| 208 | +extraNodeTransformFactories: [ |
| 209 | + assignAttrsAtTag('path', { hello: 'world'}) |
| 210 | +] |
| 211 | +``` |
| 212 | + |
| 213 | +結果は次のとおりです |
| 214 | + |
| 215 | +```ts |
| 216 | +// src/asn/AccountBookFilled.ts |
| 217 | + |
| 218 | +const AccountBookFilled: IconDefinition = { |
| 219 | + icon: { |
| 220 | + tag: 'svg', |
| 221 | + attrs: { viewBox: '0 0 1024 1024' }, |
| 222 | + children: [ |
| 223 | + { |
| 224 | + tag: 'path', |
| 225 | + attrs: { |
| 226 | + d: |
| 227 | + 'M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zM648.3 426.8l-87.7 161.1h45.7c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4v29.7h63.4c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4V752c0 5.5-4.5 10-10 10h-41.3c-5.5 0-10-4.5-10-10v-51.8h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h63.1v-29.7h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h45.2l-88-161.1c-2.6-4.8-.9-10.9 4-13.6 1.5-.8 3.1-1.2 4.8-1.2h46c3.8 0 7.2 2.1 8.9 5.5l72.9 144.3 73.2-144.3a10 10 0 018.9-5.5h45c5.5 0 10 4.5 10 10 .1 1.7-.3 3.3-1.1 4.8z', |
| 228 | + hello: 'world' |
| 229 | + } |
| 230 | + } |
| 231 | + ] |
| 232 | + }, |
| 233 | + name: 'account-book', |
| 234 | + theme: 'filled' |
| 235 | +}; |
| 236 | +``` |
| 237 | + |
| 238 | +#### 例: テーマ、名前、さらにはアイコンの以前の属性にアクセスする |
| 239 | + |
| 240 | +```ts |
| 241 | +extraNodeTransformFactories: [ |
| 242 | + assignAttrsAtTag('path', ({ name, theme, previousAttrs }) => ({ |
| 243 | + hello: `${name}-${theme}-${previousAttrs.d}` |
| 244 | + })) |
| 245 | +] |
| 246 | +``` |
| 247 | + |
| 248 | +結果は次のとおりです |
| 249 | + |
| 250 | +```ts |
| 251 | +// src/asn/AccountBookFilled.ts |
| 252 | + |
| 253 | +const AccountBookFilled: IconDefinition = { |
| 254 | + icon: { |
| 255 | + tag: 'svg', |
| 256 | + attrs: { viewBox: '0 0 1024 1024' }, |
| 257 | + children: [ |
| 258 | + { |
| 259 | + tag: 'path', |
| 260 | + attrs: { |
| 261 | + d: |
| 262 | + 'M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zM648.3 426.8l-87.7 161.1h45.7c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4v29.7h63.4c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4V752c0 5.5-4.5 10-10 10h-41.3c-5.5 0-10-4.5-10-10v-51.8h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h63.1v-29.7h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h45.2l-88-161.1c-2.6-4.8-.9-10.9 4-13.6 1.5-.8 3.1-1.2 4.8-1.2h46c3.8 0 7.2 2.1 8.9 5.5l72.9 144.3 73.2-144.3a10 10 0 018.9-5.5h45c5.5 0 10 4.5 10 10 .1 1.7-.3 3.3-1.1 4.8z', |
| 263 | + hello: |
| 264 | + 'account-book-filled-M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zM648.3 426.8l-87.7 161.1h45.7c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4v29.7h63.4c5.5 0 10 4.5 10 10v21.3c0 5.5-4.5 10-10 10h-63.4V752c0 5.5-4.5 10-10 10h-41.3c-5.5 0-10-4.5-10-10v-51.8h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h63.1v-29.7h-63.1c-5.5 0-10-4.5-10-10v-21.3c0-5.5 4.5-10 10-10h45.2l-88-161.1c-2.6-4.8-.9-10.9 4-13.6 1.5-.8 3.1-1.2 4.8-1.2h46c3.8 0 7.2 2.1 8.9 5.5l72.9 144.3 73.2-144.3a10 10 0 018.9-5.5h45c5.5 0 10 4.5 10 10 .1 1.7-.3 3.3-1.1 4.8z' |
| 265 | + } |
| 266 | + } |
| 267 | + ] |
| 268 | + }, |
| 269 | + name: 'account-book', |
| 270 | + theme: 'filled' |
| 271 | +}; |
| 272 | +``` |
0 commit comments