@openfairygui/cli 0.2.0 → 0.2.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.
package/dist/cli.mjs CHANGED
@@ -864,7 +864,7 @@ var ExtensibleProperty = class extends Property {
864
864
  };
865
865
  //#endregion
866
866
  //#region ../core/src/constants.ts
867
- const VERSION = `v0.2.0`;
867
+ const VERSION = `v0.2.2`;
868
868
  /** Binary package file magic number: "FGUI" as uint32. */
869
869
  const FGUI_MAGIC = 1179080009;
870
870
  /** Null string index in the binary string table. */
@@ -19463,6 +19463,17 @@ function formatTrimmedFixed$1(value, precision = 2) {
19463
19463
  if (precision === 0) return value.toFixed(0);
19464
19464
  return value.toFixed(precision).replace(/(?:\.0+|(\.\d*?[1-9])0+)$/, "$1");
19465
19465
  }
19466
+ const INT32_MIN = -2147483648;
19467
+ const INT32_MAX = 2147483647;
19468
+ function formatProjectInt32(value, field = "project XML integer") {
19469
+ if (!Number.isFinite(value)) throw new Error(`${field} must be finite.`);
19470
+ const normalized = Math.trunc(value);
19471
+ if (normalized < INT32_MIN || normalized > INT32_MAX) throw new Error(`${field} must fit a signed 32-bit integer.`);
19472
+ return Object.is(normalized, -0) ? "0" : String(normalized);
19473
+ }
19474
+ function formatProjectInt32List(values, field) {
19475
+ return values.map((value) => formatProjectInt32(value, field)).join(",");
19476
+ }
19466
19477
  function formatDisplayAlpha(value) {
19467
19478
  return formatTrimmedFixed$1(value, 2);
19468
19479
  }
