reduce imports and exports

main
Mike Fix 6 years ago committed by Michael Fix
parent 3aec3ebc28
commit dbde17a65f

@ -30,8 +30,7 @@ import {
DEFAULT_CODE,
DEFAULT_SETTINGS,
DEFAULT_LANGUAGE,
DEFAULT_PRESET_ID,
MAX_PAYLOAD_SIZE
DEFAULT_PRESET_ID
} from '../lib/constants'
import { serializeState, getQueryStringState } from '../lib/routing'
import {
@ -40,8 +39,7 @@ import {
unescapeHtml,
formatCode,
omit,
isSafari,
sizeOf
verifyPayloadSize
} from '../lib/util'
import LanguageIcon from './svg/Language'
import ThemeIcon from './svg/Theme'
@ -113,7 +111,10 @@ class Editor extends React.Component {
window.addEventListener('offline', this.setOffline)
window.addEventListener('online', this.setOnline)
this.isSafari = isSafari()
this.isSafari =
window.navigator &&
window.navigator.userAgent.indexOf('Safari') !== -1 &&
window.navigator.userAgent.indexOf('Chrome') === -1
}
componentWillUnmount() {
@ -271,9 +272,7 @@ class Editor extends React.Component {
updateBackground({ photographer, ...changes } = {}) {
if (this.isSafari) {
this.disablePNG =
typeof changes.backgroundImage === 'string' &&
sizeOf(changes.backgroundImage) > MAX_PAYLOAD_SIZE
this.disablePNG = !verifyPayloadSize(changes.backgroundImage)
}
if (photographer) {

@ -641,5 +641,3 @@ export const DEFAULT_PRESETS = [
id: 'preset:6'
}
]
export const MAX_PAYLOAD_SIZE = 5000000 //bytes

@ -77,10 +77,9 @@ export const stringifyRGBA = obj => `rgba(${obj.r},${obj.g},${obj.b},${obj.a})`
export const capitalize = s => s.charAt(0).toUpperCase() + s.slice(1)
export const isSafari = () =>
window &&
window.navigator &&
window.navigator.userAgent.indexOf('Safari') !== -1 &&
window.navigator.userAgent.indexOf('Chrome') === -1
const MAX_PAYLOAD_SIZE = 5e6
export const verifyPayloadSize = str => {
if (typeof str !== 'string') return true
export const sizeOf = str => str.length * 2 //bytes
return new Blob([str]).size < MAX_PAYLOAD_SIZE // bytes
}

Loading…
Cancel
Save