Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7369 lines
256 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Paper.js v0.12.15 - The Swiss Army Knife of Vector Graphics Scripting.
  3. * http://paperjs.org/
  4. *
  5. * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
  6. * http://juerglehni.com/ & https://puckey.studio/
  7. *
  8. * Distributed under the MIT license. See LICENSE file for details.
  9. *
  10. * All rights reserved.
  11. *
  12. * Date: Wed Mar 17 10:49:48 2021 +0100
  13. *
  14. * This is an auto-generated type definition.
  15. */
  16. declare namespace paper {
  17. /**
  18. * All properties and functions that expect color values in the form
  19. * of instances of Color objects, also accept named colors and hex values as
  20. * strings which are then converted to instances of
  21. * {@link Color} internally.
  22. */
  23. class Color {
  24. /**
  25. * The type of the color as a string.
  26. */
  27. type: string
  28. /**
  29. * The color components that define the color, including the alpha value
  30. * if defined.
  31. */
  32. readonly components: number[]
  33. /**
  34. * The color's alpha value as a number between `0` and `1`.
  35. * All colors of the different subclasses support alpha values.
  36. */
  37. alpha: number
  38. /**
  39. * The amount of red in the color as a value between `0` and `1`.
  40. */
  41. red: number
  42. /**
  43. * The amount of green in the color as a value between `0` and `1`.
  44. */
  45. green: number
  46. /**
  47. * The amount of blue in the color as a value between `0` and `1`.
  48. */
  49. blue: number
  50. /**
  51. * The amount of gray in the color as a value between `0` and `1`.
  52. */
  53. gray: number
  54. /**
  55. * The hue of the color as a value in degrees between `0` and `360`.
  56. */
  57. hue: number
  58. /**
  59. * The saturation of the color as a value between `0` and `1`.
  60. */
  61. saturation: number
  62. /**
  63. * The brightness of the color as a value between `0` and `1`.
  64. */
  65. brightness: number
  66. /**
  67. * The lightness of the color as a value between `0` and `1`.
  68. *
  69. * Note that all other components are shared with HSB.
  70. */
  71. lightness: number
  72. /**
  73. * The gradient object describing the type of gradient and the stops.
  74. */
  75. gradient: Gradient
  76. /**
  77. * The highlight point of the gradient.
  78. */
  79. highlight: Point
  80. /**
  81. * Creates a RGB Color object.
  82. *
  83. * @param red - the amount of red in the color as a value between
  84. * `0` and `1`
  85. * @param green - the amount of green in the color as a value
  86. * between `0` and `1`
  87. * @param blue - the amount of blue in the color as a value
  88. * between `0` and `1`
  89. * @param alpha - the alpha of the color as a value between `0`
  90. * and `1`
  91. */
  92. constructor(red: number, green: number, blue: number, alpha?: number)
  93. /**
  94. * Creates a gray Color object.
  95. *
  96. * @param gray - the amount of gray in the color as a value
  97. * between `0` and `1`
  98. * @param alpha - the alpha of the color as a value between `0`
  99. * and `1`
  100. */
  101. constructor(gray: number, alpha?: number)
  102. /**
  103. * Creates a Color object from a CSS string. All common CSS color string
  104. * formats are supported:
  105. * - Named colors (e.g. `'red'`, `'fuchsia'`, …)
  106. * - Hex strings (`'#ffff00'`, `'#ff0'`, …)
  107. * - RGB strings (`'rgb(255, 128, 0)'`, `'rgba(255, 128, 0, 0.5)'`, …)
  108. * - HSL strings (`'hsl(180deg, 20%, 50%)'`,
  109. * `'hsla(3.14rad, 20%, 50%, 0.5)'`, …)
  110. *
  111. * @param color - the color's CSS string representation
  112. */
  113. constructor(color: string)
  114. /**
  115. * Creates a gradient Color object.
  116. */
  117. constructor(gradient: Gradient, origin: Point, destination: Point, highlight?: Point)
  118. /**
  119. * Creates a HSB, HSL or gradient Color object from the properties of
  120. * the provided object:
  121. *
  122. * @option hsb.hue {Number} the hue of the color as a value in degrees
  123. * between `0` and `360`
  124. * @option hsb.saturation {Number} the saturation of the color as a
  125. * value between `0` and `1`
  126. * @option hsb.brightness {Number} the brightness of the color as a
  127. * value between `0` and `1`
  128. * @option hsb.alpha {Number} the alpha of the color as a value between
  129. * `0` and `1`
  130. * @option hsl.hue {Number} the hue of the color as a value in degrees
  131. * between `0` and `360`
  132. * @option hsl.saturation {Number} the saturation of the color as a
  133. * value between `0` and `1`
  134. * @option hsl.lightness {Number} the lightness of the color as a value
  135. * between `0` and `1`<br>
  136. * @option hsl.alpha {Number} the alpha of the color as a value between
  137. * `0` and `1`
  138. * @option gradient.gradient {Gradient} the gradient object that
  139. * describes the color stops and type of gradient to be used
  140. * @option gradient.origin {Point} the origin point of the gradient
  141. * @option gradient.destination {Point} the destination point of the
  142. * gradient
  143. * @option gradient.stops {GradientStop[]} the gradient stops describing
  144. * the gradient, as an alternative to providing a gradient object
  145. * @option gradient.radial {Boolean} controls whether the gradient is
  146. * radial, as an alternative to providing a gradient object
  147. *
  148. * @param object - an object describing the components and
  149. * properties of the color
  150. */
  151. constructor(object: object)
  152. /**
  153. * Sets the color to the passed values. Note that any sequence of
  154. * parameters that is supported by the various {@link Color}
  155. * constructors also work for calls of `set()`.
  156. */
  157. set(...values: any[]): Color
  158. /**
  159. * Converts the color to another type.
  160. *
  161. * @param type - the color type to convert to. Possible values:
  162. * {@values 'rgb', 'gray', 'hsb', 'hsl'}
  163. *
  164. * @return the converted color as a new instance
  165. */
  166. convert(type: string): Color
  167. /**
  168. * Checks if the color has an alpha value.
  169. *
  170. * @return true if the color has an alpha value
  171. */
  172. hasAlpha(): boolean
  173. /**
  174. * Checks if the component color values of the color are the
  175. * same as those of the supplied one.
  176. *
  177. * @param color - the color to compare with
  178. *
  179. * @return true if the colors are the same
  180. */
  181. equals(color: Color): boolean
  182. /**
  183. * @return a copy of the color object
  184. */
  185. clone(): Color
  186. /**
  187. * @return a string representation of the color
  188. */
  189. toString(): string
  190. /**
  191. * Returns the color as a CSS string.
  192. *
  193. * @param hex - whether to return the color in hexadecimal
  194. * representation or as a CSS RGB / RGBA string.
  195. *
  196. * @return a CSS string representation of the color
  197. */
  198. toCSS(hex: boolean): string
  199. /**
  200. * Transform the gradient color by the specified matrix.
  201. *
  202. * @param matrix - the matrix to transform the gradient color by
  203. */
  204. transform(matrix: Matrix): void
  205. /**
  206. * Returns a color object with random {@link #red}, {@link #green}
  207. * and {@link #blue} values between `0` and `1`.
  208. *
  209. * @return the newly created color object
  210. */
  211. static random(): Color
  212. /**
  213. * Returns the addition of the supplied value to both coordinates of
  214. * the color as a new color.
  215. * The object itself is not modified!
  216. *
  217. * @param number - the number to add
  218. *
  219. * @return the addition of the color and the value as a new
  220. * color
  221. */
  222. add(number: number): Color
  223. /**
  224. * Returns the addition of the supplied color to the color as a new
  225. * color.
  226. * The object itself is not modified!
  227. *
  228. * @param color - the color to add
  229. *
  230. * @return the addition of the two colors as a new color
  231. */
  232. add(color: Color): Color
  233. /**
  234. * Returns the subtraction of the supplied value to both coordinates of
  235. * the color as a new color.
  236. * The object itself is not modified!
  237. *
  238. * @param number - the number to subtract
  239. *
  240. * @return the subtraction of the color and the value as a new
  241. * color
  242. */
  243. subtract(number: number): Color
  244. /**
  245. * Returns the subtraction of the supplied color to the color as a new
  246. * color.
  247. * The object itself is not modified!
  248. *
  249. * @param color - the color to subtract
  250. *
  251. * @return the subtraction of the two colors as a new color
  252. */
  253. subtract(color: Color): Color
  254. /**
  255. * Returns the multiplication of the supplied value to both coordinates
  256. * of the color as a new color.
  257. * The object itself is not modified!
  258. *
  259. * @param number - the number to multiply
  260. *
  261. * @return the multiplication of the color and the value as a
  262. * new color
  263. */
  264. multiply(number: number): Color
  265. /**
  266. * Returns the multiplication of the supplied color to the color as a
  267. * new color.
  268. * The object itself is not modified!
  269. *
  270. * @param color - the color to multiply
  271. *
  272. * @return the multiplication of the two colors as a new color
  273. */
  274. multiply(color: Color): Color
  275. /**
  276. * Returns the division of the supplied value to both coordinates of
  277. * the color as a new color.
  278. * The object itself is not modified!
  279. *
  280. * @param number - the number to divide
  281. *
  282. * @return the division of the color and the value as a new
  283. * color
  284. */
  285. divide(number: number): Color
  286. /**
  287. * Returns the division of the supplied color to the color as a new
  288. * color.
  289. * The object itself is not modified!
  290. *
  291. * @param color - the color to divide
  292. *
  293. * @return the division of the two colors as a new color
  294. */
  295. divide(color: Color): Color
  296. }
  297. /**
  298. * A compound path is a complex path that is made up of one or more
  299. * simple sub-paths. It can have the `nonzero` fill rule, or the `evenodd` rule
  300. * applied. Both rules use mathematical equations to determine if any region is
  301. * outside or inside the final shape. The `evenodd` rule is more predictable:
  302. * Every other region within a such a compound path is a hole, regardless of
  303. * path direction.
  304. *
  305. * All the paths in a compound path take on the style of the compound path and
  306. * can be accessed through its {@link Item#children} list.
  307. */
  308. class CompoundPath extends PathItem {
  309. /**
  310. * Specifies whether the compound-path is fully closed, meaning all its
  311. * contained sub-paths are closed path.
  312. *
  313. * @see Path#closed
  314. */
  315. closed: boolean
  316. /**
  317. * The first Segment contained within the compound-path, a short-cut to
  318. * calling {@link Path#firstSegment} on {@link Item#firstChild}.
  319. */
  320. readonly firstSegment: Segment
  321. /**
  322. * The last Segment contained within the compound-path, a short-cut to
  323. * calling {@link Path#lastSegment} on {@link Item#lastChild}.
  324. */
  325. readonly lastSegment: Segment
  326. /**
  327. * All the curves contained within the compound-path, from all its child
  328. * {@link Path} items.
  329. */
  330. readonly curves: Curve[]
  331. /**
  332. * The first Curve contained within the compound-path, a short-cut to
  333. * calling {@link Path#firstCurve} on {@link Item#firstChild}.
  334. */
  335. readonly firstCurve: Curve
  336. /**
  337. * The last Curve contained within the compound-path, a short-cut to
  338. * calling {@link Path#lastCurve} on {@link Item#lastChild}.
  339. */
  340. readonly lastCurve: Curve
  341. /**
  342. * The area that the compound-path's geometry is covering, calculated by
  343. * getting the {@link Path#area} of each sub-path and it adding up.
  344. * Note that self-intersecting paths and sub-paths of different orientation
  345. * can result in areas that cancel each other out.
  346. */
  347. readonly area: number
  348. /**
  349. * The total length of all sub-paths in this compound-path, calculated by
  350. * getting the {@link Path#length} of each sub-path and it adding up.
  351. */
  352. readonly length: number
  353. /**
  354. * Creates a new compound path item from SVG path-data and places it at the
  355. * top of the active layer.
  356. *
  357. * @param pathData - the SVG path-data that describes the geometry
  358. * of this path
  359. */
  360. constructor(pathData: string)
  361. /**
  362. * Creates a new compound path item from an object description and places it
  363. * at the top of the active layer.
  364. *
  365. * @param object - an object containing properties to be set on the
  366. * path
  367. */
  368. constructor(object: object)
  369. }
  370. /**
  371. * The Curve object represents the parts of a path that are connected by
  372. * two following {@link Segment} objects. The curves of a path can be accessed
  373. * through its {@link Path#curves} array.
  374. *
  375. * While a segment describe the anchor point and its incoming and outgoing
  376. * handles, a Curve object describes the curve passing between two such
  377. * segments. Curves and segments represent two different ways of looking at the
  378. * same thing, but focusing on different aspects. Curves for example offer many
  379. * convenient ways to work with parts of the path, finding lengths, positions or
  380. * tangents at given offsets.
  381. */
  382. class Curve {
  383. /**
  384. * The first anchor point of the curve.
  385. */
  386. point1: Point
  387. /**
  388. * The second anchor point of the curve.
  389. */
  390. point2: Point
  391. /**
  392. * The handle point that describes the tangent in the first anchor point.
  393. */
  394. handle1: Point
  395. /**
  396. * The handle point that describes the tangent in the second anchor point.
  397. */
  398. handle2: Point
  399. /**
  400. * The first segment of the curve.
  401. */
  402. readonly segment1: Segment
  403. /**
  404. * The second segment of the curve.
  405. */
  406. readonly segment2: Segment
  407. /**
  408. * The path that the curve belongs to.
  409. */
  410. readonly path: Path
  411. /**
  412. * The index of the curve in the {@link Path#curves} array.
  413. */
  414. readonly index: number
  415. /**
  416. * The next curve in the {@link Path#curves} array that the curve
  417. * belongs to.
  418. */
  419. readonly next: Curve
  420. /**
  421. * The previous curve in the {@link Path#curves} array that the curve
  422. * belongs to.
  423. */
  424. readonly previous: Curve
  425. /**
  426. * Specifies whether the points and handles of the curve are selected.
  427. */
  428. selected: boolean
  429. /**
  430. * An array of 8 float values, describing this curve's geometry in four
  431. * absolute x/y pairs (point1, handle1, handle2, point2). This format is
  432. * used internally for efficient processing of curve geometries, e.g. when
  433. * calculating intersections or bounds.
  434. *
  435. * Note that the handles are converted to absolute coordinates.
  436. */
  437. readonly values: number[]
  438. /**
  439. * An array of 4 point objects, describing this curve's geometry in absolute
  440. * coordinates (point1, handle1, handle2, point2).
  441. *
  442. * Note that the handles are converted to absolute coordinates.
  443. */
  444. readonly points: Point[]
  445. /**
  446. * The approximated length of the curve.
  447. */
  448. readonly length: number
  449. /**
  450. * The area that the curve's geometry is covering.
  451. */
  452. readonly area: number
  453. /**
  454. * The bounding rectangle of the curve excluding stroke width.
  455. */
  456. bounds: Rectangle
  457. /**
  458. * The bounding rectangle of the curve including stroke width.
  459. */
  460. strokeBounds: Rectangle
  461. /**
  462. * The bounding rectangle of the curve including handles.
  463. */
  464. handleBounds: Rectangle
  465. /**
  466. * Creates a new curve object.
  467. */
  468. constructor(segment1: Segment, segment2: Segment)
  469. /**
  470. * Creates a new curve object.
  471. */
  472. constructor(point1: Point, handle1: Point, handle2: Point, point2: Point)
  473. /**
  474. * Returns a copy of the curve.
  475. */
  476. clone(): Curve
  477. /**
  478. * @return a string representation of the curve
  479. */
  480. toString(): string
  481. /**
  482. * Determines the type of cubic Bézier curve via discriminant
  483. * classification, as well as the curve-time parameters of the associated
  484. * points of inflection, loops, cusps, etc.
  485. *
  486. * @return the curve classification information as an object, see
  487. * options
  488. */
  489. classify(): object
  490. /**
  491. * Removes the curve from the path that it belongs to, by removing its
  492. * second segment and merging its handle with the first segment.
  493. *
  494. * @return true if the curve was removed
  495. */
  496. remove(): boolean
  497. /**
  498. * Checks if the this is the first curve in the {@link Path#curves} array.
  499. *
  500. * @return true if this is the first curve
  501. */
  502. isFirst(): boolean
  503. /**
  504. * Checks if the this is the last curve in the {@link Path#curves} array.
  505. *
  506. * @return true if this is the last curve
  507. */
  508. isLast(): boolean
  509. /**
  510. * Creates a new curve as a sub-curve from this curve, its range defined by
  511. * the given curve-time parameters. If `from` is larger than `to`, then
  512. * the resulting curve will have its direction reversed.
  513. *
  514. * @param from - the curve-time parameter at which the sub-curve
  515. * starts
  516. * @param to - the curve-time parameter at which the sub-curve
  517. * ends
  518. *
  519. * @return the newly create sub-curve
  520. */
  521. getPart(from: number, to: number): Curve
  522. /**
  523. * Divides the curve into two curves at the given offset or location. The
  524. * curve itself is modified and becomes the first part, the second part is
  525. * returned as a new curve. If the curve belongs to a path item, a new
  526. * segment is inserted into the path at the given location, and the second
  527. * part becomes a part of the path as well.
  528. *
  529. * @see #divideAtTime(time)
  530. *
  531. * @param location - the offset or location on the
  532. * curve at which to divide
  533. *
  534. * @return the second part of the divided curve if the location is
  535. * valid, {code null} otherwise
  536. */
  537. divideAt(location: number | CurveLocation): Curve
  538. /**
  539. * Divides the curve into two curves at the given curve-time parameter. The
  540. * curve itself is modified and becomes the first part, the second part is
  541. * returned as a new curve. If the modified curve belongs to a path item,
  542. * the second part is also added to the path.
  543. *
  544. * @see #divideAt(offset)
  545. *
  546. * @param time - the curve-time parameter on the curve at which to
  547. * divide
  548. *
  549. * @return the second part of the divided curve, if the offset is
  550. * within the valid range, {code null} otherwise.
  551. */
  552. divideAtTime(time: number): Curve
  553. /**
  554. * Splits the path this curve belongs to at the given offset. After
  555. * splitting, the path will be open. If the path was open already, splitting
  556. * will result in two paths.
  557. *
  558. * @see Path#splitAt(offset)
  559. *
  560. * @param location - the offset or location on the
  561. * curve at which to split
  562. *
  563. * @return the newly created path after splitting, if any
  564. */
  565. splitAt(location: number | CurveLocation): Path
  566. /**
  567. * Splits the path this curve belongs to at the given offset. After
  568. * splitting, the path will be open. If the path was open already, splitting
  569. * will result in two paths.
  570. *
  571. * @see Path#splitAt(offset)
  572. *
  573. * @param time - the curve-time parameter on the curve at which to
  574. * split
  575. *
  576. * @return the newly created path after splitting, if any
  577. */
  578. splitAtTime(time: number): Path
  579. /**
  580. * Returns a reversed version of the curve, without modifying the curve
  581. * itself.
  582. *
  583. * @return a reversed version of the curve
  584. */
  585. reversed(): Curve
  586. /**
  587. * Clears the curve's handles by setting their coordinates to zero,
  588. * turning the curve into a straight line.
  589. */
  590. clearHandles(): void
  591. /**
  592. * Checks if this curve has any curve handles set.
  593. *
  594. * @see Curve#handle1
  595. * @see Curve#handle2
  596. * @see Segment#hasHandles()
  597. * @see Path#hasHandles()
  598. *
  599. * @return true if the curve has handles set
  600. */
  601. hasHandles(): boolean
  602. /**
  603. * Checks if this curve has any length.
  604. *
  605. * @param epsilon - the epsilon against which to compare the
  606. * curve's length
  607. *
  608. * @return true if the curve is longer than the given epsilon
  609. */
  610. hasLength(epsilon?: number): boolean
  611. /**
  612. * Checks if this curve appears as a straight line. This can mean that
  613. * it has no handles defined, or that the handles run collinear with the
  614. * line that connects the curve's start and end point, not falling
  615. * outside of the line.
  616. *
  617. * @return true if the curve is straight
  618. */
  619. isStraight(): boolean
  620. /**
  621. * Checks if this curve is parametrically linear, meaning that it is
  622. * straight and its handles are positioned at 1/3 and 2/3 of the total
  623. * length of the curve.
  624. *
  625. * @return true if the curve is parametrically linear
  626. */
  627. isLinear(): boolean
  628. /**
  629. * Checks if the the two curves describe straight lines that are
  630. * collinear, meaning they run in parallel.
  631. *
  632. * @param curve - the other curve to check against
  633. *
  634. * @return true if the two lines are collinear
  635. */
  636. isCollinear(curve: Curve): boolean
  637. /**
  638. * Checks if the curve is a straight horizontal line.
  639. *
  640. * @return true if the line is horizontal
  641. */
  642. isHorizontal(): boolean
  643. /**
  644. * Checks if the curve is a straight vertical line.
  645. *
  646. * @return true if the line is vertical
  647. */
  648. isVertical(): boolean
  649. /**
  650. * Calculates the curve location at the specified offset on the curve.
  651. *
  652. * @param offset - the offset on the curve
  653. *
  654. * @return the curve location at the specified the offset
  655. */
  656. getLocationAt(offset: number): CurveLocation
  657. /**
  658. * Calculates the curve location at the specified curve-time parameter on
  659. * the curve.
  660. *
  661. * @param time - the curve-time parameter on the curve
  662. *
  663. * @return the curve location at the specified the location
  664. */
  665. getLocationAtTime(time: number): CurveLocation
  666. /**
  667. * Calculates the curve-time parameter of the specified offset on the path,
  668. * relative to the provided start parameter. If offset is a negative value,
  669. * the parameter is searched to the left of the start parameter. If no start
  670. * parameter is provided, a default of `0` for positive values of `offset`
  671. * and `1` for negative values of `offset`.
  672. *
  673. * @param offset - the offset at which to find the curve-time, in
  674. * curve length units
  675. * @param start - the curve-time in relation to which the offset is
  676. * determined
  677. *
  678. * @return the curve-time parameter at the specified location
  679. */
  680. getTimeAt(offset: number, start?: number): number
  681. /**
  682. * Calculates the curve-time parameters where the curve is tangential to
  683. * provided tangent. Note that tangents at the start or end are included.
  684. *
  685. * @param tangent - the tangent to which the curve must be tangential
  686. *
  687. * @return at most two curve-time parameters, where the curve is
  688. * tangential to the given tangent
  689. */
  690. getTimesWithTangent(tangent: Point): number[]
  691. /**
  692. * Calculates the curve offset at the specified curve-time parameter on
  693. * the curve.
  694. *
  695. * @param time - the curve-time parameter on the curve
  696. *
  697. * @return the curve offset at the specified the location
  698. */
  699. getOffsetAtTime(time: number): number
  700. /**
  701. * Returns the curve location of the specified point if it lies on the
  702. * curve, `null` otherwise.
  703. *
  704. * @param point - the point on the curve
  705. *
  706. * @return the curve location of the specified point
  707. */
  708. getLocationOf(point: Point): CurveLocation
  709. /**
  710. * Returns the length of the path from its beginning up to up to the
  711. * specified point if it lies on the path, `null` otherwise.
  712. *
  713. * @param point - the point on the path
  714. *
  715. * @return the length of the path up to the specified point
  716. */
  717. getOffsetOf(point: Point): number
  718. /**
  719. * Returns the curve-time parameter of the specified point if it lies on the
  720. * curve, `null` otherwise.
  721. * Note that if there is more than one possible solution in a
  722. * self-intersecting curve, the first found result is returned.
  723. *
  724. * @param point - the point on the curve
  725. *
  726. * @return the curve-time parameter of the specified point
  727. */
  728. getTimeOf(point: Point): number
  729. /**
  730. * Returns the nearest location on the curve to the specified point.
  731. *
  732. * @param point - the point for which we search the nearest location
  733. *
  734. * @return the location on the curve that's the closest to
  735. * the specified point
  736. */
  737. getNearestLocation(point: Point): CurveLocation
  738. /**
  739. * Returns the nearest point on the curve to the specified point.
  740. *
  741. * @param point - the point for which we search the nearest point
  742. *
  743. * @return the point on the curve that's the closest to the
  744. * specified point
  745. */
  746. getNearestPoint(point: Point): Point
  747. /**
  748. * Calculates the point on the curve at the given location.
  749. *
  750. * @param location - the offset or location on the
  751. * curve
  752. *
  753. * @return the point on the curve at the given location
  754. */
  755. getPointAt(location: number | CurveLocation): Point
  756. /**
  757. * Calculates the normalized tangent vector of the curve at the given
  758. * location.
  759. *
  760. * @param location - the offset or location on the
  761. * curve
  762. *
  763. * @return the normalized tangent of the curve at the given location
  764. */
  765. getTangentAt(location: number | CurveLocation): Point
  766. /**
  767. * Calculates the normal vector of the curve at the given location.
  768. *
  769. * @param location - the offset or location on the
  770. * curve
  771. *
  772. * @return the normal of the curve at the given location
  773. */
  774. getNormalAt(location: number | CurveLocation): Point
  775. /**
  776. * Calculates the weighted tangent vector of the curve at the given
  777. * location, its length reflecting the curve velocity at that location.
  778. *
  779. * @param location - the offset or location on the
  780. * curve
  781. *
  782. * @return the weighted tangent of the curve at the given location
  783. */
  784. getWeightedTangentAt(location: number | CurveLocation): Point
  785. /**
  786. * Calculates the weighted normal vector of the curve at the given location,
  787. * its length reflecting the curve velocity at that location.
  788. *
  789. * @param location - the offset or location on the
  790. * curve
  791. *
  792. * @return the weighted normal of the curve at the given location
  793. */
  794. getWeightedNormalAt(location: number | CurveLocation): Point
  795. /**
  796. * Calculates the curvature of the curve at the given location. Curvatures
  797. * indicate how sharply a curve changes direction. A straight line has zero
  798. * curvature, where as a circle has a constant curvature. The curve's radius
  799. * at the given location is the reciprocal value of its curvature.
  800. *
  801. * @param location - the offset or location on the
  802. * curve
  803. *
  804. * @return the curvature of the curve at the given location
  805. */
  806. getCurvatureAt(location: number | CurveLocation): number
  807. /**
  808. * Calculates the point on the curve at the given location.
  809. *
  810. * @param time - the curve-time parameter on the curve
  811. *
  812. * @return the point on the curve at the given location
  813. */
  814. getPointAtTime(time: number): Point
  815. /**
  816. * Calculates the normalized tangent vector of the curve at the given
  817. * location.
  818. *
  819. * @param time - the curve-time parameter on the curve
  820. *
  821. * @return the normalized tangent of the curve at the given location
  822. */
  823. getTangentAtTime(time: number): Point
  824. /**
  825. * Calculates the normal vector of the curve at the given location.
  826. *
  827. * @param time - the curve-time parameter on the curve
  828. *
  829. * @return the normal of the curve at the given location
  830. */
  831. getNormalAtTime(time: number): Point
  832. /**
  833. * Calculates the weighted tangent vector of the curve at the given
  834. * location, its length reflecting the curve velocity at that location.
  835. *
  836. * @param time - the curve-time parameter on the curve
  837. *
  838. * @return the weighted tangent of the curve at the given location
  839. */
  840. getWeightedTangentAtTime(time: number): Point
  841. /**
  842. * Calculates the weighted normal vector of the curve at the given location,
  843. * its length reflecting the curve velocity at that location.
  844. *
  845. * @param time - the curve-time parameter on the curve
  846. *
  847. * @return the weighted normal of the curve at the given location
  848. */
  849. getWeightedNormalAtTime(time: number): Point
  850. /**
  851. * Calculates the curvature of the curve at the given location. Curvatures
  852. * indicate how sharply a curve changes direction. A straight line has zero
  853. * curvature, where as a circle has a constant curvature. The curve's radius
  854. * at the given location is the reciprocal value of its curvature.
  855. *
  856. * @param time - the curve-time parameter on the curve
  857. *
  858. * @return the curvature of the curve at the given location
  859. */
  860. getCurvatureAtTime(time: number): number
  861. /**
  862. * Returns all intersections between two {@link Curve} objects as an
  863. * array of {@link CurveLocation} objects.
  864. *
  865. * @param curve - the other curve to find the intersections with
  866. * (if the curve itself or `null` is passed, the self intersection
  867. * of the curve is returned, if it exists)
  868. *
  869. * @return the locations of all intersections between
  870. * the curves
  871. */
  872. getIntersections(curve: Curve): CurveLocation[]
  873. }
  874. /**
  875. * CurveLocation objects describe a location on {@link Curve} objects, as
  876. * defined by the curve-time {@link #time}, a value between `0` (beginning
  877. * of the curve) and `1` (end of the curve). If the curve is part of a
  878. * {@link Path} item, its {@link #index} inside the {@link Path#curves}
  879. * array is also provided.
  880. *
  881. * The class is in use in many places, such as
  882. * {@link Path#getLocationAt},
  883. * {@link Path#getLocationOf},
  884. * {@link PathItem#getNearestLocation},
  885. * {@link PathItem#getIntersections},
  886. * etc.
  887. */
  888. class CurveLocation {
  889. /**
  890. * The segment of the curve which is closer to the described location.
  891. */
  892. readonly segment: Segment
  893. /**
  894. * The curve that this location belongs to.
  895. */
  896. readonly curve: Curve
  897. /**
  898. * The path that this locations is situated on.
  899. */
  900. readonly path: Path
  901. /**
  902. * The index of the {@link #curve} within the {@link Path#curves} list, if
  903. * it is part of a {@link Path} item.
  904. */
  905. readonly index: number
  906. /**
  907. * The curve-time parameter, as used by various bezier curve calculations.
  908. * It is value between `0` (beginning of the curve) and `1` (end of the
  909. * curve).
  910. */
  911. readonly time: number
  912. /**
  913. * The point which is defined by the {@link #curve} and
  914. * {@link #time}.
  915. */
  916. readonly point: Point
  917. /**
  918. * The length of the path from its beginning up to the location described
  919. * by this object. If the curve is not part of a path, then the length
  920. * within the curve is returned instead.
  921. */
  922. readonly offset: number
  923. /**
  924. * The length of the curve from its beginning up to the location described
  925. * by this object.
  926. */
  927. readonly curveOffset: number
  928. /**
  929. * The curve location on the intersecting curve, if this location is the
  930. * result of a call to {@link PathItem#getIntersections} /
  931. * {@link Curve#getIntersections}.
  932. */
  933. readonly intersection: CurveLocation
  934. /**
  935. * The tangential vector to the {@link #curve} at the given location.
  936. */
  937. readonly tangent: Point
  938. /**
  939. * The normal vector to the {@link #curve} at the given location.
  940. */
  941. readonly normal: Point
  942. /**
  943. * The curvature of the {@link #curve} at the given location.
  944. */
  945. readonly curvature: number
  946. /**
  947. * The distance from the queried point to the returned location.
  948. *
  949. * @see Curve#getNearestLocation(point)
  950. * @see PathItem#getNearestLocation(point)
  951. */
  952. readonly distance: number
  953. /**
  954. * Creates a new CurveLocation object.
  955. */
  956. constructor(curve: Curve, time: number, point?: Point)
  957. /**
  958. * Checks whether tow CurveLocation objects are describing the same location
  959. * on a path, by applying the same tolerances as elsewhere when dealing with
  960. * curve-time parameters.
  961. *
  962. * @return true if the locations are equal
  963. */
  964. equals(location: CurveLocation): boolean
  965. /**
  966. * @return a string representation of the curve location
  967. */
  968. toString(): string
  969. /**
  970. * Checks if the location is an intersection with another curve and is
  971. * merely touching the other curve, as opposed to crossing it.
  972. *
  973. * @see #isCrossing()
  974. *
  975. * @return true if the location is an intersection that is
  976. * merely touching another curve
  977. */
  978. isTouching(): boolean
  979. /**
  980. * Checks if the location is an intersection with another curve and is
  981. * crossing the other curve, as opposed to just touching it.
  982. *
  983. * @see #isTouching()
  984. *
  985. * @return true if the location is an intersection that is
  986. * crossing another curve
  987. */
  988. isCrossing(): boolean
  989. /**
  990. * Checks if the location is an intersection with another curve and is
  991. * part of an overlap between the two involved paths.
  992. *
  993. * @see #isCrossing()
  994. * @see #isTouching()
  995. *
  996. * @return true if the location is an intersection that is
  997. * part of an overlap between the two involved paths
  998. */
  999. hasOverlap(): boolean
  1000. }
  1001. /**
  1002. * The Event object is the base class for any of the other event types,
  1003. * such as {@link MouseEvent}, {@link ToolEvent} and {@link KeyEvent}.
  1004. */
  1005. class Event {
  1006. /**
  1007. * The time at which the event was created, in milliseconds since the epoch.
  1008. */
  1009. readonly timeStamp: number
  1010. /**
  1011. * The current state of the keyboard modifiers.
  1012. *
  1013. * @see Key.modifiers
  1014. */
  1015. readonly modifiers: any
  1016. /**
  1017. * Cancels the event if it is cancelable, without stopping further
  1018. * propagation of the event.
  1019. */
  1020. preventDefault(): void
  1021. /**
  1022. * Prevents further propagation of the current event.
  1023. */
  1024. stopPropagation(): void
  1025. /**
  1026. * Cancels the event if it is cancelable, and stops stopping further
  1027. * propagation of the event. This is has the same effect as calling both
  1028. * {@link #stopPropagation} and {@link #preventDefault}.
  1029. *
  1030. * Any handler can also return `false` to indicate that `stop()` should be
  1031. * called right after.
  1032. */
  1033. stop(): void
  1034. }
  1035. /**
  1036. * The Gradient object.
  1037. */
  1038. class Gradient {
  1039. /**
  1040. * The gradient stops on the gradient ramp.
  1041. */
  1042. stops: GradientStop[]
  1043. /**
  1044. * Specifies whether the gradient is radial or linear.
  1045. */
  1046. radial: boolean
  1047. /**
  1048. * @return a copy of the gradient
  1049. */
  1050. clone(): Gradient
  1051. /**
  1052. * Checks whether the gradient is equal to the supplied gradient.
  1053. *
  1054. * @return true if they are equal
  1055. */
  1056. equals(gradient: Gradient): boolean
  1057. }
  1058. /**
  1059. * The GradientStop object.
  1060. */
  1061. class GradientStop {
  1062. /**
  1063. * The ramp-point of the gradient stop as a value between `0` and `1`.
  1064. */
  1065. offset: number
  1066. /**
  1067. * The color of the gradient stop.
  1068. */
  1069. color: Color
  1070. /**
  1071. * Creates a GradientStop object.
  1072. *
  1073. * @param color - the color of the stop
  1074. * @param offset - the position of the stop on the gradient
  1075. * ramp as a value between `0` and `1`; `null` or `undefined` for automatic
  1076. * assignment.
  1077. */
  1078. constructor(color?: Color, offset?: number)
  1079. /**
  1080. * @return a copy of the gradient-stop
  1081. */
  1082. clone(): GradientStop
  1083. }
  1084. /**
  1085. * A Group is a collection of items. When you transform a Group, its
  1086. * children are treated as a single unit without changing their relative
  1087. * positions.
  1088. */
  1089. class Group extends Item {
  1090. /**
  1091. * Specifies whether the group item is to be clipped. When setting to
  1092. * `true`, the first child in the group is automatically defined as the
  1093. * clipping mask.
  1094. */
  1095. clipped: boolean
  1096. /**
  1097. * Creates a new Group item and places it at the top of the active layer.
  1098. *
  1099. * @param children - An array of children that will be added to the
  1100. * newly created group
  1101. */
  1102. constructor(children?: Item[])
  1103. /**
  1104. * Creates a new Group item and places it at the top of the active layer.
  1105. *
  1106. * @param object - an object containing the properties to be set on
  1107. * the group
  1108. */
  1109. constructor(object: object)
  1110. }
  1111. /**
  1112. * A HitResult object contains information about the results of a hit
  1113. * test. It is returned by {@link Item#hitTest} and
  1114. * {@link Project#hitTest}.
  1115. */
  1116. class HitResult {
  1117. /**
  1118. * Describes the type of the hit result. For example, if you hit a segment
  1119. * point, the type would be `'segment'`.
  1120. */
  1121. type: string
  1122. /**
  1123. * If the HitResult has a {@link HitResult#type} of `'bounds'`, this
  1124. * property describes which corner of the bounding rectangle was hit.
  1125. */
  1126. name: string
  1127. /**
  1128. * The item that was hit.
  1129. */
  1130. item: Item
  1131. /**
  1132. * If the HitResult has a type of 'curve' or 'stroke', this property gives
  1133. * more information about the exact position that was hit on the path.
  1134. */
  1135. location: CurveLocation
  1136. /**
  1137. * If the HitResult has a type of 'pixel', this property refers to the color
  1138. * of the pixel on the {@link Raster} that was hit.
  1139. */
  1140. color: Color | null
  1141. /**
  1142. * If the HitResult has a type of 'stroke', 'segment', 'handle-in' or
  1143. * 'handle-out', this property refers to the segment that was hit or that
  1144. * is closest to the hitResult.location on the curve.
  1145. */
  1146. segment: Segment
  1147. /**
  1148. * Describes the actual coordinates of the segment, handle or bounding box
  1149. * corner that was hit.
  1150. */
  1151. point: Point
  1152. }
  1153. /**
  1154. * The Item type allows you to access and modify the items in
  1155. * Paper.js projects. Its functionality is inherited by different project
  1156. * item types such as {@link Path}, {@link CompoundPath}, {@link Group},
  1157. * {@link Layer} and {@link Raster}. They each add a layer of functionality that
  1158. * is unique to their type, but share the underlying properties and functions
  1159. * that they inherit from Item.
  1160. */
  1161. class Item {
  1162. /**
  1163. * The unique id of the item.
  1164. */
  1165. readonly id: number
  1166. /**
  1167. * The class name of the item as a string.
  1168. */
  1169. className: string
  1170. /**
  1171. * The name of the item. If the item has a name, it can be accessed by name
  1172. * through its parent's children list.
  1173. */
  1174. name: string
  1175. /**
  1176. * The path style of the item.
  1177. */
  1178. style: Style
  1179. /**
  1180. * Specifies whether the item is locked. When set to `true`, item
  1181. * interactions with the mouse are disabled.
  1182. */
  1183. locked: boolean
  1184. /**
  1185. * Specifies whether the item is visible. When set to `false`, the item
  1186. * won't be drawn.
  1187. */
  1188. visible: boolean
  1189. /**
  1190. * The blend mode with which the item is composited onto the canvas. Both
  1191. * the standard canvas compositing modes, as well as the new CSS blend modes
  1192. * are supported. If blend-modes cannot be rendered natively, they are
  1193. * emulated. Be aware that emulation can have an impact on performance.
  1194. */
  1195. blendMode: string
  1196. /**
  1197. * The opacity of the item as a value between `0` and `1`.
  1198. */
  1199. opacity: number
  1200. /**
  1201. * Specifies whether the item is selected. This will also return `true` for
  1202. * {@link Group} items if they are partially selected, e.g. groups
  1203. * containing selected or partially selected paths.
  1204. *
  1205. * Paper.js draws the visual outlines of selected items on top of your
  1206. * project. This can be useful for debugging, as it allows you to see the
  1207. * construction of paths, position of path curves, individual segment points
  1208. * and bounding boxes of symbol and raster items.
  1209. *
  1210. * @see Project#selectedItems
  1211. * @see Segment#selected
  1212. * @see Curve#selected
  1213. * @see Point#selected
  1214. */
  1215. selected: boolean
  1216. /**
  1217. * Specifies whether the item defines a clip mask. This can only be set on
  1218. * paths and compound paths, and only if the item is already contained
  1219. * within a clipping group.
  1220. */
  1221. clipMask: boolean
  1222. /**
  1223. * A plain javascript object which can be used to store
  1224. * arbitrary data on the item.
  1225. */
  1226. data: any
  1227. /**
  1228. * The item's position within the parent item's coordinate system. By
  1229. * default, this is the {@link Rectangle#center} of the item's
  1230. * {@link #bounds} rectangle.
  1231. */
  1232. position: Point
  1233. /**
  1234. * The item's pivot point specified in the item coordinate system, defining
  1235. * the point around which all transformations are hinging. This is also the
  1236. * reference point for {@link #position}. By default, it is set to `null`,
  1237. * meaning the {@link Rectangle#center} of the item's {@link #bounds}
  1238. * rectangle is used as pivot.
  1239. */
  1240. pivot: Point
  1241. /**
  1242. * The bounding rectangle of the item excluding stroke width.
  1243. */
  1244. bounds: Rectangle
  1245. /**
  1246. * The bounding rectangle of the item including stroke width.
  1247. */
  1248. strokeBounds: Rectangle
  1249. /**
  1250. * The bounding rectangle of the item including handles.
  1251. */
  1252. handleBounds: Rectangle
  1253. /**
  1254. * The bounding rectangle of the item without any matrix transformations.
  1255. *
  1256. * Typical use case would be drawing a frame around the object where you
  1257. * want to draw something of the same size, position, rotation, and scaling,
  1258. * like a selection frame.
  1259. */
  1260. internalBounds: Rectangle
  1261. /**
  1262. * The current rotation angle of the item, as described by its
  1263. * {@link #matrix}.
  1264. * Please note that this only returns meaningful values for items with
  1265. * {@link #applyMatrix} set to `false`, meaning they do not directly bake
  1266. * transformations into their content.
  1267. */
  1268. rotation: number
  1269. /**
  1270. * The current scale factor of the item, as described by its
  1271. * {@link #matrix}.
  1272. * Please note that this only returns meaningful values for items with
  1273. * {@link #applyMatrix} set to `false`, meaning they do not directly bake
  1274. * transformations into their content.
  1275. */
  1276. scaling: Point
  1277. /**
  1278. * The item's transformation matrix, defining position and dimensions in
  1279. * relation to its parent item in which it is contained.
  1280. */
  1281. matrix: Matrix
  1282. /**
  1283. * The item's global transformation matrix in relation to the global project
  1284. * coordinate space. Note that the view's transformations resulting from
  1285. * zooming and panning are not factored in.
  1286. */
  1287. readonly globalMatrix: Matrix
  1288. /**
  1289. * The item's global matrix in relation to the view coordinate space. This
  1290. * means that the view's transformations resulting from zooming and panning
  1291. * are factored in.
  1292. */
  1293. readonly viewMatrix: Matrix
  1294. /**
  1295. * Controls whether the transformations applied to the item (e.g. through
  1296. * {@link #transform}, {@link #rotate},
  1297. * {@link #scale}, etc.) are stored in its {@link #matrix} property,
  1298. * or whether they are directly applied to its contents or children (passed
  1299. * on to the segments in {@link Path} items, the children of {@link Group}
  1300. * items, etc.).
  1301. */
  1302. applyMatrix: boolean
  1303. /**
  1304. * The project that this item belongs to.
  1305. */
  1306. readonly project: Project
  1307. /**
  1308. * The view that this item belongs to.
  1309. */
  1310. readonly view: View
  1311. /**
  1312. * The layer that this item is contained within.
  1313. */
  1314. readonly layer: Layer
  1315. /**
  1316. * The item that this item is contained within.
  1317. */
  1318. parent: Item
  1319. /**
  1320. * The children items contained within this item. Items that define a
  1321. * {@link #name} can also be accessed by name.
  1322. *
  1323. * <b>Please note:</b> The children array should not be modified directly
  1324. * using array functions. To remove single items from the children list, use
  1325. * {@link Item#remove}, to remove all items from the children list, use
  1326. * {@link Item#removeChildren}. To add items to the children list, use
  1327. * {@link Item#addChild} or {@link Item#insertChild}.
  1328. */
  1329. children: Item[]
  1330. /**
  1331. * The first item contained within this item. This is a shortcut for
  1332. * accessing `item.children[0]`.
  1333. */
  1334. readonly firstChild: Item
  1335. /**
  1336. * The last item contained within this item.This is a shortcut for
  1337. * accessing `item.children[item.children.length - 1]`.
  1338. */
  1339. readonly lastChild: Item
  1340. /**
  1341. * The next item on the same level as this item.
  1342. */
  1343. readonly nextSibling: Item
  1344. /**
  1345. * The previous item on the same level as this item.
  1346. */
  1347. readonly previousSibling: Item
  1348. /**
  1349. * The index of this item within the list of its parent's children.
  1350. */
  1351. readonly index: number
  1352. /**
  1353. * The color of the stroke.
  1354. */
  1355. strokeColor: Color | null
  1356. /**
  1357. * The width of the stroke.
  1358. */
  1359. strokeWidth: number
  1360. /**
  1361. * The shape to be used at the beginning and end of open {@link Path} items,
  1362. * when they have a stroke.
  1363. */
  1364. strokeCap: string
  1365. /**
  1366. * The shape to be used at the segments and corners of {@link Path} items
  1367. * when they have a stroke.
  1368. */
  1369. strokeJoin: string
  1370. /**
  1371. * The dash offset of the stroke.
  1372. */
  1373. dashOffset: number
  1374. /**
  1375. * Specifies whether the stroke is to be drawn taking the current affine
  1376. * transformation into account (the default behavior), or whether it should
  1377. * appear as a non-scaling stroke.
  1378. */
  1379. strokeScaling: boolean
  1380. /**
  1381. * Specifies an array containing the dash and gap lengths of the stroke.
  1382. */
  1383. dashArray: number[]
  1384. /**
  1385. * The miter limit of the stroke.
  1386. * When two line segments meet at a sharp angle and miter joins have been
  1387. * specified for {@link Item#strokeJoin}, it is possible for the miter to
  1388. * extend far beyond the {@link Item#strokeWidth} of the path. The
  1389. * miterLimit imposes a limit on the ratio of the miter length to the
  1390. * {@link Item#strokeWidth}.
  1391. */
  1392. miterLimit: number
  1393. /**
  1394. * The fill color of the item.
  1395. */
  1396. fillColor: Color | null
  1397. /**
  1398. * The fill-rule with which the shape gets filled. Please note that only
  1399. * modern browsers support fill-rules other than `'nonzero'`.
  1400. */
  1401. fillRule: string
  1402. /**
  1403. * The shadow color.
  1404. */
  1405. shadowColor: Color | null
  1406. /**
  1407. * The shadow's blur radius.
  1408. */
  1409. shadowBlur: number
  1410. /**
  1411. * The shadow's offset.
  1412. */
  1413. shadowOffset: Point
  1414. /**
  1415. * The color the item is highlighted with when selected. If the item does
  1416. * not specify its own color, the color defined by its layer is used instead.
  1417. */
  1418. selectedColor: Color | null
  1419. /**
  1420. * Item level handler function to be called on each frame of an animation.
  1421. * The function receives an event object which contains information about
  1422. * the frame event:
  1423. *
  1424. * @see View#onFrame
  1425. *
  1426. * @option event.count {Number} the number of times the frame event was
  1427. * fired
  1428. * @option event.time {Number} the total amount of time passed since the
  1429. * first frame event in seconds
  1430. * @option event.delta {Number} the time passed in seconds since the last
  1431. * frame event
  1432. */
  1433. onFrame: Function | null
  1434. /**
  1435. * The function to be called when the mouse button is pushed down on the
  1436. * item. The function receives a {@link MouseEvent} object which contains
  1437. * information about the mouse event.
  1438. * Note that such mouse events bubble up the scene graph hierarchy and will
  1439. * reach the view, unless they are stopped with {@link
  1440. * Event#stopPropagation()} or by returning `false` from the handler.
  1441. *
  1442. * @see View#onMouseDown
  1443. */
  1444. onMouseDown: Function | null
  1445. /**
  1446. * The function to be called when the mouse position changes while the mouse
  1447. * is being dragged over the item. The function receives a {@link
  1448. * MouseEvent} object which contains information about the mouse event.
  1449. * Note that such mouse events bubble up the scene graph hierarchy and will
  1450. * reach the view, unless they are stopped with {@link
  1451. * Event#stopPropagation()} or by returning `false` from the handler.
  1452. *
  1453. * @see View#onMouseDrag
  1454. */
  1455. onMouseDrag: Function | null
  1456. /**
  1457. * The function to be called when the mouse button is released over the item.
  1458. * The function receives a {@link MouseEvent} object which contains
  1459. * information about the mouse event.
  1460. * Note that such mouse events bubble up the scene graph hierarchy and will
  1461. * reach the view, unless they are stopped with {@link
  1462. * Event#stopPropagation()} or by returning `false` from the handler.
  1463. *
  1464. * @see View#onMouseUp
  1465. */
  1466. onMouseUp: Function | null
  1467. /**
  1468. * The function to be called when the mouse clicks on the item. The function
  1469. * receives a {@link MouseEvent} object which contains information about the
  1470. * mouse event.
  1471. * Note that such mouse events bubble up the scene graph hierarchy and will
  1472. * reach the view, unless they are stopped with {@link
  1473. * Event#stopPropagation()} or by returning `false` from the handler.
  1474. *
  1475. * @see View#onClick
  1476. */
  1477. onClick: Function | null
  1478. /**
  1479. * The function to be called when the mouse double clicks on the item. The
  1480. * function receives a {@link MouseEvent} object which contains information
  1481. * about the mouse event.
  1482. * Note that such mouse events bubble up the scene graph hierarchy and will
  1483. * reach the view, unless they are stopped with {@link
  1484. * Event#stopPropagation()} or by returning `false` from the handler.
  1485. *
  1486. * @see View#onDoubleClick
  1487. */
  1488. onDoubleClick: Function | null
  1489. /**
  1490. * The function to be called repeatedly while the mouse moves over the item.
  1491. * The function receives a {@link MouseEvent} object which contains
  1492. * information about the mouse event.
  1493. * Note that such mouse events bubble up the scene graph hierarchy and will
  1494. * reach the view, unless they are stopped with {@link
  1495. * Event#stopPropagation()} or by returning `false` from the handler.
  1496. *
  1497. * @see View#onMouseMove
  1498. */
  1499. onMouseMove: Function | null
  1500. /**
  1501. * The function to be called when the mouse moves over the item. This
  1502. * function will only be called again, once the mouse moved outside of the
  1503. * item first. The function receives a {@link MouseEvent} object which
  1504. * contains information about the mouse event.
  1505. * Note that such mouse events bubble up the scene graph hierarchy and will
  1506. * reach the view, unless they are stopped with {@link
  1507. * Event#stopPropagation()} or by returning `false` from the handler.
  1508. *
  1509. * @see View#onMouseEnter
  1510. */
  1511. onMouseEnter: Function | null
  1512. /**
  1513. * The function to be called when the mouse moves out of the item.
  1514. * The function receives a {@link MouseEvent} object which contains
  1515. * information about the mouse event.
  1516. * Note that such mouse events bubble up the scene graph hierarchy and will
  1517. * reach the view, unless they are stopped with {@link
  1518. * Event#stopPropagation()} or by returning `false` from the handler.
  1519. *
  1520. * @see View#onMouseLeave
  1521. */
  1522. onMouseLeave: Function | null
  1523. /**
  1524. * Sets the properties of the passed object literal on this item to the
  1525. * values defined in the object literal, if the item has property of the
  1526. * given name (or a setter defined for it).
  1527. *
  1528. * @return the item itself
  1529. */
  1530. set(props: object): this
  1531. /**
  1532. * Clones the item within the same project and places the copy above the
  1533. * item.
  1534. *
  1535. * @option [insert=true] specifies whether the copy should be
  1536. * inserted into the scene graph. When set to `true`, it is inserted
  1537. * above the original
  1538. * @option [deep=true] specifies whether the item's children should also be
  1539. * cloned
  1540. *
  1541. * @return the newly cloned item
  1542. */
  1543. clone(options?: object): this
  1544. /**
  1545. * Copies the content of the specified item over to this item.
  1546. *
  1547. * @param source - the item to copy the content from
  1548. */
  1549. copyContent(source: Item): void
  1550. /**
  1551. * Copies all attributes of the specified item over to this item. This
  1552. * includes its style, visibility, matrix, pivot, blend-mode, opacity,
  1553. * selection state, data, name, etc.
  1554. *
  1555. * @param source - the item to copy the attributes from
  1556. * @param excludeMatrix - whether to exclude the transformation
  1557. * matrix when copying all attributes
  1558. */
  1559. copyAttributes(source: Item, excludeMatrix: boolean): void
  1560. /**
  1561. * Rasterizes the item into a newly created Raster object. The item itself
  1562. * is not removed after rasterization.
  1563. *
  1564. * @option [resolution=view.resolution] {Number} the desired resolution to
  1565. * be used when rasterizing, in pixels per inch (DPI). If not specified,
  1566. * the value of `view.resolution` is used by default.
  1567. * @option [raster=null] {Raster} specifies a raster to be reused when
  1568. * rasterizing. If the raster has the desired size already, then the
  1569. * underlying canvas is reused and no new memory needs to be allocated.
  1570. * If no raster is provided, a new raster item is created and returned
  1571. * instead.
  1572. * @option [insert=true] {Boolean} specifies whether the raster should be
  1573. * inserted into the scene graph. When set to `true`, it is inserted
  1574. * above the rasterized item.
  1575. *
  1576. * @param options - the rasterization options
  1577. *
  1578. * @return the reused raster or the newly created raster item
  1579. */
  1580. rasterize(options?: object): Raster
  1581. /**
  1582. * Checks whether the item's geometry contains the given point.
  1583. *
  1584. * @param point - the point to check for
  1585. */
  1586. contains(point: Point): boolean
  1587. /**
  1588. * @param rect - the rectangle to check against
  1589. */
  1590. isInside(rect: Rectangle): boolean
  1591. /**
  1592. * @param item - the item to check against
  1593. */
  1594. intersects(item: Item): boolean
  1595. /**
  1596. * Performs a hit-test on the item and its children (if it is a {@link
  1597. * Group} or {@link Layer}) at the location of the specified point,
  1598. * returning the first found hit.
  1599. *
  1600. * The options object allows you to control the specifics of the hit-
  1601. * test and may contain a combination of the following values:
  1602. *
  1603. * @option [options.tolerance={@link PaperScope#settings}.hitTolerance]
  1604. * {Number} the tolerance of the hit-test
  1605. * @option options.class {Function} only hit-test against a specific item
  1606. * class, or any of its sub-classes, by providing the constructor
  1607. * function against which an `instanceof` check is performed:
  1608. * {@values Group, Layer, Path, CompoundPath, Shape, Raster,
  1609. * SymbolItem, PointText, ...}
  1610. * @option options.match {Function} a match function to be called for each
  1611. * found hit result: Return `true` to return the result, `false` to keep
  1612. * searching
  1613. * @option [options.fill=true] {Boolean} hit-test the fill of items
  1614. * @option [options.stroke=true] {Boolean} hit-test the stroke of path
  1615. * items, taking into account the setting of stroke color and width
  1616. * @option [options.segments=true] {Boolean} hit-test for {@link
  1617. * Segment#point} of {@link Path} items
  1618. * @option options.curves {Boolean} hit-test the curves of path items,
  1619. * without taking the stroke color or width into account
  1620. * @option options.handles {Boolean} hit-test for the handles ({@link
  1621. * Segment#handleIn} / {@link Segment#handleOut}) of path segments.
  1622. * @option options.ends {Boolean} only hit-test for the first or last
  1623. * segment points of open path items
  1624. * @option options.position {Boolean} hit-test the {@link Item#position} of
  1625. * of items, which depends on the setting of {@link Item#pivot}
  1626. * @option options.center {Boolean} hit-test the {@link Rectangle#center} of
  1627. * the bounding rectangle of items ({@link Item#bounds})
  1628. * @option options.bounds {Boolean} hit-test the corners and side-centers of
  1629. * the bounding rectangle of items ({@link Item#bounds})
  1630. * @option options.guides {Boolean} hit-test items that have {@link
  1631. * Item#guide} set to `true`
  1632. * @option options.selected {Boolean} only hit selected items
  1633. *
  1634. * @param point - the point where the hit-test should be performed
  1635. * (in global coordinates system).
  1636. *
  1637. * @return a hit result object describing what exactly was hit
  1638. * or `null` if nothing was hit
  1639. */
  1640. hitTest(point: Point, options?: object): HitResult
  1641. /**
  1642. * Performs a hit-test on the item and its children (if it is a {@link
  1643. * Group} or {@link Layer}) at the location of the specified point,
  1644. * returning all found hits.
  1645. *
  1646. * The options object allows you to control the specifics of the hit-
  1647. * test. See {@link #hitTest} for a list of all options.
  1648. *
  1649. * @see #hitTest(point[, options]);
  1650. *
  1651. * @param point - the point where the hit-test should be performed
  1652. * (in global coordinates system).
  1653. *
  1654. * @return hit result objects for all hits, describing what
  1655. * exactly was hit or `null` if nothing was hit
  1656. */
  1657. hitTestAll(point: Point, options?: object): HitResult[]
  1658. /**
  1659. * Checks whether the item matches the criteria described by the given
  1660. * object, by iterating over all of its properties and matching against
  1661. * their values through {@link #matches}.
  1662. *
  1663. * See {@link Project#getItems} for a selection of illustrated
  1664. * examples.
  1665. *
  1666. * @see #getItems(options)
  1667. *
  1668. * @param options - the criteria to match against
  1669. *
  1670. * @return true if the item matches all the criteria
  1671. */
  1672. matches(options: object | Function): boolean
  1673. /**
  1674. * Checks whether the item matches the given criteria. Extended matching is
  1675. * possible by providing a compare function or a regular expression.
  1676. * Matching points, colors only work as a comparison of the full object, not
  1677. * partial matching (e.g. only providing the x-coordinate to match all
  1678. * points with that x-value). Partial matching does work for
  1679. * {@link Item#data}.
  1680. *
  1681. * See {@link Project#getItems} for a selection of illustrated
  1682. * examples.
  1683. *
  1684. * @see #getItems(options)
  1685. *
  1686. * @param name - the name of the state to match against
  1687. * @param compare - the value, function or regular expression to
  1688. * compare against
  1689. *
  1690. * @return true if the item matches the state
  1691. */
  1692. matches(name: string, compare: object): boolean
  1693. /**
  1694. * Fetch the descendants (children or children of children) of this item
  1695. * that match the properties in the specified object. Extended matching is
  1696. * possible by providing a compare function or regular expression. Matching
  1697. * points, colors only work as a comparison of the full object, not partial
  1698. * matching (e.g. only providing the x- coordinate to match all points with
  1699. * that x-value). Partial matching does work for {@link Item#data}.
  1700. *
  1701. * Matching items against a rectangular area is also possible, by setting
  1702. * either `options.inside` or `options.overlapping` to a rectangle
  1703. * describing the area in which the items either have to be fully or partly
  1704. * contained.
  1705. *
  1706. * See {@link Project#getItems} for a selection of illustrated
  1707. * examples.
  1708. *
  1709. * @see #matches(options)
  1710. *
  1711. * @option [options.recursive=true] {Boolean} whether to loop recursively
  1712. * through all children, or stop at the current level
  1713. * @option options.match {Function} a match function to be called for each
  1714. * item, allowing the definition of more flexible item checks that are
  1715. * not bound to properties. If no other match properties are defined,
  1716. * this function can also be passed instead of the `options` object
  1717. * @option options.class {Function} the constructor function of the item
  1718. * type to match against
  1719. * @option options.inside {Rectangle} the rectangle in which the items need
  1720. * to be fully contained
  1721. * @option options.overlapping {Rectangle} the rectangle with which the
  1722. * items need to at least partly overlap
  1723. *
  1724. * @param options - the criteria to match against
  1725. *
  1726. * @return the list of matching descendant items
  1727. */
  1728. getItems(options: object | Function): Item[]
  1729. /**
  1730. * Fetch the first descendant (child or child of child) of this item
  1731. * that matches the properties in the specified object.
  1732. * Extended matching is possible by providing a compare function or
  1733. * regular expression. Matching points, colors only work as a comparison
  1734. * of the full object, not partial matching (e.g. only providing the x-
  1735. * coordinate to match all points with that x-value). Partial matching
  1736. * does work for {@link Item#data}.
  1737. * See {@link Project#getItems} for a selection of illustrated
  1738. * examples.
  1739. *
  1740. * @see #getItems(options)
  1741. *
  1742. * @param options - the criteria to match against
  1743. *
  1744. * @return the first descendant item matching the given criteria
  1745. */
  1746. getItem(options: object | Function): Item
  1747. /**
  1748. * Exports (serializes) the item with its content and child items to a JSON
  1749. * data string.
  1750. *
  1751. * @option [options.asString=true] {Boolean} whether the JSON is returned as
  1752. * a `Object` or a `String`
  1753. * @option [options.precision=5] {Number} the amount of fractional digits in
  1754. * numbers used in JSON data
  1755. *
  1756. * @param options - the serialization options
  1757. *
  1758. * @return the exported JSON data
  1759. */
  1760. exportJSON(options?: object): string
  1761. /**
  1762. * Imports (deserializes) the stored JSON data into this item. If the data
  1763. * describes an item of the same class or a parent class of the item, the
  1764. * data is imported into the item itself. If not, the imported item is added
  1765. * to this item's {@link Item#children} list. Note that not all type of
  1766. * items can have children.
  1767. *
  1768. * @param json - the JSON data to import from
  1769. */
  1770. importJSON(json: string): Item
  1771. /**
  1772. * Exports the item with its content and child items as an SVG DOM.
  1773. *
  1774. * @option [options.bounds='view'] {String|Rectangle} the bounds of the area
  1775. * to export, either as a string ({@values 'view', content'}), or a
  1776. * {@link Rectangle} object: `'view'` uses the view bounds,
  1777. * `'content'` uses the stroke bounds of all content
  1778. * @option [options.matrix=paper.view.matrix] {Matrix} the matrix with which
  1779. * to transform the exported content: If `options.bounds` is set to
  1780. * `'view'`, `paper.view.matrix` is used, for all other settings of
  1781. * `options.bounds` the identity matrix is used.
  1782. * @option [options.asString=false] {Boolean} whether a SVG node or a
  1783. * `String` is to be returned
  1784. * @option [options.precision=5] {Number} the amount of fractional digits in
  1785. * numbers used in SVG data
  1786. * @option [options.matchShapes=false] {Boolean} whether path items should
  1787. * tried to be converted to SVG shape items (rect, circle, ellipse,
  1788. * line, polyline, polygon), if their geometries match
  1789. * @option [options.embedImages=true] {Boolean} whether raster images should
  1790. * be embedded as base64 data inlined in the xlink:href attribute, or
  1791. * kept as a link to their external URL.
  1792. *
  1793. * @param options - the export options
  1794. *
  1795. * @return the item converted to an SVG node or a
  1796. * `String` depending on `option.asString` value
  1797. */
  1798. exportSVG(options?: object): SVGElement | string
  1799. /**
  1800. * Converts the provided SVG content into Paper.js items and adds them to
  1801. * the this item's children list. Note that the item is not cleared first.
  1802. * You can call {@link Item#removeChildren} to do so.
  1803. *
  1804. * @option [options.expandShapes=false] {Boolean} whether imported shape
  1805. * items should be expanded to path items
  1806. * @option options.onLoad {Function} the callback function to call once the
  1807. * SVG content is loaded from the given URL receiving two arguments: the
  1808. * converted `item` and the original `svg` data as a string. Only
  1809. * required when loading from external resources.
  1810. * @option options.onError {Function} the callback function to call if an
  1811. * error occurs during loading. Only required when loading from external
  1812. * resources.
  1813. * @option [options.insert=true] {Boolean} whether the imported items should
  1814. * be added to the item that `importSVG()` is called on
  1815. * @option [options.applyMatrix={@link PaperScope#settings}.applyMatrix]
  1816. * {Boolean} whether the imported items should have their transformation
  1817. * matrices applied to their contents or not
  1818. *
  1819. * @param svg - the SVG content to import, either as a SVG
  1820. * DOM node, a string containing SVG content, or a string describing the
  1821. * URL of the SVG file to fetch.
  1822. * @param options - the import options
  1823. *
  1824. * @return the newly created Paper.js item containing the converted
  1825. * SVG content
  1826. */
  1827. importSVG(svg: SVGElement | string, options?: object): Item
  1828. /**
  1829. * Imports the provided external SVG file, converts it into Paper.js items
  1830. * and adds them to the this item's children list. Note that the item is not
  1831. * cleared first. You can call {@link Item#removeChildren} to do so.
  1832. *
  1833. * @param svg - the URL of the SVG file to fetch.
  1834. * @param onLoad - the callback function to call once the SVG
  1835. * content is loaded from the given URL receiving two arguments: the
  1836. * converted `item` and the original `svg` data as a string. Only
  1837. * required when loading from external files.
  1838. *
  1839. * @return the newly created Paper.js item containing the converted
  1840. * SVG content
  1841. */
  1842. importSVG(svg: SVGElement | string, onLoad: Function): Item
  1843. /**
  1844. * Adds the specified item as a child of this item at the end of the its
  1845. * {@link #children} list. You can use this function for groups, compound
  1846. * paths and layers.
  1847. *
  1848. * @param item - the item to be added as a child
  1849. *
  1850. * @return the added item, or `null` if adding was not possible
  1851. */
  1852. addChild(item: Item): Item
  1853. /**
  1854. * Inserts the specified item as a child of this item at the specified index
  1855. * in its {@link #children} list. You can use this function for groups,
  1856. * compound paths and layers.
  1857. *
  1858. * @param index - the index at which to insert the item
  1859. * @param item - the item to be inserted as a child
  1860. *
  1861. * @return the inserted item, or `null` if inserting was not possible
  1862. */
  1863. insertChild(index: number, item: Item): Item
  1864. /**
  1865. * Adds the specified items as children of this item at the end of the its
  1866. * children list. You can use this function for groups, compound paths and
  1867. * layers.
  1868. *
  1869. * @param items - the items to be added as children
  1870. *
  1871. * @return the added items, or `null` if adding was not possible
  1872. */
  1873. addChildren(items: Item[]): Item[]
  1874. /**
  1875. * Inserts the specified items as children of this item at the specified
  1876. * index in its {@link #children} list. You can use this function for
  1877. * groups, compound paths and layers.
  1878. *
  1879. * @param items - the items to be appended as children
  1880. *
  1881. * @return the inserted items, or `null` if inserted was not
  1882. * possible
  1883. */
  1884. insertChildren(index: number, items: Item[]): Item[]
  1885. /**
  1886. * Inserts this item above the specified item.
  1887. *
  1888. * @param item - the item above which it should be inserted
  1889. *
  1890. * @return the inserted item, or `null` if inserting was not possible
  1891. */
  1892. insertAbove(item: Item): Item
  1893. /**
  1894. * Inserts this item below the specified item.
  1895. *
  1896. * @param item - the item below which it should be inserted
  1897. *
  1898. * @return the inserted item, or `null` if inserting was not possible
  1899. */
  1900. insertBelow(item: Item): Item
  1901. /**
  1902. * Sends this item to the back of all other items within the same parent.
  1903. */
  1904. sendToBack(): void
  1905. /**
  1906. * Brings this item to the front of all other items within the same parent.
  1907. */
  1908. bringToFront(): void
  1909. /**
  1910. * Adds it to the specified owner, which can be either a {@link Item} or a
  1911. * {@link Project}.
  1912. *
  1913. * @param owner - the item or project to
  1914. * add the item to
  1915. *
  1916. * @return the item itself, if it was successfully added
  1917. */
  1918. addTo(owner: Project | Layer | Group | CompoundPath): this
  1919. /**
  1920. * Clones the item and adds it to the specified owner, which can be either
  1921. * a {@link Item} or a {@link Project}.
  1922. *
  1923. * @param owner - the item or project to
  1924. * copy the item to
  1925. *
  1926. * @return the new copy of the item, if it was successfully added
  1927. */
  1928. copyTo(owner: Project | Layer | Group | CompoundPath): this
  1929. /**
  1930. * If this is a group, layer or compound-path with only one child-item,
  1931. * the child-item is moved outside and the parent is erased. Otherwise, the
  1932. * item itself is returned unmodified.
  1933. *
  1934. * @return the reduced item
  1935. */
  1936. reduce(options: any): Item
  1937. /**
  1938. * Removes the item and all its children from the project. The item is not
  1939. * destroyed and can be inserted again after removal.
  1940. *
  1941. * @return true if the item was removed
  1942. */
  1943. remove(): boolean
  1944. /**
  1945. * Replaces this item with the provided new item which will takes its place
  1946. * in the project hierarchy instead.
  1947. *
  1948. * @param item - the item that will replace this item
  1949. *
  1950. * @return true if the item was replaced
  1951. */
  1952. replaceWith(item: Item): boolean
  1953. /**
  1954. * Removes all of the item's {@link #children} (if any).
  1955. *
  1956. * @return an array containing the removed items
  1957. */
  1958. removeChildren(): Item[]
  1959. /**
  1960. * Removes the children from the specified `start` index to and excluding
  1961. * the `end` index from the parent's {@link #children} array.
  1962. *
  1963. * @param start - the beginning index, inclusive
  1964. * @param end - the ending index, exclusive
  1965. *
  1966. * @return an array containing the removed items
  1967. */
  1968. removeChildren(start: number, end?: number): Item[]
  1969. /**
  1970. * Reverses the order of the item's children
  1971. */
  1972. reverseChildren(): void
  1973. /**
  1974. * Specifies whether the item has any content or not. The meaning of what
  1975. * content is differs from type to type. For example, a {@link Group} with
  1976. * no children, a {@link TextItem} with no text content and a {@link Path}
  1977. * with no segments all are considered empty.
  1978. *
  1979. * @param recursively - whether an item with children should be
  1980. * considered empty if all its descendants are empty
  1981. */
  1982. isEmpty(recursively?: boolean): boolean
  1983. /**
  1984. * Checks whether the item has a fill.
  1985. *
  1986. * @return true if the item has a fill
  1987. */
  1988. hasFill(): boolean
  1989. /**
  1990. * Checks whether the item has a stroke.
  1991. *
  1992. * @return true if the item has a stroke
  1993. */
  1994. hasStroke(): boolean
  1995. /**
  1996. * Checks whether the item has a shadow.
  1997. *
  1998. * @return true if the item has a shadow
  1999. */
  2000. hasShadow(): boolean
  2001. /**
  2002. * Checks if the item contains any children items.
  2003. *
  2004. * @return true it has one or more children
  2005. */
  2006. hasChildren(): boolean
  2007. /**
  2008. * Checks whether the item and all its parents are inserted into scene graph
  2009. * or not.
  2010. *
  2011. * @return true if the item is inserted into the scene graph
  2012. */
  2013. isInserted(): boolean
  2014. /**
  2015. * Checks if this item is above the specified item in the stacking order
  2016. * of the project.
  2017. *
  2018. * @param item - the item to check against
  2019. *
  2020. * @return true if it is above the specified item
  2021. */
  2022. isAbove(item: Item): boolean
  2023. /**
  2024. * Checks if the item is below the specified item in the stacking order of
  2025. * the project.
  2026. *
  2027. * @param item - the item to check against
  2028. *
  2029. * @return true if it is below the specified item
  2030. */
  2031. isBelow(item: Item): boolean
  2032. /**
  2033. * Checks whether the specified item is the parent of the item.
  2034. *
  2035. * @param item - the item to check against
  2036. *
  2037. * @return true if it is the parent of the item
  2038. */
  2039. isParent(item: Item): boolean
  2040. /**
  2041. * Checks whether the specified item is a child of the item.
  2042. *
  2043. * @param item - the item to check against
  2044. *
  2045. * @return true it is a child of the item
  2046. */
  2047. isChild(item: Item): boolean
  2048. /**
  2049. * Checks if the item is contained within the specified item.
  2050. *
  2051. * @param item - the item to check against
  2052. *
  2053. * @return true if it is inside the specified item
  2054. */
  2055. isDescendant(item: Item): boolean
  2056. /**
  2057. * Checks if the item is an ancestor of the specified item.
  2058. *
  2059. * @param item - the item to check against
  2060. *
  2061. * @return true if the item is an ancestor of the specified
  2062. * item
  2063. */
  2064. isAncestor(item: Item): boolean
  2065. /**
  2066. * Checks if the item is an a sibling of the specified item.
  2067. *
  2068. * @param item - the item to check against
  2069. *
  2070. * @return true if the item is aa sibling of the specified item
  2071. */
  2072. isSibling(item: Item): boolean
  2073. /**
  2074. * Checks whether the item is grouped with the specified item.
  2075. *
  2076. * @return true if the items are grouped together
  2077. */
  2078. isGroupedWith(item: Item): boolean
  2079. /**
  2080. * Translates (moves) the item by the given offset views.
  2081. *
  2082. * @param delta - the offset to translate the item by
  2083. */
  2084. translate(delta: Point): void
  2085. /**
  2086. * Rotates the item by a given angle around the given center point.
  2087. *
  2088. * Angles are oriented clockwise and measured in degrees.
  2089. *
  2090. * @see Matrix#rotate(angle[, center])
  2091. *
  2092. * @param angle - the rotation angle
  2093. */
  2094. rotate(angle: number, center?: Point): void
  2095. /**
  2096. * Scales the item by the given value from its center point, or optionally
  2097. * from a supplied point.
  2098. *
  2099. * @param scale - the scale factor
  2100. */
  2101. scale(scale: number, center?: Point): void
  2102. /**
  2103. * Scales the item by the given values from its center point, or optionally
  2104. * from a supplied point.
  2105. *
  2106. * @param hor - the horizontal scale factor
  2107. * @param ver - the vertical scale factor
  2108. */
  2109. scale(hor: number, ver: number, center?: Point): void
  2110. /**
  2111. * Shears the item by the given value from its center point, or optionally
  2112. * by a supplied point.
  2113. *
  2114. * @see Matrix#shear(shear[, center])
  2115. *
  2116. * @param shear - the horizontal and vertical shear factors as a point
  2117. */
  2118. shear(shear: Point, center?: Point): void
  2119. /**
  2120. * Shears the item by the given values from its center point, or optionally
  2121. * by a supplied point.
  2122. *
  2123. * @see Matrix#shear(hor, ver[, center])
  2124. *
  2125. * @param hor - the horizontal shear factor
  2126. * @param ver - the vertical shear factor
  2127. */
  2128. shear(hor: number, ver: number, center?: Point): void
  2129. /**
  2130. * Skews the item by the given angles from its center point, or optionally
  2131. * by a supplied point.
  2132. *
  2133. * @see Matrix#shear(skew[, center])
  2134. *
  2135. * @param skew - the horizontal and vertical skew angles in degrees
  2136. */
  2137. skew(skew: Point, center?: Point): void
  2138. /**
  2139. * Skews the item by the given angles from its center point, or optionally
  2140. * by a supplied point.
  2141. *
  2142. * @see Matrix#shear(hor, ver[, center])
  2143. *
  2144. * @param hor - the horizontal skew angle in degrees
  2145. * @param ver - the vertical sskew angle in degrees
  2146. */
  2147. skew(hor: number, ver: number, center?: Point): void
  2148. /**
  2149. * Transform the item.
  2150. *
  2151. * @param matrix - the matrix by which the item shall be transformed
  2152. */
  2153. transform(matrix: Matrix): void
  2154. /**
  2155. * Converts the specified point from global project coordinate space to the
  2156. * item's own local coordinate space.
  2157. *
  2158. * @param point - the point to be transformed
  2159. *
  2160. * @return the transformed point as a new instance
  2161. */
  2162. globalToLocal(point: Point): Point
  2163. /**
  2164. * Converts the specified point from the item's own local coordinate space
  2165. * to the global project coordinate space.
  2166. *
  2167. * @param point - the point to be transformed
  2168. *
  2169. * @return the transformed point as a new instance
  2170. */
  2171. localToGlobal(point: Point): Point
  2172. /**
  2173. * Converts the specified point from the parent's coordinate space to
  2174. * item's own local coordinate space.
  2175. *
  2176. * @param point - the point to be transformed
  2177. *
  2178. * @return the transformed point as a new instance
  2179. */
  2180. parentToLocal(point: Point): Point
  2181. /**
  2182. * Converts the specified point from the item's own local coordinate space
  2183. * to the parent's coordinate space.
  2184. *
  2185. * @param point - the point to be transformed
  2186. *
  2187. * @return the transformed point as a new instance
  2188. */
  2189. localToParent(point: Point): Point
  2190. /**
  2191. * Transform the item so that its {@link #bounds} fit within the specified
  2192. * rectangle, without changing its aspect ratio.
  2193. */
  2194. fitBounds(rectangle: Rectangle, fill?: boolean): void
  2195. /**
  2196. * Attaches an event handler to the item.
  2197. *
  2198. * @param type - the type of event: {@values 'frame', mousedown',
  2199. * 'mouseup', 'mousedrag', 'click', 'doubleclick', 'mousemove',
  2200. * 'mouseenter', 'mouseleave'}
  2201. * @param function - the function to be called when the event
  2202. * occurs, receiving a {@link MouseEvent} or {@link Event} object as its
  2203. * sole argument
  2204. *
  2205. * @return this item itself, so calls can be chained
  2206. */
  2207. on(type: string, callback: Function): this
  2208. /**
  2209. * Attaches one or more event handlers to the item.
  2210. *
  2211. * @param object - an object containing one or more of the following
  2212. * properties: {@values frame, mousedown, mouseup, mousedrag, click,
  2213. * doubleclick, mousemove, mouseenter, mouseleave}
  2214. *
  2215. * @return this item itself, so calls can be chained
  2216. */
  2217. on(object: object): this
  2218. /**
  2219. * Detach an event handler from the item.
  2220. *
  2221. * @param type - the type of event: {@values 'frame', mousedown',
  2222. * 'mouseup', 'mousedrag', 'click', 'doubleclick', 'mousemove',
  2223. * 'mouseenter', 'mouseleave'}
  2224. * @param function - the function to be detached
  2225. *
  2226. * @return this item itself, so calls can be chained
  2227. */
  2228. off(type: string, callback: Function): this
  2229. /**
  2230. * Detach one or more event handlers to the item.
  2231. *
  2232. * @param object - an object containing one or more of the following
  2233. * properties: {@values frame, mousedown, mouseup, mousedrag, click,
  2234. * doubleclick, mousemove, mouseenter, mouseleave}
  2235. *
  2236. * @return this item itself, so calls can be chained
  2237. */
  2238. off(object: object): this
  2239. /**
  2240. * Emit an event on the item.
  2241. *
  2242. * @param type - the type of event: {@values 'frame', mousedown',
  2243. * 'mouseup', 'mousedrag', 'click', 'doubleclick', 'mousemove',
  2244. * 'mouseenter', 'mouseleave'}
  2245. * @param event - an object literal containing properties describing
  2246. * the event
  2247. *
  2248. * @return true if the event had listeners
  2249. */
  2250. emit(type: string, event: object): boolean
  2251. /**
  2252. * Check if the item has one or more event handlers of the specified type.
  2253. *
  2254. * @param type - the type of event: {@values 'frame', mousedown',
  2255. * 'mouseup', 'mousedrag', 'click', 'doubleclick', 'mousemove',
  2256. * 'mouseenter', 'mouseleave'}
  2257. *
  2258. * @return true if the item has one or more event handlers of
  2259. * the specified type
  2260. */
  2261. responds(type: string): boolean
  2262. /**
  2263. * Removes the item when the events specified in the passed options object
  2264. * occur.
  2265. *
  2266. * @option options.move {Boolean) remove the item when the next {@link
  2267. * Tool#onMouseMove} event is fired.
  2268. * @option options.drag {Boolena) remove the item when the next {@link
  2269. * Tool#onMouseDrag} event is fired.
  2270. * @option options.down {Boolean) remove the item when the next {@link
  2271. * Tool#onMouseDown} event is fired.
  2272. * @option options.up {Boolean) remove the item when the next {@link
  2273. * Tool#onMouseUp} event is fired.
  2274. */
  2275. removeOn(options: object): void
  2276. /**
  2277. * Removes the item when the next {@link Tool#onMouseMove} event is fired.
  2278. */
  2279. removeOnMove(): void
  2280. /**
  2281. * Removes the item when the next {@link Tool#onMouseDown} event is fired.
  2282. */
  2283. removeOnDown(): void
  2284. /**
  2285. * Removes the item when the next {@link Tool#onMouseDrag} event is fired.
  2286. */
  2287. removeOnDrag(): void
  2288. /**
  2289. * Removes the item when the next {@link Tool#onMouseUp} event is fired.
  2290. */
  2291. removeOnUp(): void
  2292. /**
  2293. * Tween item between two states.
  2294. *
  2295. * @option options.duration {Number} the duration of the tweening
  2296. * @option [options.easing='linear'] {Function|String} an easing function or the type
  2297. * of the easing: {@values 'linear' 'easeInQuad' 'easeOutQuad'
  2298. * 'easeInOutQuad' 'easeInCubic' 'easeOutCubic' 'easeInOutCubic'
  2299. * 'easeInQuart' 'easeOutQuart' 'easeInOutQuart' 'easeInQuint'
  2300. * 'easeOutQuint' 'easeInOutQuint'}
  2301. * @option [options.start=true] {Boolean} whether to start tweening automatically
  2302. *
  2303. * @param from - the state at the start of the tweening
  2304. * @param to - the state at the end of the tweening
  2305. * @param options - the options or the duration
  2306. */
  2307. tween(from: object, to: object, options: object | number): Tween
  2308. /**
  2309. * Tween item to a state.
  2310. *
  2311. * @see Item#tween(from, to, options)
  2312. *
  2313. * @param to - the state at the end of the tweening
  2314. * @param options - the options or the duration
  2315. */
  2316. tween(to: object, options: object | number): Tween
  2317. /**
  2318. * Tween item.
  2319. *
  2320. * @see Item#tween(from, to, options)
  2321. *
  2322. * @param options - the options or the duration
  2323. */
  2324. tween(options: object | number): Tween
  2325. /**
  2326. * Tween item to a state.
  2327. *
  2328. * @see Item#tween(to, options)
  2329. *
  2330. * @param to - the state at the end of the tweening
  2331. * @param options - the options or the duration
  2332. */
  2333. tweenTo(to: object, options: object | number): Tween
  2334. /**
  2335. * Tween item from a state to its state before the tweening.
  2336. *
  2337. * @see Item#tween(from, to, options)
  2338. *
  2339. * @param from - the state at the start of the tweening
  2340. * @param options - the options or the duration
  2341. */
  2342. tweenFrom(from: object, options: object | number): Tween
  2343. }
  2344. class Key {
  2345. /**
  2346. * The current state of the keyboard modifiers.
  2347. *
  2348. * @option modifiers.shift {Boolean} {@true if the shift key is
  2349. * pressed}.
  2350. * @option modifiers.control {Boolean} {@true if the control key is
  2351. * pressed}.
  2352. * @option modifiers.alt {Boolean} {@true if the alt/option key is
  2353. * pressed}.
  2354. * @option modifiers.meta {Boolean} {@true if the meta/windows/command
  2355. * key is pressed}.
  2356. * @option modifiers.capsLock {Boolean} {@true if the caps-lock key is
  2357. * active}.
  2358. * @option modifiers.space {Boolean} {@true if the space key is
  2359. * pressed}.
  2360. * @option modifiers.option {Boolean} {@true if the alt/option key is
  2361. * pressed}. This is the same as `modifiers.alt`
  2362. * @option modifiers.command {Boolean} {@true if the meta key is pressed
  2363. * on Mac, or the control key is pressed on Windows and Linux}.
  2364. */
  2365. static modifiers: any
  2366. /**
  2367. * Checks whether the specified key is pressed.
  2368. *
  2369. * @param key - any character or special key descriptor:
  2370. * {@values 'enter', 'space', 'shift', 'control', 'alt', 'meta',
  2371. * 'caps-lock', 'left', 'up', 'right', 'down', 'escape', 'delete',
  2372. * ...}
  2373. *
  2374. * @return true if the key is pressed
  2375. */
  2376. static isDown(key: string): boolean
  2377. }
  2378. /**
  2379. * The KeyEvent object is received by the {@link Tool}'s keyboard
  2380. * handlers {@link Tool#onKeyDown}, {@link Tool#onKeyUp}. The KeyEvent object is
  2381. * the only parameter passed to these functions and contains information about
  2382. * the keyboard event.
  2383. */
  2384. class KeyEvent extends Event {
  2385. /**
  2386. * The type of mouse event.
  2387. */
  2388. type: string
  2389. /**
  2390. * The character representation of the key that caused this key event,
  2391. * taking into account the current key-modifiers (e.g. shift, control,
  2392. * caps-lock, etc.)
  2393. */
  2394. character: string
  2395. /**
  2396. * The key that caused this key event, either as a lower-case character or
  2397. * special key descriptor.
  2398. */
  2399. key: string
  2400. /**
  2401. * @return a string representation of the key event
  2402. */
  2403. toString(): string
  2404. }
  2405. /**
  2406. * The Layer item represents a layer in a Paper.js project.
  2407. *
  2408. * The layer which is currently active can be accessed through
  2409. * {@link Project#activeLayer}.
  2410. * An array of all layers in a project can be accessed through
  2411. * {@link Project#layers}.
  2412. */
  2413. class Layer extends Group {
  2414. /**
  2415. * Creates a new Layer item and places it at the end of the
  2416. * {@link Project#layers} array. The newly created layer will be activated,
  2417. * so all newly created items will be placed within it.
  2418. *
  2419. * @param children - An array of items that will be added to the
  2420. * newly created layer
  2421. */
  2422. constructor(children?: Item[])
  2423. /**
  2424. * Creates a new Layer item and places it at the end of the
  2425. * {@link Project#layers} array. The newly created layer will be activated,
  2426. * so all newly created items will be placed within it.
  2427. *
  2428. * @param object - an object containing the properties to be set on
  2429. * the layer
  2430. */
  2431. constructor(object: object)
  2432. /**
  2433. * Activates the layer.
  2434. */
  2435. activate(): void
  2436. }
  2437. /**
  2438. * An affine transformation matrix performs a linear mapping from 2D
  2439. * coordinates to other 2D coordinates that preserves the "straightness" and
  2440. * "parallelness" of lines.
  2441. *
  2442. * Such a coordinate transformation can be represented by a 3 row by 3
  2443. * column matrix with an implied last row of `[ 0 0 1 ]`. This matrix
  2444. * transforms source coordinates `(x, y)` into destination coordinates `(x',y')`
  2445. * by considering them to be a column vector and multiplying the coordinate
  2446. * vector by the matrix according to the following process:
  2447. *
  2448. * [ x ] [ a c tx ] [ x ] [ a * x + c * y + tx ]
  2449. * [ y ] = [ b d ty ] [ y ] = [ b * x + d * y + ty ]
  2450. * [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
  2451. *
  2452. * Note the locations of b and c.
  2453. *
  2454. * This class is optimized for speed and minimizes calculations based on its
  2455. * knowledge of the underlying matrix (as opposed to say simply performing
  2456. * matrix multiplication).
  2457. */
  2458. class Matrix {
  2459. /**
  2460. * The value that affects the transformation along the x axis when scaling
  2461. * or rotating, positioned at (0, 0) in the transformation matrix.
  2462. */
  2463. a: number
  2464. /**
  2465. * The value that affects the transformation along the y axis when rotating
  2466. * or skewing, positioned at (1, 0) in the transformation matrix.
  2467. */
  2468. b: number
  2469. /**
  2470. * The value that affects the transformation along the x axis when rotating
  2471. * or skewing, positioned at (0, 1) in the transformation matrix.
  2472. */
  2473. c: number
  2474. /**
  2475. * The value that affects the transformation along the y axis when scaling
  2476. * or rotating, positioned at (1, 1) in the transformation matrix.
  2477. */
  2478. d: number
  2479. /**
  2480. * The distance by which to translate along the x axis, positioned at (2, 0)
  2481. * in the transformation matrix.
  2482. */
  2483. tx: number
  2484. /**
  2485. * The distance by which to translate along the y axis, positioned at (2, 1)
  2486. * in the transformation matrix.
  2487. */
  2488. ty: number
  2489. /**
  2490. * The matrix values as an array, in the same sequence as they are passed
  2491. * to {@link #initialize}.
  2492. */
  2493. readonly values: number[]
  2494. /**
  2495. * The translation of the matrix as a vector.
  2496. */
  2497. readonly translation: Point
  2498. /**
  2499. * The scaling values of the matrix, if it can be decomposed.
  2500. *
  2501. * @see #decompose()
  2502. */
  2503. readonly scaling: Point
  2504. /**
  2505. * The rotation angle of the matrix, if it can be decomposed.
  2506. *
  2507. * @see #decompose()
  2508. */
  2509. readonly rotation: number
  2510. /**
  2511. * Creates a 2D affine transformation matrix that describes the identity
  2512. * transformation.
  2513. */
  2514. constructor()
  2515. /**
  2516. * Creates a 2D affine transformation matrix.
  2517. *
  2518. * @param a - the a property of the transform
  2519. * @param b - the b property of the transform
  2520. * @param c - the c property of the transform
  2521. * @param d - the d property of the transform
  2522. * @param tx - the tx property of the transform
  2523. * @param ty - the ty property of the transform
  2524. */
  2525. constructor(a: number, b: number, c: number, d: number, tx: number, ty: number)
  2526. /**
  2527. * Creates a 2D affine transformation matrix.
  2528. *
  2529. * @param values - the matrix values to initialize this matrix with
  2530. */
  2531. constructor(values: number[])
  2532. /**
  2533. * Creates a 2D affine transformation matrix.
  2534. *
  2535. * @param matrix - the matrix to copy the values from
  2536. */
  2537. constructor(matrix: Matrix)
  2538. /**
  2539. * Sets the matrix to the passed values. Note that any sequence of
  2540. * parameters that is supported by the various {@link Matrix} constructors
  2541. * also work for calls of `set()`.
  2542. */
  2543. set(...values: any[]): Point
  2544. /**
  2545. * @return a copy of this transform
  2546. */
  2547. clone(): Matrix
  2548. /**
  2549. * Checks whether the two matrices describe the same transformation.
  2550. *
  2551. * @param matrix - the matrix to compare this matrix to
  2552. *
  2553. * @return true if the matrices are equal
  2554. */
  2555. equals(matrix: Matrix): boolean
  2556. /**
  2557. * @return a string representation of this transform
  2558. */
  2559. toString(): string
  2560. /**
  2561. * Resets the matrix by setting its values to the ones of the identity
  2562. * matrix that results in no transformation.
  2563. */
  2564. reset(): void
  2565. /**
  2566. * Attempts to apply the matrix to the content of item that it belongs to,
  2567. * meaning its transformation is baked into the item's content or children.
  2568. *
  2569. * @param recursively - controls whether to apply
  2570. * transformations recursively on children
  2571. *
  2572. * @return true if the matrix was applied
  2573. */
  2574. apply(recursively?: boolean): boolean
  2575. /**
  2576. * Concatenates this matrix with a translate transformation.
  2577. *
  2578. * @param point - the vector to translate by
  2579. *
  2580. * @return this affine transform
  2581. */
  2582. translate(point: Point): Matrix
  2583. /**
  2584. * Concatenates this matrix with a translate transformation.
  2585. *
  2586. * @param dx - the distance to translate in the x direction
  2587. * @param dy - the distance to translate in the y direction
  2588. *
  2589. * @return this affine transform
  2590. */
  2591. translate(dx: number, dy: number): Matrix
  2592. /**
  2593. * Concatenates this matrix with a scaling transformation.
  2594. *
  2595. * @param scale - the scaling factor
  2596. * @param center - the center for the scaling transformation
  2597. *
  2598. * @return this affine transform
  2599. */
  2600. scale(scale: number, center?: Point): Matrix
  2601. /**
  2602. * Concatenates this matrix with a scaling transformation.
  2603. *
  2604. * @param hor - the horizontal scaling factor
  2605. * @param ver - the vertical scaling factor
  2606. * @param center - the center for the scaling transformation
  2607. *
  2608. * @return this affine transform
  2609. */
  2610. scale(hor: number, ver: number, center?: Point): Matrix
  2611. /**
  2612. * Concatenates this matrix with a rotation transformation around an
  2613. * anchor point.
  2614. *
  2615. * @param angle - the angle of rotation measured in degrees
  2616. * @param center - the anchor point to rotate around
  2617. *
  2618. * @return this affine transform
  2619. */
  2620. rotate(angle: number, center: Point): Matrix
  2621. /**
  2622. * Concatenates this matrix with a rotation transformation around an
  2623. * anchor point.
  2624. *
  2625. * @param angle - the angle of rotation measured in degrees
  2626. * @param x - the x coordinate of the anchor point
  2627. * @param y - the y coordinate of the anchor point
  2628. *
  2629. * @return this affine transform
  2630. */
  2631. rotate(angle: number, x: number, y: number): Matrix
  2632. /**
  2633. * Concatenates this matrix with a shear transformation.
  2634. *
  2635. * @param shear - the shear factor in x and y direction
  2636. * @param center - the center for the shear transformation
  2637. *
  2638. * @return this affine transform
  2639. */
  2640. shear(shear: Point, center?: Point): Matrix
  2641. /**
  2642. * Concatenates this matrix with a shear transformation.
  2643. *
  2644. * @param hor - the horizontal shear factor
  2645. * @param ver - the vertical shear factor
  2646. * @param center - the center for the shear transformation
  2647. *
  2648. * @return this affine transform
  2649. */
  2650. shear(hor: number, ver: number, center?: Point): Matrix
  2651. /**
  2652. * Concatenates this matrix with a skew transformation.
  2653. *
  2654. * @param skew - the skew angles in x and y direction in degrees
  2655. * @param center - the center for the skew transformation
  2656. *
  2657. * @return this affine transform
  2658. */
  2659. skew(skew: Point, center?: Point): Matrix
  2660. /**
  2661. * Concatenates this matrix with a skew transformation.
  2662. *
  2663. * @param hor - the horizontal skew angle in degrees
  2664. * @param ver - the vertical skew angle in degrees
  2665. * @param center - the center for the skew transformation
  2666. *
  2667. * @return this affine transform
  2668. */
  2669. skew(hor: number, ver: number, center?: Point): Matrix
  2670. /**
  2671. * Appends the specified matrix to this matrix. This is the equivalent of
  2672. * multiplying `(this matrix) * (specified matrix)`.
  2673. *
  2674. * @param matrix - the matrix to append
  2675. *
  2676. * @return this matrix, modified
  2677. */
  2678. append(matrix: Matrix): Matrix
  2679. /**
  2680. * Prepends the specified matrix to this matrix. This is the equivalent of
  2681. * multiplying `(specified matrix) * (this matrix)`.
  2682. *
  2683. * @param matrix - the matrix to prepend
  2684. *
  2685. * @return this matrix, modified
  2686. */
  2687. prepend(matrix: Matrix): Matrix
  2688. /**
  2689. * Returns a new matrix as the result of appending the specified matrix to
  2690. * this matrix. This is the equivalent of multiplying
  2691. * `(this matrix) * (specified matrix)`.
  2692. *
  2693. * @param matrix - the matrix to append
  2694. *
  2695. * @return the newly created matrix
  2696. */
  2697. appended(matrix: Matrix): Matrix
  2698. /**
  2699. * Returns a new matrix as the result of prepending the specified matrix
  2700. * to this matrix. This is the equivalent of multiplying
  2701. * `(specified matrix) * (this matrix)`.
  2702. *
  2703. * @param matrix - the matrix to prepend
  2704. *
  2705. * @return the newly created matrix
  2706. */
  2707. prepended(matrix: Matrix): Matrix
  2708. /**
  2709. * Inverts the matrix, causing it to perform the opposite transformation.
  2710. * If the matrix is not invertible (in which case {@link #isSingular}
  2711. * returns true), `null` is returned.
  2712. *
  2713. * @return this matrix, or `null`, if the matrix is singular.
  2714. */
  2715. invert(): Matrix
  2716. /**
  2717. * Creates a new matrix that is the inversion of this matrix, causing it to
  2718. * perform the opposite transformation. If the matrix is not invertible (in
  2719. * which case {@link #isSingular} returns true), `null` is returned.
  2720. *
  2721. * @return this matrix, or `null`, if the matrix is singular.
  2722. */
  2723. inverted(): Matrix
  2724. /**
  2725. * @return whether this matrix is the identity matrix
  2726. */
  2727. isIdentity(): boolean
  2728. /**
  2729. * Checks whether the matrix is invertible. A matrix is not invertible if
  2730. * the determinant is 0 or any value is infinite or NaN.
  2731. *
  2732. * @return whether the matrix is invertible
  2733. */
  2734. isInvertible(): boolean
  2735. /**
  2736. * Checks whether the matrix is singular or not. Singular matrices cannot be
  2737. * inverted.
  2738. *
  2739. * @return whether the matrix is singular
  2740. */
  2741. isSingular(): boolean
  2742. /**
  2743. * Transforms a point and returns the result.
  2744. *
  2745. * @param point - the point to be transformed
  2746. *
  2747. * @return the transformed point
  2748. */
  2749. transform(point: Point): Point
  2750. /**
  2751. * Transforms an array of coordinates by this matrix and stores the results
  2752. * into the destination array, which is also returned.
  2753. *
  2754. * @param src - the array containing the source points
  2755. * as x, y value pairs
  2756. * @param dst - the array into which to store the transformed
  2757. * point pairs
  2758. * @param count - the number of points to transform
  2759. *
  2760. * @return the dst array, containing the transformed coordinates
  2761. */
  2762. transform(src: number[], dst: number[], count: number): number[]
  2763. /**
  2764. * Inverse transforms a point and returns the result.
  2765. *
  2766. * @param point - the point to be transformed
  2767. */
  2768. inverseTransform(point: Point): Point
  2769. /**
  2770. * Decomposes the affine transformation described by this matrix into
  2771. * `scaling`, `rotation` and `skewing`, and returns an object with
  2772. * these properties.
  2773. *
  2774. * @return the decomposed matrix
  2775. */
  2776. decompose(): object
  2777. /**
  2778. * Applies this matrix to the specified Canvas Context.
  2779. */
  2780. applyToContext(ctx: CanvasRenderingContext2D): void
  2781. }
  2782. /**
  2783. * The MouseEvent object is received by the {@link Item}'s mouse event
  2784. * handlers {@link Item#onMouseDown}, {@link Item#onMouseDrag},
  2785. * {@link Item#onMouseMove}, {@link Item#onMouseUp}, {@link Item#onClick},
  2786. * {@link Item#onDoubleClick}, {@link Item#onMouseEnter} and
  2787. * {@link Item#onMouseLeave}. The MouseEvent object is the only parameter passed
  2788. * to these functions and contains information about the mouse event.
  2789. */
  2790. class MouseEvent extends Event {
  2791. /**
  2792. * The type of mouse event.
  2793. */
  2794. type: string
  2795. /**
  2796. * The position of the mouse in project coordinates when the event was
  2797. * fired.
  2798. */
  2799. point: Point
  2800. /**
  2801. * The item that dispatched the event. It is different from
  2802. * {@link #currentTarget} when the event handler is called during
  2803. * the bubbling phase of the event.
  2804. */
  2805. target: Item
  2806. /**
  2807. * The current target for the event, as the event traverses the scene graph.
  2808. * It always refers to the element the event handler has been attached to as
  2809. * opposed to {@link #target} which identifies the element on
  2810. * which the event occurred.
  2811. */
  2812. currentTarget: Item
  2813. delta: Point
  2814. /**
  2815. * @return a string representation of the mouse event
  2816. */
  2817. toString(): string
  2818. }
  2819. /**
  2820. * The `PaperScope` class represents the scope associated with a Paper
  2821. * context. When working with PaperScript, these scopes are automatically
  2822. * created for us, and through clever scoping the properties and methods of
  2823. * the active scope seem to become part of the global scope.
  2824. *
  2825. * When working with normal JavaScript code, `PaperScope` objects need to be
  2826. * manually created and handled.
  2827. *
  2828. * Paper classes can only be accessed through `PaperScope` objects. Thus in
  2829. * PaperScript they are global, while in JavaScript, they are available on the
  2830. * global {@link paper} object. For JavaScript you can use {@link
  2831. * PaperScope#install(scope) } to install the Paper classes and objects on the
  2832. * global scope. Note that when working with more than one scope, this still
  2833. * works for classes, but not for objects like {@link PaperScope#project}, since
  2834. * they are not updated in the injected scope if scopes are switched.
  2835. *
  2836. * The global {@link paper} object is simply a reference to the currently active
  2837. * `PaperScope`.
  2838. */
  2839. class PaperScope {
  2840. /**
  2841. * The version of Paper.js, as a string.
  2842. */
  2843. readonly version: string
  2844. /**
  2845. * Gives access to paper's configurable settings.
  2846. *
  2847. * @option [settings.insertItems=true] {Boolean} controls whether newly
  2848. * created items are automatically inserted into the scene graph, by
  2849. * adding them to {@link Project#activeLayer}
  2850. * @option [settings.applyMatrix=true] {Boolean} controls what value newly
  2851. * created items have their {@link Item#applyMatrix} property set to
  2852. * (Note that not all items can set this to `false`)
  2853. * @option [settings.handleSize=4] {Number} the size of the curve handles
  2854. * when drawing selections
  2855. * @option [settings.hitTolerance=0] {Number} the default tolerance for hit-
  2856. * tests, when no value is specified
  2857. */
  2858. settings: any
  2859. /**
  2860. * The currently active project.
  2861. */
  2862. project: Project
  2863. /**
  2864. * The list of all open projects within the current Paper.js context.
  2865. */
  2866. projects: Project[]
  2867. /**
  2868. * The reference to the active project's view.
  2869. */
  2870. readonly view: View
  2871. /**
  2872. * The reference to the active tool.
  2873. */
  2874. tool: Tool
  2875. /**
  2876. * The list of available tools.
  2877. */
  2878. tools: Tool[]
  2879. Color: typeof Color
  2880. CompoundPath: typeof CompoundPath
  2881. Curve: typeof Curve
  2882. CurveLocation: typeof CurveLocation
  2883. Event: typeof Event
  2884. Gradient: typeof Gradient
  2885. GradientStop: typeof GradientStop
  2886. Group: typeof Group
  2887. HitResult: typeof HitResult
  2888. Item: typeof Item
  2889. Key: typeof Key
  2890. KeyEvent: typeof KeyEvent
  2891. Layer: typeof Layer
  2892. Matrix: typeof Matrix
  2893. MouseEvent: typeof MouseEvent
  2894. PaperScope: typeof PaperScope
  2895. PaperScript: typeof PaperScript
  2896. Path: typeof Path
  2897. PathItem: typeof PathItem
  2898. Point: typeof Point
  2899. PointText: typeof PointText
  2900. Project: typeof Project
  2901. Raster: typeof Raster
  2902. Rectangle: typeof Rectangle
  2903. Segment: typeof Segment
  2904. Shape: typeof Shape
  2905. Size: typeof Size
  2906. Style: typeof Style
  2907. SymbolDefinition: typeof SymbolDefinition
  2908. SymbolItem: typeof SymbolItem
  2909. TextItem: typeof TextItem
  2910. Tool: typeof Tool
  2911. ToolEvent: typeof ToolEvent
  2912. Tween: typeof Tween
  2913. View: typeof View
  2914. /**
  2915. * Creates a PaperScope object.
  2916. */
  2917. constructor()
  2918. /**
  2919. * Compiles the PaperScript code into a compiled function and executes it.
  2920. * The compiled function receives all properties of this {@link PaperScope}
  2921. * as arguments, to emulate a global scope with unaffected performance. It
  2922. * also installs global view and tool handlers automatically on the
  2923. * respective objects.
  2924. *
  2925. * @option options.url {String} the url of the source, for source-map
  2926. * debugging
  2927. * @option options.source {String} the source to be used for the source-
  2928. * mapping, in case the code that's passed in has already been mingled.
  2929. *
  2930. * @param code - the PaperScript code
  2931. * @param options - the compilation options
  2932. */
  2933. execute(code: string, options?: object): void
  2934. /**
  2935. * Injects the paper scope into any other given scope. Can be used for
  2936. * example to inject the currently active PaperScope into the window's
  2937. * global scope, to emulate PaperScript-style globally accessible Paper
  2938. * classes and objects.
  2939. *
  2940. * <b>Please note:</b> Using this method may override native constructors
  2941. * (e.g. Path). This may cause problems when using Paper.js in conjunction
  2942. * with other libraries that rely on these constructors. Keep the library
  2943. * scoped if you encounter issues caused by this.
  2944. */
  2945. install(scope: any): void
  2946. /**
  2947. * Sets up an empty project for us. If a canvas is provided, it also creates
  2948. * a {@link View} for it, both linked to this scope.
  2949. *
  2950. * @param element - the HTML canvas element
  2951. * this scope should be associated with, or an ID string by which to find
  2952. * the element, or the size of the canvas to be created for usage in a web
  2953. * worker.
  2954. */
  2955. setup(element: HTMLCanvasElement | string | Size): void
  2956. /**
  2957. * Activates this PaperScope, so all newly created items will be placed
  2958. * in its active project.
  2959. */
  2960. activate(): void
  2961. /**
  2962. * Retrieves a PaperScope object with the given scope id.
  2963. */
  2964. static get(id: any): PaperScope
  2965. }
  2966. class PaperScript {
  2967. /**
  2968. * Compiles PaperScript code into JavaScript code.
  2969. *
  2970. * @option options.url {String} the url of the source, for source-map
  2971. * generation
  2972. * @option options.source {String} the source to be used for the source-
  2973. * mapping, in case the code that's passed in has already been mingled.
  2974. *
  2975. * @param code - the PaperScript code
  2976. * @param options - the compilation options
  2977. *
  2978. * @return an object holding the compiled PaperScript translated
  2979. * into JavaScript code along with source-maps and other information.
  2980. */
  2981. static compile(code: string, options?: object): object
  2982. /**
  2983. * Compiles the PaperScript code into a compiled function and executes it.
  2984. * The compiled function receives all properties of the passed {@link
  2985. * PaperScope} as arguments, to emulate a global scope with unaffected
  2986. * performance. It also installs global view and tool handlers automatically
  2987. * on the respective objects.
  2988. *
  2989. * @option options.url {String} the url of the source, for source-map
  2990. * generation
  2991. * @option options.source {String} the source to be used for the source-
  2992. * mapping, in case the code that's passed in has already been mingled.
  2993. *
  2994. * @param code - the PaperScript code
  2995. * @param scope - the scope for which the code is executed
  2996. * @param options - the compilation options
  2997. *
  2998. * @return the exports defined in the executed code
  2999. */
  3000. static execute(code: string, scope: PaperScope, options?: object): object
  3001. /**
  3002. * Loads, compiles and executes PaperScript code in the HTML document. Note
  3003. * that this method is executed automatically for all scripts in the
  3004. * document through a window load event. You can optionally call it earlier
  3005. * (e.g. from a DOM ready event), or you can mark scripts to be ignored by
  3006. * setting the attribute `ignore="true"` or `data-paper-ignore="true"`, and
  3007. * call the `PaperScript.load(script)` method for each script separately
  3008. * when needed.
  3009. *
  3010. * @param script - the script to load. If none is
  3011. * provided, all scripts of the HTML document are iterated over and
  3012. * loaded
  3013. *
  3014. * @return the scope produced for the passed `script`, or
  3015. * `undefined` of multiple scripts area loaded
  3016. */
  3017. static load(script?: HTMLScriptElement): PaperScope
  3018. }
  3019. /**
  3020. * The path item represents a path in a Paper.js project.
  3021. */
  3022. class Path extends PathItem {
  3023. /**
  3024. * The segments contained within the path.
  3025. */
  3026. segments: Segment[]
  3027. /**
  3028. * The first Segment contained within the path.
  3029. */
  3030. readonly firstSegment: Segment
  3031. /**
  3032. * The last Segment contained within the path.
  3033. */
  3034. readonly lastSegment: Segment
  3035. /**
  3036. * The curves contained within the path.
  3037. */
  3038. readonly curves: Curve[]
  3039. /**
  3040. * The first Curve contained within the path.
  3041. */
  3042. readonly firstCurve: Curve
  3043. /**
  3044. * The last Curve contained within the path.
  3045. */
  3046. readonly lastCurve: Curve
  3047. /**
  3048. * Specifies whether the path is closed. If it is closed, Paper.js connects
  3049. * the first and last segments.
  3050. */
  3051. closed: boolean
  3052. /**
  3053. * The approximate length of the path.
  3054. */
  3055. readonly length: number
  3056. /**
  3057. * The area that the path's geometry is covering. Self-intersecting paths
  3058. * can contain sub-areas that cancel each other out.
  3059. */
  3060. readonly area: number
  3061. /**
  3062. * Specifies whether the path and all its segments are selected. Cannot be
  3063. * `true` on an empty path.
  3064. */
  3065. fullySelected: boolean
  3066. /**
  3067. * Creates a new path item and places it at the top of the active layer.
  3068. *
  3069. * @param segments - An array of segments (or points to be
  3070. * converted to segments) that will be added to the path
  3071. */
  3072. constructor(segments?: Segment[])
  3073. /**
  3074. * Creates a new path item from SVG path-data and places it at the top of
  3075. * the active layer.
  3076. *
  3077. * @param pathData - the SVG path-data that describes the geometry
  3078. * of this path
  3079. */
  3080. constructor(pathData: string)
  3081. /**
  3082. * Creates a new path item from an object description and places it at the
  3083. * top of the active layer.
  3084. *
  3085. * @param object - an object containing properties to be set on the
  3086. * path
  3087. */
  3088. constructor(object: object)
  3089. /**
  3090. * Adds one or more segments to the end of the {@link #segments} array of
  3091. * this path.
  3092. *
  3093. * @param segment - the segment or point to be
  3094. * added.
  3095. *
  3096. * @return the added segment(s). This is not necessarily
  3097. * the same object, e.g. if the segment to be added already belongs to
  3098. * another path.
  3099. */
  3100. add(...segment: (Segment | Point | number[])[]): Segment | Segment[]
  3101. /**
  3102. * Inserts one or more segments at a given index in the list of this path's
  3103. * segments.
  3104. *
  3105. * @param index - the index at which to insert the segment
  3106. * @param segment - the segment or point to be inserted.
  3107. *
  3108. * @return the added segment. This is not necessarily the same
  3109. * object, e.g. if the segment to be added already belongs to another path
  3110. */
  3111. insert(index: number, segment: Segment | Point): Segment
  3112. /**
  3113. * Adds an array of segments (or types that can be converted to segments)
  3114. * to the end of the {@link #segments} array.
  3115. *
  3116. * @return an array of the added segments. These segments are
  3117. * not necessarily the same objects, e.g. if the segment to be added already
  3118. * belongs to another path
  3119. */
  3120. addSegments(segments: Segment[]): Segment[]
  3121. /**
  3122. * Inserts an array of segments at a given index in the path's
  3123. * {@link #segments} array.
  3124. *
  3125. * @param index - the index at which to insert the segments
  3126. * @param segments - the segments to be inserted
  3127. *
  3128. * @return an array of the added segments. These segments are
  3129. * not necessarily the same objects, e.g. if the segment to be added already
  3130. * belongs to another path
  3131. */
  3132. insertSegments(index: number, segments: Segment[]): Segment[]
  3133. /**
  3134. * Removes the segment at the specified index of the path's
  3135. * {@link #segments} array.
  3136. *
  3137. * @param index - the index of the segment to be removed
  3138. *
  3139. * @return the removed segment
  3140. */
  3141. removeSegment(index: number): Segment
  3142. /**
  3143. * Removes all segments from the path's {@link #segments} array.
  3144. *
  3145. * @return an array containing the removed segments
  3146. */
  3147. removeSegments(): Segment[]
  3148. /**
  3149. * Removes the segments from the specified `from` index to the `to` index
  3150. * from the path's {@link #segments} array.
  3151. *
  3152. * @param from - the beginning index, inclusive
  3153. * @param to - the ending index, exclusive
  3154. *
  3155. * @return an array containing the removed segments
  3156. */
  3157. removeSegments(from: number, to?: number): Segment[]
  3158. /**
  3159. * Checks if any of the curves in the path have curve handles set.
  3160. *
  3161. * @see Segment#hasHandles()
  3162. * @see Curve#hasHandles()
  3163. *
  3164. * @return true if the path has curve handles set
  3165. */
  3166. hasHandles(): boolean
  3167. /**
  3168. * Clears the path's handles by setting their coordinates to zero,
  3169. * turning the path into a polygon (or a polyline if it isn't closed).
  3170. */
  3171. clearHandles(): void
  3172. /**
  3173. * Divides the path on the curve at the given offset or location into two
  3174. * curves, by inserting a new segment at the given location.
  3175. *
  3176. * @see Curve#divideAt(location)
  3177. *
  3178. * @param location - the offset or location on the
  3179. * path at which to divide the existing curve by inserting a new segment
  3180. *
  3181. * @return the newly inserted segment if the location is valid,
  3182. * `null` otherwise
  3183. */
  3184. divideAt(location: number | CurveLocation): Segment
  3185. /**
  3186. * Splits the path at the given offset or location. After splitting, the
  3187. * path will be open. If the path was open already, splitting will result in
  3188. * two paths.
  3189. *
  3190. * @param location - the offset or location at which to
  3191. * split the path
  3192. *
  3193. * @return the newly created path after splitting, if any
  3194. */
  3195. splitAt(location: number | CurveLocation): Path
  3196. /**
  3197. * Joins the path with the other specified path, which will be removed in
  3198. * the process. They can be joined if the first or last segments of either
  3199. * path lie in the same location. Locations are optionally compare with a
  3200. * provide `tolerance` value.
  3201. *
  3202. * If `null` or `this` is passed as the other path, the path will be joined
  3203. * with itself if the first and last segment are in the same location.
  3204. *
  3205. * @param path - the path to join this path with; `null` or `this` to
  3206. * join the path with itself
  3207. * @param tolerance - the tolerance with which to decide if two
  3208. * segments are to be considered the same location when joining
  3209. */
  3210. join(path: Path, tolerance?: number): void
  3211. /**
  3212. * Reduces the path by removing curves that have a length of 0,
  3213. * and unnecessary segments between two collinear flat curves.
  3214. *
  3215. * @return the reduced path
  3216. */
  3217. reduce(options: any): Path
  3218. /**
  3219. * Attempts to create a new shape item with same geometry as this path item,
  3220. * and inherits all settings from it, similar to {@link Item#clone}.
  3221. *
  3222. * @see Shape#toPath(insert)
  3223. *
  3224. * @param insert - specifies whether the new shape should be
  3225. * inserted into the scene graph. When set to `true`, it is inserted above
  3226. * the path item
  3227. *
  3228. * @return the newly created shape item with the same geometry as
  3229. * this path item if it can be matched, `null` otherwise
  3230. */
  3231. toShape(insert?: boolean): Shape
  3232. /**
  3233. * Returns the curve location of the specified point if it lies on the
  3234. * path, `null` otherwise.
  3235. *
  3236. * @param point - the point on the path
  3237. *
  3238. * @return the curve location of the specified point
  3239. */
  3240. getLocationOf(point: Point): CurveLocation
  3241. /**
  3242. * Returns the length of the path from its beginning up to up to the
  3243. * specified point if it lies on the path, `null` otherwise.
  3244. *
  3245. * @param point - the point on the path
  3246. *
  3247. * @return the length of the path up to the specified point
  3248. */
  3249. getOffsetOf(point: Point): number
  3250. /**
  3251. * Returns the curve location of the specified offset on the path.
  3252. *
  3253. * @param offset - the offset on the path, where `0` is at
  3254. * the beginning of the path and {@link Path#length} at the end
  3255. *
  3256. * @return the curve location at the specified offset
  3257. */
  3258. getLocationAt(offset: number): CurveLocation
  3259. /**
  3260. * Calculates the point on the path at the given offset.
  3261. *
  3262. * @param offset - the offset on the path, where `0` is at
  3263. * the beginning of the path and {@link Path#length} at the end
  3264. *
  3265. * @return the point at the given offset
  3266. */
  3267. getPointAt(offset: number): Point
  3268. /**
  3269. * Calculates the normalized tangent vector of the path at the given offset.
  3270. *
  3271. * @param offset - the offset on the path, where `0` is at
  3272. * the beginning of the path and {@link Path#length} at the end
  3273. *
  3274. * @return the normalized tangent vector at the given offset
  3275. */
  3276. getTangentAt(offset: number): Point
  3277. /**
  3278. * Calculates the normal vector of the path at the given offset.
  3279. *
  3280. * @param offset - the offset on the path, where `0` is at
  3281. * the beginning of the path and {@link Path#length} at the end
  3282. *
  3283. * @return the normal vector at the given offset
  3284. */
  3285. getNormalAt(offset: number): Point
  3286. /**
  3287. * Calculates the weighted tangent vector of the path at the given offset.
  3288. *
  3289. * @param offset - the offset on the path, where `0` is at
  3290. * the beginning of the path and {@link Path#length} at the end
  3291. *
  3292. * @return the weighted tangent vector at the given offset
  3293. */
  3294. getWeightedTangentAt(offset: number): Point
  3295. /**
  3296. * Calculates the weighted normal vector of the path at the given offset.
  3297. *
  3298. * @param offset - the offset on the path, where `0` is at
  3299. * the beginning of the path and {@link Path#length} at the end
  3300. *
  3301. * @return the weighted normal vector at the given offset
  3302. */
  3303. getWeightedNormalAt(offset: number): Point
  3304. /**
  3305. * Calculates the curvature of the path at the given offset. Curvatures
  3306. * indicate how sharply a path changes direction. A straight line has zero
  3307. * curvature, where as a circle has a constant curvature. The path's radius
  3308. * at the given offset is the reciprocal value of its curvature.
  3309. *
  3310. * @param offset - the offset on the path, where `0` is at
  3311. * the beginning of the path and {@link Path#length} at the end
  3312. *
  3313. * @return the normal vector at the given offset
  3314. */
  3315. getCurvatureAt(offset: number): number
  3316. /**
  3317. * Calculates path offsets where the path is tangential to the provided
  3318. * tangent. Note that tangents at the start or end are included. Tangents at
  3319. * segment points are returned even if only one of their handles is
  3320. * collinear with the provided tangent.
  3321. *
  3322. * @param tangent - the tangent to which the path must be tangential
  3323. *
  3324. * @return path offsets where the path is tangential to the
  3325. * provided tangent
  3326. */
  3327. getOffsetsWithTangent(tangent: Point): number[]
  3328. }
  3329. namespace Path {
  3330. class Line extends Path {
  3331. /**
  3332. * Creates a linear path item from two points describing a line.
  3333. *
  3334. * @param from - the line's starting point
  3335. * @param to - the line's ending point
  3336. */
  3337. constructor(from: Point, to: Point)
  3338. /**
  3339. * Creates a linear path item from the properties described by an object
  3340. * literal.
  3341. *
  3342. * @param object - an object containing properties describing the
  3343. * path's attributes
  3344. */
  3345. constructor(object: object)
  3346. }
  3347. class Circle extends Path {
  3348. /**
  3349. * Creates a circular path item.
  3350. *
  3351. * @param center - the center point of the circle
  3352. * @param radius - the radius of the circle
  3353. */
  3354. constructor(center: Point, radius: number)
  3355. /**
  3356. * Creates a circular path item from the properties described by an
  3357. * object literal.
  3358. *
  3359. * @param object - an object containing properties describing the
  3360. * path's attributes
  3361. */
  3362. constructor(object: object)
  3363. }
  3364. class Rectangle extends Path {
  3365. /**
  3366. * Creates a rectangular path item, with optionally rounded corners.
  3367. *
  3368. * @param rectangle - the rectangle object describing the
  3369. * geometry of the rectangular path to be created
  3370. * @param radius - the size of the rounded corners
  3371. */
  3372. constructor(rectangle: paper.Rectangle, radius?: Size)
  3373. /**
  3374. * Creates a rectangular path item from a point and a size object.
  3375. *
  3376. * @param point - the rectangle's top-left corner.
  3377. * @param size - the rectangle's size.
  3378. */
  3379. constructor(point: Point, size: Size)
  3380. /**
  3381. * Creates a rectangular path item from the passed points. These do not
  3382. * necessarily need to be the top left and bottom right corners, the
  3383. * constructor figures out how to fit a rectangle between them.
  3384. *
  3385. * @param from - the first point defining the rectangle
  3386. * @param to - the second point defining the rectangle
  3387. */
  3388. constructor(from: Point, to: Point)
  3389. /**
  3390. * Creates a rectangular path item from the properties described by an
  3391. * object literal.
  3392. *
  3393. * @param object - an object containing properties describing the
  3394. * path's attributes
  3395. */
  3396. constructor(object: object)
  3397. }
  3398. class Ellipse extends Path {
  3399. /**
  3400. * Creates an elliptical path item.
  3401. *
  3402. * @param rectangle - the rectangle circumscribing the ellipse
  3403. */
  3404. constructor(rectangle: paper.Rectangle)
  3405. /**
  3406. * Creates an elliptical path item from the properties described by an
  3407. * object literal.
  3408. *
  3409. * @param object - an object containing properties describing the
  3410. * path's attributes
  3411. */
  3412. constructor(object: object)
  3413. }
  3414. class Arc extends Path {
  3415. /**
  3416. * Creates a circular arc path item.
  3417. *
  3418. * @param from - the starting point of the circular arc
  3419. * @param through - the point the arc passes through
  3420. * @param to - the end point of the arc
  3421. */
  3422. constructor(from: Point, through: Point, to: Point)
  3423. /**
  3424. * Creates an circular arc path item from the properties described by an
  3425. * object literal.
  3426. *
  3427. * @param object - an object containing properties describing the
  3428. * path's attributes
  3429. */
  3430. constructor(object: object)
  3431. }
  3432. class RegularPolygon extends Path {
  3433. /**
  3434. * Creates a regular polygon shaped path item.
  3435. *
  3436. * @param center - the center point of the polygon
  3437. * @param sides - the number of sides of the polygon
  3438. * @param radius - the radius of the polygon
  3439. */
  3440. constructor(center: Point, sides: number, radius: number)
  3441. /**
  3442. * Creates a regular polygon shaped path item from the properties
  3443. * described by an object literal.
  3444. *
  3445. * @param object - an object containing properties describing the
  3446. * path's attributes
  3447. */
  3448. constructor(object: object)
  3449. }
  3450. class Star extends Path {
  3451. /**
  3452. * Creates a star shaped path item.
  3453. *
  3454. * The largest of `radius1` and `radius2` will be the outer radius of
  3455. * the star. The smallest of radius1 and radius2 will be the inner
  3456. * radius.
  3457. *
  3458. * @param center - the center point of the star
  3459. * @param points - the number of points of the star
  3460. */
  3461. constructor(center: Point, points: number, radius1: number, radius2: number)
  3462. /**
  3463. * Creates a star shaped path item from the properties described by an
  3464. * object literal.
  3465. *
  3466. * @param object - an object containing properties describing the
  3467. * path's attributes
  3468. */
  3469. constructor(object: object)
  3470. }
  3471. }
  3472. /**
  3473. * The PathItem class is the base for any items that describe paths and
  3474. * offer standardised methods for drawing and path manipulation, such as
  3475. * {@link Path} and {@link CompoundPath}.
  3476. */
  3477. class PathItem extends Item {
  3478. /**
  3479. * Returns a point that is guaranteed to be inside the path.
  3480. */
  3481. readonly interiorPoint: Point
  3482. /**
  3483. * Specifies whether the path as a whole is oriented clock-wise, by looking
  3484. * at the path's area.
  3485. * Note that self-intersecting paths and sub-paths of different orientation
  3486. * can result in areas that cancel each other out.
  3487. *
  3488. * @see Path#area
  3489. * @see CompoundPath#area
  3490. */
  3491. clockwise: boolean
  3492. /**
  3493. * The path's geometry, formatted as SVG style path data.
  3494. */
  3495. pathData: string
  3496. /**
  3497. * Unites the geometry of the specified path with this path's geometry
  3498. * and returns the result as a new path item.
  3499. *
  3500. * @option [options.insert=true] {Boolean} whether the resulting item
  3501. * should be inserted back into the scene graph, above both paths
  3502. * involved in the operation
  3503. *
  3504. * @param path - the path to unite with
  3505. * @param options - the boolean operation options
  3506. *
  3507. * @return the resulting path item
  3508. */
  3509. unite(path: PathItem, options?: object): PathItem
  3510. /**
  3511. * Intersects the geometry of the specified path with this path's
  3512. * geometry and returns the result as a new path item.
  3513. *
  3514. * @option [options.insert=true] {Boolean} whether the resulting item
  3515. * should be inserted back into the scene graph, above both paths
  3516. * involved in the operation
  3517. * @option [options.trace=true] {Boolean} whether the tracing method is
  3518. * used, treating both paths as areas when determining which parts
  3519. * of the paths are to be kept in the result, or whether the first
  3520. * path is only to be split at intersections, keeping the parts of
  3521. * the curves that intersect with the area of the second path.
  3522. *
  3523. * @param path - the path to intersect with
  3524. * @param options - the boolean operation options
  3525. *
  3526. * @return the resulting path item
  3527. */
  3528. intersect(path: PathItem, options?: object): PathItem
  3529. /**
  3530. * Subtracts the geometry of the specified path from this path's
  3531. * geometry and returns the result as a new path item.
  3532. *
  3533. * @option [options.insert=true] {Boolean} whether the resulting item
  3534. * should be inserted back into the scene graph, above both paths
  3535. * involved in the operation
  3536. * @option [options.trace=true] {Boolean} whether the tracing method is
  3537. * used, treating both paths as areas when determining which parts
  3538. * of the paths are to be kept in the result, or whether the first
  3539. * path is only to be split at intersections, removing the parts of
  3540. * the curves that intersect with the area of the second path.
  3541. *
  3542. * @param path - the path to subtract
  3543. * @param options - the boolean operation options
  3544. *
  3545. * @return the resulting path item
  3546. */
  3547. subtract(path: PathItem, options?: object): PathItem
  3548. /**
  3549. * Excludes the intersection of the geometry of the specified path with
  3550. * this path's geometry and returns the result as a new path item.
  3551. *
  3552. * @option [options.insert=true] {Boolean} whether the resulting item
  3553. * should be inserted back into the scene graph, above both paths
  3554. * involved in the operation
  3555. *
  3556. * @param path - the path to exclude the intersection of
  3557. * @param options - the boolean operation options
  3558. *
  3559. * @return the resulting path item
  3560. */
  3561. exclude(path: PathItem, options?: object): PathItem
  3562. /**
  3563. * Splits the geometry of this path along the geometry of the specified
  3564. * path returns the result as a new group item. This is equivalent to
  3565. * calling {@link #subtract} and {@link #intersect} and
  3566. * putting the results into a new group.
  3567. *
  3568. * @option [options.insert=true] {Boolean} whether the resulting item
  3569. * should be inserted back into the scene graph, above both paths
  3570. * involved in the operation
  3571. * @option [options.trace=true] {Boolean} whether the tracing method is
  3572. * used, treating both paths as areas when determining which parts
  3573. * of the paths are to be kept in the result, or whether the first
  3574. * path is only to be split at intersections.
  3575. *
  3576. * @param path - the path to divide by
  3577. * @param options - the boolean operation options
  3578. *
  3579. * @return the resulting path item
  3580. */
  3581. divide(path: PathItem, options?: object): PathItem
  3582. /**
  3583. * Fixes the orientation of the sub-paths of a compound-path, assuming
  3584. * that non of its sub-paths intersect, by reorienting them so that they
  3585. * are of different winding direction than their containing paths,
  3586. * except for disjoint sub-paths, i.e. islands, which are oriented so
  3587. * that they have the same winding direction as the the biggest path.
  3588. *
  3589. * @param nonZero - controls if the non-zero fill-rule
  3590. * is to be applied, by counting the winding of each nested path and
  3591. * discarding sub-paths that do not contribute to the final result
  3592. * @param clockwise - if provided, the orientation of the root
  3593. * paths will be set to the orientation specified by `clockwise`,
  3594. * otherwise the orientation of the largest root child is used.
  3595. *
  3596. * @return a reference to the item itself, reoriented
  3597. */
  3598. reorient(nonZero?: boolean, clockwise?: boolean): PathItem
  3599. /**
  3600. * Creates a path item from the given SVG path-data, determining if the
  3601. * data describes a plain path or a compound-path with multiple
  3602. * sub-paths.
  3603. *
  3604. * @param pathData - the SVG path-data to parse
  3605. *
  3606. * @return the newly created path item
  3607. */
  3608. static create(pathData: string): Path | CompoundPath
  3609. /**
  3610. * Creates a path item from the given segments array, determining if the
  3611. * array describes a plain path or a compound-path with multiple
  3612. * sub-paths.
  3613. *
  3614. * @param segments - the segments array to parse
  3615. *
  3616. * @return the newly created path item
  3617. */
  3618. static create(segments: number[][]): Path | CompoundPath
  3619. /**
  3620. * Creates a path item from the given object, determining if the
  3621. * contained information describes a plain path or a compound-path with
  3622. * multiple sub-paths.
  3623. *
  3624. * @param object - an object containing the properties describing
  3625. * the item to be created
  3626. *
  3627. * @return the newly created path item
  3628. */
  3629. static create(object: object): Path | CompoundPath
  3630. /**
  3631. * Returns all intersections between two {@link PathItem} items as an array
  3632. * of {@link CurveLocation} objects. {@link CompoundPath} items are also
  3633. * supported.
  3634. *
  3635. * @see #getCrossings(path)
  3636. *
  3637. * @param path - the other item to find the intersections with
  3638. * @param include - a callback function that can be used to
  3639. * filter out undesired locations right while they are collected. When
  3640. * defined, it shall return {@true to include a location}.
  3641. *
  3642. * @return the locations of all intersection between the
  3643. * paths
  3644. */
  3645. getIntersections(path: PathItem, include?: Function): CurveLocation[]
  3646. /**
  3647. * Returns all crossings between two {@link PathItem} items as an array of
  3648. * {@link CurveLocation} objects. {@link CompoundPath} items are also
  3649. * supported. Crossings are intersections where the paths actually are
  3650. * crossing each other, as opposed to simply touching.
  3651. *
  3652. * @see #getIntersections(path)
  3653. *
  3654. * @param path - the other item to find the crossings with
  3655. *
  3656. * @return the locations of all crossings between the
  3657. * paths
  3658. */
  3659. getCrossings(path: PathItem): CurveLocation[]
  3660. /**
  3661. * Returns the nearest location on the path item to the specified point.
  3662. *
  3663. * @param point - the point for which we search the nearest location
  3664. *
  3665. * @return the location on the path that's the closest to
  3666. * the specified point
  3667. */
  3668. getNearestLocation(point: Point): CurveLocation
  3669. /**
  3670. * Returns the nearest point on the path item to the specified point.
  3671. *
  3672. * @param point - the point for which we search the nearest point
  3673. *
  3674. * @return the point on the path that's the closest to the specified
  3675. * point
  3676. */
  3677. getNearestPoint(point: Point): Point
  3678. /**
  3679. * Reverses the orientation of the path item. When called on
  3680. * {@link CompoundPath} items, each of the nested paths is reversed. On
  3681. * {@link Path} items, the sequence of {@link Path#segments} is reversed.
  3682. */
  3683. reverse(): void
  3684. /**
  3685. * Flattens the curves in path items to a sequence of straight lines, by
  3686. * subdividing them enough times until the specified maximum error is met.
  3687. *
  3688. * @param flatness - the maximum error between the flattened
  3689. * lines and the original curves
  3690. */
  3691. flatten(flatness?: number): void
  3692. /**
  3693. * Smooths the path item without changing the amount of segments in the path
  3694. * or moving the segments' locations, by smoothing and adjusting the angle
  3695. * and length of the segments' handles based on the position and distance of
  3696. * neighboring segments.
  3697. *
  3698. * Smoothing works both for open paths and closed paths, and can be applied
  3699. * to the full path, as well as a sub-range of it. If a range is defined
  3700. * using the `options.from` and `options.to` properties, only the curve
  3701. * handles inside that range are touched. If one or both limits of the range
  3702. * are specified in negative indices, the indices are wrapped around the end
  3703. * of the curve. That way, a smoothing range in a close path can even wrap
  3704. * around the connection between the last and the first segment.
  3705. *
  3706. * Four different smoothing methods are available:
  3707. *
  3708. * - `'continuous'` smooths the path item by adjusting its curve handles so
  3709. * that the first and second derivatives of all involved curves are
  3710. * continuous across their boundaries.
  3711. *
  3712. * This method tends to result in the smoothest results, but does not
  3713. * allow for further parametrization of the handles.
  3714. *
  3715. * - `'asymmetric'` is based on the same principle as `'continuous'` but
  3716. * uses different factors so that the result is asymmetric. This used to
  3717. * the only method available until v0.10.0, and is currently still the
  3718. * default when no method is specified, for reasons of backward
  3719. * compatibility. It will eventually be removed.
  3720. *
  3721. * - `'catmull-rom'` uses the Catmull-Rom spline to smooth the segment.
  3722. *
  3723. * The optionally passed factor controls the knot parametrization of the
  3724. * algorithm:
  3725. *
  3726. * - `0.0`: the standard, uniform Catmull-Rom spline
  3727. * - `0.5`: the centripetal Catmull-Rom spline, guaranteeing no
  3728. * self-intersections
  3729. * - `1.0`: the chordal Catmull-Rom spline
  3730. *
  3731. * - `'geometric'` use a simple heuristic and empiric geometric method to
  3732. * smooth the segment's handles. The handles were weighted, meaning that
  3733. * big differences in distances between the segments will lead to
  3734. * probably undesired results.
  3735. *
  3736. * The optionally passed factor defines the tension parameter (`0...1`),
  3737. * controlling the amount of smoothing as a factor by which to scale
  3738. * each handle.
  3739. *
  3740. * @see Segment#smooth([options])
  3741. *
  3742. * @option [options.type='asymmetric'] {String} the type of smoothing
  3743. * method: {@values 'continuous', 'asymmetric', 'catmull-rom',
  3744. * 'geometric'}
  3745. * @option options.factor {Number} the factor parameterizing the smoothing
  3746. * method — default: `0.5` for `'catmull-rom'`, `0.4` for `'geometric'`
  3747. * @option options.from {Number|Segment|Curve} the segment or curve at which
  3748. * to start smoothing, if not the full path shall be smoothed
  3749. * (inclusive). This can either be a segment index, or a segment or
  3750. * curve object that is part of the path. If the passed number is
  3751. * negative, the index is wrapped around the end of the path.
  3752. * @option options.to {Number|Segment|Curve} the segment or curve to which
  3753. * the handles of the path shall be processed (inclusive). This can
  3754. * either be a segment index, or a segment or curve object that is part
  3755. * of the path. If the passed number is negative, the index is wrapped
  3756. * around the end of the path.
  3757. *
  3758. * @param options - the smoothing options
  3759. */
  3760. smooth(options?: object): void
  3761. /**
  3762. * Fits a sequence of as few curves as possible through the path's anchor
  3763. * points, ignoring the path items's curve-handles, with an allowed maximum
  3764. * error. When called on {@link CompoundPath} items, each of the nested
  3765. * paths is simplified. On {@link Path} items, the {@link Path#segments}
  3766. * array is processed and replaced by the resulting sequence of fitted
  3767. * curves.
  3768. *
  3769. * This method can be used to process and simplify the point data received
  3770. * from a mouse or touch device.
  3771. *
  3772. * @param tolerance - the allowed maximum error when fitting
  3773. * the curves through the segment points
  3774. *
  3775. * @return true if the method was capable of fitting curves
  3776. * through the path's segment points
  3777. */
  3778. simplify(tolerance?: number): boolean
  3779. /**
  3780. * Interpolates between the two specified path items and uses the result
  3781. * as the geometry for this path item. The number of children and
  3782. * segments in the two paths involved in the operation should be the same.
  3783. *
  3784. * @param from - the path item defining the geometry when `factor`
  3785. * is `0`
  3786. * @param to - the path item defining the geometry when `factor`
  3787. * is `1`
  3788. * @param factor - the interpolation coefficient, typically between
  3789. * `0` and `1`, but extrapolation is possible too
  3790. */
  3791. interpolate(from: PathItem, to: PathItem, factor: number): void
  3792. /**
  3793. * Compares the geometry of two paths to see if they describe the same
  3794. * shape, detecting cases where paths start in different segments or even
  3795. * use different amounts of curves to describe the same shape, as long as
  3796. * their orientation is the same, and their segments and handles really
  3797. * result in the same visual appearance of curves.
  3798. *
  3799. * @param path - the path to compare this path's geometry with
  3800. *
  3801. * @return true if two paths describe the same shape
  3802. */
  3803. compare(path: PathItem): boolean
  3804. /**
  3805. * On a normal empty {@link Path}, the point is simply added as the path's
  3806. * first segment. If called on a {@link CompoundPath}, a new {@link Path} is
  3807. * created as a child and the point is added as its first segment.
  3808. *
  3809. * @param point - the point in which to start the path
  3810. */
  3811. moveTo(point: Point): void
  3812. /**
  3813. * Adds a straight curve to the path, from the the last segment in the path
  3814. * to the specified point.
  3815. *
  3816. * @param point - the destination point of the newly added straight
  3817. * curve
  3818. */
  3819. lineTo(point: Point): void
  3820. /**
  3821. * Adds an arc from the position of the last segment in the path, passing
  3822. * through the specified `through` point, to the specified `to` point, by
  3823. * adding one or more segments to the path.
  3824. *
  3825. * @param through - the point where the arc should pass through
  3826. * @param to - the point where the arc should end
  3827. */
  3828. arcTo(through: Point, to: Point): void
  3829. /**
  3830. * Adds an arc from the position of the last segment in the path to
  3831. * the specified point, by adding one or more segments to the path.
  3832. *
  3833. * @param to - the point where the arc should end
  3834. * @param clockwise - specifies whether the arc should be
  3835. * drawn in clockwise direction
  3836. */
  3837. arcTo(to: Point, clockwise?: boolean): void
  3838. /**
  3839. * Adds a curve from the last segment in the path through the specified
  3840. * `through` point, to the specified destination point by adding one segment
  3841. * to the path.
  3842. *
  3843. * @param through - the point through which the curve should pass
  3844. * @param to - the destination point of the newly added curve
  3845. * @param time - the curve-time parameter at which the
  3846. * `through` point is to be located
  3847. */
  3848. curveTo(through: Point, to: Point, time?: number): void
  3849. /**
  3850. * Adds a cubic bezier curve to the path, from the last segment to the
  3851. * specified destination point, with the curve itself defined by two
  3852. * specified handles.
  3853. *
  3854. * @param handle1 - the location of the first handle of the newly
  3855. * added curve in absolute coordinates, out of which the relative values
  3856. * for {@link Segment#handleOut} of its first segment are calculated
  3857. * @param handle2 - the location of the second handle of the newly
  3858. * added curve in absolute coordinates, out of which the relative values
  3859. * for {@link Segment#handleIn} of its second segment are calculated
  3860. * @param to - the destination point of the newly added curve
  3861. */
  3862. cubicCurveTo(handle1: Point, handle2: Point, to: Point): void
  3863. /**
  3864. * Adds a quadratic bezier curve to the path, from the last segment to the
  3865. * specified destination point, with the curve itself defined by the
  3866. * specified handle.
  3867. *
  3868. * Note that Paper.js only stores cubic curves, so the handle is actually
  3869. * converted.
  3870. *
  3871. * @param handle - the location of the handle of the newly added
  3872. * quadratic curve in absolute coordinates, out of which the relative
  3873. * values for {@link Segment#handleOut} of the resulting cubic curve's
  3874. * first segment and {@link Segment#handleIn} of its second segment are
  3875. * calculated
  3876. * @param to - the destination point of the newly added curve
  3877. */
  3878. quadraticCurveTo(handle: Point, to: Point): void
  3879. /**
  3880. * Closes the path. When closed, Paper.js connects the first and last
  3881. * segment of the path with an additional curve. The difference to setting
  3882. * {@link Path#closed} to `true` is that this will also merge the first
  3883. * segment with the last if they lie in the same location.
  3884. *
  3885. * @see Path#closed
  3886. */
  3887. closePath(): void
  3888. /**
  3889. * If called on a {@link CompoundPath}, a new {@link Path} is created as a
  3890. * child and a point is added as its first segment relative to the position
  3891. * of the last segment of the current path.
  3892. */
  3893. moveBy(to: Point): void
  3894. /**
  3895. * Adds a straight curve to the path, from the the last segment in the path
  3896. * to the `to` vector specified relatively to it.
  3897. *
  3898. * @param point - the vector describing the destination of the newly
  3899. * added straight curve
  3900. */
  3901. lineBy(point: Point): void
  3902. /**
  3903. * Adds an arc from the position of the last segment in the path, passing
  3904. * through the specified `through` vector, to the specified `to` vector, all
  3905. * specified relatively to it by these given vectors, by adding one or more
  3906. * segments to the path.
  3907. *
  3908. * @param through - the vector where the arc should pass through
  3909. * @param to - the vector where the arc should end
  3910. */
  3911. arcBy(through: Point, to: Point): void
  3912. /**
  3913. * Adds an arc from the position of the last segment in the path to the `to`
  3914. * vector specified relatively to it, by adding one or more segments to the
  3915. * path.
  3916. *
  3917. * @param to - the vector where the arc should end
  3918. * @param clockwise - specifies whether the arc should be
  3919. * drawn in clockwise direction
  3920. */
  3921. arcBy(to: Point, clockwise?: boolean): void
  3922. /**
  3923. * Adds a curve from the last segment in the path through the specified
  3924. * `through` vector, to the specified `to` vector, all specified relatively
  3925. * to it by these given vectors, by adding one segment to the path.
  3926. *
  3927. * @param through - the vector through which the curve should pass
  3928. * @param to - the destination vector of the newly added curve
  3929. * @param time - the curve-time parameter at which the
  3930. * `through` point is to be located
  3931. */
  3932. curveBy(through: Point, to: Point, time?: number): void
  3933. /**
  3934. * Adds a cubic bezier curve to the path, from the last segment to the
  3935. * to the specified `to` vector, with the curve itself defined by two
  3936. * specified handles.
  3937. *
  3938. * @param handle1 - the location of the first handle of the newly
  3939. * added curve
  3940. * @param handle2 - the location of the second handle of the newly
  3941. * added curve
  3942. * @param to - the destination point of the newly added curve
  3943. */
  3944. cubicCurveBy(handle1: Point, handle2: Point, to: Point): void
  3945. /**
  3946. * Adds a quadratic bezier curve to the path, from the last segment to the
  3947. * specified destination point, with the curve itself defined by the
  3948. * specified handle.
  3949. *
  3950. * Note that Paper.js only stores cubic curves, so the handle is actually
  3951. * converted.
  3952. *
  3953. * @param handle - the handle of the newly added quadratic curve out
  3954. * of which the values for {@link Segment#handleOut} of the resulting
  3955. * cubic curve's first segment and {@link Segment#handleIn} of its
  3956. * second segment are calculated
  3957. * @param to - the destination point of the newly added curve
  3958. */
  3959. quadraticCurveBy(handle: Point, to: Point): void
  3960. }
  3961. /**
  3962. * The Point object represents a point in the two dimensional space
  3963. * of the Paper.js project. It is also used to represent two dimensional
  3964. * vector objects.
  3965. */
  3966. class Point {
  3967. /**
  3968. * The x coordinate of the point
  3969. */
  3970. x: number
  3971. /**
  3972. * The y coordinate of the point
  3973. */
  3974. y: number
  3975. /**
  3976. * The length of the vector that is represented by this point's coordinates.
  3977. * Each point can be interpreted as a vector that points from the origin (`x
  3978. * = 0`, `y = 0`) to the point's location. Setting the length changes the
  3979. * location but keeps the vector's angle.
  3980. */
  3981. length: number
  3982. /**
  3983. * The vector's angle in degrees, measured from the x-axis to the vector.
  3984. */
  3985. angle: number
  3986. /**
  3987. * The vector's angle in radians, measured from the x-axis to the vector.
  3988. */
  3989. angleInRadians: number
  3990. /**
  3991. * The quadrant of the {@link #angle} of the point.
  3992. *
  3993. * Angles between 0 and 90 degrees are in quadrant `1`. Angles between 90
  3994. * and 180 degrees are in quadrant `2`, angles between 180 and 270 degrees
  3995. * are in quadrant `3` and angles between 270 and 360 degrees are in
  3996. * quadrant `4`.
  3997. */
  3998. readonly quadrant: number
  3999. /**
  4000. * This property is only valid if the point is an anchor or handle point
  4001. * of a {@link Segment} or a {@link Curve}, or the position of an
  4002. * {@link Item}, as returned by {@link Item#position},
  4003. * {@link Segment#point}, {@link Segment#handleIn},
  4004. * {@link Segment#handleOut}, {@link Curve#point1}, {@link Curve#point2},
  4005. * {@link Curve#handle1}, {@link Curve#handle2}.
  4006. *
  4007. * In those cases, it returns {@true if it the point is selected}.
  4008. *
  4009. * Paper.js renders selected points on top of your project. This is very
  4010. * useful when debugging.
  4011. */
  4012. selected: boolean
  4013. /**
  4014. * Creates a Point object with the given x and y coordinates.
  4015. *
  4016. * @param x - the x coordinate
  4017. * @param y - the y coordinate
  4018. */
  4019. constructor(x: number, y: number)
  4020. /**
  4021. * Creates a Point object using the numbers in the given array as
  4022. * coordinates.
  4023. */
  4024. constructor(array: any[])
  4025. /**
  4026. * Creates a Point object using the width and height values of the given
  4027. * Size object.
  4028. */
  4029. constructor(size: Size)
  4030. /**
  4031. * Creates a Point object using the coordinates of the given Point object.
  4032. */
  4033. constructor(point: Point)
  4034. /**
  4035. * Creates a Point object using the properties in the given object.
  4036. *
  4037. * @param object - the object describing the point's properties
  4038. */
  4039. constructor(object: object)
  4040. /**
  4041. * Sets the point to the passed values. Note that any sequence of parameters
  4042. * that is supported by the various {@link Point} constructors also work
  4043. * for calls of `set()`.
  4044. */
  4045. set(...values: any[]): Point
  4046. /**
  4047. * Checks whether the coordinates of the point are equal to that of the
  4048. * supplied point.
  4049. *
  4050. * @return true if the points are equal
  4051. */
  4052. equals(point: Point): boolean
  4053. /**
  4054. * Returns a copy of the point.
  4055. *
  4056. * @return the cloned point
  4057. */
  4058. clone(): Point
  4059. /**
  4060. * @return a string representation of the point
  4061. */
  4062. toString(): string
  4063. /**
  4064. * Returns the smaller angle between two vectors. The angle is unsigned, no
  4065. * information about rotational direction is given.
  4066. *
  4067. * @return the angle in degrees
  4068. */
  4069. getAngle(point: Point): number
  4070. /**
  4071. * Returns the smaller angle between two vectors in radians. The angle is
  4072. * unsigned, no information about rotational direction is given.
  4073. *
  4074. * @return the angle in radians
  4075. */
  4076. getAngleInRadians(point: Point): number
  4077. /**
  4078. * Returns the angle between two vectors. The angle is directional and
  4079. * signed, giving information about the rotational direction.
  4080. *
  4081. * Read more about angle units and orientation in the description of the
  4082. * {@link #angle} property.
  4083. *
  4084. * @return the angle between the two vectors
  4085. */
  4086. getDirectedAngle(point: Point): number
  4087. /**
  4088. * Returns the distance between the point and another point.
  4089. *
  4090. * @param squared - Controls whether the distance should
  4091. * remain squared, or its square root should be calculated
  4092. */
  4093. getDistance(point: Point, squared?: boolean): number
  4094. /**
  4095. * Normalize modifies the {@link #length} of the vector to `1` without
  4096. * changing its angle and returns it as a new point. The optional `length`
  4097. * parameter defines the length to normalize to. The object itself is not
  4098. * modified!
  4099. *
  4100. * @param length - The length of the normalized vector
  4101. *
  4102. * @return the normalized vector of the vector that is represented
  4103. * by this point's coordinates
  4104. */
  4105. normalize(length?: number): Point
  4106. /**
  4107. * Rotates the point by the given angle around an optional center point.
  4108. * The object itself is not modified.
  4109. *
  4110. * Read more about angle units and orientation in the description of the
  4111. * {@link #angle} property.
  4112. *
  4113. * @param angle - the rotation angle
  4114. * @param center - the center point of the rotation
  4115. *
  4116. * @return the rotated point
  4117. */
  4118. rotate(angle: number, center: Point): Point
  4119. /**
  4120. * Transforms the point by the matrix as a new point. The object itself is
  4121. * not modified!
  4122. *
  4123. * @return the transformed point
  4124. */
  4125. transform(matrix: Matrix): Point
  4126. /**
  4127. * Returns the addition of the supplied value to both coordinates of
  4128. * the point as a new point.
  4129. * The object itself is not modified!
  4130. *
  4131. * @param number - the number to add
  4132. *
  4133. * @return the addition of the point and the value as a new point
  4134. */
  4135. add(number: number): Point
  4136. /**
  4137. * Returns the addition of the supplied point to the point as a new
  4138. * point.
  4139. * The object itself is not modified!
  4140. *
  4141. * @param point - the point to add
  4142. *
  4143. * @return the addition of the two points as a new point
  4144. */
  4145. add(point: Point): Point
  4146. /**
  4147. * Returns the subtraction of the supplied value to both coordinates of
  4148. * the point as a new point.
  4149. * The object itself is not modified!
  4150. *
  4151. * @param number - the number to subtract
  4152. *
  4153. * @return the subtraction of the point and the value as a new point
  4154. */
  4155. subtract(number: number): Point
  4156. /**
  4157. * Returns the subtraction of the supplied point to the point as a new
  4158. * point.
  4159. * The object itself is not modified!
  4160. *
  4161. * @param point - the point to subtract
  4162. *
  4163. * @return the subtraction of the two points as a new point
  4164. */
  4165. subtract(point: Point): Point
  4166. /**
  4167. * Returns the multiplication of the supplied value to both coordinates of
  4168. * the point as a new point.
  4169. * The object itself is not modified!
  4170. *
  4171. * @param number - the number to multiply by
  4172. *
  4173. * @return the multiplication of the point and the value as a new
  4174. * point
  4175. */
  4176. multiply(number: number): Point
  4177. /**
  4178. * Returns the multiplication of the supplied point to the point as a new
  4179. * point.
  4180. * The object itself is not modified!
  4181. *
  4182. * @param point - the point to multiply by
  4183. *
  4184. * @return the multiplication of the two points as a new point
  4185. */
  4186. multiply(point: Point): Point
  4187. /**
  4188. * Returns the division of the supplied value to both coordinates of
  4189. * the point as a new point.
  4190. * The object itself is not modified!
  4191. *
  4192. * @param number - the number to divide by
  4193. *
  4194. * @return the division of the point and the value as a new point
  4195. */
  4196. divide(number: number): Point
  4197. /**
  4198. * Returns the division of the supplied point to the point as a new
  4199. * point.
  4200. * The object itself is not modified!
  4201. *
  4202. * @param point - the point to divide by
  4203. *
  4204. * @return the division of the two points as a new point
  4205. */
  4206. divide(point: Point): Point
  4207. /**
  4208. * The modulo operator returns the integer remainders of dividing the point
  4209. * by the supplied value as a new point.
  4210. *
  4211. * @return the integer remainders of dividing the point by the value
  4212. * as a new point
  4213. */
  4214. modulo(value: number): Point
  4215. /**
  4216. * The modulo operator returns the integer remainders of dividing the point
  4217. * by the supplied value as a new point.
  4218. *
  4219. * @return the integer remainders of dividing the points by each
  4220. * other as a new point
  4221. */
  4222. modulo(point: Point): Point
  4223. /**
  4224. * Checks whether the point is inside the boundaries of the rectangle.
  4225. *
  4226. * @param rect - the rectangle to check against
  4227. *
  4228. * @return true if the point is inside the rectangle
  4229. */
  4230. isInside(rect: Rectangle): boolean
  4231. /**
  4232. * Checks if the point is within a given distance of another point.
  4233. *
  4234. * @param point - the point to check against
  4235. * @param tolerance - the maximum distance allowed
  4236. *
  4237. * @return true if it is within the given distance
  4238. */
  4239. isClose(point: Point, tolerance: number): boolean
  4240. /**
  4241. * Checks if the vector represented by this point is collinear (parallel) to
  4242. * another vector.
  4243. *
  4244. * @param point - the vector to check against
  4245. *
  4246. * @return true it is collinear
  4247. */
  4248. isCollinear(point: Point): boolean
  4249. /**
  4250. * Checks if the vector represented by this point is orthogonal
  4251. * (perpendicular) to another vector.
  4252. *
  4253. * @param point - the vector to check against
  4254. *
  4255. * @return true it is orthogonal
  4256. */
  4257. isOrthogonal(point: Point): boolean
  4258. /**
  4259. * Checks if this point has both the x and y coordinate set to 0.
  4260. *
  4261. * @return true if both x and y are 0
  4262. */
  4263. isZero(): boolean
  4264. /**
  4265. * Checks if this point has an undefined value for at least one of its
  4266. * coordinates.
  4267. *
  4268. * @return true if either x or y are not a number
  4269. */
  4270. isNaN(): boolean
  4271. /**
  4272. * Checks if the vector is within the specified quadrant. Note that if the
  4273. * vector lies on the boundary between two quadrants, `true` will be
  4274. * returned for both quadrants.
  4275. *
  4276. * @see #quadrant
  4277. *
  4278. * @param quadrant - the quadrant to check against
  4279. *
  4280. * @return true if either x or y are not a number
  4281. */
  4282. isInQuadrant(quadrant: number): boolean
  4283. /**
  4284. * Returns the dot product of the point and another point.
  4285. *
  4286. * @return the dot product of the two points
  4287. */
  4288. dot(point: Point): number
  4289. /**
  4290. * Returns the cross product of the point and another point.
  4291. *
  4292. * @return the cross product of the two points
  4293. */
  4294. cross(point: Point): number
  4295. /**
  4296. * Returns the projection of the point onto another point.
  4297. * Both points are interpreted as vectors.
  4298. *
  4299. * @return the projection of the point onto another point
  4300. */
  4301. project(point: Point): Point
  4302. /**
  4303. * Returns a new point with rounded {@link #x} and {@link #y} values. The
  4304. * object itself is not modified!
  4305. */
  4306. round(): Point
  4307. /**
  4308. * Returns a new point with the nearest greater non-fractional values to the
  4309. * specified {@link #x} and {@link #y} values. The object itself is not
  4310. * modified!
  4311. */
  4312. ceil(): Point
  4313. /**
  4314. * Returns a new point with the nearest smaller non-fractional values to the
  4315. * specified {@link #x} and {@link #y} values. The object itself is not
  4316. * modified!
  4317. */
  4318. floor(): Point
  4319. /**
  4320. * Returns a new point with the absolute values of the specified {@link #x}
  4321. * and {@link #y} values. The object itself is not modified!
  4322. */
  4323. abs(): Point
  4324. /**
  4325. * Returns a new point object with the smallest {@link #x} and
  4326. * {@link #y} of the supplied points.
  4327. *
  4328. * @return the newly created point object
  4329. */
  4330. static min(point1: Point, point2: Point): Point
  4331. /**
  4332. * Returns a new point object with the largest {@link #x} and
  4333. * {@link #y} of the supplied points.
  4334. *
  4335. * @return the newly created point object
  4336. */
  4337. static max(point1: Point, point2: Point): Point
  4338. /**
  4339. * Returns a point object with random {@link #x} and {@link #y} values
  4340. * between `0` and `1`.
  4341. *
  4342. * @return the newly created point object
  4343. */
  4344. static random(): Point
  4345. }
  4346. /**
  4347. * A PointText item represents a piece of typography in your Paper.js
  4348. * project which starts from a certain point and extends by the amount of
  4349. * characters contained in it.
  4350. */
  4351. class PointText extends TextItem {
  4352. /**
  4353. * The PointText's anchor point
  4354. */
  4355. point: Point
  4356. /**
  4357. * Creates a point text item
  4358. *
  4359. * @param point - the position where the text will start
  4360. */
  4361. constructor(point: Point)
  4362. /**
  4363. * Creates a point text item from the properties described by an object
  4364. * literal.
  4365. *
  4366. * @param object - an object containing properties describing the
  4367. * path's attributes
  4368. */
  4369. constructor(object: object)
  4370. }
  4371. /**
  4372. * A Project object in Paper.js is what usually is referred to as the
  4373. * document: The top level object that holds all the items contained in the
  4374. * scene graph. As the term document is already taken in the browser context,
  4375. * it is called Project.
  4376. *
  4377. * Projects allow the manipulation of the styles that are applied to all newly
  4378. * created items, give access to the selected items, and will in future versions
  4379. * offer ways to query for items in the scene graph defining specific
  4380. * requirements, and means to persist and load from different formats, such as
  4381. * SVG and PDF.
  4382. *
  4383. * The currently active project can be accessed through the
  4384. * {@link PaperScope#project} variable.
  4385. *
  4386. * An array of all open projects is accessible through the
  4387. * {@link PaperScope#projects} variable.
  4388. */
  4389. class Project {
  4390. /**
  4391. * The reference to the project's view.
  4392. */
  4393. readonly view: View
  4394. /**
  4395. * The currently active path style. All selected items and newly
  4396. * created items will be styled with this style.
  4397. */
  4398. currentStyle: Style
  4399. /**
  4400. * The index of the project in the {@link PaperScope#projects} list.
  4401. */
  4402. readonly index: number
  4403. /**
  4404. * The layers contained within the project.
  4405. */
  4406. readonly layers: Layer[]
  4407. /**
  4408. * The layer which is currently active. New items will be created on this
  4409. * layer by default.
  4410. */
  4411. readonly activeLayer: Layer
  4412. /**
  4413. * The symbol definitions shared by all symbol items contained place ind
  4414. * project.
  4415. */
  4416. readonly symbolDefinitions: SymbolDefinition[]
  4417. /**
  4418. * The selected items contained within the project.
  4419. */
  4420. readonly selectedItems: Item[]
  4421. /**
  4422. * Creates a Paper.js project containing one empty {@link Layer}, referenced
  4423. * by {@link Project#activeLayer}.
  4424. *
  4425. * Note that when working with PaperScript, a project is automatically
  4426. * created for us and the {@link PaperScope#project} variable points to it.
  4427. *
  4428. * @param element - the HTML canvas element
  4429. * that should be used as the element for the view, or an ID string by which
  4430. * to find the element, or the size of the canvas to be created for usage in
  4431. * a web worker.
  4432. */
  4433. constructor(element: HTMLCanvasElement | string | Size)
  4434. /**
  4435. * Activates this project, so all newly created items will be placed
  4436. * in it.
  4437. */
  4438. activate(): void
  4439. /**
  4440. * Clears the project by removing all {@link Project#layers}.
  4441. */
  4442. clear(): void
  4443. /**
  4444. * Checks whether the project has any content or not.
  4445. */
  4446. isEmpty(): boolean
  4447. /**
  4448. * Removes this project from the {@link PaperScope#projects} list, and also
  4449. * removes its view, if one was defined.
  4450. */
  4451. remove(): void
  4452. /**
  4453. * Selects all items in the project.
  4454. */
  4455. selectAll(): void
  4456. /**
  4457. * Deselects all selected items in the project.
  4458. */
  4459. deselectAll(): void
  4460. /**
  4461. * Adds the specified layer at the end of the this project's {@link #layers}
  4462. * list.
  4463. *
  4464. * @param layer - the layer to be added to the project
  4465. *
  4466. * @return the added layer, or `null` if adding was not possible
  4467. */
  4468. addLayer(layer: Layer): Layer
  4469. /**
  4470. * Inserts the specified layer at the specified index in this project's
  4471. * {@link #layers} list.
  4472. *
  4473. * @param index - the index at which to insert the layer
  4474. * @param layer - the layer to be inserted in the project
  4475. *
  4476. * @return the added layer, or `null` if adding was not possible
  4477. */
  4478. insertLayer(index: number, layer: Layer): Layer
  4479. /**
  4480. * Performs a hit-test on the items contained within the project at the
  4481. * location of the specified point.
  4482. *
  4483. * The options object allows you to control the specifics of the hit-test
  4484. * and may contain a combination of the following values:
  4485. *
  4486. * @option [options.tolerance={@link PaperScope#settings}.hitTolerance]
  4487. * {Number} the tolerance of the hit-test
  4488. * @option options.class {Function} only hit-test against a specific item
  4489. * class, or any of its sub-classes, by providing the constructor
  4490. * function against which an `instanceof` check is performed:
  4491. * {@values Group, Layer, Path, CompoundPath, Shape, Raster,
  4492. * SymbolItem, PointText, ...}
  4493. * @option options.match {Function} a match function to be called for each
  4494. * found hit result: Return `true` to return the result, `false` to keep
  4495. * searching
  4496. * @option [options.fill=true] {Boolean} hit-test the fill of items
  4497. * @option [options.stroke=true] {Boolean} hit-test the stroke of path
  4498. * items, taking into account the setting of stroke color and width
  4499. * @option [options.segments=true] {Boolean} hit-test for {@link
  4500. * Segment#point} of {@link Path} items
  4501. * @option options.curves {Boolean} hit-test the curves of path items,
  4502. * without taking the stroke color or width into account
  4503. * @option options.handles {Boolean} hit-test for the handles ({@link
  4504. * Segment#handleIn} / {@link Segment#handleOut}) of path segments.
  4505. * @option options.ends {Boolean} only hit-test for the first or last
  4506. * segment points of open path items
  4507. * @option options.position {Boolean} hit-test the {@link Item#position} of
  4508. * of items, which depends on the setting of {@link Item#pivot}
  4509. * @option options.center {Boolean} hit-test the {@link Rectangle#center} of
  4510. * the bounding rectangle of items ({@link Item#bounds})
  4511. * @option options.bounds {Boolean} hit-test the corners and side-centers of
  4512. * the bounding rectangle of items ({@link Item#bounds})
  4513. * @option options.guides {Boolean} hit-test items that have {@link
  4514. * Item#guide} set to `true`
  4515. * @option options.selected {Boolean} only hit selected items
  4516. *
  4517. * @param point - the point where the hit-test should be performed
  4518. *
  4519. * @return a hit result object that contains more information
  4520. * about what exactly was hit or `null` if nothing was hit
  4521. */
  4522. hitTest(point: Point, options?: object): HitResult
  4523. /**
  4524. * Performs a hit-test on the item and its children (if it is a {@link
  4525. * Group} or {@link Layer}) at the location of the specified point,
  4526. * returning all found hits.
  4527. *
  4528. * The options object allows you to control the specifics of the hit-
  4529. * test. See {@link #hitTest} for a list of all options.
  4530. *
  4531. * @see #hitTest(point[, options]);
  4532. *
  4533. * @param point - the point where the hit-test should be performed
  4534. *
  4535. * @return hit result objects for all hits, describing what
  4536. * exactly was hit or `null` if nothing was hit
  4537. */
  4538. hitTestAll(point: Point, options?: object): HitResult[]
  4539. /**
  4540. * Fetch items contained within the project whose properties match the
  4541. * criteria in the specified object.
  4542. *
  4543. * Extended matching of properties is possible by providing a comparator
  4544. * function or regular expression. Matching points, colors only work as a
  4545. * comparison of the full object, not partial matching (e.g. only providing
  4546. * the x- coordinate to match all points with that x-value). Partial
  4547. * matching does work for {@link Item#data}.
  4548. *
  4549. * Matching items against a rectangular area is also possible, by setting
  4550. * either `options.inside` or `options.overlapping` to a rectangle
  4551. * describing the area in which the items either have to be fully or partly
  4552. * contained.
  4553. *
  4554. * @see Item#matches(options)
  4555. * @see Item#getItems(options)
  4556. *
  4557. * @option [options.recursive=true] {Boolean} whether to loop recursively
  4558. * through all children, or stop at the current level
  4559. * @option options.match {Function} a match function to be called for each
  4560. * item, allowing the definition of more flexible item checks that are
  4561. * not bound to properties. If no other match properties are defined,
  4562. * this function can also be passed instead of the `match` object
  4563. * @option options.class {Function} the constructor function of the item
  4564. * type to match against
  4565. * @option options.inside {Rectangle} the rectangle in which the items need
  4566. * to be fully contained
  4567. * @option options.overlapping {Rectangle} the rectangle with which the
  4568. * items need to at least partly overlap
  4569. *
  4570. * @param options - the criteria to match against
  4571. *
  4572. * @return the list of matching items contained in the project
  4573. */
  4574. getItems(options: object | Function): Item[]
  4575. /**
  4576. * Fetch the first item contained within the project whose properties
  4577. * match the criteria in the specified object.
  4578. * Extended matching is possible by providing a compare function or
  4579. * regular expression. Matching points, colors only work as a comparison
  4580. * of the full object, not partial matching (e.g. only providing the x-
  4581. * coordinate to match all points with that x-value). Partial matching
  4582. * does work for {@link Item#data}.
  4583. *
  4584. * See {@link #getItems} for a selection of illustrated examples.
  4585. *
  4586. * @param options - the criteria to match against
  4587. *
  4588. * @return the first item in the project matching the given criteria
  4589. */
  4590. getItem(options: object | Function): Item
  4591. /**
  4592. * Exports (serializes) the project with all its layers and child items to a
  4593. * JSON data object or string.
  4594. *
  4595. * @option [options.asString=true] {Boolean} whether the JSON is returned as
  4596. * a `Object` or a `String`
  4597. * @option [options.precision=5] {Number} the amount of fractional digits in
  4598. * numbers used in JSON data
  4599. *
  4600. * @param options - the serialization options
  4601. *
  4602. * @return the exported JSON data
  4603. */
  4604. exportJSON(options?: object): string
  4605. /**
  4606. * Imports (deserializes) the stored JSON data into the project.
  4607. * Note that the project is not cleared first. You can call
  4608. * {@link Project#clear} to do so.
  4609. *
  4610. * @param json - the JSON data to import from
  4611. *
  4612. * @return the imported item
  4613. */
  4614. importJSON(json: string): Item
  4615. /**
  4616. * Exports the project with all its layers and child items as an SVG DOM,
  4617. * all contained in one top level SVG group node.
  4618. *
  4619. * @option [options.bounds='view'] {String|Rectangle} the bounds of the area
  4620. * to export, either as a string ({@values 'view', content'}), or a
  4621. * {@link Rectangle} object: `'view'` uses the view bounds,
  4622. * `'content'` uses the stroke bounds of all content
  4623. * @option [options.matrix=paper.view.matrix] {Matrix} the matrix with which
  4624. * to transform the exported content: If `options.bounds` is set to
  4625. * `'view'`, `paper.view.matrix` is used, for all other settings of
  4626. * `options.bounds` the identity matrix is used.
  4627. * @option [options.asString=false] {Boolean} whether a SVG node or a
  4628. * `String` is to be returned
  4629. * @option [options.precision=5] {Number} the amount of fractional digits in
  4630. * numbers used in SVG data
  4631. * @option [options.matchShapes=false] {Boolean} whether path items should
  4632. * tried to be converted to SVG shape items (rect, circle, ellipse,
  4633. * line, polyline, polygon), if their geometries match
  4634. * @option [options.embedImages=true] {Boolean} whether raster images should
  4635. * be embedded as base64 data inlined in the xlink:href attribute, or
  4636. * kept as a link to their external URL.
  4637. *
  4638. * @param options - the export options
  4639. *
  4640. * @return the project converted to an SVG node or a
  4641. * `String` depending on `option.asString` value
  4642. */
  4643. exportSVG(options?: object): SVGElement | string
  4644. /**
  4645. * Converts the provided SVG content into Paper.js items and adds them to
  4646. * the active layer of this project.
  4647. * Note that the project is not cleared first. You can call
  4648. * {@link Project#clear} to do so.
  4649. *
  4650. * @option [options.expandShapes=false] {Boolean} whether imported shape
  4651. * items should be expanded to path items
  4652. * @option options.onLoad {Function} the callback function to call once the
  4653. * SVG content is loaded from the given URL receiving two arguments: the
  4654. * converted `item` and the original `svg` data as a string. Only
  4655. * required when loading from external resources.
  4656. * @option options.onError {Function} the callback function to call if an
  4657. * error occurs during loading. Only required when loading from external
  4658. * resources.
  4659. * @option [options.insert=true] {Boolean} whether the imported items should
  4660. * be added to the project that `importSVG()` is called on
  4661. * @option [options.applyMatrix={@link PaperScope#settings}.applyMatrix]
  4662. * {Boolean} whether the imported items should have their transformation
  4663. * matrices applied to their contents or not
  4664. *
  4665. * @param svg - the SVG content to import, either as a SVG
  4666. * DOM node, a string containing SVG content, or a string describing the
  4667. * URL of the SVG file to fetch.
  4668. * @param options - the import options
  4669. *
  4670. * @return the newly created Paper.js item containing the converted
  4671. * SVG content
  4672. */
  4673. importSVG(svg: SVGElement | string, options?: object): Item
  4674. /**
  4675. * Imports the provided external SVG file, converts it into Paper.js items
  4676. * and adds them to the active layer of this project.
  4677. * Note that the project is not cleared first. You can call
  4678. * {@link Project#clear} to do so.
  4679. *
  4680. * @param svg - the URL of the SVG file to fetch.
  4681. * @param onLoad - the callback function to call once the SVG
  4682. * content is loaded from the given URL receiving two arguments: the
  4683. * converted `item` and the original `svg` data as a string. Only
  4684. * required when loading from external files.
  4685. *
  4686. * @return the newly created Paper.js item containing the converted
  4687. * SVG content
  4688. */
  4689. importSVG(svg: SVGElement | string, onLoad: Function): Item
  4690. }
  4691. /**
  4692. * The Raster item represents an image in a Paper.js project.
  4693. */
  4694. class Raster extends Item {
  4695. /**
  4696. * The size of the raster in pixels.
  4697. */
  4698. size: Size
  4699. /**
  4700. * The width of the raster in pixels.
  4701. */
  4702. width: number
  4703. /**
  4704. * The height of the raster in pixels.
  4705. */
  4706. height: number
  4707. /**
  4708. * The loading state of the raster image.
  4709. */
  4710. readonly loaded: boolean
  4711. /**
  4712. * The resolution of the raster at its current size, in PPI (pixels per
  4713. * inch).
  4714. */
  4715. readonly resolution: Size
  4716. /**
  4717. * The HTMLImageElement or Canvas element of the raster, if one is
  4718. * associated.
  4719. * Note that for consistency, a {@link #onLoad} event will be triggered on
  4720. * the raster even if the image has already finished loading before, or if
  4721. * we are setting the raster to a canvas.
  4722. */
  4723. image: HTMLImageElement | HTMLCanvasElement
  4724. /**
  4725. * The Canvas object of the raster. If the raster was created from an image,
  4726. * accessing its canvas causes the raster to try and create one and draw the
  4727. * image into it. Depending on security policies, this might fail, in which
  4728. * case `null` is returned instead.
  4729. */
  4730. canvas: HTMLCanvasElement
  4731. /**
  4732. * The Canvas 2D drawing context of the raster.
  4733. */
  4734. context: CanvasRenderingContext2D
  4735. /**
  4736. * The source of the raster, which can be set using a DOM Image, a Canvas,
  4737. * a data url, a string describing the URL to load the image from, or the
  4738. * ID of a DOM element to get the image from (either a DOM Image or a
  4739. * Canvas). Reading this property will return the url of the source image or
  4740. * a data-url.
  4741. * Note that for consistency, a {@link #onLoad} event will be triggered on
  4742. * the raster even if the image has already finished loading before.
  4743. */
  4744. source: HTMLImageElement | HTMLCanvasElement | string
  4745. /**
  4746. * The crossOrigin value to be used when loading the image resource, in
  4747. * order to support CORS. Note that this needs to be set before setting the
  4748. * {@link #source} property in order to always work (e.g. when the image is
  4749. * cached in the browser).
  4750. */
  4751. crossOrigin: string
  4752. /**
  4753. * Determines if the raster is drawn with pixel smoothing when scaled up or
  4754. * down, and if so, at which quality its pixels are to be smoothed. The
  4755. * settings of this property control both the `imageSmoothingEnabled` and
  4756. * `imageSmoothingQuality` properties of the `CanvasRenderingContext2D`
  4757. * interface.
  4758. *
  4759. * By default, smoothing is enabled at `'low'` quality. It can be set to of
  4760. * `'off'` to scale the raster's pixels by repeating the nearest neighboring
  4761. * pixels, or to `'low'`, `'medium'` or `'high'` to control the various
  4762. * degrees of available image smoothing quality.
  4763. *
  4764. * For backward compatibility, it can can also be set to `false` (= `'off'`)
  4765. * or `true` (= `'low'`).
  4766. */
  4767. smoothing: string
  4768. /**
  4769. * The event handler function to be called when the underlying image has
  4770. * finished loading and is ready to be used. This is also triggered when
  4771. * the image is already loaded, or when a canvas is used instead of an
  4772. * image.
  4773. */
  4774. onLoad: Function | null
  4775. /**
  4776. * The event handler function to be called when there is an error loading
  4777. * the underlying image.
  4778. */
  4779. onError: Function | null
  4780. /**
  4781. * Creates a new raster item from the passed argument, and places it in the
  4782. * active layer. `source` can either be a DOM Image, a Canvas, or a string
  4783. * describing the URL to load the image from, or the ID of a DOM element to
  4784. * get the image from (either a DOM Image or a Canvas).
  4785. *
  4786. * @param source - the source of
  4787. * the raster
  4788. * @param position - the center position at which the raster item is
  4789. * placed
  4790. */
  4791. constructor(source?: HTMLImageElement | HTMLCanvasElement | string, position?: Point)
  4792. /**
  4793. * Creates a new empty raster of the given size, and places it in the
  4794. * active layer.
  4795. *
  4796. * @param size - the size of the raster
  4797. * @param position - the center position at which the raster item is
  4798. * placed
  4799. */
  4800. constructor(size: Size, position?: Point)
  4801. /**
  4802. * Creates a new raster from an object description, and places it in the
  4803. * active layer.
  4804. *
  4805. * @param object - an object containing properties to be set on the
  4806. * raster
  4807. */
  4808. constructor(object: object)
  4809. /**
  4810. * Extracts a part of the Raster's content as a sub image, and returns it as
  4811. * a Canvas object.
  4812. *
  4813. * @param rect - the boundaries of the sub image in pixel
  4814. * coordinates
  4815. *
  4816. * @return the sub image as a Canvas object
  4817. */
  4818. getSubCanvas(rect: Rectangle): HTMLCanvasElement
  4819. /**
  4820. * Extracts a part of the raster item's content as a new raster item, placed
  4821. * in exactly the same place as the original content.
  4822. *
  4823. * @param rect - the boundaries of the sub raster in pixel
  4824. * coordinates
  4825. *
  4826. * @return the sub raster as a newly created raster item
  4827. */
  4828. getSubRaster(rect: Rectangle): Raster
  4829. /**
  4830. * Returns a Base 64 encoded `data:` URL representation of the raster.
  4831. */
  4832. toDataURL(): string
  4833. /**
  4834. * Draws an image on the raster.
  4835. *
  4836. * @param point - the offset of the image as a point in pixel
  4837. * coordinates
  4838. */
  4839. drawImage(image: CanvasImageSource, point: Point): void
  4840. /**
  4841. * Calculates the average color of the image within the given path,
  4842. * rectangle or point. This can be used for creating raster image
  4843. * effects.
  4844. *
  4845. * @return the average color contained in the area covered by the
  4846. * specified path, rectangle or point
  4847. */
  4848. getAverageColor(object: Path | Rectangle | Point): Color
  4849. /**
  4850. * Gets the color of a pixel in the raster.
  4851. *
  4852. * @param x - the x offset of the pixel in pixel coordinates
  4853. * @param y - the y offset of the pixel in pixel coordinates
  4854. *
  4855. * @return the color of the pixel
  4856. */
  4857. getPixel(x: number, y: number): Color
  4858. /**
  4859. * Gets the color of a pixel in the raster.
  4860. *
  4861. * @param point - the offset of the pixel as a point in pixel
  4862. * coordinates
  4863. *
  4864. * @return the color of the pixel
  4865. */
  4866. getPixel(point: Point): Color
  4867. /**
  4868. * Sets the color of the specified pixel to the specified color.
  4869. *
  4870. * @param x - the x offset of the pixel in pixel coordinates
  4871. * @param y - the y offset of the pixel in pixel coordinates
  4872. * @param color - the color that the pixel will be set to
  4873. */
  4874. setPixel(x: number, y: number, color: Color): void
  4875. /**
  4876. * Sets the color of the specified pixel to the specified color.
  4877. *
  4878. * @param point - the offset of the pixel as a point in pixel
  4879. * coordinates
  4880. * @param color - the color that the pixel will be set to
  4881. */
  4882. setPixel(point: Point, color: Color): void
  4883. /**
  4884. * Clears the image, if it is backed by a canvas.
  4885. */
  4886. clear(): void
  4887. createImageData(size: Size): ImageData
  4888. getImageData(rect: Rectangle): ImageData
  4889. setImageData(data: ImageData, point: Point): void
  4890. }
  4891. /**
  4892. * A Rectangle specifies an area that is enclosed by it's top-left
  4893. * point (x, y), its width, and its height. It should not be confused with a
  4894. * rectangular path, it is not an item.
  4895. */
  4896. class Rectangle {
  4897. /**
  4898. * The x position of the rectangle.
  4899. */
  4900. x: number
  4901. /**
  4902. * The y position of the rectangle.
  4903. */
  4904. y: number
  4905. /**
  4906. * The width of the rectangle.
  4907. */
  4908. width: number
  4909. /**
  4910. * The height of the rectangle.
  4911. */
  4912. height: number
  4913. /**
  4914. * The top-left point of the rectangle
  4915. */
  4916. point: Point
  4917. /**
  4918. * The size of the rectangle
  4919. */
  4920. size: Size
  4921. /**
  4922. * The position of the left hand side of the rectangle. Note that this
  4923. * doesn't move the whole rectangle; the right hand side stays where it was.
  4924. */
  4925. left: number
  4926. /**
  4927. * The top coordinate of the rectangle. Note that this doesn't move the
  4928. * whole rectangle: the bottom won't move.
  4929. */
  4930. top: number
  4931. /**
  4932. * The position of the right hand side of the rectangle. Note that this
  4933. * doesn't move the whole rectangle; the left hand side stays where it was.
  4934. */
  4935. right: number
  4936. /**
  4937. * The bottom coordinate of the rectangle. Note that this doesn't move the
  4938. * whole rectangle: the top won't move.
  4939. */
  4940. bottom: number
  4941. /**
  4942. * The center point of the rectangle.
  4943. */
  4944. center: Point
  4945. /**
  4946. * The top-left point of the rectangle.
  4947. */
  4948. topLeft: Point
  4949. /**
  4950. * The top-right point of the rectangle.
  4951. */
  4952. topRight: Point
  4953. /**
  4954. * The bottom-left point of the rectangle.
  4955. */
  4956. bottomLeft: Point
  4957. /**
  4958. * The bottom-right point of the rectangle.
  4959. */
  4960. bottomRight: Point
  4961. /**
  4962. * The left-center point of the rectangle.
  4963. */
  4964. leftCenter: Point
  4965. /**
  4966. * The top-center point of the rectangle.
  4967. */
  4968. topCenter: Point
  4969. /**
  4970. * The right-center point of the rectangle.
  4971. */
  4972. rightCenter: Point
  4973. /**
  4974. * The bottom-center point of the rectangle.
  4975. */
  4976. bottomCenter: Point
  4977. /**
  4978. * The area of the rectangle.
  4979. */
  4980. readonly area: number
  4981. /**
  4982. * Specifies whether an item's bounds are to appear as selected.
  4983. *
  4984. * Paper.js draws the bounds of items with selected bounds on top of
  4985. * your project. This is very useful when debugging.
  4986. */
  4987. selected: boolean
  4988. /**
  4989. * Creates a Rectangle object.
  4990. *
  4991. * @param point - the top-left point of the rectangle
  4992. * @param size - the size of the rectangle
  4993. */
  4994. constructor(point: Point, size: Size)
  4995. /**
  4996. * Creates a rectangle object.
  4997. *
  4998. * @param x - the left coordinate
  4999. * @param y - the top coordinate
  5000. */
  5001. constructor(x: number, y: number, width: number, height: number)
  5002. /**
  5003. * Creates a rectangle object from the passed points. These do not
  5004. * necessarily need to be the top left and bottom right corners, the
  5005. * constructor figures out how to fit a rectangle between them.
  5006. *
  5007. * @param from - the first point defining the rectangle
  5008. * @param to - the second point defining the rectangle
  5009. */
  5010. constructor(from: Point, to: Point)
  5011. /**
  5012. * Creates a new rectangle object from the passed rectangle object.
  5013. */
  5014. constructor(rectangle: Rectangle)
  5015. /**
  5016. * Creates a Rectangle object.
  5017. *
  5018. * @param object - an object containing properties to be set on the
  5019. * rectangle
  5020. */
  5021. constructor(object: object)
  5022. /**
  5023. * Sets the rectangle to the passed values. Note that any sequence of
  5024. * parameters that is supported by the various {@link Rectangle}
  5025. * constructors also work for calls of `set()`.
  5026. */
  5027. set(...values: any[]): Rectangle
  5028. /**
  5029. * Returns a copy of the rectangle.
  5030. */
  5031. clone(): Rectangle
  5032. /**
  5033. * Checks whether the coordinates and size of the rectangle are equal to
  5034. * that of the supplied rectangle.
  5035. *
  5036. * @return true if the rectangles are equal
  5037. */
  5038. equals(rect: Rectangle): boolean
  5039. /**
  5040. * @return a string representation of this rectangle
  5041. */
  5042. toString(): string
  5043. /**
  5044. * @return true if the rectangle is empty
  5045. */
  5046. isEmpty(): boolean
  5047. /**
  5048. * Tests if the specified point is inside the boundary of the rectangle.
  5049. *
  5050. * @param point - the specified point
  5051. *
  5052. * @return true if the point is inside the rectangle's boundary
  5053. */
  5054. contains(point: Point): boolean
  5055. /**
  5056. * Tests if the interior of the rectangle entirely contains the specified
  5057. * rectangle.
  5058. *
  5059. * @param rect - the specified rectangle
  5060. *
  5061. * @return true if the rectangle entirely contains the specified
  5062. * rectangle
  5063. */
  5064. contains(rect: Rectangle): boolean
  5065. /**
  5066. * Tests if the interior of this rectangle intersects the interior of
  5067. * another rectangle. Rectangles just touching each other are considered as
  5068. * non-intersecting, except if a `epsilon` value is specified by which this
  5069. * rectangle's dimensions are increased before comparing.
  5070. *
  5071. * @param rect - the specified rectangle
  5072. * @param epsilon - the epsilon against which to compare the
  5073. * rectangle's dimensions
  5074. *
  5075. * @return true if the rectangle and the specified rectangle
  5076. * intersect each other
  5077. */
  5078. intersects(rect: Rectangle, epsilon?: number): boolean
  5079. /**
  5080. * Returns a new rectangle representing the intersection of this rectangle
  5081. * with the specified rectangle.
  5082. *
  5083. * @param rect - the rectangle to be intersected with this
  5084. * rectangle
  5085. *
  5086. * @return the largest rectangle contained in both the specified
  5087. * rectangle and in this rectangle
  5088. */
  5089. intersect(rect: Rectangle): Rectangle
  5090. /**
  5091. * Returns a new rectangle representing the union of this rectangle with the
  5092. * specified rectangle.
  5093. *
  5094. * @param rect - the rectangle to be combined with this rectangle
  5095. *
  5096. * @return the smallest rectangle containing both the specified
  5097. * rectangle and this rectangle
  5098. */
  5099. unite(rect: Rectangle): Rectangle
  5100. /**
  5101. * Adds a point to this rectangle. The resulting rectangle is the smallest
  5102. * rectangle that contains both the original rectangle and the specified
  5103. * point.
  5104. *
  5105. * After adding a point, a call to {@link #contains} with the added
  5106. * point as an argument does not necessarily return `true`. The {@link
  5107. * Rectangle#contains(point)} method does not return `true` for points on
  5108. * the right or bottom edges of a rectangle. Therefore, if the added point
  5109. * falls on the left or bottom edge of the enlarged rectangle, {@link
  5110. * Rectangle#contains(point)} returns `false` for that point.
  5111. *
  5112. * @return the smallest rectangle that contains both the
  5113. * original rectangle and the specified point
  5114. */
  5115. include(point: Point): Rectangle
  5116. /**
  5117. * Returns a new rectangle expanded by the specified amount in horizontal
  5118. * and vertical directions.
  5119. *
  5120. * @param amount - the amount to expand the rectangle in
  5121. * both directions
  5122. *
  5123. * @return the expanded rectangle
  5124. */
  5125. expand(amount: number | Size | Point): Rectangle
  5126. /**
  5127. * Returns a new rectangle expanded by the specified amounts in horizontal
  5128. * and vertical directions.
  5129. *
  5130. * @param hor - the amount to expand the rectangle in horizontal
  5131. * direction
  5132. * @param ver - the amount to expand the rectangle in vertical
  5133. * direction
  5134. *
  5135. * @return the expanded rectangle
  5136. */
  5137. expand(hor: number, ver: number): Rectangle
  5138. /**
  5139. * Returns a new rectangle scaled by the specified amount from its center.
  5140. *
  5141. * @return the scaled rectangle
  5142. */
  5143. scale(amount: number): Rectangle
  5144. /**
  5145. * Returns a new rectangle scaled in horizontal direction by the specified
  5146. * `hor` amount and in vertical direction by the specified `ver` amount
  5147. * from its center.
  5148. *
  5149. * @return the scaled rectangle
  5150. */
  5151. scale(hor: number, ver: number): Rectangle
  5152. }
  5153. /**
  5154. * The Segment object represents the points of a path through which its
  5155. * {@link Curve} objects pass. The segments of a path can be accessed through
  5156. * its {@link Path#segments} array.
  5157. *
  5158. * Each segment consists of an anchor point ({@link Segment#point}) and
  5159. * optionaly an incoming and an outgoing handle ({@link Segment#handleIn} and
  5160. * {@link Segment#handleOut}), describing the tangents of the two {@link Curve}
  5161. * objects that are connected by this segment.
  5162. */
  5163. class Segment {
  5164. /**
  5165. * The anchor point of the segment.
  5166. */
  5167. point: Point
  5168. /**
  5169. * The handle point relative to the anchor point of the segment that
  5170. * describes the in tangent of the segment.
  5171. */
  5172. handleIn: Point
  5173. /**
  5174. * The handle point relative to the anchor point of the segment that
  5175. * describes the out tangent of the segment.
  5176. */
  5177. handleOut: Point
  5178. /**
  5179. * Specifies whether the segment is selected.
  5180. */
  5181. selected: boolean
  5182. /**
  5183. * The index of the segment in the {@link Path#segments} array that the
  5184. * segment belongs to.
  5185. */
  5186. readonly index: number
  5187. /**
  5188. * The path that the segment belongs to.
  5189. */
  5190. readonly path: Path
  5191. /**
  5192. * The curve that the segment belongs to. For the last segment of an open
  5193. * path, the previous segment is returned.
  5194. */
  5195. readonly curve: Curve
  5196. /**
  5197. * The curve location that describes this segment's position on the path.
  5198. */
  5199. readonly location: CurveLocation
  5200. /**
  5201. * The next segment in the {@link Path#segments} array that the segment
  5202. * belongs to. If the segments belongs to a closed path, the first segment
  5203. * is returned for the last segment of the path.
  5204. */
  5205. readonly next: Segment
  5206. /**
  5207. * The previous segment in the {@link Path#segments} array that the
  5208. * segment belongs to. If the segments belongs to a closed path, the last
  5209. * segment is returned for the first segment of the path.
  5210. */
  5211. readonly previous: Segment
  5212. /**
  5213. * Creates a new Segment object.
  5214. *
  5215. * @param point - the anchor point of the segment
  5216. * @param handleIn - the handle point relative to the
  5217. * anchor point of the segment that describes the in tangent of the
  5218. * segment
  5219. * @param handleOut - the handle point relative to the
  5220. * anchor point of the segment that describes the out tangent of the
  5221. * segment
  5222. */
  5223. constructor(point?: Point, handleIn?: Point, handleOut?: Point)
  5224. /**
  5225. * Creates a new Segment object.
  5226. *
  5227. * @param object - an object containing properties to be set on the
  5228. * segment
  5229. */
  5230. constructor(object: object)
  5231. /**
  5232. * Checks if the segment has any curve handles set.
  5233. *
  5234. * @see Segment#handleIn
  5235. * @see Segment#handleOut
  5236. * @see Curve#hasHandles()
  5237. * @see Path#hasHandles()
  5238. *
  5239. * @return true if the segment has handles set
  5240. */
  5241. hasHandles(): boolean
  5242. /**
  5243. * Checks if the segment connects two curves smoothly, meaning that its two
  5244. * handles are collinear and segment does not form a corner.
  5245. *
  5246. * @see Point#isCollinear()
  5247. *
  5248. * @return true if the segment is smooth
  5249. */
  5250. isSmooth(): boolean
  5251. /**
  5252. * Clears the segment's handles by setting their coordinates to zero,
  5253. * turning the segment into a corner.
  5254. */
  5255. clearHandles(): void
  5256. /**
  5257. * Smooths the bezier curves that pass through this segment by taking into
  5258. * account the segment's position and distance to the neighboring segments
  5259. * and changing the direction and length of the segment's handles
  5260. * accordingly without moving the segment itself.
  5261. *
  5262. * Two different smoothing methods are available:
  5263. *
  5264. * - `'catmull-rom'` uses the Catmull-Rom spline to smooth the segment.
  5265. *
  5266. * The optionally passed factor controls the knot parametrization of the
  5267. * algorithm:
  5268. *
  5269. * - `0.0`: the standard, uniform Catmull-Rom spline
  5270. * - `0.5`: the centripetal Catmull-Rom spline, guaranteeing no
  5271. * self-intersections
  5272. * - `1.0`: the chordal Catmull-Rom spline
  5273. *
  5274. * - `'geometric'` use a simple heuristic and empiric geometric method to
  5275. * smooth the segment's handles. The handles were weighted, meaning that
  5276. * big differences in distances between the segments will lead to
  5277. * probably undesired results.
  5278. *
  5279. * The optionally passed factor defines the tension parameter (`0...1`),
  5280. * controlling the amount of smoothing as a factor by which to scale
  5281. * each handle.
  5282. *
  5283. * @see PathItem#smooth([options])
  5284. *
  5285. * @option [options.type='catmull-rom'] {String} the type of smoothing
  5286. * method: {@values 'catmull-rom', 'geometric'}
  5287. * @option options.factor {Number} the factor parameterizing the smoothing
  5288. * method — default: `0.5` for `'catmull-rom'`, `0.4` for `'geometric'`
  5289. *
  5290. * @param options - the smoothing options
  5291. */
  5292. smooth(options?: object): void
  5293. /**
  5294. * Checks if the this is the first segment in the {@link Path#segments}
  5295. * array.
  5296. *
  5297. * @return true if this is the first segment
  5298. */
  5299. isFirst(): boolean
  5300. /**
  5301. * Checks if the this is the last segment in the {@link Path#segments}
  5302. * array.
  5303. *
  5304. * @return true if this is the last segment
  5305. */
  5306. isLast(): boolean
  5307. /**
  5308. * Reverses the {@link #handleIn} and {@link #handleOut} vectors of this
  5309. * segment, modifying the actual segment without creating a copy.
  5310. *
  5311. * @return the reversed segment
  5312. */
  5313. reverse(): Segment
  5314. /**
  5315. * Returns the reversed the segment, without modifying the segment itself.
  5316. *
  5317. * @return the reversed segment
  5318. */
  5319. reversed(): Segment
  5320. /**
  5321. * Removes the segment from the path that it belongs to.
  5322. *
  5323. * @return true if the segment was removed
  5324. */
  5325. remove(): boolean
  5326. clone(): Segment
  5327. /**
  5328. * @return a string representation of the segment
  5329. */
  5330. toString(): string
  5331. /**
  5332. * Transform the segment by the specified matrix.
  5333. *
  5334. * @param matrix - the matrix to transform the segment by
  5335. */
  5336. transform(matrix: Matrix): void
  5337. /**
  5338. * Interpolates between the two specified segments and sets the point and
  5339. * handles of this segment accordingly.
  5340. *
  5341. * @param from - the segment defining the geometry when `factor` is
  5342. * `0`
  5343. * @param to - the segment defining the geometry when `factor` is
  5344. * `1`
  5345. * @param factor - the interpolation coefficient, typically between
  5346. * `0` and `1`, but extrapolation is possible too
  5347. */
  5348. interpolate(from: Segment, to: Segment, factor: number): void
  5349. }
  5350. class Shape extends Item {
  5351. /**
  5352. * The type of shape of the item as a string.
  5353. */
  5354. type: string
  5355. /**
  5356. * The size of the shape.
  5357. */
  5358. size: Size
  5359. /**
  5360. * The radius of the shape, as a number if it is a circle, or a size object
  5361. * for ellipses and rounded rectangles.
  5362. */
  5363. radius: number | Size
  5364. /**
  5365. * Creates a new path item with same geometry as this shape item, and
  5366. * inherits all settings from it, similar to {@link Item#clone}.
  5367. *
  5368. * @see Path#toShape(insert)
  5369. *
  5370. * @param insert - specifies whether the new path should be
  5371. * inserted into the scene graph. When set to `true`, it is inserted
  5372. * above the shape item
  5373. *
  5374. * @return the newly created path item with the same geometry as
  5375. * this shape item
  5376. */
  5377. toPath(insert?: boolean): Path
  5378. }
  5379. namespace Shape {
  5380. class Circle extends Shape {
  5381. /**
  5382. * Creates a circular shape item.
  5383. *
  5384. * @param center - the center point of the circle
  5385. * @param radius - the radius of the circle
  5386. */
  5387. constructor(center: Point, radius: number)
  5388. /**
  5389. * Creates a circular shape item from the properties described by an
  5390. * object literal.
  5391. *
  5392. * @param object - an object containing properties describing the
  5393. * shape's attributes
  5394. */
  5395. constructor(object: object)
  5396. }
  5397. class Rectangle extends Shape {
  5398. /**
  5399. * Creates a rectangular shape item, with optionally rounded corners.
  5400. *
  5401. * @param rectangle - the rectangle object describing the
  5402. * geometry of the rectangular shape to be created
  5403. * @param radius - the size of the rounded corners
  5404. */
  5405. constructor(rectangle: paper.Rectangle, radius?: Size)
  5406. /**
  5407. * Creates a rectangular shape item from a point and a size object.
  5408. *
  5409. * @param point - the rectangle's top-left corner.
  5410. * @param size - the rectangle's size.
  5411. */
  5412. constructor(point: Point, size: Size)
  5413. /**
  5414. * Creates a rectangular shape item from the passed points. These do not
  5415. * necessarily need to be the top left and bottom right corners, the
  5416. * constructor figures out how to fit a rectangle between them.
  5417. *
  5418. * @param from - the first point defining the rectangle
  5419. * @param to - the second point defining the rectangle
  5420. */
  5421. constructor(from: Point, to: Point)
  5422. /**
  5423. * Creates a rectangular shape item from the properties described by an
  5424. * object literal.
  5425. *
  5426. * @param object - an object containing properties describing the
  5427. * shape's attributes
  5428. */
  5429. constructor(object: object)
  5430. }
  5431. class Ellipse extends Shape {
  5432. /**
  5433. * Creates an elliptical shape item.
  5434. *
  5435. * @param rectangle - the rectangle circumscribing the ellipse
  5436. */
  5437. constructor(rectangle: paper.Rectangle)
  5438. /**
  5439. * Creates an elliptical shape item from the properties described by an
  5440. * object literal.
  5441. *
  5442. * @param object - an object containing properties describing the
  5443. * shape's attributes
  5444. */
  5445. constructor(object: object)
  5446. }
  5447. }
  5448. /**
  5449. * The Size object is used to describe the size or dimensions of
  5450. * something, through its {@link #width} and {@link #height} properties.
  5451. */
  5452. class Size {
  5453. /**
  5454. * The width of the size
  5455. */
  5456. width: number
  5457. /**
  5458. * The height of the size
  5459. */
  5460. height: number
  5461. /**
  5462. * Creates a Size object with the given width and height values.
  5463. *
  5464. * @param width - the width
  5465. * @param height - the height
  5466. */
  5467. constructor(width: number, height: number)
  5468. /**
  5469. * Creates a Size object using the numbers in the given array as
  5470. * dimensions.
  5471. */
  5472. constructor(array: any[])
  5473. /**
  5474. * Creates a Size object using the coordinates of the given Size object.
  5475. */
  5476. constructor(size: Size)
  5477. /**
  5478. * Creates a Size object using the {@link Point#x} and {@link Point#y}
  5479. * values of the given Point object.
  5480. */
  5481. constructor(point: Point)
  5482. /**
  5483. * Creates a Size object using the properties in the given object.
  5484. */
  5485. constructor(object: object)
  5486. /**
  5487. * Sets the size to the passed values. Note that any sequence of parameters
  5488. * that is supported by the various {@link Size} constructors also work
  5489. * for calls of `set()`.
  5490. */
  5491. set(...values: any[]): Size
  5492. /**
  5493. * Checks whether the width and height of the size are equal to those of the
  5494. * supplied size.
  5495. *
  5496. * @param size - the size to compare to
  5497. */
  5498. equals(size: Size): boolean
  5499. /**
  5500. * Returns a copy of the size.
  5501. */
  5502. clone(): Size
  5503. /**
  5504. * @return a string representation of the size
  5505. */
  5506. toString(): string
  5507. /**
  5508. * Returns the addition of the supplied value to the width and height of the
  5509. * size as a new size. The object itself is not modified!
  5510. *
  5511. * @param number - the number to add
  5512. *
  5513. * @return the addition of the size and the value as a new size
  5514. */
  5515. add(number: number): Size
  5516. /**
  5517. * Returns the addition of the width and height of the supplied size to the
  5518. * size as a new size. The object itself is not modified!
  5519. *
  5520. * @param size - the size to add
  5521. *
  5522. * @return the addition of the two sizes as a new size
  5523. */
  5524. add(size: Size): Size
  5525. /**
  5526. * Returns the subtraction of the supplied value from the width and height
  5527. * of the size as a new size. The object itself is not modified!
  5528. * The object itself is not modified!
  5529. *
  5530. * @param number - the number to subtract
  5531. *
  5532. * @return the subtraction of the size and the value as a new size
  5533. */
  5534. subtract(number: number): Size
  5535. /**
  5536. * Returns the subtraction of the width and height of the supplied size from
  5537. * the size as a new size. The object itself is not modified!
  5538. *
  5539. * @param size - the size to subtract
  5540. *
  5541. * @return the subtraction of the two sizes as a new size
  5542. */
  5543. subtract(size: Size): Size
  5544. /**
  5545. * Returns the multiplication of the supplied value with the width and
  5546. * height of the size as a new size. The object itself is not modified!
  5547. *
  5548. * @param number - the number to multiply by
  5549. *
  5550. * @return the multiplication of the size and the value as a new size
  5551. */
  5552. multiply(number: number): Size
  5553. /**
  5554. * Returns the multiplication of the width and height of the supplied size
  5555. * with the size as a new size. The object itself is not modified!
  5556. *
  5557. * @param size - the size to multiply by
  5558. *
  5559. * @return the multiplication of the two sizes as a new size
  5560. */
  5561. multiply(size: Size): Size
  5562. /**
  5563. * Returns the division of the supplied value by the width and height of the
  5564. * size as a new size. The object itself is not modified!
  5565. *
  5566. * @param number - the number to divide by
  5567. *
  5568. * @return the division of the size and the value as a new size
  5569. */
  5570. divide(number: number): Size
  5571. /**
  5572. * Returns the division of the width and height of the supplied size by the
  5573. * size as a new size. The object itself is not modified!
  5574. *
  5575. * @param size - the size to divide by
  5576. *
  5577. * @return the division of the two sizes as a new size
  5578. */
  5579. divide(size: Size): Size
  5580. /**
  5581. * The modulo operator returns the integer remainders of dividing the size
  5582. * by the supplied value as a new size.
  5583. *
  5584. * @return the integer remainders of dividing the size by the value
  5585. * as a new size
  5586. */
  5587. modulo(value: number): Size
  5588. /**
  5589. * The modulo operator returns the integer remainders of dividing the size
  5590. * by the supplied size as a new size.
  5591. *
  5592. * @return the integer remainders of dividing the sizes by each
  5593. * other as a new size
  5594. */
  5595. modulo(size: Size): Size
  5596. /**
  5597. * Checks if this size has both the width and height set to 0.
  5598. *
  5599. * @return true if both width and height are 0
  5600. */
  5601. isZero(): boolean
  5602. /**
  5603. * Checks if the width or the height of the size are NaN.
  5604. *
  5605. * @return true if the width or height of the size are NaN
  5606. */
  5607. isNaN(): boolean
  5608. /**
  5609. * Returns a new size with rounded {@link #width} and {@link #height}
  5610. * values. The object itself is not modified!
  5611. */
  5612. round(): Size
  5613. /**
  5614. * Returns a new size with the nearest greater non-fractional values to the
  5615. * specified {@link #width} and {@link #height} values. The object itself is
  5616. * not modified!
  5617. */
  5618. ceil(): Size
  5619. /**
  5620. * Returns a new size with the nearest smaller non-fractional values to the
  5621. * specified {@link #width} and {@link #height} values. The object itself is
  5622. * not modified!
  5623. */
  5624. floor(): Size
  5625. /**
  5626. * Returns a new size with the absolute values of the specified
  5627. * {@link #width} and {@link #height} values. The object itself is not
  5628. * modified!
  5629. */
  5630. abs(): Size
  5631. /**
  5632. * Returns a new size object with the smallest {@link #width} and
  5633. * {@link #height} of the supplied sizes.
  5634. *
  5635. * @return the newly created size object
  5636. */
  5637. static min(size1: Size, size2: Size): Size
  5638. /**
  5639. * Returns a new size object with the largest {@link #width} and
  5640. * {@link #height} of the supplied sizes.
  5641. *
  5642. * @return the newly created size object
  5643. */
  5644. static max(size1: Size, size2: Size): Size
  5645. /**
  5646. * Returns a size object with random {@link #width} and {@link #height}
  5647. * values between `0` and `1`.
  5648. *
  5649. * @return the newly created size object
  5650. */
  5651. static random(): Size
  5652. }
  5653. /**
  5654. * Style is used for changing the visual styles of items
  5655. * contained within a Paper.js project and is returned by
  5656. * {@link Item#style} and {@link Project#currentStyle}.
  5657. *
  5658. * All properties of Style are also reflected directly in {@link Item},
  5659. * i.e.: {@link Item#fillColor}.
  5660. *
  5661. * To set multiple style properties in one go, you can pass an object to
  5662. * {@link Item#style}. This is a convenient way to define a style once and
  5663. * apply it to a series of items:
  5664. */
  5665. class Style {
  5666. /**
  5667. * The view that this style belongs to.
  5668. */
  5669. readonly view: View
  5670. /**
  5671. * The color of the stroke.
  5672. */
  5673. strokeColor: Color | null
  5674. /**
  5675. * The width of the stroke.
  5676. */
  5677. strokeWidth: number
  5678. /**
  5679. * The shape to be used at the beginning and end of open {@link Path} items,
  5680. * when they have a stroke.
  5681. */
  5682. strokeCap: string
  5683. /**
  5684. * The shape to be used at the segments and corners of {@link Path} items
  5685. * when they have a stroke.
  5686. */
  5687. strokeJoin: string
  5688. /**
  5689. * Specifies whether the stroke is to be drawn taking the current affine
  5690. * transformation into account (the default behavior), or whether it should
  5691. * appear as a non-scaling stroke.
  5692. */
  5693. strokeScaling: boolean
  5694. /**
  5695. * The dash offset of the stroke.
  5696. */
  5697. dashOffset: number
  5698. /**
  5699. * Specifies an array containing the dash and gap lengths of the stroke.
  5700. */
  5701. dashArray: number[]
  5702. /**
  5703. * The miter limit of the stroke. When two line segments meet at a sharp
  5704. * angle and miter joins have been specified for {@link #strokeJoin}, it is
  5705. * possible for the miter to extend far beyond the {@link #strokeWidth} of
  5706. * the path. The miterLimit imposes a limit on the ratio of the miter length
  5707. * to the {@link #strokeWidth}.
  5708. */
  5709. miterLimit: number
  5710. /**
  5711. * The fill color.
  5712. */
  5713. fillColor: Color | null
  5714. /**
  5715. * The fill-rule with which the shape gets filled. Please note that only
  5716. * modern browsers support fill-rules other than `'nonzero'`.
  5717. */
  5718. fillRule: string
  5719. /**
  5720. * The shadow color.
  5721. */
  5722. shadowColor: Color | null
  5723. /**
  5724. * The shadow's blur radius.
  5725. */
  5726. shadowBlur: number
  5727. /**
  5728. * The shadow's offset.
  5729. */
  5730. shadowOffset: Point
  5731. /**
  5732. * The color the item is highlighted with when selected. If the item does
  5733. * not specify its own color, the color defined by its layer is used instead.
  5734. */
  5735. selectedColor: Color | null
  5736. /**
  5737. * The font-family to be used in text content.
  5738. */
  5739. fontFamily: string
  5740. /**
  5741. * The font-weight to be used in text content.
  5742. */
  5743. fontWeight: string | number
  5744. /**
  5745. * The font size of text content, as a number in pixels, or as a string with
  5746. * optional units `'px'`, `'pt'` and `'em'`.
  5747. */
  5748. fontSize: number | string
  5749. /**
  5750. * The text leading of text content.
  5751. */
  5752. leading: number | string
  5753. /**
  5754. * The justification of text paragraphs.
  5755. */
  5756. justification: string
  5757. /**
  5758. * Style objects don't need to be created directly. Just pass an object to
  5759. * {@link Item#style} or {@link Project#currentStyle}, it will be converted
  5760. * to a Style object internally.
  5761. */
  5762. constructor(style: object)
  5763. }
  5764. /**
  5765. * Symbols allow you to place multiple instances of an item in your
  5766. * project. This can save memory, since all instances of a symbol simply refer
  5767. * to the original item and it can speed up moving around complex objects, since
  5768. * internal properties such as segment lists and gradient positions don't need
  5769. * to be updated with every transformation.
  5770. */
  5771. class SymbolDefinition {
  5772. /**
  5773. * The project that this symbol belongs to.
  5774. */
  5775. readonly project: Project
  5776. /**
  5777. * The item used as the symbol's definition.
  5778. */
  5779. item: Item
  5780. /**
  5781. * Creates a Symbol definition.
  5782. *
  5783. * @param item - the source item which is removed from the scene graph
  5784. * and becomes the symbol's definition.
  5785. */
  5786. constructor(item: Item, dontCenter?: boolean)
  5787. /**
  5788. * Places in instance of the symbol in the project.
  5789. *
  5790. * @param position - the position of the placed symbol
  5791. */
  5792. place(position?: Point): SymbolItem
  5793. /**
  5794. * Returns a copy of the symbol.
  5795. */
  5796. clone(): SymbolDefinition
  5797. /**
  5798. * Checks whether the symbol's definition is equal to the supplied symbol.
  5799. *
  5800. * @return true if they are equal
  5801. */
  5802. equals(symbol: SymbolDefinition): boolean
  5803. }
  5804. /**
  5805. * A symbol item represents an instance of a symbol which has been
  5806. * placed in a Paper.js project.
  5807. */
  5808. class SymbolItem extends Item {
  5809. /**
  5810. * The symbol definition that the placed symbol refers to.
  5811. */
  5812. definition: SymbolDefinition
  5813. /**
  5814. * Creates a new symbol item.
  5815. *
  5816. * @param definition - the definition to place or an
  5817. * item to place as a symbol
  5818. * @param point - the center point of the placed symbol
  5819. */
  5820. constructor(definition: SymbolDefinition | Item, point?: Point)
  5821. }
  5822. /**
  5823. * The TextItem type allows you to create typography. Its functionality
  5824. * is inherited by different text item types such as {@link PointText}, and
  5825. * {@link AreaText} (coming soon). They each add a layer of functionality
  5826. * that is unique to their type, but share the underlying properties and
  5827. * functions that they inherit from TextItem.
  5828. */
  5829. class TextItem extends Item {
  5830. /**
  5831. * The text contents of the text item.
  5832. */
  5833. content: string
  5834. /**
  5835. * The font-family to be used in text content.
  5836. */
  5837. fontFamily: string
  5838. /**
  5839. * The font-weight to be used in text content.
  5840. */
  5841. fontWeight: string | number
  5842. /**
  5843. * The font size of text content, as a number in pixels, or as a string with
  5844. * optional units `'px'`, `'pt'` and `'em'`.
  5845. */
  5846. fontSize: number | string
  5847. /**
  5848. * The text leading of text content.
  5849. */
  5850. leading: number | string
  5851. /**
  5852. * The justification of text paragraphs.
  5853. */
  5854. justification: string
  5855. }
  5856. /**
  5857. * The Tool object refers to a script that the user can interact with by
  5858. * using the mouse and keyboard and can be accessed through the global
  5859. * `tool` variable. All its properties are also available in the paper
  5860. * scope.
  5861. *
  5862. * The global `tool` variable only exists in scripts that contain mouse handler
  5863. * functions ({@link #onMouseMove}, {@link #onMouseDown}, {@link #onMouseDrag},
  5864. * {@link #onMouseUp}) or a keyboard handler function ({@link #onKeyDown},
  5865. * {@link #onKeyUp}).
  5866. */
  5867. class Tool {
  5868. /**
  5869. * The minimum distance the mouse has to drag before firing the onMouseDrag
  5870. * event, since the last onMouseDrag event.
  5871. */
  5872. minDistance: number
  5873. /**
  5874. * The maximum distance the mouse has to drag before firing the onMouseDrag
  5875. * event, since the last onMouseDrag event.
  5876. */
  5877. maxDistance: number
  5878. fixedDistance: number
  5879. /**
  5880. * The function to be called when the mouse button is pushed down. The
  5881. * function receives a {@link ToolEvent} object which contains information
  5882. * about the tool event.
  5883. */
  5884. onMouseDown: Function | null
  5885. /**
  5886. * The function to be called when the mouse position changes while the mouse
  5887. * is being dragged. The function receives a {@link ToolEvent} object which
  5888. * contains information about the tool event.
  5889. */
  5890. onMouseDrag: Function | null
  5891. /**
  5892. * The function to be called the mouse moves within the project view. The
  5893. * function receives a {@link ToolEvent} object which contains information
  5894. * about the tool event.
  5895. */
  5896. onMouseMove: Function | null
  5897. /**
  5898. * The function to be called when the mouse button is released. The function
  5899. * receives a {@link ToolEvent} object which contains information about the
  5900. * tool event.
  5901. */
  5902. onMouseUp: Function | null
  5903. /**
  5904. * The function to be called when the user presses a key on the keyboard.
  5905. * The function receives a {@link KeyEvent} object which contains
  5906. * information about the keyboard event.
  5907. *
  5908. * If the function returns `false`, the keyboard event will be prevented
  5909. * from bubbling up. This can be used for example to stop the window from
  5910. * scrolling, when you need the user to interact with arrow keys.
  5911. */
  5912. onKeyDown: Function | null
  5913. /**
  5914. * The function to be called when the user releases a key on the keyboard.
  5915. * The function receives a {@link KeyEvent} object which contains
  5916. * information about the keyboard event.
  5917. *
  5918. * If the function returns `false`, the keyboard event will be prevented
  5919. * from bubbling up. This can be used for example to stop the window from
  5920. * scrolling, when you need the user to interact with arrow keys.
  5921. */
  5922. onKeyUp: Function | null
  5923. /**
  5924. * Activates this tool, meaning {@link PaperScope#tool} will
  5925. * point to it and it will be the one that receives tool events.
  5926. */
  5927. activate(): void
  5928. /**
  5929. * Removes this tool from the {@link PaperScope#tools} list.
  5930. */
  5931. remove(): void
  5932. /**
  5933. * Attach an event handler to the tool.
  5934. *
  5935. * @param type - the event type: {@values 'mousedown', 'mouseup',
  5936. * 'mousedrag', 'mousemove', 'keydown', 'keyup'}
  5937. * @param function - the function to be called when the event
  5938. * occurs, receiving a {@link ToolEvent} object as its sole argument
  5939. *
  5940. * @return this tool itself, so calls can be chained
  5941. */
  5942. on(type: string, callback: Function): Tool
  5943. /**
  5944. * Attach one or more event handlers to the tool.
  5945. *
  5946. * @param param - an object literal containing one or more of the
  5947. * following properties: {@values mousedown, mouseup, mousedrag,
  5948. * mousemove, keydown, keyup}
  5949. *
  5950. * @return this tool itself, so calls can be chained
  5951. */
  5952. on(param: object): Tool
  5953. /**
  5954. * Detach an event handler from the tool.
  5955. *
  5956. * @param type - the event type: {@values 'mousedown', 'mouseup',
  5957. * 'mousedrag', 'mousemove', 'keydown', 'keyup'}
  5958. * @param function - the function to be detached
  5959. *
  5960. * @return this tool itself, so calls can be chained
  5961. */
  5962. off(type: string, callback: Function): Tool
  5963. /**
  5964. * Detach one or more event handlers from the tool.
  5965. *
  5966. * @param param - an object literal containing one or more of the
  5967. * following properties: {@values mousedown, mouseup, mousedrag,
  5968. * mousemove, keydown, keyup}
  5969. *
  5970. * @return this tool itself, so calls can be chained
  5971. */
  5972. off(param: object): Tool
  5973. /**
  5974. * Emit an event on the tool.
  5975. *
  5976. * @param type - the event type: {@values 'mousedown', 'mouseup',
  5977. * 'mousedrag', 'mousemove', 'keydown', 'keyup'}
  5978. * @param event - an object literal containing properties describing
  5979. * the event
  5980. *
  5981. * @return true if the event had listeners
  5982. */
  5983. emit(type: string, event: object): boolean
  5984. /**
  5985. * Check if the tool has one or more event handlers of the specified type.
  5986. *
  5987. * @param type - the event type: {@values 'mousedown', 'mouseup',
  5988. * 'mousedrag', 'mousemove', 'keydown', 'keyup'}
  5989. *
  5990. * @return true if the tool has one or more event handlers of
  5991. * the specified type
  5992. */
  5993. responds(type: string): boolean
  5994. }
  5995. /**
  5996. * ToolEvent The ToolEvent object is received by the {@link Tool}'s mouse
  5997. * event handlers {@link Tool#onMouseDown}, {@link Tool#onMouseDrag},
  5998. * {@link Tool#onMouseMove} and {@link Tool#onMouseUp}. The ToolEvent
  5999. * object is the only parameter passed to these functions and contains
  6000. * information about the mouse event.
  6001. */
  6002. class ToolEvent extends Event {
  6003. /**
  6004. * The type of tool event.
  6005. */
  6006. type: string
  6007. /**
  6008. * The position of the mouse in project coordinates when the event was
  6009. * fired.
  6010. */
  6011. point: Point
  6012. /**
  6013. * The position of the mouse in project coordinates when the previous
  6014. * event was fired.
  6015. */
  6016. lastPoint: Point
  6017. /**
  6018. * The position of the mouse in project coordinates when the mouse button
  6019. * was last clicked.
  6020. */
  6021. downPoint: Point
  6022. /**
  6023. * The point in the middle between {@link #lastPoint} and
  6024. * {@link #point}. This is a useful position to use when creating
  6025. * artwork based on the moving direction of the mouse, as returned by
  6026. * {@link #delta}.
  6027. */
  6028. middlePoint: Point
  6029. /**
  6030. * The difference between the current position and the last position of the
  6031. * mouse when the event was fired. In case of the mouseup event, the
  6032. * difference to the mousedown position is returned.
  6033. */
  6034. delta: Point
  6035. /**
  6036. * The number of times the mouse event was fired.
  6037. */
  6038. count: number
  6039. /**
  6040. * The item at the position of the mouse (if any).
  6041. *
  6042. * If the item is contained within one or more {@link Group} or
  6043. * {@link CompoundPath} items, the most top level group or compound path
  6044. * that it is contained within is returned.
  6045. */
  6046. item: Item
  6047. /**
  6048. * @return a string representation of the tool event
  6049. */
  6050. toString(): string
  6051. }
  6052. /**
  6053. * Allows tweening `Object` properties between two states for a given
  6054. * duration. To tween properties on Paper.js {@link Item} instances,
  6055. * {@link Item#tween} can be used, which returns created
  6056. * tween instance.
  6057. *
  6058. * @see Item#tween(from, to, options)
  6059. * @see Item#tween(to, options)
  6060. * @see Item#tween(options)
  6061. * @see Item#tweenTo(to, options)
  6062. * @see Item#tweenFrom(from, options)
  6063. */
  6064. class Tween {
  6065. /**
  6066. * The function to be called when the tween is updated. It receives an
  6067. * object as its sole argument, containing the current progress of the
  6068. * tweening and the factor calculated by the easing function.
  6069. */
  6070. onUpdate: Function | null
  6071. /**
  6072. * Creates a new tween.
  6073. *
  6074. * @param object - the object to tween the properties on
  6075. * @param from - the state at the start of the tweening
  6076. * @param to - the state at the end of the tweening
  6077. * @param duration - the duration of the tweening
  6078. * @param easing - the type of the easing
  6079. * function or the easing function
  6080. * @param start - whether to start tweening automatically
  6081. */
  6082. constructor(object: object, from: object, to: object, duration: number, easing?: string | Function, start?: boolean)
  6083. /**
  6084. * Set a function that will be executed when the tween completes.
  6085. *
  6086. * @param function - the function to execute when the tween
  6087. * completes
  6088. */
  6089. then(callback: Function): Tween
  6090. /**
  6091. * Start tweening.
  6092. */
  6093. start(): Tween
  6094. /**
  6095. * Stop tweening.
  6096. */
  6097. stop(): Tween
  6098. }
  6099. /**
  6100. * The View object wraps an HTML element and handles drawing and user
  6101. * interaction through mouse and keyboard for it. It offer means to scroll the
  6102. * view, find the currently visible bounds in project coordinates, or the
  6103. * center, both useful for constructing artwork that should appear centered on
  6104. * screen.
  6105. */
  6106. class View {
  6107. /**
  6108. * Controls whether the view is automatically updated in the next animation
  6109. * frame on changes, or whether you prefer to manually call
  6110. * {@link #update} or {@link #requestUpdate} after changes.
  6111. * Note that this is `true` by default, except for Node.js, where manual
  6112. * updates make more sense.
  6113. */
  6114. autoUpdate: boolean
  6115. /**
  6116. * The underlying native element.
  6117. */
  6118. readonly element: HTMLCanvasElement
  6119. /**
  6120. * The ratio between physical pixels and device-independent pixels (DIPs)
  6121. * of the underlying canvas / device.
  6122. * It is `1` for normal displays, and `2` or more for
  6123. * high-resolution displays.
  6124. */
  6125. readonly pixelRatio: number
  6126. /**
  6127. * The resoltuion of the underlying canvas / device in pixel per inch (DPI).
  6128. * It is `72` for normal displays, and `144` for high-resolution
  6129. * displays with a pixel-ratio of `2`.
  6130. */
  6131. readonly resolution: number
  6132. /**
  6133. * The size of the view. Changing the view's size will resize it's
  6134. * underlying element.
  6135. */
  6136. viewSize: Size
  6137. /**
  6138. * The bounds of the currently visible area in project coordinates.
  6139. */
  6140. readonly bounds: Rectangle
  6141. /**
  6142. * The size of the visible area in project coordinates.
  6143. */
  6144. readonly size: Size
  6145. /**
  6146. * The center of the visible area in project coordinates.
  6147. */
  6148. center: Point
  6149. /**
  6150. * The view's zoom factor by which the project coordinates are magnified.
  6151. *
  6152. * @see #scaling
  6153. */
  6154. zoom: number
  6155. /**
  6156. * The current rotation angle of the view, as described by its
  6157. * {@link #matrix}.
  6158. */
  6159. rotation: number
  6160. /**
  6161. * The current scale factor of the view, as described by its
  6162. * {@link #matrix}.
  6163. *
  6164. * @see #zoom
  6165. */
  6166. scaling: Point
  6167. /**
  6168. * The view's transformation matrix, defining the view onto the project's
  6169. * contents (position, zoom level, rotation, etc).
  6170. */
  6171. matrix: Matrix
  6172. /**
  6173. * Handler function to be called on each frame of an animation.
  6174. * The function receives an event object which contains information about
  6175. * the frame event:
  6176. *
  6177. * @see Item#onFrame
  6178. *
  6179. * @option event.count {Number} the number of times the frame event was
  6180. * fired
  6181. * @option event.time {Number} the total amount of time passed since the
  6182. * first frame event in seconds
  6183. * @option event.delta {Number} the time passed in seconds since the last
  6184. * frame event
  6185. */
  6186. onFrame: Function | null
  6187. /**
  6188. * Handler function that is called whenever a view is resized.
  6189. */
  6190. onResize: Function | null
  6191. /**
  6192. * The function to be called when the mouse button is pushed down on the
  6193. * view. The function receives a {@link MouseEvent} object which contains
  6194. * information about the mouse event.
  6195. * Note that such mouse events bubble up the scene graph hierarchy, reaching
  6196. * the view at the end, unless they are stopped before with {@link
  6197. * Event#stopPropagation()} or by returning `false` from a handler.
  6198. *
  6199. * @see Item#onMouseDown
  6200. */
  6201. onMouseDown: Function | null
  6202. /**
  6203. * The function to be called when the mouse position changes while the mouse
  6204. * is being dragged over the view. The function receives a {@link
  6205. * MouseEvent} object which contains information about the mouse event.
  6206. * Note that such mouse events bubble up the scene graph hierarchy, reaching
  6207. * the view at the end, unless they are stopped before with {@link
  6208. * Event#stopPropagation()} or by returning `false` from a handler.
  6209. *
  6210. * @see Item#onMouseDrag
  6211. */
  6212. onMouseDrag: Function | null
  6213. /**
  6214. * The function to be called when the mouse button is released over the item.
  6215. * The function receives a {@link MouseEvent} object which contains
  6216. * information about the mouse event.
  6217. *
  6218. * @see Item#onMouseUp
  6219. */
  6220. onMouseUp: Function | null
  6221. /**
  6222. * The function to be called when the mouse clicks on the view. The function
  6223. * receives a {@link MouseEvent} object which contains information about the
  6224. * mouse event.
  6225. * Note that such mouse events bubble up the scene graph hierarchy, reaching
  6226. * the view at the end, unless they are stopped before with {@link
  6227. * Event#stopPropagation()} or by returning `false` from a handler.
  6228. *
  6229. * @see Item#onClick
  6230. */
  6231. onClick: Function | null
  6232. /**
  6233. * The function to be called when the mouse double clicks on the view. The
  6234. * function receives a {@link MouseEvent} object which contains information
  6235. * about the mouse event.
  6236. * Note that such mouse events bubble up the scene graph hierarchy, reaching
  6237. * the view at the end, unless they are stopped before with {@link
  6238. * Event#stopPropagation()} or by returning `false` from a handler.
  6239. *
  6240. * @see Item#onDoubleClick
  6241. */
  6242. onDoubleClick: Function | null
  6243. /**
  6244. * The function to be called repeatedly while the mouse moves over the
  6245. * view. The function receives a {@link MouseEvent} object which contains
  6246. * information about the mouse event.
  6247. * Note that such mouse events bubble up the scene graph hierarchy, reaching
  6248. * the view at the end, unless they are stopped before with {@link
  6249. * Event#stopPropagation()} or by returning `false` from a handler.
  6250. *
  6251. * @see Item#onMouseMove
  6252. */
  6253. onMouseMove: Function | null
  6254. /**
  6255. * The function to be called when the mouse moves over the view. This
  6256. * function will only be called again, once the mouse moved outside of the
  6257. * view first. The function receives a {@link MouseEvent} object which
  6258. * contains information about the mouse event.
  6259. * Note that such mouse events bubble up the scene graph hierarchy, reaching
  6260. * the view at the end, unless they are stopped before with {@link
  6261. * Event#stopPropagation()} or by returning `false` from a handler.
  6262. *
  6263. * @see Item#onMouseEnter
  6264. */
  6265. onMouseEnter: Function | null
  6266. /**
  6267. * The function to be called when the mouse moves out of the view.
  6268. * The function receives a {@link MouseEvent} object which contains
  6269. * information about the mouse event.
  6270. * Note that such mouse events bubble up the scene graph hierarchy, reaching
  6271. * the view at the end, unless they are stopped before with {@link
  6272. * Event#stopPropagation()} or by returning `false` from a handler.
  6273. *
  6274. * @see View#onMouseLeave
  6275. */
  6276. onMouseLeave: Function | null
  6277. /**
  6278. * Removes this view from the project and frees the associated element.
  6279. */
  6280. remove(): void
  6281. /**
  6282. * Updates the view if there are changes. Note that when using built-in
  6283. * event hanlders for interaction, animation and load events, this method is
  6284. * invoked for you automatically at the end.
  6285. *
  6286. * @return true if the view was updated
  6287. */
  6288. update(): boolean
  6289. /**
  6290. * Requests an update of the view if there are changes through the browser's
  6291. * requestAnimationFrame() mechanism for smooth animation. Note that when
  6292. * using built-in event handlers for interaction, animation and load events,
  6293. * updates are automatically invoked for you automatically at the end.
  6294. */
  6295. requestUpdate(): void
  6296. /**
  6297. * Makes all animation play by adding the view to the request animation
  6298. * loop.
  6299. */
  6300. play(): void
  6301. /**
  6302. * Makes all animation pause by removing the view from the request animation
  6303. * loop.
  6304. */
  6305. pause(): void
  6306. /**
  6307. * Checks whether the view is currently visible within the current browser
  6308. * viewport.
  6309. *
  6310. * @return true if the view is visible
  6311. */
  6312. isVisible(): boolean
  6313. /**
  6314. * Checks whether the view is inserted into the browser DOM.
  6315. *
  6316. * @return true if the view is inserted
  6317. */
  6318. isInserted(): boolean
  6319. /**
  6320. * Translates (scrolls) the view by the given offset vector.
  6321. *
  6322. * @param delta - the offset to translate the view by
  6323. */
  6324. translate(delta: Point): void
  6325. /**
  6326. * Rotates the view by a given angle around the given center point.
  6327. *
  6328. * Angles are oriented clockwise and measured in degrees.
  6329. *
  6330. * @see Matrix#rotate(angle[, center])
  6331. *
  6332. * @param angle - the rotation angle
  6333. */
  6334. rotate(angle: number, center?: Point): void
  6335. /**
  6336. * Scales the view by the given value from its center point, or optionally
  6337. * from a supplied point.
  6338. *
  6339. * @param scale - the scale factor
  6340. */
  6341. scale(scale: number, center?: Point): void
  6342. /**
  6343. * Scales the view by the given values from its center point, or optionally
  6344. * from a supplied point.
  6345. *
  6346. * @param hor - the horizontal scale factor
  6347. * @param ver - the vertical scale factor
  6348. */
  6349. scale(hor: number, ver: number, center?: Point): void
  6350. /**
  6351. * Shears the view by the given value from its center point, or optionally
  6352. * by a supplied point.
  6353. *
  6354. * @see Matrix#shear(shear[, center])
  6355. *
  6356. * @param shear - the horizontal and vertical shear factors as a point
  6357. */
  6358. shear(shear: Point, center?: Point): void
  6359. /**
  6360. * Shears the view by the given values from its center point, or optionally
  6361. * by a supplied point.
  6362. *
  6363. * @see Matrix#shear(hor, ver[, center])
  6364. *
  6365. * @param hor - the horizontal shear factor
  6366. * @param ver - the vertical shear factor
  6367. */
  6368. shear(hor: number, ver: number, center?: Point): void
  6369. /**
  6370. * Skews the view by the given angles from its center point, or optionally
  6371. * by a supplied point.
  6372. *
  6373. * @see Matrix#shear(skew[, center])
  6374. *
  6375. * @param skew - the horizontal and vertical skew angles in degrees
  6376. */
  6377. skew(skew: Point, center?: Point): void
  6378. /**
  6379. * Skews the view by the given angles from its center point, or optionally
  6380. * by a supplied point.
  6381. *
  6382. * @see Matrix#shear(hor, ver[, center])
  6383. *
  6384. * @param hor - the horizontal skew angle in degrees
  6385. * @param ver - the vertical sskew angle in degrees
  6386. */
  6387. skew(hor: number, ver: number, center?: Point): void
  6388. /**
  6389. * Transform the view.
  6390. *
  6391. * @param matrix - the matrix by which the view shall be transformed
  6392. */
  6393. transform(matrix: Matrix): void
  6394. /**
  6395. * Converts the passed point from project coordinate space to view
  6396. * coordinate space, which is measured in browser pixels in relation to the
  6397. * position of the view element.
  6398. *
  6399. * @param point - the point in project coordinates to be converted
  6400. *
  6401. * @return the point converted into view coordinates
  6402. */
  6403. projectToView(point: Point): Point
  6404. /**
  6405. * Converts the passed point from view coordinate space to project
  6406. * coordinate space.
  6407. *
  6408. * @param point - the point in view coordinates to be converted
  6409. *
  6410. * @return the point converted into project coordinates
  6411. */
  6412. viewToProject(point: Point): Point
  6413. /**
  6414. * Determines and returns the event location in project coordinate space.
  6415. *
  6416. * @param event - the native event object for which to determine the
  6417. * location.
  6418. *
  6419. * @return the event point in project coordinates.
  6420. */
  6421. getEventPoint(event: Event): Point
  6422. /**
  6423. * Attach an event handler to the view.
  6424. *
  6425. * @param type - the type of event: {@values 'frame', 'resize',
  6426. * 'mousedown', 'mouseup', 'mousedrag', 'click', 'doubleclick',
  6427. * 'mousemove', 'mouseenter', 'mouseleave'}
  6428. * @param function - the function to be called when the event
  6429. * occurs, receiving a {@link MouseEvent} or {@link Event} object as its
  6430. * sole argument
  6431. *
  6432. * @return this view itself, so calls can be chained
  6433. */
  6434. on(type: string, callback: Function): View
  6435. /**
  6436. * Attach one or more event handlers to the view.
  6437. *
  6438. * @param param - an object literal containing one or more of the
  6439. * following properties: {@values frame, resize}
  6440. *
  6441. * @return this view itself, so calls can be chained
  6442. */
  6443. on(param: object): View
  6444. /**
  6445. * Detach an event handler from the view.
  6446. *
  6447. * @param type - the event type: {@values 'frame', 'resize',
  6448. * 'mousedown', 'mouseup', 'mousedrag', 'click', 'doubleclick',
  6449. * 'mousemove', 'mouseenter', 'mouseleave'}
  6450. * @param function - the function to be detached
  6451. *
  6452. * @return this view itself, so calls can be chained
  6453. */
  6454. off(type: string, callback: Function): View
  6455. /**
  6456. * Detach one or more event handlers from the view.
  6457. *
  6458. * @param param - an object literal containing one or more of the
  6459. * following properties: {@values frame, resize}
  6460. *
  6461. * @return this view itself, so calls can be chained
  6462. */
  6463. off(param: object): View
  6464. /**
  6465. * Emit an event on the view.
  6466. *
  6467. * @param type - the event type: {@values 'frame', 'resize',
  6468. * 'mousedown', 'mouseup', 'mousedrag', 'click', 'doubleclick',
  6469. * 'mousemove', 'mouseenter', 'mouseleave'}
  6470. * @param event - an object literal containing properties describing
  6471. * the event
  6472. *
  6473. * @return true if the event had listeners
  6474. */
  6475. emit(type: string, event: object): boolean
  6476. /**
  6477. * Check if the view has one or more event handlers of the specified type.
  6478. *
  6479. * @param type - the event type: {@values 'frame', 'resize',
  6480. * 'mousedown', 'mouseup', 'mousedrag', 'click', 'doubleclick',
  6481. * 'mousemove', 'mouseenter', 'mouseleave'}
  6482. *
  6483. * @return true if the view has one or more event handlers of
  6484. * the specified type
  6485. */
  6486. responds(type: string): boolean
  6487. }
  6488. }
  6489. declare module 'paper/dist/paper-core'
  6490. {
  6491. const paperCore: Pick<paper.PaperScope, Exclude<keyof paper.PaperScope, 'PaperScript'>>;
  6492. export = paperCore
  6493. }
  6494. declare module 'paper'
  6495. {
  6496. const paperFull: paper.PaperScope;
  6497. export = paperFull
  6498. }