Skip to content

Commit 6469c02

Browse files
committed
core&ui: new typst & fix
1 parent b9aab59 commit 6469c02

File tree

10 files changed

+131
-78
lines changed

10 files changed

+131
-78
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"devDependencies": {
1818
"@expo-google-fonts/noto-color-emoji": "^0.2.3",
1919
"@expo-google-fonts/noto-sans-sc": "^0.2.3",
20-
"@hydrooj/eslint-config": "^1.0.10",
21-
"@hydrooj/register": "^1.0.1",
22-
"@hydrooj/utils": "^1.4.24",
23-
"@types/node": "^20.14.2",
24-
"@yao-pkg/pkg": "^5.12.0",
20+
"@hydrooj/eslint-config": "^1.1.1",
21+
"@hydrooj/register": "^1.0.3",
22+
"@hydrooj/utils": "^1.4.28",
23+
"@types/node": "^20.16.11",
24+
"@yao-pkg/pkg": "^5.15.0",
2525
"dejavu-fonts-ttf": "^2.37.3",
26-
"eslint": "^8.57.0",
27-
"eslint-import-resolver-typescript": "^3.6.1",
28-
"typescript": "^5.3.3"
26+
"eslint": "^8.57.1",
27+
"eslint-import-resolver-typescript": "^3.6.3",
28+
"typescript": "5.4.5"
2929
},
3030
"resolutions": {
3131
"formidable": "patch:formidable@npm%3A2.1.2#~/.yarn/patches/formidable-npm-2.1.2-40ba18d67f.patch"

packages/server/client/typst.ts

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,44 +61,61 @@ class TypstCompilerDriver {
6161

6262
export function generateTypst(team: string, location: string, filename: string, lang: string, codeColor: boolean) {
6363
return `
64-
#let print(
65-
team: "",
66-
location: "",
67-
filename: "",
68-
lang: "",
69-
body
70-
) = {
71-
set document(author: (team), title: filename)
72-
set text(font: ("Linux Libertine"), lang: "zh")
73-
set page(
74-
paper: "a4",
75-
header: [
76-
#if (location != "") {
77-
[[#location]]
78-
}
79-
#team
80-
#h(1fr)
81-
By Hydro/XCPC-TOOLS
82-
83-
filename: #filename
84-
#h(1fr)
85-
Page #counter(page).display("1 of 1", both: true)
86-
]
87-
)
88-
89-
raw(read(filename), lang: lang, block: true${codeColor ? '' : ', theme: "BW.tmtheme"'})
90-
body
64+
#let fit(name: "", width: 147mm) = {
65+
context {
66+
if measure(text(name)).width < width {
67+
return name
68+
}
69+
for len in range(name.codepoints().len() - 1, 5, step: -1) {
70+
if measure(text(name
71+
.codepoints()
72+
.slice(0, len)
73+
.join() + " ...")).width < width {
74+
return name.codepoints().slice(0, len).join() + " ..."
75+
}
76+
}
77+
panic("Error")
78+
}
9179
}
9280
93-
#show raw.line: it => {
94-
box(stack(
95-
dir: ltr,
96-
box(width: 18pt)[#it.number],
97-
it.body,
98-
))
81+
#let print(
82+
team: "",
83+
location: "",
84+
filename: "",
85+
lang: "",
86+
) = {
87+
set document(author: (team), title: filename)
88+
set text(lang: "zh")
89+
set page(
90+
paper: "a4",
91+
header: [
92+
#if (location != "") {
93+
text(weight: "black", size: 10pt)[[#location]]
94+
}
95+
#fit(name: team)
96+
#linebreak()
97+
filename: #filename
98+
#h(1fr)
99+
By Hydro/XCPC-TOOLS | Page #counter(page).display("1 of 1", both: true)
100+
],
101+
)
102+
show raw.where(block: true): code => {
103+
show raw.line: it => {
104+
box(
105+
stack(
106+
dir: ltr,
107+
box(width: 0em, align(right, text(fill: gray)[#it.number])),
108+
h(1em),
109+
it.body,
110+
),
111+
)
112+
}
113+
code
114+
}
115+
raw(read(filename), lang: lang, block: true${codeColor ? '' : ', theme: "BW.tmtheme"'})
99116
}
100117
101-
#show: print.with(
118+
#print(
102119
team: ${JSON.stringify(team || '')},
103120
location: ${JSON.stringify(location || '')},
104121
filename: ${JSON.stringify(filename || '')},

packages/server/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
"devDependencies": {
1313
"@types/fs-extra": "^11.0.4",
1414
"@types/js-yaml": "^4.0.9",
15-
"@types/superagent": "^8.1.7"
15+
"@types/superagent": "^8.1.9"
1616
},
1717
"dependencies": {
1818
"@freedom_sky/esc-pos-encoder": "^5.8.0",
19-
"@hydrooj/framework": "0.0.5",
19+
"@hydrooj/framework": "0.1.0",
2020
"@myriaddreamin/typst-ts-web-compiler": "^0.5.0-rc4",
2121
"@myteril/node-win-printer": "^1.1.5",
2222
"base16384": "^1.0.0",
23-
"cordis": "3.16.0",
23+
"cordis": "3.18.1",
2424
"koa-proxies": "^0.12.4",
2525
"lodash": "^4.17.21",
2626
"nedb-promises": "^6.2.3",
2727
"prom-client": "^15.1.3",
2828
"schemastery": "^3.14.6",
29-
"superagent": "^9.0.2",
29+
"superagent": "^10.1.0",
3030
"unix-print": "^1.3.2",
31-
"ws": "^8.17.0"
31+
"ws": "^8.18.0"
3232
}
3333
}

packages/server/service/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from '@hydrooj/framework/decorators';
66

77
export async function apply(pluginContext: Context) {
88
pluginContext.plugin(WebService, {
9+
host: '0.0.0.0',
910
port: config.port,
1011
});
1112
pluginContext.inject(['server'], ({ server }) => {

packages/ui/.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
// FIXME A bug with eslint-parser
2727
// 'template-curly-spacing': 'off',
2828

29-
'@typescript-eslint/indent': [
29+
'@stylistic/indent': [
3030
'warn',
3131
2,
3232
{ SwitchCase: 1 },

packages/ui/app/App.tsx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,49 @@
11
import React from 'react';
22
import { AppShell, Container } from '@mantine/core';
3-
import { HashRouter, Route, Routes } from 'react-router-dom';
3+
import {
4+
HashRouter, Outlet, Route, Routes,
5+
} from 'react-router-dom';
46
import { Header } from './components/Header';
57
import Balloon from './pages/Balloon';
68
import Commands from './pages/Commands';
79
import Dashboard from './pages/Dashboard';
810
import Logs from './pages/Logs';
911
import Monitor from './pages/Monitor';
1012
import Print from './pages/Print';
13+
import Resolver from './Resolver';
14+
15+
function DefaultLayout() {
16+
return (
17+
<AppShell
18+
header={{ height: '60px' }}
19+
padding="md"
20+
>
21+
<AppShell.Header>
22+
<Header />
23+
</AppShell.Header>
24+
<AppShell.Main>
25+
<Container size="xl">
26+
<Outlet />
27+
</Container>
28+
<Logs />
29+
</AppShell.Main>
30+
</AppShell>
31+
);
32+
}
1133

1234
export default function App() {
1335
return (
1436
<HashRouter>
15-
<AppShell
16-
header={{ height: '60px' }}
17-
padding="md"
18-
>
19-
<AppShell.Header>
20-
<Header />
21-
</AppShell.Header>
22-
<AppShell.Main>
23-
<Container size="xl">
24-
<Routes>
25-
<Route path="/" element={<Dashboard />} />
26-
<Route path="/print" element={<Print />} />
27-
<Route path="/balloon" element={<Balloon />} />
28-
<Route path="/monitor" element={<Monitor />} />
29-
<Route path="/commands" element={<Commands />} />
30-
</Routes>
31-
</Container>
32-
<Logs />
33-
</AppShell.Main>
34-
</AppShell>
37+
<Routes>
38+
<Route path="/" element={<DefaultLayout />}>
39+
<Route index element={<Dashboard />} />
40+
<Route path="/print" element={<Print />} />
41+
<Route path="/balloon" element={<Balloon />} />
42+
<Route path="/monitor" element={<Monitor />} />
43+
<Route path="/commands" element={<Commands />} />
44+
</Route>
45+
<Route path="/resolver" element={<Resolver />} />
46+
</Routes>
3547
</HashRouter>
3648
);
3749
}

packages/ui/app/Resolver.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import {
3+
Card, Center,
4+
} from '@mantine/core';
5+
6+
export default function Monitor() {
7+
return (
8+
<Card shadow="sm" padding="lg" radius="md" withBorder style={{ height: '100vh' }}>
9+
<Center>@Hydro/XCPC-Tools</Center>
10+
</Card>
11+
);
12+
}

packages/ui/app/components/BalloonsModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ export function BalloonsClient({ clients, refresh }) {
5050
<Fieldset legend="Add Client" mb="lg">
5151
<LoadingOverlay visible={adding} zIndex={1000} overlayProps={{ radius: 'sm', blur: 2 }} />
5252
<FocusTrap active>
53-
<TextInput label="Client Name" placeholder="Client Name" value={name} onChange={(e) => setName(e.currentTarget.value)} data-autofocus />
53+
<TextInput
54+
label="Client Name"
55+
placeholder="Client Name"
56+
value={name}
57+
onChange={(e) => setName(e.currentTarget.value)} data-autofocus
58+
/>
5459
</FocusTrap>
5560
<Button color="blue" fullWidth mt="md" radius="md" onClick={addClient}>Submit</Button>
5661
</Fieldset>

packages/ui/app/pages/Monitor.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function Monitor() {
4848
<MonitorBatchModal refresh={query.refetch} />
4949
</Group>
5050
</Group>
51-
<Tabs value={activeTab} onChange={setActiveTab}>
51+
<Tabs value={activeTab} onChange={(value) => setActiveTab(value!)}>
5252
<Tabs.List>
5353
<Tabs.Tab value="all">All({query.data?.monitors ? Object.values(query.data?.monitors || {}).length : 0})</Tabs.Tab>
5454
{Object.keys(query.data?.groups || {}).map((group) => (
@@ -71,9 +71,15 @@ export default function Monitor() {
7171
<Text c="dimmed">No monitors found</Text>
7272
</Center>
7373
) : (useTableMode ? (
74-
<MonitorTable monitors={(query.data?.groups[group] || []).map((m) => query.data?.monitors[m])} openMonitorInfo={openMonitorInfo} />
74+
<MonitorTable
75+
monitors={(query.data?.groups[group] || []).map((m) => query.data?.monitors[m])}
76+
openMonitorInfo={openMonitorInfo}
77+
/>
7578
) : (
76-
<MonitorCards monitors={(query.data?.groups[group] || []).map((m) => query.data?.monitors[m])} openMonitorInfo={openMonitorInfo} />
79+
<MonitorCards
80+
monitors={(query.data?.groups[group] || []).map((m) => query.data?.monitors[m])}
81+
openMonitorInfo={openMonitorInfo}
82+
/>
7783
)))}
7884
</Tabs.Panel>
7985
))}

packages/ui/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"@types/react": "^18.3.3",
2222
"@types/react-dom": "^18.3.0",
2323
"css-loader": "^6.11.0",
24-
"esbuild-loader": "^4.1.0",
24+
"esbuild-loader": "^4.2.2",
2525
"mpegts.js": "^1.7.3",
26-
"postcss": "^8.4.38",
27-
"postcss-loader": "^7.3.3",
28-
"postcss-preset-mantine": "^1.15.0",
26+
"postcss": "^8.4.47",
27+
"postcss-loader": "^7.3.4",
28+
"postcss-preset-mantine": "^1.17.0",
2929
"postcss-simple-vars": "^7.0.1",
3030
"react": "^18.3.1",
3131
"react-dom": "^18.3.1",
32-
"react-router-dom": "^6.23.1",
32+
"react-router-dom": "^6.27.0",
3333
"style-loader": "^3.3.4",
3434
"webpack": "^5.92.0",
3535
"webpack-dev-server": "^5.0.4"

0 commit comments

Comments
 (0)