Skip to content

Instantly share code, notes, and snippets.

@d1y
Last active August 2, 2024 19:24
Show Gist options
  • Save d1y/64b2098dac30be4d47aaac2f1a7d8149 to your computer and use it in GitHub Desktop.
Save d1y/64b2098dac30be4d47aaac2f1a7d8149 to your computer and use it in GitHub Desktop.
let value = `.bg-yellow-gradient {
background-image: linear-gradient(45deg, #f5fe00, #ff6600) !important;
color: $dark-3 !important;
}
.bg-orange-gradient {
background-image: linear-gradient(45deg, #ff9700, #ed1c24) !important;
color: $white !important;
}
.bg-red-gradient {
background-image: linear-gradient(45deg, #f33a41, #ed0586) !important;
color: $white !important;
}
.bg-pink-gradient {
background-image: linear-gradient(45deg, #fea894, #ff1047) !important;
color: $white !important;
}
.bg-mauve-gradient {
background-image: linear-gradient(45deg, #c01f95, #7115cc) !important;
color: $white !important;
}
.bg-purple-gradient {
background-image: linear-gradient(45deg, #9829ea, #5908fb) !important;
color: $white !important;
}
.bg-blue-gradient {
background-image: linear-gradient(45deg, #00b8f9, #0166eb) !important;
color: $white !important;
}
.bg-cyan-gradient {
background-image: linear-gradient(45deg, #06edfe, #48b2fe) !important;
color: $white !important;
}
.bg-green-gradient {
background-image: linear-gradient(45deg, #3ab54a, #8cc63f) !important;
color: $white !important;
}
.bg-olive-gradient {
background-image: linear-gradient(45deg, #90e630, #39d266) !important;
color: $white !important;
}
.bg-grey-gradient {
background-image: linear-gradient(45deg, #9aadb9, #354855) !important;
color: $white !important;
}
.bg-brown-gradient {
background-image: linear-gradient(45deg, #ca6f2e, #cb1413) !important;
color: $white !important;
}`
let output = `class CuLinearGradient {\n`
const ret = value.split("}").map(item=> {
item = item.trim()
if (!item) return false
const [ ,name] = item.match(/bg-(\S+)-gradient/)
const [ a, b ] = item.match(/#(\S+)/g)
const a1 = a.replace(",", "").replace("#","").replace(")", "")
const a2 = b.replace(",", "").replace("#","").replace(")", "")
return { name, a1, a2 }
}).filter(Boolean).map(item=> {
output += ` static const ${item.name} = LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xff${item.a1}),
Color(0xff${item.a2}),
],
);\n`
})
output += `}`
console.log(output)
const x = '' // https://raw.githubusercontent.com/wen-gang/coloruiBeta/7f057208f13162a4bdb9dd00f8f8a1bd6093e88d/app/scss/icon/_coloricon.scss
function camelize(str) {
let arr = str.split('-');
let capital = arr.map((item, index) => index ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase() : item.toLowerCase());
let ret = capital.join("");
return ret
}
/**
* @type {Array<{name: string, value: string}>}
*/
const obj = x.split("\n").map(item => {
let [, name, value] = item.match(/\.cicon-(\S+):before {content: "([\S\d]+)";}/)
name = camelize(name)
return { name, value }
})
let result = ``
result += `/// \`colorui\` 图标库
/// wget -O fonts/iconfont.ttf https://at.alicdn.com/t/font_1656945_d66u4pxvlq6.ttf
library colorui;
import 'package:flutter/widgets.dart';
class CuIcons {
static const String _family = 'cufont';
static const String _pkg = 'colorui';
CuIcons._();
`
obj.forEach(item => {
result += ` static const IconData ${item.name} =\n IconData(0x${item.value}, fontFamily: _family, fontPackage: _pkg);\n`
})
result += `}`
copy(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment