Skip to content

Commit 1abbd7b

Browse files
committed
works now without border set in css
1 parent ac836b3 commit 1abbd7b

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

src/css-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import CSS_COLOR_NAMES from './external/bobspace:html-colors';
22

3-
const toPx = typeof document !== 'undefined' && require('./external/heygrady:units:length');
3+
const toPx = typeof document !== 'undefined' && require('./external/heygrady:units:length').default;
44

55
/** @returns {string} */
66
function convertPlainColor(val) {
@@ -26,7 +26,7 @@ function convertPlainColor(val) {
2626
function convertColorOpacity(val) {
2727
if (val?.startsWith('rgba') || val?.startsWith('hsla')) {
2828
return Number(val.match(/(\d*\.?\d+)?\)$/)[1])
29-
} else return 1
29+
} else return 0
3030
}
3131

3232
const htmlLengthNotSvgErrorTemplate = (a, b) => `<RoundDiv> ${a} must be ${b ? `either ${b}, or` : ''} in one of the following units: ch, cm, em, ex, in, mm, pc, pt, px, rem, vh, vmax, vmin, vw.`

src/external/apearce:react-shadow-dom.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* by apearce
44
*/
55

6-
import React from 'react';
6+
import React, {Fragment} from 'react';
77
import ReactDOM from 'react-dom';
88
import PropTypes from 'prop-types';
99

@@ -67,7 +67,7 @@ export default class ShadowRoot extends React.PureComponent {
6767

6868
render() {
6969
if (!this.state.initialized) {
70-
return <span ref={this.placeholder}></span>;
70+
return <span ref={this.placeholder}/>;
7171
}
7272

7373
return ReactDOM.createPortal(this.props.children, this.shadowRoot);

src/generator.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default function generateSvgSquircle(height, width, radius) {
6363

6464
const startPoint = `${a0xw},${wyOffset}`
6565

66-
return `M${startPoint}
66+
const path = `M${startPoint}
6767
${width / 2 < a0x[1]
6868
? ''
6969
: `L${width - a0xw},0`
@@ -108,4 +108,9 @@ export default function generateSvgSquircle(height, width, radius) {
108108
.replace(/\d+\.\d+/g, match =>
109109
Math.round(Number(match) * (10 ** roundToNthPlace)) / (10 ** roundToNthPlace)
110110
)
111+
112+
if (path.match(/[^ M0LCZ,]/) === null)
113+
return ''
114+
115+
return path
111116
}

src/main.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function RoundDiv({style, children, ...props}) {
1414
const [radius, setRadius] = useState(Array(4).fill(0))
1515

1616
const [borderColor, setBorderColor] = useState(Array(4).fill('transparent'))
17-
const [borderOpacity, setBorderOpacity] = useState(Array(4).fill(1))
17+
const [borderOpacity, setBorderOpacity] = useState(Array(4).fill(0))
1818
const [borderWidth, setBorderWidth] = useState(Array(4).fill(0))
1919

2020
const [path, setPath] = useState('Z')
@@ -23,17 +23,19 @@ export default function RoundDiv({style, children, ...props}) {
2323

2424
const div = useRef()
2525

26-
const updateStatesWithArgs = useCallback(() => updateStates({
27-
div,
28-
style,
29-
setPosition,
30-
setHeight,
31-
setWidth,
32-
setRadius,
33-
setBorderColor,
34-
setBorderWidth,
35-
setBorderOpacity
36-
}), [style])
26+
const updateStatesWithArgs = useCallback(() => {
27+
updateStates({
28+
div,
29+
style,
30+
setPosition,
31+
setHeight,
32+
setWidth,
33+
setRadius,
34+
setBorderColor,
35+
setBorderWidth,
36+
setBorderOpacity
37+
})
38+
}, [style])
3739

3840
useEffect(updateStatesWithArgs, [style, updateStatesWithArgs])
3941

@@ -81,8 +83,9 @@ export default function RoundDiv({style, children, ...props}) {
8183

8284
const divStyle = {
8385
...style,
84-
clipPath: `path("${path}")`,
85-
borderColor: 'transparent'
86+
clipPath: (path.startsWith('Z') || path === '') ? '' : `path("${path}")`,
87+
borderColor: 'transparent',
88+
borderRadius: 0,
8689
}
8790

8891
return <div {...props} style={divStyle} ref={div}>

src/styleSheetWatcher.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
console.log()
2-
31
const CSSChangeEvent = typeof CustomEvent !== 'undefined' ? new CustomEvent('css-change') : 'css-change';
42

53
export default function attachCSSWatcher(callback) {
@@ -8,6 +6,15 @@ export default function attachCSSWatcher(callback) {
86

97
const CSSWatcher = new EventTarget()
108

9+
if (typeof document !== 'undefined') {
10+
if (document.readyState === 'complete')
11+
CSSWatcher.dispatchEvent(CSSChangeEvent)
12+
else
13+
window.addEventListener('load', () =>
14+
CSSWatcher.dispatchEvent(CSSChangeEvent)
15+
)
16+
}
17+
1118
;(function watchCSS() {
1219
let CSS = getCSSText()
1320
setInterval(() => {

src/updateStates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function updateStates(args) {
4040
const returnNthOverwrittenOrCurrent = r =>
4141
!r ? false :
4242
r?.overwritten.length > 0
43-
? r.overwritten[n ?? 0].value
43+
? r.overwritten[n ?? 0]?.value
4444
: r.current?.value
4545

4646
const normal = getStyle(key, div.current)
@@ -73,7 +73,7 @@ export default function updateStates(args) {
7373
if (!divStyle) return
7474
ReactDOM.unstable_batchedUpdates(() => {
7575
lazySetRadius(
76-
getBorderRadii(1)
76+
getBorderRadii(0)
7777
.map(s => Math.min(
7878
toNumber(s, div.current, htmlBorderRadiusNotSvgError),
7979
height / 2,

0 commit comments

Comments
 (0)