# -*- coding: utf-8 -*- """Restore all CJK in TopologyCanvas.tsx after encoding corruption.""" from __future__ import annotations import re from pathlib import Path p = Path(__file__).resolve().parents[1] / "src" / "TopologyCanvas.tsx" text = p.read_text(encoding="utf-8") misses: list[str] = [] def sub(pattern: str, repl: str, *, flags: int = 0, count: int = 0, label: str = "") -> None: global text new, n = re.subn(pattern, repl, text, count=count, flags=flags) tag = label or pattern[:56] if n == 0: misses.append(tag) print("MISS:", tag) else: print(f"OK x{n}:", tag) text = new # comments sub(r"// iframe \?+ Tab \?+", "// iframe 内无法全屏时,通知父页 Tab 全屏", label="fullscreen comment") sub(r"// Free place .+?pin every dragged id", "// Free place → pin every dragged id", label="free place comment") # placeholders used in draw / create sub(r'(wrapTextLines\(ctx, n\.text \|\| )"\?+"', r'\1"未命名"', label="unnamed wrap") sub(r'(n\.text \|\| )"\?+"', r'\1"未命名"', label="unnamed text") # create defaults sub( r'text: "\?+", parentId: parent\b', 'text: "新节点", parentId: parent', label="tab child", ) sub( r': \{ type: "create_node", text: "\?+" \},', ': { type: "create_node", text: "新节点" },', label="tab orphan / enter orphan", ) sub( r'text: "\?+",\n parentId: selectedIds\[0\],\n sidePref: -1', 'text: "左侧子主题",\n parentId: selectedIds[0],\n sidePref: -1', label="arrow left", ) sub( r'text: "\?+",\n parentId: selectedIds\[0\],\n sidePref: 1', 'text: "右侧子主题",\n parentId: selectedIds[0],\n sidePref: 1', label="arrow right", ) sub( r'text: "\?+",\n parentId: parentOfSel', 'text: "兄弟节点",\n parentId: parentOfSel', label="enter sibling", ) sub( r'text: "\?+",\n \.\.\.\(selectedIds\[0\]', 'text: "新节点",\n ...(selectedIds[0]', label="dblclick create", ) sub(r'label: "\?+"', 'label: "关联"', label="relation label") # toolbar: back sub( r'(className="canvas-tool-btn"\n title=")\?+("\n onClick=\{requestBackToRoster\}\n >\n )\?+(\n )', r"\1返回画布列表\2返回\3", label="back to roster", ) # tool modes sub(r'\["select", "\?+", "V"\]', '["select", "选择", "V"]', label="select") sub(r'\["pan", "\?+", "H"\]', '["pan", "平移", "H"]', label="pan") sub(r'\["link", "\?+", "C"\]', '["link", "连线", "C"]', label="link") # drag scope — title may contain latin (N)/(B)/Shift so match loosely sub( r'(aria-pressed=\{dragScope === "node"\}\n onClick=\{\(\) => setDragScope\("node"\)\}\n >\n )\?+(\n )', r"\1单点\2", label="drag node label", ) sub( r'(dragScope === "node" \? " is-active" : ""\}`\}\n title=")\?+(")', r"\1单点拖拽:只移动当前节点 (N);按住 Shift 也可临时单点\2", label="drag node title", ) sub( r'(aria-pressed=\{dragScope === "branch"\}\n onClick=\{\(\) => setDragScope\("branch"\)\}\n >\n )\?+(\n )', r"\1整枝\2", label="drag branch label", ) sub( r'(dragScope === "branch" \? " is-active" : ""\}`\}\n title=")\?+(")', r"\1整枝拖拽:节点与子孙一起移动 (B)\2", label="drag branch title", ) # bubble / card / unpin sub( r'(className=\{`canvas-tool-btn\$\{cardView \? "" : " is-active"\}`\}\n title=")\?+("\n aria-pressed=\{!cardView\})', r"\1气泡视图:精简标题\2", label="bubble title", ) sub( r'(void setPrefs\(\{ nodeViewMode: "bubble" \}\);\n \}\}\n >\n )\?+(\n \n \n \n \n
\n