Skip to content

Commit 79a6e5e

Browse files
committed
feat: initial commit
1 parent 5e3fb7b commit 79a6e5e

File tree

152 files changed

+12393
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+12393
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Directory for instrumented libs generated by jscoverage/JSCover
12+
lib-cov
13+
14+
# Coverage directory used by tools like istanbul
15+
coverage
16+
17+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18+
.grunt
19+
20+
# node-waf configuration
21+
.lock-wscript
22+
23+
# Compiled binary addons (http://nodejs.org/api/addons.html)
24+
build/Release
25+
26+
# Dependency directory
27+
node_modules
28+
29+
# Optional npm cache directory
30+
.npm
31+
32+
# Optional REPL history
33+
.node_repl_history
34+
35+
# Others
36+
.DS_Store
37+
38+
# Assets
39+
assets

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false
4+
}

build/normalize.js

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import fs from 'fs'
2+
import path from 'path'
3+
import mkdirp from 'mkdirp'
4+
import rimraf from 'rimraf'
5+
import svgson, { stringify } from 'svgson'
6+
import Svgo from 'svgo'
7+
const svgo = new Svgo({
8+
multipass: true,
9+
removeViewBox: false,
10+
floatPrecision: 2
11+
})
12+
13+
let icons = 0
14+
const RAW_DIR = path.resolve(__dirname, '../raw/')
15+
const SVG_DIR = path.resolve(__dirname, '../svg/')
16+
const ICON_PATTERN = /^(.+)\.svg$/
17+
18+
rimraf.sync(SVG_DIR)
19+
mkdirp.sync(SVG_DIR)
20+
21+
Promise.all(
22+
fs.readdirSync(RAW_DIR).map(async file => {
23+
if (!ICON_PATTERN.test(file)) {
24+
return
25+
}
26+
27+
let fileData = fs.readFileSync(path.resolve(RAW_DIR, file), 'utf8')
28+
let { error, data } = await svgo.optimize(fileData)
29+
if (error) {
30+
console.error(file, error)
31+
return
32+
}
33+
34+
let el = await svgson(data)
35+
console.log(`Normalizing ${file}...`)
36+
let { attributes } = el
37+
let { width, height, viewBox } = attributes
38+
if (!(width && height)) {
39+
if (!viewBox) {
40+
console.error(file, `doesn't contain a valid size declaration.`)
41+
console.error(width, height, viewBox)
42+
}
43+
44+
;[, width, height] = (viewBox.match(/0 0 (\d+) (\d+)/) || []).map(size =>
45+
parseInt(size, 10)
46+
)
47+
}
48+
49+
if (!(width && height)) {
50+
console.error(file, `doesn't contain a valid size declaration.`)
51+
console.error(width, height, viewBox)
52+
}
53+
54+
if (!viewBox) {
55+
attributes.viewBox = `0 0 ${width} ${height}`
56+
}
57+
58+
walkElement(el, {
59+
enter (node) {
60+
let { attributes } = node
61+
62+
delete attributes.class
63+
64+
let ctxFill = (getContextAttr(node, 'fill') || '').toLowerCase()
65+
let ctxStroke = (getContextAttr(node, 'stroke') || '').toLowerCase()
66+
let attrFill = (attributes.fill || '').toLowerCase()
67+
let attrStroke = (attributes.stroke || '').toLowerCase()
68+
69+
if (attrFill) {
70+
if (!ctxFill) {
71+
if (attrFill !== 'none') {
72+
attributes.fill = 'currentColor'
73+
console.log(` fill: ${attrFill} -> currentColor`)
74+
}
75+
} else {
76+
if (attrFill === ctxFill) {
77+
delete attributes.fill
78+
console.log(` fill: ${attrFill} -> / (same as context)`)
79+
} else if (attrFill !== 'none') {
80+
attributes.fill = 'currentColor'
81+
console.log(
82+
` fill: ${attrFill} -> currentColor (different from context)`
83+
)
84+
}
85+
}
86+
}
87+
88+
if (attrStroke) {
89+
if (!ctxStroke) {
90+
if (attrStroke !== 'none') {
91+
attributes.stroke = 'currentColor'
92+
console.log(` stroke: ${attrStroke} -> currentColor`)
93+
} else {
94+
delete attributes.stroke
95+
console.log(` stroke: ${attrStroke} -> / (same as default)`)
96+
}
97+
} else {
98+
if (attrStroke && attrStroke === ctxStroke) {
99+
delete attributes.stroke
100+
console.log(` stroke: ${attrStroke} -> / (same as context)`)
101+
} else if (attrStroke !== 'none') {
102+
attributes.stroke = 'currentColor'
103+
console.log(
104+
` stroke: ${attrStroke} -> currentColor (different from context)`
105+
)
106+
}
107+
}
108+
}
109+
}
110+
})
111+
112+
fs.writeFileSync(path.join(SVG_DIR, file), stringify(el), 'utf8')
113+
icons++
114+
})
115+
).then(() => {
116+
console.log(`Normalized ${icons} icons.`)
117+
})
118+
119+
function walkElement (el, { enter, leave }) {
120+
if (typeof enter === 'function') {
121+
enter(el)
122+
}
123+
if (el.children && el.children.length) {
124+
el.children.forEach(child => {
125+
child.parentNode = el
126+
walkElement(child, { enter, leave })
127+
delete child.parentNode
128+
})
129+
}
130+
if (typeof leave === 'function') {
131+
leave(el)
132+
}
133+
}
134+
135+
function getContextAttr (el, attr) {
136+
let node = el.parentNode
137+
while (node) {
138+
if (node.attributes && node.attributes[attr]) {
139+
return node.attributes[attr]
140+
}
141+
142+
node = node.parentNode
143+
}
144+
return null
145+
}

lerna.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"packages": [
3+
"packages/*"
4+
],
5+
"version": "0.0.0"
6+
}

0 commit comments

Comments
 (0)