@@ -19520,7 +19531,7 @@ function normalizeGearSizeSegment(segment, fixedScale, omitIdentityScale) {
19520
19531
  if (!segment || segment === "-") return segment;
19521
19532
  const parts = segment.split(",");
19522
19533
  if (parts.length < 2) return segment;
19523
- const normalized = [String(Math.trunc(Number(parts[0] ?? 0))), String(Math.trunc(Number(parts[1] ?? 0)))];
19534
+ const normalized = [formatProjectInt32(Number(parts[0] ?? 0), "gearSize width"), formatProjectInt32(Number(parts[1] ?? 0), "gearSize height")];
19524
19535
  if (parts.length >= 4) {
19525
19536
  if (omitIdentityScale && isIdentityGearSizeScale(segment)) return normalized.join(",");
19526
19537
  const scaleFormatter = fixedScale ? (value) => {
@@ -19531,12 +19542,23 @@ function normalizeGearSizeSegment(segment, fixedScale, omitIdentityScale) {
19531
19542
  }
19532
19543
  return normalized.join(",");
19533
19544
  }
19545
+ function normalizeGearXYSegment(segment) {
19546
+ if (!segment || segment === "-") return segment;
19547
+ const parts = segment.split(",");
19548
+ if (parts.length < 2) return segment;
19549
+ return [
19550
+ formatProjectInt32(Number(parts[0] ?? 0), "gearXY x"),
19551
+ formatProjectInt32(Number(parts[1] ?? 0), "gearXY y"),
19552
+ ...parts.slice(2)
19553
+ ].join(",");
19554
+ }
19534
19555
  function shouldCompactTextGearColor(ownerType, ownerName) {
19535
19556
  return (ownerType === "GTextField" || ownerType === "GRichTextField" || ownerType === "GTextInput") && ownerName === "title";
19536
19557
  }
19537
19558
  function normalizeGearXmlValue(gearType, value, ownerType, ownerName, gear) {
19538
19559
  const raw = String(value ?? "");
19539
19560
  switch (gearType) {
19561
+ case GearType.XY: return raw.split("|").map((segment) => normalizeGearXYSegment(segment)).join("|");
19540
19562
  case GearType.Size: {
19541
19563
  const fixedScale = !gear?.getTween();
19542
19564
  const segments = raw.split("|");
@@ -19556,10 +19578,10 @@ function normalizeGearXmlValue(gearType, value, ownerType, ownerName, gear) {
19556
19578
  }
19557
19579
  function writeCommonDisplayState(target, object, protocol) {
19558
19580
  const specs = protocol.attrs;
19559
- if (specs.xy) writeXmlAttr(target, specs.xy, `${object.getX?.() ?? 0},${object.getY?.() ?? 0}`);
19581
+ if (specs.xy) writeXmlAttr(target, specs.xy, formatProjectInt32List([object.getX?.() ?? 0, object.getY?.() ?? 0], "display object xy"));
19560
19582
  const width = object.getWidth?.() ?? 0;
19561
19583
  const height = object.getHeight?.() ?? 0;
19562
- if (specs.size && (width !== 0 || height !== 0)) writeXmlAttr(target, specs.size, `${width},${height}`);
19584
+ if (specs.size && (width !== 0 || height !== 0)) writeXmlAttr(target, specs.size, formatProjectInt32List([width, height], "display object size"));
19563
19585
  if (specs.locked && object.getLocked?.()) writeXmlAttr(target, specs.locked, "true");
19564
19586
  const restrictSize = [
19565
19587
  object.getMinWidth?.() ?? 0,
@@ -19567,7 +19589,7 @@ function writeCommonDisplayState(target, object, protocol) {
19567
19589
  object.getMinHeight?.() ?? 0,
19568
19590
  object.getMaxHeight?.() ?? 0
19569
19591
  ];
19570
- if (specs.restrictSize && restrictSize.some((value) => value !== 0)) writeXmlAttr(target, specs.restrictSize, restrictSize.join(","));
19592
+ if (specs.restrictSize && restrictSize.some((value) => value !== 0)) writeXmlAttr(target, specs.restrictSize, formatProjectInt32List(restrictSize, "display object restrictSize"));
19571
19593
  if (specs.aspect && object.getAspect?.()) writeXmlAttr(target, specs.aspect, "true");
19572
19594
  const pivotX = object.getPivotX?.() ?? 0;
19573
19595
  const pivotY = object.getPivotY?.() ?? 0;
@@ -19597,8 +19619,13 @@ function writeCommonDisplayState(target, object, protocol) {
19597
19619
  function hasNonZeroInsets(value) {
19598
19620
  return !!value && !!(value.top || value.bottom || value.left || value.right);
19599
19621
  }
19600
- function formatInsets(value) {
19601
- return `${value.top ?? 0},${value.bottom ?? 0},${value.left ?? 0},${value.right ?? 0}`;
19622
+ function formatInsets(value, field = "margin") {
19623
+ return formatProjectInt32List([
19624
+ value.top ?? 0,
19625
+ value.bottom ?? 0,
19626
+ value.left ?? 0,
19627
+ value.right ?? 0
19628
+ ], field);
19602
19629
  }
19603
19630
  function formatFillMethod(fillMethod) {
19604
19631
  return {
@@ -20116,7 +20143,7 @@ function serializeChild(obj) {
20116
20143
  const scrollBarFlags = typedObj.getScrollBarFlags?.() ?? 0;
20117
20144
  if (scrollBarFlags !== 0) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.scrollBarFlags, String(scrollBarFlags));
20118
20145
  const scrollBarMargin = typedObj.getScrollBarMargin?.();
20119
- if (hasNonZeroInsets(scrollBarMargin)) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.scrollBarMargin, formatInsets(scrollBarMargin));
20146
+ if (hasNonZeroInsets(scrollBarMargin)) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.scrollBarMargin, formatInsets(scrollBarMargin, "list scrollBarMargin"));
20120
20147
  const vtScrollBarRes = typedObj.getVtScrollBarRes?.() ?? "";
20121
20148
  const hzScrollBarRes = typedObj.getHzScrollBarRes?.() ?? "";
20122
20149
  if (vtScrollBarRes || hzScrollBarRes) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.scrollBarRes, `${vtScrollBarRes},${hzScrollBarRes}`);
@@ -20124,9 +20151,9 @@ function serializeChild(obj) {
20124
20151
  const footerRes = typedObj.getFooterRes?.() ?? "";
20125
20152
  if (headerRes || footerRes) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.ptrRes, `${headerRes},${footerRes}`);
20126
20153
  const margin = typedObj.getMargin?.();
20127
- if (hasNonZeroInsets(margin)) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.margin, formatInsets(margin));
20154
+ if (hasNonZeroInsets(margin)) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.margin, formatInsets(margin, "list margin"));
20128
20155
  const clipSoftness = typedObj.getClipSoftness?.();
20129
- if (clipSoftness && ((clipSoftness.x ?? 0) !== 0 || (clipSoftness.y ?? 0) !== 0)) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.clipSoftness, `${clipSoftness.x ?? 0},${clipSoftness.y ?? 0}`);
20156
+ if (clipSoftness && ((clipSoftness.x ?? 0) !== 0 || (clipSoftness.y ?? 0) !== 0)) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.clipSoftness, formatProjectInt32List([clipSoftness.x ?? 0, clipSoftness.y ?? 0], "list clipSoftness"));
20130
20157
  if (typedObj.getScrollItemToViewOnClick?.() === false) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.scrollItemToViewOnClick, "false");
20131
20158
  if (typedObj.getFoldInvisibleItems?.() === true) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.foldInvisibleItems, "true");
20132
20159
  if (typedObj.getAutoClearItems?.() === true) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.autoClearItems, "true");
@@ -20368,7 +20395,7 @@ async function writeComponent(fs, comp, pkgDir, sourceRelativePath) {
20368
20395
  await fs.mkdir(fs.dirname(targetPath));
20369
20396
  const compAttrs = {};
20370
20397
  const [w, h] = [typedComp.getWidth?.() ?? 0, typedComp.getHeight?.() ?? 0];
20371
- if (w || h) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.size, `${w},${h}`);
20398
+ if (w || h) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.size, formatProjectInt32List([w, h], "component size"));
20372
20399
  const [pivotX, pivotY] = [typedComp.getPivotX?.() ?? 0, typedComp.getPivotY?.() ?? 0];
