# -*- coding: utf-8 -*- """Restore CJK in TopologyCanvas.tsx; tolerate latin1/broken middot encoding.""" from __future__ import annotations import re from pathlib import Path p = Path(__file__).resolve().parents[1] / "src" / "TopologyCanvas.tsx" raw = p.read_bytes() try: text = raw.decode("utf-8") except UnicodeDecodeError: text = raw.decode("latin1") # Normalize stray CP1252/latin1 middot into a matchable char text = text.replace("\xb7", "·") 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 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") sub(r"// Contain: \?+", "// Contain: 等比例完整放入框内,不裁切", label="contain comment") sub(r'(wrapTextLines\(ctx, n\.text \|\| )"\?+"', r'\1"未命名"', label="unnamed wrap") sub(r'(n\.text \|\| )"\?+"', r'\1"未命名"', label="unnamed text") 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") sub( r'(className="canvas-tool-btn"\n title=")\?+("\n onClick=\{requestBackToRoster\}\n >\n )\?+(\n )', r"\1返回画布列表\2返回\3", label="back to roster", ) sub(r'\["select", "\?+", "V"\]', '["select", "选择", "V"]', label="select") sub(r'\["pan", "\?+", "H"\]', '["pan", "平移", "H"]', label="pan") sub(r'\["link", "\?+", "C"\]', '["link", "连线", "C"]', label="link") 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", ) 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