| 39 | type Param = { value: number | null; subparams: number[]; colon: boolean } |
| 40 | |
| 41 | function parseParams(str: string): Param[] { |
| 42 | if (str === '') return [{ value: 0, subparams: [], colon: false }] |
| 43 | |
| 44 | const result: Param[] = [] |
| 45 | let current: Param = { value: null, subparams: [], colon: false } |
| 46 | let num = '' |
| 47 | let inSub = false |
| 48 | |
| 49 | for (let i = 0; i <= str.length; i++) { |
| 50 | const c = str[i] |
| 51 | if (c === ';' || c === undefined) { |
| 52 | const n = num === '' ? null : parseInt(num, 10) |
| 53 | if (inSub) { |
| 54 | if (n !== null) current.subparams.push(n) |
| 55 | } else { |
| 56 | current.value = n |
| 57 | } |
| 58 | result.push(current) |
| 59 | current = { value: null, subparams: [], colon: false } |
| 60 | num = '' |
| 61 | inSub = false |
| 62 | } else if (c === ':') { |
| 63 | const n = num === '' ? null : parseInt(num, 10) |
| 64 | if (!inSub) { |
| 65 | current.value = n |
| 66 | current.colon = true |
| 67 | inSub = true |
| 68 | } else { |
| 69 | if (n !== null) current.subparams.push(n) |
| 70 | } |
| 71 | num = '' |
| 72 | } else if (c >= '0' && c <= '9') { |
| 73 | num += c |
| 74 | } |
| 75 | } |
| 76 | return result |
| 77 | } |
| 78 | |
| 79 | function parseExtendedColor( |
| 80 | params: Param[], |