@ragnoryok1/dsh-client-locale-ru 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ //#region src/client/typography.ts
2
+ /**
3
+ * Russian screen typography for translated strings.
4
+ *
5
+ * The harness locale contract is a flat `Record<string, string>`, so a
6
+ * language pack cannot reach the composed sentences a component builds from
7
+ * several keys, and cannot ask the host to insert typography. The rendered DOM
8
+ * is the one place where every translated string passes through, so this module
9
+ * rewrites text nodes in place. The rules are deliberately conservative: they
10
+ * only fire on unambiguous straight-quote and spaced-hyphen patterns, and the
11
+ * DOM pass skips code, form fields and editable content.
12
+ */
13
+ /** Straight double quotes around a span become Russian guillemets. */
14
+ const QUOTED = /"([^"\n]{1,200})"/g;
15
+ /** A spaced hyphen between two words is an em dash in Russian typography. */
16
+ const SPACED_HYPHEN = /(?<=[\p{L}\p{N}»\)]) - (?=[\p{L}\p{N}«\(])/gu;
17
+ /** Three dots in running text are an ellipsis. */
18
+ const ELLIPSIS = /\.{3}(?=\s|$)/g;
19
+ /** A digit followed by a lowercase letter keeps a non-breaking space. */
20
+ const NUMBER_UNIT = /(\d) ([а-яё]{1,24})(?![а-яё])/giu;
21
+ /** Non-breaking space keeps a number attached to a short unit-like token. */
22
+ const NUMBER_SYMBOL = /(\d) ([%°₽$€£]|кб|КБ|МБ|ГБ)(?=\s|$)/giu;
23
+ /** Guillemets, em dash, ellipsis, and non-breaking spaces in running text. */
24
+ function applyRussianTypography(text) {
25
+ return text.replace(QUOTED, "«$1»").replace(SPACED_HYPHEN, " — ").replace(ELLIPSIS, "…").replace(NUMBER_UNIT, "$1\xA0$2").replace(NUMBER_SYMBOL, "$1\xA0$2");
26
+ }
27
+ /** Elements whose text is code, data or user input and must stay verbatim. */
28
+ const SKIP_SELECTOR = [
29
+ "code",
30
+ "pre",
31
+ "kbd",
32
+ "samp",
33
+ "var",
34
+ "textarea",
35
+ "input",
36
+ "select",
37
+ "option",
38
+ "[contenteditable]:not([contenteditable=\"false\"])",
39
+ "[data-typography=\"off\"]"
40
+ ].join(",");
41
+ /** Text nodes already rewritten, so a later pass leaves them alone. */
42
+ const processed = /* @__PURE__ */ new WeakSet();
43
+ /** Whether the node sits inside content that must not be rewritten. */
44
+ function isSkipped(node) {
45
+ const element = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
46
+ return element === null || element.closest(SKIP_SELECTOR) !== null;
47
+ }
48
+ function rewriteNode(node) {
49
+ if (node.nodeType === Node.TEXT_NODE) {
50
+ if (processed.has(node)) return;
51
+ processed.add(node);
52
+ const before = node.data;
53
+ const after = applyRussianTypography(before);
54
+ if (after !== before) node.data = after;
55
+ return;
56
+ }
57
+ if (node.nodeType !== Node.ELEMENT_NODE || isSkipped(node)) return;
58
+ for (const child of node.childNodes) rewriteNode(child);
59
+ }
60
+ /**
61
+ * Start the typography pass on a document and keep it current as the app
62
+ * renders. Returns a disposer that stops observing.
63
+ *
64
+ * @param doc - document whose body carries the rendered interface.
65
+ * @returns disposer removing the observer.
66
+ */
67
+ function startRussianTypography(doc) {
68
+ const root = doc.body;
69
+ if (root === null) return () => {};
70
+ rewriteNode(root);
71
+ const observer = new MutationObserver((records) => {
72
+ for (const record of records) {
73
+ if (record.type === "characterData") {
74
+ if (isSkipped(record.target)) continue;
75
+ rewriteNode(record.target);
76
+ continue;
77
+ }
78
+ for (const added of record.addedNodes) rewriteNode(added);
79
+ }
80
+ });
81
+ observer.observe(root, {
82
+ childList: true,
83
+ characterData: true,
84
+ subtree: true
85
+ });
86
+ return () => observer.disconnect();
87
+ }
88
+ //#endregion
89
+ export { applyRussianTypography, startRussianTypography };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ragnoryok1/dsh-client-locale-ru",
3
- "description": "Russian (ru) language pack for the DeepSeek Harness web GUI - installable hybrid dsh.bundle + dsh.client plugin, 52 namespaces, verified against dsh 0.1.7-rc.2",
4
- "version": "0.1.7",
3
+ "description": "Russian (ru) language pack for the DeepSeek Harness web GUI - installable hybrid dsh.bundle + dsh.client plugin, 53 namespaces, verified against dsh 0.2.1-alpha.1",
4
+ "version": "0.2.0",
5
5
  "keywords": [
6
6
  "deepseek",
7
7
  "deepseek-harness",
@@ -40,6 +40,10 @@
40
40
  "types": "./lib/client.d.ts",
41
41
  "default": "./lib/client.js"
42
42
  },
43
+ "./typography": {
44
+ "types": "./lib/typography.d.ts",
45
+ "default": "./lib/typography.js"
46
+ },
43
47
  "./cordis.patch.yml": "./cordis.patch.yml",
44
48
  "./package.json": "./package.json"
45
49
  },
@@ -56,25 +60,30 @@
56
60
  },
57
61
  "scripts": {
58
62
  "build": "tsdown",
63
+ "check:typography": "node scripts/check-typography.mjs",
64
+ "audit": "node scripts/audit.mjs",
65
+ "verify": "npm run build && npm run check:typography && node scripts/audit.mjs",
59
66
  "prepublishOnly": "npm run build"
60
67
  },
61
68
  "license": "MIT",
62
69
  "peerDependencies": {
63
70
  "@deepseek-ai/cordis": "^4.0.2",
64
- "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.2 <0.2.0"
71
+ "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.2 <0.3.0"
65
72
  },
66
73
  "devDependencies": {
67
74
  "@deepseek-ai/cordis": "^4.0.2",
68
- "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.2 <0.2.0",
75
+ "@deepseek-ai/dsh-client-locale": ">=0.1.0-rc.2 <0.3.0",
69
76
  "tsdown": "^0.22.2",
70
77
  "typescript": "^5.6.0"
71
78
  },
72
79
  "files": [
73
80
  "lib/",
74
81
  "images/",
82
+ "assets/",
75
83
  "cordis.patch.yml",
76
84
  "README.md",
77
85
  "CHANGELOG.md",
78
86
  "LICENSE"
79
87
  ]
80
88
  }
89
+