mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-17 19:19:47 +00:00
(Almost the) rest of the redesign (#880)
* Load demo img * two-up styles * Back button * Button size tweak * Move back btn * Move options and back button into a single grid * Simpler max height * Responsive grid * Feed index into options * Option heading themes * More option styles * Changing checkbox position * Theme range input & use transforms * Range input underline theme * Checkbox color * Add toggle * Reorder * Arrow revealer * Round two-up thumb * Don't bundle CSS urls starting # * Results in progress * Fix Safari bugs * Download blobs * Loading spinner * Hook up download button * Different style for original image * Mobile design for results * Remove demo auto-loader * Remove redundant colors * Sticky headings
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import PointerTracker from 'pointer-tracker';
|
||||
import * as style from './style.css';
|
||||
import 'add-css:./style.css';
|
||||
|
||||
@@ -28,7 +27,7 @@ function getPrescision(value: string): number {
|
||||
|
||||
class RangeInputElement extends HTMLElement {
|
||||
private _input: HTMLInputElement;
|
||||
private _valueDisplay?: HTMLDivElement;
|
||||
private _valueDisplay?: HTMLSpanElement;
|
||||
private _ignoreChange = false;
|
||||
|
||||
static get observedAttributes() {
|
||||
@@ -41,15 +40,22 @@ class RangeInputElement extends HTMLElement {
|
||||
this._input.type = 'range';
|
||||
this._input.className = style.input;
|
||||
|
||||
const tracker = new PointerTracker(this._input, {
|
||||
start: (): boolean => {
|
||||
if (tracker.currentPointers.length !== 0) return false;
|
||||
this._input.classList.add(style.touchActive);
|
||||
return true;
|
||||
},
|
||||
end: () => {
|
||||
let activePointer: number | undefined;
|
||||
|
||||
// Not using pointer-tracker here due to https://bugs.webkit.org/show_bug.cgi?id=219636.
|
||||
this.addEventListener('pointerdown', (event) => {
|
||||
if (activePointer) return;
|
||||
activePointer = event.pointerId;
|
||||
this._input.classList.add(style.touchActive);
|
||||
const pointerUp = (event: PointerEvent) => {
|
||||
if (event.pointerId !== activePointer) return;
|
||||
activePointer = undefined;
|
||||
this._input.classList.remove(style.touchActive);
|
||||
},
|
||||
window.removeEventListener('pointerup', pointerUp);
|
||||
window.removeEventListener('pointercancel', pointerUp);
|
||||
};
|
||||
window.addEventListener('pointerup', pointerUp);
|
||||
window.addEventListener('pointercancel', pointerUp);
|
||||
});
|
||||
|
||||
for (const event of RETARGETED_EVENTS) {
|
||||
@@ -66,13 +72,13 @@ class RangeInputElement extends HTMLElement {
|
||||
this.innerHTML =
|
||||
`<div class="${style.thumbWrapper}">` +
|
||||
`<div class="${style.thumb}"></div>` +
|
||||
`<div class="${style.valueDisplay}"></div>` +
|
||||
`<div class="${style.valueDisplay}"><svg width="32" height="62"><path d="M27.3 27.3C25 29.6 17 35.8 17 43v3c0 3 2.5 5 3.2 5.8a6 6 0 1 1-8.5 0C12.6 51 15 49 15 46v-3c0-7.2-8-13.4-10.3-15.7A16 16 0 0 1 16 0a16 16 0 0 1 11.3 27.3z"/></svg><span></span></div>` +
|
||||
'</div>';
|
||||
|
||||
this.insertBefore(this._input, this.firstChild);
|
||||
this._valueDisplay = this.querySelector(
|
||||
'.' + style.valueDisplay,
|
||||
) as HTMLDivElement;
|
||||
'.' + style.valueDisplay + ' > span',
|
||||
) as HTMLSpanElement;
|
||||
// Set inline styles (this is useful when used with frameworks which might clear inline styles)
|
||||
this._update();
|
||||
}
|
||||
|
||||
@@ -23,10 +23,8 @@ range-input::before {
|
||||
width: 100%;
|
||||
height: 2px;
|
||||
border-radius: 1px;
|
||||
box-shadow: 0 -0.5px 0 rgba(0, 0, 0, 0.3),
|
||||
inset 0 0.5px 0 rgba(255, 255, 255, 0.2), 0 0.5px 0 rgba(255, 255, 255, 0.3);
|
||||
background: linear-gradient(#34b9eb, #218ab1) 0 / var(--value-percent, 0%)
|
||||
100% no-repeat #eee;
|
||||
background: linear-gradient(var(--main-theme-color), var(--main-theme-color))
|
||||
0 / var(--value-percent, 0%) 100% no-repeat var(--medium-light-gray);
|
||||
}
|
||||
|
||||
.input {
|
||||
@@ -41,14 +39,12 @@ range-input::before {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
bottom: 3px;
|
||||
left: var(--value-percent, 0%);
|
||||
left: 0;
|
||||
margin-left: -6px;
|
||||
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><circle cx="5" cy="5" r="1" fill="%235D509E" /></svg>')
|
||||
center no-repeat #34b9eb;
|
||||
background: var(--main-theme-color);
|
||||
border-radius: 50%;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
box-shadow: 0 0.5px 2px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.thumb-wrapper {
|
||||
@@ -58,21 +54,19 @@ range-input::before {
|
||||
bottom: 0;
|
||||
height: 0;
|
||||
overflow: visible;
|
||||
transform: translate(var(--value-percent, 0%), 0);
|
||||
}
|
||||
|
||||
.value-display {
|
||||
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="62" fill="none"><path fill="%2334B9EB" d="M27.3 27.3C25 29.6 17 35.8 17 43v3c0 3 2.5 5 3.2 5.8a6 6 0 1 1-8.5 0C12.6 51 15 49 15 46v-3c0-7.2-8-13.4-10.3-15.7A16 16 0 0 1 16 0a16 16 0 0 1 11.3 27.3z"/><circle cx="16" cy="56" r="1" fill="%235D509E"/></svg>')
|
||||
top center no-repeat;
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
left: var(--value-percent, 0%);
|
||||
left: 0;
|
||||
bottom: 3px;
|
||||
width: 32px;
|
||||
height: 62px;
|
||||
text-align: center;
|
||||
padding: 8px 3px 0;
|
||||
margin: 0 0 0 -16px;
|
||||
filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
|
||||
transform-origin: 50% 90%;
|
||||
opacity: 0.0001;
|
||||
transform: scale(0.2);
|
||||
@@ -86,6 +80,19 @@ range-input::before {
|
||||
will-change: transform;
|
||||
pointer-events: none;
|
||||
overflow: hidden;
|
||||
|
||||
> svg {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
fill: var(--main-theme-color);
|
||||
}
|
||||
|
||||
> span {
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
|
||||
.touch-active + .thumb-wrapper .value-display {
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
box-sizing: border-box;
|
||||
text-decoration: underline;
|
||||
text-decoration-style: dotted;
|
||||
text-decoration-color: var(--main-theme-color);
|
||||
text-underline-position: under;
|
||||
width: 48px;
|
||||
position: relative;
|
||||
|
||||
Reference in New Issue
Block a user