762 Commits

Author SHA1 Message Date
Ole M 66aece3aad docs(common): update reference url to ICU docs (#47518)
PR Close #47518
2022-09-29 10:53:28 -07:00
Andrew Kushnir c9bdf9bab1 fix(common): rename rawSrc -> ngSrc in NgOptimizedImage directive (#47362) (#47396)
As an ongoing effort to stabilize the NgOptimizedImage API before existing the Developer Preview, this commit renames the `rawSrc` attribute used for the NgOptimizedImage selector matching to `ngSrc`. The `rawSrcset` is also renamed to `ngSrcset` for consistency.

The motivation for this change is to align the attribute name better with other built-in directives, such as `ngFor`, `ngIf`, `ngClass`, `ngStyle`, etc.

Note: this is technically a breaking change, but since the NgOptimizedImage directive is in the Developer Preview mode, we land the change in a patch branch.

PR Close #47362

PR Close #47396
2022-09-12 01:18:55 -07:00
Andrew Kushnir 403b970e78 refactor(common): create an NgFor alias for NgForOf directive (#47309)
This commit adds a re-export of the `NgForOf` class as `NgFor` to improve the DX for cases when the directive is used as standalone. Developers can import `NgFor` class, which better matches the `ngFor` attribute used in a template.

PR Close #47309
2022-09-09 14:04:55 -07:00
Jeremy Elbourn f4825c7b9d refactor(common): remove unnecesary null (#47238)
These null values are unused and unecessary. I suspect it's a remnant from when the codebase was transpiled to Dart.

PR Close #47238
2022-09-06 09:57:38 -07:00
jaybell 1875ce520a fix(common): use DOCUMENT token to query for preconnect links (#47353)
`PreconnectLinkChecker` checks to see if preconnect links have been added to the `<head>` element but uses `document` directly which does not exist when rendering in Angular Universal. This PR switches the `PreconnectLinkChecker` to use the `DOCUMENT` token instead so that the query works when SSR'ing

PR Close #47353
2022-09-06 09:56:27 -07:00
Kara Erickson c0d7ac9ec2 fix(common): improve formatting of image warnings (#47299)
This is a tiny fix to add paragraph breaks in
image distortion warnings to make them a bit
easier to read. With this change, the intrinsic
and rendered image sizes are printed on their
own lines instead of mid-paragraph.

PR Close #47299
2022-09-06 09:55:57 -07:00
Daniel Ostrovsky 626340b2a6 docs(http): Update HttClient "JSON object" to "JavaScript object" (#47325)
updated all references of "JSON object" to "JavaScript object" in HttpClient `common/http/src/client.ts`

Fixes #43242

PR Close #47325
2022-09-03 11:00:44 -07:00
Giovanni Alberto Rivas af975d5bef docs(http): replace http method return description (#47322)
PR Close #47322
2022-09-01 19:14:56 -07:00
Kara Erickson c5db867ddc fix(common): remove duplicate deepForEach (#47189)
This commit removes a duplicate deepForEach
function from url.ts. It is also in the
preconnect_link_checker, where it is actually
used.

PR Close #47189
2022-08-24 12:20:58 -07:00
Pawel Kozlowski f9511bf6e8 fix(common): avoid interacting with a destroyed injector (#47243)
The NgOptimizedImage directive was previously trying to use an
already destroyed injector in the ngOnDestroy callback. This fix
pre-injects necessery tokens so no injector calls are done
in the destroy process.

PR Close #47243
2022-08-24 12:20:24 -07:00
Pawel Kozlowski dc29e21b14 fix(common): consider density descriptors with multiple digits as valid (#47230)
Valid density descriptors used in the NgOptimizedImage can contain multiple
digits (ex. 1.25x, 25x). This change fixes the issue where density descriptors
with multiple digits (ex. 25x) where considered invalid.

Please note that a valid density descriptor might still be rejected by the
directive's validation logic if the supplied value is too big.

PR Close #47230
2022-08-23 16:21:14 -07:00
Kara Erickson 32caa8b669 fix(common): support density descriptors with 2+ decimals (#47197) (#47232)
This commit fixes a bug where `rawSrcset` in the image
directive would allow density descriptors like `1.5x`
but not like `1.25x`. Now descriptors with 2+ digits
after the decimal point should work.

PR Close #47197

PR Close #47232
2022-08-23 16:12:41 -07:00
Pawel Kozlowski 6790d3ceb1 refactor(common): post-review image directive cleanup (#47170) (#47232)
Minor cleanups based on the review comments that were
not addressed after the initial review.

PR Close #47170

PR Close #47232
2022-08-23 16:12:41 -07:00
Kara Erickson fff8056e7f fix(common): fix formatting on oversized image error (#47188) (#47232)
This is a tiny commit to add newlines in the image
directive's "oversized image" error. Currently, the
rendered and intrinsic image sizes are printed
mid-line, which make them a little hard to read.
This commit puts them each on their own line.

PR Close #47188

PR Close #47232
2022-08-23 16:12:41 -07:00
Andrew Kushnir 0ca5eb3088 refactor(common): minor NgOptimizedImage directive updates (#47082)
This commit contains a set of small changes based on the feedback received in #47082.

PR Close #47082
2022-08-16 17:36:54 +00:00
Kara Erickson f81765b333 feat(common): warn if rendered size is much smaller than intrinsic (#47082)
This commit adds a console warning in development mode
if the ultimate rendered size of the image is much
smaller than the dimensions of the requested image.
In this case, the warning recommends adjusting the
size of the source image or using the `rawSrcset`
attribute to implement responsive sizing.

PR Close #47082
2022-08-16 17:36:54 +00:00
Pawel Kozlowski 0f6b30bdc9 refactor(common): address review feedback for NgOptimizedImage (#47082)
Addresses part of the review feedback for the NgOptimizedImage directive.

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir 213f57cb3d refactor(common): various NgOptimizedImage directive updates (#47082)
This commit contains a set of small changes based on the feedback received in https://github.com/angular/angular/pull/47082.

PR Close #47082
2022-08-16 17:36:54 +00:00
Kara Erickson aa254244f4 refactor(common): clean up util.ts and preconnect_link_checker files (#47082)
This commit cleans up some stylistic nits and
moves functions out of util.ts into files that
are more specifically named (url.ts and error.ts).

PR Close #47082
2022-08-16 17:36:54 +00:00
Kara Erickson d71dfe931f fix(common): set bound width and height onto host element (#47082)
This commit fixes a bug in NgOptimizedImage where
if you bound the width or height attribute (e.g.
`[width]=width`), the attribute would only be
reflected as "ng-reflect-x". The actual "width" or
"height" attribute would not be set on the host
element. This is a problem because the exact named
attribute must be set on the element for the
browser to detect it and use it to reserve space
for the image (and thus prevent CLS).

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir 45cc85f3b8 refactor(common): use quotes instead of backticks in missing width/height error message (#47082)
This commit updates the error message thrown at runtime when an `<img>` doesn't contain width and/or height attributes.

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir a1bcfd029b docs: add description and usage notes to the NgOptimizedImage directive (#47082)
This commit adds the docs for the NgOptimizedImage directive.
As a part of this commit, we also remove an export of directive-related symbols previously exposed as public APIs (i.e. APIs can not be used directly).

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir d5f7da2120 feat(common): define public API surface for NgOptimizedImage directive (#47082)
This commit annotates a set of symbols exposed by the NgOptimizedImage directive as a public API.

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir d3c6c37a12 refactor(common): make NgOptimizedImage directive standalone (#47082)
This commit updates the NgOptimizedImage directive to become standalone and removes no longer needed NgOptimizedImageModule class.

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir f995f9fad1 refactor(common): update error messages of NgOptimizedImage directive (#47082)
This commit updates error messages that the NgOptimizedImage directive throws or logs into a console.

PR Close #47082
2022-08-16 17:36:54 +00:00
Katie Hempenius 451b85ca17 feat(common): explain why width/height is required (#47082)
Update error message text to explain why width & height are required
attributes.

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir 244ad766c0 test(common): add parent injector to the createEnvironmentInjector calls in tests (#47082)
This commit updates the `createEnvironmentInjector` calls to pass parent injector, which became required as an argument.

PR Close #47082
2022-08-16 17:36:54 +00:00
Kara Erickson b380fdd59e feat(common): add a density cap for image srcsets (#47082)
With this commit, the NgOptimizedImage directive will throw
a runtime error if it detects that one of the density descriptors
in rawSrcset is higher than 3x. It's generally not recommended
to use density descriptors higher than ~2, as it causes image to
download at very large sizes on mobile screens (thus slowing down
LCP). The density max is set conservatively to 3 in case apps
expect users to zoom in.

In future commits, we may want to throw even at densities >
than 2 and provide a configuration override for the zoom case.

PR Close #47082
2022-08-16 17:36:54 +00:00
Pawel Kozlowski 59ea528f8e refactor(common): simplify URL construction in image loaders (#47082)
This commit simplifies the URL construction logic by capturing
the base path and loader config argumnets in one function.

PR Close #47082
2022-08-16 17:36:54 +00:00
Pawel Kozlowski 91555e9f99 refactor(common): remove code duplication in image loaders (#47082)
This commit moves the URL normalization logic in loaders to
the common loader logic.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 8106084679 refactor(common): throw an error if an absolute URL is passed to Image Loaders (#47082)
This commit updates the logic of Image Loaders to throw an error in case an absolute URL is provided an an input to the loader function. The loaders can construct URLs based on image paths relative to the bas URL configured for a loader.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 2ee4654546 Revert "fix(common): sanitize rawSrc and rawSrcset values in NgOptimizedImage directive" (#47082)
This reverts commit a0fdb8c7e9.

The `src` and `srcset` attributes don't pose security threats in modern browser, so sanitization is not really necessary.

PR Close #47082
2022-08-16 17:36:53 +00:00
Pawel Kozlowski 768a310b6e refactor(common): unify url error reporting in image loaders (#47082)
This refactoring pulls url-related error reporting into one place.
It also makes sure that error messages and the related error
reporting logic are tree-shakable.

PR Close #47082
2022-08-16 17:36:53 +00:00
Pawel Kozlowski feb6ee8f6e refactor(common): remove unnecessary toString conversions (#47082)
A small refactor that removes explicit toString calls when not needed.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 8343133e94 refactor(common): add missing format error call in NgOptimizedImage (#47082)
This commit adds the missing `formatRuntimeError` function to the code that makes sure there is no image distortion.

PR Close #47082
2022-08-16 17:36:53 +00:00
Pawel Kozlowski bd76ad6fa6 refactor(common): properly configure PRECONNECT_CHECK_BLOCKLIST (#47082)
Refactoring tests made me realise that we are misinterpreting the
ensurePreconnect option - in fact it should configure the
PRECONNECT_CHECK_BLOCKLIST provider _only_ if the ensurePreconnect
is set to false.

PR Close #47082
2022-08-16 17:36:53 +00:00
Pawel Kozlowski 3b17d4c011 test(common): remove unneeded describe block (#47082)
This commit removes a nested describe block as it
does't add any value this point. Also moved the
utils tests to the bottom of the file as those are
less important as compared to the other tests.

PR Close #47082
2022-08-16 17:36:53 +00:00
Katie Hempenius 8d3701cb4c feat(common): add warnings re: image distortion (#47082)
Checks whether image is visually distorted. Also adds a check to verify that width and height are set to a non-zero number.

PR Close #47082
2022-08-16 17:36:53 +00:00
Pawel Kozlowski c23f32c38e refactor(common): remove code duplication in loaders (#47082)
This change introduces common infrastructure for image
loaders. This removes code duplication and makes it
easier to write loaders - a loader author just needs
to provide a loader config to the URL mapping function.

PR Close #47082
2022-08-16 17:36:53 +00:00
Katie Hempenius bff870db61 feat(common): add cloudflare loader (#47082)
Closes #46315

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 3836ebbbdf refactor(common): move loader util functions to a common location (#47082)
This commit refactors the code to avoid an extra utils file and instead, all extra helpers are moved to a common location.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir dde5b9bff0 refactor(common): allow Cloudinary and ImageKit loaders to specify the ensurePreconnect option (#47082)
This commit modifies the provideCloudinaryLoader and provideImageKitLoader functions to support an additional ensurePreconnect option, similar to the Imgix loader functions.

PR Close #47082
2022-08-16 17:36:53 +00:00
Katie Hempenius 4e952ba216 feat(common): add loaders for cloudinary & imagekit (#47082)
This commit adds loaders for cloudinary and imagekit.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 1cf43deb18 fix(common): sanitize rawSrc and rawSrcset values in NgOptimizedImage directive (#47082)
This commit applies a sanitization to values produced by a loader, before they are used for the `src` and `srcset` image element properties.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 3774d84cfb test(common): optimize image loader tests of the NgOptimizedImage directive (#47082)
This commit updates the image loader tests to avoid creating the TestBed environment, since it's not really needed for the tests. Instead, the loader functions are invoked directly and the output is verified.

PR Close #47082
2022-08-16 17:36:53 +00:00
Pawel Kozlowski 98f20436ec refactor(common): allow loaders to specify the ensurePreconnect option (#47082)
This commit modifies the provideImgixLoader function to support
an additional ensurePreconnect option. Other loaders could follow
the same pattern to support a similar option as well.

As more loaders get developed we will refactor code to streamline
the loader authoring and enforce consistency.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 2d2e199ccc refactor(common): move LCP image observer to a separate file (#46295) (#47082)
This is a small refactoring to extract the LCP image observer to a separate file, similar to the preconnect link checker class location.
PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 586274fe65 feat(common): provide an ability to exclude origins from preconnect checks in NgOptimizedImage (#47082)
This commit adds an extra logic to add an ability to exclude origins from preconnect checks in NgOptimizedImage by configuring the `PRECONNECT_CHECK_BLOCKLIST` multi-provider.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 7baf9a46cd feat(common): verify that priority images have preconnect links (#47082)
This commit updates the `NgOptimizedImage` directive to add a logic to detect whether an image, marked with the "priority" attribute has a corresponding `<link rel="preconnect">` tag in the `document.head` for better performance.

PR Close #47082
2022-08-16 17:36:53 +00:00
Kara Erickson 7ce497e5bc feat(common): add built-in Imgix loader (#47082)
This commit adds a built-in Imgix loader for the
NgOptimizedImage directive. If you provide the
desired Imgix hostname, an ImageLoader will be
generated with the correct options.

Usage looks like this:

```ts
providers: [
  provideImgixLoader('https://some.imgix.net')
]
```

It sets the "auto=format" flag by default, which
ensures that the smallest image format supported
by the browser is served.

This change also moves the IMAGE_LOADER, ImageLoader,
and ImageLoaderConfig into a new directory that will
be shared by all built-in image loaders.

PR Close #47082
2022-08-16 17:36:52 +00:00