100pah commented on code in PR #20865:
URL: https://github.com/apache/echarts/pull/20865#discussion_r2061397276
##########
src/visual/tokens.ts:
##########
@@ -0,0 +1,116 @@
+const tokens = {
+ color: {
+ theme: [
+ '#5978e3',
+ '#b6d634',
+ '#505372',
+ '#ff994d',
+ '#0ca8df',
+ '#ffd10a',
+ '#fb628b',
+ '#785db0',
+ '#3fbe95'
+ ],
+
+ neutral00: '#fff',
+ neutral05: '#f4f7fd',
+ neutral10: '#e8ebf0',
+ neutral15: '#dbdee4',
+ neutral20: '#cfd2d7',
+ neutral25: '#c3c5cb',
+ neutral30: '#b7b9be',
+ neutral35: '#aaacb2',
+ neutral40: '#9ea0a5',
+ neutral45: '#929399',
+ neutral50: '#86878c',
+ neutral55: '#797b7f',
+ neutral60: '#6d6e73',
+ neutral65: '#616266',
+ neutral70: '#54555a',
+ neutral75: '#48494d',
+ neutral80: '#3c3c41',
+ neutral85: '#303034',
+ neutral90: '#232328',
+ neutral95: '#17171b',
+ neutral99: '#000',
+
+ accent05: '#eef2fc',
+ accent10: '#dee4f9',
+ accent15: '#cdd7f7',
+ accent20: '#bdc9f4',
+ accent25: '#acbcf1',
+ accent30: '#9baeee',
+ accent35: '#8ba1eb',
+ accent40: '#7a93e9',
+ accent45: '#6a86e6',
+ accent50: '#5978e3',
+ accent55: '#506ccc',
+ accent60: '#4760b6',
+ accent65: '#3e549f',
+ accent70: '#354888',
+ accent75: '#2d3c72',
+ accent80: '#24305b',
+ accent85: '#1b2444',
+ accent90: '#12182d',
+ accent95: '#090c17',
+
+ transparent: 'rgba(0,0,0,0)',
+
+ primary: '@neutral80',
+ secondary: '@neutral70',
+ tertiary: '@neutral60',
+ quaternary: '@neutral50',
+ disabled: '@neutral20',
+
+ border: '@neutral30',
+ borderTint: '@neutral20',
+ borderShade: '@neutral40',
+
+ background: '@neutral05',
+ backgroundTint: 'rgba(234,237,245,0.5)',
+ backgroundTransparent: 'rgba(255,255,255,0)',
+ backgroundShade: '@neutral10',
+
+ shadow: 'rgba(0,0,0,0.2)',
+ shadowTint: 'rgba(129,130,136,0.2)',
+
+ axisLine: '@neutral70',
+ axisLineTint: '@neutral40',
+ axisTick: '@axisLine',
+ axisTickMinor: '@neutral60',
+ axisLabel: '@axisLine',
+ axisSplitLine: '@neutral15',
+ axisMinorSplitLine: '@neutral05'
+ },
+ size: {
+ xxs: 2,
+ xs: 5,
+ s: 10,
+ m: 15,
+ l: 20,
+ xl: 30,
+ xxl: 40,
+ xxxl: 50
+ }
+} as const;
+
+function decodeTokens() {
+ const color = tokens.color as {
+ [key: string]: string | readonly string[]
+ };
+ for (const key in color) {
+ if (Object.prototype.hasOwnProperty.call(color, key)) {
+ const value = color[key];
+ if (typeof value === 'string' && value.startsWith('@')) {
+ const refKey = value.slice(1);
+ if (refKey in color) {
+ color[key] = color[refKey];
+ }
+ }
+ }
+ }
+}
Review Comment:
I think this decodeToken and "@" grammar is not correct enough as a common
util; and not necessary as local function.
### Not correct enough as a common util
The current implementation requires the token declaration to be
order-dependent, that is, if declared as
```
{
some: '@some2',
some2: '#abc'
}
```
The result will be wrong.
This is not intuitive as a declarative DSL.
Additionally, the code is not necessary to use `Object.prototype` and prefer
not to use `startWith` since there is no shim.
A order-independent impl may be like (but **I do not recommend introducing
any of these implementation**):
```ts
// But still NO dead loop checker and no array/object deep visit impl yet.
function decodeTokens() {
const stack: string[] = [];
each(tokens.color, (value, key) => {
while (isString(value) && value.indexOf('@') === 0) {
stack.push(key);
key = value.slice(1);
value = tokens.color[key];
}
while (stack.length) {
tokens.color[stack.pop()] = value;
}
});
}
```
### Not necessary as a local impl
It can be simply implemented without "@" grammar:
```
import { extend } from 'zrender/src/core/util';
const tokens = {};
const color = tokens.color = {
theme: [
'#5978e3',
'#b6d634',
'#505372',
'#ff994d',
'#0ca8df',
'#ffd10a',
'#fb628b',
'#785db0',
'#3fbe95'
],
neutral00: '#fff',
neutral05: '#f4f7fd',
neutral10: '#e8ebf0',
neutral15: '#dbdee4',
neutral20: '#cfd2d7',
neutral25: '#c3c5cb',
neutral30: '#b7b9be',
neutral35: '#aaacb2',
neutral40: '#9ea0a5',
neutral45: '#929399',
neutral50: '#86878c',
neutral55: '#797b7f',
neutral60: '#6d6e73',
neutral65: '#616266',
neutral70: '#54555a',
neutral75: '#48494d',
neutral80: '#3c3c41',
neutral85: '#303034',
neutral90: '#232328',
neutral95: '#17171b',
neutral99: '#000',
accent05: '#eef2fc',
accent10: '#dee4f9',
accent15: '#cdd7f7',
accent20: '#bdc9f4',
accent25: '#acbcf1',
accent30: '#9baeee',
accent35: '#8ba1eb',
accent40: '#7a93e9',
accent45: '#6a86e6',
accent50: '#5978e3',
accent55: '#506ccc',
accent60: '#4760b6',
accent65: '#3e549f',
accent70: '#354888',
accent75: '#2d3c72',
accent80: '#24305b',
accent85: '#1b2444',
accent90: '#12182d',
accent95: '#090c17',
transparent: 'rgba(0,0,0,0)',
};
extend(color, {
primary: color.neutral80,
secondary: color.neutral70,
tertiary: color.neutral60,
quaternary: color.neutral50,
disabled: color.neutral20,
border: color.neutral30,
borderTint: color.neutral20,
borderShade: color.neutral40,
background: color.neutral05,
backgroundTint: 'rgba(234,237,245,0.5)',
backgroundTransparent: 'rgba(255,255,255,0)',
backgroundShade: color.neutral10,
shadow: 'rgba(0,0,0,0.2)',
shadowTint: 'rgba(129,130,136,0.2)',
axisLine: color.neutral70,
axisLineTint: color.neutral40,
axisTick: color.neutral70,
axisTickMinor: color.neutral60,
axisLabel: color.neutral70,
axisSplitLine: color.neutral15,
axisMinorSplitLine: color.neutral05,
});
tokens.size = {
xxs: 2,
xs: 5,
s: 10,
m: 15,
l: 20,
xl: 30,
xxl: 40,
xxxl: 50
};
```
I recommend the latter way; do not introduce the complexity.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]