@worldware/msg-cli 0.6.1 → 0.6.2

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.
@@ -4,10 +4,10 @@ import {
4
4
  } from "./chunk-Q775ZGC5.mjs";
5
5
  import {
6
6
  mf1MessageToPgsExport
7
- } from "./chunk-PQJA3H4Z.mjs";
7
+ } from "./chunk-QMSV2PP2.mjs";
8
8
  import {
9
9
  selectMessageToPgsExport
10
- } from "./chunk-HH6ZOHO4.mjs";
10
+ } from "./chunk-Z7H6FUD6.mjs";
11
11
  import {
12
12
  dynamicImportFromUrl
13
13
  } from "./chunk-KRQA4FRY.mjs";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  parsePgsSwitch,
3
3
  selectMessageDataToPgsExport
4
- } from "./chunk-HH6ZOHO4.mjs";
4
+ } from "./chunk-Z7H6FUD6.mjs";
5
5
 
6
6
  // src/lib/pgs-mf1.ts
7
7
  import { parse } from "@messageformat/parser";
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-Q775ZGC5.mjs";
4
4
  import {
5
5
  pgsImportToMf1Message
6
- } from "./chunk-PQJA3H4Z.mjs";
6
+ } from "./chunk-QMSV2PP2.mjs";
7
7
  import {
8
8
  pgsImportToSelectMessage
9
- } from "./chunk-HH6ZOHO4.mjs";
9
+ } from "./chunk-Z7H6FUD6.mjs";
10
10
  import {
11
11
  dynamicImportFromUrl
12
12
  } from "./chunk-KRQA4FRY.mjs";
@@ -89,7 +89,18 @@ async function importMsgProject(projectsDir, projectName) {
89
89
  }
90
90
  var xmlParser = new XMLParser({
91
91
  ignoreAttributes: false,
92
- attributeNamePrefix: "@_"
92
+ attributeNamePrefix: "@_",
93
+ // Keep segment content as raw XML: the default (non-order-preserving) mode
94
+ // groups mixed content by tag, scrambling text around inline elements.
95
+ // extractSegmentText re-parses it in document order.
96
+ stopNodes: ["*.source", "*.target"]
97
+ });
98
+ var inlineContentParser = new XMLParser({
99
+ ignoreAttributes: false,
100
+ attributeNamePrefix: "@_",
101
+ preserveOrder: true,
102
+ trimValues: false,
103
+ parseTagValue: false
93
104
  });
