@digitalcanopy/assets 0.1.0 → 1.0.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/package.json +15 -10
- package/src/__tests__/resolvers.test.ts +37 -9
- package/src/index.ts +1 -1
- package/src/resolvers/cdn.ts +52 -0
- package/src/resolvers/index.ts +1 -62
package/package.json
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalcanopy/assets",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "./
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
8
9
|
},
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
|
-
"types": "./
|
|
12
|
-
"
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js"
|
|
13
15
|
},
|
|
14
16
|
"./manifests": {
|
|
15
|
-
"types": "./
|
|
16
|
-
"
|
|
17
|
+
"types": "./dist/manifests/index.d.ts",
|
|
18
|
+
"import": "./dist/manifests/index.mjs",
|
|
19
|
+
"require": "./dist/manifests/index.js"
|
|
17
20
|
},
|
|
18
21
|
"./resolvers": {
|
|
19
|
-
"types": "./
|
|
20
|
-
"
|
|
22
|
+
"types": "./dist/resolvers/cdn.d.ts",
|
|
23
|
+
"import": "./dist/resolvers/cdn.mjs",
|
|
24
|
+
"require": "./dist/resolvers/cdn.js"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"scripts": {
|
|
24
|
-
"build": "
|
|
28
|
+
"build": "tsup src/index.ts src/manifests/index.ts src/resolvers/cdn.ts --dts --format cjs,esm",
|
|
25
29
|
"typecheck": "tsc --noEmit",
|
|
26
30
|
"test": "vitest run",
|
|
27
31
|
"test:boundaries": "vitest run"
|
|
@@ -29,6 +33,7 @@
|
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"@types/pngjs": "^6.0.5",
|
|
31
35
|
"pngjs": "^7.0.0",
|
|
36
|
+
"tsup": "^8.5.1",
|
|
32
37
|
"typescript": "^5.7.3",
|
|
33
38
|
"vitest": "^3.0.5"
|
|
34
39
|
}
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import {
|
|
3
|
+
CDN_BASE_URL,
|
|
3
4
|
KENNEY_CDN_BASE,
|
|
4
5
|
getKenneyAssetUrl,
|
|
5
6
|
getKenneyAudioUrl,
|
|
6
7
|
getKenneyCardUrl,
|
|
7
8
|
getKenneyCharacterUrl,
|
|
8
|
-
} from '../resolvers/
|
|
9
|
+
} from '../resolvers/cdn';
|
|
9
10
|
|
|
10
11
|
describe('@digitalcanopy/assets CDN Resolvers', () => {
|
|
11
12
|
it('resolves base CDN URL correctly', () => {
|
|
13
|
+
expect(CDN_BASE_URL).toBe('https://cdn.sunshade.icu/assets/kenney');
|
|
12
14
|
expect(KENNEY_CDN_BASE).toBe('https://cdn.sunshade.icu/assets/kenney');
|
|
13
15
|
});
|
|
14
16
|
|
|
15
|
-
it('resolves
|
|
16
|
-
const url = getKenneyAssetUrl('modular-characters', 'base_01');
|
|
17
|
+
it('resolves asset url with assetPath including extension', () => {
|
|
18
|
+
const url = getKenneyAssetUrl('modular-characters', 'base_01.png');
|
|
17
19
|
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/modular-characters/base_01.png');
|
|
18
20
|
});
|
|
19
21
|
|
|
20
|
-
it('resolves asset
|
|
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', () => {
|
|
21
28
|
const url = getKenneyAssetUrl('ui-pack', 'button-default', 'svg');
|
|
22
29
|
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/button-default.svg');
|
|
23
30
|
});
|
|
24
31
|
|
|
25
|
-
it('
|
|
32
|
+
it('resolves bare asset key with leading dot in extension cleanly', () => {
|
|
26
33
|
const url = getKenneyAssetUrl('ui-pack', 'button-default', '.svg');
|
|
27
34
|
expect(url).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/button-default.svg');
|
|
28
35
|
});
|
|
29
36
|
|
|
30
|
-
it('does not duplicate extension if
|
|
37
|
+
it('does not duplicate extension if assetPath already has it matching ext', () => {
|
|
31
38
|
const url1 = getKenneyAssetUrl('cards', 'card-spades-10.png');
|
|
32
39
|
expect(url1).toBe('https://cdn.sunshade.icu/assets/kenney/cards/card-spades-10.png');
|
|
33
40
|
|
|
@@ -35,21 +42,42 @@ describe('@digitalcanopy/assets CDN Resolvers', () => {
|
|
|
35
42
|
expect(url2).toBe('https://cdn.sunshade.icu/assets/kenney/cards/card-spades-10.png');
|
|
36
43
|
});
|
|
37
44
|
|
|
38
|
-
it('
|
|
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', () => {
|
|
39
56
|
const ogg = getKenneyAudioUrl('click-a');
|
|
40
57
|
expect(ogg).toBe('https://cdn.sunshade.icu/assets/kenney/ui-pack/sounds/click-a.ogg');
|
|
41
58
|
|
|
42
59
|
const wav = getKenneyAudioUrl('switch-b', 'wav');
|
|
43
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');
|
|
44
64
|
});
|
|
45
65
|
|
|
46
|
-
it('resolves playing card URLs correctly', () => {
|
|
66
|
+
it('resolves playing card URLs correctly and normalizes dotted extension', () => {
|
|
47
67
|
const card = getKenneyCardUrl('card-spades-10');
|
|
48
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');
|
|
49
73
|
});
|
|
50
74
|
|
|
51
|
-
it('resolves character avatar component URLs correctly', () => {
|
|
75
|
+
it('resolves character avatar component URLs correctly and normalizes dotted extension', () => {
|
|
52
76
|
const face = getKenneyCharacterUrl('face', 'face-0');
|
|
53
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');
|
|
54
82
|
});
|
|
55
83
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './resolvers/
|
|
1
|
+
export * from './resolvers/cdn';
|
|
2
2
|
export * from './manifests/index';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const CDN_BASE_URL = 'https://cdn.sunshade.icu/assets/kenney';
|
|
2
|
+
export const KENNEY_CDN_BASE = CDN_BASE_URL;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a Kenney asset pack and asset path to a Cloudflare R2 CDN URL.
|
|
6
|
+
* Handles both full relative paths (e.g. 'base_01.png') and bare keys with optional extensions.
|
|
7
|
+
*
|
|
8
|
+
* @param pack - Asset pack slug (e.g. 'modular-characters', 'cards', 'ui-pack')
|
|
9
|
+
* @param assetPath - Relative file path or bare asset key
|
|
10
|
+
* @param ext - Optional extension override (e.g. 'png', 'svg', '.svg')
|
|
11
|
+
*/
|
|
12
|
+
export function getKenneyAssetUrl(pack: string, assetPath: string, ext?: string): string {
|
|
13
|
+
const cleanPack = pack.replace(/^\/+|\/+$/g, '');
|
|
14
|
+
let cleanPath = assetPath.replace(/^\/+/, '');
|
|
15
|
+
|
|
16
|
+
if (ext) {
|
|
17
|
+
const cleanExt = ext.startsWith('.') ? ext.slice(1) : ext;
|
|
18
|
+
if (cleanPath.toLowerCase().endsWith(`.${cleanExt.toLowerCase()}`)) {
|
|
19
|
+
return `${CDN_BASE_URL}/${cleanPack}/${cleanPath}`;
|
|
20
|
+
}
|
|
21
|
+
return `${CDN_BASE_URL}/${cleanPack}/${cleanPath}.${cleanExt}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const hasExt = /\.[a-zA-Z0-9]+$/.test(cleanPath);
|
|
25
|
+
const finalPath = hasExt ? cleanPath : `${cleanPath}.png`;
|
|
26
|
+
return `${CDN_BASE_URL}/${cleanPack}/${finalPath}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getKenneyAudioUrl(
|
|
30
|
+
soundName: string,
|
|
31
|
+
ext: 'ogg' | 'wav' | 'mp3' | string = 'ogg'
|
|
32
|
+
): string {
|
|
33
|
+
const cleanName = soundName.replace(/^\/+|\/+$/g, '').replace(/\.[a-zA-Z0-9]+$/, '');
|
|
34
|
+
const cleanExt = ext.startsWith('.') ? ext.slice(1) : ext;
|
|
35
|
+
return `${CDN_BASE_URL}/ui-pack/sounds/${cleanName}.${cleanExt}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getKenneyCardUrl(cardKey: string, ext: string = 'png'): string {
|
|
39
|
+
const cleanKey = cardKey.replace(/^\/+|\/+$/g, '').replace(/\.[a-zA-Z0-9]+$/, '');
|
|
40
|
+
const cleanExt = ext.startsWith('.') ? ext.slice(1) : ext;
|
|
41
|
+
return `${CDN_BASE_URL}/cards/${cleanKey}.${cleanExt}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getKenneyCharacterUrl(
|
|
45
|
+
category: 'face' | 'hair' | 'pants' | 'shirts' | 'shoes' | 'skin' | string,
|
|
46
|
+
itemKey: string,
|
|
47
|
+
ext: string = 'png'
|
|
48
|
+
): string {
|
|
49
|
+
const cleanKey = itemKey.replace(/^\/+|\/+$/g, '').replace(/\.[a-zA-Z0-9]+$/, '');
|
|
50
|
+
const cleanExt = ext.startsWith('.') ? ext.slice(1) : ext;
|
|
51
|
+
return `${CDN_BASE_URL}/modular-characters/${category}/${cleanKey}.${cleanExt}`;
|
|
52
|
+
}
|
package/src/resolvers/index.ts
CHANGED
|
@@ -1,62 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Cloudflare R2 Edge CDN Base URL for SunShade Kenney Assets
|
|
3
|
-
*/
|
|
4
|
-
export const KENNEY_CDN_BASE = 'https://cdn.sunshade.icu/assets/kenney';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Resolves a Kenney asset pack, key, and optional extension to a Cloudflare R2 CDN URL.
|
|
8
|
-
* Format: https://cdn.sunshade.icu/assets/kenney/{pack}/{key}.{ext}
|
|
9
|
-
*
|
|
10
|
-
* @param pack - Asset pack slug (e.g., 'modular-characters', 'cards', 'ui-pack')
|
|
11
|
-
* @param key - Asset key or relative subpath (e.g., 'base_01', 'card-spades-10', 'click-a')
|
|
12
|
-
* @param ext - Optional extension ('png', 'svg', 'ogg', etc.). Defaults to 'png' if not supplied and key lacks an extension.
|
|
13
|
-
* @returns Fully qualified Cloudflare R2 public URL
|
|
14
|
-
*/
|
|
15
|
-
export function getKenneyAssetUrl(pack: string, key: string, ext?: string): string {
|
|
16
|
-
const cleanPack = pack.replace(/^\/+|\/+$/g, '');
|
|
17
|
-
const cleanKey = key.replace(/^\/+|\/+$/g, '');
|
|
18
|
-
|
|
19
|
-
if (ext) {
|
|
20
|
-
const cleanExt = ext.startsWith('.') ? ext.slice(1) : ext;
|
|
21
|
-
if (cleanKey.toLowerCase().endsWith(`.${cleanExt.toLowerCase()}`)) {
|
|
22
|
-
return `${KENNEY_CDN_BASE}/${cleanPack}/${cleanKey}`;
|
|
23
|
-
}
|
|
24
|
-
return `${KENNEY_CDN_BASE}/${cleanPack}/${cleanKey}.${cleanExt}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const hasExt = /\.[a-zA-Z0-9]+$/.test(cleanKey);
|
|
28
|
-
const finalKey = hasExt ? cleanKey : `${cleanKey}.png`;
|
|
29
|
-
return `${KENNEY_CDN_BASE}/${cleanPack}/${finalKey}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Resolves UI and game audio sound effects from the Kenney UI Audio pack.
|
|
34
|
-
* Format: https://cdn.sunshade.icu/assets/kenney/ui-pack/sounds/{name}.{ext}
|
|
35
|
-
*/
|
|
36
|
-
export function getKenneyAudioUrl(
|
|
37
|
-
soundName: string,
|
|
38
|
-
ext: 'ogg' | 'wav' | 'mp3' = 'ogg'
|
|
39
|
-
): string {
|
|
40
|
-
const cleanName = soundName.replace(/^\/+|\/+$/g, '').replace(/\.[a-zA-Z0-9]+$/, '');
|
|
41
|
-
return `${KENNEY_CDN_BASE}/ui-pack/sounds/${cleanName}.${ext}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Resolves playing card face and cardback textures.
|
|
46
|
-
* Format: https://cdn.sunshade.icu/assets/kenney/cards/{cardKey}.png
|
|
47
|
-
*/
|
|
48
|
-
export function getKenneyCardUrl(cardKey: string, ext: string = 'png'): string {
|
|
49
|
-
return getKenneyAssetUrl('cards', cardKey, ext);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Resolves modular character cosmetic parts.
|
|
54
|
-
* Format: https://cdn.sunshade.icu/assets/kenney/modular-characters/{category}/{itemKey}.png
|
|
55
|
-
*/
|
|
56
|
-
export function getKenneyCharacterUrl(
|
|
57
|
-
category: 'face' | 'hair' | 'pants' | 'shirts' | 'shoes' | 'skin' | string,
|
|
58
|
-
itemKey: string,
|
|
59
|
-
ext: string = 'png'
|
|
60
|
-
): string {
|
|
61
|
-
return getKenneyAssetUrl('modular-characters', `${category}/${itemKey}`, ext);
|
|
62
|
-
}
|
|
1
|
+
export * from './cdn';
|