@openfairygui/cli 0.2.0-alpha.1 → 0.2.0-alpha.10
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/bin/cli.cjs +0 -0
- package/dist/cli.mjs +208 -25
- package/package.json +47 -47
- package/src/cli.ts +79 -43
package/bin/cli.cjs
CHANGED
|
File without changes
|
package/dist/cli.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { createNodeBackendRuntime } from "@openfairygui/backend/node";
|
|
2
3
|
import * as fs$1 from "node:fs/promises";
|
|
3
4
|
import fs from "node:fs/promises";
|
|
@@ -1262,6 +1263,7 @@ var ImageResource = class extends ExtensibleProperty {
|
|
|
1262
1263
|
path: "",
|
|
1263
1264
|
branch: "",
|
|
1264
1265
|
branchItemIds: [],
|
|
1266
|
+
highResolutionItemIds: [],
|
|
1265
1267
|
width: 0,
|
|
1266
1268
|
height: 0,
|
|
1267
1269
|
exported: false,
|
|
@@ -1308,6 +1310,12 @@ var ImageResource = class extends ExtensibleProperty {
|
|
|
1308
1310
|
setBranchItemIds(ids) {
|
|
1309
1311
|
return this.set("branchItemIds", [...ids]);
|
|
1310
1312
|
}
|
|
1313
|
+
getHighResolutionItemIds() {
|
|
1314
|
+
return [...this.get("highResolutionItemIds")];
|
|
1315
|
+
}
|
|
1316
|
+
setHighResolutionItemIds(ids) {
|
|
1317
|
+
return this.set("highResolutionItemIds", [...ids]);
|
|
1318
|
+
}
|
|
1311
1319
|
getWidth() {
|
|
1312
1320
|
return this.get("width");
|
|
1313
1321
|
}
|
|
@@ -1677,6 +1685,7 @@ var MovieClipResource = class extends ExtensibleProperty {
|
|
|
1677
1685
|
path: "",
|
|
1678
1686
|
branch: "",
|
|
1679
1687
|
branchItemIds: [],
|
|
1688
|
+
highResolutionItemIds: [],
|
|
1680
1689
|
fileName: "",
|
|
1681
1690
|
exported: false,
|
|
1682
1691
|
width: 0,
|
|
@@ -1712,6 +1721,12 @@ var MovieClipResource = class extends ExtensibleProperty {
|
|
|
1712
1721
|
setBranchItemIds(ids) {
|
|
1713
1722
|
return this.set("branchItemIds", [...ids]);
|
|
1714
1723
|
}
|
|
1724
|
+
getHighResolutionItemIds() {
|
|
1725
|
+
return [...this.get("highResolutionItemIds")];
|
|
1726
|
+
}
|
|
1727
|
+
setHighResolutionItemIds(ids) {
|
|
1728
|
+
return this.set("highResolutionItemIds", [...ids]);
|
|
1729
|
+
}
|
|
1715
1730
|
getFileName() {
|
|
1716
1731
|
return this.get("fileName");
|
|
1717
1732
|
}
|
|
@@ -2775,6 +2790,7 @@ var GObject = class extends ExtensibleProperty {
|
|
|
2775
2790
|
sourceHeight: 0,
|
|
2776
2791
|
initWidth: 0,
|
|
2777
2792
|
initHeight: 0,
|
|
2793
|
+
customData: "",
|
|
2778
2794
|
relations: [],
|
|
2779
2795
|
gears: new RefList()
|
|
2780
2796
|
});
|
|
@@ -2815,6 +2831,12 @@ var GObject = class extends ExtensibleProperty {
|
|
|
2815
2831
|
setInitHeight(v) {
|
|
2816
2832
|
return this.setObjectProp("initHeight", v);
|
|
2817
2833
|
}
|
|
2834
|
+
getCustomData() {
|
|
2835
|
+
return this.getObjectProp("customData");
|
|
2836
|
+
}
|
|
2837
|
+
setCustomData(v) {
|
|
2838
|
+
return this.setObjectProp("customData", v);
|
|
2839
|
+
}
|
|
2818
2840
|
/****** Relations ******/
|
|
2819
2841
|
getRelations() {
|
|
2820
2842
|
return this.getObjectProp("relations");
|
|
@@ -9682,13 +9704,13 @@ const IMAGE_NODE = defineNode(mergeAttrs(IMAGE_PANEL_ATTRS, XY_SIZE_ATTRS, LOCKE
|
|
|
9682
9704
|
const GRAPH_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, LOCKED_ATTRS, RESTRICT_SIZE_ATTRS, PIVOT_ATTRS, ANCHOR_ATTRS, GROUP_REF_ATTRS, ROTATION_ALPHA_ATTRS, VISIBLE_ATTRS, TOUCHABLE_ATTRS, GRAPH_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9683
9705
|
const MOVIE_CLIP_NODE = defineNode(mergeAttrs(MOVIE_CLIP_PANEL_ATTRS, XY_SIZE_ATTRS, PIVOT_ATTRS, GROUP_REF_ATTRS, ROTATION_ALPHA_ATTRS, VISIBLE_ATTRS, GRAYED_ATTRS, RESOURCE_LINK_ATTRS, FILTER_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9684
9706
|
const COMPONENT_INSTANCE_NODE = defineNode(mergeAttrs(COMPONENT_INSTANCE_PANEL_ATTRS, XY_SIZE_ATTRS, LOCKED_ATTRS, RESTRICT_SIZE_ATTRS, ASPECT_ATTRS, PIVOT_ATTRS, ANCHOR_ATTRS, SCALE_ATTRS, GROUP_REF_ATTRS, ROTATION_ALPHA_ATTRS, VISIBLE_ATTRS, TOUCHABLE_ATTRS, GRAYED_ATTRS, INSTANCE_MISC_PANEL_ATTRS, RESOURCE_LINK_ATTRS, FILTER_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN, WITH_INSTANCE_EXTENSION_CHILDREN));
|
|
9685
|
-
const LOADER_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, PIVOT_ATTRS, SCALE_ATTRS, GROUP_REF_ATTRS, GRAYED_ATTRS, LOADER_PANEL_ATTRS, FILTER_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9686
|
-
const LOADER3D_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, LOADER3D_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9687
|
-
const TEXT_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, RESTRICT_SIZE_ATTRS, { customData: { canonical: "customData" } }, GROUP_REF_ATTRS, TEXT_PANEL_ATTRS, TEXT_INPUT_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9688
|
-
const TEXT_INPUT_NODE = defineNode(mergeAttrs(TEXT_INPUT_PANEL_ATTRS));
|
|
9689
|
-
const RICH_TEXT_NODE = defineNode(mergeAttrs(RICH_TEXT_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9707
|
+
const LOADER_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, PIVOT_ATTRS, SCALE_ATTRS, GROUP_REF_ATTRS, VISIBLE_ATTRS, GRAYED_ATTRS, LOADER_PANEL_ATTRS, FILTER_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9708
|
+
const LOADER3D_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, VISIBLE_ATTRS, LOADER3D_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9709
|
+
const TEXT_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, RESTRICT_SIZE_ATTRS, { customData: { canonical: "customData" } }, GROUP_REF_ATTRS, ROTATION_ALPHA_ATTRS, VISIBLE_ATTRS, TOUCHABLE_ATTRS, GRAYED_ATTRS, TEXT_PANEL_ATTRS, TEXT_INPUT_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9710
|
+
const TEXT_INPUT_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, RESTRICT_SIZE_ATTRS, GROUP_REF_ATTRS, ROTATION_ALPHA_ATTRS, VISIBLE_ATTRS, TOUCHABLE_ATTRS, GRAYED_ATTRS, TEXT_PANEL_ATTRS, TEXT_INPUT_PANEL_ATTRS));
|
|
9711
|
+
const RICH_TEXT_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, GROUP_REF_ATTRS, ROTATION_ALPHA_ATTRS, VISIBLE_ATTRS, TOUCHABLE_ATTRS, GRAYED_ATTRS, TEXT_PANEL_ATTRS, RICH_TEXT_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN));
|
|
9690
9712
|
const GROUP_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, LOCKED_ATTRS, GROUP_REF_ATTRS, VISIBLE_ATTRS, GROUP_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GROUP_GEAR_CHILDREN));
|
|
9691
|
-
const LIST_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, GROUP_REF_ATTRS, TOUCHABLE_ATTRS, LIST_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN, WITH_LIST_ITEM_CHILDREN));
|
|
9713
|
+
const LIST_NODE = defineNode(mergeAttrs(XY_SIZE_ATTRS, GROUP_REF_ATTRS, VISIBLE_ATTRS, TOUCHABLE_ATTRS, LIST_PANEL_ATTRS), mergeChildren(WITH_RELATION_CHILDREN, WITH_GEAR_CHILDREN, WITH_LIST_ITEM_CHILDREN));
|
|
9692
9714
|
const DISPLAY_LIST_CONTAINER$2 = defineContainer({
|
|
9693
9715
|
image: IMAGE_NODE,
|
|
9694
9716
|
graph: GRAPH_NODE,
|
|
@@ -10142,6 +10164,10 @@ function parseComboBoxItemXmlNode(item) {
|
|
|
10142
10164
|
icon: readXmlAttr(item, specs.icon) ?? null
|
|
10143
10165
|
};
|
|
10144
10166
|
}
|
|
10167
|
+
function getProjectBasePath(fs, projectPath) {
|
|
10168
|
+
const basePath = fs.dirname(projectPath);
|
|
10169
|
+
return basePath === "." ? "" : basePath;
|
|
10170
|
+
}
|
|
10145
10171
|
var ProjectReader = class {
|
|
10146
10172
|
_fs;
|
|
10147
10173
|
constructor(fs) {
|
|
@@ -10150,7 +10176,7 @@ var ProjectReader = class {
|
|
|
10150
10176
|
async read(projectPath) {
|
|
10151
10177
|
const fs = this._fs;
|
|
10152
10178
|
const doc = new Document();
|
|
10153
|
-
const basePath =
|
|
10179
|
+
const basePath = getProjectBasePath(fs, projectPath);
|
|
10154
10180
|
const ctx = new ReaderContext(doc, basePath);
|
|
10155
10181
|
const projDesc = getXmlNode(parseXML(await fs.readFile(projectPath)).projectDescription);
|
|
10156
10182
|
if (projDesc) {
|
|
@@ -10871,6 +10897,16 @@ var ProjectReader = class {
|
|
|
10871
10897
|
}
|
|
10872
10898
|
const textGroup = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.group);
|
|
10873
10899
|
if (textGroup) g.setGroup(textGroup);
|
|
10900
|
+
const textRotation = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.rotation);
|
|
10901
|
+
if (textRotation !== void 0) g.setRotation(parseFloat2(textRotation));
|
|
10902
|
+
const textAlpha = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.alpha);
|
|
10903
|
+
if (textAlpha !== void 0) g.setAlpha(parseFloat2(textAlpha, 1));
|
|
10904
|
+
const textVisible = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.visible);
|
|
10905
|
+
if (textVisible !== void 0) g.setVisible(parseBool(textVisible));
|
|
10906
|
+
const textTouchable = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.touchable);
|
|
10907
|
+
if (textTouchable !== void 0) g.setTouchable(parseBool(textTouchable));
|
|
10908
|
+
const textGrayed = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.grayed);
|
|
10909
|
+
if (textGrayed !== void 0) g.setGrayed(parseBool(textGrayed));
|
|
10874
10910
|
const textCustomData = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.customData);
|
|
10875
10911
|
if (textCustomData !== void 0) g.setCustomData(textCustomData);
|
|
10876
10912
|
const textValue = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.text);
|
|
@@ -10981,6 +11017,16 @@ var ProjectReader = class {
|
|
|
10981
11017
|
}
|
|
10982
11018
|
const richTextGroup = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.group);
|
|
10983
11019
|
if (richTextGroup) g.setGroup(richTextGroup);
|
|
11020
|
+
const richTextRotation = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.richText.attrs.rotation);
|
|
11021
|
+
if (richTextRotation !== void 0) g.setRotation(parseFloat2(richTextRotation));
|
|
11022
|
+
const richTextAlpha = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.richText.attrs.alpha);
|
|
11023
|
+
if (richTextAlpha !== void 0) g.setAlpha(parseFloat2(richTextAlpha, 1));
|
|
11024
|
+
const richTextVisible = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.richText.attrs.visible);
|
|
11025
|
+
if (richTextVisible !== void 0) g.setVisible(parseBool(richTextVisible));
|
|
11026
|
+
const richTextTouchable = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.richText.attrs.touchable);
|
|
11027
|
+
if (richTextTouchable !== void 0) g.setTouchable(parseBool(richTextTouchable));
|
|
11028
|
+
const richTextGrayed = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.richText.attrs.grayed);
|
|
11029
|
+
if (richTextGrayed !== void 0) g.setGrayed(parseBool(richTextGrayed));
|
|
10984
11030
|
const richText = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.text);
|
|
10985
11031
|
if (richText !== void 0) g.setText(String(richText));
|
|
10986
11032
|
const richTextFontSize = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.fontSize);
|
|
@@ -11069,6 +11115,16 @@ var ProjectReader = class {
|
|
|
11069
11115
|
}
|
|
11070
11116
|
const inputGroup = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.group);
|
|
11071
11117
|
if (inputGroup) g.setGroup(inputGroup);
|
|
11118
|
+
const inputRotation = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.textInput.attrs.rotation);
|
|
11119
|
+
if (inputRotation !== void 0) g.setRotation(parseFloat2(inputRotation));
|
|
11120
|
+
const inputAlpha = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.textInput.attrs.alpha);
|
|
11121
|
+
if (inputAlpha !== void 0) g.setAlpha(parseFloat2(inputAlpha, 1));
|
|
11122
|
+
const inputVisible = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.textInput.attrs.visible);
|
|
11123
|
+
if (inputVisible !== void 0) g.setVisible(parseBool(inputVisible));
|
|
11124
|
+
const inputTouchable = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.textInput.attrs.touchable);
|
|
11125
|
+
if (inputTouchable !== void 0) g.setTouchable(parseBool(inputTouchable));
|
|
11126
|
+
const inputGrayed = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.textInput.attrs.grayed);
|
|
11127
|
+
if (inputGrayed !== void 0) g.setGrayed(parseBool(inputGrayed));
|
|
11072
11128
|
const inputText = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.text);
|
|
11073
11129
|
if (inputText !== void 0) g.setText(String(inputText));
|
|
11074
11130
|
const inputFontSize = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.fontSize);
|
|
@@ -11275,6 +11331,8 @@ var ProjectReader = class {
|
|
|
11275
11331
|
}
|
|
11276
11332
|
const loaderGrayed = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.grayed);
|
|
11277
11333
|
if (loaderGrayed !== void 0) g.setGrayed(parseBool(loaderGrayed));
|
|
11334
|
+
const loaderVisible = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.visible);
|
|
11335
|
+
if (loaderVisible !== void 0) g.setVisible(parseBool(loaderVisible));
|
|
11278
11336
|
const loaderUrl = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.url);
|
|
11279
11337
|
if (loaderUrl) g.setUrl(loaderUrl);
|
|
11280
11338
|
const loaderAlign = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.align);
|
|
@@ -11348,6 +11406,8 @@ var ProjectReader = class {
|
|
|
11348
11406
|
const [w, h] = parseSizeString(loader3dSize);
|
|
11349
11407
|
g.setSize(w, h);
|
|
11350
11408
|
}
|
|
11409
|
+
const loader3dVisible = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader3D.attrs.visible);
|
|
11410
|
+
if (loader3dVisible !== void 0) g.setVisible(parseBool(loader3dVisible));
|
|
11351
11411
|
const loader3dUrl = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader3D.attrs.url);
|
|
11352
11412
|
if (loader3dUrl) g.setUrl(loader3dUrl);
|
|
11353
11413
|
const loader3dAlign = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader3D.attrs.align);
|
|
@@ -11530,6 +11590,8 @@ var ProjectReader = class {
|
|
|
11530
11590
|
}
|
|
11531
11591
|
const listGroup = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.group);
|
|
11532
11592
|
if (listGroup) g.setGroup(listGroup);
|
|
11593
|
+
const listVisible = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.visible);
|
|
11594
|
+
if (listVisible !== void 0) g.setVisible(parseBool(listVisible));
|
|
11533
11595
|
const listTouchable = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.touchable);
|
|
11534
11596
|
if (listTouchable !== void 0) g.setTouchable(parseBool(listTouchable));
|
|
11535
11597
|
const defaultItem = readXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.defaultItem);
|
|
@@ -12715,6 +12777,7 @@ var ProjectWriter = class {
|
|
|
12715
12777
|
if (pivotX !== 0 || pivotY !== 0) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.pivot, `${pivotX},${pivotY}`);
|
|
12716
12778
|
const [scaleX, scaleY] = [typedObj.getScaleX?.() ?? 1, typedObj.getScaleY?.() ?? 1];
|
|
12717
12779
|
if (scaleX !== 1 || scaleY !== 1) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.scale, `${scaleX},${scaleY}`);
|
|
12780
|
+
if (typedObj.getVisible?.() === false) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.visible, "false");
|
|
12718
12781
|
if (typedObj.getGrayed?.()) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.grayed, "true");
|
|
12719
12782
|
const url = typedObj.getUrl?.();
|
|
12720
12783
|
if (url) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader.attrs.url, url);
|
|
@@ -12776,6 +12839,7 @@ var ProjectWriter = class {
|
|
|
12776
12839
|
if (typedObj.getFilterData?.()) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.movieClip.attrs.filterData, typedObj.getFilterData?.());
|
|
12777
12840
|
}
|
|
12778
12841
|
if (type === "GTextField" || type === "GRichTextField" || type === "GTextInput") {
|
|
12842
|
+
const textNodeProtocol = type === "GRichTextField" ? PROJECT_XML_PROTOCOL.richText : type === "GTextInput" ? PROJECT_XML_PROTOCOL.textInput : PROJECT_XML_PROTOCOL.text;
|
|
12779
12843
|
const [x, y] = [typedObj.getX?.() ?? 0, typedObj.getY?.() ?? 0];
|
|
12780
12844
|
writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.xy, `${x},${y}`);
|
|
12781
12845
|
const [w, h] = [typedObj.getWidth?.() ?? 0, typedObj.getHeight?.() ?? 0];
|
|
@@ -12802,6 +12866,11 @@ var ProjectWriter = class {
|
|
|
12802
12866
|
if (underlaySoftness !== 0) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.richText.attrs.underlaySoftness, String(underlaySoftness));
|
|
12803
12867
|
}
|
|
12804
12868
|
if (typedObj.getGroup?.()) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.group, typedObj.getGroup?.());
|
|
12869
|
+
if ((typedObj.getRotation?.() ?? 0) !== 0) writeXmlAttr(attrs, textNodeProtocol.attrs.rotation, String(typedObj.getRotation?.() ?? 0));
|
|
12870
|
+
if ((typedObj.getAlpha?.() ?? 1) !== 1) writeXmlAttr(attrs, textNodeProtocol.attrs.alpha, formatDisplayAlpha(typedObj.getAlpha?.() ?? 1));
|
|
12871
|
+
if (typedObj.getVisible?.() === false) writeXmlAttr(attrs, textNodeProtocol.attrs.visible, "false");
|
|
12872
|
+
if (typedObj.getTouchable?.() === false) writeXmlAttr(attrs, textNodeProtocol.attrs.touchable, "false");
|
|
12873
|
+
if (typedObj.getGrayed?.()) writeXmlAttr(attrs, textNodeProtocol.attrs.grayed, "true");
|
|
12805
12874
|
if (typedObj.getCustomData?.()) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.text.attrs.customData, typedObj.getCustomData?.());
|
|
12806
12875
|
}
|
|
12807
12876
|
if ((type === "GList" || type === "GTree") && typedObj.getGroup?.()) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.group, typedObj.getGroup?.());
|
|
@@ -12810,12 +12879,14 @@ var ProjectWriter = class {
|
|
|
12810
12879
|
writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.xy, `${x},${y}`);
|
|
12811
12880
|
const [w, h] = [typedObj.getWidth?.() ?? 0, typedObj.getHeight?.() ?? 0];
|
|
12812
12881
|
if (w !== 0 || h !== 0) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.size, `${w},${h}`);
|
|
12882
|
+
if (typedObj.getVisible?.() === false) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.list.attrs.visible, "false");
|
|
12813
12883
|
}
|
|
12814
12884
|
if (type === "GLoader3D") {
|
|
12815
12885
|
const [x, y] = [typedObj.getX?.() ?? 0, typedObj.getY?.() ?? 0];
|
|
12816
12886
|
writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader3D.attrs.xy, `${x},${y}`);
|
|
12817
12887
|
const [w, h] = [typedObj.getWidth?.() ?? 0, typedObj.getHeight?.() ?? 0];
|
|
12818
12888
|
if (w !== 0 || h !== 0) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader3D.attrs.size, `${w},${h}`);
|
|
12889
|
+
if (typedObj.getVisible?.() === false) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader3D.attrs.visible, "false");
|
|
12819
12890
|
const url = typedObj.getUrl?.();
|
|
12820
12891
|
if (url) writeXmlAttr(attrs, PROJECT_XML_PROTOCOL.loader3D.attrs.url, url);
|
|
12821
12892
|
const align = typedObj.getAlign?.();
|
|
@@ -18375,11 +18446,13 @@ var BinaryReader = class {
|
|
|
18375
18446
|
if (branchCnt2 > 0) if (branchIncluded) branchItemIds = buf.readSArray(branchCnt2);
|
|
18376
18447
|
else branchItemIds = [buf.readS() ?? ""];
|
|
18377
18448
|
const highResCnt = buf.getUint8();
|
|
18378
|
-
|
|
18449
|
+
const highResolutionItemIds = [];
|
|
18450
|
+
for (let highResIndex = 0; highResIndex < highResCnt; highResIndex++) highResolutionItemIds.push(buf.readS());
|
|
18379
18451
|
if (createdResource) {
|
|
18380
18452
|
createdResource.setPath(itemPath);
|
|
18381
18453
|
createdResource.setBranch(branchName);
|
|
18382
18454
|
createdResource.setBranchItemIds(branchItemIds);
|
|
18455
|
+
createdResource.setHighResolutionItemIds?.(highResolutionItemIds);
|
|
18383
18456
|
}
|
|
18384
18457
|
}
|
|
18385
18458
|
buf.pos = nextPos;
|
|
@@ -20422,7 +20495,9 @@ var BinaryWriter = class {
|
|
|
20422
20495
|
data.writeSEx(branchName || null);
|
|
20423
20496
|
data.writeUint8(branchItemIds.length);
|
|
20424
20497
|
for (const branchItemId of branchItemIds) data.writeSEx(branchItemId || null);
|
|
20425
|
-
|
|
20498
|
+
const highResolutionItemIds = getItemHighResolutionItemIds(res, publishedItemIdMap, packageItemIds);
|
|
20499
|
+
data.writeUint8(highResolutionItemIds.length);
|
|
20500
|
+
for (const highResolutionItemId of highResolutionItemIds) data.writeS(highResolutionItemId);
|
|
20426
20501
|
}
|
|
20427
20502
|
const nextPos = data.pos;
|
|
20428
20503
|
const savedPos = data.pos;
|
|
@@ -20693,6 +20768,15 @@ function getItemBranchItemIds(item, branchNames, branchItemIdsMap) {
|
|
|
20693
20768
|
if (!inferred) return [];
|
|
20694
20769
|
return inferred.some((value) => !!value) ? [...inferred] : [];
|
|
20695
20770
|
}
|
|
20771
|
+
function getItemHighResolutionItemIds(item, publishedItemIdMap, packageItemIds) {
|
|
20772
|
+
const resolvedIds = (item.getHighResolutionItemIds?.() ?? []).map((id) => {
|
|
20773
|
+
if (!id) return null;
|
|
20774
|
+
const publishedId = publishedItemIdMap.get(id) ?? id;
|
|
20775
|
+
return packageItemIds.has(publishedId) ? publishedId : null;
|
|
20776
|
+
});
|
|
20777
|
+
while (resolvedIds.length > 0 && !resolvedIds[resolvedIds.length - 1]) resolvedIds.pop();
|
|
20778
|
+
return resolvedIds;
|
|
20779
|
+
}
|
|
20696
20780
|
function getAtlasId(atlas) {
|
|
20697
20781
|
return `atlas${atlas.getIndex()}`;
|
|
20698
20782
|
}
|
|
@@ -20721,8 +20805,8 @@ function getPixelHitTestEntry(resource) {
|
|
|
20721
20805
|
/**
|
|
20722
20806
|
* Abstract I/O base class for reading and writing FairyGUI projects.
|
|
20723
20807
|
*
|
|
20724
|
-
* Platform-specific
|
|
20725
|
-
*
|
|
20808
|
+
* Platform-specific adapters provide the file system abstraction required by
|
|
20809
|
+
* the reader/writer.
|
|
20726
20810
|
*
|
|
20727
20811
|
* @category I/O
|
|
20728
20812
|
*/
|
|
@@ -20748,7 +20832,7 @@ var PlatformIO = class {
|
|
|
20748
20832
|
* Usage:
|
|
20749
20833
|
*
|
|
20750
20834
|
* ```ts
|
|
20751
|
-
* import { NodeIO } from '@openfairygui/core';
|
|
20835
|
+
* import { NodeIO } from '@openfairygui/core/node';
|
|
20752
20836
|
*
|
|
20753
20837
|
* const io = new NodeIO();
|
|
20754
20838
|
* const doc = await io.readProject('./path/to/project.fairy');
|
|
@@ -21833,15 +21917,15 @@ function atlas(_options = {}) {
|
|
|
21833
21917
|
}
|
|
21834
21918
|
for (const res of orderedAllResources) if (isImageResource$1(res)) {
|
|
21835
21919
|
const resId = res.getId();
|
|
21836
|
-
if (!res.getExported() && referencedIds.size > 0 && !referencedIds.has(resId)) continue;
|
|
21920
|
+
if (selectedPublishIds.size === 0 && !res.getExported() && referencedIds.size > 0 && !referencedIds.has(resId)) continue;
|
|
21837
21921
|
await _collectImage(res, pkg, inputs, encoder, options, doTrim, logger);
|
|
21838
21922
|
} else if (isMovieClipResource$1(res)) {
|
|
21839
21923
|
const resId = res.getId();
|
|
21840
|
-
if (!res.getExported() && referencedIds.size > 0 && !referencedIds.has(resId)) continue;
|
|
21924
|
+
if (selectedPublishIds.size === 0 && !res.getExported() && referencedIds.size > 0 && !referencedIds.has(resId)) continue;
|
|
21841
21925
|
await _collectMovieClipFrames(doc, res, pkg, inputs, encoder, options, logger);
|
|
21842
21926
|
} else if (isFontResource$1(res)) {
|
|
21843
21927
|
const resId = res.getId();
|
|
21844
|
-
if (!res.getExported() && referencedIds.size > 0 && !referencedIds.has(resId)) continue;
|
|
21928
|
+
if (selectedPublishIds.size === 0 && !res.getExported() && referencedIds.size > 0 && !referencedIds.has(resId)) continue;
|
|
21845
21929
|
await _collectFontTexture(doc, res, pkg, options);
|
|
21846
21930
|
}
|
|
21847
21931
|
if (inputs.length === 0) continue;
|
|
@@ -21942,7 +22026,8 @@ function atlas(_options = {}) {
|
|
|
21942
22026
|
if (input.trimBuffer) {
|
|
21943
22027
|
imgBuffer = input.trimBuffer;
|
|
21944
22028
|
if (imgBuffer.length === 0) continue;
|
|
21945
|
-
} else
|
|
22029
|
+
} else if (input.rasterizedBuffer) imgBuffer = input.rasterizedBuffer;
|
|
22030
|
+
else {
|
|
21946
22031
|
if (!isImageResource$1(input.resource)) {
|
|
21947
22032
|
logger.warn(`atlas: Non-image input "${input.id}" is missing inline buffer, skipping compositing.`);
|
|
21948
22033
|
continue;
|
|
@@ -22153,9 +22238,9 @@ function sortResourcesByOrder(resources, orderMap, inputOrderMap) {
|
|
|
22153
22238
|
* Returns the trimmed buffer, dimensions, and offsets.
|
|
22154
22239
|
* Falls back to the original image if trim fails (e.g. no alpha channel, no transparent edges).
|
|
22155
22240
|
*/
|
|
22156
|
-
async function _trimImage(encoder,
|
|
22241
|
+
async function _trimImage(encoder, input, originalWidth, originalHeight) {
|
|
22157
22242
|
try {
|
|
22158
|
-
const trimResult = await encoder(
|
|
22243
|
+
const trimResult = await encoder(input).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
22159
22244
|
if (!isResolvedBuffer(trimResult)) throw new Error("atlas: encoder raw alpha trim did not return resolved metadata.");
|
|
22160
22245
|
const { data, info } = trimResult;
|
|
22161
22246
|
const width = info.width;
|
|
@@ -22184,7 +22269,7 @@ async function _trimImage(encoder, filePath, originalWidth, originalHeight) {
|
|
|
22184
22269
|
const trimmedWidth = maxX - minX + 1;
|
|
22185
22270
|
const trimmedHeight = maxY - minY + 1;
|
|
22186
22271
|
return {
|
|
22187
|
-
buffer: await encoder(
|
|
22272
|
+
buffer: await encoder(input).extract({
|
|
22188
22273
|
left: minX,
|
|
22189
22274
|
top: minY,
|
|
22190
22275
|
width: trimmedWidth,
|
|
@@ -22199,7 +22284,7 @@ async function _trimImage(encoder, filePath, originalWidth, originalHeight) {
|
|
|
22199
22284
|
};
|
|
22200
22285
|
} catch {
|
|
22201
22286
|
return {
|
|
22202
|
-
buffer: await encoder(
|
|
22287
|
+
buffer: await encoder(input).png().toBuffer(),
|
|
22203
22288
|
width: originalWidth,
|
|
22204
22289
|
height: originalHeight,
|
|
22205
22290
|
offsetX: 0,
|
|
@@ -22223,7 +22308,10 @@ function _resolveImagePath(resource, pkg, basePath) {
|
|
|
22223
22308
|
async function _collectImage(resource, pkg, inputs, encoder, options, doTrim, logger) {
|
|
22224
22309
|
let origW = resource.getWidth() ?? 0;
|
|
22225
22310
|
let origH = resource.getHeight() ?? 0;
|
|
22311
|
+
const declaredWidth = origW;
|
|
22312
|
+
const declaredHeight = origH;
|
|
22226
22313
|
let sourceHasAlpha = false;
|
|
22314
|
+
let rasterizedBuffer;
|
|
22227
22315
|
if (encoder && options.basePath) {
|
|
22228
22316
|
const filePath = _resolveImagePath(resource, pkg, options.basePath);
|
|
22229
22317
|
try {
|
|
@@ -22235,6 +22323,10 @@ async function _collectImage(resource, pkg, inputs, encoder, options, doTrim, lo
|
|
|
22235
22323
|
resource.setHeight(origH);
|
|
22236
22324
|
}
|
|
22237
22325
|
sourceHasAlpha = metadata.hasAlpha === true || metadata.channels === 4;
|
|
22326
|
+
if (/\.svg$/i.test(resolveImageFileName$1(resource)) && declaredWidth > 0 && declaredHeight > 0) {
|
|
22327
|
+
rasterizedBuffer = await encoder(filePath).resize(declaredWidth, declaredHeight, { fit: "fill" }).png().toBuffer();
|
|
22328
|
+
sourceHasAlpha = true;
|
|
22329
|
+
}
|
|
22238
22330
|
} catch {
|
|
22239
22331
|
if (origW === 0 || origH === 0) {
|
|
22240
22332
|
logger.warn(`atlas: Could not read image "${filePath}", skipping.`);
|
|
@@ -22248,7 +22340,7 @@ async function _collectImage(resource, pkg, inputs, encoder, options, doTrim, lo
|
|
|
22248
22340
|
if (doTrim && sourceHasAlpha && options.basePath && encoder) {
|
|
22249
22341
|
const filePath = _resolveImagePath(resource, pkg, options.basePath);
|
|
22250
22342
|
try {
|
|
22251
|
-
const trimResult = await _trimImage(encoder, filePath, origW, origH);
|
|
22343
|
+
const trimResult = await _trimImage(encoder, rasterizedBuffer ?? filePath, origW, origH);
|
|
22252
22344
|
packW = trimResult.width;
|
|
22253
22345
|
packH = trimResult.height;
|
|
22254
22346
|
offX = trimResult.offsetX;
|
|
@@ -22268,6 +22360,7 @@ async function _collectImage(resource, pkg, inputs, encoder, options, doTrim, lo
|
|
|
22268
22360
|
offsetY: offY,
|
|
22269
22361
|
resource,
|
|
22270
22362
|
trimBuffer: trimBuf,
|
|
22363
|
+
rasterizedBuffer,
|
|
22271
22364
|
sourceKind: "image"
|
|
22272
22365
|
});
|
|
22273
22366
|
}
|
|
@@ -23947,6 +24040,9 @@ function isImageResource(resource) {
|
|
|
23947
24040
|
function isMovieClipResource(resource) {
|
|
23948
24041
|
return resource.propertyType === "MovieClipResource";
|
|
23949
24042
|
}
|
|
24043
|
+
function isHighResolutionResource(resource) {
|
|
24044
|
+
return isImageResource(resource) || isMovieClipResource(resource);
|
|
24045
|
+
}
|
|
23950
24046
|
function isMiscResource(resource) {
|
|
23951
24047
|
return resource.propertyType === "MiscResource";
|
|
23952
24048
|
}
|
|
@@ -24067,6 +24163,70 @@ function getBranchName(resource) {
|
|
|
24067
24163
|
function buildBranchResourceKey(resource) {
|
|
24068
24164
|
return `${resource.propertyType}|${resource.getPath() ?? ""}|${resource.getName() ?? ""}`;
|
|
24069
24165
|
}
|
|
24166
|
+
const HIGH_RESOLUTION_LEVELS = [
|
|
24167
|
+
{
|
|
24168
|
+
scale: 2,
|
|
24169
|
+
bit: 1,
|
|
24170
|
+
slot: 0
|
|
24171
|
+
},
|
|
24172
|
+
{
|
|
24173
|
+
scale: 3,
|
|
24174
|
+
bit: 2,
|
|
24175
|
+
slot: 1
|
|
24176
|
+
},
|
|
24177
|
+
{
|
|
24178
|
+
scale: 4,
|
|
24179
|
+
bit: 4,
|
|
24180
|
+
slot: 2
|
|
24181
|
+
}
|
|
24182
|
+
];
|
|
24183
|
+
function buildHighResolutionResourceKey(resource, name = resource.getName()) {
|
|
24184
|
+
return `${resource.propertyType}|${resource.getBranch?.() ?? ""}|${resource.getPath() ?? ""}|${name}`;
|
|
24185
|
+
}
|
|
24186
|
+
function isHighResolutionVariantName(name) {
|
|
24187
|
+
return /@(?:2|3|4)x(?:\.[^./\\]+)?$/iu.test(name);
|
|
24188
|
+
}
|
|
24189
|
+
function appendHighResolutionScaleToName(name, scale) {
|
|
24190
|
+
const extensionIndex = name.lastIndexOf(".");
|
|
24191
|
+
if (extensionIndex > 0) return `${name.slice(0, extensionIndex)}@${scale}x${name.slice(extensionIndex)}`;
|
|
24192
|
+
return `${name}@${scale}x`;
|
|
24193
|
+
}
|
|
24194
|
+
function trimTrailingMissingHighResolutionIds(ids) {
|
|
24195
|
+
while (ids.length > 0 && !ids[ids.length - 1]) ids.pop();
|
|
24196
|
+
return ids;
|
|
24197
|
+
}
|
|
24198
|
+
function collectHighResolutionItemIds(resources, publishedResourceIds, includeHighResolution) {
|
|
24199
|
+
const result = /* @__PURE__ */ new Map();
|
|
24200
|
+
if (includeHighResolution <= 0) return result;
|
|
24201
|
+
const highResolutionResourceByKey = /* @__PURE__ */ new Map();
|
|
24202
|
+
for (const resource of resources) {
|
|
24203
|
+
if (!isHighResolutionResource(resource)) continue;
|
|
24204
|
+
highResolutionResourceByKey.set(buildHighResolutionResourceKey(resource), resource);
|
|
24205
|
+
}
|
|
24206
|
+
for (const resource of resources) {
|
|
24207
|
+
if (!isHighResolutionResource(resource)) continue;
|
|
24208
|
+
if (!publishedResourceIds.has(resource.getId())) continue;
|
|
24209
|
+
if (isHighResolutionVariantName(resource.getName())) continue;
|
|
24210
|
+
const ids = [];
|
|
24211
|
+
for (const level of HIGH_RESOLUTION_LEVELS) {
|
|
24212
|
+
if ((includeHighResolution & level.bit) === 0) {
|
|
24213
|
+
ids[level.slot] = null;
|
|
24214
|
+
continue;
|
|
24215
|
+
}
|
|
24216
|
+
const highResolutionResource = highResolutionResourceByKey.get(buildHighResolutionResourceKey(resource, appendHighResolutionScaleToName(resource.getName(), level.scale)));
|
|
24217
|
+
if (!highResolutionResource) {
|
|
24218
|
+
ids[level.slot] = null;
|
|
24219
|
+
continue;
|
|
24220
|
+
}
|
|
24221
|
+
const highResolutionId = highResolutionResource.getId();
|
|
24222
|
+
publishedResourceIds.add(highResolutionId);
|
|
24223
|
+
ids[level.slot] = highResolutionId;
|
|
24224
|
+
}
|
|
24225
|
+
trimTrailingMissingHighResolutionIds(ids);
|
|
24226
|
+
if (ids.length > 0) result.set(resource.getId(), ids);
|
|
24227
|
+
}
|
|
24228
|
+
return result;
|
|
24229
|
+
}
|
|
24070
24230
|
function collectPackagePublishContext(pkg, options) {
|
|
24071
24231
|
const pkgId = pkg.getId();
|
|
24072
24232
|
const resources = pkg.listResources();
|
|
@@ -24170,6 +24330,7 @@ function collectPackagePublishContext(pkg, options) {
|
|
|
24170
24330
|
}
|
|
24171
24331
|
}
|
|
24172
24332
|
}
|
|
24333
|
+
const highResolutionItemIds = collectHighResolutionItemIds(resources, publishedResourceIds, options.includeHighResolution);
|
|
24173
24334
|
if (!options.includeBranches) {
|
|
24174
24335
|
const mainByKey = /* @__PURE__ */ new Map();
|
|
24175
24336
|
const activeBranchByKey = /* @__PURE__ */ new Map();
|
|
@@ -24218,6 +24379,7 @@ function collectPackagePublishContext(pkg, options) {
|
|
|
24218
24379
|
referencedIds,
|
|
24219
24380
|
publishedResourceIds,
|
|
24220
24381
|
pixelHitTestImageIds,
|
|
24382
|
+
highResolutionItemIds,
|
|
24221
24383
|
effectiveResourceIds,
|
|
24222
24384
|
includeBranches: false
|
|
24223
24385
|
};
|
|
@@ -24226,6 +24388,7 @@ function collectPackagePublishContext(pkg, options) {
|
|
|
24226
24388
|
referencedIds,
|
|
24227
24389
|
publishedResourceIds,
|
|
24228
24390
|
pixelHitTestImageIds,
|
|
24391
|
+
highResolutionItemIds,
|
|
24229
24392
|
effectiveResourceIds: new Map([...publishedResourceIds].map((resourceId) => [resourceId, resourceId])),
|
|
24230
24393
|
includeBranches: true
|
|
24231
24394
|
};
|
|
@@ -24274,8 +24437,11 @@ async function applyPixelHitTests(pkg, imageIds, basePath, encoder) {
|
|
|
24274
24437
|
}
|
|
24275
24438
|
}
|
|
24276
24439
|
async function annotatePackagePublishArtifacts(pkg, basePath, encoder, options) {
|
|
24277
|
-
const { publishedResourceIds, pixelHitTestImageIds, effectiveResourceIds, includeBranches } = collectPackagePublishContext(pkg, options);
|
|
24278
|
-
for (const resource of pkg.listResources())
|
|
24440
|
+
const { publishedResourceIds, pixelHitTestImageIds, highResolutionItemIds, effectiveResourceIds, includeBranches } = collectPackagePublishContext(pkg, options);
|
|
24441
|
+
for (const resource of pkg.listResources()) {
|
|
24442
|
+
setPublishedIdExtra(resource, effectiveResourceIds.get(resource.getId()) ?? null);
|
|
24443
|
+
if (isHighResolutionResource(resource)) resource.setHighResolutionItemIds(highResolutionItemIds.get(resource.getId()) ?? []);
|
|
24444
|
+
}
|
|
24279
24445
|
await applyPixelHitTests(pkg, pixelHitTestImageIds, basePath, encoder);
|
|
24280
24446
|
const extras = pkg.getExtras() ?? {};
|
|
24281
24447
|
pkg.setExtras({
|
|
@@ -24412,6 +24578,7 @@ function publish(options) {
|
|
|
24412
24578
|
}
|
|
24413
24579
|
const includeBranches = (publishSettings.branchProcessing ?? 0) === 0;
|
|
24414
24580
|
const activeBranch = includeBranches ? "" : options.branch ?? "";
|
|
24581
|
+
const includeHighResolution = publishSettings.includeHighResolution ?? 0;
|
|
24415
24582
|
const atlasRuntimeOptions = resolvePublishAtlasRuntimeOptions(ext);
|
|
24416
24583
|
const allDocPackages = root.listPackages();
|
|
24417
24584
|
const pkgMap = /* @__PURE__ */ new Map();
|
|
@@ -24420,7 +24587,8 @@ function publish(options) {
|
|
|
24420
24587
|
_computeDependencies(pkg, pkgMap);
|
|
24421
24588
|
await annotatePackagePublishArtifacts(pkg, options.basePath, options.encoder, {
|
|
24422
24589
|
includeBranches,
|
|
24423
|
-
activeBranch
|
|
24590
|
+
activeBranch,
|
|
24591
|
+
includeHighResolution
|
|
24424
24592
|
});
|
|
24425
24593
|
}
|
|
24426
24594
|
await atlas({
|
|
@@ -24525,6 +24693,21 @@ Options:
|
|
|
24525
24693
|
Input can be a .fairy file or a project root directory (auto-discovers .fairy file).
|
|
24526
24694
|
File extension and binary format are read from project settings.
|
|
24527
24695
|
`;
|
|
24696
|
+
const require = createRequire(import.meta.url);
|
|
24697
|
+
function getInjectedPackageVersion() {
|
|
24698
|
+
const version = import.meta.env?.PACKAGE_VERSION;
|
|
24699
|
+
return typeof version === "string" && version.length > 0 ? version : null;
|
|
24700
|
+
}
|
|
24701
|
+
function readPackageVersion() {
|
|
24702
|
+
const injectedVersion = getInjectedPackageVersion();
|
|
24703
|
+
if (injectedVersion) return injectedVersion;
|
|
24704
|
+
try {
|
|
24705
|
+
const pkg = require("../package.json");
|
|
24706
|
+
if (typeof pkg.version === "string" && pkg.version.length > 0) return pkg.version;
|
|
24707
|
+
} catch {}
|
|
24708
|
+
return "0.0.0-dev";
|
|
24709
|
+
}
|
|
24710
|
+
const PACKAGE_VERSION = readPackageVersion();
|
|
24528
24711
|
/** Resolve input to a .fairy file path. Accepts a directory or a .fairy file. */
|
|
24529
24712
|
async function resolveFairyPath(input) {
|
|
24530
24713
|
const resolved = path.resolve(input);
|
|
@@ -24545,7 +24728,7 @@ async function main() {
|
|
|
24545
24728
|
return;
|
|
24546
24729
|
}
|
|
24547
24730
|
if (args.includes("--version") || args.includes("-v")) {
|
|
24548
|
-
console.log(
|
|
24731
|
+
console.log(PACKAGE_VERSION);
|
|
24549
24732
|
return;
|
|
24550
24733
|
}
|
|
24551
24734
|
const command = args[0];
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
2
|
+
"name": "@openfairygui/cli",
|
|
3
|
+
"version": "0.2.0-alpha.10",
|
|
4
|
+
"description": "FairyGUI Headless Authoring SDK — command-line interface.",
|
|
5
|
+
"author": "OpenFairyGUI Contributors",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/OpenFairyGUI/OpenFairyGUI.git",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/OpenFairyGUI/OpenFairyGUI#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/OpenFairyGUI/OpenFairyGUI/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"bin": {
|
|
18
|
+
"ofgui": "bin/cli.cjs",
|
|
19
|
+
"openfairygui": "bin/cli.cjs"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/",
|
|
23
|
+
"bin/",
|
|
24
|
+
"src/"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"fairygui",
|
|
28
|
+
"cli",
|
|
29
|
+
"ui",
|
|
30
|
+
"headless",
|
|
31
|
+
"authoring",
|
|
32
|
+
"publish",
|
|
33
|
+
"restore"
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@openfairygui/core": "0.2.0-alpha.10",
|
|
37
|
+
"@openfairygui/functions": "0.2.0-alpha.8"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@openfairygui/backend": "0.2.0-alpha.10"
|
|
41
|
+
},
|
|
42
|
+
"optionalDependencies": {
|
|
43
|
+
"sharp": ">=0.33.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsdown src/cli.ts --format esm --platform node --no-dts --external sharp --env.PACKAGE_VERSION=$npm_package_version"
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { createNodeBackendRuntime } from '@openfairygui/backend/node';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
ProjectType,
|
|
5
|
-
} from '@openfairygui/core';
|
|
2
|
+
import { ProjectType } from '@openfairygui/core';
|
|
3
|
+
import { NodeIO } from '@openfairygui/core/node';
|
|
6
4
|
import {
|
|
7
5
|
inspect,
|
|
8
6
|
publish,
|
|
@@ -17,6 +15,7 @@ import {
|
|
|
17
15
|
type RestoreImageExtractor,
|
|
18
16
|
} from '@openfairygui/functions';
|
|
19
17
|
import fs from 'node:fs/promises';
|
|
18
|
+
import { createRequire } from 'node:module';
|
|
20
19
|
import path from 'node:path';
|
|
21
20
|
import { parseArgs } from 'node:util';
|
|
22
21
|
|
|
@@ -53,6 +52,29 @@ Input can be a .fairy file or a project root directory (auto-discovers .fairy fi
|
|
|
53
52
|
File extension and binary format are read from project settings.
|
|
54
53
|
`;
|
|
55
54
|
|
|
55
|
+
const require = createRequire(import.meta.url);
|
|
56
|
+
|
|
57
|
+
function getInjectedPackageVersion(): string | null {
|
|
58
|
+
const version = (import.meta as ImportMeta & { env?: { PACKAGE_VERSION?: string } }).env?.PACKAGE_VERSION;
|
|
59
|
+
return typeof version === 'string' && version.length > 0 ? version : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readPackageVersion(): string {
|
|
63
|
+
const injectedVersion = getInjectedPackageVersion();
|
|
64
|
+
if (injectedVersion) return injectedVersion;
|
|
65
|
+
try {
|
|
66
|
+
const pkg = require('../package.json') as { version?: unknown };
|
|
67
|
+
if (typeof pkg.version === 'string' && pkg.version.length > 0) {
|
|
68
|
+
return pkg.version;
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
// Keep the CLI usable when executed from a bundled artifact missing package.json.
|
|
72
|
+
}
|
|
73
|
+
return '0.0.0-dev';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const PACKAGE_VERSION = readPackageVersion();
|
|
77
|
+
|
|
56
78
|
/** Resolve input to a .fairy file path. Accepts a directory or a .fairy file. */
|
|
57
79
|
async function resolveFairyPath(input: string): Promise<string> {
|
|
58
80
|
const resolved = path.resolve(input);
|
|
@@ -70,7 +92,9 @@ async function resolveFairyPath(input: string): Promise<string> {
|
|
|
70
92
|
return path.join(resolved, fairyFiles[0]);
|
|
71
93
|
}
|
|
72
94
|
if (fairyFiles.length > 1) {
|
|
73
|
-
throw new Error(
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Multiple .fairy files found in ${resolved}: ${fairyFiles.join(', ')}. Please specify one.`,
|
|
97
|
+
);
|
|
74
98
|
}
|
|
75
99
|
throw new Error(`No .fairy file found in ${resolved}`);
|
|
76
100
|
}
|
|
@@ -87,7 +111,7 @@ async function main(): Promise<void> {
|
|
|
87
111
|
}
|
|
88
112
|
|
|
89
113
|
if (args.includes('--version') || args.includes('-v')) {
|
|
90
|
-
console.log(
|
|
114
|
+
console.log(PACKAGE_VERSION);
|
|
91
115
|
return;
|
|
92
116
|
}
|
|
93
117
|
|
|
@@ -195,24 +219,25 @@ async function createRestoreImageProcessors(): Promise<RestoreImageProcessors> {
|
|
|
195
219
|
});
|
|
196
220
|
if (input.rotated) image = image.rotate(90);
|
|
197
221
|
const { data, info } = await image.png().toBuffer({ resolveWithObject: true });
|
|
198
|
-
const needsOriginalCanvas =
|
|
199
|
-
input.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
222
|
+
const needsOriginalCanvas =
|
|
223
|
+
input.expectedWidth > 0 &&
|
|
224
|
+
input.expectedHeight > 0 &&
|
|
225
|
+
(input.offsetX !== 0 ||
|
|
226
|
+
input.offsetY !== 0 ||
|
|
227
|
+
info.width !== input.expectedWidth ||
|
|
228
|
+
info.height !== input.expectedHeight);
|
|
204
229
|
|
|
205
230
|
if (needsOriginalCanvas) {
|
|
206
231
|
if (
|
|
207
|
-
input.offsetX < 0
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
232
|
+
input.offsetX < 0 ||
|
|
233
|
+
input.offsetY < 0 ||
|
|
234
|
+
input.offsetX + info.width > input.expectedWidth ||
|
|
235
|
+
input.offsetY + info.height > input.expectedHeight
|
|
211
236
|
) {
|
|
212
237
|
throw new Error(
|
|
213
|
-
`restore: Cropped image does not fit original canvas for ${targetPath}: `
|
|
214
|
-
|
|
215
|
-
|
|
238
|
+
`restore: Cropped image does not fit original canvas for ${targetPath}: ` +
|
|
239
|
+
`crop ${info.width}x${info.height} at ${input.offsetX},${input.offsetY}, ` +
|
|
240
|
+
`canvas ${input.expectedWidth}x${input.expectedHeight}`,
|
|
216
241
|
);
|
|
217
242
|
}
|
|
218
243
|
const composed = await sharp({
|
|
@@ -227,26 +252,26 @@ async function createRestoreImageProcessors(): Promise<RestoreImageProcessors> {
|
|
|
227
252
|
.png()
|
|
228
253
|
.toBuffer({ resolveWithObject: true });
|
|
229
254
|
if (
|
|
230
|
-
input.expectedWidth > 0
|
|
231
|
-
|
|
232
|
-
|
|
255
|
+
input.expectedWidth > 0 &&
|
|
256
|
+
input.expectedHeight > 0 &&
|
|
257
|
+
(composed.info.width !== input.expectedWidth || composed.info.height !== input.expectedHeight)
|
|
233
258
|
) {
|
|
234
259
|
throw new Error(
|
|
235
|
-
`restore: Cropped image size mismatch for ${targetPath}: `
|
|
236
|
-
|
|
260
|
+
`restore: Cropped image size mismatch for ${targetPath}: ` +
|
|
261
|
+
`expected ${input.expectedWidth}x${input.expectedHeight}, got ${composed.info.width}x${composed.info.height}`,
|
|
237
262
|
);
|
|
238
263
|
}
|
|
239
264
|
return composed.data;
|
|
240
265
|
}
|
|
241
266
|
|
|
242
267
|
if (
|
|
243
|
-
input.expectedWidth > 0
|
|
244
|
-
|
|
245
|
-
|
|
268
|
+
input.expectedWidth > 0 &&
|
|
269
|
+
input.expectedHeight > 0 &&
|
|
270
|
+
(info.width !== input.expectedWidth || info.height !== input.expectedHeight)
|
|
246
271
|
) {
|
|
247
272
|
throw new Error(
|
|
248
|
-
`restore: Cropped image size mismatch for ${targetPath}: `
|
|
249
|
-
|
|
273
|
+
`restore: Cropped image size mismatch for ${targetPath}: ` +
|
|
274
|
+
`expected ${input.expectedWidth}x${input.expectedHeight}, got ${info.width}x${info.height}`,
|
|
250
275
|
);
|
|
251
276
|
}
|
|
252
277
|
return data;
|
|
@@ -294,7 +319,9 @@ function printReport(report: InspectReport): void {
|
|
|
294
319
|
console.log('\nPackage details:');
|
|
295
320
|
for (const pkg of report.packages) {
|
|
296
321
|
const res = pkg.resources;
|
|
297
|
-
console.log(
|
|
322
|
+
console.log(
|
|
323
|
+
` ${pkg.name} (${pkg.id}): ${res.images.count} img, ${res.sounds.count} snd, ${res.fonts.count} font, ${res.components.count} comp`,
|
|
324
|
+
);
|
|
298
325
|
}
|
|
299
326
|
}
|
|
300
327
|
|
|
@@ -347,7 +374,12 @@ async function cmdRestore(args: string[]): Promise<void> {
|
|
|
347
374
|
|
|
348
375
|
const releaseDir = path.resolve(positionals[0]);
|
|
349
376
|
const outputDir = path.resolve(values.output);
|
|
350
|
-
const pkgFilter = values.packages
|
|
377
|
+
const pkgFilter = values.packages
|
|
378
|
+
? values.packages
|
|
379
|
+
.split(',')
|
|
380
|
+
.map((s) => s.trim())
|
|
381
|
+
.filter(Boolean)
|
|
382
|
+
: undefined;
|
|
351
383
|
const projectType = parseProjectType(values['project-type']);
|
|
352
384
|
const { cropImage, extractImage } = await createRestoreImageProcessors();
|
|
353
385
|
|
|
@@ -385,7 +417,9 @@ async function cmdPublish(args: string[]): Promise<void> {
|
|
|
385
417
|
});
|
|
386
418
|
|
|
387
419
|
if (positionals.length === 0 || !values.output) {
|
|
388
|
-
console.error(
|
|
420
|
+
console.error(
|
|
421
|
+
'Usage: ofgui publish <project-dir> --output <dir> [--compressed] [--packages a,b,c] [--branch name]',
|
|
422
|
+
);
|
|
389
423
|
process.exit(1);
|
|
390
424
|
}
|
|
391
425
|
|
|
@@ -454,17 +488,19 @@ async function cmdPublish(args: string[]): Promise<void> {
|
|
|
454
488
|
},
|
|
455
489
|
};
|
|
456
490
|
|
|
457
|
-
await doc.transform(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
491
|
+
await doc.transform(
|
|
492
|
+
publish({
|
|
493
|
+
output: outputDir,
|
|
494
|
+
compressed: resolved.compressed,
|
|
495
|
+
fileExtension: resolved.fileExtension,
|
|
496
|
+
packages: resolved.packages,
|
|
497
|
+
fs: publishFs,
|
|
498
|
+
encoder,
|
|
499
|
+
basePath: path.join(projectDir, 'assets'),
|
|
500
|
+
atlas: atlasConfig,
|
|
501
|
+
branch: values.branch,
|
|
502
|
+
}),
|
|
503
|
+
);
|
|
468
504
|
|
|
469
505
|
console.log(`\nDone! Output: ${outputDir}`);
|
|
470
506
|
}
|