@digitalcanopy/assets 1.0.0 → 1.1.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 +55 -0
- package/dist/catalog/index.d.mts +94 -0
- package/dist/catalog/index.d.ts +94 -0
- package/dist/catalog/index.js +540 -0
- package/dist/catalog/index.mjs +30 -0
- package/dist/chunk-BUUV7WRE.mjs +502 -0
- package/dist/chunk-CIMJYYCP.mjs +3612 -0
- package/dist/chunk-FECYZWQ6.mjs +278 -0
- package/dist/chunk-MFWLT2XV.mjs +47 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4483 -0
- package/dist/index.mjs +74 -0
- package/dist/manifests/index.d.mts +79 -0
- package/dist/manifests/index.d.ts +79 -0
- package/dist/manifests/index.js +3647 -0
- package/dist/manifests/index.mjs +24 -0
- package/dist/registry/index.d.mts +98 -0
- package/dist/registry/index.d.ts +98 -0
- package/dist/registry/index.js +321 -0
- package/dist/registry/index.mjs +12 -0
- package/dist/resolvers/cdn.d.mts +16 -0
- package/dist/resolvers/cdn.d.ts +16 -0
- package/dist/resolvers/cdn.js +76 -0
- package/dist/resolvers/cdn.mjs +16 -0
- package/dist/types-Cy3PZIX4.d.mts +52 -0
- package/dist/types-_dmvJ9qx.d.ts +52 -0
- package/package.json +19 -3
- package/scripts/generate-manifests.mjs +0 -409
- package/src/__tests__/manifests.test.ts +0 -129
- package/src/__tests__/resolvers.test.ts +0 -83
- package/src/__tests__/sync-r2.test.ts +0 -82
- package/src/index.ts +0 -2
- package/src/manifests/index.ts +0 -81
- package/src/manifests/isometric-tiles.atlas.json +0 -592
- package/src/manifests/keys.ts +0 -160
- package/src/manifests/modular-characters.atlas.json +0 -856
- package/src/manifests/playing-cards.atlas.json +0 -1408
- package/src/manifests/ui-sprites.atlas.json +0 -568
- package/src/resolvers/cdn.ts +0 -52
- package/src/resolvers/index.ts +0 -1
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -20
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
CDN_BASE_URL,
|
|
4
|
-
KENNEY_CDN_BASE,
|
|
5
|
-
getKenneyAssetUrl,
|
|
6
|
-
getKenneyAudioUrl,
|
|
7
|
-
getKenneyCardUrl,
|
|
8
|
-
getKenneyCharacterUrl,
|
|
9
|
-
} from '../resolvers/cdn';
|
|
10
|
-
|
|
11
|
-
describe('@digitalcanopy/assets CDN Resolvers', () => {
|
|
12
|
-
it('resolves base CDN URL correctly', () => {
|
|
13
|
-
expect(CDN_BASE_URL).toBe('https://cdn.sunshade.icu/assets/kenney');
|
|
14
|
-
expect(KENNEY_CDN_BASE).toBe('https://cdn.sunshade.icu/assets/kenney');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('resolves asset url with assetPath including extension', () => {
|
|
18
|
-
const url = getKenneyAssetUrl('modular-characters', 'base_01.png');
|
|
19
|
-
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/modular-characters/base_01.png');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('resolves bare asset keys by appending .png by default', () => {
|
|
23
|
-
const url = getKenneyAssetUrl('cards', 'spades_10');
|
|
24
|
-
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/cards/spades_10.png');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('resolves bare asset key with explicit extension string', () => {
|
|
28
|
-
const url = getKenneyAssetUrl('ui-pack', 'button-default', 'svg');
|
|
29
|
-
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/button-default.svg');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('resolves bare asset key with leading dot in extension cleanly', () => {
|
|
33
|
-
const url = getKenneyAssetUrl('ui-pack', 'button-default', '.svg');
|
|
34
|
-
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/button-default.svg');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('does not duplicate extension if assetPath already has it matching ext', () => {
|
|
38
|
-
const url1 = getKenneyAssetUrl('cards', 'card-spades-10.png');
|
|
39
|
-
expect(url1).toBe('https://cdn.sunshade.icu/assets/kenney/cards/card-spades-10.png');
|
|
40
|
-
|
|
41
|
-
const url2 = getKenneyAssetUrl('cards', 'card-spades-10.png', 'png');
|
|
42
|
-
expect(url2).toBe('https://cdn.sunshade.icu/assets/kenney/cards/card-spades-10.png');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('handles leading and trailing slashes cleanly', () => {
|
|
46
|
-
const url = getKenneyAssetUrl('/ui-pack/', '/button-default.svg');
|
|
47
|
-
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/button-default.svg');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('resolves nested asset paths correctly', () => {
|
|
51
|
-
const url = getKenneyAssetUrl('cards', 'subfolder/card-spades-10.png');
|
|
52
|
-
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/cards/subfolder/card-spades-10.png');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('resolves audio sound effects correctly and normalizes dotted extension', () => {
|
|
56
|
-
const ogg = getKenneyAudioUrl('click-a');
|
|
57
|
-
expect(ogg).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/sounds/click-a.ogg');
|
|
58
|
-
|
|
59
|
-
const wav = getKenneyAudioUrl('switch-b', 'wav');
|
|
60
|
-
expect(wav).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/sounds/switch-b.wav');
|
|
61
|
-
|
|
62
|
-
const dotted = getKenneyAudioUrl('switch-b', '.wav');
|
|
63
|
-
expect(dotted).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/sounds/switch-b.wav');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('resolves playing card URLs correctly and normalizes dotted extension', () => {
|
|
67
|
-
const card = getKenneyCardUrl('card-spades-10');
|
|
68
|
-
expect(card).toBe('https://cdn.sunshade.icu/assets/kenney/cards/card-spades-10.png');
|
|
69
|
-
|
|
70
|
-
const svgCard = getKenneyCardUrl('card-spades-10', '.svg');
|
|
71
|
-
expect(svgCard).toBe('https://cdn.sunshade.icu/assets/kenney/cards/card-spades-10.svg');
|
|
72
|
-
expect(svgCard).not.toContain('..svg');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('resolves character avatar component URLs correctly and normalizes dotted extension', () => {
|
|
76
|
-
const face = getKenneyCharacterUrl('face', 'face-0');
|
|
77
|
-
expect(face).toBe('https://cdn.sunshade.icu/assets/kenney/modular-characters/face/face-0.png');
|
|
78
|
-
|
|
79
|
-
const dottedFace = getKenneyCharacterUrl('face', 'face-0', '.png');
|
|
80
|
-
expect(dottedFace).toBe('https://cdn.sunshade.icu/assets/kenney/modular-characters/face/face-0.png');
|
|
81
|
-
expect(dottedFace).not.toContain('..png');
|
|
82
|
-
});
|
|
83
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
validateTaxonomyPath,
|
|
7
|
-
runSync,
|
|
8
|
-
verifyCdnEndpoint,
|
|
9
|
-
} from '../../../../scripts/sync-kenney-r2.mjs';
|
|
10
|
-
|
|
11
|
-
describe('Cloudflare R2 Taxonomy Validation', () => {
|
|
12
|
-
let tempFixtureDir: string;
|
|
13
|
-
|
|
14
|
-
beforeAll(() => {
|
|
15
|
-
tempFixtureDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kenney-test-fixtures-'));
|
|
16
|
-
const cardsPack = path.join(tempFixtureDir, 'kenney_cards');
|
|
17
|
-
const charPack = path.join(tempFixtureDir, 'kenney_modular-characters');
|
|
18
|
-
|
|
19
|
-
fs.mkdirSync(cardsPack, { recursive: true });
|
|
20
|
-
fs.mkdirSync(charPack, { recursive: true });
|
|
21
|
-
|
|
22
|
-
fs.writeFileSync(path.join(cardsPack, 'spades_10.png'), 'fake-png-data');
|
|
23
|
-
fs.writeFileSync(path.join(charPack, 'base_01.png'), 'fake-png-data');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterAll(() => {
|
|
27
|
-
if (tempFixtureDir && fs.existsSync(tempFixtureDir)) {
|
|
28
|
-
fs.rmSync(tempFixtureDir, { recursive: true, force: true });
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('accepts valid modular character paths', () => {
|
|
33
|
-
const res = validateTaxonomyPath('assets/kenney/modular-characters/base_01.png');
|
|
34
|
-
expect(res.valid).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('accepts valid playing card paths', () => {
|
|
38
|
-
const res = validateTaxonomyPath('assets/kenney/cards/spades_10.png');
|
|
39
|
-
expect(res.valid).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('accepts valid UI audio paths', () => {
|
|
43
|
-
const res = validateTaxonomyPath('assets/kenney/ui-pack/sounds/click-a.ogg');
|
|
44
|
-
expect(res.valid).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('rejects keys without assets/kenney/ prefix', () => {
|
|
48
|
-
const res = validateTaxonomyPath('other/path/image.png');
|
|
49
|
-
expect(res.valid).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('handles dry-run mode without invoking remote uploader', async () => {
|
|
53
|
-
const mockUploader = vi.fn();
|
|
54
|
-
const res = await runSync({ dryRun: true, sourceDir: tempFixtureDir, uploader: mockUploader });
|
|
55
|
-
expect(mockUploader).not.toHaveBeenCalled();
|
|
56
|
-
expect(res.success).toBe(true);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('invokes uploader for each validated file in active mode', async () => {
|
|
60
|
-
const uploadedKeys: string[] = [];
|
|
61
|
-
const mockUploader = vi.fn((bucket, key) => {
|
|
62
|
-
uploadedKeys.push(key);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const res = await runSync({ dryRun: false, sourceDir: tempFixtureDir, uploader: mockUploader });
|
|
66
|
-
expect(res.success).toBe(true);
|
|
67
|
-
expect(mockUploader).toHaveBeenCalled();
|
|
68
|
-
expect(uploadedKeys.length).toBe(2);
|
|
69
|
-
expect(uploadedKeys).toContain('assets/kenney/cards/spades_10.png');
|
|
70
|
-
expect(uploadedKeys).toContain('assets/kenney/modular-characters/base_01.png');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('propagates errors and aborts when uploader fails', async () => {
|
|
74
|
-
const failingUploader = vi.fn(() => {
|
|
75
|
-
throw new Error('R2 write permission denied');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await expect(
|
|
79
|
-
runSync({ dryRun: false, sourceDir: tempFixtureDir, uploader: failingUploader })
|
|
80
|
-
).rejects.toThrow('R2 write permission denied');
|
|
81
|
-
});
|
|
82
|
-
});
|
package/src/index.ts
DELETED
package/src/manifests/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import playingCardsAtlasJson from './playing-cards.atlas.json';
|
|
2
|
-
import isometricTilesAtlasJson from './isometric-tiles.atlas.json';
|
|
3
|
-
import modularCharactersAtlasJson from './modular-characters.atlas.json';
|
|
4
|
-
import uiSpritesAtlasJson from './ui-sprites.atlas.json';
|
|
5
|
-
|
|
6
|
-
export * from './keys';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Atlas and Sprite Sheet Coordinate Specifications
|
|
10
|
-
* Compatible with Flame (Flutter) and HTML5 Canvas / Pixi / WebGL
|
|
11
|
-
*/
|
|
12
|
-
export interface SpriteBounds {
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
w: number;
|
|
16
|
-
h: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface AnchorPoint {
|
|
20
|
-
ax: number;
|
|
21
|
-
ay: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface AtlasFrame {
|
|
25
|
-
frame: SpriteBounds;
|
|
26
|
-
rotated?: boolean;
|
|
27
|
-
trimmed?: boolean;
|
|
28
|
-
spriteSourceSize?: SpriteBounds;
|
|
29
|
-
sourceSize?: { w: number; h: number };
|
|
30
|
-
anchor?: AnchorPoint;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface AtlasManifest {
|
|
34
|
-
meta: {
|
|
35
|
-
app: string;
|
|
36
|
-
version: string;
|
|
37
|
-
image: string;
|
|
38
|
-
format: string;
|
|
39
|
-
size: { w: number; h: number };
|
|
40
|
-
scale: string;
|
|
41
|
-
pack: string;
|
|
42
|
-
};
|
|
43
|
-
frames: Record<string, AtlasFrame>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface AssetManifestMetadata {
|
|
47
|
-
pack_id: string;
|
|
48
|
-
name: string;
|
|
49
|
-
category: string;
|
|
50
|
-
license: string;
|
|
51
|
-
total_assets: number;
|
|
52
|
-
cdn_base: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export const playingCardsAtlas = playingCardsAtlasJson as AtlasManifest;
|
|
56
|
-
export const isometricTilesAtlas = isometricTilesAtlasJson as AtlasManifest;
|
|
57
|
-
export const modularCharactersAtlas = modularCharactersAtlasJson as AtlasManifest;
|
|
58
|
-
export const uiSpritesAtlas = uiSpritesAtlasJson as AtlasManifest;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Retrieves frame coordinate data from an atlas manifest.
|
|
62
|
-
*/
|
|
63
|
-
export function getFrameCoordinates(
|
|
64
|
-
manifest: AtlasManifest,
|
|
65
|
-
frameKey: string
|
|
66
|
-
): AtlasFrame | undefined {
|
|
67
|
-
return manifest.frames[frameKey];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Formats coordinates for Flame (Flutter) SpriteComponent.fromFrame data mapping.
|
|
72
|
-
*/
|
|
73
|
-
export function toFlameSpriteData(manifest: AtlasManifest, frameKey: string) {
|
|
74
|
-
const frameData = manifest.frames[frameKey];
|
|
75
|
-
if (!frameData) return null;
|
|
76
|
-
return {
|
|
77
|
-
srcPosition: [frameData.frame.x, frameData.frame.y] as [number, number],
|
|
78
|
-
srcSize: [frameData.frame.w, frameData.frame.h] as [number, number],
|
|
79
|
-
anchor: [frameData.anchor?.ax ?? 0.5, frameData.anchor?.ay ?? 0.5] as [number, number],
|
|
80
|
-
};
|
|
81
|
-
}
|