Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import type {
Interpolation,
ScopedInsertableStyles,
CSSCache
} from '@emotion/types'
import hashString from '@emotion/hash'
import unitless from '@emotion/unitless'
import memoize from '@emotion/memoize'
const hyphenateRegex = /[A-Z]|^ms/g
export const processStyleName: (styleName: string) => string = memoize(
(styleName: string) => styleName.replace(hyphenateRegex, '-$&').toLowerCase()
)
export let processStyleValue = (key: string, value: string): string => {
if (value == null || typeof value === 'boolean') {
return ''
}
if (
unitless[key] !== 1 &&
key.charCodeAt(1) !== 45 && // custom properties
!isNaN(value) &&
value !== 0
) {
return value + 'px'
}
// Wait for the browser to finish rendering before scrolling.
setTimeout(function() {
if (element) {
element.click()
}
}, 0)
}
}
})
}
const ClassName = (props: any) => {
return props.children(props.className)
}
const createLiveCode = memoize(logoUrl => props => (
{internalCodeStylesClassName => (
// @flow
import findRoot from 'find-root'
import memoize from '@emotion/memoize'
import nodePath from 'path'
import hashString from '@emotion/hash'
import escapeRegexp from 'escape-string-regexp'
let hashArray = (arr: Array) => hashString(arr.join(''))
const unsafeRequire = require
const getPackageRootPath = memoize(filename => findRoot(filename))
const separator = new RegExp(escapeRegexp(nodePath.sep), 'g')
const normalizePath = path => nodePath.normalize(path).replace(separator, '/')
export function getTargetClassName(state: *, t: *) {
if (state.emotionTargetClassNameCount === undefined) {
state.emotionTargetClassNameCount = 0
}
const filename = state.file.opts.filename
// normalize the file path to ignore folder structure
// outside the current node project and arch-specific delimiters
let moduleName = ''
let rootPath = filename
// @flow
import findRoot from 'find-root'
import memoize from '@emotion/memoize'
import nodePath from 'path'
import hashString from '@emotion/hash'
let hashArray = (arr: Array) => hashString(arr.join(''))
const unsafeRequire = require
const getPackageRootPath = memoize(filename => findRoot(filename))
export function getTargetClassName(state: *, t: *) {
if (state.emotionTargetClassNameCount === undefined) {
state.emotionTargetClassNameCount = 0
}
const filename = state.file.opts.filename
// normalize the file path to ignore folder structure
// outside the current node project and arch-specific delimiters
let moduleName = ''
let rootPath = filename
try {
rootPath = getPackageRootPath(filename)
moduleName = unsafeRequire(rootPath + '/package.json').name
// @flow
import memoize from '@emotion/memoize'
import unitless from '@emotion/unitless'
const hyphenateRegex = /[A-Z]|^ms/g
export const processStyleName: (styleName: string) => string = memoize(
(styleName: string) => styleName.replace(hyphenateRegex, '-$&').toLowerCase()
)
export let processStyleValue = (key: string, value: string): string => {
if (value == null || typeof value === 'boolean') {
return ''
}
if (
unitless[key] !== 1 &&
key.charCodeAt(1) !== 45 && // custom properties
!isNaN(value) &&
value !== 0
) {
return value + 'px'
}
const memoize = require('@emotion/memoize').default
const isPropValid = require('@emotion/is-prop-valid').default
const systemProps = require('styled-system/props')
const regex = new RegExp(`^(${systemProps.join('|')})$`)
module.exports = memoize(prop => isPropValid(prop) && !regex.test(prop))
const ILLEGAL_ESCAPE_SEQUENCE_ERROR = `You have illegal escape sequence in your template literal, most likely inside content's property value.
Because you write your CSS inside a JavaScript string you actually have to do double escaping, so for example "content: '\\00d7';" should become "content: '\\\\00d7';".
You can read more about this here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#ES2018_revision_of_illegal_escape_sequences`
const UNDEFINED_AS_OBJECT_KEY_ERROR =
"You have passed in falsy value as style object's key (can happen when in example you pass unexported component as computed key)."
let hyphenateRegex = /[A-Z]|^ms/g
let animationRegex = /_EMO_([^_]+?)_([^]*?)_EMO_/g
const isCustomProperty = (property: string) => property.charCodeAt(1) === 45
const isProcessableValue = value => value != null && typeof value !== 'boolean'
const processStyleName = memoize(
(styleName: string) =>
isCustomProperty(styleName)
? styleName
: styleName.replace(hyphenateRegex, '-$&').toLowerCase()
)
let processStyleValue = (
key: string,
value: string | number
): string | number => {
switch (key) {
case 'animation':
case 'animationName': {
if (typeof value === 'string') {
return value.replace(animationRegex, (match, p1, p2) => {
cursor = {
import memoize from '@emotion/memoize'
declare var codegen: { require: string => RegExp }
const reactPropsRegex = codegen.require('./props')
export default memoize(RegExp.prototype.test.bind(reactPropsRegex))