-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: export Group, Layer, Slice as types only
We only want these to exist as types that users can refer to. We don't want users to directly instantiate these classes. This change breaks the original `traverseNode()` example, which was using `instanceof` to narrow a `Node` into `Psd`, `Layer`, `Group`. From now on, users now have to check the `type` field to do so. To make `traverseNode()` work, we replaced `Node` with a union type of `Psd`, `Layer`, and `Group`. We also added `NodeParent` and `NodeChild` types to better identify which types can be parents and which can be children. The original `Node` interface has been renamed to `NodeBase`.
- Loading branch information
1 parent
bcee878
commit 564b5a5
Showing
7 changed files
with
98 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @webtoon/psd | ||
// Copyright 2021-present NAVER WEBTOON | ||
// MIT License | ||
|
||
import {NodeChild, NodeParent} from "./Node"; | ||
|
||
export interface NodeBase< | ||
Parent extends NodeParent = NodeParent, | ||
Child extends NodeChild = NodeChild | ||
> { | ||
type: "Psd" | "Group" | "Layer"; | ||
name: string; | ||
parent?: Parent; | ||
children?: Child[]; | ||
opacity: number; | ||
composedOpacity: number; | ||
addChild?: (node: Child) => void; | ||
hasChildren?: () => boolean; | ||
freeze?: () => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters