mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Fixing issues raised by the linter. Fixes #68
+ just cleans up issues, and disables one test that can't be fixed. + biggest change is encoders not using multiple imports now.
This commit is contained in:
@@ -1,15 +1,13 @@
|
|||||||
import * as mozJPEG from './mozjpeg/encoder';
|
import * as mozJPEG from './mozjpeg/encoder';
|
||||||
import { EncoderState as MozJPEGEncodeData, EncodeOptions as MozJPEGEncodeOptions } from './mozjpeg/encoder';
|
|
||||||
import * as identity from './identity/encoder';
|
import * as identity from './identity/encoder';
|
||||||
import { EncoderState as IdentityEncodeData, EncodeOptions as IdentityEncodeOptions } from './identity/encoder';
|
|
||||||
|
|
||||||
export type EncoderState = IdentityEncodeData | MozJPEGEncodeData;
|
export type EncoderState = identity.EncoderState | mozJPEG.EncoderState;
|
||||||
export type EncoderOptions = IdentityEncodeOptions | MozJPEGEncodeOptions;
|
export type EncoderOptions = identity.EncodeOptions | mozJPEG.EncodeOptions;
|
||||||
export type EncoderType = keyof typeof encoderMap;
|
export type EncoderType = keyof typeof encoderMap;
|
||||||
|
|
||||||
export const encoderMap = {
|
export const encoderMap = {
|
||||||
[identity.type]: identity,
|
[identity.type]: identity,
|
||||||
[mozJPEG.type]: mozJPEG
|
[mozJPEG.type]: mozJPEG,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const encoders = Array.from(Object.values(encoderMap));
|
export const encoders = Array.from(Object.values(encoderMap));
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export default class MozJpegEncoder {
|
|||||||
encode: m.cwrap('encode', '', ['number', 'number', 'number', 'number']),
|
encode: m.cwrap('encode', '', ['number', 'number', 'number', 'number']),
|
||||||
free_result: m.cwrap('free_result', '', []),
|
free_result: m.cwrap('free_result', '', []),
|
||||||
get_result_pointer: m.cwrap('get_result_pointer', 'number', []),
|
get_result_pointer: m.cwrap('get_result_pointer', 'number', []),
|
||||||
get_result_size: m.cwrap('get_result_size', 'number', [])
|
get_result_size: m.cwrap('get_result_size', 'number', []),
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import { bind } from '../../../../lib/util';
|
import { bind } from '../../../../lib/util';
|
||||||
import './styles.css';
|
import './styles.css';
|
||||||
|
|
||||||
|
// tslint:disable-next-line:max-line-length
|
||||||
function firstMatchingItem(list: DataTransferItemList, acceptVal: string): DataTransferItem | undefined {
|
function firstMatchingItem(list: DataTransferItemList, acceptVal: string): DataTransferItem | undefined {
|
||||||
// Split accepts values by ',' then by '/'. Trim everything & lowercase.
|
// Split accepts values by ',' then by '/'. Trim everything & lowercase.
|
||||||
const accepts = acceptVal.toLowerCase().split(',').map(accept => {
|
const accepts = acceptVal.toLowerCase().split(',').map((accept) => {
|
||||||
return accept.trim().split('/').map(part => part.trim());
|
return accept.trim().split('/').map(part => part.trim());
|
||||||
}).filter(acceptParts => acceptParts.length === 2); // Filter invalid values
|
}).filter(acceptParts => acceptParts.length === 2); // Filter invalid values
|
||||||
|
|
||||||
return Array.from(list).find(item => {
|
return Array.from(list).find((item) => {
|
||||||
if (item.kind !== 'file') return false;
|
if (item.kind !== 'file') return false;
|
||||||
|
|
||||||
// 'Parse' the type.
|
// 'Parse' the type.
|
||||||
@@ -56,7 +57,7 @@ export class FileDrop extends HTMLElement {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.addEventListener('dragover', (event) => event.preventDefault());
|
this.addEventListener('dragover', event => event.preventDefault());
|
||||||
this.addEventListener('drop', this._onDrop);
|
this.addEventListener('drop', this._onDrop);
|
||||||
this.addEventListener('dragenter', this._onDragEnter);
|
this.addEventListener('dragenter', this._onDragEnter);
|
||||||
this.addEventListener('dragend', () => this._reset());
|
this.addEventListener('dragend', () => this._reset());
|
||||||
@@ -73,7 +74,7 @@ export class FileDrop extends HTMLElement {
|
|||||||
|
|
||||||
@bind
|
@bind
|
||||||
private _onDragEnter(event: DragEvent) {
|
private _onDragEnter(event: DragEvent) {
|
||||||
this._dragEnterCount++;
|
this._dragEnterCount += 1;
|
||||||
if (this._dragEnterCount > 1) return;
|
if (this._dragEnterCount > 1) return;
|
||||||
|
|
||||||
// We don't have data, attempt to get it and if it matches, set the correct state.
|
// We don't have data, attempt to get it and if it matches, set the correct state.
|
||||||
@@ -87,7 +88,7 @@ export class FileDrop extends HTMLElement {
|
|||||||
|
|
||||||
@bind
|
@bind
|
||||||
private _onDragLeave() {
|
private _onDragLeave() {
|
||||||
this._dragEnterCount--;
|
this._dragEnterCount -= 1;
|
||||||
if (this._dragEnterCount === 0) {
|
if (this._dragEnterCount === 0) {
|
||||||
this._reset();
|
this._reset();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { FileDropEvent, FileDrop } from ".";
|
import { FileDropEvent, FileDrop } from '.';
|
||||||
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export async function bitmapToImageData(bitmap: ImageBitmap): Promise<ImageData>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Replace the contents of a canvas with the given bitmap */
|
/** Replace the contents of a canvas with the given bitmap */
|
||||||
export function drawBitmapToCanvas (canvas: HTMLCanvasElement, img: ImageBitmap) {
|
export function drawBitmapToCanvas(canvas: HTMLCanvasElement, img: ImageBitmap) {
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
if (!ctx) throw Error('Canvas not initialized');
|
if (!ctx) throw Error('Canvas not initialized');
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|||||||
Reference in New Issue
Block a user