-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modernise fast svg library by using inject, standalone and prov…
…ide function
- Loading branch information
Showing
8 changed files
with
142 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Provider, makeEnvironmentProviders } from '@angular/core'; | ||
import { | ||
SvgLoadStrategy, | ||
SvgLoadStrategyImpl, | ||
SvgOptions, | ||
SvgOptionsToken, | ||
SvgRegistry, | ||
} from '..'; | ||
import { FastSvgProviderOptions } from './provider-config.interface'; | ||
|
||
/** | ||
* @description | ||
* Use this function to register the FastSvg providers in your application. | ||
* | ||
* @param options {FastSvgProviderOptions} - The options for the FastSvg providers. | ||
* @return {EnvironmentProviders} - The providers for the FastSvg module. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* bootstrapApplication(AppComponent, { | ||
* providers: [ | ||
* provideFastSVG({ | ||
* url: (name: string) => `path/to/svg-assets/${name}.svg`, | ||
* }) | ||
* ]}); | ||
* ``` | ||
*/ | ||
export const provideFastSVG = (options: FastSvgProviderOptions) => { | ||
const svgOptions: SvgOptions = { | ||
url: options.url, | ||
suspenseSvgString: options.suspenseSvgString || undefined, | ||
defaultSize: options.defaultSize || undefined, | ||
}; | ||
|
||
const providers: Provider[] = [ | ||
SvgRegistry, | ||
{ | ||
provide: SvgLoadStrategy, | ||
useClass: options.svgLoadStrategy || SvgLoadStrategyImpl, | ||
}, | ||
{ provide: SvgOptionsToken, useValue: svgOptions }, | ||
]; | ||
|
||
return makeEnvironmentProviders(providers); | ||
}; |