Skip to content

Commit 1d816b7

Browse files
committed
1 parent fbee6e5 commit 1d816b7

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

app/components/selection/box-model.element.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export class BoxModel extends HTMLElement {
2626

2727
if (mode === 'padding') {
2828
this.drawable = {
29-
height: bounds.height,
30-
width: bounds.width,
31-
top: 0,
32-
left: 0,
29+
height: bounds.height - (sides.borders.top + sides.borders.bottom),
30+
width: bounds.width - (sides.borders.right + sides.borders.left),
31+
top: 0 + sides.borders.top,
32+
left: 0 + sides.borders.left,
3333
rotation: 'rotate(-45)',
3434
}
3535
}
@@ -69,6 +69,7 @@ export class BoxModel extends HTMLElement {
6969
}
7070

7171
styles({sides}) {
72+
console.log(sides.borders)
7273
this.style.setProperty('--width', `${this.drawable.width}px`)
7374
this.style.setProperty('--height', `${this.drawable.height}px`)
7475
this.style.setProperty('--top', `${this.drawable.top}px`)
@@ -135,7 +136,7 @@ export class BoxModel extends HTMLElement {
135136
if (sides.top) {
136137
this.createMeasurement({
137138
x: (bounds.width / 2) - offset,
138-
y: (window.scrollY * -1),
139+
y: (window.scrollY * -1) + sides.borders.top,
139140
d: sides.top,
140141
q: 'top',
141142
v: true,
@@ -145,7 +146,7 @@ export class BoxModel extends HTMLElement {
145146
if (sides.bottom) {
146147
this.createMeasurement({
147148
x: (bounds.width / 2) - offset,
148-
y: (window.scrollY * -1) + (bounds.height - sides.bottom),
149+
y: (window.scrollY * -1) + (bounds.height - sides.bottom - sides.borders.bottom),
149150
d: sides.bottom,
150151
q: 'bottom',
151152
v: true,
@@ -154,7 +155,7 @@ export class BoxModel extends HTMLElement {
154155
}
155156
if (sides.right) {
156157
this.createMeasurement({
157-
x: bounds.width - sides.right,
158+
x: bounds.width - sides.right - sides.borders.right,
158159
y: (window.scrollY * -1) + (bounds.height / 2) - offset,
159160
d: sides.right,
160161
q: 'right',
@@ -164,7 +165,7 @@ export class BoxModel extends HTMLElement {
164165
}
165166
if (sides.left) {
166167
this.createMeasurement({
167-
x: 0,
168+
x: 0 + sides.borders.left,
168169
y: (window.scrollY * -1) + (bounds.height / 2) - offset,
169170
d: sides.left,
170171
q: 'left',

app/features/padding.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import hotkeys from 'hotkeys-js'
2-
import { metaKey, getStyle, getSide, showHideSelected } from '../utilities/'
2+
import { metaKey, getStyle, getSide, showHideSelected, expandBorders } from '../utilities/'
33

44
const key_events = 'up,down,left,right'
55
.split(',')
@@ -91,6 +91,7 @@ function removeBackgrounds(els) {
9191
export function createPaddingVisual(el, hover = false) {
9292
const bounds = el.getBoundingClientRect()
9393
const calculatedStyle = getStyle(el, 'padding')
94+
const calculatedBorder = expandBorders(getStyle(el, 'border-width'))
9495
const boxdisplay = document.createElement('visbug-boxmodel')
9596

9697
if (calculatedStyle !== '0px') {
@@ -112,7 +113,10 @@ export function createPaddingVisual(el, hover = false) {
112113
mode: 'padding',
113114
color: hover ? 'purple' : 'pink',
114115
bounds,
115-
sides,
116+
sides: {
117+
...sides,
118+
borders: calculatedBorder,
119+
},
116120
}
117121
}
118122

app/utilities/styles.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,37 @@ export const firstUsableFontFromFamily = family => {
165165

166166
return match
167167
}
168+
169+
export const expandBorders = (borderString) => {
170+
let expanded = {}
171+
let split = borderString.split(' ').map(i=>parseInt(i))
172+
173+
switch (split.length) {
174+
case 1:
175+
expanded = {
176+
top: split[0],
177+
right: split[0],
178+
bottom: split[0],
179+
left: split[0],
180+
}
181+
break
182+
case 2:
183+
expanded = {
184+
top: split[0],
185+
right: split[1],
186+
bottom: split[0],
187+
left: split[1],
188+
}
189+
break
190+
case 4:
191+
expanded = {
192+
top: split[0],
193+
right: split[1],
194+
bottom: split[2],
195+
left: split[3],
196+
}
197+
break
198+
}
199+
200+
return expanded
201+
}

0 commit comments

Comments
 (0)