From ed451e4dfa07a9e2ad99dd9880aa567c415f09f2 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Thu, 30 Jul 2020 14:43:46 +0100 Subject: [PATCH] "native" to "builtin" (#788) --- src/codecs/decoders.ts | 8 ++++---- src/codecs/resize/processor-sync.ts | 6 +++--- src/components/select/index.tsx | 4 ++-- src/components/select/style.scss | 2 +- src/lib/util.ts | 8 ++++---- src/sw/util.ts | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/codecs/decoders.ts b/src/codecs/decoders.ts index 8347bcf2..b23f3791 100644 --- a/src/codecs/decoders.ts +++ b/src/codecs/decoders.ts @@ -1,19 +1,19 @@ -import { nativeDecode, sniffMimeType, canDecodeImage } from '../lib/util'; +import { builtinDecode, sniffMimeType, canDecodeImage } from '../lib/util'; import Processor from './processor'; import webpDataUrl from 'url-loader!./tiny.webp'; -const nativeWebPSupported = canDecodeImage(webpDataUrl); +const webPSupported = canDecodeImage(webpDataUrl); export async function decodeImage(blob: Blob, processor: Processor): Promise { const mimeType = await sniffMimeType(blob); try { - if (mimeType === 'image/webp' && !(await nativeWebPSupported)) { + if (mimeType === 'image/webp' && !(await webPSupported)) { return await processor.webpDecode(blob); } // Otherwise, just throw it at the browser's decoder. - return await nativeDecode(blob); + return await builtinDecode(blob); } catch (err) { throw Error("Couldn't decode image"); } diff --git a/src/codecs/resize/processor-sync.ts b/src/codecs/resize/processor-sync.ts index f2192185..22b5e85b 100644 --- a/src/codecs/resize/processor-sync.ts +++ b/src/codecs/resize/processor-sync.ts @@ -1,4 +1,4 @@ -import { nativeResize, NativeResizeMethod, drawableToImageData } from '../../lib/util'; +import { builtinResize, BuiltinResizeMethod, drawableToImageData } from '../../lib/util'; import { BrowserResizeOptions, VectorResizeOptions } from './processor-meta'; import { getContainOffsets } from './util'; @@ -12,9 +12,9 @@ export function browserResize(data: ImageData, opts: BrowserResizeOptions): Imag ({ sx, sy, sw, sh } = getContainOffsets(sw, sh, opts.width, opts.height)); } - return nativeResize( + return builtinResize( data, sx, sy, sw, sh, opts.width, opts.height, - opts.method.slice('browser-'.length) as NativeResizeMethod, + opts.method.slice('browser-'.length) as BuiltinResizeMethod, ); } diff --git a/src/components/select/index.tsx b/src/components/select/index.tsx index cbaf4541..d9cc9abc 100644 --- a/src/components/select/index.tsx +++ b/src/components/select/index.tsx @@ -12,8 +12,8 @@ export default class Select extends Component { return (
- +
); } diff --git a/src/components/select/style.scss b/src/components/select/style.scss index b13ea914..82f21a02 100644 --- a/src/components/select/style.scss +++ b/src/components/select/style.scss @@ -2,7 +2,7 @@ position: relative; } -.native-select { +.builtin-select { background: #2f2f2f; border-radius: 4px; font: inherit; diff --git a/src/lib/util.ts b/src/lib/util.ts index 538626c8..d0f9828f 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -163,7 +163,7 @@ export function drawableToImageData( return ctx.getImageData(0, 0, width, height); } -export async function nativeDecode(blob: Blob): Promise { +export async function builtinDecode(blob: Blob): Promise { // Prefer createImageBitmap as it's the off-thread option for Firefox. const drawable = 'createImageBitmap' in self ? await createImageBitmap(blob) : await blobToImg(blob); @@ -171,13 +171,13 @@ export async function nativeDecode(blob: Blob): Promise { return drawableToImageData(drawable); } -export type NativeResizeMethod = 'pixelated' | 'low' | 'medium' | 'high'; +export type BuiltinResizeMethod = 'pixelated' | 'low' | 'medium' | 'high'; -export function nativeResize( +export function builtinResize( data: ImageData, sx: number, sy: number, sw: number, sh: number, dw: number, dh: number, - method: NativeResizeMethod, + method: BuiltinResizeMethod, ): ImageData { const canvasSource = document.createElement('canvas'); canvasSource.width = data.width; diff --git a/src/sw/util.ts b/src/sw/util.ts index cb7156b3..8faa1020 100644 --- a/src/sw/util.ts +++ b/src/sw/util.ts @@ -116,7 +116,7 @@ export async function cacheAdditionalProcessors(cacheName: string, buildAssets: return createImageBitmap(blob).then(() => true, () => false); })(); - // No point caching the WebP decoder if it's supported natively: + // No point caching the WebP decoder if the browser supports it: if (supportsWebP) { toCache = toCache.filter(asset => !/webp[\-_]dec/.test(asset)); }