20373
20400
  if (pivotX !== 0 || pivotY !== 0) {
20374
20401
  writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.pivot, `${pivotX},${pivotY}`);
@@ -20381,14 +20408,14 @@ async function writeComponent(fs, comp, pkgDir, sourceRelativePath) {
20381
20408
  2: "scroll"
20382
20409
  }[overflow] ?? "visible");
20383
20410
  const margin = typedComp.getMargin?.();
20384
- if (hasNonZeroInsets(margin)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.margin, formatInsets(margin));
20411
+ if (hasNonZeroInsets(margin)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.margin, formatInsets(margin, "component margin"));
20385
20412
  const restrictSize = [
20386
20413
  typedComp.getMinWidth?.() ?? 0,
20387
20414
  typedComp.getMaxWidth?.() ?? 0,
20388
20415
  typedComp.getMinHeight?.() ?? 0,
20389
20416
  typedComp.getMaxHeight?.() ?? 0
20390
20417
  ];
20391
- if (restrictSize.some((value) => value !== 0)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.restrictSize, restrictSize.join(","));
20418
+ if (restrictSize.some((value) => value !== 0)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.restrictSize, formatProjectInt32List(restrictSize, "component restrictSize"));
20392
20419
  if (typedComp.getBgColorEnabled?.()) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.bgColorEnabled, "true");
20393
20420
  const bgColor = typedComp.getBgColor?.();
20394
20421
  if (bgColor) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.bgColor, bgColor);
@@ -20397,9 +20424,9 @@ async function writeComponent(fs, comp, pkgDir, sourceRelativePath) {
20397
20424
  const designImageLayer = typedComp.getDesignImageLayer?.() ?? 0;
20398
20425
  if (designImageLayer !== 0) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.designImageLayer, String(designImageLayer));
20399
20426
  const designImageOffsetX = typedComp.getDesignImageOffsetX?.() ?? 0;
20400
- if (designImageOffsetX !== 0) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.designImageOffsetX, String(designImageOffsetX));
20427
+ if (designImageOffsetX !== 0) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.designImageOffsetX, formatProjectInt32(designImageOffsetX, "designImageOffsetX"));
20401
20428
  const designImageOffsetY = typedComp.getDesignImageOffsetY?.() ?? 0;
