| 1 |
"use strict"; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 13 |
exports.hyphenate = exports.parse = void 0; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
function parse(value) { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
const styles = []; |
| 28 |
let i = 0; |
| 29 |
let parenDepth = 0; |
| 30 |
let quote = 0; |
| 31 |
let valueStart = 0; |
| 32 |
let propStart = 0; |
| 33 |
let currentProp = null; |
| 34 |
while (i < value.length) { |
| 35 |
const token = value.charCodeAt(i++); |
| 36 |
switch (token) { |
| 37 |
case 40 : |
| 38 |
parenDepth++; |
| 39 |
break; |
| 40 |
case 41 : |
| 41 |
parenDepth--; |
| 42 |
break; |
| 43 |
case 39 : |
| 44 |
|
| 45 |
|
| 46 |
if (quote === 0 ) { |
| 47 |
quote = 39 ; |
| 48 |
} else if ( |
| 49 |
quote === 39 && |
| 50 |
value.charCodeAt(i - 1) !== 92 |
| 51 |
) { |
| 52 |
quote = 0 ; |
| 53 |
} |
| 54 |
break; |
| 55 |
case 34 : |
| 56 |
|
| 57 |
if (quote === 0 ) { |
| 58 |
quote = 34 ; |
| 59 |
} else if ( |
| 60 |
quote === 34 && |
| 61 |
value.charCodeAt(i - 1) !== 92 |
| 62 |
) { |
| 63 |
quote = 0 ; |
| 64 |
} |
| 65 |
break; |
| 66 |
case 58 : |
| 67 |
if ( |
| 68 |
!currentProp && |
| 69 |
parenDepth === 0 && |
| 70 |
quote === 0 |
| 71 |
) { |
| 72 |
currentProp = hyphenate(value.substring(propStart, i - 1).trim()); |
| 73 |
valueStart = i; |
| 74 |
} |
| 75 |
break; |
| 76 |
case 59 : |
| 77 |
if ( |
| 78 |
currentProp && |
| 79 |
valueStart > 0 && |
| 80 |
parenDepth === 0 && |
| 81 |
quote === 0 |
| 82 |
) { |
| 83 |
const styleVal = value.substring(valueStart, i - 1).trim(); |
| 84 |
styles.push(currentProp, styleVal); |
| 85 |
propStart = i; |
| 86 |
valueStart = 0; |
| 87 |
currentProp = null; |
| 88 |
} |
| 89 |
break; |
| 90 |
} |
| 91 |
} |
| 92 |
if (currentProp && valueStart) { |
| 93 |
const styleVal = value.slice(valueStart).trim(); |
| 94 |
styles.push(currentProp, styleVal); |
| 95 |
} |
| 96 |
return styles; |
| 97 |
} |
| 98 |
exports.parse = parse; |
| 99 |
function hyphenate(value) { |
| 100 |
return value |
| 101 |
.replace(/[a-z][A-Z]/g, (v) => { |
| 102 |
return v.charAt(0) + "-" + v.charAt(1); |
| 103 |
}) |
| 104 |
.toLowerCase(); |
| 105 |
} |
| 106 |
exports.hyphenate = hyphenate; |