mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-12 08:47:31 +00:00
Basic grid setup
This commit is contained in:
@@ -60,7 +60,7 @@ const encoderOptionsComponentMap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
orientation: 'horizontal' | 'vertical';
|
mobileView: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
source?: SourceImage;
|
source?: SourceImage;
|
||||||
imageIndex: number;
|
imageIndex: number;
|
||||||
@@ -155,7 +155,6 @@ export default class Options extends Component<Props, State> {
|
|||||||
imageIndex,
|
imageIndex,
|
||||||
imageFile,
|
imageFile,
|
||||||
downloadUrl,
|
downloadUrl,
|
||||||
orientation,
|
|
||||||
encoderState,
|
encoderState,
|
||||||
preprocessorState,
|
preprocessorState,
|
||||||
onEncoderOptionsChange,
|
onEncoderOptionsChange,
|
||||||
|
|||||||
@@ -2,12 +2,19 @@ $horizontalPadding: 15px;
|
|||||||
|
|
||||||
.options {
|
.options {
|
||||||
color: #fff;
|
color: #fff;
|
||||||
width: 300px;
|
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
|
max-width: 400px;
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
@media (min-width: 600px) {
|
||||||
|
width: 300px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.options-title {
|
.options-title {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { twoUpHandle } from './custom-els/TwoUp/styles.css';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
originalImage?: ImageData;
|
originalImage?: ImageData;
|
||||||
orientation: 'horizontal' | 'vertical';
|
mobileView: boolean;
|
||||||
leftCompressed?: ImageData;
|
leftCompressed?: ImageData;
|
||||||
rightCompressed?: ImageData;
|
rightCompressed?: ImageData;
|
||||||
leftImgContain: boolean;
|
leftImgContain: boolean;
|
||||||
@@ -180,10 +180,7 @@ export default class Output extends Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render(
|
render(
|
||||||
{
|
{ mobileView, leftImgContain, rightImgContain, originalImage }: Props,
|
||||||
orientation, leftCompressed, rightCompressed, leftImgContain, rightImgContain,
|
|
||||||
originalImage,
|
|
||||||
}: Props,
|
|
||||||
{ scale, editingScale, altBackground }: State,
|
{ scale, editingScale, altBackground }: State,
|
||||||
) {
|
) {
|
||||||
const leftDraw = this.leftDrawable();
|
const leftDraw = this.leftDrawable();
|
||||||
@@ -194,7 +191,7 @@ export default class Output extends Component<Props, State> {
|
|||||||
<two-up
|
<two-up
|
||||||
legacy-clip-compat
|
legacy-clip-compat
|
||||||
class={style.twoUp}
|
class={style.twoUp}
|
||||||
orientation={orientation}
|
orientation={mobileView ? 'vertical' : 'horizontal'}
|
||||||
// Event redirecting. See onRetargetableEvent.
|
// Event redirecting. See onRetargetableEvent.
|
||||||
onTouchStartCapture={this.onRetargetableEvent}
|
onTouchStartCapture={this.onRetargetableEvent}
|
||||||
onTouchEndCapture={this.onRetargetableEvent}
|
onTouchEndCapture={this.onRetargetableEvent}
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ import { cleanMerge, cleanSet } from '../../lib/clean-modify';
|
|||||||
import Processor from '../../codecs/processor';
|
import Processor from '../../codecs/processor';
|
||||||
import { VectorResizeOptions, BitmapResizeOptions } from '../../codecs/resize/processor-meta';
|
import { VectorResizeOptions, BitmapResizeOptions } from '../../codecs/resize/processor-meta';
|
||||||
|
|
||||||
type Orientation = 'horizontal' | 'vertical';
|
|
||||||
|
|
||||||
export interface SourceImage {
|
export interface SourceImage {
|
||||||
file: File | Fileish;
|
file: File | Fileish;
|
||||||
data: ImageData;
|
data: ImageData;
|
||||||
@@ -69,7 +67,7 @@ interface State {
|
|||||||
loading: boolean;
|
loading: boolean;
|
||||||
loadingCounter: number;
|
loadingCounter: number;
|
||||||
error?: string;
|
error?: string;
|
||||||
orientation: Orientation;
|
mobileView: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UpdateImageOptions {
|
interface UpdateImageOptions {
|
||||||
@@ -156,7 +154,7 @@ async function processSvg(blob: Blob): Promise<HTMLImageElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class Compress extends Component<Props, State> {
|
export default class Compress extends Component<Props, State> {
|
||||||
widthQuery = window.matchMedia('(min-width: 500px)');
|
widthQuery = window.matchMedia('(max-width: 600px)');
|
||||||
|
|
||||||
state: State = {
|
state: State = {
|
||||||
source: undefined,
|
source: undefined,
|
||||||
@@ -178,7 +176,7 @@ export default class Compress extends Component<Props, State> {
|
|||||||
loading: false,
|
loading: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
orientation: this.widthQuery.matches ? 'horizontal' : 'vertical',
|
mobileView: this.widthQuery.matches,
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly encodeCache = new ResultCache();
|
private readonly encodeCache = new ResultCache();
|
||||||
@@ -193,7 +191,7 @@ export default class Compress extends Component<Props, State> {
|
|||||||
|
|
||||||
@bind
|
@bind
|
||||||
private onMobileWidthChange() {
|
private onMobileWidthChange() {
|
||||||
this.setState({ orientation: this.widthQuery.matches ? 'horizontal' : 'vertical' });
|
this.setState({ mobileView: this.widthQuery.matches });
|
||||||
}
|
}
|
||||||
|
|
||||||
private onEncoderTypeChange(index: 0 | 1, newType: EncoderType): void {
|
private onEncoderTypeChange(index: 0 | 1, newType: EncoderType): void {
|
||||||
@@ -395,15 +393,15 @@ export default class Compress extends Component<Props, State> {
|
|||||||
this.setState({ images });
|
this.setState({ images });
|
||||||
}
|
}
|
||||||
|
|
||||||
render({ }: Props, { loading, images, source, orientation }: State) {
|
render({ }: Props, { loading, images, source, mobileView }: State) {
|
||||||
const [leftImage, rightImage] = images;
|
const [leftImage, rightImage] = images;
|
||||||
const [leftImageData, rightImageData] = images.map(i => i.data);
|
const [leftImageData, rightImageData] = images.map(i => i.data);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={`${style.compress} ${style[orientation]}`}>
|
<div class={style.compress}>
|
||||||
<Output
|
<Output
|
||||||
originalImage={source && source.data}
|
originalImage={source && source.data}
|
||||||
orientation={orientation}
|
mobileView={mobileView}
|
||||||
leftCompressed={leftImageData}
|
leftCompressed={leftImageData}
|
||||||
rightCompressed={rightImageData}
|
rightCompressed={rightImageData}
|
||||||
leftImgContain={leftImage.preprocessorState.resize.fitMethod === 'cover'}
|
leftImgContain={leftImage.preprocessorState.resize.fitMethod === 'cover'}
|
||||||
@@ -413,7 +411,7 @@ export default class Compress extends Component<Props, State> {
|
|||||||
<Options
|
<Options
|
||||||
loading={loading || image.loading}
|
loading={loading || image.loading}
|
||||||
source={source}
|
source={source}
|
||||||
orientation={orientation}
|
mobileView={mobileView}
|
||||||
imageIndex={index}
|
imageIndex={index}
|
||||||
imageFile={image.file}
|
imageFile={image.file}
|
||||||
downloadUrl={image.downloadUrl}
|
downloadUrl={image.downloadUrl}
|
||||||
|
|||||||
@@ -3,20 +3,16 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
contain: strict;
|
contain: strict;
|
||||||
display: grid;
|
display: grid;
|
||||||
|
align-items: end;
|
||||||
|
align-content: end;
|
||||||
|
grid-template-rows: 1fr auto;
|
||||||
|
|
||||||
&.horizontal {
|
@media (min-width: 600px) {
|
||||||
grid-template-columns: 1fr auto;
|
grid-template-columns: 1fr auto;
|
||||||
grid-template-rows: calc(100% - 75px);
|
grid-template-rows: calc(100% - 75px);
|
||||||
|
|
||||||
@media (min-width: 860px) {
|
|
||||||
grid-template-rows: 100%;
|
|
||||||
}
|
|
||||||
align-items: end;
|
|
||||||
align-content: end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.vertical {
|
@media (min-width: 860px) {
|
||||||
// TODO: make the mobile view work
|
grid-template-rows: 100%;
|
||||||
background: red;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user