-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathzoom.ts
More file actions
45 lines (35 loc) · 908 Bytes
/
zoom.ts
File metadata and controls
45 lines (35 loc) · 908 Bytes
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
import assert from "assert";
import Fraction from "fraction.js";
import { RootStore } from "../../store";
import { Action } from "../action";
/**
* Arguments for the ZoomAction.
*/
export interface ZoomArgs {
to: Fraction;
}
/**
* Action for setting the notefield zoom.
*/
export class ZoomAction implements Action {
args: ZoomArgs;
oldZoom!: Fraction;
store: RootStore;
/**
* The default scalar for zooming.
*/
static readonly SCALAR = 1.5;
constructor(store: RootStore, args: ZoomArgs) {
assert(args.to.compare(0) === 1, "zoom must be greater than zero");
this.args = args;
this.store = store;
}
run(): void {
const { notefield } = this.store;
this.oldZoom = notefield.data.zoom;
notefield.setZoom(this.args.to);
}
undo(): void {
this.store.notefield.setZoom(this.oldZoom);
}
}