2 import { bottomRight, topLeft } from '$lib/stores/canvas';
3 import { modulo } from '$lib/math';
4 import { maxSize } from '$lib/config';
7 const width = widget.box.right - widget.box.left;
8 const height = widget.box.bottom - widget.box.top;
10 // Coordinates in canvas space are (p,q)
11 // Coordinates in screen space are (x,y)
17 const pCanvas = modulo($topLeft.x, maxSize);
18 const qCanvas = modulo($topLeft.y, maxSize);
20 const pBoundary = pCanvas + Math.abs($topLeft.x - $bottomRight.x);
21 const qBoundary = qCanvas + Math.abs($topLeft.y - $bottomRight.y);
23 const pWidget = widget.box.left;
24 const qWidget = widget.box.top;
26 xWidget = pWidget - pCanvas;
27 yWidget = qWidget - qCanvas;
29 // Case 1: Boundary jump happens inside the box
30 if (pWidget < pCanvas && pBoundary > maxSize && pWidget < pBoundary - maxSize) {
31 xWidget = xWidget + maxSize;
33 // Case 2: Boundary jump happens to the left of the box
34 else if (pWidget > pCanvas && pBoundary < maxSize && pWidget > pBoundary) {
35 xWidget = xWidget - maxSize;
38 // Case 1: Boundary jump happens inside the box
39 if (qWidget < qCanvas && qBoundary > maxSize && qWidget < qBoundary - maxSize) {
40 yWidget = yWidget + maxSize;
42 // Case 2: Boundary jump happens above the top of the box
43 else if (qWidget > qCanvas && qBoundary < maxSize && qWidget > qBoundary) {
44 yWidget = yWidget - maxSize;
51 style:width="{width}px"
52 style:height="{height}px"
53 style:left="{xWidget}px"
54 style:top="{yWidget}px"
62 background-color: #f0f;
63 border: 1px solid black;