Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 34 additions & 35 deletions bun.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.95.11.wasm",
"https://plugins.dprint.dev/json-0.20.0.wasm",
"https://plugins.dprint.dev/typescript-0.95.12.wasm",
"https://plugins.dprint.dev/json-0.21.0.wasm",
"https://plugins.dprint.dev/markdown-0.20.0.wasm",
"https://plugins.dprint.dev/g-plane/malva-v0.14.3.wasm",
"https://plugins.dprint.dev/g-plane/malva-v0.15.0.wasm",
"https://plugins.dprint.dev/g-plane/markup_fmt-v0.24.0.wasm",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm"
]
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@
"purecss": "^3.0.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"tshet-uinh": "^0.15.3"
"tshet-uinh": "^0.16.0-beta.8"
},
"devDependencies": {
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.37.0",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"@typescript-eslint/parser": "^8.46.1",
"@vitejs/plugin-react-swc": "^4.2.0",
"@eslint/js": "^9.39.1",
"@types/react": "^19.2.5",
"@types/react-dom": "^19.2.3",
"@typescript-eslint/parser": "^8.46.4",
"@vitejs/plugin-react-swc": "^4.2.2",
"dprint": "^0.50.2",
"eslint": "^9.38.0",
"eslint": "^9.39.1",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^7.0.1",
"globals": "^16.4.0",
"globals": "^16.5.0",
"process": "^0.11.10",
"typescript": "^5.9.3",
"typescript-eslint": "^8.46.2",
"vite": "^7.1.12"
"typescript-eslint": "^8.46.4",
"vite": "^7.2.2"
},
"browserslist": {
"production": ">0.2% and not dead and supports es6-module",
Expand Down
10 changes: 6 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
常見字頻序,
type 查詢方式,
查詢音韻地位,
條目有效字頭,
type 顯示哪些字,
} from "./utils";

Expand Down Expand Up @@ -83,11 +84,12 @@ export default function App() {
}
const 結果 = new Set<string>();
for (const 音韻地位 of 各音韻地位) {
const 條目 = 資料.query音韻地位(音韻地位);
if (顯示哪些字 === "一個音韻地位只顯示一個代表字" && 條目.length) {
結果.add(條目.reduce((prev, cur) => compare字頭order(cur.字頭, prev.字頭) < 0 ? cur : prev).字頭);
const 各條目 = 資料.query音韻地位(音韻地位);
if (顯示哪些字 === "一個音韻地位只顯示一個代表字" && 各條目.length) {
結果.add(各條目.map(條目有效字頭).reduce((prev, cur) => compare字頭order(cur, prev) < 0 ? cur : prev));
} else {
for (const { 字頭 } of 條目) {
for (const 條目 of 各條目) {
const 字頭 = 條目有效字頭(條目);
if (顯示哪些字 === "顯示所有字" || 常見字頻序.has(字頭)) {
結果.add(字頭);
}
Expand Down
24 changes: 15 additions & 9 deletions src/CharInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function CharInfo({ show, index, 字頭, isQueried音韻地位, c
const [tabIndex, setTabIndex] = useState(0);

const 條目結果originalOrder = useMemo(() => {
const by地位 = new Map<string, 資料.檢索結果[]>();
const by地位 = new Map<string, 資料.資料條目[]>();

for (const 條目 of 資料.query字頭(字頭)) {
const key = 條目.音韻地位.描述;
Expand Down Expand Up @@ -67,15 +67,21 @@ export default function CharInfo({ show, index, 字頭, isQueried音韻地位, c
))}
</div>
<div className="pages">
{條目結果.map(([描述, 條目們], i) => (
{條目結果.map(([描述, 各條目], i) => (
<ul key={描述} className={`page${i === tabIndex ? "" : " hidden"}`}>
{條目們.map(條目 => {
const { 反切: 反切_, 釋義, 來源 } = 條目;
const 反切 = 反切_ ? `${反切_}${來源?.文獻 === "王三" ? "反" : "切"} ` : "";
const 來源括註 = 來源 && ["廣韻", "王三"].includes(來源.文獻)
? `[${來源.文獻} ${來源.韻目}韻]`
: "";
return <li key={i} className="pageItem">{`${反切}${釋義}${來源括註}`}</li>;
{各條目.map(條目 => {
const { 字頭: 條目字頭, 字頭說明, 反切, 直音, 釋義, 來源, 韻目 } = 條目;
const 音注 = 反切 ? 反切 + (來源 === "廣韻" ? "切" : "反") : "音" + 直音;
return (
<li key={i} className="pageItem">
<p>
<span className="headword">{條目字頭}</span> {音注}
</p>
{釋義 ? <p>{釋義}</p> : null}
{字頭說明 ? <p className="headwordNote">{字頭說明}</p> : null}
<p>{來源} {韻目}韻</p>
</li>
);
})}
</ul>
))}
Expand Down
17 changes: 17 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,23 @@ output {
margin: 0;
padding: 0 1.5rem 0 2.5rem;
}
.infoMain .pageItem {
margin: 0.4rem 0;
}
.infoMain .pageItem > p {
margin: 0.1rem 0 0;
}
.infoMain .pageItem > p:first-child {
margin: 0;
}
.infoMain .pageItem .headword {
font-size: 1.375rem;
line-height: 1;
}
.infoMain .pageItem > .headwordNote {
color: #bb0000;
font-size: 0.875rem;
}
.infoMain .links {
padding: 1rem 0.75rem 0.5rem;
font-size: 85%;
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export const 常見字頻序 = new Map<string, number>();

export const compare字頭order = (a: string, b: string) => (常見字頻序.get(a) ?? 99999) - (常見字頻序.get(b) ?? 99999);

/** 條目的校正後字頭,但應刪條目(沒有校正字頭)則用字頭原貌 */
export function 條目有效字頭(條目: 資料.資料條目): string {
// NOTE Non-null assertion safe because 字頭校正 and 字頭原貌 cannot be both null
return (條目.字頭校正 ?? 條目.字頭原貌)!;
}

export type 查詢方式 = "音韻表達式" | "音韻描述";
export type 顯示哪些字 = "只顯示常用字" | "一個音韻地位只顯示一個代表字" | "顯示所有字";

Expand Down