Skip to content

Commit 0e208b5

Browse files
authored
Migrate from Flow to TypeScript (#548)
1 parent 90031bd commit 0e208b5

Some content is hidden

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

99 files changed

+17600
-17659
lines changed

.babelrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"presets": ["next/babel"],
33
"plugins": [
4-
"transform-flow-strip-types",
54
[
65
"styled-components",
76
{

.flowconfig

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/ci-workflow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ jobs:
99
with:
1010
node-version: '22'
1111
- run: yarn
12-
- run: NODE_OPTIONS=--openssl-legacy-provider yarn build
13-
- run: yarn flow
12+
- run: yarn build
13+
- run: yarn type-check

common/animations.js renamed to common/animations.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import styled, { css } from "styled-components";
2-
import { animations } from "@common/constants";
2+
import { animations, spacing } from "@common/constants";
33
import { sif } from "@common/styled";
44

55
const Delay = () => styled.div`
6-
${sif("xl")(css`
7-
animation-delay: 2s;
8-
`)}
9-
${sif("l")(css`
10-
animation-delay: 1s;
11-
`)}
6+
${sif("xl")(css`
7+
animation-delay: 2s;
8+
`)}
9+
${sif("l")(css`
10+
animation-delay: 1s;
11+
`)}
1212
${sif("m")(css`
13-
animation-delay: 0.5s;
14-
`)}
13+
animation-delay: 0.5s;
14+
`)}
1515
${sif("s")(css`
16-
animation-delay: 0.25s;
17-
`)}
16+
animation-delay: 0.25s;
17+
`)}
1818
`;
1919

2020
const FadeIn = () => styled.div`

common/colors.js renamed to common/colors.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
function shadeColor(color, percent, rgb) {
1+
function shadeColor(color: string, percent: number, rgb?: boolean): string {
22
if (color == null) {
33
console.error("Null color is getting passed to darken");
44
}
55
var R = parseInt(color.substring(1, 3), 16);
66
var G = parseInt(color.substring(3, 5), 16);
77
var B = parseInt(color.substring(5, 7), 16);
88

9-
R = parseInt((R * (100 + percent)) / 100);
10-
G = parseInt((G * (100 + percent)) / 100);
11-
B = parseInt((B * (100 + percent)) / 100);
9+
R = Math.floor((R * (100 + percent)) / 100);
10+
G = Math.floor((G * (100 + percent)) / 100);
11+
B = Math.floor((B * (100 + percent)) / 100);
1212

1313
R = R < 255 ? R : 255;
1414
G = G < 255 ? G : 255;
@@ -23,9 +23,13 @@ function shadeColor(color, percent, rgb) {
2323
return "#" + RR + GG + BB;
2424
}
2525

26-
export const darken = (color, percent, rgb) =>
26+
export const darken = (color: string, percent: number, rgb?: boolean): string =>
2727
shadeColor(color, -1 * percent, rgb);
28-
export const lighten = (color, percent, rgb) => shadeColor(color, percent, rgb);
28+
export const lighten = (
29+
color: string,
30+
percent: number,
31+
rgb?: boolean
32+
): string => shadeColor(color, percent, rgb);
2933
let mainColor = "#334865";
3034
let colorTextBase = "#313131"; // Default text color
3135
let primaryColor = "#5764c6";
@@ -60,7 +64,6 @@ export const colors = {
6064
primaryColor,
6165
linkColor,
6266
bgColor,
63-
colorTextBase,
6467
darkPrimaryColor,
6568
lightPrimaryColor,
6669
darkColor,
@@ -81,5 +84,5 @@ export const colors = {
8184
// Meta colors
8285
codeColor,
8386
lightCodeColor,
84-
highlightColor
87+
highlightColor,
8588
};

common/constants.js renamed to common/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ const animations = {
1515
timingAnimation,
1616
timingAnimationDelay,
1717
easing,
18-
transition
18+
transition,
1919
};
2020

2121
const fonts = {
2222
headings: `"Nunito", sans-serif`,
2323
body: `-apple-system, system-ui, BlinkMacSystemFont, "Segoe UI",
24-
Roboto`
24+
Roboto`,
2525
};
2626

2727
const spacing = {
2828
unit,
2929
gutter,
3030
globalWidth,
31-
headerHeight
31+
headerHeight,
3232
};
3333

3434
const effects = {
@@ -63,7 +63,7 @@ const effects = {
6363
colors.mainColor,
6464
25,
6565
true
66-
)}, 0.5)`
66+
)}, 0.5)`,
6767
};
6868

