@openfairygui/functions 0.2.0-alpha.11 → 0.2.0-alpha.13
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 +28 -3
- package/dist/atlas-CDn6TirX.d.ts +193 -0
- package/dist/atlas-CHsu2Y8i.d.cts +193 -0
- package/dist/codegen-C7PPZrB3.d.cts +241 -0
- package/dist/codegen-CEnmtjBP.d.ts +241 -0
- package/dist/index.cjs +41 -3429
- package/dist/index.d.cts +4 -337
- package/dist/index.d.ts +4 -337
- package/dist/index.js +29 -3417
- package/dist/node.cjs +128 -0
- package/dist/node.d.cts +31 -0
- package/dist/node.d.ts +31 -0
- package/dist/node.js +127 -0
- package/dist/publish-Bl-GK9kt.js +3337 -0
- package/dist/publish-CtCXsMdj.cjs +3408 -0
- package/dist/web.cjs +272 -0
- package/dist/web.d.cts +41 -0
- package/dist/web.d.ts +41 -0
- package/dist/web.js +271 -0
- package/package.json +24 -4
- package/src/{plugins/loader.ts → adapters/node/plugins.ts} +8 -11
- package/src/adapters/node/publish.ts +129 -0
- package/src/adapters/web/publish.ts +404 -0
- package/src/atlas.ts +236 -144
- package/src/codegen.ts +3 -2
- package/src/index.ts +19 -3
- package/src/node.ts +4 -0
- package/src/plugins/types.ts +9 -0
- package/src/publish/contracts.ts +80 -0
- package/src/publish.ts +131 -102
- package/src/shared-types.ts +3 -8
- package/src/web.ts +11 -0
package/dist/node.cjs
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_publish = require("./publish-CtCXsMdj.cjs");
|
|
3
|
+
//#region src/adapters/node/plugins.ts
|
|
4
|
+
const importNative$1 = new Function("id", "return import(id)");
|
|
5
|
+
async function loadPlugins(doc, pluginsDir) {
|
|
6
|
+
if (!pluginsDir) return [];
|
|
7
|
+
const fs = await importNative$1("node:fs/promises");
|
|
8
|
+
const path = await importNative$1("node:path");
|
|
9
|
+
let entries;
|
|
10
|
+
try {
|
|
11
|
+
entries = await fs.readdir(pluginsDir, { withFileTypes: true });
|
|
12
|
+
} catch {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const plugins = [];
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
if (!entry.isDirectory()) continue;
|
|
18
|
+
const pluginDir = path.join(pluginsDir, entry.name);
|
|
19
|
+
try {
|
|
20
|
+
const manifest = await readPluginManifest(fs, path, pluginDir);
|
|
21
|
+
if (!manifest) continue;
|
|
22
|
+
const plugin = await loadPlugin(resolvePluginMain(path, pluginDir, manifest));
|
|
23
|
+
plugins.push({
|
|
24
|
+
name: manifest.name,
|
|
25
|
+
plugin
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
doc.getLogger().warn(`publish: Plugin "${entry.name}" was skipped: ${require_publish.formatPluginError(error)}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return plugins;
|
|
32
|
+
}
|
|
33
|
+
async function readPluginManifest(fs, path, pluginDir) {
|
|
34
|
+
const manifestPath = path.join(pluginDir, "package.json");
|
|
35
|
+
const content = await fs.readFile(manifestPath, "utf-8");
|
|
36
|
+
const manifest = JSON.parse(content);
|
|
37
|
+
if (!manifest.name) throw new Error(`Codegen plugin at ${pluginDir} is missing package.json name.`);
|
|
38
|
+
if (!manifest.main) throw new Error(`Codegen plugin "${manifest.name}" is missing package.json main.`);
|
|
39
|
+
return manifest;
|
|
40
|
+
}
|
|
41
|
+
function resolvePluginMain(path, pluginDir, manifest) {
|
|
42
|
+
const mainPath = path.resolve(pluginDir, manifest.main);
|
|
43
|
+
const relative = path.relative(pluginDir, mainPath);
|
|
44
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) throw new Error(`Codegen plugin "${manifest.name}" main must resolve inside its plugin directory.`);
|
|
45
|
+
return mainPath;
|
|
46
|
+
}
|
|
47
|
+
async function loadPlugin(mainPath) {
|
|
48
|
+
const { createJiti } = await importNative$1("jiti");
|
|
49
|
+
const mod = await createJiti(require("url").pathToFileURL(__filename).href).import(mainPath);
|
|
50
|
+
const defaultExport = mod.default;
|
|
51
|
+
return isObject(defaultExport) ? defaultExport : mod;
|
|
52
|
+
}
|
|
53
|
+
function isObject(value) {
|
|
54
|
+
return value !== null && typeof value === "object";
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/adapters/node/publish.ts
|
|
58
|
+
const importNative = new Function("id", "return import(id)");
|
|
59
|
+
async function createNodePublishFileSystem() {
|
|
60
|
+
const [fs, path] = await Promise.all([importNative("node:fs/promises"), importNative("node:path")]);
|
|
61
|
+
return {
|
|
62
|
+
async readFileRaw(filePath) {
|
|
63
|
+
const data = await fs.readFile(filePath);
|
|
64
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
65
|
+
},
|
|
66
|
+
async writeFileRaw(filePath, data) {
|
|
67
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
68
|
+
await fs.writeFile(filePath, data);
|
|
69
|
+
},
|
|
70
|
+
async mkdir(dirPath) {
|
|
71
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
72
|
+
},
|
|
73
|
+
async readdir(dirPath) {
|
|
74
|
+
return fs.readdir(dirPath);
|
|
75
|
+
},
|
|
76
|
+
async deleteFile(filePath) {
|
|
77
|
+
await fs.rm(filePath, { force: true });
|
|
78
|
+
},
|
|
79
|
+
join(...paths) {
|
|
80
|
+
return path.join(...paths);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async function resolveNodeAssetsPath(document, assetsPath) {
|
|
85
|
+
if (assetsPath) return assetsPath;
|
|
86
|
+
const projectDir = document.getProjectDir?.() ?? "";
|
|
87
|
+
if (!projectDir) return void 0;
|
|
88
|
+
return (await importNative("node:path")).join(projectDir, "assets");
|
|
89
|
+
}
|
|
90
|
+
async function loadSharpBackend() {
|
|
91
|
+
try {
|
|
92
|
+
const sharp = await importNative("sharp");
|
|
93
|
+
return sharp.default ?? sharp;
|
|
94
|
+
} catch {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function loadNodePublishPlugins(document, assetsPath) {
|
|
99
|
+
const projectDir = document.getProjectDir?.() || (assetsPath ? require_publish.resolveProjectBasePath(assetsPath) : "");
|
|
100
|
+
if (!projectDir) return [];
|
|
101
|
+
return loadPlugins(document, (await importNative("node:path")).join(projectDir, "plugins"));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Publish a FairyGUI project through the standard Node host adapter.
|
|
105
|
+
*
|
|
106
|
+
* The adapter owns Node filesystem, Sharp, and project plugin discovery.
|
|
107
|
+
* For custom environments, use the lower-level `publish()` core with explicit
|
|
108
|
+
* capabilities instead.
|
|
109
|
+
*/
|
|
110
|
+
async function publishNode(options) {
|
|
111
|
+
const { document, assetsPath: configuredAssetsPath, atlas, encoder: configuredEncoder, plugins: configuredPlugins, ...publishOptions } = options;
|
|
112
|
+
const [fileSystem, assetsPath] = await Promise.all([createNodePublishFileSystem(), resolveNodeAssetsPath(document, configuredAssetsPath)]);
|
|
113
|
+
const [encoder, plugins] = await Promise.all([configuredEncoder === void 0 ? loadSharpBackend() : Promise.resolve(configuredEncoder), configuredPlugins === void 0 ? loadNodePublishPlugins(document, assetsPath) : Promise.resolve(configuredPlugins)]);
|
|
114
|
+
if (!encoder) document.getLogger().warn("publish: Sharp is unavailable; atlas layout will be generated without PNG output.");
|
|
115
|
+
await document.transform(require_publish.publish({
|
|
116
|
+
...publishOptions,
|
|
117
|
+
basePath: assetsPath,
|
|
118
|
+
encoder,
|
|
119
|
+
atlas: {
|
|
120
|
+
...atlas,
|
|
121
|
+
readFileRaw: fileSystem.readFileRaw
|
|
122
|
+
},
|
|
123
|
+
fs: fileSystem,
|
|
124
|
+
plugins
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
exports.publishNode = publishNode;
|
package/dist/node.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { r as AtlasRasterBackend } from "./atlas-CHsu2Y8i.cjs";
|
|
2
|
+
import { O as PublishOptions, m as LoadedPlugin } from "./codegen-C7PPZrB3.cjs";
|
|
3
|
+
import { Document } from "@openfairygui/core";
|
|
4
|
+
|
|
5
|
+
//#region src/adapters/node/publish.d.ts
|
|
6
|
+
interface PublishNodeOptions extends Omit<PublishOptions, 'atlas' | 'basePath' | 'encoder' | 'fs' | 'plugins'> {
|
|
7
|
+
document: Document;
|
|
8
|
+
/**
|
|
9
|
+
* Assets directory. Defaults to `<document project dir>/assets` when available.
|
|
10
|
+
*/
|
|
11
|
+
assetsPath?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Override the standard Sharp raster backend.
|
|
14
|
+
*/
|
|
15
|
+
encoder?: AtlasRasterBackend;
|
|
16
|
+
/**
|
|
17
|
+
* Supply already-loaded hooks. Pass an empty array to skip project plugin discovery.
|
|
18
|
+
*/
|
|
19
|
+
plugins?: LoadedPlugin[];
|
|
20
|
+
atlas?: Omit<NonNullable<PublishOptions['atlas']>, 'readFileRaw'>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Publish a FairyGUI project through the standard Node host adapter.
|
|
24
|
+
*
|
|
25
|
+
* The adapter owns Node filesystem, Sharp, and project plugin discovery.
|
|
26
|
+
* For custom environments, use the lower-level `publish()` core with explicit
|
|
27
|
+
* capabilities instead.
|
|
28
|
+
*/
|
|
29
|
+
declare function publishNode(options: PublishNodeOptions): Promise<void>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { type PublishNodeOptions, publishNode };
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { r as AtlasRasterBackend } from "./atlas-CDn6TirX.js";
|
|
2
|
+
import { O as PublishOptions, m as LoadedPlugin } from "./codegen-CEnmtjBP.js";
|
|
3
|
+
import { Document } from "@openfairygui/core";
|
|
4
|
+
|
|
5
|
+
//#region src/adapters/node/publish.d.ts
|
|
6
|
+
interface PublishNodeOptions extends Omit<PublishOptions, 'atlas' | 'basePath' | 'encoder' | 'fs' | 'plugins'> {
|
|
7
|
+
document: Document;
|
|
8
|
+
/**
|
|
9
|
+
* Assets directory. Defaults to `<document project dir>/assets` when available.
|
|
10
|
+
*/
|
|
11
|
+
assetsPath?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Override the standard Sharp raster backend.
|
|
14
|
+
*/
|
|
15
|
+
encoder?: AtlasRasterBackend;
|
|
16
|
+
/**
|
|
17
|
+
* Supply already-loaded hooks. Pass an empty array to skip project plugin discovery.
|
|
18
|
+
*/
|
|
19
|
+
plugins?: LoadedPlugin[];
|
|
20
|
+
atlas?: Omit<NonNullable<PublishOptions['atlas']>, 'readFileRaw'>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Publish a FairyGUI project through the standard Node host adapter.
|
|
24
|
+
*
|
|
25
|
+
* The adapter owns Node filesystem, Sharp, and project plugin discovery.
|
|
26
|
+
* For custom environments, use the lower-level `publish()` core with explicit
|
|
27
|
+
* capabilities instead.
|
|
28
|
+
*/
|
|
29
|
+
declare function publishNode(options: PublishNodeOptions): Promise<void>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { type PublishNodeOptions, publishNode };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { l as resolveProjectBasePath, t as publish, u as formatPluginError } from "./publish-Bl-GK9kt.js";
|
|
2
|
+
//#region src/adapters/node/plugins.ts
|
|
3
|
+
const importNative$1 = new Function("id", "return import(id)");
|
|
4
|
+
async function loadPlugins(doc, pluginsDir) {
|
|
5
|
+
if (!pluginsDir) return [];
|
|
6
|
+
const fs = await importNative$1("node:fs/promises");
|
|
7
|
+
const path = await importNative$1("node:path");
|
|
8
|
+
let entries;
|
|
9
|
+
try {
|
|
10
|
+
entries = await fs.readdir(pluginsDir, { withFileTypes: true });
|
|
11
|
+
} catch {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const plugins = [];
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
if (!entry.isDirectory()) continue;
|
|
17
|
+
const pluginDir = path.join(pluginsDir, entry.name);
|
|
18
|
+
try {
|
|
19
|
+
const manifest = await readPluginManifest(fs, path, pluginDir);
|
|
20
|
+
if (!manifest) continue;
|
|
21
|
+
const plugin = await loadPlugin(resolvePluginMain(path, pluginDir, manifest));
|
|
22
|
+
plugins.push({
|
|
23
|
+
name: manifest.name,
|
|
24
|
+
plugin
|
|
25
|
+
});
|
|
26
|
+
} catch (error) {
|
|
27
|
+
doc.getLogger().warn(`publish: Plugin "${entry.name}" was skipped: ${formatPluginError(error)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return plugins;
|
|
31
|
+
}
|
|
32
|
+
async function readPluginManifest(fs, path, pluginDir) {
|
|
33
|
+
const manifestPath = path.join(pluginDir, "package.json");
|
|
34
|
+
const content = await fs.readFile(manifestPath, "utf-8");
|
|
35
|
+
const manifest = JSON.parse(content);
|
|
36
|
+
if (!manifest.name) throw new Error(`Codegen plugin at ${pluginDir} is missing package.json name.`);
|
|
37
|
+
if (!manifest.main) throw new Error(`Codegen plugin "${manifest.name}" is missing package.json main.`);
|
|
38
|
+
return manifest;
|
|
39
|
+
}
|
|
40
|
+
function resolvePluginMain(path, pluginDir, manifest) {
|
|
41
|
+
const mainPath = path.resolve(pluginDir, manifest.main);
|
|
42
|
+
const relative = path.relative(pluginDir, mainPath);
|
|
43
|
+
if (relative.startsWith("..") || path.isAbsolute(relative)) throw new Error(`Codegen plugin "${manifest.name}" main must resolve inside its plugin directory.`);
|
|
44
|
+
return mainPath;
|
|
45
|
+
}
|
|
46
|
+
async function loadPlugin(mainPath) {
|
|
47
|
+
const { createJiti } = await importNative$1("jiti");
|
|
48
|
+
const mod = await createJiti(import.meta.url).import(mainPath);
|
|
49
|
+
const defaultExport = mod.default;
|
|
50
|
+
return isObject(defaultExport) ? defaultExport : mod;
|
|
51
|
+
}
|
|
52
|
+
function isObject(value) {
|
|
53
|
+
return value !== null && typeof value === "object";
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/adapters/node/publish.ts
|
|
57
|
+
const importNative = new Function("id", "return import(id)");
|
|
58
|
+
async function createNodePublishFileSystem() {
|
|
59
|
+
const [fs, path] = await Promise.all([importNative("node:fs/promises"), importNative("node:path")]);
|
|
60
|
+
return {
|
|
61
|
+
async readFileRaw(filePath) {
|
|
62
|
+
const data = await fs.readFile(filePath);
|
|
63
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
64
|
+
},
|
|
65
|
+
async writeFileRaw(filePath, data) {
|
|
66
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
67
|
+
await fs.writeFile(filePath, data);
|
|
68
|
+
},
|
|
69
|
+
async mkdir(dirPath) {
|
|
70
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
71
|
+
},
|
|
72
|
+
async readdir(dirPath) {
|
|
73
|
+
return fs.readdir(dirPath);
|
|
74
|
+
},
|
|
75
|
+
async deleteFile(filePath) {
|
|
76
|
+
await fs.rm(filePath, { force: true });
|
|
77
|
+
},
|
|
78
|
+
join(...paths) {
|
|
79
|
+
return path.join(...paths);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async function resolveNodeAssetsPath(document, assetsPath) {
|
|
84
|
+
if (assetsPath) return assetsPath;
|
|
85
|
+
const projectDir = document.getProjectDir?.() ?? "";
|
|
86
|
+
if (!projectDir) return void 0;
|
|
87
|
+
return (await importNative("node:path")).join(projectDir, "assets");
|
|
88
|
+
}
|
|
89
|
+
async function loadSharpBackend() {
|
|
90
|
+
try {
|
|
91
|
+
const sharp = await importNative("sharp");
|
|
92
|
+
return sharp.default ?? sharp;
|
|
93
|
+
} catch {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async function loadNodePublishPlugins(document, assetsPath) {
|
|
98
|
+
const projectDir = document.getProjectDir?.() || (assetsPath ? resolveProjectBasePath(assetsPath) : "");
|
|
99
|
+
if (!projectDir) return [];
|
|
100
|
+
return loadPlugins(document, (await importNative("node:path")).join(projectDir, "plugins"));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Publish a FairyGUI project through the standard Node host adapter.
|
|
104
|
+
*
|
|
105
|
+
* The adapter owns Node filesystem, Sharp, and project plugin discovery.
|
|
106
|
+
* For custom environments, use the lower-level `publish()` core with explicit
|
|
107
|
+
* capabilities instead.
|
|
108
|
+
*/
|
|
109
|
+
async function publishNode(options) {
|
|
110
|
+
const { document, assetsPath: configuredAssetsPath, atlas, encoder: configuredEncoder, plugins: configuredPlugins, ...publishOptions } = options;
|
|
111
|
+
const [fileSystem, assetsPath] = await Promise.all([createNodePublishFileSystem(), resolveNodeAssetsPath(document, configuredAssetsPath)]);
|
|
112
|
+
const [encoder, plugins] = await Promise.all([configuredEncoder === void 0 ? loadSharpBackend() : Promise.resolve(configuredEncoder), configuredPlugins === void 0 ? loadNodePublishPlugins(document, assetsPath) : Promise.resolve(configuredPlugins)]);
|
|
113
|
+
if (!encoder) document.getLogger().warn("publish: Sharp is unavailable; atlas layout will be generated without PNG output.");
|
|
114
|
+
await document.transform(publish({
|
|
115
|
+
...publishOptions,
|
|
116
|
+
basePath: assetsPath,
|
|
117
|
+
encoder,
|
|
118
|
+
atlas: {
|
|
119
|
+
...atlas,
|
|
120
|
+
readFileRaw: fileSystem.readFileRaw
|
|
121
|
+
},
|
|
122
|
+
fs: fileSystem,
|
|
123
|
+
plugins
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { publishNode };
|