-
Notifications
You must be signed in to change notification settings - Fork 24.8k
/
imgix_loader.ts
37 lines (34 loc) 路 1.34 KB
/
imgix_loader.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {createImageLoader, ImageLoaderConfig} from './image_loader';
/**
* Function that generates a built-in ImageLoader for Imgix and turns it
* into an Angular provider.
*
* @param path path to the desired Imgix origin,
* e.g. https://somepath.imgix.net or https://images.mysite.com
* @param options An object that allows to provide extra configuration:
* - `ensurePreconnect`: boolean flag indicating whether the NgOptimizedImage directive
* should verify that there is a corresponding `<link rel="preconnect">`
* present in the document's `<head>`.
* @returns Set of providers to configure the Imgix loader.
*
* @publicApi
* @developerPreview
*/
export const provideImgixLoader =
createImageLoader(createImgixURL, ngDevMode ? ['https://somepath.imgix.net/'] : undefined);
function createImgixURL(path: string, config: ImageLoaderConfig) {
const url = new URL(`${path}/${config.src}`);
// This setting ensures the smallest allowable format is set.
url.searchParams.set('auto', 'format');
if (config.width) {
url.searchParams.set('w', config.width.toString());
}
return url.href;
}