@adonis-agora/media 0.21.0 → 0.22.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/CHANGELOG.md +33 -0
- package/README.md +38 -5
- package/dist/providers/media_provider.d.ts.map +1 -1
- package/dist/providers/media_provider.js +7 -0
- package/dist/providers/media_provider.js.map +1 -1
- package/dist/src/define_config.d.ts +20 -1
- package/dist/src/define_config.d.ts.map +1 -1
- package/dist/src/define_config.js.map +1 -1
- package/dist/src/delivery.d.ts +55 -1
- package/dist/src/delivery.d.ts.map +1 -1
- package/dist/src/delivery.js +19 -1
- package/dist/src/delivery.js.map +1 -1
- package/dist/src/delivery_signing.d.ts +70 -0
- package/dist/src/delivery_signing.d.ts.map +1 -0
- package/dist/src/delivery_signing.js +82 -0
- package/dist/src/delivery_signing.js.map +1 -0
- package/dist/src/errors.d.ts +28 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +47 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/image_processor.d.ts +57 -1
- package/dist/src/image_processor.d.ts.map +1 -1
- package/dist/src/image_processor.js +16 -1
- package/dist/src/image_processor.js.map +1 -1
- package/dist/src/index.d.ts +7 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/media_collection.d.ts +27 -0
- package/dist/src/media_collection.d.ts.map +1 -1
- package/dist/src/media_collection.js +26 -1
- package/dist/src/media_collection.js.map +1 -1
- package/dist/src/media_library.d.ts +114 -2
- package/dist/src/media_library.d.ts.map +1 -1
- package/dist/src/media_library.js +361 -16
- package/dist/src/media_library.js.map +1 -1
- package/dist/src/media_manager.d.ts +8 -1
- package/dist/src/media_manager.d.ts.map +1 -1
- package/dist/src/media_manager.js +5 -0
- package/dist/src/media_manager.js.map +1 -1
- package/dist/src/processors/sharp.d.ts +7 -2
- package/dist/src/processors/sharp.d.ts.map +1 -1
- package/dist/src/processors/sharp.js +105 -6
- package/dist/src/processors/sharp.js.map +1 -1
- package/dist/src/responsive_image.d.ts +88 -0
- package/dist/src/responsive_image.d.ts.map +1 -0
- package/dist/src/responsive_image.js +109 -0
- package/dist/src/responsive_image.js.map +1 -0
- package/dist/src/testing/fake_image_processor.d.ts +3 -2
- package/dist/src/testing/fake_image_processor.d.ts.map +1 -1
- package/dist/src/testing/fake_image_processor.js +2 -2
- package/dist/src/testing/fake_image_processor.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media_manager.d.ts","sourceRoot":"","sources":["../../src/media_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"media_manager.d.ts","sourceRoot":"","sources":["../../src/media_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAC5F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uB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,YAAY,IAAI,OAAO,CAE1B;IAED,8EAA8E;IAC9E,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,6BAEjB;IAED,uFAAuF;IACvF,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAEnF;IAED,gEAAgE;IAChE,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAE7F;IAED,qDAAqD;IACrD,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;IAED,kFAAkF;IAClF,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAE3E;CACF"}
|
|
@@ -46,6 +46,11 @@ export class MediaManager {
|
|
|
46
46
|
...(options.deliverySignedTtlSeconds !== undefined
|
|
47
47
|
? { deliverySignedTtlSeconds: options.deliverySignedTtlSeconds }
|
|
48
48
|
: {}),
|
|
49
|
+
...(options.deliveryImages !== undefined ? { deliveryImages: options.deliveryImages } : {}),
|
|
50
|
+
...(options.deliverySigning !== undefined
|
|
51
|
+
? { deliverySigning: options.deliverySigning }
|
|
52
|
+
: {}),
|
|
53
|
+
...(options.deliveryPath !== undefined ? { deliveryPath: options.deliveryPath } : {}),
|
|
49
54
|
});
|
|
50
55
|
this.attachments = new AttachmentManager({
|
|
51
56
|
storage: this.storage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media_manager.js","sourceRoot":"","sources":["../../src/media_manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"media_manager.js","sourceRoot":"","sources":["../../src/media_manager.ts"],"names":[],"mappings":"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AAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,uFAAuF;IACvF,oBAAoB,CAAC,KAAgC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,gEAAgE;IAChE,oBAAoB,CAAC,KAAgC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,qDAAqD;IACrD,iBAAiB,CAAC,KAA6B;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,kFAAkF;IAClF,WAAW,CAAC,KAAuB;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ConversionPreset, type ConversionResult, type ConvertOptions, type ImageProcessor } from '../image_processor.js';
|
|
2
2
|
/**
|
|
3
3
|
* `ImageProcessor` backed by [sharp](https://sharp.pixelplumbing.com). Auto-orients from EXIF,
|
|
4
4
|
* resizes/crops via `fit`, optionally blurs, converts format, and applies quality. The default output format is `webp`. Import this directly
|
|
5
5
|
* (`@adonis-agora/media/processors/sharp`) or select it lazily with `processors.sharp()` in config.
|
|
6
6
|
*/
|
|
7
7
|
export declare class SharpImageProcessor implements ImageProcessor {
|
|
8
|
-
|
|
8
|
+
stripMetadata(input: Buffer): Promise<Buffer | undefined>;
|
|
9
|
+
dimensions(input: Buffer): Promise<{
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
} | undefined>;
|
|
13
|
+
convert(input: Buffer, preset: ConversionPreset, options?: ConvertOptions): Promise<ConversionResult>;
|
|
9
14
|
}
|
|
10
15
|
//# sourceMappingURL=sharp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharp.d.ts","sourceRoot":"","sources":["../../../src/processors/sharp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sharp.d.ts","sourceRoot":"","sources":["../../../src/processors/sharp.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EAEpB,MAAM,uBAAuB,CAAC;AAS/B;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IAClD,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAiC9D;IAEK,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAOtF;IAEK,OAAO,CACX,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,EACxB,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CA+C3B;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import sharp from 'sharp';
|
|
2
|
+
import { presetCrops, } from '../image_processor.js';
|
|
2
3
|
const CONTENT_TYPE = {
|
|
3
4
|
jpeg: 'image/jpeg',
|
|
4
5
|
png: 'image/png',
|
|
@@ -11,23 +12,121 @@ const CONTENT_TYPE = {
|
|
|
11
12
|
* (`@adonis-agora/media/processors/sharp`) or select it lazily with `processors.sharp()` in config.
|
|
12
13
|
*/
|
|
13
14
|
export class SharpImageProcessor {
|
|
14
|
-
async
|
|
15
|
+
async stripMetadata(input) {
|
|
16
|
+
const metadata = await sharp(input).metadata();
|
|
17
|
+
// sharp reports AVIF as `heif` with AV1 compression; a real HEIC (HEVC) cannot be re-encoded.
|
|
18
|
+
const format = metadata.format === 'heif'
|
|
19
|
+
? metadata.compression === 'av1'
|
|
20
|
+
? 'avif'
|
|
21
|
+
: undefined
|
|
22
|
+
: metadata.format;
|
|
23
|
+
if (format !== 'jpeg' &&
|
|
24
|
+
format !== 'png' &&
|
|
25
|
+
format !== 'webp' &&
|
|
26
|
+
format !== 'avif' &&
|
|
27
|
+
format !== 'tiff') {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const hasMetadata = Boolean(metadata.exif || metadata.xmp || metadata.iptc);
|
|
31
|
+
// An orientation tag is metadata too, and stripping it alone would turn the image sideways:
|
|
32
|
+
// `rotate()` bakes it into the pixels first.
|
|
33
|
+
if (!hasMetadata && (metadata.orientation ?? 1) === 1)
|
|
34
|
+
return undefined;
|
|
35
|
+
const animated = format === 'webp' && (metadata.pages ?? 1) > 1;
|
|
36
|
+
// sharp drops all metadata unless told to keep it; the colour profile is kept so the colours
|
|
37
|
+
// do not shift. Lossy formats are re-encoded at high quality, lossless ones losslessly.
|
|
38
|
+
let pipeline = sharp(input, { animated }).rotate().keepIccProfile();
|
|
39
|
+
if (format === 'jpeg')
|
|
40
|
+
pipeline = pipeline.jpeg({ quality: 92, mozjpeg: true });
|
|
41
|
+
else if (format === 'png')
|
|
42
|
+
pipeline = pipeline.png();
|
|
43
|
+
else if (format === 'webp')
|
|
44
|
+
pipeline = pipeline.webp({ quality: 92 });
|
|
45
|
+
else if (format === 'avif')
|
|
46
|
+
pipeline = pipeline.avif({ quality: 70 });
|
|
47
|
+
else
|
|
48
|
+
pipeline = pipeline.tiff();
|
|
49
|
+
return pipeline.toBuffer();
|
|
50
|
+
}
|
|
51
|
+
async dimensions(input) {
|
|
52
|
+
const metadata = await sharp(input).metadata();
|
|
53
|
+
if (!metadata.width || !metadata.height)
|
|
54
|
+
return undefined;
|
|
55
|
+
const swap = (metadata.orientation ?? 1) >= 5;
|
|
56
|
+
// An animated image reports the frame strip; one frame is `pageHeight` tall.
|
|
57
|
+
const height = metadata.pageHeight ?? metadata.height;
|
|
58
|
+
return swap ? { width: height, height: metadata.width } : { width: metadata.width, height };
|
|
59
|
+
}
|
|
60
|
+
async convert(input, preset, options = {}) {
|
|
61
|
+
const format = preset.format ?? 'webp';
|
|
62
|
+
// An animated GIF/WebP keeps every frame — but only into a format that can hold them (WebP):
|
|
63
|
+
// read animated into JPEG/PNG/AVIF and sharp stacks the frames into one tall image instead.
|
|
64
|
+
const animated = format === 'webp';
|
|
15
65
|
// `rotate()` with no angle applies the EXIF orientation — without it a portrait phone photo
|
|
16
66
|
// comes out sideways, since the output drops the EXIF tag that made it display upright.
|
|
17
|
-
let pipeline = sharp(input).rotate();
|
|
18
|
-
|
|
67
|
+
let pipeline = sharp(input, { animated }).rotate();
|
|
68
|
+
const focal = options.focalPoint && presetCrops(preset)
|
|
69
|
+
? await focalCrop(input, preset, options.focalPoint)
|
|
70
|
+
: undefined;
|
|
71
|
+
if (focal) {
|
|
72
|
+
// Scale to cover the box, then cut the box out around the focal point.
|
|
73
|
+
pipeline = pipeline
|
|
74
|
+
.resize({ width: focal.scaledWidth, height: focal.scaledHeight, fit: 'fill' })
|
|
75
|
+
.extract({
|
|
76
|
+
left: focal.left,
|
|
77
|
+
top: focal.top,
|
|
78
|
+
width: preset.width,
|
|
79
|
+
height: preset.height,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else if (preset.width || preset.height) {
|
|
19
83
|
pipeline = pipeline.resize({
|
|
20
84
|
...(preset.width ? { width: preset.width } : {}),
|
|
21
85
|
...(preset.height ? { height: preset.height } : {}),
|
|
22
86
|
fit: preset.fit ?? 'cover',
|
|
87
|
+
...(preset.withoutEnlargement ? { withoutEnlargement: true } : {}),
|
|
88
|
+
...(preset.position ? { position: preset.position } : {}),
|
|
23
89
|
});
|
|
24
90
|
}
|
|
25
91
|
if (preset.blur)
|
|
26
92
|
pipeline = pipeline.blur(preset.blur);
|
|
27
|
-
const format = preset.format ?? 'webp';
|
|
28
93
|
pipeline = pipeline.toFormat(format, preset.quality ? { quality: preset.quality } : {});
|
|
29
|
-
const data = await pipeline.toBuffer();
|
|
30
|
-
return {
|
|
94
|
+
const { data, info } = await pipeline.toBuffer({ resolveWithObject: true });
|
|
95
|
+
return {
|
|
96
|
+
data,
|
|
97
|
+
format,
|
|
98
|
+
contentType: CONTENT_TYPE[format] ?? 'application/octet-stream',
|
|
99
|
+
width: info.width,
|
|
100
|
+
// An animated output reports the whole frame strip as `height`; one frame is `pageHeight`.
|
|
101
|
+
height: info.pageHeight ?? info.height,
|
|
102
|
+
};
|
|
31
103
|
}
|
|
32
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The crop box for `preset` (both sides, `cover`) that puts `focal` as close to its centre as the
|
|
107
|
+
* image allows: scale the image to just cover the box, then shift the box toward the point,
|
|
108
|
+
* clamped to the edges. `undefined` for an animated image (frames are cropped by sharp's own
|
|
109
|
+
* gravity instead) or one whose size cannot be read.
|
|
110
|
+
*/
|
|
111
|
+
async function focalCrop(input, preset, focal) {
|
|
112
|
+
const metadata = await sharp(input).metadata();
|
|
113
|
+
if ((metadata.pages ?? 1) > 1 || !metadata.width || !metadata.height)
|
|
114
|
+
return undefined;
|
|
115
|
+
// `metadata()` is pre-rotation; orientations 5–8 swap the axes of what is displayed.
|
|
116
|
+
const swap = (metadata.orientation ?? 1) >= 5;
|
|
117
|
+
const width = swap ? metadata.height : metadata.width;
|
|
118
|
+
const height = swap ? metadata.width : metadata.height;
|
|
119
|
+
const boxWidth = preset.width;
|
|
120
|
+
const boxHeight = preset.height;
|
|
121
|
+
const scale = Math.max(boxWidth / width, boxHeight / height);
|
|
122
|
+
const scaledWidth = Math.max(boxWidth, Math.round(width * scale));
|
|
123
|
+
const scaledHeight = Math.max(boxHeight, Math.round(height * scale));
|
|
124
|
+
const clamp = (value, max) => Math.min(Math.max(value, 0), max);
|
|
125
|
+
return {
|
|
126
|
+
scaledWidth,
|
|
127
|
+
scaledHeight,
|
|
128
|
+
left: clamp(Math.round(focal.x * scaledWidth - boxWidth / 2), scaledWidth - boxWidth),
|
|
129
|
+
top: clamp(Math.round(focal.y * scaledHeight - boxHeight / 2), scaledHeight - boxHeight),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
33
132
|
//# sourceMappingURL=sharp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharp.js","sourceRoot":"","sources":["../../../src/processors/sharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"sharp.js","sourceRoot":"","sources":["../../../src/processors/sharp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAKL,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAE/B,MAAM,YAAY,GAA2B;IAC3C,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,YAAY;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAC9B,KAAK,CAAC,aAAa,CAAC,KAAa;QAC/B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC/C,8FAA8F;QAC9F,MAAM,MAAM,GACV,QAAQ,CAAC,MAAM,KAAK,MAAM;YACxB,CAAC,CAAC,QAAQ,CAAC,WAAW,KAAK,KAAK;gBAC9B,CAAC,CAAC,MAAM;gBACR,CAAC,CAAC,SAAS;YACb,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QACtB,IACE,MAAM,KAAK,MAAM;YACjB,MAAM,KAAK,KAAK;YAChB,MAAM,KAAK,MAAM;YACjB,MAAM,KAAK,MAAM;YACjB,MAAM,KAAK,MAAM,EACjB,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5E,4FAA4F;QA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E,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChF,OAAO;QACL,WAAW;QACX,YAAY;QACZ,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,WAAW,GAAG,QAAQ,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAC;QACrF,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,GAAG,SAAS,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;KACzF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ConversionPreset } from './image_processor.js';
|
|
2
|
+
import type { MediaRecord } from './media_record.js';
|
|
3
|
+
/**
|
|
4
|
+
* Everything an `<img>` needs to render a stored image the way `next/image` does — a `srcset` of
|
|
5
|
+
* the collection's sizes, the intrinsic dimensions to reserve layout, and the blur-up preview.
|
|
6
|
+
* Plain JSON: hand it to the page as a prop (Inertia, a JSON API) and render it with
|
|
7
|
+
* `<MediaImage image={...} />` from `@adonis-agora/media-react`, or spread it on an `<img>`.
|
|
8
|
+
*/
|
|
9
|
+
export interface ResponsiveImage {
|
|
10
|
+
/** The widest candidate (or the original when there are none) — the `src` fallback. */
|
|
11
|
+
src: string;
|
|
12
|
+
/** `"<url> 320w, <url> 960w"`. Absent when no candidate has a known width. */
|
|
13
|
+
srcSet?: string;
|
|
14
|
+
/** Intrinsic width of the image as displayed (EXIF orientation applied). */
|
|
15
|
+
width?: number;
|
|
16
|
+
/** Intrinsic height of the image as displayed. */
|
|
17
|
+
height?: number;
|
|
18
|
+
/** Blur-up preview, when the collection declares `transformers.placeholder()`. */
|
|
19
|
+
placeholder?: {
|
|
20
|
+
dataUrl: string;
|
|
21
|
+
color: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The record's focal point (`setFocalPoint()`), for CSS crops: `<MediaImage>` turns it into
|
|
25
|
+
* `object-position`, so `object-fit: cover` keeps the same part the server's crops keep.
|
|
26
|
+
*/
|
|
27
|
+
focalPoint?: {
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface ResponsiveImageOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Presets to offer as `srcset` candidates. Default: every preset of the collection. Presets that
|
|
35
|
+
* would not be the same picture at another resolution are always left out — a `blur` preset, or
|
|
36
|
+
* one whose fixed `width`×`height` crops to a different aspect ratio than the original.
|
|
37
|
+
*/
|
|
38
|
+
conversions?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Generate a candidate preset that has not been generated yet (cached afterwards, like `url()`).
|
|
41
|
+
* Default `false`: missing ones are skipped, so building the props never resizes on the request
|
|
42
|
+
* path — declare the presets you list here `eager: true` so they exist from the attach on.
|
|
43
|
+
*/
|
|
44
|
+
generate?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Sign every URL for this long (seconds or a duration string) instead of using the public URL —
|
|
47
|
+
* for a private bucket. For the app's own delivery route, use {@link url}.
|
|
48
|
+
*/
|
|
49
|
+
expiresIn?: string | number;
|
|
50
|
+
/**
|
|
51
|
+
* Build each URL yourself (`conversion` is `undefined` for the original), e.g. to point at the
|
|
52
|
+
* app's delivery route. Takes precedence over {@link expiresIn}.
|
|
53
|
+
*/
|
|
54
|
+
url?: (conversion: string | undefined) => string | Promise<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Build the `srcSet` from the delivery route's on-demand resize instead of presets: one
|
|
57
|
+
* candidate per width, as `media.library.deliveryUrl(id, { width })` — signed when
|
|
58
|
+
* `delivery.signing` is configured. `true` uses `delivery.images.widths` below the original's
|
|
59
|
+
* width; pass `widths` (any, when signed) and `quality` to choose.
|
|
60
|
+
*/
|
|
61
|
+
onDemand?: boolean | {
|
|
62
|
+
widths?: readonly number[];
|
|
63
|
+
quality?: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Formats every current browser decodes; anything else (HEIC, TIFF) is never a candidate. */
|
|
67
|
+
export declare const BROWSER_IMAGE_TYPES: Set<string>;
|
|
68
|
+
/** A `srcset` candidate before its URL is resolved; `conversion` is `undefined` for the original. */
|
|
69
|
+
export interface ImageCandidate {
|
|
70
|
+
conversion: string | undefined;
|
|
71
|
+
width: number;
|
|
72
|
+
/** Its height, when known — what an art-directed group reports as its intrinsic size. */
|
|
73
|
+
height?: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Pick the `srcset` candidates of a record: the generated presets that are the same picture at
|
|
77
|
+
* another width, plus the original when it is a browser-decodable image of known width. Sorted
|
|
78
|
+
* narrowest first, one per width. Pure — {@link MediaLibrary.image} resolves the URLs.
|
|
79
|
+
*
|
|
80
|
+
* "The same picture" means the same aspect ratio as a reference: the original's, or — when the
|
|
81
|
+
* caller lists `include` explicitly, which is how an art-directed `<source>` (square crops for
|
|
82
|
+
* phones, say) asks for its group — the first listed conversion's. The original joins only if it
|
|
83
|
+
* matches that reference.
|
|
84
|
+
*
|
|
85
|
+
* @internal exported for tests.
|
|
86
|
+
*/
|
|
87
|
+
export declare function imageCandidates(record: MediaRecord, presets: ConversionPreset[], include?: string[]): ImageCandidate[];
|
|
88
|
+
//# sourceMappingURL=responsive_image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsive_image.d.ts","sourceRoot":"","sources":["../../src/responsive_image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,uFAAuF;IACvF,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,MAAM,CAAC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
|
|
1
|
+
import { placeholderOf } from './transformers/placeholder.js';
|
|
2
|
+
/** Formats every current browser decodes; anything else (HEIC, TIFF) is never a candidate. */
|
|
3
|
+
export const BROWSER_IMAGE_TYPES = new Set([
|
|
4
|
+
'image/jpeg',
|
|
5
|
+
'image/png',
|
|
6
|
+
'image/webp',
|
|
7
|
+
'image/avif',
|
|
8
|
+
'image/gif',
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Pick the `srcset` candidates of a record: the generated presets that are the same picture at
|
|
12
|
+
* another width, plus the original when it is a browser-decodable image of known width. Sorted
|
|
13
|
+
* narrowest first, one per width. Pure — {@link MediaLibrary.image} resolves the URLs.
|
|
14
|
+
*
|
|
15
|
+
* "The same picture" means the same aspect ratio as a reference: the original's, or — when the
|
|
16
|
+
* caller lists `include` explicitly, which is how an art-directed `<source>` (square crops for
|
|
17
|
+
* phones, say) asks for its group — the first listed conversion's. The original joins only if it
|
|
18
|
+
* matches that reference.
|
|
19
|
+
*
|
|
20
|
+
* @internal exported for tests.
|
|
21
|
+
*/
|
|
22
|
+
export function imageCandidates(record, presets, include) {
|
|
23
|
+
const placeholder = placeholderOf(record);
|
|
24
|
+
const originalAspect = placeholder ? placeholder.width / placeholder.height : undefined;
|
|
25
|
+
const sized = [];
|
|
26
|
+
for (const preset of presets) {
|
|
27
|
+
if (include && !include.includes(preset.name))
|
|
28
|
+
continue;
|
|
29
|
+
if (preset.blur)
|
|
30
|
+
continue;
|
|
31
|
+
const conversion = record.conversions[preset.name];
|
|
32
|
+
if (!conversion?.path)
|
|
33
|
+
continue;
|
|
34
|
+
const size = conversionSize(preset, conversion.meta);
|
|
35
|
+
if (!size)
|
|
36
|
+
continue;
|
|
37
|
+
const aspect = size.height !== undefined
|
|
38
|
+
? size.width / size.height
|
|
39
|
+
: size.keepsAspect
|
|
40
|
+
? originalAspect
|
|
41
|
+
: undefined;
|
|
42
|
+
sized.push({
|
|
43
|
+
name: preset.name,
|
|
44
|
+
width: size.width,
|
|
45
|
+
height: size.height,
|
|
46
|
+
aspect,
|
|
47
|
+
keepsAspect: size.keepsAspect,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
let reference = originalAspect;
|
|
51
|
+
if (include) {
|
|
52
|
+
const first = include
|
|
53
|
+
.map((name) => sized.find((s) => s.name === name))
|
|
54
|
+
.find((s) => s?.aspect !== undefined);
|
|
55
|
+
if (first)
|
|
56
|
+
reference = first.aspect;
|
|
57
|
+
}
|
|
58
|
+
const candidates = [];
|
|
59
|
+
for (const s of sized) {
|
|
60
|
+
const fits = reference === undefined
|
|
61
|
+
? s.keepsAspect
|
|
62
|
+
: s.aspect !== undefined && sameAspect(s.aspect, reference);
|
|
63
|
+
if (!fits)
|
|
64
|
+
continue;
|
|
65
|
+
const height = s.height ?? (s.aspect ? Math.round(s.width / s.aspect) : undefined);
|
|
66
|
+
candidates.push({ conversion: s.name, width: s.width, ...(height ? { height } : {}) });
|
|
67
|
+
}
|
|
68
|
+
if (placeholder &&
|
|
69
|
+
BROWSER_IMAGE_TYPES.has(record.mimeType) &&
|
|
70
|
+
(reference === undefined || sameAspect(originalAspect, reference))) {
|
|
71
|
+
candidates.push({
|
|
72
|
+
conversion: undefined,
|
|
73
|
+
width: placeholder.width,
|
|
74
|
+
height: placeholder.height,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
candidates.sort((a, b) => a.width - b.width);
|
|
78
|
+
return candidates.filter((c, i) => i === 0 || c.width !== candidates[i - 1].width);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Output size of a generated preset. The processor records it in `meta` (since 0.22); for a
|
|
82
|
+
* conversion generated before that, it is derived from the preset when the preset pins it down:
|
|
83
|
+
* a lone `width` keeps the aspect ratio, and `cover`/`fill`/`contain` output exactly
|
|
84
|
+
* `width`×`height`. `keepsAspect` says whether the preset can change the aspect ratio at all —
|
|
85
|
+
* only one that can (`width` AND `height`, cropped or padded) needs the comparison.
|
|
86
|
+
*/
|
|
87
|
+
function conversionSize(preset, meta) {
|
|
88
|
+
const fit = preset.fit ?? 'cover';
|
|
89
|
+
const keepsAspect = !(preset.width && preset.height) || fit === 'inside' || fit === 'outside';
|
|
90
|
+
if (meta && isDimension(meta.width) && isDimension(meta.height)) {
|
|
91
|
+
return { width: meta.width, height: meta.height, keepsAspect };
|
|
92
|
+
}
|
|
93
|
+
if (!preset.width)
|
|
94
|
+
return undefined;
|
|
95
|
+
if (!preset.height)
|
|
96
|
+
return { width: preset.width, keepsAspect: true };
|
|
97
|
+
if (fit === 'cover' || fit === 'fill' || fit === 'contain') {
|
|
98
|
+
return { width: preset.width, height: preset.height, keepsAspect: false };
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
function isDimension(value) {
|
|
103
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0;
|
|
104
|
+
}
|
|
105
|
+
/** Same picture at another size? Whole-pixel rounding skews tiny outputs, hence the tolerance. */
|
|
106
|
+
function sameAspect(candidate, reference) {
|
|
107
|
+
return Math.abs(candidate - reference) / reference < 0.02;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=responsive_image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsive_image.js","sourceRoot":"","sources":["../../src/responsive_image.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AA0D9D,8FAA8F;AAC9F,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IACzC,YAAY;IACZ,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,WAAW;CACZ,CAAC,CAAC;AAUH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAmB,EACnB,OAA2B,EAC3B,OAAkB;IAElB,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,cAAc,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC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AAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;AAC1E,CAAC;AAED,kGAAkG;AAClG,SAAS,UAAU,CAAC,SAAiB,EAAE,SAAiB;IACtD,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;AAC5D,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConversionPreset, ConversionResult, ImageProcessor } from '../image_processor.js';
|
|
1
|
+
import type { ConversionPreset, ConversionResult, ConvertOptions, ImageProcessor } from '../image_processor.js';
|
|
2
2
|
/**
|
|
3
3
|
* Deterministic {@link ImageProcessor} for tests — never touches sharp. It records every call and
|
|
4
4
|
* returns a tiny synthetic buffer tagged with the preset, so conversion paths and lazy/eager
|
|
@@ -8,7 +8,8 @@ export declare class FakeImageProcessor implements ImageProcessor {
|
|
|
8
8
|
readonly calls: Array<{
|
|
9
9
|
inputSize: number;
|
|
10
10
|
preset: ConversionPreset;
|
|
11
|
+
options?: ConvertOptions;
|
|
11
12
|
}>;
|
|
12
|
-
convert(input: Buffer, preset: ConversionPreset): Promise<ConversionResult>;
|
|
13
|
+
convert(input: Buffer, preset: ConversionPreset, options?: ConvertOptions): Promise<ConversionResult>;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=fake_image_processor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake_image_processor.d.ts","sourceRoot":"","sources":["../../../src/testing/fake_image_processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"fake_image_processor.d.ts","sourceRoot":"","sources":["../../../src/testing/fake_image_processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,MAAM,uBAAuB,CAAC;AAS/B;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,gBAAgB,CAAC;QAAC,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,CAAC,CAC3F;IAEC,OAAO,CACX,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAK3B;CACF"}
|
|
@@ -11,8 +11,8 @@ const CONTENT_TYPE = {
|
|
|
11
11
|
*/
|
|
12
12
|
export class FakeImageProcessor {
|
|
13
13
|
calls = [];
|
|
14
|
-
async convert(input, preset) {
|
|
15
|
-
this.calls.push({ inputSize: input.byteLength, preset });
|
|
14
|
+
async convert(input, preset, options) {
|
|
15
|
+
this.calls.push({ inputSize: input.byteLength, preset, ...(options ? { options } : {}) });
|
|
16
16
|
const format = preset.format ?? 'webp';
|
|
17
17
|
const data = Buffer.from(`fake:${preset.name}:${preset.width ?? ''}x${preset.height ?? ''}`);
|
|
18
18
|
return { data, format, contentType: CONTENT_TYPE[format] ?? 'application/octet-stream' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake_image_processor.js","sourceRoot":"","sources":["../../../src/testing/fake_image_processor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fake_image_processor.js","sourceRoot":"","sources":["../../../src/testing/fake_image_processor.ts"],"names":[],"mappings":"AAOA,MAAM,YAAY,GAA2B;IAC3C,IAAI,EAAE,YAAY;IAClB,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,YAAY;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACpB,KAAK,GACZ,EAAE,CAAC;IAEL,KAAK,CAAC,OAAO,CACX,KAAa,EACb,MAAwB,EACxB,OAAwB;QAExB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC1F,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC;QACvC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC,CAAC;QAC7F,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,0BAA0B,EAAE,CAAC;IAC3F,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, all on top of @adonisjs/drive. Pluggable MediaStore (in-memory + Lucid) and ImageProcessor (sharp). Part of the Agora ecosystem.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
},
|
|
148
148
|
"devDependencies": {
|
|
149
149
|
"@adonis-agora/media-dashboard": "9.0.0",
|
|
150
|
-
"@adonis-agora/media-react": "0.
|
|
150
|
+
"@adonis-agora/media-react": "0.7.0",
|
|
151
151
|
"@adonisjs/assembler": "8.6.0",
|
|
152
152
|
"@adonisjs/core": "7.6.0",
|
|
153
153
|
"@adonisjs/drive": "4.0.0",
|