-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
140 lines (136 loc) · 3.73 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Squircle rectangle CSS paint worklet</title>
<meta charset="utf-8">
<meta name="description" content="">
<meta property="og:title" content="Squircle rectangle CSS paint worklet">
<meta property="og:image" content="https://squircle-rect.netlify.app/squircle-rect-css-paint-worklet.png">
<meta property="og:description" content="">
<meta name="twitter:image:alt" content="Screenshot with title, input for radius and an example squircle rectangle that says I AM SQUIRCLE in all caps.">
<meta name="twitter:site" content="@sakamies">
</head>
<body>
<div class="content">
<h1>
Squircle rectangle
<br>
CSS paint worklet
</h1>
<label>Radius</label>
<input type="range" min=0 max=200 id="radius-input">
<div class="squircle-rect">
I AM SQUIRCLE
<br>
<small>Rectangle, resizable</small>
</div>
<p>
<small>Try resizing from the handle (on desktop) ⤴</small>
</p>
<p class="links">
<a href="https://twitter.com/sakamies">Twitter</a>
<a href="https://mastodon.social/@sakamies">Mastodon</a>
<a href="https://github.com/sakamies/squircle-rect">Github</a>
</p>
</div>
<!-- Polyfill browsers that don't yet support CSS Paint API. -->
<script src="https://unpkg.com/css-paint-polyfill"></script>
<script>
//Import CSS Paint Worklet module.
CSS.paintWorklet.addModule('/squircle-rect.js')
//Demo stuff
const radiusInput = document.querySelector('#radius-input')
const squirclerect = document.querySelector('.squircle-rect')
function setRadius (e) {
console.log(squirclerect, e, e.target)
squirclerect.style.setProperty('--squircle-radius', e.target.value)
}
radiusInput.addEventListener('change', setRadius)
radiusInput.addEventListener('input', setRadius)
</script>
<style>
:root {
--cc: #009de6;
}
/* Some niceness for later, when browser support is all there.
@property --squircle-radius {
syntax: '<integer>';
inherits: true;
initial-value: 0;
}
@property --squircle-smooth {
syntax: '<integer>';
inherits: true;
initial-value: .5;
}
@property --squircle-color {
syntax: '<string>';
inherits: true;
}
*/
.squircle-rect {
font-size: 2rem;
font-weight: 900;
display: grid;
place-content: center;
place-items: center;
color: white;
/*The actual bit about the squircle*/
--squircle-color: var(--cc);
--squircle-radius: 100;
--squircle-smooth: .5; /*TODO: Smoothing parameter*/
background: paint(squircle-rect);
/*-------*/
resize: both;
overflow: hidden;
width: 300px;
height: 200px;
margin: 0 0 1rem 0;
padding: 1rem;
max-width: 100%;
}
html, body {
height: 100%;
min-height: 100%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
font-size: 2rem;
line-height: 1;
text-align: center;
display: grid;
color: black;
background: white;
}
h1 {
font-size: 3rem;
margin: 2rem 0 2rem 0;
}
p {
margin: 0 0 2rem 0;
}
small {
font-size: 1rem;
}
a {
color: var(--cc);
}
input {
accent-color: var(--cc);
margin: 0 0 1rem 0;
}
.content {
display: grid;
place-content: center;
place-items: center;
margin: auto;
}
.links {
font-size: 1.25rem;
margin: 0 0 .75rem 0;
}
</style>
</body>
</html>