Viewer zoom and sharper tiles
Mouse wheel, trackpad and two-finger pinch zoom in the album viewer, up to one image pixel per device pixel; drag pans while zoomed and only the visible tiles of the needed level are loaded. Default WebP quality raised to top 90, mid 88, low 88, with smart_subsample for WebP tiles and the seed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ae898a2787
commit
aaf7cafdf9
9 files changed
+302
-18
No files matched your search
@@ -82,7 +82,7 @@ Unknown fields are errors, so typos are caught.
|
||||
| `images.tile_size` | `512` | Tile edge in pixels. |
|
||||
| `images.overlap` | `1` | Tile overlap in pixels. |
|
||||
| `images.format` | `"webp"` | `"webp"` or `"avif"` (AVIF needs a libheif AV1 encoder). |
|
||||
| `images.quality` | `{ top = 82, mid = 85, low = 88 }` | Top two levels, levels above 1100 px, levels up to 1100 px. |
|
||||
| `images.quality` | `{ top = 90, mid = 88, low = 88 }` | Top two levels, levels above 1100 px, levels up to 1100 px. |
|
||||
| `images.min_levels` | `6` | Minimum pyramid depth. |
|
||||
| `images.seed_px` | `48` | Long edge of the blurred placeholder. |
|
||||
| `images.tile_names` | `"hashed"` | Only `"hashed"` in v1. |
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
|
||||
1. Autorotate by EXIF orientation, convert to sRGB from the embedded profile.
|
||||
2. Read camera, lens, focal length, aperture, shutter, ISO and date into the manifest. Drop everything else, including GPS. Tiles carry no metadata.
|
||||
3. Pyramid: tiles 512 px, 1 px overlap; each level halves the previous one until the long edge is under 100 px. Level 0 is the smallest.
|
||||
4. WebP by default (AVIF optional). Quality per level: `top` for the top two levels, `low` for levels whose long edge is at most 1100 px, `mid` otherwise.
|
||||
4. WebP by default (AVIF optional); WebP tiles and the seed are saved with `smart_subsample` so chroma stays sharp. Quality per level: `top` for the top two levels, `low` for levels whose long edge is at most 1100 px, `mid` otherwise.
|
||||
5. Seed: a 48 px (long edge) WebP, base64 inside the album manifest.
|
||||
6. No resolution cap: the full-resolution level is stored; the loader never fetches beyond screen size × max_dpr.
|
||||
7. Tile paths: `/t/<photo-hash>/<tile-id>.webp`. photo-hash = first 16 hex of SHA-256 over the original bytes + a processing-settings fingerprint. tile-id = first 16 hex of HMAC-SHA-256(site key, photo-hash|level|x|y). The site key is generated once and kept in the state folder. On disk and in developer tools the tiles are an unordered pile of patches; only the manifest maps them back.
|
||||
@@ -106,7 +106,7 @@ cache = "/var/cache/luphoto"
|
||||
tile_size = 512
|
||||
overlap = 1
|
||||
format = "webp"
|
||||
quality = { top = 82, mid = 85, low = 88 }
|
||||
quality = { top = 90, mid = 88, low = 88 }
|
||||
min_levels = 6
|
||||
seed_px = 48
|
||||
tile_names = "hashed"
|
||||
|
||||
@@ -105,7 +105,7 @@ func Defaults() Config {
|
||||
TileSize: 512,
|
||||
Overlap: 1,
|
||||
Format: "webp",
|
||||
Quality: Quality{Top: 82, Mid: 85, Low: 88},
|
||||
Quality: Quality{Top: 90, Mid: 88, Low: 88},
|
||||
MinLevels: 6,
|
||||
SeedPx: 48,
|
||||
TileNames: "hashed",
|
||||
|
||||
@@ -113,11 +113,15 @@ func New(ctx context.Context, cfg *config.Config) (*Processor, error) {
|
||||
}
|
||||
img := cfg.Images
|
||||
keySum := sha256.Sum256(key)
|
||||
format := img.Format
|
||||
if format == "webp" {
|
||||
format += "+smart_subsample"
|
||||
}
|
||||
fingerprint := strings.Join([]string{
|
||||
processorVersion,
|
||||
"tile=" + strconv.Itoa(img.TileSize),
|
||||
"overlap=" + strconv.Itoa(img.Overlap),
|
||||
"format=" + img.Format,
|
||||
"format=" + format,
|
||||
fmt.Sprintf("q=%d,%d,%d", img.Quality.Top, img.Quality.Mid, img.Quality.Low),
|
||||
"min_levels=" + strconv.Itoa(img.MinLevels),
|
||||
"seed=" + strconv.Itoa(img.SeedPx),
|
||||
|
||||
@@ -107,7 +107,7 @@ func (p *Processor) renderOG(ctx context.Context, job *Job) (*Record, error) {
|
||||
}
|
||||
final := filepath.Join(p.OGDir, job.Hash+".jpg")
|
||||
tmp := fsutil.TempName(final) + ".jpg"
|
||||
if err := p.vips.Run(ctx, "thumbnail", prepared, tmp+p.vips.SaveOptions(OGQuality),
|
||||
if err := p.vips.Run(ctx, "thumbnail", prepared, tmp+p.vips.SaveOptions("jpeg", OGQuality),
|
||||
strconv.Itoa(OGWidth), "--height", strconv.Itoa(OGHeight), "--crop", "centre"); err != nil {
|
||||
_ = os.Remove(tmp)
|
||||
return nil, err
|
||||
@@ -323,7 +323,7 @@ func (p *Processor) resize(ctx context.Context, src, dst string, from, to [2]int
|
||||
|
||||
func (p *Processor) seed(ctx context.Context, src, work string) (string, error) {
|
||||
out := filepath.Join(work, "seed."+p.images.Format)
|
||||
if err := p.vips.Run(ctx, "thumbnail", src, out+p.vips.SaveOptions(p.images.Quality.Low),
|
||||
if err := p.vips.Run(ctx, "thumbnail", src, out+p.vips.SaveOptions(p.images.Format, p.images.Quality.Low),
|
||||
strconv.Itoa(p.images.SeedPx), "--height", strconv.Itoa(p.images.SeedPx)); err != nil {
|
||||
return "", fmt.Errorf("seed: %w", err)
|
||||
}
|
||||
@@ -373,7 +373,7 @@ func (p *Processor) cutLevel(ctx context.Context, hash, src, stage string, level
|
||||
"--depth", "one",
|
||||
"--tile-size", strconv.Itoa(p.images.TileSize),
|
||||
"--overlap", strconv.Itoa(p.Overlap()),
|
||||
"--suffix", ext+p.vips.SaveOptions(quality)); err != nil {
|
||||
"--suffix", ext+p.vips.SaveOptions(p.images.Format, quality)); err != nil {
|
||||
return Level{}, err
|
||||
}
|
||||
dir, err := levelDir(base + "_files")
|
||||
|
||||
@@ -99,7 +99,10 @@ func (v *Vips) Run(ctx context.Context, args ...string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Vips) SaveOptions(quality int) string {
|
||||
func (v *Vips) SaveOptions(format string, quality int) string {
|
||||
if format == "webp" {
|
||||
return "[Q=" + strconv.Itoa(quality) + ",smart_subsample=true," + v.Strip + "]"
|
||||
}
|
||||
return "[Q=" + strconv.Itoa(quality) + "," + v.Strip + "]"
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
"use strict";(()=>{(function(r){let t={from:"Guoliang",to:"Lucio",letters:[{ch:"G",kind:"keep",shared:"M8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50",fullA:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",fullB:"M8.50 0.00L8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50L80.00 91.50",out:[{d:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00",P:79.21,j:"end"},{d:"M58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",P:73.21,j:"start"}],in:[{d:"M8.50 22.00L8.50 0.00",P:22,j:"start"},{d:"M58.00 91.50L80.00 91.50",P:22,j:"start"}],x0:0,x1:0,dot:null},{ch:"u",kind:"keep",shared:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullA:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullB:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",out:[],in:[],x0:88.8,x1:88,dot:null},{ch:"o",kind:"keep",shared:"M38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullB:"M60.00 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50L60.00 91.50",out:[{d:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50",P:60.41,j:"both"}],in:[{d:"M38.00 46.50L60.00 46.50",P:22,j:"start"},{d:"M38.00 91.50L60.00 91.50",P:22,j:"start"}],x0:159,x1:158.2,dot:null},{ch:"l",kind:"fade",d:"M8.50 0.00L8.50 100.00",x0:230.8,x1:230.8,dot:null},{ch:"i",kind:"keep",shared:"M8.50 38.00L8.50 100.00",fullA:"M8.50 38.00L8.50 100.00",fullB:"M8.50 38.00L8.50 100.00",out:[],in:[],x0:262.8,x1:227.9,dot:[0,14,17]},{ch:"a",kind:"fade",d:"M38.00 91.50L51.50 91.50L51.50 78.00L51.50 60.00L51.50 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",x0:291.6,x1:291.6,dot:null},{ch:"n",kind:"fade",d:"M51.50 100.00L51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00L8.50 100.00",x0:362.7,x1:362.7,dot:null},{ch:"g",kind:"keep",shared:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M0.00 127.50L38.00 127.50A13.50 13.50 0 0 0 51.50 114.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00",fullB:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",out:[{d:"M51.50 60.00L51.50 114.00A13.50 13.50 0 0 1 38.00 127.50L0.00 127.50",P:113.21,j:"start"}],in:[],x0:432.9,x1:256.7,dot:null}],pad:17,vbw:526.9,vbh:170,stroke:17,raysT:"translate(0.000 22.727) scale(0.7727)"},e="M47.6 70.7L71.9 61.1L71.1 58.2L45.2 62.0ZM44.9 61.5L61.2 40.9L59.1 38.8L38.5 55.1ZM38.0 54.8L41.8 28.9L38.9 28.1L29.3 52.4Z",i="http://www.w3.org/2000/svg",s=(c,w)=>{let d=document.createElementNS(i,c);for(let u in w)d.setAttribute(u,w[u]);return d},n=()=>r.matchMedia&&r.matchMedia("(prefers-reduced-motion: reduce)").matches,o=c=>Math.max(0,Math.min(1,c)),a=c=>c*c*(3-2*c),l=.5;function h(c,w){let d=0,u=0,p=null,g=0;function A(y){let b=(y-g)/w;g=y,d=d<u?Math.min(u,d+b):Math.max(u,d-b),c(d),p=d===u?null:requestAnimationFrame(A)}function v(y){if(u=y,n()){d=y,c(d);return}p===null&&(g=performance.now(),p=requestAnimationFrame(A))}return{play:()=>v(1),reverse:()=>v(0),toggle:()=>v(u?0:1),set:y=>{cancelAnimationFrame(p),p=null,u=d=y,c(d)},stop:()=>{cancelAnimationFrame(p),p=null},get t(){return d}}}function m(c,w,d,u){let p=o(u)*w;if(c.style.visibility=p<.05?"hidden":"visible",d==="both"){let g=p/2;c.setAttribute("stroke-dasharray",g.toFixed(2)+" "+Math.max(0,w-2*g).toFixed(2)+" "+g.toFixed(2)),c.setAttribute("stroke-dashoffset","0")}else d==="end"?(c.setAttribute("stroke-dasharray",p.toFixed(2)+" "+(2*w+20).toFixed(2)),c.setAttribute("stroke-dashoffset",(-(w-p)).toFixed(2))):(c.setAttribute("stroke-dasharray",p.toFixed(2)+" "+(2*w+20).toFixed(2)),c.setAttribute("stroke-dashoffset","0"))}function M(c,w={}){let d=Object.assign({trigger:"hover",color:"currentColor",rays:"#FFF3CF",duration:450,autoDelay:1800},w),u=s("svg",{viewBox:"0 0 "+t.vbw+" "+t.vbh,role:"img","aria-label":"Guoliang Chen, Lucio"});u.style.display="block",u.style.width="100%",u.style.height="auto";let p=sLine truncated
|
||||
"use strict";(()=>{(function(r){let t={from:"Guoliang",to:"Lucio",letters:[{ch:"G",kind:"keep",shared:"M8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50",fullA:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",fullB:"M8.50 0.00L8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50L80.00 91.50",out:[{d:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00",P:79.21,j:"end"},{d:"M58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",P:73.21,j:"start"}],in:[{d:"M8.50 22.00L8.50 0.00",P:22,j:"start"},{d:"M58.00 91.50L80.00 91.50",P:22,j:"start"}],x0:0,x1:0,dot:null},{ch:"u",kind:"keep",shared:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullA:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullB:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",out:[],in:[],x0:88.8,x1:88,dot:null},{ch:"o",kind:"keep",shared:"M38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullB:"M60.00 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50L60.00 91.50",out:[{d:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50",P:60.41,j:"both"}],in:[{d:"M38.00 46.50L60.00 46.50",P:22,j:"start"},{d:"M38.00 91.50L60.00 91.50",P:22,j:"start"}],x0:159,x1:158.2,dot:null},{ch:"l",kind:"fade",d:"M8.50 0.00L8.50 100.00",x0:230.8,x1:230.8,dot:null},{ch:"i",kind:"keep",shared:"M8.50 38.00L8.50 100.00",fullA:"M8.50 38.00L8.50 100.00",fullB:"M8.50 38.00L8.50 100.00",out:[],in:[],x0:262.8,x1:227.9,dot:[0,14,17]},{ch:"a",kind:"fade",d:"M38.00 91.50L51.50 91.50L51.50 78.00L51.50 60.00L51.50 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",x0:291.6,x1:291.6,dot:null},{ch:"n",kind:"fade",d:"M51.50 100.00L51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00L8.50 100.00",x0:362.7,x1:362.7,dot:null},{ch:"g",kind:"keep",shared:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M0.00 127.50L38.00 127.50A13.50 13.50 0 0 0 51.50 114.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00",fullB:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",out:[{d:"M51.50 60.00L51.50 114.00A13.50 13.50 0 0 1 38.00 127.50L0.00 127.50",P:113.21,j:"start"}],in:[],x0:432.9,x1:256.7,dot:null}],pad:17,vbw:526.9,vbh:170,stroke:17,raysT:"translate(0.000 22.727) scale(0.7727)"},e="M47.6 70.7L71.9 61.1L71.1 58.2L45.2 62.0ZM44.9 61.5L61.2 40.9L59.1 38.8L38.5 55.1ZM38.0 54.8L41.8 28.9L38.9 28.1L29.3 52.4Z",i="http://www.w3.org/2000/svg",s=(d,x)=>{let c=document.createElementNS(i,d);for(let u in x)c.setAttribute(u,x[u]);return c},n=()=>r.matchMedia&&r.matchMedia("(prefers-reduced-motion: reduce)").matches,o=d=>Math.max(0,Math.min(1,d)),a=d=>d*d*(3-2*d),h=.5;function l(d,x){let c=0,u=0,f=null,g=0;function A(y){let b=(y-g)/x;g=y,c=c<u?Math.min(u,c+b):Math.max(u,c-b),d(c),f=c===u?null:requestAnimationFrame(A)}function v(y){if(u=y,n()){c=y,d(c);return}f===null&&(g=performance.now(),f=requestAnimationFrame(A))}return{play:()=>v(1),reverse:()=>v(0),toggle:()=>v(u?0:1),set:y=>{cancelAnimationFrame(f),f=null,u=c=y,d(c)},stop:()=>{cancelAnimationFrame(f),f=null},get t(){return c}}}function m(d,x,c,u){let f=o(u)*x;if(d.style.visibility=f<.05?"hidden":"visible",c==="both"){let g=f/2;d.setAttribute("stroke-dasharray",g.toFixed(2)+" "+Math.max(0,x-2*g).toFixed(2)+" "+g.toFixed(2)),d.setAttribute("stroke-dashoffset","0")}else c==="end"?(d.setAttribute("stroke-dasharray",f.toFixed(2)+" "+(2*x+20).toFixed(2)),d.setAttribute("stroke-dashoffset",(-(x-f)).toFixed(2))):(d.setAttribute("stroke-dasharray",f.toFixed(2)+" "+(2*x+20).toFixed(2)),d.setAttribute("stroke-dashoffset","0"))}function L(d,x={}){let c=Object.assign({trigger:"hover",color:"currentColor",rays:"#FFF3CF",duration:450,autoDelay:1800},x),u=s("svg",{viewBox:"0 0 "+t.vbw+" "+t.vbh,role:"img","aria-label":"Guoliang Chen, Lucio"});u.style.display="block",u.style.width="100%",u.style.height="auto";let f=sLine truncated
|
||||
@@ -12,7 +12,7 @@ cache = "/var/cache/luphoto"
|
||||
tile_size = 512
|
||||
overlap = 1
|
||||
format = "webp"
|
||||
quality = { top = 82, mid = 85, low = 88 }
|
||||
quality = { top = 90, mid = 88, low = 88 }
|
||||
min_levels = 6
|
||||
seed_px = 48
|
||||
tile_names = "hashed"
|
||||
|
||||
+284
-7
@@ -42,6 +42,10 @@ const flickSpeed = 0.35;
|
||||
const rubberBand = 0.35;
|
||||
const captionZone = 0.2;
|
||||
const idleMs = 2500;
|
||||
const zoomSettleMs = 120;
|
||||
const wheelLine = 16;
|
||||
const wheelRate = 0.002;
|
||||
const pinchWheelRate = 0.01;
|
||||
|
||||
function cubicBezier(x1: number, y1: number, x2: number, y2: number): (t: number) => number {
|
||||
const cx = 3 * x1;
|
||||
@@ -133,6 +137,24 @@ export class Viewer {
|
||||
private pinned = false;
|
||||
private resizeTimer = 0;
|
||||
private indexRequested = false;
|
||||
private ox = 0;
|
||||
private oy = 0;
|
||||
private secondId: number | null = null;
|
||||
private ax = 0;
|
||||
private ay = 0;
|
||||
private bx = 0;
|
||||
private by = 0;
|
||||
private pinching = false;
|
||||
private stale = false;
|
||||
private zoom = 1;
|
||||
private zoomMax = 1;
|
||||
private zoomPhoto = -1;
|
||||
private zx = 0;
|
||||
private zy = 0;
|
||||
private slackX = 0;
|
||||
private slackY = 0;
|
||||
private zoomTimer = 0;
|
||||
private gestureZoom = 1;
|
||||
|
||||
constructor(
|
||||
private readonly stage: HTMLElement,
|
||||
@@ -235,6 +257,8 @@ export class Viewer {
|
||||
const rect = this.stage.getBoundingClientRect();
|
||||
this.vw = Math.max(1, rect.width);
|
||||
this.vh = Math.max(1, rect.height);
|
||||
this.ox = rect.left;
|
||||
this.oy = rect.top;
|
||||
this.dpr = Math.min(window.devicePixelRatio || 1, this.settings.maxDpr);
|
||||
const cw = Math.max(1, Math.round(this.vw * this.dpr));
|
||||
const ch = Math.max(1, Math.round(this.vh * this.dpr));
|
||||
@@ -322,6 +346,13 @@ export class Viewer {
|
||||
this.updateCaption();
|
||||
}
|
||||
});
|
||||
stage.addEventListener("wheel", (e) => this.onWheel(e), { passive: false });
|
||||
stage.addEventListener("gesturestart", (e) => {
|
||||
e.preventDefault();
|
||||
this.gestureZoom = this.zoom;
|
||||
});
|
||||
stage.addEventListener("gesturechange", (e) => this.onGesture(e as Event & { scale?: number; clientX?: number; clientY?: number }));
|
||||
stage.addEventListener("gestureend", (e) => e.preventDefault());
|
||||
stage.addEventListener("dragstart", (e) => e.preventDefault());
|
||||
stage.addEventListener("selectstart", (e) => e.preventDefault());
|
||||
if (this.settings.blockContextMenu) {
|
||||
@@ -332,6 +363,9 @@ export class Viewer {
|
||||
const target = this.stopForHash();
|
||||
if (this.stops[target].photo !== this.stops[this.current].photo) {
|
||||
this.jump(target);
|
||||
} else if (this.clearZoom()) {
|
||||
this.startSession();
|
||||
this.updateCaption();
|
||||
}
|
||||
});
|
||||
new ResizeObserver(() => this.onResize()).observe(stage);
|
||||
@@ -349,6 +383,7 @@ export class Viewer {
|
||||
if (before === this.vw + "x" + this.vh + "@" + this.dpr) {
|
||||
return;
|
||||
}
|
||||
this.clearZoom();
|
||||
this.tween = null;
|
||||
this.camera = this.stops[this.current].camera;
|
||||
this.requestDraw();
|
||||
@@ -379,7 +414,11 @@ export class Viewer {
|
||||
this.go(this.stops.length - 2);
|
||||
break;
|
||||
case "Escape":
|
||||
location.assign("/");
|
||||
if (this.zoomPhoto >= 0) {
|
||||
this.go(this.current);
|
||||
} else {
|
||||
location.assign("/");
|
||||
}
|
||||
break;
|
||||
case "i":
|
||||
case "I":
|
||||
@@ -393,7 +432,24 @@ export class Viewer {
|
||||
}
|
||||
|
||||
private onPointerDown(e: PointerEvent): void {
|
||||
if (this.pointerId !== null || (e.pointerType === "mouse" && e.button !== 0)) {
|
||||
if (e.pointerType === "mouse" && e.button !== 0) {
|
||||
return;
|
||||
}
|
||||
if (this.pointerId !== null) {
|
||||
if (
|
||||
this.secondId === null &&
|
||||
e.pointerType !== "mouse" &&
|
||||
this.pointerType !== "mouse" &&
|
||||
!this.stale &&
|
||||
(this.zoomPhoto >= 0 || (!this.dragging && this.enterZoom()))
|
||||
) {
|
||||
this.secondId = e.pointerId;
|
||||
this.bx = e.clientX;
|
||||
this.by = e.clientY;
|
||||
this.pinching = true;
|
||||
this.dragging = true;
|
||||
this.stage.setPointerCapture(e.pointerId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ((e.target as Element).closest("a, button")) {
|
||||
@@ -402,8 +458,11 @@ export class Viewer {
|
||||
this.pointerId = e.pointerId;
|
||||
this.pointerType = e.pointerType;
|
||||
this.dragging = false;
|
||||
this.stale = false;
|
||||
this.downX = e.clientX;
|
||||
this.downY = e.clientY;
|
||||
this.ax = e.clientX;
|
||||
this.ay = e.clientY;
|
||||
this.downT = e.timeStamp;
|
||||
this.tween = null;
|
||||
this.downCamera = this.camera;
|
||||
@@ -422,7 +481,11 @@ export class Viewer {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (e.pointerId !== this.pointerId) {
|
||||
if (this.pinching && (e.pointerId === this.pointerId || e.pointerId === this.secondId)) {
|
||||
this.pinchMove(e.pointerId, e.clientX, e.clientY);
|
||||
return;
|
||||
}
|
||||
if (e.pointerId !== this.pointerId || this.stale) {
|
||||
return;
|
||||
}
|
||||
const dx = e.clientX - this.downX;
|
||||
@@ -433,6 +496,16 @@ export class Viewer {
|
||||
this.updateCaption();
|
||||
}
|
||||
if (!this.dragging) {
|
||||
this.ax = e.clientX;
|
||||
this.ay = e.clientY;
|
||||
return;
|
||||
}
|
||||
if (this.zoomPhoto >= 0) {
|
||||
this.zx += e.clientX - this.ax;
|
||||
this.zy += e.clientY - this.ay;
|
||||
this.ax = e.clientX;
|
||||
this.ay = e.clientY;
|
||||
this.settleZoom();
|
||||
return;
|
||||
}
|
||||
this.samples.push({ t: e.timeStamp, x: e.clientX });
|
||||
@@ -444,6 +517,10 @@ export class Viewer {
|
||||
}
|
||||
|
||||
private onPointerUp(e: PointerEvent, cancelled: boolean): void {
|
||||
if (this.pinching && (e.pointerId === this.pointerId || e.pointerId === this.secondId)) {
|
||||
this.endPinch(e.pointerId);
|
||||
return;
|
||||
}
|
||||
if (e.pointerId !== this.pointerId) {
|
||||
return;
|
||||
}
|
||||
@@ -454,12 +531,16 @@ export class Viewer {
|
||||
const wasDragging = this.dragging;
|
||||
this.dragging = false;
|
||||
this.stage.classList.remove("is-dragging");
|
||||
if (this.stale) {
|
||||
this.stale = false;
|
||||
return;
|
||||
}
|
||||
const moved = Math.hypot(e.clientX - this.downX, e.clientY - this.downY);
|
||||
if (!cancelled && !wasDragging && moved < tapDistance && e.timeStamp - this.downT < tapMs) {
|
||||
this.onTap(e);
|
||||
return;
|
||||
}
|
||||
if (!wasDragging) {
|
||||
if (!wasDragging || this.zoomPhoto >= 0) {
|
||||
return;
|
||||
}
|
||||
let velocity = 0;
|
||||
@@ -491,7 +572,7 @@ export class Viewer {
|
||||
|
||||
private onTap(e: PointerEvent): void {
|
||||
const stop = this.stops[this.current];
|
||||
if (stop.photo < 0) {
|
||||
if (stop.photo < 0 || this.zoomPhoto >= 0) {
|
||||
return;
|
||||
}
|
||||
const rect = this.photoRect(stop.photo);
|
||||
@@ -501,6 +582,178 @@ export class Viewer {
|
||||
}
|
||||
}
|
||||
|
||||
private onWheel(e: WheelEvent): void {
|
||||
e.preventDefault();
|
||||
if (this.pinching || (this.dragging && this.zoomPhoto < 0)) {
|
||||
return;
|
||||
}
|
||||
let delta = e.deltaY;
|
||||
if (e.deltaMode === 1) {
|
||||
delta *= wheelLine;
|
||||
} else if (e.deltaMode === 2) {
|
||||
delta *= this.vh;
|
||||
}
|
||||
if (delta === 0) {
|
||||
return;
|
||||
}
|
||||
const step = Math.max(-1, Math.min(1, delta * (e.ctrlKey ? pinchWheelRate : wheelRate)));
|
||||
const x = e.clientX - this.ox;
|
||||
const y = e.clientY - this.oy;
|
||||
this.zoomTo(this.zoom * Math.exp(-step), x, y, x, y);
|
||||
}
|
||||
|
||||
private onGesture(e: Event & { scale?: number; clientX?: number; clientY?: number }): void {
|
||||
e.preventDefault();
|
||||
if (this.pointerId !== null || !e.scale) {
|
||||
return;
|
||||
}
|
||||
const x = (e.clientX ?? this.ox + this.vw / 2) - this.ox;
|
||||
const y = (e.clientY ?? this.oy + this.vh / 2) - this.oy;
|
||||
this.zoomTo(this.gestureZoom * e.scale, x, y, x, y);
|
||||
}
|
||||
|
||||
private pinchMove(id: number, x: number, y: number): void {
|
||||
const px = (this.ax + this.bx) / 2 - this.ox;
|
||||
const py = (this.ay + this.by) / 2 - this.oy;
|
||||
const before = Math.hypot(this.ax - this.bx, this.ay - this.by);
|
||||
if (id === this.pointerId) {
|
||||
this.ax = x;
|
||||
this.ay = y;
|
||||
} else {
|
||||
this.bx = x;
|
||||
this.by = y;
|
||||
}
|
||||
const after = Math.hypot(this.ax - this.bx, this.ay - this.by);
|
||||
const target = before > 1 && after > 1 ? (this.zoom * after) / before : this.zoom;
|
||||
this.zoomTo(target, px, py, (this.ax + this.bx) / 2 - this.ox, (this.ay + this.by) / 2 - this.oy);
|
||||
}
|
||||
|
||||
private endPinch(id: number): void {
|
||||
if (this.stage.hasPointerCapture(id)) {
|
||||
this.stage.releasePointerCapture(id);
|
||||
}
|
||||
if (id === this.pointerId) {
|
||||
this.pointerId = this.secondId;
|
||||
this.ax = this.bx;
|
||||
this.ay = this.by;
|
||||
}
|
||||
this.secondId = null;
|
||||
this.pinching = false;
|
||||
this.dragging = true;
|
||||
if (this.zoomPhoto >= 0) {
|
||||
this.settleZoom();
|
||||
}
|
||||
}
|
||||
|
||||
private enterZoom(): boolean {
|
||||
const stop = this.stops[this.current];
|
||||
if (stop.photo < 0 || this.suspended) {
|
||||
return false;
|
||||
}
|
||||
const layout = this.layouts[stop.photo];
|
||||
const max = this.manifest.photos[stop.photo].width / (window.devicePixelRatio || 1) / layout.width;
|
||||
if (max <= 1.001) {
|
||||
return false;
|
||||
}
|
||||
this.tween = null;
|
||||
this.camera = stop.camera;
|
||||
this.zoomPhoto = stop.photo;
|
||||
this.zoomMax = max;
|
||||
this.zoom = 1;
|
||||
this.zx = layout.left - (this.camera - this.vw / 2);
|
||||
this.zy = layout.top;
|
||||
this.slackX = this.zx - this.clampAxis(this.zx, layout.width, this.vw, 0);
|
||||
this.slackY = this.zy - this.clampAxis(this.zy, layout.height, this.vh, 0);
|
||||
this.updateCaption();
|
||||
return true;
|
||||
}
|
||||
|
||||
private zoomTo(target: number, px: number, py: number, qx: number, qy: number): void {
|
||||
if (this.zoomPhoto < 0 && (target <= 1 || !this.enterZoom())) {
|
||||
return;
|
||||
}
|
||||
const zoom = Math.max(1, Math.min(this.zoomMax, target));
|
||||
const f = zoom / this.zoom;
|
||||
this.zx = qx - (px - this.zx) * f;
|
||||
this.zy = qy - (py - this.zy) * f;
|
||||
this.zoom = zoom;
|
||||
this.settleZoom();
|
||||
}
|
||||
|
||||
private settleZoom(): void {
|
||||
const layout = this.layouts[this.zoomPhoto];
|
||||
this.zx = this.clampAxis(this.zx, layout.width * this.zoom, this.vw, this.slackX);
|
||||
this.zy = this.clampAxis(this.zy, layout.height * this.zoom, this.vh, this.slackY);
|
||||
this.requestDraw();
|
||||
if (this.zoom <= 1 && !this.pinching) {
|
||||
this.camera = layout.left + this.vw / 2 - this.zx;
|
||||
this.go(this.nearestStop(this.camera));
|
||||
return;
|
||||
}
|
||||
clearTimeout(this.zoomTimer);
|
||||
this.zoomTimer = window.setTimeout(() => this.startZoomSession(), zoomSettleMs);
|
||||
}
|
||||
|
||||
private clampAxis(position: number, size: number, view: number, slack: number): number {
|
||||
const centre = (view - size) / 2;
|
||||
let lo = Math.min(view - size, centre);
|
||||
let hi = Math.max(0, centre);
|
||||
const extra = slack * Math.max(0, 2 - this.zoom);
|
||||
if (extra > 0) {
|
||||
hi += extra;
|
||||
} else {
|
||||
lo += extra;
|
||||
}
|
||||
return Math.min(hi, Math.max(lo, position));
|
||||
}
|
||||
|
||||
private clearZoom(): boolean {
|
||||
if (this.zoomPhoto < 0) {
|
||||
return false;
|
||||
}
|
||||
this.zoomPhoto = -1;
|
||||
this.zoom = 1;
|
||||
this.gestureZoom = 1;
|
||||
clearTimeout(this.zoomTimer);
|
||||
this.zoomTimer = 0;
|
||||
if (this.pointerId !== null) {
|
||||
this.stale = true;
|
||||
this.pinching = false;
|
||||
this.secondId = null;
|
||||
}
|
||||
this.requestDraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
private levelDpr(): number {
|
||||
if (this.zoomPhoto >= 0 && this.zoom >= this.zoomMax * 0.999) {
|
||||
return Math.max(this.dpr, window.devicePixelRatio || 1);
|
||||
}
|
||||
return this.dpr;
|
||||
}
|
||||
|
||||
private startZoomSession(): void {
|
||||
this.zoomTimer = 0;
|
||||
if (this.suspended || this.zoomPhoto < 0) {
|
||||
return;
|
||||
}
|
||||
const layout = this.layouts[this.zoomPhoto];
|
||||
const w = layout.width * this.zoom;
|
||||
const h = layout.height * this.zoom;
|
||||
const a = Math.max(0, this.zx);
|
||||
const b = Math.min(this.vw, this.zx + w);
|
||||
const c = Math.max(0, this.zy);
|
||||
const d = Math.min(this.vh, this.zy + h);
|
||||
if (b <= a || d <= c) {
|
||||
return;
|
||||
}
|
||||
this.loader(this.zoomPhoto).start(
|
||||
{ displayWidth: w, u0: (a - this.zx) / w, u1: (b - this.zx) / w, v0: (c - this.zy) / h, v1: (d - this.zy) / h },
|
||||
this.levelDpr(),
|
||||
() => undefined,
|
||||
);
|
||||
}
|
||||
|
||||
private rubber(camera: number): number {
|
||||
const min = this.stops[0].camera;
|
||||
const max = this.stops[this.stops.length - 1].camera;
|
||||
@@ -526,6 +779,7 @@ export class Viewer {
|
||||
private go(index: number): void {
|
||||
const target = Math.max(0, Math.min(this.stops.length - 1, index));
|
||||
const previous = this.current;
|
||||
const unzoomed = this.clearZoom();
|
||||
const to = this.stops[target].camera;
|
||||
if (this.reducedMotion.matches) {
|
||||
this.crossfade(() => {
|
||||
@@ -549,6 +803,9 @@ export class Viewer {
|
||||
if (target !== previous) {
|
||||
this.activate(previous);
|
||||
} else {
|
||||
if (unzoomed) {
|
||||
this.startSession();
|
||||
}
|
||||
this.updateCaption();
|
||||
}
|
||||
this.requestDraw();
|
||||
@@ -556,6 +813,7 @@ export class Viewer {
|
||||
|
||||
private jump(index: number): void {
|
||||
const previous = this.current;
|
||||
this.clearZoom();
|
||||
this.tween = null;
|
||||
this.crossfade(() => {
|
||||
this.current = index;
|
||||
@@ -661,6 +919,7 @@ export class Viewer {
|
||||
return;
|
||||
}
|
||||
this.suspended = false;
|
||||
this.clearZoom();
|
||||
this.canvas.width = 0;
|
||||
this.measure();
|
||||
this.camera = this.stops[this.current].camera;
|
||||
@@ -746,7 +1005,7 @@ export class Viewer {
|
||||
|
||||
private updateCaption(): void {
|
||||
const stop = this.stops[this.current];
|
||||
const visible = stop.photo >= 0 && !this.dragging && (this.pinned || this.hover);
|
||||
const visible = stop.photo >= 0 && this.zoomPhoto < 0 && !this.dragging && (this.pinned || this.hover);
|
||||
if (visible) {
|
||||
const rect = this.photoRect(stop.photo);
|
||||
this.caption.place(rect.left, rect.right - rect.left, this.vh - rect.bottom);
|
||||
@@ -835,7 +1094,25 @@ export class Viewer {
|
||||
const dpr = this.dpr;
|
||||
const near = this.stops[this.current].photo;
|
||||
const from = Math.max(0, (near < 0 ? this.layouts.length - 1 : near) - 2);
|
||||
const to = Math.min(this.layouts.length - 1, (near < 0 ? this.layouts.length - 1 : near) + 2);
|
||||
const to = this.zoomPhoto >= 0 ? -1 : Math.min(this.layouts.length - 1, (near < 0 ? this.layouts.length - 1 : near) + 2);
|
||||
if (this.zoomPhoto >= 0) {
|
||||
const layout = this.layouts[this.zoomPhoto];
|
||||
const w = layout.width * this.zoom;
|
||||
if (this.loader(this.zoomPhoto).draw({
|
||||
g,
|
||||
originX: this.zx * dpr,
|
||||
originY: this.zy * dpr,
|
||||
width: w * dpr,
|
||||
height: layout.height * this.zoom * dpr,
|
||||
canvasWidth: cw,
|
||||
canvasHeight: ch,
|
||||
displayWidth: w,
|
||||
dpr: this.levelDpr(),
|
||||
now,
|
||||
})) {
|
||||
again = true;
|
||||
}
|
||||
}
|
||||
for (let i = from; i <= to; i++) {
|
||||
const layout = this.layouts[i];
|
||||
if (layout.left + layout.width < left || layout.left > right) {
|
||||
|
||||
Reference in new issue
Block a user