|
346 | 346 | context.restore(); |
347 | 347 | } |
348 | 348 |
|
349 | | - // sync hit canvas with main canvas |
| 349 | + /* |
| 350 | + * Sync hit canvas with main canvas |
| 351 | + */ |
350 | 352 | if (hitCanvasContext) { |
351 | | - // scale hit canvas to match main canvas |
352 | | - scaleCanvas(hitCanvasContext, ctx.containerWidth, ctx.containerHeight); |
353 | | - hitCanvasContext.clearRect(0, 0, ctx.containerWidth, ctx.containerHeight); |
354 | | -
|
355 | | - // reset and sync transform to the state after retainState components |
356 | | - hitCanvasContext.resetTransform(); |
357 | | - hitCanvasContext.setTransform(mainTransformAfterRetain); |
358 | | -
|
359 | | - // reset color generator |
360 | | - colorGenerator = rgbColorGenerator(); |
361 | | -
|
362 | 353 | const inactiveMoving = !activeCanvas && transformCtx.moving; |
363 | | -
|
364 | | - // render retainState components on hit canvas (e.g., Group) |
365 | | - for (const c of retainStateComponents) { |
366 | | - const componentHasEvents = c.events && Object.values(c.events).filter((d) => d).length > 0; |
367 | | -
|
368 | | - if (componentHasEvents && !inactiveMoving && !transformCtx.dragging) { |
369 | | - // since the transform was already applied via setTransform, skip rendering |
370 | | - // the retainState component's transform again; proceed to its children |
371 | | - continue; |
| 354 | + if (disableHitCanvas || transformCtx.dragging || inactiveMoving) { |
| 355 | + // Skip rendering hit canvas |
| 356 | + hitCanvasContext.clearRect(0, 0, ctx.containerWidth, ctx.containerHeight); |
| 357 | + } else { |
| 358 | + // scale hit canvas to match main canvas |
| 359 | + scaleCanvas(hitCanvasContext, ctx.containerWidth, ctx.containerHeight); |
| 360 | + hitCanvasContext.clearRect(0, 0, ctx.containerWidth, ctx.containerHeight); |
| 361 | +
|
| 362 | + // reset and sync transform to the state after retainState components |
| 363 | + hitCanvasContext.resetTransform(); |
| 364 | + hitCanvasContext.setTransform(mainTransformAfterRetain); |
| 365 | +
|
| 366 | + // reset color generator |
| 367 | + colorGenerator = rgbColorGenerator(); |
| 368 | +
|
| 369 | + // render retainState components on hit canvas (e.g., Group) |
| 370 | + for (const c of retainStateComponents) { |
| 371 | + const componentHasEvents = |
| 372 | + c.events && Object.values(c.events).filter((d) => d).length > 0; |
| 373 | +
|
| 374 | + if (componentHasEvents) { |
| 375 | + // since the transform was already applied via setTransform, skip rendering |
| 376 | + // the retainState component's transform again; proceed to its children |
| 377 | + continue; |
| 378 | + } |
372 | 379 | } |
373 | | - } |
374 | 380 |
|
375 | | - // render non-retainState components on hit canvas |
376 | | - for (const c of nonRetainStateComponents) { |
377 | | - const componentHasEvents = c.events && Object.values(c.events).filter((d) => d).length > 0; |
| 381 | + // render non-retainState components on hit canvas |
| 382 | + for (const c of nonRetainStateComponents) { |
| 383 | + const componentHasEvents = |
| 384 | + c.events && Object.values(c.events).filter((d) => d).length > 0; |
378 | 385 |
|
379 | | - if (componentHasEvents && !inactiveMoving && !transformCtx.dragging && !disableHitCanvas) { |
380 | | - const color = getColorStr(colorGenerator.next().value); |
381 | | - const styleOverrides = { styles: { fill: color, stroke: color, _fillOpacity: 0.1 } }; |
| 386 | + if (componentHasEvents) { |
| 387 | + const color = getColorStr(colorGenerator.next().value); |
| 388 | + const styleOverrides = { styles: { fill: color, stroke: color, _fillOpacity: 0.1 } }; |
382 | 389 |
|
383 | | - hitCanvasContext.save(); |
384 | | - c.render(hitCanvasContext, styleOverrides); |
385 | | - hitCanvasContext.restore(); |
| 390 | + hitCanvasContext.save(); |
| 391 | + c.render(hitCanvasContext, styleOverrides); |
| 392 | + hitCanvasContext.restore(); |
386 | 393 |
|
387 | | - componentByColor.set(color, c); |
| 394 | + componentByColor.set(color, c); |
| 395 | + } |
388 | 396 | } |
389 | 397 | } |
390 | 398 | } |
|
0 commit comments