94
105
  function parseXliff20(xml) {
95
106
  try {
@@ -118,28 +129,39 @@ function categoryToNoteType(category) {
118
129
  function extractSegmentText(segment) {
119
130
  if (segment == null) return "";
120
131
  const seg = segment;
121
- const target = seg.target ?? seg.source;
122
- if (typeof target === "string") return target;
123
- if (target && typeof target === "object") {
124
- return extractInlineText(target);
125
- }
126
- return "";
132
+ const content = seg.target ?? seg.source;
133
+ const raw = content && typeof content === "object" ? content["#text"] : content;
134
+ if (typeof raw !== "string" || raw === "") return "";
135
+ const [root] = inlineContentParser.parse(`<c>${raw}</c>`);
136
+ return extractInlineText(root.c).trim();
137
+ }
138
+ function codePointFromHex(hex) {
139
+ const cp = /^[0-9a-f]{1,6}$/i.test(hex ?? "") ? parseInt(hex, 16) : NaN;
140
+ return cp <= 1114111 ? String.fromCodePoint(cp) : "\uFFFD";
127
141
  }
128
- function extractInlineText(node) {
142
+ function extractInlineText(nodes) {
129
143
  let text = "";
130
- if ("#text" in node && typeof node["#text"] === "string") {
131
- text += node["#text"];
132
- }
133
- const children = ["pc", "sc", "ec", "ph", "mrk", "sm", "em", "cp", "target", "source"];
134
- for (const tag of children) {
135
- const child = node[tag];
136
- if (Array.isArray(child)) {
137
- for (const c of child) {
138
- const childObj = typeof c === "object" && c !== null ? c : {};
139
- text += extractInlineText(childObj);
140
- }
141
- } else if (child && typeof child === "object") {
142
- text += extractInlineText(child);
144
+ for (const node of nodes) {
145
+ if ("#text" in node) {
146
+ text += String(node["#text"]);
147
+ continue;
148
+ }
149
+ const tag = Object.keys(node).find((k) => k !== ":@");
150
+ const attrs = node[":@"] ?? {};
151
+ switch (tag) {
152
+ case "ph":
153
+ case "sc":
154
+ case "ec":
155
+ text += attrs["@_equiv"] ?? attrs["@_disp"] ?? "";
156
+ break;
157
+ case "cp":
158
+ text += codePointFromHex(attrs["@_hex"]);
159
+ break;
160
+ case "sm":
161
+ case "em":
162
+ break;
163
+ default:
164
+ if (tag) text += extractInlineText(node[tag]);
143
165
  }
144
166
  }
145
167
  return text;
@@ -39,9 +39,7 @@ function getFunctionName(expr) {
39
39
  return expr.functionRef?.name;
40
40
  }
41
41
  function getOption(opts, key) {
42
- if (!opts) return void 0;
43
- if (opts instanceof Map) return opts.get(key);
44
- return opts[key];
42
+ return opts?.[key];
45
43
  }
46
44
  function getSelectOptionOrdinal(expr) {
47
45
  const sel = getOption(expr.functionRef?.options, "select");
@@ -183,9 +181,7 @@ function pgsImportToSelectMessage(switchAttr, segments) {
183
181
  }
184
182
  });
185
183
  } else if (kind === "ordinal") {
186
- const opts = /* @__PURE__ */ new Map([
187
- ["select", { type: "literal", value: "ordinal" }]
188
- ]);
184
+ const opts = { select: { type: "literal", value: "ordinal" } };
189
185
  declarations.push({
190
186
  type: "input",
191
187
  name,
@@ -171,9 +171,7 @@ function getFunctionName(expr) {
171
171
  return expr.functionRef?.name;
172
172
  }
173
173
  function getOption(opts, key) {
174
- if (!opts) return void 0;
175
- if (opts instanceof Map) return opts.get(key);
176
- return opts[key];
174
+ return opts?.[key];
177
175
  }
178
176
  function getSelectOptionOrdinal(expr) {
179
177
  const sel = getOption(expr.functionRef?.options, "select");
@@ -5,10 +5,10 @@ import {
5
5
  importMsgResourcesFromPaths,
6
6
  serializeResourceGroupsToXliff,
7
7
  writeXliffFiles
8
- } from "../chunk-WGI2EFOS.mjs";
8
+ } from "../chunk-HZHAP6XM.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
- import "../chunk-PQJA3H4Z.mjs";
11
- import "../chunk-HH6ZOHO4.mjs";
10
+ import "../chunk-QMSV2PP2.mjs";
11
+ import "../chunk-Z7H6FUD6.mjs";
12
12
  import "../chunk-KRQA4FRY.mjs";
13
13
  import {
14
14
  loadPackageJsonForMsg
@@ -200,9 +200,7 @@ function pgsImportToSelectMessage(switchAttr, segments) {
200
200
  }
201
201
  });
202
202
  } else if (kind === "ordinal") {
203
- const opts = /* @__PURE__ */ new Map([
204
- ["select", { type: "literal", value: "ordinal" }]
205
- ]);
203
+ const opts = { select: { type: "literal", value: "ordinal" } };
206
204
  declarations.push({
207
205
  type: "input",
208
206
  name,
@@ -443,7 +441,18 @@ async function importMsgProject(projectsDir, projectName) {
443
441
  }
444
442
  var xmlParser = new import_fast_xml_parser.XMLParser({
445
443
  ignoreAttributes: false,
446
- attributeNamePrefix: "@_"
444
+ attributeNamePrefix: "@_",
445
+ // Keep segment content as raw XML: the default (non-order-preserving) mode
446
+ // groups mixed content by tag, scrambling text around inline elements.
447
+ // extractSegmentText re-parses it in document order.
448
+ stopNodes: ["*.source", "*.target"]
449
+ });
450
+ var inlineContentParser = new import_fast_xml_parser.XMLParser({
451
+ ignoreAttributes: false,
452
+ attributeNamePrefix: "@_",
453
+ preserveOrder: true,
454
+ trimValues: false,
455
+ parseTagValue: false
447
456
  });
448
457
  function parseXliff20(xml) {
449
458
  try {
@@ -472,28 +481,39 @@ function categoryToNoteType(category) {
472
481
  function extractSegmentText(segment) {
473
482
  if (segment == null) return "";
474
483
  const seg = segment;
475
- const target = seg.target ?? seg.source;
476
- if (typeof target === "string") return target;
477
- if (target && typeof target === "object") {
478
- return extractInlineText(target);
479
- }
480
- return "";
484
+ const content = seg.target ?? seg.source;
485
+ const raw = content && typeof content === "object" ? content["#text"] : content;
486
+ if (typeof raw !== "string" || raw === "") return "";
487
+ const [root] = inlineContentParser.parse(`<c>${raw}</c>`);
488
+ return extractInlineText(root.c).trim();
489
+ }
490
+ function codePointFromHex(hex) {
491
+ const cp = /^[0-9a-f]{1,6}$/i.test(hex ?? "") ? parseInt(hex, 16) : NaN;
492
+ return cp <= 1114111 ? String.fromCodePoint(cp) : "\uFFFD";
481
493
  }
482
- function extractInlineText(node) {
494
+ function extractInlineText(nodes) {
483
495
  let text = "";
484
- if ("#text" in node && typeof node["#text"] === "string") {
485
- text += node["#text"];
486
- }
487
- const children = ["pc", "sc", "ec", "ph", "mrk", "sm", "em", "cp", "target", "source"];
488
- for (const tag of children) {
489
- const child = node[tag];
490
- if (Array.isArray(child)) {
491
- for (const c of child) {
492
- const childObj = typeof c === "object" && c !== null ? c : {};
493
- text += extractInlineText(childObj);
494
- }
495
- } else if (child && typeof child === "object") {
496
- text += extractInlineText(child);
496
+ for (const node of nodes) {
497
+ if ("#text" in node) {
498
+ text += String(node["#text"]);
499
+ continue;
500
+ }
501
+ const tag = Object.keys(node).find((k) => k !== ":@");
502
+ const attrs = node[":@"] ?? {};
503
+ switch (tag) {
504
+ case "ph":
505
+ case "sc":
506
+ case "ec":
507
+ text += attrs["@_equiv"] ?? attrs["@_disp"] ?? "";
508
+ break;
509
+ case "cp":
510
+ text += codePointFromHex(attrs["@_hex"]);
511
+ break;
512
+ case "sm":
513
+ case "em":
514
+ break;
515
+ default:
516
+ if (tag) text += extractInlineText(node[tag]);
497
517
  }
498
518
  }
499
519
  return text;
@@ -5,10 +5,10 @@ import {
5
5
  parseXliffFilename,
6
6
  processXliffFile,
7
7
  writeTranslationFiles
8
- } from "../chunk-3MCULZ7L.mjs";
8
+ } from "../chunk-WOGVKE3R.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
- import "../chunk-PQJA3H4Z.mjs";
11
- import "../chunk-HH6ZOHO4.mjs";
10
+ import "../chunk-QMSV2PP2.mjs";
11
+ import "../chunk-Z7H6FUD6.mjs";
12
12
  import "../chunk-KRQA4FRY.mjs";
13
13
  import {
14
14
  loadPackageJsonForMsg
@@ -108,9 +108,7 @@ function getFunctionName(expr) {
108
108
  return expr.functionRef?.name;
109
109
  }
110
110
  function getOption(opts, key) {
111
- if (!opts) return void 0;
112
- if (opts instanceof Map) return opts.get(key);
113
- return opts[key];
111
+ return opts?.[key];
114
112
  }
115
113
  function getSelectOptionOrdinal(expr) {
116
114
  const sel = getOption(expr.functionRef?.options, "select");
@@ -5,10 +5,10 @@ import {
5
5
  importMsgResourcesFromPaths,
6
6
  serializeResourceGroupsToXliff,
7
7
  writeXliffFiles
8
- } from "../chunk-WGI2EFOS.mjs";
8
+ } from "../chunk-HZHAP6XM.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
- import "../chunk-PQJA3H4Z.mjs";
11
- import "../chunk-HH6ZOHO4.mjs";
10
+ import "../chunk-QMSV2PP2.mjs";
11
+ import "../chunk-Z7H6FUD6.mjs";
12
12
  import "../chunk-KRQA4FRY.mjs";
13
13
  import "../chunk-F7XZRKP7.mjs";
14
14
  export {
@@ -141,9 +141,7 @@ function pgsImportToSelectMessage(switchAttr, segments) {
141
141
  }
142
142
  });
143
143
  } else if (kind === "ordinal") {
144
- const opts = /* @__PURE__ */ new Map([
145
- ["select", { type: "literal", value: "ordinal" }]
146
- ]);
144
+ const opts = { select: { type: "literal", value: "ordinal" } };
147
145
  declarations.push({
148
146
  type: "input",
149
147
  name,
@@ -384,7 +382,18 @@ async function importMsgProject(projectsDir, projectName) {
384
382
  }
385
383
  var xmlParser = new import_fast_xml_parser.XMLParser({
386
384
  ignoreAttributes: false,
387
- attributeNamePrefix: "@_"
385
+ attributeNamePrefix: "@_",
386
+ // Keep segment content as raw XML: the default (non-order-preserving) mode
387
+ // groups mixed content by tag, scrambling text around inline elements.
388
+ // extractSegmentText re-parses it in document order.
389
+ stopNodes: ["*.source", "*.target"]
390
+ });
391
+ var inlineContentParser = new import_fast_xml_parser.XMLParser({
392
+ ignoreAttributes: false,
393
+ attributeNamePrefix: "@_",
394
+ preserveOrder: true,
395
+ trimValues: false,
396
+ parseTagValue: false
388
397
  });
389
398
  function parseXliff20(xml) {
390
399
  try {
@@ -413,28 +422,39 @@ function categoryToNoteType(category) {
413
422
  function extractSegmentText(segment) {
414
423
  if (segment == null) return "";
415
424
  const seg = segment;
416
- const target = seg.target ?? seg.source;
417
- if (typeof target === "string") return target;
418
- if (target && typeof target === "object") {
419
- return extractInlineText(target);
420
- }
421
- return "";
425
+ const content = seg.target ?? seg.source;
426
+ const raw = content && typeof content === "object" ? content["#text"] : content;
427
+ if (typeof raw !== "string" || raw === "") return "";
428
+ const [root] = inlineContentParser.parse(`<c>${raw}</c>`);
429
+ return extractInlineText(root.c).trim();
430
+ }
431
+ function codePointFromHex(hex) {
432
+ const cp = /^[0-9a-f]{1,6}$/i.test(hex ?? "") ? parseInt(hex, 16) : NaN;
433
+ return cp <= 1114111 ? String.fromCodePoint(cp) : "\uFFFD";
422
434
  }
423
- function extractInlineText(node) {
435
+ function extractInlineText(nodes) {
424
436
  let text = "";
425
- if ("#text" in node && typeof node["#text"] === "string") {
426
- text += node["#text"];
427
- }
428
- const children = ["pc", "sc", "ec", "ph", "mrk", "sm", "em", "cp", "target", "source"];
429
- for (const tag of children) {
430
- const child = node[tag];
431
- if (Array.isArray(child)) {
432
- for (const c of child) {
433
- const childObj = typeof c === "object" && c !== null ? c : {};
434
- text += extractInlineText(childObj);
435
- }
436
- } else if (child && typeof child === "object") {
437
- text += extractInlineText(child);
437
+ for (const node of nodes) {
438
+ if ("#text" in node) {
439
+ text += String(node["#text"]);
440
+ continue;
441
+ }
442
+ const tag = Object.keys(node).find((k) => k !== ":@");
443
+ const attrs = node[":@"] ?? {};
444
+ switch (tag) {
445
+ case "ph":
446
+ case "sc":
447
+ case "ec":
448
+ text += attrs["@_equiv"] ?? attrs["@_disp"] ?? "";
449
+ break;
450
+ case "cp":
451
+ text += codePointFromHex(attrs["@_hex"]);
452
+ break;
453
+ case "sm":
454
+ case "em":
455
+ break;
456
+ default:
457
+ if (tag) text += extractInlineText(node[tag]);
438
458
  }
439
459
  }
440
460
  return text;
@@ -9,10 +9,10 @@ import {
9
9
  processXliffFile,
10
10
  writeTranslationFiles,
11
11
  xliffDirSegments
12
- } from "../chunk-3MCULZ7L.mjs";
12
+ } from "../chunk-WOGVKE3R.mjs";
13
13
  import "../chunk-Q775ZGC5.mjs";
14
- import "../chunk-PQJA3H4Z.mjs";
15
- import "../chunk-HH6ZOHO4.mjs";
14
+ import "../chunk-QMSV2PP2.mjs";
15
+ import "../chunk-Z7H6FUD6.mjs";
16
16
  import "../chunk-KRQA4FRY.mjs";
17
17
  import "../chunk-F7XZRKP7.mjs";
18
18
  export {
@@ -62,9 +62,7 @@ function getFunctionName(expr) {
62
62
  return expr.functionRef?.name;
63
63
  }
64
64
  function getOption(opts, key) {
65
- if (!opts) return void 0;
66
- if (opts instanceof Map) return opts.get(key);
67
- return opts[key];
65
+ return opts?.[key];
68
66
  }
69
67
  function getSelectOptionOrdinal(expr) {
70
68
  const sel = getOption(expr.functionRef?.options, "select");
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  mf1MessageToPgsExport,
3
3
  pgsImportToMf1Message
4
- } from "../chunk-PQJA3H4Z.mjs";
5
- import "../chunk-HH6ZOHO4.mjs";
4
+ } from "../chunk-QMSV2PP2.mjs";
5
+ import "../chunk-Z7H6FUD6.mjs";
6
6
  export {
7
7
  mf1MessageToPgsExport,
8
8
  pgsImportToMf1Message
@@ -63,9 +63,7 @@ function getFunctionName(expr) {
63
63
  return expr.functionRef?.name;
64
64
  }
65
65
  function getOption(opts, key) {
66
- if (!opts) return void 0;
67
- if (opts instanceof Map) return opts.get(key);
68
- return opts[key];
66
+ return opts?.[key];
69
67
  }
70
68
  function getSelectOptionOrdinal(expr) {
71
69
  const sel = getOption(expr.functionRef?.options, "select");
@@ -207,9 +205,7 @@ function pgsImportToSelectMessage(switchAttr, segments) {
207
205
  }
208
206
  });
209
207
  } else if (kind === "ordinal") {
210
- const opts = /* @__PURE__ */ new Map([
211
- ["select", { type: "literal", value: "ordinal" }]
212
- ]);
208
+ const opts = { select: { type: "literal", value: "ordinal" } };
213
209
  declarations.push({
214
210
  type: "input",
215
211
  name,
@@ -3,7 +3,7 @@
3
3
  * (`pgs:switch` / `pgs:case`, urn:oasis:names:tc:xliff:pgs:1.0).
4
4
  *
5
5
  * Ordinal vs cardinal :number uses the `select` option passed to PluralRules
6
- * (`select=ordinal` in MF2 syntax → options Map key `select`, literal `ordinal`).
6
+ * (`select=ordinal` in MF2 syntax → options key `select`, literal `ordinal`).
7
7
  */
8
8
  /** PGS selector keywords (XLIFF 2.2 Extended Part 2 §4.9). */
9
9
  type PgsSelectorKind = "plural" | "ordinal" | "gender" | "select";
@@ -3,7 +3,7 @@
3
3
  * (`pgs:switch` / `pgs:case`, urn:oasis:names:tc:xliff:pgs:1.0).
4
4
  *
5
5
  * Ordinal vs cardinal :number uses the `select` option passed to PluralRules
6
- * (`select=ordinal` in MF2 syntax → options Map key `select`, literal `ordinal`).
6
+ * (`select=ordinal` in MF2 syntax → options key `select`, literal `ordinal`).
7
7
  */
8
8
  /** PGS selector keywords (XLIFF 2.2 Extended Part 2 §4.9). */
9
9
  type PgsSelectorKind = "plural" | "ordinal" | "gender" | "select";
@@ -7,7 +7,7 @@ import {
7
7
  pgsTokenToMf2Key,
8
8
  selectMessageDataToPgsExport,
9
9
  selectMessageToPgsExport
10
- } from "../chunk-HH6ZOHO4.mjs";
10
+ } from "../chunk-Z7H6FUD6.mjs";
11
11
  export {
12
12
  classifySelectMessageForPgs,
13
13
  messagesStructurallyEqual,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldware/msg-cli",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "CLI for msg library",
5
5
  "main": "dist/commands/init.cjs",
6
6
  "module": "dist/commands/init.mjs",