20402
- if (designImageOffsetY !== 0) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.designImageOffsetY, String(designImageOffsetY));
20429
+ if (designImageOffsetY !== 0) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.designImageOffsetY, formatProjectInt32(designImageOffsetY, "designImageOffsetY"));
20403
20430
  const idNum = typedComp.getIdNum?.() ?? 0;
20404
20431
  if (idNum !== 0) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.idnum, String(idNum));
20405
20432
  const initName = typedComp.getInitName?.();
@@ -20407,7 +20434,7 @@ async function writeComponent(fs, comp, pkgDir, sourceRelativePath) {
20407
20434
  const remark = typedComp.getRemark?.();
20408
20435
  if (remark) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.remark, remark);
20409
20436
  const clipSoftness = typedComp.getClipSoftness?.();
20410
- if (clipSoftness && ((clipSoftness.x ?? 0) !== 0 || (clipSoftness.y ?? 0) !== 0)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.clipSoftness, `${clipSoftness.x ?? 0},${clipSoftness.y ?? 0}`);
20437
+ if (clipSoftness && ((clipSoftness.x ?? 0) !== 0 || (clipSoftness.y ?? 0) !== 0)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.clipSoftness, formatProjectInt32List([clipSoftness.x ?? 0, clipSoftness.y ?? 0], "component clipSoftness"));
20411
20438
  if (typedComp.getOpaque?.() === false) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.opaque, "false");
20412
20439
  const mask = typedComp.getMask?.();
20413
20440
  if (mask) {
@@ -20437,7 +20464,7 @@ async function writeComponent(fs, comp, pkgDir, sourceRelativePath) {
20437
20464
  const scrollBarFlags = typedComp.getScrollBarFlags?.() ?? 0;
20438
20465
  if (scrollBarFlags !== 0) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.scrollBarFlags, String(scrollBarFlags));
20439
20466
  const scrollBarMargin = typedComp.getScrollBarMargin?.();
20440
- if (hasNonZeroInsets(scrollBarMargin)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.scrollBarMargin, formatInsets(scrollBarMargin));
20467
+ if (hasNonZeroInsets(scrollBarMargin)) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.scrollBarMargin, formatInsets(scrollBarMargin, "component scrollBarMargin"));
20441
20468
  const vtScrollBarRes = typedComp.getVtScrollBarRes?.() ?? "";
20442
20469
  const hzScrollBarRes = typedComp.getHzScrollBarRes?.() ?? "";
20443
20470
  if (vtScrollBarRes || hzScrollBarRes) writeXmlAttr(compAttrs, PROJECT_XML_PROTOCOL.componentRoot.attrs.scrollBarRes, `${vtScrollBarRes},${hzScrollBarRes}`);
