aboutsummaryrefslogtreecommitdiff
path: root/src/web/component/timeline/index.js
blob: 0e237a1bd9cbfdb001de86fa18f83fc1dfff7190 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const container = Z.by_id('container');

function getRandomColor() {
  var letters = '0123456789ABCDEF';
  var color = '#';
  for (var i = 0; i < 6; i++) {
    color += letters[Math.floor(Math.random() * 16)];
  }
  return color;
}

for (let i = 0; i < 10000; ++i) {
	container.appendChild(Z.native('div', {
		innerText: i,
		className: 'image',
		style: {
			background: getRandomColor(),
			aspectRatio: '1 / ' + (Math.random() + 0.5),
		},
	}));
}

const zoom = new (class {
	constructor() {
		this.committed = 5;
		this.count = 5;
		container.style.gridTemplateColumns = `repeat(5, 1fr)`;
		container.classList.toggle('tiling', this.count != 1);
	}

	update(delta, point) {
		this.count += delta;
		this.count = Math.min(Math.max(this.count, 1), 20);

		const scale = this.committed / this.count;
		const rects = Z.document.getClientRects()[0];

		const x = point.x;
		const y = point.y - rects.y;

		container.style.transformOrigin = `${x}px ${y}px`;
		container.style.transform = `scale(${scale})`;

	}

	commit() {
		console.log('commit');
		this.count = Math.round(this.count);
		container.style.transform = 'scale(1)';
		container.style.gridTemplateColumns = `repeat(${this.count}, 1fr)`;
		container.classList.toggle('tiling', this.count != 1);
		this.committed = this.count;
	}
});

Z.document.onwheel = (event) => {
	if (!event.ctrlKey) {
		return;
	}
	event.preventDefault();
	zoom.update(event.wheelDeltaY / 120, { x: 0, y: 0 });
	zoom.commit();
};

const pinch = new Pinch(Z.document);
pinch.onpinch = (delta, point) => {
	zoom.update(delta / 20, point);
};

pinch.onfinish = (delta) => {
	zoom.commit();
};