Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 92x 96x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 6x 6x 1x 1x 1x 1x 1x 6x 6x 4x 6x 92x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 92x 92x 92x 92x 92x 92x 92x 92x 91x 91x 91x 91x 91x 91x 91x 92x 92x 90x 90x 90x 90x 90x 92x 92x 92x 92x 92x 92x 92x 92x | import { css, html, PropertyValueMap } from 'lit';
import { property } from 'lit/decorators.js';
import { RapidElement } from '../RapidElement';
import { getClasses } from '../utils';
import { styleMap } from 'lit-html/directives/style-map.js';
/**
* This component relies on a bit of sleight of hand magic
* to achieve it's effect. As such, it requires the use of
* computed animation times and window.setTimeout().
*/
export class Lightbox extends RapidElement {
static get styles() {
return css`
:host {
z-index: 10000;
position: absolute;
top: 0;
left: 0;
}
.mask {
display: flex;
opacity: 0;
background: rgba(0, 0, 0, 0.5);
position: absolute;
height: 100svh;
width: 100svw;
pointer-events: none;
}
.zoom .mask {
opacity: 1;
pointer-events: auto;
}
.matte {
position: absolute;
transform: translate(400, 400) scale(3, 3);
border-radius: 2%;
overflow: hidden;
box-shadow: 0 0 12px 3px rgba(0, 0, 0, 0.15);
}
.download {
background: rgba(0, 0, 0, 0.5);
position: absolute;
display:flex;
align-items:center;
color:#fff;
padding:0.5em;
border-radius:var(--curvature);
background:rgba(0,0,0,0.5);
}
}
`;
}
@property({ type: Number })
animationTime = 300;
@property({ type: Boolean })
show = false;
@property({ type: Boolean })
zoom = false;
@property({ type: Number })
zoomPct = 0.9;
private ele: HTMLElement;
private left: number;
private top: number;
private height: number;
private width: number;
private scale = 1;
private xTrans = 0;
private yTrans = 0;
protected updated(
changed: PropertyValueMap<any> | Map<PropertyKey, unknown>
): void {
if (changed.has('show') && this.show) {
window.setTimeout(() => {
this.zoom = true;
}, 0);
}
if (changed.has('zoom') && !this.zoom && this.show) {
window.setTimeout(() => {
this.show = false;
}, this.animationTime);
}
}
public showElement(ele: HTMLElement) {
// size our matte according to the ele's boundaries
const bounds = ele.getBoundingClientRect();
this.ele = ele.cloneNode() as HTMLElement;
(this.ele as any).zoom = true;
this.left = bounds.left;
this.top = bounds.top;
this.width = bounds.width;
this.height = bounds.height;
this.xTrans = 0;
this.yTrans = 0;
this.scale = 1;
let desiredWidth = this.width;
let desiredHeight = this.height;
let desiredScale = this.scale;
const maxHeight = window.innerHeight * this.zoomPct;
const maxWidth = window.innerWidth * this.zoomPct;
// if the width fits, constrain by height
if (this.width * (maxHeight / this.height) < maxWidth) {
desiredHeight = window.innerHeight * this.zoomPct;
desiredScale = desiredHeight / this.height;
desiredWidth = this.width * desiredScale;
} else {
desiredWidth = window.innerWidth * this.zoomPct;
desiredScale = desiredWidth / this.width;
desiredHeight = this.height * desiredScale;
}
const xGrowth = (desiredWidth - this.width) / 2;
const xDest = (window.innerWidth - desiredWidth) / 2;
this.xTrans = xDest - this.left + xGrowth;
const yGrowth = (desiredHeight - this.height) / 2;
const yDest = (window.innerHeight - desiredHeight) / 2;
this.yTrans = yDest - this.top + yGrowth;
this.scale = desiredScale;
this.show = true;
}
public handleClick() {
this.zoom = false;
}
public render() {
const styles = {
transition: `transform ${this.animationTime}ms ease, box-shadow ${this.animationTime}ms ease`
};
if (this.show) {
styles['left'] = this.left + 'px';
styles['top'] = this.top + 'px';
styles['width'] = this.width + 'px';
}
if (this.zoom) {
styles['transform'] =
`translate(${this.xTrans}px, ${this.yTrans}px) scale(${this.scale}, ${this.scale})`;
}
return html`
<div
class=${getClasses({
container: true,
show: this.show,
zoom: this.zoom
})}
@click=${this.handleClick}
>
<div
class=${getClasses({ mask: true })}
style="transition: all ${this.animationTime}ms; ease"
></div>
<div class=${getClasses({ matte: true })} style=${styleMap(styles)}>
${this.show ? html`${this.ele}` : null}
</div>
</div>
`;
}
}
|