-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
217 lines (198 loc) · 6.88 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>focus-picker</title>
<!-- og metadata -->
<meta property="og:title" content="focus-picker" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://focus-picker.pages.dev/" />
<meta
property="og:image"
content="https://focus-picker.pages.dev/focus-picker.jpeg"
/>
<meta property="og:image:width" content="1565" />
<meta property="og:image:height" content="1288" />
<meta
property="og:description"
content="A web component utility to help you find the perfect object-position for your images"
/>
<meta property="og:site_name" content="focus-picker" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/themes/light.css"
/>
<style>
html,
body {
height: 100%;
margin: 0;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
}
.grid {
height: 100%;
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 3fr);
grid-template-rows: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 3fr);
gap: 1rem;
}
@media (max-width: 800px) {
.grid {
grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
grid-template-rows: minmax(0, 1fr) minmax(0, 2fr);
}
/* hide all images */
.grid img {
display: none;
}
/* re-enable the first three images */
.grid img:nth-child(-n + 3) {
display: block;
}
/* first image should take up a full row */
.grid img:nth-child(1) {
grid-column: 1 / -1;
}
}
.grid img {
width: 100%;
height: 100%;
object-fit: cover;
object-position: var(--position, 50% 50%);
}
.container {
display: block;
position: fixed;
bottom: 0;
right: 0;
width: clamp(200px, 50%, 400px);
padding: 1rem;
background-color: white;
.flex {
margin-top: 0.5rem;
display: flex;
align-items: center;
gap: 0.5rem;
& p {
margin: 0;
font-variant-numeric: tabular-nums;
}
& a {
margin-inline-start: auto;
& svg {
height: 1.5em;
}
}
}
}
.image-src {
display: flex;
align-items: center;
margin-bottom: 0.5rem;
}
.image-src label {
margin-right: 0.5rem;
}
.image-src input {
flex-grow: 1;
padding: 0.5em;
border-radius: 0.25rem;
border-style: solid;
border-color: gray;
}
focus-picker {
display: block;
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<div class="grid">
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
<img src="https://picsum.photos/2000/1200" alt="" />
</div>
<div class="container">
<div class="image-src">
<label for="src">Image URL</label>
<input
type="text"
id="src"
value="https://picsum.photos/2000/1200"
placeholder="https://picsum.photos/2000/1200"
/>
</div>
<focus-picker id="picker">
<img src="https://picsum.photos/2000/1200" alt="" />
</focus-picker>
<div class="flex">
<sl-copy-button
id="copy-btn"
value="object-position: 50% 50%;"
></sl-copy-button>
<p id="copy-text">object-position: 50% 50%;</p>
<a
aria-label="View source on github"
href="https://github.com/third774/focus-picker"
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 96">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
fill="#24292f"
/>
</svg>
</a>
</div>
</div>
<script src="src/index.ts" type="module"></script>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/copy-button/copy-button.js"
></script>
<script>
const copyBtn = document.querySelector("#copy-btn");
const copyText = document.querySelector("#copy-text");
const picker = document.querySelector("#picker");
const grid = document.querySelector(".grid");
picker.addEventListener("focuspicked", (e) => {
grid.setAttribute("style", "--position: " + event.detail.position);
copyBtn.value = `offset-position: ${e.detail.position};`;
copyText.innerHTML = `offset-position: ${e.detail.position.replace(
" ",
" "
)};`;
// also have access to x and y values (beteween 0 and 1)
console.log(e.detail.x, e.detail.y);
});
function updateImages(src) {
const images = document.querySelectorAll("img");
images.forEach((img) => {
img.src = src;
});
}
// update images when input changes
const input = document.querySelector("#src");
input.addEventListener("input", (e) => {
updateImages(e.target.value);
});
const url = new URL(window.location.href);
const src = url.searchParams.get("src");
if (src) {
updateImages(src);
input.value = src;
}
</script>
</body>
</html>