UNPKG

@antv/x6

Version:

JavaScript diagramming library that uses SVG and HTML for rendering

30 lines (25 loc) 860 B
const hyphenPattern = /-(.)/g function camelize(str: string) { return str.replace(hyphenPattern, (_, char) => char.toUpperCase()) } const memoized: { [key: string]: string | null } = {} const prefixes = ['webkit', 'ms', 'moz', 'o'] const testStyle = typeof document !== 'undefined' ? document.createElement('div').style : {} function getWithPrefix(name: string) { for (let i = 0; i < prefixes.length; i += 1) { const prefixedName = prefixes[i] + name if (prefixedName in testStyle) { return prefixedName } } return null } export function getVendorPrefixedName(property: string) { const name = camelize(property) if (memoized[name] == null) { const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1) memoized[name] = name in testStyle ? name : getWithPrefix(capitalizedName) } return memoized[name] }