diff --git a/package.json b/package.json index e923c42..b90a055 100644 --- a/package.json +++ b/package.json @@ -131,7 +131,7 @@ ], "tsdoc/syntax": "warn", "no-undef": "error", - "no-undefined": "error" + "no-undefined": "off" } }, "hintConfig": { diff --git a/scripts/analyze.ts b/scripts/analyze.ts index 834f90c..902cda2 100644 --- a/scripts/analyze.ts +++ b/scripts/analyze.ts @@ -1,6 +1,5 @@ import { readFileSync } from "fs"; import { load } from "js-yaml"; -import { examples } from "~/lib"; const estimate = (n: number, k: number) => (n * n) / (2 * k); diff --git a/scripts/recursive.ts b/scripts/recursive.ts index 179ee42..0c20f42 100644 --- a/scripts/recursive.ts +++ b/scripts/recursive.ts @@ -1,6 +1,5 @@ import { readFileSync, writeFileSync } from "fs"; import type { Compound, PrimitiveCharacter } from "~/lib"; -import { Character } from "~/lib"; const repertoire = JSON.parse( readFileSync("public/cache/repertoire.json", "utf-8"), @@ -16,7 +15,7 @@ for (const character of repertoire) { | undefined; if (!compound) continue; const children = compound.operandList; - for (const [index, child] of children.entries()) { + for (const child of children.values()) { descendants.set(child, (descendants.get(child) ?? []).concat(name)); } } diff --git a/spec/component.spec.ts b/spec/component.spec.ts index 55a4def..2261080 100644 --- a/spec/component.spec.ts +++ b/spec/component.spec.ts @@ -2,15 +2,13 @@ import { describe, expect, it } from "vitest"; import { classifier, createConfig, - defaultConfig, generateSchemes, getComponentScheme, - listToObject, makeIntervalSum, recursiveRenderComponent, renderRootList, } from "~/lib"; -import type { DerivedComponent, PrimitiveRepertoire } from "~/lib"; +import type { DerivedComponent } from "~/lib"; import { primitiveRepertoire, repertoire, diff --git a/spec/degenerator.spec.ts b/spec/degenerator.spec.ts index 3ab1f84..2ede63f 100644 --- a/spec/degenerator.spec.ts +++ b/spec/degenerator.spec.ts @@ -93,7 +93,7 @@ const hasroot = (a: RenderedGlyph, indices: number[], root: RenderedGlyph) => { }; describe("degenerate cross tests", () => { - const { 大, 天, 九, 丸, 山, 出, 冖, 农, 赤, 以, 人, 氺, 丆, 疌, 龰, 夫 } = + const { 大, 天, 九, 丸, 山, 出, 冖, 农, 以, 人, 氺, 丆, 疌, 龰, 夫 } = renderedGlyphs as any; const han = renderedGlyphs["\ue104"]!; it("says 天 has 大", () => { diff --git a/spec/element.spec.ts b/spec/element.spec.ts index 0b7a565..b757c8a 100644 --- a/spec/element.spec.ts +++ b/spec/element.spec.ts @@ -5,8 +5,6 @@ import { renderName, renderList, parseList, - findElement, - CodableObject, } from "../src/lib/element"; describe("element", () => { diff --git a/spec/mock.ts b/spec/mock.ts index cb7b3b5..967c3f1 100644 --- a/spec/mock.ts +++ b/spec/mock.ts @@ -6,7 +6,7 @@ import type { PrimitiveCharacter, Repertoire, } from "~/lib"; -import { listToObject, determine, computeComponent } from "~/lib"; +import { determine, computeComponent } from "~/lib"; export const primitiveRepertoire = Object.fromEntries( (rawrepertoire as PrimitiveCharacter[]).map((x) => [ @@ -17,7 +17,7 @@ export const primitiveRepertoire = Object.fromEntries( export const repertoire = determine(primitiveRepertoire); export const computedComponents = Object.fromEntries( Object.entries(repertoire) - .filter(([k, v]) => v.glyph?.type === "basic_component") + .filter(([_, v]) => v.glyph?.type === "basic_component") .map(([k, v]) => { const glyph = (v.glyph as BasicComponent).strokes; return [k, computeComponent(k, glyph)]; diff --git a/spec/selector.spec.ts b/spec/selector.spec.ts index 3ae1424..9b27a74 100644 --- a/spec/selector.spec.ts +++ b/spec/selector.spec.ts @@ -1,10 +1,9 @@ import { describe, expect, it } from "vitest"; import type { Environment, Scheme } from "~/lib"; -import { length, bias, order, crossing, attaching, analysis } from "~/lib"; +import { length, bias, order, crossing, attaching } from "~/lib"; import { select } from "~/lib"; import { computedComponents, focusAnalysis, repertoire } from "./mock"; import { defaultConfig } from "~/lib"; -import { Config } from "~/lib"; const analysisConfig = focusAnalysis(defaultConfig, repertoire); const { 天 } = computedComponents as any; diff --git a/spec/topology.spec.ts b/spec/topology.spec.ts index 14db64b..f10c9a1 100644 --- a/spec/topology.spec.ts +++ b/spec/topology.spec.ts @@ -1,7 +1,7 @@ import { expect, describe, it } from "vitest"; import type { StrokeRelation, CubicCurve, LinearCurve } from "~/lib"; -import { findTopology, curveRelation, renderSVGGlyph } from "~/lib"; -import { area, render } from "~/lib"; +import { findTopology, curveRelation } from "~/lib"; +import { area } from "~/lib"; import type { Draw, Point } from "~/lib"; import { computedGlyphs2 as computedGlyphs } from "./mock"; import { getIntervalPosition, makeCurve } from "~/lib"; diff --git a/src/atoms/analysis.ts b/src/atoms/analysis.ts index ddafd78..1c2d1a1 100644 --- a/src/atoms/analysis.ts +++ b/src/atoms/analysis.ts @@ -1,10 +1,4 @@ -import type { - Analysis, - Degenerator, - Selector, - SieveName, - Feature, -} from "~/lib"; +import type { Analysis, Degenerator, Selector, Feature } from "~/lib"; import { focusAtom } from "jotai-optics"; import { analysisAtom } from "./config"; import { mergeClassifier } from "~/lib"; diff --git a/src/atoms/assets.ts b/src/atoms/assets.ts index 4b56692..c1534a0 100644 --- a/src/atoms/assets.ts +++ b/src/atoms/assets.ts @@ -1,5 +1,11 @@ import { atomWithStorage } from "jotai/utils"; -import type { Dictionary, Distribution, Equivalence, Frequency } from "."; +import type { + CustomElementMap, + Dictionary, + Distribution, + Equivalence, + Frequency, +} from "~/lib"; import { MiniDb } from "jotai-minidb"; const db = new MiniDb(); @@ -20,8 +26,6 @@ export const userPairEquivalenceAtom = atomWithStorage( undefined, ); -export type CustomElementMap = Record; - export const customElementsAtom = atomWithStorage< Record >("custom_elements", {}); diff --git a/src/atoms/cache.ts b/src/atoms/cache.ts index f0c6b81..3615da3 100644 --- a/src/atoms/cache.ts +++ b/src/atoms/cache.ts @@ -11,7 +11,6 @@ import { Thread, algebraAtom, analysisAtom, - assetsAtom, charactersAtom, dictionaryAtom, encoderAtom, diff --git a/src/atoms/constants.ts b/src/atoms/constants.ts index 708bcd2..c77741c 100644 --- a/src/atoms/constants.ts +++ b/src/atoms/constants.ts @@ -1,4 +1,5 @@ import { atom } from "jotai"; +import type { Dictionary, Distribution, Equivalence, Frequency } from "~/lib"; import { getDictFromTSV, getDistributionFromTSV, @@ -58,17 +59,6 @@ export const mutateRepertoireAtom = atom( }, ); -interface Loss { - ideal: number; - lt_penalty: number; - gt_penalty: number; -} - -export type Dictionary = [string, string][]; -export type Frequency = Record; -export type Distribution = Record; -export type Equivalence = Record; - export const defaultDictionaryAtom = atom>(async () => getDictFromTSV(await fetchAsset("dictionary", "txt")), ); diff --git a/src/atoms/data.ts b/src/atoms/data.ts index e1a739c..38f962f 100644 --- a/src/atoms/data.ts +++ b/src/atoms/data.ts @@ -1,4 +1,4 @@ -import { atom, useAtomValue } from "jotai"; +import { atom } from "jotai"; import { primitiveRepertoireAtom } from "./constants"; import type { CharacterSetSpecifier, diff --git a/src/atoms/encoder.ts b/src/atoms/encoder.ts index 3ea6f6c..4e044d3 100644 --- a/src/atoms/encoder.ts +++ b/src/atoms/encoder.ts @@ -1,7 +1,6 @@ import { focusAtom } from "jotai-optics"; import { encoderAtom } from "."; import type { ShortCodeRule, WordRule } from "~/lib"; -import { ShortCodeScheme } from "~/lib"; export const maxLengthAtom = focusAtom(encoderAtom, (o) => o.prop("max_length"), diff --git a/src/atoms/hooks.ts b/src/atoms/hooks.ts index 72e9f93..0d90f42 100644 --- a/src/atoms/hooks.ts +++ b/src/atoms/hooks.ts @@ -1,5 +1,5 @@ import type { Config } from "~/lib"; -import { isValidCJKChar, makeWorker } from "~/lib"; +import { isValidCJKChar, makeJsWorker, makeWasmWorker } from "~/lib"; import useTitle from "ahooks/es/useTitle"; import init, { validate } from "libchai"; import type { LibchaiOutputEvent } from "~/worker"; @@ -12,12 +12,11 @@ import { load } from "js-yaml"; export class Thread { private worker: Worker; - constructor(type: "js" | "wasm") { - const url = type === "js" ? "../jsworker.ts" : undefined; - this.worker = makeWorker(url); + public constructor(type: "js" | "wasm") { + this.worker = type === "js" ? makeJsWorker() : makeWasmWorker(); } - async spawn(func: string, args: any[]): Promise { + public async spawn(func: string, args: any[]): Promise { return await new Promise((resolve) => { const channel = new MessageChannel(); channel.port1.onmessage = ({ data }) => { diff --git a/src/atoms/index.ts b/src/atoms/index.ts index d8444d7..87543e5 100644 --- a/src/atoms/index.ts +++ b/src/atoms/index.ts @@ -1,5 +1,5 @@ import type { WritableAtom } from "jotai"; -import { useAtom, useAtomValue, useSetAtom } from "jotai"; +import { useAtomValue, useSetAtom } from "jotai"; export * from "jotai"; export * from "./constants"; diff --git a/src/atoms/optimization.ts b/src/atoms/optimization.ts index 3e505df..0cefac5 100644 --- a/src/atoms/optimization.ts +++ b/src/atoms/optimization.ts @@ -1,5 +1,5 @@ import { focusAtom } from "jotai-optics"; -import { atom, optimAtom } from "."; +import { optimAtom } from "."; export const objectiveAtom = focusAtom(optimAtom, (o) => o.prop("objective")); objectiveAtom.debugLabel = "optimization.objective"; diff --git a/src/components/Action.tsx b/src/components/Action.tsx index 44edefa..a7f242f 100644 --- a/src/components/Action.tsx +++ b/src/components/Action.tsx @@ -6,10 +6,9 @@ import { Input, Popconfirm, Popover, - Space, } from "antd"; import type { ForwardedRef } from "react"; -import { createContext, forwardRef, useContext, useState } from "react"; +import { forwardRef, useContext, useState } from "react"; import { remoteCreate, remoteCreateWithoutUnicode, @@ -22,7 +21,6 @@ import type { Reading } from "~/lib"; import { chars, isValidCJKChar, - getDummyBasicComponent, getDummyCompound, getDummyDerivedComponent, } from "~/lib"; @@ -30,7 +28,6 @@ import { useAtomValue, useSetAtom, mutateRepertoireAtom, - useAtom, repertoireAtom, nextUnicodeAtom, useAddAtom, diff --git a/src/components/CharacterQuery.tsx b/src/components/CharacterQuery.tsx index 23ff621..5fff150 100644 --- a/src/components/CharacterQuery.tsx +++ b/src/components/CharacterQuery.tsx @@ -1,6 +1,6 @@ -import { Form, Input } from "antd"; +import { Form } from "antd"; import type { CharacterFilter } from "~/lib"; -import { Operator, PrimitiveRepertoire, Repertoire, operators } from "~/lib"; +import { operators } from "~/lib"; import { ProFormDigit, ProFormSelect, diff --git a/src/components/CharacterSearch.tsx b/src/components/CharacterSearch.tsx index e2c9f0d..36fe413 100644 --- a/src/components/CharacterSearch.tsx +++ b/src/components/CharacterSearch.tsx @@ -1,6 +1,5 @@ import { Input } from "antd"; import SearchOutlined from "@ant-design/icons/SearchOutlined"; -import { Repertoire } from "~/lib"; interface StrokeSearchProps { setSequence: (s: string) => void; diff --git a/src/components/CharacterSelect.tsx b/src/components/CharacterSelect.tsx index 49ff2fc..b47767e 100644 --- a/src/components/CharacterSelect.tsx +++ b/src/components/CharacterSelect.tsx @@ -4,9 +4,7 @@ import { displayAtom, sequenceAtom, sortedRepertoireAtom } from "~/atoms"; import { Select } from "./Utils"; import type { SelectProps } from "antd"; import type { Character } from "~/lib"; -import { PrimitiveCharacter } from "~/lib"; import type { ProFormSelectProps } from "@ant-design/pro-components"; -import { ProFormSelect } from "@ant-design/pro-components"; interface ItemSelectProps extends SelectProps { customFilter?: (e: [string, Character]) => boolean; @@ -22,14 +20,14 @@ export const GlyphSelect = (props: ItemSelectProps & ProFormSelectProps) => { useEffect(() => { const initial = char ? [{ value: char, label: display(char) }] : []; setData(initial); - }, [props.value]); + }, [props.value, char, display]); const onSearch = (input: string) => { if (input.length === 0) { setData([]); return; } const allResults = sortedRepertoire - .filter(props.customFilter ?? ((_) => true)) + .filter(customFilter ?? (() => true)) .map(([x]) => ({ value: x, label: display(x), diff --git a/src/components/CharacterTable.tsx b/src/components/CharacterTable.tsx index ce58d14..79750d5 100644 --- a/src/components/CharacterTable.tsx +++ b/src/components/CharacterTable.tsx @@ -37,7 +37,7 @@ import { import ComponentForm from "./ComponentForm"; import CompoundForm from "./CompoundForm"; import { remoteUpdate } from "~/api"; -import { DeleteButton, PlusButton } from "./Utils"; +import { DeleteButton } from "./Utils"; import Element from "./Element"; import * as O from "optics-ts/standalone"; import CharacterQuery from "./CharacterQuery"; @@ -52,9 +52,13 @@ function ReadingList({ readings }: { readings: Reading[] }) { return ( {readings.map((reading, index) => { - const core = {reading.pinyin}; + const core = {reading.pinyin}; if (readings.length === 1) return core; - return {core}; + return ( + + {core} + + ); })} ); @@ -379,7 +383,7 @@ export default function CharacterTable() { - {}} ref={ref3} /> + {}} ref={ref3} />
diff --git a/src/components/Classifier.tsx b/src/components/Classifier.tsx index b89fb24..0a18c10 100644 --- a/src/components/Classifier.tsx +++ b/src/components/Classifier.tsx @@ -4,7 +4,6 @@ import { customClassifierAtom, useAddAtom, useAtomValue, - useSetAtom, } from "~/atoms"; import { Button, Flex, Space, notification } from "antd"; import Element from "~/components/Element"; diff --git a/src/components/ComponentForm.tsx b/src/components/ComponentForm.tsx index 5586b49..f0e449e 100644 --- a/src/components/ComponentForm.tsx +++ b/src/components/ComponentForm.tsx @@ -1,9 +1,9 @@ import type { FormListFieldData } from "antd"; -import { Button, Flex, Form, Dropdown, notification } from "antd"; -import { EditorColumn, EditorRow, NumberInput } from "./Utils"; +import { Flex, Form } from "antd"; +import { EditorColumn, EditorRow } from "./Utils"; import type { MutableRefObject, ReactNode } from "react"; import { useRef } from "react"; -import type { PrimitiveCharacter, Component, Character } from "~/lib"; +import type { Character, Component } from "~/lib"; import type { Feature } from "~/lib"; import { getDummySVGStroke, schema } from "~/lib"; import { getDummyReferenceStroke, isComponent } from "~/lib"; @@ -183,7 +183,7 @@ export default function ComponentForm({ ) : ( {title} ); - const isValidSource = ([name, _]: [string, Character]) => { + const isValidSource = ([name]: [string, Character]) => { let component: Component | undefined = repertoire[name]?.glyphs.find(isComponent); if (component === undefined) return false; @@ -262,7 +262,7 @@ export default function ComponentForm({ : getDummySVGStroke("横") } > - {(meta, index) => { + {(meta) => { return ( - {(meta, i) => ( + {(meta) => ( diff --git a/src/components/ConfigManager.tsx b/src/components/ConfigManager.tsx index 2dc600e..f6ab8e1 100644 --- a/src/components/ConfigManager.tsx +++ b/src/components/ConfigManager.tsx @@ -1,4 +1,4 @@ -import { Button, Flex, notification } from "antd"; +import { Button, Flex } from "antd"; import { configAtom, roundTestConfig, useAtom, validateConfig } from "~/atoms"; import { examples, exportYAML } from "~/lib"; diff --git a/src/components/Debugger.tsx b/src/components/Debugger.tsx index 62a4901..e542fcc 100644 --- a/src/components/Debugger.tsx +++ b/src/components/Debugger.tsx @@ -4,12 +4,7 @@ import { useAtom, useAtomValue } from "jotai"; import { atomWithStorage } from "jotai/utils"; import { useMemo, useState } from "react"; import type { DictEntry } from "~/atoms"; -import { - EncodeResult, - charactersAtom, - configAtom, - repertoireAtom, -} from "~/atoms"; +import { charactersAtom, configAtom, repertoireAtom } from "~/atoms"; import { encodeResultAtom } from "~/atoms/cache"; import { Select, Uploader } from "~/components/Utils"; import { getSupplemental } from "~/lib"; diff --git a/src/components/DetailEditor.tsx b/src/components/DetailEditor.tsx index 4b92f63..a221fa0 100644 --- a/src/components/DetailEditor.tsx +++ b/src/components/DetailEditor.tsx @@ -5,8 +5,8 @@ import { Cascader, Flex, Form, Typography } from "antd"; import type { CodableObject } from "~/lib"; import { parseList, defaultAlgebra, renderList } from "~/lib"; import { Select } from "./Utils"; -import type { Op, UnaryOp } from "~/lib"; -import { binaryOps, ops, unaryOps } from "~/lib"; +import type { Op } from "~/lib"; +import { ops, unaryOps } from "~/lib"; import TextArea from "antd/es/input/TextArea"; import { useAtomValue, keyboardAtom, algebraAtom } from "~/atoms"; import { customElementsAtom } from "~/atoms/assets"; diff --git a/src/components/ElementAdder.tsx b/src/components/ElementAdder.tsx index 354e96f..8b5cc29 100644 --- a/src/components/ElementAdder.tsx +++ b/src/components/ElementAdder.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { Select, Button, Flex } from "antd"; +import { Button, Flex } from "antd"; import { keyboardAtom, useAtomValue, diff --git a/src/components/ElementPicker.tsx b/src/components/ElementPicker.tsx index 4561f66..2c79456 100644 --- a/src/components/ElementPicker.tsx +++ b/src/components/ElementPicker.tsx @@ -6,23 +6,16 @@ import styled from "styled-components"; import { algebraAtom, customClassifierAtom, - repertoireAtom, sortedRepertoireAtom, useAtomValue, useRemoveAtom, } from "~/atoms"; import Algebra from "./Algebra"; import type { PronunciationElementTypes } from "~/lib"; -import { applyRules, defaultAlgebra } from "~/lib"; import { operators } from "~/lib"; import { customElementsAtom } from "~/atoms/assets"; import { phonemeEnumerationAtom } from "~/atoms/cache"; -interface ElementPickerProps { - content: Map; - editable?: boolean; -} - const Wrapper = styled(Tabs)` & .ant-tabs-nav-wrap { transform: none !important; diff --git a/src/components/ElementPool.tsx b/src/components/ElementPool.tsx index ea13c70..d1f2d71 100644 --- a/src/components/ElementPool.tsx +++ b/src/components/ElementPool.tsx @@ -41,7 +41,6 @@ const Element = ({ }) => { const keyboard = useAtomValue(keyboardAtom); const { mapping, grouping } = keyboard; - const determiedRepertoire = useAtomValue(repertoireAtom); const glyphMap = useAtomValue(glyphAtom); const type = x === currentElement diff --git a/src/components/GlyphView.tsx b/src/components/GlyphView.tsx index 28593e8..d66eece 100644 --- a/src/components/GlyphView.tsx +++ b/src/components/GlyphView.tsx @@ -1,7 +1,7 @@ import styled from "styled-components"; -import type { Compound, SVGStroke } from "~/lib"; +import type { SVGStroke } from "~/lib"; -const FontView = ({ reference }: { reference: string }) => ( +export const FontView = ({ reference }: { reference: string }) => ( { Object.entries(grouping) .filter(([, to]) => to === name) .map(([x]) => x), - [grouping], + [grouping, name], ); const partialAffiliates = useMemo( () => @@ -63,9 +62,7 @@ const KeysEditor = ({ onDelete?: () => void; }) => { const addMapping = useAddAtom(mappingAtom); - const addGrouping = useAddAtom(groupingAtom); const removeMapping = useRemoveAtom(mappingAtom); - const removeGrouping = useRemoveAtom(groupingAtom); const display = useAtomValue(displayAtom); return ( @@ -144,7 +141,7 @@ const AdjustableRootPopoverContent = ({ 部分归并元素 {partialAffiliates.map(([x, keys]) => ( - + ))} )} @@ -260,7 +257,7 @@ export default function Mapping() { const { alphabet, mapping_type, mapping } = useAtomValue(keyboardAtom); const repertoire = useAtomValue(repertoireAtom); const keyboard = Array.from( - "QWERTYUIOPASDFGHJKL:ZXCVBNM<>?" + "qwertyuiopasdfghjkl;zxcvbnm,./", + "QWERTYUIOPASDFGHJKL:ZXCVBNM<>?qwertyuiopasdfghjkl;zxcvbnm,./", ); const printable_ascii = range(32, 127).map((x) => String.fromCodePoint(x)); const [char, setChar] = useState(undefined); @@ -332,7 +329,7 @@ export default function Mapping() { unknownKeys.push(key); continue; } - if ("strokes" in glyph && glyph.strokes.length == 1) { + if ("strokes" in glyph && glyph.strokes.length === 1) { unknownKeys.push(key); continue; } diff --git a/src/components/Optimizer.tsx b/src/components/Optimizer.tsx index b05aace..15c206b 100644 --- a/src/components/Optimizer.tsx +++ b/src/components/Optimizer.tsx @@ -8,30 +8,20 @@ import { Typography, notification, } from "antd"; -import { useAtom, useAtomValue } from "jotai"; +import { useAtomValue } from "jotai"; import { useState } from "react"; import type { DictEntry } from "~/atoms"; +import { configAtom, assetsAtom, makeEncodeCallback } from "~/atoms"; import { - configAtom, - repertoireAtom, - assetsAtom, - dictionaryAtom, - makeEncodeCallback, - charactersAtom, -} from "~/atoms"; -import { - assemble, exportTSV, exportYAML, - makeWorker, + makeWasmWorker, stringifySequence, } from "~/lib"; import type { LibchaiOutputEvent } from "~/worker"; import { load } from "js-yaml"; import type { Solver } from "~/lib"; -import { analysisResultAtom, assemblyResultAtom } from "~/atoms/cache"; -import { analysis } from "~/lib"; -import { customElementsAtom } from "~/atoms/assets"; +import { assemblyResultAtom } from "~/atoms/cache"; const Schedule = ({ params, @@ -108,7 +98,7 @@ export default function Optimizer() {