@openfairygui/functions 0.2.0-alpha.7 → 0.2.0
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 +52 -6
- package/dist/atlas-C6tbl7nn.d.ts +193 -0
- package/dist/atlas-CHsu2Y8i.d.cts +193 -0
- package/dist/index.cjs +17 -3603
- package/dist/index.d.cts +5 -294
- package/dist/index.d.ts +5 -294
- package/dist/index.js +4 -3595
- package/dist/node.cjs +256 -0
- package/dist/node.d.cts +36 -0
- package/dist/node.d.ts +36 -0
- package/dist/node.js +254 -0
- package/dist/publish-CykUJfVa.cjs +3269 -0
- package/dist/publish-DXoaC1Nl.js +3174 -0
- package/dist/restore-BQp01WY3.js +914 -0
- package/dist/restore-BeWaJNjR.d.cts +288 -0
- package/dist/restore-CEywQUHz.cjs +919 -0
- package/dist/restore-Dh0-Nvms.d.ts +288 -0
- package/dist/uam-transaction.cjs +29 -14
- package/dist/uam-transaction.d.cts +2 -1
- package/dist/uam-transaction.d.ts +2 -1
- package/dist/uam-transaction.js +30 -16
- package/dist/web.cjs +440 -0
- package/dist/web.d.cts +44 -0
- package/dist/web.d.ts +44 -0
- package/dist/web.js +439 -0
- package/package.json +29 -4
- package/src/adapters/node/plugins.ts +82 -0
- package/src/adapters/node/publish.ts +130 -0
- package/src/adapters/node/restore.ts +187 -0
- package/src/adapters/web/publish.ts +196 -0
- package/src/adapters/web/raster.ts +421 -0
- package/src/atlas/font.ts +95 -0
- package/src/atlas/inputs.ts +445 -0
- package/src/atlas/jta.ts +157 -0
- package/src/atlas/packing.ts +762 -0
- package/src/atlas.ts +129 -1221
- package/src/codegen.ts +108 -82
- package/src/index.ts +43 -3
- package/src/node.ts +8 -0
- package/src/path-utils.ts +40 -0
- package/src/plugins/types.ts +56 -0
- package/src/publish/contracts.ts +80 -0
- package/src/publish/external-resources.ts +117 -0
- package/src/publish/options.ts +180 -0
- package/src/publish/package-context.ts +608 -0
- package/src/publish/resource-references.ts +210 -0
- package/src/publish.ts +327 -975
- package/src/restore-internals/font.ts +100 -0
- package/src/restore-internals/movie-clip.ts +104 -0
- package/src/restore-internals/output-transaction.ts +124 -0
- package/src/restore.ts +122 -311
- package/src/shared-types.ts +4 -8
- package/src/uam-transaction.ts +34 -17
- package/src/utils.ts +28 -0
- package/src/web.ts +11 -0
package/dist/web.cjs
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_publish = require("./publish-CykUJfVa.cjs");
|
|
3
|
+
let _openfairygui_core = require("@openfairygui/core");
|
|
4
|
+
let fast_xml_parser = require("fast-xml-parser");
|
|
5
|
+
//#region src/adapters/web/raster.ts
|
|
6
|
+
const MAX_SVG_SOURCE_BYTES = 8 * 1024 * 1024;
|
|
7
|
+
const MAX_SVG_DIMENSION = 16384;
|
|
8
|
+
const MAX_SVG_PIXELS = 64 * 1024 * 1024;
|
|
9
|
+
const MAX_SVG_NODES = 5e4;
|
|
10
|
+
const UNSAFE_SVG_ELEMENTS = new Set([
|
|
11
|
+
"a",
|
|
12
|
+
"animate",
|
|
13
|
+
"animatecolor",
|
|
14
|
+
"animatemotion",
|
|
15
|
+
"animatetransform",
|
|
16
|
+
"audio",
|
|
17
|
+
"canvas",
|
|
18
|
+
"discard",
|
|
19
|
+
"embed",
|
|
20
|
+
"feimage",
|
|
21
|
+
"foreignobject",
|
|
22
|
+
"iframe",
|
|
23
|
+
"image",
|
|
24
|
+
"object",
|
|
25
|
+
"script",
|
|
26
|
+
"set",
|
|
27
|
+
"style",
|
|
28
|
+
"video"
|
|
29
|
+
]);
|
|
30
|
+
function unsafeSvg(message) {
|
|
31
|
+
throw new Error(`publishBrowser: unsafe SVG input (${message}).`);
|
|
32
|
+
}
|
|
33
|
+
function svgLocalName(name) {
|
|
34
|
+
return name.split(":").at(-1).toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
function parseSvgLength(value, name) {
|
|
37
|
+
if (value === void 0) return void 0;
|
|
38
|
+
const match = String(value).match(/^\s*(?:\d+(?:\.\d+)?|\.\d+)(?:px)?\s*$/iu);
|
|
39
|
+
if (!match) unsafeSvg(`${name} must use a finite pixel value`);
|
|
40
|
+
const parsed = Number.parseFloat(match[0]);
|
|
41
|
+
if (!Number.isFinite(parsed) || parsed <= 0 || parsed > MAX_SVG_DIMENSION) unsafeSvg(`${name} exceeds the supported dimensions`);
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
function validateSvgAttribute(name, value) {
|
|
45
|
+
const normalizedName = name.toLowerCase();
|
|
46
|
+
if (normalizedName === "xmlns" || normalizedName.startsWith("xmlns:")) return;
|
|
47
|
+
const localName = svgLocalName(name);
|
|
48
|
+
const text = String(value);
|
|
49
|
+
if (localName.startsWith("on")) unsafeSvg(`event attribute "${name}" is not allowed`);
|
|
50
|
+
if (localName === "style" || localName === "src") unsafeSvg(`attribute "${name}" is not allowed`);
|
|
51
|
+
if (localName === "href" && !/^#[A-Za-z_][\w:.-]*$/u.test(text)) unsafeSvg(`external reference in "${name}" is not allowed`);
|
|
52
|
+
if (/(?:^|[\s("'=])(?:https?:|file:|javascript:|data:|\/\/)/iu.test(text)) unsafeSvg(`external URL in "${name}" is not allowed`);
|
|
53
|
+
for (const match of text.matchAll(/url\s*\(([^)]*)\)/giu)) {
|
|
54
|
+
const reference = (match[1] ?? "").trim().replace(/^(['"])(.*)\1$/u, "$2");
|
|
55
|
+
if (!/^#[A-Za-z_][\w:.-]*$/u.test(reference)) unsafeSvg(`external url() in "${name}" is not allowed`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function visitSvgEntry(entry) {
|
|
59
|
+
const pending = [entry];
|
|
60
|
+
let nodeCount = 0;
|
|
61
|
+
while (pending.length > 0) {
|
|
62
|
+
const current = pending.pop();
|
|
63
|
+
for (const [name, value] of Object.entries(current)) {
|
|
64
|
+
if (name === ":@" || name.startsWith("#") || name.startsWith("?")) continue;
|
|
65
|
+
if (++nodeCount > MAX_SVG_NODES) unsafeSvg("node count exceeds the supported limit");
|
|
66
|
+
const localName = svgLocalName(name);
|
|
67
|
+
if (UNSAFE_SVG_ELEMENTS.has(localName)) unsafeSvg(`element <${name}> is not allowed`);
|
|
68
|
+
for (const [attributeName, attributeValue] of Object.entries(current[":@"] ?? {})) validateSvgAttribute(attributeName, attributeValue);
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
for (const child of value) if (child && typeof child === "object" && !Array.isArray(child)) pending.push(child);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function validateSvg(bytes) {
|
|
76
|
+
if (bytes.byteLength === 0 || bytes.byteLength > MAX_SVG_SOURCE_BYTES) unsafeSvg("source size is unsupported");
|
|
77
|
+
let source;
|
|
78
|
+
try {
|
|
79
|
+
source = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
80
|
+
} catch {
|
|
81
|
+
unsafeSvg("source is not valid UTF-8");
|
|
82
|
+
}
|
|
83
|
+
if (/<!\s*(?:doctype|entity)\b|<\?xml-stylesheet\b/iu.test(source)) unsafeSvg("DTD, entities, and stylesheets are not allowed");
|
|
84
|
+
if (fast_xml_parser.XMLValidator.validate(source, { allowBooleanAttributes: false }) !== true) unsafeSvg("source is not well-formed XML");
|
|
85
|
+
const roots = new fast_xml_parser.XMLParser({
|
|
86
|
+
preserveOrder: true,
|
|
87
|
+
ignoreAttributes: false,
|
|
88
|
+
attributeNamePrefix: "",
|
|
89
|
+
parseAttributeValue: false,
|
|
90
|
+
parseTagValue: false,
|
|
91
|
+
processEntities: false,
|
|
92
|
+
trimValues: false
|
|
93
|
+
}).parse(source).flatMap((entry) => Object.keys(entry).filter((name) => name !== ":@" && !name.startsWith("#") && !name.startsWith("?")).map((name) => ({
|
|
94
|
+
entry,
|
|
95
|
+
name
|
|
96
|
+
})));
|
|
97
|
+
if (roots.length !== 1 || svgLocalName(roots[0].name) !== "svg") unsafeSvg("a single <svg> root is required");
|
|
98
|
+
const root = roots[0].entry;
|
|
99
|
+
visitSvgEntry(root);
|
|
100
|
+
const attributes = root[":@"] ?? {};
|
|
101
|
+
const width = parseSvgLength(attributes.width, "width");
|
|
102
|
+
const height = parseSvgLength(attributes.height, "height");
|
|
103
|
+
let viewBoxWidth;
|
|
104
|
+
let viewBoxHeight;
|
|
105
|
+
if (attributes.viewBox !== void 0) {
|
|
106
|
+
const viewBox = String(attributes.viewBox).trim().split(/[\s,]+/u).map(Number);
|
|
107
|
+
if (viewBox.length !== 4 || viewBox.some((value) => !Number.isFinite(value)) || viewBox[2] <= 0 || viewBox[3] <= 0) unsafeSvg("viewBox must contain four finite values with positive dimensions");
|
|
108
|
+
viewBoxWidth = viewBox[2];
|
|
109
|
+
viewBoxHeight = viewBox[3];
|
|
110
|
+
if (viewBoxWidth > MAX_SVG_DIMENSION || viewBoxHeight > MAX_SVG_DIMENSION) unsafeSvg("viewBox exceeds the supported dimensions");
|
|
111
|
+
}
|
|
112
|
+
if ((width ?? viewBoxWidth ?? 300) * (height ?? viewBoxHeight ?? 150) > MAX_SVG_PIXELS) unsafeSvg("pixel count exceeds the supported limit");
|
|
113
|
+
}
|
|
114
|
+
function getBrowserContext(canvas) {
|
|
115
|
+
const context = canvas.getContext("2d");
|
|
116
|
+
if (!context) throw new Error("publishBrowser: a 2D canvas context is unavailable.");
|
|
117
|
+
return context;
|
|
118
|
+
}
|
|
119
|
+
function createBrowserCanvas(width, height) {
|
|
120
|
+
if (typeof OffscreenCanvas !== "undefined") return new OffscreenCanvas(width, height);
|
|
121
|
+
if (typeof globalThis.document === "undefined") throw new Error("publishBrowser: OffscreenCanvas or a DOM canvas is required for atlas PNG generation.");
|
|
122
|
+
const canvas = globalThis.document.createElement("canvas");
|
|
123
|
+
canvas.width = width;
|
|
124
|
+
canvas.height = height;
|
|
125
|
+
return canvas;
|
|
126
|
+
}
|
|
127
|
+
function assertBrowserImageSupport() {
|
|
128
|
+
if (typeof createImageBitmap !== "function") throw new Error("publishBrowser: createImageBitmap is required for atlas PNG generation.");
|
|
129
|
+
if (typeof OffscreenCanvas === "undefined" && typeof globalThis.document === "undefined") throw new Error("publishBrowser: OffscreenCanvas or a DOM canvas is required for atlas PNG generation.");
|
|
130
|
+
}
|
|
131
|
+
function createRaster(width, height, background) {
|
|
132
|
+
const canvas = createBrowserCanvas(width, height);
|
|
133
|
+
const context = getBrowserContext(canvas);
|
|
134
|
+
context.clearRect(0, 0, width, height);
|
|
135
|
+
if (background && background.alpha > 0) {
|
|
136
|
+
context.fillStyle = `rgba(${background.r}, ${background.g}, ${background.b}, ${background.alpha})`;
|
|
137
|
+
context.fillRect(0, 0, width, height);
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
canvas,
|
|
141
|
+
width,
|
|
142
|
+
height
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function imageMimeType(path) {
|
|
146
|
+
if (/\.svg$/iu.test(path)) return "image/svg+xml";
|
|
147
|
+
if (/\.jpe?g$/iu.test(path)) return "image/jpeg";
|
|
148
|
+
if (/\.webp$/iu.test(path)) return "image/webp";
|
|
149
|
+
if (/\.gif$/iu.test(path)) return "image/gif";
|
|
150
|
+
return "image/png";
|
|
151
|
+
}
|
|
152
|
+
function imageMimeTypeFromBytes(bytes) {
|
|
153
|
+
if (bytes[0] === 255 && bytes[1] === 216) return "image/jpeg";
|
|
154
|
+
if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70) return "image/gif";
|
|
155
|
+
if (bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70) return "image/webp";
|
|
156
|
+
return "image/png";
|
|
157
|
+
}
|
|
158
|
+
async function canvasToPng(canvas) {
|
|
159
|
+
let blob;
|
|
160
|
+
if ("convertToBlob" in canvas && typeof canvas.convertToBlob === "function") blob = await canvas.convertToBlob({ type: "image/png" });
|
|
161
|
+
else blob = await new Promise((resolve, reject) => {
|
|
162
|
+
canvas.toBlob((value) => {
|
|
163
|
+
if (value) resolve(value);
|
|
164
|
+
else reject(/* @__PURE__ */ new Error("publishBrowser: canvas PNG encoding failed."));
|
|
165
|
+
}, "image/png");
|
|
166
|
+
});
|
|
167
|
+
return new Uint8Array(await blob.arrayBuffer());
|
|
168
|
+
}
|
|
169
|
+
async function decodeRaster(bytes, mimeType) {
|
|
170
|
+
if (typeof createImageBitmap !== "function") throw new Error("publishBrowser: createImageBitmap is required for atlas PNG generation.");
|
|
171
|
+
const copy = bytes.slice();
|
|
172
|
+
if (mimeType === "image/svg+xml") validateSvg(copy);
|
|
173
|
+
const blob = new Blob([copy.buffer], { type: mimeType });
|
|
174
|
+
let bitmap;
|
|
175
|
+
try {
|
|
176
|
+
bitmap = await createImageBitmap(blob);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (mimeType !== "image/svg+xml") throw error;
|
|
179
|
+
return decodeSvgWithDom(blob);
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const raster = createRaster(bitmap.width, bitmap.height);
|
|
183
|
+
getBrowserContext(raster.canvas).drawImage(bitmap, 0, 0);
|
|
184
|
+
return raster;
|
|
185
|
+
} finally {
|
|
186
|
+
bitmap.close();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function decodeSvgWithDom(blob) {
|
|
190
|
+
if (typeof globalThis.Image !== "function" || typeof globalThis.URL?.createObjectURL !== "function" || typeof globalThis.URL?.revokeObjectURL !== "function") throw new Error("publishBrowser: createImageBitmap rejected SVG and DOM image decoding is unavailable.");
|
|
191
|
+
const url = globalThis.URL.createObjectURL(blob);
|
|
192
|
+
try {
|
|
193
|
+
const image = new globalThis.Image();
|
|
194
|
+
await new Promise((resolve, reject) => {
|
|
195
|
+
image.onload = () => resolve();
|
|
196
|
+
image.onerror = () => reject(/* @__PURE__ */ new Error("publishBrowser: DOM image decoding failed for SVG."));
|
|
197
|
+
image.src = url;
|
|
198
|
+
});
|
|
199
|
+
const width = image.naturalWidth || image.width;
|
|
200
|
+
const height = image.naturalHeight || image.height;
|
|
201
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0 || width > MAX_SVG_DIMENSION || height > MAX_SVG_DIMENSION || width * height > MAX_SVG_PIXELS) unsafeSvg("decoded dimensions exceed the supported limit");
|
|
202
|
+
const raster = createRaster(width, height);
|
|
203
|
+
getBrowserContext(raster.canvas).drawImage(image, 0, 0);
|
|
204
|
+
return raster;
|
|
205
|
+
} finally {
|
|
206
|
+
globalThis.URL.revokeObjectURL(url);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
var BrowserImagePipeline = class {
|
|
210
|
+
rawOutput = false;
|
|
211
|
+
constructor(raster, decode, write) {
|
|
212
|
+
this.raster = raster;
|
|
213
|
+
this.decode = decode;
|
|
214
|
+
this.write = write;
|
|
215
|
+
}
|
|
216
|
+
ensureAlpha() {
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
resize(options) {
|
|
220
|
+
this.raster = this.raster.then((source) => {
|
|
221
|
+
const target = createRaster(options.width, options.height);
|
|
222
|
+
getBrowserContext(target.canvas).drawImage(source.canvas, 0, 0, options.width, options.height);
|
|
223
|
+
return target;
|
|
224
|
+
});
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
raw() {
|
|
228
|
+
this.rawOutput = true;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
extract(options) {
|
|
232
|
+
this.raster = this.raster.then((source) => {
|
|
233
|
+
const target = createRaster(options.width, options.height);
|
|
234
|
+
getBrowserContext(target.canvas).drawImage(source.canvas, options.left, options.top, options.width, options.height, 0, 0, options.width, options.height);
|
|
235
|
+
return target;
|
|
236
|
+
});
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
png() {
|
|
240
|
+
this.rawOutput = false;
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
rotate(angle) {
|
|
244
|
+
this.raster = this.raster.then((source) => {
|
|
245
|
+
if (angle % 180 === 0) return source;
|
|
246
|
+
const target = createRaster(source.height, source.width);
|
|
247
|
+
const context = getBrowserContext(target.canvas);
|
|
248
|
+
context.save();
|
|
249
|
+
if (angle === 270 || angle === -90) {
|
|
250
|
+
context.translate(0, source.width);
|
|
251
|
+
context.rotate(-Math.PI / 2);
|
|
252
|
+
} else {
|
|
253
|
+
context.translate(source.height, 0);
|
|
254
|
+
context.rotate(Math.PI / 2);
|
|
255
|
+
}
|
|
256
|
+
context.drawImage(source.canvas, 0, 0);
|
|
257
|
+
context.restore();
|
|
258
|
+
return target;
|
|
259
|
+
});
|
|
260
|
+
return this;
|
|
261
|
+
}
|
|
262
|
+
composite(inputs) {
|
|
263
|
+
this.raster = this.raster.then(async (target) => {
|
|
264
|
+
const context = getBrowserContext(target.canvas);
|
|
265
|
+
for (const input of inputs) {
|
|
266
|
+
const source = await this.decode(input.input);
|
|
267
|
+
context.drawImage(source.canvas, input.left, input.top);
|
|
268
|
+
}
|
|
269
|
+
return target;
|
|
270
|
+
});
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
async metadata() {
|
|
274
|
+
const raster = await this.raster;
|
|
275
|
+
return {
|
|
276
|
+
width: raster.width,
|
|
277
|
+
height: raster.height,
|
|
278
|
+
channels: 4,
|
|
279
|
+
hasAlpha: true
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
async toBuffer(options) {
|
|
283
|
+
const raster = await this.raster;
|
|
284
|
+
if (options?.resolveWithObject) {
|
|
285
|
+
const data = getBrowserContext(raster.canvas).getImageData(0, 0, raster.width, raster.height).data;
|
|
286
|
+
return {
|
|
287
|
+
data: new Uint8Array(data),
|
|
288
|
+
info: {
|
|
289
|
+
width: raster.width,
|
|
290
|
+
height: raster.height,
|
|
291
|
+
channels: 4
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
if (this.rawOutput) return new Uint8Array(getBrowserContext(raster.canvas).getImageData(0, 0, raster.width, raster.height).data);
|
|
296
|
+
return canvasToPng(raster.canvas);
|
|
297
|
+
}
|
|
298
|
+
async toFile(path) {
|
|
299
|
+
const raster = await this.raster;
|
|
300
|
+
await this.write(path, await canvasToPng(raster.canvas));
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
function createBrowserImageEncoder(sourceFileSystem, outputFileSystem) {
|
|
304
|
+
const decode = (bytes) => decodeRaster(bytes, imageMimeTypeFromBytes(bytes));
|
|
305
|
+
return (input) => {
|
|
306
|
+
return new BrowserImagePipeline(typeof input === "string" ? sourceFileSystem.readFileRaw(input).then((bytes) => decodeRaster(bytes, imageMimeType(input))) : input instanceof Uint8Array ? decode(input) : Promise.resolve(createRaster(input.create.width, input.create.height, input.create.background)), decode, outputFileSystem.writeFileRaw);
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/adapters/web/publish.ts
|
|
311
|
+
function createTrackingFileSystem(fileSystem, files) {
|
|
312
|
+
return {
|
|
313
|
+
join: (...paths) => fileSystem.join(...paths),
|
|
314
|
+
mkdir: (path) => fileSystem.mkdir(path),
|
|
315
|
+
writeFileRaw: async (path, data) => {
|
|
316
|
+
await fileSystem.writeFileRaw(path, data);
|
|
317
|
+
files.set(path, data.byteLength);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function createDiagnosticLogger(logger, diagnostics) {
|
|
322
|
+
return {
|
|
323
|
+
debug(message) {
|
|
324
|
+
diagnostics.push({
|
|
325
|
+
level: "debug",
|
|
326
|
+
message
|
|
327
|
+
});
|
|
328
|
+
logger.debug(message);
|
|
329
|
+
},
|
|
330
|
+
info(message) {
|
|
331
|
+
diagnostics.push({
|
|
332
|
+
level: "info",
|
|
333
|
+
message
|
|
334
|
+
});
|
|
335
|
+
logger.info(message);
|
|
336
|
+
},
|
|
337
|
+
warn(message) {
|
|
338
|
+
diagnostics.push({
|
|
339
|
+
level: "warning",
|
|
340
|
+
message
|
|
341
|
+
});
|
|
342
|
+
logger.warn(message);
|
|
343
|
+
},
|
|
344
|
+
error(message) {
|
|
345
|
+
diagnostics.push({
|
|
346
|
+
level: "error",
|
|
347
|
+
message
|
|
348
|
+
});
|
|
349
|
+
logger.error(message);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function toResult(success, files, diagnostics) {
|
|
354
|
+
return {
|
|
355
|
+
success,
|
|
356
|
+
files: [...files].map(([path, size]) => ({
|
|
357
|
+
path,
|
|
358
|
+
size
|
|
359
|
+
})),
|
|
360
|
+
diagnostics
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function unsupportedSetting(setting, path, message) {
|
|
364
|
+
return {
|
|
365
|
+
level: "error",
|
|
366
|
+
code: "unsupported_publish_setting",
|
|
367
|
+
setting,
|
|
368
|
+
path,
|
|
369
|
+
message
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Publish a loaded FairyGUI project to browser-provided storage.
|
|
374
|
+
*
|
|
375
|
+
* The adapter uses browser Canvas APIs for atlas composition, writes only through
|
|
376
|
+
* the supplied output filesystem, and intentionally skips Node publish plugins.
|
|
377
|
+
*/
|
|
378
|
+
async function publishBrowser(options) {
|
|
379
|
+
const files = /* @__PURE__ */ new Map();
|
|
380
|
+
const diagnostics = [];
|
|
381
|
+
const root = options.document.getRoot();
|
|
382
|
+
const previousProjectType = root.getProjectType();
|
|
383
|
+
const previousLogger = options.document.getLogger();
|
|
384
|
+
options.document.setLogger(createDiagnosticLogger(previousLogger, diagnostics));
|
|
385
|
+
try {
|
|
386
|
+
if (options.projectType !== "layabox") throw new Error(`publishBrowser: unsupported project type "${String(options.projectType)}".`);
|
|
387
|
+
root.setProjectType(_openfairygui_core.ProjectType.LayaBox);
|
|
388
|
+
const resolved = require_publish.resolvePublishOptions(options.document, {
|
|
389
|
+
compressed: options.compressed,
|
|
390
|
+
packages: options.packages,
|
|
391
|
+
atlas: options.atlas
|
|
392
|
+
});
|
|
393
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(resolved.fileExtension)) {
|
|
394
|
+
diagnostics.push(unsupportedSetting("fileExtension", "settings.publish.fileExtension", `publishBrowser: unsupported fileExtension "${resolved.fileExtension}".`));
|
|
395
|
+
return toResult(false, files, diagnostics);
|
|
396
|
+
}
|
|
397
|
+
const selectedPackageNames = options.packages?.length ? new Set(options.packages) : null;
|
|
398
|
+
const selectedPackages = root.listPackages().filter((pkg) => !selectedPackageNames || selectedPackageNames.has(pkg.getName()));
|
|
399
|
+
if (require_publish.resolveCodeGenerationSettings(options.document).allowGenCode) {
|
|
400
|
+
const packageIndex = selectedPackages.findIndex((pkg) => pkg.getGenCode());
|
|
401
|
+
if (packageIndex >= 0) {
|
|
402
|
+
const pkg = selectedPackages[packageIndex];
|
|
403
|
+
diagnostics.push(unsupportedSetting("codeGeneration", `packages[${root.listPackages().indexOf(pkg)}].publish.genCode`, `publishBrowser: code generation requested by package "${pkg.getName()}" is not supported.`));
|
|
404
|
+
return toResult(false, files, diagnostics);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
assertBrowserImageSupport();
|
|
408
|
+
const outputFileSystem = createTrackingFileSystem(options.outputFileSystem, files);
|
|
409
|
+
const sourceAssetsPath = options.sourceFileSystem.join(options.document.getProjectDir(), "assets");
|
|
410
|
+
await options.document.transform(require_publish.publish({
|
|
411
|
+
output: options.output,
|
|
412
|
+
compressed: resolved.compressed,
|
|
413
|
+
fileExtension: resolved.fileExtension,
|
|
414
|
+
packages: options.packages,
|
|
415
|
+
branch: options.branch,
|
|
416
|
+
basePath: sourceAssetsPath,
|
|
417
|
+
encoder: createBrowserImageEncoder(options.sourceFileSystem, outputFileSystem),
|
|
418
|
+
atlas: {
|
|
419
|
+
...options.atlas,
|
|
420
|
+
readFileRaw: (path) => options.sourceFileSystem.readFileRaw(path)
|
|
421
|
+
},
|
|
422
|
+
fs: outputFileSystem,
|
|
423
|
+
plugins: [],
|
|
424
|
+
codeGeneration: false
|
|
425
|
+
}));
|
|
426
|
+
return toResult(true, files, diagnostics);
|
|
427
|
+
} catch (error) {
|
|
428
|
+
diagnostics.push({
|
|
429
|
+
level: "error",
|
|
430
|
+
code: "publish_failed",
|
|
431
|
+
message: error instanceof Error ? error.message : String(error)
|
|
432
|
+
});
|
|
433
|
+
return toResult(false, files, diagnostics);
|
|
434
|
+
} finally {
|
|
435
|
+
root.setProjectType(previousProjectType);
|
|
436
|
+
options.document.setLogger(previousLogger);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
exports.publishBrowser = publishBrowser;
|
package/dist/web.d.cts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { d as PublishSourceFileSystem, t as AtlasOptions, u as PublishOutputFileSystem } from "./atlas-CHsu2Y8i.cjs";
|
|
2
|
+
import { Document } from "@openfairygui/core";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/web/publish.d.ts
|
|
5
|
+
type BrowserPublishProjectType = 'layabox';
|
|
6
|
+
type BrowserPublishAtlasOptions = Pick<AtlasOptions, 'maxSize' | 'fast' | 'allowRotation' | 'padding' | 'powerOfTwo' | 'square' | 'multiPage' | 'trimImage' | 'extractAlpha'>;
|
|
7
|
+
type BrowserPublishSourceFileSystem = PublishSourceFileSystem;
|
|
8
|
+
type BrowserPublishOutputFileSystem = PublishOutputFileSystem;
|
|
9
|
+
interface BrowserPublishOptions {
|
|
10
|
+
document: Document;
|
|
11
|
+
sourceFileSystem: BrowserPublishSourceFileSystem;
|
|
12
|
+
outputFileSystem: BrowserPublishOutputFileSystem;
|
|
13
|
+
projectType: BrowserPublishProjectType;
|
|
14
|
+
output: string;
|
|
15
|
+
compressed?: boolean;
|
|
16
|
+
packages?: string[];
|
|
17
|
+
branch?: string;
|
|
18
|
+
atlas?: BrowserPublishAtlasOptions;
|
|
19
|
+
}
|
|
20
|
+
interface BrowserPublishDiagnostic {
|
|
21
|
+
level: 'debug' | 'info' | 'warning' | 'error';
|
|
22
|
+
message: string;
|
|
23
|
+
code?: 'unsupported_publish_setting' | 'publish_failed';
|
|
24
|
+
setting?: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
}
|
|
27
|
+
interface BrowserPublishedFile {
|
|
28
|
+
path: string;
|
|
29
|
+
size: number;
|
|
30
|
+
}
|
|
31
|
+
interface BrowserPublishResult {
|
|
32
|
+
success: boolean;
|
|
33
|
+
files: BrowserPublishedFile[];
|
|
34
|
+
diagnostics: BrowserPublishDiagnostic[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Publish a loaded FairyGUI project to browser-provided storage.
|
|
38
|
+
*
|
|
39
|
+
* The adapter uses browser Canvas APIs for atlas composition, writes only through
|
|
40
|
+
* the supplied output filesystem, and intentionally skips Node publish plugins.
|
|
41
|
+
*/
|
|
42
|
+
declare function publishBrowser(options: BrowserPublishOptions): Promise<BrowserPublishResult>;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type BrowserPublishAtlasOptions, type BrowserPublishDiagnostic, type BrowserPublishOptions, type BrowserPublishOutputFileSystem, type BrowserPublishProjectType, type BrowserPublishResult, type BrowserPublishSourceFileSystem, type BrowserPublishedFile, publishBrowser };
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { d as PublishSourceFileSystem, t as AtlasOptions, u as PublishOutputFileSystem } from "./atlas-C6tbl7nn.js";
|
|
2
|
+
import { Document } from "@openfairygui/core";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/web/publish.d.ts
|
|
5
|
+
type BrowserPublishProjectType = 'layabox';
|
|
6
|
+
type BrowserPublishAtlasOptions = Pick<AtlasOptions, 'maxSize' | 'fast' | 'allowRotation' | 'padding' | 'powerOfTwo' | 'square' | 'multiPage' | 'trimImage' | 'extractAlpha'>;
|
|
7
|
+
type BrowserPublishSourceFileSystem = PublishSourceFileSystem;
|
|
8
|
+
type BrowserPublishOutputFileSystem = PublishOutputFileSystem;
|
|
9
|
+
interface BrowserPublishOptions {
|
|
10
|
+
document: Document;
|
|
11
|
+
sourceFileSystem: BrowserPublishSourceFileSystem;
|
|
12
|
+
outputFileSystem: BrowserPublishOutputFileSystem;
|
|
13
|
+
projectType: BrowserPublishProjectType;
|
|
14
|
+
output: string;
|
|
15
|
+
compressed?: boolean;
|
|
16
|
+
packages?: string[];
|
|
17
|
+
branch?: string;
|
|
18
|
+
atlas?: BrowserPublishAtlasOptions;
|
|
19
|
+
}
|
|
20
|
+
interface BrowserPublishDiagnostic {
|
|
21
|
+
level: 'debug' | 'info' | 'warning' | 'error';
|
|
22
|
+
message: string;
|
|
23
|
+
code?: 'unsupported_publish_setting' | 'publish_failed';
|
|
24
|
+
setting?: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
}
|
|
27
|
+
interface BrowserPublishedFile {
|
|
28
|
+
path: string;
|
|
29
|
+
size: number;
|
|
30
|
+
}
|
|
31
|
+
interface BrowserPublishResult {
|
|
32
|
+
success: boolean;
|
|
33
|
+
files: BrowserPublishedFile[];
|
|
34
|
+
diagnostics: BrowserPublishDiagnostic[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Publish a loaded FairyGUI project to browser-provided storage.
|
|
38
|
+
*
|
|
39
|
+
* The adapter uses browser Canvas APIs for atlas composition, writes only through
|
|
40
|
+
* the supplied output filesystem, and intentionally skips Node publish plugins.
|
|
41
|
+
*/
|
|
42
|
+
declare function publishBrowser(options: BrowserPublishOptions): Promise<BrowserPublishResult>;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type BrowserPublishAtlasOptions, type BrowserPublishDiagnostic, type BrowserPublishOptions, type BrowserPublishOutputFileSystem, type BrowserPublishProjectType, type BrowserPublishResult, type BrowserPublishSourceFileSystem, type BrowserPublishedFile, publishBrowser };
|