@openfairygui/functions 0.2.0-alpha.34 → 0.2.0-alpha.35
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/README.md +3 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/node.cjs +2 -2
- package/dist/node.js +2 -2
- package/dist/{publish-BJk8UzRP.js → publish--8vagaSA.js} +135 -210
- package/dist/{publish-DCP0AYx2.cjs → publish-Bv7E2fZE.cjs} +139 -208
- package/dist/{restore-C98ugT2H.js → restore-CknfGMJM.js} +9 -1
- package/dist/{restore-BUaCK8ui.cjs → restore-iTgeWr7-.cjs} +9 -1
- package/dist/web.cjs +33 -4
- package/dist/web.d.cts +3 -0
- package/dist/web.d.ts +3 -0
- package/dist/web.js +33 -4
- package/package.json +2 -2
- package/src/adapters/web/publish.ts +40 -3
- package/src/atlas/inputs.ts +72 -110
- package/src/atlas/jta.ts +116 -170
- package/src/atlas.ts +12 -1
- package/src/publish.ts +45 -2
- package/src/restore.ts +10 -0
|
@@ -599,153 +599,76 @@ function parseFnt(text) {
|
|
|
599
599
|
}
|
|
600
600
|
//#endregion
|
|
601
601
|
//#region src/atlas/jta.ts
|
|
602
|
-
const PNG_SIGNATURE = new Uint8Array([
|
|
603
|
-
137,
|
|
604
|
-
80,
|
|
605
|
-
78,
|
|
606
|
-
71,
|
|
607
|
-
13,
|
|
608
|
-
10,
|
|
609
|
-
26,
|
|
610
|
-
10
|
|
611
|
-
]);
|
|
612
602
|
function extractJtaFrames(data) {
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
let firstPngOffset = -1;
|
|
616
|
-
while (offset < data.length) {
|
|
617
|
-
const signatureIndex = findPngSignature(data, offset);
|
|
618
|
-
if (signatureIndex === -1) break;
|
|
619
|
-
if (firstPngOffset === -1) firstPngOffset = signatureIndex;
|
|
620
|
-
const end = findPngEnd(data, signatureIndex);
|
|
621
|
-
if (end === -1) break;
|
|
622
|
-
frames.push(data.subarray(signatureIndex, end));
|
|
623
|
-
offset = end;
|
|
624
|
-
}
|
|
625
|
-
if (firstPngOffset === -1 || frames.length === 0) return { frames: [] };
|
|
603
|
+
const parsed = (0, _openfairygui_core.parseJta)(data);
|
|
604
|
+
const derived = (0, _openfairygui_core.deriveMovieClipModel)(parsed);
|
|
626
605
|
return {
|
|
627
|
-
frames,
|
|
628
|
-
meta:
|
|
606
|
+
frames: parsed.textures.map((texture) => texture.raw),
|
|
607
|
+
meta: {
|
|
608
|
+
interval: derived.interval,
|
|
609
|
+
repeatDelay: derived.repeatDelay,
|
|
610
|
+
swing: derived.swing,
|
|
611
|
+
width: derived.dimensions.width,
|
|
612
|
+
height: derived.dimensions.height,
|
|
613
|
+
frames: derived.frames.map((frame) => ({
|
|
614
|
+
addDelay: frame.addDelay,
|
|
615
|
+
offsetX: frame.rectX,
|
|
616
|
+
offsetY: frame.rectY,
|
|
617
|
+
width: frame.rectWidth,
|
|
618
|
+
height: frame.rectHeight,
|
|
619
|
+
textureIndex: frame.textureIndex
|
|
620
|
+
}))
|
|
621
|
+
}
|
|
629
622
|
};
|
|
630
623
|
}
|
|
631
|
-
function
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
const speedRaw = readUint8At(data, state, end);
|
|
673
|
-
const repeatDelayRaw = readUint8At(data, state, end);
|
|
674
|
-
const swingRaw = readInt8At(data, state, end);
|
|
675
|
-
const frameTableCount = readInt16BEAt(data, state, end);
|
|
676
|
-
if (speedRaw == null || repeatDelayRaw == null || swingRaw == null || frameTableCount == null) return void 0;
|
|
677
|
-
const frames = [];
|
|
678
|
-
for (let index = 0; index < frameTableCount; index += 1) {
|
|
679
|
-
const delayRaw = readInt16BEAt(data, state, end);
|
|
680
|
-
const offsetX = readInt16BEAt(data, state, end);
|
|
681
|
-
const offsetY = readInt16BEAt(data, state, end);
|
|
682
|
-
const frameWidth = readInt16BEAt(data, state, end);
|
|
683
|
-
const frameHeight = readInt16BEAt(data, state, end);
|
|
684
|
-
const textureIndex = readInt16BEAt(data, state, end);
|
|
685
|
-
if (delayRaw == null || offsetX == null || offsetY == null || frameWidth == null || frameHeight == null || textureIndex == null) break;
|
|
686
|
-
frames.push({
|
|
687
|
-
addDelay: Math.trunc(1e3 / fps * delayRaw),
|
|
688
|
-
offsetX,
|
|
689
|
-
offsetY,
|
|
690
|
-
width: frameWidth,
|
|
691
|
-
height: frameHeight,
|
|
692
|
-
textureIndex
|
|
624
|
+
function detectSupportedRasterFormat(data) {
|
|
625
|
+
if (data.length >= 8 && data[0] === 137 && data[1] === 80 && data[2] === 78 && data[3] === 71 && data[4] === 13 && data[5] === 10 && data[6] === 26 && data[7] === 10) return "png";
|
|
626
|
+
if (data.length >= 2 && data[0] === 255 && data[1] === 216) return "jpeg";
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
function couldNotDecode(filePath, frameIndex, textureIndex) {
|
|
630
|
+
return /* @__PURE__ */ new Error(`atlas: Could not decode MovieClip "${filePath}" frame ${frameIndex} (texture ${textureIndex}).`);
|
|
631
|
+
}
|
|
632
|
+
async function prepareJtaForPublish(data, encoder, filePath) {
|
|
633
|
+
const extracted = extractJtaFrames(data);
|
|
634
|
+
const firstFrameIndexByTextureIndex = /* @__PURE__ */ new Map();
|
|
635
|
+
for (let frameIndex = 0; frameIndex < extracted.meta.frames.length; frameIndex += 1) {
|
|
636
|
+
const textureIndex = extracted.meta.frames[frameIndex].textureIndex;
|
|
637
|
+
if (textureIndex >= 0 && !firstFrameIndexByTextureIndex.has(textureIndex)) firstFrameIndexByTextureIndex.set(textureIndex, frameIndex);
|
|
638
|
+
}
|
|
639
|
+
const referencedTextures = [];
|
|
640
|
+
for (let textureIndex = 0; textureIndex < extracted.frames.length; textureIndex += 1) {
|
|
641
|
+
const firstFrameIndex = firstFrameIndexByTextureIndex.get(textureIndex);
|
|
642
|
+
if (firstFrameIndex === void 0) continue;
|
|
643
|
+
const raw = extracted.frames[textureIndex];
|
|
644
|
+
if (raw.byteLength === 0) throw new Error(`atlas: MovieClip "${filePath}" frame ${firstFrameIndex} references empty texture ${textureIndex}.`);
|
|
645
|
+
const detectedFormat = detectSupportedRasterFormat(raw);
|
|
646
|
+
if (!detectedFormat) throw new Error(`atlas: MovieClip "${filePath}" frame ${firstFrameIndex} (texture ${textureIndex}) uses an unsupported raster format; only PNG and JPEG are supported.`);
|
|
647
|
+
const imageInfo = (0, _openfairygui_core.probeRasterImage)(raw);
|
|
648
|
+
if (!imageInfo || imageInfo.format !== detectedFormat) throw couldNotDecode(filePath, firstFrameIndex, textureIndex);
|
|
649
|
+
let buffer = raw;
|
|
650
|
+
if (encoder) {
|
|
651
|
+
try {
|
|
652
|
+
buffer = await encoder(raw).png().toBuffer();
|
|
653
|
+
} catch {
|
|
654
|
+
throw couldNotDecode(filePath, firstFrameIndex, textureIndex);
|
|
655
|
+
}
|
|
656
|
+
const normalizedInfo = (0, _openfairygui_core.probeRasterImage)(buffer);
|
|
657
|
+
if (!normalizedInfo || normalizedInfo.format !== "png" || normalizedInfo.width !== imageInfo.width || normalizedInfo.height !== imageInfo.height) throw couldNotDecode(filePath, firstFrameIndex, textureIndex);
|
|
658
|
+
}
|
|
659
|
+
referencedTextures.push({
|
|
660
|
+
textureIndex,
|
|
661
|
+
firstFrameIndex,
|
|
662
|
+
buffer,
|
|
663
|
+
width: imageInfo.width,
|
|
664
|
+
height: imageInfo.height
|
|
693
665
|
});
|
|
694
666
|
}
|
|
695
667
|
return {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
swing: swingRaw === 1,
|
|
699
|
-
width,
|
|
700
|
-
height,
|
|
701
|
-
frames: frames.length === 0 && frameCount > 0 ? [] : frames
|
|
668
|
+
...extracted,
|
|
669
|
+
referencedTextures
|
|
702
670
|
};
|
|
703
671
|
}
|
|
704
|
-
function readUtfBE(data, state, end) {
|
|
705
|
-
const length = readUint16BEAt(data, state, end);
|
|
706
|
-
if (length == null || state.offset + length > end) return null;
|
|
707
|
-
const value = new TextDecoder().decode(data.subarray(state.offset, state.offset + length));
|
|
708
|
-
state.offset += length;
|
|
709
|
-
return value;
|
|
710
|
-
}
|
|
711
|
-
function readUint8At(data, state, end) {
|
|
712
|
-
if (state.offset + 1 > end) return null;
|
|
713
|
-
const value = data[state.offset];
|
|
714
|
-
state.offset += 1;
|
|
715
|
-
return value ?? 0;
|
|
716
|
-
}
|
|
717
|
-
function readInt8At(data, state, end) {
|
|
718
|
-
if (state.offset + 1 > end) return null;
|
|
719
|
-
const value = new DataView(data.buffer, data.byteOffset, data.byteLength).getInt8(state.offset);
|
|
720
|
-
state.offset += 1;
|
|
721
|
-
return value;
|
|
722
|
-
}
|
|
723
|
-
function readUint16BEAt(data, state, end) {
|
|
724
|
-
if (state.offset + 2 > end) return null;
|
|
725
|
-
const value = readUint16BE(data, state.offset);
|
|
726
|
-
state.offset += 2;
|
|
727
|
-
return value;
|
|
728
|
-
}
|
|
729
|
-
function readInt16BEAt(data, state, end) {
|
|
730
|
-
if (state.offset + 2 > end) return null;
|
|
731
|
-
const value = new DataView(data.buffer, data.byteOffset, data.byteLength).getInt16(state.offset, false);
|
|
732
|
-
state.offset += 2;
|
|
733
|
-
return value;
|
|
734
|
-
}
|
|
735
|
-
function readInt32BEAt(data, state, end) {
|
|
736
|
-
if (state.offset + 4 > end) return null;
|
|
737
|
-
const value = new DataView(data.buffer, data.byteOffset, data.byteLength).getInt32(state.offset, false);
|
|
738
|
-
state.offset += 4;
|
|
739
|
-
return value;
|
|
740
|
-
}
|
|
741
|
-
function readUint16BE(data, offset) {
|
|
742
|
-
if (offset + 1 >= data.length) return 0;
|
|
743
|
-
return data[offset] << 8 | data[offset + 1];
|
|
744
|
-
}
|
|
745
|
-
function readUint32BE(data, offset) {
|
|
746
|
-
if (offset + 3 >= data.length) return 0;
|
|
747
|
-
return data[offset] * 16777216 + ((data[offset + 1] ?? 0) << 16) + ((data[offset + 2] ?? 0) << 8) + (data[offset + 3] ?? 0);
|
|
748
|
-
}
|
|
749
672
|
//#endregion
|
|
750
673
|
//#region src/atlas/inputs.ts
|
|
751
674
|
function getPublishedItemId(resource) {
|
|
@@ -815,6 +738,27 @@ async function _trimImage(encoder, input, originalWidth, originalHeight) {
|
|
|
815
738
|
};
|
|
816
739
|
}
|
|
817
740
|
}
|
|
741
|
+
function resolveMovieClipSourcePath(resource, pkg, basePath) {
|
|
742
|
+
const fileName = `${resource.getName()}.jta`;
|
|
743
|
+
const resourcePath = resource.getPath() ?? "/";
|
|
744
|
+
return `${basePath}/${pkg.getName()}${resourcePath}${fileName}`;
|
|
745
|
+
}
|
|
746
|
+
async function prepareMovieClipResource(resource, pkg, encoder, basePath, readFileRaw) {
|
|
747
|
+
const filePath = resolveMovieClipSourcePath(resource, pkg, basePath);
|
|
748
|
+
let raw;
|
|
749
|
+
try {
|
|
750
|
+
raw = await readFileRaw(filePath);
|
|
751
|
+
} catch {
|
|
752
|
+
throw new Error(`atlas: Could not read MovieClip "${filePath}".`);
|
|
753
|
+
}
|
|
754
|
+
try {
|
|
755
|
+
return await prepareJtaForPublish(raw, encoder, filePath);
|
|
756
|
+
} catch (error) {
|
|
757
|
+
if (error instanceof Error && error.message.startsWith("atlas:")) throw error;
|
|
758
|
+
const detail = error instanceof Error ? ` ${error.message}` : "";
|
|
759
|
+
throw new Error(`atlas: Could not parse MovieClip "${filePath}".${detail}`);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
818
762
|
/** Collect a single ImageResource into the inputs array. */
|
|
819
763
|
async function collectImage(resource, pkg, inputs, encoder, options, doTrim, logger) {
|
|
820
764
|
let origW = resource.getWidth() ?? 0;
|
|
@@ -888,82 +832,45 @@ async function collectMovieClipFrames(doc, resource, pkg, inputs, encoder, optio
|
|
|
888
832
|
}
|
|
889
833
|
if (!encoder && options.strictOutput) throw new Error(`atlas: MovieClip "${resource.getId()}" requires an encoder for complete raster output.`);
|
|
890
834
|
const mcId = resource.getId();
|
|
891
|
-
const
|
|
892
|
-
const mcPath = resource.getPath() ?? "/";
|
|
893
|
-
const filePath = `${options.basePath}/${pkg.getName()}${mcPath}${mcName}`;
|
|
835
|
+
const filePath = resolveMovieClipSourcePath(resource, pkg, options.basePath);
|
|
894
836
|
try {
|
|
895
|
-
const jta =
|
|
896
|
-
if (jta.frames.length === 0) return;
|
|
897
|
-
const frameMetas = jta.meta?.frames ?? [];
|
|
837
|
+
const jta = options.preparedMovieClips?.get(resource) ?? await prepareMovieClipResource(resource, pkg, encoder, options.basePath, options.readFileRaw);
|
|
898
838
|
for (const frame of resource.listFrames()) resource.removeFrame(frame);
|
|
899
|
-
resource.setInterval(jta.meta
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
resource.addFrame(frame);
|
|
923
|
-
}
|
|
924
|
-
} else for (let frameIndex = 0; frameIndex < jta.frames.length; frameIndex += 1) {
|
|
925
|
-
const itemId = `${mcId}_${frameIndex}`;
|
|
926
|
-
const input = await createMovieClipFrameInput(jta.frames[frameIndex], itemId, resource, encoder, options.strictOutput);
|
|
927
|
-
if (!input) continue;
|
|
928
|
-
inputs.push(input);
|
|
929
|
-
const frame = doc.createMovieFrame(itemId);
|
|
930
|
-
frame.setRectX(0).setRectY(0).setRectWidth(input.originalWidth).setRectHeight(input.originalHeight).setAddDelay(0).setSpriteId(itemId);
|
|
839
|
+
resource.setInterval(jta.meta.interval).setSwing(jta.meta.swing).setRepeatDelay(jta.meta.repeatDelay);
|
|
840
|
+
const spriteIdByTextureIndex = /* @__PURE__ */ new Map();
|
|
841
|
+
for (const texture of jta.referencedTextures) {
|
|
842
|
+
if (texture.width <= 0 || texture.height <= 0) continue;
|
|
843
|
+
const itemId = `${mcId}_${texture.firstFrameIndex}`;
|
|
844
|
+
inputs.push({
|
|
845
|
+
id: itemId,
|
|
846
|
+
width: texture.width,
|
|
847
|
+
height: texture.height,
|
|
848
|
+
originalWidth: texture.width,
|
|
849
|
+
originalHeight: texture.height,
|
|
850
|
+
offsetX: 0,
|
|
851
|
+
offsetY: 0,
|
|
852
|
+
resource,
|
|
853
|
+
trimBuffer: texture.buffer,
|
|
854
|
+
sourceKind: "movieclip-frame"
|
|
855
|
+
});
|
|
856
|
+
spriteIdByTextureIndex.set(texture.textureIndex, itemId);
|
|
857
|
+
}
|
|
858
|
+
for (let frameIndex = 0; frameIndex < jta.meta.frames.length; frameIndex += 1) {
|
|
859
|
+
const meta = jta.meta.frames[frameIndex];
|
|
860
|
+
const frame = doc.createMovieFrame(`${mcId}_${frameIndex}`);
|
|
861
|
+
frame.setRectX(meta.offsetX).setRectY(meta.offsetY).setRectWidth(meta.width).setRectHeight(meta.height).setAddDelay(meta.addDelay).setSpriteId(meta.textureIndex === -1 ? "" : spriteIdByTextureIndex.get(meta.textureIndex) ?? "");
|
|
931
862
|
resource.addFrame(frame);
|
|
932
863
|
}
|
|
933
|
-
if (
|
|
934
|
-
resource.setWidth(jta.meta
|
|
935
|
-
resource.setHeight(jta.meta
|
|
864
|
+
if (jta.meta.width > 0 && jta.meta.height > 0) {
|
|
865
|
+
resource.setWidth(jta.meta.width);
|
|
866
|
+
resource.setHeight(jta.meta.height);
|
|
936
867
|
}
|
|
937
|
-
} catch {
|
|
938
|
-
const message = `atlas: Could not parse MovieClip "${filePath}".`;
|
|
939
|
-
if (options.strictOutput) throw
|
|
868
|
+
} catch (error) {
|
|
869
|
+
const message = error instanceof Error ? error.message : `atlas: Could not parse MovieClip "${filePath}".`;
|
|
870
|
+
if (options.strictOutput) throw error;
|
|
940
871
|
logger.warn(`${message} Skipping frames.`);
|
|
941
872
|
}
|
|
942
873
|
}
|
|
943
|
-
async function createMovieClipFrameInput(buffer, itemId, resource, encoder, strictOutput) {
|
|
944
|
-
if (!encoder || buffer.length === 0) return null;
|
|
945
|
-
try {
|
|
946
|
-
const meta = await encoder(buffer).metadata();
|
|
947
|
-
const width = meta.width ?? 0;
|
|
948
|
-
const height = meta.height ?? 0;
|
|
949
|
-
if (width <= 0 || height <= 0) return null;
|
|
950
|
-
return {
|
|
951
|
-
id: itemId,
|
|
952
|
-
width,
|
|
953
|
-
height,
|
|
954
|
-
originalWidth: width,
|
|
955
|
-
originalHeight: height,
|
|
956
|
-
offsetX: 0,
|
|
957
|
-
offsetY: 0,
|
|
958
|
-
resource,
|
|
959
|
-
trimBuffer: buffer,
|
|
960
|
-
sourceKind: "movieclip-frame"
|
|
961
|
-
};
|
|
962
|
-
} catch {
|
|
963
|
-
if (strictOutput) throw new Error(`atlas: Could not decode MovieClip frame "${itemId}".`);
|
|
964
|
-
return null;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
874
|
/** Collect a Bitmap Font's texture image, packed under the font's ID. */
|
|
968
875
|
async function collectFontTexture(doc, fontRes, pkg, options) {
|
|
969
876
|
const textureId = fontRes.getTextureId?.() ?? "";
|
|
@@ -3137,7 +3044,7 @@ function publish(options) {
|
|
|
3137
3044
|
return paths.join("/");
|
|
3138
3045
|
}
|
|
3139
3046
|
});
|
|
3140
|
-
const publishPackage = async (plan, writerFs, packageIndex) => {
|
|
3047
|
+
const publishPackage = async (plan, writerFs, packageIndex, preparedMovieClips) => {
|
|
3141
3048
|
if (options.fs && !plan.outputDir) throw new Error("publish: no output directory resolved. Provide --output, or configure global publish.path / package publishPath.");
|
|
3142
3049
|
if (options.fs) {
|
|
3143
3050
|
await options.fs.mkdir(plan.outputDir);
|
|
@@ -3155,6 +3062,7 @@ function publish(options) {
|
|
|
3155
3062
|
mkdir: options.fs ? options.fs.mkdir : void 0,
|
|
3156
3063
|
readFileRaw: options.atlas?.readFileRaw ?? options.fs?.readFileRaw,
|
|
3157
3064
|
strictOutput: options.fs !== void 0,
|
|
3065
|
+
preparedMovieClips,
|
|
3158
3066
|
packages: [plan.pkg.getName()],
|
|
3159
3067
|
...atlasRuntimeOptions
|
|
3160
3068
|
})(doc);
|
|
@@ -3207,8 +3115,25 @@ function publish(options) {
|
|
|
3207
3115
|
}
|
|
3208
3116
|
const unresolvedPlan = plans.find((plan) => !plan.outputDir);
|
|
3209
3117
|
if (unresolvedPlan) throw new Error(`publish: no output directory resolved for package "${unresolvedPlan.pkg.getName()}". Provide --output, or configure global publish.path / package publishPath.`);
|
|
3118
|
+
const publishedMovieClips = allPackages.flatMap((pkg) => {
|
|
3119
|
+
const publishedResourceIds = getAnnotatedPublishedResourceIds(pkg);
|
|
3120
|
+
return pkg.listResources().filter((resource) => {
|
|
3121
|
+
return publishedResourceIds.has(resource.getId()) && isMovieClipResource(resource);
|
|
3122
|
+
}).map((resource) => ({
|
|
3123
|
+
pkg,
|
|
3124
|
+
resource
|
|
3125
|
+
}));
|
|
3126
|
+
});
|
|
3127
|
+
const preparedMovieClips = /* @__PURE__ */ new Map();
|
|
3128
|
+
if (publishedMovieClips.length > 0) {
|
|
3129
|
+
if (!options.encoder) throw new Error("publish: MovieClip output requires an encoder.");
|
|
3130
|
+
if (!options.basePath) throw new Error("publish: MovieClip output requires basePath.");
|
|
3131
|
+
const readFileRaw = options.atlas?.readFileRaw ?? options.fs.readFileRaw;
|
|
3132
|
+
if (!readFileRaw) throw new Error("publish: MovieClip output requires readFileRaw.");
|
|
3133
|
+
for (const { pkg, resource } of publishedMovieClips) preparedMovieClips.set(resource, await prepareMovieClipResource(resource, pkg, options.encoder, options.basePath, readFileRaw));
|
|
3134
|
+
}
|
|
3210
3135
|
const writerFs = toBinaryWriterFileSystem(options.fs);
|
|
3211
|
-
for (const plan of plans) await publishPackage(plan, writerFs, allDocPackages.indexOf(plan.pkg));
|
|
3136
|
+
for (const plan of plans) await publishPackage(plan, writerFs, allDocPackages.indexOf(plan.pkg), preparedMovieClips);
|
|
3212
3137
|
if (options.codeGeneration !== false) await publishCodeGeneration(doc, {
|
|
3213
3138
|
basePath: options.basePath,
|
|
3214
3139
|
fs: options.fs,
|
|
@@ -3309,6 +3234,12 @@ Object.defineProperty(exports, "publishCodeGeneration", {
|
|
|
3309
3234
|
return publishCodeGeneration;
|
|
3310
3235
|
}
|
|
3311
3236
|
});
|
|
3237
|
+
Object.defineProperty(exports, "resolveCodeGenerationSettings", {
|
|
3238
|
+
enumerable: true,
|
|
3239
|
+
get: function() {
|
|
3240
|
+
return resolveCodeGenerationSettings;
|
|
3241
|
+
}
|
|
3242
|
+
});
|
|
3312
3243
|
Object.defineProperty(exports, "resolvePackageCodegenPlan", {
|
|
3313
3244
|
enumerable: true,
|
|
3314
3245
|
get: function() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as
|
|
1
|
+
import { d as basename, f as normalizeComparablePath, p as trimTrailingSlashes } from "./publish--8vagaSA.js";
|
|
2
2
|
import { BinaryReader, ProjectType, ProjectWriter, generateId } from "@openfairygui/core";
|
|
3
3
|
//#region src/restore-internals/output-transaction.ts
|
|
4
4
|
function isPathWithin(root, candidate) {
|
|
@@ -486,6 +486,14 @@ var RestoreWorkflow = class {
|
|
|
486
486
|
common: {},
|
|
487
487
|
adaptation: {}
|
|
488
488
|
});
|
|
489
|
+
for (const pkg of doc.getRoot().listPackages()) pkg.setSourceAtlasSettings({
|
|
490
|
+
...pkg.getSourceAtlasSettings(),
|
|
491
|
+
atlases: pkg.listAtlases().map((atlas) => ({
|
|
492
|
+
index: atlas.getIndex(),
|
|
493
|
+
name: atlas.getIndex() === 0 ? "Default" : atlas.getName(),
|
|
494
|
+
compression: false
|
|
495
|
+
}))
|
|
496
|
+
});
|
|
489
497
|
}
|
|
490
498
|
_initializeImageFileNames(doc) {
|
|
491
499
|
for (const pkg of doc.getRoot().listPackages()) for (const resource of pkg.listResources()) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_publish = require("./publish-
|
|
1
|
+
const require_publish = require("./publish-Bv7E2fZE.cjs");
|
|
2
2
|
let _openfairygui_core = require("@openfairygui/core");
|
|
3
3
|
//#region src/restore-internals/output-transaction.ts
|
|
4
4
|
function isPathWithin(root, candidate) {
|
|
@@ -486,6 +486,14 @@ var RestoreWorkflow = class {
|
|
|
486
486
|
common: {},
|
|
487
487
|
adaptation: {}
|
|
488
488
|
});
|
|
489
|
+
for (const pkg of doc.getRoot().listPackages()) pkg.setSourceAtlasSettings({
|
|
490
|
+
...pkg.getSourceAtlasSettings(),
|
|
491
|
+
atlases: pkg.listAtlases().map((atlas) => ({
|
|
492
|
+
index: atlas.getIndex(),
|
|
493
|
+
name: atlas.getIndex() === 0 ? "Default" : atlas.getName(),
|
|
494
|
+
compression: false
|
|
495
|
+
}))
|
|
496
|
+
});
|
|
489
497
|
}
|
|
490
498
|
_initializeImageFileNames(doc) {
|
|
491
499
|
for (const pkg of doc.getRoot().listPackages()) for (const resource of pkg.listResources()) {
|
package/dist/web.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_publish = require("./publish-
|
|
2
|
+
const require_publish = require("./publish-Bv7E2fZE.cjs");
|
|
3
3
|
let _openfairygui_core = require("@openfairygui/core");
|
|
4
4
|
//#region src/adapters/web/raster.ts
|
|
5
5
|
function getBrowserContext(canvas) {
|
|
@@ -223,6 +223,15 @@ function toResult(success, files, diagnostics) {
|
|
|
223
223
|
diagnostics
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
+
function unsupportedSetting(setting, path, message) {
|
|
227
|
+
return {
|
|
228
|
+
level: "error",
|
|
229
|
+
code: "unsupported_publish_setting",
|
|
230
|
+
setting,
|
|
231
|
+
path,
|
|
232
|
+
message
|
|
233
|
+
};
|
|
234
|
+
}
|
|
226
235
|
/**
|
|
227
236
|
* Publish a loaded FairyGUI project to browser-provided storage.
|
|
228
237
|
*
|
|
@@ -238,14 +247,33 @@ async function publishBrowser(options) {
|
|
|
238
247
|
options.document.setLogger(createDiagnosticLogger(previousLogger, diagnostics));
|
|
239
248
|
try {
|
|
240
249
|
if (options.projectType !== "layabox") throw new Error(`publishBrowser: unsupported project type "${String(options.projectType)}".`);
|
|
241
|
-
assertBrowserImageSupport();
|
|
242
250
|
root.setProjectType(_openfairygui_core.ProjectType.LayaBox);
|
|
251
|
+
const resolved = require_publish.resolvePublishOptions(options.document, {
|
|
252
|
+
compressed: options.compressed,
|
|
253
|
+
packages: options.packages,
|
|
254
|
+
atlas: options.atlas
|
|
255
|
+
});
|
|
256
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(resolved.fileExtension)) {
|
|
257
|
+
diagnostics.push(unsupportedSetting("fileExtension", "settings.publish.fileExtension", `publishBrowser: unsupported fileExtension "${resolved.fileExtension}".`));
|
|
258
|
+
return toResult(false, files, diagnostics);
|
|
259
|
+
}
|
|
260
|
+
const selectedPackageNames = options.packages?.length ? new Set(options.packages) : null;
|
|
261
|
+
const selectedPackages = root.listPackages().filter((pkg) => !selectedPackageNames || selectedPackageNames.has(pkg.getName()));
|
|
262
|
+
if (require_publish.resolveCodeGenerationSettings(options.document).allowGenCode) {
|
|
263
|
+
const packageIndex = selectedPackages.findIndex((pkg) => pkg.getGenCode());
|
|
264
|
+
if (packageIndex >= 0) {
|
|
265
|
+
const pkg = selectedPackages[packageIndex];
|
|
266
|
+
diagnostics.push(unsupportedSetting("codeGeneration", `packages[${root.listPackages().indexOf(pkg)}].publish.genCode`, `publishBrowser: code generation requested by package "${pkg.getName()}" is not supported.`));
|
|
267
|
+
return toResult(false, files, diagnostics);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
assertBrowserImageSupport();
|
|
243
271
|
const outputFileSystem = createTrackingFileSystem(options.outputFileSystem, files);
|
|
244
272
|
const sourceAssetsPath = options.sourceFileSystem.join(options.document.getProjectDir(), "assets");
|
|
245
273
|
await options.document.transform(require_publish.publish({
|
|
246
274
|
output: options.output,
|
|
247
|
-
compressed:
|
|
248
|
-
fileExtension:
|
|
275
|
+
compressed: resolved.compressed,
|
|
276
|
+
fileExtension: resolved.fileExtension,
|
|
249
277
|
packages: options.packages,
|
|
250
278
|
branch: options.branch,
|
|
251
279
|
basePath: sourceAssetsPath,
|
|
@@ -262,6 +290,7 @@ async function publishBrowser(options) {
|
|
|
262
290
|
} catch (error) {
|
|
263
291
|
diagnostics.push({
|
|
264
292
|
level: "error",
|
|
293
|
+
code: "publish_failed",
|
|
265
294
|
message: error instanceof Error ? error.message : String(error)
|
|
266
295
|
});
|
|
267
296
|
return toResult(false, files, diagnostics);
|
package/dist/web.d.cts
CHANGED
|
@@ -20,6 +20,9 @@ interface BrowserPublishOptions {
|
|
|
20
20
|
interface BrowserPublishDiagnostic {
|
|
21
21
|
level: 'debug' | 'info' | 'warning' | 'error';
|
|
22
22
|
message: string;
|
|
23
|
+
code?: 'unsupported_publish_setting' | 'publish_failed';
|
|
24
|
+
setting?: string;
|
|
25
|
+
path?: string;
|
|
23
26
|
}
|
|
24
27
|
interface BrowserPublishedFile {
|
|
25
28
|
path: string;
|
package/dist/web.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ interface BrowserPublishOptions {
|
|
|
20
20
|
interface BrowserPublishDiagnostic {
|
|
21
21
|
level: 'debug' | 'info' | 'warning' | 'error';
|
|
22
22
|
message: string;
|
|
23
|
+
code?: 'unsupported_publish_setting' | 'publish_failed';
|
|
24
|
+
setting?: string;
|
|
25
|
+
path?: string;
|
|
23
26
|
}
|
|
24
27
|
interface BrowserPublishedFile {
|
|
25
28
|
path: string;
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as publish } from "./publish
|
|
1
|
+
import { c as resolveCodeGenerationSettings, n as resolvePublishOptions, t as publish } from "./publish--8vagaSA.js";
|
|
2
2
|
import { ProjectType } from "@openfairygui/core";
|
|
3
3
|
//#region src/adapters/web/raster.ts
|
|
4
4
|
function getBrowserContext(canvas) {
|
|
@@ -222,6 +222,15 @@ function toResult(success, files, diagnostics) {
|
|
|
222
222
|
diagnostics
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
|
+
function unsupportedSetting(setting, path, message) {
|
|
226
|
+
return {
|
|
227
|
+
level: "error",
|
|
228
|
+
code: "unsupported_publish_setting",
|
|
229
|
+
setting,
|
|
230
|
+
path,
|
|
231
|
+
message
|
|
232
|
+
};
|
|
233
|
+
}
|
|
225
234
|
/**
|
|
226
235
|
* Publish a loaded FairyGUI project to browser-provided storage.
|
|
227
236
|
*
|
|
@@ -237,14 +246,33 @@ async function publishBrowser(options) {
|
|
|
237
246
|
options.document.setLogger(createDiagnosticLogger(previousLogger, diagnostics));
|
|
238
247
|
try {
|
|
239
248
|
if (options.projectType !== "layabox") throw new Error(`publishBrowser: unsupported project type "${String(options.projectType)}".`);
|
|
240
|
-
assertBrowserImageSupport();
|
|
241
249
|
root.setProjectType(ProjectType.LayaBox);
|
|
250
|
+
const resolved = resolvePublishOptions(options.document, {
|
|
251
|
+
compressed: options.compressed,
|
|
252
|
+
packages: options.packages,
|
|
253
|
+
atlas: options.atlas
|
|
254
|
+
});
|
|
255
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(resolved.fileExtension)) {
|
|
256
|
+
diagnostics.push(unsupportedSetting("fileExtension", "settings.publish.fileExtension", `publishBrowser: unsupported fileExtension "${resolved.fileExtension}".`));
|
|
257
|
+
return toResult(false, files, diagnostics);
|
|
258
|
+
}
|
|
259
|
+
const selectedPackageNames = options.packages?.length ? new Set(options.packages) : null;
|
|
260
|
+
const selectedPackages = root.listPackages().filter((pkg) => !selectedPackageNames || selectedPackageNames.has(pkg.getName()));
|
|
261
|
+
if (resolveCodeGenerationSettings(options.document).allowGenCode) {
|
|
262
|
+
const packageIndex = selectedPackages.findIndex((pkg) => pkg.getGenCode());
|
|
263
|
+
if (packageIndex >= 0) {
|
|
264
|
+
const pkg = selectedPackages[packageIndex];
|
|
265
|
+
diagnostics.push(unsupportedSetting("codeGeneration", `packages[${root.listPackages().indexOf(pkg)}].publish.genCode`, `publishBrowser: code generation requested by package "${pkg.getName()}" is not supported.`));
|
|
266
|
+
return toResult(false, files, diagnostics);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
assertBrowserImageSupport();
|
|
242
270
|
const outputFileSystem = createTrackingFileSystem(options.outputFileSystem, files);
|
|
243
271
|
const sourceAssetsPath = options.sourceFileSystem.join(options.document.getProjectDir(), "assets");
|
|
244
272
|
await options.document.transform(publish({
|
|
245
273
|
output: options.output,
|
|
246
|
-
compressed:
|
|
247
|
-
fileExtension:
|
|
274
|
+
compressed: resolved.compressed,
|
|
275
|
+
fileExtension: resolved.fileExtension,
|
|
248
276
|
packages: options.packages,
|
|
249
277
|
branch: options.branch,
|
|
250
278
|
basePath: sourceAssetsPath,
|
|
@@ -261,6 +289,7 @@ async function publishBrowser(options) {
|
|
|
261
289
|
} catch (error) {
|
|
262
290
|
diagnostics.push({
|
|
263
291
|
level: "error",
|
|
292
|
+
code: "publish_failed",
|
|
264
293
|
message: error instanceof Error ? error.message : String(error)
|
|
265
294
|
});
|
|
266
295
|
return toResult(false, files, diagnostics);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfairygui/functions",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.35",
|
|
4
4
|
"description": "FairyGUI Headless Authoring SDK — composable transform functions.",
|
|
5
5
|
"author": "OpenFairyGUI Contributors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"jiti": "^2.6.1",
|
|
77
|
-
"@openfairygui/core": "0.2.0-alpha.
|
|
77
|
+
"@openfairygui/core": "0.2.0-alpha.35"
|
|
78
78
|
},
|
|
79
79
|
"optionalDependencies": {
|
|
80
80
|
"sharp": ">=0.33.0"
|