-
Notifications
You must be signed in to change notification settings - Fork 47
/
Group.ts
44 lines (38 loc) · 1.06 KB
/
Group.ts
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
// @webtoon/psd
// Copyright 2021-present NAVER WEBTOON
// MIT License
import {GroupFrame} from "../sections";
import {NodeChild, NodeParent} from "./Node";
import {NodeBase} from "./NodeBase";
/**
* A layer group, which may contain layers and other layer groups.
* @alpha
*/
export class Group implements NodeBase<NodeParent, NodeChild> {
readonly type = "Group";
readonly children: NodeChild[] = [];
/** @internal */
constructor(
private layerFrame: GroupFrame | undefined,
public readonly parent: NodeParent
) {}
get name(): string {
return this.layerFrame?.layerProperties.name ?? "";
}
get opacity(): number {
return this.layerFrame?.layerProperties.opacity ?? 0;
}
get composedOpacity(): number {
return this.parent.composedOpacity * (this.opacity / 255);
}
addChild(node: NodeChild): void {
this.children.push(node);
}
hasChildren(): boolean {
return this.children.length !== 0;
}
freeze(): void {
this.children.forEach((node) => (node as NodeBase).freeze?.());
Object.freeze(this.children);
}
}