* Draw the given code scope. * * @param scope - The code scope to draw.
(scope: CodeScope)
| 162 | * @param scope - The code scope to draw. |
| 163 | */ |
| 164 | public drawScope(scope: CodeScope) { |
| 165 | const progress = unwrap(scope.progress); |
| 166 | for (const wrappedFragment of scope.fragments) { |
| 167 | const possibleFragment = unwrap(wrappedFragment); |
| 168 | if (isCodeScope(possibleFragment)) { |
| 169 | this.drawScope(possibleFragment); |
| 170 | continue; |
| 171 | } |
| 172 | if (Array.isArray(possibleFragment)) { |
| 173 | this.drawScope({ |
| 174 | progress: scope.progress, |
| 175 | fragments: possibleFragment, |
| 176 | }); |
| 177 | continue; |
| 178 | } |
| 179 | |
| 180 | const fragment = parseCodeFragment( |
| 181 | possibleFragment, |
| 182 | this.context, |
| 183 | this.monoWidth, |
| 184 | ); |
| 185 | const timingOffset = 0.8; |
| 186 | let alpha = 1; |
| 187 | let offsetY = 0; |
| 188 | if (fragment.before.content !== fragment.after.content) { |
| 189 | const mirrored = Math.abs(progress - 0.5) * 2; |
| 190 | alpha = clampRemap(1, 1 - timingOffset, 1, 0, mirrored); |
| 191 | |
| 192 | const scale = progress < 0.5 ? 4 : -4; |
| 193 | offsetY = map( |
| 194 | Math.abs(fragment.after.newRows - fragment.before.newRows) / scale, |
| 195 | 0, |
| 196 | mirrored, |
| 197 | ); |
| 198 | } |
| 199 | |
| 200 | this.drawToken(fragment, scope, this.cursor.addY(offsetY), alpha); |
| 201 | |
| 202 | this.beforeCursor.x = this.calculateWidth( |
| 203 | fragment.before, |
| 204 | this.beforeCursor.x, |
| 205 | ); |
| 206 | this.afterCursor.x = this.calculateWidth( |
| 207 | fragment.after, |
| 208 | this.afterCursor.x, |
| 209 | ); |
| 210 | this.beforeCursor.y += fragment.before.newRows; |
| 211 | this.afterCursor.y += fragment.after.newRows; |
| 212 | |
| 213 | this.beforeIndex += fragment.before.content.length; |
| 214 | this.afterIndex += fragment.after.content.length; |
| 215 | |
| 216 | this.cursor.y += map( |
| 217 | fragment.before.newRows, |
| 218 | fragment.after.newRows, |
| 219 | progress, |
| 220 | ); |
| 221 |
no test coverage detected