@openfairygui/cli 0.2.0-alpha.36 → 0.2.0-alpha.37

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +35 -8
  2. package/package.json +4 -4
package/dist/cli.mjs CHANGED
@@ -9503,6 +9503,11 @@ const preserveOrderParser = new XMLParser({
9503
9503
  ...defaultOptions,
9504
9504
  preserveOrder: true
9505
9505
  });
9506
+ const rawPreserveOrderParser = new XMLParser({
9507
+ ...defaultOptions,
9508
+ preserveOrder: true,
9509
+ trimValues: false
9510
+ });
9506
9511
  function escapeXmlAttr(value) {
9507
9512
  return String(value).replace(/&/g, "&amp;").replace(/\r\n/g, "&#xA;").replace(/[\r\n]/g, "&#xA;").replace(/\t/g, "&#x9;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
9508
9513
  }
@@ -9521,6 +9526,9 @@ function parseXML(xml) {
9521
9526
  function parseXMLPreserveOrder(xml) {
9522
9527
  return preserveOrderParser.parse(xml);
9523
9528
  }
9529
+ function parseXMLPreserveOrderRaw(xml) {
9530
+ return rawPreserveOrderParser.parse(xml);
9531
+ }
9524
9532
  function parseXYString(v) {
9525
9533
  if (!v) return [0, 0];
9526
9534
  const parts = v.split(",");
@@ -18298,38 +18306,57 @@ function appendOrderedValue(target, key, value) {
18298
18306
  }
18299
18307
  target[key] = [current, value];
18300
18308
  }
18301
- function normalizeOrderedChildren(entries) {
18309
+ function getOrderedElementEntries(entries) {
18310
+ return entries.filter((entry) => Object.keys(entry).some((key) => key !== ":@" && key !== "#text"));
18311
+ }
18312
+ function normalizeOrderedChildren(entries, rawEntries = []) {
18302
18313
  const out = {};
18303
- for (const entry of entries) {
18314
+ const elements = getOrderedElementEntries(entries);
18315
+ const rawElements = getOrderedElementEntries(rawEntries);
18316
+ for (const [index, entry] of elements.entries()) {
18304
18317
  const attrs = entry[":@"] ?? {};
18318
+ const rawEntry = rawElements[index] ?? {};
18319
+ const rawAttrs = rawEntry[":@"] ?? {};
18305
18320
  for (const [tagName, value] of Object.entries(entry)) {
18306
18321
  if (tagName === ":@" || tagName === "#text") continue;
18307
- const normalizedChildren = normalizeOrderedChildren(Array.isArray(value) ? value : []);
18308
- appendOrderedValue(out, tagName, Object.keys(normalizedChildren).length > 0 ? {
18322
+ const normalizedChildren = normalizeOrderedChildren(Array.isArray(value) ? value : [], Array.isArray(rawEntry[tagName]) ? rawEntry[tagName] : []);
18323
+ const normalizedAttrs = tagName === "property" && typeof rawAttrs.value === "string" ? {
18309
18324
  ...attrs,
18325
+ value: rawAttrs.value
18326
+ } : attrs;
18327
+ appendOrderedValue(out, tagName, Object.keys(normalizedChildren).length > 0 ? {
18328
+ ...normalizedAttrs,
18310
18329
  ...normalizedChildren
18311
- } : { ...attrs });
18330
+ } : { ...normalizedAttrs });
18312
18331
  }
18313
18332
  }
18314
18333
  return out;
18315
18334
  }
18316
18335
  function getOrderedDisplayListItems(xmlContent) {
18317
- const componentEntry = parseXMLPreserveOrder(xmlContent).find((entry) => "component" in entry);
18336
+ const ordered = parseXMLPreserveOrder(xmlContent);
18337
+ const rawOrdered = parseXMLPreserveOrderRaw(xmlContent);
18338
+ const componentEntry = ordered.find((entry) => "component" in entry);
18339
+ const rawComponentEntry = rawOrdered.find((entry) => "component" in entry);
18318
18340
  if (!componentEntry) return [];
18319
18341
  const displayListEntry = (Array.isArray(componentEntry.component) ? componentEntry.component : []).find((entry) => "displayList" in entry);
18342
+ const rawDisplayListEntry = (Array.isArray(rawComponentEntry?.component) ? rawComponentEntry.component : []).find((entry) => "displayList" in entry);
18320
18343
  if (!displayListEntry) return [];
18321
- return (Array.isArray(displayListEntry.displayList) ? displayListEntry.displayList : []).flatMap((entry) => {
18344
+ const displayListChildren = Array.isArray(displayListEntry.displayList) ? getOrderedElementEntries(displayListEntry.displayList) : [];
18345
+ const rawDisplayListChildren = Array.isArray(rawDisplayListEntry?.displayList) ? getOrderedElementEntries(rawDisplayListEntry.displayList) : [];
18346
+ return displayListChildren.flatMap((entry, index) => {
18322
18347
  const rawTagName = Object.keys(entry).find((key) => key !== ":@" && key !== "#text");
18323
18348
  if (!rawTagName) return [];
18324
18349
  const attrs = entry[":@"] ?? {};
18325
18350
  const nestedEntries = Array.isArray(entry[rawTagName]) ? entry[rawTagName] : [];
18351
+ const rawEntry = rawDisplayListChildren[index] ?? {};
18352
+ const rawNestedEntries = Array.isArray(rawEntry[rawTagName]) ? rawEntry[rawTagName] : [];
18326
18353
  const rawAttrs = readRawDisplayListAttrs(xmlContent, rawTagName, attrs.id);
18327
18354
  return [{
18328
18355
  tagName: rawTagName.toLowerCase(),
18329
18356
  attrs: {
18330
18357
  ...rawAttrs,
18331
18358
  ...attrs,
18332
- ...normalizeOrderedChildren(nestedEntries)
18359
+ ...normalizeOrderedChildren(nestedEntries, rawNestedEntries)
18333
18360
  }
18334
18361
  }];
18335
18362
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfairygui/cli",
3
- "version": "0.2.0-alpha.36",
3
+ "version": "0.2.0-alpha.37",
4
4
  "description": "FairyGUI Headless Authoring SDK — command-line interface.",
5
5
  "author": "OpenFairyGUI Contributors",
6
6
  "license": "MIT",
@@ -33,13 +33,13 @@
33
33
  "restore"
34
34
  ],
35
35
  "devDependencies": {
36
- "@openfairygui/functions": "0.2.0-alpha.36",
37
- "@openfairygui/core": "0.2.0-alpha.36"
36
+ "@openfairygui/functions": "0.2.0-alpha.37",
37
+ "@openfairygui/core": "0.2.0-alpha.37"
38
38
  },
39
39
  "dependencies": {
40
40
  "commander": "^14.0.2",
41
41
  "jiti": "^2.7.0",
42
- "@openfairygui/backend": "0.2.0-alpha.36"
42
+ "@openfairygui/backend": "0.2.0-alpha.37"
43
43
  },
44
44
  "optionalDependencies": {
45
45
  "sharp": ">=0.33.0"