M7: hardening and final pass
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
00ee2a6d12
commit
ae898a2787
30 files changed
+878
-107
No files matched your search
@@ -86,7 +86,7 @@ Unknown fields are errors, so typos are caught.
|
||||
| `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. |
|
||||
| `images.scramble_cells` | `false` | Reserved for M7. |
|
||||
| `images.scramble_cells` | `false` | Shuffle the 64 px cells inside each tile with a per-photo key; the browser restores them when it decodes a tile. Forces tile overlap 0. Changing it reprocesses everything. |
|
||||
| `loading.budget_ms` | `3000` | Time budget per photo in the browser. |
|
||||
| `loading.max_dpr` | `2.0` | Highest device pixel ratio the loader honours. |
|
||||
| `loading.concurrency` | `6` | Parallel tile requests. |
|
||||
@@ -134,7 +134,7 @@ rsync writes to dotted temp names and renames at the end, which the watcher igno
|
||||
|
||||
## Web server
|
||||
|
||||
- **Serve mode**: LuPhoto serves `current` itself with the right headers (immutable caching for `/t/`, `/og/`, `/assets/`; one minute for HTML and JSON; CSP; hotlink 403 on `/t/*`; precompressed gzip; no directory listings). Put Caddy (`packaging/Caddyfile.serve`), nginx (`packaging/nginx.serve.conf`) or a Cloudflare Tunnel in front.
|
||||
- **Serve mode**: LuPhoto serves `current` itself with the right headers (immutable caching for `/t/`, `/og/`, `/assets/`; one minute for HTML and JSON; CSP; hotlink 403 on `/t/*`; precompressed gzip; no directory listings; `404.html` for missing paths). Put Caddy (`packaging/Caddyfile.serve`), nginx (`packaging/nginx.serve.conf`) or a Cloudflare Tunnel in front.
|
||||
- **Export mode**: serve `/var/lib/luphoto/site/current` with `packaging/Caddyfile` or `packaging/nginx.conf`. Each build writes `.gz` files next to HTML, JSON, JS, CSS and SVG for `precompressed gzip` / `gzip_static`.
|
||||
- **Cloudflare**: `packaging/cloudflared.yml` and `packaging/cloudflare.md` (cache rules).
|
||||
|
||||
@@ -173,7 +173,7 @@ This type-checks with `tsc --noEmit` (strict) and bundles with esbuild. Fonts ar
|
||||
/var/lib/luphoto/
|
||||
site/
|
||||
current -> builds/<id>
|
||||
builds/<id>/index.html, index.<id>.json, a/<slug>/index.html, a/<slug>/manifest.<id>.json, assets/, t -> ../../t, og -> ../../og
|
||||
builds/<id>/index.html, 404.html, index.<id>.json, a/<slug>/index.html, a/<slug>/manifest.<id>.json, assets/, t -> ../../t, og -> ../../og (plus .gz copies)
|
||||
t/<photo-hash>/<tile-id>.webp
|
||||
og/<hash>.jpg
|
||||
state/
|
||||
|
||||
+7
-7
@@ -11,7 +11,7 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
|
||||
-> serve mode (built-in HTTP) or export mode (folder for Caddy/nginx) -> Cloudflare Tunnel + cache -> browser canvas stitches visible tiles
|
||||
```
|
||||
|
||||
- Commands: `luphoto build` runs once; `luphoto serve` builds, watches and serves; `luphoto export` builds into the output folder and keeps watching. `-config` flag, default `/etc/luphoto/config.toml`.
|
||||
- Commands: `luphoto build` runs once; `luphoto serve` builds, watches and serves; `luphoto export` builds into the output folder and keeps watching; `luphoto run` does `serve` or `export` as `server.mode` says (the systemd unit uses it); `luphoto version`. `-config` flag, default `/etc/luphoto/config.toml`. Rebuilds never overlap: changes during a build cause one follow-up build.
|
||||
- Tiling with libvips CLI (`vips`), installed by `apt install libvips-tools`. Support libvips 8.12 (Ubuntu 22.04) and 8.15 (Ubuntu 24.04): metadata stripping is `strip` on 8.12 and `keep=none` on 8.15+.
|
||||
- Front-end: plain TypeScript, no framework, bundled with esbuild, embedded in the binary with `go:embed`. Fixed Lucio brand.
|
||||
- Speed and memory matter: photos are processed in parallel by a bounded worker pool; hashing, EXIF reading and tile renaming run concurrently; the browser fetches tiles concurrently and decodes off the main thread.
|
||||
@@ -47,7 +47,7 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
|
||||
- `cover.crop` is `[x, y, w, h]` in original pixels; or `cover.focus_y` (0–1) picks a 32:9 band at full width. Default: first photo, focus_y 0.5.
|
||||
- `order` sorts ascending; albums without it sort newest `date` first, after ordered ones. `hidden: true` builds the album but leaves it off the index.
|
||||
- Album slug = folder name. Captions are plain text with `*emphasis*` and line breaks only.
|
||||
- A broken album.json makes the build skip that album and log why; the previous build stays live.
|
||||
- A broken album.json makes the build skip that album and log why; the previous build's version of that album stays live (it is carried into the new build).
|
||||
|
||||
## Processing each photo
|
||||
|
||||
@@ -60,7 +60,7 @@ uploads (rsync/SFTP) -> /srv/luphoto/albums -> watcher (debounce) -> processor (
|
||||
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.
|
||||
8. Album manifest `/a/<slug>/manifest.<build>.json`: per photo width, height, level sizes, tile grid per level, tile ids in row-major order per level, byte size of every tile, caption, title, alt, EXIF, slides, seed. Covers are pyramids too and are described in `/index.<build>.json`.
|
||||
|
||||
Incremental: a photo is reprocessed only when its photo-hash is new. Each build writes `builds/<id>/` (HTML, manifests, assets) next to a shared `t/` tile folder; the `current` symlink flips only when the build is complete. Keep the last `keep_builds` builds; delete tile folders no kept build references. Write everything to temporary names and rename, so readers never see partial files.
|
||||
Incremental: a photo is reprocessed only when its photo-hash is new. Each build writes `builds/<id>/` (HTML, manifests, assets, `404.html`, and a `.gz` copy of every HTML, JSON, JS, CSS and SVG file for precompressed serving) next to a shared `t/` tile folder and a shared `og/` folder of 1200×630 Open Graph JPEGs cut around each album cover (the only non-tiled images; derived, small, metadata stripped); the `current` symlink flips only when the build is complete. Keep the last `keep_builds` builds; delete tile folders no kept build references. Write everything to temporary names and rename, so readers never see partial files.
|
||||
|
||||
Storage: about 1.33× the top level, roughly 6–10 MB of tiles per Z8 photo.
|
||||
|
||||
@@ -77,7 +77,7 @@ Moving to another photo aborts that photo's requests. Prefetch the next photo's
|
||||
|
||||
## Screens
|
||||
|
||||
Album index: full-width strips, 8 px apart on phones, 16 px on desktop. Header with the Lucio wordmark (Guoliang → Lucio morph on hover, the only animation on this screen); footer with the chop. Closed strip 32:6 showing the `collapsed_focus_y` band of the 32:9 cover, height `min(100vw*6/32, 28vh)`; open 32:9, height `min(100vw*9/32, 62vh)`; wider screens crop left/right, never stretch. Desktop: hover opens. Touch: the strip nearest the vertical centre opens while scrolling; tap enters. On open the height animates 240 ms, then the title fades in (light-on): mono date line, then the title in Bricolage Grotesque, bottom-left. Covers use the tile loader; closed strips load only the visible band; only strips near the viewport load.
|
||||
Album index: full-width strips, 8 px apart on phones, 16 px on desktop. Header with the Lucio wordmark (Guoliang → Lucio morph on hover, the only animation on this screen); footer with the chop. Closed strip 32:6 showing the `collapsed_focus_y` band of the 32:9 cover, height `min(100vw*6/32, 28vh)`; open 32:9, height `min(100vw*9/32, 62vh)`; the cover is drawn cover-fit, never stretched (under the height caps a very wide screen crops top and bottom). Desktop: hover opens. Touch: the strip nearest the vertical centre opens while scrolling; tap enters. On open the height animates 240 ms, then the title fades in (light-on): mono date line, then the title in Bricolage Grotesque, bottom-left. Covers use the tile loader; closed strips load only the visible band; only strips near the viewport load.
|
||||
|
||||
Album viewer: one photo at a time, contained in the viewport (fills height or width, never stretched), centred on graphite. Swipe right-to-left, ←/→, click-and-drag; one pointer-events handler for mouse and touch with flick velocity and rubber-band ends; Home/End; Esc returns to the index. `slides: N`: the photo is scaled so a 1/N-wide section fits the viewport; moving between its slides is a continuous pan. `/a/<slug>/#7` opens photo 7. End card: chop, "— Lucio", the next album's strip. Reduced motion: crossfades.
|
||||
|
||||
@@ -87,7 +87,7 @@ Lucio brand (source of truth: ../LUCIO_ip): graphite #111114 ground, paper #F3F1
|
||||
|
||||
## Discouraging saves
|
||||
|
||||
No `<img>` for photos, only canvas. Output never contains an original. Right-click, drag, selection and long-press callouts are disabled. Hashed tile names (above). Optional `scramble_cells` (off): shuffle 64 px cells inside each tile with a per-photo key and reorder when drawing. Hotlink: Referer check on `/t/*` in the built-in server and the Caddy/nginx examples.
|
||||
No `<img>` for photos, only canvas. Output never contains an original. Right-click, drag, selection and long-press callouts are disabled. Hashed tile names (above). Optional `scramble_cells` (off): shuffle the full 64 px cells inside each tile with a per-photo key (HMAC of the site key and photo-hash, then a seeded Fisher–Yates per tile; tile overlap is 0 when on); the client restores each tile once when it decodes it, before it is cached and drawn. Hotlink: Referer check on `/t/*` in the built-in server and the Caddy/nginx examples; an empty Referer and the site's own host are allowed.
|
||||
|
||||
## Config `/etc/luphoto/config.toml`
|
||||
|
||||
@@ -128,14 +128,14 @@ block_context_menu = true
|
||||
hotlink_allow = ["photos.luciochen.com"]
|
||||
```
|
||||
|
||||
Defaults when a path is missing: running as root or under systemd uses `/var/lib/luphoto/site` and `/var/cache/luphoto`; otherwise `$XDG_DATA_HOME/luphoto/site` and `$XDG_CACHE_HOME/luphoto` (Go `os.UserCacheDir` equivalents). The site key lives in the state folder next to the output. SIGHUP re-reads the config and rebuilds. The watcher ignores `.part`, `.tmp`, dotfiles and rsync temp names.
|
||||
Defaults when a path is missing: running as root or under systemd uses `/var/lib/luphoto/site` and `/var/cache/luphoto`; otherwise `$XDG_DATA_HOME/luphoto/site` and `$XDG_CACHE_HOME/luphoto` (Go `os.UserCacheDir` equivalents). The site key and the per-photo processing records live in the state folder (`state/`) next to the output. SIGHUP re-reads the config and rebuilds. The watcher ignores `.part`, `.tmp`, dotfiles and rsync temp names.
|
||||
|
||||
## Deployment
|
||||
|
||||
- `.deb` via nfpm: binary, `/etc/luphoto/config.toml`, systemd unit, `luphoto` user, `/srv/luphoto/albums`. Depends on `libvips-tools`. Ubuntu 22.04/24.04, Debian 12; other distros: tarball + unit file.
|
||||
- systemd: read-only albums, read-write output and cache only, NoNewPrivileges, ProtectSystem=strict.
|
||||
- Cloudflare Tunnel; cache rule `/t/*` for a month; HTML and manifests short TTL; manifests are build-named, so no purging.
|
||||
- Caddy (export): root `/var/lib/luphoto/site/current`, `/t/*` `public, max-age=31536000, immutable`, `/a/*` `max-age=60`, CSP `default-src 'self'; img-src 'self' blob: data:; frame-ancestors 'none'`, hotlink 403 on `/t/*`. Serve mode: `reverse_proxy 127.0.0.1:8080`, the built-in server sends the same headers. nginx equivalent provided.
|
||||
- Caddy (export): root `/var/lib/luphoto/site/current`, `/t/*` `public, max-age=31536000, immutable`, `/a/*` `max-age=60`, `/og/*` and `/assets/*` immutable too, HTML and index JSON `max-age=60`, CSP `default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'`, `nosniff`, `Referrer-Policy: strict-origin-when-cross-origin`, hotlink 403 on `/t/*`, precompressed gzip, no directory listings, `404.html` for missing paths, GET/HEAD only. Serve mode: `reverse_proxy 127.0.0.1:8080`, the built-in server sends the same headers. nginx equivalent provided.
|
||||
|
||||
## Milestones
|
||||
|
||||
|
||||
+20
-2
@@ -337,13 +337,25 @@ func coverCrop(c *album.Cover, width, height int) ([4]int, error) {
|
||||
return [4]int{x, y, max(1, w), max(1, h)}, nil
|
||||
}
|
||||
|
||||
func (b *builder) overlap() int {
|
||||
if b.cfg.Images.ScrambleCells {
|
||||
return 0
|
||||
}
|
||||
return b.cfg.Images.Overlap
|
||||
}
|
||||
|
||||
func (b *builder) tiles() site.Tiles {
|
||||
return site.Tiles{
|
||||
tiles := site.Tiles{
|
||||
Format: b.cfg.Images.Format,
|
||||
TileSize: b.cfg.Images.TileSize,
|
||||
Overlap: b.cfg.Images.Overlap,
|
||||
Overlap: b.overlap(),
|
||||
Path: "/t/",
|
||||
}
|
||||
if b.cfg.Images.ScrambleCells {
|
||||
tiles.Scrambled = true
|
||||
tiles.Cell = process.ScrambleCell
|
||||
}
|
||||
return tiles
|
||||
}
|
||||
|
||||
func (b *builder) manifest(id string, plan *albumPlan, records map[string]*process.Record) *site.Manifest {
|
||||
@@ -507,6 +519,12 @@ func (b *builder) writeBuild(id string, manifests []*site.Manifest) error {
|
||||
if err == nil {
|
||||
err = fsutil.WritePublicAtomic(filepath.Join(stage, "index.html"), html)
|
||||
}
|
||||
if err == nil {
|
||||
html, err = fsutil.Render(func(w io.Writer) error { return site.RenderNotFound(w, id, page) })
|
||||
}
|
||||
if err == nil {
|
||||
err = fsutil.WritePublicAtomic(filepath.Join(stage, "404.html"), html)
|
||||
}
|
||||
errs[len(manifests)] = err
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
@@ -34,11 +34,12 @@ type Level struct {
|
||||
}
|
||||
|
||||
type Pyramid struct {
|
||||
Hash string `json:"hash"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Levels []Level `json:"levels"`
|
||||
Seed string `json:"seed"`
|
||||
Hash string `json:"hash"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Levels []Level `json:"levels"`
|
||||
Seed string `json:"seed"`
|
||||
Scramble string `json:"scramble,omitempty"`
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
|
||||
@@ -22,6 +22,13 @@ import (
|
||||
|
||||
const minLongEdge = 100
|
||||
|
||||
func (p *Processor) Overlap() int {
|
||||
if p.images.ScrambleCells {
|
||||
return 0
|
||||
}
|
||||
return p.images.Overlap
|
||||
}
|
||||
|
||||
func LevelSizes(width, height, minLevels int) [][2]int {
|
||||
sizes := [][2]int{{width, height}}
|
||||
for {
|
||||
@@ -155,6 +162,10 @@ func (p *Processor) process(ctx context.Context, job *Job) (*Record, error) {
|
||||
}
|
||||
}
|
||||
|
||||
scrambleSeed := ""
|
||||
if p.images.ScrambleCells {
|
||||
scrambleSeed = p.ScrambleSeed(job.Hash)
|
||||
}
|
||||
levels := make([]Level, count)
|
||||
var seed string
|
||||
var firstErr error
|
||||
@@ -188,7 +199,17 @@ func (p *Processor) process(ctx context.Context, job *Job) (*Record, error) {
|
||||
go func(i int, src *refFile) {
|
||||
defer wg.Done()
|
||||
defer src.release()
|
||||
level, err := p.cutLevel(ctx, job.Hash, src.path, stage, i, count, sizes[i])
|
||||
input := src.path
|
||||
if p.images.ScrambleCells {
|
||||
scrambled := filepath.Join(work, "s"+strconv.Itoa(i)+".v")
|
||||
if err := ScrambleV(src.path, scrambled, scrambleSeed, i, p.images.TileSize, ScrambleCell); err != nil {
|
||||
fail(fmt.Errorf("scramble level %d: %w", i, err))
|
||||
return
|
||||
}
|
||||
defer os.Remove(scrambled)
|
||||
input = scrambled
|
||||
}
|
||||
level, err := p.cutLevel(ctx, job.Hash, input, stage, i, count, sizes[i])
|
||||
if err != nil {
|
||||
fail(fmt.Errorf("level %d: %w", i, err))
|
||||
return
|
||||
@@ -236,11 +257,11 @@ func (p *Processor) process(ctx context.Context, job *Job) (*Record, error) {
|
||||
committed = true
|
||||
|
||||
rec := &Record{
|
||||
Pyramid: Pyramid{Hash: job.Hash, Width: width, Height: height, Levels: levels, Seed: seed},
|
||||
Pyramid: Pyramid{Hash: job.Hash, Width: width, Height: height, Levels: levels, Seed: seed, Scramble: scrambleSeed},
|
||||
Kind: job.Kind,
|
||||
Format: p.images.Format,
|
||||
TileSize: p.images.TileSize,
|
||||
Overlap: p.images.Overlap,
|
||||
Overlap: p.Overlap(),
|
||||
Processed: time.Now().UTC().Truncate(time.Second),
|
||||
}
|
||||
if job.Kind == "photo" {
|
||||
@@ -351,7 +372,7 @@ func (p *Processor) cutLevel(ctx context.Context, hash, src, stage string, level
|
||||
"--layout", "dz",
|
||||
"--depth", "one",
|
||||
"--tile-size", strconv.Itoa(p.images.TileSize),
|
||||
"--overlap", strconv.Itoa(p.images.Overlap),
|
||||
"--overlap", strconv.Itoa(p.Overlap()),
|
||||
"--suffix", ext+p.vips.SaveOptions(quality)); err != nil {
|
||||
return Level{}, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
package process
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
ScrambleCell = 64
|
||||
scrambleWorkers = 2
|
||||
vipsHeaderSize = 64
|
||||
)
|
||||
|
||||
var bandFormatSize = map[int32]int{0: 1, 1: 1, 2: 2, 3: 2, 4: 4, 5: 4, 6: 4, 7: 8, 8: 8, 9: 16}
|
||||
|
||||
func (p *Processor) ScrambleSeed(hash string) string {
|
||||
mac := hmac.New(sha256.New, p.key)
|
||||
mac.Write([]byte("scramble|" + hash))
|
||||
return hex.EncodeToString(mac.Sum(nil))[:16]
|
||||
}
|
||||
|
||||
func tileSeed(seed string, level, x, y int) uint32 {
|
||||
h := uint32(2166136261)
|
||||
for _, c := range []byte(seed + "|" + strconv.Itoa(level) + "|" + strconv.Itoa(x) + "|" + strconv.Itoa(y)) {
|
||||
h ^= uint32(c)
|
||||
h *= 16777619
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
type mulberry32 struct {
|
||||
state uint32
|
||||
}
|
||||
|
||||
func (m *mulberry32) next() float64 {
|
||||
m.state += 0x6D2B79F5
|
||||
a := m.state
|
||||
t := (a ^ (a >> 15)) * (a | 1)
|
||||
t = (t + (t^(t>>7))*(t|61)) ^ t
|
||||
return float64(t^(t>>14)) / 4294967296
|
||||
}
|
||||
|
||||
func CellPermutation(n int, seed uint32) []int {
|
||||
perm := make([]int, n)
|
||||
for i := range perm {
|
||||
perm[i] = i
|
||||
}
|
||||
rng := mulberry32{state: seed}
|
||||
for i := n - 1; i > 0; i-- {
|
||||
j := int(rng.next() * float64(i+1))
|
||||
perm[i], perm[j] = perm[j], perm[i]
|
||||
}
|
||||
return perm
|
||||
}
|
||||
|
||||
type vHeader struct {
|
||||
width, height int
|
||||
pixelBytes int
|
||||
}
|
||||
|
||||
func readVHeader(f *os.File) (vHeader, error) {
|
||||
var raw [vipsHeaderSize]byte
|
||||
if _, err := io.ReadFull(io.NewSectionReader(f, 0, vipsHeaderSize), raw[:]); err != nil {
|
||||
return vHeader{}, err
|
||||
}
|
||||
var order binary.ByteOrder
|
||||
switch {
|
||||
case raw[0] == vipsMagicIntel[0] && raw[1] == vipsMagicIntel[1] && raw[2] == vipsMagicIntel[2] && raw[3] == vipsMagicIntel[3]:
|
||||
order = binary.LittleEndian
|
||||
case raw[0] == vipsMagicSparc[0] && raw[1] == vipsMagicSparc[1] && raw[2] == vipsMagicSparc[2] && raw[3] == vipsMagicSparc[3]:
|
||||
order = binary.BigEndian
|
||||
default:
|
||||
return vHeader{}, errors.New("not a vips image")
|
||||
}
|
||||
width := int(int32(order.Uint32(raw[4:8])))
|
||||
height := int(int32(order.Uint32(raw[8:12])))
|
||||
bands := int(int32(order.Uint32(raw[12:16])))
|
||||
format := int32(order.Uint32(raw[20:24]))
|
||||
coding := int32(order.Uint32(raw[24:28]))
|
||||
size, ok := bandFormatSize[format]
|
||||
if !ok || coding != 0 || width <= 0 || height <= 0 || bands <= 0 {
|
||||
return vHeader{}, fmt.Errorf("unsupported vips image (format %d, coding %d)", format, coding)
|
||||
}
|
||||
return vHeader{width: width, height: height, pixelBytes: bands * size}, nil
|
||||
}
|
||||
|
||||
func ScrambleV(src, dst, seed string, level, tileSize, cell int) error {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
header, err := readVHeader(in)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", src, err)
|
||||
}
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ok := false
|
||||
defer func() {
|
||||
out.Close()
|
||||
if !ok {
|
||||
os.Remove(dst)
|
||||
}
|
||||
}()
|
||||
if _, err := io.Copy(out, io.NewSectionReader(in, 0, vipsHeaderSize)); err != nil {
|
||||
return err
|
||||
}
|
||||
rowBytes := int64(header.width) * int64(header.pixelBytes)
|
||||
dataEnd := vipsHeaderSize + rowBytes*int64(header.height)
|
||||
bands := (header.height + tileSize - 1) / tileSize
|
||||
jobs := make(chan int)
|
||||
errs := make([]error, scrambleWorkers)
|
||||
var wg sync.WaitGroup
|
||||
for w := 0; w < min(scrambleWorkers, bands); w++ {
|
||||
wg.Add(1)
|
||||
go func(w int) {
|
||||
defer wg.Done()
|
||||
buf := make([]byte, int64(min(tileSize, header.height))*rowBytes)
|
||||
tmp := make([]byte, cell*cell*header.pixelBytes)
|
||||
for band := range jobs {
|
||||
if errs[w] != nil {
|
||||
continue
|
||||
}
|
||||
errs[w] = scrambleBand(in, out, buf, tmp, header, band, rowBytes, seed, level, tileSize, cell)
|
||||
}
|
||||
}(w)
|
||||
}
|
||||
for band := 0; band < bands; band++ {
|
||||
jobs <- band
|
||||
}
|
||||
close(jobs)
|
||||
wg.Wait()
|
||||
if err := errors.Join(errs...); err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := in.Stat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.Size() > dataEnd {
|
||||
if _, err := io.Copy(io.NewOffsetWriter(out, dataEnd), io.NewSectionReader(in, dataEnd, info.Size()-dataEnd)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
ok = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func scrambleBand(in, out *os.File, buf, tmp []byte, header vHeader, band int, rowBytes int64, seed string, level, tileSize, cell int) error {
|
||||
top := band * tileSize
|
||||
rows := min(tileSize, header.height-top)
|
||||
data := buf[:int64(rows)*rowBytes]
|
||||
offset := vipsHeaderSize + int64(top)*rowBytes
|
||||
if _, err := in.ReadAt(data, offset); err != nil {
|
||||
return err
|
||||
}
|
||||
cellRows := rows / cell
|
||||
cellBytes := cell * header.pixelBytes
|
||||
tiles := (header.width + tileSize - 1) / tileSize
|
||||
for tx := 0; tx < tiles; tx++ {
|
||||
width := min(tileSize, header.width-tx*tileSize)
|
||||
cols := width / cell
|
||||
n := cols * cellRows
|
||||
if n < 2 {
|
||||
continue
|
||||
}
|
||||
perm := CellPermutation(n, tileSeed(seed, level, tx, band))
|
||||
origin := tx * tileSize * header.pixelBytes
|
||||
at := func(index, row int) []byte {
|
||||
cy, cx := index/cols, index%cols
|
||||
start := int64(cy*cell+row)*rowBytes + int64(origin+cx*cellBytes)
|
||||
return data[start : start+int64(cellBytes)]
|
||||
}
|
||||
done := make([]bool, n)
|
||||
for start := 0; start < n; start++ {
|
||||
if done[start] || perm[start] == start {
|
||||
done[start] = true
|
||||
continue
|
||||
}
|
||||
for r := 0; r < cell; r++ {
|
||||
copy(tmp[r*cellBytes:(r+1)*cellBytes], at(start, r))
|
||||
}
|
||||
i := start
|
||||
for {
|
||||
done[i] = true
|
||||
j := perm[i]
|
||||
if j == start {
|
||||
for r := 0; r < cell; r++ {
|
||||
copy(at(i, r), tmp[r*cellBytes:(r+1)*cellBytes])
|
||||
}
|
||||
break
|
||||
}
|
||||
for r := 0; r < cell; r++ {
|
||||
copy(at(i, r), at(j, r))
|
||||
}
|
||||
i = j
|
||||
}
|
||||
}
|
||||
}
|
||||
_, err := out.WriteAt(data, offset)
|
||||
return err
|
||||
}
|
||||
@@ -79,10 +79,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
settings := h.settings.Load()
|
||||
clean := path.Clean("/" + r.URL.Path)
|
||||
if !visible(clean) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if strings.HasPrefix(clean, "/t/") && hotlinked(r, settings.HotlinkAllow) {
|
||||
http.Error(w, "forbidden", http.StatusForbidden)
|
||||
return
|
||||
@@ -92,17 +88,21 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "no build published yet", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
if !visible(clean) {
|
||||
notFound(w, r, root)
|
||||
return
|
||||
}
|
||||
name := filepath.Join(root, filepath.FromSlash(clean))
|
||||
info, err := os.Stat(name)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
notFound(w, r, root)
|
||||
return
|
||||
}
|
||||
if info.IsDir() {
|
||||
index := filepath.Join(name, "index.html")
|
||||
indexInfo, err := os.Stat(index)
|
||||
if err != nil || !indexInfo.Mode().IsRegular() {
|
||||
http.NotFound(w, r)
|
||||
notFound(w, r, root)
|
||||
return
|
||||
}
|
||||
if !strings.HasSuffix(r.URL.Path, "/") {
|
||||
@@ -119,12 +119,28 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
name, info, clean = index, indexInfo, path.Join(clean, "index.html")
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
http.NotFound(w, r)
|
||||
notFound(w, r, root)
|
||||
return
|
||||
}
|
||||
serveFile(w, r, clean, name, info)
|
||||
}
|
||||
|
||||
func notFound(w http.ResponseWriter, r *http.Request, root string) {
|
||||
page, err := os.ReadFile(filepath.Join(root, "404.html"))
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
header := w.Header()
|
||||
header.Set("Content-Type", contentTypes[".html"])
|
||||
header.Set("Cache-Control", cacheShort)
|
||||
header.Set("Content-Length", strconv.Itoa(len(page)))
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
if r.Method != http.MethodHead {
|
||||
_, _ = w.Write(page)
|
||||
}
|
||||
}
|
||||
|
||||
func visible(clean string) bool {
|
||||
for _, part := range strings.Split(clean, "/") {
|
||||
if strings.HasPrefix(part, ".") {
|
||||
|
||||
+28
-5
@@ -6,6 +6,7 @@ import (
|
||||
"html/template"
|
||||
"io"
|
||||
"net/url"
|
||||
"unicode"
|
||||
|
||||
"github.com/luciochen233/luphoto/internal/process"
|
||||
)
|
||||
@@ -13,7 +14,16 @@ import (
|
||||
//go:embed templates/*.html
|
||||
var templateFiles embed.FS
|
||||
|
||||
var templates = template.Must(template.ParseFS(templateFiles, "templates/*.html"))
|
||||
var templates = template.Must(template.New("site").Funcs(template.FuncMap{"lang": Lang}).ParseFS(templateFiles, "templates/*.html"))
|
||||
|
||||
func Lang(text string) string {
|
||||
for _, r := range text {
|
||||
if unicode.Is(unicode.Han, r) {
|
||||
return "zh"
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
const (
|
||||
SiteName = "Photos · Lucio"
|
||||
@@ -21,10 +31,12 @@ const (
|
||||
)
|
||||
|
||||
type Tiles struct {
|
||||
Format string `json:"format"`
|
||||
TileSize int `json:"tile_size"`
|
||||
Overlap int `json:"overlap"`
|
||||
Path string `json:"path"`
|
||||
Format string `json:"format"`
|
||||
TileSize int `json:"tile_size"`
|
||||
Overlap int `json:"overlap"`
|
||||
Path string `json:"path"`
|
||||
Scrambled bool `json:"scrambled,omitempty"`
|
||||
Cell int `json:"cell,omitempty"`
|
||||
}
|
||||
|
||||
type Photo struct {
|
||||
@@ -184,3 +196,14 @@ func RenderAlbum(w io.Writer, m *Manifest, page Page) error {
|
||||
ManifestURL: ManifestURL(m.Build, m.Slug),
|
||||
})
|
||||
}
|
||||
|
||||
func RenderNotFound(w io.Writer, build string, page Page) error {
|
||||
return templates.ExecuteTemplate(w, "404.html", head{
|
||||
Page: page,
|
||||
Build: build,
|
||||
Title: "Not found · Lucio",
|
||||
Description: SiteDescription,
|
||||
Path: "/404.html",
|
||||
IndexURL: IndexURL(build),
|
||||
})
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
:root{--lucio-graphite: #111114;--lucio-graphite-2: #1A1A1F;--lucio-graphite-3: #26262D;--lucio-paper: #F3F1EC;--lucio-paper-2: #E9E6DF;--lucio-paper-3: #D9D6CD;--lucio-beam: #FFF3CF;--lucio-beam-deep: #5E5238;--lucio-beam-glow: #FFFBF0;--lucio-steel: #8A94A6;--lucio-steel-deep: #3F4B60;--lucio-cinnabar: #C3361F;--lucio-cinnabar-light: #F08A77;--lucio-ash: #666A74;--lucio-ash-dark: #43464F;--lucio-ash-light: #A6A9B3;--lucio-font-display: "Bricolage Grotesque", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;--lucio-font-body: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;--lucio-font-mono: "IBM Plex Mono", "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;--lucio-font-cjk-display: "Noto Serif SC", "Songti SC", "SimSun", serif;--lucio-font-cjk-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;--lucio-space-1: 4px;--lucio-space-2: 8px;--lucio-space-3: 12px;--lucio-space-4: 16px;--lucio-space-5: 24px;--lucio-space-6: 32px;--lucio-space-7: 48px;--lucio-space-8: 64px;--lucio-space-9: 96px;--lucio-space-10: 128px;--lucio-radius-none: 0px;--lucio-radius-sm: 4px;--lucio-radius-md: 8px;--lucio-radius-lg: 16px;--lucio-radius-icon: 22%;--lucio-shadow-glow: 0 0 0 1px rgba(255,243,207,.3), 0 8px 32px -8px rgba(255,243,207,.35);--lucio-motion-fast: .12s;--lucio-ease-fast: cubic-bezier(.2, 0, 0, 1);--lucio-motion-base: .24s;--lucio-ease-base: cubic-bezier(.2, 0, 0, 1);--lucio-motion-glow: .9s;--lucio-ease-glow: cubic-bezier(.16, 1, .3, 1)}@font-face{font-family:Bricolage Grotesque;font-style:normal;font-weight:200 800;font-display:swap;src:url("./bricolage-grotesque-latin-ext-wght-normal.EMW626ZA.woff2") format("woff2-variations");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:Bricolage Grotesque;font-style:normal;font-weight:200 800;font-display:swap;src:url("./bricolage-grotesque-latin-wght-normal.HY2A4V5R.woff2") format("woff2-variations");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-ext-400-normal.EDOVP6TU.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-400-normal.COQVXTP6.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:500;font-display:swap;src:url("./ibm-plex-sans-latin-ext-500-normal.SG2XNXKB.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:500;font-display:swap;src:url("./ibm-plex-sans-latin-500-normal.JTONHBWS.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:600;font-display:swap;src:url("./ibm-plex-sans-latin-ext-600-normal.ZNWKNRXL.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:600;font-display:swap;src:url("./ibm-plex-sans-latin-600-normal.DTNZULF4.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:italic;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-ext-400-italic.VMPJJ47P.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:italic;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-400-italic.PR7YQ55B.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,Line truncated
|
||||
:root{--lucio-graphite: #111114;--lucio-graphite-2: #1A1A1F;--lucio-graphite-3: #26262D;--lucio-paper: #F3F1EC;--lucio-paper-2: #E9E6DF;--lucio-paper-3: #D9D6CD;--lucio-beam: #FFF3CF;--lucio-beam-deep: #5E5238;--lucio-beam-glow: #FFFBF0;--lucio-steel: #8A94A6;--lucio-steel-deep: #3F4B60;--lucio-cinnabar: #C3361F;--lucio-cinnabar-light: #F08A77;--lucio-ash: #666A74;--lucio-ash-dark: #43464F;--lucio-ash-light: #A6A9B3;--lucio-font-display: "Bricolage Grotesque", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;--lucio-font-body: "IBM Plex Sans", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;--lucio-font-mono: "IBM Plex Mono", "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;--lucio-font-cjk-display: "Noto Serif SC", "Songti SC", "SimSun", serif;--lucio-font-cjk-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;--lucio-space-1: 4px;--lucio-space-2: 8px;--lucio-space-3: 12px;--lucio-space-4: 16px;--lucio-space-5: 24px;--lucio-space-6: 32px;--lucio-space-7: 48px;--lucio-space-8: 64px;--lucio-space-9: 96px;--lucio-space-10: 128px;--lucio-radius-none: 0px;--lucio-radius-sm: 4px;--lucio-radius-md: 8px;--lucio-radius-lg: 16px;--lucio-radius-icon: 22%;--lucio-shadow-glow: 0 0 0 1px rgba(255,243,207,.3), 0 8px 32px -8px rgba(255,243,207,.35);--lucio-motion-fast: .12s;--lucio-ease-fast: cubic-bezier(.2, 0, 0, 1);--lucio-motion-base: .24s;--lucio-ease-base: cubic-bezier(.2, 0, 0, 1);--lucio-motion-glow: .9s;--lucio-ease-glow: cubic-bezier(.16, 1, .3, 1)}@font-face{font-family:Bricolage Grotesque;font-style:normal;font-weight:200 800;font-display:swap;src:url("./bricolage-grotesque-latin-ext-wght-normal.EMW626ZA.woff2") format("woff2-variations");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:Bricolage Grotesque;font-style:normal;font-weight:200 800;font-display:swap;src:url("./bricolage-grotesque-latin-wght-normal.HY2A4V5R.woff2") format("woff2-variations");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-ext-400-normal.EDOVP6TU.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-400-normal.COQVXTP6.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:500;font-display:swap;src:url("./ibm-plex-sans-latin-ext-500-normal.SG2XNXKB.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:500;font-display:swap;src:url("./ibm-plex-sans-latin-500-normal.JTONHBWS.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:600;font-display:swap;src:url("./ibm-plex-sans-latin-ext-600-normal.ZNWKNRXL.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:normal;font-weight:600;font-display:swap;src:url("./ibm-plex-sans-latin-600-normal.DTNZULF4.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}@font-face{font-family:IBM Plex Sans;font-style:italic;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-ext-400-italic.VMPJJ47P.woff2") format("woff2");unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}@font-face{font-family:IBM Plex Sans;font-style:italic;font-weight:400;font-display:swap;src:url("./ibm-plex-sans-latin-400-italic.PR7YQ55B.woff2") format("woff2");unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,Line truncated
|
||||
@@ -1 +1 @@
|
||||
"use strict";(()=>{function dt(){let t=navigator.deviceMemory,e=typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches,i=Math.min(screen.width,screen.height)<=820;return t!==void 0&&t<=4||e&&i?120*1048576:250*1048576}var U=class{constructor(t){this.budget=t;this.entries=new Map;this.used=0}get(t){let e=this.entries.get(t);return e&&(this.entries.delete(t),this.entries.set(t,e)),e}has(t){return this.entries.has(t)}put(t,e){let i=this.entries.get(t);if(i){i.bitmap!==e&&e.close();return}let s=e.width*e.height*4;this.entries.set(t,{bitmap:e,bytes:s,at:performance.now()}),this.used+=s,this.evict()}evict(){for(;this.used>this.budget&&this.entries.size>1;){let t=this.entries.keys().next();if(t.done)return;let e=this.entries.get(t.value);this.entries.delete(t.value),e&&(this.used-=e.bytes,e.bitmap.close())}}};(function(a){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 l=document.createElementNS(i,c);for(let u in w)l.setAttribute(u,w[u]);return l},n=()=>a.matchMedia&&a.matchMedia("(prefers-reduced-motion: reduce)").matches,r=c=>Math.max(0,Math.min(1,c)),o=c=>c*c*(3-2*c),d=.5;function h(c,w){let l=0,u=0,p=null,b=0;function C(y){let v=(y-b)/w;b=y,l=l<u?Math.min(u,l+v):Math.max(u,l-v),c(l),p=l===u?null:requestAnimationFrame(C)}function f(y){if(u=y,n()){l=y,c(l);return}p===null&&(b=performance.now(),p=requestAnimationFrame(C))}return{play:()=>f(1),reverse:()=>f(0),toggle:()=>f(u?0:1),set:y=>{cancelAnimationFrame(p),p=null,u=l=y,c(l)},stop:()=>{cancelAnimationFrame(p),p=nulLine 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=(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
|
||||
@@ -1 +1 @@
|
||||
"use strict";(()=>{var s=self,o=new Map;s.onmessage=t=>{let e=t.data;if(e.type==="abort"){o.get(e.key)?.abort(),o.delete(e.key);return}l(e)};async function l(t){let e=new AbortController;o.set(t.key,e);let i=performance.now();try{let r=await fetch(t.url,{signal:e.signal,credentials:"same-origin"});if(!r.ok)throw new Error("HTTP "+r.status);let a=await r.blob(),c=performance.now()-i,n=await createImageBitmap(a);if(e.signal.aborted)throw n.close(),new Error("aborted");s.postMessage({key:t.key,ok:!0,bitmap:n,bytes:a.size,ms:c},[n])}catch(r){s.postMessage({key:t.key,ok:!1,bytes:0,ms:0,error:String(r)})}finally{o.delete(t.key)}}})();
|
||||
"use strict";(()=>{function k(r){let n=r.seed+"|"+r.level+"|"+r.x+"|"+r.y,o=2166136261;for(let t=0;t<n.length;t++)o=Math.imul(o^n.charCodeAt(t),16777619)>>>0;return o}function v(r,n){let o=new Array(r);for(let e=0;e<r;e++)o[e]=e;let t=n|0,a=()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296};for(let e=r-1;e>0;e--){let s=Math.floor(a()*(e+1)),m=o[e];o[e]=o[s],o[s]=m}return o}function g(r,n,o,t,a){r.drawImage(n,0,0);let e=a.cell,s=Math.floor(o/e),m=Math.floor(t/e),u=s*m;if(u<2)return;let d=v(u,k(a));for(let c=0;c<u;c++){let f=d[c];if(f===c)continue;let p=c%s*e,y=Math.floor(c/s)*e,h=f%s*e,w=Math.floor(f/s)*e;r.drawImage(n,p,y,e,e,h,w,e,e)}}var l=self,i=new Map,M=typeof createImageBitmap=="function",b=self.OffscreenCanvas;l.onmessage=r=>{let n=r.data;if(n.type==="abort"){i.get(n.key)?.abort(),i.delete(n.key);return}S(n)};function x(r,n){if(!b)throw new Error("unsupported-offscreen");let o=new b(r.width,r.height),t=o.getContext("2d");if(!t)throw new Error("unsupported-offscreen");return g(t,r,r.width,r.height,n),r.close(),o.transferToImageBitmap()}async function S(r){if(!M){l.postMessage({key:r.key,ok:!1,bytes:0,ms:0,error:"unsupported-bitmap"});return}if(r.scramble&&!b){l.postMessage({key:r.key,ok:!1,bytes:0,ms:0,error:"unsupported-offscreen"});return}let n=new AbortController;i.set(r.key,n);let o=performance.now();try{let t=await fetch(r.url,{signal:n.signal,credentials:"same-origin"});if(!t.ok)throw new Error("HTTP "+t.status);let a=await t.blob(),e=performance.now()-o,s=await createImageBitmap(a);if(r.scramble&&(s=x(s,r.scramble)),n.signal.aborted)throw s.close(),new Error("aborted");l.postMessage({key:r.key,ok:!0,bitmap:s,bytes:a.size,ms:e},[s])}catch(t){let a=t instanceof Error?t.message:String(t);l.postMessage({key:r.key,ok:!1,bytes:0,ms:0,error:a})}finally{i.delete(r.key)}}})();
|
||||
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{{template "head" .}}
|
||||
</head>
|
||||
<body class="index-page not-found" data-page="notfound"{{template "body-data" .}}>
|
||||
<header class="site-header">
|
||||
<a class="wordmark" href="/" aria-label="Lucio, all albums"><span class="wordmark-text">Lucio</span></a>
|
||||
</header>
|
||||
<main class="message" id="main">
|
||||
<p class="message-eyebrow">404</p>
|
||||
<h1 class="message-title">Nothing here</h1>
|
||||
<p class="message-text">This page does not exist, or the album moved. <a href="/">All albums</a></p>
|
||||
</main>
|
||||
{{template "footer" .}}
|
||||
</body>
|
||||
</html>
|
||||
@@ -5,12 +5,14 @@
|
||||
<link rel="preload" href="{{.ManifestURL}}" as="fetch" crossorigin>
|
||||
</head>
|
||||
<body class="viewer" data-page="album" data-album="{{.Slug}}" data-manifest="{{.ManifestURL}}"{{template "body-data" .}}>
|
||||
<a class="skip-link" href="#stage">Skip to photos</a>
|
||||
<a class="home-mark" href="/" aria-label="Lucio, all albums"><span class="wordmark-text">Lucio</span></a>
|
||||
<main id="stage" class="stage" aria-label="{{.AlbumTitle}}">
|
||||
<h1 class="visually-hidden">{{.AlbumTitle}}{{if .Subtitle}} · {{.Subtitle}}{{end}}</h1>
|
||||
<main id="stage" class="stage" tabindex="0" aria-label="{{.AlbumTitle}}, photo viewer" aria-keyshortcuts="ArrowLeft ArrowRight Home End Escape i">
|
||||
<h1 class="visually-hidden"><span{{with lang .AlbumTitle}} lang="{{.}}"{{end}}>{{.AlbumTitle}}</span>{{if .Subtitle}} · <span{{with lang .Subtitle}} lang="{{.}}"{{end}}>{{.Subtitle}}</span>{{end}}</h1>
|
||||
</main>
|
||||
<div class="album-fallback">
|
||||
<p>{{.Photos}} photos{{if .Date}} · <time>{{.Date}}</time>{{end}}</p>
|
||||
<p class="load-error" hidden>This album could not be loaded right now.</p>
|
||||
<noscript><p>This album needs JavaScript to draw its photos.</p></noscript>
|
||||
<p><a href="/">All albums</a></p>
|
||||
</div>
|
||||
|
||||
@@ -25,3 +25,7 @@
|
||||
<script src="{{.Assets.JS.URL}}" defer></script>
|
||||
{{- end}}
|
||||
{{define "body-data"}} data-build="{{.Build}}" data-index="{{.IndexURL}}" data-worker="{{.Assets.Worker.URL}}" data-budget-ms="{{.BudgetMS}}" data-max-dpr="{{.MaxDPR}}" data-concurrency="{{.Concurrency}}" data-block-context-menu="{{.BlockContextMenu}}"{{end}}
|
||||
{{define "footer"}}<footer class="site-footer">
|
||||
<p class="footer-line">Guoliang Chen · <span lang="zh">陈国梁</span> · Lucio</p>
|
||||
<span class="chop">{{.Assets.Chop}}</span>
|
||||
</footer>{{end}}
|
||||
@@ -5,22 +5,20 @@
|
||||
<link rel="preload" href="{{.IndexURL}}" as="fetch" crossorigin>
|
||||
</head>
|
||||
<body class="index-page" data-page="index"{{template "body-data" .}}>
|
||||
<a class="skip-link" href="#strips">Skip to albums</a>
|
||||
<header class="site-header">
|
||||
<a class="wordmark" href="/" aria-label="Lucio, all albums"><span class="wordmark-text">Lucio</span></a>
|
||||
</header>
|
||||
<main id="strips" class="strips">
|
||||
<main id="strips" class="strips" tabindex="-1">
|
||||
<h1 class="visually-hidden">Photos by Lucio</h1>
|
||||
{{- range .Albums}}
|
||||
<a class="strip" href="/a/{{.Slug}}/" data-slug="{{.Slug}}">
|
||||
<span class="strip-text">{{if .Date}}<span class="strip-eyebrow">{{.Date}}</span>{{end}}<span class="strip-title">{{.Title}}</span>{{if .Subtitle}}<span class="strip-subtitle">{{.Subtitle}}</span>{{end}}</span>
|
||||
<span class="strip-text">{{if .Date}}<span class="strip-eyebrow">{{.Date}}</span>{{end}}<span class="strip-title"{{with lang .Title}} lang="{{.}}"{{end}}>{{.Title}}</span>{{if .Subtitle}}<span class="strip-subtitle"{{with lang .Subtitle}} lang="{{.}}"{{end}}>{{.Subtitle}}</span>{{end}}</span>
|
||||
</a>
|
||||
{{- else}}
|
||||
<p class="empty">No albums yet.</p>
|
||||
{{- end}}
|
||||
</main>
|
||||
<footer class="site-footer">
|
||||
<p class="footer-line">Guoliang Chen · 陈国梁 · Lucio</p>
|
||||
<span class="chop">{{.Assets.Chop}}</span>
|
||||
</footer>
|
||||
{{template "footer" .}}
|
||||
</body>
|
||||
</html>
|
||||
+9
-1
@@ -9,7 +9,7 @@ photos.luciochen.com {
|
||||
respond @hotlink 403
|
||||
|
||||
@hidden path */.* *.gz
|
||||
respond @hidden 404
|
||||
error @hidden 404
|
||||
|
||||
@immutable path /t/* /og/* /assets/*
|
||||
header @immutable Cache-Control "public, max-age=31536000, immutable"
|
||||
@@ -30,4 +30,12 @@ photos.luciochen.com {
|
||||
file_server {
|
||||
precompressed gzip
|
||||
}
|
||||
|
||||
handle_errors {
|
||||
@notfound expression {err.status_code} == 404
|
||||
rewrite @notfound /404.html
|
||||
file_server {
|
||||
precompressed gzip
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ server {
|
||||
disable_symlinks off;
|
||||
gzip_static on;
|
||||
server_tokens off;
|
||||
error_page 404 /404.html;
|
||||
|
||||
if ($request_method !~ ^(GET|HEAD)$) {
|
||||
return 405;
|
||||
@@ -28,6 +29,14 @@ server {
|
||||
return 404;
|
||||
}
|
||||
|
||||
location = /404.html {
|
||||
internal;
|
||||
add_header Cache-Control "public, max-age=60" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; img-src 'self' blob: data:; font-src 'self'; worker-src 'self'; frame-ancestors 'none'" always;
|
||||
add_header X-Content-Type-Options nosniff always;
|
||||
add_header Referrer-Policy strict-origin-when-cross-origin always;
|
||||
}
|
||||
|
||||
location /t/ {
|
||||
if ($luphoto_hotlink) {
|
||||
return 403;
|
||||
|
||||
@@ -490,3 +490,74 @@ html:not(.has-strips) .strip-subtitle {
|
||||
animation-duration: 0ms !important;
|
||||
}
|
||||
}
|
||||
|
||||
html {
|
||||
touch-action: manipulation;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
.skip-link {
|
||||
position: absolute;
|
||||
top: var(--lucio-space-2);
|
||||
left: var(--lucio-space-4);
|
||||
z-index: 10;
|
||||
padding: var(--lucio-space-2) var(--lucio-space-3);
|
||||
background: var(--lucio-graphite-2);
|
||||
color: var(--lucio-paper);
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
text-decoration: none;
|
||||
transform: translateY(-200%);
|
||||
}
|
||||
|
||||
.skip-link:focus-visible {
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.stage:focus-visible {
|
||||
outline: 2px solid var(--lucio-beam);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
.strip {
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.load-error {
|
||||
color: var(--lucio-ash-light);
|
||||
}
|
||||
|
||||
.message {
|
||||
padding: var(--lucio-space-9) var(--gutter) var(--lucio-space-8);
|
||||
max-width: 68ch;
|
||||
}
|
||||
|
||||
.message-eyebrow {
|
||||
margin: 0;
|
||||
font-family: var(--lucio-font-mono);
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--lucio-ash-light);
|
||||
}
|
||||
|
||||
.message-title {
|
||||
margin: var(--lucio-space-2) 0 var(--lucio-space-4);
|
||||
font-family: var(--lucio-font-display);
|
||||
font-size: 36px;
|
||||
font-weight: 700;
|
||||
line-height: 1.15;
|
||||
letter-spacing: -0.015em;
|
||||
}
|
||||
|
||||
.message-text {
|
||||
margin: 0;
|
||||
color: var(--lucio-paper);
|
||||
}
|
||||
|
||||
.message-text a {
|
||||
text-decoration: underline;
|
||||
}
|
||||
+41
-8
@@ -1,3 +1,4 @@
|
||||
import { mountWordmark } from "./brand";
|
||||
import { TileCache, cacheBudget } from "./cache";
|
||||
import { IndexPage } from "./index";
|
||||
import { Scheduler } from "./scheduler";
|
||||
@@ -23,13 +24,39 @@ async function startAlbum(stage: HTMLElement, settings: Settings): Promise<void>
|
||||
}
|
||||
const { scheduler, cache } = shared(settings);
|
||||
document.documentElement.classList.add("has-viewer");
|
||||
new Viewer(stage, manifest, settings, { scheduler, cache, settings, tiles: manifest.tiles });
|
||||
lifecycle(new Viewer(stage, manifest, settings, { scheduler, cache, settings, tiles: manifest.tiles }));
|
||||
}
|
||||
|
||||
async function startIndex(root: HTMLElement, settings: Settings): Promise<void> {
|
||||
const index = await fetchJSON<SiteIndex>(settings.indexUrl);
|
||||
const { scheduler, cache } = shared(settings);
|
||||
new IndexPage(root, index, settings, { scheduler, cache, settings, tiles: index.tiles });
|
||||
lifecycle(new IndexPage(root, index, settings, { scheduler, cache, settings, tiles: index.tiles }));
|
||||
}
|
||||
|
||||
interface Suspendable {
|
||||
suspend(hidden: boolean): void;
|
||||
resume(): void;
|
||||
}
|
||||
|
||||
function lifecycle(target: Suspendable): void {
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.visibilityState === "hidden") {
|
||||
target.suspend(false);
|
||||
} else {
|
||||
target.resume();
|
||||
}
|
||||
});
|
||||
window.addEventListener("pagehide", () => target.suspend(true));
|
||||
window.addEventListener("pageshow", (event) => {
|
||||
if (event.persisted) {
|
||||
target.resume();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showLoadError(): void {
|
||||
document.documentElement.classList.remove("has-viewer");
|
||||
document.querySelector<HTMLElement>(".load-error")?.removeAttribute("hidden");
|
||||
}
|
||||
|
||||
function boot(): void {
|
||||
@@ -37,16 +64,22 @@ function boot(): void {
|
||||
if (settings.page === "album") {
|
||||
const stage = document.getElementById("stage");
|
||||
if (stage) {
|
||||
startAlbum(stage, settings).catch((error: unknown) => {
|
||||
stage.dataset.error = String(error);
|
||||
document.documentElement.classList.remove("has-viewer");
|
||||
});
|
||||
startAlbum(stage, settings).catch(() => showLoadError());
|
||||
}
|
||||
} else if (settings.page === "notfound") {
|
||||
const header = document.querySelector<HTMLElement>(".site-header .wordmark");
|
||||
if (header) {
|
||||
mountWordmark(header, false);
|
||||
}
|
||||
} else if (settings.page === "index") {
|
||||
const root = document.getElementById("strips");
|
||||
if (root) {
|
||||
startIndex(root, settings).catch((error: unknown) => {
|
||||
root.dataset.error = String(error);
|
||||
startIndex(root, settings).catch(() => {
|
||||
document.documentElement.classList.remove("has-strips");
|
||||
const header = document.querySelector<HTMLElement>(".site-header .wordmark");
|
||||
if (header && !header.classList.contains("has-svg")) {
|
||||
mountWordmark(header, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+22
-15
@@ -1,5 +1,7 @@
|
||||
import { releaseImage, type TileImage } from "./scheduler";
|
||||
|
||||
export interface CachedTile {
|
||||
bitmap: ImageBitmap;
|
||||
bitmap: TileImage;
|
||||
bytes: number;
|
||||
at: number;
|
||||
}
|
||||
@@ -8,22 +10,27 @@ interface NavigatorWithMemory extends Navigator {
|
||||
deviceMemory?: number;
|
||||
}
|
||||
|
||||
export function cacheBudget(): number {
|
||||
const mb = 1024 * 1024;
|
||||
const mb = 1024 * 1024;
|
||||
|
||||
export function isConstrainedDevice(): boolean {
|
||||
const memory = (navigator as NavigatorWithMemory).deviceMemory;
|
||||
const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
|
||||
const smallScreen = Math.min(screen.width, screen.height) <= 820;
|
||||
if ((memory !== undefined && memory <= 4) || (coarse && smallScreen)) {
|
||||
return 120 * mb;
|
||||
if (typeof memory === "number" && memory <= 4) {
|
||||
return true;
|
||||
}
|
||||
return 250 * mb;
|
||||
const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
|
||||
const shortSide = Math.min(screen.width, screen.height);
|
||||
return coarse && shortSide <= 820;
|
||||
}
|
||||
|
||||
export function cacheBudget(): number {
|
||||
return isConstrainedDevice() ? 120 * mb : 250 * mb;
|
||||
}
|
||||
|
||||
export class TileCache {
|
||||
private readonly entries = new Map<string, CachedTile>();
|
||||
private used = 0;
|
||||
|
||||
constructor(private readonly budget: number) {}
|
||||
constructor(readonly budget: number) {}
|
||||
|
||||
get(id: string): CachedTile | undefined {
|
||||
const entry = this.entries.get(id);
|
||||
@@ -38,22 +45,22 @@ export class TileCache {
|
||||
return this.entries.has(id);
|
||||
}
|
||||
|
||||
put(id: string, bitmap: ImageBitmap): void {
|
||||
put(id: string, bitmap: TileImage): void {
|
||||
const existing = this.entries.get(id);
|
||||
if (existing) {
|
||||
if (existing.bitmap !== bitmap) {
|
||||
bitmap.close();
|
||||
releaseImage(bitmap);
|
||||
}
|
||||
return;
|
||||
}
|
||||
const bytes = bitmap.width * bitmap.height * 4;
|
||||
this.entries.set(id, { bitmap, bytes, at: performance.now() });
|
||||
this.used += bytes;
|
||||
this.evict();
|
||||
this.trim(this.budget);
|
||||
}
|
||||
|
||||
private evict(): void {
|
||||
while (this.used > this.budget && this.entries.size > 1) {
|
||||
trim(limit: number): void {
|
||||
while (this.used > limit && this.entries.size > 0) {
|
||||
const oldest = this.entries.keys().next();
|
||||
if (oldest.done) {
|
||||
return;
|
||||
@@ -62,7 +69,7 @@ export class TileCache {
|
||||
this.entries.delete(oldest.value);
|
||||
if (entry) {
|
||||
this.used -= entry.bytes;
|
||||
entry.bitmap.close();
|
||||
releaseImage(entry.bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-6
@@ -1,5 +1,15 @@
|
||||
import type { Exif, Photo } from "./types";
|
||||
|
||||
const han = /[㐀-鿿豈-]/;
|
||||
|
||||
export function setLang(element: HTMLElement, text: string): void {
|
||||
if (han.test(text)) {
|
||||
element.lang = "zh";
|
||||
} else {
|
||||
element.removeAttribute("lang");
|
||||
}
|
||||
}
|
||||
|
||||
function pad(n: number): string {
|
||||
return n < 10 ? "0" + n : String(n);
|
||||
}
|
||||
@@ -102,23 +112,20 @@ export class CaptionPanel {
|
||||
private readonly meta: HTMLElement;
|
||||
private readonly title: HTMLElement;
|
||||
private readonly text: HTMLElement;
|
||||
private readonly alt: HTMLElement;
|
||||
private visible = false;
|
||||
private placement = "";
|
||||
|
||||
constructor(parent: HTMLElement) {
|
||||
this.element = document.createElement("section");
|
||||
this.element.className = "caption";
|
||||
this.element.setAttribute("aria-live", "polite");
|
||||
this.element.setAttribute("aria-label", "Caption");
|
||||
this.meta = document.createElement("p");
|
||||
this.meta.className = "caption-meta";
|
||||
this.title = document.createElement("h2");
|
||||
this.title.className = "caption-title";
|
||||
this.text = document.createElement("p");
|
||||
this.text.className = "caption-text";
|
||||
this.alt = document.createElement("p");
|
||||
this.alt.className = "visually-hidden";
|
||||
this.element.append(this.meta, this.title, this.text, this.alt);
|
||||
this.element.append(this.meta, this.title, this.text);
|
||||
parent.appendChild(this.element);
|
||||
}
|
||||
|
||||
@@ -126,9 +133,10 @@ export class CaptionPanel {
|
||||
this.meta.textContent = metaLine(index, total, photo, showExif);
|
||||
this.title.textContent = photo.title ?? "";
|
||||
this.title.hidden = !photo.title;
|
||||
setLang(this.title, photo.title ?? "");
|
||||
renderRichText(this.text, photo.caption ?? "");
|
||||
this.text.hidden = !photo.caption;
|
||||
this.alt.textContent = photo.alt ?? "";
|
||||
setLang(this.text, photo.caption ?? "");
|
||||
}
|
||||
|
||||
show(visible: boolean): void {
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ export function visibleTiles(pyramid: Pyramid, levelIndex: number, view: View, t
|
||||
|
||||
export function drawTile(
|
||||
g: CanvasRenderingContext2D,
|
||||
bitmap: ImageBitmap,
|
||||
bitmap: { width: number; height: number } & CanvasImageSource,
|
||||
level: Level,
|
||||
x: number,
|
||||
y: number,
|
||||
|
||||
+38
-2
@@ -8,6 +8,8 @@ const hysteresis = 24;
|
||||
export class IndexPage {
|
||||
private readonly strips: Strip[] = [];
|
||||
private readonly onScreen = new Set<Strip>();
|
||||
private readonly inView = new Set<Strip>();
|
||||
private suspended = false;
|
||||
private readonly indicator: BusyIndicator;
|
||||
private readonly hoverMode: MediaQueryList;
|
||||
private wordmark: MorphHandle | null = null;
|
||||
@@ -19,7 +21,7 @@ export class IndexPage {
|
||||
private readonly root: HTMLElement,
|
||||
index: SiteIndex,
|
||||
private readonly settings: Settings,
|
||||
env: StripEnv,
|
||||
private readonly env: StripEnv,
|
||||
) {
|
||||
const anchors = Array.from(root.querySelectorAll<HTMLElement>("a.strip"));
|
||||
const bySlug = new Map(index.albums.map((album) => [album.slug, album]));
|
||||
@@ -52,6 +54,36 @@ export class IndexPage {
|
||||
this.bind();
|
||||
}
|
||||
|
||||
suspend(hidden: boolean): void {
|
||||
if (this.suspended) {
|
||||
return;
|
||||
}
|
||||
this.suspended = true;
|
||||
for (const strip of this.strips) {
|
||||
strip.loader.stop();
|
||||
if (hidden) {
|
||||
strip.detach();
|
||||
}
|
||||
}
|
||||
this.env.scheduler.cancelAll();
|
||||
this.env.cache.trim(hidden ? 0 : this.env.cache.budget / 4);
|
||||
}
|
||||
|
||||
resume(): void {
|
||||
if (!this.suspended) {
|
||||
return;
|
||||
}
|
||||
this.suspended = false;
|
||||
for (const strip of this.strips) {
|
||||
if (this.inView.has(strip)) {
|
||||
strip.attach();
|
||||
}
|
||||
if (strip.isNear) {
|
||||
strip.startSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private wordmarkMoving(): boolean {
|
||||
const t = this.wordmark?.t ?? 0;
|
||||
return t > 0 && t < 1;
|
||||
@@ -93,8 +125,12 @@ export class IndexPage {
|
||||
continue;
|
||||
}
|
||||
if (entry.isIntersecting) {
|
||||
strip.attach();
|
||||
this.inView.add(strip);
|
||||
if (!this.suspended) {
|
||||
strip.attach();
|
||||
}
|
||||
} else {
|
||||
this.inView.delete(strip);
|
||||
strip.detach();
|
||||
}
|
||||
}
|
||||
|
||||
+44
-10
@@ -1,6 +1,7 @@
|
||||
import type { TileCache } from "./cache";
|
||||
import { drawTile, neededLevel, tileRange, visibleTiles, type TileRef, type View } from "./geometry";
|
||||
import { PRIORITY_CURRENT, PRIORITY_PREFETCH, type Scheduler, type TileResult } from "./scheduler";
|
||||
import { AbortError, PRIORITY_CURRENT, PRIORITY_PREFETCH, decodeBlob, releaseImage, type Scheduler, type TileResult } from "./scheduler";
|
||||
import type { ScrambleSpec } from "./scramble";
|
||||
import { currentThroughput, recordThroughput } from "./throughput";
|
||||
import type { Pyramid, Settings, Tiles } from "./types";
|
||||
|
||||
@@ -22,6 +23,25 @@ export interface LoadStatus {
|
||||
}
|
||||
|
||||
const fadeMs = 180;
|
||||
const retryMs = 400;
|
||||
|
||||
function wait(ms: number, signal: AbortSignal): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (signal.aborted) {
|
||||
reject(new AbortError());
|
||||
return;
|
||||
}
|
||||
const timer = setTimeout(() => {
|
||||
signal.removeEventListener("abort", stop);
|
||||
resolve();
|
||||
}, ms);
|
||||
const stop = () => {
|
||||
clearTimeout(timer);
|
||||
reject(new AbortError());
|
||||
};
|
||||
signal.addEventListener("abort", stop, { once: true });
|
||||
});
|
||||
}
|
||||
const probeStep = 3;
|
||||
const seedUpscale = 4;
|
||||
|
||||
@@ -73,7 +93,7 @@ export class PhotoLoader {
|
||||
for (let i = 0; i < raw.length; i++) {
|
||||
bytes[i] = raw.charCodeAt(i);
|
||||
}
|
||||
const bitmap = await createImageBitmap(new Blob([bytes], { type: "image/" + this.env.tiles.format }));
|
||||
const bitmap = await decodeBlob(new Blob([bytes], { type: "image/" + this.env.tiles.format }));
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = bitmap.width * seedUpscale;
|
||||
canvas.height = bitmap.height * seedUpscale;
|
||||
@@ -89,17 +109,31 @@ export class PhotoLoader {
|
||||
}
|
||||
const pad = seedUpscale * 2;
|
||||
g.drawImage(bitmap, -pad, -pad, canvas.width + pad * 2, canvas.height + pad * 2);
|
||||
bitmap.close();
|
||||
releaseImage(bitmap);
|
||||
this.seedImage = canvas;
|
||||
}
|
||||
|
||||
private fetchTile(tile: TileRef, priority: number, signal: AbortSignal): Promise<TileResult> {
|
||||
const id = this.pyramid.levels[tile.level].tiles[tile.index];
|
||||
return this.env.scheduler.request(id, this.tileUrl(id), priority, signal).then((result) => {
|
||||
this.env.cache.put(id, result.bitmap);
|
||||
this.env.requestDraw();
|
||||
return result;
|
||||
});
|
||||
private async fetchTile(tile: TileRef, priority: number, signal: AbortSignal): Promise<TileResult> {
|
||||
const level = this.pyramid.levels[tile.level];
|
||||
const id = level.tiles[tile.index];
|
||||
const tiles = this.env.tiles;
|
||||
const scramble: ScrambleSpec | undefined =
|
||||
tiles.scrambled && this.pyramid.scramble
|
||||
? { seed: this.pyramid.scramble, level: tile.level, x: tile.x, y: tile.y, cell: tiles.cell ?? 64 }
|
||||
: undefined;
|
||||
let result: TileResult;
|
||||
try {
|
||||
result = await this.env.scheduler.request(id, this.tileUrl(id), priority, signal, scramble);
|
||||
} catch (error) {
|
||||
if (signal.aborted || error instanceof AbortError) {
|
||||
throw error;
|
||||
}
|
||||
await wait(retryMs + Math.random() * retryMs, signal);
|
||||
result = await this.env.scheduler.request(id, this.tileUrl(id), priority, signal, scramble);
|
||||
}
|
||||
this.env.cache.put(id, result.bitmap);
|
||||
this.env.requestDraw();
|
||||
return result;
|
||||
}
|
||||
|
||||
private uncached(level: number, view: View): TileRef[] {
|
||||
|
||||
+94
-16
@@ -1,8 +1,12 @@
|
||||
import { unscramble, type ScrambleSpec } from "./scramble";
|
||||
|
||||
export const PRIORITY_CURRENT = 0;
|
||||
export const PRIORITY_PREFETCH = 1;
|
||||
|
||||
export type TileImage = ImageBitmap | HTMLImageElement | HTMLCanvasElement;
|
||||
|
||||
export interface TileResult {
|
||||
bitmap: ImageBitmap;
|
||||
bitmap: TileImage;
|
||||
bytes: number;
|
||||
ms: number;
|
||||
}
|
||||
@@ -16,6 +20,7 @@ interface Job {
|
||||
key: number;
|
||||
id: string;
|
||||
url: string;
|
||||
scramble?: ScrambleSpec;
|
||||
priority: number;
|
||||
seq: number;
|
||||
waiters: Set<Waiter>;
|
||||
@@ -27,7 +32,7 @@ interface Job {
|
||||
interface WorkerReply {
|
||||
key: number;
|
||||
ok: boolean;
|
||||
bitmap?: ImageBitmap;
|
||||
bitmap?: TileImage;
|
||||
bytes: number;
|
||||
ms: number;
|
||||
error?: string;
|
||||
@@ -40,11 +45,56 @@ export class AbortError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export function releaseImage(image: TileImage): void {
|
||||
if ("close" in image) {
|
||||
image.close();
|
||||
} else if (image instanceof HTMLCanvasElement) {
|
||||
image.width = 0;
|
||||
image.height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export async function decodeBlob(blob: Blob): Promise<TileImage> {
|
||||
if (typeof createImageBitmap === "function") {
|
||||
return createImageBitmap(blob);
|
||||
}
|
||||
const url = URL.createObjectURL(blob);
|
||||
try {
|
||||
const image = new Image();
|
||||
image.decoding = "async";
|
||||
image.src = url;
|
||||
await image.decode();
|
||||
return image;
|
||||
} finally {
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
|
||||
async function restore(image: TileImage, spec: ScrambleSpec): Promise<TileImage> {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = image.width;
|
||||
canvas.height = image.height;
|
||||
const g = canvas.getContext("2d");
|
||||
if (!g) {
|
||||
return image;
|
||||
}
|
||||
unscramble(g, image, image.width, image.height, spec);
|
||||
releaseImage(image);
|
||||
if (typeof createImageBitmap === "function") {
|
||||
const bitmap = await createImageBitmap(canvas);
|
||||
canvas.width = 0;
|
||||
canvas.height = 0;
|
||||
return bitmap;
|
||||
}
|
||||
return canvas;
|
||||
}
|
||||
|
||||
export class Scheduler {
|
||||
private readonly byId = new Map<string, Job>();
|
||||
private readonly byKey = new Map<number, Job>();
|
||||
private readonly queue: Job[] = [];
|
||||
private readonly workers: Worker[] = [];
|
||||
private workersUnscramble = true;
|
||||
private running = 0;
|
||||
private nextKey = 1;
|
||||
private nextSeq = 1;
|
||||
@@ -59,7 +109,7 @@ export class Scheduler {
|
||||
try {
|
||||
const worker = new Worker(workerUrl);
|
||||
const index = this.workers.length;
|
||||
worker.onmessage = (event: MessageEvent<WorkerReply>) => this.onReply(event.data);
|
||||
worker.onmessage = (event: MessageEvent<WorkerReply>) => this.onReply(event.data, index);
|
||||
worker.onerror = () => this.dropWorker(index);
|
||||
this.workers.push(worker);
|
||||
} catch {
|
||||
@@ -68,7 +118,7 @@ export class Scheduler {
|
||||
}
|
||||
}
|
||||
|
||||
request(id: string, url: string, priority: number, signal: AbortSignal): Promise<TileResult> {
|
||||
request(id: string, url: string, priority: number, signal: AbortSignal, scramble?: ScrambleSpec): Promise<TileResult> {
|
||||
if (signal.aborted) {
|
||||
return Promise.reject(new AbortError());
|
||||
}
|
||||
@@ -83,6 +133,7 @@ export class Scheduler {
|
||||
key: this.nextKey++,
|
||||
id,
|
||||
url,
|
||||
scramble,
|
||||
priority,
|
||||
seq: this.nextSeq++,
|
||||
waiters: new Set(),
|
||||
@@ -118,6 +169,17 @@ export class Scheduler {
|
||||
});
|
||||
}
|
||||
|
||||
cancelAll(): void {
|
||||
for (const job of [...this.byKey.values()]) {
|
||||
const waiters = [...job.waiters];
|
||||
job.waiters.clear();
|
||||
for (const waiter of waiters) {
|
||||
waiter.reject(new AbortError());
|
||||
}
|
||||
this.cancel(job);
|
||||
}
|
||||
}
|
||||
|
||||
private cancel(job: Job): void {
|
||||
this.forget(job);
|
||||
if (!job.running) {
|
||||
@@ -163,12 +225,16 @@ export class Scheduler {
|
||||
|
||||
private start(job: Job): void {
|
||||
const live = this.liveWorkers();
|
||||
if (live.length > 0) {
|
||||
if (live.length > 0 && (!job.scramble || this.workersUnscramble)) {
|
||||
const index = live[this.nextWorker++ % live.length];
|
||||
job.worker = index;
|
||||
this.workers[index].postMessage({ type: "fetch", key: job.key, url: job.url });
|
||||
this.workers[index].postMessage({ type: "fetch", key: job.key, url: job.url, scramble: job.scramble });
|
||||
return;
|
||||
}
|
||||
this.runOnMainThread(job);
|
||||
}
|
||||
|
||||
private runOnMainThread(job: Job): void {
|
||||
job.worker = -1;
|
||||
job.controller = new AbortController();
|
||||
void this.fetchOnMainThread(job, job.controller.signal);
|
||||
@@ -193,9 +259,7 @@ export class Scheduler {
|
||||
delete this.workers[index];
|
||||
for (const job of this.byKey.values()) {
|
||||
if (job.running && job.worker === index) {
|
||||
job.worker = -1;
|
||||
job.controller = new AbortController();
|
||||
void this.fetchOnMainThread(job, job.controller.signal);
|
||||
this.runOnMainThread(job);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,17 +273,31 @@ export class Scheduler {
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const ms = performance.now() - started;
|
||||
const bitmap = await createImageBitmap(blob);
|
||||
this.onReply({ key: job.key, ok: true, bitmap, bytes: blob.size, ms });
|
||||
let image = await decodeBlob(blob);
|
||||
if (job.scramble) {
|
||||
image = await restore(image, job.scramble);
|
||||
}
|
||||
this.onReply({ key: job.key, ok: true, bitmap: image, bytes: blob.size, ms }, -1);
|
||||
} catch (error) {
|
||||
this.onReply({ key: job.key, ok: false, bytes: 0, ms: 0, error: String(error) });
|
||||
this.onReply({ key: job.key, ok: false, bytes: 0, ms: 0, error: String(error) }, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private onReply(reply: WorkerReply): void {
|
||||
private onReply(reply: WorkerReply, from: number): void {
|
||||
const job = this.byKey.get(reply.key);
|
||||
if (!job || !job.running) {
|
||||
reply.bitmap?.close();
|
||||
if (!job || !job.running || job.worker !== from) {
|
||||
if (reply.bitmap) {
|
||||
releaseImage(reply.bitmap);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!reply.ok && from >= 0 && (reply.error === "unsupported-bitmap" || reply.error === "unsupported-offscreen")) {
|
||||
if (reply.error === "unsupported-bitmap") {
|
||||
this.dropWorker(from);
|
||||
} else {
|
||||
this.workersUnscramble = false;
|
||||
this.runOnMainThread(job);
|
||||
}
|
||||
return;
|
||||
}
|
||||
job.running = false;
|
||||
@@ -233,7 +311,7 @@ export class Scheduler {
|
||||
waiter.resolve(result);
|
||||
}
|
||||
if (waiters.length === 0) {
|
||||
reply.bitmap.close();
|
||||
releaseImage(reply.bitmap);
|
||||
}
|
||||
} else {
|
||||
const error = new Error(reply.error ?? "tile failed");
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
export interface ScrambleSpec {
|
||||
seed: string;
|
||||
level: number;
|
||||
x: number;
|
||||
y: number;
|
||||
cell: number;
|
||||
}
|
||||
|
||||
export function tileSeed(spec: ScrambleSpec): number {
|
||||
const text = spec.seed + "|" + spec.level + "|" + spec.x + "|" + spec.y;
|
||||
let h = 2166136261;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
h = Math.imul(h ^ text.charCodeAt(i), 16777619) >>> 0;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
export function cellPermutation(n: number, seed: number): number[] {
|
||||
const perm = new Array<number>(n);
|
||||
for (let i = 0; i < n; i++) {
|
||||
perm[i] = i;
|
||||
}
|
||||
let state = seed | 0;
|
||||
const next = (): number => {
|
||||
state = (state + 0x6d2b79f5) | 0;
|
||||
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
||||
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
for (let i = n - 1; i > 0; i--) {
|
||||
const j = Math.floor(next() * (i + 1));
|
||||
const swap = perm[i];
|
||||
perm[i] = perm[j];
|
||||
perm[j] = swap;
|
||||
}
|
||||
return perm;
|
||||
}
|
||||
|
||||
export interface CellCanvas {
|
||||
drawImage(image: CanvasImageSource, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
|
||||
drawImage(image: CanvasImageSource, dx: number, dy: number): void;
|
||||
}
|
||||
|
||||
export function unscramble(g: CellCanvas, image: CanvasImageSource, width: number, height: number, spec: ScrambleSpec): void {
|
||||
g.drawImage(image, 0, 0);
|
||||
const cell = spec.cell;
|
||||
const cols = Math.floor(width / cell);
|
||||
const rows = Math.floor(height / cell);
|
||||
const n = cols * rows;
|
||||
if (n < 2) {
|
||||
return;
|
||||
}
|
||||
const perm = cellPermutation(n, tileSeed(spec));
|
||||
for (let i = 0; i < n; i++) {
|
||||
const source = perm[i];
|
||||
if (source === i) {
|
||||
continue;
|
||||
}
|
||||
const sx = (i % cols) * cell;
|
||||
const sy = Math.floor(i / cols) * cell;
|
||||
const dx = (source % cols) * cell;
|
||||
const dy = Math.floor(source / cols) * cell;
|
||||
g.drawImage(image, sx, sy, cell, cell, dx, dy, cell, cell);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,10 @@ export class Strip {
|
||||
return this.expanded;
|
||||
}
|
||||
|
||||
get isNear(): boolean {
|
||||
return this.near;
|
||||
}
|
||||
|
||||
layout(size: StripSize): void {
|
||||
const cover = this.cover;
|
||||
const scale = Math.max(size.width / cover.width, size.open / cover.height);
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface Pyramid {
|
||||
height: number;
|
||||
levels: Level[];
|
||||
seed: string;
|
||||
scramble?: string;
|
||||
}
|
||||
|
||||
export interface Exif {
|
||||
@@ -40,6 +41,8 @@ export interface Tiles {
|
||||
tile_size: number;
|
||||
overlap: number;
|
||||
path: string;
|
||||
scrambled?: boolean;
|
||||
cell?: number;
|
||||
}
|
||||
|
||||
export interface Manifest {
|
||||
|
||||
+66
-2
@@ -1,5 +1,5 @@
|
||||
import { cloneChop, mountWordmark } from "./brand";
|
||||
import { CaptionPanel } from "./caption";
|
||||
import { CaptionPanel, setLang } from "./caption";
|
||||
import type { View } from "./geometry";
|
||||
import { BusyIndicator, ProgressLine } from "./indicator";
|
||||
import { PhotoLoader, type LoaderEnv } from "./loader";
|
||||
@@ -106,6 +106,9 @@ export class Viewer {
|
||||
private readonly homeMark: HTMLElement | null;
|
||||
private nextStrip: Strip | null = null;
|
||||
private idleTimer = 0;
|
||||
private announceTimer = 0;
|
||||
private suspended = false;
|
||||
private readonly announcer: HTMLElement;
|
||||
private readonly reducedMotion: MediaQueryList;
|
||||
private readonly loaders: Array<PhotoLoader | undefined>;
|
||||
private layouts: PhotoLayout[] = [];
|
||||
@@ -139,7 +142,11 @@ export class Viewer {
|
||||
) {
|
||||
this.canvas = document.createElement("canvas");
|
||||
this.canvas.className = "stage-canvas";
|
||||
this.canvas.setAttribute("aria-hidden", "true");
|
||||
this.canvas.setAttribute("role", "img");
|
||||
this.announcer = document.createElement("p");
|
||||
this.announcer.className = "visually-hidden";
|
||||
this.announcer.setAttribute("aria-live", "polite");
|
||||
this.announcer.setAttribute("aria-atomic", "true");
|
||||
this.fade = document.createElement("canvas");
|
||||
this.fade.className = "stage-fade";
|
||||
this.fade.setAttribute("aria-hidden", "true");
|
||||
@@ -155,6 +162,7 @@ export class Viewer {
|
||||
this.nextFrame = this.endCard.querySelector(".next-strip") as HTMLElement;
|
||||
stage.prepend(this.canvas, this.fade);
|
||||
stage.appendChild(this.endCard);
|
||||
stage.appendChild(this.announcer);
|
||||
this.caption = new CaptionPanel(stage);
|
||||
this.progress = new ProgressLine(document.body);
|
||||
this.indicator = new BusyIndicator(document.body);
|
||||
@@ -594,6 +602,7 @@ export class Viewer {
|
||||
this.indicator.watch(null);
|
||||
this.progress.watch(null);
|
||||
}
|
||||
this.describe(stop.photo, previousStop >= 0);
|
||||
if (stop.photo >= 0) {
|
||||
const photo = this.manifest.photos[stop.photo];
|
||||
this.caption.set(photo, stop.photo, this.manifest.photos.length, this.manifest.show_exif);
|
||||
@@ -606,6 +615,60 @@ export class Viewer {
|
||||
this.updateCaption();
|
||||
}
|
||||
|
||||
private describe(photoIndex: number, announce: boolean): void {
|
||||
const total = this.manifest.photos.length;
|
||||
let label: string;
|
||||
if (photoIndex < 0) {
|
||||
const next = this.nextLink.querySelector(".next-title")?.textContent ?? "";
|
||||
label = "End of album." + (next ? " Next album: " + next + "." : "");
|
||||
} else {
|
||||
const photo = this.manifest.photos[photoIndex];
|
||||
const name = photo.alt || photo.title || "";
|
||||
label = "Photo " + (photoIndex + 1) + " of " + total + (name ? ": " + name : "");
|
||||
}
|
||||
this.canvas.setAttribute("aria-label", label);
|
||||
clearTimeout(this.announceTimer);
|
||||
if (announce) {
|
||||
this.announceTimer = window.setTimeout(() => {
|
||||
this.announcer.textContent = label;
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
suspend(hidden: boolean): void {
|
||||
if (this.suspended) {
|
||||
return;
|
||||
}
|
||||
this.suspended = true;
|
||||
this.tween = null;
|
||||
for (const loader of this.loaders) {
|
||||
loader?.stop();
|
||||
}
|
||||
this.nextStrip?.loader.stop();
|
||||
this.env.scheduler.cancelAll();
|
||||
this.env.cache.trim(hidden ? 0 : this.env.cache.budget / 4);
|
||||
if (hidden) {
|
||||
this.nextStrip?.detach();
|
||||
this.canvas.width = 1;
|
||||
this.canvas.height = 1;
|
||||
this.fade.width = 1;
|
||||
this.fade.height = 1;
|
||||
}
|
||||
}
|
||||
|
||||
resume(): void {
|
||||
if (!this.suspended) {
|
||||
return;
|
||||
}
|
||||
this.suspended = false;
|
||||
this.canvas.width = 0;
|
||||
this.measure();
|
||||
this.camera = this.stops[this.current].camera;
|
||||
this.syncNextStrip();
|
||||
this.startSession();
|
||||
this.requestDraw();
|
||||
}
|
||||
|
||||
private startSession(): void {
|
||||
const stop = this.stops[this.current];
|
||||
if (stop.photo < 0) {
|
||||
@@ -723,6 +786,7 @@ export class Viewer {
|
||||
}
|
||||
if (title) {
|
||||
title.textContent = next.title;
|
||||
setLang(title as HTMLElement, next.title);
|
||||
}
|
||||
if (next.cover) {
|
||||
this.nextStrip = new Strip(
|
||||
|
||||
+40
-2
@@ -1,7 +1,10 @@
|
||||
import { unscramble, type ScrambleSpec } from "./scramble";
|
||||
|
||||
interface FetchMessage {
|
||||
type: "fetch";
|
||||
key: number;
|
||||
url: string;
|
||||
scramble?: ScrambleSpec;
|
||||
}
|
||||
|
||||
interface AbortMessage {
|
||||
@@ -25,8 +28,17 @@ interface WorkerScope {
|
||||
postMessage(message: Outgoing, transfer?: Transferable[]): void;
|
||||
}
|
||||
|
||||
interface OffscreenLike {
|
||||
getContext(kind: "2d"): CanvasRenderingContext2D | null;
|
||||
transferToImageBitmap(): ImageBitmap;
|
||||
}
|
||||
|
||||
type OffscreenConstructor = new (width: number, height: number) => OffscreenLike;
|
||||
|
||||
const scope = self as unknown as WorkerScope;
|
||||
const controllers = new Map<number, AbortController>();
|
||||
const canDecode = typeof createImageBitmap === "function";
|
||||
const Offscreen = (self as unknown as { OffscreenCanvas?: OffscreenConstructor }).OffscreenCanvas;
|
||||
|
||||
scope.onmessage = (event) => {
|
||||
const message = event.data;
|
||||
@@ -38,7 +50,29 @@ scope.onmessage = (event) => {
|
||||
void load(message);
|
||||
};
|
||||
|
||||
function restore(bitmap: ImageBitmap, spec: ScrambleSpec): ImageBitmap {
|
||||
if (!Offscreen) {
|
||||
throw new Error("unsupported-offscreen");
|
||||
}
|
||||
const canvas = new Offscreen(bitmap.width, bitmap.height);
|
||||
const g = canvas.getContext("2d");
|
||||
if (!g) {
|
||||
throw new Error("unsupported-offscreen");
|
||||
}
|
||||
unscramble(g, bitmap, bitmap.width, bitmap.height, spec);
|
||||
bitmap.close();
|
||||
return canvas.transferToImageBitmap();
|
||||
}
|
||||
|
||||
async function load(message: FetchMessage): Promise<void> {
|
||||
if (!canDecode) {
|
||||
scope.postMessage({ key: message.key, ok: false, bytes: 0, ms: 0, error: "unsupported-bitmap" });
|
||||
return;
|
||||
}
|
||||
if (message.scramble && !Offscreen) {
|
||||
scope.postMessage({ key: message.key, ok: false, bytes: 0, ms: 0, error: "unsupported-offscreen" });
|
||||
return;
|
||||
}
|
||||
const controller = new AbortController();
|
||||
controllers.set(message.key, controller);
|
||||
const started = performance.now();
|
||||
@@ -49,14 +83,18 @@ async function load(message: FetchMessage): Promise<void> {
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const ms = performance.now() - started;
|
||||
const bitmap = await createImageBitmap(blob);
|
||||
let bitmap = await createImageBitmap(blob);
|
||||
if (message.scramble) {
|
||||
bitmap = restore(bitmap, message.scramble);
|
||||
}
|
||||
if (controller.signal.aborted) {
|
||||
bitmap.close();
|
||||
throw new Error("aborted");
|
||||
}
|
||||
scope.postMessage({ key: message.key, ok: true, bitmap, bytes: blob.size, ms }, [bitmap]);
|
||||
} catch (error) {
|
||||
scope.postMessage({ key: message.key, ok: false, bytes: 0, ms: 0, error: String(error) });
|
||||
const text = error instanceof Error ? error.message : String(error);
|
||||
scope.postMessage({ key: message.key, ok: false, bytes: 0, ms: 0, error: text });
|
||||
} finally {
|
||||
controllers.delete(message.key);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user