@flighthq/image 0.5.1-edge.1471.4e82419 → 0.5.1-edge.1685.dc0e23a
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 +2 -2
- package/dist/contract.d.ts +1 -3
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +1 -3
- package/dist/contract.js.map +1 -1
- package/dist/imageResourceReference.d.ts +2 -2
- package/dist/imageResourceReference.d.ts.map +1 -1
- package/dist/imageResourceReference.js +13 -14
- package/dist/imageResourceReference.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/imageResourceReference.test.ts +31 -24
package/README.md
CHANGED
|
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/image`. The `@flight
|
|
|
13
13
|
This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
|
|
14
14
|
|
|
15
15
|
- [Flight project](https://github.com/flighthq/flight)
|
|
16
|
-
- [Source for @flighthq/image@0.5.1-edge.
|
|
17
|
-
- [License](https://github.com/flighthq/flight/blob/
|
|
16
|
+
- [Source for @flighthq/image@0.5.1-edge.1685.dc0e23a](https://github.com/flighthq/flight/tree/dc0e23a17453ec75c20ccbf07058a57b5ef10c4c/packages/image)
|
|
17
|
+
- [License](https://github.com/flighthq/flight/blob/dc0e23a17453ec75c20ccbf07058a57b5ef10c4c/LICENSE.md)
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export * from './imageResource';
|
|
2
2
|
export * from './imageResourceFrom';
|
|
3
|
+
export * from './imageResourceReference';
|
|
3
4
|
export * from './imageSourceDimensions';
|
|
4
5
|
export * from './imageTestHelper';
|
|
5
|
-
export * from './imageResourceReference';
|
|
6
|
-
export { initializeCompressedImageResource } from './imageResource';
|
|
7
|
-
export { initializeEmbeddedImageResourceReference, initializeExternalImageResourceReference, } from './imageResourceReference';
|
|
8
6
|
//# sourceMappingURL=contract.d.ts.map
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export * from './imageResource';
|
|
2
2
|
export * from './imageResourceFrom';
|
|
3
|
+
export * from './imageResourceReference';
|
|
3
4
|
export * from './imageSourceDimensions';
|
|
4
5
|
export * from './imageTestHelper';
|
|
5
|
-
export * from './imageResourceReference';
|
|
6
|
-
export { initializeCompressedImageResource } from './imageResource';
|
|
7
|
-
export { initializeEmbeddedImageResourceReference, initializeExternalImageResourceReference, } from './imageResourceReference';
|
|
8
6
|
//# sourceMappingURL=contract.js.map
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AlphaType, EmbeddedImageResourceReference, ExternalImageResourceReference, ImageResourceFailure, ImageResourceFetch, ImageResourceReference, ImageBitmapCompositionResolver, ImageResourceReferenceResolutionExplanation, TextureSource, EntityConstruction } from '@flighthq/types/contract';
|
|
1
|
+
import type { AlphaType, EmbeddedImageResourceReference, ExternalImageResourceReference, HostImageDecodeCapabilities, ImageDecodeFallback, ImageResourceFailure, ImageResourceFetch, ImageResourceReference, ImageBitmapCompositionResolver, ImageResourceReferenceResolutionExplanation, TextureSource, EntityConstruction } from '@flighthq/types/contract';
|
|
2
2
|
export declare function createEmbeddedImageResourceReference(bytes: Uint8Array, mimeType?: string | null, alphaType?: AlphaType): EmbeddedImageResourceReference;
|
|
3
3
|
export declare function createExternalImageResourceReference(uri: string, basePath?: string | null): ExternalImageResourceReference;
|
|
4
4
|
export declare function createImageResourceFailure(cause: unknown): ImageResourceFailure;
|
|
@@ -7,5 +7,5 @@ export declare function initializeEmbeddedImageResourceReference(out: EntityCons
|
|
|
7
7
|
export declare function initializeExternalImageResourceReference(out: EntityConstruction<ExternalImageResourceReference>, uri: string, basePath?: string | null): void;
|
|
8
8
|
export declare function registerImageBitmapCompositionResolver(resolver: ImageBitmapCompositionResolver | null): void;
|
|
9
9
|
export declare function resetFailedImageResourceReference(ref: ImageResourceReference): boolean;
|
|
10
|
-
export declare function resolveImageResourceReference(ref: ImageResourceReference, fetch: ImageResourceFetch, signal: AbortSignal): Promise<TextureSource | null>;
|
|
10
|
+
export declare function resolveImageResourceReference(imageDecode: Readonly<HostImageDecodeCapabilities>, ref: ImageResourceReference, fetch: ImageResourceFetch, signal: AbortSignal, fallbackDecode?: ImageDecodeFallback): Promise<TextureSource | null>;
|
|
11
11
|
//# sourceMappingURL=imageResourceReference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageResourceReference.d.ts","sourceRoot":"","sources":["../src/imageResourceReference.ts"],"names":[],"mappings":"AAEA,OA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M,GAAG,IAAW,EAC9B,SAAS,GAAE,SAAsB,GAChC,IAAI,CAQN;AAED,wBAAgB,wCAAwC,CACtD,GAAG,EAAE,kBAAkB,CAAC,8BAA8B,CAAC,EACvD,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAM,GAAG,IAAW,GAC7B,IAAI,CAQN;AAMD,wBAAgB,sCAAsC,CAAC,QAAQ,EAAE,8BAA8B,GAAG,IAAI,GAAG,IAAI,CAE5G;AAID,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,sBAAsB,GAAG,OAAO,CAKtF;AAUD,wBAAsB,6BAA6B,CACjD,WAAW,EAAE,QAAQ,CAAC,2BAA2B,CAAC,EAClD,GAAG,EAAE,sBAAsB,EAC3B,KAAK,EAAE,kBAAkB,EACzB,MAAM,EAAE,WAAW,EACnB,cAAc,CAAC,EAAE,mBAAmB,GACnC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CA4B/B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
|
-
import { decodeImage, decodeImagePremultiplied
|
|
2
|
+
import { decodeImage, decodeImagePremultiplied } from '@flighthq/image-codec/contract';
|
|
3
3
|
import { BitmapTextureSourceKind, ImageResourceFailureKind, ImageResourceReferenceKind, ResourceResolutionState, } from '@flighthq/types/contract';
|
|
4
4
|
export function createEmbeddedImageResourceReference(bytes, mimeType = null, alphaType = 'straight') {
|
|
5
5
|
const out = allocateEntity();
|
|
@@ -15,14 +15,18 @@ export function createExternalImageResourceReference(uri, basePath = null) {
|
|
|
15
15
|
// knowledge; this async resource layer turns its RGBA result into the live Bitmap entity renderers
|
|
16
16
|
// dispatch by kind. The reference's alpha request is carried onto the source verbatim, so bytes that
|
|
17
17
|
// are already premultiplied never get multiplied a second time at renderer upload.
|
|
18
|
-
async function decodeEmbeddedImageResourceReference(ref, signal) {
|
|
18
|
+
async function decodeEmbeddedImageResourceReference(imageDecode, ref, signal, fallbackDecode) {
|
|
19
19
|
if (ref.bitmapComposition !== undefined && _resolveImageBitmapComposition !== null) {
|
|
20
|
-
return _resolveImageBitmapComposition(ref, signal);
|
|
20
|
+
return _resolveImageBitmapComposition(imageDecode, ref, signal);
|
|
21
21
|
}
|
|
22
22
|
signal.throwIfAborted();
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const premultiplied = ref.alphaType === 'premultiplied';
|
|
24
|
+
let decoded = await (premultiplied
|
|
25
|
+
? decodeImagePremultiplied(imageDecode, ref.bytes, ref.mimeType ?? undefined)
|
|
26
|
+
: decodeImage(imageDecode, ref.bytes, ref.mimeType ?? undefined));
|
|
27
|
+
if (decoded === null && fallbackDecode !== undefined && ref.mimeType !== null) {
|
|
28
|
+
decoded = await fallbackDecode(ref.bytes, ref.mimeType, premultiplied ? { premultiplyAlpha: true } : undefined);
|
|
29
|
+
}
|
|
26
30
|
signal.throwIfAborted();
|
|
27
31
|
if (decoded === null)
|
|
28
32
|
return null;
|
|
@@ -109,22 +113,17 @@ export function resetFailedImageResourceReference(ref) {
|
|
|
109
113
|
//
|
|
110
114
|
// This is the whole lifecycle for a document that resolves its images once. A caller needing concurrency
|
|
111
115
|
// limits, priority, or retry drives those around this atom rather than inside it.
|
|
112
|
-
export async function resolveImageResourceReference(ref, fetch, signal) {
|
|
116
|
+
export async function resolveImageResourceReference(imageDecode, ref, fetch, signal, fallbackDecode) {
|
|
113
117
|
ref.failure = null;
|
|
114
118
|
ref.state = ResourceResolutionState.Loading;
|
|
115
119
|
try {
|
|
116
|
-
const usesOrdinaryEmbeddedDecode = ref.kind === ImageResourceReferenceKind.Embedded &&
|
|
117
|
-
(ref.bitmapComposition === undefined || _resolveImageBitmapComposition === null);
|
|
118
120
|
const source = ref.kind === ImageResourceReferenceKind.Embedded
|
|
119
|
-
? await decodeEmbeddedImageResourceReference(ref, signal)
|
|
121
|
+
? await decodeEmbeddedImageResourceReference(imageDecode, ref, signal, fallbackDecode)
|
|
120
122
|
: await fetch(ref, signal);
|
|
121
123
|
if (source === null) {
|
|
122
|
-
const decodeFailure = usesOrdinaryEmbeddedDecode
|
|
123
|
-
? explainImageDecodeFailure(ref.bytes, ref.mimeType ?? undefined)
|
|
124
|
-
: null;
|
|
125
124
|
const out = allocateEntity();
|
|
126
125
|
out.kind = ImageResourceFailureKind.Unavailable;
|
|
127
|
-
out.message =
|
|
126
|
+
out.message = 'Image resource unavailable';
|
|
128
127
|
out.name = null;
|
|
129
128
|
ref.failure = finishEntity(out);
|
|
130
129
|
ref.state = ResourceResolutionState.Failed;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imageResourceReference.js","sourceRoot":"","sources":["../src/imageResourceReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,
|
|
1
|
+
{"version":3,"file":"imageResourceReference.js","sourceRoot":"","sources":["../src/imageResourceReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAgBvF,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAElC,MAAM,UAAU,oCAAoC,CAClD,KAAiB,EACjB,WAA0B,IAAI,EAC9B,YAAuB,UAAU;IAEjC,MAAM,GAAG,GAAG,cAAc,EAAkC,CAAC;IAC7D,wCAAwC,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC1E,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,oCAAoC,CAClD,GAAW,EACX,WAA0B,IAAI;IAE9B,MAAM,GAAG,GAAG,cAAc,EAAk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C,KAAK,GAAG,uBAAuB,CAAC,MAAM,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,GAAG,CAAC,KAAK,GAAG,uBAAuB,CAAC,QAAQ,CAAC;QAC7C,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,GAAG,CAAC,KAAK,GAAG,uBAAuB,CAAC,UAAU,CAAC;YAC/C,MAAM,KAAK,CAAC;QACd,CAAC;QACD,GAAG,CAAC,OAAO,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;QAChD,GAAG,CAAC,KAAK,GAAG,uBAAuB,CAAC,MAAM,CAAC;QAC3C,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { cloneImageResource, createCompressedImageResource,
|
|
1
|
+
export { cloneImageResource, createCompressedImageResource, createImageResource, invalidateImageResource, isImageResourceEmpty, } from './imageResource';
|
|
2
|
+
export * from './imageResourceFrom';
|
|
3
|
+
export { createEmbeddedImageResourceReference, createExternalImageResourceReference, createImageResourceFailure, explainImageResourceReferenceResolution, resetFailedImageResourceReference, resolveImageResourceReference, } from './imageResourceReference';
|
|
2
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,OAAO,EACL,oCAAoC,EACpC,oCAAoC,EACpC,0BAA0B,EAC1B,uCAAuC,EACvC,iCAAiC,EACjC,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { cloneImageResource, createCompressedImageResource,
|
|
1
|
+
export { cloneImageResource, createCompressedImageResource, createImageResource, invalidateImageResource, isImageResourceEmpty, } from './imageResource';
|
|
2
|
+
export * from './imageResourceFrom';
|
|
3
|
+
export { createEmbeddedImageResourceReference, createExternalImageResourceReference, createImageResourceFailure, explainImageResourceReferenceResolution, resetFailedImageResourceReference, resolveImageResourceReference, } from './imageResourceReference';
|
|
2
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,OAAO,EACL,oCAAoC,EACpC,oCAAoC,EACpC,0BAA0B,EAC1B,uCAAuC,EACvC,iCAAiC,EACjC,6BAA6B,GAC9B,MAAM,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/image",
|
|
3
|
-
"version": "0.5.1-edge.
|
|
3
|
+
"version": "0.5.1-edge.1685.dc0e23a",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/entity": "0.5.1-edge.
|
|
42
|
-
"@flighthq/image-codec": "0.5.1-edge.
|
|
43
|
-
"@flighthq/types": "0.5.1-edge.
|
|
41
|
+
"@flighthq/entity": "0.5.1-edge.1685.dc0e23a",
|
|
42
|
+
"@flighthq/image-codec": "0.5.1-edge.1685.dc0e23a",
|
|
43
|
+
"@flighthq/types": "0.5.1-edge.1685.dc0e23a"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.3.0"
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
Bitmap,
|
|
4
|
+
HostImageDecodeCapabilities,
|
|
5
|
+
HostImageDecodeFormatCapability,
|
|
6
|
+
ImageResource,
|
|
7
|
+
} from '@flighthq/types/contract';
|
|
4
8
|
import {
|
|
5
9
|
BitmapTextureSourceKind,
|
|
6
10
|
EntityRuntimeKey,
|
|
@@ -20,20 +24,26 @@ import {
|
|
|
20
24
|
resolveImageResourceReference,
|
|
21
25
|
} from './imageResourceReference';
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
const fakeSlot: HostImageDecodeFormatCapability = {
|
|
28
|
+
decode: vi.fn().mockResolvedValue({
|
|
29
|
+
data: new Uint8ClampedArray([0x11, 0x22, 0x33, 0x44]),
|
|
30
|
+
height: 1,
|
|
31
|
+
width: 1,
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const caps: HostImageDecodeCapabilities = { png: fakeSlot };
|
|
24
36
|
|
|
25
37
|
beforeEach(() => {
|
|
26
|
-
|
|
38
|
+
vi.mocked(fakeSlot.decode).mockResolvedValue({
|
|
27
39
|
data: new Uint8ClampedArray([0x11, 0x22, 0x33, 0x44]),
|
|
28
40
|
height: 1,
|
|
29
41
|
width: 1,
|
|
30
42
|
});
|
|
31
|
-
registerImageDecoder('image/png', decoder);
|
|
32
43
|
});
|
|
33
44
|
|
|
34
45
|
afterEach(() => {
|
|
35
46
|
registerImageBitmapCompositionResolver(null);
|
|
36
|
-
clearImageDecoders();
|
|
37
47
|
});
|
|
38
48
|
|
|
39
49
|
const unusedFetch = () => Promise.resolve(null);
|
|
@@ -134,22 +144,20 @@ describe('registerImageBitmapCompositionResolver', () => {
|
|
|
134
144
|
const ref = createEmbeddedImageResourceReference(new Uint8Array([1]), 'image/png');
|
|
135
145
|
ref.bitmapComposition = { kind: 'acme/alpha-plane', payload: new Uint8Array([7]) };
|
|
136
146
|
|
|
137
|
-
expect(await resolveImageResourceReference(ref, unusedFetch, new AbortController().signal)).toBe(bitmap);
|
|
147
|
+
expect(await resolveImageResourceReference(caps, ref, unusedFetch, new AbortController().signal)).toBe(bitmap);
|
|
138
148
|
expect(resolver).toHaveBeenCalledOnce();
|
|
139
|
-
expect(
|
|
149
|
+
expect(fakeSlot.decode).not.toHaveBeenCalled();
|
|
140
150
|
});
|
|
141
151
|
|
|
142
|
-
// Null is how the owner takes the join back out. The slot is the whole of image's knowledge about
|
|
143
|
-
// composition, so an emptied slot must leave the ordinary straight-decode path exactly as it was.
|
|
144
152
|
it('restores the ordinary decode path when the resolver is taken back out', async () => {
|
|
145
153
|
registerImageBitmapCompositionResolver(vi.fn().mockResolvedValue(createTestBitmap('straight')));
|
|
146
154
|
registerImageBitmapCompositionResolver(null);
|
|
147
155
|
const ref = createEmbeddedImageResourceReference(new Uint8Array([1]), 'image/png');
|
|
148
156
|
ref.bitmapComposition = { kind: 'acme/alpha-plane', payload: new Uint8Array([7]) };
|
|
149
157
|
|
|
150
|
-
const source = await resolveImageResourceReference(ref, unusedFetch, new AbortController().signal);
|
|
158
|
+
const source = await resolveImageResourceReference(caps, ref, unusedFetch, new AbortController().signal);
|
|
151
159
|
|
|
152
|
-
expect(
|
|
160
|
+
expect(fakeSlot.decode).toHaveBeenCalledWith(ref.bytes);
|
|
153
161
|
expect(source?.kind).toBe(BitmapTextureSourceKind);
|
|
154
162
|
});
|
|
155
163
|
});
|
|
@@ -180,7 +188,7 @@ describe('resetFailedImageResourceReference', () => {
|
|
|
180
188
|
describe('resolveImageResourceReference', () => {
|
|
181
189
|
it('decodes embedded bytes and marks the reference resolved', async () => {
|
|
182
190
|
const ref = createEmbeddedImageResourceReference(new Uint8Array([0x89, 0x50, 0x4e, 0x47]), 'image/png');
|
|
183
|
-
const source = await resolveImageResourceReference(ref, unusedFetch, new AbortController().signal);
|
|
191
|
+
const source = await resolveImageResourceReference(caps, ref, unusedFetch, new AbortController().signal);
|
|
184
192
|
expect(source).toMatchObject({
|
|
185
193
|
alphaType: 'straight',
|
|
186
194
|
data: new Uint8ClampedArray([0x11, 0x22, 0x33, 0x44]),
|
|
@@ -189,7 +197,7 @@ describe('resolveImageResourceReference', () => {
|
|
|
189
197
|
width: 1,
|
|
190
198
|
});
|
|
191
199
|
expect(EntityRuntimeKey in source!).toBe(true);
|
|
192
|
-
expect(
|
|
200
|
+
expect(fakeSlot.decode).toHaveBeenCalledWith(ref.bytes);
|
|
193
201
|
expect(ref.state).toBe(ResourceResolutionState.Resolved);
|
|
194
202
|
expect(ref.failure).toBeNull();
|
|
195
203
|
});
|
|
@@ -197,20 +205,19 @@ describe('resolveImageResourceReference', () => {
|
|
|
197
205
|
it('requests and declares premultiplied output when the plain reference says its source retains it', async () => {
|
|
198
206
|
const ref = createEmbeddedImageResourceReference(new Uint8Array([1]), 'image/png', 'premultiplied');
|
|
199
207
|
|
|
200
|
-
const source = await resolveImageResourceReference(ref, unusedFetch, new AbortController().signal);
|
|
208
|
+
const source = await resolveImageResourceReference(caps, ref, unusedFetch, new AbortController().signal);
|
|
201
209
|
|
|
202
|
-
expect(
|
|
210
|
+
expect(fakeSlot.decode).toHaveBeenCalledWith(ref.bytes, { premultiplyAlpha: true });
|
|
203
211
|
expect(source?.alphaType).toBe('premultiplied');
|
|
204
212
|
});
|
|
205
213
|
|
|
206
214
|
it('retains the missing-decoder cause when embedded bytes cannot be decoded', async () => {
|
|
207
|
-
clearImageDecoders();
|
|
208
215
|
const ref = createEmbeddedImageResourceReference(new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]));
|
|
209
216
|
|
|
210
|
-
expect(await resolveImageResourceReference(ref, unusedFetch, new AbortController().signal)).toBeNull();
|
|
217
|
+
expect(await resolveImageResourceReference({}, ref, unusedFetch, new AbortController().signal)).toBeNull();
|
|
211
218
|
expect(ref.failure).toMatchObject({
|
|
212
219
|
kind: ImageResourceFailureKind.Unavailable,
|
|
213
|
-
message: '
|
|
220
|
+
message: 'Image resource unavailable',
|
|
214
221
|
name: null,
|
|
215
222
|
});
|
|
216
223
|
});
|
|
@@ -219,14 +226,14 @@ describe('resolveImageResourceReference', () => {
|
|
|
219
226
|
const ref = createExternalImageResourceReference('atlas.png', '/assets');
|
|
220
227
|
const fetched = { width: 2 } as ImageResource;
|
|
221
228
|
const fetch = vi.fn().mockResolvedValue(fetched);
|
|
222
|
-
expect(await resolveImageResourceReference(ref, fetch, new AbortController().signal)).toBe(fetched);
|
|
229
|
+
expect(await resolveImageResourceReference(caps, ref, fetch, new AbortController().signal)).toBe(fetched);
|
|
223
230
|
expect(fetch).toHaveBeenCalledOnce();
|
|
224
231
|
expect(ref.state).toBe(ResourceResolutionState.Resolved);
|
|
225
232
|
});
|
|
226
233
|
|
|
227
234
|
it('records an unavailable failure when the fetch seam returns null', async () => {
|
|
228
235
|
const ref = createExternalImageResourceReference('missing.png');
|
|
229
|
-
expect(await resolveImageResourceReference(ref, unusedFetch, new AbortController().signal)).toBeNull();
|
|
236
|
+
expect(await resolveImageResourceReference(caps, ref, unusedFetch, new AbortController().signal)).toBeNull();
|
|
230
237
|
expect(ref.state).toBe(ResourceResolutionState.Failed);
|
|
231
238
|
expect(ref.failure?.kind).toBe(ImageResourceFailureKind.Unavailable);
|
|
232
239
|
});
|
|
@@ -234,7 +241,7 @@ describe('resolveImageResourceReference', () => {
|
|
|
234
241
|
it('records a thrown cause as a failure rather than rethrowing', async () => {
|
|
235
242
|
const ref = createExternalImageResourceReference('boom.png');
|
|
236
243
|
const fetch = vi.fn().mockRejectedValue(new Error('network down'));
|
|
237
|
-
expect(await resolveImageResourceReference(ref, fetch, new AbortController().signal)).toBeNull();
|
|
244
|
+
expect(await resolveImageResourceReference(caps, ref, fetch, new AbortController().signal)).toBeNull();
|
|
238
245
|
expect(ref.state).toBe(ResourceResolutionState.Failed);
|
|
239
246
|
expect(ref.failure).toMatchObject({ kind: ImageResourceFailureKind.Error, message: 'network down', name: 'Error' });
|
|
240
247
|
});
|
|
@@ -246,7 +253,7 @@ describe('resolveImageResourceReference', () => {
|
|
|
246
253
|
controller.abort();
|
|
247
254
|
return Promise.reject(new Error('aborted'));
|
|
248
255
|
});
|
|
249
|
-
await expect(resolveImageResourceReference(ref, fetch, controller.signal)).rejects.toThrow('aborted');
|
|
256
|
+
await expect(resolveImageResourceReference(caps, ref, fetch, controller.signal)).rejects.toThrow('aborted');
|
|
250
257
|
expect(ref.state).toBe(ResourceResolutionState.Unresolved);
|
|
251
258
|
expect(ref.failure).toBeNull();
|
|
252
259
|
});
|
|
@@ -256,7 +263,7 @@ describe('resolveImageResourceReference', () => {
|
|
|
256
263
|
ref.failure = { [EntityRuntimeKey]: undefined, kind: ImageResourceFailureKind.Error, message: 'old', name: null };
|
|
257
264
|
ref.state = ResourceResolutionState.Failed;
|
|
258
265
|
const fetch = vi.fn().mockResolvedValue({ width: 1 } as ImageResource);
|
|
259
|
-
await resolveImageResourceReference(ref, fetch, new AbortController().signal);
|
|
266
|
+
await resolveImageResourceReference(caps, ref, fetch, new AbortController().signal);
|
|
260
267
|
expect(ref.failure).toBeNull();
|
|
261
268
|
expect(ref.state).toBe(ResourceResolutionState.Resolved);
|
|
262
269
|
});
|