@@ -28700,14 +28727,15 @@ function resolvePublishOptions(doc, overrides = {}) {
28700
28727
  const root = doc.getRoot();
28701
28728
  const publishSettings = (root.getSettings?.() ?? {}).publish ?? {};
28702
28729
  const atlasSetting = publishSettings.atlasSetting ?? {};
28703
- const projectType = root.getProjectType();
28704
- const fileExtension = overrides.fileExtension ?? resolveDefaultPublishFileExtension(projectType, publishSettings);
28730
+ const projectType = overrides.targetProjectType ?? root.getProjectType();
28731
+ const explicitLayaboxTarget = overrides.targetProjectType === ProjectType.LayaBox;
28732
+ const fileExtension = overrides.fileExtension ?? (explicitLayaboxTarget ? "fui" : resolveDefaultPublishFileExtension(projectType, publishSettings));
28705
28733
  let compressed = overrides.compressed ?? publishSettings.compressDesc ?? false;
28706
28734
  if (projectType === UNITY_PROJECT_TYPE) compressed = overrides.compressed ?? false;
28707
28735
  const atlasOptions = {
28708
28736
  maxSize: overrides.atlas?.maxSize ?? atlasSetting.maxSize ?? 2048,
28709
28737
  fast: overrides.atlas?.fast ?? atlasSetting.fast ?? true,
28710
- allowRotation: overrides.atlas?.allowRotation ?? atlasSetting.allowRotation ?? false,
28738
+ allowRotation: overrides.atlas?.allowRotation ?? (explicitLayaboxTarget ? false : atlasSetting.allowRotation ?? false),
28711
28739
  padding: overrides.atlas?.padding ?? atlasSetting.padding ?? 2,
28712
28740
  powerOfTwo: overrides.atlas?.powerOfTwo ?? atlasSetting.sizeOption === "pot",
28713
28741
  square: overrides.atlas?.square ?? atlasSetting.forceSquare ?? false,
@@ -29382,7 +29410,8 @@ function registerPublishCommand(program) {
29382
29410
  const pkgFilter = options.packages?.split(",").map((value) => value.trim());
29383
29411
  const resolved = resolvePublishOptions(doc, {
29384
29412
  compressed: options.compressed,
29385
- packages: pkgFilter
29413
+ packages: pkgFilter,
29414
+ targetProjectType: projectType
29386
29415
  });
29387
29416
  console.log(`Settings: ext=${resolved.fileExtension}, compressed=${resolved.compressed}`);
29388
29417
  if (options.branch) console.log(`Active branch: ${options.branch}`);
@@ -29425,7 +29454,7 @@ function registerRestoreCommand(program) {
29425
29454
  //#region src/utils/package-version.ts
29426
29455
  const require$1 = createRequire(import.meta.url);
29427
29456
  function getInjectedPackageVersion() {
29428
- const version = "0.2.0";
29457
+ const version = "0.2.2";
29429
29458
  return typeof version === "string" && true ? version : null;
29430
29459
  }
29431
29460
  function readPackageVersion() {
@@ -29453,7 +29482,7 @@ function createProgram() {
29453
29482
  " openfairygui",
29454
29483
  "",
29455
29484
  "Input can be a .fairy file or a project root directory (auto-discovers .fairy file).",
29456
- "File extension and binary format are read from project settings."
29485
+ "Publish settings are read from the project; --project-type applies target-specific output rules."
29457
29486
  ].join("\n"));
29458
29487
  return program;
29459
29488
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfairygui/cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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/core": "0.2.0",
37
- "@openfairygui/functions": "0.2.0"
36
+ "@openfairygui/core": "0.2.2",
37
+ "@openfairygui/functions": "0.2.2"
38
38
  },
39
39
  "dependencies": {
40
40
  "commander": "^14.0.2",
41
41
  "jiti": "^2.7.0",
42
- "@openfairygui/backend": "0.2.0"
42
+ "@openfairygui/backend": "0.2.2"
43
43
  },
44
44
  "optionalDependencies": {
45
45
  "sharp": ">=0.33.0"
package/src/cli.ts CHANGED
@@ -25,7 +25,7 @@ function createProgram(): Command {
25
25
  ' openfairygui',
26
26
  '',
27
27
  'Input can be a .fairy file or a project root directory (auto-discovers .fairy file).',
28
- 'File extension and binary format are read from project settings.',
28
+ 'Publish settings are read from the project; --project-type applies target-specific output rules.',
29
29
  ].join('\n'),
30
30
  );
31
31
 
@@ -1,8 +1,8 @@
1
- import type { Command } from 'commander';
1
+ import path from 'node:path';
2
2
  import { NodeIO } from '@openfairygui/core/node';
3
3
  import { resolvePublishOptions } from '@openfairygui/functions';
4
4
  import { publishNode } from '@openfairygui/functions/node';
5
- import path from 'node:path';
5
+ import type { Command } from 'commander';
6
6
  import { resolveFairyPath } from '../utils/project-input.js';
7
7
  import { parseProjectType } from '../utils/project-type.js';
8
8
 
@@ -44,6 +44,7 @@ export function registerPublishCommand(program: Command): void {
44
44
  const resolved = resolvePublishOptions(doc, {
45
45
  compressed: options.compressed,
46
46
  packages: pkgFilter,
47
+ targetProjectType: projectType,
47
48
  });
48
49
 
49
50
  console.log(`Settings: ext=${resolved.fileExtension}, compressed=${resolved.compressed}`);