-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement basic VueImgixClient
- Loading branch information
1 parent
28d421e
commit b1c3036
Showing
3 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './vue-imgix'; |
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,16 @@ | ||
export interface IImgixClientOptions { | ||
domain: string; | ||
} | ||
|
||
export interface IBuildUrlObjectResult { | ||
src: string; | ||
srcset: string; | ||
} | ||
export type IBuildUrlObject = ( | ||
url: string, | ||
options: {}, | ||
) => IBuildUrlObjectResult; | ||
|
||
export interface IVueImgixClient { | ||
buildUrlObject: IBuildUrlObject; | ||
} |
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,27 @@ | ||
import ImgixClient from 'imgix-core-js'; | ||
import { IBuildUrlObjectResult, IImgixClientOptions, IVueImgixClient } from './types'; | ||
|
||
class VueImgixClient implements IVueImgixClient { | ||
#client: ImgixClient; | ||
constructor(options: IImgixClientOptions) { | ||
this.#client = new ImgixClient(options) | ||
} | ||
|
||
buildUrlObject(url: string, options: {}): IBuildUrlObjectResult { | ||
const src = this.#client.buildURL(url, options) | ||
const srcset = this.#client.buildSrcSet(url, options) | ||
|
||
return {src, srcset} | ||
} | ||
} | ||
|
||
export const buildImgixClient = (options: IImgixClientOptions) => { | ||
const client = new VueImgixClient({ | ||
...options, | ||
}); | ||
|
||
return client; | ||
}; | ||
|
||
export type { IVueImgixClient }; | ||
|