Skip to content

Commit 3e4335e

Browse files
committed
refactor: better Gradient interface
1 parent a8a42bf commit 3e4335e

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

src/core/elements.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export const selectors = [
331331
"#hard-solved-progress",
332332
] as const;
333333

334-
export function Gradient(id: string, colors: [string, number][], ratio = 0) {
334+
export function Gradient(id: string, colors: Record<string, string>, ratio = 0) {
335335
return new Item({
336336
type: "linearGradient",
337337
attr: {
@@ -341,8 +341,8 @@ export function Gradient(id: string, colors: [string, number][], ratio = 0) {
341341
x2: Math.round(Math.cos(ratio) * 100) / 100,
342342
y2: Math.round(Math.sin(ratio) * 100) / 100,
343343
},
344-
children: colors.map((color) => {
345-
return new Item({ type: "stop", attr: { offset: color[1], "stop-color": color[0] } });
344+
children: Object.entries(colors).map(([offset, color]) => {
345+
return new Item({ type: "stop", attr: { offset, "stop-color": color } });
346346
}),
347347
});
348348
}

src/core/exts/activity.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ export function ActivityExtension(generator: Generator): Extension {
7272
new Item({
7373
type: "defs",
7474
children: [
75-
Gradient("ext-activity-mask-gradient", [
76-
["#fff", 0],
77-
["#fff", 0.85],
78-
["#000", 1],
79-
]),
75+
Gradient("ext-activity-mask-gradient", {
76+
0: "#fff",
77+
0.85: "#fff",
78+
1: "#000",
79+
}),
8080
new Item({
8181
type: "mask",
8282
attr: { id: "ext-activity-mask" },

src/core/theme/unicorn.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,8 @@ export default Theme({
1212
extends: new Item({
1313
type: "defs",
1414
children: [
15-
Gradient("g-bg", [
16-
["#dbeafe", 0],
17-
["#e0e7ff", 0.5],
18-
["#fae8ff", 1],
19-
]),
20-
Gradient("g-text", [
21-
["#2563eb", 0],
22-
["#4f46e5", 0.5],
23-
["#d946ef", 1],
24-
]),
15+
Gradient("g-bg", { 0: "#dbeafe", 0.5: "#e0e7ff", 1: "#fae8ff" }),
16+
Gradient("g-text", { 0: "#2563eb", 0.5: "#4f46e5", 1: "#d946ef" }),
2517
],
2618
}),
2719
});

0 commit comments

Comments
 (0)