1import { CanvasGroupOptions, CanvasElementOptions } from 'app/features/canvas';
2import { GroupState } from './group';
3import { Scene } from './scene';
4
5export class RootElement extends GroupState {
6  constructor(public options: CanvasGroupOptions, public scene: Scene, private changeCallback: () => void) {
7    super(options, scene);
8  }
9
10  isRoot(): this is RootElement {
11    return true;
12  }
13
14  // The parent size is always fullsize
15  updateSize(width: number, height: number) {
16    super.updateSize(width, height);
17    this.width = width;
18    this.height = height;
19    this.sizeStyle.width = width;
20    this.sizeStyle.height = height;
21  }
22
23  // root type can not change
24  onChange(options: CanvasElementOptions) {
25    this.revId++;
26    this.options = { ...options } as CanvasGroupOptions;
27    this.changeCallback();
28  }
29
30  getSaveModel() {
31    const { placement, anchor, ...rest } = this.options;
32
33    return {
34      ...rest, // everything except placement & anchor
35      elements: this.elements.map((v) => v.getSaveModel()),
36    } as CanvasGroupOptions;
37  }
38}
39