Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | 160x 160x 160x 160x 238x 238x 238x 238x 254x 254x 254x 238x 160x 306x 44x 44x 87x 87x 87x 63x 90x 44x 262x 262x 238x 160x 160x 160x 15x 15x 22x 18x 18x 15x 160x 14x 14x 14x 20x 20x 20x 19x 14x 160x 306x 306x 141x 165x 90x 180x 180x 128x 75x 23x 30x 27x 306x 160x 1x 1x 1x 1x 1x | import { isArray, isString, isObject, hyphenate } from './' import { isNoUnitNumericStyleProp } from './domAttrConfig' const hashedCustomProperty = /^[0-9a-f]{8}/i; const customPropertyPrefix = '--'; function normalizeCustomProperty(value: Record<string, string> | string): Record<string, string> | string { if (isObject(value)) { const objectKeys = Object.keys(value); const res: Record<string, string> = {}; for (let i = 0; i < objectKeys.length; i++) { const item = objectKeys[i]; Iif (item.match(hashedCustomProperty)) { res[`${customPropertyPrefix}${item}`] = value[item]; continue; } res[item] = value[item]; } return res; } Iif (value.match(hashedCustomProperty)) { return `${customPropertyPrefix}${value}`; } return value; } export type NormalizedStyle = Record<string, string | number> export function normalizeStyle( value: unknown ): NormalizedStyle | string | undefined { if (isArray(value)) { const res: NormalizedStyle = {} for (let i = 0; i < value.length; i++) { const item = value[i] const normalized = isString(item) ? parseStringStyle(item) : (normalizeStyle(item) as NormalizedStyle) if (normalized) { for (const key in normalized) { res[key] = normalized[key] } } } return res } else Iif (isString(value)) { return normalizeCustomProperty(value); } else if (isObject(value)) { return normalizeCustomProperty(value); } } const listDelimiterRE = /;(?![^(]*\))/g const propertyDelimiterRE = /:(.+)/ export function parseStringStyle(cssText: string): NormalizedStyle { const ret: NormalizedStyle = {} cssText.split(listDelimiterRE).forEach(item => { if (item) { const tmp = item.split(propertyDelimiterRE) tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim()) } }) return ret } export function stringifyStyle( styles: NormalizedStyle | string | undefined ): string { let ret = '' Iif (!styles || isString(styles)) { return ret } for (const key in styles) { const value = styles[key] const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key) if ( isString(value) || (typeof value === 'number' && isNoUnitNumericStyleProp(normalizedKey)) ) { // only render valid values ret += `${normalizedKey}:${value};` } } return ret } export function normalizeClass(value: unknown): string { let res = '' if (isString(value)) { res = value } else if (isArray(value)) { for (let i = 0; i < value.length; i++) { const normalized = normalizeClass(value[i]) if (normalized) { res += normalized + ' ' } } } else if (isObject(value)) { for (const name in value) { if (value[name]) { res += name + ' ' } } } return res.trim() } export function normalizeProps(props: Record<string, any> | null) { Iif (!props) return null let { class: klass, style } = props Iif (klass && !isString(klass)) { props.class = normalizeClass(klass) } Iif (style) { props.style = normalizeStyle(style) } return props } |