@openfairygui/functions 0.3.0-alpha.4 → 0.3.1
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/dist/{atlas-C6tbl7nn.d.ts → atlas-BtWa1DwO.d.ts} +6 -0
- package/dist/{atlas-CHsu2Y8i.d.cts → atlas-CSqHsG0X.d.cts} +6 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/node.cjs +128 -30
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +128 -30
- package/dist/{publish-CyBj2o7n.js → publish-Cy09yjfn.js} +122 -54
- package/dist/{publish-C7qHwEiP.cjs → publish-DhMv_lEP.cjs} +122 -54
- package/dist/{restore-BeWaJNjR.d.cts → restore-CbscKkNw.d.ts} +9 -4
- package/dist/{restore-DVo1hXpN.js → restore-DB_L_xq4.js} +1 -1
- package/dist/{restore-Dh0-Nvms.d.ts → restore-k3oX26Fs.d.cts} +9 -4
- package/dist/{restore-LXbDQqmT.cjs → restore-n61oZ4nw.cjs} +1 -1
- package/dist/web.cjs +47 -64
- package/dist/web.d.cts +2 -2
- package/dist/web.d.ts +2 -2
- package/dist/web.js +49 -66
- package/package.json +5 -2
- package/src/adapters/node/plugins.ts +29 -13
- package/src/adapters/node/publish.ts +74 -4
- package/src/adapters/node/validate.ts +1 -0
- package/src/adapters/web/publish.ts +2 -0
- package/src/adapters/web/raster.ts +55 -72
- package/src/atlas/packing.ts +22 -13
- package/src/atlas.ts +22 -3
- package/src/codegen.ts +24 -11
- package/src/plugins/types.ts +7 -0
- package/src/publish/contracts.ts +3 -0
- package/src/publish/external-resources.ts +12 -6
- package/src/publish/options.ts +21 -7
- package/src/publish/package-context.ts +35 -11
- package/src/publish/resource-references.ts +21 -6
- package/src/publish.ts +26 -4
- package/src/utils.ts +2 -2
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ProjectType,
|
|
10
10
|
type SoundResource,
|
|
11
11
|
type SpineResource,
|
|
12
|
+
type SwfResource,
|
|
12
13
|
} from '@openfairygui/core';
|
|
13
14
|
import type { AtlasRasterBackend } from './contracts.js';
|
|
14
15
|
import { collectPackageResourceReferences } from './resource-references.js';
|
|
@@ -69,6 +70,12 @@ export function isSoundResource(resource: ReturnType<Package['listResources']>[n
|
|
|
69
70
|
return resource.propertyType === 'SoundResource';
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
export function isSwfResource(
|
|
74
|
+
resource: ReturnType<Package['listResources']>[number],
|
|
75
|
+
): resource is SwfResource {
|
|
76
|
+
return resource.propertyType === 'SwfResource';
|
|
77
|
+
}
|
|
78
|
+
|
|
72
79
|
function isSpineResource(resource: ReturnType<Package['listResources']>[number]): resource is SpineResource {
|
|
73
80
|
return resource.propertyType === 'SpineResource';
|
|
74
81
|
}
|
|
@@ -132,10 +139,15 @@ export function extname(fileName: string): string {
|
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
function resolvePublishedMiscFileName(resource: MiscResource, projectType: number): string {
|
|
135
|
-
const
|
|
136
|
-
if (projectType
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
const fileName = `${getPublishedId(resource)}${extname(resource.getFile())}`;
|
|
143
|
+
if (projectType === UNITY_PROJECT_TYPE && fileName.toLowerCase().endsWith('.atlas')) {
|
|
144
|
+
return `${fileName}.txt`;
|
|
145
|
+
}
|
|
146
|
+
return fileName;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function resolvePublishedSwfFileName(resource: SwfResource): string {
|
|
150
|
+
return `${getPublishedId(resource)}${extname(resource.getFile()) || '.swf'}`;
|
|
139
151
|
}
|
|
140
152
|
|
|
141
153
|
function resolvePublishedSkeletonFileName(resource: SpineResource | DragonBonesResource, projectType: number): string {
|
|
@@ -235,18 +247,19 @@ function collectHighResolutionItemIds(
|
|
|
235
247
|
resources: ReturnType<Package['listResources']>,
|
|
236
248
|
publishedResourceIds: Set<string>,
|
|
237
249
|
includeHighResolution: number,
|
|
250
|
+
excludedResourceIds: Set<string>,
|
|
238
251
|
): Map<string, Array<string | null>> {
|
|
239
252
|
const result = new Map<string, Array<string | null>>();
|
|
240
253
|
if (includeHighResolution <= 0) return result;
|
|
241
254
|
|
|
242
255
|
const highResolutionResourceByKey = new Map<string, ImageResource | MovieClipResource>();
|
|
243
256
|
for (const resource of resources) {
|
|
244
|
-
if (!isHighResolutionResource(resource)) continue;
|
|
257
|
+
if (!isHighResolutionResource(resource) || excludedResourceIds.has(resource.getId())) continue;
|
|
245
258
|
highResolutionResourceByKey.set(buildHighResolutionResourceKey(resource), resource);
|
|
246
259
|
}
|
|
247
260
|
|
|
248
261
|
for (const resource of resources) {
|
|
249
|
-
if (!isHighResolutionResource(resource)) continue;
|
|
262
|
+
if (!isHighResolutionResource(resource) || excludedResourceIds.has(resource.getId())) continue;
|
|
250
263
|
if (!publishedResourceIds.has(resource.getId())) continue;
|
|
251
264
|
if (isHighResolutionVariantName(resource.getName())) continue;
|
|
252
265
|
|
|
@@ -290,6 +303,7 @@ function collectPackagePublishContext(
|
|
|
290
303
|
},
|
|
291
304
|
): PackagePublishContext {
|
|
292
305
|
const resources = pkg.listResources();
|
|
306
|
+
const excludedResourceIds = new Set(pkg.getSourceAtlasSettings().excludedResourceIds);
|
|
293
307
|
const resourceMap = new Map(resources.map((resource) => [resource.getId(), resource]));
|
|
294
308
|
const referencedIds = collectPackageResourceReferences(pkg).localResourceIds;
|
|
295
309
|
const pixelHitTestImageIds = new Set<string>();
|
|
@@ -304,10 +318,15 @@ function collectPackagePublishContext(
|
|
|
304
318
|
while (changed) {
|
|
305
319
|
changed = false;
|
|
306
320
|
for (const resourceId of [...exportedResourceIds]) {
|
|
321
|
+
if (excludedResourceIds.has(resourceId)) {
|
|
322
|
+
exportedResourceIds.delete(resourceId);
|
|
323
|
+
changed = true;
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
307
326
|
const resource = resourcesById.get(resourceId);
|
|
308
327
|
if (!resource || !isSkeletonResource(resource)) continue;
|
|
309
328
|
for (const requiredId of resource.getRequireIds()) {
|
|
310
|
-
if (!requiredId || exportedResourceIds.has(requiredId)) continue;
|
|
329
|
+
if (!requiredId || excludedResourceIds.has(requiredId) || exportedResourceIds.has(requiredId)) continue;
|
|
311
330
|
exportedResourceIds.add(requiredId);
|
|
312
331
|
changed = true;
|
|
313
332
|
}
|
|
@@ -318,7 +337,7 @@ function collectPackagePublishContext(
|
|
|
318
337
|
|
|
319
338
|
for (const atlas of pkg.listAtlases()) {
|
|
320
339
|
for (const sprite of atlas.listSprites()) {
|
|
321
|
-
spriteItemIds.add(sprite.getItemId());
|
|
340
|
+
if (!excludedResourceIds.has(sprite.getItemId())) spriteItemIds.add(sprite.getItemId());
|
|
322
341
|
}
|
|
323
342
|
}
|
|
324
343
|
|
|
@@ -331,8 +350,8 @@ function collectPackagePublishContext(
|
|
|
331
350
|
const hitTest = component.getHitTest?.()?.trim();
|
|
332
351
|
if (hitTest && !hitTest.includes(',')) {
|
|
333
352
|
const targetChild = childMap.get(hitTest);
|
|
334
|
-
|
|
335
|
-
if (sourceId) {
|
|
353
|
+
const sourceId = (targetChild as { getSrc?(): string } | undefined)?.getSrc?.();
|
|
354
|
+
if (sourceId && !excludedResourceIds.has(sourceId)) {
|
|
336
355
|
const sourceResource = resourceMap.get(sourceId);
|
|
337
356
|
if (sourceResource && isImageResource(sourceResource)) {
|
|
338
357
|
pixelHitTestImageIds.add(sourceId);
|
|
@@ -344,7 +363,7 @@ function collectPackagePublishContext(
|
|
|
344
363
|
const publishedResourceIds = new Set<string>(spriteItemIds);
|
|
345
364
|
for (const resource of resources) {
|
|
346
365
|
const resourceId = resource.getId();
|
|
347
|
-
if (!resourceId) continue;
|
|
366
|
+
if (!resourceId || excludedResourceIds.has(resourceId)) continue;
|
|
348
367
|
if (isComponentResource(resource)) {
|
|
349
368
|
if (resource.getExported() || referencedIds.has(resourceId)) {
|
|
350
369
|
publishedResourceIds.add(resourceId);
|
|
@@ -390,6 +409,7 @@ function collectPackagePublishContext(
|
|
|
390
409
|
resources,
|
|
391
410
|
publishedResourceIds,
|
|
392
411
|
options.includeHighResolution,
|
|
412
|
+
excludedResourceIds,
|
|
393
413
|
);
|
|
394
414
|
|
|
395
415
|
if (!options.includeBranches) {
|
|
@@ -576,6 +596,10 @@ export async function annotatePackagePublishArtifacts(
|
|
|
576
596
|
setPublishedFileExtra(resource, resolvePublishedMiscFileName(resource, options.projectType));
|
|
577
597
|
continue;
|
|
578
598
|
}
|
|
599
|
+
if (isSwfResource(resource)) {
|
|
600
|
+
setPublishedFileExtra(resource, resolvePublishedSwfFileName(resource));
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
579
603
|
if (isSkeletonResource(resource)) {
|
|
580
604
|
setPublishedFileExtra(resource, resolvePublishedSkeletonFileName(resource, options.projectType));
|
|
581
605
|
}
|
|
@@ -3,7 +3,9 @@ import type { HasOptionalFont } from '../shared-types.js';
|
|
|
3
3
|
|
|
4
4
|
interface ReferenceItem {
|
|
5
5
|
icon?: string | null;
|
|
6
|
+
selectedIcon?: string | null;
|
|
6
7
|
url?: string | null;
|
|
8
|
+
propertyOverrides?: Array<{ value: string }>;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
interface ReferenceGear {
|
|
@@ -24,6 +26,7 @@ interface ReferenceChild extends HasOptionalFont {
|
|
|
24
26
|
getPackageId?(): string;
|
|
25
27
|
getSrc?(): string;
|
|
26
28
|
getUrl?(): string;
|
|
29
|
+
getClearOnPublish?(): boolean;
|
|
27
30
|
getInstanceSound?(): string;
|
|
28
31
|
getDefaultItem?(): string;
|
|
29
32
|
getIcon?(): string;
|
|
@@ -31,6 +34,7 @@ interface ReferenceChild extends HasOptionalFont {
|
|
|
31
34
|
getDropdown?(): string;
|
|
32
35
|
getSound?(): string;
|
|
33
36
|
getText?(): string;
|
|
37
|
+
getAutoClearText?(): boolean;
|
|
34
38
|
getInstanceIcon?(): string;
|
|
35
39
|
getInstanceSelectedIcon?(): string;
|
|
36
40
|
getVtScrollBarRes?(): string;
|
|
@@ -38,7 +42,10 @@ interface ReferenceChild extends HasOptionalFont {
|
|
|
38
42
|
getHeaderRes?(): string;
|
|
39
43
|
getFooterRes?(): string;
|
|
40
44
|
getInstanceComboItems?(): Array<{ icon: string | null }>;
|
|
45
|
+
getInstanceAutoClearItems?(): boolean;
|
|
41
46
|
getListItems?(): ReferenceItem[];
|
|
47
|
+
getAutoClearItems?(): boolean;
|
|
48
|
+
getPropertyOverrides?(): Array<{ value: string }>;
|
|
42
49
|
listGears?(): ReferenceGear[];
|
|
43
50
|
}
|
|
44
51
|
|
|
@@ -130,7 +137,7 @@ function collectComponentReferences(
|
|
|
130
137
|
ownerPackageId: string,
|
|
131
138
|
component: Component,
|
|
132
139
|
): void {
|
|
133
|
-
const referenceComponent = component as
|
|
140
|
+
const referenceComponent = component as unknown as ReferenceComponent;
|
|
134
141
|
for (const child of referenceComponent.listChildren()) {
|
|
135
142
|
const sourceId = child.getSrc?.();
|
|
136
143
|
if (sourceId) {
|
|
@@ -141,9 +148,9 @@ function collectComponentReferences(
|
|
|
141
148
|
if (sourcePackageId && sourcePackageId !== ownerPackageId) target.packageIds.add(sourcePackageId);
|
|
142
149
|
|
|
143
150
|
addFontReferences(target, ownerPackageId, child.getFont?.());
|
|
144
|
-
addTextReferences(target, ownerPackageId, child.getText?.());
|
|
151
|
+
if (!child.getAutoClearText?.()) addTextReferences(target, ownerPackageId, child.getText?.());
|
|
145
152
|
for (const reference of [
|
|
146
|
-
child.getUrl?.(),
|
|
153
|
+
child.getClearOnPublish?.() ? undefined : child.getUrl?.(),
|
|
147
154
|
child.getDefaultItem?.(),
|
|
148
155
|
child.getIcon?.(),
|
|
149
156
|
child.getSelectedIcon?.(),
|
|
@@ -159,13 +166,20 @@ function collectComponentReferences(
|
|
|
159
166
|
]) {
|
|
160
167
|
addUiReference(target, ownerPackageId, reference);
|
|
161
168
|
}
|
|
162
|
-
for (const item of child.getInstanceComboItems?.() ?? []) {
|
|
169
|
+
for (const item of child.getInstanceAutoClearItems?.() ? [] : (child.getInstanceComboItems?.() ?? [])) {
|
|
163
170
|
addUiReference(target, ownerPackageId, item.icon);
|
|
164
171
|
}
|
|
165
|
-
for (const item of child.getListItems?.() ?? []) {
|
|
172
|
+
for (const item of child.getAutoClearItems?.() ? [] : (child.getListItems?.() ?? [])) {
|
|
166
173
|
addUiReference(target, ownerPackageId, item.icon);
|
|
174
|
+
addUiReference(target, ownerPackageId, item.selectedIcon);
|
|
167
175
|
addUiReference(target, ownerPackageId, item.url);
|
|
176
|
+
addUnknownReferences(target, ownerPackageId, item.propertyOverrides?.map((property) => property.value));
|
|
168
177
|
}
|
|
178
|
+
addUnknownReferences(
|
|
179
|
+
target,
|
|
180
|
+
ownerPackageId,
|
|
181
|
+
child.getPropertyOverrides?.().map((property) => property.value),
|
|
182
|
+
);
|
|
169
183
|
for (const gear of child.listGears?.() ?? []) {
|
|
170
184
|
addUnknownReferences(target, ownerPackageId, gear.getValues?.());
|
|
171
185
|
addUnknownReferences(target, ownerPackageId, gear.getDefaultValue?.());
|
|
@@ -201,8 +215,9 @@ export function collectPackageResourceReferences(pkg: Package): PackageResourceR
|
|
|
201
215
|
localResourceIds: new Set<string>(),
|
|
202
216
|
packageIds: new Set<string>(),
|
|
203
217
|
};
|
|
218
|
+
const excludedResourceIds = new Set(pkg.getSourceAtlasSettings().excludedResourceIds);
|
|
204
219
|
for (const resource of pkg.listResources()) {
|
|
205
|
-
if (resource.propertyType === 'Component') {
|
|
220
|
+
if (resource.propertyType === 'Component' && !excludedResourceIds.has(resource.getId())) {
|
|
206
221
|
collectComponentReferences(references, pkg.getId(), resource);
|
|
207
222
|
}
|
|
208
223
|
}
|
package/src/publish.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type FileSystem,
|
|
6
6
|
type MovieClipResource,
|
|
7
7
|
type Package,
|
|
8
|
+
ProjectType,
|
|
8
9
|
type Transform,
|
|
9
10
|
} from '@openfairygui/core';
|
|
10
11
|
import { atlas } from './atlas.js';
|
|
@@ -12,7 +13,7 @@ import { prepareMovieClipResource } from './atlas/inputs.js';
|
|
|
12
13
|
import type { PreparedJtaData } from './atlas/jta.js';
|
|
13
14
|
import { publishCodeGeneration, resolveProjectBasePath } from './codegen.js';
|
|
14
15
|
import { dirname, isAbsolutePathLike, trimTrailingSlashes } from './path-utils.js';
|
|
15
|
-
import { formatPluginError, type LoadedPlugin } from './plugins/types.js';
|
|
16
|
+
import { formatPluginError, type LoadedPlugin, shouldAbortPluginFailure } from './plugins/types.js';
|
|
16
17
|
import type { PublishFileSystem } from './publish/contracts.js';
|
|
17
18
|
import {
|
|
18
19
|
annotatePackagePublishArtifacts,
|
|
@@ -74,7 +75,9 @@ async function runPublishPluginHook(
|
|
|
74
75
|
try {
|
|
75
76
|
await fn(doc, options);
|
|
76
77
|
} catch (error) {
|
|
77
|
-
|
|
78
|
+
const message = `publish: Plugin "${plugin.name}" ${hook} failed: ${formatPluginError(error)}`;
|
|
79
|
+
if (shouldAbortPluginFailure(plugin)) throw new Error(message);
|
|
80
|
+
logger.warn(message);
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
}
|
|
@@ -194,6 +197,26 @@ export function publish(options: PublishOptions): Transform {
|
|
|
194
197
|
}
|
|
195
198
|
}
|
|
196
199
|
const publishName = pkg.getPublishName() || pkg.getName();
|
|
200
|
+
const sourceAtlas = pkg.getSourceAtlasSettings();
|
|
201
|
+
const usePackageAtlas = !sourceAtlas.useGlobal;
|
|
202
|
+
const atlas: ResolvedPublishAtlasOptions = {
|
|
203
|
+
...config.atlas,
|
|
204
|
+
maxSize: options.atlas?.maxSize ?? (usePackageAtlas ? sourceAtlas.maxSize : config.atlas.maxSize),
|
|
205
|
+
allowRotation: config.projectType === ProjectType.LayaBox
|
|
206
|
+
? false
|
|
207
|
+
: (options.atlas?.allowRotation ?? (usePackageAtlas ? sourceAtlas.allowRotation : config.atlas.allowRotation)),
|
|
208
|
+
powerOfTwo: options.atlas?.powerOfTwo
|
|
209
|
+
?? (usePackageAtlas ? sourceAtlas.sizeOption === 'pot' : config.atlas.powerOfTwo),
|
|
210
|
+
maxAtlasIndex: options.atlas?.maxAtlasIndex ?? sourceAtlas.maxIndex,
|
|
211
|
+
multipleOfFour: options.atlas?.multipleOfFour
|
|
212
|
+
?? (usePackageAtlas ? sourceAtlas.sizeOption === 'mof' : config.atlas.multipleOfFour),
|
|
213
|
+
square: options.atlas?.square ?? (usePackageAtlas ? sourceAtlas.forceSquare : config.atlas.square),
|
|
214
|
+
multiPage: options.atlas?.multiPage ?? (usePackageAtlas ? sourceAtlas.paging : config.atlas.multiPage),
|
|
215
|
+
extractAlpha: config.projectType === ProjectType.Unity && (
|
|
216
|
+
options.atlas?.extractAlpha
|
|
217
|
+
?? (usePackageAtlas || sourceAtlas.extractAlpha ? sourceAtlas.extractAlpha : config.atlas.extractAlpha)
|
|
218
|
+
),
|
|
219
|
+
};
|
|
197
220
|
|
|
198
221
|
return {
|
|
199
222
|
pkg,
|
|
@@ -206,7 +229,7 @@ export function publish(options: PublishOptions): Transform {
|
|
|
206
229
|
activeBranch: config.activeBranch,
|
|
207
230
|
includeHighResolution: config.includeHighResolution,
|
|
208
231
|
separatedAtlasForBranch: config.separatedAtlasForBranch,
|
|
209
|
-
atlas
|
|
232
|
+
atlas,
|
|
210
233
|
};
|
|
211
234
|
};
|
|
212
235
|
|
|
@@ -255,7 +278,6 @@ export function publish(options: PublishOptions): Transform {
|
|
|
255
278
|
const atlasRuntimeOptions = resolvePublishAtlasRuntimeOptions(plan.fileExtension);
|
|
256
279
|
await atlas({
|
|
257
280
|
...plan.atlas,
|
|
258
|
-
...(options.atlas ?? {}),
|
|
259
281
|
separatedAtlasForBranch: plan.separatedAtlasForBranch,
|
|
260
282
|
encoder: options.encoder,
|
|
261
283
|
basePath: options.basePath,
|
package/src/utils.ts
CHANGED
|
@@ -13,7 +13,7 @@ export function createTransform(name: string, fn: Transform): Transform {
|
|
|
13
13
|
return fn;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function parseTextureSetMode(value: string | null | undefined): TextureSetMode {
|
|
16
|
+
export function parseTextureSetMode(value: string | null | undefined, maxAtlasIndex = 10): TextureSetMode {
|
|
17
17
|
const raw = value?.trim() ?? '';
|
|
18
18
|
if (!raw) {
|
|
19
19
|
return { kind: 'auto', raw: '' };
|
|
@@ -29,7 +29,7 @@ export function parseTextureSetMode(value: string | null | undefined): TextureSe
|
|
|
29
29
|
}
|
|
30
30
|
if (/^\d+$/.test(raw)) {
|
|
31
31
|
const pageIndex = Number(raw);
|
|
32
|
-
if (pageIndex >= 0 && pageIndex <=
|
|
32
|
+
if (pageIndex >= 0 && pageIndex <= maxAtlasIndex) {
|
|
33
33
|
return { kind: 'page', raw, pageIndex };
|
|
34
34
|
}
|
|
35
35
|
}
|