-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `responsive-image` service has been dropped and replaced with a simple static module from the new `core` package.
- Loading branch information
1 parent
71270e7
commit 5a69e21
Showing
18 changed files
with
85 additions
and
198 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,7 @@ | ||
--- | ||
'ember-responsive-image': major | ||
--- | ||
|
||
Drop service class | ||
|
||
The `responsive-image` service has been dropped and replaced with a simple static module from the new `core` package. |
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,23 @@ | ||
// import { config } from '../config.ts'; | ||
|
||
import type { Env } from './types'; | ||
|
||
const screenWidth = typeof screen !== 'undefined' ? screen.width : 320; | ||
const devicePixelRatio = window?.devicePixelRatio ?? 1; | ||
const physicalWidth = screenWidth * devicePixelRatio; | ||
// TODO: figure out user config | ||
// const deviceWidths = config.deviceWidths; | ||
const deviceWidths = [640, 750, 828, 1080, 1200, 1920, 2048, 3840]; | ||
|
||
export const env: Env = { | ||
screenWidth, | ||
physicalWidth, | ||
devicePixelRatio, | ||
deviceWidths, | ||
}; | ||
|
||
export function getDestinationWidthBySize(size = 100): number { | ||
const factor = size / 100; | ||
|
||
return physicalWidth * factor; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export type * from './types.ts'; | ||
export { findMatchingImage } from './match.ts'; | ||
export * from './env.ts'; | ||
|
||
export type * from './types.ts'; |
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
49 changes: 14 additions & 35 deletions
49
packages/ember-responsive-image/src/helpers/responsive-image-resolve.ts
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 |
---|---|---|
@@ -1,39 +1,18 @@ | ||
import { inject as service } from '@ember/service'; | ||
import { | ||
getDestinationWidthBySize, | ||
type ImageData, | ||
type ImageType, | ||
} from '@ember-responsive-image/core'; | ||
import { htmlSafe } from '@ember/template'; | ||
import Helper from '@ember/component/helper'; | ||
import ResponsiveImageService from '../services/responsive-image.ts'; | ||
import type { ImageType, ImageData } from '@ember-responsive-image/core'; | ||
|
||
interface ResponsiveImageResolveSignature { | ||
Args: { | ||
Positional: [ImageData]; | ||
Named: { | ||
size?: number; | ||
format?: ImageType; | ||
}; | ||
}; | ||
Return: ReturnType<typeof htmlSafe> | undefined; | ||
} | ||
|
||
/** | ||
* @class responsiveImageResolve | ||
* @namespace Helpers | ||
* @extends Ember.Helper | ||
* @public | ||
*/ | ||
export default class ResponsiveImageResolve extends Helper<ResponsiveImageResolveSignature> { | ||
@service | ||
responsiveImage!: ResponsiveImageService; | ||
|
||
compute( | ||
[data]: [ImageData], | ||
{ | ||
size, | ||
format = data.imageTypes[0], | ||
}: { size?: number; format?: ImageType }, | ||
): ReturnType<typeof htmlSafe> | undefined { | ||
const width = this.responsiveImage.getDestinationWidthBySize(size ?? 0); | ||
export default function responsiveImageResolve( | ||
data: ImageData, | ||
{ | ||
size, | ||
format = data.imageTypes[0], | ||
}: { size?: number; format?: ImageType } = {}, | ||
): ReturnType<typeof htmlSafe> | undefined { | ||
const width = getDestinationWidthBySize(size); | ||
|
||
return htmlSafe(data.imageUrlFor(width, format)); | ||
} | ||
return htmlSafe(data.imageUrlFor(width, format)); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export { default as ResponsiveImage } from './components/responsive-image.ts'; | ||
export { default as ResponsiveImageService } from './services/responsive-image.ts'; | ||
export { default as resolve } from './helpers/responsive-image-resolve.ts'; | ||
export type { ImageData } from '@ember-responsive-image/core'; |
33 changes: 0 additions & 33 deletions
33
packages/ember-responsive-image/src/services/responsive-image.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.