6969
export { spacing, fonts, effects, animations };

common/css-paint-polyfill.js renamed to common/css-paint-polyfill.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
!(function() {
1+
// @ts-nocheck
2+
!(function () {
23
function e(e, t) {
34
var n = new XMLHttpRequest();
4-
(n.onreadystatechange = function() {
5+
(n.onreadystatechange = function () {
56
4 === n.readyState && t(n.responseText);
67
}),
78
n.open("GET", e, !0),
@@ -14,9 +15,9 @@
1415
window.CSS || (window.CSS = {}),
1516
"paintWorklet" in window.CSS ||
1617
t(window.CSS, "paintWorklet", {
17-
get: function() {
18+
get: function () {
1819
return n || (n = new F());
19-
}
20+
},
2021
});
2122
var r = "css-paint-polyfill",
2223
i = document.createElement(r);
@@ -26,7 +27,8 @@
2627
var a = o.sheet,
2728
s = i.style,
2829
l = [],
29-
u = /(paint\(|-moz-element\(#paint-|-webkit-canvas\(paint-|[('"]blob:[^'"#]+#paint=|[('"]data:image\/paint-)/,
30+
u =
31+
/(paint\(|-moz-element\(#paint-|-webkit-canvas\(paint-|[('"]blob:[^'"#]+#paint=|[('"]data:image\/paint-)/,
3032
c = "getCSSCanvasContext" in document,
3133
d = (s.backgroundImage = "-moz-element(#" + r + ")") === s.backgroundImage;
3234
s.cssText = "";
@@ -36,7 +38,7 @@
3638
"function" == typeof Promise
3739
? Promise.prototype.then.bind(Promise.resolve())
3840
: setTimeout,
39-
h = function() {
41+
h = function () {
4042
return window.devicePixelRatio || 1;
4143
},
4244
g = {},
@@ -73,7 +75,7 @@
7375
toRemove: [],
7476
counters: {},
7577
isNew: !1,
76-
sheetId: null
78+
sheetId: null,
7779
},
7880
n = 0;
7981
n < e.length;
@@ -87,7 +89,7 @@
8789
}
8890
for (var i = t.toRemove.length; i--; ) delete m[t.toRemove[i].key];
8991
t.toProcess.length > 0 &&
90-
(function(e) {
92+
(function (e) {
9193
for (var t = document.querySelectorAll(e), n = 0; n < t.length; n++)
9294
N(t[n]);
9395
})(t.toProcess.join(", "));
@@ -175,7 +177,7 @@
175177
function L(e, t, n) {
176178
for (
177179
var r = e.length,
178-
i = function() {
180+
i = function () {
179181
--r || t.apply(null, n || l);
180182
},
181183
o = 0;
@@ -191,7 +193,7 @@
191193
return (
192194
null == n &&
193195
((n = e.$$paintId = ++D),
194-
(function(e) {
196+
(function (e) {
195197
if (!0 === p) return;
196198
if (e.style.ownerElement === e) return;
197199
t(e.style, "ownerElement", { value: e });
@@ -238,9 +240,9 @@
238240
e.$$paintPending = !1;
239241
}
240242
var z = {
241-
get: function(e) {
243+
get: function (e) {
242244
return e in E ? E[e] : (E[e] = k.getPropertyValue(e));
243-
}
245+
},
244246
},
245247
D = 0;
246248
function M(e, t) {
@@ -253,7 +255,7 @@
253255
for (
254256
var s = {
255257
width: parseFloat(z.get("width")),
256-
height: parseFloat(z.get("height"))
258+
height: parseFloat(z.get("height")),
257259
},
258260
l = h(),
259261
u = e.$$paintedProperties,
@@ -264,7 +266,8 @@
264266
for (
265267
var v = r[p],
266268
f = z.get(v),
267-
m = /(,|\b|^)url\((['"]?)((?:-moz-element\(#|-webkit-canvas\()paint-\d+-([^;,]+)\)|(?:data:image\/paint-|blob:[^'"#]+#paint=)([^"';, ]+)[;,].*?)\2\)(,|\b|$)/g,
269+
m =
270+
/(,|\b|^)url\((['"]?)((?:-moz-element\(#|-webkit-canvas\()paint-\d+-([^;,]+)\)|(?:data:image\/paint-|blob:[^'"#]+#paint=)([^"';, ]+)[;,].*?)\2\)(,|\b|$)/g,
268271
y = "",
269272
b = 0,
270273
w = [],
@@ -362,12 +365,12 @@
362365
function B(e, t, n) {
363366
e.setProperty(t, n, "important");
364367
}
365-
var F = function() {
368+
var F = function () {
366369
v(w);
367370
var e = document.createElement("x-a");
368371
document.body.appendChild(e);
369372
var n = !1;
370-
new MutationObserver(function(e) {
373+
new MutationObserver(function (e) {
371374
if (!0 !== n) {
372375
n = !0;
373376
for (var t = 0; t < e.length; t++) {
@@ -381,40 +384,40 @@
381384
}
382385
}).observe(document.body, { childList: !0, attributes: !0, subtree: !0 }),
383386
(e.style.cssText = "color: red;"),
384-
setTimeout(function() {
387+
setTimeout(function () {
385388
if (((p = "$$paintPending" in e), document.body.removeChild(e), !p)) {
386389
var n = Object.getOwnPropertyDescriptor(
387390
CSSStyleDeclaration.prototype,
388391
"cssText"
389392
),
390393
r = n.set;
391-
(n.set = function(e) {
394+
(n.set = function (e) {
392395
return this.ownerElement && N(this.ownerElement), r.call(this, e);
393396
}),
394397
t(CSSStyleDeclaration.prototype, "cssText", n);
395398
}
396399
});
397400
};
398-
F.prototype.addModule = function(n) {
401+
F.prototype.addModule = function (n) {
399402
var r = this;
400-
e(n, function(e) {
403+
e(n, function (e) {
401404
var n = {
402-
registerPaint: function(e, t) {
403-
!(function(e, t, n) {
405+
registerPaint: function (e, t) {
406+
!(function (e, t, n) {
404407
g[e] = {
405408
worklet: n,
406409
Painter: t,
407410
properties: t.inputProperties
408411
? [].slice.call(t.inputProperties)
409412
: [],
410413
bit: 0,
411-
instances: []
414+
instances: [],
412415
};
413416
})(e, t, { context: n, realm: o });
414-
}
417+
},
415418
};
416419
t(n, "devicePixelRatio", { get: h }), (n.self = n);
417-
var o = new function(e, t) {
420+
var o = new (function (e, t) {
418421
var n = document.createElement("iframe");
419422
(n.style.cssText =
420423
"position:absolute; left:0; top:-999px; width:1px; height:1px;"),
@@ -434,7 +437,7 @@
434437
),
435438
i.body.appendChild(l),
436439
(this.exec = r.$hook(e, console));
437-
}(n, i);
440+
})(n, i);
438441
(e = (r.transpile || String)(e)), o.exec(e);
439442
});
440443
};

common/lib/index.js renamed to common/lib/index.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
// @flow
2-
3-
import type { Context } from "next";
1+
import type { GetServerSidePropsContext, NextPageContext } from "next";
2+
import type { Platform } from "../../types/platform";
43

54
import "isomorphic-fetch";
65

7-
const EXTENSIONS = {
6+
const EXTENSIONS: Record<Platform, string> = {
87
macOS: ".dmg",
98
Linux: ".AppImage",
10-
Windows: ".exe"
9+
Windows: ".exe",
1110
};
1211

13-
export function detectPlatform(ctx: Context): Platform {
12+
export function detectPlatform(
13+
ctx: GetServerSidePropsContext | NextPageContext
14+
): Platform {
1415
if (ctx.req && ctx.req.headers) {
1516
// Server side
1617
const ua = ctx.req.headers["user-agent"];
17-
if (/Windows/.test(ua)) {
18+
if (ua && /Windows/.test(ua)) {
1819
return "Windows";
19-
} else if (/Linux/.test(ua)) {
20+
} else if (ua && /Linux/.test(ua)) {
2021
return "Linux";
2122
}
2223
// Client side
23-
} else if (navigator.platform) {
24+
} else if (typeof navigator !== "undefined" && navigator.platform) {
2425
if (/Win/.test(navigator.platform)) {
2526
return "Windows";
2627
} else if (/Linux/.test(navigator.platform)) {
@@ -38,7 +39,7 @@ export async function getDownloadUrl(platform: Platform): Promise<string> {
3839
);
3940
const json = await res.json();
4041

41-
const asset = json.assets.find(asset => {
42+
const asset = json.assets.find((asset: any) => {
4243
return asset.browser_download_url.endsWith(EXTENSIONS[platform]);
4344
});
4445

0 commit comments

Comments
 (0)