@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 CHANGED
@@ -49,7 +49,9 @@ const result = await publishBrowser({
49
49
  if (!result.success) console.error(result.diagnostics);
50
50
  ```
51
51
 
52
- The browser entry uses native Canvas APIs for atlas PNGs, writes only through `outputFileSystem`, supplies no Node plugin capability, and disables non-runtime code generation.
52
+ The browser entry uses native Canvas APIs for atlas PNGs, writes only through `outputFileSystem`, and supplies no Node plugin capability. Persisted Laya publish compression, atlas, and safe file-extension settings apply; explicit `compressed` and `atlas` options override their corresponding settings. Explicit `output`, `branch`, and `packages` also keep their normal precedence, so desktop-only configured output paths are not used when `output` is supplied.
53
+
54
+ Browser code generation is not supported. If global code generation is enabled and a selected package requests it, preflight returns `unsupported_publish_setting` with `setting` and `path` before Canvas checks or output writes. On any failure, `files` lists only `writeFileRaw` operations that completed successfully; `success: false` with a non-empty list therefore means built-in output is partial. Callers needing atomic publication should provide a transactional or staging `outputFileSystem`.
53
55
 
54
56
  Publish plugins are documented in the repository guide:
55
57
 
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_publish = require("./publish-DCP0AYx2.cjs");
3
- const require_restore = require("./restore-BUaCK8ui.cjs");
2
+ const require_publish = require("./publish-Bv7E2fZE.cjs");
3
+ const require_restore = require("./restore-iTgeWr7-.cjs");
4
4
  const require_uam_transaction = require("./uam-transaction.cjs");
5
5
  //#region src/inspect.ts
6
6
  function mapResource(resource) {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as decodeText, c as resolvePackageCodegenPlan, h as createTransform, i as buildCodegenClasses, m as atlas, n as resolvePublishOptions, o as encodeText, r as AUTO_GENERATED_CODE_MARK, s as publishCodeGeneration, t as publish } from "./publish-BJk8UzRP.js";
2
- import { t as restore } from "./restore-C98ugT2H.js";
1
+ import { a as decodeText, g as createTransform, h as atlas, i as buildCodegenClasses, l as resolvePackageCodegenPlan, n as resolvePublishOptions, o as encodeText, r as AUTO_GENERATED_CODE_MARK, s as publishCodeGeneration, t as publish } from "./publish--8vagaSA.js";
2
+ import { t as restore } from "./restore-CknfGMJM.js";
3
3
  import { applyUamTransactionApp, applyUamTransactionAppAsync } from "./uam-transaction.js";
4
4
  //#region src/inspect.ts
5
5
  function mapResource(resource) {
package/dist/node.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_publish = require("./publish-DCP0AYx2.cjs");
3
- const require_restore = require("./restore-BUaCK8ui.cjs");
2
+ const require_publish = require("./publish-Bv7E2fZE.cjs");
3
+ const require_restore = require("./restore-iTgeWr7-.cjs");
4
4
  //#region src/adapters/node/plugins.ts
5
5
  const importNative$2 = new Function("id", "return import(id)");
6
6
  async function loadPlugins(doc, pluginsDir) {
package/dist/node.js CHANGED
@@ -1,5 +1,5 @@
1
- import { l as resolveProjectBasePath, p as formatPluginError, t as publish } from "./publish-BJk8UzRP.js";
2
- import { t as restore } from "./restore-C98ugT2H.js";
1
+ import { m as formatPluginError, t as publish, u as resolveProjectBasePath } from "./publish--8vagaSA.js";
2
+ import { t as restore } from "./restore-CknfGMJM.js";
3
3
  //#region src/adapters/node/plugins.ts
4
4
  const importNative$2 = new Function("id", "return import(id)");
5
5
  async function loadPlugins(doc, pluginsDir) {
@@ -1,4 +1,4 @@
1
- import { BinaryWriter, GearType, ProjectType, TransitionActionType } from "@openfairygui/core";
1
+ import { BinaryWriter, GearType, ProjectType, TransitionActionType, deriveMovieClipModel, parseJta, probeRasterImage } from "@openfairygui/core";
2
2
  //#region src/utils.ts
3
3
  /**
4
4
  * Wraps a transform function, assigning it a name for the transform stack.
@@ -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 frames = [];
614
- let offset = 0;
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 = parseJta(data);
604
+ const derived = deriveMovieClipModel(parsed);
626
605
  return {
627
- frames,
628
- meta: parseJtaHeader(data, firstPngOffset, frames.length)
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 findPngSignature(data, fromIndex) {
632
- for (let index = fromIndex; index <= data.length - PNG_SIGNATURE.length; index += 1) {
633
- let matched = true;
634
- for (let signatureIndex = 0; signatureIndex < PNG_SIGNATURE.length; signatureIndex += 1) if (data[index + signatureIndex] !== PNG_SIGNATURE[signatureIndex]) {
635
- matched = false;
636
- break;
637
- }
638
- if (matched) return index;
639
- }
640
- return -1;
641
- }
642
- function findPngEnd(data, start) {
643
- let position = start + PNG_SIGNATURE.length;
644
- while (position + 8 <= data.length) {
645
- const length = readUint32BE(data, position);
646
- position += 8;
647
- if (position + length + 4 > data.length) return -1;
648
- const isEnd = data[position - 4] === 73 && data[position - 3] === 69 && data[position - 2] === 78 && data[position - 1] === 68;
649
- position += length + 4;
650
- if (isEnd) return position;
651
- }
652
- return -1;
653
- }
654
- function parseJtaHeader(data, firstPngOffset, frameCount) {
655
- if (data.length < 10) return void 0;
656
- const state = { offset: 0 };
657
- const end = Math.min(firstPngOffset, data.length);
658
- if (!readUtfBE(data, state, end)) return void 0;
659
- const version = readInt32BEAt(data, state, end);
660
- if (version == null) return void 0;
661
- const fpsRaw = readInt8At(data, state, end);
662
- if (fpsRaw == null) return void 0;
663
- const fps = fpsRaw > 0 ? fpsRaw : 24;
664
- if (state.offset + 3 > end) return void 0;
665
- state.offset += 3;
666
- if (version < 102) return void 0;
667
- readUint16BEAt(data, state, end);
668
- readUint16BEAt(data, state, end);
669
- const width = readUint16BEAt(data, state, end);
670
- const height = readUint16BEAt(data, state, end);
671
- if (width == null || height == null) return void 0;
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 = 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 = 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
- interval: Math.trunc(1e3 / fps * (speedRaw || 1)),
697
- repeatDelay: Math.trunc(1e3 / fps * repeatDelayRaw),
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 mcName = resource.getName() + ".jta";
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 = extractJtaFrames(await options.readFileRaw(filePath));
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?.interval ?? 100).setSwing(jta.meta?.swing ?? false).setRepeatDelay(jta.meta?.repeatDelay ?? 0);
900
- if (frameMetas.length > 0) {
901
- const firstFrameIndexByTextureIndex = /* @__PURE__ */ new Map();
902
- for (let frameIndex = 0; frameIndex < frameMetas.length; frameIndex += 1) {
903
- const meta = frameMetas[frameIndex];
904
- const textureIndex = Number.isFinite(meta.textureIndex) ? meta.textureIndex : frameIndex;
905
- if (!firstFrameIndexByTextureIndex.has(textureIndex)) firstFrameIndexByTextureIndex.set(textureIndex, frameIndex);
906
- }
907
- const spriteIdByTextureIndex = /* @__PURE__ */ new Map();
908
- for (let textureIndex = 0; textureIndex < jta.frames.length; textureIndex += 1) {
909
- const exportFrameIndex = firstFrameIndexByTextureIndex.get(textureIndex);
910
- if (exportFrameIndex === void 0) continue;
911
- const itemId = `${mcId}_${exportFrameIndex}`;
912
- const input = await createMovieClipFrameInput(jta.frames[textureIndex], itemId, resource, encoder, options.strictOutput);
913
- if (!input) continue;
914
- inputs.push(input);
915
- spriteIdByTextureIndex.set(textureIndex, itemId);
916
- }
917
- for (let frameIndex = 0; frameIndex < frameMetas.length; frameIndex += 1) {
918
- const meta = frameMetas[frameIndex];
919
- const textureIndex = Number.isFinite(meta.textureIndex) ? meta.textureIndex : frameIndex;
920
- const frame = doc.createMovieFrame(`${mcId}_${frameIndex}`);
921
- frame.setRectX(meta.offsetX).setRectY(meta.offsetY).setRectWidth(meta.width).setRectHeight(meta.height).setAddDelay(meta.addDelay).setSpriteId(spriteIdByTextureIndex.get(textureIndex) ?? "");
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 ((jta.meta?.width ?? 0) > 0 && (jta.meta?.height ?? 0) > 0) {
934
- resource.setWidth(jta.meta?.width ?? 0);
935
- resource.setHeight(jta.meta?.height ?? 0);
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 new Error(message);
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,
@@ -3243,4 +3168,4 @@ function _computeDependencies(doc, pkg, pkgMap) {
3243
3168
  }
3244
3169
  }
3245
3170
  //#endregion
3246
- export { decodeText as a, resolvePackageCodegenPlan as c, normalizeComparablePath as d, trimTrailingSlashes as f, createTransform as h, buildCodegenClasses as i, resolveProjectBasePath as l, atlas as m, resolvePublishOptions as n, encodeText as o, formatPluginError as p, AUTO_GENERATED_CODE_MARK as r, publishCodeGeneration as s, publish as t, basename as u };
3171
+ export { decodeText as a, resolveCodeGenerationSettings as c, basename as d, normalizeComparablePath as f, createTransform as g, atlas as h, buildCodegenClasses as i, resolvePackageCodegenPlan as l, formatPluginError as m, resolvePublishOptions as n, encodeText as o, trimTrailingSlashes as p, AUTO_GENERATED_CODE_MARK as r, publishCodeGeneration as s, publish as t, resolveProjectBasePath as u };